/* Doodles + Illustrations — hand-drawn SVG library */
const { Fragment } = React;

// ---------- Networking & server glyphs (stroke-based) ----------

// Server rack — 4U with status LEDs
const Squiggle = ({ className, style }) => (
  <svg className={className} style={style} viewBox="0 0 80 120" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="square" strokeLinejoin="miter">
    <rect x="6" y="6" width="68" height="108" rx="2"/>
    {[0,1,2,3].map(i => (
      <g key={i}>
        <rect x="12" y={14 + i*24} width="56" height="18" rx="1"/>
        <circle cx="20" cy={23 + i*24} r="1.6" fill="currentColor"/>
        <circle cx="26" cy={23 + i*24} r="1.6" fill="currentColor" opacity="0.4"/>
        <line x1="34" y1={23 + i*24} x2="62" y2={23 + i*24} strokeWidth="1.2" opacity="0.6"/>
      </g>
    ))}
  </svg>
);

// Router with antennas + downlink lines
const Star = ({ className, style }) => (
  <svg className={className} style={style} viewBox="0 0 64 64" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round">
    <rect x="10" y="34" width="44" height="14" rx="2" fill="currentColor" fillOpacity="0.12"/>
    <circle cx="18" cy="41" r="1.4" fill="currentColor"/>
    <circle cx="24" cy="41" r="1.4" fill="currentColor" opacity="0.6"/>
    <circle cx="30" cy="41" r="1.4" fill="currentColor" opacity="0.6"/>
    <line x1="22" y1="34" x2="22" y2="22"/>
    <line x1="32" y1="34" x2="32" y2="14"/>
    <line x1="42" y1="34" x2="42" y2="22"/>
    <circle cx="22" cy="20" r="2"/>
    <circle cx="32" cy="12" r="2"/>
    <circle cx="42" cy="20" r="2"/>
    <line x1="10" y1="54" x2="20" y2="54" strokeWidth="2"/>
    <line x1="26" y1="54" x2="38" y2="54" strokeWidth="2" opacity="0.5"/>
    <line x1="44" y1="54" x2="54" y2="54" strokeWidth="2" opacity="0.5"/>
  </svg>
);

// Packet (small envelope with header bar)
const Sparkle = ({ className, style }) => (
  <svg className={className} style={style} viewBox="0 0 40 40" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="square">
    <rect x="6" y="10" width="28" height="20" rx="1.5" fill="currentColor" fillOpacity="0.15"/>
    <line x1="6" y1="16" x2="34" y2="16"/>
    <line x1="10" y1="22" x2="18" y2="22"/>
    <line x1="10" y1="26" x2="24" y2="26" opacity="0.6"/>
  </svg>
);

// Network switch cloud with port indicators
const CloudDoodle = ({ className, style }) => (
  <svg className={className} style={style} viewBox="0 0 100 60" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round">
    <rect x="10" y="20" width="80" height="28" rx="3" fill="currentColor" fillOpacity="0.1"/>
    {[18, 30, 42, 54, 66, 78].map((x, i) => (
      <g key={i}>
        <rect x={x-3} y="28" width="6" height="8" rx="0.5"/>
        <circle cx={x} cy="44" r="1.2" fill="currentColor" opacity={i % 2 ? 0.4 : 1}/>
      </g>
    ))}
    <text x="50" y="16" textAnchor="middle" fill="currentColor" fontSize="6" fontFamily="JetBrains Mono" letterSpacing="0.1em">SW-01</text>
  </svg>
);

// Fiber-optic curved cable between two endpoints
const ArrowCurve = ({ className, style }) => (
  <svg className={className} style={style} viewBox="0 0 130 60" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
    <path d="M8 50 Q 50 0, 100 30 T 124 22"/>
    <circle cx="8" cy="50" r="3" fill="currentColor"/>
    <circle cx="124" cy="22" r="3" fill="currentColor"/>
    <path d="M40 25 l-3 3 M 70 18 l-3 3 M 95 22 l-3 3" opacity="0.5"/>
  </svg>
);

