// clamp-svgs.jsx — Procedural engineering-drawing clamp icons.
// Each clamp is a top-down or front view rendered with simple primitives:
// rectangles (body), circles (pipe + bolt holes), lines (centerlines, dimensions).
// No realistic illustration — pure technical schematic.

const { useState } = React;

const SCH = {
  stroke: "currentColor",
  strokeWidth: 1.6,
  fill: "none",
  vectorEffect: "non-scaling-stroke",
};

// --- Standard DIN 3015-1 single clamp (front view)
function ClampStandard({ size = 200, showDims = false, accent = "#15524A" }) {
  return (
    <svg viewBox="0 0 200 160" width="100%" height="100%" style={{ color: "var(--ink)" }}>
      {/* clamp body — split halves */}
      <rect x="40" y="40" width="120" height="40" {...SCH} />
      <rect x="40" y="80" width="120" height="40" {...SCH} />
      {/* center pipe */}
      <circle cx="100" cy="80" r="28" {...SCH} />
      <circle cx="100" cy="80" r="22" {...SCH} fill={accent} fillOpacity="0.06" />
      {/* centerlines */}
      <line x1="100" y1="20" x2="100" y2="140" stroke="currentColor" strokeWidth="0.5" strokeDasharray="3 3" opacity="0.4" />
      <line x1="20" y1="80" x2="180" y2="80" stroke="currentColor" strokeWidth="0.5" strokeDasharray="3 3" opacity="0.4" />
      {/* bolts (left/right) */}
      <circle cx="56" cy="80" r="5" {...SCH} />
      <circle cx="144" cy="80" r="5" {...SCH} />
      <circle cx="56" cy="80" r="1.5" fill="currentColor" />
      <circle cx="144" cy="80" r="1.5" fill="currentColor" />
      {/* mounting holes */}
      <circle cx="50" cy="60" r="2" fill="currentColor" opacity="0.3" />
      <circle cx="150" cy="60" r="2" fill="currentColor" opacity="0.3" />
      <circle cx="50" cy="100" r="2" fill="currentColor" opacity="0.3" />
      <circle cx="150" cy="100" r="2" fill="currentColor" opacity="0.3" />
      {showDims && (
        <g style={{ fontFamily: "var(--font-mono)", fontSize: "9px" }} fill={accent}>
          <line x1="40" y1="148" x2="160" y2="148" stroke={accent} strokeWidth="0.8" />
          <line x1="40" y1="144" x2="40" y2="152" stroke={accent} strokeWidth="0.8" />
          <line x1="160" y1="144" x2="160" y2="152" stroke={accent} strokeWidth="0.8" />
          <text x="100" y="158" textAnchor="middle">B = 120</text>
        </g>
      )}
    </svg>
  );
}

// --- Heavy DIN 3015-2
function ClampHeavy({ size = 200, accent = "#15524A" }) {
  return (
    <svg viewBox="0 0 200 160" width="100%" height="100%" style={{ color: "var(--ink)" }}>
      <rect x="32" y="32" width="136" height="48" {...SCH} />
      <rect x="32" y="80" width="136" height="48" {...SCH} />
      <circle cx="100" cy="80" r="34" {...SCH} />
      <circle cx="100" cy="80" r="28" {...SCH} fill={accent} fillOpacity="0.06" />
      <line x1="100" y1="14" x2="100" y2="146" stroke="currentColor" strokeWidth="0.5" strokeDasharray="3 3" opacity="0.4" />
      {/* heavy bolts */}
      <circle cx="48" cy="80" r="7" {...SCH} strokeWidth="2" />
      <circle cx="152" cy="80" r="7" {...SCH} strokeWidth="2" />
      <circle cx="48" cy="80" r="2.5" fill="currentColor" />
      <circle cx="152" cy="80" r="2.5" fill="currentColor" />
      {/* extra cap plate */}
      <rect x="28" y="24" width="144" height="8" {...SCH} />
      <rect x="28" y="128" width="144" height="8" {...SCH} />
      {/* corner mounts */}
      <circle cx="40" cy="28" r="2.5" fill="currentColor" opacity="0.4" />
      <circle cx="160" cy="28" r="2.5" fill="currentColor" opacity="0.4" />
      <circle cx="40" cy="132" r="2.5" fill="currentColor" opacity="0.4" />
      <circle cx="160" cy="132" r="2.5" fill="currentColor" opacity="0.4" />
    </svg>
  );
}

