"use client";
import { useEffect, useState } from "react";
import DoctorAvatar from "@/app/component/DoctorAvatar";
import QrImg from "./QrImg";
import SiteLogo from "./SiteLogo";
import { getStateInfoClient } from "@/lib/getStateInfoClient";
import { posterSpecialtyLine, splitSpecialties } from "@/lib/specialtyDisplay";
import { doctorTitle } from "@/helper";
import StarDI from "@/components/icons/StarDI";
import { FEATURES } from "@/config/features";
const ACCENT = "#16528C";
const ACCENT_LIGHT = "#2E77C4";
const ORANGE = "#F17732";
function PosterLight({ data, onQrReady }) {
const [city, setCity] = useState(null);
useEffect(() => {
const { matchedCity } = getStateInfoClient();
setCity(matchedCity || null);
}, []);
// قرینهٔ پوستر تیره — همان دلیل: برش عددیِ ثابت با نامهای بلند از کادر بیرون میزد.
const { primary, rest } = splitSpecialties(data?.specialties);
const subSpecialties = posterSpecialtyLine(rest, 78);
const services = (data?.expertise ?? []).filter((s) => s?.name);
const shownServices = services.slice(0, 8);
const moreServices = services.length - shownServices.length;
const rawAddress = data?.address?.[0]?.address;
const address =
rawAddress && rawAddress.length > 120
? `${rawAddress.slice(0, 120).trimEnd()}…`
: rawAddress;
const phones = (data?.address ?? [])
.map((a) => a?.phone)
.filter(Boolean)
.slice(0, 2);
const badges = [
Number(data?.experience) > 0 && { label: `${data.experience} سال تجربه` },
FEATURES.posterRatings && (data?.point ?? 0) > 0 && { icon:
{subSpecialties.text} {subSpecialties.hidden > 0 && ` و ${subSpecialties.hidden} تخصص دیگر`}
)} {badges.length > 0 && (کد نظام پزشکی:{" "} {data.medical_system_code}
)} {/* services */} {shownServices.length > 0 && (خدمات
آدرس: {address}
)} {phones.length > 0 && (تلفن: {phones.map((p, i) => ( {p} {i < phones.length - 1 ? " | " : ""} ))}
)}