// Ethernet cable with RJ45 connector
const ArrowSquiggle = ({ className, style }) => (
  <svg className={className} style={style} viewBox="0 0 130 30" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
    <path d="M6 18 Q 22 6, 38 18 T 70 18 T 100 18"/>
    <rect x="100" y="10" width="22" height="14" rx="1.5" fill="currentColor" fillOpacity="0.18"/>
    <rect x="106" y="6" width="4" height="6" rx="0.5"/>
    <rect x="113" y="6" width="4" height="6" rx="0.5"/>
    <circle cx="6" cy="18" r="2.4" fill="currentColor"/>
  </svg>
);

// Datacenter pod grid (servers as small bars)
const Dots = ({ className, style }) => (
  <svg className={className} style={style} viewBox="0 0 90 40" fill="none" stroke="currentColor" strokeWidth="1" strokeLinecap="square">
    {[0,1,2,3,4,5,6].map((c) => (
      [0,1,2,3].map((r) => (
        <g key={`${c}-${r}`}>
          <rect x={4 + c*12} y={2 + r*10} width="9" height="7" rx="0.5" fill="currentColor" fillOpacity={r === 1 ? 0.6 : 0.15}/>
          <circle cx={6 + c*12} cy={5.5 + r*10} r="0.6" fill="currentColor"/>
        </g>
      ))
    )).flat()}
  </svg>
);

// Broadcast / signal arcs
const Burst = ({ className, style }) => (
  <svg className={className} style={style} viewBox="0 0 60 60" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round">
    <circle cx="30" cy="42" r="3" fill="currentColor"/>
    <path d="M22 38 a 12 12 0 0 1 16 0"/>
    <path d="M16 34 a 22 22 0 0 1 28 0" opacity="0.7"/>
    <path d="M10 30 a 32 32 0 0 1 40 0" opacity="0.45"/>
    <path d="M4 26 a 42 42 0 0 1 52 0" opacity="0.2"/>
  </svg>
);

// Data flow loop with packet arrow
const LoopArrow = ({ className, style }) => (
  <svg className={className} style={style} viewBox="0 0 100 80" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
    <path d="M20 50 a 30 26 0 1 1 60 0 a 30 26 0 1 1 -60 0"/>
    <path d="M50 24 l 6 -4 M 50 24 l 6 4"/>
    <rect x="42" y="62" width="16" height="10" rx="1" fill="currentColor" fillOpacity="0.2"/>
    <line x1="46" y1="66" x2="54" y2="66" strokeWidth="1.2"/>
    <line x1="46" y1="69" x2="50" y2="69" strokeWidth="1.2" opacity="0.5"/>
  </svg>
);

// ---------- Logos / brand marks ----------

const AbsoloMark = ({ size = 32, className }) => (
  <svg className={className} width={size} height={size} viewBox="0 0 48 48" fill="none">
    <defs>
      <linearGradient id="absoloGrad" x1="0" y1="0" x2="1" y2="1">
        <stop offset="0%" stopColor="#3461FF"/>
        <stop offset="50%" stopColor="#9B7BFF"/>
        <stop offset="100%" stopColor="#FF6BA8"/>
      </linearGradient>
    </defs>
    <circle cx="24" cy="24" r="20" fill="url(#absoloGrad)"/>
    <path d="M24 12 a12 12 0 1 1 0 24 a12 12 0 0 1 0 -24 M24 18 a6 6 0 1 0 0 12 a6 6 0 0 0 0 -12 z" fill="#0A0E1A" fillRule="evenodd"/>
    <circle cx="36" cy="36" r="4" fill="#4DE0C5"/>
  </svg>
);

// ---------- Feature icons (custom outline 1.5px) ----------

const I = ({ children, color }) => (
  <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke={color || "currentColor"} strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round">
    {children}
  </svg>
);

