import Link from "next/link";

export const CRM_WORKSPACE_LINKS = [
  { href: "/crm", label: "Overview" },
  { href: "/companies", label: "Companies" },
  { href: "/brokers", label: "Brokers" },
  { href: "/shippers", label: "Shippers" },
] as const;

export function CrmWorkspaceNavigation({ currentHref }: { currentHref: string }) {
  return (
    <section className="rounded-2xl border bg-white p-4 shadow-sm">
      <div className="flex flex-col gap-3 lg:flex-row lg:items-start lg:justify-between">
        <div>
          <div className="text-[11px] font-semibold uppercase tracking-[0.18em] text-slate-400">CRM workspace path</div>
          <div className="mt-1 text-base font-semibold text-slate-900">Move between partner relationship lists without hunting through the app.</div>
          <div className="mt-1 text-sm text-slate-500">Use CRM for companies, brokers, and shippers. Drivers and owner operators stay under People & Assets.</div>
        </div>
        <div className="rounded-full bg-slate-100 px-3 py-1.5 text-xs font-medium text-slate-700">Current area stays highlighted</div>
      </div>
      <div className="mt-4 flex flex-wrap gap-2">
        {CRM_WORKSPACE_LINKS.map((item) => {
          const active = currentHref === item.href;
          return active ? (
            <span key={item.href} className="rounded-full bg-slate-900 px-3 py-1.5 text-xs font-semibold text-white">{item.label}</span>
          ) : (
            <Link key={item.href} href={item.href} className="rounded-full border bg-white px-3 py-1.5 text-xs font-medium text-slate-700 hover:bg-slate-50">{item.label}</Link>
          );
        })}
      </div>
    </section>
  );
}

export function CrmWorkspaceLaunchCards({
  createHref,
  createLabel,
  listHref,
  listLabel,
  analyticsHref = "/crm",
  analyticsLabel = "CRM Overview",
  intelligenceHref = "/cori?source=crm&question=Help me choose the best CRM follow-up.",
}: {
  createHref?: string;
  createLabel?: string;
  listHref: string;
  listLabel: string;
  analyticsHref?: string;
  analyticsLabel?: string;
  intelligenceHref?: string;
}) {
  const cards = [
    {
      href: listHref,
      eyebrow: "List workspace",
      title: listLabel,
      detail: "Open the list with filters, follow-up context, and record actions.",
    },
    {
      href: analyticsHref,
      eyebrow: "Overview",
      title: analyticsLabel,
      detail: "Return to the main CRM view for relationship follow-up work.",
    },
    {
      href: intelligenceHref,
      eyebrow: "CORI help",
      title: "Ask CORI",
      detail: "Ask CORI to help choose the next follow-up or prepare a simple outreach step.",
    },
  ] as const;

  return (
    <section className="grid gap-3 lg:grid-cols-3 xl:grid-cols-4">
      {cards.map((card) => (
        <Link key={card.href} href={card.href} className="rounded-2xl border bg-white p-4 shadow-sm hover:bg-slate-50">
          <div className="text-[11px] font-semibold uppercase tracking-[0.18em] text-slate-400">{card.eyebrow}</div>
          <div className="mt-2 text-sm font-semibold text-slate-900">{card.title}</div>
          <div className="mt-2 text-sm text-slate-500">{card.detail}</div>
        </Link>
      ))}
      {createHref && createLabel ? (
        <Link href={createHref} className="rounded-2xl border border-slate-900 bg-slate-900 p-4 text-white shadow-sm hover:bg-slate-800">
          <div className="text-[11px] font-semibold uppercase tracking-[0.18em] text-slate-300">Create</div>
          <div className="mt-2 text-sm font-semibold">{createLabel}</div>
          <div className="mt-2 text-sm text-slate-200">Start a new record from this relationship workspace.</div>
        </Link>
      ) : null}
    </section>
  );
}
