"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 _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function _toArray(r) { return _arrayWithHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableRest(); }
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 _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
// GHS CRM — Planning-module (zelfde opbouw als Opmetingen: Dashboard | Kanban | Lijsten | Agenda)
// Eén werk-item per gewonnen deal. Alles leest/schrijft via window.crmStore — synchroon met de contactfiche.

var PLAN_COL = {
  te_plannen: _objectSpread({
    id: 'te_plannen',
    label: 'TE PLANNEN'
  }, gs('nieuw', {
    icon: 'calendar'
  })),
  ingepland: _objectSpread({
    id: 'ingepland',
    label: 'INGEPLAND'
  }, gs('klaar', {
    icon: 'clock'
  })),
  uitgevoerd: _objectSpread({
    id: 'uitgevoerd',
    label: 'UITGEVOERD'
  }, gs('afgerond', {
    icon: 'check'
  }))
};
var PLAN_LBL = {
  te_plannen: 'Te plannen',
  ingepland: 'Ingepland',
  uitgevoerd: 'Uitgevoerd'
};
var PL_SEC_HINT = {
  te_plannen: 'Gewonnen deals wachten op een datum',
  ingepland: 'Ploeg en datum vastgelegd',
  uitgevoerd: 'Uitgevoerd — werkbon volgt'
};
var plToday = function plToday() {
  return window.GHS_TODAY;
};
var plCrewName = function plCrewName(id) {
  return ((window.ghsCrewLid ? window.ghsCrewLid(id) : null) || {}).name || id;
};
var plCrewNames = function plCrewNames(ids) {
  return (ids || []).map(plCrewName).filter(Boolean);
};
// Vaste kleur per ploeglid — herkenbaar in alle planningsagenda's
var PL_CREW_COLORS = {
  w1: '#00D900',
  w2: '#00aaff',
  w3: '#bf63ff',
  w4: '#ffb020',
  w5: '#ff5a4d',
  w6: '#e8c547'
};
window.PL_CREW_COLORS = PL_CREW_COLORS;
/* De kleur per technieker is instelbaar (ploeg-bezet.jsx) — overal dezelfde bron. */
var plCrewColor = function plCrewColor(id) {
  if (window.ghsCrewKleur) return window.ghsCrewKleur(id);
  var w = window.ghsCrewLid ? window.ghsCrewLid(id) : null;
  return PL_CREW_COLORS[w && w.legacy || id] || PL_CREW_COLORS[id] || '#6b8a8a';
};
// Soort werk — kleurcode van elke inplanning (centraal in crm-data).
var plWork = function plWork(id) {
  return window.planWork ? window.planWork(id) : {
    id: 'pv_hellend',
    label: 'PV hellend / Elektrisch',
    "short": 'PV hellend',
    color: '#ffb020'
  };
};
var plWorkList = function plWorkList() {
  return window.PLANNING_WORK || [];
};

/* ── Nabijheid op basis van Belgische postcodes ───────────────────────
   Benaderende coördinaten per postcode-zone (eerste twee cijfers). Daarmee
   clusteren we 'te plannen' werven die dicht bij elkaar liggen tot ritten
   van max 3 klanten — zo rijden de installateurs zo weinig mogelijk. */
var PL_PC_COORDS = {
  10: [50.85, 4.35],
  11: [50.85, 4.38],
  12: [50.83, 4.32],
  13: [50.70, 4.61],
  14: [50.60, 4.33],
  15: [50.73, 4.24],
  16: [50.78, 4.25],
  17: [50.86, 4.26],
  18: [50.93, 4.43],
  19: [50.88, 4.47],
  20: [51.22, 4.40],
  21: [51.21, 4.44],
  22: [51.18, 4.83],
  23: [51.32, 4.95],
  24: [51.16, 4.99],
  25: [51.13, 4.57],
  26: [51.10, 4.52],
  28: [51.03, 4.48],
  29: [51.25, 4.50],
  30: [50.88, 4.70],
  31: [50.90, 4.71],
  32: [50.98, 4.84],
  33: [50.81, 4.94],
  34: [50.75, 5.08],
  35: [50.93, 5.34],
  36: [50.99, 5.50],
  37: [50.78, 5.46],
  38: [50.82, 5.19],
  39: [51.22, 5.42],
  40: [50.63, 5.57],
  41: [50.68, 5.51],
  42: [50.60, 5.55],
  43: [50.66, 5.45],
  44: [50.62, 5.58],
  45: [50.53, 5.24],
  46: [50.61, 5.77],
  47: [50.63, 6.03],
  48: [50.59, 5.86],
  49: [50.49, 5.10],
  50: [50.47, 4.87],
  51: [50.46, 4.85],
  53: [50.42, 4.65],
  55: [50.26, 4.95],
  56: [50.30, 4.75],
  60: [50.41, 4.44],
  61: [50.34, 4.38],
  62: [50.42, 4.45],
  63: [50.34, 4.29],
  64: [50.21, 4.35],
  65: [50.24, 4.24],
  66: [50.00, 5.72],
  67: [49.68, 5.81],
  68: [49.85, 5.40],
  69: [50.22, 5.34],
  70: [50.45, 3.95],
  71: [50.48, 4.19],
  72: [50.44, 4.05],
  73: [50.42, 3.85],
  75: [50.61, 3.39],
  76: [50.52, 3.46],
  77: [50.74, 3.21],
  78: [50.71, 3.30],
  79: [50.63, 3.78],
  80: [51.21, 3.22],
  82: [51.19, 3.18],
  83: [51.34, 3.28],
  84: [51.23, 2.92],
  85: [50.83, 3.27],
  86: [51.03, 2.86],
  87: [50.95, 3.38],
  88: [50.95, 3.12],
  89: [50.85, 2.88],
  90: [51.05, 3.72],
  91: [51.17, 4.14],
  92: [51.03, 4.10],
  93: [50.94, 4.04],
  94: [50.83, 4.02],
  95: [50.77, 3.88],
  96: [50.75, 3.60],
  97: [50.84, 3.61],
  98: [50.98, 3.53],
  99: [51.19, 3.56]
};
var PL_CITY_COORDS = {
  gent: [51.05, 3.72],
  antwerpen: [51.22, 4.40],
  leuven: [50.88, 4.70],
  brugge: [51.21, 3.22],
  hasselt: [50.93, 5.34],
  mechelen: [51.03, 4.48],
  brussel: [50.85, 4.35],
  turnhout: [51.32, 4.95],
  aalst: [50.94, 4.04],
  oostende: [51.23, 2.92],
  'sint-niklaas': [51.17, 4.14],
  roeselare: [50.95, 3.12],
  kortrijk: [50.83, 3.27],
  deinze: [50.98, 3.53],
  waregem: [50.89, 3.42],
  oudenaarde: [50.84, 3.61]
};
window.plCoord = function (item) {
  return plCoord(item);
};
var plCoord = function plCoord(item) {
  /* Eerst het midden van de postcode of deelgemeente (src/lib/geo-be.js, GeoNames); de zones hieronder zijn de terugval. */
  var G = window.GHS_GEO_BE,
    k = String(item.postcode || '').trim();
  if (G && G.postcode[k]) {
    var n = window.rdNorm ? window.rdNorm(item.city) : '';
    return n && G.plaats[k + '|' + n] || G.postcode[k];
  }
  var pc = parseInt(String(item.postcode || '').trim(), 10);
  if (pc >= 1000 && pc <= 9999) {
    var c = PL_PC_COORDS[Math.floor(pc / 100)];
    if (c) return c;
  }
  return PL_CITY_COORDS[(item.city || '').trim().toLowerCase()] || null;
};
var plKm = function plKm(a, b) {
  var r = Math.PI / 180,
    dLat = (b[0] - a[0]) * r,
    dLng = (b[1] - a[1]) * r;
  var s = Math.pow(Math.sin(dLat / 2), 2) + Math.cos(a[0] * r) * Math.cos(b[0] * r) * Math.pow(Math.sin(dLng / 2), 2);
  return 6371 * 2 * Math.atan2(Math.sqrt(s), Math.sqrt(1 - s));
};
var PL_GROUP_COLORS = ['#00D900', '#00aaff', '#bf63ff', '#ffb020', '#ff5a4d', '#e8c547'];
/* Greedy clustering: per werf de 2 dichtstbijzijnde open werven binnen 20 km → ritten van 2-3 klanten. */
var plSuggestGroups = function plSuggestGroups(items) {
  var pts = items.map(function (i) {
    return {
      i: i,
      ll: plCoord(i)
    };
  }).filter(function (x) {
    return x.ll;
  }).sort(function (a, b) {
    return a.ll[1] - b.ll[1];
  });
  var used = new Set();
  var groups = [];
  var _iterator = _createForOfIteratorHelper(pts),
    _step;
  try {
    var _loop = function _loop() {
        var p = _step.value;
        if (used.has(p.i.id)) return 0; // continue
        var near = pts.filter(function (q) {
          return q.i.id !== p.i.id && !used.has(q.i.id) && plKm(p.ll, q.ll) <= 20;
        }).sort(function (a, b) {
          return plKm(p.ll, a.ll) - plKm(p.ll, b.ll);
        }).slice(0, 2);
        if (!near.length) return 0; // continue
        var members = [p].concat(_toConsumableArray(near));
        members.forEach(function (m) {
          return used.add(m.i.id);
        });
        var maxKm = Math.round(Math.max.apply(Math, [1].concat(_toConsumableArray(members.flatMap(function (a) {
          return members.map(function (b) {
            return plKm(a.ll, b.ll);
          });
        })))));
        var cityCount = {};
        members.forEach(function (m) {
          var c = m.i.city || '?';
          cityCount[c] = (cityCount[c] || 0) + 1;
        });
        var region = Object.keys(cityCount).sort(function (a, b) {
          return cityCount[b] - cityCount[a];
        })[0];
        var gi = groups.length;
        groups.push({
          id: 'rit' + gi,
          label: 'Rit ' + String.fromCharCode(65 + gi),
          color: PL_GROUP_COLORS[gi % PL_GROUP_COLORS.length],
          region: region,
          maxKm: maxKm,
          items: members.map(function (m) {
            return m.i;
          })
        });
      },
      _ret;
    for (_iterator.s(); !(_step = _iterator.n()).done;) {
      _ret = _loop();
      if (_ret === 0) continue;
    }
  } catch (err) {
    _iterator.e(err);
  } finally {
    _iterator.f();
  }
  return groups;
};
var plDaySlots = function plDaySlots(n) {
  return n >= 3 ? [['08:00', '10:30'], ['11:00', '13:30'], ['14:00', '16:30']] : [['08:00', '11:30'], ['12:30', '16:00']];
};
var PL_ROLES = [['Dakwerker', 'Installateurs'], ['Elektricien', 'Elektriciens'], ['Service', 'Techniekers / service']];
// Werk-omschrijving = opsomming van de artikeltypes uit de offerte (niet de vrije dealnaam).
var plWerkOms = function plWerkOms(dealItems, fallback) {
  var idx = window.artIndex ? window.artIndex() : null;
  var labels = _toConsumableArray(new Set((dealItems || []).map(function (l) {
    if (!l.artId) return null;
    var a = idx ? idx.get(l.artId) : null;
    return a ? window.ptype ? window.ptype(a.type).label : a.type : null;
  }).filter(Boolean)));
  return labels.length ? labels.join(', ') : fallback || '';
};

/* Eén planningsitem per gewonnen deal — de deal moet zélf klaar zijn (eigen opmeting
   afgerond of CAT 1). De klantfase zegt niets: een andere offerte van dezelfde klant
   mag deze nooit vooruitschuiven. */
var mapPlanItems = function mapPlanItems(contacts) {
  var out = [];
  contacts.forEach(function (c) {
    (c.deals || []).filter(function (d) {
      return d.won && !d.service;
    }).forEach(function (d) {
      var slots = (c.planningSlots || []).filter(function (p) {
        return p.dealRef === d.ref;
      }).sort(function (a, b) {
        return (a.date + (a.start || '')).localeCompare(b.date + (b.start || ''));
      });
      var slot = slots[0] || null;
      var ws = (c.werkbonState || {})[d.ref] || {};
      if (!slot && !ws.installed && !(window.dealKlaarVoorPlanning ? window.dealKlaarVoorPlanning(c, d) : true)) return; // eigen opmeting nog niet klaar
      if (ws.planRemoved && !ws.installed && !slot) return; // handmatig uit de planning gehaald
      /* Eén werkbon per moment. Het dossier is pas uitgevoerd als élk moment dat is,
         en gaat pas naar facturatie als élke werkbon opgeleverd is. */
      var bonnen = window.ghsWbBonnen ? window.ghsWbBonnen(c, d.ref) : {};
      var voortgang = window.ghsWbVoortgang ? window.ghsWbVoortgang(c, d.ref) : {
        totaal: slots.length,
        klaar: 0,
        open: slots.length,
        compleet: false
      };
      var alleUit = slots.length > 0 && slots.every(function (s) {
        return (bonnen[s.id] || {}).installed;
      });
      var status = alleUit || ws.installed ? 'uitgevoerd' : slot ? 'ingepland' : 'te_plannen';
      /* De dagenteller volgt het OUDSTE onafgewerkte moment — zo ziet een dossier
         nooit fris uit terwijl er een moment ligt te wachten. */
      var openSlots = slots.filter(function (s) {
        return !(bonnen[s.id] || {}).werkbon;
      });
      var dagenSinds = openSlots.length ? openSlots[0].date : ws.installedAt ? String(ws.installedAt).slice(0, 10) : slot ? slot.date : null;
      out.push({
        bonnen: bonnen,
        voortgang: voortgang,
        dagenSinds: dagenSinds,
        los: !!d.los,
        fs: (c.facturatieState || {})[d.ref] || {},
        id: "".concat(c.id, ":").concat(d.ref),
        _cid: c.id,
        dealRef: d.ref,
        dealName: d.name,
        dealType: d.type,
        werkOms: d.los ? d.name || 'Los werk' : plWerkOms(d.items, d.name),
        kwp: d.kwp || 0,
        kwh: d.kwh || 0,
        client: "".concat(c.firstName, " ").concat(c.lastName),
        address: c.address,
        city: c.city,
        postcode: c.postalCode,
        verkoper: c.verkoper,
        slots: slots,
        slot: slot,
        slotId: slot ? slot.id : null,
        date: slot ? slot.date : null,
        start: slot ? slot.start : null,
        end: slot ? slot.end : null,
        crew: slots.length ? _toConsumableArray(new Set(slots.flatMap(function (s) {
          return s.crew || [];
        }))) : [],
        info: slot ? slot.info || '' : '',
        work: slot ? slot.work : null,
        installed: !!ws.installed,
        installedAt: ws.installedAt || null,
        werkbon: ws.werkbon || null,
        status: status,
        /* Het voorschot gaat vóór de planning: zolang het niet betaald is, geen nieuw moment. */
        vsWacht: window.dealVoorschotWacht ? window.dealVoorschotWacht(c, d) : null
      });
    });
  });
  return out;
};
var openPlanFiche = function openPlanFiche(item) {
  return window.crmStore.openFiche(item._cid, 'planning');
};
var plCrewIdsOf = function plCrewIdsOf(crew) {
  return (window.ghsCrewIds ? window.ghsCrewIds(crew) : crew || []).map(function (x) {
    return typeof x === 'string' ? x : x.id;
  });
};
/* Alle ingeplande momenten als agenda-items. Met `crewFilter` blijven enkel de
   werken over waar minstens één van die ploegleden op staat — zo zie je de
   bezetting van wie je wilt inplannen, niet het hele bedrijf. */
var plAllSlotItems = function plAllSlotItems(excludeSlotId, crewFilter) {
  return window.crmStore.getState().contacts.flatMap(function (c) {
    return (c.planningSlots || []).map(function (p) {
      return {
        p: p,
        c: c
      };
    });
  }).filter(function (_ref) {
    var p = _ref.p;
    return p.id !== excludeSlotId;
  }).map(function (_ref2) {
    var p = _ref2.p,
      c = _ref2.c;
    return {
      p: p,
      c: c,
      ids: plCrewIdsOf(p.crew)
    };
  }).filter(function (_ref3) {
    var ids = _ref3.ids;
    return !crewFilter || !crewFilter.length || ids.some(function (id) {
      return crewFilter.includes(id);
    });
  }).map(function (_ref4) {
    var p = _ref4.p,
      c = _ref4.c,
      ids = _ref4.ids;
    var toon = crewFilter && crewFilter.length ? ids.filter(function (id) {
      return crewFilter.includes(id);
    }) : ids;
    return {
      id: p.id,
      date: p.date,
      start: p.start || null,
      end: p.end || null,
      crewIds: ids,
      label: "".concat(c.firstName, " ").concat(c.lastName),
      sub: "".concat(plWork(p.work)["short"]).concat(toon.length ? ' · ' + plCrewNames(toon).map(function (n) {
        return n.split(' ')[0];
      }).join(', ') : '').concat(window.zpSlotStand && window.zpSlotStand(p).id !== 'klant' && window.zpSlotStand(p).id !== 'bevestigd' ? ' · ' + window.zpSlotStand(p).kort : ''),
      color: plWork(p.work).color,
      dashed: !!(window.zpSlotStand && ['gereserveerd', 'onbevestigd', 'gemeld'].includes(window.zpSlotStand(p).id))
    };
  });
};
/* Wie van de ploeg is al bezet in dit tijdvak? → { id: [klantnaam, …] } */
var plBezet = function plBezet(form, excludeSlotId) {
  var uit = {};
  if (!form || !form.date) return uit;
  var s = form.start || '00:00',
    e = form.end || '23:59';
  plAllSlotItems(excludeSlotId).forEach(function (it) {
    if (it.date !== form.date) return;
    if ((it.start || '00:00') < e && s < (it.end || '23:59')) it.crewIds.forEach(function (id) {
      (uit[id] = uit[id] || []).push(it.label);
    });
  });
  return uit;
};
/* ── Ploeg-selectie (installateurs / elektriciens / techniekers) ────────── */
var PlCrewPicker = function PlCrewPicker(_ref5) {
  var crew = _ref5.crew,
    onToggle = _ref5.onToggle,
    _ref5$bezet = _ref5.bezet,
    bezet = _ref5$bezet === void 0 ? {} : _ref5$bezet;
  return /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      flexDirection: 'column',
      gap: 7
    }
  }, PL_ROLES.map(function (_ref6) {
    var _ref7 = _slicedToArray(_ref6, 2),
      role = _ref7[0],
      label = _ref7[1];
    return /*#__PURE__*/React.createElement("div", {
      key: role,
      style: {
        display: 'flex',
        alignItems: 'center',
        gap: 7,
        flexWrap: 'wrap'
      }
    }, /*#__PURE__*/React.createElement("span", {
      style: {
        fontFamily: T.fontBody,
        fontSize: 10,
        fontWeight: 700,
        color: T.fg4,
        width: 130,
        letterSpacing: '0.06em',
        textTransform: 'uppercase'
      }
    }, label), (window.PLANNING_CREW || []).filter(function (w) {
      return w.role === role;
    }).map(function (w) {
      var on = crew.includes(w.id);
      var druk = bezet[w.id];
      var c = plCrewColor(w.id);
      return /*#__PURE__*/React.createElement("button", {
        key: w.id,
        onClick: function onClick() {
          return onToggle(w.id);
        },
        title: druk ? "Al ingepland in dit tijdvak: ".concat(druk.join(', ')) : 'Vrij in dit tijdvak',
        style: {
          display: 'inline-flex',
          alignItems: 'center',
          gap: 6,
          padding: '6px 11px',
          background: on ? "".concat(c, "14") : 'transparent',
          border: "1px solid ".concat(on ? c : T.stroke1),
          borderRadius: 4,
          cursor: 'pointer',
          color: on ? c : T.fg3,
          fontFamily: T.fontBody,
          fontSize: 11.5,
          fontWeight: 600,
          transition: 'all 120ms',
          opacity: druk && !on ? 0.55 : 1
        }
      }, /*#__PURE__*/React.createElement("span", {
        style: {
          width: 8,
          height: 8,
          borderRadius: 2,
          background: c,
          opacity: on ? 1 : 0.35
        }
      }), w.name, druk && /*#__PURE__*/React.createElement("span", {
        style: {
          fontSize: 9.5,
          fontWeight: 700,
          color: '#ffb020',
          letterSpacing: '0.06em'
        }
      }, "BEZET"));
    }));
  }));
};

/* ── Soort werk — bepaalt de kleurcode in de agenda ───────────────────── */
var PlWorkPicker = function PlWorkPicker(_ref8) {
  var value = _ref8.value,
    onPick = _ref8.onPick;
  return /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      gap: 6,
      flexWrap: 'wrap'
    }
  }, plWorkList().map(function (w) {
    var on = value === w.id;
    return /*#__PURE__*/React.createElement("button", {
      key: w.id,
      onClick: function onClick() {
        return onPick(w.id);
      },
      style: {
        display: 'inline-flex',
        alignItems: 'center',
        gap: 7,
        padding: '6px 11px',
        background: on ? "".concat(w.color, "22") : 'transparent',
        border: "1px solid ".concat(on ? w.color : T.stroke1),
        borderRadius: 4,
        cursor: 'pointer',
        color: on ? w.color : T.fg3,
        fontFamily: T.fontBody,
        fontSize: 11.5,
        fontWeight: 600,
        transition: 'all 120ms'
      }
    }, /*#__PURE__*/React.createElement("span", {
      style: {
        width: 9,
        height: 9,
        borderRadius: 2,
        background: w.color,
        opacity: on ? 1 : 0.4
      }
    }), w.label);
  }));
};

