// Shared line-icon set for the staff admin area (AdminShell) and the
// reseller/customer portal (ResellerShell) — both now share ONE visual
// language (see admin-shell.jsx / reseller-shell.jsx): a light
// black-on-white sidebar nav, each item paired with one of these icons.
//
// Deliberately plain geometric line-drawing style (1.6 stroke, square
// caps, no fill except where noted) — matches the existing LockIcon in
// nav.jsx and the TowerSchematic in shared/primitives.jsx, so nothing
// here introduces a new illustration style to the codebase.
//
// Every icon takes a single `size` prop (default 18) and renders
// `currentColor` for both stroke and fill, so the calling button's own
// `color` style drives the icon colour — no separate colour prop needed,
// and active/hover states "just work" by changing the parent's color.
//
// Loaded before admin-shell.jsx and reseller-shell.jsx (see index.html).

function IconOverview({ size = 18 }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="square" strokeLinejoin="round" aria-hidden="true">
      <rect x="3.5" y="3.5" width="7" height="7" />
      <rect x="13.5" y="3.5" width="7" height="4.5" />
      <rect x="13.5" y="10.5" width="7" height="10" />
      <rect x="3.5" y="13" width="7" height="7.5" />
    </svg>
  );
}

function IconQuote({ size = 18 }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="square" strokeLinejoin="round" aria-hidden="true">
      <rect x="4.5" y="3" width="15" height="18" />
      <line x1="8" y1="8" x2="16" y2="8" />
      <line x1="8" y1="12" x2="16" y2="12" />
      <line x1="8" y1="16" x2="13" y2="16" />
    </svg>
  );
}

function IconOrders({ size = 18 }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="square" strokeLinejoin="round" aria-hidden="true">
      <path d="M3.5 7 L12 3.5 L20.5 7 L12 10.5 Z" />
      <path d="M3.5 7 V17 L12 20.5 V10.5" />
      <path d="M20.5 7 V17 L12 20.5" />
    </svg>
  );
}

function IconInvoices({ size = 18 }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="square" strokeLinejoin="round" aria-hidden="true">
      <path d="M5.5 3h9l4 4v14h-13z" />
      <path d="M14.5 3v4h4" />
      <line x1="8.5" y1="11" x2="15.5" y2="11" />
      <line x1="8.5" y1="14.5" x2="15.5" y2="14.5" />
      <line x1="8.5" y1="18" x2="12.5" y2="18" />
    </svg>
  );
}

function IconPurchaseOrders({ size = 18 }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="square" strokeLinejoin="round" aria-hidden="true">
      <rect x="4" y="4.5" width="16" height="15" />
      <path d="M8 4.5 V2.5 h8 v2" />
      <path d="M8.5 11.5 l2 2 l5-5" />
    </svg>
  );
}

function IconAssets({ size = 18 }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="square" strokeLinejoin="round" aria-hidden="true">
      <rect x="5" y="15.5" width="14" height="2" />
      <circle cx="8.5" cy="17.5" r="1.6" />
      <circle cx="15.5" cy="17.5" r="1.6" />
      <rect x="7" y="10" width="10" height="4" />
      <polygon points="4,10 8,6.5 8,10" />
      <polygon points="20,10 16,6.5 16,10" />
      <line x1="9" y1="3.5" x2="9" y2="6.5" />
      <line x1="15" y1="3.5" x2="15" y2="6.5" />
    </svg>
  );
}

function IconPriceList({ size = 18 }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="square" strokeLinejoin="round" aria-hidden="true">
      <circle cx="12" cy="12" r="8.5" />
      <line x1="9" y1="9" x2="15" y2="15" />
      <circle cx="9.3" cy="9.3" r="0.4" fill="currentColor" stroke="none" />
      <circle cx="14.7" cy="14.7" r="0.4" fill="currentColor" stroke="none" />
    </svg>
  );
}

