// Cenniki produktowe LINEA i HORIZON (ceny sugerowane netto, +25%, kwiecień 2026).
// Dane wygenerowane z arkuszy producenta — nie edytować ręcznie wartości.

const LINEA_PRICING = {
  "widths": [
    306,
    406,
    506,
    606,
    706,
    806,
    906,
    1006
  ],
  "projections": [
    250,
    300,
    350,
    400,
    500,
    600
  ],
  "roofs": [
    {
      "id": "brak",
      "name": "Bez pokrycia dachowego",
      "prices": {
        "250": {
          "306": 7707,
          "406": 9173,
          "506": 10639,
          "606": 12106,
          "706": 14385,
          "806": 15852,
          "906": 17318,
          "1006": 18785
        },
        "300": {
          "306": 8164,
          "406": 9761,
          "506": 11358,
          "606": 12955,
          "706": 15365,
          "806": 16961,
          "906": 18558,
          "1006": 20155
        },
        "350": {
          "306": 8622,
          "406": 10349,
          "506": 12076,
          "606": 13804,
          "706": 16344,
          "806": 18071,
          "906": 19798,
          "1006": 21525
        },
        "400": {
          "306": 9080,
          "406": 10937,
          "506": 12795,
          "606": 14652,
          "706": 17323,
          "806": 19181,
          "906": 21038,
          "1006": 22896
        },
        "500": {
          "306": 9996,
          "406": 12114,
          "506": 14232,
          "606": 16350,
          "706": 19282,
          "806": 21400,
          "906": 23518,
          "1006": 25636
        },
        "600": {
          "306": 10911,
          "406": 13290,
          "506": 15669,
          "606": 18048,
          "706": 21240,
          "806": 23619,
          "906": 25998,
          "1006": 28377
        }
      }
    },
    {
      "id": "opal",
      "name": "Poliwęglan Strong Opal UV",
      "prices": {
        "250": {
          "306": 8494,
          "406": 10223,
          "506": 11952,
          "606": 13681,
          "706": 16223,
          "806": 17952,
          "906": 19681,
          "1006": 21410
        },
        "300": {
          "306": 9109,
          "406": 11021,
          "506": 12933,
          "606": 14845,
          "706": 17570,
          "806": 19481,
          "906": 21393,
          "1006": 23305
        },
        "350": {
          "306": 9725,
          "406": 11819,
          "506": 13914,
          "606": 16009,
          "706": 18916,
          "806": 21011,
          "906": 23106,
          "1006": 25200
        },
        "400": {
          "306": 10340,
          "406": 12617,
          "506": 14895,
          "606": 17172,
          "706": 20263,
          "806": 22541,
          "906": 24818,
          "1006": 27096
        },
        "500": {
          "306": 11571,
          "406": 14214,
          "506": 16857,
          "606": 19500,
          "706": 22957,
          "806": 25600,
          "906": 28243,
          "1006": 30886
        },
        "600": {
          "306": 12801,
          "406": 15810,
          "506": 18819,
          "606": 21828,
          "706": 25650,
          "806": 28659,
          "906": 31668,
          "1006": 34677
        }
      }
    },
    {
      "id": "boxgrey",
      "name": "Poliwęglan BOX Grey 133 UV",
      "prices": {
        "250": {
          "306": 8888,
          "406": 10748,
          "506": 12608,
          "606": 14468,
          "706": 17142,
          "806": 19002,
          "906": 20862,
          "1006": 22722
        },
        "300": {
          "306": 9582,
          "406": 11651,
          "506": 13720,
          "606": 15790,
          "706": 18672,
          "806": 20741,
          "906": 22811,
          "1006": 24880
        },
        "350": {
          "306": 10276,
          "406": 12554,
          "506": 14833,
          "606": 17111,
          "706": 20203,
          "806": 22481,
          "906": 24759,
          "1006": 27038
        },
        "400": {
          "306": 10970,
          "406": 13457,
          "506": 15945,
          "606": 18432,
          "706": 21733,
          "806": 24221,
          "906": 26708,
          "1006": 29196
        },
        "500": {
          "306": 12358,
          "406": 15264,
          "506": 18169,
          "606": 21075,
          "706": 24794,
          "806": 27700,
          "906": 30606,
          "1006": 33511
        },
        "600": {
          "306": 13746,
          "406": 17070,
          "506": 20394,
          "606": 23718,
          "706": 27855,
          "806": 31179,
          "906": 34503,
          "1006": 37827
        }
      }
    },
    {
      "id": "solar",
      "name": "Poliwęglan Strong SolarControl UV",
      "prices": {
        "250": {
          "306": 8691,
          "406": 10485,
          "506": 12280,
          "606": 14075,
          "706": 16682,
          "806": 18477,
          "906": 20271,
          "1006": 22066
        },
        "300": {
          "306": 9346,
          "406": 11336,
          "506": 13327,
          "606": 15317,
          "706": 18121,
          "806": 20111,
          "906": 22102,
          "1006": 24093
        },
        "350": {
          "306": 10000,
          "406": 12187,
          "506": 14373,
          "606": 16560,
          "706": 19560,
          "806": 21746,
          "906": 23933,
          "1006": 26119
        },
        "400": {
          "306": 10655,
          "406": 13037,
          "506": 15420,
          "606": 17802,
          "706": 20998,
          "806": 23381,
          "906": 25763,
          "1006": 28146
        },
        "500": {
          "306": 11964,
          "406": 14739,
          "506": 17513,
          "606": 20288,
          "706": 23875,
          "806": 26650,
          "906": 29424,
          "1006": 32199
        }
      }
    },
    {
      "id": "glass",
      "name": "Szkło VSG / ESG",
      "prices": {
        "250": {
          "306": 10581,
          "406": 13005,
          "506": 15430,
          "606": 17855,
          "706": 21092,
          "806": 23517,
          "906": 25941,
          "1006": 28366
        },
        "300": {
          "306": 11614,
          "406": 14360,
          "506": 17107,
          "606": 19853,
          "706": 23413,
          "806": 26159,
          "906": 28906,
          "1006": 31653
        },
        "350": {
          "306": 13363,
          "406": 16670,
          "506": 19978,
          "606": 23285,
          "706": 26592,
          "806": 29900,
          "906": 33207,
          "1006": 36515
        },
        "400": {
          "306": 14498,
          "406": 18161,
          "506": 21825,
          "606": 25488,
          "706": 29152,
          "806": 32815,
          "906": 36479,
          "1006": 40142
        },
        "500": {
          "306": 16768,
          "406": 21144,
          "506": 25519,
          "606": 29895,
          "706": 34271,
          "806": 38647,
          "906": 43022,
          "1006": 47398
        }
      }
    }
  ]
};

