import { useEffect } from 'react'
import { appKeys, appStorage } from 'src/state/storage'
import { useToastController } from 'tamagui'

// Non-blocking surfacing of the Acceptable Use note. Fires once on the first
// composer mount per install and persists `app.acceptableUseAcceptedAt` so it
// never re-fires. Replaces the earlier root-level blocking AlertDialog —
// halflig.ht/terms + halflig.ht/moderation are the source of truth, and this
// toast just signals that the user is now operating under those policies.
export function useAcceptableUseToastOnce() {
  const toast = useToastController()
  useEffect(() => {
    if (appStorage.getNumber(appKeys.acceptableUseAcceptedAt)) return
    toast.show('Posting through Halflight', {
      message:
        "By posting, you agree to your instance's terms and Halflight's Acceptable Use Policy at halflig.ht/terms.",
      duration: 6000,
    })
    appStorage.set(appKeys.acceptableUseAcceptedAt, Date.now())
  }, [toast])
}
