"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 _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 _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); }
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 _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 _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 _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; }
// GHS — Calculator Wizard (sandbox)
// 3 stappen: Informatie → Calculator → Klantportaal
// Wraps SolarBatteryCalc + alternate product calculators

/* ─────────────────────────────────────────────────────── PRODUCTEN */
var PRODUCTS = [{
  id: 'zp_batt',
  name: 'Zonnepanelen + Batterij',
  icon: 'sun',
  color: '#00D900',
  desc: 'Volledige installatie met batterijopslag'
}, {
  id: 'zp',
  name: 'Zonnepanelen',
  icon: 'sun',
  color: '#ffb020',
  desc: 'Enkel PV-panelen + omvormer'
}, {
  id: 'batt',
  name: 'Batterij',
  icon: 'battery',
  color: '#bf63ff',
  desc: 'Retrofit op bestaande PV-installatie'
}, {
  id: 'laadpaal',
  name: 'Laadpaal',
  icon: 'zap',
  color: '#00aaff',
  desc: 'EV-laadpunten enkel- of dual-poorts'
}, {
  id: 'airco',
  name: 'Airconditioning',
  icon: 'wind',
  color: '#7DD3FC',
  desc: 'Mono- of multi-split koeling & verwarming'
}, {
  id: 'warmtepomp',
  name: 'Warmtepomp',
  icon: 'thermometer',
  color: '#ff5a4d',
  desc: 'Lucht/water of geothermisch'
}, {
  id: 'andere',
  name: 'Andere',
  icon: 'plus',
  color: '#6b8a8a',
  desc: 'Vrij samengestelde offerte'
}];

/* Zonnepanelen en batterijen: één tegel per samenstelling (calculatorprofiel = een tabblad van de calculator-Excel).
   Zonder profielen blijven de oude tegels zonnepanelen / batterij staan. */
var LEGACY_SOLAR = ['zp_batt', 'zp', 'batt'];
/* Enkel de actieve profielen die voor de huidige gebruiker openstaan (Admin en Office zien ze allemaal). */
var profielProducten = function profielProducten() {
  return (window.calcProfielen ? window.calcProfielen() : []).filter(function (p) {
    return p.actief !== false && (!window.calcProfielVoorGebruiker || window.calcProfielVoorGebruiker(p));
  }).map(function (p) {
    var heeft = function heeft(id) {
        return p.regels.some(function (r) {
          return (r && r.id ? r.id : r) === id;
        });
      },
      zp = heeft('zonnepanelen'),
      bat = heeft('batterij');
    var voor = p.verkopersModus === 'enkel' ? p.verkopers || [] : null;
    return {
      id: p.id,
      name: p.label,
      icon: zp ? 'sun' : 'battery',
      color: zp ? '#00D900' : '#bf63ff',
      profiel: true,
      zp: zp,
      bat: bat,
      desc: window.calcProfielOmschrijving ? window.calcProfielOmschrijving(p) : zp ? "Panelen, montage en plaatsing met het ".concat(p.platforms.join(' / '), "-systeem") : "".concat(p.platforms.join(' / '), ": batterij, omvormer en aansluiting \u2014 zonder panelen"),
      voor: voor ? voor.length ? "Enkel voor ".concat(voor.map(function (n) {
        return n.split(' ')[0];
      }).join(', ')) : 'Enkel voor Admin en Office' : null
    };
  });
};
var alleProducten = function alleProducten() {
  var pr = profielProducten();
  return pr.length ? [].concat(_toConsumableArray(pr), _toConsumableArray(PRODUCTS.filter(function (p) {
    return !LEGACY_SOLAR.includes(p.id);
  }))) : PRODUCTS;
};
var productBestaat = function productBestaat(id) {
  return alleProducten().some(function (p) {
    return p.id === id;
  }) || PRODUCTS.some(function (p) {
    return p.id === id && !profielProducten().length;
  });
};
/* Een profiel dat intussen verwijderd of uitgezet is, breekt een lopende wizard niet. */
var productById = function productById(id) {
  return alleProducten().find(function (p) {
    return p.id === id;
  }) || PRODUCTS.find(function (p) {
    return p.id === id && !profielProducten().length;
  }) || {
    id: id,
    name: 'Profiel niet meer beschikbaar',
    icon: 'package',
    color: '#8a8f98',
    desc: ''
  };
};

/* Lucide-style stroke icons for products not in shared.jsx */
var ProductIcon = function ProductIcon(_ref) {
  var id = _ref.id,
    _ref$size = _ref.size,
    size = _ref$size === void 0 ? 24 : _ref$size,
    color = _ref.color;
  var c = color || T.fg2;
  var props = {
    width: size,
    height: size,
    viewBox: '0 0 24 24',
    fill: 'none',
    stroke: c,
    strokeWidth: 1.6,
    strokeLinecap: 'round',
    strokeLinejoin: 'round'
  };
  if (id === 'wind') return /*#__PURE__*/React.createElement("svg", props, /*#__PURE__*/React.createElement("path", {
    d: "M17.7 7.7a2.5 2.5 0 1 1 1.8 4.3H2"
  }), /*#__PURE__*/React.createElement("path", {
    d: "M9.6 4.6A2 2 0 1 1 11 8H2"
  }), /*#__PURE__*/React.createElement("path", {
    d: "M12.6 19.4A2 2 0 1 0 14 16H2"
  }));
  if (id === 'thermometer') return /*#__PURE__*/React.createElement("svg", props, /*#__PURE__*/React.createElement("path", {
    d: "M14 4v10.54a4 4 0 1 1-4 0V4a2 2 0 0 1 4 0Z"
  }));
  return /*#__PURE__*/React.createElement(Icon, {
    name: id,
    size: size,
    color: c
  });
};

/* Get product id from a deal type string */
var inferProduct = function inferProduct(type) {
  if (!type) return null;
  var t = type.toLowerCase();
  if (t.includes('batterij') && t.includes('zonnepanelen')) return 'zp_batt';
  if (t.includes('zonnepanelen') && t.includes('warmtepomp')) return 'warmtepomp';
  if (t.includes('airco')) return 'airco';
  if (t.includes('warmtepomp')) return 'warmtepomp';
  if (t.includes('laadpaal')) return 'laadpaal';
  if (t.includes('zonnepanelen')) return 'zp';
  if (t.includes('batterij')) return 'batt';
  return null;
};

/* ─────────────────────────────────────────────────────── STEP HEADER */
var StepHeader = function StepHeader(_ref2) {
  var step = _ref2.step,
    setStep = _ref2.setStep,
    canGoTo = _ref2.canGoTo;
  var steps = [{
    id: 1,
    label: 'Informatie',
    icon: 'filetext'
  }, {
    id: 2,
    label: 'Calculator',
    icon: 'calculator'
  }, {
    id: 3,
    label: 'Klantportaal',
    icon: 'user'
  }];
  return /*#__PURE__*/React.createElement("div", {
    style: {
      borderBottom: "1px solid ".concat(T.stroke1),
      background: T.bg0,
      padding: '14px 24px'
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      alignItems: 'center',
      justifyContent: 'center',
      gap: 0,
      maxWidth: 760,
      margin: '0 auto'
    }
  }, steps.map(function (s, i) {
    var isActive = step === s.id;
    var isDone = step > s.id;
    var can = canGoTo(s.id);
    return /*#__PURE__*/React.createElement(React.Fragment, {
      key: s.id
    }, /*#__PURE__*/React.createElement("button", {
      disabled: !can,
      onClick: function onClick() {
        return can && setStep(s.id);
      },
      style: {
        background: 'transparent',
        border: 'none',
        cursor: can ? 'pointer' : 'default',
        display: 'flex',
        alignItems: 'center',
        gap: 10,
        padding: '6px 14px',
        opacity: can ? 1 : 0.45
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        width: 32,
        height: 32,
        borderRadius: '50%',
        background: isActive ? T.accent : isDone ? 'rgba(0,217,0,0.18)' : T.bg2,
        border: "1.5px solid ".concat(isActive ? T.accent : isDone ? T.accent : T.stroke1),
        boxShadow: isActive ? '0 0 14px rgba(0,217,0,0.4)' : 'none',
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'center',
        fontFamily: T.fontDisplay,
        fontSize: 14,
        fontWeight: 700,
        color: isActive ? T.bg0 : isDone ? T.accent : T.fg3,
        transition: 'all 220ms cubic-bezier(0.22,1,0.36,1)',
        flexShrink: 0
      }
    }, isDone ? /*#__PURE__*/React.createElement(Icon, {
      name: "check",
      size: 14,
      color: T.accent
    }) : s.id), /*#__PURE__*/React.createElement("div", {
      style: {
        textAlign: 'left'
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        fontSize: 9,
        fontFamily: T.fontBody,
        fontWeight: 700,
        letterSpacing: '0.16em',
        textTransform: 'uppercase',
        color: isActive ? T.accent : T.fg4
      }
    }, "STAP ", s.id), /*#__PURE__*/React.createElement("div", {
      style: {
        fontFamily: T.fontDisplay,
        fontSize: 13,
        fontWeight: 600,
        color: isActive ? T.fg1 : isDone ? T.fg2 : T.fg3
      }
    }, s.label))), i < steps.length - 1 && /*#__PURE__*/React.createElement("div", {
      style: {
        flex: 1,
        maxWidth: 80,
        height: 1,
        background: "linear-gradient(90deg, ".concat(step > s.id ? T.accent : T.stroke1, ", ").concat(step > s.id + 0.5 ? T.accent : T.stroke1, ")"),
        margin: '0 4px',
        opacity: 0.5
      }
    }));
  })));
};

/* ─────────────────────────────────────────────────────── STEP 1: INFORMATIE */
/* ── Btw: de woning, per offerte ──────────────────────────────────────────────
   Het tarief volgt de btw-regels (Instellingen › Btw-tarieven): per product, voor deze klant en
   deze woning. Zolang de woning onbekend is: het gewone tarief van het product. */