const LINEA_ADDONS = [
  {
    "name": "Klin boczny (wypełnienie szczytu)",
    "price": 399,
    "unit": "/ szt.",
    "note": "poliwęglan; szkło od 933 zł"
  },
  {
    "name": "System szyb przesuwnych",
    "price": 2884,
    "unit": "/ kpl.",
    "note": "bez szkła; ze szkłem ESG od 4 179 zł"
  },
  {
    "name": "System żaluzji pionowych",
    "price": 990,
    "unit": "/ szt.",
    "note": "regulacja światła i prywatności"
  },
  {
    "name": "Ściana pełna ALUX",
    "price": 600,
    "unit": "/ m²",
    "note": "sublimacja +160 zł/m²"
  },
  {
    "name": "Szkło ESG do zabudowy",
    "price": 216,
    "unit": "/ m²",
    "note": "ESG 8 transparentne"
  }
];

const HORIZON_PRICING = {
  "std": [
    {
      "size": "4x3",
      "glass": 18320,
      "lamele": 23507
    },
    {
      "size": "5x3",
      "glass": 22170,
      "lamele": 28854
    },
    {
      "size": "6x3",
      "glass": 24941,
      "lamele": 33062
    },
    {
      "size": "4x4",
      "glass": 21891,
      "lamele": 28609
    },
    {
      "size": "5x4",
      "glass": 27024,
      "lamele": 33754
    },
    {
      "size": "6x4",
      "glass": 30119,
      "lamele": 38862
    }
  ],
  "lux": [
    {
      "size": "6x3",
      "glass": 27730,
      "lamele": 32988
    },
    {
      "size": "8x3",
      "glass": 38786,
      "lamele": 40866
    },
    {
      "size": "6x4",
      "glass": 31645,
      "lamele": 38625
    },
    {
      "size": "8x4",
      "glass": 42905,
      "lamele": 50076
    }
  ],
  "delux": [
    {
      "size": "6x4",
      "glass": 74208,
      "lamele": 67940
    }
  ],
  "carport": [
    {
      "size": "6x5",
      "opal": 26136
    },
    {
      "size": "6x6",
      "opal": 28987
    }
  ],
  "walls": [
    {
      "name": "System szyb przesuwnych (2500×3720, grafit)",
      "price": 6419
    },
    {
      "name": "System FIX (2500×3720, ornament)",
      "price": 10367
    },
    {
      "name": "Przysłona Screen (2500×3720)",
      "price": 6111
    },
    {
      "name": "Markiza (DELUX S64)",
      "price": 15109
    }
  ]
};


