import { Briefcase, ShieldCheck, Wallet } from "lucide-react";

/**
 * "Business travel" plus whichever approval chip applies (PRD §6.1, LEIS-1015).
 *
 * Presentational on purpose — it takes the answer, it does not fetch it. The
 * home page knows the gate from the policy it already loads for the panel
 * beside it, and a second component resolving the same thing independently is
 * how two parts of one screen end up disagreeing for a render.
 *
 * ── Why two chips and not one ────────────────────────────────────────────
 *
 * `BusinessTravelLabel` on the SRP says "Business travel · needs approval" as a
 * single pill, and only when approval IS required — silence otherwise. That
 * works beside a list of fares, where the absence of a warning is readable.
 * It does not work here: the home page states the arrangement before anything
 * has been chosen, and "no approval" is a fact an admin and a no-approval
 * group both need told, not an absence. So both branches render, and they are
 * separate chips because they are separate facts: what kind of trip this is,
 * and who pays for it.
 *
 * Tone never carries the meaning alone — each chip says what it means in
 * words, so the amber/green distinction is reinforcement, not the message.
 */

/** The copy, in one place, because the SRP label says the same things. */
export const CHIP_COPY = {
  businessTravel: "Business travel",
  needsApproval: "Needs approval",
  noApproval: "No approval · you pay at checkout",
  approvalConsequence: "Your admin reviews this trip and pays for it once approved.",
  directConsequence: "You can book this trip yourself and pay with a saved company card.",
} as const;

const CHIP_BASE =
  "inline-flex items-center gap-[6px] rounded-full px-[12px] py-[6px] text-[13px] font-medium leading-none";

export function StatusChips({
  approvalRequired,
  className = "",
}: {
  approvalRequired: boolean;
  className?: string;
}) {
  return (
    <div className={`flex flex-wrap items-center gap-[8px] ${className}`}>
      <span
        className={CHIP_BASE}
        style={{ backgroundColor: "var(--fra-blue-bg)", color: "var(--fra-navy)" }}
      >
        <Briefcase size={14} aria-hidden="true" style={{ color: "var(--fra-navy)" }} />
        {CHIP_COPY.businessTravel}
      </span>

      {approvalRequired ? (
        <span
          className={CHIP_BASE}
          style={{
            backgroundColor: "var(--fra-pending-bg)",
            color: "var(--fra-pending)",
            border: "1px solid var(--fra-pending-border)",
          }}
        >
          <ShieldCheck size={14} aria-hidden="true" style={{ color: "var(--fra-pending)" }} />
          {CHIP_COPY.needsApproval}
        </span>
      ) : (
        <span
          className={CHIP_BASE}
          style={{ backgroundColor: "var(--fra-approved-bg)", color: "var(--fra-approved)" }}
        >
          <Wallet size={14} aria-hidden="true" style={{ color: "var(--fra-approved)" }} />
          {CHIP_COPY.noApproval}
        </span>
      )}
    </div>
  );
}

/**
 * The placeholder that holds the chips' space while the gate is unknown.
 *
 * Not the chips themselves greyed out: "Business travel" alone reads as a
 * claim that no approval is needed, and showing it before the answer arrives
 * would tell half the companies using this the opposite of the truth on the
 * one question that decides who pays. Same reasoning as `BusinessTravelLabel`,
 * which renders nothing at all — but this sits inside a card with a fixed
 * layout, so the row holds its height instead of collapsing and reflowing.
 */
export function StatusChipsSkeleton() {
  return (
    <div className="flex items-center gap-[8px]" aria-hidden="true">
      <span
        className="h-[27px] w-[116px] animate-pulse rounded-full motion-reduce:animate-none"
        style={{ backgroundColor: "var(--fra-hover)" }}
      />
      <span
        className="h-[27px] w-[132px] animate-pulse rounded-full motion-reduce:animate-none"
        style={{ backgroundColor: "var(--fra-hover)" }}
      />
    </div>
  );
}
