import { VENDEDOR } from "@/lib/vendedor";

type Linha = { rotulo: string; valor: string; href?: string };

// Mostra apenas os dados do vendedor que já foram preenchidos em src/lib/vendedor.ts.
export function Identificacao() {
  const soDigitos = (s: string) => s.replace(/\D/g, "");

  const linhas: Linha[] = [
    { rotulo: "Vendedor", valor: VENDEDOR.nome },
    ...(VENDEDOR.documento ? [{ rotulo: "CPF/CNPJ", valor: VENDEDOR.documento }] : []),
    ...(VENDEDOR.endereco ? [{ rotulo: "Endereço", valor: VENDEDOR.endereco }] : []),
    { rotulo: "E-mail", valor: VENDEDOR.email, href: `mailto:${VENDEDOR.email}` },
    ...(VENDEDOR.whatsapp
      ? [{ rotulo: "WhatsApp", valor: VENDEDOR.whatsapp, href: `https://wa.me/55${soDigitos(VENDEDOR.whatsapp)}` }]
      : []),
    ...(VENDEDOR.instagram
      ? [
          {
            rotulo: "Instagram",
            valor: VENDEDOR.instagram,
            href: `https://www.instagram.com/${VENDEDOR.instagram.replace(/^@/, "")}/`,
          },
        ]
      : []),
  ];

  return (
    <dl className="divide-y divide-zinc-100 text-sm">
      {linhas.map((l) => (
        <div key={l.rotulo} className="flex justify-between gap-4 py-2">
          <dt className="text-zinc-500">{l.rotulo}</dt>
          <dd className="text-right text-zinc-900">
            {l.href ? (
              <a
                href={l.href}
                {...(l.href.startsWith("http") ? { target: "_blank", rel: "noopener noreferrer" } : {})}
                className="underline"
              >
                {l.valor}
              </a>
            ) : (
              l.valor
            )}
          </dd>
        </div>
      ))}
    </dl>
  );
}
