/* global React */
// Line-icon set (2-2.5px stroke). All icons accept size + className.

const Icon = ({ children, size = 22, strokeWidth = 2.2, className, viewBox = "0 0 24 24" }) =>
  React.createElement(
    "svg",
    {
      width: size,
      height: size,
      viewBox,
      fill: "none",
      stroke: "currentColor",
      strokeWidth,
      strokeLinecap: "round",
      strokeLinejoin: "round",
      className,
      "aria-hidden": "true"
    },
    children
  );

// Channel icons
const IconWhatsApp = (p) => <Icon {...p}><path d="M3 21l2-5.5A8.5 8.5 0 1 1 8.5 19L3 21Z" /><path d="M8.5 9.5c.5 2 1.5 3 3 4l1.5-1.2c.4-.3.9-.4 1.4-.2l2.4 1c.4.2.7.6.7 1v1.4c0 .6-.4 1.2-1 1.4-3.6.8-8.4-2-9.2-5.6-.1-.6.3-1.2.8-1.4l1.3-.6c.5-.2 1-.1 1.4.2L11 10" /></Icon>;
const IconVoice = (p) => <Icon {...p}><path d="M4 9v6M8 6v12M12 4v16M16 7v10M20 10v4" /></Icon>;
const IconWebChat = (p) => <Icon {...p}><path d="M4 6h16v10H10l-4 4v-4H4z" /><path d="M8 10h.01M12 10h.01M16 10h.01" /></Icon>;
const IconMobile = (p) => <Icon {...p}><rect x="7" y="3" width="10" height="18" rx="2" /><path d="M11 18h2" /></Icon>;
const IconInstagram = (p) => <Icon {...p}><rect x="3" y="3" width="18" height="18" rx="5" /><circle cx="12" cy="12" r="4" /><circle cx="17.5" cy="6.5" r="0.6" fill="currentColor" stroke="none" /></Icon>;
const IconEmail = (p) => <Icon {...p}><rect x="3" y="5" width="18" height="14" rx="2" /><path d="m3 7 9 6 9-6" /></Icon>;
const IconHeadset = (p) => <Icon {...p}><path d="M4 13a8 8 0 0 1 16 0v4a2 2 0 0 1-2 2h-2v-6h4M4 13v4a2 2 0 0 0 2 2h2v-6H4" /></Icon>;

// Capability icons
const IconWelcome = (p) => <Icon {...p}><circle cx="12" cy="8" r="4" /><path d="M4 21c0-4 4-6 8-6s8 2 8 6" /></Icon>;
const IconDoc = (p) => <Icon {...p}><path d="M7 3h7l5 5v13a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Z" /><path d="M14 3v5h5M9 13h6M9 17h4" /></Icon>;
const IconChart = (p) => <Icon {...p}><path d="M4 4v17h17" /><path d="M8 16v-4M13 16V9M18 16v-6" /></Icon>;
const IconCalendar = (p) => <Icon {...p}><rect x="3" y="5" width="18" height="16" rx="2" /><path d="M3 10h18M8 3v4M16 3v4" /><circle cx="8" cy="15" r="0.7" fill="currentColor" stroke="none" /><circle cx="12" cy="15" r="0.7" fill="currentColor" stroke="none" /><circle cx="16" cy="15" r="0.7" fill="currentColor" stroke="none" /></Icon>;
const IconCart = (p) => <Icon {...p}><path d="M3 4h2l2 12h12l2-8H7" /><circle cx="9" cy="20" r="1.2" /><circle cx="18" cy="20" r="1.2" /></Icon>;
const IconCopilot = (p) => <Icon {...p}><path d="M12 3 4 7v6c0 4 3.5 7 8 8 4.5-1 8-4 8-8V7l-8-4Z" /><path d="m9 12 2 2 4-4" /></Icon>;

// Sector icons
const IconShield = (p) => <Icon {...p}><path d="M12 3 4 6v7c0 4 3.5 7 8 8 4.5-1 8-4 8-8V6l-8-3Z" /><path d="M9 12h6M12 9v6" /></Icon>;
const IconCar = (p) => <Icon {...p}><path d="M5 17h14M3 17v-4l2-5h14l2 5v4M5 17v2h3v-2M16 17v2h3v-2" /><circle cx="8" cy="14" r="1.2" /><circle cx="16" cy="14" r="1.2" /></Icon>;
const IconBag = (p) => <Icon {...p}><path d="M5 8h14l-1 12H6L5 8Z" /><path d="M9 8V6a3 3 0 0 1 6 0v2" /></Icon>;
const IconHealth = (p) => <Icon {...p}><path d="M12 21s-7-5-7-11a4 4 0 0 1 7-2 4 4 0 0 1 7 2c0 6-7 11-7 11Z" /><path d="M9 11h2v-2h2v2h2v2h-2v2h-2v-2H9z" /></Icon>;
const IconFinance = (p) => <Icon {...p}><rect x="3" y="6" width="18" height="13" rx="2" /><path d="M3 11h18" /><circle cx="17" cy="15" r="1.2" /></Icon>;
const IconTelecom = (p) => <Icon {...p}><path d="M4 14a14 14 0 0 1 16 0M7 17a9 9 0 0 1 10 0M10 20a4 4 0 0 1 4 0" /><circle cx="12" cy="9" r="0.8" fill="currentColor" stroke="none" /></Icon>;
const IconTransit = (p) => <Icon {...p}><rect x="5" y="3" width="14" height="14" rx="2" /><path d="M5 11h14M9 17v3M15 17v3" /><circle cx="9" cy="14" r="0.7" fill="currentColor" stroke="none" /><circle cx="15" cy="14" r="0.7" fill="currentColor" stroke="none" /></Icon>;