// --- Twin (DIN 3015-3)
function ClampTwin({ size = 200, accent = "#15524A" }) {
  return (
    <svg viewBox="0 0 220 160" width="100%" height="100%" style={{ color: "var(--ink)" }}>
      <rect x="20" y="44" width="180" height="36" {...SCH} />
      <rect x="20" y="80" width="180" height="36" {...SCH} />
      <circle cx="74" cy="80" r="24" {...SCH} />
      <circle cx="74" cy="80" r="18" {...SCH} fill={accent} fillOpacity="0.06" />
      <circle cx="146" cy="80" r="24" {...SCH} />
      <circle cx="146" cy="80" r="18" {...SCH} fill={accent} fillOpacity="0.06" />
      <line x1="74" y1="24" x2="74" y2="140" stroke="currentColor" strokeWidth="0.5" strokeDasharray="3 3" opacity="0.4" />
      <line x1="146" y1="24" x2="146" y2="140" stroke="currentColor" strokeWidth="0.5" strokeDasharray="3 3" opacity="0.4" />
      <circle cx="34" cy="80" r="5" {...SCH} />
      <circle cx="110" cy="80" r="5" {...SCH} />
      <circle cx="186" cy="80" r="5" {...SCH} />
      <circle cx="34" cy="80" r="1.5" fill="currentColor" />
      <circle cx="110" cy="80" r="1.5" fill="currentColor" />
      <circle cx="186" cy="80" r="1.5" fill="currentColor" />
    </svg>
  );
}

// --- Stainless (with hatching to indicate steel)
function ClampStainless({ accent = "#15524A" }) {
  return (
    <svg viewBox="0 0 200 160" width="100%" height="100%" style={{ color: "var(--ink)" }}>
      <defs>
        <pattern id="hatch-ss" patternUnits="userSpaceOnUse" width="6" height="6" patternTransform="rotate(45)">
          <line x1="0" y1="0" x2="0" y2="6" stroke="currentColor" strokeWidth="0.8" opacity="0.25" />
        </pattern>
      </defs>
      <rect x="40" y="40" width="120" height="40" fill="url(#hatch-ss)" />
      <rect x="40" y="80" width="120" height="40" fill="url(#hatch-ss)" />
      <rect x="40" y="40" width="120" height="40" {...SCH} />
      <rect x="40" y="80" width="120" height="40" {...SCH} />
      <circle cx="100" cy="80" r="28" fill="var(--paper)" />
      <circle cx="100" cy="80" r="28" {...SCH} />
      <circle cx="100" cy="80" r="22" {...SCH} />
      <line x1="100" y1="20" x2="100" y2="140" stroke="currentColor" strokeWidth="0.5" strokeDasharray="3 3" opacity="0.4" />
      <circle cx="56" cy="80" r="5" {...SCH} fill="var(--paper)" />
      <circle cx="144" cy="80" r="5" {...SCH} fill="var(--paper)" />
      <circle cx="56" cy="80" r="1.5" fill="currentColor" />
      <circle cx="144" cy="80" r="1.5" fill="currentColor" />
    </svg>
  );
}