/* ── Planner — velden + ploeg + agenda als kies-oppervlak (zoals de opmetingsagenda) ── */
var plMin = function plMin(t) {
  var _String$split$map = String(t || '0:0').split(':').map(Number),
    _String$split$map2 = _slicedToArray(_String$split$map, 2),
    h = _String$split$map2[0],
    m = _String$split$map2[1];
  return h * 60 + (m || 0);
};
var plPlus = function plPlus(iso, n) {
  var d = new Date(iso + 'T12:00:00');
  d.setDate(d.getDate() + n);
  return d.toISOString().slice(0, 10);
};
var plTijd = function plTijd(m) {
  return "".concat(String(Math.min(23, Math.floor(m / 60))).padStart(2, '0'), ":").concat(String(Math.max(0, m) % 60).padStart(2, '0'));
};
/* Dagdeel uit een tijdvak: voormiddag (eindigt uiterlijk 13:00), namiddag (begint vanaf 12:00), anders hele dag. */
var plSlotVan = function plSlotVan(start, end) {
  var a = plMin(start),
    b = plMin(end);
  return b <= 13 * 60 ? 'vm' : a >= 12 * 60 ? 'nm' : 'dag';
};
/* ── Planner ──────────────────────────────────────────────────────────────────
   In de volgorde waarin je plant: 1 soort werk → 2 venster (ten vroegste, ten laatste) en
   geschatte werkduur → 3 beste voorstel (minste rijtijd tussen de jobs rond dit adres) →
   4 het gekozen moment, de ploeg en de werkinfo. De agenda eronder blijft het kies-oppervlak.
   Opmaak zoals de rest van het ERP: kleine kopletters per blok, velden van het huis
   (GhsDatumVeld, GhsTijdVeld), tegels op bg2 met afgesneden hoeken, één knoppenrij. */
var PlWerkPlanner = function PlWerkPlanner(_ref9) {
  var item = _ref9.item,
    prefill = _ref9.prefill,
    onSave = _ref9.onSave,
    onCancel = _ref9.onCancel,
    title = _ref9.title,
    onMinimize = _ref9.onMinimize,
    alsVenster = _ref9.alsVenster;
  var stdU = function stdU(w) {
    return window.rdDuurVoor ? window.rdDuurVoor(w) : 4;
  };
  var _React$useState = React.useState(item.work || 'pv_hellend'),
    _React$useState2 = _slicedToArray(_React$useState, 2),
    work = _React$useState2[0],
    setWorkRaw = _React$useState2[1];
  var bestaand = !!(item.slotId && item.start && item.end);
  var _React$useState3 = React.useState(bestaand ? Math.round((plMin(item.end) - plMin(item.start)) / 15) / 4 : stdU(item.work || 'pv_hellend')),
    _React$useState4 = _slicedToArray(_React$useState3, 2),
    duur = _React$useState4[0],
    setDuurRaw = _React$useState4[1];
  var _React$useState5 = React.useState({
      van: plPlus(plToday(), 1),
      tot: plPlus(plToday(), window.rdDrm ? window.rdDrm('plan_horizon_dagen') : 28)
    }),
    _React$useState6 = _slicedToArray(_React$useState5, 2),
    venster = _React$useState6[0],
    setVenster = _React$useState6[1];
  var _React$useState7 = React.useState({
      date: (prefill === null || prefill === void 0 ? void 0 : prefill.date) || item.date || '',
      start: (prefill === null || prefill === void 0 ? void 0 : prefill.start) || item.start || '08:00',
      end: (prefill === null || prefill === void 0 ? void 0 : prefill.end) || item.end || plTijd(8 * 60 + Math.round((bestaand ? 6 : stdU(item.work || 'pv_hellend')) * 60))
    }),
    _React$useState8 = _slicedToArray(_React$useState7, 2),
    form = _React$useState8[0],
    setForm = _React$useState8[1];
  var _React$useState9 = React.useState(item.tijdslot || null),
    _React$useState0 = _slicedToArray(_React$useState9, 2),
    tijdslot = _React$useState0[0],
    setTijdslot = _React$useState0[1];
  var _React$useState1 = React.useState(!!item.uurVrij),
    _React$useState10 = _slicedToArray(_React$useState1, 2),
    uurVrij = _React$useState10[0],
    setUurVrij = _React$useState10[1];
  var _React$useState11 = React.useState(window.ghsCrewIds ? window.ghsCrewIds(item.crew) : item.crew || []),
    _React$useState12 = _slicedToArray(_React$useState11, 2),
    crew = _React$useState12[0],
    setCrew = _React$useState12[1];
  var _React$useState13 = React.useState(item.info || ''),
    _React$useState14 = _slicedToArray(_React$useState13, 2),
    info = _React$useState14[0],
    setInfo = _React$useState14[1];
  var _React$useState15 = React.useState((prefill === null || prefill === void 0 ? void 0 : prefill.date) || item.date || plToday()),
    _React$useState16 = _slicedToArray(_React$useState15, 2),
    base = _React$useState16[0],
    setBase = _React$useState16[1];
  var eindVan = function eindVan(start, uren) {
    return plTijd(plMin(start) + Math.round(uren * 60) + (uren > 5 ? 30 : 0));
  };
  /* Soort werk → standaardduur; duur → einde schuift mee; einde met de hand → duur volgt. */
  var setWork = function setWork(w) {
    setWorkRaw(w);
    var u = stdU(w);
    setDuurRaw(u);
    setForm(function (f) {
      return _objectSpread(_objectSpread({}, f), {}, {
        end: eindVan(f.start, u)
      });
    });
  };
  var setDuur = function setDuur(u) {
    var v = Math.max(0.25, Number(u) || 0.25);
    setDuurRaw(v);
    setForm(function (f) {
      return _objectSpread(_objectSpread({}, f), {}, {
        end: eindVan(f.start, v)
      });
    });
  };
  var setStart = function setStart(v) {
    return setForm(function (f) {
      return _objectSpread(_objectSpread({}, f), {}, {
        start: v,
        end: eindVan(v, duur)
      });
    });
  };
  var setEnd = function setEnd(v) {
    setForm(function (f) {
      return _objectSpread(_objectSpread({}, f), {}, {
        end: v
      });
    });
    setDuurRaw(Math.max(0.25, Math.round((plMin(v) - plMin(form.start)) / 15) / 4));
  };
  var kiesMoment = function kiesMoment(date, start, end, crewKeuze, slot) {
    setForm(function (f) {
      return _objectSpread(_objectSpread({}, f), {}, {
        date: date,
        start: start,
        end: end
      });
    });
    setBase(date);
    setTijdslot(slot || plSlotVan(start, end));
    setDuurRaw(Math.max(0.25, Math.round((plMin(end) - plMin(start)) / 15) / 4));
    if (crewKeuze && (!crew.length || !crew.includes(crewKeuze[0]))) setCrew(crewKeuze);
  };
  var toggle = function toggle(id) {
    return setCrew(function (cs) {
      return cs.includes(id) ? cs.filter(function (x) {
        return x !== id;
      }) : [].concat(_toConsumableArray(cs), [id]);
    });
  };
  var _React$useState17 = React.useState(false),
    _React$useState18 = _slicedToArray(_React$useState17, 2),
    alles = _React$useState18[0],
    setAlles = _React$useState18[1];
  var bezet = React.useMemo(function () {
    return plBezet(form, item.slotId);
  }, [form.date, form.start, form.end, item.slotId]);
  var conflict = crew.filter(function (id) {
    return bezet[id];
  });
  var agendaItems = React.useMemo(function () {
    return plAllSlotItems(item.slotId, alles ? null : crew);
  }, [item.slotId, alles, crew.join(',')]);
  var can = form.date && form.start && form.end && !!work;
  var duurMin = Math.max(30, Math.round(duur * 60));
  var slotLabel = {
    vm: 'Voormiddag',
    nm: 'Namiddag',
    dag: 'Hele dag'
  };
  var Datum = window.GhsDatumVeld;
  var fld = {
    background: T.bg0,
    border: "1px solid ".concat(T.stroke1),
    clipPath: cutPath(5),
    padding: '9px 11px',
    color: T.fg1,
    fontFamily: T.fontBody,
    fontSize: 12.5,
    outline: 'none',
    width: '100%',
    boxSizing: 'border-box',
    minHeight: 38
  };
  var lbl = {
    fontFamily: T.fontBody,
    fontSize: 9,
    fontWeight: 700,
    letterSpacing: '0.12em',
    textTransform: 'uppercase',
    color: T.fg3,
    marginBottom: 5,
    display: 'block'
  };
  var hint = {
    fontFamily: T.fontBody,
    fontSize: 11.5,
    color: T.fg3,
    lineHeight: 1.5
  };
  /* Blokkop: nummer en titel in kleine kapitalen, de uitleg eronder — zoals de kolomkoppen en sectiekoppen van de lijsten. */
  var kop = function kop(n, titel, sub, rechts) {
    return /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        alignItems: 'flex-start',
        gap: 12,
        marginBottom: 10
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        flex: 1,
        minWidth: 0
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        alignItems: 'center',
        gap: 8
      }
    }, /*#__PURE__*/React.createElement("span", {
      style: {
        fontFamily: T.fontBody,
        fontSize: 9.5,
        fontWeight: 800,
        letterSpacing: '0.14em',
        textTransform: 'uppercase',
        color: T.accent
      }
    }, "Stap ".concat(n)), /*#__PURE__*/React.createElement("span", {
      style: {
        fontFamily: T.fontDisplay,
        fontSize: 13.5,
        fontWeight: 600,
        color: T.fg1
      }
    }, titel)), sub && /*#__PURE__*/React.createElement("div", {
      style: _objectSpread(_objectSpread({}, hint), {}, {
        marginTop: 2
      })
    }, sub)), rechts);
  };
  var tegel = {
    background: T.bg2,
    border: "1px solid ".concat(T.stroke1),
    clipPath: cutPath(8),
    padding: '14px 16px'
  };
  var gekozenTekst = form.date ? "".concat(plDateNL(form.date), " \xB7 ").concat(tijdslot ? slotLabel[tijdslot] + ' · ' : '').concat(form.start, "\u2013").concat(form.end) : null;
  var knoppen = [/*#__PURE__*/React.createElement(Button, {
    key: "ok",
    variant: "primary",
    size: "sm",
    icon: "check",
    disabled: !can,
    onClick: function onClick() {
      return can && onSave(_objectSpread(_objectSpread({}, form), {}, {
        crew: crew,
        work: work,
        info: info.trim(),
        slotId: item.slotId || null,
        tijdslot: tijdslot || plSlotVan(form.start, form.end),
        uurVrij: uurVrij
      }));
    }
  }, item.slotId ? 'Wijzigingen opslaan' : crew.length ? 'Werk inplannen' : 'Reserveren'), window.GhsZelfplanKnop && !item.slotId ? /*#__PURE__*/React.createElement(window.GhsZelfplanKnop, {
    key: "zelf",
    variant: "beige",
    "data-rang": 1,
    cid: item._cid,
    dealRef: item.dealRef,
    soort: "installatie",
    work: work,
    duurMin: duurMin,
    techIds: crew.length ? crew : null,
    vroegsteISO: venster.van,
    laatsteISO: venster.tot
  }) : null, onMinimize && !alsVenster ? /*#__PURE__*/React.createElement(Button, {
    key: "min",
    variant: "ghost",
    size: "sm",
    icon: "chevrondown",
    title: "Minimaliseren \u2014 het venster gaat naar de dock onderaan",
    "aria-label": "Minimaliseren",
    onClick: onMinimize
  }) : null].filter(Boolean);
  var knoppenRij = /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      gap: 8,
      alignItems: 'center',
      flexWrap: 'wrap-reverse',
      justifyContent: 'flex-end'
    }
  }, window.ghsKnopVolgorde ? window.ghsKnopVolgorde(knoppen, 'flex-end') : knoppen);
  var stappen = /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
    style: tegel
  }, kop(1, 'Soort werk', 'Bepaalt de kleurcode in de agenda en de standaard werkduur.'), /*#__PURE__*/React.createElement(PlWorkPicker, {
    value: work,
    onPick: setWork
  })), /*#__PURE__*/React.createElement("div", {
    style: tegel
  }, kop(2, 'Wanneer mag het?', "Het venster waarin gezocht wordt, en hoe lang het werk duurt. Tot ".concat(window.rdDrm ? window.rdDrm('plan_halve_dag_uren') : 4, " u past in een voormiddag of namiddag; langer werk krijgt een hele dag.")), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'grid',
      gridTemplateColumns: 'repeat(auto-fit,minmax(170px,1fr))',
      gap: 12
    }
  }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", {
    style: lbl
  }, "Ten vroegste"), Datum ? /*#__PURE__*/React.createElement(Datum, {
    value: venster.van,
    onChange: function onChange(v) {
      return setVenster(function (x) {
        return _objectSpread(_objectSpread({}, x), {}, {
          van: v
        });
      });
    }
  }) : /*#__PURE__*/React.createElement("input", {
    type: "date",
    value: venster.van,
    onChange: function onChange(e) {
      return setVenster(function (x) {
        return _objectSpread(_objectSpread({}, x), {}, {
          van: e.target.value
        });
      });
    },
    style: fld
  })), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", {
    style: lbl
  }, "Ten laatste"), Datum ? /*#__PURE__*/React.createElement(Datum, {
    value: venster.tot,
    onChange: function onChange(v) {
      return setVenster(function (x) {
        return _objectSpread(_objectSpread({}, x), {}, {
          tot: v
        });
      });
    }
  }) : /*#__PURE__*/React.createElement("input", {
    type: "date",
    value: venster.tot,
    onChange: function onChange(e) {
      return setVenster(function (x) {
        return _objectSpread(_objectSpread({}, x), {}, {
          tot: e.target.value
        });
      });
    },
    style: fld
  })), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", {
    style: lbl
  }, "Geschatte werkduur"), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      alignItems: 'center',
      gap: 10
    }
  }, /*#__PURE__*/React.createElement("input", {
    type: "number",
    min: 0.25,
    step: 0.25,
    value: duur,
    onChange: function onChange(e) {
      return setDuur(e.target.value);
    },
    "aria-label": "Geschatte werkduur in uren",
    style: _objectSpread(_objectSpread({}, fld), {}, {
      width: 84,
      textAlign: 'center',
      fontFamily: T.fontDisplay,
      fontSize: 14,
      fontWeight: 600
    })
  }), /*#__PURE__*/React.createElement("span", {
    style: _objectSpread(_objectSpread({}, hint), {}, {
      color: duur !== stdU(work) ? '#ffb020' : T.fg3
    })
  }, duur !== stdU(work) ? "uur \xB7 aangepast (standaard ".concat(stdU(work), " u)") : "uur \xB7 standaard voor ".concat(plWork(work)["short"])))))), /*#__PURE__*/React.createElement("div", null, kop(3, 'Beste voorstel', 'Tijdsloten tussen jobs zo dicht mogelijk bij dit adres, binnen het venster. Klik op een voorstel om het over te nemen.'), window.GhsBesteVoorstel ? /*#__PURE__*/React.createElement(window.GhsBesteVoorstel, {
    contacts: window.crmStore.getState().contacts,
    cid: item._cid,
    duurMin: duurMin,
    techIds: crew.length ? crew : null,
    zonder: item.slotId || null,
    van: venster.van,
    tot: venster.tot,
    aantal: 3,
    compact: true,
    gekozen: {
      date: form.date,
      start: form.start,
      crew: crew
    },
    onKies: function onKies(v) {
      return kiesMoment(v.date, v.start, v.end, v.crew, v.slot);
    }
  }) : /*#__PURE__*/React.createElement("div", {
    style: hint
  }, "Rijtijden niet geladen.")), /*#__PURE__*/React.createElement("div", {
    style: _objectSpread(_objectSpread({}, tegel), {}, {
      border: "1px solid ".concat(form.date ? T.strokeAccent : T.stroke1)
    })
  }, kop(4, 'Gekozen moment', form.date ? null : 'Nog geen moment — kies een voorstel hierboven of klik/sleep een tijdvak in de agenda.', gekozenTekst && /*#__PURE__*/React.createElement("span", {
    style: {
      display: 'inline-flex',
      alignItems: 'center',
      gap: 7,
      padding: '6px 11px',
      background: 'rgba(0,217,0,0.10)',
      border: "1px solid ".concat(T.strokeAccent),
      clipPath: cutPath(5),
      fontFamily: T.fontDisplay,
      fontSize: 13,
      fontWeight: 600,
      color: T.fg1,
      whiteSpace: 'nowrap'
    }
  }, /*#__PURE__*/React.createElement(Icon, {
    name: "calendar",
    size: 13,
    color: T.accent
  }), gekozenTekst)), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'grid',
      gridTemplateColumns: '1.3fr 1fr 1fr',
      gap: 12,
      marginBottom: 12
    }
  }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", {
    style: lbl
  }, "Datum"), Datum ? /*#__PURE__*/React.createElement(Datum, {
    value: form.date,
    onChange: function onChange(v) {
      return kiesMoment(v, form.start, form.end);
    }
  }) : /*#__PURE__*/React.createElement("input", {
    type: "date",
    value: form.date,
    onChange: function onChange(e) {
      return kiesMoment(e.target.value, form.start, form.end);
    },
    style: fld
  })), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", {
    style: lbl
  }, "Start"), /*#__PURE__*/React.createElement(window.GhsTijdVeld, {
    value: form.start,
    onChange: setStart,
    style: fld
  })), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", {
    style: lbl
  }, "Einde"), /*#__PURE__*/React.createElement(window.GhsTijdVeld, {
    value: form.end,
    onChange: setEnd,
    style: fld
  }))), /*#__PURE__*/React.createElement("div", {
    style: {
      marginBottom: 12
    }
  }, /*#__PURE__*/React.createElement("span", {
    style: lbl
  }, "Ploeg \u2014 wie gaat mee \xB7 BEZET = al ingepland in dit tijdvak"), /*#__PURE__*/React.createElement(PlCrewPicker, {
    crew: crew,
    onToggle: toggle,
    bezet: bezet
  })), conflict.length > 0 && /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      alignItems: 'flex-start',
      gap: 9,
      padding: '9px 12px',
      marginBottom: 12,
      background: 'rgba(255,176,32,0.08)',
      border: '1px solid rgba(255,176,32,0.35)',
      clipPath: cutPath(6)
    }
  }, /*#__PURE__*/React.createElement(Icon, {
    name: "alert",
    size: 13,
    color: "#ffb020"
  }), /*#__PURE__*/React.createElement("div", {
    style: _objectSpread(_objectSpread({}, hint), {}, {
      color: T.fg2
    })
  }, /*#__PURE__*/React.createElement("b", {
    style: {
      color: '#ffb020'
    }
  }, "Dubbele inplanning"), " \u2014 ", conflict.map(function (id) {
    return "".concat(plCrewName(id).split(' ')[0], " (").concat(bezet[id].join(', '), ")");
  }).join(' · '), ". Kies een ander tijdvak of haal het ploeglid uit de selectie.")), /*#__PURE__*/React.createElement("div", {
    style: {
      marginBottom: 12
    }
  }, /*#__PURE__*/React.createElement("span", {
    style: lbl
  }, "Werkinfo"), /*#__PURE__*/React.createElement("textarea", {
    value: info,
    onChange: function onChange(e) {
      return setInfo(e.target.value);
    },
    placeholder: "Wat moet er gebeuren, materiaal, toegang, ...",
    style: _objectSpread(_objectSpread({}, fld), {}, {
      resize: 'vertical',
      minHeight: 56
    })
  })), /*#__PURE__*/React.createElement("label", {
    style: {
      display: 'flex',
      alignItems: 'flex-start',
      gap: 9,
      cursor: 'pointer'
    }
  }, /*#__PURE__*/React.createElement("input", {
    type: "checkbox",
    checked: uurVrij,
    onChange: function onChange(e) {
      return setUurVrij(e.target.checked);
    },
    style: {
      marginTop: 2
    }
  }), /*#__PURE__*/React.createElement("span", {
    style: _objectSpread(_objectSpread({}, hint), {}, {
      color: T.fg2
    })
  }, /*#__PURE__*/React.createElement("b", {
    style: {
      color: T.fg1
    }
  }, "Uur mag naar de klant."), " Standaard krijgt de klant enkel het dagdeel; het uur volgt ".concat(window.rdDrm ? window.rdDrm('plan_slot_dagen') : 2, " dagen vooraf. Vink aan als de klant er uitdrukkelijk om vraagt.")))), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      alignItems: 'center',
      justifyContent: 'space-between',
      gap: 10,
      marginBottom: 8
    }
  }, /*#__PURE__*/React.createElement("span", {
    style: hint
  }, alles || !crew.length ? 'Agenda toont alle geplande werken.' : "Agenda toont enkel de bezetting van ".concat(plCrewNames(crew).map(function (n) {
    return n.split(' ')[0];
  }).join(', '), ".")), crew.length > 0 && /*#__PURE__*/React.createElement(Button, {
    variant: "ghost",
    size: "sm",
    icon: alles ? 'users' : 'eye',
    onClick: function onClick() {
      return setAlles(function (v) {
        return !v;
      });
    }
  }, alles ? 'Enkel mijn ploeg' : 'Alle werken tonen')), /*#__PURE__*/React.createElement(window.OpmAgendaGrid, {
    items: agendaItems,
    base: base,
    setBase: setBase,
    value: form,
    onPick: function onPick(date, start, end) {
      return kiesMoment(date, start, end);
    },
    pickHint: alles || !crew.length ? 'Klik of sleep een tijdvak — bezetting van alle geplande werken' : 'Klik of sleep een tijdvak — vrije ruimte = beschikbaar voor de gekozen ploeg'
  })));
  /* Als venster: kop zoals de werkbon en het ticket (klant, soort, dossier), de stappen in het
     midden en de knoppen in de voet — sluiten links, de hoofdactie rechts. */
  if (alsVenster && window.GhsVensterKop) return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(window.GhsVensterKop, {
    avatar: item.client,
    titel: item.client,
    attrs: {
      'data-pl-kop': ''
    },
    chips: [{
      label: item.slotId ? 'Werk verplaatsen' : 'Werk inplannen',
      icon: 'calendar'
    }],
    meta: [item.dealRef ? /*#__PURE__*/React.createElement("b", {
      key: "r",
      style: {
        color: T.fg1,
        fontWeight: 700,
        letterSpacing: '0.02em'
      }
    }, item.dealRef) : null, item.dealName, item.address],
    onMinimize: onMinimize,
    onClose: onCancel,
    sluitTitel: "Sluiten zonder in te plannen"
  }), window.GhsGrootScherm && /*#__PURE__*/React.createElement(window.GhsGrootScherm, {
    wat: "Werk inplannen",
    sleutel: "werk-inplannen",
    kort: "Een moment kiezen in de ploegagenda gaat het vlotst op een computer of tablet."
  }), /*#__PURE__*/React.createElement("div", {
    style: {
      flex: 1,
      minHeight: 0,
      overflowY: 'auto',
      padding: '22px 26px 28px',
      display: 'flex',
      flexDirection: 'column',
      gap: 16
    }
  }, stappen), /*#__PURE__*/React.createElement("div", {
    "data-pl-voet": "",
    style: window.GHS_VENSTER_VOET
  }, /*#__PURE__*/React.createElement(Button, {
    variant: "ghost",
    flush: "start",
    onClick: onCancel
  }, "Sluiten"), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      alignItems: 'center',
      gap: 12,
      flexWrap: 'wrap',
      justifyContent: 'flex-end',
      marginLeft: 'auto'
    }
  }, /*#__PURE__*/React.createElement("span", {
    style: _objectSpread(_objectSpread({}, hint), {}, {
      color: form.date ? T.fg2 : T.fg3
    })
  }, gekozenTekst || 'Nog geen moment gekozen'), knoppenRij)));
  return /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      flexDirection: 'column',
      gap: 16
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      alignItems: 'center',
      justifyContent: 'space-between',
      gap: '10px 16px',
      flexWrap: 'wrap'
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      flex: '1 1 280px',
      minWidth: 0
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      fontFamily: T.fontDisplay,
      fontSize: 16,
      fontWeight: 600,
      color: T.fg1,
      lineHeight: 1.25
    }
  }, title || "Werk inplannen \u2014 ".concat(item.client)), /*#__PURE__*/React.createElement("div", {
    style: _objectSpread(_objectSpread({}, hint), {}, {
      marginTop: 3
    })
  }, item.dealRef, " \xB7 ", item.dealName, " \xB7 ", item.address)), knoppenRij), stappen);
};
/* Het planner-venster kan naar de dock, net als een ticket: het dossier blijft open terwijl je iets anders nakijkt. */
var PlPlannerModal = function PlPlannerModal(_ref0) {
  var item = _ref0.item,
    onClose = _ref0.onClose,
    onSave = _ref0.onSave;
  var _React$useState19 = React.useState(false),
    _React$useState20 = _slicedToArray(_React$useState19, 2),
    min = _React$useState20[0],
    setMin = _React$useState20[1];
  /* Geminimaliseerd blijft het venster gemount (verborgen): wat je al koos, blijft staan. */
  if (window.useDockPanel) window.useDockPanel(min, {
    key: 'plan-' + (item.slotId || item.dealRef),
    icon: 'calendar',
    title: "".concat(item.slotId ? 'Werk verplaatsen' : 'Werk inplannen', " \u2014 ").concat(item.client),
    sub: item.dealRef,
    restore: function restore() {
      return setMin(false);
    },
    close: onClose
  });
  if (!window.ghsVensterLaag) return /*#__PURE__*/React.createElement(Modal, {
    open: !min,
    onClose: onClose,
    title: "Planningsagenda",
    width: 880
  }, /*#__PURE__*/React.createElement(PlWerkPlanner, {
    item: item,
    onCancel: onClose,
    onSave: onSave,
    onMinimize: window.useDockPanel ? function () {
      return setMin(true);
    } : null
  }));
  return /*#__PURE__*/React.createElement(GhsPortal, null, /*#__PURE__*/React.createElement("div", {
    "data-pl-venster": "",
    style: window.ghsVensterLaag(2800, {
      display: min ? 'none' : 'flex'
    })
  }, /*#__PURE__*/React.createElement("div", {
    role: "dialog",
    "aria-modal": "true",
    "aria-label": "Werk inplannen \u2014 ".concat(item.client),
    "data-ghs-venster": "planner",
    style: window.ghsVensterKader({
      maxWidth: 1100
    })
  }, /*#__PURE__*/React.createElement("div", {
    style: accentEdge(18)
  }), /*#__PURE__*/React.createElement(PlWerkPlanner, {
    alsVenster: true,
    item: item,
    onCancel: onClose,
    onSave: onSave,
    onMinimize: window.useDockPanel ? function () {
      return setMin(true);
    } : null
  }))));
};

