// Part type definitions, SVG drawings, density (g/cm³) for steel, and pricing constants.

const PART_TYPES = [
  {
    id: 'planka',
    name: 'Планки',
    label: 'Планка',
    short: 'PL',
    drawing: (
      <svg viewBox="0 0 120 80" fill="none" stroke="currentColor" strokeWidth="1.2">
        <rect x="14" y="28" width="92" height="24" />
        <line x1="14" y1="20" x2="106" y2="20" strokeDasharray="2 2" />
        <line x1="14" y1="60" x2="106" y2="60" strokeDasharray="2 2" />
        <text x="60" y="14" textAnchor="middle" fontFamily="monospace" fontSize="6" fill="currentColor" stroke="none">L</text>
        <text x="112" y="42" fontFamily="monospace" fontSize="6" fill="currentColor" stroke="none">H</text>
      </svg>
    ),
    fields: ['L', 'B', 'H'],
    placeholders: { L: 1500, B: 100, H: 60 },
    limits: { L: [50, 3500], B: [30, 300], H: [30, 300] },
    // volume in mm³
    volume: ({ L, B, H }) => L * B * H,
    specs: ['до 1 250 кг', 'L < 3500 мм', 'B = 30–300 мм', 'H = 30–300 мм'],
  },
  {
    id: 'val',
    name: 'Валы',
    label: 'Вал',
    short: 'VL',
    drawing: (
      <svg viewBox="0 0 120 80" fill="none" stroke="currentColor" strokeWidth="1.2">
        <rect x="14" y="32" width="92" height="16" />
        <ellipse cx="14" cy="40" rx="3" ry="8" />
        <ellipse cx="106" cy="40" rx="3" ry="8" />
        <line x1="14" y1="22" x2="106" y2="22" strokeDasharray="2 2" />
        <text x="60" y="16" textAnchor="middle" fontFamily="monospace" fontSize="6" fill="currentColor" stroke="none">L</text>
        <text x="112" y="42" fontFamily="monospace" fontSize="6" fill="currentColor" stroke="none">D</text>
      </svg>
    ),
    fields: ['L', 'D'],
    placeholders: { L: 2000, D: 180 },
    limits: { L: [50, 3500], D: [90, 300] },
    volume: ({ L, D }) => L * Math.PI * (D / 2) ** 2,
    specs: ['до 1 250 кг', 'D = 90–300 мм', 'L < 3500 мм'],
  },
  {
    id: 'val-ust',
    name: 'Валы с уступами',
    label: 'Вал с уступом',
    short: 'VU',
    drawing: (
      <svg viewBox="0 0 120 80" fill="none" stroke="currentColor" strokeWidth="1.2">
        <rect x="14" y="34" width="22" height="12" />
        <rect x="36" y="28" width="48" height="24" />
        <rect x="84" y="34" width="22" height="12" />
        <line x1="14" y1="22" x2="106" y2="22" strokeDasharray="2 2" />
        <text x="60" y="16" textAnchor="middle" fontFamily="monospace" fontSize="6" fill="currentColor" stroke="none">L</text>
        <text x="60" y="62" textAnchor="middle" fontFamily="monospace" fontSize="6" fill="currentColor" stroke="none">D / d</text>
      </svg>
    ),
    fields: ['L', 'D', 'd'],
    placeholders: { L: 2000, D: 220, d: 140 },
    limits: { L: [50, 3500], D: [100, 300], d: [90, 250] },
    // approx half D, half d
    volume: ({ L, D, d }) => (L / 2) * Math.PI * (D / 2) ** 2 + (L / 2) * Math.PI * (d / 2) ** 2,
    specs: ['до 1 250 кг', 'D = 100–300 мм', 'd = 90–250 мм', 'L < 3500 мм'],
  },
  {
    id: 'disk',
    name: 'Диски с отверстием',
    label: 'Диск',
    short: 'DK',
    drawing: (
      <svg viewBox="0 0 120 80" fill="none" stroke="currentColor" strokeWidth="1.2">
        <circle cx="60" cy="40" r="26" />
        <circle cx="60" cy="40" r="9" />
        <line x1="34" y1="40" x2="86" y2="40" strokeDasharray="2 2" />
        <text x="60" y="14" textAnchor="middle" fontFamily="monospace" fontSize="6" fill="currentColor" stroke="none">D</text>
        <text x="60" y="74" textAnchor="middle" fontFamily="monospace" fontSize="6" fill="currentColor" stroke="none">d</text>
      </svg>
    ),
    fields: ['D', 'd', 'H'],
    placeholders: { D: 400, d: 80, H: 80 },
    limits: { D: [60, 600], d: [60, 120], H: [30, 300] },
    volume: ({ D, d, H }) => H * (Math.PI * (D / 2) ** 2 - Math.PI * (d / 2) ** 2),
    specs: ['до 350 кг', 'D < 600 мм', 'd = 60–120 мм', 'H = 30–300 мм'],
  },
  {
    id: 'koltso',
    name: 'Кольца раскатные',
    label: 'Кольцо',
    short: 'KL',
    drawing: (
      <svg viewBox="0 0 120 80" fill="none" stroke="currentColor" strokeWidth="1.2">
        <circle cx="60" cy="40" r="28" />
        <circle cx="60" cy="40" r="20" />
        <text x="60" y="14" textAnchor="middle" fontFamily="monospace" fontSize="6" fill="currentColor" stroke="none">D</text>
        <text x="60" y="44" textAnchor="middle" fontFamily="monospace" fontSize="6" fill="currentColor" stroke="none">d</text>
      </svg>
    ),
    fields: ['D', 'd', 'H'],
    placeholders: { D: 600, d: 500, H: 150 },
    limits: { D: [100, 900], d: [80, 800], H: [90, 250] },
    volume: ({ D, d, H }) => H * (Math.PI * (D / 2) ** 2 - Math.PI * (d / 2) ** 2),
    specs: ['до 350 кг', 'D < 900 мм', 'd < 800 мм', 'H = 90–250 мм'],
  },
  {
    id: 'kub',
    name: 'Кубики',
    label: 'Кубик',
    short: 'KB',
    drawing: (
      <svg viewBox="0 0 120 80" fill="none" stroke="currentColor" strokeWidth="1.2">
        <rect x="34" y="22" width="40" height="40" />
        <line x1="34" y1="22" x2="46" y2="14" />
        <line x1="74" y1="22" x2="86" y2="14" />
        <line x1="74" y1="62" x2="86" y2="54" />
        <line x1="46" y1="14" x2="86" y2="14" />
        <line x1="86" y1="14" x2="86" y2="54" />
      </svg>
    ),
    fields: ['L', 'B', 'H'],
    placeholders: { L: 200, B: 200, H: 200 },
    limits: { L: [30, 300], B: [30, 300], H: [30, 300] },
    volume: ({ L, B, H }) => L * B * H,
    specs: ['до 350 кг', 'L = 30–300 мм', 'B = 30–300 мм', 'H = 30–300 мм'],
  },
];