// --- PP / Polypropylene (rounded body, thicker outline)
function ClampPP({ accent = "#15524A" }) {
  return (
    <svg viewBox="0 0 200 160" width="100%" height="100%" style={{ color: "var(--ink)" }}>
      <rect x="38" y="40" width="124" height="40" rx="6" {...SCH} strokeWidth="2" />
      <rect x="38" y="80" width="124" height="40" rx="6" {...SCH} strokeWidth="2" />
      <circle cx="100" cy="80" r="28" {...SCH} />
      <circle cx="100" cy="80" r="22" {...SCH} fill={accent} fillOpacity="0.06" />
      <line x1="100" y1="20" x2="100" y2="140" stroke="currentColor" strokeWidth="0.5" strokeDasharray="3 3" opacity="0.4" />
      <circle cx="56" cy="80" r="5" {...SCH} />
      <circle cx="144" cy="80" r="5" {...SCH} />
      <circle cx="56" cy="80" r="1.5" fill="currentColor" />
      <circle cx="144" cy="80" r="1.5" fill="currentColor" />
      {/* PP texture indicator */}
      <circle cx="60" cy="50" r="1.5" fill="currentColor" opacity="0.4" />
      <circle cx="140" cy="50" r="1.5" fill="currentColor" opacity="0.4" />
      <circle cx="60" cy="110" r="1.5" fill="currentColor" opacity="0.4" />
      <circle cx="140" cy="110" r="1.5" fill="currentColor" opacity="0.4" />
    </svg>
  );
}

// --- Cushion / rubber-insert
function ClampCushion({ accent = "#15524A" }) {
  return (
    <svg viewBox="0 0 200 160" width="100%" height="100%" style={{ color: "var(--ink)" }}>
      <rect x="40" y="40" width="120" height="40" {...SCH} />
      <rect x="40" y="80" width="120" height="40" {...SCH} />
      {/* outer pipe seat */}
      <circle cx="100" cy="80" r="30" {...SCH} />
      {/* cushion layer (dashed) */}
      <circle cx="100" cy="80" r="25" stroke="currentColor" strokeWidth="1.2" fill="none" strokeDasharray="4 3" />
      {/* pipe */}
      <circle cx="100" cy="80" r="20" {...SCH} fill={accent} fillOpacity="0.08" />
      <line x1="100" y1="20" x2="100" y2="140" stroke="currentColor" strokeWidth="0.5" strokeDasharray="3 3" opacity="0.4" />
      <circle cx="56" cy="80" r="5" {...SCH} />
      <circle cx="144" cy="80" r="5" {...SCH} />
      <circle cx="56" cy="80" r="1.5" fill="currentColor" />
      <circle cx="144" cy="80" r="1.5" fill="currentColor" />
    </svg>
  );
}

// --- Weld plate
function WeldPlate({ accent = "#15524A" }) {
  return (
    <svg viewBox="0 0 200 160" width="100%" height="100%" style={{ color: "var(--ink)" }}>
      <rect x="30" y="55" width="140" height="50" {...SCH} />
      <line x1="30" y1="65" x2="170" y2="65" stroke="currentColor" strokeWidth="0.8" />
      <line x1="30" y1="95" x2="170" y2="95" stroke="currentColor" strokeWidth="0.8" />
      {/* threaded studs */}
      <circle cx="60" cy="80" r="6" {...SCH} />
      <circle cx="100" cy="80" r="6" {...SCH} />
      <circle cx="140" cy="80" r="6" {...SCH} />
      <circle cx="60" cy="80" r="2" fill="currentColor" />
      <circle cx="100" cy="80" r="2" fill="currentColor" />
      <circle cx="140" cy="80" r="2" fill="currentColor" />
      {/* weld seam zigzag */}
      <path d="M 30 120 L 38 116 L 46 120 L 54 116 L 62 120 L 70 116 L 78 120 L 86 116 L 94 120 L 102 116 L 110 120 L 118 116 L 126 120 L 134 116 L 142 120 L 150 116 L 158 120 L 166 116 L 170 120" stroke={accent} strokeWidth="1.2" fill="none" />
      <text x="30" y="42" style={{ fontFamily: "var(--font-mono)", fontSize: "9px" }} fill="currentColor" opacity="0.6">WELD PLATE — DIN 3015</text>
    </svg>
  );
}