/* ── Werk-kaart (kanban) ─────────────────────────────────────────────────── */
var plDateNL = function plDateNL(iso) {
  return new Date(iso + 'T00:00:00').toLocaleDateString('nl-BE', {
    day: 'numeric',
    month: 'short'
  });
};
// Ingepland moment — elk moment heeft zijn eigen soort werk (= kleurcode).
var PlMomentRow = function PlMomentRow(_ref1) {
  var s = _ref1.s,
    onEdit = _ref1.onEdit;
  var w = plWork(s.work);
  var od = s.date < plToday();
  return /*#__PURE__*/React.createElement("button", {
    onClick: function onClick(e) {
      e.stopPropagation();
      onEdit && onEdit(s);
    },
    title: onEdit ? 'Aanpassen of verplaatsen' : undefined,
    style: {
      display: 'flex',
      alignItems: 'stretch',
      gap: 8,
      width: '100%',
      textAlign: 'left',
      padding: '6px 9px',
      background: "".concat(w.color, "14"),
      border: "1px solid ".concat(w.color, "40"),
      borderRadius: 5,
      cursor: onEdit ? 'pointer' : 'default',
      transition: 'background 140ms'
    },
    onMouseEnter: function onMouseEnter(e) {
      e.currentTarget.style.background = "".concat(w.color, "26");
    },
    onMouseLeave: function onMouseLeave(e) {
      e.currentTarget.style.background = "".concat(w.color, "14");
    }
  }, /*#__PURE__*/React.createElement("span", {
    style: {
      width: 3,
      borderRadius: 2,
      background: w.color,
      flexShrink: 0
    }
  }), /*#__PURE__*/React.createElement("span", {
    style: {
      flex: 1,
      minWidth: 0
    }
  }, /*#__PURE__*/React.createElement("span", {
    style: {
      display: 'block',
      fontFamily: T.fontBody,
      fontSize: 10,
      fontWeight: 700,
      textTransform: 'uppercase',
      letterSpacing: '0.05em',
      color: w.color,
      overflow: 'hidden',
      textOverflow: 'ellipsis',
      whiteSpace: 'nowrap'
    }
  }, w.label), /*#__PURE__*/React.createElement("span", {
    style: {
      display: 'block',
      fontFamily: T.fontBody,
      fontSize: 11,
      color: od ? '#ff5a4d' : T.fg2,
      overflow: 'hidden',
      textOverflow: 'ellipsis',
      whiteSpace: 'nowrap'
    }
  }, plDateNL(s.date), " \xB7 ", s.start, "\u2013", s.end, (s.crew || []).length ? ' · ' + plCrewNames(s.crew).map(function (n) {
    return n.split(' ')[0];
  }).join(', ') : ' · geen ploeg'), window.zpSlotStand && function () {
    var z = window.zpSlotStand(s);
    return /*#__PURE__*/React.createElement("span", {
      style: {
        display: 'inline-flex',
        alignItems: 'center',
        gap: 5,
        marginTop: 3,
        fontFamily: T.fontBody,
        fontSize: 10.5,
        fontWeight: 700,
        color: z.kleur
      }
    }, /*#__PURE__*/React.createElement("span", {
      style: {
        width: 6,
        height: 6,
        borderRadius: '50%',
        background: z.kleur
      }
    }), z.label);
  }()), onEdit && /*#__PURE__*/React.createElement(Icon, {
    name: "edit",
    size: 11,
    color: T.fg4
  }));
};

/* ── Werf uit de planning halen ───────────────────────────────────────────────
   Enkel zolang de werf nog niet uitgevoerd is: een uitgevoerde werf hangt vast
   aan een werkbon en blijft staan. Terug te draaien met Ctrl+Z. */
var PlanDeleteBtn = function PlanDeleteBtn(_ref10) {
  var item = _ref10.item;
  var _React$useState21 = React.useState(false),
    _React$useState22 = _slicedToArray(_React$useState21, 2),
    ask = _React$useState22[0],
    setAsk = _React$useState22[1];
  var stop = function stop(e) {
    return e.stopPropagation();
  };
  if (item.status === 'uitgevoerd') return null;
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
    title: "Werf uit de planning halen \u2014 de gewonnen deal blijft bestaan",
    onClick: function onClick(e) {
      stop(e);
      setAsk(true);
    },
    style: {
      width: 24,
      height: 24,
      display: 'flex',
      alignItems: 'center',
      justifyContent: 'center',
      background: 'transparent',
      border: "1px solid ".concat(T.stroke1),
      borderRadius: 5,
      cursor: 'pointer',
      color: T.fg4,
      flex: 'none',
      transition: 'all 140ms'
    },
    onMouseEnter: function onMouseEnter(e) {
      e.currentTarget.style.borderColor = '#ff5a4d';
      e.currentTarget.style.color = '#ff5a4d';
    },
    onMouseLeave: function onMouseLeave(e) {
      e.currentTarget.style.borderColor = T.stroke1;
      e.currentTarget.style.color = T.fg4;
    }
  }, /*#__PURE__*/React.createElement(Icon, {
    name: "trash",
    size: 11,
    color: "currentColor"
  })), ask && /*#__PURE__*/React.createElement("div", {
    onClick: stop
  }, /*#__PURE__*/React.createElement(Modal, {
    open: true,
    onClose: function onClose() {
      return setAsk(false);
    },
    title: "Werf uit de planning halen?",
    width: 460
  }, /*#__PURE__*/React.createElement("p", {
    style: {
      margin: '0 0 8px',
      fontSize: 13,
      color: T.fg2,
      fontFamily: T.fontBody,
      lineHeight: 1.6
    }
  }, /*#__PURE__*/React.createElement("b", {
    style: {
      color: T.fg1
    }
  }, item.dealRef, " \u2014 ", item.client), " verdwijnt uit de planning", item.slots && item.slots.length ? ', samen met de ingeplande momenten' : '', "."), /*#__PURE__*/React.createElement("p", {
    style: {
      margin: '0 0 16px',
      fontSize: 12,
      color: T.fg3,
      fontFamily: T.fontBody,
      lineHeight: 1.6
    }
  }, "De gewonnen deal en de opmeting blijven behouden. Met ", /*#__PURE__*/React.createElement("b", {
    style: {
      color: T.fg2
    }
  }, "Ctrl+Z"), " draai je dit terug."), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      justifyContent: 'flex-end',
      gap: 8
    }
  }, /*#__PURE__*/React.createElement(Button, {
    variant: "secondary",
    onClick: function onClick() {
      return setAsk(false);
    }
  }, "Annuleren"), /*#__PURE__*/React.createElement(Button, {
    variant: "danger",
    icon: "trash",
    onClick: function onClick() {
      window.crmStore.removePlanning(item._cid, item.dealRef);
      setAsk(false);
    }
  }, "Uit planning halen")))));
};
var PlanCard = function PlanCard(_ref11) {
  var item = _ref11.item,
    tag = _ref11.tag,
    onOpen = _ref11.onOpen,
    onPlan = _ref11.onPlan,
    onPlanSlot = _ref11.onPlanSlot,
    onPlanExtra = _ref11.onPlanExtra,
    onDone = _ref11.onDone,
    onReopen = _ref11.onReopen,
    _onDragStart = _ref11.onDragStart,
    onDragEnd = _ref11.onDragEnd;
  var overdue = item.date && item.status === 'ingepland' && item.date < plToday();
  var slots = item.slots || [];
  var _React$useState23 = React.useState(false),
    _React$useState24 = _slicedToArray(_React$useState23, 2),
    docsOpen = _React$useState24[0],
    setDocsOpen = _React$useState24[1];
  var docCount = docsOpen ? plDocCount(item._cid) : null;
  var stripes = slots.map(function (s) {
    return plWork(s.work).color;
  });
  return /*#__PURE__*/React.createElement("div", {
    draggable: true,
    onDragStart: function onDragStart(e) {
      e.dataTransfer.effectAllowed = 'move';
      _onDragStart(item);
    },
    onDragEnd: onDragEnd,
    className: "k-card",
    style: {
      position: 'relative',
      background: T.bg1,
      border: "1px solid ".concat(T.stroke1),
      clipPath: cutPath(8),
      padding: '12px 14px 12px ' + (stripes.length ? 10 + 4 * stripes.length : 14) + 'px',
      marginBottom: 8,
      overflow: 'hidden'
    },
    onMouseEnter: function onMouseEnter(e) {
      e.currentTarget.style.background = T.bg2;
      e.currentTarget.style.borderColor = T.stroke2;
    },
    onMouseLeave: function onMouseLeave(e) {
      e.currentTarget.style.background = T.bg1;
      e.currentTarget.style.borderColor = T.stroke1;
    }
  }, stripes.length > 0 && /*#__PURE__*/React.createElement("div", {
    title: slots.map(function (s) {
      return plWork(s.work).label;
    }).join(' · '),
    style: {
      position: 'absolute',
      left: 0,
      top: 0,
      bottom: 0,
      width: 4 * stripes.length,
      display: 'flex',
      pointerEvents: 'none'
    }
  }, stripes.map(function (c, i) {
    return /*#__PURE__*/React.createElement("div", {
      key: i,
      style: {
        flex: 1,
        background: c
      }
    });
  })), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      justifyContent: 'space-between',
      alignItems: 'flex-start',
      marginBottom: 5
    },
    onClick: function onClick() {
      return onOpen(item);
    }
  }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
    style: {
      fontSize: 9,
      color: T.fg4,
      fontFamily: T.fontBody,
      letterSpacing: '0.08em',
      marginBottom: 2
    }
  }, item.dealRef), /*#__PURE__*/React.createElement("div", {
    style: {
      fontFamily: T.fontBody,
      fontSize: 13,
      fontWeight: 700,
      color: T.fg1
    }
  }, item.client), /*#__PURE__*/React.createElement("div", {
    style: {
      fontSize: 11,
      color: T.fg3,
      fontFamily: T.fontBody,
      marginTop: 1
    }
  }, item.address)), item.status === 'uitgevoerd' && /*#__PURE__*/React.createElement(Badge, {
    type: "success",
    dot: true
  }, "Uitgevoerd"), /*#__PURE__*/React.createElement("div", {
    onClick: function onClick(e) {
      return e.stopPropagation();
    },
    style: {
      flex: 'none'
    }
  }, /*#__PURE__*/React.createElement(PlanDeleteBtn, {
    item: item
  })), item.status === 'te_plannen' && tag && /*#__PURE__*/React.createElement("span", {
    title: "Suggestie op postcode ".concat(tag.n, " \u2014 regio ").concat(tag.region, ": deze werven liggen dicht bij elkaar (menselijk nazicht nodig)"),
    style: {
      display: 'inline-flex',
      alignItems: 'center',
      gap: 5,
      padding: '2px 8px',
      background: 'rgba(0,217,0,0.1)',
      border: '1px solid rgba(0,217,0,0.35)',
      borderRadius: 3,
      fontFamily: T.fontBody,
      fontSize: 9.5,
      fontWeight: 700,
      color: T.accent,
      whiteSpace: 'nowrap'
    }
  }, /*#__PURE__*/React.createElement(Icon, {
    name: "mappin",
    size: 9,
    color: T.accent
  }), "Suggestie ", tag.n)), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      gap: 5,
      marginBottom: 8,
      flexWrap: 'wrap',
      alignItems: 'center'
    }
  }, /*#__PURE__*/React.createElement("span", {
    style: {
      fontSize: 10,
      color: T.fg3,
      fontFamily: T.fontBody
    }
  }, item.dealName), item.kwp > 0 && /*#__PURE__*/React.createElement(Badge, {
    type: "accent"
  }, item.kwp, " kWp"), item.kwh > 0 && /*#__PURE__*/React.createElement(Badge, {
    type: "info"
  }, item.kwh, " kWh")), slots.length > 0 && /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      flexDirection: 'column',
      gap: 4,
      marginBottom: 8
    }
  }, /*#__PURE__*/React.createElement("span", {
    style: {
      fontFamily: T.fontBody,
      fontSize: 9,
      fontWeight: 700,
      letterSpacing: '0.1em',
      textTransform: 'uppercase',
      color: T.fg4
    }
  }, "Ingeplande momenten \xB7 ", slots.length), slots.map(function (s) {
    return /*#__PURE__*/React.createElement(PlMomentRow, {
      key: s.id,
      s: s,
      onEdit: onPlanSlot ? function () {
        return onPlanSlot(item, s);
      } : null
    });
  })), item.status === 'te_plannen' && item.vsWacht && window.GhsVoorschotWacht && /*#__PURE__*/React.createElement(window.GhsVoorschotWacht, {
    w: item.vsWacht,
    cid: item._cid,
    breed: true
  }), item.status === 'te_plannen' && !item.vsWacht && /*#__PURE__*/React.createElement("button", {
    onClick: function onClick(e) {
      e.stopPropagation();
      onPlan(item);
    },
    style: {
      width: '100%',
      background: 'rgba(255,176,32,0.12)',
      border: '1px solid rgba(255,176,32,0.3)',
      borderRadius: 5,
      padding: '7px 0',
      cursor: 'pointer',
      color: '#ffb020',
      fontFamily: T.fontBody,
      fontSize: 11,
      fontWeight: 700,
      display: 'flex',
      alignItems: 'center',
      justifyContent: 'center',
      gap: 6,
      transition: 'all 140ms'
    },
    onMouseEnter: function onMouseEnter(e) {
      return e.currentTarget.style.background = 'rgba(255,176,32,0.22)';
    },
    onMouseLeave: function onMouseLeave(e) {
      return e.currentTarget.style.background = 'rgba(255,176,32,0.12)';
    }
  }, /*#__PURE__*/React.createElement(Icon, {
    name: "calendar",
    size: 13,
    color: "#ffb020"
  }), "Werk inplannen"), item.status === 'ingepland' && /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      flexDirection: 'column',
      gap: 6
    },
    onClick: function onClick(e) {
      return e.stopPropagation();
    }
  }, /*#__PURE__*/React.createElement(Button, {
    variant: "primary",
    size: "sm",
    icon: "check",
    style: {
      width: '100%'
    },
    onClick: function onClick() {
      return onDone(item);
    }
  }, "Uitgevoerd melden"), /*#__PURE__*/React.createElement(Button, {
    variant: "beige",
    size: "sm",
    icon: "plus",
    style: {
      width: '100%'
    },
    onClick: function onClick() {
      return (onPlanExtra || onPlan)(item);
    }
  }, "Extra moment")), item.status === 'uitgevoerd' && /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      alignItems: 'center',
      gap: 6,
      flexWrap: 'wrap'
    },
    onClick: function onClick(e) {
      return e.stopPropagation();
    }
  }, /*#__PURE__*/React.createElement("span", {
    style: {
      display: 'inline-flex',
      alignItems: 'center',
      gap: 5,
      padding: '5px 10px',
      background: T.bg2,
      borderRadius: 5,
      color: item.werkbon ? T.fg2 : '#ffb020',
      fontFamily: T.fontBody,
      fontSize: 10.5,
      fontWeight: 700,
      whiteSpace: 'nowrap'
    }
  }, /*#__PURE__*/React.createElement(Icon, {
    name: "clipboard",
    size: 11,
    color: item.werkbon ? T.accent : '#ffb020'
  }), item.werkbon ? "Werkbon ".concat(item.werkbon.nr) : 'Werkbon op te maken'), /*#__PURE__*/React.createElement(Button, {
    variant: "ghost",
    size: "sm",
    icon: "refresh",
    onClick: function onClick() {
      return onReopen(item);
    }
  }, "Heropenen")));
};

/* ── Lijst-rij — zelfde info & acties, volle breedte ─────────────────────── */
var plDagen = function plDagen(i) {
  var s = i.dagenSinds || (i.installedAt ? String(i.installedAt).slice(0, 10) : i.date || i.slot && i.slot.date || null);
  return s && window.ghsDagenSinds ? window.ghsDagenSinds(s) || 0 : -1;
};
var PLAN_LIST_GRID = '74px 100px minmax(104px,1.3fr) minmax(92px,1fr) 178px minmax(88px,0.9fr) minmax(150px,1fr) 356px 32px';
/* Kolommen op maat van de inhoud: de lijst meet zichzelf en zet het raster in
   --ghs-grid (zie useGhsAutoGrid). De knoppenkolom (index 7) neemt de rest. */
var PLAN_AUTO_GRID = 'var(--ghs-grid, ' + PLAN_LIST_GRID + ')';
/* ── Los werk aan een offerte hangen ─────────────────────────────────────────
   Bewust een tussenstap met bevestiging: het werk verhuist mét zijn momenten en
   werkbonnen naar een ander dossier, en dat wil je nooit per ongeluk doen. */