// ===================== KOMPONENTY =====================
const PRICING_VAT = 1.23;
function fmtPLN(n) {
  if (n == null || isNaN(n)) return '—';
  return new Intl.NumberFormat('pl-PL').format(Math.round(n)) + ' zł';
}
const meters = (cm) => String(cm / 100).replace('.', ',');

// Wyróżniony box: wymiary na miarę + zastrzeżenie prawne (wspólny dla LINEA i HORIZON)
function PricingCallout({ onQuote }) {
  return (
    <div className="pricing__callout-wrap">
      <div className="pricing__callout">
        <div className="pricing__callout-txt">
          <strong>Potrzebujesz innych wymiarów?</strong>
          <p>Realizujemy zadaszenia także w wymiarach niestandardowych — dopasowanych do Twojego tarasu i architektury domu. W takim przypadku wycenę przygotowujemy indywidualnie.</p>
        </div>
        <Button variant="primary" size="lg" onClick={onQuote}>Zamów bezpłatną wycenę</Button>
      </div>
      <p className="pricing__legal">
        Podane ceny są orientacyjne (sugerowane), netto. Nie stanowią oferty w rozumieniu art. 71 Kodeksu cywilnego —
        dokładną wycenę przygotujemy indywidualnie.
      </p>
    </div>
  );
}

// --- LINEA: interaktywny kalkulator (pokrycie × szerokość × wysięg) ---
function PricingLinea({ onQuote }) {
  const P = LINEA_PRICING;
  const [roof, setRoof] = React.useState('opal');
  const [width, setWidth] = React.useState(606);
  const [proj, setProj] = React.useState(400);
  const roofObj = P.roofs.find(r => r.id === roof) || P.roofs[0];
  const projAvail = P.projections.filter(p => roofObj.prices[String(p)]);
  const effProj = projAvail.includes(proj) ? proj : projAvail[projAvail.length - 1];
  const net = roofObj.prices[String(effProj)] ? roofObj.prices[String(effProj)][String(width)] : null;

  return (
    <section className="section section--warm pricing-section">
      <div className="container">
        <SectionHead title="Orientacyjny cennik LINEA"
          sub="Po wybraniu pokrycia dachu, szerokości i wysięgu zobaczysz sugerowaną cenę konstrukcji. Wymiary niestandardowe wyceniamy indywidualnie." />
        <div className="pricing">
          <div className="pricing__controls">
            <label className="pricing__field">
              <span>Pokrycie dachu</span>
              <select value={roof} onChange={e => setRoof(e.target.value)}>
                {P.roofs.map(r => <option key={r.id} value={r.id}>{r.name}</option>)}
              </select>
            </label>
            <label className="pricing__field">
              <span>Szerokość</span>
              <select value={width} onChange={e => setWidth(Number(e.target.value))}>
                {P.widths.map(w => <option key={w} value={w}>{meters(w)} m</option>)}
              </select>
            </label>
            <label className="pricing__field">
              <span>Wysięg (głębokość)</span>
              <select value={effProj} onChange={e => setProj(Number(e.target.value))}>
                {projAvail.map(p => <option key={p} value={p}>{meters(p)} m</option>)}
              </select>
            </label>
          </div>
          <div className="pricing__result">
            {net ? (
              <React.Fragment>
                <div className="pricing__net">od {fmtPLN(net)} <span>netto</span></div>
                <div className="pricing__gross">od {fmtPLN(net * PRICING_VAT)} brutto (z VAT 23%)</div>
              </React.Fragment>
            ) : (
              <div className="pricing__net pricing__net--ask">Wycena indywidualna</div>
            )}
            <div className="pricing__dims">LINEA {meters(width)} × {meters(effProj)} m · {roofObj.name}</div>
          </div>
        </div>

        <h4 className="block-title pricing__subhead">Zabudowa ścian i dodatki</h4>
        <div className="pricing__addons">
          {LINEA_ADDONS.map((a, i) => (
            <div key={i} className="pricing__addon">
              <div className="pricing__addon-top">
                <span className="pricing__addon-name">{a.name}</span>
                <span className="pricing__addon-price">od {fmtPLN(a.price)} <em>{a.unit}</em></span>
              </div>
              {a.note && <div className="pricing__addon-note">{a.note}</div>}
            </div>
          ))}
        </div>

        <PricingCallout onQuote={onQuote} />
      </div>
    </section>
  );
}