var CALC_BTW_STD = {
  zp_batt: 6,
  zp: 6,
  batt: 6,
  warmtepomp: 6,
  laadpaal: 21,
  airco: 21,
  andere: 21
};
var calcTypeVoor = function calcTypeVoor(pid) {
  var p = productById(pid) || {};
  if (p.profiel) return p.zp && p.bat ? 'Zonnepanelen + batterij' : p.zp ? 'Zonnepanelen' : 'Thuisbatterij';
  return {
    zp_batt: 'Zonnepanelen + batterij',
    zp: 'Zonnepanelen',
    batt: 'Thuisbatterij',
    laadpaal: 'Laadpaal',
    airco: 'Airco',
    warmtepomp: 'Warmtepomp',
    andere: 'Andere'
  }[pid] || p.name || 'Andere';
};
var calcContact = function calcContact(id) {
  return (window.crmStore && window.crmStore.getState().contacts || window.CONTACTS || []).find(function (c) {
    return c.id === id;
  }) || null;
};
var calcBtwInfo = function calcBtwInfo(data, pid) {
  var p = productById(pid) || {};
  var std = CALC_BTW_STD[pid] != null ? CALC_BTW_STD[pid] : p.profiel ? 6 : 21;
  var c = calcContact(data.contactId);
  if (!c || !window.ghsBtwVoorstel) return {
    pct: std,
    onbekend: true,
    reden: ''
  };
  /* Geen antwoorden in de calculator → wat bij een vorige offerte van deze klant gekend was. */
  var v = window.ghsBtwVoorstel(c, {
    type: calcTypeVoor(pid),
    woning: data.b2b ? null : data.woning
  });
  return v.pct == null ? {
    pct: std,
    onbekend: true,
    reden: v.reden
  } : {
    pct: Number(v.pct),
    onbekend: false,
    verlegd: !!v.verlegd,
    reden: v.reden
  };
};
var calcBtwVoor = function calcBtwVoor(data, pid) {
  return calcBtwInfo(data, pid).pct;
};
var CalcBtwWoning = function CalcBtwWoning(_ref3) {
  var data = _ref3.data,
    setData = _ref3.setData;
  var sel = data.products || [];
  var c = calcContact(data.contactId);
  var wNu = data.woning || (c && window.ghsWoningVan ? window.ghsWoningVan(c) : {});
  var zet = function zet(veld, waarde) {
    return setData(function (d) {
      return _objectSpread(_objectSpread({}, d), {}, {
        woning: _objectSpread(_objectSpread({}, d.woning || wNu), {}, _defineProperty({}, veld, waarde))
      });
    });
  };
  var info = sel.map(function (pid) {
    return _objectSpread({
      pid: pid,
      naam: productById(pid).name
    }, calcBtwInfo(data, pid));
  });
  var onbekend = info.some(function (x) {
    return x.onbekend;
  });
  return /*#__PURE__*/React.createElement("div", {
    "data-calc-btw": "",
    style: {
      background: T.bg1,
      border: "1px solid ".concat(T.stroke1),
      clipPath: cutPath(10),
      padding: '14px 16px',
      marginBottom: 18
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      alignItems: 'center',
      gap: 8,
      marginBottom: 10
    }
  }, /*#__PURE__*/React.createElement(Icon, {
    name: "percent",
    size: 14,
    color: T.accent
  }), /*#__PURE__*/React.createElement("span", {
    style: {
      fontFamily: T.fontBody,
      fontSize: 12.5,
      fontWeight: 700,
      color: T.fg1
    }
  }, "Btw \u2014 de woning"), /*#__PURE__*/React.createElement("span", {
    style: {
      fontFamily: T.fontBody,
      fontSize: 11.5,
      color: T.fg3
    }
  }, data.b2b ? 'onderneming: volgens de btw-regels' : 'bepaalt 6 % of 21 % voor deze offerte')), !data.b2b && window.GhsWoningVragen && /*#__PURE__*/React.createElement(window.GhsWoningVragen, {
    w: wNu,
    onZet: zet
  }), info.length > 0 && /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      gap: '6px 14px',
      flexWrap: 'wrap',
      marginTop: 10,
      fontFamily: T.fontBody,
      fontSize: 11.5,
      color: T.fg3
    }
  }, info.map(function (x) {
    return /*#__PURE__*/React.createElement("span", {
      key: x.pid,
      "data-calc-btw-product": x.pid
    }, x.naam, ": ", /*#__PURE__*/React.createElement("b", {
      style: {
        color: x.onbekend ? '#ffb020' : T.fg1
      }
    }, x.verlegd ? 'verlegd (0 %)' : "".concat(x.pct, " %")), x.onbekend ? ' (voorlopig)' : '');
  })), onbekend && !data.b2b && /*#__PURE__*/React.createElement("div", {
    style: {
      marginTop: 6,
      fontFamily: T.fontBody,
      fontSize: 11.5,
      color: '#ffb020',
      lineHeight: 1.5
    }
  }, "Vraag na hoe oud de woning is: tot dan rekent de calculator het gewone tarief van het product. Je kan het ook later in de offerte-editor invullen."));
};
var Step1Informatie = function Step1Informatie(_ref4) {
  var data = _ref4.data,
    setData = _ref4.setData,
    onNext = _ref4.onNext,
    fromDeal = _ref4.fromDeal;
  var sel = data.products || [];
  var canNext = sel.length > 0 && !!data.klant;
  var toggleProduct = function toggleProduct(pid) {
    return setData(function (d) {
      var cur = d.products || [];
      var next = cur.includes(pid) ? cur.filter(function (x) {
        return x !== pid;
      }) : [].concat(_toConsumableArray(cur), [pid]);
      // Drop offerte snapshots for products no longer selected
      var nextOffertes = Object.fromEntries(Object.entries(d.offertes || {}).filter(function (_ref5) {
        var _ref6 = _slicedToArray(_ref5, 1),
          k = _ref6[0];
        return next.includes(k);
      }));
      return _objectSpread(_objectSpread({}, d), {}, {
        products: next,
        offertes: nextOffertes
      });
    });
  };
  return /*#__PURE__*/React.createElement("div", {
    style: {
      maxWidth: 980,
      margin: '0 auto',
      padding: '32px 24px'
    }
  }, /*#__PURE__*/React.createElement(CalcContactCard, {
    data: data,
    setData: setData,
    fromDeal: fromDeal
  }), /*#__PURE__*/React.createElement("div", {
    style: {
      marginBottom: 18
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      fontSize: 10,
      fontFamily: T.fontBody,
      fontWeight: 700,
      letterSpacing: '0.18em',
      textTransform: 'uppercase',
      color: T.fg4,
      marginBottom: 4
    }
  }, "STAP 1 \u2014 INFORMATIE"), /*#__PURE__*/React.createElement("h2", {
    style: {
      margin: 0,
      fontFamily: T.fontDisplay,
      fontSize: 28,
      fontWeight: 600,
      color: T.fg1,
      letterSpacing: '-0.02em'
    }
  }, "Waarvoor wil je een offerte aanmaken?"), /*#__PURE__*/React.createElement("p", {
    style: {
      margin: '6px 0 0',
      fontSize: 13,
      color: T.fg3,
      fontFamily: T.fontBody
    }
  }, "Kies voor zonnepanelen en batterijen de samenstelling \u2014 zoals de tabbladen van de calculator. Meerdere keuzes = per keuze een aparte offerte.")), [['Zonnepanelen + batterij', function (p) {
    return p.profiel && p.zp && p.bat;
  }], ['Zonnepanelen', function (p) {
    return p.profiel && p.zp && !p.bat;
  }], ['Enkel batterij', function (p) {
    return p.profiel && !p.zp;
  }], [profielProducten().length ? 'Andere producten' : '', function (p) {
    return !p.profiel;
  }]].map(function (_ref7) {
    var _ref8 = _slicedToArray(_ref7, 2),
      titel = _ref8[0],
      past = _ref8[1];
    var groep = alleProducten().filter(past);
    if (!groep.length) return null;
    return /*#__PURE__*/React.createElement("div", {
      key: titel || 'alle',
      style: {
        marginBottom: 18
      }
    }, titel && /*#__PURE__*/React.createElement("div", {
      style: {
        fontSize: 10,
        fontFamily: T.fontBody,
        fontWeight: 700,
        letterSpacing: '0.14em',
        textTransform: 'uppercase',
        color: T.fg3,
        marginBottom: 8
      }
    }, titel), /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'grid',
        gridTemplateColumns: 'repeat(auto-fit,minmax(200px,1fr))',
        gap: 10
      }
    }, groep.map(function (p) {
      var on = sel.includes(p.id);
      var idx = sel.indexOf(p.id);
      return /*#__PURE__*/React.createElement("button", {
        key: p.id,
        onClick: function onClick() {
          return toggleProduct(p.id);
        },
        style: {
          background: on ? "".concat(p.color, "15") : T.bg1,
          border: "1px solid ".concat(on ? p.color : T.stroke1),
          clipPath: cutPath(12),
          padding: '18px 16px',
          cursor: 'pointer',
          textAlign: 'left',
          /* inhoud bovenaan: iconen en titels staan in een rij op dezelfde hoogte, ook bij langere tekst */
          display: 'flex',
          flexDirection: 'column',
          alignItems: 'flex-start',
          justifyContent: 'flex-start',
          transition: 'all 180ms',
          position: 'relative',
          overflow: 'hidden',
          boxShadow: on ? "0 0 24px ".concat(p.color, "30") : 'none'
        },
        onMouseEnter: function onMouseEnter(e) {
          if (!on) {
            e.currentTarget.style.borderColor = T.stroke2;
            e.currentTarget.style.background = T.bg2;
          }
        },
        onMouseLeave: function onMouseLeave(e) {
          if (!on) {
            e.currentTarget.style.borderColor = T.stroke1;
            e.currentTarget.style.background = T.bg1;
          }
        }
      }, /*#__PURE__*/React.createElement("div", {
        style: {
          width: 38,
          height: 38,
          clipPath: cutPath(6),
          background: on ? "".concat(p.color, "25") : T.bg3,
          display: 'flex',
          alignItems: 'center',
          justifyContent: 'center',
          marginBottom: 10
        }
      }, /*#__PURE__*/React.createElement(ProductIcon, {
        id: p.icon,
        size: 20,
        color: on ? p.color : T.fg2
      })), /*#__PURE__*/React.createElement("div", {
        style: {
          fontFamily: T.fontDisplay,
          fontSize: 15,
          fontWeight: 600,
          color: on ? p.color : T.fg1,
          marginBottom: 3
        }
      }, p.name), /*#__PURE__*/React.createElement("div", {
        style: {
          fontSize: 11,
          color: T.fg3,
          fontFamily: T.fontBody,
          lineHeight: 1.5
        }
      }, p.desc), p.voor && /*#__PURE__*/React.createElement("div", {
        style: {
          display: 'inline-flex',
          alignItems: 'center',
          gap: 5,
          marginTop: 7,
          fontSize: 10.5,
          fontFamily: T.fontBody,
          fontWeight: 700,
          color: T.fg3
        }
      }, /*#__PURE__*/React.createElement(Icon, {
        name: "user",
        size: 11,
        color: T.fg4
      }), p.voor), on && /*#__PURE__*/React.createElement("div", {
        style: {
          position: 'absolute',
          top: 10,
          right: 10,
          width: 22,
          height: 22,
          borderRadius: '50%',
          background: p.color,
          display: 'flex',
          alignItems: 'center',
          justifyContent: 'center',
          boxShadow: "0 0 8px ".concat(p.color, "80"),
          fontFamily: T.fontDisplay,
          fontSize: 11,
          fontWeight: 700,
          color: T.bg0
        }
      }, idx + 1));
    })));
  }), data.contactId && /*#__PURE__*/React.createElement(CalcBtwWoning, {
    data: data,
    setData: setData
  }), sel.length > 0 && /*#__PURE__*/React.createElement("div", {
    style: {
      background: 'rgba(0,217,0,0.06)',
      border: '1px solid rgba(0,217,0,0.25)',
      clipPath: cutPath(10),
      padding: '12px 16px',
      marginBottom: 18,
      display: 'flex',
      alignItems: 'center',
      gap: 12
    }
  }, /*#__PURE__*/React.createElement(Icon, {
    name: "check",
    size: 14,
    color: T.accent
  }), /*#__PURE__*/React.createElement("div", {
    style: {
      flex: 1
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      fontSize: 12,
      fontFamily: T.fontBody,
      fontWeight: 700,
      color: T.fg1
    }
  }, sel.length, " ", sel.length === 1 ? 'offerte' : 'offertes', " worden aangemaakt"), /*#__PURE__*/React.createElement("div", {
    style: {
      fontSize: 11,
      color: T.fg3,
      marginTop: 1
    }
  }, sel.map(function (id) {
    return productById(id).name;
  }).join(' · ')))), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      justifyContent: 'space-between',
      alignItems: 'center'
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      fontSize: 11,
      color: T.fg4,
      fontFamily: T.fontBody
    }
  }, !data.klant ? 'Kies eerst een contact.' : canNext ? 'Klaar om verder te gaan' : 'Selecteer minstens één product.'), /*#__PURE__*/React.createElement(Button, {
    variant: "primary",
    icon: "check",
    onClick: onNext,
    fullWidth: false,
    style: {
      opacity: canNext ? 1 : 0.4,
      pointerEvents: canNext ? 'auto' : 'none'
    }
  }, "Naar calculator", sel.length > 1 ? " (".concat(sel.length, ")") : '', " \u2192")));
};

/* ─────────────────────────────────────────────────────── STEP 2 ALT CALCULATORS */
var sumLines = function sumLines(lines) {
  return lines.reduce(function (s, l) {
    return s + (Number(l.total) || 0);
  }, 0);
};
var SimpleCalcShell = function SimpleCalcShell(_ref9) {
  var left = _ref9.left,
    lineItems = _ref9.lineItems,
    klant = _ref9.klant,
    btw = _ref9.btw,
    onPriceChange = _ref9.onPriceChange,
    _ref9$types = _ref9.types,
    types = _ref9$types === void 0 ? [] : _ref9$types;
  var _React$useState = React.useState(CALC_STD_MARGIN),
    _React$useState2 = _slicedToArray(_React$useState, 2),
    margin = _React$useState2[0],
    setMargin = _React$useState2[1];
  var _React$useState3 = React.useState([]),
    _React$useState4 = _slicedToArray(_React$useState3, 2),
    rows = _React$useState4[0],
    setRows = _React$useState4[1];
  var _React$useState5 = React.useState([]),
    _React$useState6 = _slicedToArray(_React$useState5, 2),
    customLines = _React$useState6[0],
    setCustomLines = _React$useState6[1];
  var _React$useState7 = React.useState(false),
    _React$useState8 = _slicedToArray(_React$useState7, 2),
    pick = _React$useState8[0],
    setPick = _React$useState8[1];
  var _useKlantmodus = useKlantmodus(),
    _useKlantmodus2 = _slicedToArray(_useKlantmodus, 1),
    priv = _useKlantmodus2[0];
  var store = useArticles();

  // Offertelijnen uit de artikeldatabank — prijzen komen rechtstreeks uit Stock & artikelen.
  var artLines = rows.map(function (r) {
    var a = store.articles.find(function (x) {
      return x.id === r.id;
    }) || r.snap;
    var b = Number(a.buyPrice) || 0;
    return {
      name: "".concat(r.qty, "\xD7 ").concat(a.code, " \xB7 ").concat(a.name),
      qty: r.qty,
      buy: b,
      total: r.qty * b,
      artId: a.id,
      art: a
    };
  });
  var all = [].concat(_toConsumableArray(lineItems), _toConsumableArray(artLines));
  var buy = sumLines(all);
  var sellBase = buy > 0 ? buy / (1 - margin / 100) : 0;
  var customTotal = customLines.reduce(function (s, c) {
    return s + (Number(c.amount) || 0);
  }, 0);
  var sell = Math.max(0, sellBase + customTotal);
  var btwAm = sell * (btw / 100);
  var total = sell + btwAm;
  var issues = calcCheckArticles(artLines.map(function (l) {
    return l.art;
  }));
  var geblokkeerd = calcBlocking(issues).length > 0;
  var artIds = artLines.map(function (l) {
    return l.artId;
  });
  var artKey = rows.map(function (r) {
    return "".concat(r.id, ":").concat(r.qty);
  }).join(',');
  React.useEffect(function () {
    if (onPriceChange) onPriceChange({
      buy: buy,
      sell: sell,
      btwAm: btwAm,
      total: total,
      margin: margin,
      lineItems: all,
      klant: klant,
      btw: btw,
      artIds: artIds,
      issues: issues
    });
    // only re-fire when computed total or margin changes — prevents render loops
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [total, sell, margin, klant, artKey]);
  var setQty = function setQty(id, q) {
    return setRows(function (p) {
      return p.map(function (r) {
        return r.id === id ? _objectSpread(_objectSpread({}, r), {}, {
          qty: Math.max(1, q)
        }) : r;
      });
    });
  };
  var addArt = function addArt(a) {
    return setRows(function (p) {
      return p.some(function (r) {
        return r.id === a.id;
      }) ? p.map(function (r) {
        return r.id === a.id ? _objectSpread(_objectSpread({}, r), {}, {
          qty: r.qty + 1
        }) : r;
      }) : [].concat(_toConsumableArray(p), [{
        id: a.id,
        qty: 1,
        snap: a
      }]);
    });
  };
  return /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      gap: 0,
      height: 'auto',
      minHeight: 600
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      flex: 1,
      overflowY: 'auto',
      padding: 20
    }
  }, left, /*#__PURE__*/React.createElement(CalcSection, {
    title: "ARTIKELEN UIT DE DATABANK",
    icon: "package"
  }, /*#__PURE__*/React.createElement(CalcIssuePanel, {
    issues: issues,
    compact: true
  }), rows.length === 0 && /*#__PURE__*/React.createElement("div", {
    style: {
      fontFamily: T.fontBody,
      fontSize: 11.5,
      color: T.fg4,
      marginBottom: 10
    }
  }, "Voeg artikels toe uit Stock & artikelen \u2014 code, prijs, marge en datasheets komen automatisch mee."), artLines.map(function (l) {
    return /*#__PURE__*/React.createElement("div", {
      key: l.artId,
      style: {
        display: 'grid',
        gridTemplateColumns: 'minmax(0,1fr) 92px 92px 30px',
        gap: 8,
        alignItems: 'center',
        padding: '7px 0',
        borderBottom: "1px solid ".concat(T.stroke1)
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        minWidth: 0
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        fontFamily: T.fontBody,
        fontSize: 12,
        fontWeight: 600,
        color: T.fg1,
        overflow: 'hidden',
        textOverflow: 'ellipsis',
        whiteSpace: 'nowrap'
      }
    }, l.art.code, " \xB7 ", l.art.name), /*#__PURE__*/React.createElement("div", {
      style: {
        fontFamily: T.fontBody,
        fontSize: 10.5,
        color: T.fg4
      }
    }, ptype(l.art.type).label, (l.art.sheets || []).length ? " \xB7 ".concat(l.art.sheets.length, " datasheet").concat(l.art.sheets.length > 1 ? 's' : '') : '')), /*#__PURE__*/React.createElement(NumInput, {
      value: l.qty,
      onChange: function onChange(v) {
        return setQty(l.artId, Number(v) || 1);
      },
      min: 1,
      step: 1
    }), /*#__PURE__*/React.createElement("span", {
      style: {
        fontFamily: T.fontDisplay,
        fontSize: 13,
        fontWeight: 600,
        color: priv ? T.fg4 : T.fg1,
        textAlign: 'right',
        fontVariantNumeric: 'tabular-nums'
      }
    }, priv ? '•••' : fmtEur(l.total)), /*#__PURE__*/React.createElement("button", {
      onClick: function onClick() {
        return setRows(function (p) {
          return p.filter(function (r) {
            return r.id !== l.artId;
          });
        });
      },
      style: {
        background: 'none',
        border: 'none',
        cursor: 'pointer',
        color: T.fg3,
        padding: 6
      }
    }, /*#__PURE__*/React.createElement(Icon, {
      name: "trash",
      size: 13
    })));
  }), /*#__PURE__*/React.createElement("div", {
    style: {
      marginTop: 10
    }
  }, /*#__PURE__*/React.createElement(Button, {
    variant: "secondary",
    size: "sm",
    icon: "plus",
    onClick: function onClick() {
      return setPick(true);
    }
  }, "Artikel toevoegen"))), /*#__PURE__*/React.createElement(ArtPickModal, {
    open: pick,
    onClose: function onClose() {
      return setPick(false);
    },
    types: types,
    onPick: addArt
  })), /*#__PURE__*/React.createElement("div", {
    style: {
      width: 320,
      borderLeft: "1px solid ".concat(T.stroke1),
      background: T.bg0,
      padding: '16px 18px',
      overflowY: 'auto',
      flexShrink: 0
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      fontSize: 10,
      fontFamily: T.fontBody,
      fontWeight: 700,
      letterSpacing: '0.16em',
      textTransform: 'uppercase',
      color: T.fg3,
      marginBottom: 10
    }
  }, "OFFERTE SAMENVATTING"), geblokkeerd && /*#__PURE__*/React.createElement("div", {
    style: {
      background: 'rgba(255,90,77,0.10)',
      border: '1px solid rgba(255,90,77,0.4)',
      clipPath: cutPath(8),
      padding: '9px 11px',
      marginBottom: 10,
      fontFamily: T.fontBody,
      fontSize: 11,
      color: '#ff5a4d',
      lineHeight: 1.5
    }
  }, "Deze offerte kan niet berekend worden zolang de gemarkeerde artikels geen aankoop- en verkoopprijs hebben."), all.map(function (li, i) {
    return /*#__PURE__*/React.createElement("div", {
      key: i,
      style: {
        display: 'flex',
        justifyContent: 'space-between',
        padding: '7px 0',
        borderBottom: "1px solid ".concat(T.stroke1)
      }
    }, /*#__PURE__*/React.createElement("span", {
      style: {
        fontSize: 11,
        color: T.fg2,
        fontFamily: T.fontBody,
        fontWeight: 500,
        flex: 1
      }
    }, li.name), /*#__PURE__*/React.createElement("span", {
      style: {
        fontSize: 12,
        fontFamily: T.fontDisplay,
        fontWeight: 600,
        color: T.fg1,
        fontVariantNumeric: 'tabular-nums'
      }
    }, fmtEur(buy > 0 ? sellBase * (li.total / buy) : 0)));
  }), customLines.map(function (c) {
    return /*#__PURE__*/React.createElement("div", {
      key: c.id,
      style: {
        display: 'flex',
        alignItems: 'center',
        gap: 7,
        padding: '5px 0',
        borderBottom: "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;
          });
        });
      },
      style: {
        flex: 1,
        minWidth: 0,
        boxSizing: 'border-box',
        padding: '5px 8px',
        background: T.bg2,
        border: "1px solid ".concat(T.stroke1),
        borderRadius: 4,
        outline: 'none',
        color: T.fg1,
        fontFamily: T.fontBody,
        fontSize: 11.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;
          });
        });
      },
      style: {
        width: 80,
        boxSizing: 'border-box',
        padding: '5px 8px',
        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: 12,
        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;
          });
        });
      },
      style: {
        background: 'none',
        border: 'none',
        cursor: 'pointer',
        color: T.fg4,
        padding: 4
      }
    }, /*#__PURE__*/React.createElement(Icon, {
      name: "trash",
      size: 12
    })));
  }), /*#__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%',
      margin: '8px 0 4px',
      padding: '7px 10px',
      background: 'transparent',
      border: "1px dashed ".concat(T.stroke1),
      borderRadius: 5,
      cursor: 'pointer',
      color: T.fg3,
      fontFamily: T.fontBody,
      fontSize: 11.5,
      fontWeight: 600
    }
  }, /*#__PURE__*/React.createElement(Icon, {
    name: "plus",
    size: 12,
    color: "currentColor"
  }), "Regel toevoegen \u2014 korting of meerprijs"), !priv && /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      justifyContent: 'space-between',
      padding: '10px 0'
    }
  }, /*#__PURE__*/React.createElement("span", {
    style: {
      fontSize: 12,
      color: T.fg2
    }
  }, "Aankoop totaal"), /*#__PURE__*/React.createElement("span", {
    style: {
      fontFamily: T.fontDisplay,
      fontSize: 13,
      fontWeight: 600,
      color: T.fg2,
      fontVariantNumeric: 'tabular-nums'
    }
  }, fmtEur(buy))), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      justifyContent: 'space-between',
      padding: '10px 0',
      borderBottom: "1px solid ".concat(T.stroke1)
    }
  }, /*#__PURE__*/React.createElement("span", {
    style: {
      fontSize: 12,
      color: T.fg2
    }
  }, "Verkoop excl. BTW"), /*#__PURE__*/React.createElement("span", {
    style: {
      fontFamily: T.fontDisplay,
      fontSize: 14,
      fontWeight: 600,
      color: T.fg1,
      fontVariantNumeric: 'tabular-nums'
    }
  }, fmtEur(sell))), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      justifyContent: 'space-between',
      padding: '8px 0'
    }
  }, /*#__PURE__*/React.createElement("span", {
    style: {
      fontSize: 12,
      color: T.fg2
    }
  }, +btw === 0 ? 'Btw verlegd (0 %)' : "BTW ".concat(btw, "%")), /*#__PURE__*/React.createElement("span", {
    style: {
      fontFamily: T.fontDisplay,
      fontSize: 13,
      color: T.fg2,
      fontVariantNumeric: 'tabular-nums'
    }
  }, fmtEur(btwAm))), /*#__PURE__*/React.createElement("div", {
    style: {
      background: T.bg1,
      clipPath: cutPath(8),
      padding: '12px 14px',
      marginTop: 10,
      display: 'flex',
      justifyContent: 'space-between',
      alignItems: 'center'
    }
  }, /*#__PURE__*/React.createElement("span", {
    style: {
      fontFamily: T.fontBody,
      fontSize: 12,
      fontWeight: 700,
      color: T.fg1,
      letterSpacing: '0.05em'
    }
  }, "TOTAAL"), /*#__PURE__*/React.createElement("span", {
    style: {
      fontFamily: T.fontDisplay,
      fontSize: 22,
      fontWeight: 600,
      color: T.accent,
      letterSpacing: '-0.02em',
      fontVariantNumeric: 'tabular-nums'
    }
  }, fmtEur(total)))));
};

