"use client"; import { useEffect, useRef, useState } from "react"; import { Bot, KeyRound, Save, User } from "lucide-react"; import { updatePassword, updateProfile } from "./actions"; import { createClient } from "@/lib/supabase/client"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; type AiProvider = "groq" | "ollama" | "openai"; function getInitialAiProvider(): AiProvider { if (typeof window === "undefined") { return "groq"; } const savedProvider = localStorage.getItem("mindspace_ai_provider"); return savedProvider === "ollama" || savedProvider === "openai" ? savedProvider : "groq"; } function getInitialApiKey() { if (typeof window === "undefined") { return ""; } return localStorage.getItem("mindspace_api_key") ?? ""; } export default function SettingsPage() { const [aiProvider, setAiProvider] = useState(getInitialAiProvider); const [apiKey, setApiKey] = useState(getInitialApiKey); const [saveStatus, setSaveStatus] = useState(""); const [firstName, setFirstName] = useState(""); const [lastName, setLastName] = useState(""); const [avatarUrl, setAvatarUrl] = useState(""); const [profileSaveStatus, setProfileSaveStatus] = useState(""); const [passwordSaveStatus, setPasswordSaveStatus] = useState(""); const [supabase] = useState(() => createClient()); const formRef = useRef(null); useEffect(() => { let isActive = true; const fetchProfile = async () => { const { data: { user }, } = await supabase.auth.getUser(); if (!user || !isActive) { return; } const { data } = await supabase .from("profiles") .select("*") .eq("id", user.id) .single(); if (!data || !isActive) { return; } setFirstName(data.first_name || ""); setLastName(data.last_name || ""); setAvatarUrl(data.avatar_url || ""); }; void fetchProfile(); return () => { isActive = false; }; }, [supabase]); const handleSaveAI = () => { localStorage.setItem("mindspace_ai_provider", aiProvider); localStorage.setItem("mindspace_api_key", apiKey); setSaveStatus("Ayarlar başarıyla kaydedildi!"); window.setTimeout(() => setSaveStatus(""), 3000); }; const handleProfileAction = async (formData: FormData) => { const response = await updateProfile(formData); if (response?.error) { setProfileSaveStatus(`Hata: ${response.error}`); } else { setProfileSaveStatus("Profil başarıyla güncellendi!"); const avatar = formData.get("avatar"); if (avatar instanceof File && avatar.size > 0) { window.location.reload(); } } window.setTimeout(() => setProfileSaveStatus(""), 3000); }; const handlePasswordAction = async (formData: FormData) => { const response = await updatePassword(formData); if (response?.error) { setPasswordSaveStatus(`Hata: ${response.error}`); } else { setPasswordSaveStatus("Şifre başarıyla güncellendi!"); formRef.current?.reset(); } window.setTimeout(() => setPasswordSaveStatus(""), 3000); }; return (

Ayarlar

Kullanıcı profili ve yapay zeka asistanı yapılandırmanızı yönetin.

Kullanıcı Profili

{avatarUrl ? ( <> {/* Avatar URL dış kaynaklı olduğu için bu önizlemede native img kullanıyoruz. */} {/* eslint-disable-next-line @next/next/no-img-element */} Avatar ) : (
)}
setFirstName(event.target.value)} />
setLastName(event.target.value)} />
{profileSaveStatus && ( {profileSaveStatus} )}

Şifre Değiştir

{passwordSaveStatus && ( {passwordSaveStatus} )}

Terapist (AI) Ayarları

Gizliliğiniz için yerel Ollama önerilir. Sunucunuzda çalışmayan durumlarda OpenAI veya Groq gibi bulut çözümlerine geçebilirsiniz.

{aiProvider !== "ollama" && (
setApiKey(event.target.value)} placeholder="sk-..." />

Anahtarınız sadece tarayıcınızın kendi local hafızasında saklanır; herhangi bir sunucuya kaydedilmez.

)}
{saveStatus && ( {saveStatus} )}
); }