const FeatIcons = {
  database: <I><ellipse cx="12" cy="5" rx="8" ry="3"/><path d="M4 5v6c0 1.66 3.58 3 8 3s8-1.34 8-3V5"/><path d="M4 11v6c0 1.66 3.58 3 8 3s8-1.34 8-3v-6"/></I>,
  storage: <I><path d="M3 7l9-4 9 4-9 4-9-4z"/><path d="M3 12l9 4 9-4"/><path d="M3 17l9 4 9-4"/></I>,
  ssl: <I><rect x="4" y="11" width="16" height="10" rx="2"/><path d="M8 11V7a4 4 0 1 1 8 0v4"/><circle cx="12" cy="16" r="1.2" fill="currentColor"/></I>,
  ssh: <I><rect x="3" y="4" width="18" height="14" rx="2"/><path d="M7 9l3 2-3 2"/><path d="M12 14h4"/></I>,
  snapshot: <I><path d="M3 12a9 9 0 1 0 3-6.7"/><path d="M3 4v5h5"/><circle cx="12" cy="12" r="3"/></I>,
  region: <I><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"/></I>,
  rocket: <I><path d="M5 13s-2 2-2 5c3 0 5-2 5-2"/><path d="M19 5s-7 0-11 4l-3 3 5 5 3-3c4-4 4-11 4-11s-2 1-4 3"/><circle cx="14" cy="10" r="1.4"/></I>,
  code: <I><path d="M9 7l-5 5 5 5"/><path d="M15 7l5 5-5 5"/></I>,
  git: <I><circle cx="6" cy="6" r="2.5"/><circle cx="6" cy="18" r="2.5"/><circle cx="18" cy="12" r="2.5"/><path d="M6 8.5v7"/><path d="M8.5 6h6a4 4 0 0 1 4 4v0"/></I>,
  globe: <I><circle cx="12" cy="12" r="9"/><path d="M12 3v18M3 12h18M5 7c3 2 11 2 14 0M5 17c3-2 11-2 14 0"/></I>,
  bolt: <I><path d="M13 2L4 14h7l-1 8 9-12h-7l1-8z"/></I>,
};

// ---------- Template logos ----------

const TplLogos = {
  wordpress: (
    <svg viewBox="0 0 100 100" fill="none">
      <circle cx="50" cy="50" r="46" stroke="currentColor" strokeWidth="3"/>
      <path d="M14 50c0 14 8 26 20 32L19 41c-3 3-5 6-5 9z M86 50c0-6-2-10-5-13l-15 39c12-6 20-15 20-26z M50 18c-7 0-13 2-19 5l9 27 6-19c0-3-3-5-6-5l13-8z M50 60l-11 33c4 1 7 1 11 1 5 0 9-1 13-2L52 60z" fill="currentColor"/>
    </svg>
  ),
  woocommerce: (
    <svg viewBox="0 0 100 100" fill="none">
      <path d="M14 22 H 78 a8 8 0 0 1 8 8 v22 a8 8 0 0 1 -8 8 H 56 l-10 12 v-12 H 22 a8 8 0 0 1 -8 -8 v-22 a8 8 0 0 1 8 -8 z" fill="currentColor" opacity="0.9"/>
      <text x="50" y="50" textAnchor="middle" fill="#0A0E1A" fontSize="18" fontFamily="serif" fontStyle="italic" fontWeight="700">Woo</text>
    </svg>
  ),
  ghost: (
    <svg viewBox="0 0 100 100" fill="none" stroke="currentColor" strokeWidth="4">
      <path d="M22 24 H 78 M 22 44 H 60 M 22 64 H 78 M 22 84 H 50" strokeLinecap="round"/>
    </svg>
  ),
  laravel: (
    <svg viewBox="0 0 100 100" fill="currentColor">
      <path d="M50 18 L80 36 L80 64 L50 82 L20 64 L20 36 Z" fillOpacity="0.15" stroke="currentColor" strokeWidth="3"/>
      <path d="M50 30 L70 42 L50 54 L30 42 Z M30 54 L50 66 L50 78 L30 66 Z M50 66 L70 54 L70 66 L50 78 Z"/>
    </svg>
  ),
  next: (
    <svg viewBox="0 0 100 100" fill="none">
      <circle cx="50" cy="50" r="46" fill="currentColor"/>
      <path d="M34 32 L34 70 L40 70 L40 42 L65 70 L72 70 L42 32 Z M60 32 L60 56 L66 64 L66 32 Z" fill="#0A0E1A"/>
    </svg>
  ),
  express: (
    <svg viewBox="0 0 100 100" fill="currentColor">
      <text x="50" y="60" textAnchor="middle" fontSize="38" fontFamily="monospace" fontWeight="700">EX</text>
      <rect x="20" y="70" width="60" height="3"/>
    </svg>
  ),
  fastapi: (
    <svg viewBox="0 0 100 100" fill="none">
      <circle cx="50" cy="50" r="40" fill="currentColor"/>
      <path d="M52 22 L34 56 L48 56 L44 78 L66 44 L52 44 Z" fill="#0A0E1A"/>
    </svg>
  ),
  static: (
    <svg viewBox="0 0 100 100" fill="none" stroke="currentColor" strokeWidth="3">
      <rect x="14" y="20" width="72" height="60" rx="4"/>
      <path d="M14 32 H 86" strokeWidth="2"/>
      <circle cx="22" cy="26" r="1.5" fill="currentColor"/>
      <circle cx="28" cy="26" r="1.5" fill="currentColor"/>
      <circle cx="34" cy="26" r="1.5" fill="currentColor"/>
      <path d="M24 46 H 76 M 24 56 H 60 M 24 66 H 70" strokeWidth="2" opacity="0.5"/>
    </svg>
  ),
  django: (
    <svg viewBox="0 0 100 100" fill="currentColor">
      <text x="50" y="62" textAnchor="middle" fontSize="32" fontFamily="serif" fontWeight="800">Dj</text>
    </svg>
  ),
};