var PlKoppelModal = function PlKoppelModal(_ref12) {
  var item = _ref12.item,
    onClose = _ref12.onClose;
  var _React$useState25 = React.useState(null),
    _React$useState26 = _slicedToArray(_React$useState25, 2),
    keuze = _React$useState26[0],
    setKeuze = _React$useState26[1];
  var cid = item._cid || item.cid;
  var c = (window.crmStore.getState().contacts || []).find(function (x) {
    return x.id === cid;
  });
  var deals = (c && c.deals || []).filter(function (d) {
    return !d.los;
  });
  var doel = deals.find(function (d) {
    return d.ref === keuze;
  }) || null;
  var slots = item.slots || [];
  var voortgang = item.voortgang || {
    klaar: 0
  };
  var koppel = function koppel() {
    window.crmStore.koppelLosWerk(cid, item.dealRef, keuze);
    onClose();
  };
  return /*#__PURE__*/React.createElement(Modal, {
    open: true,
    onClose: onClose,
    title: "Los werk koppelen \u2014 ".concat(item.client),
    width: 600
  }, /*#__PURE__*/React.createElement("p", {
    style: {
      margin: '0 0 14px',
      fontFamily: T.fontBody,
      fontSize: 12.5,
      color: T.fg2,
      lineHeight: 1.6
    }
  }, /*#__PURE__*/React.createElement("b", {
    style: {
      color: T.fg1
    }
  }, item.dealRef), " \u2014 ", item.dealName, " staat nu als los werk. Kies de offerte waar het bij hoort; ook een afgewerkte offerte kan."), deals.length === 0 ? /*#__PURE__*/React.createElement("div", {
    style: {
      padding: '18px 12px',
      textAlign: 'center',
      fontFamily: T.fontBody,
      fontSize: 12.5,
      color: T.fg3
    }
  }, "Deze klant heeft nog geen offertes om aan te koppelen.") : /*#__PURE__*/React.createElement("div", {
    style: {
      maxHeight: 300,
      overflowY: 'auto',
      display: 'flex',
      flexDirection: 'column',
      gap: 6,
      marginBottom: 14,
      paddingRight: 8,
      marginRight: -8
    }
  }, deals.map(function (d) {
    var on = keuze === d.ref;
    var stand = d.won ? {
      l: 'Gewonnen',
      k: T.accent
    } : d.lost ? {
      l: 'Verloren',
      k: '#ff5a4d'
    } : {
      l: 'Lopend',
      k: '#ffb020'
    };
    return /*#__PURE__*/React.createElement("button", {
      key: d.ref,
      onClick: function onClick() {
        return setKeuze(d.ref);
      },
      style: {
        display: 'flex',
        alignItems: 'center',
        gap: 10,
        padding: '10px 12px',
        background: on ? 'rgba(0,217,0,0.10)' : T.bg1,
        border: "1px solid ".concat(on ? T.strokeAccent : T.stroke1),
        clipPath: cutPath(6),
        cursor: 'pointer',
        textAlign: 'left'
      }
    }, /*#__PURE__*/React.createElement("span", {
      style: {
        fontFamily: T.fontBody,
        fontSize: 11,
        fontWeight: 700,
        color: T.fg3,
        letterSpacing: '0.04em',
        whiteSpace: 'nowrap'
      }
    }, d.ref), /*#__PURE__*/React.createElement("span", {
      style: {
        flex: 1,
        minWidth: 0,
        fontFamily: T.fontBody,
        fontSize: 12.5,
        color: T.fg1,
        overflow: 'hidden',
        textOverflow: 'ellipsis',
        whiteSpace: 'nowrap'
      }
    }, d.name), /*#__PURE__*/React.createElement("span", {
      style: {
        padding: '2px 8px',
        background: "".concat(stand.k, "1a"),
        border: "1px solid ".concat(stand.k, "59"),
        borderRadius: 3,
        fontFamily: T.fontBody,
        fontSize: 10,
        fontWeight: 700,
        color: stand.k,
        whiteSpace: 'nowrap'
      }
    }, stand.l));
  })), doel && /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      alignItems: 'flex-start',
      gap: 10,
      padding: '11px 13px',
      background: 'rgba(255,176,32,0.08)',
      border: '1px solid rgba(255,176,32,0.45)',
      clipPath: cutPath(7),
      marginBottom: 14
    }
  }, /*#__PURE__*/React.createElement(Icon, {
    name: "info",
    size: 15,
    color: "#ffb020"
  }), /*#__PURE__*/React.createElement("span", {
    style: {
      fontFamily: T.fontBody,
      fontSize: 11.5,
      color: T.fg2,
      lineHeight: 1.55
    }
  }, slots.length === 1 ? 'Het moment' : "Alle ".concat(slots.length, " momenten"), " en ", voortgang.klaar === 1 ? 'de werkbon' : "".concat(voortgang.klaar || 'de', " werkbonnen"), " verhuizen naar ", /*#__PURE__*/React.createElement("b", {
    style: {
      color: T.fg1
    }
  }, doel.ref), ". Het losse dossier ", item.dealRef, " verdwijnt. ", doel.won && ' Dat dossier is al gewonnen — de facturatie telt dit werk voortaan mee.', /*#__PURE__*/React.createElement("br", null), "Terugdraaien kan met ", /*#__PURE__*/React.createElement("b", {
    style: {
      color: T.fg2
    }
  }, "Ongedaan maken"), " in de topbalk.")), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      gap: 8,
      justifyContent: 'flex-end'
    }
  }, /*#__PURE__*/React.createElement(Button, {
    variant: "ghost",
    onClick: onClose
  }, "Annuleren"), /*#__PURE__*/React.createElement(Button, {
    variant: "primary",
    icon: "link",
    disabled: !keuze,
    onClick: koppel
  }, "Koppelen aan ", keuze || 'offerte')));
};
var PlanListRow = function PlanListRow(_ref13) {
  var item = _ref13.item,
    onOpen = _ref13.onOpen,
    onPlan = _ref13.onPlan,
    onPlanSlot = _ref13.onPlanSlot,
    onPlanExtra = _ref13.onPlanExtra,
    onDone = _ref13.onDone,
    onReopen = _ref13.onReopen,
    _onDragStart2 = _ref13.onDragStart,
    onDragEnd = _ref13.onDragEnd;
  var slots = item.slots || [];
  var _React$useState27 = React.useState(false),
    _React$useState28 = _slicedToArray(_React$useState27, 2),
    docsOpen = _React$useState28[0],
    setDocsOpen = _React$useState28[1];
  var _React$useState29 = React.useState(null),
    _React$useState30 = _slicedToArray(_React$useState29, 2),
    koppel = _React$useState30[0],
    setKoppel = _React$useState30[1];
  var momOpen = true;
  var docCount = docsOpen ? plDocCount(item._cid) : null;
  var stripes = slots.map(function (s) {
    return plWork(s.work).color;
  });
  var open = momOpen || docsOpen;
  /* Zolang er iets openstaat vormen rij en panelen één kaart: geen tussenranden,
     dezelfde ondergrond, en de werkkleur-rail loopt door tot onderaan. */
  var railBreedte = 4 * Math.max(1, stripes.length);
  var overdue = item.status !== 'uitgevoerd' && slots.some(function (s) {
    return s.date && s.date < plToday() && !((item.bonnen || {})[s.id] || {}).installed;
  });
  /* Datum voorbij en niet uitgevoerd: geen rode sluier over de tekst (die wordt onleesbaar),
     maar een dieper, bijna zwart-rood vlak en een volle rode rail links. */
  var rijBg = overdue ? "linear-gradient(90deg, #170604 0%, #170604 42%, ".concat(T.bg1, " 100%)") : T.bg1;
  var rijBgHover = overdue ? "linear-gradient(90deg, #210a07 0%, #210a07 42%, ".concat(T.bg2, " 100%)") : T.bg2;
  var railKleuren = overdue ? ['#e0362a'] : stripes.length ? stripes : [T.stroke2];
  var paneel = {
    position: 'relative',
    background: rijBg,
    borderTop: "1px solid ".concat(overdue ? 'rgba(224,54,42,0.34)' : T.stroke1),
    padding: '13px 22px 15px ' + (22 + railBreedte) + 'px'
  };
  var rail = /*#__PURE__*/React.createElement("div", {
    "aria-hidden": "true",
    style: {
      position: 'absolute',
      left: 0,
      top: 0,
      bottom: 0,
      width: railBreedte,
      display: 'flex',
      opacity: overdue ? 1 : 0.45,
      pointerEvents: 'none'
    }
  }, railKleuren.map(function (c, i) {
    return /*#__PURE__*/React.createElement("div", {
      key: i,
      style: {
        flex: 1,
        background: c
      }
    });
  }));
  var btn = function btn(color, bg, border) {
    return {
      display: 'inline-flex',
      alignItems: 'center',
      justifyContent: 'center',
      gap: 6,
      height: 30,
      padding: '0 11px',
      background: bg,
      border: "1px solid ".concat(border),
      clipPath: cutPath(6),
      cursor: 'pointer',
      color: color,
      fontFamily: T.fontBody,
      fontSize: 10.5,
      fontWeight: 700,
      whiteSpace: 'nowrap',
      transition: 'all 140ms'
    };
  };
  var lucht = function lucht(zijde) {
    return /*#__PURE__*/React.createElement("div", {
      "aria-hidden": "true",
      style: _defineProperty({
        height: 15,
        background: T.bg0
      }, zijde === 'boven' ? 'borderBottom' : 'borderTop', "1px solid ".concat(T.stroke2))
    });
  };
  return /*#__PURE__*/React.createElement(React.Fragment, null, open && lucht('boven'), /*#__PURE__*/React.createElement("div", {
    "data-ghs-row": item._cid,
    "data-ghs-rij": "",
    draggable: true,
    onDragStart: function onDragStart(e) {
      e.dataTransfer.effectAllowed = 'move';
      _onDragStart2(item);
    },
    onDragEnd: onDragEnd,
    onClick: function onClick() {
      return onOpen(item);
    },
    className: "k-row",
    style: {
      position: 'relative',
      display: 'grid',
      gridTemplateColumns: PLAN_AUTO_GRID,
      alignItems: 'center',
      gap: 16,
      padding: '15px 22px 15px ' + (18 + 4 * stripes.length) + 'px',
      background: rijBg,
      borderBottom: open ? 'none' : "1px solid ".concat(overdue ? 'rgba(224,54,42,0.34)' : T.stroke1)
    },
    onMouseEnter: function onMouseEnter(e) {
      return e.currentTarget.style.background = rijBgHover;
    },
    onMouseLeave: function onMouseLeave(e) {
      return e.currentTarget.style.background = rijBg;
    }
  }, /*#__PURE__*/React.createElement("div", {
    title: overdue ? 'Datum voorbij — nog niet uitgevoerd' : slots.map(function (s) {
      return plWork(s.work).label;
    }).join(' · '),
    style: {
      position: 'absolute',
      left: 0,
      top: 0,
      bottom: 0,
      width: railBreedte,
      display: 'flex'
    }
  }, railKleuren.map(function (c, i) {
    return /*#__PURE__*/React.createElement("div", {
      key: i,
      style: {
        flex: 1,
        background: c
      }
    });
  })), function () {
    var sinds = item.dagenSinds || (item.installedAt ? String(item.installedAt).slice(0, 10) : item.date || item.slot && item.slot.date || null);
    var dagen = sinds && window.ghsDagenSinds ? window.ghsDagenSinds(sinds) : null;
    var open = (item.voortgang || {}).open;
    return /*#__PURE__*/React.createElement(window.GhsDagenCel, {
      dagen: dagen,
      sinds: sinds && window.dCrmIsoToNL ? dCrmIsoToNL(sinds) : null,
      extra: open ? 'sinds het oudste open moment' : item.installedAt ? 'sinds de uitvoering' : item.date ? 'sinds de ingeplande datum' : 'nog niet ingepland'
    });
  }(), /*#__PURE__*/React.createElement("div", {
    style: {
      fontFamily: T.fontBody,
      fontSize: 11,
      fontWeight: 700,
      color: T.fg3,
      letterSpacing: '0.04em',
      overflow: 'hidden',
      textOverflow: 'ellipsis',
      whiteSpace: 'nowrap'
    }
  }, item.dealRef || item.nr, item.los && /*#__PURE__*/React.createElement("span", {
    title: "Los werk zonder offerte \u2014 kan achteraf aan een offerte gekoppeld worden",
    style: {
      display: 'block',
      marginTop: 3,
      fontSize: 9,
      fontWeight: 700,
      letterSpacing: '0.1em',
      color: '#8f9c88'
    }
  }, "LOS WERK")), /*#__PURE__*/React.createElement("div", {
    style: {
      minWidth: 0
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      fontFamily: T.fontBody,
      fontSize: 13.5,
      fontWeight: 700,
      color: T.fg1,
      lineHeight: 1.35,
      overflow: 'hidden',
      textOverflow: 'ellipsis',
      whiteSpace: 'nowrap'
    }
  }, item.client), /*#__PURE__*/React.createElement("div", {
    style: {
      fontFamily: T.fontBody,
      fontSize: 11.5,
      color: T.fg3,
      lineHeight: 1.4,
      marginTop: 1,
      overflow: 'hidden',
      textOverflow: 'ellipsis',
      whiteSpace: 'nowrap'
    }
  }, item.address)), /*#__PURE__*/React.createElement("div", {
    style: {
      minWidth: 0,
      display: 'flex',
      alignItems: 'center',
      gap: 6
    }
  }, /*#__PURE__*/React.createElement("span", {
    title: item.werkOms || item.dealName,
    style: {
      fontFamily: T.fontBody,
      fontSize: 11.5,
      color: T.fg2,
      overflow: 'hidden',
      textOverflow: 'ellipsis',
      whiteSpace: 'nowrap'
    }
  }, item.werkOms || item.dealName)), /*#__PURE__*/React.createElement("div", {
    style: {
      minWidth: 0,
      display: 'flex',
      flexDirection: 'column',
      gap: 3
    }
  }, slots.length === 0 ? /*#__PURE__*/React.createElement("span", {
    style: {
      fontFamily: T.fontBody,
      fontSize: 11.5,
      color: '#ffb020',
      fontWeight: 600
    }
  }, "Nog geen moment ingepland") : slots.map(function (s, si) {
    var b = (item.bonnen || {})[s.id] || {};
    var st = b.werkbon ? 'bon' : b.installed ? 'uit' : 'plan';
    var kl = st === 'bon' ? T.accent : st === 'uit' ? '#ffb020' : plWork(s.work).color;
    var laat = !b.installed && s.date && s.date < plToday();
    return /*#__PURE__*/React.createElement("span", {
      key: s.id,
      title: "Moment ".concat(si + 1, " van ").concat(slots.length, " \xB7 ").concat(plWork(s.work).label, " \xB7 ").concat(st === 'bon' ? 'werkbon ' + b.werkbon.nr : st === 'uit' ? 'uitgevoerd, werkbon nog op te maken' : laat ? 'datum voorbij, nog niet gemeld' : 'nog uit te voeren'),
      style: {
        display: 'flex',
        alignItems: 'center',
        gap: 6,
        fontFamily: T.fontBody,
        fontSize: 11.5,
        color: laat ? '#ff5a4d' : st === 'bon' ? T.fg3 : T.fg2,
        whiteSpace: 'nowrap'
      }
    }, /*#__PURE__*/React.createElement("span", {
      style: {
        width: 7,
        height: 7,
        borderRadius: '50%',
        background: st === 'plan' ? 'transparent' : kl,
        border: "1.5px solid ".concat(kl),
        flex: 'none'
      }
    }), s.date ? new Date(s.date + 'T00:00:00').toLocaleDateString('nl-BE', {
      day: 'numeric',
      month: 'short'
    }) : '—', s.start ? ' · ' + s.start : '', slots.length > 1 && /*#__PURE__*/React.createElement("span", {
      style: {
        fontSize: 9.5,
        fontWeight: 700,
        color: T.fg4
      }
    }, si + 1, "/", slots.length));
  }), slots.length > 1 && /*#__PURE__*/React.createElement("span", {
    style: {
      fontFamily: T.fontBody,
      fontSize: 10,
      fontWeight: 700,
      color: item.voortgang.compleet ? T.accent : '#ffb020',
      marginTop: 1
    }
  }, item.voortgang.klaar, "/", item.voortgang.totaal, " werkbonnen klaar")), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      alignItems: 'center',
      gap: 6,
      minWidth: 0
    }
  }, item.crew && item.crew.length > 0 ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Icon, {
    name: "users",
    size: 12,
    color: T.fg4
  }), /*#__PURE__*/React.createElement("span", {
    style: {
      fontSize: 11.5,
      color: T.fg2,
      fontFamily: T.fontBody,
      overflow: 'hidden',
      textOverflow: 'ellipsis',
      whiteSpace: 'nowrap'
    }
  }, item.crew.map(function (x) {
    return typeof x === 'string' ? plCrewName(x) : x.name || plCrewName(x.id);
  }).filter(Boolean).join(', '))) : /*#__PURE__*/React.createElement("span", {
    style: {
      fontSize: 11,
      color: item.status === 'te_plannen' ? '#ffb020' : T.fg4,
      fontFamily: T.fontBody,
      fontWeight: item.status === 'te_plannen' ? 600 : 400
    }
  }, item.status === 'te_plannen' ? 'Nog geen ploeg' : '—')), function () {
    var ct = window.crmStore ? (window.crmStore.getState().contacts || []).find(function (x) {
      return x.id === item._cid;
    }) : null;
    var statussen = ct && window.planStatusVoorDossier ? window.planStatusVoorDossier(ct, item.dealRef) : [];
    var nieuw = ct && window.planKlantNieuw ? window.planKlantNieuw(ct, item.dealRef) : 0;
    return /*#__PURE__*/React.createElement(window.GhsStatusCel, {
      statussen: statussen,
      nieuw: nieuw,
      onGelezen: function onGelezen() {
        return window.crmStore.markPlanBerichtenGelezen(item._cid, item.dealRef);
      }
    });
  }(), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      alignItems: 'center',
      justifyContent: 'flex-end',
      gap: 6,
      flexWrap: 'wrap-reverse'
    },
    onClick: function onClick(e) {
      return e.stopPropagation();
    }
  }, window.ghsKnopVolgorde([/*#__PURE__*/React.createElement("button", {
    key: "docs",
    title: "Documenten van dit contact \u2014 offertes, opmeting, werkbon, factuur",
    onClick: function onClick() {
      return setDocsOpen(function (v) {
        return !v;
      });
    },
    style: _objectSpread(_objectSpread({}, btn(docsOpen ? T.accent : T.fg2, docsOpen ? 'rgba(0,217,0,0.12)' : 'transparent', docsOpen ? 'rgba(0,217,0,0.3)' : T.stroke1)), {}, {
      padding: '0 9px'
    })
  }, /*#__PURE__*/React.createElement(Icon, {
    name: "file",
    size: 12,
    color: "currentColor"
  }), "Docs", /*#__PURE__*/React.createElement(Icon, {
    name: docsOpen ? 'chevronup' : 'chevrondown',
    size: 11,
    color: "currentColor"
  })),
  /* Inplannen hoort bij het moment: die knop staat in de momentenstrip eronder,
     dus hier alleen 'Extra moment' zodra er al iets gepland is. */
  item.status !== 'te_plannen' && /*#__PURE__*/React.createElement(Button, {
    key: "extra",
    variant: "beige",
    size: "sm",
    icon: "plus",
    onClick: function onClick() {
      return (onPlanExtra || onPlan)(item);
    }
  }, "Extra moment"), /* Los werk hoort soms toch bij een bestaand dossier — ook bij een afgewerkt. */
  item.los && /*#__PURE__*/React.createElement(Button, {
    key: "koppel",
    variant: "ghost",
    size: "sm",
    icon: "link",
    onClick: function onClick() {
      return setKoppel(item);
    }
  }, "Koppelen aan offerte"), /* Naar facturatie hoort bij het dossier, dus pas als élke werkbon klaar is */
  slots.length > 0 && item.voortgang.compleet && !(item.fs && (item.fs.sentISO || item.fs.status)) && /*#__PURE__*/React.createElement(Button, {
    key: "fact",
    variant: "beige",
    size: "sm",
    icon: "wallet",
    onClick: function onClick() {
      return window.crmStore.openFiche(item._cid, 'werkbonnen');
    }
  }, "Naar facturatie")], 'flex-end')), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      justifyContent: 'flex-end'
    },
    onClick: function onClick(e) {
      return e.stopPropagation();
    }
  }, /*#__PURE__*/React.createElement(PlanDeleteBtn, {
    item: item
  }))), momOpen && /*#__PURE__*/React.createElement("div", {
    style: paneel
  }, rail, /*#__PURE__*/React.createElement(window.GhsMomentKop, {
    klaar: item.voortgang.klaar,
    totaal: item.voortgang.totaal,
    titel: "Installatiemomenten \u2014 ".concat(item.client)
  }), slots.length === 0 ? /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      justifyContent: 'flex-end',
      padding: '2px 0 0'
    }
  }, item.vsWacht && window.GhsVoorschotWacht ? /*#__PURE__*/React.createElement(window.GhsVoorschotWacht, {
    w: item.vsWacht,
    cid: item._cid
  }) : /*#__PURE__*/React.createElement(Button, {
    variant: "primary",
    size: "sm",
    icon: "calendar",
    onClick: function onClick() {
      return onPlan(item);
    }
  }, "Werk inplannen")) : /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      flexDirection: 'column',
      gap: 8
    }
  }, slots.map(function (s, si) {
    return /*#__PURE__*/React.createElement(window.GhsMomentRij, {
      key: s.id,
      slot: s,
      index: si,
      total: slots.length,
      bon: (item.bonnen || {})[s.id] || {},
      vandaag: plToday(),
      onUitgevoerd: function onUitgevoerd() {
        return window.crmStore.markInstalled(item._cid, item.dealRef, s.id);
      },
      onWerkbon: function onWerkbon() {
        return window.ghsOpenWerkbonEditor ? window.ghsOpenWerkbonEditor(item._cid, item.dealRef, s.id) : window.crmStore.openFiche(item._cid, 'werkbonnen');
      },
      onBewerken: onPlanSlot ? function () {
        return onPlanSlot(item, s);
      } : null,
      onMail: function onMail() {
        return window.ghsMailNaarBlok && window.ghsMailNaarBlok('installatie_gepland', item._cid, item.dealRef, {
          slotId: s.id,
          slotIds: [s.id]
        });
      },
      onHeropenen: ((item.bonnen || {})[s.id] || {}).werkbon && item.fs && (item.fs.sentISO || item.fs.status) ? null : function () {
        /* Terugzetten wist de bon, dus het nazicht van dit dossier vervalt mee. */
        window.crmStore.setWerkbonStatus(item._cid, item.dealRef, 'ingepland', s.id);
        window.crmStore.zetWerkbonNazicht(item._cid, item.dealRef, false);
      },
      onVerwijder: function onVerwijder() {
        return window.crmStore.removePlanningSlot(item._cid, item.dealRef, s.id);
      }
    });
  }))), docsOpen && /*#__PURE__*/React.createElement("div", {
    style: paneel
  }, rail, /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      alignItems: 'center',
      gap: 7,
      marginBottom: 8
    }
  }, /*#__PURE__*/React.createElement("span", {
    style: {
      fontFamily: T.fontBody,
      fontSize: 9.5,
      fontWeight: 700,
      letterSpacing: '0.12em',
      textTransform: 'uppercase',
      color: T.fg4
    }
  }, "Documenten \u2014 ", item.client), /*#__PURE__*/React.createElement("span", {
    style: {
      fontFamily: T.fontBody,
      fontSize: 10.5,
      color: T.fg4
    }
  }, docCount, " bestand", docCount === 1 ? '' : 'en')), /*#__PURE__*/React.createElement(PlDocsPanel, {
    cid: item._cid,
    onOpenFiche: function onOpenFiche() {
      return onOpen(item);
    }
  })), open && lucht('onder'), koppel && /*#__PURE__*/React.createElement(PlKoppelModal, {
    item: koppel,
    onClose: function onClose() {
      return setKoppel(null);
    }
  }));
};