// --- HORIZON: interaktywny kalkulator (wariant × wymiary × pokrycie) ---
function PricingHorizon({ onQuote }) {
  const H = HORIZON_PRICING;
  const COVER = { glass: 'Szkło ESG+EVG 55.2', lamele: 'Aluminiowe lamele 200', opal: 'Poliwęglan OPAL UV' };
  const LINES = [
    { id: 'standard', name: 'HORIZON Standard', opt: 'Standard',                          desc: 'Wersja podstawowa — moduły 4–6 m szerokości.', items: H.std,     coverings: ['glass', 'lamele'] },
    { id: 'lux',      name: 'HORIZON LUX',      opt: 'LUX — głębszy (do 8 m szerokości)',  desc: 'Powiększone moduły, głębokość zadaszenia do 2 m.', items: H.lux,     coverings: ['glass', 'lamele'] },
    { id: 'delux',    name: 'HORIZON DELUX',    opt: 'DELUX — z możliwością zabudowy ścian', desc: 'Najbogatsza wersja, przystosowana do zabudowy ścian.', items: H.delux,   coverings: ['glass', 'lamele'] },
    { id: 'carport',  name: 'HORIZON Carport',  opt: 'Carport — wiata na samochód',        desc: 'Zadaszenie na samochód z lekkim poliwęglanem.', items: H.carport, coverings: ['opal'] },
  ];
  const [line, setLine] = React.useState('standard');
  const [sizeIdx, setSizeIdx] = React.useState(0);
  const [cover, setCover] = React.useState('glass');
  const lineObj = LINES.find(l => l.id === line) || LINES[0];
  const effSizeIdx = Math.min(sizeIdx, lineObj.items.length - 1);
  const item = lineObj.items[effSizeIdx];
  const effCover = lineObj.coverings.includes(cover) ? cover : lineObj.coverings[0];
  const net = item ? item[effCover] : null;
  const sizeLabel = item ? (item.size.replace('x', ' × ') + ' m') : '';

  return (
    <section className="section section--warm pricing-section">
      <div className="container">
        <SectionHead title="Orientacyjny cennik HORIZON"
          sub="Po wybraniu wariantu, wymiarów i pokrycia dachu zobaczysz sugerowaną cenę gotowego zadaszenia. Wymiary niestandardowe i projekty indywidualne wyceniamy osobno." />
        <div className="pricing">
          <div className="pricing__controls">
            <label className="pricing__field">
              <span>Wariant</span>
              <select value={line} onChange={e => { setLine(e.target.value); setSizeIdx(0); }}>
                {LINES.map(l => <option key={l.id} value={l.id}>{l.opt}</option>)}
              </select>
              <small className="pricing__hint">{lineObj.desc}</small>
            </label>
            <label className="pricing__field">
              <span>Wymiary (szerokość × głębokość)</span>
              <select value={effSizeIdx} onChange={e => setSizeIdx(Number(e.target.value))}>
                {lineObj.items.map((it, i) => <option key={i} value={i}>{it.size.replace('x', ' × ')} m</option>)}
              </select>
            </label>
            <label className="pricing__field">
              <span>Pokrycie dachu</span>
              <select value={effCover} onChange={e => setCover(e.target.value)} disabled={lineObj.coverings.length < 2}>
                {lineObj.coverings.map(c => <option key={c} value={c}>{COVER[c]}</option>)}
              </select>
            </label>
          </div>
          <div className="pricing__result">
            {net ? (
              <React.Fragment>
                <div className="pricing__net">od {fmtPLN(net)} <span>netto</span></div>
                <div className="pricing__gross">od {fmtPLN(net * PRICING_VAT)} brutto (z VAT 23%)</div>
              </React.Fragment>
            ) : (
              <div className="pricing__net pricing__net--ask">Wycena indywidualna</div>
            )}
            <div className="pricing__dims">{lineObj.name} · {sizeLabel} · {COVER[effCover]}</div>
          </div>
        </div>

        <h4 className="block-title pricing__subhead">Systemy ścienne (HORIZON DELUX)</h4>
        <div className="pricing__addons">
          {H.walls.map((w, i) => (
            <div key={i} className="pricing__addon">
              <div className="pricing__addon-top">
                <span className="pricing__addon-name">{w.name}</span>
                <span className="pricing__addon-price">od {fmtPLN(w.price)} <em>netto</em></span>
              </div>
            </div>
          ))}
        </div>

        <PricingCallout onQuote={onQuote} />
      </div>
    </section>
  );
}

window.PricingLinea = PricingLinea;
window.PricingHorizon = PricingHorizon;
