"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
// GHS CRM — Solar Calculator (fully functional)
// Alle keuzes komen uit de artikeldatabank (Stock & artikelen → schakelaar "Calc").
// Prijzen zijn altijd de aankoopprijs van het artikel; de rekeneenheid van het
// artikel bepaalt of er × panelen, × meter of één keer per installatie gerekend wordt.

var DAK_FAMILY_LABEL = {
  pan: 'Pannendak',
  leien: 'Leien',
  plat: 'Platdak',
  steel: 'Steeldeck'
};
var dakFamilyOf = function dakFamilyOf(a) {
  var d = (a && a.specs && a.specs.daktype || '').toLowerCase();
  return d.includes('pan') ? 'pan' : d.includes('leien') ? 'leien' : d.includes('plat') ? 'plat' : d.includes('steel') ? 'steel' : '';
};
var MONTAGE_INLEG_ID = '__inleg';

/* Alle keuzelijsten komen uit de artikeldatabank — zie artikelen-calc-link.jsx.
   De alternatieve weergaven (solar_calc_layouts*.jsx) werken met de oude vorm,
   dus zetten we de artikels om naar diezelfde velden. */
var plaatsingForDak = function plaatsingForDak(articles, fam) {
  var alle = calcArtList(articles, 'montage_dak', 'plaatsing');
  var eigen = fam ? alle.filter(function (a) {
    return dakFamilyOf(a) === fam;
  }) : [];
  return eigen.length ? eigen : alle;
};
var spec = function spec(a, k) {
  return a && a.specs ? a.specs[k] : undefined;
};
var asPanel = function asPanel(a) {
  return {
    id: a.id,
    name: a.name,
    watt: Number(spec(a, 'wp')) || 0,
    buy: Number(a.buyPrice) || 0,
    supplier: a.supplier || a.brand || '—',
    inCalc: a.inCalc === true,
    art: a
  };
};
var asInverter = function asInverter(a) {
  return {
    id: a.id,
    name: a.name,
    buy: Number(a.buyPrice) || 0,
    maxKw: Number(spec(a, 'acKw')) || 0,
    phase: String(spec(a, 'fasen') || '').includes('3') ? 3 : 1,
    hybrid: !!spec(a, 'hybride'),
    inCalc: a.inCalc === true,
    art: a
  };
};
var asBattery = function asBattery(a) {
  return {
    id: a.id,
    name: a.name,
    buy: Number(a.buyPrice) || 0,
    kwh: Number(spec(a, 'kwh')) || 0,
    inCalc: a.inCalc === true,
    art: a
  };
};
var asSimple = function asSimple(a) {
  return {
    id: a.id,
    name: a.name,
    buy: Number(a.buyPrice) || 0,
    inCalc: a.inCalc === true,
    art: a
  };
};
var asMontage = function asMontage(a) {
  return {
    id: a.id,
    name: a.name,
    pricePerPanel: Number(a.buyPrice) || 0,
    family: dakFamilyOf(a) || 'pan',
    inCalc: a.inCalc === true,
    art: a
  };
};
var LEGACY_INLEG = {
  id: MONTAGE_INLEG_ID,
  name: 'ALIUS INLEG PANNENDAK',
  pricePerPanel: null,
  family: 'pan',
  dynamic: true,
  inCalc: true
};
/* De alternatieve weergaven lezen deze globals; ze worden bij elke render van de
   calculator gevuld met de actuele artikels. Hier alvast lege defaults zodat het
   laden van die bestanden nooit op een ontbrekende naam struikelt. */
Object.assign(window, {
  PANELS: [],
  INVERTERS: [],
  BATTERIES: [{
    id: 'none',
    name: 'Geen batterij',
    kwh: 0,
    buy: 0
  }],
  OPTIMIZERS: [{
    id: 'none',
    name: 'Geen optimizers',
    buy: 0
  }],
  MONTAGE_TYPES: [LEGACY_INLEG],
  PLAATSING_OPTS: [],
  AANSLUITING: [],
  OPSTART: [],
  KEURING_OPTS: [{
    id: 'none',
    name: 'Geen keuring',
    buy: 0
  }],
  EXTRA_OPTS: [],
  DC_PRICE_PER_M: 0,
  DAK_FAMILY_LABEL: DAK_FAMILY_LABEL,
  plaatsingForFamily: function plaatsingForFamily() {
    return [];
  },
  familyOfMontage: function familyOfMontage() {
    return 'pan';
  }
});
var COMM_TIERS = [{
  min: 15,
  max: 18,
  pct: 6
}, {
  min: 18,
  max: 22,
  pct: 8
}, {
  min: 22,
  max: 26,
  pct: 10
}, {
  min: 26,
  max: 32,
  pct: 11
}, {
  min: 32,
  max: 38,
  pct: 12
}];
function getCommTier(marginPct) {
  return COMM_TIERS.find(function (t) {
    return marginPct >= t.min && marginPct < t.max;
  }) || null;
}
var CalcSection = function CalcSection(_ref) {
  var title = _ref.title,
    icon = _ref.icon,
    children = _ref.children,
    compact = _ref.compact,
    style = _ref.style;
  return /*#__PURE__*/React.createElement("div", {
    style: _objectSpread({
      background: T.bg1,
      clipPath: cutPath(compact ? 10 : 12),
      padding: compact ? '11px 13px' : '16px 18px',
      position: 'relative',
      marginBottom: compact ? 0 : 10
    }, style)
  }, /*#__PURE__*/React.createElement("div", {
    style: accentEdge(compact ? 10 : 12)
  }), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      alignItems: 'center',
      gap: 7,
      marginBottom: compact ? 9 : 14
    }
  }, /*#__PURE__*/React.createElement(Icon, {
    name: icon,
    size: compact ? 12 : 14,
    color: T.accent
  }), /*#__PURE__*/React.createElement("span", {
    style: {
      fontFamily: T.fontBody,
      fontSize: compact ? 9 : 10,
      fontWeight: 700,
      letterSpacing: compact ? '0.12em' : '0.16em',
      textTransform: 'uppercase',
      color: T.fg3
    }
  }, title)), children);
};

/* ───────── Offerte samenvatting: bouwstenen ─────────
   Een deel = tussenkop met een lijn erboven (dezelfde taal als de tussenkoppen in de dakvlakkaart).
   Een post = wat de klant krijgt, met de verkoopprijs. Een rij = label en bedrag. */