/* ── Documenten van een contact — offertes, opmeting, werkbon, factuur ───── */
var plContactDocs = function plContactDocs(cid) {
  var c = (window.crmStore.getState().contacts || []).find(function (x) {
    return x.id === cid;
  });
  if (!c) return [];
  var groups = [];
  var offertes = [];
  (c.deals || []).forEach(function (d) {
    var extra = ((c.dealDocs || {})[d.ref] || []).map(function (x) {
      return typeof x === 'string' ? x : x.name;
    });
    [].concat(_toConsumableArray(d.docs || []), _toConsumableArray(extra)).forEach(function (n) {
      return offertes.push({
        name: n,
        meta: "".concat(d.ref, " \xB7 ").concat(d.name),
        tag: d.won ? 'Gewonnen' : 'Offerte'
      });
    });
  });
  if (offertes.length) groups.push({
    id: 'off',
    label: 'Offertes & deals',
    icon: 'file',
    color: '#ffb020',
    docs: offertes
  });
  var opm = [];
  (c.opmetingen || []).forEach(function (o) {
    return (o.docs || []).forEach(function (d) {
      return opm.push({
        name: d.name || d,
        meta: "".concat(o.nr || 'Opmeting').concat(d.size ? ' · ' + d.size : ''),
        tag: 'Opmeting'
      });
    });
  });
  if (opm.length) groups.push({
    id: 'opm',
    label: 'Opmeting',
    icon: 'clipboard',
    color: '#00aaff',
    docs: opm
  });
  var wb = [];
  Object.entries(c.werkbonState || {}).forEach(function (_ref15) {
    var _ref16 = _slicedToArray(_ref15, 2),
      ref = _ref16[0],
      st = _ref16[1];
    if (st.werkbon) wb.push({
      name: "".concat(st.werkbon.nr, ".pdf"),
      meta: "".concat(ref, " \xB7 ").concat(st.werkbon.date),
      tag: 'Werkbon'
    });
  });
  if (wb.length) groups.push({
    id: 'wb',
    label: 'Werkbonnen',
    icon: 'clipboard',
    color: T.accent,
    docs: wb
  });
  var fac = [];
  Object.entries(c.facturatieState || {}).forEach(function (_ref17) {
    var _ref18 = _slicedToArray(_ref17, 2),
      ref = _ref18[0],
      f = _ref18[1];
    if (f.factuurNr) fac.push({
      name: "".concat(f.factuurNr, ".pdf"),
      meta: "".concat(ref, " \xB7 ").concat(f.factuurDate || '', " \xB7 ").concat(f.status || ''),
      tag: 'Factuur'
    });
  });
  if (fac.length) groups.push({
    id: 'fac',
    label: 'Facturatie',
    icon: 'euro',
    color: '#bf63ff',
    docs: fac
  });
  return groups;
};
var plDocCount = function plDocCount(cid) {
  return plContactDocs(cid).reduce(function (a, g) {
    return a + g.docs.length;
  }, 0);
};

/* Documentregel met voorbeeldvenster — zelfde gedrag als in de contactfiche. */
var PlDocRow = function PlDocRow(_ref19) {
  var name = _ref19.name,
    meta = _ref19.meta,
    color = _ref19.color,
    client = _ref19.client,
    cid = _ref19.cid;
  var _React$useState31 = React.useState(false),
    _React$useState32 = _slicedToArray(_React$useState31, 2),
    preview = _React$useState32[0],
    setPreview = _React$useState32[1];
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
    onClick: function onClick(e) {
      e.stopPropagation();
      if (window.ghsDock) window.ghsDock.openDoc({
        name: name,
        meta: meta,
        client: client,
        cid: cid
      });else setPreview(true);
    },
    title: "Klik om een voorbeeld te bekijken",
    style: {
      display: 'flex',
      alignItems: 'center',
      gap: 8,
      padding: '6px 10px',
      background: T.bg1,
      border: "1px solid ".concat(T.stroke1),
      borderRadius: 5,
      cursor: 'pointer'
    },
    onMouseEnter: function onMouseEnter(e) {
      e.currentTarget.style.borderColor = T.stroke2;
      e.currentTarget.style.background = T.bg2;
    },
    onMouseLeave: function onMouseLeave(e) {
      e.currentTarget.style.borderColor = T.stroke1;
      e.currentTarget.style.background = T.bg1;
    }
  }, /*#__PURE__*/React.createElement(Icon, {
    name: "file",
    size: 12,
    color: color || T.accent
  }), /*#__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'
    }
  }, name), meta && /*#__PURE__*/React.createElement("div", {
    style: {
      fontFamily: T.fontBody,
      fontSize: 10,
      color: T.fg4,
      overflow: 'hidden',
      textOverflow: 'ellipsis',
      whiteSpace: 'nowrap'
    }
  }, meta)), /*#__PURE__*/React.createElement(Icon, {
    name: "eye",
    size: 12,
    color: T.fg4
  })), preview && window.DocPreviewModal && /*#__PURE__*/React.createElement(window.DocPreviewModal, {
    name: name,
    meta: meta,
    onClose: function onClose() {
      return setPreview(false);
    }
  }));
};
var PlDocsPanel = function PlDocsPanel(_ref20) {
  var cid = _ref20.cid,
    onOpenFiche = _ref20.onOpenFiche,
    compact = _ref20.compact;
  var groups = plContactDocs(cid);
  var plClient = function () {
    try {
      var c = window.crmStore.getState().contacts.find(function (x) {
        return x.id === cid;
      });
      return c ? "".concat(c.firstName, " ").concat(c.lastName) : null;
    } catch (e) {
      return null;
    }
  }();
  if (!groups.length) return /*#__PURE__*/React.createElement("div", {
    style: {
      padding: '10px 0',
      fontFamily: T.fontBody,
      fontSize: 11.5,
      color: T.fg4
    }
  }, "Nog geen documenten gekoppeld aan dit contact.");
  return /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      flexDirection: 'column',
      gap: 9
    }
  }, groups.map(function (g) {
    return /*#__PURE__*/React.createElement("div", {
      key: g.id
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        alignItems: 'center',
        gap: 6,
        marginBottom: 5
      }
    }, /*#__PURE__*/React.createElement(Icon, {
      name: g.icon,
      size: 11,
      color: g.color
    }), /*#__PURE__*/React.createElement("span", {
      style: {
        fontFamily: T.fontBody,
        fontSize: 9.5,
        fontWeight: 700,
        letterSpacing: '0.12em',
        textTransform: 'uppercase',
        color: g.color
      }
    }, g.label), /*#__PURE__*/React.createElement("span", {
      style: {
        fontFamily: T.fontBody,
        fontSize: 10,
        color: T.fg4
      }
    }, g.docs.length)), /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'grid',
        gridTemplateColumns: compact ? '1fr' : '1fr 1fr',
        gap: 5
      }
    }, g.docs.map(function (d, i) {
      return /*#__PURE__*/React.createElement(PlDocRow, {
        key: g.id + i,
        name: d.name,
        meta: d.meta,
        color: g.color,
        client: plClient,
        cid: cid
      });
    })));
  }), onOpenFiche && /*#__PURE__*/React.createElement("button", {
    onClick: onOpenFiche,
    style: {
      alignSelf: 'flex-start',
      marginTop: 2,
      background: 'none',
      border: 'none',
      cursor: 'pointer',
      color: T.fg3,
      fontFamily: T.fontBody,
      fontSize: 11,
      display: 'flex',
      alignItems: 'center',
      gap: 5
    },
    onMouseEnter: function onMouseEnter(e) {
      return e.currentTarget.style.color = T.accent;
    },
    onMouseLeave: function onMouseLeave(e) {
      return e.currentTarget.style.color = T.fg3;
    }
  }, /*#__PURE__*/React.createElement(Icon, {
    name: "chevronright",
    size: 11,
    color: "currentColor"
  }), "Alles in de contactfiche openen"));
};

/* ── Stap 2 van 'Werk inplannen': kies de offerte (gewonnen deal) van dit contact ── */
var PlDealPicker = function PlDealPicker(_ref21) {
  var contact = _ref21.contact,
    items = _ref21.items,
    onCancel = _ref21.onCancel,
    _onSave = _ref21.onSave,
    onKies = _ref21.onKies;
  var _React$useState33 = React.useState(null),
    _React$useState34 = _slicedToArray(_React$useState33, 2),
    chosen = _React$useState34[0],
    setChosenRaw = _React$useState34[1];
  var _React$useState35 = React.useState(null),
    _React$useState36 = _slicedToArray(_React$useState35, 2),
    inspect = _React$useState36[0],
    setInspect = _React$useState36[1];
  var _React$useState37 = React.useState(false),
    _React$useState38 = _slicedToArray(_React$useState37, 2),
    showDocs = _React$useState38[0],
    setShowDocs = _React$useState38[1];
  var wonDeals = (contact.deals || []).filter(function (d) {
    return d.won;
  });
  var existing = items.filter(function (i) {
    return i._cid === contact.id;
  });
  var eur = function eur(n) {
    return '€ ' + Number(n || 0).toLocaleString('nl-BE', {
      maximumFractionDigits: 0
    });
  };
  var itemFor = function itemFor(d) {
    return existing.find(function (i) {
      return i.dealRef === d.ref;
    }) || {
      id: "".concat(contact.id, ":").concat(d.ref),
      _cid: contact.id,
      dealRef: d.ref,
      dealName: d.name,
      dealType: d.type,
      kwp: d.kwp || 0,
      kwh: d.kwh || 0,
      client: "".concat(contact.firstName, " ").concat(contact.lastName),
      address: contact.address,
      city: contact.city,
      verkoper: contact.verkoper,
      slot: null,
      slotId: null,
      date: null,
      start: null,
      end: null,
      crew: [],
      info: '',
      installed: false,
      werkbon: null,
      status: 'te_plannen'
    };
  };
  /* In de agenda plannen: een offerte kiezen opent meteen de planmodus. */
  var setChosen = function setChosen(d) {
    return d && onKies ? onKies(itemFor(d)) : setChosenRaw(d);
  };
  if (chosen) {
    var it = itemFor(chosen);
    return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        alignItems: 'center',
        gap: 10,
        padding: '9px 12px',
        background: T.bg2,
        border: "1px solid ".concat(T.stroke1),
        clipPath: cutPath(8),
        marginBottom: 12
      }
    }, /*#__PURE__*/React.createElement("button", {
      onClick: function onClick() {
        return setChosen(null);
      },
      style: {
        display: 'flex',
        alignItems: 'center',
        gap: 5,
        background: 'none',
        border: 'none',
        cursor: 'pointer',
        color: T.fg3,
        fontFamily: T.fontBody,
        fontSize: 11.5,
        fontWeight: 600
      },
      onMouseEnter: function onMouseEnter(e) {
        return e.currentTarget.style.color = T.accent;
      },
      onMouseLeave: function onMouseLeave(e) {
        return e.currentTarget.style.color = T.fg3;
      }
    }, "\u2190 Andere offerte"), /*#__PURE__*/React.createElement("span", {
      style: {
        width: 1,
        height: 16,
        background: T.stroke1
      }
    }), /*#__PURE__*/React.createElement("span", {
      style: {
        fontFamily: T.fontBody,
        fontSize: 12.5,
        fontWeight: 700,
        color: T.fg1
      }
    }, chosen.ref, " \u2014 ", chosen.name), chosen.kwp > 0 && /*#__PURE__*/React.createElement(Badge, {
      type: "accent"
    }, chosen.kwp, " kWp"), chosen.kwh > 0 && /*#__PURE__*/React.createElement(Badge, {
      type: "info"
    }, chosen.kwh, " kWh"), /*#__PURE__*/React.createElement("span", {
      style: {
        marginLeft: 'auto',
        fontFamily: T.fontBody,
        fontSize: 12,
        color: T.fg2
      }
    }, eur(chosen.total))), /*#__PURE__*/React.createElement(PlWerkPlanner, {
      item: it,
      title: "".concat(it.slotId ? 'Werk verplaatsen' : 'Werk inplannen', " \u2014 ").concat(it.client),
      onCancel: onCancel,
      onSave: function onSave(f) {
        return _onSave(it, f);
      }
    }));
  }
  return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      alignItems: 'center',
      gap: 11,
      padding: '11px 13px',
      background: T.bg2,
      border: "1px solid ".concat(T.stroke1),
      clipPath: cutPath(8),
      marginBottom: 12
    }
  }, /*#__PURE__*/React.createElement(Avatar, {
    name: "".concat(contact.firstName, " ").concat(contact.lastName),
    size: 32
  }), /*#__PURE__*/React.createElement("div", {
    style: {
      flex: 1,
      minWidth: 0
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      fontFamily: T.fontBody,
      fontSize: 13.5,
      fontWeight: 700,
      color: T.fg1
    }
  }, contact.firstName, " ", contact.lastName), /*#__PURE__*/React.createElement("div", {
    style: {
      fontFamily: T.fontBody,
      fontSize: 11.5,
      color: T.fg3
    }
  }, contact.address, " \xB7 ", contact.phone || '')), /*#__PURE__*/React.createElement("button", {
    onClick: function onClick() {
      return setShowDocs(function (v) {
        return !v;
      });
    },
    style: {
      display: 'inline-flex',
      alignItems: 'center',
      gap: 6,
      padding: '6px 11px',
      background: showDocs ? 'rgba(0,217,0,0.12)' : 'transparent',
      border: "1px solid ".concat(showDocs ? 'rgba(0,217,0,0.3)' : T.stroke1),
      borderRadius: 5,
      cursor: 'pointer',
      color: showDocs ? T.accent : T.fg2,
      fontFamily: T.fontBody,
      fontSize: 11,
      fontWeight: 700
    }
  }, /*#__PURE__*/React.createElement(Icon, {
    name: "file",
    size: 12,
    color: "currentColor"
  }), "Alle documenten", /*#__PURE__*/React.createElement(Icon, {
    name: showDocs ? 'chevronup' : 'chevrondown',
    size: 11,
    color: "currentColor"
  }))), showDocs && /*#__PURE__*/React.createElement("div", {
    style: {
      padding: '11px 13px',
      background: T.bg0,
      border: "1px solid ".concat(T.stroke1),
      clipPath: cutPath(8),
      marginBottom: 12
    }
  }, /*#__PURE__*/React.createElement(PlDocsPanel, {
    cid: contact.id
  })), /*#__PURE__*/React.createElement("div", {
    style: {
      fontFamily: T.fontBody,
      fontSize: 9.5,
      fontWeight: 700,
      letterSpacing: '0.12em',
      textTransform: 'uppercase',
      color: T.fg4,
      marginBottom: 7
    }
  }, "Gekoppelde offertes (", wonDeals.length, ")"), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      flexDirection: 'column',
      gap: 8
    }
  }, wonDeals.map(function (d) {
    var it = itemFor(d);
    var open = inspect === d.ref;
    var docs = [].concat(_toConsumableArray(d.docs || []), _toConsumableArray(((contact.dealDocs || {})[d.ref] || []).map(function (x) {
      return typeof x === 'string' ? x : x.name;
    })));
    return /*#__PURE__*/React.createElement("div", {
      key: d.ref,
      style: {
        background: T.bg2,
        border: "1px solid ".concat(open ? T.strokeAccent : T.stroke1),
        clipPath: cutPath(8),
        overflow: 'hidden'
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        alignItems: 'center',
        gap: 10,
        padding: '11px 13px'
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        flex: 1,
        minWidth: 0
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        alignItems: 'center',
        gap: 7,
        flexWrap: 'wrap'
      }
    }, /*#__PURE__*/React.createElement("span", {
      style: {
        fontFamily: T.fontBody,
        fontSize: 9.5,
        color: T.fg4,
        letterSpacing: '0.06em'
      }
    }, d.ref), /*#__PURE__*/React.createElement("span", {
      style: {
        fontFamily: T.fontBody,
        fontSize: 13,
        fontWeight: 700,
        color: T.fg1
      }
    }, d.name), /*#__PURE__*/React.createElement(Badge, {
      type: it.status === 'uitgevoerd' ? 'success' : it.status === 'ingepland' ? 'info' : 'warning',
      dot: true
    }, PLAN_LBL[it.status])), /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        alignItems: 'center',
        gap: 8,
        marginTop: 3,
        flexWrap: 'wrap'
      }
    }, d.kwp > 0 && /*#__PURE__*/React.createElement(Badge, {
      type: "accent"
    }, d.kwp, " kWp"), d.kwh > 0 && /*#__PURE__*/React.createElement(Badge, {
      type: "info"
    }, d.kwh, " kWh"), /*#__PURE__*/React.createElement("span", {
      style: {
        fontFamily: T.fontBody,
        fontSize: 11.5,
        color: T.fg2
      }
    }, eur(d.total), " incl. btw"), d.signedDate && /*#__PURE__*/React.createElement("span", {
      style: {
        fontFamily: T.fontBody,
        fontSize: 11,
        color: T.fg4
      }
    }, "getekend ", d.signedDate))), /*#__PURE__*/React.createElement("button", {
      onClick: function onClick() {
        return setInspect(open ? null : d.ref);
      },
      style: {
        display: 'inline-flex',
        alignItems: 'center',
        gap: 5,
        padding: '6px 11px',
        background: 'transparent',
        border: "1px solid ".concat(T.stroke1),
        borderRadius: 5,
        cursor: 'pointer',
        color: T.fg2,
        fontFamily: T.fontBody,
        fontSize: 11,
        fontWeight: 700,
        whiteSpace: 'nowrap'
      },
      onMouseEnter: function onMouseEnter(e) {
        e.currentTarget.style.borderColor = '#00aaff';
        e.currentTarget.style.color = '#00aaff';
      },
      onMouseLeave: function onMouseLeave(e) {
        e.currentTarget.style.borderColor = T.stroke1;
        e.currentTarget.style.color = T.fg2;
      }
    }, /*#__PURE__*/React.createElement(Icon, {
      name: "eye",
      size: 12,
      color: "currentColor"
    }), "Offerte nakijken", /*#__PURE__*/React.createElement(Icon, {
      name: open ? 'chevronup' : 'chevrondown',
      size: 11,
      color: "currentColor"
    })), it.status !== 'uitgevoerd' && window.dealVoorschotWacht && window.dealVoorschotWacht(contact, d) && window.GhsVoorschotWacht ? /*#__PURE__*/React.createElement(window.GhsVoorschotWacht, {
      w: window.dealVoorschotWacht(contact, d),
      cid: contact.id
    }) : it.status !== 'uitgevoerd' ? /*#__PURE__*/React.createElement("button", {
      onClick: function onClick() {
        return setChosen(d);
      },
      style: {
        display: 'inline-flex',
        alignItems: 'center',
        gap: 6,
        padding: '6px 12px',
        background: 'rgba(0,217,0,0.12)',
        border: '1px solid rgba(0,217,0,0.3)',
        borderRadius: 5,
        cursor: 'pointer',
        color: T.accent,
        fontFamily: T.fontBody,
        fontSize: 11,
        fontWeight: 700,
        whiteSpace: 'nowrap'
      },
      onMouseEnter: function onMouseEnter(e) {
        return e.currentTarget.style.background = 'rgba(0,217,0,0.22)';
      },
      onMouseLeave: function onMouseLeave(e) {
        return e.currentTarget.style.background = 'rgba(0,217,0,0.12)';
      }
    }, /*#__PURE__*/React.createElement(Icon, {
      name: "calendar",
      size: 12,
      color: T.accent
    }), it.slotId ? 'Extra moment' : 'Inplannen') : /*#__PURE__*/React.createElement("span", {
      style: {
        fontFamily: T.fontBody,
        fontSize: 11,
        color: T.fg4,
        whiteSpace: 'nowrap'
      }
    }, "Uitgevoerd")), open && /*#__PURE__*/React.createElement("div", {
      style: {
        padding: '11px 13px',
        background: T.bg0,
        borderTop: "1px solid ".concat(T.stroke1)
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'grid',
        gridTemplateColumns: 'repeat(auto-fit,minmax(170px,1fr))',
        gap: 8,
        marginBottom: 10
      }
    }, [['Type', d.type || '—'], ['Subtotaal', eur(d.subtotal)], ["Btw ".concat(d.btwPct != null ? d.btwPct + '%' : ''), eur(d.btw)], ['Totaal incl.', eur(d.total)]].map(function (_ref22) {
      var _ref23 = _slicedToArray(_ref22, 2),
        l = _ref23[0],
        v = _ref23[1];
      return /*#__PURE__*/React.createElement("div", {
        key: l,
        style: {
          padding: '8px 10px',
          background: T.bg1,
          border: "1px solid ".concat(T.stroke1),
          borderRadius: 5
        }
      }, /*#__PURE__*/React.createElement("div", {
        style: {
          fontFamily: T.fontBody,
          fontSize: 9.5,
          color: T.fg4,
          letterSpacing: '0.08em',
          textTransform: 'uppercase'
        }
      }, l), /*#__PURE__*/React.createElement("div", {
        style: {
          fontFamily: T.fontBody,
          fontSize: 12.5,
          fontWeight: 700,
          color: T.fg1,
          marginTop: 2
        }
      }, v));
    })), (d.items || []).length > 0 && /*#__PURE__*/React.createElement("div", {
      style: {
        marginBottom: 10
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        fontFamily: T.fontBody,
        fontSize: 9.5,
        fontWeight: 700,
        letterSpacing: '0.12em',
        textTransform: 'uppercase',
        color: T.fg4,
        marginBottom: 5
      }
    }, "Offertelijnen"), /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        flexDirection: 'column',
        gap: 3
      }
    }, d.items.map(function (ln, i) {
      return /*#__PURE__*/React.createElement("div", {
        key: i,
        style: {
          display: 'flex',
          alignItems: 'center',
          gap: 10,
          padding: '6px 10px',
          background: T.bg1,
          border: "1px solid ".concat(T.stroke1),
          borderRadius: 4
        }
      }, /*#__PURE__*/React.createElement("div", {
        style: {
          flex: 1,
          minWidth: 0
        }
      }, /*#__PURE__*/React.createElement("div", {
        style: {
          fontFamily: T.fontBody,
          fontSize: 11.5,
          color: T.fg1,
          overflow: 'hidden',
          textOverflow: 'ellipsis',
          whiteSpace: 'nowrap'
        }
      }, ln.label), ln.detail && /*#__PURE__*/React.createElement("div", {
        style: {
          fontFamily: T.fontBody,
          fontSize: 10,
          color: T.fg4,
          overflow: 'hidden',
          textOverflow: 'ellipsis',
          whiteSpace: 'nowrap'
        }
      }, ln.detail)), /*#__PURE__*/React.createElement("span", {
        style: {
          fontFamily: T.fontBody,
          fontSize: 11,
          color: T.fg3
        }
      }, ln.qty, "\xD7"), /*#__PURE__*/React.createElement("span", {
        style: {
          fontFamily: T.fontBody,
          fontSize: 11.5,
          color: T.fg2
        }
      }, eur(ln.amount)));
    }))), /*#__PURE__*/React.createElement("div", {
      style: {
        fontFamily: T.fontBody,
        fontSize: 9.5,
        fontWeight: 700,
        letterSpacing: '0.12em',
        textTransform: 'uppercase',
        color: T.fg4,
        marginBottom: 5
      }
    }, "Documenten bij deze offerte"), docs.length === 0 ? /*#__PURE__*/React.createElement("div", {
      style: {
        fontFamily: T.fontBody,
        fontSize: 11.5,
        color: T.fg4
      }
    }, "Geen documenten gekoppeld.") : /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'grid',
        gridTemplateColumns: '1fr 1fr',
        gap: 5
      }
    }, docs.map(function (n, i) {
      return /*#__PURE__*/React.createElement(PlDocRow, {
        key: i,
        name: n,
        meta: d.ref,
        color: "#ffb020",
        cid: contact && contact.id
      });
    }))));
  }), wonDeals.length === 0 && /*#__PURE__*/React.createElement("div", {
    style: {
      padding: '14px 0',
      textAlign: 'center',
      fontFamily: T.fontBody,
      fontSize: 12,
      color: T.fg4
    }
  }, "Geen gewonnen deals voor deze klant.")));
};