function IconCustomers({ size = 18 }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="square" strokeLinejoin="round" aria-hidden="true">
      <circle cx="9" cy="7.5" r="3" />
      <path d="M3.5 20 v-1.5 c0-3 2.5-5 5.5-5 s5.5 2 5.5 5 V20" />
      <circle cx="17" cy="8.5" r="2.4" />
      <path d="M15.5 12.2 c2.7 0.4 4.6 2.2 4.6 4.8 V20" />
    </svg>
  );
}

function IconApprovals({ size = 18 }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="square" strokeLinejoin="round" aria-hidden="true">
      <circle cx="12" cy="12" r="8.5" />
      <path d="M8 12.3 l2.6 2.6 l5.4-6" />
    </svg>
  );
}

function IconSpecSheets({ size = 18 }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="square" strokeLinejoin="round" aria-hidden="true">
      <path d="M6 3.5h8l4 4v13H6z" />
      <path d="M14 3.5v4h4" />
      <line x1="9" y1="12" x2="15" y2="12" />
      <line x1="9" y1="15.5" x2="15" y2="15.5" />
    </svg>
  );
}

function IconTicket({ size = 18 }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="square" strokeLinejoin="round" aria-hidden="true">
      <path d="M3.5 8.5 a2 2 0 000 4" />
      <path d="M3.5 8.5 v-2 h17 v13 h-17 v-2" />
      <path d="M3.5 12.5 a2 2 0 000 4" style={{ display: "none" }} />
      <line x1="14.5" y1="6.5" x2="14.5" y2="19.5" strokeDasharray="2.5 2.5" />
    </svg>
  );
}

function IconTicketList({ size = 18 }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="square" strokeLinejoin="round" aria-hidden="true">
      <rect x="3.5" y="4" width="17" height="16" />
      <line x1="7" y1="8.5" x2="17" y2="8.5" />
      <line x1="7" y1="12" x2="17" y2="12" />
      <line x1="7" y1="15.5" x2="13" y2="15.5" />
    </svg>
  );
}

function IconSettings({ size = 18 }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
      <circle cx="12" cy="12" r="3.2" />
      <path d="M12 3.5 v2.6 M12 17.9 v2.6 M20.5 12 h-2.6 M5.6 12 H3 M17.8 6.2 l-1.9 1.9 M8 15.9 l-1.9 1.9 M17.8 17.8 l-1.9-1.9 M8 8.1 L6.1 6.2" />
    </svg>
  );
}

function IconStaff({ size = 18 }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="square" strokeLinejoin="round" aria-hidden="true">
      <circle cx="12" cy="7.5" r="3.4" />
      <path d="M4.5 20 v-1.8 c0-3.4 3.4-5.7 7.5-5.7 s7.5 2.3 7.5 5.7 V20" />
    </svg>
  );
}

function IconSignOut({ size = 18 }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="square" strokeLinejoin="round" aria-hidden="true">
      <path d="M9.5 4h-4v16h4" />
      <line x1="9.5" y1="12" x2="20" y2="12" />
      <path d="M16 8 l4 4 l-4 4" />
    </svg>
  );
}

function IconMissionControl({ size = 18 }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="square" strokeLinejoin="round" aria-hidden="true">
      <circle cx="12" cy="12" r="8.5" />
      <circle cx="12" cy="12" r="3" fill="currentColor" stroke="none" />
      <line x1="12" y1="1.7" x2="12" y2="4.5" />
      <line x1="12" y1="19.5" x2="12" y2="22.3" />
      <line x1="1.7" y1="12" x2="4.5" y2="12" />
      <line x1="19.5" y1="12" x2="22.3" y2="12" />
    </svg>
  );
}

function IconChevronRight({ size = 14, style }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="square" strokeLinejoin="round" aria-hidden="true" style={style}>
      <path d="M8 4 L16 12 L8 20" />
    </svg>
  );
}

function IconChevronDown({ size = 12 }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="square" strokeLinejoin="round" aria-hidden="true">
      <path d="M4 8 L12 16 L20 8" />
    </svg>
  );
}

