import Link from "@/components/Link";
import Breadcrumbs from "@/components/Breadcrumbs";
import Icon from "@/components/Icon";
import { team, type Rep } from "@/lib/channels";
import { crumbTrail } from "@/lib/seo";

export function PersonCard({ rep }: { rep: Rep }) {
  return (
    <article className="an-person">
      <div className="an-person__photo">
        <Link href={`/team/${rep.slug}`}>
          <img src={rep.photo} alt={rep.name} width={500} height={500} loading="lazy" />
        </Link>
      </div>
      <div className="an-person__body">
        <div>
          <h3><Link href={`/team/${rep.slug}`}>{rep.name}</Link></h3>
          <p className="an-person__title">{rep.title}</p>
        </div>
        <div className="an-chips">
          {rep.expertise.map((tag) => (
            <span key={tag} className="an-tag an-tag--line">{tag}</span>
          ))}
        </div>
        <p className="an-person__intro">{rep.intro}</p>
        <div className="an-person__actions">
          <Link href={`/contact?rep=${rep.slug}`} className="an-btn an-btn--primary an-btn--sm" data-track="profile_contact_click" data-track-rep={rep.slug} data-track-location="person_card">Connect with {rep.first}</Link>
        </div>
      </div>
    </article>
  );
}

/** Directory markup shared by /team and an unknown profile slug. */
export function TeamDirectory({ unavailableSlug = "" }: { unavailableSlug?: string }) {
  const members = team.filter((rep) => rep.active);
  return (
    <>
      <section className="an-hero an-hero--channel an-hero--center">
        <div className="an-wrap an-hero__copy">
          <Breadcrumbs items={crumbTrail("/team")} />
          <span className="an-eyebrow">Our team</span>
          <h1 className="an-h1">Meet the <span className="an-ai-text">Team</span></h1>
          <p className="an-lede">At Advertising.net, our people drive our innovation and growth. Our team brings together digital strategists, technology experts, data scientists, and client success professionals who work together to shape the future of search and AI-powered advertising. With a shared focus on creativity, expertise, and collaboration, we build effective advertising solutions and develop lasting partnerships with clients around the world.</p>
        </div>
      </section>
      <section className="an-section an-section--paper" id="sales-team">
        <div className="an-wrap">
          <h2 className="an-sr">Our sales team</h2>
          {unavailableSlug ? (
            <div className="u-mb-28px an-alert an-alert--info" role="status">
              <Icon name="people" />
              <div>That profile isn’t available right now. Choose another team member below, or <Link data-track-location="team_intro" href="/contact">send a general inquiry</Link> and our team will route it.</div>
            </div>
          ) : null}
          <div className="an-team">
            {members.map((rep) => <PersonCard key={rep.slug} rep={rep} />)}
          </div>
        </div>
      </section>
    </>
  );
}
