"use client"; import { useEffect, useRef, useState } from "react"; import Link from "next/link"; import { Pencil, Ruler, Weight, GraduationCap, Briefcase, Heart, Sparkles, Search, Plus, X, User as UserIcon, } from "lucide-react"; import { Card } from "@/components/ui/Card"; import { Tag } from "@/components/ui/Badge"; import { Avatar } from "@/components/ui/Avatar"; import { FullScreenLoader } from "@/components/ui/FullScreenLoader"; import { ErrorBanner } from "@/components/ui/ErrorBanner"; import { getProfileMe, uploadPhoto, deletePhoto, photoUrl, FullProfile, Photo } from "@/lib/api"; import { formatApiError } from "@/lib/hooks"; import { calcAge } from "@/lib/utils"; function selectionTitles(profile: FullProfile, key: string): string[] { return profile.selections.find((s) => s.category_key === key)?.titles ?? []; } function SectionCard({ icon, title, editHref, children, }: { icon: React.ReactNode; title: string; editHref: string; children: React.ReactNode; }) { return ( {icon} {title} {children} ); } const MAX_PHOTOS = 6; function PhotosSection({ photos, onChange }: { photos: Photo[]; onChange: (photos: Photo[]) => void }) { const fileInputRef = useRef(null); const [uploading, setUploading] = useState(false); const [error, setError] = useState(null); async function handleFile(e: React.ChangeEvent) { const file = e.target.files?.[0]; e.target.value = ""; if (!file) return; setUploading(true); setError(null); try { const photo = await uploadPhoto(file); onChange([...photos, photo]); } catch (err) { setError(formatApiError(err)); } finally { setUploading(false); } } async function handleDelete(id: number) { setError(null); try { await deletePhoto(id); onChange(photos.filter((p) => p.id !== id)); } catch (err) { setError(formatApiError(err)); } } return ( عکسهای پروفایل {photos.length}/{MAX_PHOTOS} {photos.map((p) => ( {/* eslint-disable-next-line @next/next/no-img-element */} handleDelete(p.id)} className="absolute top-1 left-1 w-6 h-6 rounded-full bg-black/50 flex items-center justify-center text-white" aria-label="حذف عکس" > ))} {photos.length < MAX_PHOTOS && ( fileInputRef.current?.click()} disabled={uploading} className="aspect-square rounded-(--radius-md) border-2 border-dashed border-(--color-border-default) flex items-center justify-center text-(--color-content-tertiary) disabled:opacity-50" > )} ); } export default function ProfilePage() { const [profile, setProfile] = useState(null); const [error, setError] = useState(null); useEffect(() => { getProfileMe() .then(setProfile) .catch((err) => setError(formatApiError(err))); }, []); if (error) { return ( ); } if (!profile) return ; const { user } = profile; const age = calcAge(user.birth_date); const education = selectionTitles(profile, "education_level")[0]; const fieldOfStudy = selectionTitles(profile, "field_of_study")[0]; const occupations = selectionTitles(profile, "occupation"); const importance = selectionTitles(profile, "important_in_relationship"); const interests = selectionTitles(profile, "interest"); const lookingFor = selectionTitles(profile, "looking_for")[0]; const mainPhoto = profile.photos[0]; return ( {mainPhoto ? ( {/* eslint-disable-next-line @next/next/no-img-element */} ) : ( )} {user.first_name || "بدون نام"} {age ? `، ${age}` : ""} {user.phone} {profile.photos.length === 0 && ( بدون عکس، توی صفحهی دوستیابی کمتر دیده میشی. همین الان یکی اضافه کن. )} setProfile((p) => (p ? { ...p, photos } : p))} /> } title="قد و وزن" editHref="/onboarding/body-info"> {user.height_cm ?? "—"} سانتیمتر {user.weight_kg ?? "—"} کیلوگرم } title="تحصیلات" editHref="/onboarding/education"> {education ?? "—"} {fieldOfStudy ? `· ${fieldOfStudy}` : ""} } title="فعالیتها" editHref="/onboarding/occupations"> {occupations.length ? ( occupations.map((t) => ) ) : ( — )} } title="توی رابطه برام مهمه" editHref="/onboarding/relationship-importance" > {importance.length ? ( importance.map((t) => ) ) : ( — )} } title="علاقهمندیها" editHref="/onboarding/interests"> {interests.length ? ( interests.map((t) => ) ) : ( — )} } title="دنبال چی میگردم" editHref="/onboarding/looking-for"> {lookingFor ?? "—"} {profile.profile_answers.length > 0 && ( } title="یکم از خودم" editHref="/onboarding/profile-questions"> {profile.profile_answers.map((a) => ( {a.question?.text} {a.answer} ))} )} ); }
{user.phone}
{education ?? "—"} {fieldOfStudy ? `· ${fieldOfStudy}` : ""}
{lookingFor ?? "—"}
{a.question?.text}
{a.answer}