"use client"

import { useEffect, useState } from "react"

import { PaymentMethodEnum } from "@/constants/booking"

export function useAvailablePaymentOptions(
  otherPaymentOptions: PaymentMethodEnum[]
) {
  const [availablePaymentOptions, setAvailablePaymentOptions] = useState<
    PaymentMethodEnum[]
  >(
    otherPaymentOptions.filter(
      (option) => option !== PaymentMethodEnum.applePay
    )
  )

  useEffect(() => {
    if (window.ApplePaySession) {
      setAvailablePaymentOptions(otherPaymentOptions)
    }
  }, [otherPaymentOptions, setAvailablePaymentOptions])

  return availablePaymentOptions
}
