"use client"; import { useEffect, useRef, useState } from "react"; import { ArrowRight, CircleDollarSign, X } from "lucide-react"; import type { PaymentGuidance } from "@/data/schemas/chat"; import { recordChatActionEventById } from "@/lib/chat/chat_action_events"; import { useActiveCharacter } from "@/providers/character-provider"; import { useAppNavigator } from "@/router/use-app-navigator"; import { useUserSelector } from "@/stores/user/user-context"; import styles from "./chat-area.module.css"; export interface PaymentGuidanceCardProps { guidance: PaymentGuidance; } export function PaymentGuidanceCard({ guidance }: PaymentGuidanceCardProps) { const character = useActiveCharacter(); const navigator = useAppNavigator(); const isVip = useUserSelector((state) => state.context.isVip); const [dismissed, setDismissed] = useState(false); const viewedIdRef = useRef(null); const belongsToCurrentCharacter = guidance.characterId === character.id; const hasPurchaseAction = guidance.mode === "guide" && guidance.target === "subscription" && guidance.ctaLabel !== null && guidance.purchaseOptions.length > 0; useEffect(() => { if (!belongsToCurrentCharacter) return; if (viewedIdRef.current === guidance.guidanceId) return; viewedIdRef.current = guidance.guidanceId; void recordChatActionEventById( guidance.guidanceId, character.id, "viewed", ).catch(() => undefined); }, [belongsToCurrentCharacter, character.id, guidance.guidanceId]); if (!belongsToCurrentCharacter || dismissed) return null; const subscriptionType = isVip || !guidance.purchaseOptions.includes("vip") ? "topup" : "vip"; return ( ); }