/* ── Suggestiescheiding — groene lijn met 'Suggestie op postcode N' ──────── */
var PlSuggestieDivider = function PlSuggestieDivider(_ref24) {
  var n = _ref24.n,
    region = _ref24.region,
    count = _ref24.count,
    maxKm = _ref24.maxKm;
  return /*#__PURE__*/React.createElement("div", {
    style: {
      margin: '10px 2px 8px'
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      alignItems: 'center',
      gap: 8
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      flex: 1,
      height: 1,
      background: 'rgba(0,217,0,0.45)'
    }
  }), /*#__PURE__*/React.createElement("span", {
    style: {
      fontFamily: T.fontBody,
      fontSize: 9,
      fontWeight: 700,
      letterSpacing: '0.1em',
      textTransform: 'uppercase',
      color: T.accent,
      whiteSpace: 'nowrap'
    }
  }, "Suggestie op postcode ", n), /*#__PURE__*/React.createElement("div", {
    style: {
      flex: 1,
      height: 1,
      background: 'rgba(0,217,0,0.45)'
    }
  })), /*#__PURE__*/React.createElement("div", {
    style: {
      textAlign: 'center',
      fontFamily: T.fontBody,
      fontSize: 9.5,
      color: T.fg4,
      marginTop: 2
    }
  }, region, " \xB7 ", count, " werven \xB7 max \xB1", maxKm, " km"));
};

/* ── Dagscheiding — groepeert de lijst per installatiedag ──────────────────── */
var plDayInfo = function plDayInfo(iso) {
  if (!iso) return {
    dag: 'Nog geen datum',
    datum: '',
    rel: null,
    kleur: '#ffb020'
  };
  var d = new Date(iso + 'T00:00:00');
  var verschil = Math.round((d - new Date(plToday() + 'T00:00:00')) / 864e5);
  var rel = verschil === 0 ? 'vandaag' : verschil === 1 ? 'morgen' : verschil === -1 ? 'gisteren' : verschil > 1 ? "over ".concat(verschil, " dagen") : "".concat(Math.abs(verschil), " dagen geleden");
  return {
    dag: d.toLocaleDateString('nl-BE', {
      weekday: 'long'
    }),
    datum: d.toLocaleDateString('nl-BE', {
      day: 'numeric',
      month: 'long',
      year: 'numeric'
    }),
    rel: rel,
    verschil: verschil,
    kleur: verschil === 0 ? T.accent : verschil < 0 ? T.fg4 : '#00aaff'
  };
};
var PlDayDivider = function PlDayDivider(_ref25) {
  var iso = _ref25.iso,
    count = _ref25.count,
    compact = _ref25.compact;
  return !iso || iso === '—' ? /*#__PURE__*/React.createElement(window.GhsBlokKop, {
    kleur: "#ffb020",
    titel: "Nog niet ingepland",
    icon: "clock",
    pil: "".concat(count, " te plannen"),
    compact: compact
  }) : /*#__PURE__*/React.createElement(window.GhsDagDivider, {
    iso: iso,
    count: count,
    eenheid: "werf",
    eenheidMv: "werven",
    compact: compact
  });
};
/* Rijen met een dagscheiding ertussen, telkens de datum wisselt. */
var plWithDays = function plWithDays(list) {
  var out = [];
  var vorige = "\0";
  var tel = {};
  list.forEach(function (i) {
    var k = i.date || '';
    tel[k] = (tel[k] || 0) + 1;
  });
  list.forEach(function (i, idx) {
    var k = i.date || '';
    if (k !== vorige) {
      out.push({
        kind: 'day',
        key: 'day' + idx + '-' + k,
        iso: i.date || null,
        count: tel[k]
      });
      vorige = k;
    }
    out.push({
      kind: 'item',
      key: i.id,
      item: i
    });
  });
  return out;
};
var PlRestDivider = function PlRestDivider(_ref26) {
  var count = _ref26.count;
  return /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      alignItems: 'center',
      gap: 8,
      margin: '12px 2px 8px',
      gridColumn: '1/-1'
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      flex: 1,
      height: 1,
      background: T.stroke1
    }
  }), /*#__PURE__*/React.createElement("span", {
    style: {
      fontFamily: T.fontBody,
      fontSize: 9,
      fontWeight: 700,
      letterSpacing: '0.1em',
      textTransform: 'uppercase',
      color: T.fg4,
      whiteSpace: 'nowrap'
    }
  }, "Overige werven \xB7 ", count), /*#__PURE__*/React.createElement("div", {
    style: {
      flex: 1,
      height: 1,
      background: T.stroke1
    }
  }));
};

/* Kaarten in suggestievolgorde: gegroepeerde werven eerst (op nabijheid), daarna de rest. */
var plOrderBySuggestion = function plOrderBySuggestion(colItems, groups, byDate) {
  var rows = [];
  var seen = new Set();
  groups.forEach(function (g, gi) {
    var members = colItems.filter(function (i) {
      return g.items.some(function (m) {
        return m.id === i.id;
      });
    }).sort(byDate);
    if (!members.length) return;
    rows.push({
      kind: 'div',
      key: 'd' + gi,
      n: gi + 1,
      region: g.region,
      count: members.length,
      maxKm: g.maxKm
    });
    members.forEach(function (i) {
      rows.push({
        kind: 'item',
        key: i.id,
        item: i,
        n: gi + 1,
        region: g.region
      });
      seen.add(i.id);
    });
  });
  var rest = colItems.filter(function (i) {
    return !seen.has(i.id);
  }).sort(byDate);
  if (rest.length && rows.length) rows.push({
    kind: 'rest',
    key: 'rest',
    count: rest.length
  });
  rest.forEach(function (i) {
    return rows.push({
      kind: 'item',
      key: i.id,
      item: i,
      n: null
    });
  });
  return rows;
};

/* ── Agenda-view — zelfde opbouw als de opmetingsagenda ──────────────────── */
var PlanAgendaView = function PlanAgendaView(_ref27) {
  var items = _ref27.items,
    onPlan = _ref27.onPlan,
    onOpen = _ref27.onOpen,
    groups = _ref27.groups;
  var _React$useState39 = React.useState(plToday()),
    _React$useState40 = _slicedToArray(_React$useState39, 2),
    base = _React$useState40[0],
    setBase = _React$useState40[1];
  var _React$useState41 = React.useState(null),
    _React$useState42 = _slicedToArray(_React$useState41, 2),
    planning = _React$useState42[0],
    setPlanning = _React$useState42[1];
  var _React$useState43 = React.useState({
      date: '',
      start: '',
      end: '',
      crew: [],
      work: null,
      info: ''
    }),
    _React$useState44 = _slicedToArray(_React$useState43, 2),
    pForm = _React$useState44[0],
    setPForm = _React$useState44[1];
  // Inplannen start hier: de velden vouwen uit het gekozen tijdvak in de agenda.
  var startPlan = function startPlan(item, slot) {
    var s = slot || null;
    if (!s && window.ghsVoorschotPoort && !window.ghsVoorschotPoort(item._cid, item.dealRef)) return;
    setPlanning(s ? _objectSpread(_objectSpread({}, item), {}, {
      slot: s,
      slotId: s.id
    }) : _objectSpread(_objectSpread({}, item), {}, {
      slot: null,
      slotId: null
    }));
    setPForm({
      date: s ? s.date : '',
      start: s ? s.start || '' : '',
      end: s ? s.end || '' : '',
      crew: window.ghsCrewIds ? window.ghsCrewIds(s ? s.crew : item.crew) : s ? s.crew || [] : item.crew || [],
      work: s ? s.work : item.dealType === 'airco' ? 'airco' : null,
      info: s ? s.info || '' : ''
    });
    if (s && s.date) setBase(s.date);
  };
  var cancelPlan = function cancelPlan() {
    setPlanning(null);
    setPForm({
      date: '',
      start: '',
      end: '',
      crew: [],
      work: null,
      info: ''
    });
  };
  var pickSlot = function pickSlot(date, start, end) {
    setPForm(function (f) {
      return _objectSpread(_objectSpread({}, f), {}, {
        date: date,
        start: start,
        end: end
      });
    });
    setBase(date);
  };
  /* Zonder ploeg reserveer je het tijdvak; met ploeg plan je het in. */
  var pCan = !!(planning && pForm.date && pForm.start && pForm.end && pForm.work);
  var savePlanning = function savePlanning() {
    if (!pCan) return;
    onPlan(planning, _objectSpread(_objectSpread({}, pForm), {}, {
      slotId: planning.slotId || null
    }));
    cancelPlan();
  };
  var pFld = {
    background: T.bg2,
    border: "1px solid ".concat(T.stroke1),
    borderRadius: 5,
    padding: '8px 10px',
    color: T.fg1,
    fontFamily: T.fontBody,
    fontSize: 12.5,
    outline: 'none',
    width: '100%',
    boxSizing: 'border-box'
  };
  var pLbl = {
    fontFamily: T.fontBody,
    fontSize: 9,
    fontWeight: 700,
    letterSpacing: '0.12em',
    textTransform: 'uppercase',
    color: T.fg3,
    marginBottom: 4,
    display: 'block'
  };
  var _React$useState45 = React.useState({}),
    _React$useState46 = _slicedToArray(_React$useState45, 2),
    crewOn = _React$useState46[0],
    setCrewOn = _React$useState46[1]; // leeg = iedereen tonen
  var _React$useState47 = React.useState({}),
    _React$useState48 = _slicedToArray(_React$useState47, 2),
    workOn = _React$useState48[0],
    setWorkOn = _React$useState48[1]; // leeg = alle soorten werk tonen
  var activeCrew = Object.keys(crewOn).filter(function (k) {
    return crewOn[k];
  });
  var activeWork = Object.keys(workOn).filter(function (k) {
    return workOn[k];
  });
  var ingepland = items.filter(function (i) {
    return i.status === 'ingepland';
  }).filter(function (i) {
    return activeCrew.length === 0 || i.crew.some(function (id) {
      return activeCrew.includes(id);
    });
  });
  var teplannen = items.filter(function (i) {
    return i.status === 'te_plannen';
  });
  // Één blok per ingepland moment — gekleurd volgens het soort werk.
  var gridItems = ingepland.flatMap(function (i) {
    return (i.slots || []).filter(function (s) {
      return activeWork.length === 0 || activeWork.includes(s.work || 'pv_hellend');
    }).filter(function (s) {
      return activeCrew.length === 0 || (window.ghsCrewIds ? window.ghsCrewIds(s.crew) : s.crew || []).some(function (id) {
        return activeCrew.includes(id);
      });
    }).filter(function (s) {
      return !planning || s.id !== planning.slotId;
    }).map(function (s) {
      var w = plWork(s.work);
      return {
        id: s.id,
        date: s.date,
        start: s.start || null,
        end: s.end || null,
        label: i.client,
        sub: "".concat(w["short"]).concat((s.crew || []).length ? ' · ' + plCrewNames(s.crew).map(function (n) {
          return n.split(' ')[0];
        }).join(', ') : ''),
        meta: [w.label].concat(_toConsumableArray(function () {
          var _String$split = String(s.adres || i.address || '').split(','),
            _String$split2 = _toArray(_String$split),
            str = _String$split2[0],
            gem = _arrayLikeToArray(_String$split2).slice(1);
          return [str, gem.join(',').trim() || "".concat(i.postcode || '', " ").concat(i.city || '')];
        }()), [(s.crew || []).length ? "Ploeg: ".concat(plCrewNames(s.crew).map(function (n) {
          return n.split(' ')[0];
        }).join(', ')) : 'Nog geen ploeg toegewezen', "".concat(i.dealRef || '').concat(i.dealName ? ' · ' + i.dealName : '')]).map(function (t) {
          return String(t).trim();
        }).filter(Boolean),
        ploegLijn: true,
        // ploeg onder een eigen lijn, los van het adres
        color: w.color,
        _item: i,
        _slot: s
      };
    });
  });
  return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      alignItems: 'center',
      gap: 7,
      marginBottom: 8,
      flexWrap: 'wrap'
    }
  }, /*#__PURE__*/React.createElement("span", {
    style: {
      fontFamily: T.fontBody,
      fontSize: 9,
      fontWeight: 700,
      letterSpacing: '0.12em',
      textTransform: 'uppercase',
      color: T.fg3
    }
  }, "Soort werk"), plWorkList().map(function (w) {
    var on = activeWork.length === 0 || workOn[w.id];
    return /*#__PURE__*/React.createElement("button", {
      key: w.id,
      onClick: function onClick() {
        return setWorkOn(function (s) {
          return _objectSpread(_objectSpread({}, s), {}, _defineProperty({}, w.id, !s[w.id]));
        });
      },
      title: "".concat(w.label, " \u2014 klik om te filteren"),
      style: {
        display: 'inline-flex',
        alignItems: 'center',
        gap: 6,
        padding: '4px 10px',
        background: workOn[w.id] ? "".concat(w.color, "1f") : 'transparent',
        border: "1px solid ".concat(workOn[w.id] ? w.color : T.stroke1),
        borderRadius: 4,
        cursor: 'pointer',
        color: on ? w.color : T.fg4,
        fontFamily: T.fontBody,
        fontSize: 11,
        fontWeight: 700,
        opacity: on ? 1 : 0.55,
        transition: 'all 140ms'
      }
    }, /*#__PURE__*/React.createElement("span", {
      style: {
        width: 8,
        height: 8,
        borderRadius: 2,
        background: w.color,
        opacity: on ? 1 : 0.35
      }
    }), w.label);
  })), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      alignItems: 'center',
      gap: 7,
      marginBottom: 6,
      flexWrap: 'wrap'
    }
  }, /*#__PURE__*/React.createElement("span", {
    style: {
      fontFamily: T.fontBody,
      fontSize: 9,
      fontWeight: 700,
      letterSpacing: '0.12em',
      textTransform: 'uppercase',
      color: T.fg3
    }
  }, "Ploeg"), (window.PLANNING_CREW || []).map(function (w) {
    var c = plCrewColor(w.id);
    var on = activeCrew.length === 0 || crewOn[w.id];
    return /*#__PURE__*/React.createElement("button", {
      key: w.id,
      onClick: function onClick() {
        return setCrewOn(function (s) {
          return _objectSpread(_objectSpread({}, s), {}, _defineProperty({}, w.id, !s[w.id]));
        });
      },
      title: "".concat(w.name, " \xB7 ").concat(w.role, " \u2014 klik om te filteren"),
      style: {
        display: 'inline-flex',
        alignItems: 'center',
        gap: 6,
        padding: '4px 10px',
        background: crewOn[w.id] ? "".concat(c, "1a") : 'transparent',
        border: "1px solid ".concat(crewOn[w.id] ? c : T.stroke1),
        borderRadius: 4,
        cursor: 'pointer',
        color: on ? c : T.fg4,
        fontFamily: T.fontBody,
        fontSize: 11,
        fontWeight: 700,
        opacity: on ? 1 : 0.55,
        transition: 'all 140ms'
      }
    }, /*#__PURE__*/React.createElement("span", {
      style: {
        width: 8,
        height: 8,
        borderRadius: 2,
        background: c,
        opacity: on ? 1 : 0.35
      }
    }), w.name.split(' ')[0]);
  }), /*#__PURE__*/React.createElement("span", {
    style: {
      marginLeft: 'auto',
      fontFamily: T.fontBody,
      fontSize: 11,
      color: T.fg3
    }
  }, ingepland.length, " ingepland \xB7 ", teplannen.length, " nog in te plannen")), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      alignItems: 'center',
      gap: 6,
      marginBottom: 12,
      fontFamily: T.fontBody,
      fontSize: 10.5,
      color: T.fg4
    }
  }, /*#__PURE__*/React.createElement(Icon, {
    name: "info",
    size: 11,
    color: T.fg4
  }), "De kleur van een blok = het soort werk. E\xE9n deal kan meerdere momenten hebben; elk moment staat apart in de agenda. Klik een ploeglid om zijn planning te filteren."), planning && /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      alignItems: 'center',
      gap: 12,
      flexWrap: 'wrap',
      background: 'rgba(0,217,0,0.07)',
      border: "1px solid ".concat(T.strokeAccent),
      clipPath: cutPath(10),
      padding: '10px 14px',
      marginBottom: 12
    }
  }, /*#__PURE__*/React.createElement(Icon, {
    name: "calendar",
    size: 15,
    color: T.accent
  }), /*#__PURE__*/React.createElement("span", {
    style: {
      fontFamily: T.fontDisplay,
      fontSize: 14,
      fontWeight: 600,
      color: T.fg1
    }
  }, planning.slotId ? 'Werk verzetten' : 'Werk inplannen', " \u2014 ", planning.client), /*#__PURE__*/React.createElement("span", {
    style: {
      fontFamily: T.fontBody,
      fontSize: 11.5,
      color: T.fg3
    }
  }, planning.dealRef, " \xB7 ", planning.dealName), /*#__PURE__*/React.createElement("span", {
    style: {
      marginLeft: 'auto',
      display: 'flex',
      alignItems: 'center',
      gap: 10
    }
  }, /*#__PURE__*/React.createElement("span", {
    style: {
      fontFamily: T.fontBody,
      fontSize: 11.5,
      color: pForm.date && pForm.start ? T.accent : '#ffb020'
    }
  }, pForm.date && pForm.start ? "".concat(pForm.date, " \xB7 ").concat(pForm.start, "\u2013").concat(pForm.end) : 'Klik of sleep een tijdvak in de agenda'), /*#__PURE__*/React.createElement(Button, {
    variant: "ghost",
    size: "sm",
    icon: "x",
    onClick: cancelPlan
  }, "Annuleren"))), /*#__PURE__*/React.createElement(window.OpmAgendaGrid, {
    items: gridItems,
    base: base,
    setBase: setBase,
    value: planning ? pForm : null,
    onPick: planning ? pickSlot : null,
    onMoveItem: function onMoveItem(x, date, start, end) {
      return onPlan(x._item, {
        date: date,
        start: start,
        end: end,
        crew: x._slot.crew || [],
        info: x._slot.info || '',
        work: x._slot.work,
        slotId: x._slot.id
      });
    },
    onOpenItem: function onOpenItem(x) {
      return onOpen(x._item);
    },
    pickHint: planning ? "Kies een tijdvak voor ".concat(planning.client) : 'Sleep een blok om te verzetten · klik om de contactfiche te openen',
    pickPanel: planning ? /*#__PURE__*/React.createElement("div", {
      style: {
        padding: 14
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        fontFamily: T.fontDisplay,
        fontSize: 14,
        fontWeight: 600,
        color: T.fg1
      }
    }, planning.slotId ? 'Werk verzetten' : 'Werk inplannen'), /*#__PURE__*/React.createElement("div", {
      style: {
        fontFamily: T.fontBody,
        fontSize: 11.5,
        color: T.fg3,
        marginTop: 2,
        marginBottom: 12
      }
    }, planning.client, " \xB7 ", planning.dealRef), /*#__PURE__*/React.createElement("label", {
      style: {
        display: 'block',
        marginBottom: 9
      }
    }, /*#__PURE__*/React.createElement("span", {
      style: pLbl
    }, "Datum"), /*#__PURE__*/React.createElement(window.GhsDatumVeld, {
      value: pForm.date,
      onChange: function onChange(v) {
        return setPForm(function (f) {
          return _objectSpread(_objectSpread({}, f), {}, {
            date: v
          });
        });
      }
    })), /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'grid',
        gridTemplateColumns: '1fr 1fr',
        gap: 9,
        marginBottom: 9
      }
    }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", {
      style: pLbl
    }, "Start"), /*#__PURE__*/React.createElement(window.GhsTijdVeld, {
      value: pForm.start,
      onChange: function onChange(v) {
        return setPForm(function (f) {
          return _objectSpread(_objectSpread({}, f), {}, {
            start: v
          });
        });
      },
      style: pFld
    })), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", {
      style: pLbl
    }, "Einde"), /*#__PURE__*/React.createElement(window.GhsTijdVeld, {
      value: pForm.end,
      onChange: function onChange(v) {
        return setPForm(function (f) {
          return _objectSpread(_objectSpread({}, f), {}, {
            end: v
          });
        });
      },
      style: pFld
    }))), /*#__PURE__*/React.createElement("div", {
      style: {
        marginBottom: 9
      }
    }, /*#__PURE__*/React.createElement("span", {
      style: pLbl
    }, "Soort werk"), /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        flexWrap: 'wrap',
        gap: 6
      }
    }, plWorkList().map(function (w) {
      var on = pForm.work === w.id;
      return /*#__PURE__*/React.createElement("button", {
        key: w.id,
        onClick: function onClick() {
          return setPForm(function (f) {
            return _objectSpread(_objectSpread({}, f), {}, {
              work: w.id
            });
          });
        },
        style: {
          display: 'inline-flex',
          alignItems: 'center',
          gap: 6,
          padding: '5px 10px',
          background: on ? "".concat(w.color, "22") : 'transparent',
          border: "1px solid ".concat(on ? w.color : T.stroke1),
          borderRadius: 4,
          cursor: 'pointer',
          color: on ? w.color : T.fg3,
          fontFamily: T.fontBody,
          fontSize: 11,
          fontWeight: 700
        }
      }, /*#__PURE__*/React.createElement("span", {
        style: {
          width: 7,
          height: 7,
          borderRadius: 2,
          background: w.color,
          opacity: on ? 1 : 0.4
        }
      }), w["short"] || w.label);
    }))), /*#__PURE__*/React.createElement("div", {
      style: {
        marginBottom: 13
      }
    }, /*#__PURE__*/React.createElement("span", {
      style: pLbl
    }, "Ploeg"), /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        flexWrap: 'wrap',
        gap: 6
      }
    }, (window.PLANNING_CREW || []).map(function (w) {
      var on = pForm.crew.includes(w.id);
      var c = plCrewColor(w.id);
      return /*#__PURE__*/React.createElement("button", {
        key: w.id,
        onClick: function onClick() {
          return setPForm(function (f) {
            return _objectSpread(_objectSpread({}, f), {}, {
              crew: on ? f.crew.filter(function (x) {
                return x !== w.id;
              }) : [].concat(_toConsumableArray(f.crew), [w.id])
            });
          });
        },
        title: "".concat(w.name, " \xB7 ").concat(w.role),
        style: {
          display: 'inline-flex',
          alignItems: 'center',
          gap: 6,
          padding: '5px 10px',
          background: on ? "".concat(c, "22") : 'transparent',
          border: "1px solid ".concat(on ? c : T.stroke1),
          borderRadius: 4,
          cursor: 'pointer',
          color: on ? c : T.fg3,
          fontFamily: T.fontBody,
          fontSize: 11,
          fontWeight: 700
        }
      }, /*#__PURE__*/React.createElement("span", {
        style: {
          width: 7,
          height: 7,
          borderRadius: 2,
          background: c,
          opacity: on ? 1 : 0.4
        }
      }), w.name.split(' ')[0]);
    }))), /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        gap: 8,
        justifyContent: 'flex-end'
      }
    }, /*#__PURE__*/React.createElement(Button, {
      variant: "ghost",
      size: "sm",
      icon: "x",
      onClick: cancelPlan
    }, "Annuleren"), /*#__PURE__*/React.createElement(Button, {
      variant: "primary",
      size: "sm",
      icon: "check",
      disabled: !pCan,
      onClick: savePlanning
    }, planning.slotId ? 'Verzetten' : (pForm.crew || []).length ? 'Inplannen' : 'Reserveren'))) : null
  }), function () {
    var werkChip = function werkChip(w) {
      return /*#__PURE__*/React.createElement("span", {
        style: {
          display: 'inline-flex',
          alignItems: 'center',
          gap: 6,
          padding: '2px 8px',
          background: "".concat(w.color, "1f"),
          border: "1px solid ".concat(w.color, "55"),
          borderRadius: 3,
          fontFamily: T.fontBody,
          fontSize: 10.5,
          fontWeight: 700,
          color: w.color,
          whiteSpace: 'nowrap'
        }
      }, /*#__PURE__*/React.createElement("span", {
        style: {
          width: 7,
          height: 7,
          borderRadius: 2,
          background: w.color
        }
      }), w["short"] || w.label);
    };
    var slotRijen = ingepland.flatMap(function (i) {
      return (i.slots || []).filter(function (s) {
        return activeWork.length === 0 || activeWork.includes(s.work || 'pv_hellend');
      }).filter(function (s) {
        return activeCrew.length === 0 || (window.ghsCrewIds ? window.ghsCrewIds(s.crew) : s.crew || []).some(function (id) {
          return activeCrew.includes(id);
        });
      }).map(function (s) {
        return {
          item: i,
          slot: s
        };
      });
    }).sort(function (x, y) {
      return (x.slot.date + (x.slot.start || '')).localeCompare(y.slot.date + (y.slot.start || ''));
    });
    var uitgevoerd = items.filter(function (i) {
      return i.status === 'uitgevoerd';
    });
    var rij = function rij(key, data, actief) {
      return {
        kind: 'rij',
        key: key,
        data: data,
        cid: data.item._cid,
        actief: !!actief
      };
    };
    var teRijen = plOrderBySuggestion(teplannen, groups, function () {
      return 0;
    }).map(function (r) {
      if (r.kind === 'div') return {
        kind: 'blok',
        key: r.key,
        kleur: T.accent,
        icon: 'mappin',
        titel: "Rit-suggestie ".concat(r.n).concat(r.region ? ' · ' + r.region : ''),
        pil: "".concat(r.count, " werven").concat(r.maxKm ? ' · max ' + r.maxKm + ' km' : '')
      };
      if (r.kind === 'rest') return {
        kind: 'blok',
        key: r.key,
        kleur: '#8aa39a',
        titel: 'Overige werven',
        pil: String(r.count)
      };
      return rij(r.item.id, {
        item: r.item,
        slot: null,
        suggestie: r.n
      }, planning && planning.id === r.item.id);
    });
    var kolommen = [{
      l: 'DEAL',
      w: '108px',
      cel: function cel(d) {
        return /*#__PURE__*/React.createElement("span", {
          style: {
            fontFamily: T.fontBody,
            fontSize: 11,
            fontWeight: 700,
            color: T.fg3,
            letterSpacing: '0.04em'
          }
        }, d.item.dealRef);
      }
    }, {
      l: 'KLANT',
      w: 'minmax(150px,1.4fr)',
      cel: function cel(d) {
        return /*#__PURE__*/React.createElement("div", {
          style: {
            minWidth: 0
          }
        }, /*#__PURE__*/React.createElement("div", {
          style: _objectSpread(_objectSpread({}, window.ghsRegelNaam), {}, {
            overflow: 'hidden',
            textOverflow: 'ellipsis',
            whiteSpace: 'nowrap'
          })
        }, d.item.client), /*#__PURE__*/React.createElement("div", {
          style: window.ghsRegelSub
        }, d.item.city, d.item.kwp > 0 ? " \xB7 ".concat(d.item.kwp, " kWp") : ''));
      }
    }, {
      l: 'WERK',
      w: 'minmax(130px,1.2fr)',
      cel: function cel(d) {
        return d.slot ? werkChip(plWork(d.slot.work)) : /*#__PURE__*/React.createElement("span", {
          style: {
            fontFamily: T.fontBody,
            fontSize: 12.5,
            color: T.fg2,
            overflow: 'hidden',
            textOverflow: 'ellipsis',
            whiteSpace: 'nowrap'
          }
        }, d.item.werkOms || d.item.dealName);
      }
    }, {
      l: 'WANNEER',
      w: '165px',
      cel: function cel(d) {
        return d.slot ? /*#__PURE__*/React.createElement("div", {
          style: {
            minWidth: 0
          }
        }, /*#__PURE__*/React.createElement("div", {
          style: {
            fontFamily: T.fontBody,
            fontSize: 12.5,
            color: T.fg1,
            whiteSpace: 'nowrap'
          }
        }, new Date(d.slot.date + 'T00:00:00').toLocaleDateString('nl-BE', {
          day: 'numeric',
          month: 'short'
        })), /*#__PURE__*/React.createElement("div", {
          style: window.ghsRegelSub
        }, d.slot.start ? "".concat(d.slot.start).concat(d.slot.end ? '–' + d.slot.end : '') : 'zonder uur')) : /*#__PURE__*/React.createElement("span", {
          style: {
            fontFamily: T.fontBody,
            fontSize: 12,
            fontWeight: 600,
            color: '#ffb020',
            whiteSpace: 'nowrap'
          }
        }, "Nog in te plannen");
      }
    }, {
      l: 'PLOEG',
      w: 'minmax(120px,1.1fr)',
      cel: function cel(d) {
        var crew = d.slot ? d.slot.crew || [] : d.item.crew;
        return /*#__PURE__*/React.createElement("span", {
          style: {
            fontFamily: T.fontBody,
            fontSize: 12.5,
            color: crew.length ? T.fg2 : T.fg4,
            overflow: 'hidden',
            textOverflow: 'ellipsis',
            whiteSpace: 'nowrap'
          }
        }, crew.length ? plCrewNames(crew).map(function (n) {
          return n.split(' ')[0];
        }).join(', ') : '—');
      }
    }, {
      l: 'ACTIES',
      w: '240px',
      rechts: true,
      acties: true,
      cel: function cel(d) {
        if (d.item.status === 'uitgevoerd') return /*#__PURE__*/React.createElement("span", {
          style: {
            display: 'inline-flex',
            alignItems: 'center',
            gap: 6,
            fontFamily: T.fontBody,
            fontSize: 11.5,
            fontWeight: 600,
            color: T.fg3
          }
        }, /*#__PURE__*/React.createElement(Icon, {
          name: "check",
          size: 13,
          color: T.accent
        }), "Uitgevoerd");
        if (d.slot) return /*#__PURE__*/React.createElement(React.Fragment, null, window.ghsKnopVolgorde([/*#__PURE__*/React.createElement(Button, {
          key: "extra",
          variant: "ghost",
          size: "sm",
          icon: "plus",
          onClick: function onClick() {
            return startPlan(d.item, null);
          }
        }, "Extra moment"), /*#__PURE__*/React.createElement(Button, {
          key: "verzet",
          variant: "beige",
          size: "sm",
          icon: "calendar",
          onClick: function onClick() {
            return startPlan(d.item, d.slot);
          }
        }, "Verzetten")], 'flex-end'));
        var on = planning && planning.id === d.item.id;
        if (d.item.vsWacht && window.GhsVoorschotWacht) return /*#__PURE__*/React.createElement(window.GhsVoorschotWacht, {
          w: d.item.vsWacht,
          cid: d.item._cid
        });
        return on ? /*#__PURE__*/React.createElement(Button, {
          variant: "ghost",
          size: "sm",
          icon: "x",
          onClick: cancelPlan
        }, "Annuleren") : /*#__PURE__*/React.createElement(Button, {
          variant: "primary",
          size: "sm",
          icon: "calendar",
          onClick: function onClick() {
            return startPlan(d.item, null);
          }
        }, "Inplannen");
      }
    }];
    var secties = [{
      id: 'pl-teplannen',
      label: 'Nog in te plannen — kies een tijdvak in de agenda',
      kleur: '#ffb020',
      icon: 'clock',
      aantal: teplannen.length,
      rijen: teRijen,
      leeg: 'Alles ingepland'
    }, {
      id: 'pl-ingepland',
      label: 'Ingepland',
      kleur: '#00aaff',
      icon: 'calendar',
      dicht: true,
      aantal: slotRijen.length,
      rijen: window.ghsMetDagen(slotRijen, function (d) {
        return d.slot.date;
      }, function (d) {
        return rij(d.slot.id, d, planning && planning.slotId === d.slot.id);
      }),
      leeg: 'Nog niets ingepland',
      pillen: [{
        n: slotRijen.filter(function (d) {
          return d.slot.date < plToday();
        }).length,
        label: 'over datum',
        kleur: '#ff5a4d',
        icon: 'info'
      }]
    }, {
      id: 'pl-uitgevoerd',
      label: 'Uitgevoerd',
      kleur: T.accent,
      icon: 'check',
      dicht: true,
      rijen: uitgevoerd.map(function (i) {
        return rij(i.id, {
          item: i,
          slot: i.slot
        });
      }),
      leeg: 'Nog niets uitgevoerd'
    }];
    /* Ingevouwen: in de agenda kijk je naar de agenda, de lijst is opvolging. */
    return /*#__PURE__*/React.createElement(window.GhsAgendaLijst, {
      secties: secties.map(function (s) {
        return _objectSpread(_objectSpread({}, s), {}, {
          dicht: true
        });
      }),
      kolommen: kolommen,
      onRij: function onRij(d) {
        return onOpen(d.item);
      },
      eenheid: "werf",
      eenheidMv: "werven"
    });
  }());
};

