/** * WordPres dependencies */ import { Popover, Spinner } from '@safe-wordpress/components'; import { useRef, useState } from '@safe-wordpress/element'; import { _x } from '@safe-wordpress/i18n'; /** * External dependencies */ import { usePageAttribute } from '@nab/data'; /** * Internal dependencies */ import './style.scss'; export const ChatBot = (): JSX.Element | null => { const [ loading, setLoading ] = useState( true ); const iframe = useRef< HTMLIFrameElement | null >( null ); const [ isOpen, openChatBot ] = usePageAttribute( 'chatbot/status', false ); if ( ! isOpen ) { return null; } const onNewChat = () => iframe.current?.contentWindow?.postMessage( { type: 'nelio-ab-testing-chatbot-reset', } ); const onClose = () => openChatBot( false ); const url = 'https://neliosoftware.com/testing/support-bot/'; const virtualAnchor = { getBoundingClientRect: () => ( { top: window.innerHeight, left: window.innerWidth - 12, right: window.innerWidth, bottom: window.innerHeight, width: 0, height: 0, } ), ownerDocument: document, }; return ( { _x( 'Help', 'text', 'nelio-ab-testing' ) } { loading && ( ) } setLoading( false ) } title={ _x( 'Support Chat Bot', 'text', 'nelio-ab-testing' ) } src={ url } > ); }; const HeaderButton = ( { type, onClick, }: { readonly type: 'close' | 'edit'; readonly onClick: () => void; } ) => { const label = 'edit' === type ? _x( 'New Chat', 'command', 'nelio-ab-testing' ) : _x( 'Close Chat', 'command', 'nelio-ab-testing' ); return ( { 'edit' === type ? ( ) : ( ) } ); };