import { useCallback, useContext } from 'preact/hooks' import { SeamlyApiContext } from 'ui/components/core/seamly-api-context' export const useSeamlyApiContext = () => { const api = useContext(SeamlyApiContext) if (!api) { throw new Error( 'useSeamlyApiContext has to be used within ', ) } return api } export const useSeamlyObjectStore = () => { const api = useSeamlyApiContext() return api.store } export const useSeamlyConversationUrl = () => { const { get } = useSeamlyObjectStore() if (get) { return get('conversationUrl') } return null } export const useSeamlyHasConversation = () => { const api = useSeamlyApiContext() const hasConversation = useCallback(() => { return api.hasConversation() }, [api]) return hasConversation }