/* ── Laadpaal calc — alle keuzes uit de artikeldatabank ───────────── */
var LaadpaalCalc = function LaadpaalCalc(_ref0) {
  var klant = _ref0.klant,
    onPriceChange = _ref0.onPriceChange,
    _ref0$btw = _ref0.btw,
    btw = _ref0$btw === void 0 ? 21 : _ref0$btw;
  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(t, g) {
    var l = calcArtList(arts, t, g);
    return l.length ? l[0].id : '';
  };
  var _React$useState9 = React.useState(function () {
      return eerste('laadpalen', 'laadpaal') || eerste('laadpalen');
    }),
    _React$useState0 = _slicedToArray(_React$useState9, 2),
    modelId = _React$useState0[0],
    setModelId = _React$useState0[1];
  var _React$useState1 = React.useState(1),
    _React$useState10 = _slicedToArray(_React$useState1, 2),
    qty = _React$useState10[0],
    setQty = _React$useState10[1];
  var _React$useState11 = React.useState(function () {
      return eerste('diensten', 'werk');
    }),
    _React$useState12 = _slicedToArray(_React$useState11, 2),
    montageId = _React$useState12[0],
    setMontageId = _React$useState12[1];
  var _React$useState13 = React.useState(function () {
      return eerste('montage_elek', 'bekabeling');
    }),
    _React$useState14 = _slicedToArray(_React$useState13, 2),
    kabelId = _React$useState14[0],
    setKabelId = _React$useState14[1];
  var _React$useState15 = React.useState(8),
    _React$useState16 = _slicedToArray(_React$useState15, 2),
    kabel = _React$useState16[0],
    setKabel = _React$useState16[1];
  var _React$useState17 = React.useState(false),
    _React$useState18 = _slicedToArray(_React$useState17, 2),
    graafwerk = _React$useState18[0],
    setGraafwerk = _React$useState18[1];
  var _React$useState19 = React.useState(function () {
      return eerste('keuring', 'keuring');
    }),
    _React$useState20 = _slicedToArray(_React$useState19, 2),
    keuringId = _React$useState20[0],
    setKeuringId = _React$useState20[1];
  var _React$useState21 = React.useState(true),
    _React$useState22 = _slicedToArray(_React$useState21, 2),
    keuring = _React$useState22[0],
    setKeuring = _React$useState22[1];
  var model = byId(modelId),
    montage = byId(montageId),
    kabelArt = byId(kabelId),
    keuringArt = byId(keuringId);
  var graafArt = calcArtList(arts, 'diensten', 'werk').find(function (a) {
    return /graafwerk/i.test(a.name);
  }) || null;
  var p = function p(a) {
    return a ? Number(a.buyPrice) || 0 : 0;
  };
  var lineItems = [].concat(_toConsumableArray(model ? [{
    name: "".concat(qty, "\xD7 ").concat(model.name),
    qty: qty,
    buy: p(model),
    total: qty * p(model),
    art: model
  }] : []), _toConsumableArray(montage ? [{
    name: montage.name,
    qty: qty,
    buy: p(montage),
    total: qty * p(montage),
    art: montage
  }] : []), _toConsumableArray(kabelArt ? [{
    name: "".concat(kabelArt.name, " (").concat(kabel, " m)"),
    qty: kabel,
    buy: p(kabelArt),
    total: kabel * p(kabelArt),
    art: kabelArt
  }] : []), _toConsumableArray(graafwerk && graafArt ? [{
    name: graafArt.name,
    qty: 1,
    buy: p(graafArt),
    total: p(graafArt),
    art: graafArt
  }] : []), _toConsumableArray(keuring && keuringArt ? [{
    name: keuringArt.name,
    qty: 1,
    buy: p(keuringArt),
    total: p(keuringArt),
    art: keuringArt
  }] : []));
  return /*#__PURE__*/React.createElement(SimpleCalcShell, {
    klant: klant,
    btw: btw,
    onPriceChange: onPriceChange,
    lineItems: lineItems,
    types: calcTypesFor('laadpaal'),
    left: /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("h3", {
      style: {
        margin: '0 0 14px',
        fontFamily: T.fontDisplay,
        fontSize: 17,
        fontWeight: 600,
        color: T.fg1
      }
    }, "Laadpaal \u2014 ", klant), /*#__PURE__*/React.createElement(CalcSection, {
      title: "1 \xB7 LAADPAAL MODEL",
      icon: "zap"
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'grid',
        gridTemplateColumns: '2fr 1fr',
        gap: 10
      }
    }, /*#__PURE__*/React.createElement(GhsSelect, {
      label: "Model",
      value: modelId,
      onChange: setModelId,
      options: [].concat(_toConsumableArray(calcArtOptions(arts, 'laadpalen', 'laadpaal', true, function (a) {
        return "".concat(Number((a.specs || {}).kw) || '?', " kW");
      })), _toConsumableArray(calcArtOptions(arts, 'laadpalen', '', true)))
    }), /*#__PURE__*/React.createElement(NumInput, {
      label: "Aantal",
      value: qty,
      onChange: setQty,
      min: 1,
      max: 10
    }))), /*#__PURE__*/React.createElement(CalcSection, {
      title: "2 \xB7 MONTAGE",
      icon: "package"
    }, /*#__PURE__*/React.createElement(GhsSelect, {
      label: "Plaatsingswijze",
      value: montageId,
      onChange: setMontageId,
      options: calcArtOptions(arts, 'diensten', 'werk', true)
    })), /*#__PURE__*/React.createElement(CalcSection, {
      title: "3 \xB7 KABELWERK",
      icon: "link"
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'grid',
        gridTemplateColumns: '2fr 1fr auto',
        gap: 10,
        alignItems: 'end'
      }
    }, /*#__PURE__*/React.createElement(GhsSelect, {
      label: "Kabel",
      value: kabelId,
      onChange: setKabelId,
      options: calcArtOptions(arts, 'montage_elek', 'bekabeling', true)
    }), /*#__PURE__*/React.createElement(NumInput, {
      label: "Lengte (m)",
      value: kabel,
      onChange: setKabel,
      min: 1,
      max: 80,
      suffix: "m"
    }), /*#__PURE__*/React.createElement("label", {
      style: {
        display: 'flex',
        alignItems: 'center',
        gap: 8,
        padding: '9px 12px',
        background: graafwerk ? 'rgba(0,217,0,0.12)' : T.bg2,
        borderRadius: 5,
        border: "1px solid ".concat(graafwerk ? T.accent : T.stroke1),
        cursor: 'pointer'
      }
    }, /*#__PURE__*/React.createElement("input", {
      type: "checkbox",
      checked: graafwerk,
      onChange: function onChange(e) {
        return setGraafwerk(e.target.checked);
      },
      style: {
        accentColor: T.accent
      }
    }), /*#__PURE__*/React.createElement("span", {
      style: {
        fontSize: 11,
        color: graafwerk ? T.accent : T.fg2,
        fontFamily: T.fontBody,
        fontWeight: 600
      }
    }, "Graafwerk")))), /*#__PURE__*/React.createElement(CalcSection, {
      title: "4 \xB7 OPLEVERING",
      icon: "check"
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'grid',
        gridTemplateColumns: 'auto 1fr',
        gap: 10,
        alignItems: 'end'
      }
    }, /*#__PURE__*/React.createElement("label", {
      style: {
        display: 'flex',
        alignItems: 'center',
        gap: 8,
        padding: '9px 12px',
        background: keuring ? 'rgba(0,217,0,0.12)' : T.bg2,
        borderRadius: 5,
        border: "1px solid ".concat(keuring ? T.accent : T.stroke1),
        cursor: 'pointer'
      }
    }, /*#__PURE__*/React.createElement("input", {
      type: "checkbox",
      checked: keuring,
      onChange: function onChange(e) {
        return setKeuring(e.target.checked);
      },
      style: {
        accentColor: T.accent
      }
    }), /*#__PURE__*/React.createElement("span", {
      style: {
        fontSize: 12,
        color: keuring ? T.accent : T.fg2,
        fontFamily: T.fontBody,
        fontWeight: 600
      }
    }, "Keuring")), keuring && /*#__PURE__*/React.createElement(GhsSelect, {
      label: "Keuring & opmeting",
      value: keuringId,
      onChange: setKeuringId,
      options: calcArtOptions(arts, 'keuring', '', true)
    }))))
  });
};

/* ── Airco calc — binnenunits, buitenunit en montage uit de databank ── */
var AircoCalc = function AircoCalc(_ref1) {
  var klant = _ref1.klant,
    onPriceChange = _ref1.onPriceChange,
    _ref1$btw = _ref1.btw,
    btw = _ref1$btw === void 0 ? 21 : _ref1$btw;
  var store = useArticles();
  var arts = store.articles;
  var byId = function byId(id) {
    return arts.find(function (a) {
      return a.id === id;
    }) || null;
  };
  var binnenLijst = calcArtList(arts, 'airco', 'binnen').concat(calcArtList(arts, 'airco', ''));
  var eerste = function eerste(t, g) {
    var l = calcArtList(arts, t, g);
    return l.length ? l[0].id : '';
  };
  var _React$useState23 = React.useState(function () {
      return [{
        id: 'u1',
        ruimte: 'Living',
        artId: (binnenLijst[0] || {}).id || '',
        qty: 1
      }];
    }),
    _React$useState24 = _slicedToArray(_React$useState23, 2),
    units = _React$useState24[0],
    setUnits = _React$useState24[1];
  var _React$useState25 = React.useState(function () {
      return eerste('airco', 'buiten');
    }),
    _React$useState26 = _slicedToArray(_React$useState25, 2),
    buitenId = _React$useState26[0],
    setBuitenId = _React$useState26[1];
  var montageLijst = calcArtList(arts, 'airco', 'montage');
  var _React$useState27 = React.useState(function () {
      return (montageLijst.find(function (a) {
        return a.calcUnit === 'stuk';
      }) || montageLijst[0] || {}).id || '';
    }),
    _React$useState28 = _slicedToArray(_React$useState27, 2),
    montageId = _React$useState28[0],
    setMontageId = _React$useState28[1];
  var leidingArt = montageLijst.find(function (a) {
    return a.calcUnit === 'meter';
  }) || null;
  var opstartArt = montageLijst.find(function (a) {
    return a.calcUnit === 'installatie';
  }) || null;
  var _React$useState29 = React.useState(6),
    _React$useState30 = _slicedToArray(_React$useState29, 2),
    leidingMeters = _React$useState30[0],
    setLeidingMeters = _React$useState30[1];
  var p = function p(a) {
    return a ? Number(a.buyPrice) || 0 : 0;
  };
  var buiten = byId(buitenId),
    montage = byId(montageId);
  var totaalUnits = units.reduce(function (s, u) {
    return s + (Number(u.qty) || 1);
  }, 0);
  var updateUnit = function updateUnit(id, f, v) {
    return setUnits(function (prev) {
      return prev.map(function (u) {
        return u.id === id ? _objectSpread(_objectSpread({}, u), {}, _defineProperty({}, f, v)) : u;
      });
    });
  };
  var addUnit = function addUnit() {
    return setUnits(function (prev) {
      return [].concat(_toConsumableArray(prev), [{
        id: 'u' + Date.now(),
        ruimte: 'Nieuwe ruimte',
        artId: (binnenLijst[0] || {}).id || '',
        qty: 1
      }]);
    });
  };
  var removeUnit = function removeUnit(id) {
    return setUnits(function (prev) {
      return prev.filter(function (u) {
        return u.id !== id;
      });
    });
  };
  var lineItems = [].concat(_toConsumableArray(units.map(function (u) {
    var a = byId(u.artId);
    var q = Number(u.qty) || 1;
    return a ? {
      name: "".concat(q, "\xD7 ").concat(a.name, " \u2014 ").concat(u.ruimte),
      qty: q,
      buy: p(a),
      total: q * p(a),
      art: a
    } : null;
  }).filter(Boolean)), _toConsumableArray(buiten ? [{
    name: buiten.name,
    qty: 1,
    buy: p(buiten),
    total: p(buiten),
    art: buiten
  }] : []), _toConsumableArray(montage ? [{
    name: "".concat(montage.name, " (").concat(totaalUnits, " unit").concat(totaalUnits > 1 ? 's' : '', ")"),
    qty: totaalUnits,
    buy: p(montage),
    total: totaalUnits * p(montage),
    art: montage
  }] : []), _toConsumableArray(leidingArt ? [{
    name: "".concat(leidingArt.name, " (").concat(leidingMeters, " m)"),
    qty: leidingMeters,
    buy: p(leidingArt),
    total: leidingMeters * p(leidingArt),
    art: leidingArt
  }] : []), _toConsumableArray(opstartArt ? [{
    name: opstartArt.name,
    qty: 1,
    buy: p(opstartArt),
    total: p(opstartArt),
    art: opstartArt
  }] : []));
  return /*#__PURE__*/React.createElement(SimpleCalcShell, {
    klant: klant,
    btw: btw,
    onPriceChange: onPriceChange,
    lineItems: lineItems,
    types: calcTypesFor('airco'),
    left: /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("h3", {
      style: {
        margin: '0 0 14px',
        fontFamily: T.fontDisplay,
        fontSize: 17,
        fontWeight: 600,
        color: T.fg1
      }
    }, "Airconditioning \u2014 ", klant), /*#__PURE__*/React.createElement(CalcSection, {
      title: "1 \xB7 RUIMTES (BINNEN-UNITS)",
      icon: "package"
    }, units.map(function (u) {
      return /*#__PURE__*/React.createElement("div", {
        key: u.id,
        style: {
          display: 'grid',
          gridTemplateColumns: 'minmax(0,1fr) minmax(0,2fr) 70px auto',
          gap: 8,
          marginBottom: 8,
          alignItems: 'end'
        }
      }, /*#__PURE__*/React.createElement(Input, {
        label: "Ruimte",
        value: u.ruimte,
        onChange: function onChange(v) {
          return updateUnit(u.id, 'ruimte', v);
        },
        placeholder: "Bv. Living"
      }), /*#__PURE__*/React.createElement(GhsSelect, {
        label: "Binnenunit",
        value: u.artId,
        onChange: function onChange(v) {
          return updateUnit(u.id, 'artId', v);
        },
        options: binnenLijst.map(function (a) {
          return {
            value: a.id,
            label: calcArtLabel(a, true, (a.specs || {}).koelKw ? "".concat(a.specs.koelKw, " kW") : '')
          };
        })
      }), /*#__PURE__*/React.createElement(NumInput, {
        label: "Aantal",
        value: u.qty,
        onChange: function onChange(v) {
          return updateUnit(u.id, 'qty', Math.max(1, Number(v) || 1));
        },
        min: 1,
        max: 10
      }), /*#__PURE__*/React.createElement("button", {
        onClick: function onClick() {
          return removeUnit(u.id);
        },
        disabled: units.length <= 1,
        style: {
          background: 'none',
          border: 'none',
          cursor: units.length <= 1 ? 'default' : 'pointer',
          color: T.fg3,
          padding: 8,
          opacity: units.length <= 1 ? 0.3 : 1
        }
      }, /*#__PURE__*/React.createElement(Icon, {
        name: "trash",
        size: 14
      })));
    }), /*#__PURE__*/React.createElement(Button, {
      variant: "secondary",
      size: "sm",
      icon: "plus",
      onClick: addUnit
    }, "Ruimte toevoegen")), /*#__PURE__*/React.createElement(CalcSection, {
      title: "2 \xB7 BUITENUNIT",
      icon: "wind"
    }, /*#__PURE__*/React.createElement(GhsSelect, {
      label: "Buitenunit",
      value: buitenId,
      onChange: setBuitenId,
      options: calcArtOptions(arts, 'airco', 'buiten', true)
    }), /*#__PURE__*/React.createElement("div", {
      style: {
        marginTop: 8
      }
    }, /*#__PURE__*/React.createElement(Badge, {
      type: "neutral"
    }, totaalUnits, " binnenunit", totaalUnits > 1 ? 's' : ''))), /*#__PURE__*/React.createElement(CalcSection, {
      title: "3 \xB7 MONTAGE & KOELLEIDING",
      icon: "zap"
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'grid',
        gridTemplateColumns: '1fr 1fr',
        gap: 10
      }
    }, /*#__PURE__*/React.createElement(GhsSelect, {
      label: "Plaatsing per unit",
      value: montageId,
      onChange: setMontageId,
      options: montageLijst.filter(function (a) {
        return a.calcUnit === 'stuk';
      }).map(function (a) {
        return {
          value: a.id,
          label: calcArtLabel(a, true)
        };
      })
    }), /*#__PURE__*/React.createElement(NumInput, {
      label: "Koelmiddelleiding (m)",
      value: leidingMeters,
      onChange: setLeidingMeters,
      min: 2,
      max: 40,
      suffix: "m"
    }))))
  });
};

