/* Contact 360 — single contact profile view.
   Surfaces the rich data from /contacts API responses: cover photo,
   verified/premium/openToWork flags, full work history, education, skills
   with endorsements, languages, certifications, similar profiles. */

const { useState: useStateCD } = React;

function PageContactDetail({ contactId, onNavigate }) {
  const contact = window.getContact(contactId) || window.CONTACTS[0];
  if (!contact) return null;
  const company = window.getCompany(contact.companyId);
  const raw = contact.raw;
  const conv = window.CONVERSATIONS.find(c => c.contactId === contact.id);

  return (
    <>
      <PageHeader
        title={<span style={{ display: "inline-flex", alignItems: "center", gap: 10, flexWrap: "wrap", minWidth: 0 }}>
          <span style={{ overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap", minWidth: 0 }}>{contact.firstName} {contact.lastName}</span>
          {contact.verified && (
            <span title="Verified profile" style={{
              width: 18, height: 18, borderRadius: "50%",
              background: "var(--blue-soft, var(--inset))",
              color: "var(--blue, var(--accent))",
              display: "inline-flex", alignItems: "center", justifyContent: "center",
              flexShrink: 0,
            }}>
              <Icon name="check" size={12} />
            </span>
          )}
          {contact.premium && <Badge tone="warm" size="sm">Premium</Badge>}
          {contact.openToWork && <Badge tone="green" size="sm" dot>Open to work</Badge>}
          {contact.hiring && <Badge tone="violet" size="sm" dot>Hiring</Badge>}
          {contact.influencer && <Badge tone="blue" size="sm">Influencer</Badge>}
        </span>}
        subtitle={<span style={{ color: "var(--ink-2)" }}>{contact.headline}</span>}
        actions={<>
          {contact.linkedinUrl && (
            <Button size="md" icon="linkedin" title="Open LinkedIn profile"
              style={{ width: 36, padding: 0, justifyContent: "center", borderRadius: 999, color: "var(--blue-ink, var(--ink))" }}
              onClick={() => window.open(contact.linkedinUrl, "_blank")} />
          )}
          {contact.primaryEmail && (
            <Button size="md" icon="mail" title={contact.primaryEmail.email}
              style={{ width: 36, padding: 0, justifyContent: "center", borderRadius: 999 }}
              onClick={() => window.open(`mailto:${contact.primaryEmail.email}`, "_blank")} />
          )}
          {conv ? (
            <Button kind="primary" size="md" icon="send" title="Open conversation"
              style={{ borderRadius: 999, padding: "6px 14px" }}
              onClick={() => onNavigate("conversations", { conversationId: conv.id })}>
              Conversation
            </Button>
          ) : (
            <Button kind="primary" size="md" icon="send" title="Start outreach"
              style={{ borderRadius: 999, padding: "6px 14px" }}>
              Outreach
            </Button>
          )}
        </>}
      />

      {/* Cover banner — only if API supplied one */}
      {contact.coverPictureUrl && (
        <div style={{
          height: 180,
          background: `linear-gradient(180deg, transparent 60%, var(--bg) 100%), url(${contact.coverPictureUrl}) center/cover no-repeat`,
          borderBottom: "1px solid var(--line)",
        }} />
      )}

      <div className="page-pad page-pad-y">
        {/* Top identity row — avatar on banner, name + meta below the cover */}
        <div style={{
          display: "flex", alignItems: "flex-start", gap: 18,
          marginTop: contact.coverPictureUrl ? -56 : 0,
          marginBottom: 24, position: "relative",
        }}>
          <div style={{
            border: contact.coverPictureUrl ? "4px solid var(--surface)" : "none",
            borderRadius: 999,
            background: "var(--surface)",
            flexShrink: 0,
          }}>
            <Avatar name={`${contact.firstName} ${contact.lastName}`} src={contact.profilePictureUrl} size={104} />
          </div>
          <div style={{ flex: 1, minWidth: 0, paddingTop: contact.coverPictureUrl ? 60 : 0 }}>
            <div style={{ fontSize: 13, color: "var(--ink-2)", display: "flex", alignItems: "center", gap: 10, flexWrap: "wrap" }}>
              {company && (
                <span style={{ display: "inline-flex", alignItems: "center", gap: 6 }}>
                  <CompanyLogo company={company} size={20} />
                  <button onClick={() => onNavigate("account-detail", { companyId: company.id })}
                    style={{ color: "var(--ink)", fontWeight: 600 }}>
                    {company.name}
                  </button>
                </span>
              )}
              {contact.position && <span>· {contact.position}</span>}
            </div>
            <MetaLine items={[
              contact.location && <><Icon name="map-pin" size={11} />{contact.location}</>,
              contact.connectionsCount && <><Icon name="users" size={11} /><span className="mono num">{contact.connectionsCount.toLocaleString()}</span> connections</>,
              contact.followerCount && <><Icon name="trending-up" size={11} /><span className="mono num">{contact.followerCount.toLocaleString()}</span> followers</>,
              contact.tenure && <><Icon name="clock" size={11} />{contact.tenure} in role</>,
            ]} />
          </div>
        </div>

        <div className="cd-grid">
          {/* ─── Left column: profile content ─── */}
          <div style={{ display: "flex", flexDirection: "column", gap: 16 }}>
            {contact.about && <AboutCard text={contact.about} />}
            {contact.experience?.length > 0 && <ExperienceCard items={contact.experience} />}
            {contact.education?.length > 0 && <EducationCard items={contact.education} />}
            {contact.skills?.length > 0 && <SkillsCard items={contact.skills} />}
            {contact.certifications?.length > 0 && <CertificationsCard items={contact.certifications} />}
            {contact.languages?.length > 0 && <LanguagesCard items={contact.languagesRich || []} fallback={contact.languages} />}
            {contact.volunteering?.length > 0 && <SimpleListCard title="Volunteering" items={contact.volunteering}
              render={(v) => ({
                primary: v.role || v.organization,
                secondary: [v.organization, v.cause].filter(Boolean).join(" · "),
                period: v.period,
              })} />}
            {contact.projects?.length > 0 && <SimpleListCard title="Projects" items={contact.projects}
              render={(p) => ({ primary: p.name || p.title, secondary: p.description, period: p.period })} />}
            {contact.publications?.length > 0 && <SimpleListCard title="Publications" items={contact.publications}
              render={(p) => ({ primary: p.title || p.name, secondary: p.publisher, period: p.date?.text })} />}
            {contact.organizations?.length > 0 && <SimpleListCard title="Organizations" items={contact.organizations}
              render={(o) => ({ primary: o.name, secondary: o.position, period: o.period })} />}
            {contact.honorsAndAwards?.length > 0 && <SimpleListCard title="Honors & awards" items={contact.honorsAndAwards}
              render={(h) => ({ primary: h.title || h.name, secondary: h.issuer || h.description, period: h.date?.text })} />}
            {contact.causes?.length > 0 && (
              <Card padding={18}>
                <SectionTitle>Causes & interests</SectionTitle>
                <div style={{ display: "flex", flexWrap: "wrap", gap: 6 }}>
                  {contact.causes.map((c, i) => <Badge key={i} tone="violet">{c}</Badge>)}
                </div>
              </Card>
            )}
          </div>

          {/* ─── Right column: relationship + contact info ─── */}
          <div style={{ display: "flex", flexDirection: "column", gap: 16 }}>
            <RelationshipCard contact={contact} />
            <ContactInfoCard contact={contact} />
            <ProfileMetaCard contact={contact} raw={raw} />
            {contact.moreProfiles?.length > 0 && (
              <SimilarProfilesCard items={contact.moreProfiles} onNavigate={onNavigate} />
            )}
          </div>
        </div>
      </div>

      <style>{`
        .cd-grid {
          display: grid;
          grid-template-columns: minmax(0, 1fr) 360px;
          gap: 20px;
          align-items: start;
        }
        @media (max-width: 1100px) {
          .cd-grid { grid-template-columns: minmax(0, 1fr); }
        }
        .cd-section-h { display: flex; align-items: center; justify-content: space-between;
          font-size: 11px; font-weight: 600; color: var(--ink-3);
          text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 12px; }
        .cd-list-row { display: flex; gap: 12px; }
        .cd-list-row + .cd-list-row { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
        .cd-logo { width: 36px; height: 36px; border-radius: 7px; flex-shrink: 0; overflow: hidden;
          background: var(--inset); display: flex; align-items: center; justify-content: center;
          color: var(--ink-3); }
        .cd-logo img { width: 100%; height: 100%; object-fit: cover; }
        .cd-period { font-size: 11px; color: var(--ink-3); }
        .cd-period.mono { font-family: var(--mono); }
        .cd-prim  { font-size: 13px; font-weight: 600; color: var(--ink); }
        .cd-sec   { font-size: 12.5px; color: var(--ink-2); margin-top: 2px; }
        .cd-meta  { font-size: 11px; color: var(--ink-3); margin-top: 4px; }
        .cd-chip  { display: inline-flex; align-items: center; gap: 5px;
          padding: 3px 8px; border-radius: 999px; background: var(--inset);
          font-size: 11.5px; color: var(--ink-2); }
        .cd-skill-row { display: flex; align-items: center; justify-content: space-between; gap: 10px;
          padding: 8px 0; border-bottom: 1px dashed var(--line); }
        .cd-skill-row:last-child { border-bottom: none; }
        .cd-skill-name { font-size: 12.5px; color: var(--ink); font-weight: 500; }
        .cd-skill-meta { font-size: 11px; color: var(--ink-3); }
        .cd-info-row { display: grid; grid-template-columns: 18px 1fr; gap: 10px; align-items: start;
          padding: 8px 0; font-size: 12.5px; color: var(--ink-2); }
        .cd-info-row + .cd-info-row { border-top: 1px solid var(--line); }
        .cd-info-row .ic { color: var(--ink-3); margin-top: 2px; }
        .cd-info-row .val { color: var(--ink); word-break: break-word; }
        .cd-info-row .lbl { font-size: 11px; color: var(--ink-3); margin-bottom: 2px; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
      `}</style>
    </>
  );
}

/* ───── Reusable cards (this page only) ───── */

function AboutCard({ text }) {
  const [open, setOpen] = useStateCD(false);
  const truncated = text.length > 360;
  const display = open || !truncated ? text : text.slice(0, 340).trim() + "…";
  return (
    <Card padding={18}>
      <SectionTitle>About</SectionTitle>
      <div style={{ fontSize: 13, color: "var(--ink-2)", lineHeight: 1.6, whiteSpace: "pre-wrap" }}>
        {display}
      </div>
      {truncated && (
        <button onClick={() => setOpen(v => !v)}
          style={{ marginTop: 8, fontSize: 12, color: "var(--accent)", fontWeight: 600 }}>
          {open ? "Show less" : "Show more"}
        </button>
      )}
    </Card>
  );
}

function ExperienceCard({ items }) {
  return (
    <Card padding={18}>
      <SectionTitle right={<span style={{ fontSize: 11.5, color: "var(--ink-3)" }}>{items.length} positions</span>}>
        Experience
      </SectionTitle>
      <div>
        {items.map((e, i) => (
          <div key={i} className="cd-list-row">
            <div className="cd-logo">
              {e.companyLogo
                ? <img src={e.companyLogo} alt="" />
                : <Icon name="briefcase" size={14} />}
            </div>
            <div style={{ minWidth: 0, flex: 1 }}>
              <div className="cd-prim">{e.position}</div>
              <div className="cd-sec">{e.company}</div>
              <div className="cd-period mono">{e.period}{e.duration ? ` · ${e.duration}` : ""}</div>
              {(e.location || e.workplaceType || e.employmentType) && (
                <div className="cd-meta">
                  {[e.location, e.workplaceType, e.employmentType].filter(Boolean).join(" · ")}
                </div>
              )}
              {e.skills?.length > 0 && (
                <div style={{ display: "flex", flexWrap: "wrap", gap: 4, marginTop: 8 }}>
                  {e.skills.slice(0, 6).map((s, j) => (
                    <span key={j} className="cd-chip">{s}</span>
                  ))}
                </div>
              )}
              {e.description && (
                <div style={{ fontSize: 12.5, color: "var(--ink-2)", marginTop: 6, lineHeight: 1.5, whiteSpace: "pre-wrap" }}>
                  {e.description}
                </div>
              )}
            </div>
          </div>
        ))}
      </div>
    </Card>
  );
}

function EducationCard({ items }) {
  return (
    <Card padding={18}>
      <SectionTitle right={<span style={{ fontSize: 11.5, color: "var(--ink-3)" }}>{items.length} schools</span>}>
        Education
      </SectionTitle>
      <div>
        {items.map((e, i) => (
          <div key={i} className="cd-list-row">
            <div className="cd-logo">
              {e.schoolLogo
                ? <img src={e.schoolLogo} alt="" />
                : <Icon name="book" size={14} />}
            </div>
            <div style={{ minWidth: 0, flex: 1 }}>
              <div className="cd-prim">{e.school}</div>
              <div className="cd-sec">{[e.degree, e.field].filter(Boolean).join(" · ")}</div>
              {e.period && <div className="cd-period mono">{e.period}</div>}
              {e.description && (
                <div style={{ fontSize: 12.5, color: "var(--ink-2)", marginTop: 6, lineHeight: 1.5 }}>{e.description}</div>
              )}
            </div>
          </div>
        ))}
      </div>
    </Card>
  );
}

function SkillsCard({ items }) {
  const [expanded, setExpanded] = useStateCD(false);
  const shown = expanded ? items : items.slice(0, 8);
  const more = items.length - shown.length;
  return (
    <Card padding={18}>
      <SectionTitle right={<span style={{ fontSize: 11.5, color: "var(--ink-3)" }}>{items.length} skills</span>}>
        Skills
      </SectionTitle>
      <div>
        {shown.map((s, i) => (
          <div key={i} className="cd-skill-row">
            <div style={{ minWidth: 0 }}>
              <div className="cd-skill-name">{s.name}</div>
              {s.positions?.length > 0 && (
                <div className="cd-skill-meta">{s.positions[0]}{s.positions.length > 1 ? ` · +${s.positions.length - 1} more` : ""}</div>
              )}
            </div>
            {s.endorsements && (
              <span className="cd-chip" style={{ flexShrink: 0 }}>
                <Icon name="user" size={11} />{String(s.endorsements).replace(/ endorsements?/i, "")}
              </span>
            )}
          </div>
        ))}
      </div>
      {more > 0 && (
        <button onClick={() => setExpanded(true)}
          style={{ marginTop: 10, fontSize: 12, color: "var(--accent)", fontWeight: 600 }}>
          Show {more} more
        </button>
      )}
    </Card>
  );
}

function CertificationsCard({ items }) {
  return (
    <Card padding={18}>
      <SectionTitle right={<span style={{ fontSize: 11.5, color: "var(--ink-3)" }}>{items.length}</span>}>
        Certifications & licenses
      </SectionTitle>
      <div>
        {items.map((c, i) => (
          <div key={i} className="cd-list-row">
            <div className="cd-logo"><Icon name="check-square" size={14} /></div>
            <div style={{ minWidth: 0, flex: 1 }}>
              <div className="cd-prim">{c.name || c.title}</div>
              <div className="cd-sec">{c.issuer || c.authority}</div>
              {(c.issueDate || c.expirationDate || c.period) && (
                <div className="cd-period mono">
                  {c.period
                    || [c.issueDate?.text || c.issueDate, c.expirationDate?.text || c.expirationDate]
                       .filter(Boolean).join(" — ")}
                </div>
              )}
            </div>
          </div>
        ))}
      </div>
    </Card>
  );
}

function LanguagesCard({ items, fallback }) {
  /* Pill rows per language with a proficiency strength dot scale. */
  const STRENGTH = {
    "native or bilingual proficiency": 5,
    "full professional proficiency": 4,
    "professional working proficiency": 3,
    "limited working proficiency": 2,
    "elementary proficiency": 1,
  };
  const list = items?.length ? items : (fallback || []).map(s => ({ name: s, proficiency: "" }));
  return (
    <Card padding={18}>
      <SectionTitle>Languages</SectionTitle>
      <div style={{ display: "flex", flexDirection: "column", gap: 8 }}>
        {list.map((l, i) => {
          const s = STRENGTH[(l.proficiency || "").toLowerCase()] || 0;
          return (
            <div key={i} style={{ display: "flex", alignItems: "center", gap: 12 }}>
              <div style={{ fontSize: 13, color: "var(--ink)", fontWeight: 500, flex: 1, minWidth: 0 }}>{l.name}</div>
              <div style={{ fontSize: 11.5, color: "var(--ink-3)" }}>{l.proficiency}</div>
              {s > 0 && (
                <div style={{ display: "inline-flex", gap: 3 }}>
                  {[1,2,3,4,5].map(d => (
                    <span key={d} style={{
                      width: 6, height: 6, borderRadius: 999,
                      background: d <= s ? "var(--accent)" : "var(--line)",
                    }} />
                  ))}
                </div>
              )}
            </div>
          );
        })}
      </div>
    </Card>
  );
}

function SimpleListCard({ title, items, render }) {
  return (
    <Card padding={18}>
      <SectionTitle right={<span style={{ fontSize: 11.5, color: "var(--ink-3)" }}>{items.length}</span>}>
        {title}
      </SectionTitle>
      <div>
        {items.map((it, i) => {
          const r = render(it) || {};
          return (
            <div key={i} className="cd-list-row">
              <div className="cd-logo"><Icon name="circle" size={10} /></div>
              <div style={{ minWidth: 0, flex: 1 }}>
                {r.primary && <div className="cd-prim">{r.primary}</div>}
                {r.secondary && <div className="cd-sec">{r.secondary}</div>}
                {r.period && <div className="cd-period mono">{r.period}</div>}
              </div>
            </div>
          );
        })}
      </div>
    </Card>
  );
}

function RelationshipCard({ contact }) {
  return (
    <Card padding={18}>
      <SectionTitle>Relationship intelligence</SectionTitle>
      <div style={{ display: "flex", flexDirection: "column", gap: 10 }}>
        <ScoreBar label="Relationship strength" value={contact.abm.relationshipStrength} tone="green" />
        <ScoreBar label="Engagement"             value={contact.abm.engagementScore} tone="violet" />
        <ScoreBar label="Intent"                 value={contact.abm.intentScore} tone="warm" />
      </div>
      <div style={{ marginTop: 14, display: "flex", gap: 8, alignItems: "center", flexWrap: "wrap" }}>
        <Badge tone="violet" icon="target">{contact.abm.persona}</Badge>
        <Badge tone="blue">{contact.abm.buyingCommitteeRole.replace(/_/g, " ")}</Badge>
      </div>
      {contact.abm.weakBuyingSignals?.length > 0 && (
        <div style={{ marginTop: 12 }}>
          <div style={{ fontSize: 11, color: "var(--ink-3)", textTransform: "uppercase", letterSpacing: "0.04em", fontWeight: 600, marginBottom: 6 }}>
            Buying signals
          </div>
          <div style={{ display: "flex", flexWrap: "wrap", gap: 5 }}>
            {contact.abm.weakBuyingSignals.map((s, i) => <Badge key={i} tone="neutral" size="sm">{s}</Badge>)}
          </div>
        </div>
      )}
      {contact.abm.recommendedNextAction && (
        <div style={{
          marginTop: 14, padding: "10px 12px",
          background: "linear-gradient(180deg, color-mix(in oklch, var(--accent) 6%, var(--surface)), var(--surface))",
          border: "1px solid color-mix(in oklch, var(--accent) 18%, var(--line))",
          borderRadius: 8, fontSize: 12, color: "var(--ink-2)",
          display: "flex", gap: 8, alignItems: "flex-start",
        }}>
          <Icon name="sparkles" size={13} style={{ color: "var(--accent)", marginTop: 1, flexShrink: 0 }} />
          <span>{contact.abm.recommendedNextAction}</span>
        </div>
      )}
    </Card>
  );
}

function ContactInfoCard({ contact }) {
  const rows = [];
  (contact.emails || []).forEach((e, i) => {
    rows.push({
      icon: "mail",
      label: i === 0 ? "Email" : "Email (alt)",
      val: (
        <span>
          <a href={`mailto:${e.email}`} style={{ color: "var(--ink)", fontWeight: 500 }}>{e.email}</a>
          <span style={{ display: "inline-flex", gap: 6, marginLeft: 8, alignItems: "center" }}>
            <span className="cd-chip" style={{
              background: e.status === "valid" ? "var(--green-soft)" : e.status === "risky" ? "var(--warm-soft)" : "var(--inset)",
              color:      e.status === "valid" ? "var(--green-ink)" : e.status === "risky" ? "var(--warm-ink)" : "var(--ink-3)",
            }}>
              <StatusDot tone={e.status === "valid" ? "green" : e.status === "risky" ? "warm" : "neutral"} size={6} />
              {e.status}
            </span>
            {typeof e.qualityScore === "number" && (
              <span className="mono num" style={{ fontSize: 11, color: "var(--ink-3)" }}>q{e.qualityScore}</span>
            )}
          </span>
        </span>
      ),
    });
  });
  if (contact.linkedinUrl) rows.push({
    icon: "linkedin", label: "LinkedIn",
    val: <a href={contact.linkedinUrl} target="_blank" rel="noreferrer" style={{ color: "var(--accent)" }}>
      {contact.linkedinUrl.replace(/^https?:\/\/(www\.)?/, "")}
    </a>,
  });
  (contact.companyWebsites || []).forEach(w => rows.push({
    icon: "external", label: "Company web",
    val: <a href={w.url} target="_blank" rel="noreferrer" style={{ color: "var(--accent)" }}>{w.domain}</a>,
  }));
  if (contact.locationCity || contact.locationCountry) rows.push({
    icon: "map-pin", label: "Location",
    val: [contact.locationCity, contact.locationCountry].filter(Boolean).join(", "),
  });

  if (rows.length === 0) return null;
  return (
    <Card padding={18}>
      <SectionTitle>Contact info</SectionTitle>
      <div>
        {rows.map((r, i) => (
          <div key={i} className="cd-info-row">
            <Icon name={r.icon} size={14} className="ic" />
            <div>
              <div className="lbl">{r.label}</div>
              <div className="val">{r.val}</div>
            </div>
          </div>
        ))}
      </div>
    </Card>
  );
}

function ProfileMetaCard({ contact, raw }) {
  const composeLabel = ({
    UPSELL: "Connection slot open (Upsell)",
    PREMIUM_INMAIL: "Premium InMail recommended",
  })[contact.composeOptionType] || contact.composeOptionType;
  return (
    <Card padding={18}>
      <SectionTitle>Profile</SectionTitle>
      <div style={{ display: "flex", flexDirection: "column", gap: 8 }}>
        {contact.composeOptionType && (
          <Row label="Compose channel" value={
            <Badge tone={contact.composeOptionType === "PREMIUM_INMAIL" ? "warm" : "green"} size="sm" dot>
              {composeLabel}
            </Badge>
          } />
        )}
        {contact.registeredAt && <Row label="Joined LinkedIn"
          value={<span className="mono">{window.fmtDate(contact.registeredAt, { month: "short", year: "numeric" })}</span>} />}
        {contact.updatedAt && <Row label="Profile synced"
          value={<span className="mono">{window.fmtRelative(contact.updatedAt)}</span>} />}
        {raw?.primaryLocale && <Row label="Primary locale"
          value={<span className="mono">{raw.primaryLocale.language}-{raw.primaryLocale.country}</span>} />}
        {raw?._meta?.pagination && (
          <Row label="Search context"
            value={<span style={{ fontSize: 11.5, color: "var(--ink-3)" }}>
              {raw._meta.pagination.totalElements?.toLocaleString()} results · page {raw._meta.pagination.pageNumber}
            </span>} />
        )}
      </div>
    </Card>
  );
}

function Row({ label, value }) {
  return (
    <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", gap: 10 }}>
      <span style={{ fontSize: 11.5, color: "var(--ink-3)", textTransform: "uppercase", letterSpacing: "0.04em", fontWeight: 600 }}>{label}</span>
      <span>{value}</span>
    </div>
  );
}

function SimilarProfilesCard({ items, onNavigate }) {
  return (
    <Card padding={18}>
      <SectionTitle right={<span style={{ fontSize: 11.5, color: "var(--ink-3)" }}>{items.length}</span>}>
        People also viewed
      </SectionTitle>
      <div style={{ display: "flex", flexDirection: "column", gap: 10 }}>
        {items.slice(0, 6).map((p, i) => {
          const pic = window.pickPicture
            ? window.pickPicture(p.profilePicture, 100)
            : (p.profilePicture?.url || null);
          return (
            <a key={i} href={p.linkedinUrl} target="_blank" rel="noreferrer"
              style={{ display: "flex", gap: 10, alignItems: "center", textDecoration: "none" }}>
              <Avatar name={`${p.firstName || ""} ${p.lastName || ""}`} src={pic} size={32} />
              <div style={{ minWidth: 0, flex: 1 }}>
                <div style={{ fontSize: 12.5, color: "var(--ink)", fontWeight: 600,
                  overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }}>
                  {p.firstName} {p.lastName}
                </div>
                {p.headline && (
                  <div style={{ fontSize: 11.5, color: "var(--ink-3)",
                    overflow: "hidden", textOverflow: "ellipsis", display: "-webkit-box",
                    WebkitLineClamp: 2, WebkitBoxOrient: "vertical" }}>
                    {p.headline}
                  </div>
                )}
              </div>
              <Icon name="external" size={12} style={{ color: "var(--ink-3)", flexShrink: 0 }} />
            </a>
          );
        })}
      </div>
    </Card>
  );
}

window.PageContactDetail = PageContactDetail;
