"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
// GHS CRM — Dashboard: het oordeel over een module instellen zonder het dashboard te verlaten.
// Een lade rechts; erachter blijft het dashboard zichtbaar en kleurt live mee. Per module
// bepalen drie dingen het oordeel: de werkdruk (twee grenzen, een gewicht per status en één
// voor dringende opvolgtaken), op tijd afwerken (de doorlooptijd en de minimale succesrate,
// samen in één blok) en de drukte (automatisch, elke nacht om 00:00). Normen per status
// kleuren een status rood. Alles wat instelbaar is, is een termijn uit GHS_DREMPELS,
// geschreven met ghsZetDrempel — dezelfde bron als Instellingen › Statussen & termijnen.
// Welke termijnen een module heeft, volgt uit DSH_MODULES. Een termijn die ook de opvolging
// of een document stuurt, zegt dat erbij. Enkel voor wie Instellingen mag openen.
(function () {
  var DSH_EIGEN_ANKERS = ['DSH_MODULES', 'dshOordeel'];
  var nDef = function nDef(id) {
    return window.ghsDrempelDef ? window.ghsDrempelDef(id) : null;
  };
  var nEigen = function nEigen(id) {
    return !!(window.ghsDrempelEigen && window.ghsDrempelEigen(id));
  };
  var nGedeeld = function nGedeeld(def) {
    return !!def && !DSH_EIGEN_ANKERS.includes(def.anker);
  };
  var nNr = function nNr(v) {
    return (Math.round((v || 0) * 10) / 10).toLocaleString('nl-BE');
  };
  var nHerstel = function nHerstel(ids) {
    return ids.forEach(function (id) {
      if (nEigen(id)) window.ghsDrempelHerstel(id);
    });
  };
  var nBlok = function nBlok(flits) {
    return {
      display: 'flex',
      flexDirection: 'column',
      gap: 12,
      padding: 16,
      background: T.bg1,
      border: "1px solid ".concat(flits ? window.DSH_GROEN : T.stroke1),
      boxShadow: flits ? "inset 0 0 0 1px ".concat(window.DSH_GROEN) : 'none',
      clipPath: cutPath(12),
      transition: 'border-color 400ms, box-shadow 400ms'
    };
  };
  var nH4 = {
    margin: 0,
    fontFamily: T.fontDisplay,
    fontSize: 15.5,
    fontWeight: 600,
    color: T.fg1,
    lineHeight: 1.3
  };
  var nDagen = function nDagen(n) {
    return "".concat(n, " ").concat(n === 1 ? 'dag' : 'dagen');
  };

  /* De instellingen van één module: werkdruk, op tijd afwerken, en één norm per termijn die statussen delen. */
  var dshNormenVan = function dshNormenVan(m) {
    var perId = {};
    (m.statussen || []).forEach(function (s) {
      if (s.norm && s.norm !== 'altijd' && s.richting !== 'tot') (perId[s.norm] = perId[s.norm] || []).push(s);
    });
    var status = Object.keys(perId).map(function (id) {
      return {
        id: id,
        statussen: perId[id]
      };
    });
    var doorloop = (m.fase || {}).norm || null;
    var optijd = "dsh_".concat(m.id, "_optijd_min");
    var W = m.werkdruk || null;
    var wdIds = W ? [W.ids.letop, W.ids.achter].concat(_toConsumableArray(W.delen.map(function (d) {
      return d.wid;
    }))) : [];
    var tijdIds = [doorloop, nDef(optijd) ? optijd : null].filter(Boolean);
    var drukteAan = "dsh_".concat(m.id, "_drukte_aan"),
      aanhoudend = "dsh_".concat(m.id, "_aanhoudend");
    var extraIds = [drukteAan, aanhoudend].filter(function (id) {
      return nDef(id);
    });
    var statusIds = status.map(function (x) {
      return x.id;
    });
    var werkdrukId = "dsh_".concat(m.id, "_werkdruk"),
      opTijdId = "dsh_".concat(m.id, "_optijd"),
      drukteId = "dsh_".concat(m.id, "_drukte"),
      aanhoudId = "dsh_".concat(m.id, "_aanhoudend_blok");
    return {
      doorloop: doorloop,
      optijd: optijd,
      drukteAan: drukteAan,
      aanhoudend: aanhoudend,
      status: status,
      wdIds: wdIds,
      tijdIds: tijdIds,
      statusIds: statusIds,
      werkdrukId: werkdrukId,
      opTijdId: opTijdId,
      drukteId: drukteId,
      aanhoudId: aanhoudId,
      alle: [].concat(_toConsumableArray(wdIds), _toConsumableArray(tijdIds), _toConsumableArray(extraIds), _toConsumableArray(statusIds)),
      focus: [werkdrukId, opTijdId, drukteId, aanhoudId].concat(_toConsumableArray(wdIds), _toConsumableArray(tijdIds), _toConsumableArray(extraIds), _toConsumableArray(statusIds)),
      altijd: (m.statussen || []).filter(function (s) {
        return s.norm === 'altijd';
      }),
      gepland: (m.statussen || []).filter(function (s) {
        return s.richting === 'tot';
      })
    };
  };
  var DshImpact = function DshImpact(_ref) {
    var kleur = _ref.kleur,
      children = _ref.children;
    return /*#__PURE__*/React.createElement("span", {
      style: {
        display: 'inline-flex',
        alignItems: 'center',
        gap: 7,
        fontFamily: T.fontBody,
        fontSize: 12.5,
        fontWeight: 600,
        color: kleur || T.fg3,
        lineHeight: 1.4
      }
    }, kleur && /*#__PURE__*/React.createElement("span", {
      style: {
        width: 7,
        height: 7,
        borderRadius: '50%',
        background: kleur,
        flexShrink: 0
      }
    }), children);
  };

  /* Eén norm: naam, waarvoor ze geldt, de stepper, wat ze nu betekent, standaard of terugzetten. */
  var DshNormRij = function DshNormRij(_ref2) {
    var id = _ref2.id,
      geldt = _ref2.geldt,
      impact = _ref2.impact,
      breed = _ref2.breed,
      flits = _ref2.flits;
    var _window = window,
      KL = _window.DSH_KLEIN,
      GR = _window.DSH_GROEN,
      AM = _window.DSH_AMBER;
    var def = nDef(id);
    if (!def) return null;
    var eigen = nEigen(id),
      gedeeld = nGedeeld(def);
    var stdTxt = def.keuzes ? (def.keuzes.find(function (k) {
      return k.w === def.std;
    }) || {}).label || def.std : "".concat(def.std, " ").concat(def.eenheid);
    return /*#__PURE__*/React.createElement("div", {
      "data-norm": id,
      style: {
        display: 'flex',
        flexDirection: 'column',
        gap: 12,
        padding: '16px 16px 12px',
        background: eigen ? 'rgba(0,217,0,0.06)' : T.bg2,
        border: "1px solid ".concat(flits ? GR : eigen ? T.strokeAccent : T.stroke1),
        boxShadow: flits ? "inset 0 0 0 1px ".concat(GR) : 'none',
        clipPath: cutPath(10),
        transition: 'border-color 400ms, box-shadow 400ms'
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        alignItems: 'flex-start',
        gap: '6px 12px',
        flexWrap: 'wrap'
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        flex: '1 1 200px',
        minWidth: 0
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        fontFamily: T.fontBody,
        fontSize: 13.5,
        fontWeight: 700,
        color: T.fg1,
        lineHeight: 1.35
      }
    }, def.label), geldt && /*#__PURE__*/React.createElement("p", {
      style: _objectSpread(_objectSpread({}, KL), {}, {
        marginTop: 3
      })
    }, geldt)), gedeeld && /*#__PURE__*/React.createElement("span", {
      style: {
        flex: 'none',
        padding: '3px 9px',
        background: 'rgba(255,176,32,0.10)',
        border: '1px solid rgba(255,176,32,0.4)',
        borderRadius: 4,
        fontFamily: T.fontBody,
        fontSize: 11,
        fontWeight: 700,
        color: AM,
        whiteSpace: 'nowrap'
      }
    }, "Geldt ook buiten het dashboard")), gedeeld && /*#__PURE__*/React.createElement("p", {
      style: _objectSpread(_objectSpread({}, KL), {}, {
        marginTop: -4
      })
    }, def.uitleg), /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        alignItems: 'center',
        gap: '12px 18px',
        flexWrap: 'wrap'
      }
    }, window.GhsDrempelStepper ? /*#__PURE__*/React.createElement(window.GhsDrempelStepper, {
      id: id,
      groot: true
    }) : /*#__PURE__*/React.createElement("span", {
      style: {
        fontFamily: T.fontDisplay,
        fontSize: 16,
        fontWeight: 600,
        color: T.fg1
      }
    }, "".concat(window.ghsDrempel(id, def.std), " ").concat(def.eenheid)), impact && /*#__PURE__*/React.createElement("div", {
      style: {
        flex: breed ? '1 1 100%' : '1 1 160px',
        minWidth: 0
      }
    }, impact)), /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        alignItems: 'center',
        gap: 10,
        minHeight: 32,
        paddingTop: 8,
        borderTop: "1px solid ".concat(T.stroke1)
      }
    }, /*#__PURE__*/React.createElement("span", {
      style: _objectSpread(_objectSpread({}, KL), {}, {
        flex: 1
      })
    }, eigen ? "Aangepast \xB7 standaard ".concat(stdTxt) : "Standaard: ".concat(stdTxt)), eigen && /*#__PURE__*/React.createElement(Button, {
      variant: "ghost",
      size: "sm",
      icon: "refresh",
      onClick: function onClick() {
        return window.ghsDrempelHerstel(id);
      }
    }, "Terugzetten")));
  };

  /* Eén gewicht: de status, aantal × gewicht = punten, en de vier standen. */
  var DshGewichtRij = function DshGewichtRij(_ref3) {
    var d = _ref3.d;
    var KL = window.DSH_KLEIN;
    var def = nDef(d.wid);
    if (!def) return null;
    var eigen = nEigen(d.wid);
    var std = (def.keuzes || []).find(function (k) {
      return k.w === def.std;
    });
    return /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        flexDirection: 'column',
        gap: 10,
        padding: '12px 14px',
        background: eigen ? 'rgba(0,217,0,0.06)' : T.bg2,
        border: "1px solid ".concat(eigen ? T.strokeAccent : T.stroke1),
        clipPath: cutPath(9)
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        alignItems: 'center',
        gap: 10,
        minWidth: 0
      }
    }, d.opvolging ? /*#__PURE__*/React.createElement("span", {
      style: {
        display: 'flex',
        flexShrink: 0
      }
    }, /*#__PURE__*/React.createElement(Icon, {
      name: "alert",
      size: 13,
      color: window.DSH_ROOD
    })) : /*#__PURE__*/React.createElement("span", {
      style: {
        width: 8,
        height: 8,
        borderRadius: 2,
        background: d.kleur,
        flexShrink: 0
      }
    }), /*#__PURE__*/React.createElement("span", {
      style: {
        flex: 1,
        minWidth: 0,
        fontFamily: T.fontBody,
        fontSize: 13,
        fontWeight: 600,
        color: T.fg1,
        lineHeight: 1.35
      }
    }, d.label), /*#__PURE__*/React.createElement("span", {
      title: "aantal \xD7 gewicht = punten",
      style: {
        fontFamily: T.fontBody,
        fontSize: 12,
        color: T.fg3,
        whiteSpace: 'nowrap',
        fontVariantNumeric: 'tabular-nums'
      }
    }, "".concat(d.n, " \xD7 ").concat(nNr(d.w), " =")), /*#__PURE__*/React.createElement("span", {
      style: {
        minWidth: 52,
        textAlign: 'right',
        fontFamily: T.fontDisplay,
        fontSize: 14.5,
        fontWeight: 600,
        color: d.punten ? T.fg1 : T.fg4,
        fontVariantNumeric: 'tabular-nums',
        whiteSpace: 'nowrap'
      }
    }, "".concat(nNr(d.punten), " pt"))), window.GhsDrempelStepper && /*#__PURE__*/React.createElement(window.GhsDrempelStepper, {
      id: d.wid,
      groot: true
    }), eigen && /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        alignItems: 'center',
        gap: 10
      }
    }, /*#__PURE__*/React.createElement("span", {
      style: _objectSpread(_objectSpread({}, KL), {}, {
        flex: 1
      })
    }, "Aangepast \xB7 standaard: ".concat(std ? std.label.toLowerCase() : def.std)), /*#__PURE__*/React.createElement(Button, {
      variant: "ghost",
      size: "sm",
      icon: "refresh",
      onClick: function onClick() {
        return window.ghsDrempelHerstel(d.wid);
      }
    }, "Terugzetten")));
  };

  /* 1 · Werkdruk: meter, de twee grenzen en een gewicht per status. */
  var DshWerkdrukBlok = function DshWerkdrukBlok(_ref4) {
    var m = _ref4.m,
      N = _ref4.N,
      flits = _ref4.flits;
    var _window2 = window,
      LBL = _window2.DSH_LBL,
      KL = _window2.DSH_KLEIN,
      AM = _window2.DSH_AMBER,
      RO = _window2.DSH_ROOD,
      GR = _window2.DSH_GROEN;
    var W = m.werkdruk;
    var status = W.delen.filter(function (d) {
        return !d.opvolging;
      }),
      opv = W.delen.find(function (d) {
        return d.opvolging;
      });
    var gewIds = W.delen.map(function (d) {
        return d.wid;
      }),
      gewAangepast = gewIds.filter(nEigen).length;
    var kl = W.stand === 'achter' ? RO : W.stand === 'letop' ? AM : GR;
    var grensImpact = function grensImpact(v, k) {
      return W.totaal >= v ? /*#__PURE__*/React.createElement(DshImpact, {
        kleur: k
      }, "nu ".concat(nNr(W.totaal), " punten \u2014 erboven")) : /*#__PURE__*/React.createElement(DshImpact, null, "nu ".concat(nNr(W.totaal), " punten \u2014 eronder"));
    };
    return /*#__PURE__*/React.createElement("div", {
      "data-norm": N.werkdrukId,
      style: nBlok(flits)
    }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("h4", {
      style: nH4
    }, "Werkdruk"), /*#__PURE__*/React.createElement("p", {
      style: _objectSpread(_objectSpread({}, KL), {}, {
        marginTop: 4
      })
    }, "Hoeveel er tegelijk mag liggen. Elk dossier telt mee volgens het gewicht van zijn status; elke dringende opvolgtaak (onder \u201CNu doen\u201D in de opvolgband van de module) volgens haar eigen gewicht. Boven een grens verandert het oordeel over de module.")), window.DshWerkdrukMeter && /*#__PURE__*/React.createElement("div", {
      style: {
        padding: '14px 16px 8px',
        background: T.bg0,
        border: "1px solid ".concat(T.stroke1),
        clipPath: cutPath(9)
      }
    }, /*#__PURE__*/React.createElement(window.DshWerkdrukMeter, {
      W: W,
      klein: true
    })), /*#__PURE__*/React.createElement("span", {
      style: _objectSpread(_objectSpread({}, LBL), {}, {
        fontSize: 10,
        marginTop: 4
      })
    }, "Grenzen"), /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'grid',
        gridTemplateColumns: 'repeat(auto-fit,minmax(min(100%,230px),1fr))',
        gap: 10
      }
    }, /*#__PURE__*/React.createElement(DshNormRij, {
      id: W.ids.letop,
      geldt: 'Vanaf hier meldt het dashboard "Let op".',
      impact: grensImpact(W.letop, AM)
    }), /*#__PURE__*/React.createElement(DshNormRij, {
      id: W.ids.achter,
      geldt: 'Vanaf hier "Loopt achter": de module kleurt rood.',
      impact: grensImpact(W.achter, RO)
    })), W.letop >= W.achter && /*#__PURE__*/React.createElement("p", {
      style: _objectSpread(_objectSpread({}, KL), {}, {
        color: AM,
        fontWeight: 600
      })
    }, "\"Let op\" ligt niet lager dan \"Loopt achter\" \u2014 dan verschijnt Let op nooit."), /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        alignItems: 'baseline',
        justifyContent: 'space-between',
        gap: '4px 10px',
        flexWrap: 'wrap',
        marginTop: 6
      }
    }, /*#__PURE__*/React.createElement("span", {
      style: _objectSpread(_objectSpread({}, LBL), {}, {
        fontSize: 10
      })
    }, "Gewicht per status"), /*#__PURE__*/React.createElement("span", {
      style: KL
    }, "aantal \xD7 gewicht = punten \xB7 te laat weegt niet extra")), status.map(function (d) {
      return /*#__PURE__*/React.createElement(DshGewichtRij, {
        key: d.id,
        d: d
      });
    }), opv && /*#__PURE__*/React.createElement("span", {
      style: _objectSpread(_objectSpread({}, LBL), {}, {
        fontSize: 10,
        marginTop: 6
      })
    }, "Opvolging"), opv && /*#__PURE__*/React.createElement(DshGewichtRij, {
      d: opv
    }), /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        alignItems: 'center',
        gap: '8px 12px',
        flexWrap: 'wrap',
        paddingTop: 12,
        marginTop: 2,
        borderTop: "1px solid ".concat(T.stroke1)
      }
    }, /*#__PURE__*/React.createElement("span", {
      style: {
        fontFamily: T.fontBody,
        fontSize: 13,
        fontWeight: 700,
        color: T.fg1
      }
    }, "Samen"), /*#__PURE__*/React.createElement("span", {
      style: {
        fontFamily: T.fontDisplay,
        fontSize: 17,
        fontWeight: 600,
        color: kl,
        fontVariantNumeric: 'tabular-nums'
      }
    }, "".concat(nNr(W.totaal), " punten")), gewAangepast > 0 && /*#__PURE__*/React.createElement("span", {
      style: {
        marginLeft: 'auto'
      }
    }, /*#__PURE__*/React.createElement(Button, {
      variant: "ghost",
      size: "sm",
      icon: "refresh",
      onClick: function onClick() {
        return nHerstel(gewIds);
      }
    }, "Gewichten terugzetten"))));
  };

  /* 2 · Op tijd afgewerkt: de doorlooptijd (hoeveel dagen telt als op tijd) en het minimum
     dat op tijd moet zijn, naast elkaar — de twee getallen die samen de succesrate maken. */
  var DshOpTijdBlok = function DshOpTijdBlok(_ref5) {
    var m = _ref5.m,
      N = _ref5.N,
      flits = _ref5.flits;
    var _window3 = window,
      KL = _window3.DSH_KLEIN,
      AM = _window3.DSH_AMBER,
      GR = _window3.DSH_GROEN;
    var K = m.K,
      minOk = m.oordeel.drempels.minOk;
    var stap = (window.DSH_STAPPEN || []).find(function (s) {
      return s.id === (m.fase || {}).stapId;
    });
    return /*#__PURE__*/React.createElement("div", {
      "data-norm": N.opTijdId,
      style: nBlok(flits)
    }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("h4", {
      style: nH4
    }, "Op tijd afgewerkt"), /*#__PURE__*/React.createElement("p", {
      style: _objectSpread(_objectSpread({}, KL), {}, {
        marginTop: 4
      })
    }, "Een dossier telt als op tijd als het binnen de doorlooptijd hieronder afgewerkt is".concat(stap ? " (stap: ".concat(stap.label, ")") : '', ". Haalt ").concat(m.label.toLowerCase(), " het minimum niet, dan meldt het dashboard \"Let op\"."))), /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'grid',
        gridTemplateColumns: 'repeat(auto-fit,minmax(min(100%,230px),1fr))',
        gap: 10
      }
    }, N.doorloop && /*#__PURE__*/React.createElement(DshNormRij, {
      id: N.doorloop,
      flits: flits === N.doorloop,
      geldt: "Op tijd = ".concat(K.normTekst, "."),
      impact: K.looptijd.gem == null ? /*#__PURE__*/React.createElement(DshImpact, null, "nog niets afgewerkt in deze periode") : /*#__PURE__*/React.createElement(DshImpact, {
        kleur: K.looptijd.gem > K.norm ? AM : GR
      }, "nu gemiddeld ".concat(nNr(K.looptijd.gem), " dagen"))
    }), nDef(N.optijd) && /*#__PURE__*/React.createElement(DshNormRij, {
      id: N.optijd,
      flits: flits === N.optijd,
      geldt: "Zoveel procent moet binnen die doorlooptijd afgewerkt zijn.",
      impact: K.opTijd ? /*#__PURE__*/React.createElement(DshImpact, {
        kleur: K.opTijd.pct < minOk ? AM : GR
      }, "nu ".concat(K.opTijd.ok, " van ").concat(K.opTijd.n, " op tijd (").concat(K.opTijd.pct, "%)")) : /*#__PURE__*/React.createElement(DshImpact, null, "nog niets afgewerkt in deze periode")
    })));
  };

  /* 3 · Drukte: geen instelling. De grens is de gemiddelde schommeling van de instroom,
     elke nacht om 00:00 berekend; hier staat wat ze nu is en waarop ze steunt. */
  var DshDrukteBlok = function DshDrukteBlok(_ref6) {
    var m = _ref6.m,
      N = _ref6.N,
      P = _ref6.P,
      flits = _ref6.flits;
    var _window4 = window,
      LBL = _window4.DSH_LBL,
      KL = _window4.DSH_KLEIN,
      GT = _window4.DSH_GETAL,
      AM = _window4.DSH_AMBER;
    var K = m.K;
    var idx = K.instroomIdx != null ? Math.round((K.instroomIdx - 1) * 100) : null;
    var druk = idx != null && K.schommeling != null && idx > K.schommeling;
    var tegel = function tegel(label, waarde, sub, kleur) {
      return /*#__PURE__*/React.createElement("div", {
        key: label,
        style: {
          display: 'flex',
          flexDirection: 'column',
          gap: 5,
          padding: '12px 14px',
          background: T.bg2,
          border: "1px solid ".concat(kleur ? kleur + '59' : T.stroke1),
          clipPath: cutPath(8),
          minWidth: 0
        }
      }, /*#__PURE__*/React.createElement("span", {
        style: _objectSpread(_objectSpread({}, LBL), {}, {
          fontSize: 9.5
        })
      }, label), /*#__PURE__*/React.createElement("span", {
        style: _objectSpread(_objectSpread({}, GT), {}, {
          fontSize: 20,
          color: kleur || T.fg1
        })
      }, waarde), /*#__PURE__*/React.createElement("span", {
        style: KL
      }, sub));
    };
    return /*#__PURE__*/React.createElement("div", {
      "data-norm": N.drukteId,
      style: nBlok(flits)
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        alignItems: 'flex-start',
        gap: '6px 12px',
        flexWrap: 'wrap'
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        flex: '1 1 240px',
        minWidth: 0
      }
    }, /*#__PURE__*/React.createElement("h4", {
      style: nH4
    }, "Drukker dan gewoonlijk"), /*#__PURE__*/React.createElement("p", {
      style: _objectSpread(_objectSpread({}, KL), {}, {
        marginTop: 4
      })
    }, "Geen vast percentage: de grens is de gemiddelde schommeling van de instroom. Zo ver lag een drukkere periode van dezelfde lengte de voorbije 12 maanden gemiddeld boven het gemiddelde. Komt er nu meer binnen dan dat, dan meldt het dashboard \"Drukker dan gewoonlijk\".")), /*#__PURE__*/React.createElement("span", {
      style: {
        flex: 'none',
        padding: '3px 9px',
        background: T.bg2,
        border: "1px solid ".concat(T.stroke2),
        borderRadius: 4,
        fontFamily: T.fontBody,
        fontSize: 11,
        fontWeight: 700,
        color: T.fg2,
        whiteSpace: 'nowrap'
      }
    }, "Automatisch")), nDef(N.drukteAan) && /*#__PURE__*/React.createElement(DshNormRij, {
      id: N.drukteAan,
      flits: flits === N.drukteAan,
      geldt: 'Uit: deze module krijgt nooit "Drukker dan gewoonlijk"; de drukte blijft wel zichtbaar.'
    }), K.gewoonlijk == null ? /*#__PURE__*/React.createElement("p", {
      style: _objectSpread(_objectSpread({}, KL), {}, {
        color: T.fg2
      })
    }, "Nog te weinig historiek voor een periode van ".concat(nDagen(P.dagen), ": daarvoor is minstens ").concat(nDagen(K.gwNodig), " instroom nodig. Kies een kortere periode, of wacht tot er meer gegevens zijn.")) : /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'grid',
        gridTemplateColumns: 'repeat(auto-fit,minmax(min(100%,130px),1fr))',
        gap: 8
      }
    }, tegel('Gewoonlijk', "\xB1 ".concat(nNr(K.gewoonlijk)), "per ".concat(nDagen(P.dagen))), tegel('Drukker vanaf', "+".concat(K.schommeling, "%"), 'gemiddelde schommeling'), tegel('Nu', "".concat(idx > 0 ? '+' : idx < 0 ? '−' : '').concat(Math.abs(idx), "%"), "".concat(K.instroom, " binnengekomen"), druk ? AM : null)), /*#__PURE__*/React.createElement("p", {
      style: KL
    }, "Elke nacht om 00:00 opnieuw berekend".concat(K.gwDatum ? " \xB7 bijgewerkt ".concat(window.dshNL(K.gwDatum, true), " om 00:00") : '', " \xB7 telt: ").concat(m.fase.inUitleg)));
  };

  /* 4 · Aanhoudende problemen: vanaf hoeveel maanden op rij iets buiten de norm aanhoudend is,
     met de reeksen van nu (maand per maand over de voorbije 12 maanden). */
  var DshAanhoudBlok = function DshAanhoudBlok(_ref7) {
    var m = _ref7.m,
      N = _ref7.N,
      flits = _ref7.flits;
    var _window5 = window,
      KL = _window5.DSH_KLEIN,
      RO = _window5.DSH_ROOD,
      AM = _window5.DSH_AMBER;
    var alle = m.oordeel.aanhoudendAlle || [];
    var mnd = function mnd(n) {
      return "".concat(n, " ").concat(n === 1 ? 'maand' : 'maanden');
    };
    return /*#__PURE__*/React.createElement("div", {
      "data-norm": N.aanhoudId,
      style: nBlok(flits)
    }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("h4", {
      style: nH4
    }, "Aanhoudende problemen"), /*#__PURE__*/React.createElement("p", {
      style: _objectSpread(_objectSpread({}, KL), {}, {
        marginTop: 4
      })
    }, "Meer dan een momentopname: maand per maand over de voorbije 12 maanden, tegenover de normen hierboven. Telt mee: de succesrate onder het minimum, de doorlooptijd boven de norm, en een werkvoorraad die groeit (meer binnen dan afgewerkt). Een maand zonder metingen onderbreekt de reeks.")), nDef(N.aanhoudend) && /*#__PURE__*/React.createElement(DshNormRij, {
      id: N.aanhoudend,
      breed: true,
      flits: flits === N.aanhoudend,
      geldt: "Zoveel maanden op rij buiten de norm = een aanhoudend probleem.",
      impact: /*#__PURE__*/React.createElement("div", {
        style: {
          display: 'flex',
          flexDirection: 'column',
          gap: 6
        }
      }, alle.map(function (a) {
        return /*#__PURE__*/React.createElement(DshImpact, {
          key: a.id,
          kleur: a.aan ? RO : a.n ? AM : null
        }, "".concat(a.label, ": ").concat(a.n ? "".concat(mnd(a.n), " op rij buiten de norm") : 'in orde').concat(a.aan ? ' — aanhoudend' : ''));
      }))
    }));
  };

  /* Uitklapbare groep: kop met naam en stand, inhoud eronder. */
  var DshNormGroep = function DshNormGroep(_ref8) {
    var kop = _ref8.kop,
      icon = _ref8.icon,
      open = _ref8.open,
      onToggle = _ref8.onToggle,
      children = _ref8.children;
    return /*#__PURE__*/React.createElement("section", {
      style: {
        background: T.bg0,
        border: "1px solid ".concat(open ? T.stroke2 : T.stroke1),
        clipPath: cutPath(12),
        minWidth: 0
      }
    }, /*#__PURE__*/React.createElement("button", {
      type: "button",
      onClick: onToggle,
      "aria-expanded": open,
      style: {
        width: '100%',
        display: 'flex',
        alignItems: 'center',
        gap: 12,
        minHeight: 64,
        padding: '12px 16px',
        background: 'none',
        border: 'none',
        cursor: 'pointer',
        textAlign: 'left'
      }
    }, /*#__PURE__*/React.createElement("span", {
      style: {
        width: 34,
        height: 34,
        flex: 'none',
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'center',
        background: T.bg2,
        border: "1px solid ".concat(T.stroke1),
        clipPath: cutPath(6)
      }
    }, /*#__PURE__*/React.createElement(Icon, {
      name: icon,
      size: 15,
      color: T.fg2
    })), /*#__PURE__*/React.createElement("span", {
      style: {
        flex: 1,
        minWidth: 0
      }
    }, kop), /*#__PURE__*/React.createElement(Icon, {
      name: open ? 'chevronup' : 'chevrondown',
      size: 15,
      color: T.fg3
    })), open && /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        flexDirection: 'column',
        gap: 10,
        padding: '2px 16px 16px'
      }
    }, children));
  };
  var DshNormen = function DshNormen(_ref9) {
    var A = _ref9.A,
      modules = _ref9.modules,
      focus = _ref9.focus,
      onClose = _ref9.onClose;
    if (window.useGhsDrempels) window.useGhsDrempels();
    var _window6 = window,
      LBL = _window6.DSH_LBL,
      H2 = _window6.DSH_H2,
      H3 = _window6.DSH_H3,
      KL = _window6.DSH_KLEIN,
      RO = _window6.DSH_ROOD,
      GR = _window6.DSH_GROEN;
    var mods = A.modules.filter(function (m) {
      return !modules || modules.includes(m.id);
    });
    var enkel = mods.length === 1 && modules ? mods[0] : null;
    var groepVan = function groepVan(id) {
      return (mods.find(function (m) {
        return dshNormenVan(m).focus.includes(id);
      }) || {}).id;
    };
    var _React$useState = React.useState(function () {
        var s = {};
        if (enkel) s[enkel.id] = true;
        if (focus) s[groepVan(focus)] = true;
        return s;
      }),
      _React$useState2 = _slicedToArray(_React$useState, 2),
      open = _React$useState2[0],
      setOpen = _React$useState2[1];
    var _React$useState3 = React.useState(focus || null),
      _React$useState4 = _slicedToArray(_React$useState3, 2),
      flits = _React$useState4[0],
      setFlits = _React$useState4[1];
    var _React$useState5 = React.useState(false),
      _React$useState6 = _slicedToArray(_React$useState5, 2),
      zicht = _React$useState6[0],
      setZicht = _React$useState6[1];
    var scrollRef = React.useRef(null),
      sluitRef = React.useRef(null),
      sluitFn = React.useRef(onClose);
    sluitFn.current = onClose;
    React.useEffect(function () {
      var r = requestAnimationFrame(function () {
        return setZicht(true);
      });
      var knop = sluitRef.current && sluitRef.current.querySelector('[data-ghs-dialoogkop] button[aria-label]');
      if (knop) knop.focus({
        preventScroll: true
      });
      var k = function k(e) {
        if (e.key === 'Escape') sluitFn.current();
      };
      window.addEventListener('keydown', k);
      return function () {
        cancelAnimationFrame(r);
        window.removeEventListener('keydown', k);
      };
    }, []);
    React.useEffect(function () {
      if (!focus) return undefined;
      var t1 = setTimeout(function () {
        var c = scrollRef.current,
          el = c && c.querySelector("[data-norm=\"".concat(focus, "\"]"));
        if (c && el) c.scrollTo({
          top: c.scrollTop + el.getBoundingClientRect().top - c.getBoundingClientRect().top - 16,
          behavior: 'smooth'
        });
      }, 80);
      var t2 = setTimeout(function () {
        return setFlits(null);
      }, 2000);
      return function () {
        clearTimeout(t1);
        clearTimeout(t2);
      };
    }, [focus]);
    var wissel = function wissel(id) {
      return setOpen(function (o) {
        return _objectSpread(_objectSpread({}, o), {}, _defineProperty({}, id, !o[id]));
      });
    };
    var statusImpact = function statusImpact(statussen) {
      var n = statussen.reduce(function (t, s) {
          return t + s.n;
        }, 0),
        b = statussen.reduce(function (t, s) {
          return t + s.boven;
        }, 0);
      if (!n) return /*#__PURE__*/React.createElement(DshImpact, null, statussen.length > 1 ? 'nu niets in deze statussen' : 'nu niets in deze status');
      return b ? /*#__PURE__*/React.createElement(DshImpact, {
        kleur: RO
      }, "".concat(b, " van ").concat(n, " nu boven de norm")) : /*#__PURE__*/React.createElement(DshImpact, {
        kleur: GR
      }, n === 1 ? 'binnen de norm' : "alle ".concat(n, " binnen de norm"));
    };
    var Portal = typeof GhsPortal !== 'undefined' ? GhsPortal : function (_ref0) {
      var children = _ref0.children;
      return children;
    };
    var knoppen = [window.ghsGaInstelling ? /*#__PURE__*/React.createElement(Button, {
      key: "inst",
      variant: "ghost",
      icon: "settings",
      onClick: function onClick() {
        sluitFn.current();
        window.ghsGaInstelling('statussen');
      }
    }, "Alle termijnen in Instellingen") : null, /*#__PURE__*/React.createElement(Button, {
      key: "klaar",
      variant: "primary",
      icon: "check",
      onClick: function onClick() {
        return sluitFn.current();
      }
    }, "Klaar")];
    return /*#__PURE__*/React.createElement(Portal, null, /*#__PURE__*/React.createElement("div", {
      onMouseDown: function onMouseDown(e) {
        if (e.target === e.currentTarget) sluitFn.current();
      },
      style: {
        position: 'fixed',
        inset: 0,
        zIndex: 3000,
        background: zicht ? 'rgba(1,12,8,0.45)' : 'rgba(1,12,8,0)',
        transition: 'background 200ms'
      }
    }, /*#__PURE__*/React.createElement("aside", {
      ref: sluitRef,
      role: "dialog",
      "aria-modal": "true",
      "aria-label": enkel ? "Oordeel en normen voor ".concat(enkel.label) : 'Oordeel en normen',
      style: {
        position: 'absolute',
        top: 0,
        right: 0,
        bottom: 0,
        width: '90%',
        maxWidth: 580,
        display: 'flex',
        flexDirection: 'column',
        background: T.bg1,
        borderLeft: "1px solid ".concat(T.stroke2),
        boxShadow: '-24px 0 60px rgba(0,0,0,0.45)',
        transform: zicht ? 'none' : 'translateX(28px)',
        opacity: zicht ? 1 : 0,
        transition: 'transform 220ms ease, opacity 220ms ease'
      }
    }, /*#__PURE__*/React.createElement(GhsDialoogKop, {
      label: enkel ? "Dashboard \xB7 ".concat(enkel.label) : 'Dashboard',
      titel: 'Oordeel en normen',
      boven: true,
      onClose: function onClose() {
        return sluitFn.current();
      },
      sub: /*#__PURE__*/React.createElement(React.Fragment, null, "Per module bepalen drie dingen het oordeel: de werkdruk, op tijd afwerken en de drukte. Normen per status kleuren een status rood. Wat je wijzigt, geldt meteen \u2014 het dashboard erachter kleurt mee \u2014 en staat ook in Instellingen \u203A Statussen & termijnen.")
    }), /*#__PURE__*/React.createElement("div", {
      ref: scrollRef,
      style: {
        flex: 1,
        overflowY: 'auto',
        padding: '18px 22px 28px',
        display: 'flex',
        flexDirection: 'column',
        gap: 12
      }
    }, mods.map(function (m) {
      var N = dshNormenVan(m),
        aangepast = N.alle.filter(nEigen).length;
      return /*#__PURE__*/React.createElement(DshNormGroep, {
        key: m.id,
        icon: m.icon,
        open: !!open[m.id],
        onToggle: function onToggle() {
          return wissel(m.id);
        },
        kop: /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", {
          style: _objectSpread(_objectSpread({}, H3), {}, {
            display: 'block'
          })
        }, m.label), /*#__PURE__*/React.createElement("span", {
          style: {
            display: 'flex',
            alignItems: 'center',
            gap: '6px 10px',
            flexWrap: 'wrap',
            marginTop: 6
          }
        }, window.DshOordeelChip && /*#__PURE__*/React.createElement(window.DshOordeelChip, {
          o: m.oordeel
        }), m.oordeel.aanhoudend && m.oordeel.aanhoudend.length > 0 && window.DshAanhoudendChip && /*#__PURE__*/React.createElement(window.DshAanhoudendChip, {
          o: m.oordeel
        }), /*#__PURE__*/React.createElement("span", {
          style: KL
        }, "".concat(m.werkdruk ? "werkdruk ".concat(nNr(m.werkdruk.totaal), " punten \xB7 ") : '').concat(N.alle.length, " instellingen").concat(aangepast ? " \xB7 ".concat(aangepast, " aangepast") : ''))))
      }, m.oordeel.regels && window.DshRegels && /*#__PURE__*/React.createElement("div", {
        style: {
          display: 'flex',
          flexDirection: 'column',
          gap: 8
        }
      }, /*#__PURE__*/React.createElement("span", {
        style: _objectSpread(_objectSpread({}, LBL), {}, {
          fontSize: 10
        })
      }, "Zo komt het oordeel nu tot stand"), /*#__PURE__*/React.createElement(window.DshRegels, {
        regels: m.oordeel.regels,
        compact: true
      })), m.werkdruk && /*#__PURE__*/React.createElement(DshWerkdrukBlok, {
        m: m,
        N: N,
        flits: flits === N.werkdrukId
      }), N.tijdIds.length > 0 && /*#__PURE__*/React.createElement(DshOpTijdBlok, {
        m: m,
        N: N,
        flits: flits === N.opTijdId
      }), /*#__PURE__*/React.createElement(DshDrukteBlok, {
        m: m,
        N: N,
        P: A.P,
        flits: flits === N.drukteId
      }), /*#__PURE__*/React.createElement(DshAanhoudBlok, {
        m: m,
        N: N,
        flits: flits === N.aanhoudId
      }), N.status.length > 0 && /*#__PURE__*/React.createElement("div", {
        style: {
          marginTop: 10
        }
      }, /*#__PURE__*/React.createElement("span", {
        style: _objectSpread(_objectSpread({}, LBL), {}, {
          fontSize: 10
        })
      }, "Norm per status"), /*#__PURE__*/React.createElement("p", {
        style: _objectSpread(_objectSpread({}, KL), {}, {
          marginTop: 4
        })
      }, "Ligt het gemiddelde van een status boven haar norm, dan kleurt ze rood. Telt niet mee in het oordeel.")), N.status.map(function (x) {
        return /*#__PURE__*/React.createElement(DshNormRij, {
          key: x.id,
          id: x.id,
          flits: flits === x.id,
          geldt: "Geldt voor: ".concat(x.statussen.map(function (s) {
            return s.label;
          }).join(' · ')),
          impact: statusImpact(x.statussen)
        });
      }), (N.altijd.length > 0 || N.gepland.length > 0) && /*#__PURE__*/React.createElement("div", {
        style: {
          display: 'flex',
          flexDirection: 'column',
          gap: 4,
          padding: '4px 2px 0'
        }
      }, N.altijd.length > 0 && /*#__PURE__*/React.createElement("p", {
        style: KL
      }, /*#__PURE__*/React.createElement("b", {
        style: {
          color: T.fg2,
          fontWeight: 600
        }
      }, "Altijd te laat: "), N.altijd.map(function (s) {
        return s.label;
      }).join(' · ')), N.gepland.length > 0 && /*#__PURE__*/React.createElement("p", {
        style: KL
      }, /*#__PURE__*/React.createElement("b", {
        style: {
          color: T.fg2,
          fontWeight: 600
        }
      }, "Gepland, zonder norm: "), N.gepland.map(function (s) {
        return s.label;
      }).join(' · '))), aangepast > 0 && /*#__PURE__*/React.createElement("div", {
        style: {
          display: 'flex',
          justifyContent: 'flex-end',
          marginTop: 4
        }
      }, /*#__PURE__*/React.createElement(Button, {
        variant: "ghost",
        size: "sm",
        icon: "refresh",
        onClick: function onClick() {
          return nHerstel(N.alle);
        }
      }, "Alles van ".concat(m.label, " terugzetten"))));
    })), /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'flex-end',
        flexWrap: 'wrap-reverse',
        gap: 8,
        padding: '14px 24px',
        borderTop: "1px solid ".concat(T.stroke1),
        background: T.bg1
      }
    }, window.ghsKnopVolgorde ? window.ghsKnopVolgorde(knoppen, 'flex-end') : knoppen))));
  };
  Object.assign(window, {
    DshNormen: DshNormen,
    dshNormenVan: dshNormenVan
  });
})();