import { useShareService } from '~/modules/integration/services/share'

export function useShareStatus() {
    const enabled = useState<boolean | null>('share-enabled', () => null)
    const { getStatus } = useShareService()

    async function refresh() {
        try {
            const status = await getStatus()
            enabled.value = status.enabled
        } catch {
            enabled.value = false
        }
    }

    async function ensureLoaded() {
        if (enabled.value === null) {
            await refresh()
        }
    }

    return { enabled, refresh, ensureLoaded }
}
