| 1 |
import { toolSelect } from '@agent/icons'; |
| 2 |
import { useWorkflowStore } from '@agent/state/workflows'; |
| 3 |
import { __ } from '@wordpress/i18n'; |
| 4 |
import { closeSmall, Icon } from '@wordpress/icons'; |
| 5 |
import classNames from 'classnames'; |
| 6 |
|
| 7 |
export const ChatTools = ({ disabled = false }) => { |
| 8 |
const { getWorkflowsByFeature, domToolEnabled, setDomToolEnabled } = |
| 9 |
useWorkflowStore(); |
| 10 |
const domTool = getWorkflowsByFeature({ requires: ['block'] })?.length > 0; |
| 11 |
|
| 12 |
const handleClose = () => { |
| 13 |
window.dispatchEvent(new CustomEvent('extendify-agent:cancel-workflow')); |
| 14 |
setDomToolEnabled(!domToolEnabled); |
| 15 |
}; |
| 16 |
|
| 17 |
if (!domTool) return null; |
| 18 |
return ( |
| 19 |
<div className="flex items-center"> |
| 20 |
<button |
| 21 |
type="button" |
| 22 |
disabled={disabled} |
| 23 |
className={classNames( |
| 24 |
'm-0 flex items-center rounded-sm border-0 px-1 py-0.5 leading-none disabled:opacity-50 text-gray-900', |
| 25 |
{ |
| 26 |
'bg-gray-300': domToolEnabled, |
| 27 |
'bg-gray-100 text-gray-900': !domToolEnabled, |
| 28 |
'hover:bg-gray-200': !disabled, |
| 29 |
}, |
| 30 |
)} |
| 31 |
onClick={handleClose} |
| 32 |
> |
| 33 |
<Icon size={24} icon={toolSelect} /> |
| 34 |
<span className="px-1 text-sm font-medium"> |
| 35 |
{__('Select', 'extendify-local')} |
| 36 |
</span> |
| 37 |
{domToolEnabled && ( |
| 38 |
<Icon size={20} icon={closeSmall} className="fill-current" /> |
| 39 |
)} |
| 40 |
</button> |
| 41 |
</div> |
| 42 |
); |
| 43 |
}; |
| 44 |
|