| 1 |
import { |
| 2 |
ImagePicker, |
| 3 |
PickerActions, |
| 4 |
PickerButton, |
| 5 |
} from '@agent/components/ImagePicker'; |
| 6 |
import { __ } from '@wordpress/i18n'; |
| 7 |
|
| 8 |
const done = (id, result) => |
| 9 |
window.dispatchEvent( |
| 10 |
new CustomEvent('extendify-agent:client-tool-done', { |
| 11 |
detail: { id, result }, |
| 12 |
}), |
| 13 |
); |
| 14 |
|
| 15 |
export const ImageAcquisitionRequest = ({ message }) => { |
| 16 |
const { id, details } = message; |
| 17 |
const { prompt = '', search = '', tab } = details.inputs ?? {}; |
| 18 |
|
| 19 |
return ( |
| 20 |
<ImagePicker |
| 21 |
prompt={prompt} |
| 22 |
search={search} |
| 23 |
tab={tab} |
| 24 |
autoGenerate={tab === 'generate'} |
| 25 |
onSubmit={(image) => |
| 26 |
done(id, { id: image.id, url: image.source_url || image.url }) |
| 27 |
} |
| 28 |
onError={(failure) => |
| 29 |
done(id, { error: failure?.message || 'Image import failed' }) |
| 30 |
} |
| 31 |
footer={({ ready, busy, submit }) => ( |
| 32 |
<PickerActions> |
| 33 |
<PickerButton |
| 34 |
disabled={busy} |
| 35 |
onClick={() => done(id, { skipped: true })} |
| 36 |
> |
| 37 |
{__('Skip', 'extendify-local')} |
| 38 |
</PickerButton> |
| 39 |
<PickerButton primary disabled={!ready || busy} onClick={submit}> |
| 40 |
{busy |
| 41 |
? __('Saving...', 'extendify-local') |
| 42 |
: __('Submit', 'extendify-local')} |
| 43 |
</PickerButton> |
| 44 |
</PickerActions> |
| 45 |
)} |
| 46 |
/> |
| 47 |
); |
| 48 |
}; |
| 49 |
|