// --- Accessory: cover plate
function CoverPlate({ accent = "#15524A" }) {
  return (
    <svg viewBox="0 0 200 160" width="100%" height="100%" style={{ color: "var(--ink)" }}>
      <rect x="30" y="50" width="140" height="60" {...SCH} />
      <rect x="40" y="60" width="120" height="40" {...SCH} strokeDasharray="3 3" opacity="0.6" />
      <circle cx="50" cy="60" r="3" {...SCH} />
      <circle cx="150" cy="60" r="3" {...SCH} />
      <circle cx="50" cy="100" r="3" {...SCH} />
      <circle cx="150" cy="100" r="3" {...SCH} />
      <line x1="60" y1="80" x2="140" y2="80" stroke={accent} strokeWidth="1.5" />
    </svg>
  );
}

// --- U-bolt clamp (vertical view: U-bolt over pipe with mounting plate)
function ClampUbolt({ accent = "#15524A" }) {
  return (
    <svg viewBox="0 0 200 160" width="100%" height="100%" style={{ color: "var(--ink)" }}>
      {/* Mounting plate */}
      <rect x="40" y="108" width="120" height="14" {...SCH} />
      {/* U-bolt: arc over pipe + two vertical legs through plate */}
      <path d="M 76 108 L 76 70 A 24 24 0 0 1 124 70 L 124 108" {...SCH} strokeWidth="2.2" />
      {/* Pipe inside U */}
      <circle cx="100" cy="76" r="20" {...SCH} fill={accent} fillOpacity="0.06" />
      <circle cx="100" cy="76" r="14" {...SCH} />
      {/* Center & ground lines */}
      <line x1="100" y1="20" x2="100" y2="148" stroke="currentColor" strokeWidth="0.5" strokeDasharray="3 3" opacity="0.4" />
      <line x1="20" y1="122" x2="180" y2="122" stroke="currentColor" strokeWidth="0.8" />
      {/* Nuts at base of U-bolt legs */}
      <rect x="70" y="122" width="12" height="8" {...SCH} />
      <rect x="118" y="122" width="12" height="8" {...SCH} />
      <circle cx="76" cy="126" r="1.5" fill="currentColor" />
      <circle cx="124" cy="126" r="1.5" fill="currentColor" />
      {/* Mounting holes in plate */}
      <circle cx="50" cy="115" r="2.5" fill="currentColor" opacity="0.35" />
      <circle cx="150" cy="115" r="2.5" fill="currentColor" opacity="0.35" />
    </svg>
  );
}

// --- Metal tube clamp (heavier line weight + cross-section hatch indicating metal body)
function ClampMetal({ accent = "#15524A" }) {
  return (
    <svg viewBox="0 0 200 160" width="100%" height="100%" style={{ color: "var(--ink)" }}>
      <defs>
        <pattern id="hatch-metal" patternUnits="userSpaceOnUse" width="5" height="5" patternTransform="rotate(-45)">
          <line x1="0" y1="0" x2="0" y2="5" stroke="currentColor" strokeWidth="0.6" opacity="0.22" />
        </pattern>
      </defs>
      <rect x="36" y="38" width="128" height="42" fill="url(#hatch-metal)" />
      <rect x="36" y="80" width="128" height="42" fill="url(#hatch-metal)" />
      <rect x="36" y="38" width="128" height="42" {...SCH} strokeWidth="2" />
      <rect x="36" y="80" width="128" height="42" {...SCH} strokeWidth="2" />
      <circle cx="100" cy="80" r="28" fill="var(--paper)" />
      <circle cx="100" cy="80" r="28" {...SCH} strokeWidth="2" />
      <circle cx="100" cy="80" r="22" {...SCH} />
      {/* Cross-hatch second direction */}
      <circle cx="100" cy="80" r="22" {...SCH} strokeDasharray="2 2" opacity="0.4" />
      <line x1="100" y1="20" x2="100" y2="140" stroke="currentColor" strokeWidth="0.5" strokeDasharray="3 3" opacity="0.4" />
      <circle cx="56" cy="80" r="5.5" {...SCH} fill="var(--paper)" strokeWidth="2" />
      <circle cx="144" cy="80" r="5.5" {...SCH} fill="var(--paper)" strokeWidth="2" />
      <circle cx="56" cy="80" r="2" fill="currentColor" />
      <circle cx="144" cy="80" r="2" fill="currentColor" />
    </svg>
  );
}

