import { useState } from "react"; import Image from "next/image"; import { useHabcoinInventoryQuery } from "@/hooks/marriage/use-habcoin-inventory"; import { DiscountWidget } from "./discount-widget"; import type { CheckDiscountResult } from "@/hooks/marriage/use-validate-discount"; import { buyHabibCoinPackages, isInFlutterWebView, } from "@/lib/webview-actions"; import { useI18n } from "@/translations/provider"; import InformationSheet from "./information-sheet"; import { LoadingThreeDot } from "./loading-three-dot"; type SubscriptionRequiredSheetProps = { onClose: () => void; onPayment: (discountCode?: string) => void; isPaymentPending?: boolean; /** Payment error to display above the buttons (e.g. "Not enough coins"). */ errorMessage?: string | null; /** Show the "Buy Habib Coins" button (Flutter opens its packages page). */ showBuyCoins?: boolean; price?: number; planId?: number | string; }; export function SubscriptionRequiredSheet({ onClose, onPayment, isPaymentPending = false, errorMessage = null, showBuyCoins = false, price = 50, planId, }: SubscriptionRequiredSheetProps) { const { dictionary: t } = useI18n(); const [appliedDiscount, setAppliedDiscount] = useState(null); const { data: inventory, isLoading: isInventoryLoading } = useHabcoinInventoryQuery(); const finalPrice = appliedDiscount?.valid ? appliedDiscount.discountedPrice : price; const balance = inventory?.coin_balance ?? 0; const hasEnoughCoins = !showBuyCoins && (inventory === undefined ? true : balance >= finalPrice); if (isInventoryLoading) { return ; } return ( {t["You do not have enough Habib Coins"] || "You do not have enough Habib Coins"} ) : ( t["Subscription required"] || "Subscription required" ) } description={ !hasEnoughCoins ? (

{t[ "Please add more Habib Coins to your balance (or use discount code), so that you can use them to access this content" ] || "Please add more Habib Coins to your balance (or use discount code), so that you can use them to access this content"}

) : (

{t[ "To view profiles, you need a subscription. Each subscription includes up to {count} matches." ]?.replace("{count}", "3") || ( <> To view profiles, you need a subscription. Each subscription includes up to{" "} 3 {" "} matches. )}

{t[ "To view profiles, a subscription is required. This helps cover our support and matching services and applies only to male users" ] || "To view profiles, a subscription is required. This helps cover our support and matching services and applies only to male users"}

) } onClose={onClose} buttons={({ close }) => (
{planId ? ( setAppliedDiscount(res)} onDiscountCleared={() => setAppliedDiscount(null)} /> ) : null} {errorMessage && (
{errorMessage}
)}
{!hasEnoughCoins ? ( ) : ( )}
)} /> ); } export default SubscriptionRequiredSheet;