/* ── Main page ───────────────────────────────────────────────────────────── */
var PlanningPage = function PlanningPage() {
  var crm = window.useCRM();
  /* Enkel de agenda (bv. verkoper, plaatser): geen lijsten, tellers of inplanknoppen. */
  var ik = window.useGhsGebruiker ? window.useGhsGebruiker() : null;
  var alleenAgenda = !!(window.ghsAlleenAgenda && window.ghsAlleenAgenda(ik, 'planning'));
  var items = React.useMemo(function () {
    return mapPlanItems(crm.contacts);
  }, [crm.contacts]);
  /* Een planmodus die vanuit een andere module gestart werd, opent meteen de agenda. */
  var _React$useState49 = React.useState(function () {
      return window.__plPlan ? 'agenda' : window.ghsBeginView ? window.ghsBeginView('planning', 'lijsten') : 'lijsten';
    }),
    _React$useState50 = _slicedToArray(_React$useState49, 2),
    view = _React$useState50[0],
    setView = _React$useState50[1]; // dashboard | lijsten | kanban | agenda
  /* Planmodus: 'Inplannen' springt naar de agenda; bewaren of annuleren brengt je terug naar de lijsten. */
  React.useEffect(function () {
    if (window.__plPlan) setView('agenda');
    window.__plNaarAgenda = function () {
      return setView('agenda');
    };
    window.__plTerug = function () {
      return setView(function (v) {
        return v === 'agenda' ? 'lijsten' : v;
      });
    };
    return function () {
      window.__plNaarAgenda = null;
      window.__plTerug = null;
    };
  }, []);
  var _React$useState51 = React.useState(''),
    _React$useState52 = _slicedToArray(_React$useState51, 2),
    search = _React$useState52[0],
    setSearch = _React$useState52[1];
  window.useGhsReveal('planning', setSearch, setView, 'lijsten');
  var _React$useState53 = React.useState(null),
    _React$useState54 = _slicedToArray(_React$useState53, 2),
    confirm = _React$useState54[0],
    setConfirm = _React$useState54[1];
  var _React$useState55 = React.useState(null),
    _React$useState56 = _slicedToArray(_React$useState55, 2),
    planner = _React$useState56[0],
    setPlanner = _React$useState56[1]; // item dat we (ver)plannen
  var _React$useState57 = React.useState(null),
    _React$useState58 = _slicedToArray(_React$useState57, 2),
    nieuw = _React$useState58[0],
    setNieuw = _React$useState58[1]; // 'pick' | contact
  var _React$useState59 = React.useState(''),
    _React$useState60 = _slicedToArray(_React$useState59, 2),
    clientSearch = _React$useState60[0],
    setClientSearch = _React$useState60[1];
  var _React$useState61 = React.useState(null),
    _React$useState62 = _slicedToArray(_React$useState61, 2),
    draggingId = _React$useState62[0],
    setDraggingId = _React$useState62[1];
  var _React$useState63 = React.useState(null),
    _React$useState64 = _slicedToArray(_React$useState63, 2),
    dragOverCol = _React$useState64[0],
    setDragOverCol = _React$useState64[1];
  var pg = window.useGhsPaging('planning');
  var srt = window.useGhsSort('planning_v2', {
    key: 'datum',
    dir: 'asc'
  }, {
    dagen: 'desc',
    datum: 'asc'
  });
  var collapse = window.useListCollapse(Object.values(PLAN_COL).map(function (c) {
    return c.id;
  }));
  var endDrag = function endDrag() {
    setDraggingId(null);
    setDragOverCol(null);
  };
  var filtered = items.filter(function (i) {
    return ghsMatch("".concat(i.client, " ").concat(i.city, " ").concat(i.dealRef, " ").concat(i.dealName), search);
  });
  /* Voor de lijst: elk moment een eigen regel, zodat een werf op elke werkdag opduikt
     waarop er iets voor gepland staat. Werven zonder moment blijven één regel. */
  var perMoment = React.useMemo(function () {
    return filtered.flatMap(function (i) {
      var ss = i.slots || [];
      if (!ss.length) return [_objectSpread(_objectSpread({}, i), {}, {
        rijKey: i.id,
        slotIx: -1
      })];
      return ss.map(function (s, si) {
        return _objectSpread(_objectSpread({}, i), {}, {
          rijKey: i.id + '|' + s.id,
          slot: s,
          slotId: s.id,
          slotIx: si,
          date: s.date,
          start: s.start,
          end: s.end,
          work: s.work,
          crew: window.ghsCrewIds ? window.ghsCrewIds(s.crew) : s.crew || [],
          info: s.info || '',
          status: ((i.bonnen || {})[s.id] || {}).installed ? 'uitgevoerd' : 'ingepland',
          installed: !!((i.bonnen || {})[s.id] || {}).installed,
          installedAt: ((i.bonnen || {})[s.id] || {}).installedAt || null,
          werkbon: ((i.bonnen || {})[s.id] || {}).werkbon || null,
          /* De dagenteller van deze regel hoort bij dít moment. */
          dagenSinds: ((i.bonnen || {})[s.id] || {}).installedAt ? String(((i.bonnen || {})[s.id] || {}).installedAt).slice(0, 10) : s.date
        });
      });
    });
  }, [filtered]);
  // Rittensuggesties — 'te plannen' werven die dicht bij elkaar liggen (postcode-nabijheid)
  var ritGroups = React.useMemo(function () {
    return plSuggestGroups(filtered.filter(function (i) {
      return i.status === 'te_plannen' && !i.vsWacht;
    }));
  }, [filtered]);
  /* Kolommen op maat van de inhoud; knoppenkolom = index 7. */
  var planAuto = window.useGhsAutoGrid(PLAN_LIST_GRID, {
    acties: 7
  }, [perMoment.length, view]);

  /* Muteren via de store — synchroon met de contactfiche */
  var savePlan = function savePlan(item, f) {
    var slotId = f.slotId !== undefined ? f.slotId : item.slotId;
    var payload = {
      dealRef: item.dealRef,
      date: f.date,
      start: f.start,
      end: f.end,
      crew: f.crew,
      info: f.info,
      work: f.work,
      tijdslot: f.tijdslot || null,
      uurVrij: !!f.uurVrij,
      adres: item.address,
      type: 'installatie'
    };
    if (slotId) window.crmStore.updatePlanningSlot(item._cid, slotId, payload);else window.crmStore.addPlanningSlot(item._cid, payload);
    setPlanner(null);
  };
  var markDone = function markDone(item) {
    /* Deze regel is één moment: enkel dát moment wordt uitgevoerd gemeld. */
    var doIt = function doIt() {
      return window.crmStore.markInstalled(item._cid, item.dealRef, item.slotId || undefined);
    };
    if (item.slotId) setConfirm({
      title: 'Werk uitgevoerd melden?',
      msg: "".concat(item.dealRef, " \u2014 ").concat(item.client, " wordt gemarkeerd als uitgevoerd. De klant schuift door naar de werkbon-fase."),
      label: 'Uitgevoerd melden',
      onConfirm: doIt
    });else setConfirm({
      title: 'Werk uitgevoerd melden?',
      msg: "".concat(item.dealRef, " \u2014 ").concat(item.client, " is nog niet ingepland. Toch als uitgevoerd markeren?"),
      label: 'Toch uitgevoerd melden',
      onConfirm: doIt
    });
  };
  var reopen = function reopen(item) {
    return setConfirm({
      title: 'Werk heropenen?',
      msg: "".concat(item.dealRef, " \u2014 ").concat(item.client, " gaat terug naar ").concat(item.slotId ? 'Ingepland' : 'Te plannen', ". ").concat(item.werkbon ? 'De werkbon-status wordt teruggezet.' : ''),
      label: 'Heropenen',
      onConfirm: function onConfirm() {
        return window.crmStore.setWerkbonStatus(item._cid, item.dealRef, 'ingepland');
      }
    });
  };
  var unplan = function unplan(item) {
    return setConfirm({
      title: 'Inplanning verwijderen?',
      msg: "".concat(item.dealRef, " \u2014 ").concat(item.client, " verliest alle ingeplande momenten en komt terug bij Te plannen."),
      label: 'Inplanning verwijderen',
      onConfirm: function onConfirm() {
        /* Zelfde handeling als in de contactfiche: komt in het activiteitenlog en ruimt de werkbonstaat mee op. */
        if (item.installed) window.crmStore.setWerkbonStatus(item._cid, item.dealRef, 'ingepland');
        if (item.slotId) window.crmStore.removePlanning(item._cid, item.dealRef);
      }
    });
  };

  /* Sleepmatrix — zelfde patroon als de opmetingen-kanban */
  var dropOnCol = function dropOnCol(item, target) {
    if (item.status === target) return;
    if (target === 'ingepland') {
      if (item.installed) reopen(item);else if (window.ghsPlanPlaatsing && window.AgendaPage) window.ghsPlanPlaatsing(item); // te_plannen → ingepland: in de agenda een moment kiezen
      else if (!window.ghsVoorschotPoort || window.ghsVoorschotPoort(item._cid, item.dealRef)) setPlanner(item);
    } else if (target === 'uitgevoerd') {
      markDone(item);
    } else if (target === 'te_plannen') {
      unplan(item);
    }
  };
  var dropProps = function dropProps(colId) {
    return {
      onDragOver: function onDragOver(e) {
        e.preventDefault();
        e.dataTransfer.dropEffect = 'move';
        if (dragOverCol !== colId) setDragOverCol(colId);
      },
      onDragLeave: function onDragLeave() {
        if (dragOverCol === colId) setDragOverCol(null);
      },
      onDrop: function onDrop(e) {
        e.preventDefault();
        var it = draggingId ? filtered.find(function (x) {
          return x.id === draggingId;
        }) : null;
        if (it) dropOnCol(it, colId);
        endDrag();
      }
    };
  };

  // Zonder datum ('') sorteert eerst — nog niet ingeplande werven bovenaan.
  var byDate = function byDate(a, b) {
    return String(a.date || '').localeCompare(String(b.date || '')) || String(a.start || '').localeCompare(String(b.start || ''));
  };
  var inWeek = function inWeek(d) {
    return d && d >= plToday() && d <= window.dCrmAdd(plToday(), 6);
  };
  /* 'Te plannen' telt wat de planner nu kan inplannen — zelfde teller als de zijbalk. Wat op het voorschot wacht, staat apart. */
  var tePlannenN = items.filter(function (i) {
    return i.status === 'te_plannen' && !i.vsWacht;
  }).length;
  var vsWachtN = items.filter(function (i) {
    return i.status === 'te_plannen' && i.vsWacht;
  }).length;
  var ingeplandN = items.filter(function (i) {
    return i.status === 'ingepland';
  }).length;
  var weekN = items.filter(function (i) {
    return i.status === 'ingepland' && inWeek(i.date);
  }).length;
  var uitgevoerdN = items.filter(function (i) {
    return i.status === 'uitgevoerd';
  }).length;
  var werkbonN = items.filter(function (i) {
    return i.installed && !i.werkbon;
  }).length;

  /* Inplannen gebeurt in de agenda (planmodus); het venster blijft enkel als terugval zonder agenda. */
  var inAgenda = !!(window.ghsPlanPlaatsing && window.AgendaPage);
  var magNieuw = function magNieuw(i) {
    return !window.ghsVoorschotPoort || window.ghsVoorschotPoort(i._cid, i.dealRef);
  };
  var cardProps = {
    onOpen: openPlanFiche,
    onPlan: function onPlan(i) {
      return inAgenda ? window.ghsPlanPlaatsing(i) : magNieuw(i) && setPlanner(i);
    },
    onDone: markDone,
    onReopen: reopen,
    onDragStart: function onDragStart(x) {
      return setDraggingId(x.id);
    },
    onDragEnd: endDrag,
    onPlanSlot: function onPlanSlot(i, s) {
      return inAgenda ? window.ghsPlanPlaatsing(i, {
        slotId: s.id
      }) : setPlanner(_objectSpread(_objectSpread({}, i), {}, {
        slot: s,
        slotId: s.id,
        date: s.date,
        start: s.start,
        end: s.end,
        crew: s.crew || [],
        info: s.info || '',
        work: s.work
      }));
    },
    onPlanExtra: function onPlanExtra(i) {
      return inAgenda ? window.ghsPlanPlaatsing(i) : magNieuw(i) && setPlanner(_objectSpread(_objectSpread({}, i), {}, {
        slot: null,
        slotId: null,
        date: null,
        start: null,
        end: null,
        crew: [],
        info: '',
        work: null
      }));
    }
  };
  if (alleenAgenda && window.GhsAgendaInzage) {
    /* Een plaatser ziet bovenaan zijn eigen dag en rijroute. */
    var tech = ik && (window.PLANNING_CREW || []).find(function (w) {
      return w.name === ik.name;
    });
    return /*#__PURE__*/React.createElement(window.GhsAgendaInzage, {
      titel: "Planning",
      bron: "planning",
      kop: tech && window.GhsDagplanningStrip ? /*#__PURE__*/React.createElement(window.GhsDagplanningStrip, {
        contacts: crm.contacts,
        techIds: [tech.id]
      }) : null
    });
  }
  return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Topbar, {
    title: "Planning",
    user: {
      name: 'Nick De Roeck'
    }
  }), /*#__PURE__*/React.createElement("div", {
    className: "ghs-stapel",
    style: {
      padding: 24
    }
  }, /*#__PURE__*/React.createElement(GhsKpiRij, {
    min: 160
  }, /*#__PURE__*/React.createElement(GhsKpi, {
    label: "Totaal werken",
    value: items.length,
    icon: "zap",
    accent: true
  }), /*#__PURE__*/React.createElement(GhsKpi, {
    label: "Te plannen",
    value: tePlannenN,
    icon: "calendar",
    color: "#ffb020"
  }), /*#__PURE__*/React.createElement(GhsKpi, {
    label: "Ingepland",
    value: ingeplandN,
    icon: "clock",
    color: "#00aaff"
  }), /*#__PURE__*/React.createElement(GhsKpi, {
    label: "Deze week",
    value: weekN,
    icon: "mappin",
    color: "#bf63ff"
  }), /*#__PURE__*/React.createElement(GhsKpi, {
    label: "Uitgevoerd",
    value: uitgevoerdN,
    icon: "check",
    color: T.accent
  }), /*#__PURE__*/React.createElement(GhsKpi, {
    label: "Werkbon op te maken",
    value: werkbonN,
    icon: "clipboard",
    color: "#a9b0a2"
  })), /*#__PURE__*/React.createElement("div", {
    className: "ghs-werkbalk"
  }, /*#__PURE__*/React.createElement(Button, {
    variant: "primary",
    size: "sm",
    icon: "plus",
    onClick: function onClick() {
      setNieuw('pick');
      setClientSearch('');
    }
  }, "Werk inplannen"), /*#__PURE__*/React.createElement("div", {
    className: "ghs-wb-zoek"
  }, /*#__PURE__*/React.createElement(CrmSearchBar, {
    scope: "planning",
    value: search,
    onChange: setSearch,
    placeholder: "Klant, stad of deal\u2026"
  })), /*#__PURE__*/React.createElement(GhsKeuze, {
    waarde: view,
    onKies: setView,
    opties: [['dashboard', 'Dashboard', 'barchart'], ['lijsten', 'Lijsten', 'list'], ['agenda', 'Agenda', 'calendar']].map(function (_ref28) {
      var _ref29 = _slicedToArray(_ref28, 3),
        id = _ref29[0],
        label = _ref29[1],
        icon = _ref29[2];
      return {
        id: id,
        label: label,
        icon: icon
      };
    })
  }), /*#__PURE__*/React.createElement("div", {
    style: {
      marginLeft: 'auto'
    }
  })), window.PlanPriorityBand && /*#__PURE__*/React.createElement(window.PlanPriorityBand, {
    contacts: crm.contacts,
    dicht: view === 'agenda'
  }), view === 'dashboard' && /*#__PURE__*/React.createElement("div", {
    className: "ghs-stapel"
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'grid',
      gridTemplateColumns: '1fr 1fr',
      gap: GHS_RITME
    }
  }, /*#__PURE__*/React.createElement(Card, {
    p: 20,
    accent: true
  }, /*#__PURE__*/React.createElement(SectionTitle, {
    title: "Eerstvolgende werken",
    sub: "Op datum"
  }), filtered.filter(function (i) {
    return i.status === 'ingepland';
  }).sort(byDate).slice(0, 5).map(function (i) {
    return /*#__PURE__*/React.createElement("div", {
      key: i.id,
      onClick: function onClick() {
        return openPlanFiche(i);
      },
      style: {
        display: 'flex',
        alignItems: 'center',
        gap: 12,
        padding: '9px 0',
        borderBottom: "1px solid ".concat(T.stroke1),
        cursor: 'pointer'
      }
    }, /*#__PURE__*/React.createElement(Avatar, {
      name: i.client,
      size: 28
    }), /*#__PURE__*/React.createElement("div", {
      style: {
        flex: 1,
        minWidth: 0
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        fontSize: 13,
        fontFamily: T.fontBody,
        fontWeight: 600,
        color: T.fg1,
        overflow: 'hidden',
        textOverflow: 'ellipsis',
        whiteSpace: 'nowrap'
      }
    }, i.client), /*#__PURE__*/React.createElement("div", {
      style: {
        fontSize: 11,
        color: T.fg3,
        fontFamily: T.fontBody
      }
    }, i.city, " \xB7 ", i.dealName)), /*#__PURE__*/React.createElement("span", {
      style: {
        fontSize: 11.5,
        color: T.fg2,
        fontFamily: T.fontBody,
        whiteSpace: 'nowrap'
      }
    }, i.date ? new Date(i.date + 'T00:00:00').toLocaleDateString('nl-BE', {
      weekday: 'short',
      day: 'numeric',
      month: 'short'
    }) : '—'));
  }), filtered.filter(function (i) {
    return i.status === 'ingepland';
  }).length === 0 && /*#__PURE__*/React.createElement("div", {
    style: {
      padding: '14px 0',
      fontSize: 12,
      color: T.fg4,
      fontFamily: T.fontBody
    }
  }, "Niets ingepland")), /*#__PURE__*/React.createElement(Card, {
    p: 20
  }, /*#__PURE__*/React.createElement(SectionTitle, {
    title: "Status verdeling"
  }), [{
    label: 'Te plannen',
    n: tePlannenN,
    color: '#ffb020'
  }, vsWachtN > 0 && {
    label: 'Wacht op voorschot',
    n: vsWachtN,
    color: '#8f9c88'
  }, {
    label: 'Ingepland',
    n: ingeplandN,
    color: '#00aaff'
  }, {
    label: 'Uitgevoerd',
    n: uitgevoerdN,
    color: T.accent
  }].filter(Boolean).map(function (s) {
    return /*#__PURE__*/React.createElement("div", {
      key: s.label,
      style: {
        marginBottom: 12
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        justifyContent: 'space-between',
        marginBottom: 4
      }
    }, /*#__PURE__*/React.createElement("span", {
      style: {
        fontSize: 12,
        color: T.fg2,
        fontFamily: T.fontBody
      }
    }, s.label), /*#__PURE__*/React.createElement("span", {
      style: {
        fontSize: 12,
        color: T.fg1,
        fontFamily: T.fontBody,
        fontWeight: 600
      }
    }, s.n)), /*#__PURE__*/React.createElement("div", {
      style: {
        height: 5,
        background: T.bg0,
        borderRadius: 3,
        overflow: 'hidden'
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        width: "".concat(items.length > 0 ? s.n / items.length * 100 : 0, "%"),
        height: '100%',
        background: s.color,
        borderRadius: 3
      }
    })));
  }), /*#__PURE__*/React.createElement(SectionTitle, {
    title: "Ploegbezetting deze week"
  }), (window.PLANNING_CREW || []).map(function (w) {
    var n = items.filter(function (i) {
      return i.status === 'ingepland' && inWeek(i.date) && i.crew.includes(w.id);
    }).length;
    return /*#__PURE__*/React.createElement("div", {
      key: w.id,
      style: {
        display: 'flex',
        justifyContent: 'space-between',
        alignItems: 'center',
        padding: '5px 0',
        borderBottom: "1px solid ".concat(T.stroke1)
      }
    }, /*#__PURE__*/React.createElement("span", {
      style: {
        fontSize: 12,
        color: T.fg2,
        fontFamily: T.fontBody
      }
    }, w.name, " ", /*#__PURE__*/React.createElement("span", {
      style: {
        color: T.fg4,
        fontSize: 10.5
      }
    }, "\xB7 ", w.role)), /*#__PURE__*/React.createElement("span", {
      style: {
        fontSize: 12,
        color: n > 0 ? T.accent : T.fg4,
        fontFamily: T.fontDisplay,
        fontWeight: 600
      }
    }, n, " werk", n === 1 ? '' : 'en'));
  }))), /*#__PURE__*/React.createElement(Card, {
    p: 0
  }, /*#__PURE__*/React.createElement(GhsTable, {
    columns: [{
      key: 'dealRef',
      label: 'Deal'
    }, {
      key: 'client',
      label: 'Klant',
      render: function render(v, r) {
        return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
          style: {
            fontWeight: 600
          }
        }, v), /*#__PURE__*/React.createElement("div", {
          style: {
            fontSize: 11,
            color: T.fg3
          }
        }, r.city));
      }
    }, {
      key: 'dealName',
      label: 'Werk'
    }, {
      key: 'date',
      label: 'Datum',
      render: function render(v) {
        return v ? new Date(v + 'T00:00:00').toLocaleDateString('nl-BE', {
          weekday: 'short',
          day: 'numeric',
          month: 'short'
        }) : '—';
      }
    }, {
      key: 'crew',
      label: 'Ploeg',
      render: function render(v) {
        return v.length ? plCrewNames(v).map(function (n) {
          return n.split(' ')[0];
        }).join(', ') : '—';
      }
    }, {
      key: 'status',
      label: 'Status',
      render: function render(v) {
        return /*#__PURE__*/React.createElement(Badge, {
          type: v === 'uitgevoerd' ? 'success' : v === 'ingepland' ? 'info' : 'warning',
          dot: true
        }, PLAN_LBL[v]);
      }
    }],
    rows: filtered.sort(byDate),
    onRow: openPlanFiche
  }))), view === 'lijsten' && function () {
    return /*#__PURE__*/React.createElement("div", {
      ref: planAuto.ref,
      style: _objectSpread({
        display: 'flex',
        flexDirection: 'column',
        gap: GHS_RITME
      }, planAuto.style)
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        justifyContent: 'flex-end'
      }
    }, /*#__PURE__*/React.createElement(window.CollapseAllBtn, {
      allCollapsed: collapse.allCollapsed,
      onToggle: collapse.toggleAll
    })), Object.values(PLAN_COL).map(function (sec) {
      var s0 = srt.van('pl');
      var secItems = perMoment.filter(function (i) {
        return i.status === sec.id;
      }).sort(s0.key === 'dagen' ? function (a, b) {
        return (plDagen(a) - plDagen(b)) * (s0.dir === 'asc' ? 1 : -1);
      } : function (a, b) {
        return byDate(a, b) * (s0.dir === 'desc' ? -1 : 1);
      });
      var shown = pg.knip(sec.id, secItems);
      return /*#__PURE__*/React.createElement("div", _extends({
        key: sec.id
      }, dropProps(sec.id), {
        style: window.ghsLijstKader(draggingId && dragOverCol === sec.id ? T.strokeAccent : T.stroke1)
      }), /*#__PURE__*/React.createElement(window.GhsSectieKop, {
        kleur: sec.color,
        icon: sec.icon,
        label: "".concat(PLAN_LBL[sec.id] || sec.label, " \u2014 ").concat(PL_SEC_HINT[sec.id] || ''),
        aantal: secItems.length,
        open: collapse.isOpen(sec.id),
        onToggle: function onToggle() {
          return collapse.toggle(sec.id);
        },
        pillen: [{
          n: secItems.filter(function (i) {
            return !i.date;
          }).length,
          label: 'zonder datum',
          kleur: '#ffb020',
          icon: 'clock'
        }, {
          n: secItems.filter(function (i) {
            return i.date && i.status === 'ingepland' && i.date < plToday();
          }).length,
          label: 'over datum',
          kleur: '#ff5a4d',
          icon: 'info'
        }, {
          n: secItems.filter(function (i) {
            return i.date && i.date === plToday();
          }).length,
          label: 'vandaag',
          kleur: T.accent,
          icon: 'calendar'
        }]
      }), collapse.isOpen(sec.id) && /*#__PURE__*/React.createElement(React.Fragment, null, secItems.length > 0 && /*#__PURE__*/React.createElement(window.GhsKolomKoppen, {
        grid: PLAN_AUTO_GRID,
        sort: srt.van('pl'),
        onSort: function onSort(k) {
          return srt.zet('pl', k);
        },
        kolommen: [{
          l: 'DAGEN',
          k: 'dagen'
        }, {
          l: 'OFFERTE'
        }, {
          l: 'KLANT'
        }, {
          l: 'WERK'
        }, {
          l: 'MOMENT',
          k: 'datum'
        }, {
          l: 'PLOEG'
        }, {
          l: 'STATUS'
        }, {
          l: 'ACTIES',
          rechts: true
        }, {
          l: '',
          rechts: true
        }]
      }), plWithDays(shown).map(function (r) {
        return r.kind === 'day' ? /*#__PURE__*/React.createElement(PlDayDivider, {
          key: r.key,
          iso: r.iso,
          count: r.count
        }) : /*#__PURE__*/React.createElement(PlanListRow, _extends({
          key: r.item.rijKey || r.key,
          item: r.item
        }, cardProps));
      }), secItems.length === 0 && /*#__PURE__*/React.createElement("div", {
        style: {
          padding: '26px 22px',
          textAlign: 'center',
          fontSize: 12.5,
          color: T.fg4,
          fontFamily: T.fontBody
        }
      }, "Geen werken"), /*#__PURE__*/React.createElement(window.GhsPaginatie, {
        id: sec.id,
        total: secItems.length,
        paging: pg,
        eenheid: "werf",
        eenheidMv: "werven"
      })));
    }));
  }(), view === 'agenda' && window.AgendaPage && window.GhsDagplanningStrip && /*#__PURE__*/React.createElement(window.GhsDagplanningStrip, {
    contacts: crm.contacts
  }), view === 'agenda' && (window.AgendaPage ? React.createElement(window.AgendaPage, {
    embedded: true,
    fixedSource: 'planning'
  }) : /*#__PURE__*/React.createElement(PlanAgendaView, {
    items: filtered,
    onPlan: savePlan,
    onOpen: openPlanFiche,
    groups: ritGroups
  }))), confirm && /*#__PURE__*/React.createElement(Modal, {
    open: true,
    onClose: function onClose() {
      return setConfirm(null);
    },
    title: confirm.title,
    width: 460
  }, /*#__PURE__*/React.createElement("p", {
    style: {
      margin: '0 0 14px',
      fontSize: 13,
      color: T.fg2,
      fontFamily: T.fontBody,
      lineHeight: 1.6
    }
  }, confirm.msg), /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      justifyContent: 'flex-end',
      gap: 8
    }
  }, /*#__PURE__*/React.createElement(Button, {
    variant: "secondary",
    onClick: function onClick() {
      return setConfirm(null);
    }
  }, "Annuleren"), /*#__PURE__*/React.createElement(Button, {
    variant: "primary",
    onClick: function onClick() {
      confirm.onConfirm();
      setConfirm(null);
    }
  }, confirm.label))), planner && /*#__PURE__*/React.createElement(PlPlannerModal, {
    item: planner,
    onClose: function onClose() {
      return setPlanner(null);
    },
    onSave: function onSave(f) {
      return savePlan(planner, f);
    }
  }), nieuw === 'pick' && /*#__PURE__*/React.createElement(Modal, {
    open: true,
    onClose: function onClose() {
      return setNieuw(null);
    },
    title: "Werk inplannen \u2014 kies een klant",
    width: 520
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      marginBottom: 12
    }
  }, /*#__PURE__*/React.createElement(SearchBar, {
    value: clientSearch,
    onChange: setClientSearch,
    placeholder: "Zoek op naam, stad of adres..."
  })), /*#__PURE__*/React.createElement("div", {
    style: {
      maxHeight: 380,
      overflowY: 'auto',
      display: 'flex',
      flexDirection: 'column',
      gap: 6,
      paddingRight: 8,
      marginRight: -8
    }
  }, crm.contacts.filter(function (ct) {
    return (ct.deals || []).some(function (d) {
      return d.won;
    });
  }).filter(function (ct) {
    return ghsMatch("".concat(ct.firstName, " ").concat(ct.lastName, " ").concat(ct.city || '', " ").concat(ct.address || ''), clientSearch);
  }).slice(0, 30).map(function (ct) {
    return /*#__PURE__*/React.createElement("div", {
      key: ct.id,
      onClick: function onClick() {
        return setNieuw(ct);
      },
      style: {
        display: 'flex',
        alignItems: 'center',
        gap: 10,
        padding: '9px 12px',
        background: T.bg2,
        border: "1px solid ".concat(T.stroke1),
        clipPath: cutPath(8),
        cursor: 'pointer',
        transition: 'all 140ms'
      },
      onMouseEnter: function onMouseEnter(e) {
        e.currentTarget.style.borderColor = T.strokeAccent;
        e.currentTarget.style.background = T.bg1;
      },
      onMouseLeave: function onMouseLeave(e) {
        e.currentTarget.style.borderColor = T.stroke1;
        e.currentTarget.style.background = T.bg2;
      }
    }, /*#__PURE__*/React.createElement(Avatar, {
      name: "".concat(ct.firstName, " ").concat(ct.lastName),
      size: 28
    }), /*#__PURE__*/React.createElement("div", {
      style: {
        flex: 1,
        minWidth: 0
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        fontFamily: T.fontBody,
        fontSize: 13,
        fontWeight: 700,
        color: T.fg1
      }
    }, ct.firstName, " ", ct.lastName), /*#__PURE__*/React.createElement("div", {
      style: {
        fontFamily: T.fontBody,
        fontSize: 11,
        color: T.fg3,
        overflow: 'hidden',
        textOverflow: 'ellipsis',
        whiteSpace: 'nowrap'
      }
    }, ct.address || ct.city || '', " \xB7 ", (ct.deals || []).filter(function (d) {
      return d.won;
    }).length, " gewonnen deal(s)")), /*#__PURE__*/React.createElement(Icon, {
      name: "chevronright",
      size: 14,
      color: T.fg4
    }));
  })), /*#__PURE__*/React.createElement("div", {
    style: {
      marginTop: 10,
      fontFamily: T.fontBody,
      fontSize: 11,
      color: T.fg4
    }
  }, "Alleen klanten met een gewonnen deal kunnen ingepland worden.")), nieuw && nieuw !== 'pick' && /*#__PURE__*/React.createElement(Modal, {
    open: true,
    onClose: function onClose() {
      return setNieuw(null);
    },
    title: "Werk inplannen \u2014 ".concat(nieuw.firstName, " ").concat(nieuw.lastName),
    width: 880
  }, /*#__PURE__*/React.createElement(PlDealPicker, {
    contact: nieuw,
    items: items,
    onCancel: function onCancel() {
      return setNieuw(null);
    },
    onSave: function onSave(it, f) {
      savePlan(it, f);
      setNieuw(null);
    },
    onKies: inAgenda ? function (it) {
      setNieuw(null);
      window.ghsPlanPlaatsing(it);
    } : null
  })));
};
Object.assign(window, {
  PlanningPage: PlanningPage,
  PlKoppelModal: PlKoppelModal,
  plCrewColor: plCrewColor,
  PL_CREW_COLORS: PL_CREW_COLORS
});