/* ── Warmtepomp calc — unit, buffer en montage uit de databank ─────── */
var WarmtepompCalc = function WarmtepompCalc(_ref10) {
  var klant = _ref10.klant,
    onPriceChange = _ref10.onPriceChange,
    _ref10$btw = _ref10.btw,
    btw = _ref10$btw === void 0 ? 6 : _ref10$btw;
  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(t, g) {
    var l = calcArtList(arts, t, g);
    return l.length ? l[0].id : '';
  };
  var _React$useState31 = React.useState(function () {
      return eerste('warmtepompen', 'unit') || eerste('warmtepompen');
    }),
    _React$useState32 = _slicedToArray(_React$useState31, 2),
    modelId = _React$useState32[0],
    setModelId = _React$useState32[1];
  var _React$useState33 = React.useState(function () {
      return eerste('warmtepompen', 'buffer');
    }),
    _React$useState34 = _slicedToArray(_React$useState33, 2),
    bufferId = _React$useState34[0],
    setBufferId = _React$useState34[1];
  var _React$useState35 = React.useState(''),
    _React$useState36 = _slicedToArray(_React$useState35, 2),
    combiId = _React$useState36[0],
    setCombiId = _React$useState36[1];
  var _React$useState37 = React.useState(function () {
      return calcArtList(arts, 'warmtepompen', 'montage').map(function (a) {
        return a.id;
      });
    }),
    _React$useState38 = _slicedToArray(_React$useState37, 2),
    extraIds = _React$useState38[0],
    setExtraIds = _React$useState38[1];
  var _React$useState39 = React.useState(function () {
      return eerste('keuring', 'keuring');
    }),
    _React$useState40 = _slicedToArray(_React$useState39, 2),
    keuringId = _React$useState40[0],
    setKeuringId = _React$useState40[1];
  var _React$useState41 = React.useState(true),
    _React$useState42 = _slicedToArray(_React$useState41, 2),
    premie = _React$useState42[0],
    setPremie = _React$useState42[1];
  var bufferLijst = calcArtList(arts, 'warmtepompen', 'buffer');
  var montageLijst = calcArtList(arts, 'warmtepompen', 'montage');
  var p = function p(a) {
    return a ? Number(a.buyPrice) || 0 : 0;
  };
  var model = byId(modelId),
    buffer = byId(bufferId),
    combi = combiId ? byId(combiId) : null,
    keuringArt = byId(keuringId);
  var toggleExtra = function toggleExtra(id) {
    return setExtraIds(function (prev) {
      return prev.includes(id) ? prev.filter(function (x) {
        return x !== id;
      }) : [].concat(_toConsumableArray(prev), [id]);
    });
  };
  var lineItems = [].concat(_toConsumableArray(model ? [{
    name: model.name,
    qty: 1,
    buy: p(model),
    total: p(model),
    art: model
  }] : []), _toConsumableArray(buffer ? [{
    name: buffer.name,
    qty: 1,
    buy: p(buffer),
    total: p(buffer),
    art: buffer
  }] : []), _toConsumableArray(combi ? [{
    name: combi.name,
    qty: 1,
    buy: p(combi),
    total: p(combi),
    art: combi
  }] : []), _toConsumableArray(montageLijst.filter(function (a) {
    return extraIds.includes(a.id);
  }).map(function (a) {
    return {
      name: a.name,
      qty: 1,
      buy: p(a),
      total: p(a),
      art: a
    };
  })), _toConsumableArray(keuringArt ? [{
    name: keuringArt.name,
    qty: 1,
    buy: p(keuringArt),
    total: p(keuringArt),
    art: keuringArt
  }] : []));
  return /*#__PURE__*/React.createElement(SimpleCalcShell, {
    klant: klant,
    btw: btw,
    onPriceChange: onPriceChange,
    lineItems: lineItems,
    types: calcTypesFor('warmtepomp'),
    left: /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("h3", {
      style: {
        margin: '0 0 14px',
        fontFamily: T.fontDisplay,
        fontSize: 17,
        fontWeight: 600,
        color: T.fg1
      }
    }, "Warmtepomp \u2014 ", klant), /*#__PURE__*/React.createElement(CalcSection, {
      title: "1 \xB7 WARMTEPOMP",
      icon: "thermometer"
    }, /*#__PURE__*/React.createElement(GhsSelect, {
      label: "Model",
      value: modelId,
      onChange: setModelId,
      options: [].concat(_toConsumableArray(calcArtOptions(arts, 'warmtepompen', 'unit', true, function (a) {
        return "".concat(Number((a.specs || {}).warmKw) || '?', " kW");
      })), _toConsumableArray(calcArtOptions(arts, 'warmtepompen', '', true)))
    }), model && /*#__PURE__*/React.createElement("div", {
      style: {
        marginTop: 8,
        display: 'flex',
        gap: 6,
        flexWrap: 'wrap'
      }
    }, (model.specs || {}).warmKw && /*#__PURE__*/React.createElement(Badge, {
      type: "accent"
    }, model.specs.warmKw, " kW"), (model.specs || {}).type && /*#__PURE__*/React.createElement(Badge, {
      type: "neutral"
    }, model.specs.type), (model.specs || {}).scop && /*#__PURE__*/React.createElement(Badge, {
      type: "neutral"
    }, "SCOP ", model.specs.scop))), /*#__PURE__*/React.createElement(CalcSection, {
      title: "2 \xB7 BUFFER & SANITAIR",
      icon: "battery"
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'grid',
        gridTemplateColumns: '1fr 1fr',
        gap: 10
      }
    }, /*#__PURE__*/React.createElement(GhsSelect, {
      label: "Buffervat",
      value: bufferId,
      onChange: setBufferId,
      options: bufferLijst.map(function (a) {
        return {
          value: a.id,
          label: calcArtLabel(a, true)
        };
      })
    }), /*#__PURE__*/React.createElement(GhsSelect, {
      label: "Combi sanitair",
      value: combiId,
      onChange: setCombiId,
      options: [{
        value: '',
        label: 'Apart sanitair'
      }].concat(_toConsumableArray(bufferLijst.filter(function (a) {
        return /combi|boiler/i.test(a.name);
      }).map(function (a) {
        return {
          value: a.id,
          label: calcArtLabel(a, true)
        };
      })))
    }))), /*#__PURE__*/React.createElement(CalcSection, {
      title: "3 \xB7 MONTAGE & OPSTART",
      icon: "check"
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        flexWrap: 'wrap',
        gap: 6
      }
    }, montageLijst.map(function (a) {
      var on = extraIds.includes(a.id);
      return /*#__PURE__*/React.createElement("button", {
        key: a.id,
        onClick: function onClick() {
          return toggleExtra(a.id);
        },
        style: {
          background: on ? 'rgba(0,217,0,0.12)' : T.bg2,
          border: "1px solid ".concat(on ? T.strokeAccent : T.stroke1),
          borderRadius: 4,
          padding: '6px 11px',
          cursor: 'pointer',
          color: on ? T.accent : T.fg2,
          fontFamily: T.fontBody,
          fontSize: 11,
          fontWeight: 600
        }
      }, on ? '✓ ' : '', a.name, " (", fmtEur(a.buyPrice), ")");
    })), /*#__PURE__*/React.createElement("div", {
      style: {
        marginTop: 10
      }
    }, /*#__PURE__*/React.createElement(GhsSelect, {
      label: "Keuring & opmeting",
      value: keuringId,
      onChange: setKeuringId,
      options: calcArtOptions(arts, 'keuring', '', true)
    })), /*#__PURE__*/React.createElement("label", {
      style: {
        display: 'flex',
        alignItems: 'center',
        gap: 10,
        padding: '10px 14px',
        marginTop: 10,
        background: premie ? 'rgba(0,217,0,0.10)' : T.bg2,
        borderRadius: 5,
        border: "1px solid ".concat(premie ? T.accent : T.stroke1),
        cursor: 'pointer'
      }
    }, /*#__PURE__*/React.createElement("input", {
      type: "checkbox",
      checked: premie,
      onChange: function onChange(e) {
        return setPremie(e.target.checked);
      },
      style: {
        accentColor: T.accent
      }
    }), /*#__PURE__*/React.createElement("span", {
      style: {
        fontSize: 12,
        color: premie ? T.accent : T.fg2,
        fontWeight: 600
      }
    }, "Mijn VerbouwPremie aanvragen (\u2248 \u20AC 2.300 retour voor de klant)"))))
  });
};

/* ── Andere — vrije offerte ────────────────────────────────────── */
var AndereCalc = function AndereCalc(_ref11) {
  var klant = _ref11.klant,
    onPriceChange = _ref11.onPriceChange,
    _ref11$btw = _ref11.btw,
    btw = _ref11$btw === void 0 ? 21 : _ref11$btw;
  var _React$useState43 = React.useState([{
      id: 'a1',
      name: 'Artikel 1',
      qty: 1,
      buy: 0
    }]),
    _React$useState44 = _slicedToArray(_React$useState43, 2),
    items = _React$useState44[0],
    setItems = _React$useState44[1];
  var updateItem = function updateItem(id, f, v) {
    return setItems(function (prev) {
      return prev.map(function (i) {
        return i.id === id ? _objectSpread(_objectSpread({}, i), {}, _defineProperty({}, f, v)) : i;
      });
    });
  };
  var removeItem = function removeItem(id) {
    return setItems(function (prev) {
      return prev.filter(function (i) {
        return i.id !== id;
      });
    });
  };
  var addItem = function addItem() {
    return setItems(function (prev) {
      return [].concat(_toConsumableArray(prev), [{
        id: 'a' + Date.now(),
        name: '',
        qty: 1,
        buy: 0
      }]);
    });
  };
  var lineItems = items.filter(function (i) {
    return i.name;
  }).map(function (i) {
    return {
      name: i.name,
      qty: i.qty,
      buy: i.buy,
      total: i.qty * i.buy
    };
  });
  return /*#__PURE__*/React.createElement(SimpleCalcShell, {
    klant: klant,
    btw: btw,
    onPriceChange: onPriceChange,
    lineItems: lineItems,
    types: calcTypesFor('andere'),
    left: /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("h3", {
      style: {
        margin: '0 0 14px',
        fontFamily: T.fontDisplay,
        fontSize: 17,
        fontWeight: 600,
        color: T.fg1
      }
    }, "Vrije offerte \u2014 ", klant), /*#__PURE__*/React.createElement(CalcSection, {
      title: "ARTIKELEN",
      icon: "plus"
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'grid',
        gridTemplateColumns: '10px minmax(0,3fr) minmax(0,1fr) minmax(0,1fr) minmax(0,1fr) auto',
        gap: 8,
        alignItems: 'end',
        marginBottom: 8,
        padding: '0 0 8px',
        borderBottom: "1px solid ".concat(T.stroke1)
      }
    }, /*#__PURE__*/React.createElement("div", null), /*#__PURE__*/React.createElement("div", {
      style: {
        fontSize: 9,
        fontWeight: 700,
        letterSpacing: '0.12em',
        color: T.fg4,
        textTransform: 'uppercase'
      }
    }, "OMSCHRIJVING"), /*#__PURE__*/React.createElement("div", {
      style: {
        fontSize: 9,
        fontWeight: 700,
        letterSpacing: '0.12em',
        color: T.fg4,
        textTransform: 'uppercase'
      }
    }, "QTY"), /*#__PURE__*/React.createElement("div", {
      style: {
        fontSize: 9,
        fontWeight: 700,
        letterSpacing: '0.12em',
        color: T.fg4,
        textTransform: 'uppercase'
      }
    }, "\u20AC AANKOOP"), /*#__PURE__*/React.createElement("div", {
      style: {
        fontSize: 9,
        fontWeight: 700,
        letterSpacing: '0.12em',
        color: T.fg4,
        textTransform: 'uppercase'
      }
    }, "TOTAAL"), /*#__PURE__*/React.createElement("div", null)), items.map(function (it, i) {
      return /*#__PURE__*/React.createElement("div", {
        key: it.id,
        style: {
          display: 'grid',
          gridTemplateColumns: '10px minmax(0,3fr) minmax(0,1fr) minmax(0,1fr) minmax(0,1fr) auto',
          gap: 8,
          alignItems: 'center',
          marginBottom: 6
        }
      }, /*#__PURE__*/React.createElement("span", {
        style: {
          fontFamily: T.fontBody,
          fontSize: 11,
          color: T.fg4,
          fontWeight: 700
        }
      }, i + 1), /*#__PURE__*/React.createElement(Input, {
        value: it.name,
        onChange: function onChange(v) {
          return updateItem(it.id, 'name', v);
        },
        placeholder: "Artikel of dienst..."
      }), /*#__PURE__*/React.createElement(NumInput, {
        value: it.qty,
        onChange: function onChange(v) {
          return updateItem(it.id, 'qty', v);
        },
        min: 0,
        step: 1
      }), /*#__PURE__*/React.createElement(NumInput, {
        value: it.buy,
        onChange: function onChange(v) {
          return updateItem(it.id, 'buy', v);
        },
        min: 0,
        step: 10,
        suffix: "\u20AC"
      }), /*#__PURE__*/React.createElement("span", {
        style: {
          fontFamily: T.fontDisplay,
          fontSize: 13,
          fontWeight: 600,
          color: T.fg1,
          textAlign: 'right',
          fontVariantNumeric: 'tabular-nums'
        }
      }, fmtEur(it.qty * it.buy)), /*#__PURE__*/React.createElement("button", {
        onClick: function onClick() {
          return removeItem(it.id);
        },
        disabled: items.length <= 1,
        style: {
          background: 'none',
          border: 'none',
          cursor: items.length <= 1 ? 'default' : 'pointer',
          color: T.fg3,
          padding: 8,
          opacity: items.length <= 1 ? 0.3 : 1
        }
      }, /*#__PURE__*/React.createElement(Icon, {
        name: "trash",
        size: 13
      })));
    }), /*#__PURE__*/React.createElement("div", {
      style: {
        marginTop: 10
      }
    }, /*#__PURE__*/React.createElement(Button, {
      variant: "secondary",
      size: "sm",
      icon: "plus",
      onClick: addItem
    }, "Lijn toevoegen"))))
  });
};

