"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
function 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 _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
/* __IIFE_WRAPPED__ */
(function () {
  // GHS CRM — Contactfiche · shell (stepper, view-tabs), ContactFiche & FicheOverlay

  var _React = React,
    uS = _React.useState,
    useEffect = _React.useEffect;

  /* ── Deal-fase indicator ─────────────────────────────────────────────────────── */
  var PHASE_NODE = {
    done: {
      ring: T.accent,
      fill: 'rgba(0,217,0,0.16)',
      txt: T.fg2
    },
    current: {
      ring: T.accent,
      fill: 'rgba(0,217,0,0.12)',
      txt: T.fg1
    },
    upcoming: {
      ring: T.stroke2,
      fill: 'transparent',
      txt: T.fg3
    }
  };

  // Volledige stepper — verschijnt bij hover, neemt de hele balk over.
  // `show` stuurt de stagger-animatie van de fase-nodes aan.
  var FullStepper = function FullStepper(_ref) {
    var phases = _ref.phases,
      show = _ref.show,
      onPick = _ref.onPick;
    return /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        alignItems: 'center',
        width: '100%'
      }
    }, /*#__PURE__*/React.createElement("span", {
      style: {
        fontFamily: T.fontBody,
        fontSize: 9.5,
        fontWeight: 700,
        letterSpacing: '0.16em',
        textTransform: 'uppercase',
        color: T.fg3,
        marginRight: 18,
        flexShrink: 0,
        opacity: show ? 1 : 0,
        transition: 'opacity 0.25s ease 0.05s'
      }
    }, "Recente activiteit"), /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        alignItems: 'flex-start',
        flex: 1,
        minWidth: 0
      }
    }, phases.map(function (p, i) {
      var st = PHASE_NODE[p.status];
      var next = phases[i + 1];
      var delay = 0.04 + i * 0.045;
      return /*#__PURE__*/React.createElement("div", {
        key: p.id,
        style: {
          display: 'flex',
          alignItems: 'flex-start',
          flex: next ? 1 : '0 0 auto',
          minWidth: 0
        }
      }, /*#__PURE__*/React.createElement("button", {
        type: "button",
        onClick: function onClick() {
          return onPick && onPick(p.id);
        },
        title: "Openen: ".concat(p.label),
        style: {
          display: 'flex',
          flexDirection: 'column',
          alignItems: 'center',
          gap: 6,
          width: 82,
          flexShrink: 0,
          background: 'none',
          border: 'none',
          padding: 0,
          cursor: 'pointer',
          opacity: show ? 1 : 0,
          transform: show ? 'translateY(0) scale(1)' : 'translateY(6px) scale(0.7)',
          transition: "opacity 0.32s ease ".concat(delay, "s, transform 0.42s cubic-bezier(0.34,1.56,0.64,1) ").concat(delay, "s")
        },
        onMouseEnter: function onMouseEnter(e) {
          var c = e.currentTarget.firstChild;
          if (c) {
            c.style.borderColor = T.accent;
            c.style.transform = 'scale(1.12)';
          }
        },
        onMouseLeave: function onMouseLeave(e) {
          var c = e.currentTarget.firstChild;
          if (c) {
            c.style.borderColor = st.ring;
            c.style.transform = 'scale(1)';
          }
        }
      }, /*#__PURE__*/React.createElement("span", {
        style: {
          width: 28,
          height: 28,
          borderRadius: '50%',
          background: st.fill,
          border: "1.5px solid ".concat(st.ring),
          display: 'flex',
          alignItems: 'center',
          justifyContent: 'center',
          flexShrink: 0,
          transition: 'transform 0.18s ease, border-color 0.18s ease',
          boxShadow: p.status === 'current' ? T.accentGlow : 'none'
        }
      }, p.status === 'done' ? /*#__PURE__*/React.createElement(Icon, {
        name: "check",
        size: 13,
        color: T.accent,
        sw: 2.6
      }) : /*#__PURE__*/React.createElement(Icon, {
        name: p.icon,
        size: 13,
        color: st.ring
      })), /*#__PURE__*/React.createElement("span", {
        style: {
          fontFamily: T.fontBody,
          fontSize: 10.5,
          fontWeight: p.status === 'current' ? 700 : 500,
          color: st.txt,
          textAlign: 'center',
          lineHeight: 1.2,
          whiteSpace: 'nowrap'
        }
      }, p.label)), next && /*#__PURE__*/React.createElement("span", {
        style: {
          flex: 1,
          height: 2,
          marginTop: 13,
          borderRadius: 2,
          minWidth: 10,
          background: p.status === 'done' ? T.accent : T.stroke1,
          boxShadow: p.status === 'done' ? '0 0 8px rgba(0,217,0,0.4)' : 'none',
          transformOrigin: 'left',
          transform: show ? 'scaleX(1)' : 'scaleX(0)',
          opacity: show ? 1 : 0,
          transition: "transform 0.35s ease ".concat(delay + 0.05, "s, opacity 0.2s ease ").concat(delay + 0.05, "s")
        }
      }));
    })));
  };

  // Bevestigingsdialoog bij het wijzigen van de klantstatus via de stepper.
  var ConfirmKlantstatus = function ConfirmKlantstatus(_ref2) {
    var phase = _ref2.phase,
      onYes = _ref2.onYes,
      onNo = _ref2.onNo;
    return /*#__PURE__*/React.createElement("div", {
      onMouseDown: function onMouseDown(e) {
        return e.target === e.currentTarget && onNo();
      },
      style: {
        position: 'fixed',
        inset: 0,
        background: 'rgba(1,12,8,0.78)',
        backdropFilter: 'blur(5px)',
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'center',
        zIndex: 200,
        padding: '20px 20px calc(20px + var(--ghs-dock, 0px))'
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        width: 390,
        maxWidth: '100%',
        background: T.bg1,
        border: "1px solid ".concat(T.stroke2),
        clipPath: cutPath(14),
        position: 'relative',
        padding: 22,
        boxSizing: 'border-box',
        boxShadow: '0 44px 96px -28px rgba(0,0,0,0.85)'
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: accentEdge(14)
    }), /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        alignItems: 'center',
        gap: 12,
        marginBottom: 10
      }
    }, /*#__PURE__*/React.createElement("span", {
      style: {
        width: 40,
        height: 40,
        clipPath: cutPath(8),
        background: 'rgba(0,217,0,0.12)',
        border: "1px solid ".concat(T.strokeAccent),
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'center',
        flexShrink: 0
      }
    }, /*#__PURE__*/React.createElement(Icon, {
      name: phase.icon,
      size: 19,
      color: T.accent
    })), /*#__PURE__*/React.createElement("h3", {
      style: {
        margin: 0,
        fontFamily: T.fontDisplay,
        fontSize: 19,
        fontWeight: 600,
        color: T.fg1
      }
    }, "Klantstatus aanpassen?")), /*#__PURE__*/React.createElement("p", {
      style: {
        margin: '0 0 18px',
        fontFamily: T.fontBody,
        fontSize: 13.5,
        color: T.fg2,
        lineHeight: 1.55
      }
    }, "Wil je de klantstatus wijzigen naar ", /*#__PURE__*/React.createElement("span", {
      style: {
        color: T.accent,
        fontWeight: 700
      }
    }, phase.label), "?"), /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        justifyContent: 'flex-end',
        gap: 10
      }
    }, /*#__PURE__*/React.createElement(Button, {
      variant: "ghost",
      size: "sm",
      onClick: onNo
    }, "Nee"), /*#__PURE__*/React.createElement(Button, {
      variant: "primary",
      size: "sm",
      icon: "check",
      onClick: onYes
    }, "Ja"))));
  };

  // Compacte indicator naast de naam — huidige fase centraal, randen wegfadend.
  // Geen box: enkel een soft fade links/rechts in de achtergrond.
  // Hover → klapt open over de hele kopbalk (FullStepper). Header moet position:relative zijn.
  // Contact info is geen dealfase en valt buiten deze overview.
  var PhaseIndicator = function PhaseIndicator(_ref3) {
    var phases = _ref3.phases,
      onChangePhase = _ref3.onChangePhase,
      sinds = _ref3.sinds;
    var _uS = uS(false),
      _uS2 = _slicedToArray(_uS, 2),
      open = _uS2[0],
      setOpen = _uS2[1];
    var _uS3 = uS(null),
      _uS4 = _slicedToArray(_uS3, 2),
      pending = _uS4[0],
      setPending = _uS4[1];
    var dealPhases = phases.filter(function (p) {
      return p.id !== 'contact';
    });
    var PhaseDot = function PhaseDot(_ref4) {
      var p = _ref4.p;
      var done = p.status === 'done';
      return /*#__PURE__*/React.createElement("span", {
        style: {
          width: 24,
          height: 24,
          borderRadius: '50%',
          flexShrink: 0,
          background: done ? 'rgba(0,217,0,0.12)' : 'transparent',
          border: "1.5px solid ".concat(done ? T.accent : T.stroke2),
          display: 'flex',
          alignItems: 'center',
          justifyContent: 'center'
        }
      }, done ? /*#__PURE__*/React.createElement(Icon, {
        name: "check",
        size: 12,
        color: T.accent,
        sw: 2.6
      }) : /*#__PURE__*/React.createElement(Icon, {
        name: p.icon,
        size: 12,
        color: T.fg4
      }));
    };
    var ci = dealPhases.findIndex(function (p) {
      return p.status === 'current';
    });
    var before = ci >= 0 ? dealPhases.slice(0, ci) : dealPhases;
    var cur = ci >= 0 ? dealPhases[ci] : null;
    var after = ci >= 0 ? dealPhases.slice(ci + 1) : [];
    return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
      onMouseEnter: function onMouseEnter() {
        return setOpen(true);
      },
      style: {
        position: 'relative',
        flex: 1,
        minWidth: 0,
        cursor: 'default',
        display: 'flex',
        flexDirection: 'column',
        justifyContent: 'center',
        gap: 5,
        opacity: open ? 0 : 1,
        transform: open ? 'scale(0.96)' : 'scale(1)',
        transition: 'opacity 0.2s ease, transform 0.3s ease',
        pointerEvents: open ? 'none' : 'auto'
      }
    }, /*#__PURE__*/React.createElement("span", {
      style: {
        alignSelf: 'center',
        maxWidth: '100%',
        fontFamily: T.fontBody,
        fontSize: 9.5,
        fontWeight: 700,
        letterSpacing: '0.16em',
        textTransform: 'uppercase',
        color: T.fg3,
        lineHeight: 1,
        whiteSpace: 'nowrap',
        overflow: 'hidden',
        textOverflow: 'ellipsis'
      }
    }, "Recente activiteit", sinds ? " \xB7 ".concat(sinds) : ''), /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        alignItems: 'center',
        minWidth: 0,
        overflow: 'hidden'
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        flex: 1,
        minWidth: 0,
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'flex-end',
        gap: 9,
        overflow: 'hidden',
        WebkitMaskImage: 'linear-gradient(90deg,transparent 0%,#000 85%)',
        maskImage: 'linear-gradient(90deg,transparent 0%,#000 85%)'
      }
    }, before.map(function (p) {
      return /*#__PURE__*/React.createElement(PhaseDot, {
        key: p.id,
        p: p
      });
    })), cur && /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        alignItems: 'center',
        gap: 7,
        padding: '5px 11px',
        margin: '0 10px',
        background: 'rgba(0,217,0,0.12)',
        border: "1px solid ".concat(T.strokeAccent),
        clipPath: cutPath(7),
        flexShrink: 0,
        minWidth: 0,
        boxShadow: T.accentGlow
      }
    }, /*#__PURE__*/React.createElement(Icon, {
      name: cur.icon,
      size: 14,
      color: T.accent
    }), /*#__PURE__*/React.createElement("span", {
      style: {
        fontFamily: T.fontBody,
        fontSize: 12.5,
        fontWeight: 700,
        color: T.fg1,
        whiteSpace: 'nowrap',
        overflow: 'hidden',
        textOverflow: 'ellipsis'
      }
    }, cur.label)), /*#__PURE__*/React.createElement("div", {
      style: {
        flex: 1,
        minWidth: 0,
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'flex-start',
        gap: 9,
        overflow: 'hidden',
        WebkitMaskImage: 'linear-gradient(90deg,#000 15%,transparent 100%)',
        maskImage: 'linear-gradient(90deg,#000 15%,transparent 100%)'
      }
    }, after.map(function (p) {
      return /*#__PURE__*/React.createElement(PhaseDot, {
        key: p.id,
        p: p
      });
    })))), /*#__PURE__*/React.createElement("div", {
      onMouseLeave: function onMouseLeave() {
        return setOpen(false);
      },
      style: {
        position: 'absolute',
        left: 18,
        right: 120,
        top: 12,
        bottom: 12,
        zIndex: 40,
        background: 'linear-gradient(180deg,#063520,#022118)',
        border: "1px solid ".concat(open ? T.strokeAccent : 'transparent'),
        clipPath: cutPath(12),
        boxShadow: open ? '0 24px 56px -18px rgba(0,0,0,0.75)' : 'none',
        display: 'flex',
        alignItems: 'center',
        padding: '0 24px',
        opacity: open ? 1 : 0,
        transform: open ? 'scale(1)' : 'scale(0.985)',
        transition: 'opacity 0.26s ease, transform 0.34s cubic-bezier(0.4,0,0.2,1), box-shadow 0.3s ease, border-color 0.3s ease',
        pointerEvents: open ? 'auto' : 'none'
      }
    }, /*#__PURE__*/React.createElement(FullStepper, {
      phases: dealPhases,
      show: open,
      onPick: onChangePhase
    })), pending && /*#__PURE__*/React.createElement(ConfirmKlantstatus, {
      phase: dealPhases.find(function (p) {
        return p.id === pending;
      }),
      onYes: function onYes() {
        onChangePhase && onChangePhase(pending);
        setPending(null);
        setOpen(false);
      },
      onNo: function onNo() {
        return setPending(null);
      }
    }));
  };

  /* ── Topbalk-navigatie (views) ──────────────────────────────────────────────── */
  var ViewTabs = function ViewTabs(_ref5) {
    var phases = _ref5.phases,
      active = _ref5.active,
      onSelect = _ref5.onSelect;
    return /*#__PURE__*/React.createElement("div", {
      "data-ghs-fiche-tabs": "",
      style: {
        display: 'flex',
        alignItems: 'center',
        gap: 2,
        padding: '0 18px',
        borderBottom: "1px solid ".concat(T.stroke1),
        flexShrink: 0,
        overflowX: 'auto'
      }
    }, phases.map(function (p) {
      var on = active === p.id;
      return /*#__PURE__*/React.createElement(React.Fragment, {
        key: p.id
      }, /*#__PURE__*/React.createElement("button", {
        "data-tab": p.id,
        "data-locked": p.locked ? '' : undefined,
        onClick: function onClick() {
          return onSelect(p.id);
        },
        title: p.locked ? "".concat(p.label, " \u2014 alleen-lezen: je kan kijken, niet werken") : undefined,
        style: {
          position: 'relative',
          display: 'flex',
          alignItems: 'center',
          gap: 7,
          padding: '13px 15px',
          background: 'none',
          border: 'none',
          cursor: 'pointer',
          color: p.locked ? T.fg4 : on ? T.fg1 : T.fg3,
          opacity: p.locked && !on ? 0.7 : 1,
          fontFamily: T.fontBody,
          fontSize: 13,
          fontWeight: on ? 600 : 500,
          whiteSpace: 'nowrap'
        }
      }, /*#__PURE__*/React.createElement(Icon, {
        name: p.locked ? 'lock' : p.icon,
        size: 15,
        color: p.locked ? T.fg4 : on ? T.accent : 'currentColor'
      }), p.label, p.status === 'current' && /*#__PURE__*/React.createElement("span", {
        style: {
          width: 6,
          height: 6,
          borderRadius: '50%',
          background: T.accent,
          boxShadow: '0 0 6px ' + T.accent
        }
      }), on && /*#__PURE__*/React.createElement("span", {
        style: {
          position: 'absolute',
          left: 12,
          right: 12,
          bottom: -1,
          height: 2,
          background: p.locked ? T.fg4 : T.accent,
          borderRadius: 2,
          boxShadow: p.locked ? 'none' : '0 0 8px rgba(0,217,0,0.5)'
        }
      })), p.id === 'contact' && /*#__PURE__*/React.createElement("span", {
        style: {
          width: 1,
          height: 20,
          background: T.stroke2,
          margin: '0 8px',
          flexShrink: 0
        }
      }));
    }));
  };

  /* ════════════════════════════════════════════════════════════════════════════
     CONTACTFICHE — leest één contact uit de centrale store; alle views synchroon.
     ════════════════════════════════════════════════════════════════════════════ */
  var ContactFiche = function ContactFiche(_ref6) {
    var contactId = _ref6.contactId,
      initialView = _ref6.initialView,
      _ref6$syncView = _ref6.syncView,
      syncView = _ref6$syncView === void 0 ? true : _ref6$syncView,
      onMinimize = _ref6.onMinimize,
      onClose = _ref6.onClose,
      onViewChange = _ref6.onViewChange;
    var crm = window.useCRM();
    var ik = window.useGhsGebruiker ? window.useGhsGebruiker() : null;
    var c = crm.contacts.find(function (x) {
      return x.id === contactId;
    });
    var ficheView = crm.fiche.view;
    var _uS5 = uS(initialView || ficheView || c && c.currentPhase || 'contact'),
      _uS6 = _slicedToArray(_uS5, 2),
      view = _uS6[0],
      setView = _uS6[1];
    // Alleen de zichtbare fiche volgt de globale view; geminimaliseerde fiches
    // houden de tab waarop ze geminimaliseerd werden.
    useEffect(function () {
      if (syncView && ficheView) setView(ficheView);
    }, [ficheView, contactId, syncView]);
    useEffect(function () {
      onViewChange && onViewChange(view);
    }, [view]);
    if (!c) return null;
    var store = window.bindContactStore(c);
    /* Toegang per tabblad (Instellingen › Gebruikers › Toegang): een tab die uit staat,
       blijft zichtbaar maar grijs — je kan kijken wat er staat, niet erin werken. */
    var magTab = function magTab(id) {
      return !window.ghsMagFicheTab || window.ghsMagFicheTab(ik, id);
    };
    /* Wat je niet mag lezen (dossierinzage, bv. prijzen voor een plaatser), staat er niet. */
    var ziet = function ziet(id) {
      return !window.ghsZietFicheTab || window.ghsZietFicheTab(ik, id);
    };
    var toon = ziet(view) ? view : 'contact';
    var opSlot = !magTab(toon);
    var ViewComp = {
      contact: window.ContactInfoView,
      afspraken: window.AfsprakenView,
      deals: window.DealsView,
      opmetingen: window.OpmetingenView,
      planning: window.PlanningView,
      werkbonnen: window.WerkbonnenView,
      facturatie: window.FacturatieView,
      keuringen: window.KeuringView,
      abonnementen: window.AbonnementenView,
      tickets: window.ServiceView,
      service: window.ServiceView
    }[toon] || window.ContactInfoView;
    // Tickets staat na facturatie — service-opvolging, geen klantstatusfase.
    /* Keuring loopt naast facturatie: een zijspoor na het nazicht van de werkbon, geen fase. */
    var baseTabs = c.phases.concat([{
      id: 'keuringen',
      label: 'Keuring',
      icon: 'shield'
    }, {
      id: 'abonnementen',
      label: 'Onderhoudscontract',
      icon: 'refresh'
    }, {
      id: 'tickets',
      label: 'Service',
      icon: 'ticket'
    }]).filter(function (p) {
      return ziet(p.id);
    }).map(function (p) {
      return _objectSpread(_objectSpread({}, p), {}, {
        locked: !magTab(p.id)
      });
    });
    // Recente activiteit: de fase van de meest recente gebeurtenis in de fiche of modules.
    var recent = window.recentActivity(c);
    var ri = baseTabs.findIndex(function (p) {
      return p.id === recent.phase;
    });
    var viewTabs = baseTabs.map(function (p, i) {
      return _objectSpread(_objectSpread({}, p), {}, {
        status: ri < 0 ? p.status : i < ri ? 'done' : i === ri ? 'current' : 'upcoming'
      });
    });
    /* Kopkleur = de klantstatus, afgeleid uit het dossier (klant-status.jsx):
       grijs nieuw · oranje loopt · groen getekend en betaald · rood verloren. */
    var klantKleur = window.ghsKlantKleur ? window.ghsKlantKleur(c) : {
      label: window.statusLabel(c.status),
      kleur: T.accent
    };
    var kopKleur = klantKleur.kleur;
    var merk = (window.__resources || {}).iconWhite;
    var btn = {
      width: 36,
      height: 36,
      display: 'flex',
      alignItems: 'center',
      justifyContent: 'center',
      background: T.bg2,
      border: "1px solid ".concat(T.stroke1),
      clipPath: cutPath(7),
      cursor: 'pointer',
      color: T.fg2
    };
    return /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        flexDirection: 'column',
        height: '100%',
        minHeight: 0
      }
    }, /*#__PURE__*/React.createElement("div", {
      "data-ghs-fichekop": "",
      style: {
        position: 'relative',
        display: 'flex',
        alignItems: 'center',
        gap: 16,
        padding: '18px 26px 18px 30px',
        flexShrink: 0,
        overflow: 'hidden',
        isolation: 'isolate',
        background: "radial-gradient(90% 160% at 0% 0%, ".concat(kopKleur, "33 0%, ").concat(kopKleur, "0d 38%, transparent 62%), linear-gradient(100deg, rgba(0,0,0,0.12) 0%, rgba(0,0,0,0.38) 60%, rgba(0,0,0,0.50) 100%), ").concat(T.bg0),
        borderBottom: "1px solid ".concat(kopKleur, "3d")
      }
    }, /*#__PURE__*/React.createElement("span", {
      style: {
        position: 'absolute',
        left: 0,
        top: 0,
        bottom: 0,
        width: 4,
        background: kopKleur,
        boxShadow: "0 0 18px ".concat(kopKleur),
        pointerEvents: 'none'
      }
    }), /*#__PURE__*/React.createElement("span", {
      style: {
        position: 'absolute',
        left: 0,
        right: 0,
        bottom: -1,
        height: 1,
        background: "linear-gradient(90deg, ".concat(kopKleur, " 0%, ").concat(kopKleur, "66 22%, transparent 60%)"),
        pointerEvents: 'none',
        zIndex: -1
      }
    }), merk && /*#__PURE__*/React.createElement("img", {
      src: merk,
      alt: "",
      "aria-hidden": "true",
      style: {
        position: 'absolute',
        right: 150,
        top: '50%',
        height: 190,
        transform: 'translateY(-50%) rotate(-8deg)',
        opacity: 0.045,
        pointerEvents: 'none',
        userSelect: 'none',
        zIndex: -1
      }
    }), /*#__PURE__*/React.createElement("span", {
      style: {
        position: 'absolute',
        right: 0,
        top: 0,
        bottom: 0,
        width: 260,
        background: "repeating-linear-gradient(115deg, transparent 0 22px, ".concat(kopKleur, "0a 22px 23px)"),
        maskImage: 'linear-gradient(90deg, transparent, #000 70%)',
        WebkitMaskImage: 'linear-gradient(90deg, transparent, #000 70%)',
        pointerEvents: 'none',
        zIndex: -1
      }
    }), /*#__PURE__*/React.createElement("span", {
      "data-ghs-fichekop-avatar": "",
      style: {
        position: 'relative',
        display: 'flex',
        borderRadius: '50%',
        boxShadow: "0 0 0 2px ".concat(kopKleur, "55, 0 0 22px ").concat(kopKleur, "33"),
        flexShrink: 0
      }
    }, /*#__PURE__*/React.createElement(Avatar, {
      name: "".concat(c.firstName, " ").concat(c.lastName),
      size: 52
    })), /*#__PURE__*/React.createElement("div", {
      "data-ghs-fichekop-naam": "",
      style: {
        flexShrink: 0,
        minWidth: 0
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        alignItems: 'center',
        gap: 10,
        flexWrap: 'wrap'
      }
    }, /*#__PURE__*/React.createElement("h2", {
      style: {
        margin: 0,
        fontFamily: T.fontDisplay,
        fontSize: 23,
        fontWeight: 600,
        color: T.fg1
      }
    }, c.firstName, " ", c.lastName), /*#__PURE__*/React.createElement("span", {
      style: {
        display: 'inline-flex',
        alignItems: 'center',
        gap: 6,
        padding: '3px 9px 3px 8px',
        background: "".concat(kopKleur, "1f"),
        border: "1px solid ".concat(kopKleur, "66"),
        clipPath: cutPath(5),
        fontFamily: T.fontBody,
        fontSize: 11,
        fontWeight: 700,
        color: kopKleur
      }
    }, /*#__PURE__*/React.createElement("span", {
      style: {
        width: 7,
        height: 7,
        background: kopKleur,
        boxShadow: "0 0 8px ".concat(kopKleur)
      }
    }), klantKleur.label)), /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        alignItems: 'center',
        gap: 9,
        marginTop: 4,
        fontFamily: T.fontBody,
        fontSize: 12.5,
        color: T.fg3,
        flexWrap: 'wrap'
      }
    }, /*#__PURE__*/React.createElement(Icon, {
      name: "mappin",
      size: 13,
      color: T.fg4
    }), c.address, /*#__PURE__*/React.createElement("span", {
      style: {
        color: T.fg4
      }
    }, "\xB7"), /*#__PURE__*/React.createElement(Avatar, {
      name: c.verkoper,
      size: 18
    }), c.verkoper)), /*#__PURE__*/React.createElement("div", {
      "data-ghs-fichekop-status": "",
      style: {
        display: 'contents'
      }
    }, window.KlantStatusBalk ? /*#__PURE__*/React.createElement(window.KlantStatusBalk, {
      c: c,
      tabs: baseTabs,
      onView: setView,
      recent: recent.label
    }) : /*#__PURE__*/React.createElement(PhaseIndicator, {
      phases: viewTabs,
      sinds: recent.label,
      onChangePhase: setView
    })), /*#__PURE__*/React.createElement("div", {
      "data-ghs-fichekop-knoppen": "",
      style: {
        display: 'flex',
        gap: 12,
        alignItems: 'center',
        flexShrink: 0,
        marginLeft: 14
      }
    }, window.GhsPortaalKnop && /*#__PURE__*/React.createElement(window.GhsPortaalKnop, {
      cid: c.id
    }), onMinimize && window.MinimizeButton && /*#__PURE__*/React.createElement(window.MinimizeButton, {
      onClick: onMinimize
    }), /*#__PURE__*/React.createElement("button", {
      onClick: function onClick() {
        return onClose ? onClose() : window.crmStore.closeFiche();
      },
      title: "Sluiten",
      style: _objectSpread(_objectSpread({}, btn), {}, {
        background: 'rgba(255,90,77,0.10)',
        border: '1px solid rgba(255,90,77,0.38)',
        color: '#ff5a4d'
      })
    }, /*#__PURE__*/React.createElement(Icon, {
      name: "x",
      size: 17,
      color: "currentColor"
    })))), (c.posts || []).some(function (p) {
      return p.pinned;
    }) && /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        flexDirection: 'column',
        gap: 6,
        padding: '10px 26px 0',
        flexShrink: 0
      }
    }, (c.posts || []).filter(function (p) {
      return p.pinned;
    }).map(function (p) {
      return /*#__PURE__*/React.createElement("div", {
        key: p.id,
        style: {
          display: 'flex',
          alignItems: 'flex-start',
          gap: 9,
          padding: '8px 12px',
          background: 'rgba(0,217,0,0.09)',
          border: "1px solid ".concat(T.strokeAccent),
          clipPath: cutPath(6)
        }
      }, /*#__PURE__*/React.createElement(Icon, {
        name: "pin",
        size: 13,
        color: T.accent
      }), /*#__PURE__*/React.createElement("span", {
        style: {
          flex: 1,
          minWidth: 0,
          fontFamily: T.fontBody,
          fontSize: 12.5,
          fontWeight: 600,
          color: T.fg1,
          lineHeight: 1.5
        }
      }, p.text), /*#__PURE__*/React.createElement("span", {
        style: {
          fontFamily: T.fontBody,
          fontSize: 10.5,
          color: T.fg3,
          flex: 'none'
        }
      }, p.author, " \xB7 ", p.date), /*#__PURE__*/React.createElement("button", {
        onClick: function onClick() {
          return window.crmStore.togglePinPost(c.id, p.id);
        },
        title: "Losmaken",
        style: {
          background: 'none',
          border: 'none',
          cursor: 'pointer',
          color: T.fg4,
          padding: 0,
          fontSize: 14,
          lineHeight: 1,
          flex: 'none'
        }
      }, "\xD7"));
    })), /*#__PURE__*/React.createElement(ViewTabs, {
      phases: viewTabs,
      active: toon,
      onSelect: setView
    }), /*#__PURE__*/React.createElement("div", {
      "data-ghs-fiche-inhoud": "",
      style: {
        flex: 1,
        overflowY: 'auto',
        minHeight: 0,
        padding: '22px 26px 28px'
      }
    }, c.afgeschermd && /*#__PURE__*/React.createElement("div", {
      "data-ghs-afgeschermd": "",
      style: {
        display: 'flex',
        alignItems: 'flex-start',
        gap: 10,
        padding: '11px 14px',
        marginBottom: 16,
        background: 'rgba(0,170,255,0.07)',
        border: '1px solid rgba(0,170,255,0.35)',
        clipPath: cutPath(7)
      }
    }, /*#__PURE__*/React.createElement(Icon, {
      name: "lock",
      size: 15,
      color: "#00aaff"
    }), c.anoniem ? /*#__PURE__*/React.createElement("span", {
      style: {
        fontFamily: T.fontBody,
        fontSize: 13,
        color: T.fg2,
        lineHeight: 1.55
      }
    }, /*#__PURE__*/React.createElement("b", {
      style: {
        color: T.fg1
      }
    }, "Geanonimiseerd"), " op ", window.dCrmIsoToNL ? window.dCrmIsoToNL(c.anoniem.iso) : c.anoniem.iso, " \u2014 ", c.anoniem.reden, ". Naam, contactgegevens, adres, notities en berichten zijn gewist; het dossier zonder naam blijft enkel voor de statistiek.") : /*#__PURE__*/React.createElement("span", {
      style: {
        fontFamily: T.fontBody,
        fontSize: 13,
        color: T.fg2,
        lineHeight: 1.55
      }
    }, /*#__PURE__*/React.createElement("b", {
      style: {
        color: T.fg1
      }
    }, "Persoonsgegevens afgeschermd"), " sinds ", window.dCrmIsoToNL ? window.dCrmIsoToNL(c.afgeschermd.sinds) : c.afgeschermd.sinds, " \u2014 ", c.afgeschermd.reden, ". Enkel de facturen en het dossier blijven bewaard", c.afgeschermd.bewaarTot ? " tot ".concat(window.dCrmIsoToNL ? window.dCrmIsoToNL(c.afgeschermd.bewaarTot) : c.afgeschermd.bewaarTot) : '', " (wettelijke bewaarplicht). Er vertrekken geen mails en het klantenportaal is gesloten.")), c.archief && !c.afgeschermd && /*#__PURE__*/React.createElement("div", {
      "data-ghs-archief": "",
      style: {
        display: 'flex',
        alignItems: 'center',
        gap: 10,
        padding: '9px 14px',
        marginBottom: 16,
        background: T.bg1,
        border: "1px solid ".concat(T.stroke2),
        clipPath: cutPath(7),
        flexWrap: 'wrap'
      }
    }, /*#__PURE__*/React.createElement(Icon, {
      name: "archive",
      size: 15,
      color: T.fg3
    }), /*#__PURE__*/React.createElement("span", {
      style: {
        flex: '1 1 320px',
        minWidth: 0,
        fontFamily: T.fontBody,
        fontSize: 13,
        color: T.fg2,
        lineHeight: 1.55
      }
    }, /*#__PURE__*/React.createElement("b", {
      style: {
        color: T.fg1
      }
    }, "In het archief"), " sinds ", window.dCrmIsoToNL ? window.dCrmIsoToNL(c.archief.iso) : c.archief.iso, c.archief.door ? ", door ".concat(c.archief.door) : '', c.archief.reden ? " \u2014 ".concat(c.archief.reden) : '', ". Het contact staat niet in de lijsten; alles blijft bewaard."), /*#__PURE__*/React.createElement(Button, {
      variant: "secondary",
      size: "sm",
      icon: "refresh",
      onClick: function onClick() {
        return window.crmStore.haalUitArchief(c.id);
      }
    }, "Uit het archief halen")), opSlot && /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        alignItems: 'center',
        gap: 10,
        padding: '11px 14px',
        marginBottom: 16,
        background: 'rgba(246,247,235,0.05)',
        border: "1px solid ".concat(T.stroke2),
        clipPath: cutPath(7)
      }
    }, /*#__PURE__*/React.createElement(Icon, {
      name: "lock",
      size: 15,
      color: T.fg3
    }), /*#__PURE__*/React.createElement("span", {
      style: {
        fontFamily: T.fontBody,
        fontSize: 13,
        color: T.fg2,
        lineHeight: 1.5
      }
    }, /*#__PURE__*/React.createElement("b", {
      style: {
        color: T.fg1
      }
    }, "Alleen-lezen."), " Je kan zien wat er in ", (viewTabs.find(function (t) {
      return t.id === toon;
    }) || {}).label || 'dit tabblad', " staat, maar niet erin werken. Toegang regelt een beheerder in Gebruikers & Teams \u203A Toegang.")), /*#__PURE__*/React.createElement("div", {
      inert: opSlot ? '' : undefined,
      "aria-disabled": opSlot || undefined,
      style: opSlot ? {
        opacity: 0.55,
        filter: 'grayscale(0.6)',
        userSelect: 'text'
      } : undefined
    }, /*#__PURE__*/React.createElement(ViewComp, {
      c: c,
      store: store
    }), toon !== 'contact' && window.MailBlock && /*#__PURE__*/React.createElement(window.MailBlock, {
      c: c,
      store: store,
      fase: {
        abonnementen: 'onderhoud',
        tickets: 'onafhankelijk'
      }[toon] || toon
    }))));
  };

  /* Lege fiche voor een nieuw contact — bestaat pas in de databank na 'Contact aanmaken'. */
  var NewContactFiche = function NewContactFiche(_ref7) {
    var onCreated = _ref7.onCreated,
      onClose = _ref7.onClose;
    var draftC = {
      id: '__new__',
      firstName: '',
      lastName: '',
      company: 'Particulier',
      vat: '',
      companyAddress: '',
      phone: '',
      email: '',
      street: '',
      streetNr: '',
      postalCode: '',
      city: '',
      address: '',
      herkomst: 'Website',
      herkomstNote: '',
      verkoper: '',
      tags: [],
      status: 'lead',
      posts: [],
      activiteiten: [],
      appts: [],
      deals: [],
      opmetingen: [],
      planningSlots: [],
      phases: [],
      currentPhase: 'contact',
      createdAt: '',
      lastContact: '',
      lastContactISO: ''
    };
    var draftStore = {
      posts: [],
      activiteiten: [],
      addPost: function addPost() {},
      togglePinPost: function togglePinPost() {},
      updateContact: function updateContact(f) {
        return onCreated(f);
      }
    };
    var btn = {
      width: 36,
      height: 36,
      display: 'flex',
      alignItems: 'center',
      justifyContent: 'center',
      background: T.bg2,
      border: "1px solid ".concat(T.stroke1),
      clipPath: cutPath(7),
      cursor: 'pointer',
      color: T.fg2
    };
    return /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        flexDirection: 'column',
        height: '100%',
        minHeight: 0
      }
    }, window.GhsVensterKop ? /*#__PURE__*/React.createElement(window.GhsVensterKop, {
      icoon: "userplus",
      titel: "Nieuwe contactfiche",
      attrs: {
        'data-nieuw-contact-kop': ''
      },
      chips: [{
        label: 'Nog niet opgeslagen',
        kleur: '#ffb020'
      }],
      meta: ['De fiche verschijnt in de lijsten na aanmaken.'],
      onClose: onClose
    }) : /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        alignItems: 'center',
        gap: 16,
        padding: '18px 26px',
        borderBottom: "1px solid ".concat(T.stroke1),
        flexShrink: 0
      }
    }, /*#__PURE__*/React.createElement("h2", {
      style: {
        margin: 0,
        flex: 1,
        fontFamily: T.fontDisplay,
        fontSize: 23,
        fontWeight: 600,
        color: T.fg1
      }
    }, "Nieuwe contactfiche"), /*#__PURE__*/React.createElement("button", {
      onClick: onClose,
      title: "Sluiten",
      style: _objectSpread(_objectSpread({}, btn), {}, {
        background: 'rgba(255,90,77,0.10)',
        border: '1px solid rgba(255,90,77,0.38)',
        color: '#ff5a4d'
      })
    }, /*#__PURE__*/React.createElement(Icon, {
      name: "x",
      size: 17,
      color: "currentColor"
    }))), /*#__PURE__*/React.createElement("div", {
      style: {
        flex: 1,
        minHeight: 0,
        overflowY: 'auto',
        padding: '22px 26px 28px'
      }
    }, window.ContactInfoView && /*#__PURE__*/React.createElement(window.ContactInfoView, {
      c: draftC,
      store: draftStore,
      draft: true
    })));
  };

  /* Modal-overlay — opent over de actieve module.
     Alle geopende fiches blijven gemount: de actieve is zichtbaar, geminimaliseerde
     staan verborgen in de dock en komen terug op hun eigen tab. */
  var FicheDockEntry = function FicheDockEntry(_ref8) {
    var c = _ref8.c,
      view = _ref8.view,
      onRestore = _ref8.onRestore,
      onClose = _ref8.onClose;
    var lbl = (window.PHASE_TEMPLATE || []).concat([{
      id: 'abonnementen',
      label: 'Onderhoudscontract'
    }, {
      id: 'tickets',
      label: 'Service'
    }, {
      id: 'service',
      label: 'Service'
    }, {
      id: 'contact',
      label: 'Contactinfo'
    }]).find(function (p) {
      return p.id === view;
    });
    window.useDockPanel(true, {
      key: 'fiche-' + c.id,
      icon: 'user',
      title: "".concat(c.firstName, " ").concat(c.lastName),
      sub: "Contactfiche \xB7 ".concat(lbl ? lbl.label : 'Contactinfo'),
      badge: window.klantStatusDef ? window.klantStatusDef(c).label : null,
      badgeColor: window.klantStatusDef ? window.klantStatusDef(c).color : null,
      restore: onRestore,
      close: onClose
    });
    return null;
  };
  var FicheOverlay = function FicheOverlay() {
    var _window$useCRM = window.useCRM(),
      fiche = _window$useCRM.fiche,
      contacts = _window$useCRM.contacts;
    var _uS7 = uS([]),
      _uS8 = _slicedToArray(_uS7, 2),
      entries = _uS8[0],
      setEntries = _uS8[1]; // [{ id, view }] — alle geopende fiches
    var activeId = fiche.contactId;
    useEffect(function () {
      if (!activeId || activeId === '__new__') return;
      setEntries(function (es) {
        return es.some(function (e) {
          return e.id === activeId;
        }) ? es.map(function (e) {
          return e.id === activeId && fiche.view ? _objectSpread(_objectSpread({}, e), {}, {
            view: fiche.view
          }) : e;
        }) : [].concat(_toConsumableArray(es), [{
          id: activeId,
          view: fiche.view || 'contact'
        }]);
      });
    }, [activeId, fiche.view]);
    var drop = function drop(id) {
      return setEntries(function (es) {
        return es.filter(function (e) {
          return e.id !== id;
        });
      });
    };
    var live = entries.filter(function (e) {
      return contacts.some(function (c) {
        return c.id === e.id;
      });
    });
    if (!live.length && activeId !== '__new__') return null;
    return /*#__PURE__*/React.createElement(React.Fragment, null, activeId === '__new__' && /*#__PURE__*/React.createElement("div", {
      onMouseDown: function onMouseDown(ev) {
        return ev.target === ev.currentTarget && window.crmStore.closeFiche();
      },
      style: {
        position: 'absolute',
        inset: 0,
        background: 'rgba(1,12,8,0.74)',
        backdropFilter: 'blur(5px)',
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'center',
        zIndex: 61,
        padding: '24px 24px calc(24px + var(--ghs-dock, 0px))'
      }
    }, /*#__PURE__*/React.createElement("div", {
      "data-ghs-volscherm": "nieuw-contact",
      style: {
        width: '90%',
        maxWidth: 1100,
        height: '90%',
        background: T.bg1,
        clipPath: cutPath(18),
        border: "1px solid ".concat(T.stroke1),
        position: 'relative',
        overflow: 'hidden',
        boxShadow: '0 50px 110px -30px rgba(0,0,0,0.85)'
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: accentEdge(18)
    }), /*#__PURE__*/React.createElement(NewContactFiche, {
      onClose: function onClose() {
        return window.crmStore.closeFiche();
      },
      onCreated: function onCreated(f) {
        var id = window.crmStore.addContact(f);
        window.crmStore.openFiche(id, 'contact');
      }
    }))), live.map(function (e) {
      var c = contacts.find(function (x) {
        return x.id === e.id;
      });
      var on = e.id === activeId;
      return /*#__PURE__*/React.createElement(React.Fragment, {
        key: e.id
      }, !on && /*#__PURE__*/React.createElement(FicheDockEntry, {
        c: c,
        view: e.view,
        onRestore: function onRestore() {
          return window.crmStore.openFiche(e.id, e.view);
        },
        onClose: function onClose() {
          return drop(e.id);
        }
      }), /*#__PURE__*/React.createElement("div", {
        onMouseDown: function onMouseDown(ev) {
          return ev.target === ev.currentTarget && window.crmStore.closeFiche();
        },
        style: {
          position: 'absolute',
          inset: 0,
          background: 'rgba(1,12,8,0.74)',
          backdropFilter: 'blur(5px)',
          display: on ? 'flex' : 'none',
          alignItems: 'center',
          justifyContent: 'center',
          zIndex: 60,
          padding: '24px 24px calc(24px + var(--ghs-dock, 0px))'
        }
      }, /*#__PURE__*/React.createElement("div", {
        "data-ghs-venster": "contactfiche",
        style: {
          width: '90%',
          maxWidth: 1340,
          height: '90%',
          background: T.bg1,
          clipPath: cutPath(18),
          border: "1px solid ".concat(T.stroke1),
          position: 'relative',
          overflow: 'hidden',
          boxShadow: '0 50px 110px -30px rgba(0,0,0,0.85)'
        }
      }, /*#__PURE__*/React.createElement("div", {
        style: accentEdge(18)
      }), /*#__PURE__*/React.createElement(ContactFiche, {
        contactId: e.id,
        initialView: e.view,
        syncView: on,
        onMinimize: function onMinimize() {
          return window.crmStore.closeFiche();
        },
        onClose: function onClose() {
          return window.crmStore.closeFiche();
        },
        onViewChange: function onViewChange(v) {
          return setEntries(function (es) {
            return es.map(function (x) {
              return x.id === e.id ? _objectSpread(_objectSpread({}, x), {}, {
                view: v
              }) : x;
            });
          });
        }
      }))));
    }));
  };
  Object.assign(window, {
    ContactFiche: ContactFiche,
    FicheOverlay: FicheOverlay
  });
})();