// Dispatch by category id
function ClampArt({ kind = "standard", ...rest }) {
  switch (kind) {
    case "standard": return <ClampStandard {...rest} />;
    case "heavy": return <ClampHeavy {...rest} />;
    case "twin": return <ClampTwin {...rest} />;
    case "stainless": return <ClampStainless {...rest} />;
    case "pp": return <ClampPP {...rest} />;
    case "cushion": return <ClampCushion {...rest} />;
    case "weld": return <WeldPlate {...rest} />;
    case "cover": return <CoverPlate {...rest} />;
    case "ubolt": return <ClampUbolt {...rest} />;
    case "metal": return <ClampMetal {...rest} />;
    default: return <ClampStandard {...rest} />;
  }
}

// Icon helpers (UI)
function IconChevron({ size = 14, dir = "down" }) {
  const rot = { down: 0, up: 180, left: 90, right: -90 }[dir];
  return (
    <svg width={size} height={size} viewBox="0 0 16 16" style={{ transform: `rotate(${rot}deg)` }}>
      <path d="M3 6 L8 11 L13 6" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" />
    </svg>
  );
}
function IconSearch({ size = 16 }) {
  return (
    <svg width={size} height={size} viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.6">
      <circle cx="7" cy="7" r="4.5" />
      <line x1="10.3" y1="10.3" x2="13.5" y2="13.5" strokeLinecap="round" />
    </svg>
  );
}
function IconArrow({ size = 14 }) {
  return (
    <svg width={size} height={size} viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.6">
      <line x1="2" y1="8" x2="13" y2="8" strokeLinecap="round" />
      <polyline points="9,4 13,8 9,12" strokeLinecap="round" strokeLinejoin="round" />
    </svg>
  );
}
function IconArrowUR({ size = 14 }) {
  return (
    <svg width={size} height={size} viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.6">
      <line x1="3" y1="13" x2="12" y2="4" strokeLinecap="round" />
      <polyline points="5,4 12,4 12,11" strokeLinecap="round" strokeLinejoin="round" />
    </svg>
  );
}
function IconDownload({ size = 16 }) {
  return (
    <svg width={size} height={size} viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.5">
      <line x1="8" y1="2" x2="8" y2="11" strokeLinecap="round" />
      <polyline points="4,7 8,11 12,7" strokeLinecap="round" strokeLinejoin="round" />
      <line x1="2" y1="14" x2="14" y2="14" strokeLinecap="round" />
    </svg>
  );
}
function IconGrid({ size = 14 }) {
  return (
    <svg width={size} height={size} viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.4">
      <rect x="2" y="2" width="5" height="5" />
      <rect x="9" y="2" width="5" height="5" />
      <rect x="2" y="9" width="5" height="5" />
      <rect x="9" y="9" width="5" height="5" />
    </svg>
  );
}
function IconList({ size = 14 }) {
  return (
    <svg width={size} height={size} viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.4">
      <line x1="2" y1="4" x2="14" y2="4" strokeLinecap="round" />
      <line x1="2" y1="8" x2="14" y2="8" strokeLinecap="round" />
      <line x1="2" y1="12" x2="14" y2="12" strokeLinecap="round" />
    </svg>
  );
}
function IconFile({ size = 14 }) {
  return (
    <svg width={size} height={size} viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.4">
      <path d="M3 1 L10 1 L13 4 L13 15 L3 15 Z" />
      <path d="M10 1 L10 4 L13 4" />
    </svg>
  );
}
function IconQuote({ size = 16 }) {
  return (
    <svg width={size} height={size} viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.4">
      <path d="M2 3 L14 3 L14 11 L7 11 L4 14 L4 11 L2 11 Z" />
    </svg>
  );
}

Object.assign(window, {
  ClampArt, ClampStandard, ClampHeavy, ClampTwin, ClampStainless, ClampPP, ClampCushion, WeldPlate, CoverPlate, ClampUbolt, ClampMetal,
  IconChevron, IconSearch, IconArrow, IconArrowUR, IconDownload, IconGrid, IconList, IconFile, IconQuote,
});