/* ─────────────────────────────────────────────────────── STEP 2 ROUTER */
var Step2Calculator = function Step2Calculator(_ref12) {
  var data = _ref12.data,
    setData = _ref12.setData,
    onBack = _ref12.onBack,
    onNext = _ref12.onNext;
  var products = data.products || [];
  var _React$useState45 = React.useState(products[0]),
    _React$useState46 = _slicedToArray(_React$useState45, 2),
    active = _React$useState46[0],
    setActive = _React$useState46[1];
  var store = useArticles();

  // Geen voorafcontrole van de hele artikeldatabank meer — er wordt pas gecontroleerd
  // wat effectief in de offerte staat (zie CalcIssuePanel bij de offertelijnen).

  // Ensure active is one of the selected products
  React.useEffect(function () {
    if (!products.includes(active)) setActive(products[0]);
  }, [products, active]);

  // Stable onSave per productId
  var makeOnSave = React.useCallback(function (pid) {
    return function (payload) {
      setData(function (d) {
        return _objectSpread(_objectSpread({}, d), {}, {
          offertes: _objectSpread(_objectSpread({}, d.offertes), {}, _defineProperty({}, pid, payload))
        });
      });
    };
  }, [setData]);
  var offertes = data.offertes || {};
  var completed = products.filter(function (pid) {
    return offertes[pid] && ((offertes[pid].total || 0) > 0 || (offertes[pid].totalInclVAT || 0) > 0);
  });
  var hasAny = completed.length > 0;
  var renderCalc = function renderCalc(pid) {
    var prod = productById(pid);
    if (prod && prod.profiel) {
      return /*#__PURE__*/React.createElement(SolarBatteryCalc, {
        key: pid,
        isAdmin: true,
        embedded: true,
        klant: data.klant,
        mode: prod.zp ? 'zp_batt' : 'batt',
        contactId: data.contactId,
        profielId: pid,
        verkoper: data.verkoper,
        btwVoorstel: calcBtwVoor(data, pid),
        onSave: function onSave(s) {
          return setData(function (d) {
            return _objectSpread(_objectSpread({}, d), {}, {
              offertes: _objectSpread(_objectSpread({}, d.offertes), {}, _defineProperty({}, pid, {
                product: pid,
                klant: s.klant,
                sell: s.sellPrice,
                btwAm: s.btwAmount,
                total: s.totalInclVAT,
                lineItems: s.lineItems,
                summary: s.summary,
                kWp: s.kWp,
                kwh: s.kwh,
                btw: s.btw,
                items: s.items,
                calc: s.calc,
                type: s.type,
                profielLabel: s.profielLabel
              }))
            });
          });
        }
      });
    }
    if (pid === 'zp_batt' || pid === 'zp' || pid === 'batt') {
      return /*#__PURE__*/React.createElement(SolarBatteryCalc, {
        key: pid,
        isAdmin: true,
        embedded: true,
        klant: data.klant,
        mode: pid,
        contactId: data.contactId,
        btwVoorstel: calcBtwVoor(data, pid),
        onSave: function onSave(s) {
          return setData(function (d) {
            return _objectSpread(_objectSpread({}, d), {}, {
              offertes: _objectSpread(_objectSpread({}, d.offertes), {}, _defineProperty({}, pid, {
                product: pid,
                klant: s.klant,
                sell: s.sellPrice,
                btwAm: s.btwAmount,
                total: s.totalInclVAT,
                lineItems: s.lineItems,
                summary: s.summary,
                kWp: s.kWp,
                kwh: s.kwh,
                btw: s.btw
              }))
            });
          });
        }
      });
    }
    if (pid === 'laadpaal') return /*#__PURE__*/React.createElement(LaadpaalCalc, {
      key: pid,
      klant: data.klant,
      onPriceChange: makeOnSave(pid),
      btw: calcBtwVoor(data, pid)
    });
    if (pid === 'airco') return /*#__PURE__*/React.createElement(AircoCalc, {
      key: pid,
      klant: data.klant,
      onPriceChange: makeOnSave(pid),
      btw: calcBtwVoor(data, pid)
    });
    if (pid === 'warmtepomp') return /*#__PURE__*/React.createElement(WarmtepompCalc, {
      key: pid,
      klant: data.klant,
      onPriceChange: makeOnSave(pid),
      btw: calcBtwVoor(data, pid)
    });
    if (pid === 'andere') return /*#__PURE__*/React.createElement(AndereCalc, {
      key: pid,
      klant: data.klant,
      onPriceChange: makeOnSave(pid),
      btw: calcBtwVoor(data, pid)
    });
    return null;
  };
  return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
    style: {
      padding: '12px 24px 0',
      background: T.bg0,
      borderBottom: "1px solid ".concat(T.stroke1)
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      alignItems: 'center',
      justifyContent: 'space-between',
      marginBottom: 12
    }
  }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
    style: {
      fontSize: 10,
      fontFamily: T.fontBody,
      fontWeight: 700,
      letterSpacing: '0.16em',
      textTransform: 'uppercase',
      color: T.fg4
    }
  }, "STAP 2 \u2014 CALCULATOR"), /*#__PURE__*/React.createElement("div", {
    style: {
      fontFamily: T.fontDisplay,
      fontSize: 16,
      fontWeight: 600,
      color: T.fg1
    }
  }, data.klant, " ", /*#__PURE__*/React.createElement("span", {
    style: {
      color: T.fg3,
      fontWeight: 400,
      fontSize: 13
    }
  }, "\xB7 ", products.length, " ", products.length === 1 ? 'offerte' : 'offertes'))), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      gap: 8,
      alignItems: 'center'
    }
  }, /*#__PURE__*/React.createElement("span", {
    style: {
      fontSize: 11,
      color: T.fg3,
      fontFamily: T.fontBody,
      fontWeight: 600
    }
  }, completed.length, " / ", products.length, " klaar"), /*#__PURE__*/React.createElement(Button, {
    variant: "ghost",
    onClick: onBack
  }, "\u2190 Vorige"), /*#__PURE__*/React.createElement(Button, {
    variant: "primary",
    icon: "check",
    onClick: onNext,
    fullWidth: false,
    style: {
      opacity: hasAny ? 1 : 0.45,
      pointerEvents: hasAny ? 'auto' : 'none'
    }
  }, "Naar klantportaal \u2192"))), products.length > 1 && /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      gap: 0,
      overflowX: 'auto',
      marginBottom: -1
    }
  }, products.map(function (pid, idx) {
    var _offertes$pid, _offertes$pid2;
    var p = productById(pid);
    var isActive = active === pid;
    var isDone = offertes[pid] && ((offertes[pid].total || 0) > 0 || (offertes[pid].totalInclVAT || 0) > 0);
    var tot = ((_offertes$pid = offertes[pid]) === null || _offertes$pid === void 0 ? void 0 : _offertes$pid.total) || ((_offertes$pid2 = offertes[pid]) === null || _offertes$pid2 === void 0 ? void 0 : _offertes$pid2.totalInclVAT) || 0;
    return /*#__PURE__*/React.createElement("button", {
      key: pid,
      onClick: function onClick() {
        return setActive(pid);
      },
      style: {
        background: isActive ? T.bg2 : 'transparent',
        border: 'none',
        borderBottom: "2px solid ".concat(isActive ? p.color : 'transparent'),
        padding: '10px 16px',
        cursor: 'pointer',
        display: 'flex',
        alignItems: 'center',
        gap: 10,
        fontFamily: T.fontBody,
        fontSize: 12,
        fontWeight: isActive ? 700 : 500,
        color: isActive ? T.fg1 : T.fg3,
        whiteSpace: 'nowrap',
        flexShrink: 0
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        width: 22,
        height: 22,
        borderRadius: '50%',
        background: isDone ? "".concat(p.color, "30") : T.bg2,
        border: "1px solid ".concat(isActive ? p.color : T.stroke1),
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'center',
        fontFamily: T.fontDisplay,
        fontSize: 11,
        fontWeight: 700,
        color: isDone ? p.color : T.fg3
      }
    }, isDone ? /*#__PURE__*/React.createElement(Icon, {
      name: "check",
      size: 11,
      color: p.color
    }) : idx + 1), /*#__PURE__*/React.createElement("span", null, p.name), tot > 0 && /*#__PURE__*/React.createElement("span", {
      style: {
        fontFamily: T.fontDisplay,
        fontSize: 11,
        color: p.color,
        fontVariantNumeric: 'tabular-nums'
      }
    }, fmtEur(tot)));
  }))), /*#__PURE__*/React.createElement("div", {
    style: {
      padding: '14px 20px 0'
    }
  }, /*#__PURE__*/React.createElement(CalcContactCard, {
    data: data,
    setData: setData,
    compact: true
  })), active && renderCalc(active));
};

/* ─────────────────────────────────────────────────────── STEP 3 PORTAL */