// Steel grades grouped, with relative price multipliers (rough industry approximations)
const MATERIALS = [
  { id: 'st45',     name: 'Ст45',     cat: 'Углеродистая',     mult: 1.00 },
  { id: '40x',      name: '40Х',      cat: 'Легированная',     mult: 1.15 },
  { id: '40hn2ma',  name: '40ХН2МА',  cat: 'Легированная',     mult: 1.35 },
  { id: '18hgt',    name: '18ХГТ',    cat: 'Легированная',     mult: 1.20 },
  { id: '12h18n9t', name: '12Х18Н9Т', cat: 'Нержавеющая',      mult: 2.40 },
  { id: 'u10a',     name: 'У10А',     cat: 'Инструментальная', mult: 1.55 },
  { id: '22hnm',    name: '22ХНМ',    cat: 'Легированная',     mult: 1.30 },
  { id: '9hs',      name: '9ХС',      cat: 'Инструментальная', mult: 1.65 },
  { id: '8hm',      name: '8ХМ',      cat: 'Инструментальная', mult: 1.50 },
  { id: '38hmua',   name: '38ХМЮА',   cat: 'Легированная',     mult: 1.45 },
];

// Steel density g/cm³ ≈ 7.85
const STEEL_DENSITY = 7.85;
// Base price RUB / kg of finished forging (rough average for stamping)
const BASE_PRICE_PER_KG = 380;
// Method multipliers
const METHOD_MULT = { stamp: 1.00, forge: 1.18 };
// Quantity tiers (per-unit discount)
const QTY_DISCOUNT = (q) => {
  if (q >= 100) return 0.78;
  if (q >= 50) return 0.85;
  if (q >= 10) return 0.92;
  if (q >= 5) return 0.96;
  return 1.00;
};
// Estimate band (±%)
const ESTIMATE_BAND = 0.10;

Object.assign(window, {
  PART_TYPES, MATERIALS, STEEL_DENSITY, BASE_PRICE_PER_KG, METHOD_MULT, QTY_DISCOUNT, ESTIMATE_BAND
});
