"use client"; import React, { useState } from "react"; import { motion, AnimatePresence } from "motion/react"; import { useSettingsStore } from "../lib/store/settingsStore"; import { Dog, Cat, ChevronLeft, ChevronRight, ShieldCheck, Activity, Bone, Sparkles, Pill, Sparkle } from "lucide-react"; import { toPersian, cn } from "../lib/utils"; import { useRouter } from "next/navigation"; import { useUserStore } from "../lib/store/userStore"; import { useUIStore } from "../lib/store/uiStore"; import { usePetStore } from "../lib/store/usePetStore"; interface SmartAdvisorProps { onComplete?: (data: any) => void; } const MEDICAL_OPTIONS = [ { id: "joint_surgery", label: "جراحی مفاصل", condition: "جراحی مفاصل" }, { id: "recent_birth", label: "زایمان اخیر", condition: "زایمان اخیر" }, { id: "pregnancy", label: "بارداری", condition: "بارداری" }, { id: "digestion", label: "مشکلات گوارشی", condition: "مشکلات گوارشی" }, { id: "hair_loss", label: "ریزش موی شدید", condition: "ریزش موی شدید" }, { id: "appetite", label: "بی‌اشتهایی", condition: "بی‌اشتهایی" }, ]; export default function SmartAdvisor({ onComplete, rules = [] }: SmartAdvisorProps & { rules?: any[] }) { const router = useRouter(); const { isLoggedIn } = useUserStore(); const setLoginModalOpen = useUIStore(state => state.setLoginModalOpen); const { addPet, setActivePet } = usePetStore(); const texts = useSettingsStore(state => state.texts); const getText = useSettingsStore(state => state.getText); const medicalOptions = React.useMemo(() => { const jsonStr = texts['medical_options']; if (jsonStr) { try { return JSON.parse(jsonStr) as typeof MEDICAL_OPTIONS; } catch (e) { console.error("Failed to parse medical_options JSON:", e); } } return MEDICAL_OPTIONS; }, [texts]); const [step, setStep] = useState(1); // Step 1 Data const [name, setName] = useState(""); const [type, setType] = useState<"سگ" | "گربه">("سگ"); const [breed, setBreed] = useState(""); const [showError, setShowError] = useState(false); const [shake, setShake] = useState(false); // Step 2 Data const [age, setAge] = useState(3); const [weight, setWeight] = useState(10); const [activityLevel, setActivityLevel] = useState<"کم" | "متوسط" | "زیاد">("متوسط"); // Step 3 Data const [medicalConditions, setMedicalConditions] = useState([]); const handleNext = () => { if (step === 1) { if (!name.trim() || !breed.trim()) { setShowError(true); setShake(true); setTimeout(() => setShake(false), 500); return; } } setStep(s => s + 1); }; const handleBack = () => setStep(s => s - 1); const handleSubmit = () => { const data = { name, type, breed, age, weight, activityLevel, medicalConditions }; if (onComplete) { onComplete(data); } else { if (!isLoggedIn) { setLoginModalOpen(true, data); } else { const newPet: any = { ...data, id: Date.now().toString(), reminders: [], logs: [], consumptions: [] }; addPet(newPet); setActivePet(newPet.id); router.push('/profile'); } } }; return (
{getText('advisor_badge', "تکنولوژی پایش هوشمند")}

{getText('advisor_title', "دستیار سلامت کانینا")}

{getText('advisor_subtitle', "فقط چند قدم تا صدور شناسنامه هوشمند و دریافت پیشنهادات تخصصی")}

{/* Progress Indicator */}
{step === 1 && (

{getText('advisor_step1_title', "گام اول: هویت بصری")}

{getText('advisor_step1_desc', "همدم شما رو با چه اسمی صدا می‌زنید؟")}

{ setName(e.target.value); if (e.target.value.trim() && breed.trim()) setShowError(false); }} placeholder={getText('advisor_pet_name_placeholder', "لوسی، تدی...")} className={cn( "w-full bg-white border rounded-2xl py-4 px-6 focus:ring-2 outline-none font-black text-lg font-vazir placeholder-medical-gray-500 text-medical-gray-900 transition-all", showError && !name.trim() ? "border-red-500 focus:ring-red-500/30" : "border-medical-gray-300 focus:ring-canina-blue/30 focus-visible:ring-4 focus-visible:ring-canina-blue/40" )} />
{ setBreed(e.target.value); if (name.trim() && e.target.value.trim()) setShowError(false); }} placeholder={getText('advisor_pet_breed_placeholder', "ژرمن، پرشین...")} className={cn( "w-full bg-white border rounded-2xl py-4 px-6 focus:ring-2 outline-none font-bold font-vazir placeholder-medical-gray-500 text-medical-gray-900 transition-all", showError && !breed.trim() ? "border-red-500 focus:ring-red-500/30" : "border-medical-gray-300 focus:ring-canina-blue/30 focus-visible:ring-4 focus-visible:ring-canina-blue/40" )} />
{getText('advisor_submit_btn', "ثبت هویت و ادامه")} {showError && (!name.trim() || !breed.trim()) && (

{getText('advisor_validation_warning', "⚠️ لطفاً ابتدا نام و نژاد پت را در بالا وارد کنید.")}

)}
)} {step === 2 && (

{getText('advisor_step2_title', "گام دوم: پایش فیزیکی")}

{getText('advisor_step2_desc', "اطلاعات فیزیکی دقیق به دوزبندی صحیح مکمل‌ها کمک می‌کند")}

{toPersian(age.toString())} سال
{toPersian(weight.toString())} kg
{["کم", "متوسط", "زیاد"].map(level => ( ))}
)} {step === 3 && (

{getText('advisor_step3_title', "گام آخر: سوابق و حساسیت‌ها")}

{getText('advisor_step3_desc', "در صورت وجود هر یک از موارد زیر، آن را تیک بزنید")}

{medicalOptions.map((opt) => ( ))}
)}
); }