/* Per-offer portal sub-view (offerte/specs/feedback + decision) */
var OfferPortalView = function OfferPortalView(_ref13) {
  var _o$btw;
  var offerte = _ref13.offerte,
    product = _ref13.product,
    klant = _ref13.klant,
    klantAdres = _ref13.klantAdres,
    offNr = _ref13.offNr,
    decision = _ref13.decision,
    setDecision = _ref13.setDecision,
    feedback = _ref13.feedback,
    setFeedback = _ref13.setFeedback,
    _ref13$bijlagen = _ref13.bijlagen,
    bijlagen = _ref13$bijlagen === void 0 ? [] : _ref13$bijlagen;
  var _React$useState47 = React.useState('document'),
    _React$useState48 = _slicedToArray(_React$useState47, 2),
    tab = _React$useState48[0],
    setTab = _React$useState48[1];
  var o = offerte || {};
  var total = o.total || o.totalInclVAT || 0;
  var sell = o.sell || o.sellPrice || 0;
  var btw = (_o$btw = o.btw) !== null && _o$btw !== void 0 ? _o$btw : product.id === 'warmtepomp' || product.id === 'zp_batt' || product.id === 'zp' || product.id === 'batt' ? 6 : 21;
  var btwAm = o.btwAm || o.btwAmount || sell * btw / 100;
  var lines = o.lineItems || [];
  var totalSum = lines.reduce(function (s, l) {
    return s + (l.total || 0);
  }, 0);
  var submit = function submit(d) {
    return setDecision(d);
  };
  return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
    style: {
      marginBottom: 14
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      fontSize: 10,
      fontFamily: T.fontBody,
      fontWeight: 700,
      letterSpacing: '0.16em',
      textTransform: 'uppercase',
      color: T.fg3,
      marginBottom: 4
    }
  }, "OFFERTE ", offNr), /*#__PURE__*/React.createElement("h2", {
    style: {
      margin: 0,
      fontFamily: T.fontDisplay,
      fontSize: 24,
      fontWeight: 600,
      color: T.fg1,
      letterSpacing: '-0.02em'
    }
  }, product.name)), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      gap: 0,
      borderBottom: "1px solid ".concat(T.stroke1),
      marginBottom: 16
    }
  }, [{
    id: 'document',
    label: 'Offerte'
  }, {
    id: 'specs',
    label: 'Specificaties'
  }, {
    id: 'feedback',
    label: 'Vragen & feedback'
  }].map(function (t) {
    return /*#__PURE__*/React.createElement("button", {
      key: t.id,
      onClick: function onClick() {
        return setTab(t.id);
      },
      style: {
        background: 'transparent',
        border: 'none',
        borderBottom: "2px solid ".concat(tab === t.id ? product.color : 'transparent'),
        padding: '9px 16px',
        cursor: 'pointer',
        color: tab === t.id ? T.fg1 : T.fg3,
        fontFamily: T.fontBody,
        fontSize: 13,
        fontWeight: tab === t.id ? 700 : 500,
        marginBottom: -1
      }
    }, t.label);
  })), tab === 'document' && /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
    style: {
      background: '#F6F7EB',
      padding: 28,
      color: '#0b1f1c',
      fontFamily: '"Manrope",sans-serif',
      marginBottom: 16
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      justifyContent: 'space-between',
      borderBottom: '2px solid #0b1f1c',
      paddingBottom: 14,
      marginBottom: 18
    }
  }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
    style: {
      fontFamily: '"Clash Display",sans-serif',
      fontSize: 18,
      fontWeight: 600
    }
  }, "GREEN HOUSE SOLUTIONS"), /*#__PURE__*/React.createElement("div", {
    style: {
      fontSize: 11,
      opacity: 0.7,
      marginTop: 3
    }
  }, window.ghsBedrijfAdres ? window.ghsBedrijfAdres(null, ' · ') : 'Willebroeksesteenweg 15 · 2830 Willebroek')), /*#__PURE__*/React.createElement("div", {
    style: {
      textAlign: 'right'
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      fontSize: 11,
      opacity: 0.6,
      letterSpacing: '0.14em'
    }
  }, "OFFERTE"), /*#__PURE__*/React.createElement("div", {
    style: {
      fontFamily: '"Clash Display",sans-serif',
      fontSize: 20,
      fontWeight: 600
    }
  }, offNr), /*#__PURE__*/React.createElement("div", {
    style: {
      fontSize: 11,
      opacity: 0.7,
      marginTop: 2
    }
  }, "26 mei 2026", window.DL_GELDIG_DAGEN && window.DL_GELDIG_DAGEN() > 0 ? " \xB7 ".concat(window.DL_GELDIG_DAGEN(), " dagen geldig") : ''))), /*#__PURE__*/React.createElement("div", {
    style: {
      marginBottom: 18
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      fontSize: 10,
      opacity: 0.6,
      letterSpacing: '0.14em',
      marginBottom: 3
    }
  }, "AAN"), /*#__PURE__*/React.createElement("div", {
    style: {
      fontSize: 14,
      fontWeight: 600
    }
  }, klant), klantAdres && /*#__PURE__*/React.createElement("div", {
    style: {
      fontSize: 12,
      opacity: 0.7
    }
  }, klantAdres)), /*#__PURE__*/React.createElement("table", {
    style: {
      width: '100%',
      borderCollapse: 'collapse',
      fontSize: 12
    }
  }, /*#__PURE__*/React.createElement("thead", null, /*#__PURE__*/React.createElement("tr", {
    style: {
      borderBottom: '1px solid rgba(11,31,28,0.2)'
    }
  }, /*#__PURE__*/React.createElement("th", {
    style: {
      padding: '8px 0',
      textAlign: 'left',
      fontSize: 10,
      letterSpacing: '0.1em',
      opacity: 0.6,
      fontWeight: 700
    }
  }, "OMSCHRIJVING"), /*#__PURE__*/React.createElement("th", {
    style: {
      padding: '8px 0',
      textAlign: 'right',
      fontSize: 10,
      letterSpacing: '0.1em',
      opacity: 0.6,
      fontWeight: 700,
      width: 80
    }
  }, "QTY"), /*#__PURE__*/React.createElement("th", {
    style: {
      padding: '8px 0',
      textAlign: 'right',
      fontSize: 10,
      letterSpacing: '0.1em',
      opacity: 0.6,
      fontWeight: 700,
      width: 110
    }
  }, "BEDRAG"))), /*#__PURE__*/React.createElement("tbody", null, lines.map(function (li, i) {
    return /*#__PURE__*/React.createElement("tr", {
      key: i,
      style: {
        borderBottom: '1px solid rgba(11,31,28,0.08)'
      }
    }, /*#__PURE__*/React.createElement("td", {
      style: {
        padding: '8px 0',
        fontSize: 12
      }
    }, li.name), /*#__PURE__*/React.createElement("td", {
      style: {
        padding: '8px 0',
        textAlign: 'right',
        fontSize: 12,
        fontVariantNumeric: 'tabular-nums'
      }
    }, li.qty), /*#__PURE__*/React.createElement("td", {
      style: {
        padding: '8px 0',
        textAlign: 'right',
        fontSize: 12,
        fontVariantNumeric: 'tabular-nums',
        fontWeight: 600
      }
    }, fmtEur(totalSum > 0 ? sell * (li.total / totalSum) : 0)));
  }), lines.length === 0 && /*#__PURE__*/React.createElement("tr", null, /*#__PURE__*/React.createElement("td", {
    colSpan: 3,
    style: {
      padding: '14px 0',
      fontSize: 12,
      fontStyle: 'italic',
      opacity: 0.6,
      textAlign: 'center'
    }
  }, "Geen lijnen geconfigureerd voor deze offerte.")))), /*#__PURE__*/React.createElement("div", {
    style: {
      marginTop: 14,
      paddingTop: 14,
      borderTop: '2px solid #0b1f1c',
      display: 'flex',
      flexDirection: 'column',
      alignItems: 'flex-end',
      gap: 4
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      gap: 20,
      fontSize: 12
    }
  }, /*#__PURE__*/React.createElement("span", null, "Subtotaal excl. BTW"), /*#__PURE__*/React.createElement("span", {
    style: {
      fontVariantNumeric: 'tabular-nums',
      minWidth: 90,
      textAlign: 'right'
    }
  }, fmtEur(sell))), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      gap: 20,
      fontSize: 12
    }
  }, /*#__PURE__*/React.createElement("span", null, +btw === 0 ? 'Btw verlegd (0 %)' : "BTW ".concat(btw, "%")), /*#__PURE__*/React.createElement("span", {
    style: {
      fontVariantNumeric: 'tabular-nums',
      minWidth: 90,
      textAlign: 'right'
    }
  }, fmtEur(btwAm))), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      gap: 20,
      fontSize: 16,
      fontWeight: 700,
      marginTop: 4
    }
  }, /*#__PURE__*/React.createElement("span", null, "TOTAAL"), /*#__PURE__*/React.createElement("span", {
    style: {
      fontFamily: '"Clash Display",sans-serif',
      fontVariantNumeric: 'tabular-nums',
      minWidth: 90,
      textAlign: 'right',
      color: '#0b1f1c'
    }
  }, fmtEur(total)))), bijlagen.length > 0 && /*#__PURE__*/React.createElement("div", {
    style: {
      marginTop: 18,
      paddingTop: 14,
      borderTop: '1px solid rgba(11,31,28,0.2)'
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      fontSize: 10,
      opacity: 0.6,
      letterSpacing: '0.14em',
      marginBottom: 6
    }
  }, "BIJLAGEN \u2014 TECHNISCHE FICHES"), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      flexDirection: 'column',
      gap: 3
    }
  }, bijlagen.map(function (s) {
    return /*#__PURE__*/React.createElement("div", {
      key: s.id,
      style: {
        display: 'flex',
        gap: 10,
        fontSize: 11.5
      }
    }, /*#__PURE__*/React.createElement("span", {
      style: {
        fontWeight: 700,
        minWidth: 44
      }
    }, s.kind), /*#__PURE__*/React.createElement("span", {
      style: {
        flex: 1
      }
    }, s.name), /*#__PURE__*/React.createElement("span", {
      style: {
        opacity: 0.55
      }
    }, s.artCode));
  })))), !decision && /*#__PURE__*/React.createElement("div", {
    style: {
      background: T.bg0,
      border: "1px solid ".concat(T.stroke1),
      clipPath: cutPath(10),
      padding: '16px 18px'
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      fontSize: 11,
      fontFamily: T.fontBody,
      fontWeight: 700,
      letterSpacing: '0.14em',
      textTransform: 'uppercase',
      color: T.fg3,
      marginBottom: 12
    }
  }, "UW BESLISSING VOOR DEZE OFFERTE"), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      gap: 8
    }
  }, /*#__PURE__*/React.createElement("button", {
    onClick: function onClick() {
      return submit('accepted');
    },
    style: {
      flex: 1,
      background: 'rgba(0,217,0,0.12)',
      border: '1px solid rgba(0,217,0,0.4)',
      clipPath: cutPath(8),
      padding: '12px 14px',
      cursor: 'pointer',
      color: T.accent,
      fontFamily: T.fontBody,
      fontSize: 13,
      fontWeight: 700,
      display: 'flex',
      alignItems: 'center',
      justifyContent: 'center',
      gap: 8
    }
  }, /*#__PURE__*/React.createElement(Icon, {
    name: "check",
    size: 14,
    color: T.accent
  }), "Aanvaarden"), /*#__PURE__*/React.createElement("button", {
    onClick: function onClick() {
      return submit('changes');
    },
    style: {
      flex: 1,
      background: 'rgba(255,176,32,0.12)',
      border: '1px solid rgba(255,176,32,0.4)',
      clipPath: cutPath(8),
      padding: '12px 14px',
      cursor: 'pointer',
      color: '#ffb020',
      fontFamily: T.fontBody,
      fontSize: 13,
      fontWeight: 700,
      display: 'flex',
      alignItems: 'center',
      justifyContent: 'center',
      gap: 8
    }
  }, /*#__PURE__*/React.createElement(Icon, {
    name: "edit",
    size: 14,
    color: "#ffb020"
  }), "Wijziging vragen"), /*#__PURE__*/React.createElement("button", {
    onClick: function onClick() {
      return submit('rejected');
    },
    style: {
      flex: 1,
      background: 'rgba(255,90,77,0.10)',
      border: '1px solid rgba(255,90,77,0.35)',
      clipPath: cutPath(8),
      padding: '12px 14px',
      cursor: 'pointer',
      color: '#ff5a4d',
      fontFamily: T.fontBody,
      fontSize: 13,
      fontWeight: 700,
      display: 'flex',
      alignItems: 'center',
      justifyContent: 'center',
      gap: 8
    }
  }, /*#__PURE__*/React.createElement(Icon, {
    name: "x",
    size: 14,
    color: "#ff5a4d"
  }), "Weigeren"))), decision && /*#__PURE__*/React.createElement("div", {
    style: {
      background: decision === 'accepted' ? 'rgba(0,217,0,0.10)' : decision === 'rejected' ? 'rgba(255,90,77,0.10)' : 'rgba(255,176,32,0.10)',
      border: "1px solid ".concat(decision === 'accepted' ? 'rgba(0,217,0,0.35)' : decision === 'rejected' ? 'rgba(255,90,77,0.35)' : 'rgba(255,176,32,0.35)'),
      clipPath: cutPath(10),
      padding: '16px 18px',
      display: 'flex',
      alignItems: 'center',
      gap: 14
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      width: 38,
      height: 38,
      borderRadius: '50%',
      background: decision === 'accepted' ? 'rgba(0,217,0,0.2)' : decision === 'rejected' ? 'rgba(255,90,77,0.2)' : 'rgba(255,176,32,0.2)',
      display: 'flex',
      alignItems: 'center',
      justifyContent: 'center'
    }
  }, /*#__PURE__*/React.createElement(Icon, {
    name: decision === 'accepted' ? 'check' : decision === 'rejected' ? 'x' : 'edit',
    size: 18,
    color: decision === 'accepted' ? T.accent : decision === 'rejected' ? '#ff5a4d' : '#ffb020'
  })), /*#__PURE__*/React.createElement("div", {
    style: {
      flex: 1
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      fontFamily: T.fontDisplay,
      fontSize: 16,
      fontWeight: 600,
      color: T.fg1
    }
  }, decision === 'accepted' ? 'Offerte aanvaard' : decision === 'rejected' ? 'Offerte geweigerd' : 'Wijziging gevraagd'), /*#__PURE__*/React.createElement("div", {
    style: {
      fontSize: 12,
      color: T.fg3,
      fontFamily: T.fontBody,
      marginTop: 2
    }
  }, decision === 'accepted' ? 'Bedankt! Uw verkoper neemt binnen 24u contact op voor de planning.' : decision === 'rejected' ? 'Jammer dat we niet samen verder konden. Uw feedback is welkom.' : 'Uw aanvraag is genoteerd. We sturen u binnenkort een aangepaste offerte.')), /*#__PURE__*/React.createElement(Button, {
    variant: "ghost",
    size: "sm",
    onClick: function onClick() {
      return setDecision(null);
    }
  }, "Wijzigen"))), tab === 'specs' && /*#__PURE__*/React.createElement("div", {
    style: {
      background: T.bg2,
      clipPath: cutPath(10),
      padding: '18px 20px',
      border: "1px solid ".concat(T.stroke1)
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      fontSize: 11,
      fontFamily: T.fontBody,
      fontWeight: 700,
      letterSpacing: '0.14em',
      textTransform: 'uppercase',
      color: T.fg3,
      marginBottom: 14
    }
  }, "TECHNISCHE SPECIFICATIES"), o.summary ? /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'grid',
      gridTemplateColumns: '1fr 1fr',
      gap: 10
    }
  }, Object.entries(o.summary).filter(function (_ref14) {
    var _ref15 = _slicedToArray(_ref14, 2),
      _ = _ref15[0],
      v = _ref15[1];
    return v;
  }).map(function (_ref16) {
    var _ref17 = _slicedToArray(_ref16, 2),
      k = _ref17[0],
      v = _ref17[1];
    return /*#__PURE__*/React.createElement("div", {
      key: k,
      style: {
        background: T.bg1,
        padding: '10px 14px',
        clipPath: cutPath(8)
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        fontSize: 9,
        fontFamily: T.fontBody,
        fontWeight: 700,
        letterSpacing: '0.12em',
        textTransform: 'uppercase',
        color: T.fg4,
        marginBottom: 3
      }
    }, k), /*#__PURE__*/React.createElement("div", {
      style: {
        fontSize: 12,
        color: T.fg1,
        fontFamily: T.fontBody,
        fontWeight: 600
      }
    }, v));
  })) : /*#__PURE__*/React.createElement("div", null, lines.map(function (l, i) {
    return /*#__PURE__*/React.createElement("div", {
      key: i,
      style: {
        display: 'flex',
        justifyContent: 'space-between',
        padding: '8px 0',
        borderBottom: "1px solid ".concat(T.stroke1)
      }
    }, /*#__PURE__*/React.createElement("span", {
      style: {
        fontSize: 12,
        color: T.fg1,
        fontFamily: T.fontBody
      }
    }, l.name), /*#__PURE__*/React.createElement("span", {
      style: {
        fontSize: 12,
        color: T.fg3,
        fontFamily: T.fontBody,
        fontVariantNumeric: 'tabular-nums'
      }
    }, "\xD7", l.qty));
  }))), tab === 'feedback' && /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
    style: {
      background: T.bg2,
      clipPath: cutPath(10),
      padding: '18px 20px',
      border: "1px solid ".concat(T.stroke1),
      marginBottom: 14
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      fontSize: 11,
      fontFamily: T.fontBody,
      fontWeight: 700,
      letterSpacing: '0.14em',
      textTransform: 'uppercase',
      color: T.fg3,
      marginBottom: 10
    }
  }, "UW VRAAG OF OPMERKING"), /*#__PURE__*/React.createElement("textarea", {
    value: feedback,
    onChange: function onChange(e) {
      return setFeedback(e.target.value);
    },
    rows: 4,
    placeholder: "Bv. een vraag of wijziging over ".concat(product.name.toLowerCase(), "..."),
    style: {
      width: '100%',
      background: T.bg0,
      border: "1px solid ".concat(T.stroke1),
      borderRadius: 5,
      padding: 12,
      color: T.fg1,
      fontFamily: T.fontBody,
      fontSize: 12,
      lineHeight: 1.6,
      outline: 'none',
      resize: 'vertical',
      boxSizing: 'border-box'
    }
  }), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      justifyContent: 'flex-end',
      marginTop: 10
    }
  }, /*#__PURE__*/React.createElement(Button, {
    variant: "primary",
    size: "sm",
    icon: "send",
    onClick: function onClick() {
      if (feedback) setFeedback('');
    }
  }, "Vraag verzenden"))), /*#__PURE__*/React.createElement("div", {
    style: {
      fontSize: 11,
      color: T.fg3,
      fontFamily: T.fontBody,
      marginBottom: 8,
      letterSpacing: '0.14em',
      fontWeight: 700,
      textTransform: 'uppercase'
    }
  }, "VORIGE BERICHTEN"), /*#__PURE__*/React.createElement("div", {
    style: {
      background: T.bg2,
      clipPath: cutPath(10),
      padding: '14px 16px',
      border: "1px solid ".concat(T.stroke1),
      textAlign: 'center',
      fontSize: 12,
      color: T.fg4,
      fontFamily: T.fontBody,
      fontStyle: 'italic'
    }
  }, "Nog geen berichten uitgewisseld voor deze offerte.")));
};

/* Step 3: multi-offer customer portal preview */
var DECISION_META = {
  accepted: {
    label: 'Aanvaard',
    color: T.accent,
    type: 'success',
    icon: 'check'
  },
  changes: {
    label: 'Wijziging gevraagd',
    color: '#ffb020',
    type: 'warning',
    icon: 'edit'
  },
  rejected: {
    label: 'Geweigerd',
    color: '#ff5a4d',
    type: 'danger',
    icon: 'x'
  }
};

/* ── Calculator → contactfiche & Deals ──────────────────────────────────────
   Elke berekende offerte wordt als deal op de contactfiche gezet, met haar
   offertelijnen, kWp/kWh en verkoper. Vandaar loopt alles verder: activiteit,
   dealfase, facturatie én de knop "Opmeting opstarten". */