// ---------- Illustration: Sites mode mini-mock ----------

const SitesIllustration = () => (
  <svg viewBox="0 0 480 200" fill="none" xmlns="http://www.w3.org/2000/svg">
    <defs>
      <linearGradient id="sitesShade" x1="0" y1="0" x2="0" y2="1">
        <stop offset="0%" stopColor="#1B2228"/>
        <stop offset="100%" stopColor="#0E1316"/>
      </linearGradient>
    </defs>

    {/* Templates row */}
    {[
      { x: 30, l: "W" },
      { x: 130, l: "G" },
      { x: 230, l: "L" },
      { x: 330, l: "S" },
    ].map((t, i) => (
      <g key={i}>
        <rect x={t.x} y={20} width={80} height={100} rx={6} fill="url(#sitesShade)" stroke="#2A323C"/>
        <circle cx={t.x + 40} cy={56} r={18} fill="#E8742C" opacity="0.18"/>
        <text x={t.x + 40} y={62} textAnchor="middle" fill="#E8742C" fontSize="20" fontWeight="700" fontFamily="Inter">{t.l}</text>
        <rect x={t.x + 14} y={86} width={52} height={4} rx={1} fill="#2A323C"/>
        <rect x={t.x + 20} y={96} width={40} height={3} rx={1} fill="#1E242D"/>
      </g>
    ))}

    {/* Deploy button */}
    <rect x={30} y={140} width={380} height={42} rx={6} fill="#E8742C"/>
    <text x={220} y={167} textAnchor="middle" fill="#0A0C0E" fontSize="14" fontWeight="600" fontFamily="Inter">Deploy in 1 click →</text>

    {/* Cursor */}
    <g transform="translate(310, 152)">
      <path d="M0 0 L 0 14 L 4 11 L 7 17 L 10 16 L 7 10 L 12 9 Z" fill="white" stroke="#0A0C0E" strokeWidth="1"/>
    </g>
  </svg>
);

// ---------- Illustration: Apps mode mini-mock ----------

