"use client"; import { useState, useEffect } from "react"; import { motion, AnimatePresence } from "framer-motion"; import { User, Shield, CreditCard, Bell, Save, Eye, EyeOff, Loader2, CheckCircle, } from "lucide-react"; import { useCurrentUser, useUpdateProfile, useChangePassword, useCreditBalance, useCreditHistory, useSubscription, } from "@/hooks/use-api"; import { useToast } from "@/components/ui/toast"; const tabs = [ { id: "profile", label: "Profil", icon: User }, { id: "security", label: "Güvenlik", icon: Shield }, { id: "billing", label: "Abonelik", icon: CreditCard }, { id: "notifications", label: "Bildirimler", icon: Bell }, ] as const; type TabId = (typeof tabs)[number]["id"]; export default function SettingsPage() { const [activeTab, setActiveTab] = useState("profile"); return (
{/* Header */}

Ayarlar

Hesap ayarlarınızı ve tercihlerinizi yönetin

{/* Tab Navigation */}
{tabs.map((tab) => { const Icon = tab.icon; const isActive = activeTab === tab.id; return ( ); })}
{/* Tab Content */} {activeTab === "profile" && } {activeTab === "security" && } {activeTab === "billing" && } {activeTab === "notifications" && }
); } /* ─── PROFILE TAB ─── */ function ProfileTab() { const { data: userData, isLoading } = useCurrentUser(); const updateProfile = useUpdateProfile(); const toast = useToast(); const user = userData?.data ?? userData; const [firstName, setFirstName] = useState(""); const [lastName, setLastName] = useState(""); useEffect(() => { if (user) { setFirstName(user.firstName ?? ""); setLastName(user.lastName ?? ""); } }, [user]); const handleSave = async () => { try { await updateProfile.mutateAsync({ firstName, lastName }); toast.success("Profil başarıyla güncellendi"); } catch { toast.error("Profil güncellenirken bir hata oluştu"); } }; if (isLoading) { return (
); } return (

Profil Bilgileri

setFirstName(e.target.value)} className="w-full px-4 py-2.5 rounded-xl bg-[var(--color-bg-deep)] border border-[var(--color-border-faint)] text-[var(--color-text-primary)] text-sm focus:outline-none focus:border-violet-500/50 focus:ring-1 focus:ring-violet-500/25 transition-all" placeholder="Adınız" />
setLastName(e.target.value)} className="w-full px-4 py-2.5 rounded-xl bg-[var(--color-bg-deep)] border border-[var(--color-border-faint)] text-[var(--color-text-primary)] text-sm focus:outline-none focus:border-violet-500/50 focus:ring-1 focus:ring-violet-500/25 transition-all" placeholder="Soyadınız" />

E-posta adresi değiştirilemez

); } /* ─── SECURITY TAB ─── */ function SecurityTab() { const changePassword = useChangePassword(); const toast = useToast(); const [current, setCurrent] = useState(""); const [newPw, setNewPw] = useState(""); const [confirm, setConfirm] = useState(""); const [showCurrent, setShowCurrent] = useState(false); const [showNew, setShowNew] = useState(false); const handleChange = async () => { if (newPw !== confirm) { toast.warning("Yeni şifre ve onay eşleşmiyor"); return; } if (newPw.length < 8) { toast.warning("Yeni şifre en az 8 karakter olmalı"); return; } try { await changePassword.mutateAsync({ currentPassword: current, newPassword: newPw, }); toast.success("Şifre başarıyla güncellendi"); setCurrent(""); setNewPw(""); setConfirm(""); } catch { toast.error("Mevcut şifre hatalı veya bir sorun oluştu"); } }; return (

Şifre Değiştir

{/* Current */}
setCurrent(e.target.value)} className="w-full px-4 py-2.5 pr-10 rounded-xl bg-[var(--color-bg-deep)] border border-[var(--color-border-faint)] text-[var(--color-text-primary)] text-sm focus:outline-none focus:border-violet-500/50 focus:ring-1 focus:ring-violet-500/25 transition-all" />
{/* New */}
setNewPw(e.target.value)} className="w-full px-4 py-2.5 pr-10 rounded-xl bg-[var(--color-bg-deep)] border border-[var(--color-border-faint)] text-[var(--color-text-primary)] text-sm focus:outline-none focus:border-violet-500/50 focus:ring-1 focus:ring-violet-500/25 transition-all" />
{/* Confirm */}
setConfirm(e.target.value)} className="w-full px-4 py-2.5 rounded-xl bg-[var(--color-bg-deep)] border border-[var(--color-border-faint)] text-[var(--color-text-primary)] text-sm focus:outline-none focus:border-violet-500/50 focus:ring-1 focus:ring-violet-500/25 transition-all" /> {newPw && confirm && newPw !== confirm && (

Şifreler eşleşmiyor

)}
); } /* ─── BILLING TAB ─── */ function BillingTab() { const { data: creditData } = useCreditBalance(); const { data: subData } = useSubscription(); const { data: historyData } = useCreditHistory(); // eslint-disable-next-line @typescript-eslint/no-explicit-any const credits = (creditData as any)?.data ?? creditData; // eslint-disable-next-line @typescript-eslint/no-explicit-any const subscription = (subData as any)?.data ?? subData; // eslint-disable-next-line @typescript-eslint/no-explicit-any const transactions = (historyData as any)?.data?.transactions ?? (historyData as any)?.transactions ?? []; return (
{/* Abonelik Kartı */}

Abonelik Durumu

Plan

{subscription?.plan ?? "Free"}

Kalan Kredi

{credits?.remaining ?? credits?.balance ?? 0}

Aylık Limit

{subscription?.monthlyCredits ?? credits?.total ?? 3}

{/* Kredi Geçmişi */}

Kredi İşlem Geçmişi

{transactions.length === 0 ? (

Henüz işlem geçmişi bulunmuyor

) : (
{transactions.slice(0, 10).map((tx: { id: string; amount: number; type: string; description: string; createdAt: string }) => (

{tx.description || tx.type}

{new Date(tx.createdAt).toLocaleDateString("tr-TR")}

0 ? "text-emerald-400" : "text-red-400" }`} > {tx.amount > 0 ? `+${tx.amount}` : tx.amount}
))}
)}
); } /* ─── NOTIFICATIONS TAB ─── */ function NotificationsTab() { const toast = useToast(); const [prefs, setPrefs] = useState({ projectComplete: true, creditLow: true, weeklyReport: false, marketingEmails: false, }); const toggle = (key: keyof typeof prefs) => { setPrefs((p) => ({ ...p, [key]: !p[key] })); }; const handleSave = () => { toast.success("Bildirim tercihleri kaydedildi"); }; const notifItems = [ { key: "projectComplete" as const, label: "Proje Tamamlandı", desc: "Video render işlemi tamamlandığında bildirim al", }, { key: "creditLow" as const, label: "Düşük Kredi Uyarısı", desc: "Kredileriniz %20'nin altına düştüğünde uyarı al", }, { key: "weeklyReport" as const, label: "Haftalık Rapor", desc: "Haftalık kullanım raporunu e-posta ile al", }, { key: "marketingEmails" as const, label: "Pazarlama E-postaları", desc: "Yeni özellikler ve kampanyalar hakkında bilgi al", }, ]; return (

Bildirim Tercihleri

{notifItems.map((item) => (

{item.label}

{item.desc}

))}
); }