var CalcDealSync = function CalcDealSync(_ref18) {
  var data = _ref18.data,
    setData = _ref18.setData,
    products = _ref18.products,
    offertes = _ref18.offertes,
    offNrFor = _ref18.offNrFor;
  var contactId = data.contactId;
  var crm = window.useCRM ? window.useCRM() : {
    contacts: []
  };
  var contact = crm.contacts.find(function (c) {
    return c.id === contactId;
  });
  var gemaakt = data.deals || {};
  var klaar = products.filter(function (pid) {
    return offertes[pid] && ((offertes[pid].total || 0) > 0 || (offertes[pid].totalInclVAT || 0) > 0);
  });
  if (!contact || !klaar.length) return null;
  var typeVoor = function typeVoor(pid) {
    return {
      zp_batt: 'Zonnepanelen + batterij',
      zp: 'Zonnepanelen',
      batt: 'Thuisbatterij',
      laadpaal: 'Laadpaal',
      airco: 'Airco',
      warmtepomp: 'Warmtepomp',
      andere: 'Andere'
    }[pid] || (offertes[pid] || {}).type || (productById(pid) || {}).name || 'Andere';
  };
  var maakDeal = function maakDeal(pid) {
    var off = offertes[pid] || {};
    /* Samenstelling: de offertelijnen en het rekenresultaat van de rekenmotor (korting als aparte lijn). */
    if (Array.isArray(off.items) && off.items.length) {
      var c = off.calc || {};
      var _ref19 = window.crmStore.addDeal(contactId, _objectSpread(_objectSpread({
        name: window.calcDealNaam && off.calc ? window.calcDealNaam(off.calc) : "".concat(off.profielLabel || typeVoor(pid)).concat(c.nPanelen ? " \u2014 ".concat(c.nPanelen, " panelen") : '').concat(c.kwh ? " + ".concat(c.kwh, " kWh") : ''),
        type: off.type || typeVoor(pid),
        items: off.items,
        btwPct: off.btw != null ? off.btw : 6,
        kwp: off.kWp || 0,
        kwh: off.kwh || 0,
        verkoper: data.verkoper,
        calc: off.calc || null
      }, data.b2b ? {} : {
        woning: data.woning || {}
      }), {}, {
        opmCatVoorstel: c.nPanelen ? 'cat2' : 'cat1'
      }));
      setData(function (d) {
        return _objectSpread(_objectSpread({}, d), {}, {
          deals: _objectSpread(_objectSpread({}, d.deals || {}), {}, _defineProperty({}, pid, _ref19))
        });
      });
      return;
    }
    var totIncl = off.total || off.totalInclVAT || 0;
    var btwAm = off.btwAm || off.btwAmount || 0;
    var excl = off.sell || off.sellPrice || totIncl - btwAm;
    var lijnen = (off.lineItems || []).filter(function (l) {
      return (l.total || 0) > 0;
    });
    var basis = lijnen.reduce(function (s, l) {
      return s + (l.total || 0);
    }, 0);
    var items = lijnen.length ? lijnen.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 ? l.total / basis * excl : l.total) * 100) / 100
      };
    }) : [{
      label: typeVoor(pid),
      detail: '',
      qty: 1,
      amount: Math.round(excl * 100) / 100
    }];
    var ref = window.crmStore.addDeal(contactId, _objectSpread(_objectSpread({
      name: "".concat(typeVoor(pid)).concat(off.summary && off.summary.panelen ? " \u2014 ".concat(off.summary.panelen) : ''),
      type: typeVoor(pid),
      items: items,
      btwPct: off.btw != null ? off.btw : 6
    }, data.b2b ? {} : {
      woning: data.woning || {}
    }), {}, {
      kwp: off.kWp || 0,
      kwh: off.kwh || 0,
      verkoper: data.verkoper,
      opmCatVoorstel: pid === 'zp_batt' || pid === 'zp' ? 'cat2' : 'cat1'
    }));
    setData(function (d) {
      return _objectSpread(_objectSpread({}, d), {}, {
        deals: _objectSpread(_objectSpread({}, d.deals || {}), {}, _defineProperty({}, pid, ref))
      });
    });
  };
  var openStaand = klaar.filter(function (pid) {
    return !gemaakt[pid];
  });
  return /*#__PURE__*/React.createElement("div", {
    style: {
      background: T.bg1,
      border: "1px solid ".concat(T.stroke1),
      clipPath: cutPath(10),
      padding: '11px 13px',
      marginBottom: 12
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      alignItems: 'center',
      gap: 8,
      marginBottom: 8
    }
  }, /*#__PURE__*/React.createElement(Icon, {
    name: "handshake",
    size: 13,
    color: T.accent
  }), /*#__PURE__*/React.createElement("span", {
    style: {
      fontFamily: T.fontBody,
      fontSize: 11.5,
      fontWeight: 700,
      color: T.fg1,
      flex: 1
    }
  }, "Naar contactfiche & Deals"), /*#__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
    }
  }, "Fiche openen \u2192")), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      flexDirection: 'column',
      gap: 6
    }
  }, klaar.map(function (pid, idx) {
    var ref = gemaakt[pid];
    var deal = ref ? (contact.deals || []).find(function (d) {
      return d.ref === ref;
    }) : null;
    var off = offertes[pid] || {};
    return /*#__PURE__*/React.createElement("div", {
      key: pid,
      style: {
        display: 'flex',
        alignItems: 'center',
        gap: 8,
        padding: '7px 9px',
        background: T.bg0,
        border: "1px solid ".concat(ref ? T.strokeAccent : T.stroke1),
        clipPath: cutPath(8)
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        flex: 1,
        minWidth: 0
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        fontFamily: T.fontBody,
        fontSize: 11.5,
        fontWeight: 600,
        color: T.fg1,
        overflow: 'hidden',
        textOverflow: 'ellipsis',
        whiteSpace: 'nowrap'
      }
    }, off.calc && window.calcDealNaam ? window.calcDealNaam(off.calc) : typeVoor(pid)), /*#__PURE__*/React.createElement("div", {
      style: {
        fontFamily: T.fontBody,
        fontSize: 10,
        color: T.fg4
      }
    }, ref ? "Deal ".concat(ref) : offNrFor(pid, idx), " \xB7 ", fmtEur(off.total || off.totalInclVAT || 0))), ref && deal ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(window.DealSendButton, {
      contact: contact,
      deal: deal
    }), /*#__PURE__*/React.createElement(OpmStartButton, {
      contact: contact,
      deal: deal
    })) : /*#__PURE__*/React.createElement(Button, {
      variant: "secondary",
      size: "sm",
      icon: "plus",
      onClick: function onClick() {
        return maakDeal(pid);
      }
    }, "Deal aanmaken"));
  })), openStaand.length > 1 && /*#__PURE__*/React.createElement("div", {
    style: {
      marginTop: 8
    }
  }, /*#__PURE__*/React.createElement(Button, {
    variant: "primary",
    size: "sm",
    icon: "handshake",
    fullWidth: true,
    onClick: function onClick() {
      return openStaand.forEach(maakDeal);
    }
  }, "Alle ", openStaand.length, " offertes als deal aanmaken")), /*#__PURE__*/React.createElement("div", {
    style: {
      fontFamily: T.fontBody,
      fontSize: 10,
      color: T.fg4,
      marginTop: 8,
      lineHeight: 1.5
    }
  }, "De deal krijgt alle offertelijnen, het vermogen en de verkoper mee \u2014 de dealfase gaat automatisch naar ", /*#__PURE__*/React.createElement("span", {
    style: {
      color: T.fg3,
      fontWeight: 700
    }
  }, "Offerte opgemaakt"), ", en naar ", /*#__PURE__*/React.createElement("span", {
    style: {
      color: T.fg3,
      fontWeight: 700
    }
  }, "Offerte verstuurd"), " zodra je de offerte doormailt. Daarna kan je meteen een opmeting opstarten \u2014 die verschijnt in de fiche en bij Opmetingen."));
};
var Step3Portal = function Step3Portal(_ref20) {
  var _data$klant2;
  var data = _ref20.data,
    setData = _ref20.setData,
    onBack = _ref20.onBack,
    onReset = _ref20.onReset,
    fromDeal = _ref20.fromDeal;
  var products = data.products || [];
  var offertes = data.offertes || {};
  var store = useArticles();
  var usedIds = React.useMemo(function () {
    return _toConsumableArray(new Set(products.flatMap(function (pid) {
      return (offertes[pid] || {}).artIds || [];
    })));
  }, [products, offertes]);
  var usedKey = usedIds.join(',');
  var _React$useState49 = React.useState([]),
    _React$useState50 = _slicedToArray(_React$useState49, 2),
    sheets = _React$useState50[0],
    setSheets = _React$useState50[1];
  React.useEffect(function () {
    var alle = calcSheetsForArticles(store.articles, usedIds).map(function (s) {
      return s.id;
    });
    setSheets(function (prev) {
      return prev.filter(function (id) {
        return alle.includes(id);
      }).length ? prev : alle;
    });
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [usedKey]);
  /* De keuze hoort bij de offertes zelf: wat hier uitgevinkt of extra gekozen wordt, gaat mee in hun PDF. */
  React.useEffect(function () {
    var cid = data.contactId,
      refs = Object.values(data.deals || {});
    if (!cid || !refs.length || !window.crmStore.setDealDatasheets || !window.ghsDsAuto) return;
    var c = (window.crmStore.getState().contacts || []).find(function (x) {
      return x.id === cid;
    });
    if (!c) return;
    var deals = refs.map(function (r) {
      return (c.deals || []).find(function (d) {
        return d.ref === r;
      });
    }).filter(Boolean);
    var alleAuto = new Set(deals.flatMap(function (d) {
      return window.ghsDsAuto(d.items).map(function (s) {
        return s.id;
      });
    }));
    deals.forEach(function (d) {
      var auto = window.ghsDsAuto(d.items).map(function (s) {
        return s.id;
      });
      window.crmStore.setDealDatasheets(cid, d.ref, {
        uit: auto.filter(function (id) {
          return !sheets.includes(id);
        }),
        extra: sheets.filter(function (id) {
          return !alleAuto.has(id);
        })
      }, {
        stil: true
      });
    });
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [sheets.join(','), Object.values(data.deals || {}).join(',')]);
  var gekozenSheets = React.useMemo(function () {
    return calcSheetsForArticles(store.articles, usedIds).concat(store.articles.filter(function (a) {
      return !usedIds.includes(a.id);
    }).flatMap(function (a) {
      return (a.sheets || []).map(function (s) {
        return _objectSpread(_objectSpread({}, s), {}, {
          artCode: a.code,
          artName: a.name
        });
      });
    })).filter(function (s) {
      return sheets.includes(s.id);
    });
  }, [store.articles, usedKey, sheets]);
  var validPids = products.filter(function (pid) {
    return offertes[pid] && ((offertes[pid].total || 0) > 0 || (offertes[pid].totalInclVAT || 0) > 0);
  });
  var _React$useState51 = React.useState(validPids[0] || products[0]),
    _React$useState52 = _slicedToArray(_React$useState51, 2),
    active = _React$useState52[0],
    setActive = _React$useState52[1];
  var _React$useState53 = React.useState({}),
    _React$useState54 = _slicedToArray(_React$useState53, 2),
    decisions = _React$useState54[0],
    setDecisions = _React$useState54[1];
  var _React$useState55 = React.useState({}),
    _React$useState56 = _slicedToArray(_React$useState55, 2),
    feedbacks = _React$useState56[0],
    setFeedbacks = _React$useState56[1];
  React.useEffect(function () {
    if (!products.includes(active)) setActive(validPids[0] || products[0]);
  }, [products, active, validPids]);
  var _setDecision = function setDecision(pid, v) {
    return setDecisions(function (prev) {
      return _objectSpread(_objectSpread({}, prev), {}, _defineProperty({}, pid, v));
    });
  };
  var _setFeedback = function setFeedback(pid, v) {
    return setFeedbacks(function (prev) {
      return _objectSpread(_objectSpread({}, prev), {}, _defineProperty({}, pid, v));
    });
  };
  var offNrFor = function offNrFor(pid, idx) {
    var _data$klant;
    return 'OFR-2026-' + String(4800 + (((_data$klant = data.klant) === null || _data$klant === void 0 ? void 0 : _data$klant.length) || 0) + idx).padStart(4, '0');
  };
  var totalAll = products.reduce(function (s, pid) {
    var _offertes$pid3, _offertes$pid4;
    return s + (((_offertes$pid3 = offertes[pid]) === null || _offertes$pid3 === void 0 ? void 0 : _offertes$pid3.total) || ((_offertes$pid4 = offertes[pid]) === null || _offertes$pid4 === void 0 ? void 0 : _offertes$pid4.totalInclVAT) || 0);
  }, 0);
  var activeProduct = productById(active);
  var activeIdx = products.indexOf(active);
  return /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      height: '100%',
      minHeight: 600
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      width: 340,
      background: T.bg0,
      borderRight: "1px solid ".concat(T.stroke1),
      padding: '18px 18px 24px',
      overflowY: 'auto',
      flexShrink: 0
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      fontSize: 10,
      fontFamily: T.fontBody,
      fontWeight: 700,
      letterSpacing: '0.18em',
      textTransform: 'uppercase',
      color: T.fg4,
      marginBottom: 4
    }
  }, "STAP 3 \u2014 KLANTPORTAAL"), /*#__PURE__*/React.createElement("h2", {
    style: {
      margin: 0,
      fontFamily: T.fontDisplay,
      fontSize: 18,
      fontWeight: 600,
      color: T.fg1,
      marginBottom: 14
    }
  }, "Live preview"), /*#__PURE__*/React.createElement("div", {
    style: {
      background: T.bg1,
      clipPath: cutPath(10),
      padding: '12px 14px',
      marginBottom: 14,
      border: "1px solid ".concat(T.stroke1)
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      fontSize: 9,
      fontFamily: T.fontBody,
      fontWeight: 700,
      letterSpacing: '0.14em',
      textTransform: 'uppercase',
      color: T.fg4
    }
  }, "TOTAAL (", products.length, " offertes)"), /*#__PURE__*/React.createElement("div", {
    style: {
      fontFamily: T.fontDisplay,
      fontSize: 22,
      fontWeight: 600,
      color: T.accent,
      fontVariantNumeric: 'tabular-nums',
      marginTop: 4
    }
  }, fmtEur(totalAll))), /*#__PURE__*/React.createElement("div", {
    style: {
      fontSize: 9,
      fontFamily: T.fontBody,
      fontWeight: 700,
      letterSpacing: '0.14em',
      textTransform: 'uppercase',
      color: T.fg4,
      marginBottom: 8
    }
  }, "OFFERTES"), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      flexDirection: 'column',
      gap: 6,
      marginBottom: 14
    }
  }, products.map(function (pid, idx) {
    var p = productById(pid);
    var off = offertes[pid] || {};
    var tot = off.total || off.totalInclVAT || 0;
    var dec = decisions[pid];
    var isActive = active === pid;
    return /*#__PURE__*/React.createElement("button", {
      key: pid,
      onClick: function onClick() {
        return setActive(pid);
      },
      style: {
        background: isActive ? "".concat(p.color, "15") : T.bg1,
        border: "1px solid ".concat(isActive ? p.color : T.stroke1),
        clipPath: cutPath(10),
        padding: '10px 12px',
        cursor: 'pointer',
        textAlign: 'left',
        display: 'flex',
        flexDirection: 'column',
        gap: 4
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        alignItems: 'center',
        gap: 7
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        width: 18,
        height: 18,
        borderRadius: '50%',
        background: "".concat(p.color, "25"),
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'center',
        flexShrink: 0
      }
    }, /*#__PURE__*/React.createElement(ProductIcon, {
      id: p.icon,
      size: 10,
      color: p.color
    })), /*#__PURE__*/React.createElement("span", {
      style: {
        fontFamily: T.fontBody,
        fontSize: 12,
        fontWeight: 700,
        color: T.fg1,
        flex: 1,
        minWidth: 0,
        overflow: 'hidden',
        textOverflow: 'ellipsis',
        whiteSpace: 'nowrap'
      }
    }, p.name), dec && /*#__PURE__*/React.createElement(Badge, {
      type: DECISION_META[dec].type,
      dot: true
    }, DECISION_META[dec].label)), /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        justifyContent: 'space-between',
        alignItems: 'center',
        paddingLeft: 25
      }
    }, /*#__PURE__*/React.createElement("span", {
      style: {
        fontSize: 10,
        color: T.fg4,
        fontFamily: T.fontBody,
        fontFeatureSettings: '"tnum"'
      }
    }, offNrFor(pid, idx)), /*#__PURE__*/React.createElement("span", {
      style: {
        fontFamily: T.fontDisplay,
        fontSize: 13,
        fontWeight: 600,
        color: tot > 0 ? T.fg1 : T.fg4,
        fontVariantNumeric: 'tabular-nums'
      }
    }, tot > 0 ? fmtEur(tot) : '—')));
  })), /*#__PURE__*/React.createElement("div", {
    style: {
      marginBottom: 14
    }
  }, /*#__PURE__*/React.createElement(DatasheetPicker, {
    articles: store.articles,
    usedIds: usedIds,
    selected: sheets,
    onChange: setSheets
  })), /*#__PURE__*/React.createElement("div", {
    style: {
      borderTop: "1px solid ".concat(T.stroke1),
      paddingTop: 14
    }
  }, /*#__PURE__*/React.createElement(CalcDealSync, {
    data: data,
    setData: setData,
    products: products,
    offertes: offertes,
    offNrFor: offNrFor
  }), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      flexDirection: 'column',
      gap: 8
    }
  }, /*#__PURE__*/React.createElement(Button, {
    variant: "primary",
    fullWidth: true,
    icon: "send"
  }, "Alle offertes versturen"), /*#__PURE__*/React.createElement(Button, {
    variant: "secondary",
    fullWidth: true,
    icon: "copy"
  }, "Portal-link kopi\xEBren"), /*#__PURE__*/React.createElement(Button, {
    variant: "ghost",
    fullWidth: true,
    icon: "download"
  }, "Download PDF bundel", gekozenSheets.length ? " + ".concat(gekozenSheets.length, " datasheet").concat(gekozenSheets.length > 1 ? 's' : '') : '')), /*#__PURE__*/React.createElement("div", {
    style: {
      marginTop: 12,
      display: 'flex',
      gap: 6
    }
  }, /*#__PURE__*/React.createElement(Button, {
    variant: "ghost",
    size: "sm",
    onClick: onBack,
    fullWidth: true
  }, "\u2190 Aanpassen"), /*#__PURE__*/React.createElement(Button, {
    variant: "ghost",
    size: "sm",
    onClick: onReset,
    fullWidth: true
  }, "Nieuwe offerte")))), /*#__PURE__*/React.createElement("div", {
    style: {
      flex: 1,
      background: T.bg1,
      overflowY: 'auto'
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      background: T.bg0,
      borderBottom: "1px solid ".concat(T.stroke1),
      padding: '12px 24px',
      display: 'flex',
      alignItems: 'center',
      justifyContent: 'space-between'
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      alignItems: 'center',
      gap: 10
    }
  }, /*#__PURE__*/React.createElement("img", {
    src: window.__resources.logoNeg,
    alt: "GHS",
    style: {
      height: 22
    }
  }), /*#__PURE__*/React.createElement("span", {
    style: {
      fontSize: 10,
      fontFamily: T.fontBody,
      fontWeight: 700,
      letterSpacing: '0.16em',
      textTransform: 'uppercase',
      color: T.fg3
    }
  }, "KLANTPORTAAL \xB7 ", (_data$klant2 = data.klant) === null || _data$klant2 === void 0 ? void 0 : _data$klant2.toUpperCase())), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      alignItems: 'center',
      gap: 8,
      padding: '4px 10px',
      background: 'rgba(0,217,0,0.08)',
      border: '1px solid rgba(0,217,0,0.2)',
      borderRadius: 4
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      width: 6,
      height: 6,
      borderRadius: '50%',
      background: T.accent,
      boxShadow: "0 0 6px ".concat(T.accent)
    }
  }), /*#__PURE__*/React.createElement("span", {
    style: {
      fontSize: 10,
      color: T.accent,
      fontFamily: T.fontBody,
      fontWeight: 700,
      letterSpacing: '0.1em'
    }
  }, "LIVE"))), /*#__PURE__*/React.createElement("div", {
    style: {
      maxWidth: 820,
      margin: '0 auto',
      padding: 24
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      marginBottom: 18
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      fontSize: 10,
      fontFamily: T.fontBody,
      fontWeight: 700,
      letterSpacing: '0.16em',
      textTransform: 'uppercase',
      color: T.fg3,
      marginBottom: 4
    }
  }, products.length === 1 ? 'NIEUWE OFFERTE BESCHIKBAAR' : "".concat(products.length, " NIEUWE OFFERTES BESCHIKBAAR")), /*#__PURE__*/React.createElement("h1", {
    style: {
      margin: 0,
      fontFamily: T.fontDisplay,
      fontSize: 26,
      fontWeight: 600,
      color: T.fg1,
      letterSpacing: '-0.02em'
    }
  }, "Uw voorstel", products.length > 1 ? 'len' : '', " van Green House Solutions"), /*#__PURE__*/React.createElement("p", {
    style: {
      margin: '8px 0 0',
      fontSize: 13,
      color: T.fg2,
      fontFamily: T.fontBody
    }
  }, window.DL_GELDIG_DAGEN && window.DL_GELDIG_DAGEN() > 0 ? "Geldig ".concat(window.DL_GELDIG_DAGEN(), " dagen \xB7 ") : '', "uw verkoper: Ive Bogaerts \xB7 totaal: ", /*#__PURE__*/React.createElement("strong", {
    style: {
      color: T.fg1,
      fontVariantNumeric: 'tabular-nums'
    }
  }, fmtEur(totalAll)))), products.length > 1 && /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      gap: 0,
      borderBottom: "1px solid ".concat(T.stroke1),
      marginBottom: 18,
      overflowX: 'auto'
    }
  }, products.map(function (pid, idx) {
    var _offertes$pid5, _offertes$pid6;
    var p = productById(pid);
    var dec = decisions[pid];
    var tot = ((_offertes$pid5 = offertes[pid]) === null || _offertes$pid5 === void 0 ? void 0 : _offertes$pid5.total) || ((_offertes$pid6 = offertes[pid]) === null || _offertes$pid6 === void 0 ? void 0 : _offertes$pid6.totalInclVAT) || 0;
    var isActive = active === pid;
    return /*#__PURE__*/React.createElement("button", {
      key: pid,
      onClick: function onClick() {
        return setActive(pid);
      },
      style: {
        background: isActive ? T.bg2 : 'transparent',
        border: 'none',
        borderBottom: "2px solid ".concat(isActive ? p.color : 'transparent'),
        padding: '10px 14px',
        cursor: 'pointer',
        display: 'flex',
        alignItems: 'center',
        gap: 8,
        fontFamily: T.fontBody,
        fontSize: 12,
        fontWeight: isActive ? 700 : 500,
        color: isActive ? T.fg1 : T.fg3,
        whiteSpace: 'nowrap',
        flexShrink: 0,
        marginBottom: -1
      }
    }, /*#__PURE__*/React.createElement(ProductIcon, {
      id: p.icon,
      size: 13,
      color: isActive ? p.color : T.fg3
    }), /*#__PURE__*/React.createElement("span", null, p.name), /*#__PURE__*/React.createElement("span", {
      style: {
        fontFamily: T.fontDisplay,
        fontSize: 11,
        color: T.fg4,
        fontVariantNumeric: 'tabular-nums'
      }
    }, fmtEur(tot)), dec && /*#__PURE__*/React.createElement("div", {
      style: {
        width: 7,
        height: 7,
        borderRadius: '50%',
        background: DECISION_META[dec].color
      }
    }));
  })), activeProduct && /*#__PURE__*/React.createElement(OfferPortalView, {
    key: active,
    offerte: offertes[active],
    product: activeProduct,
    klant: data.klant,
    klantAdres: data.adres,
    offNr: offNrFor(active, activeIdx),
    decision: decisions[active],
    setDecision: function setDecision(v) {
      return _setDecision(active, v);
    },
    feedback: feedbacks[active] || '',
    setFeedback: function setFeedback(v) {
      return _setFeedback(active, v);
    },
    bijlagen: gekozenSheets
  }), products.length > 1 && Object.keys(decisions).length === products.length && /*#__PURE__*/React.createElement("div", {
    style: {
      marginTop: 24,
      background: T.bg0,
      border: "1px solid ".concat(T.stroke1),
      clipPath: cutPath(10),
      padding: '16px 18px'
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      fontSize: 11,
      fontFamily: T.fontBody,
      fontWeight: 700,
      letterSpacing: '0.14em',
      textTransform: 'uppercase',
      color: T.fg3,
      marginBottom: 10
    }
  }, "SAMENVATTING UW BESLISSINGEN"), products.map(function (pid) {
    var p = productById(pid);
    var d = decisions[pid];
    var m = DECISION_META[d];
    return /*#__PURE__*/React.createElement("div", {
      key: pid,
      style: {
        display: 'flex',
        justifyContent: 'space-between',
        alignItems: 'center',
        padding: '8px 0',
        borderBottom: "1px solid ".concat(T.stroke1)
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        alignItems: 'center',
        gap: 8
      }
    }, /*#__PURE__*/React.createElement(ProductIcon, {
      id: p.icon,
      size: 13,
      color: p.color
    }), /*#__PURE__*/React.createElement("span", {
      style: {
        fontSize: 12,
        color: T.fg1,
        fontFamily: T.fontBody,
        fontWeight: 600
      }
    }, p.name)), /*#__PURE__*/React.createElement(Badge, {
      type: m.type,
      dot: true
    }, m.label));
  })))));
};

