| 1 |
import { magic } from '@agent/icons'; |
| 2 |
import { useGlobalStore } from '@agent/state/global'; |
| 3 |
import { useEffect, useRef } from '@wordpress/element'; |
| 4 |
import { __ } from '@wordpress/i18n'; |
| 5 |
import { chevronUp, Icon } from '@wordpress/icons'; |
| 6 |
|
| 7 |
export const Mobile = () => { |
| 8 |
const { isMobile, minimized, setMinimized } = useGlobalStore(); |
| 9 |
const ref = useRef(null); |
| 10 |
|
| 11 |
const minimize = () => setMinimized(false); |
| 12 |
|
| 13 |
useEffect(() => { |
| 14 |
if (!isMobile || minimized) return; |
| 15 |
// Set button height as root var |
| 16 |
document.body.style.setProperty( |
| 17 |
'--extendify-agent-mobile-btn-height', |
| 18 |
`${ref.current?.offsetHeight}px`, |
| 19 |
); |
| 20 |
}, [isMobile, minimized]); |
| 21 |
|
| 22 |
useEffect(() => { |
| 23 |
if (!isMobile) return; |
| 24 |
document.body.classList.add('extendify-agent-mobile-btn-open'); |
| 25 |
return () => { |
| 26 |
document.body.classList.remove('extendify-agent-mobile-btn-open'); |
| 27 |
}; |
| 28 |
}, [isMobile]); |
| 29 |
|
| 30 |
if (!isMobile || !minimized) return null; |
| 31 |
|
| 32 |
return ( |
| 33 |
<button |
| 34 |
ref={ref} |
| 35 |
type="button" |
| 36 |
className="m-0 flex w-full items-center justify-between gap-2 bg-gray-900 px-4 py-3 font-sans text-white shadow-[0_-1px_0_0_rgba(255,255,255,0.05)]" |
| 37 |
onClick={minimize} |
| 38 |
aria-label={__('Open Agent', 'extendify-local')} |
| 39 |
> |
| 40 |
<div className="flex gap-3"> |
| 41 |
<div className="flex h-10 w-10 items-center justify-center rounded-full bg-wp-theme-main"> |
| 42 |
<Icon icon={magic} size={24} /> |
| 43 |
</div> |
| 44 |
<div className="text-left text-sm rtl:text-right"> |
| 45 |
<div className="font-semibold"> |
| 46 |
{__('AI Agent', 'extendify-local')} |
| 47 |
</div> |
| 48 |
<div className="text-gray-600"> |
| 49 |
{__('How can we help you today?', 'extendify-local')} |
| 50 |
</div> |
| 51 |
</div> |
| 52 |
</div> |
| 53 |
<Icon className="fill-white" icon={chevronUp} size={24} /> |
| 54 |
</button> |
| 55 |
); |
| 56 |
}; |
| 57 |
|