// UI icons
const IconArrow = (p) => <Icon {...p}><path d="M5 12h14M13 6l6 6-6 6" /></Icon>;
const IconArrowSm = (p) => <Icon {...p} size={p.size||16}><path d="M5 12h14M13 6l6 6-6 6" /></Icon>;
const IconCheck = (p) => <Icon {...p}><path d="m5 12 5 5 9-11" /></Icon>;
const IconX = (p) => <Icon {...p}><path d="M6 6l12 12M18 6 6 18" /></Icon>;
const IconPlay = (p) => <Icon {...p}><path d="M7 4v16l13-8L7 4Z" /></Icon>;
const IconSun = (p) => <Icon {...p}><circle cx="12" cy="12" r="4" /><path d="M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M4.93 19.07l1.41-1.41M17.66 6.34l1.41-1.41" /></Icon>;
const IconMoon = (p) => <Icon {...p}><path d="M21 13.5A8.5 8.5 0 1 1 10.5 3a7 7 0 0 0 10.5 10.5Z" /></Icon>;
const IconCloud = (p) => <Icon {...p}><path d="M7 18a4 4 0 0 1 0-8 5 5 0 0 1 9.6-1.4A4 4 0 0 1 17 18H7Z" /></Icon>;
const IconShieldCheck = (p) => <Icon {...p}><path d="M12 3 4 6v7c0 4 3.5 7 8 8 4.5-1 8-4 8-8V6l-8-3Z" /><path d="m9 12 2.2 2.2L15 10" /></Icon>;
const IconGauge = (p) => <Icon {...p}><path d="M4 16a8 8 0 1 1 16 0" /><path d="m13 10-3 5" /><circle cx="12" cy="16" r="0.7" fill="currentColor" stroke="none" /></Icon>;
const IconBolt = (p) => <Icon {...p}><path d="M13 3 4 14h7l-1 7 9-11h-7l1-7Z" /></Icon>;
const IconLinkedIn = (p) => <Icon {...p}><rect x="3" y="3" width="18" height="18" rx="3" /><path d="M8 10v7M8 7v.01M12 17v-7M12 14c0-2 1-4 3-4s3 2 3 4v3" /></Icon>;
const IconTwitter = (p) => <Icon {...p}><path d="M4 4l7 9-7 7h3l5.5-5.5L17 20h3l-7.5-9.5L19 4h-3l-4.5 4.5L8 4H4Z" /></Icon>;
const IconYoutube = (p) => <Icon {...p}><rect x="3" y="6" width="18" height="12" rx="3" /><path d="m11 9 4 3-4 3V9Z" fill="currentColor" stroke="none" /></Icon>;
const IconGlobe = (p) => <Icon {...p}><circle cx="12" cy="12" r="9" /><path d="M3 12h18M12 3c2.8 3 2.8 15 0 18M12 3c-2.8 3-2.8 15 0 18" /></Icon>;

// Kognitera brand mark — served from assets/icon_{dark,light}.svg. Renders both
// variants and lets CSS in styles.css hide the wrong one based on data-theme,
// so no theme prop has to thread through callers.
const KogniteraMark = ({ size = 28, className, style }) => {
  const h = Math.round(size * 505 / 450);
  const cls = (variant) => `km km-${variant}${className ? " " + className : ""}`;
  // Don't put `display` in inline style — CSS theme rules must be free to toggle
  // it to `none` for the inactive variant.
  const imgStyle = { width: size, height: h, ...style };
  return (
    <span className="km-wrap" style={{ width: size, height: h, ...style }} aria-hidden="true">
      <img src="assets/icon_dark.svg"  alt="" className={cls("dark")}  style={imgStyle} />
      <img src="assets/icon_light.svg" alt="" className={cls("light")} style={imgStyle} />
    </span>
  );
};

// Logo K mark - thicker stroke version of brand (kept for backward compatibility)
const LogoMark = ({ size = 22, gradient = true }) => (
  <KogniteraMark size={size} color={gradient ? undefined : "currentColor"} />
);

Object.assign(window, {
  Icon,
  IconWhatsApp, IconVoice, IconWebChat, IconMobile, IconInstagram, IconEmail, IconHeadset,
  IconWelcome, IconDoc, IconChart, IconCalendar, IconCart, IconCopilot,
  IconShield, IconCar, IconBag, IconHealth, IconFinance, IconTelecom, IconTransit,
  IconArrow, IconArrowSm, IconCheck, IconX, IconPlay, IconSun, IconMoon,
  IconCloud, IconShieldCheck, IconGauge, IconBolt,
  IconLinkedIn, IconTwitter, IconYoutube, IconGlobe,
  LogoMark, KogniteraMark
});
