// Auteur : Simon-Pierre Boucher — contact@spboucher.ai "use client"; import { useState } from "react"; export type ProfileInitial = { name: string; bio: string; city: string; phone: string; website: string; job_title: string; company: string; birth_date: string; socials: Record; isPublic: boolean; kaId: string; }; const SOCIALS: { key: string; label: string; placeholder: string }[] = [ { key: "instagram", label: "Instagram", placeholder: "@pseudo ou URL" }, { key: "facebook", label: "Facebook", placeholder: "profil ou URL" }, { key: "x", label: "X (Twitter)", placeholder: "@pseudo ou URL" }, { key: "linkedin", label: "LinkedIn", placeholder: "profil ou URL" }, { key: "tiktok", label: "TikTok", placeholder: "@pseudo ou URL" }, { key: "youtube", label: "YouTube", placeholder: "chaîne ou URL" }, ]; export default function ProfileForm({ initial }: { initial: ProfileInitial }) { const [form, setForm] = useState(initial); const [saving, setSaving] = useState(false); const [saved, setSaved] = useState(false); const [error, setError] = useState(null); const [isPublic, setIsPublic] = useState(initial.isPublic); const [copied, setCopied] = useState(false); const publicUrl = `https://www.groupe-ka.com/u/${initial.kaId}`; async function save() { setSaving(true); setError(null); const res = await fetch("/api/profile", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(form), }); const data = await res.json().catch(() => ({})); setSaving(false); if (!res.ok) { setError(data.error ?? "Enregistrement impossible — réessayez."); return; } setSaved(true); setTimeout(() => setSaved(false), 2000); } async function togglePublic(enabled: boolean) { await fetch("/api/profile/public", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ enabled }), }); setIsPublic(enabled); } const field = (key: keyof ProfileInitial, max: number) => (e: React.ChangeEvent) => setForm({ ...form, [key]: e.target.value.slice(0, max) }); return (