/**
 * Inline stroke icons (24px grid, 1.75 stroke, currentColor). No icon font or runtime dependency:
 * each icon is a few path strings, tree-shaken per page.
 */
type IconProps = { className?: string; title?: string; strokeWidth?: number };

function make(paths: React.ReactNode, displayName: string) {
  const Icon = ({ className = 'h-4 w-4', title, strokeWidth = 1.75 }: IconProps) => (
    <svg
      viewBox="0 0 24 24"
      fill="none"
      stroke="currentColor"
      strokeWidth={strokeWidth}
      strokeLinecap="round"
      strokeLinejoin="round"
      className={`shrink-0 ${className}`}
      aria-hidden={title ? undefined : true}
      role={title ? 'img' : undefined}
    >
      {title && <title>{title}</title>}
      {paths}
    </svg>
  );
  Icon.displayName = displayName;
  return Icon;
}

export const SearchIcon = make(<><circle cx="11" cy="11" r="7" /><path d="m20 20-3.5-3.5" /></>, 'SearchIcon');
export const XIcon = make(<path d="M18 6 6 18M6 6l12 12" />, 'XIcon');
export const ArrowRightIcon = make(<path d="M5 12h14m-6-6 6 6-6 6" />, 'ArrowRightIcon');
export const ArrowLeftIcon = make(<path d="M19 12H5m6 6-6-6 6-6" />, 'ArrowLeftIcon');
export const ArrowUpRightIcon = make(<path d="M7 17 17 7M8 7h9v9" />, 'ArrowUpRightIcon');
export const ChevronRightIcon = make(<path d="m9 6 6 6-6 6" />, 'ChevronRightIcon');
export const ChevronLeftIcon = make(<path d="m15 6-6 6 6 6" />, 'ChevronLeftIcon');
export const ChevronDownIcon = make(<path d="m6 9 6 6 6-6" />, 'ChevronDownIcon');
export const MenuIcon = make(<path d="M4 7h16M4 12h16M4 17h16" />, 'MenuIcon');
export const MapPinIcon = make(<><path d="M12 21s-7-6.2-7-11.5A7 7 0 0 1 19 9.5C19 14.8 12 21 12 21Z" /><circle cx="12" cy="9.5" r="2.5" /></>, 'MapPinIcon');
export const ScaleIcon = make(<><path d="M12 3v18M7 21h10M5 7h14M12 5l-.01 0" /><path d="m5 7-3 7a3.5 3.5 0 0 0 6 0L5 7Zm14 0-3 7a3.5 3.5 0 0 0 6 0l-3-7Z" /></>, 'ScaleIcon');
export const GavelIcon = make(<><path d="m14 13-7.5 7.5a2.1 2.1 0 0 1-3-3L11 10" /><path d="m16 16 6-6M8 8l6-6M9 7l8 8M21 11l-8-8" /></>, 'GavelIcon');
export const BriefcaseIcon = make(<><rect x="3" y="7" width="18" height="13" rx="2" /><path d="M8 7V5a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2M3 13h18" /></>, 'BriefcaseIcon');
export const UserIcon = make(<><circle cx="12" cy="8" r="4" /><path d="M4 21a8 8 0 0 1 16 0" /></>, 'UserIcon');
export const UsersIcon = make(<><circle cx="9" cy="8" r="3.5" /><path d="M2.5 20a6.5 6.5 0 0 1 13 0M16 4.5a3.5 3.5 0 0 1 0 7M18 14a6.5 6.5 0 0 1 3.5 6" /></>, 'UsersIcon');
export const BuildingIcon = make(<><rect x="4" y="3" width="16" height="18" rx="1.5" /><path d="M9 21v-4h6v4M8.5 7h1M14.5 7h1M8.5 11h1M14.5 11h1" /></>, 'BuildingIcon');
export const LandmarkIcon = make(<path d="M3 21h18M5 18v-7M9.5 18v-7M14.5 18v-7M19 18v-7M2.5 9 12 3l9.5 6h-19Z" />, 'LandmarkIcon');
export const ShieldCheckIcon = make(<><path d="M12 3 4.5 6v5.5c0 4.6 3.2 8.3 7.5 9.5 4.3-1.2 7.5-4.9 7.5-9.5V6L12 3Z" /><path d="m9 12 2.2 2.2L15.5 10" /></>, 'ShieldCheckIcon');
export const BadgeCheckIcon = make(<><path d="M12 2.8 14.3 5l3.1-.4.7 3 2.6 1.7-1.2 2.9 1.2 2.9-2.6 1.6-.7 3.1-3.1-.4L12 21.2 9.7 19l-3.1.4-.7-3.1-2.6-1.6 1.2-2.9-1.2-2.9L5.9 7.6l.7-3 3.1.4L12 2.8Z" /><path d="m8.8 12.2 2.2 2.2 4.2-4.4" /></>, 'BadgeCheckIcon');
export const StarIcon = make(<path d="m12 3 2.7 5.6 6.1.8-4.5 4.2 1.1 6L12 16.7 6.6 19.6l1.1-6-4.5-4.2 6.1-.8L12 3Z" />, 'StarIcon');
export const PhoneIcon = make(<path d="M5 4h3.5l1.8 4.5-2.3 1.4a11 11 0 0 0 6.1 6.1l1.4-2.3L20 15.5V19a2 2 0 0 1-2 2A16 16 0 0 1 3 6a2 2 0 0 1 2-2Z" />, 'PhoneIcon');
export const GlobeIcon = make(<><circle cx="12" cy="12" r="9" /><path d="M3 12h18M12 3a14 14 0 0 1 0 18M12 3a14 14 0 0 0 0 18" /></>, 'GlobeIcon');
export const MailIcon = make(<><rect x="3" y="5" width="18" height="14" rx="2" /><path d="m3.5 6.5 8.5 6.5 8.5-6.5" /></>, 'MailIcon');
export const ClockIcon = make(<><circle cx="12" cy="12" r="9" /><path d="M12 7v5l3 2" /></>, 'ClockIcon');
export const CalendarIcon = make(<><rect x="3.5" y="5" width="17" height="15.5" rx="2" /><path d="M3.5 10h17M8 3v4M16 3v4" /></>, 'CalendarIcon');
export const AwardIcon = make(<><circle cx="12" cy="9" r="6" /><path d="m8.5 14 -1.5 7 5-3 5 3-1.5-7" /></>, 'AwardIcon');
export const FileTextIcon = make(<><path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8l-5-5Z" /><path d="M14 3v5h5M9 13h6M9 17h6" /></>, 'FileTextIcon');
export const HeartIcon = make(<path d="M12 20s-7.5-4.6-7.5-10.2A4.3 4.3 0 0 1 12 7.2a4.3 4.3 0 0 1 7.5 2.6C19.5 15.4 12 20 12 20Z" />, 'HeartIcon');
export const HomeIcon = make(<><path d="m3 11 9-7 9 7" /><path d="M5 9.5V20h14V9.5M10 20v-6h4v6" /></>, 'HomeIcon');
export const PlaneIcon = make(<path d="M10.5 12 3 9.5 4.5 8l9 1.5 4-4a2.1 2.1 0 0 1 3 3l-4 4L18 21l-1.5 1.5-2.5-7.5-3.5 3.5V21l-1.5 1.5-1.5-3.5L4 17.5 5.5 16H8l2.5-4Z" />, 'PlaneIcon');
export const CarIcon = make(<><path d="M5 17H3v-5l2-5h14l2 5v5h-2" /><circle cx="7.5" cy="17" r="2" /><circle cx="16.5" cy="17" r="2" /><path d="M9.5 17h5M3 12h18" /></>, 'CarIcon');
export const ChildIcon = make(<><circle cx="12" cy="6" r="3" /><path d="M8 21v-5l-2-1 1.5-5h9L18 15l-2 1v5M10 21v-4h4v4" /></>, 'ChildIcon');
export const ScrollIcon = make(<><path d="M8 21h11a2 2 0 0 0 2-2v-1H10v1a2 2 0 0 1-4 0V5a2 2 0 0 0-2-2" /><path d="M4 3h12a2 2 0 0 1 2 2v13M10 8h5M10 12h5" /></>, 'ScrollIcon');
export const HandshakeIcon = make(<path d="m11 17 2 2a1.4 1.4 0 0 0 2-2m-2-2 2.5 2.5a1.4 1.4 0 0 0 2-2l-3-3M2.5 11.5 6 8l4 1.5L13 7l4 1 4.5 3.5M6 8l-3.5 3.5 7.5 7.5a1.4 1.4 0 0 0 2-2" />, 'HandshakeIcon');
export const TrendingUpIcon = make(<path d="m3 17 6-6 4 4 8-8M15 7h6v6" />, 'TrendingUpIcon');
export const ChartIcon = make(<path d="M4 20V10M10 20V4M16 20v-7M21 20H3" />, 'ChartIcon');
export const CheckIcon = make(<path d="m5 12.5 4.5 4.5L19 7.5" />, 'CheckIcon');
export const CheckCircleIcon = make(<><circle cx="12" cy="12" r="9" /><path d="m8.5 12.3 2.3 2.3 4.7-4.8" /></>, 'CheckCircleIcon');
export const AlertIcon = make(<><path d="M10.3 3.9 2.4 18a2 2 0 0 0 1.7 3h15.8a2 2 0 0 0 1.7-3L13.7 3.9a2 2 0 0 0-3.4 0Z" /><path d="M12 9v4.5M12 17.2v.1" /></>, 'AlertIcon');
export const InfoIcon = make(<><circle cx="12" cy="12" r="9" /><path d="M12 11v5.5M12 7.8v.1" /></>, 'InfoIcon');
export const FlagIcon = make(<path d="M5 21V4m0 0h11l-2 4 2 4H5" />, 'FlagIcon');
export const MessageIcon = make(<path d="M20 15a2 2 0 0 1-2 2H8l-4 4V5a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v10Z" />, 'MessageIcon');
export const LanguagesIcon = make(<path d="M4 5h9M8.5 3v2c0 4-2 7-5 8.5M6 9c1 2.5 3 4.2 6 5M13 21l4.5-10L22 21m-7.5-3h6" />, 'LanguagesIcon');
export const FilterIcon = make(<path d="M4 6h16M7 12h10M10 18h4" />, 'FilterIcon');
export const ExternalLinkIcon = make(<path d="M14 4h6v6M20 4l-9 9M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5" />, 'ExternalLinkIcon');
export const BookOpenIcon = make(<path d="M12 6.5C10 5 7 4.5 3 5v14c4-.5 7 0 9 1.5 2-1.5 5-2 9-1.5V5c-4-.5-7 0-9 1.5Zm0 0v14" />, 'BookOpenIcon');
export const SparklesIcon = make(<path d="M12 3v4M12 17v4M3 12h4M17 12h4M5.6 5.6l2.1 2.1M16.3 16.3l2.1 2.1M5.6 18.4l2.1-2.1M16.3 7.7l2.1-2.1" />, 'SparklesIcon');
export const LockIcon = make(<><rect x="4.5" y="10.5" width="15" height="10" rx="2" /><path d="M8 10.5V7.5a4 4 0 0 1 8 0v3" /></>, 'LockIcon');
export const EyeIcon = make(<><path d="M2.5 12S6 5 12 5s9.5 7 9.5 7-3.5 7-9.5 7-9.5-7-9.5-7Z" /><circle cx="12" cy="12" r="3" /></>, 'EyeIcon');
export const LayersIcon = make(<path d="m12 3 9 5-9 5-9-5 9-5Zm-9 9 9 5 9-5M3 16l9 5 9-5" />, 'LayersIcon');
export const HistoryIcon = make(<><path d="M3.5 12a8.5 8.5 0 1 0 2.5-6L3.5 8.5" /><path d="M3.5 4v4.5H8M12 8v4.5l3 1.5" /></>, 'HistoryIcon');
export const DatabaseIcon = make(<><ellipse cx="12" cy="5.5" rx="8" ry="3" /><path d="M4 5.5v13c0 1.7 3.6 3 8 3s8-1.3 8-3v-13M4 12c0 1.7 3.6 3 8 3s8-1.3 8-3" /></>, 'DatabaseIcon');
export const SendIcon = make(<path d="M21 3 10 14M21 3l-6.5 18-3.5-7-7-3.5L21 3Z" />, 'SendIcon');
export const QuoteIcon = make(<path d="M9 7H5a1 1 0 0 0-1 1v4a1 1 0 0 0 1 1h3v1a3 3 0 0 1-3 3M20 7h-4a1 1 0 0 0-1 1v4a1 1 0 0 0 1 1h3v1a3 3 0 0 1-3 3" />, 'QuoteIcon');
export const CompassIcon = make(<><circle cx="12" cy="12" r="9" /><path d="m15.5 8.5-2 5-5 2 2-5 5-2Z" /></>, 'CompassIcon');
export const HashIcon = make(<path d="M5 9h14M5 15h14M10 4 8 20M16 4l-2 16" />, 'HashIcon');

export const DashboardIcon = make(<><rect x="3" y="3" width="7.5" height="9" rx="1.5" /><rect x="13.5" y="3" width="7.5" height="5" rx="1.5" /><rect x="13.5" y="11" width="7.5" height="10" rx="1.5" /><rect x="3" y="15" width="7.5" height="6" rx="1.5" /></>, 'DashboardIcon');
export const ActivityIcon = make(<path d="M3 12h4l3-8 4 16 3-8h4" />, 'ActivityIcon');
export const GaugeIcon = make(<><path d="M12 14 15.5 9.5" /><path d="M4 18a9 9 0 1 1 16 0" /></>, 'GaugeIcon');
export const ListChecksIcon = make(<path d="m3.5 6 1.5 1.5L8 4.5M3.5 13l1.5 1.5L8 11.5M12 6h9M12 13h9M12 19.5h9M4 19.5h4" />, 'ListChecksIcon');
export const MergeIcon = make(<><circle cx="6" cy="5" r="2" /><circle cx="6" cy="19" r="2" /><circle cx="18" cy="12" r="2" /><path d="M6 7v10M6 9c0 3 3 3 6 3h4" /></>, 'MergeIcon');
export const UploadIcon = make(<path d="M12 15V4m-4.5 4.5L12 4l4.5 4.5M4 15v4a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1v-4" />, 'UploadIcon');
export const InboxIcon = make(<><path d="M3 13h5l1.5 3h5L16 13h5" /><path d="M5.5 5h13L21 13v6a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1v-6l2.5-8Z" /></>, 'InboxIcon');
export const DollarIcon = make(<path d="M12 3v18M16.5 7.5c-.6-1.5-2.3-2.5-4.5-2.5-2.5 0-4.5 1.3-4.5 3.3 0 4.7 9.5 2.4 9.5 7.2 0 2-2 3.5-5 3.5-2.4 0-4.2-1-4.8-2.7" />, 'DollarIcon');
export const KeyIcon = make(<><circle cx="8" cy="15" r="4" /><path d="m11 12 9-9M17 6l3 3M14.5 8.5l2 2" /></>, 'KeyIcon');
export const LogOutIcon = make(<path d="M9 21H5a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h4M16 17l5-5-5-5M21 12H9" />, 'LogOutIcon');
export const PlusIcon = make(<path d="M12 5v14M5 12h14" />, 'PlusIcon');
export const RefreshIcon = make(<path d="M20 11a8 8 0 0 0-14.5-4.5L3 9m0-5v5h5M4 13a8 8 0 0 0 14.5 4.5L21 15m0 5v-5h-5" />, 'RefreshIcon');
export const TrashIcon = make(<path d="M4 7h16M9 7V4h6v3M6 7l1 13h10l1-13M10 11v6M14 11v6" />, 'TrashIcon');
export const SaveIcon = make(<><path d="M5 3h11l3 3v14a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1V3Z" /><path d="M8 3v5h7V3M8 21v-7h8v7" /></>, 'SaveIcon');
export const CodeIcon = make(<path d="m8 8-4 4 4 4M16 8l4 4-4 4M13.5 5l-3 14" />, 'CodeIcon');
export const XCircleIcon = make(<><circle cx="12" cy="12" r="9" /><path d="m9 9 6 6M15 9l-6 6" /></>, 'XCircleIcon');
export const BellIcon = make(<path d="M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9M10.3 21a1.94 1.94 0 0 0 3.4 0" />, 'BellIcon');
export const ImageIcon = make(<><rect x="3" y="4" width="18" height="16" rx="2" /><circle cx="8.5" cy="9.5" r="1.5" /><path d="m21 16-5-5L5 20" /></>, 'ImageIcon');
export const ServerIcon =make(<><rect x="3" y="4" width="18" height="7" rx="1.5" /><rect x="3" y="13" width="18" height="7" rx="1.5" /><path d="M7 7.5h.01M7 16.5h.01" /></>, 'ServerIcon');

/** Animated loading ring */
export function Spinner({ className = 'h-4 w-4' }: { className?: string }) {
  return (
    <svg viewBox="0 0 24 24" className={`shrink-0 animate-spin ${className}`} fill="none" aria-hidden>
      <circle cx="12" cy="12" r="9" stroke="currentColor" strokeOpacity=".25" strokeWidth="2.5" />
      <path d="M21 12a9 9 0 0 0-9-9" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" />
    </svg>
  );
}

/** One recognisable glyph per practice area; unknown areas fall back to the scales of justice */
const AREA_ICON: Record<string, ReturnType<typeof make>> = {
  divorce: HeartIcon,
  family: UsersIcon,
  'personal-injury': CarIcon,
  criminal: GavelIcon,
  immigration: PlaneIcon,
  employment: BriefcaseIcon,
  'estate-planning': ScrollIcon,
  business: BuildingIcon,
  'real-estate': HomeIcon,
  'child-custody': ChildIcon,
};
export function PracticeAreaIcon({ slug, className }: { slug: string; className?: string }) {
  const Icon = AREA_ICON[slug] ?? ScaleIcon;
  return <Icon className={className} />;
}

export const RestoreIcon = make(<><path d="M3 10a9 9 0 1 1 2 8M3 4v6h6" /><path d="M12 7v5l3 2" /></>, 'RestoreIcon');
export const CopyIcon = make(<><rect x="8" y="8" width="12" height="12" rx="2" /><path d="M16 8V4H4v12h4" /></>, 'CopyIcon');

export const SortIcon = make(<><path d="M8 4v16m-4-4 4 4 4-4M15 5h5M15 10h4M15 15h3" /></>, 'SortIcon');

export const EyeOffIcon = make(<><path d="m3 3 18 18M10.6 5.1A11 11 0 0 1 12 5c6 0 9.5 7 9.5 7a17 17 0 0 1-3.2 4M6.1 6.1A18 18 0 0 0 2.5 12S6 19 12 19a11 11 0 0 0 5-1.2M10 10a3 3 0 0 0 4 4" /></>, 'EyeOffIcon');
