'use client';

import { Check } from 'lucide-react';
import Link from 'next/link';

import type { CompanyDetailsFormData } from './CompanyDetailsStep';

interface CompanyDoneStepProps {
  details: CompanyDetailsFormData;
  onGoToDashboard: () => void;
}

interface SummaryRowProps {
  label: string;
  value: string;
}

function SummaryRow({ label, value }: SummaryRowProps) {
  return (
    <li className="flex items-center justify-between gap-3 text-[13px]">
      <span className="text-[var(--fra-muted)]">{label}</span>
      <strong className="text-right font-semibold text-[var(--fra-heading)]">{value}</strong>
    </li>
  );
}

/** Mirrors employee-signup's DoneStep — a checkmark, a summary of what was
 *  just created, and one clear next action. The admin's inbox is empty right
 *  after this (no employees yet), so a second, lighter link to Workforce sits
 *  alongside the primary CTA rather than being the only option — they may
 *  just want to look around the dashboard first. */
export default function CompanyDoneStep({ details, onGoToDashboard }: CompanyDoneStepProps) {
  const fullName = [details.firstName, details.middleName, details.lastName].filter(Boolean).join(' ');
  const displayName = fullName.replace(/\b(\w)(\w*)/g, (_, a: string, b: string) => a.toUpperCase() + b.toLowerCase());
  return (
    <div className="mx-auto max-w-[440px] text-center">
      <span className="mx-auto mb-3.5 flex size-16 items-center justify-center rounded-full bg-[var(--fra-approved-bg)] text-[var(--fra-approved)]">
        <Check className="size-8" strokeWidth={3} />
      </span>

      <h2 className="mb-1.5 text-[22px] font-extrabold text-[var(--fra-heading)]">Company created</h2>
      <p className="mb-5 text-sm text-[var(--fra-muted)]">
        Welcome, <strong className="text-[var(--fra-heading)]">{displayName}</strong>.{' '}
        <strong className="text-[var(--fra-heading)]">{details.companyName}</strong> is ready — invite your team when
        you&apos;re set to start booking business travel.
      </p>

      <ul className="m-0 mb-5 grid list-none gap-2 rounded-xl border border-[var(--fra-border)] bg-[var(--fra-surface-2)] px-4 py-3.5 text-left">
        <SummaryRow label="Company" value={details.companyName} />
        <SummaryRow label="Business address" value={details.businessAddress} />
        <SummaryRow label="Admin" value={displayName} />
        <SummaryRow label="Work email" value={details.workEmail} />
        <SummaryRow label="Role" value="Admin" />
      </ul>

      <button
        type="button"
        onClick={onGoToDashboard}
        className="group flex h-11 w-full items-center justify-center gap-2 rounded-[var(--fra-radius-sm)] bg-[var(--fra-coral)] text-[15px] font-semibold text-white shadow-[0_4px_14px_rgba(244,93,107,0.35)] transition-colors hover:bg-[var(--fra-coral-dark)]"
      >
        <span>Go to dashboard</span>
        <svg className="size-4 transition-transform group-hover:translate-x-0.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5">
          <path strokeLinecap="round" strokeLinejoin="round" d="M5 12h14M13 6l6 6-6 6" />
        </svg>
      </button>

      <p className="mt-3.5 mb-0 text-center text-[13px] text-[var(--fra-muted)]">
        <Link href="/admin/workforce" className="font-semibold text-[var(--fra-coral)] hover:underline">
          Invite your team
        </Link>{' '}
        instead
      </p>
    </div>
  );
}