var OS_LBL = {
  fontFamily: T.fontBody,
  fontSize: 10,
  fontWeight: 700,
  letterSpacing: '0.2em',
  textTransform: 'uppercase',
  color: T.fg3
};
var OS_SUB = {
  fontFamily: T.fontBody,
  fontSize: 11.5,
  color: T.fg3,
  lineHeight: 1.45
};
var OS_CAT = {
  fontFamily: T.fontBody,
  fontSize: 9.5,
  fontWeight: 700,
  letterSpacing: '0.14em',
  textTransform: 'uppercase',
  color: T.fg4
};
var OsSectie = function OsSectie(_ref2) {
  var titel = _ref2.titel,
    rechts = _ref2.rechts,
    eerste = _ref2.eerste,
    children = _ref2.children;
  return /*#__PURE__*/React.createElement("section", {
    style: {
      marginTop: eerste ? 18 : 24,
      paddingTop: eerste ? 0 : 18,
      borderTop: eerste ? 'none' : "1px solid ".concat(T.stroke1)
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      alignItems: 'baseline',
      justifyContent: 'space-between',
      gap: 10,
      marginBottom: 8
    }
  }, /*#__PURE__*/React.createElement("h3", {
    style: _objectSpread({
      margin: 0
    }, OS_LBL)
  }, titel), rechts && /*#__PURE__*/React.createElement("span", {
    style: {
      fontFamily: T.fontBody,
      fontSize: 11.5,
      color: T.fg4,
      textAlign: 'right'
    }
  }, rechts)), children);
};
var OsPost = function OsPost(_ref3) {
  var cat = _ref3.cat,
    naam = _ref3.naam,
    detail = _ref3.detail,
    sub = _ref3.sub,
    bedrag = _ref3.bedrag,
    scheiding = _ref3.scheiding;
  return /*#__PURE__*/React.createElement("div", {
    style: {
      padding: '11px 0',
      borderTop: "1px solid ".concat(scheiding ? T.stroke2 : T.stroke1),
      marginTop: scheiding ? 8 : 0
    }
  }, cat && /*#__PURE__*/React.createElement("div", {
    style: _objectSpread(_objectSpread({}, OS_CAT), {}, {
      marginBottom: 3
    })
  }, cat), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      alignItems: 'baseline',
      gap: 14
    }
  }, /*#__PURE__*/React.createElement("span", {
    style: {
      flex: 1,
      minWidth: 0,
      fontFamily: T.fontBody,
      fontSize: 13.5,
      fontWeight: 600,
      color: T.fg1,
      lineHeight: 1.35,
      overflowWrap: 'anywhere'
    }
  }, naam), /*#__PURE__*/React.createElement("span", {
    style: {
      fontFamily: T.fontDisplay,
      fontSize: 14,
      fontWeight: 600,
      color: T.fg1,
      fontVariantNumeric: 'tabular-nums',
      whiteSpace: 'nowrap'
    }
  }, bedrag)), detail && /*#__PURE__*/React.createElement("div", {
    style: _objectSpread(_objectSpread({}, OS_SUB), {}, {
      marginTop: 2
    })
  }, detail), sub && /*#__PURE__*/React.createElement("div", {
    style: _objectSpread(_objectSpread({}, OS_SUB), {}, {
      color: T.fg4,
      marginTop: 2
    })
  }, sub));
};
var OsRij = function OsRij(_ref4) {
  var label = _ref4.label,
    waarde = _ref4.waarde,
    sterk = _ref4.sterk,
    oranje = _ref4.oranje,
    geenLijn = _ref4.geenLijn;
  return /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      alignItems: 'baseline',
      justifyContent: 'space-between',
      gap: 12,
      padding: sterk ? '12px 0 4px' : '7px 0',
      marginTop: sterk && !geenLijn ? 6 : 0,
      borderTop: sterk && !geenLijn ? "1px solid ".concat(T.stroke1) : 'none'
    }
  }, /*#__PURE__*/React.createElement("span", {
    style: {
      fontFamily: T.fontBody,
      fontSize: sterk ? 13.5 : 13,
      fontWeight: sterk ? 700 : 500,
      color: oranje ? '#ffb020' : sterk ? T.fg1 : T.fg2,
      minWidth: 0
    }
  }, label), /*#__PURE__*/React.createElement("span", {
    style: {
      fontFamily: T.fontDisplay,
      fontSize: sterk ? 17 : 13.5,
      fontWeight: 600,
      color: oranje ? '#ffb020' : T.fg1,
      fontVariantNumeric: 'tabular-nums',
      whiteSpace: 'nowrap'
    }
  }, waarde));
};
var OsChip = function OsChip(_ref5) {
  var kleur = _ref5.kleur,
    children = _ref5.children;
  return /*#__PURE__*/React.createElement("span", {
    style: {
      display: 'inline-flex',
      alignItems: 'center',
      padding: '4px 10px',
      background: kleur ? "".concat(kleur, "14") : 'rgba(246,247,235,0.05)',
      border: "1px solid ".concat(kleur ? kleur + '40' : T.stroke2),
      borderRadius: 999,
      fontFamily: T.fontBody,
      fontSize: 11.5,
      fontWeight: 700,
      color: kleur || T.fg2,
      fontVariantNumeric: 'tabular-nums',
      whiteSpace: 'nowrap'
    }
  }, children);
};
/* Naam en uitleg van een offertepost: montage en plaatsing tellen per paneel, dus geen "12×" voor de naam. */
var osPostNaam = function osPostNaam(it) {
  var n = it.label.split(' — ').slice(1).join(' — ') || it.label;
  return ['montage', 'plaatsing'].includes(it.regel) || !(it.qty > 1) ? n : "".concat(String(it.qty).replace('.', ','), "\xD7 ").concat(n);
};
var osPostDetail = function osPostDetail(it) {
  return ['montage', 'plaatsing'].includes(it.regel) && it.qty > 0 ? "Voor ".concat(String(it.qty).replace('.', ','), " panelen") : it.detail || null;
};
var NumInput = function NumInput(_ref6) {
  var label = _ref6.label,
    value = _ref6.value,
    _onChange = _ref6.onChange,
    _ref6$min = _ref6.min,
    min = _ref6$min === void 0 ? 0 : _ref6$min,
    max = _ref6.max,
    _ref6$step = _ref6.step,
    step = _ref6$step === void 0 ? 1 : _ref6$step,
    suffix = _ref6.suffix;
  return /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      flexDirection: 'column',
      gap: 4
    }
  }, label && /*#__PURE__*/React.createElement("label", {
    style: {
      fontFamily: T.fontBody,
      fontSize: 10,
      fontWeight: 700,
      letterSpacing: '0.12em',
      textTransform: 'uppercase',
      color: T.fg3
    }
  }, label), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      alignItems: 'center',
      gap: 0,
      background: T.bg0,
      border: "1px solid ".concat(T.stroke1),
      borderRadius: 4,
      overflow: 'hidden'
    }
  }, /*#__PURE__*/React.createElement("button", {
    onClick: function onClick() {
      return _onChange(Math.max(min, value - step));
    },
    style: {
      background: 'none',
      border: 'none',
      cursor: 'pointer',
      color: T.fg2,
      padding: '7px 10px',
      fontSize: 16,
      lineHeight: 1,
      fontWeight: 600
    }
  }, "\u2212"), /*#__PURE__*/React.createElement("input", {
    type: "number",
    value: value,
    onChange: function onChange(e) {
      return _onChange(Math.max(min, max ? Math.min(max, Number(e.target.value)) : Number(e.target.value)));
    },
    style: {
      flex: 1,
      background: 'transparent',
      border: 'none',
      textAlign: 'center',
      color: T.fg1,
      fontFamily: T.fontDisplay,
      fontSize: 15,
      fontWeight: 600,
      outline: 'none',
      width: 60
    }
  }), /*#__PURE__*/React.createElement("button", {
    onClick: function onClick() {
      return _onChange(max ? Math.min(max, value + step) : value + step);
    },
    style: {
      background: 'none',
      border: 'none',
      cursor: 'pointer',
      color: T.fg2,
      padding: '7px 10px',
      fontSize: 16,
      lineHeight: 1,
      fontWeight: 600
    }
  }, "+"), suffix && /*#__PURE__*/React.createElement("span", {
    style: {
      paddingRight: 10,
      color: T.fg3,
      fontSize: 12,
      fontWeight: 600
    }
  }, suffix)));
};
var ResultRow = function ResultRow(_ref7) {
  var label = _ref7.label,
    value = _ref7.value,
    sub = _ref7.sub,
    accent = _ref7.accent,
    large = _ref7.large,
    bold = _ref7.bold;
  return /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      justifyContent: 'space-between',
      alignItems: 'center',
      padding: '8px 0',
      borderBottom: "1px solid ".concat(T.stroke1)
    }
  }, /*#__PURE__*/React.createElement("span", {
    style: {
      fontFamily: T.fontBody,
      fontSize: large ? 13 : 12,
      color: accent ? T.accent : T.fg2,
      fontWeight: bold ? 600 : 400
    }
  }, label), /*#__PURE__*/React.createElement("div", {
    style: {
      textAlign: 'right'
    }
  }, /*#__PURE__*/React.createElement("span", {
    style: {
      fontFamily: large ? T.fontDisplay : T.fontBody,
      fontSize: large ? 15 : 13,
      color: accent ? T.accent : T.fg1,
      fontWeight: bold ? 700 : 600,
      letterSpacing: large ? '-0.02em' : 0,
      fontVariantNumeric: 'tabular-nums'
    }
  }, value), sub && /*#__PURE__*/React.createElement("div", {
    style: {
      fontSize: 10,
      color: T.fg3,
      fontFamily: T.fontBody
    }
  }, sub)));
};
var SolarBatteryCalc = function SolarBatteryCalc(_ref8) {
  var _ref8$isAdmin = _ref8.isAdmin,
    isAdmin = _ref8$isAdmin === void 0 ? false : _ref8$isAdmin,
    _ref8$embedded = _ref8.embedded,
    embedded = _ref8$embedded === void 0 ? false : _ref8$embedded,
    _ref8$klant = _ref8.klant,
    klant = _ref8$klant === void 0 ? '' : _ref8$klant,
    onSave = _ref8.onSave,
    _ref8$mode = _ref8.mode,
    mode = _ref8$mode === void 0 ? 'zp_batt' : _ref8$mode,
    _ref8$contactId = _ref8.contactId,
    contactId = _ref8$contactId === void 0 ? null : _ref8$contactId,
    _ref8$profielId = _ref8.profielId,
    profielId = _ref8$profielId === void 0 ? null : _ref8$profielId,
    _ref8$verkoper = _ref8.verkoper,
    verkoper = _ref8$verkoper === void 0 ? '' : _ref8$verkoper,
    _ref8$btwVoorstel = _ref8.btwVoorstel,
    btwVoorstel = _ref8$btwVoorstel === void 0 ? null : _ref8$btwVoorstel;
  var toonPV = mode !== 'batt'; // panelen, montage, plaatsing, optimizers, DC
  var toonBatt = mode !== 'zp'; // batterij
  /* Admin modus = de klantmodus uit (één schakelaar, gedeeld met KLANTMODUS bovenaan): dan komen het calculatorprofiel
     met de margeklasse, de commissie en de rekeninfo tevoorschijn. Uit = verbergmodus, de klant kan meekijken.
     Aankoopprijzen en marge in euro blijven ook in admin modus enkel voor Admin en Office. */
  var _useKlantmodus = useKlantmodus(),
    _useKlantmodus2 = _slicedToArray(_useKlantmodus, 2),
    klantmodus = _useKlantmodus2[0],
    setKlantmodus = _useKlantmodus2[1];
  var intern = !klantmodus;
  /* Hertekent bij "werk als" een andere gebruiker. */
  var gebruiker = window.useGhsGebruiker ? window.useGhsGebruiker() : window.ghsHuidigeGebruiker ? window.ghsHuidigeGebruiker() : null;
  var beheer = !gebruiker || gebruiker.role === 'Admin' || (gebruiker.disciplines || []).includes('office');
  var adminMode = intern && beheer;
  var store = useArticles();
  var arts = store.articles;
  var byId = function byId(id) {
    return arts.find(function (a) {
      return a.id === id;
    }) || null;
  };
  var eerste = function eerste(type, group) {
    var l = calcArtList(arts, type, group);
    return l.length ? l[0].id : '';
  };
  var _React$useState = React.useState(function () {
      return eerste('zonnepanelen');
    }),
    _React$useState2 = _slicedToArray(_React$useState, 2),
    panelId = _React$useState2[0],
    setPanelId = _React$useState2[1];
  // Roof faces (dakvlakken): each has its own panel count, montagemateriaal and plaatsing.
  var _React$useState3 = React.useState([{
      id: 'dv1',
      panelen: 14,
      montageId: MONTAGE_INLEG_ID,
      rows: 2,
      cols: 7,
      orient: 'landscape',
      plaatsingId: ''
    }]),
    _React$useState4 = _slicedToArray(_React$useState3, 2),
    dakvlakken = _React$useState4[0],
    setDakvlakken = _React$useState4[1];
  var _React$useState5 = React.useState(function () {
      return eerste('omvormers');
    }),
    _React$useState6 = _slicedToArray(_React$useState5, 2),
    inverterId = _React$useState6[0],
    setInverterId = _React$useState6[1];
  React.useEffect(function () {
    if (window.calcProfielZetKeuze) window.calcProfielZetKeuze('omvormer', inverterId);
  }, [inverterId]);
  var _React$useState7 = React.useState('none'),
    _React$useState8 = _slicedToArray(_React$useState7, 2),
    batteryId = _React$useState8[0],
    setBatteryId = _React$useState8[1];
  var _React$useState9 = React.useState('none'),
    _React$useState0 = _slicedToArray(_React$useState9, 2),
    optimizerId = _React$useState0[0],
    _setOptimizerId = _React$useState0[1];
  var _React$useState1 = React.useState(0),
    _React$useState10 = _slicedToArray(_React$useState1, 2),
    optimizerQty = _React$useState10[0],
    setOptimizerQty = _React$useState10[1];
  var _React$useState11 = React.useState(15),
    _React$useState12 = _slicedToArray(_React$useState11, 2),
    dcMeters = _React$useState12[0],
    setDcMeters = _React$useState12[1];
  var _React$useState13 = React.useState(function () {
      return eerste('montage_elek', 'aansluiting');
    }),
    _React$useState14 = _slicedToArray(_React$useState13, 2),
    aansluitingId = _React$useState14[0],
    setAansluitingId = _React$useState14[1];
  var _React$useState15 = React.useState(function () {
      return eerste('diensten', 'opstart');
    }),
    _React$useState16 = _slicedToArray(_React$useState15, 2),
    opstartId = _React$useState16[0],
    setOpstartId = _React$useState16[1];
  var _React$useState17 = React.useState(function () {
      return eerste('keuring');
    }),
    _React$useState18 = _slicedToArray(_React$useState17, 2),
    keuringId = _React$useState18[0],
    setKeuringId = _React$useState18[1];
  var _React$useState19 = React.useState([]),
    _React$useState20 = _slicedToArray(_React$useState19, 2),
    extraIds = _React$useState20[0],
    setExtraIds = _React$useState20[1];
  var _React$useState21 = React.useState({}),
    _React$useState22 = _slicedToArray(_React$useState21, 2),
    extraQty = _React$useState22[0],
    setExtraQty = _React$useState22[1];
  var _React$useState23 = React.useState(CALC_STD_MARGIN),
    _React$useState24 = _slicedToArray(_React$useState23, 2),
    targetMargin = _React$useState24[0],
    setTargetMargin = _React$useState24[1];
  // Vrije regels op de offerte (korting, actie, meerprijs…) — bedrag negatief = korting
  var _React$useState25 = React.useState([]),
    _React$useState26 = _slicedToArray(_React$useState25, 2),
    customLines = _React$useState26[0],
    setCustomLines = _React$useState26[1];
  var _React$useState27 = React.useState([]),
    _React$useState28 = _slicedToArray(_React$useState27, 2),
    skipBundels = _React$useState28[0],
    setSkipBundels = _React$useState28[1]; // bundel-ids die voor déze offerte zijn weggehaald
  /* Btw: wat de btw-regels voor deze klant en woning voorstellen (calculator, stap 1); in de beheerweergave aan te passen. */
  var _React$useState29 = React.useState(btwVoorstel != null ? btwVoorstel : 6),
    _React$useState30 = _slicedToArray(_React$useState29, 2),
    btw = _React$useState30[0],
    setBtw = _React$useState30[1];
  React.useEffect(function () {
    if (btwVoorstel != null) setBtw(btwVoorstel);
  }, [btwVoorstel]);
  /* 0 % (verlegd) enkel als de regels het voorstellen: een onderneming met btw-nummer. */
  var btwVerlegdKan = +btw === 0 || btwVoorstel === 0;
  var _React$useState31 = React.useState(klant),
    _React$useState32 = _slicedToArray(_React$useState31, 2),
    clientName = _React$useState32[0],
    setClientName = _React$useState32[1];
  React.useEffect(function () {
    if (klant) setClientName(klant);
  }, [klant]);
  var _React$useState33 = React.useState(false),
    _React$useState34 = _slicedToArray(_React$useState33, 2),
    showPDF = _React$useState34[0],
    setShowPDF = _React$useState34[1];
  var _React$useState35 = React.useState(null),
    _React$useState36 = _slicedToArray(_React$useState35, 2),
    melding = _React$useState36[0],
    setMelding = _React$useState36[1];
  /* Voorschot %: null = het standaardvoorschot van het producttype (Instellingen › Facturatie & nummering). */
  var _React$useState37 = React.useState(null),
    _React$useState38 = _slicedToArray(_React$useState37, 2),
    vsKeuze = _React$useState38[0],
    setVsPct = _React$useState38[1];
  var _React$useState39 = React.useState('dak_persp'),
    _React$useState40 = _slicedToArray(_React$useState39, 2),
    layout = _React$useState40[0],
    setLayout = _React$useState40[1]; // dak_persp · dak_top · dak_compact
  /* ── Samenstelling (calculatorprofiel uit stap 1): velden, prijs en korting zoals het Excel-tabblad ── */
  var profielModus = !!profielId;
  var _React$useState41 = React.useState(function () {
      return profielId && window.calcStartVelden ? window.calcStartVelden(profielId, null) : {};
    }),
    _React$useState42 = _slicedToArray(_React$useState41, 2),
    velden = _React$useState42[0],
    setVelden = _React$useState42[1];
  var _React$useState43 = React.useState(null),
    _React$useState44 = _slicedToArray(_React$useState43, 2),
    korting = _React$useState44[0],
    setKorting = _React$useState44[1]; // null = de maximale korting (Excel)
  var _React$useState45 = React.useState(0),
    _React$useState46 = _slicedToArray(_React$useState45, 2),
    setProfTik = _React$useState46[1];
  React.useEffect(function () {
    var h = function h() {
      return setProfTik(function (x) {
        return x + 1;
      });
    };
    window.addEventListener('ghs-calcprofiel-actief', h);
    window.addEventListener('ghs-calcmarge-updated', h);
    window.addEventListener('ghs-calcmontage-updated', h);
    window.addEventListener('ghs-commissie-updated', h);
    return function () {
      window.removeEventListener('ghs-calcprofiel-actief', h);
      window.removeEventListener('ghs-calcmarge-updated', h);
      window.removeEventListener('ghs-calcmontage-updated', h);
      window.removeEventListener('ghs-commissie-updated', h);
    };
  }, []);
  React.useEffect(function () {
    if (!profielId || !window.calcZetProfielActief) return;
    var a = window.calcProfielActief ? window.calcProfielActief() : null;
    if (a && a.id === profielId) return;
    var p = (window.calcProfielen ? window.calcProfielen() : []).find(function (x) {
      return x.id === profielId;
    });
    /* Samenstelling met meerdere merken (Huawei / SolarEdge): het eerste merk staat klaar, de knoppen erboven wisselen. */
    window.calcZetProfielActief({
      id: profielId,
      platform: p && p.platforms.length ? p.platforms[0] : null,
      keuzes: {},
      klasse: window.calcMargeInstellingen ? window.calcMargeInstellingen().standaard : 'Target'
    });
  }, [profielId]);
  var profActief = profielModus && window.calcProfielActief ? window.calcProfielActief() : null;
  var profPlatform = profActief && profActief.id === profielId ? profActief.platform || null : null;
  var pfRef = React.useRef(profPlatform);
  React.useEffect(function () {
    if (!profielModus || pfRef.current === profPlatform) return;
    pfRef.current = profPlatform;
    if (window.calcStartVelden) setVelden(window.calcStartVelden(profielId, profPlatform));
  }, [profPlatform]);
  var setVeld = function setVeld(id, val) {
    return setVelden(function (v) {
      return _objectSpread(_objectSpread({}, v), {}, _defineProperty({}, id, val));
    });
  };
  /* Een keuze die niet meer in haar lijst past (ander merk, omvormer met andere fasen) springt naar de beginkeuze. */
  React.useEffect(function () {
    if (!profielModus || !window.calcVeldenGeldig) return;
    setVelden(function (cur) {
      return window.calcVeldenGeldig(profielId, profPlatform, cur) || cur;
    });
  }, [profielModus, profielId, profPlatform, velden]);
  /* Het paneeltype: bij het openen de beginkeuze van het profiel; daarna moet het in de lijst van de samenstelling passen. */
  var pnRef = React.useRef(null);
  React.useEffect(function () {
    if (!profielModus || !window.calcProfielKeuzes) return;
    var l = window.calcProfielKeuzes(profielId, 'zonnepanelen', {
      platform: profPlatform
    });
    if (pnRef.current !== profielId) {
      pnRef.current = profielId;
      var b = window.calcBeginKeuze ? window.calcBeginKeuze(profielId, 'zonnepanelen', l) : l[0];
      if (b && b.id !== panelId) {
        setPanelId(b.id);
        return;
      }
    }
    if (l.length && !l.some(function (a) {
      return a.id === panelId;
    })) setPanelId(l[0].id);
  }, [profielModus, profielId, profPlatform, panelId]);
  /* Montage per dakvlak: enkel de keuzes die het profiel toelaat; bij het openen de beginkeuze van het profiel. */
  var mgRef = React.useRef(null);
  var montageBegin = function montageBegin() {
    return profielModus && window.calcMontageBegin ? window.calcMontageBegin(profielId) : null;
  };
  React.useEffect(function () {
    if (!profielModus || !window.calcMontageKeuzesVoorProfiel) return;
    var ok = new Set(window.calcMontageKeuzesVoorProfiel(profielId).map(function (k) {
        return k.id;
      })),
      begin = montageBegin();
    var eerst = mgRef.current !== profielId;
    mgRef.current = profielId;
    if (!begin) return;
    var fout = function fout(d) {
      return d.montageId !== begin.id && (eerst && d.montageId === MONTAGE_INLEG_ID || !ok.has(d.montageId));
    };
    if (dakvlakken.some(fout)) setDakvlakken(function (prev) {
      return prev.map(function (d) {
        return fout(d) ? _objectSpread(_objectSpread({}, d), {}, {
          montageId: begin.id,
          plaatsingTech: window.calcTechVoorMontage ? window.calcTechVoorMontage(begin.id) : 'pan'
        }) : d;
      });
    });
  }, [profielModus, profielId, dakvlakken]);
  var _toggleExtra = function toggleExtra(id) {
    return setExtraIds(function (prev) {
      return prev.includes(id) ? prev.filter(function (x) {
        return x !== id;
      }) : [].concat(_toConsumableArray(prev), [id]);
    });
  };

  // ── Ongedaan maken: elke wijziging aan de offerte-opbouw is een stap terug ──
  var undoRef = React.useRef({
    stack: [],
    skip: false,
    last: '',
    t0: Date.now()
  });
  var _React$useState47 = React.useState(0),
    _React$useState48 = _slicedToArray(_React$useState47, 2),
    undoN = _React$useState48[0],
    setUndoN = _React$useState48[1];
  var undoSnap = JSON.stringify({
    dakvlakken: dakvlakken,
    panelId: panelId,
    inverterId: inverterId,
    batteryId: batteryId,
    optimizerId: optimizerId,
    optimizerQty: optimizerQty,
    dcMeters: dcMeters,
    aansluitingId: aansluitingId,
    opstartId: opstartId,
    keuringId: keuringId,
    extraIds: extraIds,
    extraQty: extraQty,
    targetMargin: targetMargin,
    customLines: customLines,
    btw: btw,
    skipBundels: skipBundels,
    velden: velden,
    korting: korting
  });
  React.useEffect(function () {
    var h = undoRef.current;
    if (h.skip) {
      h.skip = false;
      h.last = undoSnap;
      return;
    }
    /* Wat de calculator bij het openen zelf invult (beginkeuzes van het profiel) is geen stap om ongedaan te maken. */
    if (Date.now() - h.t0 < 1200) {
      h.last = undoSnap;
      return;
    }
    if (h.last && h.last !== undoSnap) {
      h.stack.push(h.last);
      if (h.stack.length > 40) h.stack.shift();
      setUndoN(h.stack.length);
    }
    h.last = undoSnap;
  }, [undoSnap]);
  var undo = function undo() {
    var h = undoRef.current;
    var prev = h.stack.pop();
    if (!prev) return;
    h.skip = true;
    setUndoN(h.stack.length);
    var p = JSON.parse(prev);
    setDakvlakken(p.dakvlakken);
    setPanelId(p.panelId);
    setInverterId(p.inverterId);
    setBatteryId(p.batteryId);
    _setOptimizerId(p.optimizerId);
    setOptimizerQty(p.optimizerQty);
    setDcMeters(p.dcMeters);
    setAansluitingId(p.aansluitingId);
    setOpstartId(p.opstartId);
    setKeuringId(p.keuringId);
    setExtraIds(p.extraIds);
    setExtraQty(p.extraQty);
    setTargetMargin(p.targetMargin);
    setCustomLines(p.customLines);
    setBtw(p.btw);
    setSkipBundels(p.skipBundels || []);
    if (p.velden) setVelden(p.velden);
    setKorting(p.korting == null ? null : p.korting);
  };

  // ── Dakvlak helpers ────────────────────────────────────────────────
  var nPanels = toonPV ? dakvlakken.reduce(function (s, d) {
    return s + d.panelen;
  }, 0) : 0;
  var updateDakvlak = function updateDakvlak(id, patch) {
    return setDakvlakken(function (prev) {
      return prev.map(function (d) {
        if (d.id !== id) return d;
        var next = _objectSpread(_objectSpread({}, d), patch);
        // ander dak-type gekozen → plaatsing terugzetten naar een passende optie
        if (patch.montageId && patch.montageId !== d.montageId) {
          var fam = patch.montageId === MONTAGE_INLEG_ID ? 'pan' : dakFamilyOf(byId(patch.montageId));
          var opts = plaatsingForDak(arts, fam);
          if (!opts.some(function (p) {
            return p.id === d.plaatsingId;
          })) next.plaatsingId = opts.length ? opts[0].id : '';
        }
        return next;
      });
    });
  };
  var setNDakvlakken = function setNDakvlakken(n) {
    n = Math.max(1, Math.min(8, n));
    setDakvlakken(function (prev) {
      if (n === prev.length) return prev;
      if (n > prev.length) {
        var add = [];
        var mb = montageBegin(),
          mId = mb ? mb.id : MONTAGE_INLEG_ID;
        for (var i = prev.length; i < n; i++) add.push(_objectSpread({
          id: 'dv' + Date.now() + '_' + i,
          panelen: 0,
          montageId: mId,
          rows: 2,
          orient: 'landscape',
          plaatsingId: eerste('montage_dak', 'plaatsing')
        }, mb && window.calcTechVoorMontage ? {
          plaatsingTech: window.calcTechVoorMontage(mId)
        } : {}));
        return [].concat(_toConsumableArray(prev), add);
      }
      return prev.slice(0, n);
    });
  };
  // editing the grand total adjusts the first dakvlak
  var setTotalPanels = function setTotalPanels(v) {
    var delta = v - nPanels;
    setDakvlakken(function (prev) {
      var next = _toConsumableArray(prev);
      next[0] = _objectSpread(_objectSpread({}, next[0]), {}, {
        panelen: Math.max(0, next[0].panelen + delta)
      });
      return next;
    });
  };

  // ── Prijzen: altijd de aankoopprijs van het artikel ────────────────
  var panel = toonPV ? byId(panelId) : null;
  var inverter = byId(inverterId);
  var battery = !toonBatt || batteryId === 'none' ? null : byId(batteryId);
  var optimizer = !toonPV || optimizerId === 'none' ? null : byId(optimizerId);
  var aansluiting = byId(aansluitingId);
  var opstart = byId(opstartId);
  var keuring = keuringId === 'none' ? null : byId(keuringId);
  var dcArt = calcArtList(arts, 'montage_elek', 'bekabeling')[0] || null;
  var panelWp = panel && panel.specs && Number(panel.specs.wp) || 0;
  var invKw = inverter && inverter.specs && Number(inverter.specs.acKw) || 0;
  var invFase = inverter && inverter.specs && inverter.specs.fasen || '—';
  var invHyb = !!(inverter && inverter.specs && inverter.specs.hybride);
  var battKwh = battery && battery.specs && Number(battery.specs.kwh) || 0;
  var prijs = function prijs(a) {
    return a ? Number(a.buyPrice) || 0 : 0;
  };
  var buyPanels = nPanels * prijs(panel);
  var buyInverter = prijs(inverter);
  var buyBattery = prijs(battery);
  var buyOptimizers = optimizer ? optimizerQty * prijs(optimizer) : 0;
  var montageLines = (toonPV ? dakvlakken : []).map(function (dv, i) {
    if (dv.montageId === MONTAGE_INLEG_ID && window.montageInlegCost) {
      // Stuklijst en prijzen live uit de montagegroepen + artikeldatabank
      var rows = dv.rows || 1,
        orient = dv.orient || 'portrait';
      var r = montageInlegCost(rows, orient, dv.panelen);
      return {
        cat: "MONTAGE DAKVLAK ".concat(i + 1),
        name: "ALIUS INLEG \xB7 ".concat(dv.panelen, " pan. \xB7 ").concat(rows, " rij").concat(rows > 1 ? 'en' : '', " ").concat(orient),
        qty: dv.panelen,
        buy: dv.panelen ? r.total / dv.panelen : 0,
        total: r.total,
        bom: r.bom
      };
    }
    var m = byId(dv.montageId);
    var qty = m ? calcQtyFor(m, {
      panelen: dv.panelen,
      kWp: dv.panelen * panelWp / 1000
    }) : 0;
    return {
      cat: "MONTAGE DAKVLAK ".concat(i + 1),
      name: "".concat(m ? m.name : '—', " \xB7 ").concat(dv.panelen, " pan."),
      qty: qty,
      buy: prijs(m),
      total: qty * prijs(m),
      art: m
    };
  });
  var plaatsingLines = (toonPV ? dakvlakken : []).map(function (dv, i) {
    var p = byId(dv.plaatsingId);
    var qty = p ? calcQtyFor(p, {
      panelen: dv.panelen,
      kWp: dv.panelen * panelWp / 1000
    }) : 0;
    return {
      cat: "PLAATSING DAKVLAK ".concat(i + 1),
      name: "".concat(p ? p.name : '—', " \xB7 ").concat(dv.panelen, " pan."),
      qty: qty,
      buy: prijs(p),
      total: qty * prijs(p),
      art: p
    };
  });
  var buyMontage = montageLines.reduce(function (s, l) {
    return s + l.total;
  }, 0);
  var buyPlaatsing = plaatsingLines.reduce(function (s, l) {
    return s + l.total;
  }, 0);
  var dcPrijs = prijs(dcArt);
  var buyDC = toonPV ? dcMeters * dcPrijs : 0;
  var buyAansluiting = prijs(aansluiting);
  var buyOpstart = prijs(opstart);
  var buyKeuring = prijs(keuring);
  var extraArts = extraIds.map(byId).filter(Boolean);
  var extraLines = extraArts.map(function (a) {
    var q = a.calcUnit === 'stuk' || a.calcUnit === 'meter' || a.calcUnit === 'uur' ? Number(extraQty[a.id]) || 1 : 1;
    return {
      cat: 'EXTRA',
      name: "".concat(q > 1 ? q + '× ' : '').concat(a.name),
      qty: q,
      buy: prijs(a),
      total: q * prijs(a),
      art: a
    };
  });
  var buyExtras = extraLines.reduce(function (s, l) {
    return s + l.total;
  }, 0);
  // Artikelbundels (montage op artikelbasis): trigger-artikel in de offerte → bundel telt mee
  var bundelSelIds = [panel, inverter, battery, optimizer, aansluiting, opstart, keuring].concat(_toConsumableArray(extraArts)).filter(Boolean).map(function (a) {
    return a.id;
  });
  var bundelResAll = window.montageBundelCost ? montageBundelCost(bundelSelIds, arts) : {
    total: 0,
    bundles: []
  };
  var bundelAct = bundelResAll.bundles.filter(function (bx) {
    return !skipBundels.includes(bx.bundle.id);
  });
  var bundelWeg = bundelResAll.bundles.filter(function (bx) {
    return skipBundels.includes(bx.bundle.id);
  });
  var bundelLines = bundelAct.map(function (bx) {
    return {
      cat: 'MONTAGEBUNDEL',
      name: "".concat(bx.bundle.naam || 'Bundel', " \u2014 bij ").concat(bx.trigger ? bx.trigger.name : '?', " (").concat(bx.lines.length, " art.)"),
      qty: 1,
      buy: bx.total,
      total: bx.total,
      bom: {
        lines: bx.lines,
        total: bx.total
      },
      bundleId: bx.bundle.id
    };
  });
  var buyBundels = bundelLines.reduce(function (s, l) {
    return s + l.total;
  }, 0);
  /* Samenstelling: één rekenmotor voor de hele offerte (calc-motor.jsx), getoetst tegen de Excel. */
  var verkoperNaam = verkoper || (contactId && window.crmStore ? ((window.crmStore.getState().contacts || []).find(function (c) {
    return c.id === contactId;
  }) || {}).verkoper : '') || '';
  var res = profielModus && window.calcMotor ? window.calcMotor({
    profielId: profielId,
    platform: profPlatform,
    klasse: profActief && profActief.id === profielId ? profActief.klasse : null,
    verkoper: verkoperNaam,
    panelId: panelId,
    dakvlakken: dakvlakken,
    velden: velden,
    korting: korting,
    arts: arts
  }) : null;
  var totalBuy = res ? res.aankoop : buyPanels + buyInverter + buyBattery + buyOptimizers + buyMontage + buyPlaatsing + buyDC + buyAansluiting + buyOpstart + buyKeuring + buyExtras + buyBundels;

  // Selling price based on target margin
  /* Calculatorprofiel actief: de prijs volgt de margekeuze (calc-marge.jsx) — deel 1 = alles behalve de batterij. */
  var profAct = window.calcProfielActief ? window.calcProfielActief() : null;
  var margeModel = res ? res.marge : profAct && profAct.id && window.calcMargeVoorProfiel && totalBuy > 0 ? window.calcMargeVoorProfiel(profAct.id, totalBuy - buyBattery, buyBattery, profAct.klasse) : null;
  var sellBase = margeModel ? margeModel.prijsNaKorting : totalBuy > 0 ? totalBuy / (1 - targetMargin / 100) : 0;
  var customTotal = res ? 0 : customLines.reduce(function (s, c) {
    return s + (Number(c.amount) || 0);
  }, 0);
  var sellPrice = Math.max(0, sellBase + customTotal);
  var grossMargin = sellPrice - totalBuy;
  var grossMarginPct = sellPrice > 0 ? grossMargin / sellPrice * 100 : 0;

  // Commission
  var commTier = getCommTier(grossMarginPct);
  var commPct = commTier ? commTier.pct : 0;
  var commEur = sellPrice * (commPct / 100);
  var commCap = grossMargin * 0.35;
  var commFinal = margeModel ? margeModel.commissie : Math.min(commEur, commCap);
  var netMargin = grossMargin - commFinal;
  var netMarginPct = sellPrice > 0 ? netMargin / sellPrice * 100 : 0;

  // VAT
  var btwAmount = res && res.marge && window.calcMargeInstellingen && +window.calcMargeInstellingen().btw === +btw ? Math.round((res.totaalIncl - res.verkoopExcl) * 100) / 100 : sellPrice * (btw / 100);
  var totalInclVAT = sellPrice + btwAmount;

  // kWp
  var kWp = nPanels * panelWp / 1000;
  var kwhTot = res ? res.kwh : battKwh;
  var heeftBatt = res ? res.lijnen.some(function (l) {
    return l.regel === 'batterij';
  }) : !!battery;
  var profielType = res ? res.profiel.regels.some(function (r) {
    return r.id === 'zonnepanelen';
  }) ? heeftBatt ? 'Zonnepanelen + batterij' : 'Zonnepanelen' : 'Thuisbatterij' : null;
  var vsStd = window.ghsVoorschotStd ? window.ghsVoorschotStd(profielType || 'Zonnepanelen') : 0;
  var vsPct = vsKeuze != null ? vsKeuze : vsStd;
  var lineItems = res ? res.lijnen.map(function (l) {
    return _objectSpread({
      cat: l.cat,
      name: l.regel === 'zonnepanelen' ? "".concat(l.qty, "\xD7 ").concat(l.naam) : l.regel === 'opstart' ? "".concat(l.naam) : "".concat(l.qty > 1 && l.regel !== 'montage' && l.regel !== 'plaatsing' ? l.qty + '× ' : '').concat(l.naam).concat(l.regel === 'montage' || l.regel === 'plaatsing' ? " \xB7 ".concat(l.qty, " pan.") : ''),
      qty: l.qty,
      buy: l.buy,
      total: l.totaal,
      art: l.art || null,
      regel: l.regel
    }, l.bom ? {
      bom: {
        lines: l.bom.lines,
        total: l.bom.total
      }
    } : {});
  }) : [{
    cat: 'ZONNEPANELEN',
    name: "".concat(nPanels, "\xD7 ").concat(panel ? panel.name : '—'),
    qty: nPanels,
    buy: prijs(panel),
    total: buyPanels,
    art: panel
  }].concat(_toConsumableArray(inverter ? [{
    cat: 'OMVORMER',
    name: inverter.name,
    qty: 1,
    buy: prijs(inverter),
    total: buyInverter,
    art: inverter
  }] : []), _toConsumableArray(battery ? [{
    cat: 'BATTERIJ',
    name: battery.name,
    qty: 1,
    buy: prijs(battery),
    total: buyBattery,
    art: battery
  }] : []), _toConsumableArray(optimizer ? [{
    cat: 'OPTIMIZER',
    name: optimizer.name,
    qty: optimizerQty,
    buy: prijs(optimizer),
    total: buyOptimizers,
    art: optimizer
  }] : []), _toConsumableArray(montageLines), _toConsumableArray(plaatsingLines), _toConsumableArray(dcArt ? [{
    cat: 'DC-BEKABELING',
    name: "".concat(dcMeters, " m \xD7 ").concat(fmtEur(dcPrijs)),
    qty: dcMeters,
    buy: dcPrijs,
    total: buyDC,
    art: dcArt
  }] : []), _toConsumableArray(aansluiting ? [{
    cat: 'AANSLUITING',
    name: aansluiting.name,
    qty: 1,
    buy: buyAansluiting,
    total: buyAansluiting,
    art: aansluiting
  }] : []), _toConsumableArray(opstart ? [{
    cat: 'OPSTART',
    name: opstart.name,
    qty: 1,
    buy: buyOpstart,
    total: buyOpstart,
    art: opstart
  }] : []), _toConsumableArray(keuring ? [{
    cat: 'KEURING & OPMETING',
    name: keuring.name,
    qty: 1,
    buy: buyKeuring,
    total: buyKeuring,
    art: keuring
  }] : []), _toConsumableArray(extraLines), _toConsumableArray(bundelLines));
  // Controle: enkel de artikels die in deze offerte staan
  /* In een samenstelling rekent de margekeuze de verkoopprijs: enkel een ontbrekende aankoopprijs blokkeert dan. */
  var offerteIssues = calcCheckArticles(lineItems.map(function (l) {
    return l.art;
  }).filter(Boolean), {
    margeMotor: !!res
  });

  // Publish current snapshot to parent wizard whenever the price changes
  React.useEffect(function () {
    if (!onSave) return;
    onSave(_objectSpread(_objectSpread({
      product: 'solar',
      klant: clientName,
      kWp: kWp,
      kwh: kwhTot,
      sellPrice: sellPrice,
      btw: btw,
      btwAmount: btwAmount,
      totalInclVAT: totalInclVAT,
      lineItems: lineItems
    }, res ? {
      items: res.items,
      calc: window.calcMotorSnapshot ? window.calcMotorSnapshot(res) : null,
      type: profielType,
      profielLabel: res.profiel.label
    } : {}), {}, {
      summary: {
        panelen: "".concat(nPanels, "\xD7 ").concat(panel ? panel.name : '—'),
        omvormer: inverter ? inverter.name : '—',
        batterij: battery ? "".concat(battery.name, " (").concat(battKwh, " kWh)") : null,
        montage: dakvlakken.map(function (d) {
          var m = d.montageId === MONTAGE_INLEG_ID ? 'ALIUS inleg' : (byId(d.montageId) || {}).name || '—';
          return "".concat(m, " (").concat(d.panelen, "p)");
        }).join(' · ')
      }
    }));
    // intentionally only depend on the computed total + klant to avoid loops (samenstelling: ook de offertelijnen, het merk en de klasse)
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [totalInclVAT, sellPrice, clientName, res ? JSON.stringify([res.platform, res.klasse, res.items.map(function (i) {
    return [i.artId, i.qty, i.amount];
  })]) : '']);

  /* Het voorstel in de lay-out: dezelfde lijnen en bedragen als rechts in de samenvatting. */
  var calcDoc = function calcDoc() {
    return window.ghsCalcDoc ? window.ghsCalcDoc({
      cid: contactId || null,
      klant: clientName,
      verkoper: verkoperNaam,
      items: res ? res.items.map(function (it) {
        return {
          cat: it.korting ? '' : it.cat || '',
          name: it.korting ? 'Korting' : it.label.split(' — ').slice(1).join(' — ') || it.label,
          qty: it.qty,
          bedrag: it.amount
        };
      }) : lineItems.filter(function (li) {
        return (li.total || 0) > 0;
      }).map(function (li) {
        return {
          cat: li.cat,
          name: li.name,
          qty: li.qty,
          bedrag: li.total / (1 - targetMargin / 100)
        };
      }),
      sub: sellPrice,
      btwPct: btw,
      btwBedrag: btwAmount,
      totaal: totalInclVAT,
      kWp: kWp,
      kwh: kwhTot,
      summary: {
        panelen: nPanels ? "".concat(nPanels, "\xD7 ").concat(panel ? panel.name : '—') : '',
        omvormer: inverter ? inverter.name : '—',
        batterij: battery ? "".concat(battery.name, " (").concat(battKwh, " kWh)") : null
      }
    }) : null;
  };
  var aansluitLijst = calcArtList(arts, 'montage_elek', 'aansluiting');
  var faseVan = function faseVan(a) {
    return /3\s*fase/i.test(a && a.name || '') ? '3' : '1';
  };
  var backupVan = function backupVan(a) {
    return /back-?up/i.test(a && a.name || '');
  };
  var kiesAansluiting = function kiesAansluiting(f, b) {
    var hit = aansluitLijst.find(function (a) {
      return faseVan(a) === f && backupVan(a) === b;
    }) || aansluitLijst.find(function (a) {
      return faseVan(a) === f && !backupVan(a);
    }) || aansluitLijst[0];
    if (hit) setAansluitingId(hit.id);
  };

  // Lege plaatshouder als een categorie (nog) geen artikels heeft — vóór ctx, anders is ze daar nog undefined.
  var leeg = {
    id: '',
    name: '—',
    buy: 0,
    watt: 0,
    kwh: 0,
    supplier: '',
    pricePerPanel: 0,
    family: 'pan'
  };
  // Shared context handed to each alternative Stap-2 layout (same state, different indeling/interactie)
  var ctx = {
    adminMode: adminMode,
    mode: mode,
    toonPV: toonPV,
    toonBatt: toonBatt,
    panel: panel ? asPanel(panel) : leeg,
    setPanelId: setPanelId,
    nPanels: nPanels,
    setTotalPanels: setTotalPanels,
    dakvlakken: dakvlakken,
    setNDakvlakken: setNDakvlakken,
    updateDakvlak: updateDakvlak,
    inverter: inverter ? asInverter(inverter) : leeg,
    setInverterId: setInverterId,
    battery: battery ? asBattery(battery) : _objectSpread(_objectSpread({}, leeg), {}, {
      id: 'none',
      name: 'Geen batterij'
    }),
    setBatteryId: setBatteryId,
    optimizer: optimizer ? asSimple(optimizer) : _objectSpread(_objectSpread({}, leeg), {}, {
      id: 'none',
      name: 'Geen optimizers'
    }),
    optimizerQty: optimizerQty,
    setOptimizerQty: setOptimizerQty,
    setOptimizerId: function setOptimizerId(id) {
      _setOptimizerId(id);
      if (id !== 'none' && optimizerQty === 0) setOptimizerQty(nPanels);
    },
    dcMeters: dcMeters,
    setDcMeters: setDcMeters,
    aansluiting: aansluiting ? asSimple(aansluiting) : leeg,
    aansluitingId: aansluitingId,
    setAansluitingId: setAansluitingId,
    fase: faseVan(aansluiting),
    setFase: function setFase(v) {
      return kiesAansluiting(v, backupVan(aansluiting));
    },
    backup: backupVan(aansluiting),
    setBackup: function setBackup(b) {
      return kiesAansluiting(faseVan(aansluiting), b);
    },
    opstart: opstart ? asSimple(opstart) : leeg,
    setOpstartId: setOpstartId,
    keuring: keuring ? asSimple(keuring) : _objectSpread(_objectSpread({}, leeg), {}, {
      id: 'none',
      name: 'Geen keuring'
    }),
    setKeuringId: setKeuringId,
    extras: extraArts.map(asSimple),
    toggleExtra: function toggleExtra(ex) {
      return _toggleExtra(typeof ex === 'string' ? ex : ex.id);
    },
    targetMargin: targetMargin,
    setTargetMargin: setTargetMargin,
    btw: btw,
    setBtw: setBtw,
    kWp: kWp,
    buyPanels: buyPanels,
    buyMontage: buyMontage,
    buyPlaatsing: buyPlaatsing,
    buyDC: buyDC,
    buyInverter: buyInverter,
    buyBattery: buyBattery,
    buyOptimizers: buyOptimizers,
    buyAansluiting: buyAansluiting,
    profiel: res ? res.profiel : null,
    platform: profPlatform,
    velden: velden,
    setVeld: setVeld,
    nPanelen: nPanels,
    res: res
  };

  // ── Oude vorm voor de alternatieve weergaven (solar_calc_layouts*.jsx) ────
  var PANELS_L = calcArtList(arts, 'zonnepanelen').map(asPanel);
  var INVERTERS_L = calcArtList(arts, 'omvormers').map(asInverter);
  var BATTERIES_L = [{
    id: 'none',
    name: 'Geen batterij',
    kwh: 0,
    buy: 0,
    inCalc: true
  }].concat(_toConsumableArray(calcArtList(arts, 'batterijen').map(asBattery)));
  var OPTIMIZERS_L = [{
    id: 'none',
    name: 'Geen optimizers',
    buy: 0,
    inCalc: true
  }].concat(_toConsumableArray(calcArtList(arts, 'optimizers').map(asSimple)));
  var MONTAGE_L = [LEGACY_INLEG].concat(_toConsumableArray(calcArtList(arts, 'montage_dak', 'montage').map(asMontage)));
  var PLAATSING_L = calcArtList(arts, 'montage_dak', 'plaatsing').map(asMontage);
  var AANSLUIT_L = calcArtList(arts, 'montage_elek', 'aansluiting').map(asSimple);
  var OPSTART_L = calcArtList(arts, 'diensten', 'opstart').map(asSimple);
  var KEURING_L = [{
    id: 'none',
    name: 'Geen keuring',
    buy: 0,
    inCalc: true
  }].concat(_toConsumableArray(calcArtList(arts, 'keuring').map(asSimple)));
  var EXTRA_L = calcArtList(arts, 'diensten', 'extra').map(asSimple);
  Object.assign(window, {
    PANELS: PANELS_L,
    INVERTERS: INVERTERS_L,
    BATTERIES: BATTERIES_L,
    OPTIMIZERS: OPTIMIZERS_L,
    MONTAGE_TYPES: MONTAGE_L,
    PLAATSING_OPTS: PLAATSING_L,
    AANSLUITING: AANSLUIT_L,
    OPSTART: OPSTART_L,
    KEURING_OPTS: KEURING_L,
    EXTRA_OPTS: EXTRA_L,
    DC_PRICE_PER_M: dcPrijs,
    plaatsingForFamily: function plaatsingForFamily(fam) {
      var e = PLAATSING_L.filter(function (p) {
        return p.family === fam;
      });
      return e.length ? e : PLAATSING_L;
    },
    familyOfMontage: function familyOfMontage(id) {
      return (MONTAGE_L.find(function (m) {
        return m.id === id;
      }) || MONTAGE_L[0] || {
        family: 'pan'
      }).family;
    }
  });
  var typeLabel = {
    zp_batt: 'Zonnepanelen + batterij',
    zp: 'Zonnepanelen',
    batt: 'Thuisbatterij'
  }[mode] || 'Zonnepanelen';
  /* De kop van de samenvatting draagt de kleur van de samenstelling: groen met panelen, paars voor enkel een batterij. */
  var samenTitel = profielType || typeLabel;
  var kopKleur = samenTitel === 'Thuisbatterij' ? '#bf63ff' : T.accent;
  /* Deal aanmaken op de contactfiche — met alle offertelijnen op verkoopprijs. */
  var maakDeal = function maakDeal() {
    if (!contactId || !window.crmStore) {
      setMelding({
        ok: false,
        text: 'Kies eerst een contact in stap 1 — een deal hoort altijd bij een klant.'
      });
      return;
    }
    /* Samenstelling: de offertelijnen en het rekenresultaat komen uit de rekenmotor (zelfde bedragen als de Excel). */
    if (res && res.marge) {
      var snap = window.calcMotorSnapshot ? window.calcMotorSnapshot(res) : null;
      var naam = window.calcDealNaam && snap ? window.calcDealNaam(snap) : res.profiel.label;
      var _ref9 = window.crmStore.addDeal(contactId, {
        name: naam,
        type: profielType,
        items: res.items,
        btwPct: btw,
        kwp: res.kWp,
        kwh: kwhTot,
        voorschotPct: vsPct,
        verkoper: verkoperNaam || undefined,
        calc: snap,
        opmCatVoorstel: res.nPanelen ? 'cat2' : 'cat1'
      });
      setMelding({
        ok: true,
        text: "Deal ".concat(_ref9, " aangemaakt op de contactfiche \u2014 daar kan je meteen de opmeting opstarten.")
      });
      return;
    }
    /* Met de margekeuze: elke lijn krijgt het aandeel van zijn deel (installatie of batterij), zoals de Excel de twee lijnen verdeelt. */
    var isBat = function isBat(l) {
        return !!(battery && l.art && l.art.id === battery.id);
      },
      d1 = totalBuy - buyBattery;
    var gew = function gew(l) {
      return (margeModel ? isBat(l) ? buyBattery ? margeModel.lijnen[1].na / buyBattery : 0 : d1 ? margeModel.lijnen[0].na / d1 : 0 : 1) * (l.total || 0);
    };
    var basis = lineItems.reduce(function (s, l) {
      return s + gew(l);
    }, 0);
    var items = lineItems.filter(function (l) {
      return (l.total || 0) > 0;
    }).map(function (l) {
      return {
        label: l.cat ? "".concat(l.cat, " \u2014 ").concat(l.name) : l.name,
        detail: '',
        qty: l.qty || 1,
        artId: l.art ? l.art.id : null,
        amount: Math.round((basis > 0 ? gew(l) / basis * sellPrice : l.total) * 100) / 100
      };
    });
    var ref = window.crmStore.addDeal(contactId, {
      name: "".concat(typeLabel).concat(nPanels ? " \u2014 ".concat(nPanels, " panelen") : '').concat(battKwh ? " + ".concat(battKwh, " kWh") : ''),
      type: typeLabel,
      items: items,
      btwPct: btw,
      kwp: kWp,
      kwh: battKwh,
      voorschotPct: vsPct,
      verkoper: clientName ? undefined : undefined,
      opmCatVoorstel: toonPV ? 'cat2' : 'cat1'
    });
    setMelding({
      ok: true,
      text: "Deal ".concat(ref, " aangemaakt op de contactfiche \u2014 daar kan je meteen de opmeting opstarten.")
    });
  };
  /* Concept bewaren: de volledige configuratie, terug te vinden per klant. */
  var bewaarConcept = function bewaarConcept() {
    var concept = _objectSpread({
      id: 'cpt' + Date.now(),
      datum: new Date().toISOString(),
      contactId: contactId,
      klant: clientName || klant,
      mode: mode,
      panelId: panelId,
      dakvlakken: dakvlakken,
      inverterId: inverterId,
      batteryId: batteryId,
      optimizerId: optimizerId,
      optimizerQty: optimizerQty,
      dcMeters: dcMeters,
      aansluitingId: aansluitingId,
      opstartId: opstartId,
      keuringId: keuringId,
      extraIds: extraIds,
      extraQty: extraQty,
      customLines: customLines,
      targetMargin: targetMargin,
      btw: btw,
      totaal: totalInclVAT,
      verkoop: sellPrice,
      aankoop: totalBuy,
      profiel: profAct ? profAct.id : null,
      margeklasse: margeModel ? margeModel.klasse : null,
      doelmarge: margeModel ? margeModel.marge : null,
      korting: margeModel ? margeModel.korting : 0,
      prijsVoorKorting: margeModel ? margeModel.prijsVoorKorting : null
    }, res ? {
      samenstelling: profielId,
      platform: profPlatform,
      velden: velden,
      kortingGevraagd: korting,
      calc: window.calcMotorSnapshot ? window.calcMotorSnapshot(res) : null
    } : {});
    try {
      var key = 'ghs_calc_concepten_v1';
      var lijst = JSON.parse(localStorage.getItem(key) || '[]');
      localStorage.setItem(key, JSON.stringify([concept].concat(_toConsumableArray(Array.isArray(lijst) ? lijst : [])).slice(0, 50)));
      setMelding({
        ok: true,
        text: "Concept bewaard (".concat(fmtEur(totalInclVAT), ") \u2014 terug te vinden bij deze klant.")
      });
    } catch (e) {
      setMelding({
        ok: false,
        text: 'Concept kon niet bewaard worden in deze weergave.'
      });
    }
  };
  var LAYOUTS = [{
    id: 'dak_persp',
    label: 'Perspectief',
    icon: 'grid'
  }, {
    id: 'dak_oneblock',
    label: 'Één paneel',
    icon: 'package'
  }, {
    id: 'dak_table',
    label: 'Tabel',
    icon: 'list'
  }, {
    id: 'dak_master',
    label: 'Master-detail',
    icon: 'sun'
  }];
  return /*#__PURE__*/React.createElement("div", null, !embedded && /*#__PURE__*/React.createElement(Topbar, {
    title: "Calculator",
    user: {
      name: 'Nick De Roeck'
    }
  }), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      gap: 0,
      height: embedded ? 'auto' : 'calc(100vh - 58px)',
      overflow: embedded ? 'visible' : 'hidden',
      minHeight: embedded ? 600 : 'auto'
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      flex: '1 1 0',
      minWidth: 0,
      overflowY: 'auto',
      padding: '18px 20px 24px'
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      justifyContent: 'space-between',
      alignItems: 'center',
      gap: 14,
      flexWrap: 'wrap',
      marginBottom: 16
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      minWidth: 0,
      flex: '1 1 280px'
    }
  }, /*#__PURE__*/React.createElement("h2", {
    style: {
      margin: 0,
      fontFamily: T.fontDisplay,
      fontSize: 19,
      fontWeight: 600,
      color: T.fg1,
      lineHeight: 1.25
    }
  }, profielModus ? 'Offerte samenstellen' : 'Nieuwe offerte'), /*#__PURE__*/React.createElement("div", {
    style: {
      fontFamily: T.fontBody,
      fontSize: 12.5,
      color: T.fg3,
      marginTop: 3,
      lineHeight: 1.45
    }
  }, embedded && klant ? 'Kies de panelen, verdeel ze over de dakvlakken en vul het systeem aan. Rechts zie je meteen wat de klant krijgt en betaalt.' : clientName ? "Voor ".concat(clientName, ". Rechts zie je meteen wat de klant krijgt en betaalt.") : 'Kies de panelen en het systeem. Rechts zie je meteen wat de klant krijgt en betaalt.')), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      alignItems: 'center',
      gap: 10,
      flexWrap: 'wrap'
    }
  }, !(embedded && klant) && /*#__PURE__*/React.createElement("div", {
    style: {
      width: 200
    }
  }, /*#__PURE__*/React.createElement(Input, {
    value: clientName,
    onChange: setClientName,
    placeholder: "Naam klant"
  })), /*#__PURE__*/React.createElement("button", {
    type: "button",
    role: "switch",
    "aria-checked": intern,
    onClick: function onClick() {
      return setKlantmodus(!klantmodus);
    },
    title: intern ? 'Admin modus staat aan: calculatorprofiel, margeklasse, commissie en rekeninfo zijn zichtbaar. Klik om ze te verbergen als de klant meekijkt.' : 'Admin modus staat uit: de klant kan meekijken. Klik om het calculatorprofiel, de margeklasse en de commissie te tonen.',
    style: {
      display: 'flex',
      alignItems: 'center',
      gap: 11,
      minHeight: 44,
      padding: '6px 14px 6px 12px',
      background: intern ? 'rgba(0,217,0,0.08)' : T.bg0,
      border: "1px solid ".concat(intern ? T.strokeAccent : T.stroke2),
      clipPath: cutPath(8),
      cursor: 'pointer',
      textAlign: 'left'
    }
  }, /*#__PURE__*/React.createElement(Icon, {
    name: intern ? 'eye' : 'eyeoff',
    size: 16,
    color: intern ? T.accent : T.fg3
  }), /*#__PURE__*/React.createElement("span", {
    style: {
      display: 'flex',
      flexDirection: 'column',
      gap: 1
    }
  }, /*#__PURE__*/React.createElement("span", {
    style: {
      fontFamily: T.fontBody,
      fontSize: 12.5,
      fontWeight: 700,
      color: T.fg1
    }
  }, "Admin modus"), /*#__PURE__*/React.createElement("span", {
    style: {
      fontFamily: T.fontBody,
      fontSize: 11,
      color: T.fg3
    }
  }, intern ? 'Profiel, marge en commissie zichtbaar' : 'Verborgen: de klant kan meekijken')), /*#__PURE__*/React.createElement("span", {
    "aria-hidden": "true",
    style: {
      width: 34,
      height: 19,
      borderRadius: 10,
      background: intern ? T.accent : T.bg3,
      position: 'relative',
      transition: 'background 200ms',
      flexShrink: 0,
      marginLeft: 2
    }
  }, /*#__PURE__*/React.createElement("span", {
    style: {
      width: 13,
      height: 13,
      borderRadius: '50%',
      background: '#fff',
      position: 'absolute',
      top: 3,
      left: intern ? 18 : 3,
      transition: 'left 200ms'
    }
  }))))), !profielModus && /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      alignItems: 'center',
      gap: 10,
      marginBottom: 14,
      flexWrap: 'wrap'
    }
  }, /*#__PURE__*/React.createElement("span", {
    style: {
      fontFamily: T.fontBody,
      fontSize: 9,
      fontWeight: 700,
      letterSpacing: '0.14em',
      textTransform: 'uppercase',
      color: T.fg4
    }
  }, "Weergave"), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'inline-flex',
      background: T.bg0,
      border: "1px solid ".concat(T.stroke1),
      borderRadius: 999,
      padding: 3,
      gap: 2
    }
  }, LAYOUTS.map(function (l) {
    var on = layout === l.id;
    return /*#__PURE__*/React.createElement("button", {
      key: l.id,
      onClick: function onClick() {
        return setLayout(l.id);
      },
      style: {
        display: 'flex',
        alignItems: 'center',
        gap: 6,
        cursor: 'pointer',
        background: on ? 'rgba(0,217,0,0.14)' : 'transparent',
        border: "1px solid ".concat(on ? T.strokeAccent : 'transparent'),
        borderRadius: 999,
        padding: '6px 13px',
        color: on ? T.accent : T.fg3,
        fontFamily: T.fontBody,
        fontSize: 12,
        fontWeight: 700,
        transition: 'all 160ms'
      }
    }, /*#__PURE__*/React.createElement(Icon, {
      name: l.icon,
      size: 13,
      color: on ? T.accent : T.fg3
    }), " ", l.label);
  }))), intern && window.GhsCalcProfielKiezer && /*#__PURE__*/React.createElement(window.GhsCalcProfielKiezer, {
    vastId: profielId,
    zonderMerk: profielModus
  }), (profielModus || layout === 'dak_persp') && /*#__PURE__*/React.createElement(LayoutDakPersp, {
    ctx: ctx
  }), !profielModus && layout === 'dak_oneblock' && /*#__PURE__*/React.createElement(LayoutDakOneBlock, {
    ctx: ctx
  }), !profielModus && layout === 'dak_table' && /*#__PURE__*/React.createElement(LayoutDakTable, {
    ctx: ctx
  }), !profielModus && layout === 'dak_master' && /*#__PURE__*/React.createElement(LayoutDakMaster, {
    ctx: ctx
  }), layout === 'kolommen' && /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      gap: 10,
      alignItems: 'flex-start',
      flexWrap: 'wrap'
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      flex: '1 1 300px',
      minWidth: 280,
      display: 'flex',
      flexDirection: 'column',
      gap: 10
    }
  }, toonPV && /*#__PURE__*/React.createElement(CalcSection, {
    compact: true,
    title: "1 \xB7 ZONNEPANELEN",
    icon: "sun"
  }, /*#__PURE__*/React.createElement(GhsSelect, {
    label: "Type paneel",
    value: panelId,
    onChange: setPanelId,
    options: calcArtOptions(arts, 'zonnepanelen', '', adminMode, function (a) {
      return "".concat(Number((a.specs || {}).wp) || '?', " Wp");
    })
  }), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'grid',
      gridTemplateColumns: '1fr 1fr',
      gap: 8,
      marginTop: 8
    }
  }, /*#__PURE__*/React.createElement(NumInput, {
    label: "Aantal panelen",
    value: nPanels,
    onChange: setTotalPanels,
    min: 0,
    max: 400
  }), /*#__PURE__*/React.createElement(NumInput, {
    label: "Dakvlakken",
    value: dakvlakken.length,
    onChange: setNDakvlakken,
    min: 1,
    max: 8
  })), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      gap: 6,
      flexWrap: 'wrap',
      marginTop: 8
    }
  }, /*#__PURE__*/React.createElement(Badge, {
    type: "accent"
  }, kWp.toFixed(2).replace('.', ','), " kWp"), adminMode && /*#__PURE__*/React.createElement(Badge, {
    type: "neutral"
  }, fmtEur(buyPanels)), panel && /*#__PURE__*/React.createElement(Badge, {
    type: "neutral"
  }, panel.supplier || panel.brand || panel.code))), toonPV && /*#__PURE__*/React.createElement(CalcSection, {
    compact: true,
    title: "2 \xB7 MONTAGEMATERIAAL \u2014 PER DAKVLAK",
    icon: "package"
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      flexDirection: 'column',
      gap: 8
    }
  }, dakvlakken.map(function (dv, i) {
    var isInleg = dv.montageId === MONTAGE_INLEG_ID;
    var m = isInleg ? null : byId(dv.montageId);
    var fam = isInleg ? 'pan' : dakFamilyOf(m);
    return /*#__PURE__*/React.createElement("div", {
      key: dv.id,
      style: {
        display: 'grid',
        gridTemplateColumns: '64px 84px 1fr',
        gap: 8,
        alignItems: 'end',
        background: T.bg0,
        border: "1px solid ".concat(T.stroke1),
        clipPath: cutPath(8),
        padding: '8px 10px'
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        flexDirection: 'column',
        gap: 2
      }
    }, /*#__PURE__*/React.createElement("span", {
      style: {
        fontFamily: T.fontBody,
        fontSize: 9,
        fontWeight: 700,
        letterSpacing: '0.1em',
        textTransform: 'uppercase',
        color: T.accent
      }
    }, "Dak ", i + 1), /*#__PURE__*/React.createElement("span", {
      style: {
        fontFamily: T.fontBody,
        fontSize: 10,
        color: T.fg3
      }
    }, DAK_FAMILY_LABEL[fam] || '—')), /*#__PURE__*/React.createElement(NumInput, {
      label: "Pan.",
      value: dv.panelen,
      onChange: function onChange(v) {
        return updateDakvlak(dv.id, {
          panelen: v
        });
      },
      min: 0,
      max: 400
    }), /*#__PURE__*/React.createElement(GhsSelect, {
      label: "Montage",
      value: dv.montageId,
      onChange: function onChange(id) {
        return updateDakvlak(dv.id, {
          montageId: id
        });
      },
      options: [{
        value: MONTAGE_INLEG_ID,
        label: 'ALIUS INLEG — stuklijst uit montagegroepen'
      }].concat(_toConsumableArray(calcArtOptions(arts, 'montage_dak', 'montage', adminMode)))
    }), isInleg && /*#__PURE__*/React.createElement("div", {
      style: {
        gridColumn: '1 / -1',
        display: 'flex',
        gap: 8,
        alignItems: 'end',
        flexWrap: 'wrap'
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        width: 84
      }
    }, /*#__PURE__*/React.createElement(NumInput, {
      label: "Rijen",
      value: dv.rows || 1,
      onChange: function onChange(v) {
        return updateDakvlak(dv.id, {
          rows: Math.max(1, Math.min(3, Number(v) || 1))
        });
      },
      min: 1,
      max: 3
    })), /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        gap: 4
      }
    }, [['portrait', 'Portrait'], ['landscape', 'Landscape']].map(function (_ref0) {
      var _ref1 = _slicedToArray(_ref0, 2),
        o = _ref1[0],
        l = _ref1[1];
      return /*#__PURE__*/React.createElement("button", {
        key: o,
        onClick: function onClick() {
          return updateDakvlak(dv.id, {
            orient: o
          });
        },
        style: {
          padding: '7px 12px',
          background: (dv.orient || 'portrait') === o ? 'rgba(0,217,0,0.12)' : T.bg2,
          border: "1px solid ".concat((dv.orient || 'portrait') === o ? T.accent : T.stroke1),
          borderRadius: 5,
          cursor: 'pointer',
          color: (dv.orient || 'portrait') === o ? T.accent : T.fg2,
          fontFamily: T.fontBody,
          fontSize: 11,
          fontWeight: 600
        }
      }, l);
    }))), isInleg && window.mgBomForPanels && dv.panelen > 0 && function () {
      var bom = mgBomForPanels(dv.rows || 1, dv.orient || 'portrait', dv.panelen);
      if (!bom) return null;
      return /*#__PURE__*/React.createElement("div", {
        style: {
          gridColumn: '1 / -1',
          background: T.bg1,
          border: "1px solid ".concat(T.stroke1),
          clipPath: cutPath(8),
          padding: '8px 11px'
        }
      }, /*#__PURE__*/React.createElement("div", {
        style: {
          display: 'flex',
          alignItems: 'baseline',
          gap: 8,
          marginBottom: 6
        }
      }, /*#__PURE__*/React.createElement("span", {
        style: {
          fontFamily: T.fontBody,
          fontSize: 9.5,
          fontWeight: 700,
          letterSpacing: '0.12em',
          color: T.accent
        }
      }, "STUKLIJST MONTAGE"), /*#__PURE__*/React.createElement("span", {
        style: {
          fontFamily: T.fontBody,
          fontSize: 10,
          color: T.fg4
        }
      }, bom.group.name, " \xB7 ", dv.panelen, " panelen", bom.exact ? '' : " \u2014 materiaal voor ".concat(bom.covered).concat(bom.velden > 1 ? " (".concat(bom.velden, " velden \xD7 ").concat(bom.colPanels, ")") : ''))), bom.lines.map(function (l) {
        return /*#__PURE__*/React.createElement("div", {
          key: l.code,
          style: {
            display: 'flex',
            justifyContent: 'space-between',
            gap: 8,
            padding: '2px 0'
          }
        }, /*#__PURE__*/React.createElement("span", {
          style: {
            fontFamily: T.fontBody,
            fontSize: 10.5,
            color: T.fg2
          }
        }, l.qty, "\xD7 ", l.name), adminMode && /*#__PURE__*/React.createElement("span", {
          style: {
            fontFamily: T.fontDisplay,
            fontSize: 10.5,
            color: T.fg3,
            fontVariantNumeric: 'tabular-nums'
          }
        }, fmtEur(l.total)));
      }), adminMode && /*#__PURE__*/React.createElement("div", {
        style: {
          display: 'flex',
          justifyContent: 'space-between',
          gap: 8,
          marginTop: 5,
          paddingTop: 5,
          borderTop: "1px solid ".concat(T.stroke1)
        }
      }, /*#__PURE__*/React.createElement("span", {
        style: {
          fontFamily: T.fontBody,
          fontSize: 10.5,
          fontWeight: 700,
          color: T.fg1
        }
      }, "Montagemateriaal \xB7 ", fmtEur(bom.perPanel), "/paneel"), /*#__PURE__*/React.createElement("span", {
        style: {
          fontFamily: T.fontDisplay,
          fontSize: 12,
          fontWeight: 600,
          color: T.accent,
          fontVariantNumeric: 'tabular-nums'
        }
      }, fmtEur(bom.total))));
    }());
  })), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      gap: 6,
      marginTop: 8,
      flexWrap: 'wrap'
    }
  }, /*#__PURE__*/React.createElement(Badge, {
    type: nPanels > 0 ? 'accent' : 'warning'
  }, nPanels, " verdeeld"), adminMode && /*#__PURE__*/React.createElement(Badge, {
    type: "neutral"
  }, fmtEur(buyMontage)))), toonPV && /*#__PURE__*/React.createElement(CalcSection, {
    compact: true,
    title: "3 \xB7 PLAATSING \u2014 VOLGT DAK-TYPE",
    icon: "grid"
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      flexDirection: 'column',
      gap: 8
    }
  }, dakvlakken.map(function (dv, i) {
    var isInleg = dv.montageId === MONTAGE_INLEG_ID;
    var fam = isInleg ? 'pan' : dakFamilyOf(byId(dv.montageId));
    var opts = plaatsingForDak(arts, fam);
    return /*#__PURE__*/React.createElement("div", {
      key: dv.id,
      style: {
        display: 'grid',
        gridTemplateColumns: '64px 1fr',
        gap: 8,
        alignItems: 'end',
        background: T.bg0,
        border: "1px solid ".concat(T.stroke1),
        clipPath: cutPath(8),
        padding: '8px 10px'
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        flexDirection: 'column',
        gap: 2
      }
    }, /*#__PURE__*/React.createElement("span", {
      style: {
        fontFamily: T.fontBody,
        fontSize: 9,
        fontWeight: 700,
        letterSpacing: '0.1em',
        textTransform: 'uppercase',
        color: T.accent
      }
    }, "Dak ", i + 1), /*#__PURE__*/React.createElement("span", {
      style: {
        fontFamily: T.fontBody,
        fontSize: 10,
        color: T.fg3
      }
    }, DAK_FAMILY_LABEL[fam] || '—')), /*#__PURE__*/React.createElement(GhsSelect, {
      label: "Plaatsing",
      value: dv.plaatsingId,
      onChange: function onChange(id) {
        return updateDakvlak(dv.id, {
          plaatsingId: id
        });
      },
      options: opts.map(function (p) {
        return {
          value: p.id,
          label: calcArtLabel(p, adminMode)
        };
      })
    }));
  })), adminMode && /*#__PURE__*/React.createElement("div", {
    style: {
      marginTop: 8
    }
  }, /*#__PURE__*/React.createElement(Badge, {
    type: "neutral"
  }, fmtEur(buyPlaatsing))))), /*#__PURE__*/React.createElement("div", {
    style: {
      flex: '1 1 300px',
      minWidth: 280,
      display: 'flex',
      flexDirection: 'column',
      gap: 10
    }
  }, /*#__PURE__*/React.createElement(CalcSection, {
    compact: true,
    title: "4 \xB7 OMVORMER, BATTERIJ & OPTIMIZERS",
    icon: "zap"
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      flexDirection: 'column',
      gap: 8
    }
  }, /*#__PURE__*/React.createElement(GhsSelect, {
    label: "Omvormer",
    value: inverterId,
    onChange: setInverterId,
    options: calcArtOptions(arts, 'omvormers', '', adminMode, function (a) {
      return "".concat(Number((a.specs || {}).acKw) || '?', " kW").concat((a.specs || {}).hybride ? ' · hybride' : '');
    })
  }), toonBatt && /*#__PURE__*/React.createElement(GhsSelect, {
    label: "Batterij",
    value: batteryId,
    onChange: setBatteryId,
    options: [{
      value: 'none',
      label: 'Geen batterij'
    }].concat(_toConsumableArray(calcArtOptions(arts, 'batterijen', '', adminMode, function (a) {
      return "".concat(Number((a.specs || {}).kwh) || '?', " kWh");
    })))
  }), toonPV && /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'grid',
      gridTemplateColumns: '1fr auto',
      gap: 8,
      alignItems: 'end'
    }
  }, /*#__PURE__*/React.createElement(GhsSelect, {
    label: "Optimizers",
    value: optimizerId,
    onChange: function onChange(id) {
      _setOptimizerId(id);
      if (id !== 'none' && optimizerQty === 0) setOptimizerQty(nPanels);
    },
    options: [{
      value: 'none',
      label: 'Geen optimizers'
    }].concat(_toConsumableArray(calcArtOptions(arts, 'optimizers', '', adminMode)))
  }), optimizer && /*#__PURE__*/React.createElement(NumInput, {
    label: "Aantal",
    value: optimizerQty,
    onChange: setOptimizerQty,
    min: 0,
    max: nPanels
  }))), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      gap: 6,
      marginTop: 8,
      flexWrap: 'wrap'
    }
  }, /*#__PURE__*/React.createElement(Badge, {
    type: invHyb ? 'accent' : 'neutral'
  }, invFase), invHyb && /*#__PURE__*/React.createElement(Badge, {
    type: "accent"
  }, "Hybride"), invKw > 0 && /*#__PURE__*/React.createElement(Badge, {
    type: "neutral"
  }, invKw, " kW"), battery && /*#__PURE__*/React.createElement(Badge, {
    type: "info"
  }, battKwh, " kWh"), adminMode && /*#__PURE__*/React.createElement(Badge, {
    type: "neutral"
  }, fmtEur(buyInverter + buyBattery + buyOptimizers)))), toonPV && /*#__PURE__*/React.createElement(CalcSection, {
    compact: true,
    title: "5 \xB7 DC-BEKABELING",
    icon: "zap"
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'grid',
      gridTemplateColumns: '140px 1fr',
      gap: 10,
      alignItems: 'end'
    }
  }, /*#__PURE__*/React.createElement(NumInput, {
    label: "Aantal meter",
    value: dcMeters,
    onChange: setDcMeters,
    min: 0,
    max: 300,
    suffix: "m"
  }), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      gap: 6,
      flexWrap: 'wrap'
    }
  }, /*#__PURE__*/React.createElement(Badge, {
    type: "neutral"
  }, fmtEur(dcPrijs), "/m"), adminMode && /*#__PURE__*/React.createElement(Badge, {
    type: "neutral"
  }, fmtEur(buyDC))))), /*#__PURE__*/React.createElement(CalcSection, {
    compact: true,
    title: "6 \xB7 AANSLUITING",
    icon: "zap"
  }, /*#__PURE__*/React.createElement(GhsSelect, {
    label: "Aansluiting",
    value: aansluitingId,
    onChange: setAansluitingId,
    options: calcArtOptions(arts, 'montage_elek', 'aansluiting', adminMode)
  }), /*#__PURE__*/React.createElement("div", {
    style: {
      marginTop: 8
    }
  }, /*#__PURE__*/React.createElement(GhsSelect, {
    label: "Opstart regio",
    value: opstartId,
    onChange: setOpstartId,
    options: calcArtOptions(arts, 'diensten', 'opstart', adminMode)
  })), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      gap: 6,
      marginTop: 8,
      flexWrap: 'wrap'
    }
  }, aansluiting && /*#__PURE__*/React.createElement(Badge, {
    type: "neutral"
  }, aansluiting.name), adminMode && /*#__PURE__*/React.createElement(Badge, {
    type: "neutral"
  }, fmtEur(buyAansluiting + buyOpstart))))), /*#__PURE__*/React.createElement("div", {
    style: {
      flex: '1 1 300px',
      minWidth: 280,
      display: 'flex',
      flexDirection: 'column',
      gap: 10
    }
  }, /*#__PURE__*/React.createElement(CalcSection, {
    compact: true,
    title: "7 \xB7 KEURING & OPMETING",
    icon: "check"
  }, /*#__PURE__*/React.createElement(GhsSelect, {
    value: keuringId,
    onChange: setKeuringId,
    options: [{
      value: 'none',
      label: 'Geen keuring'
    }].concat(_toConsumableArray(calcArtOptions(arts, 'keuring', '', adminMode)))
  })), /*#__PURE__*/React.createElement(CalcSection, {
    compact: true,
    title: "8 \xB7 EXTRA'S",
    icon: "plus"
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      flexWrap: 'wrap',
      gap: 6
    }
  }, calcArtList(arts, 'diensten', 'extra').map(function (ex) {
    var on = extraIds.includes(ex.id);
    return /*#__PURE__*/React.createElement("button", {
      key: ex.id,
      onClick: function onClick() {
        return _toggleExtra(ex.id);
      },
      style: {
        background: on ? 'rgba(0,217,0,0.12)' : T.bg2,
        border: "1px solid ".concat(on ? T.strokeAccent : T.stroke1),
        borderRadius: 4,
        padding: '5px 10px',
        cursor: 'pointer',
        color: on ? T.accent : ex.inCalc === true ? T.fg2 : T.fg4,
        fontFamily: T.fontBody,
        fontSize: 11,
        fontWeight: 600
      }
    }, on ? '✓ ' : ex.inCalc === true ? '' : '○ ', ex.name, adminMode ? " (".concat(fmtEur(ex.buyPrice), ")") : '');
  })), extraLines.some(function (l) {
    return l.art && ['stuk', 'meter', 'uur'].includes(l.art.calcUnit);
  }) && /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      flexWrap: 'wrap',
      gap: 8,
      marginTop: 9
    }
  }, extraLines.filter(function (l) {
    return l.art && ['stuk', 'meter', 'uur'].includes(l.art.calcUnit);
  }).map(function (l) {
    return /*#__PURE__*/React.createElement("div", {
      key: l.art.id,
      style: {
        width: 118
      }
    }, /*#__PURE__*/React.createElement(NumInput, {
      label: "".concat(l.art.name.slice(0, 14), " (").concat(l.art.calcUnit, ")"),
      value: Number(extraQty[l.art.id]) || 1,
      min: 1,
      max: 999,
      onChange: function onChange(v) {
        return setExtraQty(function (q) {
          return _objectSpread(_objectSpread({}, q), {}, _defineProperty({}, l.art.id, Math.max(1, Number(v) || 1)));
        });
      }
    }));
  }))), /*#__PURE__*/React.createElement(CalcSection, {
    compact: true,
    title: "9 \xB7 BTW",
    icon: "percent"
  }, /*#__PURE__*/React.createElement(GhsSelect, {
    label: "BTW tarief",
    value: String(btw),
    onChange: function onChange(v) {
      return setBtw(Number(v));
    },
    options: [{
      value: '6',
      label: '6% (residentieel)'
    }, {
      value: '21',
      label: '21% (standaard)'
    }].concat(btwVerlegdKan ? [{
      value: '0',
      label: '0% (btw verlegd)'
    }] : [])
  }))))), /*#__PURE__*/React.createElement("aside", {
    "aria-label": "Offerte samenvatting",
    style: {
      flex: '0 0 auto',
      width: 'clamp(340px, 31vw, 450px)',
      borderLeft: "1px solid ".concat(T.stroke1),
      background: T.bg0,
      overflowY: embedded ? 'visible' : 'auto'
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      position: 'relative',
      overflow: 'hidden',
      isolation: 'isolate',
      padding: '20px 22px 18px 26px',
      background: "radial-gradient(110% 170% at 0% 0%, ".concat(kopKleur, "2e 0%, ").concat(kopKleur, "0a 40%, transparent 66%), linear-gradient(100deg, rgba(0,0,0,0.10) 0%, rgba(0,0,0,0.36) 100%), ").concat(T.bg0),
      borderBottom: "1px solid ".concat(kopKleur, "3d")
    }
  }, /*#__PURE__*/React.createElement("span", {
    "aria-hidden": "true",
    style: {
      position: 'absolute',
      left: 0,
      top: 0,
      bottom: 0,
      width: 4,
      background: kopKleur,
      boxShadow: "0 0 18px ".concat(kopKleur)
    }
  }), /*#__PURE__*/React.createElement("span", {
    "aria-hidden": "true",
    style: {
      position: 'absolute',
      right: 0,
      top: 0,
      bottom: 0,
      width: 180,
      background: "repeating-linear-gradient(115deg, transparent 0 22px, ".concat(kopKleur, "0a 22px 23px)"),
      maskImage: 'linear-gradient(90deg, transparent, #000 70%)',
      WebkitMaskImage: 'linear-gradient(90deg, transparent, #000 70%)',
      pointerEvents: 'none',
      zIndex: -1
    }
  }), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      alignItems: 'flex-start',
      gap: 10
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      flex: 1,
      minWidth: 0
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: OS_LBL
  }, "Offerte samenvatting"), /*#__PURE__*/React.createElement("div", {
    style: {
      fontFamily: T.fontDisplay,
      fontSize: 19,
      fontWeight: 600,
      color: T.fg1,
      lineHeight: 1.25,
      marginTop: 5
    }
  }, samenTitel)), /*#__PURE__*/React.createElement("button", {
    type: "button",
    onClick: undo,
    disabled: !undoN,
    title: undoN ? "Laatste wijziging ongedaan maken (".concat(undoN, " stap").concat(undoN > 1 ? 'pen' : '', " terug mogelijk)") : 'Niets om ongedaan te maken',
    style: {
      display: 'inline-flex',
      alignItems: 'center',
      gap: 5,
      background: undoN ? T.bg2 : 'transparent',
      border: "1px solid ".concat(undoN ? T.stroke2 : T.stroke1),
      borderRadius: 5,
      padding: '6px 10px',
      cursor: undoN ? 'pointer' : 'default',
      color: undoN ? T.fg1 : T.fg4,
      fontFamily: T.fontBody,
      fontSize: 11.5,
      fontWeight: 700,
      flexShrink: 0
    }
  }, /*#__PURE__*/React.createElement(Icon, {
    name: "chevronleft",
    size: 12,
    color: undoN ? T.accent : T.fg4
  }), "Ongedaan", undoN ? " (".concat(undoN, ")") : '')), (nPanels > 0 || kWp > 0 || kwhTot > 0) && /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      gap: 8,
      marginTop: 12,
      flexWrap: 'wrap'
    }
  }, nPanels > 0 && /*#__PURE__*/React.createElement(OsChip, null, "".concat(nPanels, " panelen")), kWp > 0 && /*#__PURE__*/React.createElement(OsChip, {
    kleur: T.accent
  }, "".concat(kWp.toFixed(2).replace('.', ','), " kWp")), kwhTot > 0 && /*#__PURE__*/React.createElement(OsChip, {
    kleur: "#bf63ff"
  }, "".concat(String(kwhTot).replace('.', ','), " kWh opslag")))), /*#__PURE__*/React.createElement("div", {
    style: {
      padding: '6px 22px 26px'
    }
  }, offerteIssues.length > 0 && /*#__PURE__*/React.createElement("div", {
    style: {
      marginTop: 16
    }
  }, /*#__PURE__*/React.createElement(CalcIssuePanel, {
    issues: offerteIssues,
    title: "Artikels in deze offerte",
    compact: true
  })), /*#__PURE__*/React.createElement(OsSectie, {
    titel: "Wat de klant krijgt",
    rechts: res ? function (n) {
      return n === 1 ? '1 post' : "".concat(n, " posten");
    }(res.items.filter(function (it) {
      return !it.korting;
    }).length) : null,
    eerste: true
  }, res && function () {
    /* Eerst de installatie (deel 1), dan de batterij (deel 2): een iets sterkere lijn waar de batterij begint. */
    var posten = res.items.filter(function (it) {
        return !it.korting;
      }),
      d1 = posten.filter(function (it) {
        return it.deel !== 2;
      }),
      d2 = posten.filter(function (it) {
        return it.deel === 2;
      });
    return [].concat(_toConsumableArray(d1), _toConsumableArray(d2)).map(function (it, i) {
      return /*#__PURE__*/React.createElement(OsPost, {
        key: i,
        cat: it.cat,
        naam: osPostNaam(it),
        detail: osPostDetail(it),
        scheiding: d1.length > 0 && i === d1.length,
        sub: it.stuklijst ? "Stuklijst: ".concat(it.stuklijst.length, " onderdelen gaan uit de stock") : null,
        bedrag: fmtEur(it.amount)
      });
    });
  }(), !res && lineItems.filter(function (li) {
    return li.total > 0;
  }).map(function (li, i) {
    var deel = totalBuy > 0 ? li.total / totalBuy * sellBase : 0;
    return /*#__PURE__*/React.createElement(OsPost, {
      key: i,
      cat: li.cat,
      naam: li.name,
      sub: li.bom ? li.bom.lines.map(function (b) {
        return "".concat(b.qty, "\xD7 ").concat(b.name);
      }).join(' · ') : null,
      bedrag: fmtEur(deel)
    });
  }), !res && customLines.map(function (c) {
    return /*#__PURE__*/React.createElement("div", {
      key: c.id,
      style: {
        display: 'flex',
        alignItems: 'center',
        gap: 8,
        padding: '8px 0',
        borderTop: "1px solid ".concat(T.stroke1)
      }
    }, /*#__PURE__*/React.createElement("input", {
      value: c.name,
      onChange: function onChange(e) {
        return setCustomLines(function (p) {
          return p.map(function (x) {
            return x.id === c.id ? _objectSpread(_objectSpread({}, x), {}, {
              name: e.target.value
            }) : x;
          });
        });
      },
      "aria-label": "Omschrijving van de regel",
      style: {
        flex: 1,
        minWidth: 0,
        boxSizing: 'border-box',
        padding: '7px 9px',
        background: T.bg2,
        border: "1px solid ".concat(T.stroke1),
        borderRadius: 4,
        outline: 'none',
        color: T.fg1,
        fontFamily: T.fontBody,
        fontSize: 12.5
      }
    }), /*#__PURE__*/React.createElement("input", {
      type: "number",
      step: "10",
      value: c.amount,
      onChange: function onChange(e) {
        return setCustomLines(function (p) {
          return p.map(function (x) {
            return x.id === c.id ? _objectSpread(_objectSpread({}, x), {}, {
              amount: e.target.value
            }) : x;
          });
        });
      },
      "aria-label": "Bedrag van de regel",
      style: {
        width: 92,
        boxSizing: 'border-box',
        padding: '7px 9px',
        background: T.bg2,
        border: "1px solid ".concat(T.stroke1),
        borderRadius: 4,
        outline: 'none',
        color: (Number(c.amount) || 0) < 0 ? '#ff5a4d' : T.fg1,
        fontFamily: T.fontDisplay,
        fontSize: 13,
        fontWeight: 600,
        textAlign: 'right'
      }
    }), /*#__PURE__*/React.createElement("button", {
      onClick: function onClick() {
        return setCustomLines(function (p) {
          return p.filter(function (x) {
            return x.id !== c.id;
          });
        });
      },
      title: "Regel verwijderen",
      style: {
        background: 'none',
        border: 'none',
        cursor: 'pointer',
        color: T.fg4,
        padding: 4
      }
    }, /*#__PURE__*/React.createElement(Icon, {
      name: "trash",
      size: 13
    })));
  }), !res && /*#__PURE__*/React.createElement("button", {
    onClick: function onClick() {
      return setCustomLines(function (p) {
        return [].concat(_toConsumableArray(p), [{
          id: 'cl' + Date.now(),
          name: '',
          amount: 0
        }]);
      });
    },
    style: {
      display: 'flex',
      alignItems: 'center',
      gap: 6,
      width: '100%',
      marginTop: 10,
      padding: '9px 11px',
      background: 'transparent',
      border: "1px dashed ".concat(T.stroke1),
      borderRadius: 5,
      cursor: 'pointer',
      color: T.fg3,
      fontFamily: T.fontBody,
      fontSize: 12,
      fontWeight: 600
    }
  }, /*#__PURE__*/React.createElement(Icon, {
    name: "plus",
    size: 12,
    color: "currentColor"
  }), "Regel toevoegen \u2014 korting of meerprijs")), /*#__PURE__*/React.createElement(OsSectie, {
    titel: "Prijs"
  }, customLines.length > 0 && /*#__PURE__*/React.createElement(OsRij, {
    label: "Verkoop v\xF3\xF3r aanpassingen",
    waarde: fmtEur(sellBase)
  }), customLines.filter(function (c) {
    return Number(c.amount);
  }).map(function (c) {
    return /*#__PURE__*/React.createElement(OsRij, {
      key: c.id,
      label: c.name.trim() || 'Aanpassing',
      waarde: fmtEur(Number(c.amount) || 0)
    });
  }), margeModel && /*#__PURE__*/React.createElement(OsRij, {
    label: intern ? "Prijs v\xF3\xF3r korting \xB7 ".concat(margeModel.klasse) : 'Prijs vóór korting',
    waarde: fmtEur(margeModel.prijsVoorKorting)
  }), res ? window.GhsProfielKorting && /*#__PURE__*/React.createElement(window.GhsProfielKorting, {
    res: res,
    korting: korting,
    setKorting: setKorting,
    intern: intern
  }) : margeModel && margeModel.korting > 0 && /*#__PURE__*/React.createElement(OsRij, {
    label: "Korting",
    waarde: fmtEur(-margeModel.korting),
    oranje: true
  }), /*#__PURE__*/React.createElement(OsRij, {
    label: "Verkoopprijs excl. btw",
    waarde: fmtEur(sellPrice),
    sterk: true,
    geenLijn: !margeModel && !customLines.length
  })), /*#__PURE__*/React.createElement("div", {
    style: {
      position: 'relative',
      marginTop: 16,
      padding: '16px 18px 18px 20px',
      background: "radial-gradient(120% 170% at 100% 0%, rgba(0,217,0,0.18) 0%, rgba(0,217,0,0.05) 42%, transparent 70%), linear-gradient(180deg, ".concat(T.bg2, ", ").concat(T.bg1, ")"),
      border: "1px solid ".concat(T.strokeAccent),
      clipPath: cutPath(12)
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: accentEdge(12)
  }), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      alignItems: 'center',
      justifyContent: 'space-between',
      gap: 10
    }
  }, /*#__PURE__*/React.createElement("label", {
    style: {
      display: 'inline-flex',
      alignItems: 'center',
      gap: 8,
      fontFamily: T.fontBody,
      fontSize: 13,
      color: T.fg2
    }
  }, "Btw", /*#__PURE__*/React.createElement("select", {
    value: String(btw),
    onChange: function onChange(e) {
      return setBtw(Number(e.target.value));
    },
    "aria-label": "Btw-tarief",
    style: {
      height: 32,
      background: T.bg0,
      border: "1px solid ".concat(T.stroke2),
      borderRadius: 5,
      padding: '0 8px',
      color: T.fg1,
      fontFamily: T.fontBody,
      fontSize: 13,
      fontWeight: 600,
      cursor: 'pointer'
    }
  }, /*#__PURE__*/React.createElement("option", {
    value: "6"
  }, "6 %"), /*#__PURE__*/React.createElement("option", {
    value: "21"
  }, "21 %"), btwVerlegdKan && /*#__PURE__*/React.createElement("option", {
    value: "0"
  }, "0 % (verlegd)"))), /*#__PURE__*/React.createElement("span", {
    style: {
      fontFamily: T.fontDisplay,
      fontSize: 14,
      fontWeight: 600,
      color: T.fg1,
      fontVariantNumeric: 'tabular-nums',
      whiteSpace: 'nowrap'
    }
  }, fmtEur(btwAmount))), /*#__PURE__*/React.createElement("div", {
    style: _objectSpread(_objectSpread({}, OS_SUB), {}, {
      marginTop: 6
    })
  }, +btw === 0 ? 'Btw verlegd: onderneming met btw-nummer (medecontractant).' : +btw === 6 ? '6 % voor een woning ouder dan 10 jaar (renovatie).' : '21 % voor een woning jonger dan 10 jaar of een bedrijf.'), /*#__PURE__*/React.createElement("div", {
    style: {
      height: 1,
      background: "linear-gradient(90deg, ".concat(T.strokeAccent, ", rgba(0,217,0,0.05))"),
      margin: '14px 0 12px'
    }
  }), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      alignItems: 'flex-end',
      justifyContent: 'space-between',
      gap: 10,
      flexWrap: 'wrap'
    }
  }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
    style: {
      fontFamily: T.fontBody,
      fontSize: 13,
      fontWeight: 700,
      color: T.fg1
    }
  }, "Totaal incl. btw"), /*#__PURE__*/React.createElement("div", {
    style: _objectSpread(_objectSpread({}, OS_SUB), {}, {
      marginTop: 2
    })
  }, res && res.marge && window.calcMargeInstellingen && +window.calcMargeInstellingen().btw === +btw ? 'Wat de klant betaalt, afgerond op 9.' : 'Wat de klant betaalt.')), /*#__PURE__*/React.createElement("span", {
    style: {
      fontFamily: T.fontDisplay,
      fontSize: 30,
      fontWeight: 600,
      color: T.accent,
      letterSpacing: '-0.02em',
      fontVariantNumeric: 'tabular-nums',
      textShadow: '0 0 22px rgba(0,217,0,0.35)',
      lineHeight: 1
    }
  }, fmtEur(totalInclVAT)))), /*#__PURE__*/React.createElement("div", {
    style: {
      marginTop: 14
    }
  }, window.GhsVoorschotBlok && /*#__PURE__*/React.createElement(window.GhsVoorschotBlok, {
    totaal: totalInclVAT,
    pct: vsPct,
    onPct: setVsPct,
    std: vsStd,
    compact: true
  })), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      flexDirection: 'column',
      gap: 10,
      marginTop: 14
    }
  }, /*#__PURE__*/React.createElement(Button, {
    variant: "primary",
    fullWidth: true,
    icon: "handshake",
    disabled: totalBuy <= 0,
    onClick: maakDeal
  }, "Deal aanmaken"), /*#__PURE__*/React.createElement(Button, {
    variant: "beige",
    fullWidth: true,
    icon: "send",
    onClick: function onClick() {
      return setShowPDF(true);
    }
  }, "Offerte genereren")), melding && /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      alignItems: 'center',
      gap: 8,
      marginTop: 12,
      padding: '10px 12px',
      background: melding.ok ? 'rgba(0,217,0,0.10)' : 'rgba(255,176,32,0.10)',
      border: "1px solid ".concat(melding.ok ? T.strokeAccent : 'rgba(255,176,32,0.4)'),
      clipPath: cutPath(8)
    }
  }, /*#__PURE__*/React.createElement(Icon, {
    name: melding.ok ? 'check' : 'alert',
    size: 14,
    color: melding.ok ? T.accent : '#ffb020'
  }), /*#__PURE__*/React.createElement("span", {
    style: {
      flex: 1,
      fontFamily: T.fontBody,
      fontSize: 12,
      color: melding.ok ? T.fg2 : '#ffb020',
      lineHeight: 1.5
    }
  }, melding.text), melding.ok && contactId && /*#__PURE__*/React.createElement("button", {
    onClick: function onClick() {
      return window.crmStore.openFiche(contactId, 'deals');
    },
    style: {
      background: 'none',
      border: 'none',
      cursor: 'pointer',
      color: T.fg3,
      fontFamily: T.fontBody,
      fontSize: 11.5,
      whiteSpace: 'nowrap'
    }
  }, "Fiche openen")), intern && /*#__PURE__*/React.createElement(OsSectie, {
    titel: "Intern",
    rechts: "Enkel in admin modus"
  }, res && res.marge && /*#__PURE__*/React.createElement(OsRij, {
    label: "Commissie".concat(verkoperNaam ? ' ' + verkoperNaam.split(' ')[0] : '').concat(res.regeling === 'eigen' ? '' : ' · ' + res.marge.klasse),
    waarde: res.regeling === 'eigen' ? 'eigen regeling' : fmtEur(res.commissie || 0)
  }), adminMode && /*#__PURE__*/React.createElement(OsRij, {
    label: "Aankoopprijs totaal",
    waarde: fmtEur(totalBuy)
  }), margeModel && adminMode && /*#__PURE__*/React.createElement(OsRij, {
    label: "Doelmarge na commissie (margekeuze)",
    waarde: "".concat(margeModel.marge.toFixed(2).replace('.', ','), " %")
  }), adminMode && /*#__PURE__*/React.createElement(OsRij, {
    label: "Brutomarge v\xF3\xF3r commissie (".concat(grossMarginPct.toFixed(1).replace('.', ','), " %)"),
    waarde: fmtEur(grossMargin)
  }), !res && adminMode && commTier && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(OsRij, {
    label: "Commissie tier ".concat(COMM_TIERS.indexOf(commTier) + 1, " \xB7 ").concat(commPct, " % van de omzet"),
    waarde: fmtEur(commEur)
  }), /*#__PURE__*/React.createElement(OsRij, {
    label: "Max 35 % van de marge",
    waarde: fmtEur(commCap)
  }), /*#__PURE__*/React.createElement(OsRij, {
    label: "Definitieve commissie",
    waarde: fmtEur(commFinal),
    sterk: true
  }), /*#__PURE__*/React.createElement(OsRij, {
    label: "Nettomarge na commissie (".concat(netMarginPct.toFixed(1).replace('.', ','), " %)"),
    waarde: fmtEur(netMargin),
    sterk: true
  })), adminMode && /*#__PURE__*/React.createElement("details", {
    style: {
      marginTop: 10,
      border: "1px solid ".concat(T.stroke1),
      clipPath: cutPath(8),
      background: T.bg1
    }
  }, /*#__PURE__*/React.createElement("summary", {
    style: {
      cursor: 'pointer',
      padding: '10px 12px',
      fontFamily: T.fontBody,
      fontSize: 12.5,
      fontWeight: 700,
      color: T.fg2
    }
  }, "Kostenlijst (aankoop) \xB7 ".concat(lineItems.length, " lijnen")), /*#__PURE__*/React.createElement("div", {
    style: {
      padding: '0 12px 10px'
    }
  }, lineItems.map(function (li, i) {
    return /*#__PURE__*/React.createElement("div", {
      key: i,
      style: {
        display: 'flex',
        justifyContent: 'space-between',
        alignItems: 'center',
        gap: 8,
        padding: '7px 0',
        borderTop: "1px solid ".concat(T.stroke1)
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        flex: 1,
        minWidth: 0
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: OS_CAT
    }, li.cat), /*#__PURE__*/React.createElement("div", {
      style: {
        fontSize: 12.5,
        color: T.fg1,
        fontFamily: T.fontBody,
        fontWeight: 500
      }
    }, li.name)), /*#__PURE__*/React.createElement("span", {
      style: {
        fontSize: 13,
        fontFamily: T.fontDisplay,
        fontWeight: 600,
        color: T.fg1,
        fontVariantNumeric: 'tabular-nums'
      }
    }, fmtEur(li.total)), li.bundleId && /*#__PURE__*/React.createElement("button", {
      onClick: function onClick() {
        return setSkipBundels(function (prev) {
          return [].concat(_toConsumableArray(prev), [li.bundleId]);
        });
      },
      title: "Bundel uit deze offerte halen (de bundel zelf blijft bestaan)",
      style: {
        background: 'none',
        border: 'none',
        cursor: 'pointer',
        color: T.fg4,
        padding: 2,
        lineHeight: 1
      }
    }, /*#__PURE__*/React.createElement(Icon, {
      name: "x",
      size: 12,
      color: "currentColor"
    })), li.cat === 'EXTRA' && li.art && /*#__PURE__*/React.createElement("button", {
      onClick: function onClick() {
        return _toggleExtra(li.art.id);
      },
      title: "Extra artikel uit deze offerte halen",
      style: {
        background: 'none',
        border: 'none',
        cursor: 'pointer',
        color: T.fg4,
        padding: 2,
        lineHeight: 1
      }
    }, /*#__PURE__*/React.createElement(Icon, {
      name: "x",
      size: 12,
      color: "currentColor"
    })));
  }), bundelWeg.length > 0 && /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      flexWrap: 'wrap',
      gap: 5,
      marginTop: 7
    }
  }, bundelWeg.map(function (bx) {
    return /*#__PURE__*/React.createElement("button", {
      key: bx.bundle.id,
      onClick: function onClick() {
        return setSkipBundels(function (prev) {
          return prev.filter(function (x) {
            return x !== bx.bundle.id;
          });
        });
      },
      title: "Bundel opnieuw toevoegen aan deze offerte",
      style: {
        display: 'inline-flex',
        alignItems: 'center',
        gap: 5,
        background: 'rgba(255,176,32,0.10)',
        border: '1px solid rgba(255,176,32,0.4)',
        borderRadius: 5,
        padding: '3px 9px',
        cursor: 'pointer',
        color: '#ffb020',
        fontFamily: T.fontBody,
        fontSize: 10.5,
        fontWeight: 700
      }
    }, /*#__PURE__*/React.createElement(Icon, {
      name: "plus",
      size: 10,
      color: "#ffb020"
    }), bx.bundle.naam || (bx.trigger ? 'Bundel ' + bx.trigger.name : 'Bundel'), " \u2014 verwijderd");
  })))), res && window.GhsProfielInfo && /*#__PURE__*/React.createElement(window.GhsProfielInfo, {
    res: res,
    adminMode: adminMode
  })), !res && !adminMode && !commTier && grossMarginPct > 0 && grossMarginPct < 15 && /*#__PURE__*/React.createElement("div", {
    style: {
      background: 'rgba(255,176,32,0.1)',
      border: '1px solid rgba(255,176,32,0.3)',
      clipPath: cutPath(8),
      padding: 10,
      marginTop: 12
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      fontSize: 12,
      color: '#ffb020',
      fontFamily: T.fontBody
    }
  }, "\u26A0 Marge onder minimum 15%"))))), showPDF && window.GhsLayoutDocModal && /*#__PURE__*/React.createElement(window.GhsLayoutDocModal, {
    g: calcDoc(),
    titel: "Prijsvoorstel",
    uitleg: "Het voorstel zoals het nu in de calculator staat \u2014 zonder verbintenis.",
    onClose: function onClose() {
      return setShowPDF(false);
    }
  }));
};
Object.assign(window, {
  SolarBatteryCalc: SolarBatteryCalc,
  PANELS: PANELS,
  INVERTERS: INVERTERS,
  BATTERIES: BATTERIES,
  MONTAGE_TYPES: MONTAGE_TYPES
});