/* ─────────────────────────────────────────────────────── MAIN PAGE */
var CalculatorPage = function CalculatorPage(_ref21) {
  var _ref21$isAdmin = _ref21.isAdmin,
    isAdmin = _ref21$isAdmin === void 0 ? false : _ref21$isAdmin;
  // Read query params (deal / klant / product prefill)
  // Read prefill — sessionStorage (from in-app deal navigation) takes priority over URL query
  var stored = function () {
    try {
      var raw = sessionStorage.getItem('ghs_calc_prefill') || localStorage.getItem('ghs_calc_prefill');
      if (raw) {
        sessionStorage.removeItem('ghs_calc_prefill');
        localStorage.removeItem('ghs_calc_prefill');
        return JSON.parse(raw);
      }
    } catch (e) {}
    return null;
  }();
  var params = new URLSearchParams(window.location.search);
  var dealId = (stored === null || stored === void 0 ? void 0 : stored.dealId) || params.get('deal');
  var klantQs = (stored === null || stored === void 0 ? void 0 : stored.klant) || params.get('klant') || '';
  var adresQs = (stored === null || stored === void 0 ? void 0 : stored.adres) || params.get('adres') || '';
  var productQs = (stored === null || stored === void 0 ? void 0 : stored.products) || params.get('product');

  // Parse product= as comma-separated list (e.g. 'zp_batt,laadpaal')
  var productList = (productQs || '').split(',').map(function (s) {
    return s.trim();
  }).filter(function (s) {
    return productBestaat(s);
  });
  var initial = {
    products: productList,
    contactId: (stored === null || stored === void 0 ? void 0 : stored.contactId) || params.get('contact') || null,
    klant: klantQs,
    adres: adresQs,
    company: (stored === null || stored === void 0 ? void 0 : stored.company) || '',
    tel: (stored === null || stored === void 0 ? void 0 : stored.tel) || '',
    email: (stored === null || stored === void 0 ? void 0 : stored.email) || '',
    verkoper: (stored === null || stored === void 0 ? void 0 : stored.verkoper) || '',
    herkomst: (stored === null || stored === void 0 ? void 0 : stored.herkomst) || '',
    notes: '',
    offertes: {}
  };
  var _React$useState57 = React.useState(initial),
    _React$useState58 = _slicedToArray(_React$useState57, 2),
    data = _React$useState58[0],
    setData = _React$useState58[1];
  var _React$useState59 = React.useState(1),
    _React$useState60 = _slicedToArray(_React$useState59, 2),
    step = _React$useState60[0],
    setStep = _React$useState60[1];

  // Contactgegevens compleet maken uit de CRM-data zodra we een contactId kennen.
  React.useEffect(function () {
    if (!data.contactId) return;
    var alle = (window.crmStore ? window.crmStore.getState().contacts : null) || window.CONTACTS || [];
    var c = alle.find(function (x) {
      return x.id === data.contactId;
    });
    if (!c) return;
    if (!data.tel) {
      setData(function (d) {
        return _objectSpread(_objectSpread({}, d), calcContactToData(c));
      });
      return;
    }
    /* Vooraf ingevuld vanuit de fiche: enkel wat de btw nodig heeft (de woning, onderneming of niet). */
    if (data.woning === undefined || data.b2b === undefined) {
      var x = calcContactToData(c);
      setData(function (d) {
        return _objectSpread(_objectSpread({}, d), {}, {
          woning: d.woning || x.woning,
          b2b: d.b2b != null ? d.b2b : x.b2b
        });
      });
    }
  }, [data.contactId, data.tel]);
  var canGoTo = function canGoTo(s) {
    if (s === 1) return true;
    if (s === 2) return (data.products || []).length > 0 && !!data.klant;
    if (s === 3) {
      var offs = data.offertes || {};
      return (data.products || []).some(function (pid) {
        return offs[pid] && ((offs[pid].total || 0) > 0 || (offs[pid].totalInclVAT || 0) > 0);
      });
    }
    return false;
  };
  var reset = function reset() {
    setData(initial);
    setStep(1);
  };

  // Tool tab: standaard wizard vs. ULTRA calculator (fully separate tools)
  var _React$useState61 = React.useState(function () {
      try {
        return sessionStorage.getItem('ghs_calc_tool') || 'wizard';
      } catch (e) {
        return 'wizard';
      }
    }),
    _React$useState62 = _slicedToArray(_React$useState61, 2),
    tool = _React$useState62[0],
    setTool = _React$useState62[1];
  React.useEffect(function () {
    try {
      sessionStorage.setItem('ghs_calc_tool', tool);
    } catch (e) {}
  }, [tool]);
  return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Topbar, {
    title: "Calculator",
    user: {
      name: 'Nick De Roeck'
    }
  }), /*#__PURE__*/React.createElement(CalcToolTabs, {
    tool: tool,
    setTool: setTool
  }), tool === 'wizard' && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(StepHeader, {
    step: step,
    setStep: setStep,
    canGoTo: canGoTo
  }), step === 1 && /*#__PURE__*/React.createElement(Step1Informatie, {
    data: data,
    setData: setData,
    onNext: function onNext() {
      return setStep(2);
    },
    fromDeal: dealId
  }), step === 2 && /*#__PURE__*/React.createElement(Step2Calculator, {
    data: data,
    setData: setData,
    onBack: function onBack() {
      return setStep(1);
    },
    onNext: function onNext() {
      return setStep(3);
    }
  }), step === 3 && /*#__PURE__*/React.createElement(Step3Portal, {
    data: data,
    setData: setData,
    onBack: function onBack() {
      return setStep(2);
    },
    onReset: reset,
    fromDeal: dealId
  })), tool === 'ultra' && /*#__PURE__*/React.createElement(UltraCalculator, {
    isAdmin: isAdmin
  }));
};

/* Tool switcher — sits between the topbar and the active tool */
var CalcToolTabs = function CalcToolTabs(_ref22) {
  var tool = _ref22.tool,
    setTool = _ref22.setTool;
  var tabs = [{
    id: 'wizard',
    label: 'Calculator',
    icon: 'calculator',
    sub: 'Offerte-wizard per product'
  }, {
    id: 'ultra',
    label: 'ULTRA calculator',
    icon: 'bolt',
    sub: '3 pakketten in één keer'
  }];
  return /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      gap: 0,
      background: T.bg0,
      borderBottom: "1px solid ".concat(T.stroke1),
      padding: '0 24px',
      alignItems: 'center'
    }
  }, tabs.map(function (t) {
    var on = tool === t.id;
    var isUltra = t.id === 'ultra';
    return /*#__PURE__*/React.createElement("button", {
      key: t.id,
      onClick: function onClick() {
        return setTool(t.id);
      },
      style: {
        background: 'transparent',
        border: 'none',
        cursor: 'pointer',
        display: 'flex',
        alignItems: 'center',
        gap: 10,
        padding: '12px 18px',
        borderBottom: "2px solid ".concat(on ? T.accent : 'transparent'),
        marginBottom: -1,
        transition: 'all 160ms'
      }
    }, /*#__PURE__*/React.createElement("span", {
      style: {
        display: 'flex',
        flexShrink: 0,
        filter: on && isUltra ? 'drop-shadow(0 0 7px rgba(0,217,0,0.35))' : 'none'
      }
    }, /*#__PURE__*/React.createElement("span", {
      style: {
        width: 30,
        height: 30,
        clipPath: cutPath(6),
        boxSizing: 'border-box',
        background: on ? 'rgba(0,217,0,0.14)' : T.bg2,
        border: "1px solid ".concat(on ? T.strokeAccent : T.stroke1),
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'center'
      }
    }, /*#__PURE__*/React.createElement(Icon, {
      name: t.icon,
      size: 15,
      color: on ? T.accent : T.fg3
    }))), /*#__PURE__*/React.createElement("div", {
      style: {
        textAlign: 'left'
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        alignItems: 'center',
        gap: 7
      }
    }, /*#__PURE__*/React.createElement("span", {
      style: {
        fontFamily: T.fontDisplay,
        fontSize: 14,
        fontWeight: 600,
        color: on ? T.fg1 : T.fg2,
        letterSpacing: '-0.01em'
      }
    }, t.label), isUltra && /*#__PURE__*/React.createElement("span", {
      style: {
        fontFamily: T.fontBody,
        fontSize: 8.5,
        fontWeight: 700,
        letterSpacing: '0.1em',
        color: T.bg0,
        background: T.accent,
        borderRadius: 4,
        padding: '2px 5px'
      }
    }, "NIEUW")), /*#__PURE__*/React.createElement("div", {
      style: {
        fontFamily: T.fontBody,
        fontSize: 10.5,
        color: on ? T.fg3 : T.fg4
      }
    }, t.sub)));
  }), /*#__PURE__*/React.createElement("div", {
    style: {
      marginLeft: 'auto'
    }
  }, /*#__PURE__*/React.createElement(KlantmodusToggle, null)));
};
Object.assign(window, {
  CalculatorPage: CalculatorPage
});