function IconSwitch({ size = 14 }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="square" strokeLinejoin="round" aria-hidden="true">
      <path d="M4 8 h13 M13 4.5 L17 8 L13 11.5" />
      <path d="M20 16 H7 M11 12.5 L7 16 L11 19.5" />
    </svg>
  );
}

function IconPulse({ size = 8 }) {
  return (
    <span style={{ position: "relative", width: size, height: size, display: "inline-block" }}>
      <span style={{ position: "absolute", inset: 0, background: "currentColor", borderRadius: "50%" }} />
      <span style={{
        position: "absolute", inset: 0, background: "currentColor", borderRadius: "50%",
        animation: "solo-pulse-ring 1.6s cubic-bezier(0,0,0.2,1) infinite",
      }} />
      <style>{`
        @keyframes solo-pulse-ring {
          0%   { transform: scale(1);   opacity: 0.55; }
          70%  { transform: scale(2.8); opacity: 0;    }
          100% { transform: scale(2.8); opacity: 0;    }
        }
      `}</style>
    </span>
  );
}

// Shared sidebar nav-item button — used identically by AdminShell (light,
// `dark=false`) and ResellerShell (dark, `dark=true`) so both shells'
// nav rows behave and feel exactly the same: active state is a solid
// 2px bar on the left edge (not a whole-row tint alone, so it reads at
// a glance even out of the corner of your eye) plus a subtle background
// tint; hover nudges the icon+label 2px to the right and lightens the
// background — small, quick, not distracting.
// Lives here (not in admin-shell.jsx) because reseller-shell.jsx loads
// BEFORE admin-shell.jsx (see index.html) but both need this button —
// portal-icons.jsx loads before either, so this is the shared home.
function ShellNavButton({ label, Icon, active, onClick, testId, dark }) {
  const [hover, setHover] = useState(false);
  const fg = dark ? "#fff" : "#000";
  const fgDim = dark ? "rgba(255,255,255,0.55)" : "rgba(0,0,0,0.55)";
  const tint = dark ? "rgba(255,255,255,0.08)" : "rgba(0,0,0,0.05)";
  const tintHover = dark ? "rgba(255,255,255,0.04)" : "rgba(0,0,0,0.025)";
  const bar = dark ? "#fff" : "#000";
  return (
    <button
      type="button" onClick={onClick} data-testid={testId}
      onMouseEnter={() => setHover(true)} onMouseLeave={() => setHover(false)}
      style={{
        background: active ? tint : hover ? tintHover : "none",
        border: "none",
        borderLeft: `2px solid ${active ? bar : "transparent"}`,
        color: active ? fg : fgDim,
        textAlign: "left", cursor: "pointer",
        padding: "11px 20px 11px 18px",
        display: "flex", alignItems: "center", gap: 12,
        fontFamily: "var(--font-body)", fontSize: 12.5,
        fontWeight: active ? 600 : 500, letterSpacing: "0.04em",
        transition: "background 140ms, border-color 140ms, color 140ms",
        width: "100%",
      }}
    >
      <span style={{
        display: "flex", alignItems: "center", justifyContent: "center",
        width: 18, flexShrink: 0,
        transform: hover && !active ? "translateX(2px)" : "translateX(0)",
        transition: "transform 140ms",
      }}>
        {Icon && <Icon size={17} />}
      </span>
      <span style={{
        transform: hover && !active ? "translateX(2px)" : "translateX(0)",
        transition: "transform 140ms",
      }}>{label}</span>
    </button>
  );
}

Object.assign(window, {
  IconOverview, IconQuote, IconOrders, IconInvoices, IconPurchaseOrders,
  IconAssets, IconPriceList, IconCustomers, IconApprovals, IconSpecSheets,
  IconTicket, IconTicketList, IconSettings, IconStaff, IconSignOut,
  IconMissionControl, IconChevronRight, IconChevronDown, IconSwitch, IconPulse,
  ShellNavButton,
});