const AppsIllustration = () => (
  <svg viewBox="0 0 480 200" fill="none" xmlns="http://www.w3.org/2000/svg">
    {/* Pipeline: git → build → deploy */}
    {[
      { x: 30,  c: "#6E7A8A", lbl: "git push", icon: "G" },
      { x: 175, c: "#F0B442", lbl: "build",    icon: "⚙" },
      { x: 320, c: "#E8742C", lbl: "live",     icon: "▶" },
    ].map((s, i) => (
      <g key={i}>
        <rect x={s.x} y={50} width={130} height={80} rx={6} fill="#0E1316" stroke="#2A323C"/>
        <circle cx={s.x + 30} cy={86} r={18} fill={s.c} fillOpacity="0.16"/>
        <text x={s.x + 30} y={92} textAnchor="middle" fill={s.c} fontSize="18" fontWeight="700">{s.icon}</text>
        <text x={s.x + 56} y={82} fill="#7B8593" fontSize="11" fontWeight="500" fontFamily="JetBrains Mono">$</text>
        <text x={s.x + 56} y={96} fill={s.c} fontSize="13" fontWeight="500" fontFamily="JetBrains Mono">{s.lbl}</text>
      </g>
    ))}

    {/* Connectors */}
    <path d="M161 90 L 174 90" stroke="#E8742C" strokeWidth="1.5" strokeDasharray="3 3" opacity="0.6"/>
    <path d="M306 90 L 319 90" stroke="#E8742C" strokeWidth="1.5" strokeDasharray="3 3" opacity="0.6"/>

    {/* Top: detected framework */}
    <g>
      <rect x={30} y={20} width={420} height={22} rx={4} fill="#11151A" stroke="#1E242D"/>
      <circle cx={42} cy={31} r={3} fill="#E8742C"/>
      <text x={54} y={35} fill="#7B8593" fontSize="11" fontFamily="JetBrains Mono">detected:</text>
      <text x={120} y={35} fill="#E8742C" fontSize="11" fontFamily="JetBrains Mono">Next.js 15</text>
      <text x={200} y={35} fill="#7B8593" fontSize="11" fontFamily="JetBrains Mono">node 22.x · pnpm 9</text>
    </g>

    {/* Bottom URL */}
    <g>
      <rect x={30} y={148} width={420} height={32} rx={4} fill="#0E1316" stroke="#2A323C"/>
      <circle cx={44} cy={164} r={3} fill="#E8742C"/>
      <text x={56} y={168} fill="#B6BFC9" fontSize="12" fontFamily="JetBrains Mono">https://</text>
      <text x={110} y={168} fill="#EDF1F5" fontSize="12" fontFamily="JetBrains Mono" fontWeight="600">acme-shop.absolo.app</text>
      <text x={300} y={168} fill="#7B8593" fontSize="11" fontFamily="JetBrains Mono">· 200 OK · 48ms</text>
    </g>
  </svg>
);

// ---------- Sparkline chart used in dashboard ----------

const Sparkline = () => {
  const points = [40,45,42,55,52,68,62,75,72,86,82,95,90,108,102,118,115,128,124,140];
  const max = 145;
  const path = points.map((p,i) => `${i === 0 ? "M" : "L"} ${i * 28} ${160 - (p/max)*140}`).join(" ");
  const area = path + ` L ${(points.length - 1) * 28} 160 L 0 160 Z`;
  return (
    <svg viewBox="0 0 540 170" width="100%" height="170" preserveAspectRatio="none">
      <defs>
        <linearGradient id="sparkF" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%" stopColor="#E8742C" stopOpacity="0.35"/>
          <stop offset="100%" stopColor="#E8742C" stopOpacity="0"/>
        </linearGradient>
      </defs>
      <path d={area} fill="url(#sparkF)"/>
      <path d={path} stroke="#E8742C" strokeWidth="2" fill="none"/>
      {points.map((p,i) => i % 4 === 0 && (
        <circle key={i} cx={i*28} cy={160 - (p/max)*140} r="2.5" fill="#E8742C"/>
      ))}
      <line x1="0" y1="160" x2="540" y2="160" stroke="#1E242D" strokeDasharray="2 4"/>
    </svg>
  );
};

Object.assign(window, {
  Squiggle, Star, Sparkle, CloudDoodle, ArrowCurve, ArrowSquiggle, Dots, Burst, LoopArrow,
  AbsoloMark, FeatIcons, TplLogos, SitesIllustration, AppsIllustration, Sparkline,
});
