var om=e=>{throw TypeError(e)};var Jo=(e,t,s)=>t.has(e)||om("Cannot "+s);var C=(e,t,s)=>(Jo(e,t,"read from private field"),s?s.call(e):t.get(e)),ue=(e,t,s)=>t.has(e)?om("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,s),te=(e,t,s,r)=>(Jo(e,t,"write to private field"),r?r.call(e,s):t.set(e,s),s),ye=(e,t,s)=>(Jo(e,t,"access private method"),s);var tl=(e,t,s,r)=>({set _(a){te(e,t,a,s)},get _(){return C(e,t,r)}});function hv(e,t){for(var s=0;sr[a]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const a of document.querySelectorAll('link[rel="modulepreload"]'))r(a);new MutationObserver(a=>{for(const i of a)if(i.type==="childList")for(const l of i.addedNodes)l.tagName==="LINK"&&l.rel==="modulepreload"&&r(l)}).observe(document,{childList:!0,subtree:!0});function s(a){const i={};return a.integrity&&(i.integrity=a.integrity),a.referrerPolicy&&(i.referrerPolicy=a.referrerPolicy),a.crossOrigin==="use-credentials"?i.credentials="include":a.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function r(a){if(a.ep)return;a.ep=!0;const i=s(a);fetch(a.href,i)}})();function mv(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var _p={exports:{}},jo={},zp={exports:{}},Ne={};/** * @license React * react.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var $i=Symbol.for("react.element"),fv=Symbol.for("react.portal"),pv=Symbol.for("react.fragment"),gv=Symbol.for("react.strict_mode"),xv=Symbol.for("react.profiler"),yv=Symbol.for("react.provider"),vv=Symbol.for("react.context"),jv=Symbol.for("react.forward_ref"),bv=Symbol.for("react.suspense"),Nv=Symbol.for("react.memo"),wv=Symbol.for("react.lazy"),cm=Symbol.iterator;function Sv(e){return e===null||typeof e!="object"?null:(e=cm&&e[cm]||e["@@iterator"],typeof e=="function"?e:null)}var Up={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},$p=Object.assign,Bp={};function Sa(e,t,s){this.props=e,this.context=t,this.refs=Bp,this.updater=s||Up}Sa.prototype.isReactComponent={};Sa.prototype.setState=function(e,t){if(typeof e!="object"&&typeof e!="function"&&e!=null)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,e,t,"setState")};Sa.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function Kp(){}Kp.prototype=Sa.prototype;function rd(e,t,s){this.props=e,this.context=t,this.refs=Bp,this.updater=s||Up}var ad=rd.prototype=new Kp;ad.constructor=rd;$p(ad,Sa.prototype);ad.isPureReactComponent=!0;var um=Array.isArray,Vp=Object.prototype.hasOwnProperty,id={current:null},qp={key:!0,ref:!0,__self:!0,__source:!0};function Qp(e,t,s){var r,a={},i=null,l=null;if(t!=null)for(r in t.ref!==void 0&&(l=t.ref),t.key!==void 0&&(i=""+t.key),t)Vp.call(t,r)&&!qp.hasOwnProperty(r)&&(a[r]=t[r]);var o=arguments.length-2;if(o===1)a.children=s;else if(1>>1,ve=B[me];if(0>>1;mea(Ce,ee))Mea(ht,Ce)?(B[me]=ht,B[Me]=ee,me=Me):(B[me]=Ce,B[V]=ee,me=V);else if(Mea(ht,ee))B[me]=ht,B[Me]=ee,me=Me;else break e}}return J}function a(B,J){var ee=B.sortIndex-J.sortIndex;return ee!==0?ee:B.id-J.id}if(typeof performance=="object"&&typeof performance.now=="function"){var i=performance;e.unstable_now=function(){return i.now()}}else{var l=Date,o=l.now();e.unstable_now=function(){return l.now()-o}}var c=[],u=[],d=1,m=null,p=3,h=!1,f=!1,g=!1,b=typeof setTimeout=="function"?setTimeout:null,y=typeof clearTimeout=="function"?clearTimeout:null,v=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function x(B){for(var J=s(u);J!==null;){if(J.callback===null)r(u);else if(J.startTime<=B)r(u),J.sortIndex=J.expirationTime,t(c,J);else break;J=s(u)}}function N(B){if(g=!1,x(B),!f)if(s(c)!==null)f=!0,P(k);else{var J=s(u);J!==null&&j(N,J.startTime-B)}}function k(B,J){f=!1,g&&(g=!1,y(S),S=-1),h=!0;var ee=p;try{for(x(J),m=s(c);m!==null&&(!(m.expirationTime>J)||B&&!_());){var me=m.callback;if(typeof me=="function"){m.callback=null,p=m.priorityLevel;var ve=me(m.expirationTime<=J);J=e.unstable_now(),typeof ve=="function"?m.callback=ve:m===s(c)&&r(c),x(J)}else r(c);m=s(c)}if(m!==null)var it=!0;else{var V=s(u);V!==null&&j(N,V.startTime-J),it=!1}return it}finally{m=null,p=ee,h=!1}}var D=!1,F=null,S=-1,L=5,T=-1;function _(){return!(e.unstable_now()-TB||125me?(B.sortIndex=ee,t(u,B),s(c)===null&&B===s(u)&&(g?(y(S),S=-1):g=!0,j(N,ee-me))):(B.sortIndex=ve,t(c,B),f||h||(f=!0,P(k))),B},e.unstable_shouldYield=_,e.unstable_wrapCallback=function(B){var J=p;return function(){var ee=p;p=J;try{return B.apply(this,arguments)}finally{p=ee}}}})(Yp);Zp.exports=Yp;var Rv=Zp.exports;/** * @license React * react-dom.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var Ov=w,rs=Rv;function q(e){for(var t="https://reactjs.org/docs/error-decoder.html?invariant="+e,s=1;s"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),Oc=Object.prototype.hasOwnProperty,_v=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/,hm={},mm={};function zv(e){return Oc.call(mm,e)?!0:Oc.call(hm,e)?!1:_v.test(e)?mm[e]=!0:(hm[e]=!0,!1)}function Uv(e,t,s,r){if(s!==null&&s.type===0)return!1;switch(typeof t){case"function":case"symbol":return!0;case"boolean":return r?!1:s!==null?!s.acceptsBooleans:(e=e.toLowerCase().slice(0,5),e!=="data-"&&e!=="aria-");default:return!1}}function $v(e,t,s,r){if(t===null||typeof t>"u"||Uv(e,t,s,r))return!0;if(r)return!1;if(s!==null)switch(s.type){case 3:return!t;case 4:return t===!1;case 5:return isNaN(t);case 6:return isNaN(t)||1>t}return!1}function zt(e,t,s,r,a,i,l){this.acceptsBooleans=t===2||t===3||t===4,this.attributeName=r,this.attributeNamespace=a,this.mustUseProperty=s,this.propertyName=e,this.type=t,this.sanitizeURL=i,this.removeEmptyString=l}var St={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){St[e]=new zt(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var t=e[0];St[t]=new zt(t,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){St[e]=new zt(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){St[e]=new zt(e,2,!1,e,null,!1,!1)});"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(e){St[e]=new zt(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){St[e]=new zt(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){St[e]=new zt(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){St[e]=new zt(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){St[e]=new zt(e,5,!1,e.toLowerCase(),null,!1,!1)});var od=/[\-:]([a-z])/g;function cd(e){return e[1].toUpperCase()}"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(e){var t=e.replace(od,cd);St[t]=new zt(t,1,!1,e,null,!1,!1)});"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(e){var t=e.replace(od,cd);St[t]=new zt(t,1,!1,e,"http://www.w3.org/1999/xlink",!1,!1)});["xml:base","xml:lang","xml:space"].forEach(function(e){var t=e.replace(od,cd);St[t]=new zt(t,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){St[e]=new zt(e,1,!1,e.toLowerCase(),null,!1,!1)});St.xlinkHref=new zt("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){St[e]=new zt(e,1,!1,e.toLowerCase(),null,!0,!0)});function ud(e,t,s,r){var a=St.hasOwnProperty(t)?St[t]:null;(a!==null?a.type!==0:r||!(2o||a[l]!==i[o]){var c=` `+a[l].replace(" at new "," at ");return e.displayName&&c.includes("")&&(c=c.replace("",e.displayName)),c}while(1<=l&&0<=o);break}}}finally{tc=!1,Error.prepareStackTrace=s}return(e=e?e.displayName||e.name:"")?qa(e):""}function Bv(e){switch(e.tag){case 5:return qa(e.type);case 16:return qa("Lazy");case 13:return qa("Suspense");case 19:return qa("SuspenseList");case 0:case 2:case 15:return e=sc(e.type,!1),e;case 11:return e=sc(e.type.render,!1),e;case 1:return e=sc(e.type,!0),e;default:return""}}function $c(e){if(e==null)return null;if(typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case Lr:return"Fragment";case Mr:return"Portal";case _c:return"Profiler";case dd:return"StrictMode";case zc:return"Suspense";case Uc:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case eg:return(e.displayName||"Context")+".Consumer";case Xp:return(e._context.displayName||"Context")+".Provider";case hd:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case md:return t=e.displayName||null,t!==null?t:$c(e.type)||"Memo";case pn:t=e._payload,e=e._init;try{return $c(e(t))}catch{}}return null}function Kv(e){var t=e.type;switch(e.tag){case 24:return"Cache";case 9:return(t.displayName||"Context")+".Consumer";case 10:return(t._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return e=t.render,e=e.displayName||e.name||"",t.displayName||(e!==""?"ForwardRef("+e+")":"ForwardRef");case 7:return"Fragment";case 5:return t;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return $c(t);case 8:return t===dd?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof t=="function")return t.displayName||t.name||null;if(typeof t=="string")return t}return null}function Kn(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function sg(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(t==="checkbox"||t==="radio")}function Vv(e){var t=sg(e)?"checked":"value",s=Object.getOwnPropertyDescriptor(e.constructor.prototype,t),r=""+e[t];if(!e.hasOwnProperty(t)&&typeof s<"u"&&typeof s.get=="function"&&typeof s.set=="function"){var a=s.get,i=s.set;return Object.defineProperty(e,t,{configurable:!0,get:function(){return a.call(this)},set:function(l){r=""+l,i.call(this,l)}}),Object.defineProperty(e,t,{enumerable:s.enumerable}),{getValue:function(){return r},setValue:function(l){r=""+l},stopTracking:function(){e._valueTracker=null,delete e[t]}}}}function rl(e){e._valueTracker||(e._valueTracker=Vv(e))}function ng(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var s=t.getValue(),r="";return e&&(r=sg(e)?e.checked?"true":"false":e.value),e=r,e!==s?(t.setValue(e),!0):!1}function zl(e){if(e=e||(typeof document<"u"?document:void 0),typeof e>"u")return null;try{return e.activeElement||e.body}catch{return e.body}}function Bc(e,t){var s=t.checked;return He({},t,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:s??e._wrapperState.initialChecked})}function pm(e,t){var s=t.defaultValue==null?"":t.defaultValue,r=t.checked!=null?t.checked:t.defaultChecked;s=Kn(t.value!=null?t.value:s),e._wrapperState={initialChecked:r,initialValue:s,controlled:t.type==="checkbox"||t.type==="radio"?t.checked!=null:t.value!=null}}function rg(e,t){t=t.checked,t!=null&&ud(e,"checked",t,!1)}function Kc(e,t){rg(e,t);var s=Kn(t.value),r=t.type;if(s!=null)r==="number"?(s===0&&e.value===""||e.value!=s)&&(e.value=""+s):e.value!==""+s&&(e.value=""+s);else if(r==="submit"||r==="reset"){e.removeAttribute("value");return}t.hasOwnProperty("value")?Vc(e,t.type,s):t.hasOwnProperty("defaultValue")&&Vc(e,t.type,Kn(t.defaultValue)),t.checked==null&&t.defaultChecked!=null&&(e.defaultChecked=!!t.defaultChecked)}function gm(e,t,s){if(t.hasOwnProperty("value")||t.hasOwnProperty("defaultValue")){var r=t.type;if(!(r!=="submit"&&r!=="reset"||t.value!==void 0&&t.value!==null))return;t=""+e._wrapperState.initialValue,s||t===e.value||(e.value=t),e.defaultValue=t}s=e.name,s!==""&&(e.name=""),e.defaultChecked=!!e._wrapperState.initialChecked,s!==""&&(e.name=s)}function Vc(e,t,s){(t!=="number"||zl(e.ownerDocument)!==e)&&(s==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+s&&(e.defaultValue=""+s))}var Qa=Array.isArray;function Hr(e,t,s,r){if(e=e.options,t){t={};for(var a=0;a"+t.valueOf().toString()+"",t=al.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)}});function ui(e,t){if(t){var s=e.firstChild;if(s&&s===e.lastChild&&s.nodeType===3){s.nodeValue=t;return}}e.textContent=t}var Ya={animationIterationCount:!0,aspectRatio:!0,borderImageOutset:!0,borderImageSlice:!0,borderImageWidth:!0,boxFlex:!0,boxFlexGroup:!0,boxOrdinalGroup:!0,columnCount:!0,columns:!0,flex:!0,flexGrow:!0,flexPositive:!0,flexShrink:!0,flexNegative:!0,flexOrder:!0,gridArea:!0,gridRow:!0,gridRowEnd:!0,gridRowSpan:!0,gridRowStart:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnSpan:!0,gridColumnStart:!0,fontWeight:!0,lineClamp:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,tabSize:!0,widows:!0,zIndex:!0,zoom:!0,fillOpacity:!0,floodOpacity:!0,stopOpacity:!0,strokeDasharray:!0,strokeDashoffset:!0,strokeMiterlimit:!0,strokeOpacity:!0,strokeWidth:!0},qv=["Webkit","ms","Moz","O"];Object.keys(Ya).forEach(function(e){qv.forEach(function(t){t=t+e.charAt(0).toUpperCase()+e.substring(1),Ya[t]=Ya[e]})});function og(e,t,s){return t==null||typeof t=="boolean"||t===""?"":s||typeof t!="number"||t===0||Ya.hasOwnProperty(e)&&Ya[e]?(""+t).trim():t+"px"}function cg(e,t){e=e.style;for(var s in t)if(t.hasOwnProperty(s)){var r=s.indexOf("--")===0,a=og(s,t[s],r);s==="float"&&(s="cssFloat"),r?e.setProperty(s,a):e[s]=a}}var Qv=He({menuitem:!0},{area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0});function Hc(e,t){if(t){if(Qv[e]&&(t.children!=null||t.dangerouslySetInnerHTML!=null))throw Error(q(137,e));if(t.dangerouslySetInnerHTML!=null){if(t.children!=null)throw Error(q(60));if(typeof t.dangerouslySetInnerHTML!="object"||!("__html"in t.dangerouslySetInnerHTML))throw Error(q(61))}if(t.style!=null&&typeof t.style!="object")throw Error(q(62))}}function Wc(e,t){if(e.indexOf("-")===-1)return typeof t.is=="string";switch(e){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var Gc=null;function fd(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var Zc=null,Wr=null,Gr=null;function vm(e){if(e=Vi(e)){if(typeof Zc!="function")throw Error(q(280));var t=e.stateNode;t&&(t=ko(t),Zc(e.stateNode,e.type,t))}}function ug(e){Wr?Gr?Gr.push(e):Gr=[e]:Wr=e}function dg(){if(Wr){var e=Wr,t=Gr;if(Gr=Wr=null,vm(e),t)for(e=0;e>>=0,e===0?32:31-(n0(e)/r0|0)|0}var il=64,ll=4194304;function Ha(e){switch(e&-e){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return e&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return e&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return e}}function Kl(e,t){var s=e.pendingLanes;if(s===0)return 0;var r=0,a=e.suspendedLanes,i=e.pingedLanes,l=s&268435455;if(l!==0){var o=l&~a;o!==0?r=Ha(o):(i&=l,i!==0&&(r=Ha(i)))}else l=s&~a,l!==0?r=Ha(l):i!==0&&(r=Ha(i));if(r===0)return 0;if(t!==0&&t!==r&&!(t&a)&&(a=r&-r,i=t&-t,a>=i||a===16&&(i&4194240)!==0))return t;if(r&4&&(r|=s&16),t=e.entangledLanes,t!==0)for(e=e.entanglements,t&=r;0s;s++)t.push(e);return t}function Bi(e,t,s){e.pendingLanes|=t,t!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,t=31-ks(t),e[t]=s}function o0(e,t){var s=e.pendingLanes&~t;e.pendingLanes=t,e.suspendedLanes=0,e.pingedLanes=0,e.expiredLanes&=t,e.mutableReadLanes&=t,e.entangledLanes&=t,t=e.entanglements;var r=e.eventTimes;for(e=e.expirationTimes;0=Xa),Dm=" ",Pm=!1;function Tg(e,t){switch(e){case"keyup":return R0.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function Fg(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var Rr=!1;function _0(e,t){switch(e){case"compositionend":return Fg(t);case"keypress":return t.which!==32?null:(Pm=!0,Dm);case"textInput":return e=t.data,e===Dm&&Pm?null:e;default:return null}}function z0(e,t){if(Rr)return e==="compositionend"||!Nd&&Tg(e,t)?(e=Pg(),kl=vd=An=null,Rr=!1,e):null;switch(e){case"paste":return null;case"keypress":if(!(t.ctrlKey||t.altKey||t.metaKey)||t.ctrlKey&&t.altKey){if(t.char&&1=t)return{node:s,offset:t-e};e=r}e:{for(;s;){if(s.nextSibling){s=s.nextSibling;break e}s=s.parentNode}s=void 0}s=Im(s)}}function Rg(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?Rg(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function Og(){for(var e=window,t=zl();t instanceof e.HTMLIFrameElement;){try{var s=typeof t.contentWindow.location.href=="string"}catch{s=!1}if(s)e=t.contentWindow;else break;t=zl(e.document)}return t}function wd(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t&&(t==="input"&&(e.type==="text"||e.type==="search"||e.type==="tel"||e.type==="url"||e.type==="password")||t==="textarea"||e.contentEditable==="true")}function W0(e){var t=Og(),s=e.focusedElem,r=e.selectionRange;if(t!==s&&s&&s.ownerDocument&&Rg(s.ownerDocument.documentElement,s)){if(r!==null&&wd(s)){if(t=r.start,e=r.end,e===void 0&&(e=t),"selectionStart"in s)s.selectionStart=t,s.selectionEnd=Math.min(e,s.value.length);else if(e=(t=s.ownerDocument||document)&&t.defaultView||window,e.getSelection){e=e.getSelection();var a=s.textContent.length,i=Math.min(r.start,a);r=r.end===void 0?i:Math.min(r.end,a),!e.extend&&i>r&&(a=r,r=i,i=a),a=Mm(s,i);var l=Mm(s,r);a&&l&&(e.rangeCount!==1||e.anchorNode!==a.node||e.anchorOffset!==a.offset||e.focusNode!==l.node||e.focusOffset!==l.offset)&&(t=t.createRange(),t.setStart(a.node,a.offset),e.removeAllRanges(),i>r?(e.addRange(t),e.extend(l.node,l.offset)):(t.setEnd(l.node,l.offset),e.addRange(t)))}}for(t=[],e=s;e=e.parentNode;)e.nodeType===1&&t.push({element:e,left:e.scrollLeft,top:e.scrollTop});for(typeof s.focus=="function"&&s.focus(),s=0;s=document.documentMode,Or=null,su=null,ti=null,nu=!1;function Lm(e,t,s){var r=s.window===s?s.document:s.nodeType===9?s:s.ownerDocument;nu||Or==null||Or!==zl(r)||(r=Or,"selectionStart"in r&&wd(r)?r={start:r.selectionStart,end:r.selectionEnd}:(r=(r.ownerDocument&&r.ownerDocument.defaultView||window).getSelection(),r={anchorNode:r.anchorNode,anchorOffset:r.anchorOffset,focusNode:r.focusNode,focusOffset:r.focusOffset}),ti&&gi(ti,r)||(ti=r,r=Ql(su,"onSelect"),0Ur||(e.current=cu[Ur],cu[Ur]=null,Ur--)}function Re(e,t){Ur++,cu[Ur]=e.current,e.current=t}var Vn={},At=Hn(Vn),Ht=Hn(!1),gr=Vn;function fa(e,t){var s=e.type.contextTypes;if(!s)return Vn;var r=e.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===t)return r.__reactInternalMemoizedMaskedChildContext;var a={},i;for(i in s)a[i]=t[i];return r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=t,e.__reactInternalMemoizedMaskedChildContext=a),a}function Wt(e){return e=e.childContextTypes,e!=null}function Wl(){ze(Ht),ze(At)}function Bm(e,t,s){if(At.current!==Vn)throw Error(q(168));Re(At,t),Re(Ht,s)}function Qg(e,t,s){var r=e.stateNode;if(t=t.childContextTypes,typeof r.getChildContext!="function")return s;r=r.getChildContext();for(var a in r)if(!(a in t))throw Error(q(108,Kv(e)||"Unknown",a));return He({},s,r)}function Gl(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||Vn,gr=At.current,Re(At,e),Re(Ht,Ht.current),!0}function Km(e,t,s){var r=e.stateNode;if(!r)throw Error(q(169));s?(e=Qg(e,t,gr),r.__reactInternalMemoizedMergedChildContext=e,ze(Ht),ze(At),Re(At,e)):ze(Ht),Re(Ht,s)}var Qs=null,Co=!1,gc=!1;function Hg(e){Qs===null?Qs=[e]:Qs.push(e)}function ij(e){Co=!0,Hg(e)}function Wn(){if(!gc&&Qs!==null){gc=!0;var e=0,t=Ie;try{var s=Qs;for(Ie=1;e>=l,a-=l,Js=1<<32-ks(t)+a|s<S?(L=F,F=null):L=F.sibling;var T=p(y,F,x[S],N);if(T===null){F===null&&(F=L);break}e&&F&&T.alternate===null&&t(y,F),v=i(T,v,S),D===null?k=T:D.sibling=T,D=T,F=L}if(S===x.length)return s(y,F),Be&&Zn(y,S),k;if(F===null){for(;SS?(L=F,F=null):L=F.sibling;var _=p(y,F,T.value,N);if(_===null){F===null&&(F=L);break}e&&F&&_.alternate===null&&t(y,F),v=i(_,v,S),D===null?k=_:D.sibling=_,D=_,F=L}if(T.done)return s(y,F),Be&&Zn(y,S),k;if(F===null){for(;!T.done;S++,T=x.next())T=m(y,T.value,N),T!==null&&(v=i(T,v,S),D===null?k=T:D.sibling=T,D=T);return Be&&Zn(y,S),k}for(F=r(y,F);!T.done;S++,T=x.next())T=h(F,y,S,T.value,N),T!==null&&(e&&T.alternate!==null&&F.delete(T.key===null?S:T.key),v=i(T,v,S),D===null?k=T:D.sibling=T,D=T);return e&&F.forEach(function(K){return t(y,K)}),Be&&Zn(y,S),k}function b(y,v,x,N){if(typeof x=="object"&&x!==null&&x.type===Lr&&x.key===null&&(x=x.props.children),typeof x=="object"&&x!==null){switch(x.$$typeof){case nl:e:{for(var k=x.key,D=v;D!==null;){if(D.key===k){if(k=x.type,k===Lr){if(D.tag===7){s(y,D.sibling),v=a(D,x.props.children),v.return=y,y=v;break e}}else if(D.elementType===k||typeof k=="object"&&k!==null&&k.$$typeof===pn&&Qm(k)===D.type){s(y,D.sibling),v=a(D,x.props),v.ref=Ua(y,D,x),v.return=y,y=v;break e}s(y,D);break}else t(y,D);D=D.sibling}x.type===Lr?(v=fr(x.props.children,y.mode,N,x.key),v.return=y,y=v):(N=Il(x.type,x.key,x.props,null,y.mode,N),N.ref=Ua(y,v,x),N.return=y,y=N)}return l(y);case Mr:e:{for(D=x.key;v!==null;){if(v.key===D)if(v.tag===4&&v.stateNode.containerInfo===x.containerInfo&&v.stateNode.implementation===x.implementation){s(y,v.sibling),v=a(v,x.children||[]),v.return=y,y=v;break e}else{s(y,v);break}else t(y,v);v=v.sibling}v=Sc(x,y.mode,N),v.return=y,y=v}return l(y);case pn:return D=x._init,b(y,v,D(x._payload),N)}if(Qa(x))return f(y,v,x,N);if(La(x))return g(y,v,x,N);fl(y,x)}return typeof x=="string"&&x!==""||typeof x=="number"?(x=""+x,v!==null&&v.tag===6?(s(y,v.sibling),v=a(v,x),v.return=y,y=v):(s(y,v),v=wc(x,y.mode,N),v.return=y,y=v),l(y)):s(y,v)}return b}var ga=Yg(!0),Jg=Yg(!1),Jl=Hn(null),Xl=null,Kr=null,Ed=null;function Dd(){Ed=Kr=Xl=null}function Pd(e){var t=Jl.current;ze(Jl),e._currentValue=t}function hu(e,t,s){for(;e!==null;){var r=e.alternate;if((e.childLanes&t)!==t?(e.childLanes|=t,r!==null&&(r.childLanes|=t)):r!==null&&(r.childLanes&t)!==t&&(r.childLanes|=t),e===s)break;e=e.return}}function Yr(e,t){Xl=e,Ed=Kr=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&t&&(Qt=!0),e.firstContext=null)}function fs(e){var t=e._currentValue;if(Ed!==e)if(e={context:e,memoizedValue:t,next:null},Kr===null){if(Xl===null)throw Error(q(308));Kr=e,Xl.dependencies={lanes:0,firstContext:e}}else Kr=Kr.next=e;return t}var Xn=null;function Ad(e){Xn===null?Xn=[e]:Xn.push(e)}function Xg(e,t,s,r){var a=t.interleaved;return a===null?(s.next=s,Ad(t)):(s.next=a.next,a.next=s),t.interleaved=s,ln(e,r)}function ln(e,t){e.lanes|=t;var s=e.alternate;for(s!==null&&(s.lanes|=t),s=e,e=e.return;e!==null;)e.childLanes|=t,s=e.alternate,s!==null&&(s.childLanes|=t),s=e,e=e.return;return s.tag===3?s.stateNode:null}var gn=!1;function Td(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function ex(e,t){e=e.updateQueue,t.updateQueue===e&&(t.updateQueue={baseState:e.baseState,firstBaseUpdate:e.firstBaseUpdate,lastBaseUpdate:e.lastBaseUpdate,shared:e.shared,effects:e.effects})}function sn(e,t){return{eventTime:e,lane:t,tag:0,payload:null,callback:null,next:null}}function On(e,t,s){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,De&2){var a=r.pending;return a===null?t.next=t:(t.next=a.next,a.next=t),r.pending=t,ln(e,s)}return a=r.interleaved,a===null?(t.next=t,Ad(r)):(t.next=a.next,a.next=t),r.interleaved=t,ln(e,s)}function El(e,t,s){if(t=t.updateQueue,t!==null&&(t=t.shared,(s&4194240)!==0)){var r=t.lanes;r&=e.pendingLanes,s|=r,t.lanes=s,gd(e,s)}}function Hm(e,t){var s=e.updateQueue,r=e.alternate;if(r!==null&&(r=r.updateQueue,s===r)){var a=null,i=null;if(s=s.firstBaseUpdate,s!==null){do{var l={eventTime:s.eventTime,lane:s.lane,tag:s.tag,payload:s.payload,callback:s.callback,next:null};i===null?a=i=l:i=i.next=l,s=s.next}while(s!==null);i===null?a=i=t:i=i.next=t}else a=i=t;s={baseState:r.baseState,firstBaseUpdate:a,lastBaseUpdate:i,shared:r.shared,effects:r.effects},e.updateQueue=s;return}e=s.lastBaseUpdate,e===null?s.firstBaseUpdate=t:e.next=t,s.lastBaseUpdate=t}function eo(e,t,s,r){var a=e.updateQueue;gn=!1;var i=a.firstBaseUpdate,l=a.lastBaseUpdate,o=a.shared.pending;if(o!==null){a.shared.pending=null;var c=o,u=c.next;c.next=null,l===null?i=u:l.next=u,l=c;var d=e.alternate;d!==null&&(d=d.updateQueue,o=d.lastBaseUpdate,o!==l&&(o===null?d.firstBaseUpdate=u:o.next=u,d.lastBaseUpdate=c))}if(i!==null){var m=a.baseState;l=0,d=u=c=null,o=i;do{var p=o.lane,h=o.eventTime;if((r&p)===p){d!==null&&(d=d.next={eventTime:h,lane:0,tag:o.tag,payload:o.payload,callback:o.callback,next:null});e:{var f=e,g=o;switch(p=t,h=s,g.tag){case 1:if(f=g.payload,typeof f=="function"){m=f.call(h,m,p);break e}m=f;break e;case 3:f.flags=f.flags&-65537|128;case 0:if(f=g.payload,p=typeof f=="function"?f.call(h,m,p):f,p==null)break e;m=He({},m,p);break e;case 2:gn=!0}}o.callback!==null&&o.lane!==0&&(e.flags|=64,p=a.effects,p===null?a.effects=[o]:p.push(o))}else h={eventTime:h,lane:p,tag:o.tag,payload:o.payload,callback:o.callback,next:null},d===null?(u=d=h,c=m):d=d.next=h,l|=p;if(o=o.next,o===null){if(o=a.shared.pending,o===null)break;p=o,o=p.next,p.next=null,a.lastBaseUpdate=p,a.shared.pending=null}}while(!0);if(d===null&&(c=m),a.baseState=c,a.firstBaseUpdate=u,a.lastBaseUpdate=d,t=a.shared.interleaved,t!==null){a=t;do l|=a.lane,a=a.next;while(a!==t)}else i===null&&(a.shared.lanes=0);vr|=l,e.lanes=l,e.memoizedState=m}}function Wm(e,t,s){if(e=t.effects,t.effects=null,e!==null)for(t=0;ts?s:4,e(!0);var r=yc.transition;yc.transition={};try{e(!1),t()}finally{Ie=s,yc.transition=r}}function xx(){return ps().memoizedState}function uj(e,t,s){var r=zn(e);if(s={lane:r,action:s,hasEagerState:!1,eagerState:null,next:null},yx(e))vx(t,s);else if(s=Xg(e,t,s,r),s!==null){var a=Ot();Cs(s,e,r,a),jx(s,t,r)}}function dj(e,t,s){var r=zn(e),a={lane:r,action:s,hasEagerState:!1,eagerState:null,next:null};if(yx(e))vx(t,a);else{var i=e.alternate;if(e.lanes===0&&(i===null||i.lanes===0)&&(i=t.lastRenderedReducer,i!==null))try{var l=t.lastRenderedState,o=i(l,s);if(a.hasEagerState=!0,a.eagerState=o,Es(o,l)){var c=t.interleaved;c===null?(a.next=a,Ad(t)):(a.next=c.next,c.next=a),t.interleaved=a;return}}catch{}finally{}s=Xg(e,t,a,r),s!==null&&(a=Ot(),Cs(s,e,r,a),jx(s,t,r))}}function yx(e){var t=e.alternate;return e===qe||t!==null&&t===qe}function vx(e,t){si=so=!0;var s=e.pending;s===null?t.next=t:(t.next=s.next,s.next=t),e.pending=t}function jx(e,t,s){if(s&4194240){var r=t.lanes;r&=e.pendingLanes,s|=r,t.lanes=s,gd(e,s)}}var no={readContext:fs,useCallback:kt,useContext:kt,useEffect:kt,useImperativeHandle:kt,useInsertionEffect:kt,useLayoutEffect:kt,useMemo:kt,useReducer:kt,useRef:kt,useState:kt,useDebugValue:kt,useDeferredValue:kt,useTransition:kt,useMutableSource:kt,useSyncExternalStore:kt,useId:kt,unstable_isNewReconciler:!1},hj={readContext:fs,useCallback:function(e,t){return Ts().memoizedState=[e,t===void 0?null:t],e},useContext:fs,useEffect:Zm,useImperativeHandle:function(e,t,s){return s=s!=null?s.concat([e]):null,Pl(4194308,4,hx.bind(null,t,e),s)},useLayoutEffect:function(e,t){return Pl(4194308,4,e,t)},useInsertionEffect:function(e,t){return Pl(4,2,e,t)},useMemo:function(e,t){var s=Ts();return t=t===void 0?null:t,e=e(),s.memoizedState=[e,t],e},useReducer:function(e,t,s){var r=Ts();return t=s!==void 0?s(t):t,r.memoizedState=r.baseState=t,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:t},r.queue=e,e=e.dispatch=uj.bind(null,qe,e),[r.memoizedState,e]},useRef:function(e){var t=Ts();return e={current:e},t.memoizedState=e},useState:Gm,useDebugValue:zd,useDeferredValue:function(e){return Ts().memoizedState=e},useTransition:function(){var e=Gm(!1),t=e[0];return e=cj.bind(null,e[1]),Ts().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,s){var r=qe,a=Ts();if(Be){if(s===void 0)throw Error(q(407));s=s()}else{if(s=t(),jt===null)throw Error(q(349));yr&30||rx(r,t,s)}a.memoizedState=s;var i={value:s,getSnapshot:t};return a.queue=i,Zm(ix.bind(null,r,i,e),[e]),r.flags|=2048,Si(9,ax.bind(null,r,i,s,t),void 0,null),s},useId:function(){var e=Ts(),t=jt.identifierPrefix;if(Be){var s=Xs,r=Js;s=(r&~(1<<32-ks(r)-1)).toString(32)+s,t=":"+t+"R"+s,s=Ni++,0<\/script>",e=e.removeChild(e.firstChild)):typeof r.is=="string"?e=l.createElement(s,{is:r.is}):(e=l.createElement(s),s==="select"&&(l=e,r.multiple?l.multiple=!0:r.size&&(l.size=r.size))):e=l.createElementNS(e,s),e[Rs]=t,e[vi]=r,Ax(e,t,!1,!1),t.stateNode=e;e:{switch(l=Wc(s,r),s){case"dialog":_e("cancel",e),_e("close",e),a=r;break;case"iframe":case"object":case"embed":_e("load",e),a=r;break;case"video":case"audio":for(a=0;ava&&(t.flags|=128,r=!0,$a(i,!1),t.lanes=4194304)}else{if(!r)if(e=to(l),e!==null){if(t.flags|=128,r=!0,s=e.updateQueue,s!==null&&(t.updateQueue=s,t.flags|=4),$a(i,!0),i.tail===null&&i.tailMode==="hidden"&&!l.alternate&&!Be)return Ct(t),null}else 2*et()-i.renderingStartTime>va&&s!==1073741824&&(t.flags|=128,r=!0,$a(i,!1),t.lanes=4194304);i.isBackwards?(l.sibling=t.child,t.child=l):(s=i.last,s!==null?s.sibling=l:t.child=l,i.last=l)}return i.tail!==null?(t=i.tail,i.rendering=t,i.tail=t.sibling,i.renderingStartTime=et(),t.sibling=null,s=Ve.current,Re(Ve,r?s&1|2:s&1),t):(Ct(t),null);case 22:case 23:return qd(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&t.mode&1?es&1073741824&&(Ct(t),t.subtreeFlags&6&&(t.flags|=8192)):Ct(t),null;case 24:return null;case 25:return null}throw Error(q(156,t.tag))}function jj(e,t){switch(kd(t),t.tag){case 1:return Wt(t.type)&&Wl(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return xa(),ze(Ht),ze(At),Md(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return Id(t),null;case 13:if(ze(Ve),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(q(340));pa()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return ze(Ve),null;case 4:return xa(),null;case 10:return Pd(t.type._context),null;case 22:case 23:return qd(),null;case 24:return null;default:return null}}var gl=!1,Et=!1,bj=typeof WeakSet=="function"?WeakSet:Set,re=null;function Vr(e,t){var s=e.ref;if(s!==null)if(typeof s=="function")try{s(null)}catch(r){Je(e,t,r)}else s.current=null}function bu(e,t,s){try{s()}catch(r){Je(e,t,r)}}var of=!1;function Nj(e,t){if(ru=Vl,e=Og(),wd(e)){if("selectionStart"in e)var s={start:e.selectionStart,end:e.selectionEnd};else e:{s=(s=e.ownerDocument)&&s.defaultView||window;var r=s.getSelection&&s.getSelection();if(r&&r.rangeCount!==0){s=r.anchorNode;var a=r.anchorOffset,i=r.focusNode;r=r.focusOffset;try{s.nodeType,i.nodeType}catch{s=null;break e}var l=0,o=-1,c=-1,u=0,d=0,m=e,p=null;t:for(;;){for(var h;m!==s||a!==0&&m.nodeType!==3||(o=l+a),m!==i||r!==0&&m.nodeType!==3||(c=l+r),m.nodeType===3&&(l+=m.nodeValue.length),(h=m.firstChild)!==null;)p=m,m=h;for(;;){if(m===e)break t;if(p===s&&++u===a&&(o=l),p===i&&++d===r&&(c=l),(h=m.nextSibling)!==null)break;m=p,p=m.parentNode}m=h}s=o===-1||c===-1?null:{start:o,end:c}}else s=null}s=s||{start:0,end:0}}else s=null;for(au={focusedElem:e,selectionRange:s},Vl=!1,re=t;re!==null;)if(t=re,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,re=e;else for(;re!==null;){t=re;try{var f=t.alternate;if(t.flags&1024)switch(t.tag){case 0:case 11:case 15:break;case 1:if(f!==null){var g=f.memoizedProps,b=f.memoizedState,y=t.stateNode,v=y.getSnapshotBeforeUpdate(t.elementType===t.type?g:ys(t.type,g),b);y.__reactInternalSnapshotBeforeUpdate=v}break;case 3:var x=t.stateNode.containerInfo;x.nodeType===1?x.textContent="":x.nodeType===9&&x.documentElement&&x.removeChild(x.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(q(163))}}catch(N){Je(t,t.return,N)}if(e=t.sibling,e!==null){e.return=t.return,re=e;break}re=t.return}return f=of,of=!1,f}function ni(e,t,s){var r=t.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var a=r=r.next;do{if((a.tag&e)===e){var i=a.destroy;a.destroy=void 0,i!==void 0&&bu(t,s,i)}a=a.next}while(a!==r)}}function Po(e,t){if(t=t.updateQueue,t=t!==null?t.lastEffect:null,t!==null){var s=t=t.next;do{if((s.tag&e)===e){var r=s.create;s.destroy=r()}s=s.next}while(s!==t)}}function Nu(e){var t=e.ref;if(t!==null){var s=e.stateNode;switch(e.tag){case 5:e=s;break;default:e=s}typeof t=="function"?t(e):t.current=e}}function Ix(e){var t=e.alternate;t!==null&&(e.alternate=null,Ix(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[Rs],delete t[vi],delete t[ou],delete t[rj],delete t[aj])),e.stateNode=null,e.return=null,e.dependencies=null,e.memoizedProps=null,e.memoizedState=null,e.pendingProps=null,e.stateNode=null,e.updateQueue=null}function Mx(e){return e.tag===5||e.tag===3||e.tag===4}function cf(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||Mx(e.return))return null;e=e.return}for(e.sibling.return=e.return,e=e.sibling;e.tag!==5&&e.tag!==6&&e.tag!==18;){if(e.flags&2||e.child===null||e.tag===4)continue e;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function wu(e,t,s){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?s.nodeType===8?s.parentNode.insertBefore(e,t):s.insertBefore(e,t):(s.nodeType===8?(t=s.parentNode,t.insertBefore(e,s)):(t=s,t.appendChild(e)),s=s._reactRootContainer,s!=null||t.onclick!==null||(t.onclick=Hl));else if(r!==4&&(e=e.child,e!==null))for(wu(e,t,s),e=e.sibling;e!==null;)wu(e,t,s),e=e.sibling}function Su(e,t,s){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?s.insertBefore(e,t):s.appendChild(e);else if(r!==4&&(e=e.child,e!==null))for(Su(e,t,s),e=e.sibling;e!==null;)Su(e,t,s),e=e.sibling}var bt=null,bs=!1;function mn(e,t,s){for(s=s.child;s!==null;)Lx(e,t,s),s=s.sibling}function Lx(e,t,s){if(Os&&typeof Os.onCommitFiberUnmount=="function")try{Os.onCommitFiberUnmount(bo,s)}catch{}switch(s.tag){case 5:Et||Vr(s,t);case 6:var r=bt,a=bs;bt=null,mn(e,t,s),bt=r,bs=a,bt!==null&&(bs?(e=bt,s=s.stateNode,e.nodeType===8?e.parentNode.removeChild(s):e.removeChild(s)):bt.removeChild(s.stateNode));break;case 18:bt!==null&&(bs?(e=bt,s=s.stateNode,e.nodeType===8?pc(e.parentNode,s):e.nodeType===1&&pc(e,s),fi(e)):pc(bt,s.stateNode));break;case 4:r=bt,a=bs,bt=s.stateNode.containerInfo,bs=!0,mn(e,t,s),bt=r,bs=a;break;case 0:case 11:case 14:case 15:if(!Et&&(r=s.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){a=r=r.next;do{var i=a,l=i.destroy;i=i.tag,l!==void 0&&(i&2||i&4)&&bu(s,t,l),a=a.next}while(a!==r)}mn(e,t,s);break;case 1:if(!Et&&(Vr(s,t),r=s.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=s.memoizedProps,r.state=s.memoizedState,r.componentWillUnmount()}catch(o){Je(s,t,o)}mn(e,t,s);break;case 21:mn(e,t,s);break;case 22:s.mode&1?(Et=(r=Et)||s.memoizedState!==null,mn(e,t,s),Et=r):mn(e,t,s);break;default:mn(e,t,s)}}function uf(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var s=e.stateNode;s===null&&(s=e.stateNode=new bj),t.forEach(function(r){var a=Tj.bind(null,e,r);s.has(r)||(s.add(r),r.then(a,a))})}}function xs(e,t){var s=t.deletions;if(s!==null)for(var r=0;ra&&(a=l),r&=~i}if(r=a,r=et()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*Sj(r/1960))-r,10e?16:e,Tn===null)var r=!1;else{if(e=Tn,Tn=null,io=0,De&6)throw Error(q(331));var a=De;for(De|=4,re=e.current;re!==null;){var i=re,l=i.child;if(re.flags&16){var o=i.deletions;if(o!==null){for(var c=0;cet()-Kd?mr(e,0):Bd|=s),Gt(e,t)}function Kx(e,t){t===0&&(e.mode&1?(t=ll,ll<<=1,!(ll&130023424)&&(ll=4194304)):t=1);var s=Ot();e=ln(e,t),e!==null&&(Bi(e,t,s),Gt(e,s))}function Aj(e){var t=e.memoizedState,s=0;t!==null&&(s=t.retryLane),Kx(e,s)}function Tj(e,t){var s=0;switch(e.tag){case 13:var r=e.stateNode,a=e.memoizedState;a!==null&&(s=a.retryLane);break;case 19:r=e.stateNode;break;default:throw Error(q(314))}r!==null&&r.delete(t),Kx(e,s)}var Vx;Vx=function(e,t,s){if(e!==null)if(e.memoizedProps!==t.pendingProps||Ht.current)Qt=!0;else{if(!(e.lanes&s)&&!(t.flags&128))return Qt=!1,yj(e,t,s);Qt=!!(e.flags&131072)}else Qt=!1,Be&&t.flags&1048576&&Wg(t,Yl,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;Al(e,t),e=t.pendingProps;var a=fa(t,At.current);Yr(t,s),a=Rd(null,t,r,e,a,s);var i=Od();return t.flags|=1,typeof a=="object"&&a!==null&&typeof a.render=="function"&&a.$$typeof===void 0?(t.tag=1,t.memoizedState=null,t.updateQueue=null,Wt(r)?(i=!0,Gl(t)):i=!1,t.memoizedState=a.state!==null&&a.state!==void 0?a.state:null,Td(t),a.updater=Do,t.stateNode=a,a._reactInternals=t,fu(t,r,e,s),t=xu(null,t,r,!0,i,s)):(t.tag=0,Be&&i&&Sd(t),Lt(null,t,a,s),t=t.child),t;case 16:r=t.elementType;e:{switch(Al(e,t),e=t.pendingProps,a=r._init,r=a(r._payload),t.type=r,a=t.tag=Ij(r),e=ys(r,e),a){case 0:t=gu(null,t,r,e,s);break e;case 1:t=rf(null,t,r,e,s);break e;case 11:t=sf(null,t,r,e,s);break e;case 14:t=nf(null,t,r,ys(r.type,e),s);break e}throw Error(q(306,r,""))}return t;case 0:return r=t.type,a=t.pendingProps,a=t.elementType===r?a:ys(r,a),gu(e,t,r,a,s);case 1:return r=t.type,a=t.pendingProps,a=t.elementType===r?a:ys(r,a),rf(e,t,r,a,s);case 3:e:{if(Ex(t),e===null)throw Error(q(387));r=t.pendingProps,i=t.memoizedState,a=i.element,ex(e,t),eo(t,r,null,s);var l=t.memoizedState;if(r=l.element,i.isDehydrated)if(i={element:r,isDehydrated:!1,cache:l.cache,pendingSuspenseBoundaries:l.pendingSuspenseBoundaries,transitions:l.transitions},t.updateQueue.baseState=i,t.memoizedState=i,t.flags&256){a=ya(Error(q(423)),t),t=af(e,t,r,s,a);break e}else if(r!==a){a=ya(Error(q(424)),t),t=af(e,t,r,s,a);break e}else for(ss=Rn(t.stateNode.containerInfo.firstChild),ns=t,Be=!0,Ns=null,s=Jg(t,null,r,s),t.child=s;s;)s.flags=s.flags&-3|4096,s=s.sibling;else{if(pa(),r===a){t=on(e,t,s);break e}Lt(e,t,r,s)}t=t.child}return t;case 5:return tx(t),e===null&&du(t),r=t.type,a=t.pendingProps,i=e!==null?e.memoizedProps:null,l=a.children,iu(r,a)?l=null:i!==null&&iu(r,i)&&(t.flags|=32),Cx(e,t),Lt(e,t,l,s),t.child;case 6:return e===null&&du(t),null;case 13:return Dx(e,t,s);case 4:return Fd(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=ga(t,null,r,s):Lt(e,t,r,s),t.child;case 11:return r=t.type,a=t.pendingProps,a=t.elementType===r?a:ys(r,a),sf(e,t,r,a,s);case 7:return Lt(e,t,t.pendingProps,s),t.child;case 8:return Lt(e,t,t.pendingProps.children,s),t.child;case 12:return Lt(e,t,t.pendingProps.children,s),t.child;case 10:e:{if(r=t.type._context,a=t.pendingProps,i=t.memoizedProps,l=a.value,Re(Jl,r._currentValue),r._currentValue=l,i!==null)if(Es(i.value,l)){if(i.children===a.children&&!Ht.current){t=on(e,t,s);break e}}else for(i=t.child,i!==null&&(i.return=t);i!==null;){var o=i.dependencies;if(o!==null){l=i.child;for(var c=o.firstContext;c!==null;){if(c.context===r){if(i.tag===1){c=sn(-1,s&-s),c.tag=2;var u=i.updateQueue;if(u!==null){u=u.shared;var d=u.pending;d===null?c.next=c:(c.next=d.next,d.next=c),u.pending=c}}i.lanes|=s,c=i.alternate,c!==null&&(c.lanes|=s),hu(i.return,s,t),o.lanes|=s;break}c=c.next}}else if(i.tag===10)l=i.type===t.type?null:i.child;else if(i.tag===18){if(l=i.return,l===null)throw Error(q(341));l.lanes|=s,o=l.alternate,o!==null&&(o.lanes|=s),hu(l,s,t),l=i.sibling}else l=i.child;if(l!==null)l.return=i;else for(l=i;l!==null;){if(l===t){l=null;break}if(i=l.sibling,i!==null){i.return=l.return,l=i;break}l=l.return}i=l}Lt(e,t,a.children,s),t=t.child}return t;case 9:return a=t.type,r=t.pendingProps.children,Yr(t,s),a=fs(a),r=r(a),t.flags|=1,Lt(e,t,r,s),t.child;case 14:return r=t.type,a=ys(r,t.pendingProps),a=ys(r.type,a),nf(e,t,r,a,s);case 15:return Sx(e,t,t.type,t.pendingProps,s);case 17:return r=t.type,a=t.pendingProps,a=t.elementType===r?a:ys(r,a),Al(e,t),t.tag=1,Wt(r)?(e=!0,Gl(t)):e=!1,Yr(t,s),bx(t,r,a),fu(t,r,a,s),xu(null,t,r,!0,e,s);case 19:return Px(e,t,s);case 22:return kx(e,t,s)}throw Error(q(156,t.tag))};function qx(e,t){return yg(e,t)}function Fj(e,t,s,r){this.tag=e,this.key=s,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=t,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function ds(e,t,s,r){return new Fj(e,t,s,r)}function Hd(e){return e=e.prototype,!(!e||!e.isReactComponent)}function Ij(e){if(typeof e=="function")return Hd(e)?1:0;if(e!=null){if(e=e.$$typeof,e===hd)return 11;if(e===md)return 14}return 2}function Un(e,t){var s=e.alternate;return s===null?(s=ds(e.tag,t,e.key,e.mode),s.elementType=e.elementType,s.type=e.type,s.stateNode=e.stateNode,s.alternate=e,e.alternate=s):(s.pendingProps=t,s.type=e.type,s.flags=0,s.subtreeFlags=0,s.deletions=null),s.flags=e.flags&14680064,s.childLanes=e.childLanes,s.lanes=e.lanes,s.child=e.child,s.memoizedProps=e.memoizedProps,s.memoizedState=e.memoizedState,s.updateQueue=e.updateQueue,t=e.dependencies,s.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext},s.sibling=e.sibling,s.index=e.index,s.ref=e.ref,s}function Il(e,t,s,r,a,i){var l=2;if(r=e,typeof e=="function")Hd(e)&&(l=1);else if(typeof e=="string")l=5;else e:switch(e){case Lr:return fr(s.children,a,i,t);case dd:l=8,a|=8;break;case _c:return e=ds(12,s,t,a|2),e.elementType=_c,e.lanes=i,e;case zc:return e=ds(13,s,t,a),e.elementType=zc,e.lanes=i,e;case Uc:return e=ds(19,s,t,a),e.elementType=Uc,e.lanes=i,e;case tg:return To(s,a,i,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case Xp:l=10;break e;case eg:l=9;break e;case hd:l=11;break e;case md:l=14;break e;case pn:l=16,r=null;break e}throw Error(q(130,e==null?e:typeof e,""))}return t=ds(l,s,t,a),t.elementType=e,t.type=r,t.lanes=i,t}function fr(e,t,s,r){return e=ds(7,e,r,t),e.lanes=s,e}function To(e,t,s,r){return e=ds(22,e,r,t),e.elementType=tg,e.lanes=s,e.stateNode={isHidden:!1},e}function wc(e,t,s){return e=ds(6,e,null,t),e.lanes=s,e}function Sc(e,t,s){return t=ds(4,e.children!==null?e.children:[],e.key,t),t.lanes=s,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function Mj(e,t,s,r,a){this.tag=t,this.containerInfo=e,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=rc(0),this.expirationTimes=rc(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=rc(0),this.identifierPrefix=r,this.onRecoverableError=a,this.mutableSourceEagerHydrationData=null}function Wd(e,t,s,r,a,i,l,o,c){return e=new Mj(e,t,s,o,c),t===1?(t=1,i===!0&&(t|=8)):t=0,i=ds(3,null,null,t),e.current=i,i.stateNode=e,i.memoizedState={element:r,isDehydrated:s,cache:null,transitions:null,pendingSuspenseBoundaries:null},Td(i),e}function Lj(e,t,s){var r=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(Gx)}catch(e){console.error(e)}}Gx(),Gp.exports=as;var Uj=Gp.exports,yf=Uj;Rc.createRoot=yf.createRoot,Rc.hydrateRoot=yf.hydrateRoot;/** * @remix-run/router v1.23.2 * * Copyright (c) Remix Software Inc. * * This source code is licensed under the MIT license found in the * LICENSE.md file in the root directory of this source tree. * * @license MIT */function Ci(){return Ci=Object.assign?Object.assign.bind():function(e){for(var t=1;t"u")throw new Error(t)}function Jd(e,t){if(!e){typeof console<"u"&&console.warn(t);try{throw new Error(t)}catch{}}}function Bj(){return Math.random().toString(36).substr(2,8)}function jf(e,t){return{usr:e.state,key:e.key,idx:t}}function Pu(e,t,s,r){return s===void 0&&(s=null),Ci({pathname:typeof e=="string"?e:e.pathname,search:"",hash:""},typeof t=="string"?Ea(t):t,{state:s,key:t&&t.key||r||Bj()})}function co(e){let{pathname:t="/",search:s="",hash:r=""}=e;return s&&s!=="?"&&(t+=s.charAt(0)==="?"?s:"?"+s),r&&r!=="#"&&(t+=r.charAt(0)==="#"?r:"#"+r),t}function Ea(e){let t={};if(e){let s=e.indexOf("#");s>=0&&(t.hash=e.substr(s),e=e.substr(0,s));let r=e.indexOf("?");r>=0&&(t.search=e.substr(r),e=e.substr(0,r)),e&&(t.pathname=e)}return t}function Kj(e,t,s,r){r===void 0&&(r={});let{window:a=document.defaultView,v5Compat:i=!1}=r,l=a.history,o=Fn.Pop,c=null,u=d();u==null&&(u=0,l.replaceState(Ci({},l.state,{idx:u}),""));function d(){return(l.state||{idx:null}).idx}function m(){o=Fn.Pop;let b=d(),y=b==null?null:b-u;u=b,c&&c({action:o,location:g.location,delta:y})}function p(b,y){o=Fn.Push;let v=Pu(g.location,b,y);u=d()+1;let x=jf(v,u),N=g.createHref(v);try{l.pushState(x,"",N)}catch(k){if(k instanceof DOMException&&k.name==="DataCloneError")throw k;a.location.assign(N)}i&&c&&c({action:o,location:g.location,delta:1})}function h(b,y){o=Fn.Replace;let v=Pu(g.location,b,y);u=d();let x=jf(v,u),N=g.createHref(v);l.replaceState(x,"",N),i&&c&&c({action:o,location:g.location,delta:0})}function f(b){let y=a.location.origin!=="null"?a.location.origin:a.location.href,v=typeof b=="string"?b:co(b);return v=v.replace(/ $/,"%20"),Qe(y,"No window.location.(origin|href) available to create URL for href: "+v),new URL(v,y)}let g={get action(){return o},get location(){return e(a,l)},listen(b){if(c)throw new Error("A history only accepts one active listener");return a.addEventListener(vf,m),c=b,()=>{a.removeEventListener(vf,m),c=null}},createHref(b){return t(a,b)},createURL:f,encodeLocation(b){let y=f(b);return{pathname:y.pathname,search:y.search,hash:y.hash}},push:p,replace:h,go(b){return l.go(b)}};return g}var bf;(function(e){e.data="data",e.deferred="deferred",e.redirect="redirect",e.error="error"})(bf||(bf={}));function Vj(e,t,s){return s===void 0&&(s="/"),qj(e,t,s)}function qj(e,t,s,r){let a=typeof t=="string"?Ea(t):t,i=ja(a.pathname||"/",s);if(i==null)return null;let l=Zx(e);Qj(l);let o=null;for(let c=0;o==null&&c{let c={relativePath:o===void 0?i.path||"":o,caseSensitive:i.caseSensitive===!0,childrenIndex:l,route:i};c.relativePath.startsWith("/")&&(Qe(c.relativePath.startsWith(r),'Absolute route path "'+c.relativePath+'" nested under path '+('"'+r+'" is not valid. An absolute child route path ')+"must start with the combined path of all its parent routes."),c.relativePath=c.relativePath.slice(r.length));let u=$n([r,c.relativePath]),d=s.concat(c);i.children&&i.children.length>0&&(Qe(i.index!==!0,"Index routes must not have child routes. Please remove "+('all child routes from route path "'+u+'".')),Zx(i.children,t,d,u)),!(i.path==null&&!i.index)&&t.push({path:u,score:Xj(u,i.index),routesMeta:d})};return e.forEach((i,l)=>{var o;if(i.path===""||!((o=i.path)!=null&&o.includes("?")))a(i,l);else for(let c of Yx(i.path))a(i,l,c)}),t}function Yx(e){let t=e.split("/");if(t.length===0)return[];let[s,...r]=t,a=s.endsWith("?"),i=s.replace(/\?$/,"");if(r.length===0)return a?[i,""]:[i];let l=Yx(r.join("/")),o=[];return o.push(...l.map(c=>c===""?i:[i,c].join("/"))),a&&o.push(...l),o.map(c=>e.startsWith("/")&&c===""?"/":c)}function Qj(e){e.sort((t,s)=>t.score!==s.score?s.score-t.score:eb(t.routesMeta.map(r=>r.childrenIndex),s.routesMeta.map(r=>r.childrenIndex)))}const Hj=/^:[\w-]+$/,Wj=3,Gj=2,Zj=1,Yj=10,Jj=-2,Nf=e=>e==="*";function Xj(e,t){let s=e.split("/"),r=s.length;return s.some(Nf)&&(r+=Jj),t&&(r+=Gj),s.filter(a=>!Nf(a)).reduce((a,i)=>a+(Hj.test(i)?Wj:i===""?Zj:Yj),r)}function eb(e,t){return e.length===t.length&&e.slice(0,-1).every((r,a)=>r===t[a])?e[e.length-1]-t[t.length-1]:0}function tb(e,t,s){let{routesMeta:r}=e,a={},i="/",l=[];for(let o=0;o{let{paramName:p,isOptional:h}=d;if(p==="*"){let g=o[m]||"";l=i.slice(0,i.length-g.length).replace(/(.)\/+$/,"$1")}const f=o[m];return h&&!f?u[p]=void 0:u[p]=(f||"").replace(/%2F/g,"/"),u},{}),pathname:i,pathnameBase:l,pattern:e}}function sb(e,t,s){t===void 0&&(t=!1),s===void 0&&(s=!0),Jd(e==="*"||!e.endsWith("*")||e.endsWith("/*"),'Route path "'+e+'" will be treated as if it were '+('"'+e.replace(/\*$/,"/*")+'" because the `*` character must ')+"always follow a `/` in the pattern. To get rid of this warning, "+('please change the route path to "'+e.replace(/\*$/,"/*")+'".'));let r=[],a="^"+e.replace(/\/*\*?$/,"").replace(/^\/*/,"/").replace(/[\\.*+^${}|()[\]]/g,"\\$&").replace(/\/:([\w-]+)(\?)?/g,(l,o,c)=>(r.push({paramName:o,isOptional:c!=null}),c?"/?([^\\/]+)?":"/([^\\/]+)"));return e.endsWith("*")?(r.push({paramName:"*"}),a+=e==="*"||e==="/*"?"(.*)$":"(?:\\/(.+)|\\/*)$"):s?a+="\\/*$":e!==""&&e!=="/"&&(a+="(?:(?=\\/|$))"),[new RegExp(a,t?void 0:"i"),r]}function nb(e){try{return e.split("/").map(t=>decodeURIComponent(t).replace(/\//g,"%2F")).join("/")}catch(t){return Jd(!1,'The URL path "'+e+'" could not be decoded because it is is a malformed URL segment. This is probably due to a bad percent '+("encoding ("+t+").")),e}}function ja(e,t){if(t==="/")return e;if(!e.toLowerCase().startsWith(t.toLowerCase()))return null;let s=t.endsWith("/")?t.length-1:t.length,r=e.charAt(s);return r&&r!=="/"?null:e.slice(s)||"/"}const rb=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,ab=e=>rb.test(e);function ib(e,t){t===void 0&&(t="/");let{pathname:s,search:r="",hash:a=""}=typeof e=="string"?Ea(e):e,i;if(s)if(ab(s))i=s;else{if(s.includes("//")){let l=s;s=s.replace(/\/\/+/g,"/"),Jd(!1,"Pathnames cannot have embedded double slashes - normalizing "+(l+" -> "+s))}s.startsWith("/")?i=wf(s.substring(1),"/"):i=wf(s,t)}else i=t;return{pathname:i,search:cb(r),hash:ub(a)}}function wf(e,t){let s=t.replace(/\/+$/,"").split("/");return e.split("/").forEach(a=>{a===".."?s.length>1&&s.pop():a!=="."&&s.push(a)}),s.length>1?s.join("/"):"/"}function kc(e,t,s,r){return"Cannot include a '"+e+"' character in a manually specified "+("`to."+t+"` field ["+JSON.stringify(r)+"]. Please separate it out to the ")+("`to."+s+"` field. Alternatively you may provide the full path as ")+'a string in and the router will parse it for you.'}function lb(e){return e.filter((t,s)=>s===0||t.route.path&&t.route.path.length>0)}function Xd(e,t){let s=lb(e);return t?s.map((r,a)=>a===s.length-1?r.pathname:r.pathnameBase):s.map(r=>r.pathnameBase)}function eh(e,t,s,r){r===void 0&&(r=!1);let a;typeof e=="string"?a=Ea(e):(a=Ci({},e),Qe(!a.pathname||!a.pathname.includes("?"),kc("?","pathname","search",a)),Qe(!a.pathname||!a.pathname.includes("#"),kc("#","pathname","hash",a)),Qe(!a.search||!a.search.includes("#"),kc("#","search","hash",a)));let i=e===""||a.pathname==="",l=i?"/":a.pathname,o;if(l==null)o=s;else{let m=t.length-1;if(!r&&l.startsWith("..")){let p=l.split("/");for(;p[0]==="..";)p.shift(),m-=1;a.pathname=p.join("/")}o=m>=0?t[m]:"/"}let c=ib(a,o),u=l&&l!=="/"&&l.endsWith("/"),d=(i||l===".")&&s.endsWith("/");return!c.pathname.endsWith("/")&&(u||d)&&(c.pathname+="/"),c}const $n=e=>e.join("/").replace(/\/\/+/g,"/"),ob=e=>e.replace(/\/+$/,"").replace(/^\/*/,"/"),cb=e=>!e||e==="?"?"":e.startsWith("?")?e:"?"+e,ub=e=>!e||e==="#"?"":e.startsWith("#")?e:"#"+e;function db(e){return e!=null&&typeof e.status=="number"&&typeof e.statusText=="string"&&typeof e.internal=="boolean"&&"data"in e}const Jx=["post","put","patch","delete"];new Set(Jx);const hb=["get",...Jx];new Set(hb);/** * React Router v6.30.3 * * Copyright (c) Remix Software Inc. * * This source code is licensed under the MIT license found in the * LICENSE.md file in the root directory of this source tree. * * @license MIT */function Ei(){return Ei=Object.assign?Object.assign.bind():function(e){for(var t=1;t{o.current=!0}),w.useCallback(function(u,d){if(d===void 0&&(d={}),!o.current)return;if(typeof u=="number"){r.go(u);return}let m=eh(u,JSON.parse(l),i,d.relative==="path");e==null&&t!=="/"&&(m.pathname=m.pathname==="/"?t:$n([t,m.pathname])),(d.replace?r.replace:r.push)(m,d.state,d)},[t,r,l,i,e])}const pb=w.createContext(null);function gb(e){let t=w.useContext(Us).outlet;return t&&w.createElement(pb.Provider,{value:e},t)}function _o(){let{matches:e}=w.useContext(Us),t=e[e.length-1];return t?t.params:{}}function zo(e,t){let{relative:s}=t===void 0?{}:t,{future:r}=w.useContext(un),{matches:a}=w.useContext(Us),{pathname:i}=dn(),l=JSON.stringify(Xd(a,r.v7_relativeSplatPath));return w.useMemo(()=>eh(e,JSON.parse(l),i,s==="path"),[e,l,i,s])}function xb(e,t){return yb(e,t)}function yb(e,t,s,r){Da()||Qe(!1);let{navigator:a}=w.useContext(un),{matches:i}=w.useContext(Us),l=i[i.length-1],o=l?l.params:{};l&&l.pathname;let c=l?l.pathnameBase:"/";l&&l.route;let u=dn(),d;if(t){var m;let b=typeof t=="string"?Ea(t):t;c==="/"||(m=b.pathname)!=null&&m.startsWith(c)||Qe(!1),d=b}else d=u;let p=d.pathname||"/",h=p;if(c!=="/"){let b=c.replace(/^\//,"").split("/");h="/"+p.replace(/^\//,"").split("/").slice(b.length).join("/")}let f=Vj(e,{pathname:h}),g=wb(f&&f.map(b=>Object.assign({},b,{params:Object.assign({},o,b.params),pathname:$n([c,a.encodeLocation?a.encodeLocation(b.pathname).pathname:b.pathname]),pathnameBase:b.pathnameBase==="/"?c:$n([c,a.encodeLocation?a.encodeLocation(b.pathnameBase).pathname:b.pathnameBase])})),i,s,r);return t&&g?w.createElement(Oo.Provider,{value:{location:Ei({pathname:"/",search:"",hash:"",state:null,key:"default"},d),navigationType:Fn.Pop}},g):g}function vb(){let e=Eb(),t=db(e)?e.status+" "+e.statusText:e instanceof Error?e.message:JSON.stringify(e),s=e instanceof Error?e.stack:null,a={padding:"0.5rem",backgroundColor:"rgba(200,200,200, 0.5)"};return w.createElement(w.Fragment,null,w.createElement("h2",null,"Unexpected Application Error!"),w.createElement("h3",{style:{fontStyle:"italic"}},t),s?w.createElement("pre",{style:a},s):null,null)}const jb=w.createElement(vb,null);class bb extends w.Component{constructor(t){super(t),this.state={location:t.location,revalidation:t.revalidation,error:t.error}}static getDerivedStateFromError(t){return{error:t}}static getDerivedStateFromProps(t,s){return s.location!==t.location||s.revalidation!=="idle"&&t.revalidation==="idle"?{error:t.error,location:t.location,revalidation:t.revalidation}:{error:t.error!==void 0?t.error:s.error,location:s.location,revalidation:t.revalidation||s.revalidation}}componentDidCatch(t,s){console.error("React Router caught the following error during render",t,s)}render(){return this.state.error!==void 0?w.createElement(Us.Provider,{value:this.props.routeContext},w.createElement(ey.Provider,{value:this.state.error,children:this.props.component})):this.props.children}}function Nb(e){let{routeContext:t,match:s,children:r}=e,a=w.useContext(Ro);return a&&a.static&&a.staticContext&&(s.route.errorElement||s.route.ErrorBoundary)&&(a.staticContext._deepestRenderedBoundaryId=s.route.id),w.createElement(Us.Provider,{value:t},r)}function wb(e,t,s,r){var a;if(t===void 0&&(t=[]),s===void 0&&(s=null),r===void 0&&(r=null),e==null){var i;if(!s)return null;if(s.errors)e=s.matches;else if((i=r)!=null&&i.v7_partialHydration&&t.length===0&&!s.initialized&&s.matches.length>0)e=s.matches;else return null}let l=e,o=(a=s)==null?void 0:a.errors;if(o!=null){let d=l.findIndex(m=>m.route.id&&(o==null?void 0:o[m.route.id])!==void 0);d>=0||Qe(!1),l=l.slice(0,Math.min(l.length,d+1))}let c=!1,u=-1;if(s&&r&&r.v7_partialHydration)for(let d=0;d=0?l=l.slice(0,u+1):l=[l[0]];break}}}return l.reduceRight((d,m,p)=>{let h,f=!1,g=null,b=null;s&&(h=o&&m.route.id?o[m.route.id]:void 0,g=m.route.errorElement||jb,c&&(u<0&&p===0?(Pb("route-fallback"),f=!0,b=null):u===p&&(f=!0,b=m.route.hydrateFallbackElement||null)));let y=t.concat(l.slice(0,p+1)),v=()=>{let x;return h?x=g:f?x=b:m.route.Component?x=w.createElement(m.route.Component,null):m.route.element?x=m.route.element:x=d,w.createElement(Nb,{match:m,routeContext:{outlet:d,matches:y,isDataRoute:s!=null},children:x})};return s&&(m.route.ErrorBoundary||m.route.errorElement||p===0)?w.createElement(bb,{location:s.location,revalidation:s.revalidation,component:g,error:h,children:v(),routeContext:{outlet:null,matches:y,isDataRoute:!0}}):v()},null)}var sy=function(e){return e.UseBlocker="useBlocker",e.UseRevalidator="useRevalidator",e.UseNavigateStable="useNavigate",e}(sy||{}),ny=function(e){return e.UseBlocker="useBlocker",e.UseLoaderData="useLoaderData",e.UseActionData="useActionData",e.UseRouteError="useRouteError",e.UseNavigation="useNavigation",e.UseRouteLoaderData="useRouteLoaderData",e.UseMatches="useMatches",e.UseRevalidator="useRevalidator",e.UseNavigateStable="useNavigate",e.UseRouteId="useRouteId",e}(ny||{});function Sb(e){let t=w.useContext(Ro);return t||Qe(!1),t}function kb(e){let t=w.useContext(Xx);return t||Qe(!1),t}function Cb(e){let t=w.useContext(Us);return t||Qe(!1),t}function ry(e){let t=Cb(),s=t.matches[t.matches.length-1];return s.route.id||Qe(!1),s.route.id}function Eb(){var e;let t=w.useContext(ey),s=kb(),r=ry();return t!==void 0?t:(e=s.errors)==null?void 0:e[r]}function Db(){let{router:e}=Sb(sy.UseNavigateStable),t=ry(ny.UseNavigateStable),s=w.useRef(!1);return ty(()=>{s.current=!0}),w.useCallback(function(a,i){i===void 0&&(i={}),s.current&&(typeof a=="number"?e.navigate(a):e.navigate(a,Ei({fromRouteId:t},i)))},[e,t])}const Sf={};function Pb(e,t,s){Sf[e]||(Sf[e]=!0)}function Ab(e,t){e==null||e.v7_startTransition,e==null||e.v7_relativeSplatPath}function Qr(e){let{to:t,replace:s,state:r,relative:a}=e;Da()||Qe(!1);let{future:i,static:l}=w.useContext(un),{matches:o}=w.useContext(Us),{pathname:c}=dn(),u=Ut(),d=eh(t,Xd(o,i.v7_relativeSplatPath),c,a==="path"),m=JSON.stringify(d);return w.useEffect(()=>u(JSON.parse(m),{replace:s,state:r,relative:a}),[u,m,a,s,r]),null}function Tb(e){return gb(e.context)}function Fe(e){Qe(!1)}function Fb(e){let{basename:t="/",children:s=null,location:r,navigationType:a=Fn.Pop,navigator:i,static:l=!1,future:o}=e;Da()&&Qe(!1);let c=t.replace(/^\/*/,"/"),u=w.useMemo(()=>({basename:c,navigator:i,static:l,future:Ei({v7_relativeSplatPath:!1},o)}),[c,o,i,l]);typeof r=="string"&&(r=Ea(r));let{pathname:d="/",search:m="",hash:p="",state:h=null,key:f="default"}=r,g=w.useMemo(()=>{let b=ja(d,c);return b==null?null:{location:{pathname:b,search:m,hash:p,state:h,key:f},navigationType:a}},[c,d,m,p,h,f,a]);return g==null?null:w.createElement(un.Provider,{value:u},w.createElement(Oo.Provider,{children:s,value:g}))}function Ib(e){let{children:t,location:s}=e;return xb(Tu(t),s)}new Promise(()=>{});function Tu(e,t){t===void 0&&(t=[]);let s=[];return w.Children.forEach(e,(r,a)=>{if(!w.isValidElement(r))return;let i=[...t,a];if(r.type===w.Fragment){s.push.apply(s,Tu(r.props.children,i));return}r.type!==Fe&&Qe(!1),!r.props.index||!r.props.children||Qe(!1);let l={id:r.props.id||i.join("-"),caseSensitive:r.props.caseSensitive,element:r.props.element,Component:r.props.Component,index:r.props.index,path:r.props.path,loader:r.props.loader,action:r.props.action,errorElement:r.props.errorElement,ErrorBoundary:r.props.ErrorBoundary,hasErrorBoundary:r.props.ErrorBoundary!=null||r.props.errorElement!=null,shouldRevalidate:r.props.shouldRevalidate,handle:r.props.handle,lazy:r.props.lazy};r.props.children&&(l.children=Tu(r.props.children,i)),s.push(l)}),s}/** * React Router DOM v6.30.3 * * Copyright (c) Remix Software Inc. * * This source code is licensed under the MIT license found in the * LICENSE.md file in the root directory of this source tree. * * @license MIT */function uo(){return uo=Object.assign?Object.assign.bind():function(e){for(var t=1;t=0)&&(s[a]=e[a]);return s}function Mb(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function Lb(e,t){return e.button===0&&(!t||t==="_self")&&!Mb(e)}function Fu(e){return e===void 0&&(e=""),new URLSearchParams(typeof e=="string"||Array.isArray(e)||e instanceof URLSearchParams?e:Object.keys(e).reduce((t,s)=>{let r=e[s];return t.concat(Array.isArray(r)?r.map(a=>[s,a]):[[s,r]])},[]))}function Rb(e,t){let s=Fu(e);return t&&t.forEach((r,a)=>{s.has(a)||t.getAll(a).forEach(i=>{s.append(a,i)})}),s}const Ob=["onClick","relative","reloadDocument","replace","state","target","to","preventScrollReset","viewTransition"],_b=["aria-current","caseSensitive","className","end","style","to","viewTransition","children"],zb="6";try{window.__reactRouterVersion=zb}catch{}const Ub=w.createContext({isTransitioning:!1}),$b="startTransition",kf=Pv[$b];function Bb(e){let{basename:t,children:s,future:r,window:a}=e,i=w.useRef();i.current==null&&(i.current=$j({window:a,v5Compat:!0}));let l=i.current,[o,c]=w.useState({action:l.action,location:l.location}),{v7_startTransition:u}=r||{},d=w.useCallback(m=>{u&&kf?kf(()=>c(m)):c(m)},[c,u]);return w.useLayoutEffect(()=>l.listen(d),[l,d]),w.useEffect(()=>Ab(r),[r]),w.createElement(Fb,{basename:t,children:s,location:o.location,navigationType:o.action,navigator:l,future:r})}const Kb=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",Vb=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,Se=w.forwardRef(function(t,s){let{onClick:r,relative:a,reloadDocument:i,replace:l,state:o,target:c,to:u,preventScrollReset:d,viewTransition:m}=t,p=ay(t,Ob),{basename:h}=w.useContext(un),f,g=!1;if(typeof u=="string"&&Vb.test(u)&&(f=u,Kb))try{let x=new URL(window.location.href),N=u.startsWith("//")?new URL(x.protocol+u):new URL(u),k=ja(N.pathname,h);N.origin===x.origin&&k!=null?u=k+N.search+N.hash:g=!0}catch{}let b=mb(u,{relative:a}),y=Qb(u,{replace:l,state:o,target:c,preventScrollReset:d,relative:a,viewTransition:m});function v(x){r&&r(x),x.defaultPrevented||y(x)}return w.createElement("a",uo({},p,{href:f||b,onClick:g||i?r:v,ref:s,target:c}))}),Cc=w.forwardRef(function(t,s){let{"aria-current":r="page",caseSensitive:a=!1,className:i="",end:l=!1,style:o,to:c,viewTransition:u,children:d}=t,m=ay(t,_b),p=zo(c,{relative:m.relative}),h=dn(),f=w.useContext(Xx),{navigator:g,basename:b}=w.useContext(un),y=f!=null&&Hb(p)&&u===!0,v=g.encodeLocation?g.encodeLocation(p).pathname:p.pathname,x=h.pathname,N=f&&f.navigation&&f.navigation.location?f.navigation.location.pathname:null;a||(x=x.toLowerCase(),N=N?N.toLowerCase():null,v=v.toLowerCase()),N&&b&&(N=ja(N,b)||N);const k=v!=="/"&&v.endsWith("/")?v.length-1:v.length;let D=x===v||!l&&x.startsWith(v)&&x.charAt(k)==="/",F=N!=null&&(N===v||!l&&N.startsWith(v)&&N.charAt(v.length)==="/"),S={isActive:D,isPending:F,isTransitioning:y},L=D?r:void 0,T;typeof i=="function"?T=i(S):T=[i,D?"active":null,F?"pending":null,y?"transitioning":null].filter(Boolean).join(" ");let _=typeof o=="function"?o(S):o;return w.createElement(Se,uo({},m,{"aria-current":L,className:T,ref:s,style:_,to:c,viewTransition:u}),typeof d=="function"?d(S):d)});var Iu;(function(e){e.UseScrollRestoration="useScrollRestoration",e.UseSubmit="useSubmit",e.UseSubmitFetcher="useSubmitFetcher",e.UseFetcher="useFetcher",e.useViewTransitionState="useViewTransitionState"})(Iu||(Iu={}));var Cf;(function(e){e.UseFetcher="useFetcher",e.UseFetchers="useFetchers",e.UseScrollRestoration="useScrollRestoration"})(Cf||(Cf={}));function qb(e){let t=w.useContext(Ro);return t||Qe(!1),t}function Qb(e,t){let{target:s,replace:r,state:a,preventScrollReset:i,relative:l,viewTransition:o}=t===void 0?{}:t,c=Ut(),u=dn(),d=zo(e,{relative:l});return w.useCallback(m=>{if(Lb(m,s)){m.preventDefault();let p=r!==void 0?r:co(u)===co(d);c(e,{replace:p,state:a,preventScrollReset:i,relative:l,viewTransition:o})}},[u,c,d,r,a,s,e,i,l,o])}function Uo(e){let t=w.useRef(Fu(e)),s=w.useRef(!1),r=dn(),a=w.useMemo(()=>Rb(r.search,s.current?null:t.current),[r.search]),i=Ut(),l=w.useCallback((o,c)=>{const u=Fu(typeof o=="function"?o(a):o);s.current=!0,i("?"+u,c)},[i,a]);return[a,l]}function Hb(e,t){t===void 0&&(t={});let s=w.useContext(Ub);s==null&&Qe(!1);let{basename:r}=qb(Iu.useViewTransitionState),a=zo(e,{relative:t.relative});if(!s.isTransitioning)return!1;let i=ja(s.currentLocation.pathname,r)||s.currentLocation.pathname,l=ja(s.nextLocation.pathname,r)||s.nextLocation.pathname;return Au(a.pathname,l)!=null||Au(a.pathname,i)!=null}var Pa=class{constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(e){return this.listeners.add(e),this.onSubscribe(),()=>{this.listeners.delete(e),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}},Wb={setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:e=>clearTimeout(e),setInterval:(e,t)=>setInterval(e,t),clearInterval:e=>clearInterval(e)},bn,nd,Ep,Gb=(Ep=class{constructor(){ue(this,bn,Wb);ue(this,nd,!1)}setTimeoutProvider(e){te(this,bn,e)}setTimeout(e,t){return C(this,bn).setTimeout(e,t)}clearTimeout(e){C(this,bn).clearTimeout(e)}setInterval(e,t){return C(this,bn).setInterval(e,t)}clearInterval(e){C(this,bn).clearInterval(e)}},bn=new WeakMap,nd=new WeakMap,Ep),tr=new Gb;function Zb(e){setTimeout(e,0)}var br=typeof window>"u"||"Deno"in globalThis;function Rt(){}function Yb(e,t){return typeof e=="function"?e(t):e}function Mu(e){return typeof e=="number"&&e>=0&&e!==1/0}function iy(e,t){return Math.max(e+(t||0)-Date.now(),0)}function Bn(e,t){return typeof e=="function"?e(t):e}function os(e,t){return typeof e=="function"?e(t):e}function Ef(e,t){const{type:s="all",exact:r,fetchStatus:a,predicate:i,queryKey:l,stale:o}=e;if(l){if(r){if(t.queryHash!==th(l,t.options))return!1}else if(!Di(t.queryKey,l))return!1}if(s!=="all"){const c=t.isActive();if(s==="active"&&!c||s==="inactive"&&c)return!1}return!(typeof o=="boolean"&&t.isStale()!==o||a&&a!==t.state.fetchStatus||i&&!i(t))}function Df(e,t){const{exact:s,status:r,predicate:a,mutationKey:i}=e;if(i){if(!t.options.mutationKey)return!1;if(s){if(Nr(t.options.mutationKey)!==Nr(i))return!1}else if(!Di(t.options.mutationKey,i))return!1}return!(r&&t.state.status!==r||a&&!a(t))}function th(e,t){return((t==null?void 0:t.queryKeyHashFn)||Nr)(e)}function Nr(e){return JSON.stringify(e,(t,s)=>Lu(s)?Object.keys(s).sort().reduce((r,a)=>(r[a]=s[a],r),{}):s)}function Di(e,t){return e===t?!0:typeof e!=typeof t?!1:e&&t&&typeof e=="object"&&typeof t=="object"?Object.keys(t).every(s=>Di(e[s],t[s])):!1}var Jb=Object.prototype.hasOwnProperty;function ly(e,t,s=0){if(e===t)return e;if(s>500)return t;const r=Pf(e)&&Pf(t);if(!r&&!(Lu(e)&&Lu(t)))return t;const i=(r?e:Object.keys(e)).length,l=r?t:Object.keys(t),o=l.length,c=r?new Array(o):{};let u=0;for(let d=0;d{tr.setTimeout(t,e)})}function Ru(e,t,s){return typeof s.structuralSharing=="function"?s.structuralSharing(e,t):s.structuralSharing!==!1?ly(e,t):t}function eN(e,t,s=0){const r=[...e,t];return s&&r.length>s?r.slice(1):r}function tN(e,t,s=0){const r=[t,...e];return s&&r.length>s?r.slice(0,-1):r}var sh=Symbol();function oy(e,t){return!e.queryFn&&(t!=null&&t.initialPromise)?()=>t.initialPromise:!e.queryFn||e.queryFn===sh?()=>Promise.reject(new Error(`Missing queryFn: '${e.queryHash}'`)):e.queryFn}function nh(e,t){return typeof e=="function"?e(...t):!!e}function sN(e,t,s){let r=!1,a;return Object.defineProperty(e,"signal",{enumerable:!0,get:()=>(a??(a=t()),r||(r=!0,a.aborted?s():a.addEventListener("abort",s,{once:!0})),a)}),e}var rr,Nn,ta,Dp,nN=(Dp=class extends Pa{constructor(){super();ue(this,rr);ue(this,Nn);ue(this,ta);te(this,ta,t=>{if(!br&&window.addEventListener){const s=()=>t();return window.addEventListener("visibilitychange",s,!1),()=>{window.removeEventListener("visibilitychange",s)}}})}onSubscribe(){C(this,Nn)||this.setEventListener(C(this,ta))}onUnsubscribe(){var t;this.hasListeners()||((t=C(this,Nn))==null||t.call(this),te(this,Nn,void 0))}setEventListener(t){var s;te(this,ta,t),(s=C(this,Nn))==null||s.call(this),te(this,Nn,t(r=>{typeof r=="boolean"?this.setFocused(r):this.onFocus()}))}setFocused(t){C(this,rr)!==t&&(te(this,rr,t),this.onFocus())}onFocus(){const t=this.isFocused();this.listeners.forEach(s=>{s(t)})}isFocused(){var t;return typeof C(this,rr)=="boolean"?C(this,rr):((t=globalThis.document)==null?void 0:t.visibilityState)!=="hidden"}},rr=new WeakMap,Nn=new WeakMap,ta=new WeakMap,Dp),rh=new nN;function Ou(){let e,t;const s=new Promise((a,i)=>{e=a,t=i});s.status="pending",s.catch(()=>{});function r(a){Object.assign(s,a),delete s.resolve,delete s.reject}return s.resolve=a=>{r({status:"fulfilled",value:a}),e(a)},s.reject=a=>{r({status:"rejected",reason:a}),t(a)},s}var rN=Zb;function aN(){let e=[],t=0,s=o=>{o()},r=o=>{o()},a=rN;const i=o=>{t?e.push(o):a(()=>{s(o)})},l=()=>{const o=e;e=[],o.length&&a(()=>{r(()=>{o.forEach(c=>{s(c)})})})};return{batch:o=>{let c;t++;try{c=o()}finally{t--,t||l()}return c},batchCalls:o=>(...c)=>{i(()=>{o(...c)})},schedule:i,setNotifyFunction:o=>{s=o},setBatchNotifyFunction:o=>{r=o},setScheduler:o=>{a=o}}}var ct=aN(),sa,wn,na,Pp,iN=(Pp=class extends Pa{constructor(){super();ue(this,sa,!0);ue(this,wn);ue(this,na);te(this,na,t=>{if(!br&&window.addEventListener){const s=()=>t(!0),r=()=>t(!1);return window.addEventListener("online",s,!1),window.addEventListener("offline",r,!1),()=>{window.removeEventListener("online",s),window.removeEventListener("offline",r)}}})}onSubscribe(){C(this,wn)||this.setEventListener(C(this,na))}onUnsubscribe(){var t;this.hasListeners()||((t=C(this,wn))==null||t.call(this),te(this,wn,void 0))}setEventListener(t){var s;te(this,na,t),(s=C(this,wn))==null||s.call(this),te(this,wn,t(this.setOnline.bind(this)))}setOnline(t){C(this,sa)!==t&&(te(this,sa,t),this.listeners.forEach(r=>{r(t)}))}isOnline(){return C(this,sa)}},sa=new WeakMap,wn=new WeakMap,na=new WeakMap,Pp),mo=new iN;function lN(e){return Math.min(1e3*2**e,3e4)}function cy(e){return(e??"online")==="online"?mo.isOnline():!0}var _u=class extends Error{constructor(e){super("CancelledError"),this.revert=e==null?void 0:e.revert,this.silent=e==null?void 0:e.silent}};function uy(e){let t=!1,s=0,r;const a=Ou(),i=()=>a.status!=="pending",l=g=>{var b;if(!i()){const y=new _u(g);p(y),(b=e.onCancel)==null||b.call(e,y)}},o=()=>{t=!0},c=()=>{t=!1},u=()=>rh.isFocused()&&(e.networkMode==="always"||mo.isOnline())&&e.canRun(),d=()=>cy(e.networkMode)&&e.canRun(),m=g=>{i()||(r==null||r(),a.resolve(g))},p=g=>{i()||(r==null||r(),a.reject(g))},h=()=>new Promise(g=>{var b;r=y=>{(i()||u())&&g(y)},(b=e.onPause)==null||b.call(e)}).then(()=>{var g;r=void 0,i()||(g=e.onContinue)==null||g.call(e)}),f=()=>{if(i())return;let g;const b=s===0?e.initialPromise:void 0;try{g=b??e.fn()}catch(y){g=Promise.reject(y)}Promise.resolve(g).then(m).catch(y=>{var D;if(i())return;const v=e.retry??(br?0:3),x=e.retryDelay??lN,N=typeof x=="function"?x(s,y):x,k=v===!0||typeof v=="number"&&su()?void 0:h()).then(()=>{t?p(y):f()})})};return{promise:a,status:()=>a.status,cancel:l,continue:()=>(r==null||r(),a),cancelRetry:o,continueRetry:c,canStart:d,start:()=>(d()?f():h().then(f),a)}}var ar,Ap,dy=(Ap=class{constructor(){ue(this,ar)}destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),Mu(this.gcTime)&&te(this,ar,tr.setTimeout(()=>{this.optionalRemove()},this.gcTime))}updateGcTime(e){this.gcTime=Math.max(this.gcTime||0,e??(br?1/0:5*60*1e3))}clearGcTimeout(){C(this,ar)&&(tr.clearTimeout(C(this,ar)),te(this,ar,void 0))}},ar=new WeakMap,Ap),ir,ra,ls,lr,pt,Ri,or,vs,Vs,Tp,oN=(Tp=class extends dy{constructor(t){super();ue(this,vs);ue(this,ir);ue(this,ra);ue(this,ls);ue(this,lr);ue(this,pt);ue(this,Ri);ue(this,or);te(this,or,!1),te(this,Ri,t.defaultOptions),this.setOptions(t.options),this.observers=[],te(this,lr,t.client),te(this,ls,C(this,lr).getQueryCache()),this.queryKey=t.queryKey,this.queryHash=t.queryHash,te(this,ir,Ff(this.options)),this.state=t.state??C(this,ir),this.scheduleGc()}get meta(){return this.options.meta}get promise(){var t;return(t=C(this,pt))==null?void 0:t.promise}setOptions(t){if(this.options={...C(this,Ri),...t},this.updateGcTime(this.options.gcTime),this.state&&this.state.data===void 0){const s=Ff(this.options);s.data!==void 0&&(this.setState(Tf(s.data,s.dataUpdatedAt)),te(this,ir,s))}}optionalRemove(){!this.observers.length&&this.state.fetchStatus==="idle"&&C(this,ls).remove(this)}setData(t,s){const r=Ru(this.state.data,t,this.options);return ye(this,vs,Vs).call(this,{data:r,type:"success",dataUpdatedAt:s==null?void 0:s.updatedAt,manual:s==null?void 0:s.manual}),r}setState(t,s){ye(this,vs,Vs).call(this,{type:"setState",state:t,setStateOptions:s})}cancel(t){var r,a;const s=(r=C(this,pt))==null?void 0:r.promise;return(a=C(this,pt))==null||a.cancel(t),s?s.then(Rt).catch(Rt):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}reset(){this.destroy(),this.setState(C(this,ir))}isActive(){return this.observers.some(t=>os(t.options.enabled,this)!==!1)}isDisabled(){return this.getObserversCount()>0?!this.isActive():this.options.queryFn===sh||this.state.dataUpdateCount+this.state.errorUpdateCount===0}isStatic(){return this.getObserversCount()>0?this.observers.some(t=>Bn(t.options.staleTime,this)==="static"):!1}isStale(){return this.getObserversCount()>0?this.observers.some(t=>t.getCurrentResult().isStale):this.state.data===void 0||this.state.isInvalidated}isStaleByTime(t=0){return this.state.data===void 0?!0:t==="static"?!1:this.state.isInvalidated?!0:!iy(this.state.dataUpdatedAt,t)}onFocus(){var s;const t=this.observers.find(r=>r.shouldFetchOnWindowFocus());t==null||t.refetch({cancelRefetch:!1}),(s=C(this,pt))==null||s.continue()}onOnline(){var s;const t=this.observers.find(r=>r.shouldFetchOnReconnect());t==null||t.refetch({cancelRefetch:!1}),(s=C(this,pt))==null||s.continue()}addObserver(t){this.observers.includes(t)||(this.observers.push(t),this.clearGcTimeout(),C(this,ls).notify({type:"observerAdded",query:this,observer:t}))}removeObserver(t){this.observers.includes(t)&&(this.observers=this.observers.filter(s=>s!==t),this.observers.length||(C(this,pt)&&(C(this,or)?C(this,pt).cancel({revert:!0}):C(this,pt).cancelRetry()),this.scheduleGc()),C(this,ls).notify({type:"observerRemoved",query:this,observer:t}))}getObserversCount(){return this.observers.length}invalidate(){this.state.isInvalidated||ye(this,vs,Vs).call(this,{type:"invalidate"})}async fetch(t,s){var c,u,d,m,p,h,f,g,b,y,v,x;if(this.state.fetchStatus!=="idle"&&((c=C(this,pt))==null?void 0:c.status())!=="rejected"){if(this.state.data!==void 0&&(s!=null&&s.cancelRefetch))this.cancel({silent:!0});else if(C(this,pt))return C(this,pt).continueRetry(),C(this,pt).promise}if(t&&this.setOptions(t),!this.options.queryFn){const N=this.observers.find(k=>k.options.queryFn);N&&this.setOptions(N.options)}const r=new AbortController,a=N=>{Object.defineProperty(N,"signal",{enumerable:!0,get:()=>(te(this,or,!0),r.signal)})},i=()=>{const N=oy(this.options,s),D=(()=>{const F={client:C(this,lr),queryKey:this.queryKey,meta:this.meta};return a(F),F})();return te(this,or,!1),this.options.persister?this.options.persister(N,D,this):N(D)},o=(()=>{const N={fetchOptions:s,options:this.options,queryKey:this.queryKey,client:C(this,lr),state:this.state,fetchFn:i};return a(N),N})();(u=this.options.behavior)==null||u.onFetch(o,this),te(this,ra,this.state),(this.state.fetchStatus==="idle"||this.state.fetchMeta!==((d=o.fetchOptions)==null?void 0:d.meta))&&ye(this,vs,Vs).call(this,{type:"fetch",meta:(m=o.fetchOptions)==null?void 0:m.meta}),te(this,pt,uy({initialPromise:s==null?void 0:s.initialPromise,fn:o.fetchFn,onCancel:N=>{N instanceof _u&&N.revert&&this.setState({...C(this,ra),fetchStatus:"idle"}),r.abort()},onFail:(N,k)=>{ye(this,vs,Vs).call(this,{type:"failed",failureCount:N,error:k})},onPause:()=>{ye(this,vs,Vs).call(this,{type:"pause"})},onContinue:()=>{ye(this,vs,Vs).call(this,{type:"continue"})},retry:o.options.retry,retryDelay:o.options.retryDelay,networkMode:o.options.networkMode,canRun:()=>!0}));try{const N=await C(this,pt).start();if(N===void 0)throw new Error(`${this.queryHash} data is undefined`);return this.setData(N),(h=(p=C(this,ls).config).onSuccess)==null||h.call(p,N,this),(g=(f=C(this,ls).config).onSettled)==null||g.call(f,N,this.state.error,this),N}catch(N){if(N instanceof _u){if(N.silent)return C(this,pt).promise;if(N.revert){if(this.state.data===void 0)throw N;return this.state.data}}throw ye(this,vs,Vs).call(this,{type:"error",error:N}),(y=(b=C(this,ls).config).onError)==null||y.call(b,N,this),(x=(v=C(this,ls).config).onSettled)==null||x.call(v,this.state.data,N,this),N}finally{this.scheduleGc()}}},ir=new WeakMap,ra=new WeakMap,ls=new WeakMap,lr=new WeakMap,pt=new WeakMap,Ri=new WeakMap,or=new WeakMap,vs=new WeakSet,Vs=function(t){const s=r=>{switch(t.type){case"failed":return{...r,fetchFailureCount:t.failureCount,fetchFailureReason:t.error};case"pause":return{...r,fetchStatus:"paused"};case"continue":return{...r,fetchStatus:"fetching"};case"fetch":return{...r,...hy(r.data,this.options),fetchMeta:t.meta??null};case"success":const a={...r,...Tf(t.data,t.dataUpdatedAt),dataUpdateCount:r.dataUpdateCount+1,...!t.manual&&{fetchStatus:"idle",fetchFailureCount:0,fetchFailureReason:null}};return te(this,ra,t.manual?a:void 0),a;case"error":const i=t.error;return{...r,error:i,errorUpdateCount:r.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:r.fetchFailureCount+1,fetchFailureReason:i,fetchStatus:"idle",status:"error",isInvalidated:!0};case"invalidate":return{...r,isInvalidated:!0};case"setState":return{...r,...t.state}}};this.state=s(this.state),ct.batch(()=>{this.observers.forEach(r=>{r.onQueryUpdate()}),C(this,ls).notify({query:this,type:"updated",action:t})})},Tp);function hy(e,t){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:cy(t.networkMode)?"fetching":"paused",...e===void 0&&{error:null,status:"pending"}}}function Tf(e,t){return{data:e,dataUpdatedAt:t??Date.now(),error:null,isInvalidated:!1,status:"success"}}function Ff(e){const t=typeof e.initialData=="function"?e.initialData():e.initialData,s=t!==void 0,r=s?typeof e.initialDataUpdatedAt=="function"?e.initialDataUpdatedAt():e.initialDataUpdatedAt:0;return{data:t,dataUpdateCount:0,dataUpdatedAt:s?r??Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:s?"success":"pending",fetchStatus:"idle"}}var Bt,ke,Oi,Ft,cr,aa,Hs,Sn,_i,ia,la,ur,dr,kn,oa,Te,Ga,zu,Uu,$u,Bu,Ku,Vu,qu,my,Fp,cN=(Fp=class extends Pa{constructor(t,s){super();ue(this,Te);ue(this,Bt);ue(this,ke);ue(this,Oi);ue(this,Ft);ue(this,cr);ue(this,aa);ue(this,Hs);ue(this,Sn);ue(this,_i);ue(this,ia);ue(this,la);ue(this,ur);ue(this,dr);ue(this,kn);ue(this,oa,new Set);this.options=s,te(this,Bt,t),te(this,Sn,null),te(this,Hs,Ou()),this.bindMethods(),this.setOptions(s)}bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.size===1&&(C(this,ke).addObserver(this),If(C(this,ke),this.options)?ye(this,Te,Ga).call(this):this.updateResult(),ye(this,Te,Bu).call(this))}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return Qu(C(this,ke),this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return Qu(C(this,ke),this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,ye(this,Te,Ku).call(this),ye(this,Te,Vu).call(this),C(this,ke).removeObserver(this)}setOptions(t){const s=this.options,r=C(this,ke);if(this.options=C(this,Bt).defaultQueryOptions(t),this.options.enabled!==void 0&&typeof this.options.enabled!="boolean"&&typeof this.options.enabled!="function"&&typeof os(this.options.enabled,C(this,ke))!="boolean")throw new Error("Expected enabled to be a boolean or a callback that returns a boolean");ye(this,Te,qu).call(this),C(this,ke).setOptions(this.options),s._defaulted&&!ho(this.options,s)&&C(this,Bt).getQueryCache().notify({type:"observerOptionsUpdated",query:C(this,ke),observer:this});const a=this.hasListeners();a&&Mf(C(this,ke),r,this.options,s)&&ye(this,Te,Ga).call(this),this.updateResult(),a&&(C(this,ke)!==r||os(this.options.enabled,C(this,ke))!==os(s.enabled,C(this,ke))||Bn(this.options.staleTime,C(this,ke))!==Bn(s.staleTime,C(this,ke)))&&ye(this,Te,zu).call(this);const i=ye(this,Te,Uu).call(this);a&&(C(this,ke)!==r||os(this.options.enabled,C(this,ke))!==os(s.enabled,C(this,ke))||i!==C(this,kn))&&ye(this,Te,$u).call(this,i)}getOptimisticResult(t){const s=C(this,Bt).getQueryCache().build(C(this,Bt),t),r=this.createResult(s,t);return dN(this,r)&&(te(this,Ft,r),te(this,aa,this.options),te(this,cr,C(this,ke).state)),r}getCurrentResult(){return C(this,Ft)}trackResult(t,s){return new Proxy(t,{get:(r,a)=>(this.trackProp(a),s==null||s(a),a==="promise"&&(this.trackProp("data"),!this.options.experimental_prefetchInRender&&C(this,Hs).status==="pending"&&C(this,Hs).reject(new Error("experimental_prefetchInRender feature flag is not enabled"))),Reflect.get(r,a))})}trackProp(t){C(this,oa).add(t)}getCurrentQuery(){return C(this,ke)}refetch({...t}={}){return this.fetch({...t})}fetchOptimistic(t){const s=C(this,Bt).defaultQueryOptions(t),r=C(this,Bt).getQueryCache().build(C(this,Bt),s);return r.fetch().then(()=>this.createResult(r,s))}fetch(t){return ye(this,Te,Ga).call(this,{...t,cancelRefetch:t.cancelRefetch??!0}).then(()=>(this.updateResult(),C(this,Ft)))}createResult(t,s){var L;const r=C(this,ke),a=this.options,i=C(this,Ft),l=C(this,cr),o=C(this,aa),u=t!==r?t.state:C(this,Oi),{state:d}=t;let m={...d},p=!1,h;if(s._optimisticResults){const T=this.hasListeners(),_=!T&&If(t,s),K=T&&Mf(t,r,s,a);(_||K)&&(m={...m,...hy(d.data,t.options)}),s._optimisticResults==="isRestoring"&&(m.fetchStatus="idle")}let{error:f,errorUpdatedAt:g,status:b}=m;h=m.data;let y=!1;if(s.placeholderData!==void 0&&h===void 0&&b==="pending"){let T;i!=null&&i.isPlaceholderData&&s.placeholderData===(o==null?void 0:o.placeholderData)?(T=i.data,y=!0):T=typeof s.placeholderData=="function"?s.placeholderData((L=C(this,la))==null?void 0:L.state.data,C(this,la)):s.placeholderData,T!==void 0&&(b="success",h=Ru(i==null?void 0:i.data,T,s),p=!0)}if(s.select&&h!==void 0&&!y)if(i&&h===(l==null?void 0:l.data)&&s.select===C(this,_i))h=C(this,ia);else try{te(this,_i,s.select),h=s.select(h),h=Ru(i==null?void 0:i.data,h,s),te(this,ia,h),te(this,Sn,null)}catch(T){te(this,Sn,T)}C(this,Sn)&&(f=C(this,Sn),h=C(this,ia),g=Date.now(),b="error");const v=m.fetchStatus==="fetching",x=b==="pending",N=b==="error",k=x&&v,D=h!==void 0,S={status:b,fetchStatus:m.fetchStatus,isPending:x,isSuccess:b==="success",isError:N,isInitialLoading:k,isLoading:k,data:h,dataUpdatedAt:m.dataUpdatedAt,error:f,errorUpdatedAt:g,failureCount:m.fetchFailureCount,failureReason:m.fetchFailureReason,errorUpdateCount:m.errorUpdateCount,isFetched:m.dataUpdateCount>0||m.errorUpdateCount>0,isFetchedAfterMount:m.dataUpdateCount>u.dataUpdateCount||m.errorUpdateCount>u.errorUpdateCount,isFetching:v,isRefetching:v&&!x,isLoadingError:N&&!D,isPaused:m.fetchStatus==="paused",isPlaceholderData:p,isRefetchError:N&&D,isStale:ah(t,s),refetch:this.refetch,promise:C(this,Hs),isEnabled:os(s.enabled,t)!==!1};if(this.options.experimental_prefetchInRender){const T=S.data!==void 0,_=S.status==="error"&&!T,K=z=>{_?z.reject(S.error):T&&z.resolve(S.data)},W=()=>{const z=te(this,Hs,S.promise=Ou());K(z)},Q=C(this,Hs);switch(Q.status){case"pending":t.queryHash===r.queryHash&&K(Q);break;case"fulfilled":(_||S.data!==Q.value)&&W();break;case"rejected":(!_||S.error!==Q.reason)&&W();break}}return S}updateResult(){const t=C(this,Ft),s=this.createResult(C(this,ke),this.options);if(te(this,cr,C(this,ke).state),te(this,aa,this.options),C(this,cr).data!==void 0&&te(this,la,C(this,ke)),ho(s,t))return;te(this,Ft,s);const r=()=>{if(!t)return!0;const{notifyOnChangeProps:a}=this.options,i=typeof a=="function"?a():a;if(i==="all"||!i&&!C(this,oa).size)return!0;const l=new Set(i??C(this,oa));return this.options.throwOnError&&l.add("error"),Object.keys(C(this,Ft)).some(o=>{const c=o;return C(this,Ft)[c]!==t[c]&&l.has(c)})};ye(this,Te,my).call(this,{listeners:r()})}onQueryUpdate(){this.updateResult(),this.hasListeners()&&ye(this,Te,Bu).call(this)}},Bt=new WeakMap,ke=new WeakMap,Oi=new WeakMap,Ft=new WeakMap,cr=new WeakMap,aa=new WeakMap,Hs=new WeakMap,Sn=new WeakMap,_i=new WeakMap,ia=new WeakMap,la=new WeakMap,ur=new WeakMap,dr=new WeakMap,kn=new WeakMap,oa=new WeakMap,Te=new WeakSet,Ga=function(t){ye(this,Te,qu).call(this);let s=C(this,ke).fetch(this.options,t);return t!=null&&t.throwOnError||(s=s.catch(Rt)),s},zu=function(){ye(this,Te,Ku).call(this);const t=Bn(this.options.staleTime,C(this,ke));if(br||C(this,Ft).isStale||!Mu(t))return;const r=iy(C(this,Ft).dataUpdatedAt,t)+1;te(this,ur,tr.setTimeout(()=>{C(this,Ft).isStale||this.updateResult()},r))},Uu=function(){return(typeof this.options.refetchInterval=="function"?this.options.refetchInterval(C(this,ke)):this.options.refetchInterval)??!1},$u=function(t){ye(this,Te,Vu).call(this),te(this,kn,t),!(br||os(this.options.enabled,C(this,ke))===!1||!Mu(C(this,kn))||C(this,kn)===0)&&te(this,dr,tr.setInterval(()=>{(this.options.refetchIntervalInBackground||rh.isFocused())&&ye(this,Te,Ga).call(this)},C(this,kn)))},Bu=function(){ye(this,Te,zu).call(this),ye(this,Te,$u).call(this,ye(this,Te,Uu).call(this))},Ku=function(){C(this,ur)&&(tr.clearTimeout(C(this,ur)),te(this,ur,void 0))},Vu=function(){C(this,dr)&&(tr.clearInterval(C(this,dr)),te(this,dr,void 0))},qu=function(){const t=C(this,Bt).getQueryCache().build(C(this,Bt),this.options);if(t===C(this,ke))return;const s=C(this,ke);te(this,ke,t),te(this,Oi,t.state),this.hasListeners()&&(s==null||s.removeObserver(this),t.addObserver(this))},my=function(t){ct.batch(()=>{t.listeners&&this.listeners.forEach(s=>{s(C(this,Ft))}),C(this,Bt).getQueryCache().notify({query:C(this,ke),type:"observerResultsUpdated"})})},Fp);function uN(e,t){return os(t.enabled,e)!==!1&&e.state.data===void 0&&!(e.state.status==="error"&&t.retryOnMount===!1)}function If(e,t){return uN(e,t)||e.state.data!==void 0&&Qu(e,t,t.refetchOnMount)}function Qu(e,t,s){if(os(t.enabled,e)!==!1&&Bn(t.staleTime,e)!=="static"){const r=typeof s=="function"?s(e):s;return r==="always"||r!==!1&&ah(e,t)}return!1}function Mf(e,t,s,r){return(e!==t||os(r.enabled,e)===!1)&&(!s.suspense||e.state.status!=="error")&&ah(e,s)}function ah(e,t){return os(t.enabled,e)!==!1&&e.isStaleByTime(Bn(t.staleTime,e))}function dN(e,t){return!ho(e.getCurrentResult(),t)}function Lf(e){return{onFetch:(t,s)=>{var d,m,p,h,f;const r=t.options,a=(p=(m=(d=t.fetchOptions)==null?void 0:d.meta)==null?void 0:m.fetchMore)==null?void 0:p.direction,i=((h=t.state.data)==null?void 0:h.pages)||[],l=((f=t.state.data)==null?void 0:f.pageParams)||[];let o={pages:[],pageParams:[]},c=0;const u=async()=>{let g=!1;const b=x=>{sN(x,()=>t.signal,()=>g=!0)},y=oy(t.options,t.fetchOptions),v=async(x,N,k)=>{if(g)return Promise.reject();if(N==null&&x.pages.length)return Promise.resolve(x);const F=(()=>{const _={client:t.client,queryKey:t.queryKey,pageParam:N,direction:k?"backward":"forward",meta:t.options.meta};return b(_),_})(),S=await y(F),{maxPages:L}=t.options,T=k?tN:eN;return{pages:T(x.pages,S,L),pageParams:T(x.pageParams,N,L)}};if(a&&i.length){const x=a==="backward",N=x?hN:Rf,k={pages:i,pageParams:l},D=N(r,k);o=await v(k,D,x)}else{const x=e??i.length;do{const N=c===0?l[0]??r.initialPageParam:Rf(r,o);if(c>0&&N==null)break;o=await v(o,N),c++}while(c{var g,b;return(b=(g=t.options).persister)==null?void 0:b.call(g,u,{client:t.client,queryKey:t.queryKey,meta:t.options.meta,signal:t.signal},s)}:t.fetchFn=u}}}function Rf(e,{pages:t,pageParams:s}){const r=t.length-1;return t.length>0?e.getNextPageParam(t[r],t,s[r],s):void 0}function hN(e,{pages:t,pageParams:s}){var r;return t.length>0?(r=e.getPreviousPageParam)==null?void 0:r.call(e,t[0],t,s[0],s):void 0}var zi,Is,It,hr,Ms,fn,Ip,mN=(Ip=class extends dy{constructor(t){super();ue(this,Ms);ue(this,zi);ue(this,Is);ue(this,It);ue(this,hr);te(this,zi,t.client),this.mutationId=t.mutationId,te(this,It,t.mutationCache),te(this,Is,[]),this.state=t.state||fy(),this.setOptions(t.options),this.scheduleGc()}setOptions(t){this.options=t,this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(t){C(this,Is).includes(t)||(C(this,Is).push(t),this.clearGcTimeout(),C(this,It).notify({type:"observerAdded",mutation:this,observer:t}))}removeObserver(t){te(this,Is,C(this,Is).filter(s=>s!==t)),this.scheduleGc(),C(this,It).notify({type:"observerRemoved",mutation:this,observer:t})}optionalRemove(){C(this,Is).length||(this.state.status==="pending"?this.scheduleGc():C(this,It).remove(this))}continue(){var t;return((t=C(this,hr))==null?void 0:t.continue())??this.execute(this.state.variables)}async execute(t){var l,o,c,u,d,m,p,h,f,g,b,y,v,x,N,k,D,F,S,L;const s=()=>{ye(this,Ms,fn).call(this,{type:"continue"})},r={client:C(this,zi),meta:this.options.meta,mutationKey:this.options.mutationKey};te(this,hr,uy({fn:()=>this.options.mutationFn?this.options.mutationFn(t,r):Promise.reject(new Error("No mutationFn found")),onFail:(T,_)=>{ye(this,Ms,fn).call(this,{type:"failed",failureCount:T,error:_})},onPause:()=>{ye(this,Ms,fn).call(this,{type:"pause"})},onContinue:s,retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode,canRun:()=>C(this,It).canRun(this)}));const a=this.state.status==="pending",i=!C(this,hr).canStart();try{if(a)s();else{ye(this,Ms,fn).call(this,{type:"pending",variables:t,isPaused:i}),await((o=(l=C(this,It).config).onMutate)==null?void 0:o.call(l,t,this,r));const _=await((u=(c=this.options).onMutate)==null?void 0:u.call(c,t,r));_!==this.state.context&&ye(this,Ms,fn).call(this,{type:"pending",context:_,variables:t,isPaused:i})}const T=await C(this,hr).start();return await((m=(d=C(this,It).config).onSuccess)==null?void 0:m.call(d,T,t,this.state.context,this,r)),await((h=(p=this.options).onSuccess)==null?void 0:h.call(p,T,t,this.state.context,r)),await((g=(f=C(this,It).config).onSettled)==null?void 0:g.call(f,T,null,this.state.variables,this.state.context,this,r)),await((y=(b=this.options).onSettled)==null?void 0:y.call(b,T,null,t,this.state.context,r)),ye(this,Ms,fn).call(this,{type:"success",data:T}),T}catch(T){try{await((x=(v=C(this,It).config).onError)==null?void 0:x.call(v,T,t,this.state.context,this,r))}catch(_){Promise.reject(_)}try{await((k=(N=this.options).onError)==null?void 0:k.call(N,T,t,this.state.context,r))}catch(_){Promise.reject(_)}try{await((F=(D=C(this,It).config).onSettled)==null?void 0:F.call(D,void 0,T,this.state.variables,this.state.context,this,r))}catch(_){Promise.reject(_)}try{await((L=(S=this.options).onSettled)==null?void 0:L.call(S,void 0,T,t,this.state.context,r))}catch(_){Promise.reject(_)}throw ye(this,Ms,fn).call(this,{type:"error",error:T}),T}finally{C(this,It).runNext(this)}}},zi=new WeakMap,Is=new WeakMap,It=new WeakMap,hr=new WeakMap,Ms=new WeakSet,fn=function(t){const s=r=>{switch(t.type){case"failed":return{...r,failureCount:t.failureCount,failureReason:t.error};case"pause":return{...r,isPaused:!0};case"continue":return{...r,isPaused:!1};case"pending":return{...r,context:t.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:t.isPaused,status:"pending",variables:t.variables,submittedAt:Date.now()};case"success":return{...r,data:t.data,failureCount:0,failureReason:null,error:null,status:"success",isPaused:!1};case"error":return{...r,data:void 0,error:t.error,failureCount:r.failureCount+1,failureReason:t.error,isPaused:!1,status:"error"}}};this.state=s(this.state),ct.batch(()=>{C(this,Is).forEach(r=>{r.onMutationUpdate(t)}),C(this,It).notify({mutation:this,type:"updated",action:t})})},Ip);function fy(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0}}var Ws,js,Ui,Mp,fN=(Mp=class extends Pa{constructor(t={}){super();ue(this,Ws);ue(this,js);ue(this,Ui);this.config=t,te(this,Ws,new Set),te(this,js,new Map),te(this,Ui,0)}build(t,s,r){const a=new mN({client:t,mutationCache:this,mutationId:++tl(this,Ui)._,options:t.defaultMutationOptions(s),state:r});return this.add(a),a}add(t){C(this,Ws).add(t);const s=vl(t);if(typeof s=="string"){const r=C(this,js).get(s);r?r.push(t):C(this,js).set(s,[t])}this.notify({type:"added",mutation:t})}remove(t){if(C(this,Ws).delete(t)){const s=vl(t);if(typeof s=="string"){const r=C(this,js).get(s);if(r)if(r.length>1){const a=r.indexOf(t);a!==-1&&r.splice(a,1)}else r[0]===t&&C(this,js).delete(s)}}this.notify({type:"removed",mutation:t})}canRun(t){const s=vl(t);if(typeof s=="string"){const r=C(this,js).get(s),a=r==null?void 0:r.find(i=>i.state.status==="pending");return!a||a===t}else return!0}runNext(t){var r;const s=vl(t);if(typeof s=="string"){const a=(r=C(this,js).get(s))==null?void 0:r.find(i=>i!==t&&i.state.isPaused);return(a==null?void 0:a.continue())??Promise.resolve()}else return Promise.resolve()}clear(){ct.batch(()=>{C(this,Ws).forEach(t=>{this.notify({type:"removed",mutation:t})}),C(this,Ws).clear(),C(this,js).clear()})}getAll(){return Array.from(C(this,Ws))}find(t){const s={exact:!0,...t};return this.getAll().find(r=>Df(s,r))}findAll(t={}){return this.getAll().filter(s=>Df(t,s))}notify(t){ct.batch(()=>{this.listeners.forEach(s=>{s(t)})})}resumePausedMutations(){const t=this.getAll().filter(s=>s.state.isPaused);return ct.batch(()=>Promise.all(t.map(s=>s.continue().catch(Rt))))}},Ws=new WeakMap,js=new WeakMap,Ui=new WeakMap,Mp);function vl(e){var t;return(t=e.options.scope)==null?void 0:t.id}var Gs,Cn,Kt,Zs,nn,Ml,Hu,Lp,pN=(Lp=class extends Pa{constructor(s,r){super();ue(this,nn);ue(this,Gs);ue(this,Cn);ue(this,Kt);ue(this,Zs);te(this,Gs,s),this.setOptions(r),this.bindMethods(),ye(this,nn,Ml).call(this)}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(s){var a;const r=this.options;this.options=C(this,Gs).defaultMutationOptions(s),ho(this.options,r)||C(this,Gs).getMutationCache().notify({type:"observerOptionsUpdated",mutation:C(this,Kt),observer:this}),r!=null&&r.mutationKey&&this.options.mutationKey&&Nr(r.mutationKey)!==Nr(this.options.mutationKey)?this.reset():((a=C(this,Kt))==null?void 0:a.state.status)==="pending"&&C(this,Kt).setOptions(this.options)}onUnsubscribe(){var s;this.hasListeners()||(s=C(this,Kt))==null||s.removeObserver(this)}onMutationUpdate(s){ye(this,nn,Ml).call(this),ye(this,nn,Hu).call(this,s)}getCurrentResult(){return C(this,Cn)}reset(){var s;(s=C(this,Kt))==null||s.removeObserver(this),te(this,Kt,void 0),ye(this,nn,Ml).call(this),ye(this,nn,Hu).call(this)}mutate(s,r){var a;return te(this,Zs,r),(a=C(this,Kt))==null||a.removeObserver(this),te(this,Kt,C(this,Gs).getMutationCache().build(C(this,Gs),this.options)),C(this,Kt).addObserver(this),C(this,Kt).execute(s)}},Gs=new WeakMap,Cn=new WeakMap,Kt=new WeakMap,Zs=new WeakMap,nn=new WeakSet,Ml=function(){var r;const s=((r=C(this,Kt))==null?void 0:r.state)??fy();te(this,Cn,{...s,isPending:s.status==="pending",isSuccess:s.status==="success",isError:s.status==="error",isIdle:s.status==="idle",mutate:this.mutate,reset:this.reset})},Hu=function(s){ct.batch(()=>{var r,a,i,l,o,c,u,d;if(C(this,Zs)&&this.hasListeners()){const m=C(this,Cn).variables,p=C(this,Cn).context,h={client:C(this,Gs),meta:this.options.meta,mutationKey:this.options.mutationKey};if((s==null?void 0:s.type)==="success"){try{(a=(r=C(this,Zs)).onSuccess)==null||a.call(r,s.data,m,p,h)}catch(f){Promise.reject(f)}try{(l=(i=C(this,Zs)).onSettled)==null||l.call(i,s.data,null,m,p,h)}catch(f){Promise.reject(f)}}else if((s==null?void 0:s.type)==="error"){try{(c=(o=C(this,Zs)).onError)==null||c.call(o,s.error,m,p,h)}catch(f){Promise.reject(f)}try{(d=(u=C(this,Zs)).onSettled)==null||d.call(u,void 0,s.error,m,p,h)}catch(f){Promise.reject(f)}}}this.listeners.forEach(m=>{m(C(this,Cn))})})},Lp),Ls,Rp,gN=(Rp=class extends Pa{constructor(t={}){super();ue(this,Ls);this.config=t,te(this,Ls,new Map)}build(t,s,r){const a=s.queryKey,i=s.queryHash??th(a,s);let l=this.get(i);return l||(l=new oN({client:t,queryKey:a,queryHash:i,options:t.defaultQueryOptions(s),state:r,defaultOptions:t.getQueryDefaults(a)}),this.add(l)),l}add(t){C(this,Ls).has(t.queryHash)||(C(this,Ls).set(t.queryHash,t),this.notify({type:"added",query:t}))}remove(t){const s=C(this,Ls).get(t.queryHash);s&&(t.destroy(),s===t&&C(this,Ls).delete(t.queryHash),this.notify({type:"removed",query:t}))}clear(){ct.batch(()=>{this.getAll().forEach(t=>{this.remove(t)})})}get(t){return C(this,Ls).get(t)}getAll(){return[...C(this,Ls).values()]}find(t){const s={exact:!0,...t};return this.getAll().find(r=>Ef(s,r))}findAll(t={}){const s=this.getAll();return Object.keys(t).length>0?s.filter(r=>Ef(t,r)):s}notify(t){ct.batch(()=>{this.listeners.forEach(s=>{s(t)})})}onFocus(){ct.batch(()=>{this.getAll().forEach(t=>{t.onFocus()})})}onOnline(){ct.batch(()=>{this.getAll().forEach(t=>{t.onOnline()})})}},Ls=new WeakMap,Rp),Ze,En,Dn,ca,ua,Pn,da,ha,Op,xN=(Op=class{constructor(e={}){ue(this,Ze);ue(this,En);ue(this,Dn);ue(this,ca);ue(this,ua);ue(this,Pn);ue(this,da);ue(this,ha);te(this,Ze,e.queryCache||new gN),te(this,En,e.mutationCache||new fN),te(this,Dn,e.defaultOptions||{}),te(this,ca,new Map),te(this,ua,new Map),te(this,Pn,0)}mount(){tl(this,Pn)._++,C(this,Pn)===1&&(te(this,da,rh.subscribe(async e=>{e&&(await this.resumePausedMutations(),C(this,Ze).onFocus())})),te(this,ha,mo.subscribe(async e=>{e&&(await this.resumePausedMutations(),C(this,Ze).onOnline())})))}unmount(){var e,t;tl(this,Pn)._--,C(this,Pn)===0&&((e=C(this,da))==null||e.call(this),te(this,da,void 0),(t=C(this,ha))==null||t.call(this),te(this,ha,void 0))}isFetching(e){return C(this,Ze).findAll({...e,fetchStatus:"fetching"}).length}isMutating(e){return C(this,En).findAll({...e,status:"pending"}).length}getQueryData(e){var s;const t=this.defaultQueryOptions({queryKey:e});return(s=C(this,Ze).get(t.queryHash))==null?void 0:s.state.data}ensureQueryData(e){const t=this.defaultQueryOptions(e),s=C(this,Ze).build(this,t),r=s.state.data;return r===void 0?this.fetchQuery(e):(e.revalidateIfStale&&s.isStaleByTime(Bn(t.staleTime,s))&&this.prefetchQuery(t),Promise.resolve(r))}getQueriesData(e){return C(this,Ze).findAll(e).map(({queryKey:t,state:s})=>{const r=s.data;return[t,r]})}setQueryData(e,t,s){const r=this.defaultQueryOptions({queryKey:e}),a=C(this,Ze).get(r.queryHash),i=a==null?void 0:a.state.data,l=Yb(t,i);if(l!==void 0)return C(this,Ze).build(this,r).setData(l,{...s,manual:!0})}setQueriesData(e,t,s){return ct.batch(()=>C(this,Ze).findAll(e).map(({queryKey:r})=>[r,this.setQueryData(r,t,s)]))}getQueryState(e){var s;const t=this.defaultQueryOptions({queryKey:e});return(s=C(this,Ze).get(t.queryHash))==null?void 0:s.state}removeQueries(e){const t=C(this,Ze);ct.batch(()=>{t.findAll(e).forEach(s=>{t.remove(s)})})}resetQueries(e,t){const s=C(this,Ze);return ct.batch(()=>(s.findAll(e).forEach(r=>{r.reset()}),this.refetchQueries({type:"active",...e},t)))}cancelQueries(e,t={}){const s={revert:!0,...t},r=ct.batch(()=>C(this,Ze).findAll(e).map(a=>a.cancel(s)));return Promise.all(r).then(Rt).catch(Rt)}invalidateQueries(e,t={}){return ct.batch(()=>(C(this,Ze).findAll(e).forEach(s=>{s.invalidate()}),(e==null?void 0:e.refetchType)==="none"?Promise.resolve():this.refetchQueries({...e,type:(e==null?void 0:e.refetchType)??(e==null?void 0:e.type)??"active"},t)))}refetchQueries(e,t={}){const s={...t,cancelRefetch:t.cancelRefetch??!0},r=ct.batch(()=>C(this,Ze).findAll(e).filter(a=>!a.isDisabled()&&!a.isStatic()).map(a=>{let i=a.fetch(void 0,s);return s.throwOnError||(i=i.catch(Rt)),a.state.fetchStatus==="paused"?Promise.resolve():i}));return Promise.all(r).then(Rt)}fetchQuery(e){const t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);const s=C(this,Ze).build(this,t);return s.isStaleByTime(Bn(t.staleTime,s))?s.fetch(t):Promise.resolve(s.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(Rt).catch(Rt)}fetchInfiniteQuery(e){return e.behavior=Lf(e.pages),this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(Rt).catch(Rt)}ensureInfiniteQueryData(e){return e.behavior=Lf(e.pages),this.ensureQueryData(e)}resumePausedMutations(){return mo.isOnline()?C(this,En).resumePausedMutations():Promise.resolve()}getQueryCache(){return C(this,Ze)}getMutationCache(){return C(this,En)}getDefaultOptions(){return C(this,Dn)}setDefaultOptions(e){te(this,Dn,e)}setQueryDefaults(e,t){C(this,ca).set(Nr(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){const t=[...C(this,ca).values()],s={};return t.forEach(r=>{Di(e,r.queryKey)&&Object.assign(s,r.defaultOptions)}),s}setMutationDefaults(e,t){C(this,ua).set(Nr(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){const t=[...C(this,ua).values()],s={};return t.forEach(r=>{Di(e,r.mutationKey)&&Object.assign(s,r.defaultOptions)}),s}defaultQueryOptions(e){if(e._defaulted)return e;const t={...C(this,Dn).queries,...this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||(t.queryHash=th(t.queryKey,t)),t.refetchOnReconnect===void 0&&(t.refetchOnReconnect=t.networkMode!=="always"),t.throwOnError===void 0&&(t.throwOnError=!!t.suspense),!t.networkMode&&t.persister&&(t.networkMode="offlineFirst"),t.queryFn===sh&&(t.enabled=!1),t}defaultMutationOptions(e){return e!=null&&e._defaulted?e:{...C(this,Dn).mutations,...(e==null?void 0:e.mutationKey)&&this.getMutationDefaults(e.mutationKey),...e,_defaulted:!0}}clear(){C(this,Ze).clear(),C(this,En).clear()}},Ze=new WeakMap,En=new WeakMap,Dn=new WeakMap,ca=new WeakMap,ua=new WeakMap,Pn=new WeakMap,da=new WeakMap,ha=new WeakMap,Op),py=w.createContext(void 0),pe=e=>{const t=w.useContext(py);if(!t)throw new Error("No QueryClient set, use QueryClientProvider to set one");return t},yN=({client:e,children:t})=>(w.useEffect(()=>(e.mount(),()=>{e.unmount()}),[e]),n.jsx(py.Provider,{value:e,children:t})),gy=w.createContext(!1),vN=()=>w.useContext(gy);gy.Provider;function jN(){let e=!1;return{clearReset:()=>{e=!1},reset:()=>{e=!0},isReset:()=>e}}var bN=w.createContext(jN()),NN=()=>w.useContext(bN),wN=(e,t,s)=>{const r=s!=null&&s.state.error&&typeof e.throwOnError=="function"?nh(e.throwOnError,[s.state.error,s]):e.throwOnError;(e.suspense||e.experimental_prefetchInRender||r)&&(t.isReset()||(e.retryOnMount=!1))},SN=e=>{w.useEffect(()=>{e.clearReset()},[e])},kN=({result:e,errorResetBoundary:t,throwOnError:s,query:r,suspense:a})=>e.isError&&!t.isReset()&&!e.isFetching&&r&&(a&&e.data===void 0||nh(s,[e.error,r])),CN=e=>{if(e.suspense){const s=a=>a==="static"?a:Math.max(a??1e3,1e3),r=e.staleTime;e.staleTime=typeof r=="function"?(...a)=>s(r(...a)):s(r),typeof e.gcTime=="number"&&(e.gcTime=Math.max(e.gcTime,1e3))}},EN=(e,t)=>e.isLoading&&e.isFetching&&!t,DN=(e,t)=>(e==null?void 0:e.suspense)&&t.isPending,Of=(e,t,s)=>t.fetchOptimistic(e).catch(()=>{s.clearReset()});function PN(e,t,s){var p,h,f,g;const r=vN(),a=NN(),i=pe(),l=i.defaultQueryOptions(e);(h=(p=i.getDefaultOptions().queries)==null?void 0:p._experimental_beforeQuery)==null||h.call(p,l);const o=i.getQueryCache().get(l.queryHash);l._optimisticResults=r?"isRestoring":"optimistic",CN(l),wN(l,a,o),SN(a);const c=!i.getQueryCache().get(l.queryHash),[u]=w.useState(()=>new t(i,l)),d=u.getOptimisticResult(l),m=!r&&e.subscribed!==!1;if(w.useSyncExternalStore(w.useCallback(b=>{const y=m?u.subscribe(ct.batchCalls(b)):Rt;return u.updateResult(),y},[u,m]),()=>u.getCurrentResult(),()=>u.getCurrentResult()),w.useEffect(()=>{u.setOptions(l)},[l,u]),DN(l,d))throw Of(l,u,a);if(kN({result:d,errorResetBoundary:a,throwOnError:l.throwOnError,query:o,suspense:l.suspense}))throw d.error;if((g=(f=i.getDefaultOptions().queries)==null?void 0:f._experimental_afterQuery)==null||g.call(f,l,d),l.experimental_prefetchInRender&&!br&&EN(d,r)){const b=c?Of(l,u,a):o==null?void 0:o.promise;b==null||b.catch(Rt).finally(()=>{u.updateResult()})}return l.notifyOnChangeProps?d:u.trackResult(d)}function ge(e,t){return PN(e,cN)}function Y(e,t){const s=pe(),[r]=w.useState(()=>new pN(s,e));w.useEffect(()=>{r.setOptions(e)},[r,e]);const a=w.useSyncExternalStore(w.useCallback(l=>r.subscribe(ct.batchCalls(l)),[r]),()=>r.getCurrentResult(),()=>r.getCurrentResult()),i=w.useCallback((l,o)=>{r.mutate(l,o).catch(Rt)},[r]);if(a.error&&nh(r.options.throwOnError,[a.error]))throw a.error;return{...a,mutate:i,mutateAsync:a.mutate}}function xy(e,t){return function(){return e.apply(t,arguments)}}const{toString:AN}=Object.prototype,{getPrototypeOf:ih}=Object,{iterator:$o,toStringTag:yy}=Symbol,Bo=(e=>t=>{const s=AN.call(t);return e[s]||(e[s]=s.slice(8,-1).toLowerCase())})(Object.create(null)),Ds=e=>(e=e.toLowerCase(),t=>Bo(t)===e),Ko=e=>t=>typeof t===e,{isArray:Aa}=Array,ba=Ko("undefined");function Qi(e){return e!==null&&!ba(e)&&e.constructor!==null&&!ba(e.constructor)&&Zt(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const vy=Ds("ArrayBuffer");function TN(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&vy(e.buffer),t}const FN=Ko("string"),Zt=Ko("function"),jy=Ko("number"),Hi=e=>e!==null&&typeof e=="object",IN=e=>e===!0||e===!1,Ll=e=>{if(Bo(e)!=="object")return!1;const t=ih(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(yy in e)&&!($o in e)},MN=e=>{if(!Hi(e)||Qi(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},LN=Ds("Date"),RN=Ds("File"),ON=Ds("Blob"),_N=Ds("FileList"),zN=e=>Hi(e)&&Zt(e.pipe),UN=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||Zt(e.append)&&((t=Bo(e))==="formdata"||t==="object"&&Zt(e.toString)&&e.toString()==="[object FormData]"))},$N=Ds("URLSearchParams"),[BN,KN,VN,qN]=["ReadableStream","Request","Response","Headers"].map(Ds),QN=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function Wi(e,t,{allOwnKeys:s=!1}={}){if(e===null||typeof e>"u")return;let r,a;if(typeof e!="object"&&(e=[e]),Aa(e))for(r=0,a=e.length;r0;)if(a=s[r],t===a.toLowerCase())return a;return null}const sr=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,Ny=e=>!ba(e)&&e!==sr;function Wu(){const{caseless:e,skipUndefined:t}=Ny(this)&&this||{},s={},r=(a,i)=>{const l=e&&by(s,i)||i;Ll(s[l])&&Ll(a)?s[l]=Wu(s[l],a):Ll(a)?s[l]=Wu({},a):Aa(a)?s[l]=a.slice():(!t||!ba(a))&&(s[l]=a)};for(let a=0,i=arguments.length;a(Wi(t,(a,i)=>{s&&Zt(a)?e[i]=xy(a,s):e[i]=a},{allOwnKeys:r}),e),WN=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),GN=(e,t,s,r)=>{e.prototype=Object.create(t.prototype,r),e.prototype.constructor=e,Object.defineProperty(e,"super",{value:t.prototype}),s&&Object.assign(e.prototype,s)},ZN=(e,t,s,r)=>{let a,i,l;const o={};if(t=t||{},e==null)return t;do{for(a=Object.getOwnPropertyNames(e),i=a.length;i-- >0;)l=a[i],(!r||r(l,e,t))&&!o[l]&&(t[l]=e[l],o[l]=!0);e=s!==!1&&ih(e)}while(e&&(!s||s(e,t))&&e!==Object.prototype);return t},YN=(e,t,s)=>{e=String(e),(s===void 0||s>e.length)&&(s=e.length),s-=t.length;const r=e.indexOf(t,s);return r!==-1&&r===s},JN=e=>{if(!e)return null;if(Aa(e))return e;let t=e.length;if(!jy(t))return null;const s=new Array(t);for(;t-- >0;)s[t]=e[t];return s},XN=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&ih(Uint8Array)),ew=(e,t)=>{const r=(e&&e[$o]).call(e);let a;for(;(a=r.next())&&!a.done;){const i=a.value;t.call(e,i[0],i[1])}},tw=(e,t)=>{let s;const r=[];for(;(s=e.exec(t))!==null;)r.push(s);return r},sw=Ds("HTMLFormElement"),nw=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(s,r,a){return r.toUpperCase()+a}),_f=(({hasOwnProperty:e})=>(t,s)=>e.call(t,s))(Object.prototype),rw=Ds("RegExp"),wy=(e,t)=>{const s=Object.getOwnPropertyDescriptors(e),r={};Wi(s,(a,i)=>{let l;(l=t(a,i,e))!==!1&&(r[i]=l||a)}),Object.defineProperties(e,r)},aw=e=>{wy(e,(t,s)=>{if(Zt(e)&&["arguments","caller","callee"].indexOf(s)!==-1)return!1;const r=e[s];if(Zt(r)){if(t.enumerable=!1,"writable"in t){t.writable=!1;return}t.set||(t.set=()=>{throw Error("Can not rewrite read-only method '"+s+"'")})}})},iw=(e,t)=>{const s={},r=a=>{a.forEach(i=>{s[i]=!0})};return Aa(e)?r(e):r(String(e).split(t)),s},lw=()=>{},ow=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function cw(e){return!!(e&&Zt(e.append)&&e[yy]==="FormData"&&e[$o])}const uw=e=>{const t=new Array(10),s=(r,a)=>{if(Hi(r)){if(t.indexOf(r)>=0)return;if(Qi(r))return r;if(!("toJSON"in r)){t[a]=r;const i=Aa(r)?[]:{};return Wi(r,(l,o)=>{const c=s(l,a+1);!ba(c)&&(i[o]=c)}),t[a]=void 0,i}}return r};return s(e,0)},dw=Ds("AsyncFunction"),hw=e=>e&&(Hi(e)||Zt(e))&&Zt(e.then)&&Zt(e.catch),Sy=((e,t)=>e?setImmediate:t?((s,r)=>(sr.addEventListener("message",({source:a,data:i})=>{a===sr&&i===s&&r.length&&r.shift()()},!1),a=>{r.push(a),sr.postMessage(s,"*")}))(`axios@${Math.random()}`,[]):s=>setTimeout(s))(typeof setImmediate=="function",Zt(sr.postMessage)),mw=typeof queueMicrotask<"u"?queueMicrotask.bind(sr):typeof process<"u"&&process.nextTick||Sy,fw=e=>e!=null&&Zt(e[$o]),R={isArray:Aa,isArrayBuffer:vy,isBuffer:Qi,isFormData:UN,isArrayBufferView:TN,isString:FN,isNumber:jy,isBoolean:IN,isObject:Hi,isPlainObject:Ll,isEmptyObject:MN,isReadableStream:BN,isRequest:KN,isResponse:VN,isHeaders:qN,isUndefined:ba,isDate:LN,isFile:RN,isBlob:ON,isRegExp:rw,isFunction:Zt,isStream:zN,isURLSearchParams:$N,isTypedArray:XN,isFileList:_N,forEach:Wi,merge:Wu,extend:HN,trim:QN,stripBOM:WN,inherits:GN,toFlatObject:ZN,kindOf:Bo,kindOfTest:Ds,endsWith:YN,toArray:JN,forEachEntry:ew,matchAll:tw,isHTMLForm:sw,hasOwnProperty:_f,hasOwnProp:_f,reduceDescriptors:wy,freezeMethods:aw,toObjectSet:iw,toCamelCase:nw,noop:lw,toFiniteNumber:ow,findKey:by,global:sr,isContextDefined:Ny,isSpecCompliantForm:cw,toJSONObject:uw,isAsyncFn:dw,isThenable:hw,setImmediate:Sy,asap:mw,isIterable:fw};function xe(e,t,s,r,a){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=e,this.name="AxiosError",t&&(this.code=t),s&&(this.config=s),r&&(this.request=r),a&&(this.response=a,this.status=a.status?a.status:null)}R.inherits(xe,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:R.toJSONObject(this.config),code:this.code,status:this.status}}});const ky=xe.prototype,Cy={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach(e=>{Cy[e]={value:e}});Object.defineProperties(xe,Cy);Object.defineProperty(ky,"isAxiosError",{value:!0});xe.from=(e,t,s,r,a,i)=>{const l=Object.create(ky);R.toFlatObject(e,l,function(d){return d!==Error.prototype},u=>u!=="isAxiosError");const o=e&&e.message?e.message:"Error",c=t==null&&e?e.code:t;return xe.call(l,o,c,s,r,a),e&&l.cause==null&&Object.defineProperty(l,"cause",{value:e,configurable:!0}),l.name=e&&e.name||"Error",i&&Object.assign(l,i),l};const pw=null;function Gu(e){return R.isPlainObject(e)||R.isArray(e)}function Ey(e){return R.endsWith(e,"[]")?e.slice(0,-2):e}function zf(e,t,s){return e?e.concat(t).map(function(a,i){return a=Ey(a),!s&&i?"["+a+"]":a}).join(s?".":""):t}function gw(e){return R.isArray(e)&&!e.some(Gu)}const xw=R.toFlatObject(R,{},null,function(t){return/^is[A-Z]/.test(t)});function Vo(e,t,s){if(!R.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,s=R.toFlatObject(s,{metaTokens:!0,dots:!1,indexes:!1},!1,function(g,b){return!R.isUndefined(b[g])});const r=s.metaTokens,a=s.visitor||d,i=s.dots,l=s.indexes,c=(s.Blob||typeof Blob<"u"&&Blob)&&R.isSpecCompliantForm(t);if(!R.isFunction(a))throw new TypeError("visitor must be a function");function u(f){if(f===null)return"";if(R.isDate(f))return f.toISOString();if(R.isBoolean(f))return f.toString();if(!c&&R.isBlob(f))throw new xe("Blob is not supported. Use a Buffer instead.");return R.isArrayBuffer(f)||R.isTypedArray(f)?c&&typeof Blob=="function"?new Blob([f]):Buffer.from(f):f}function d(f,g,b){let y=f;if(f&&!b&&typeof f=="object"){if(R.endsWith(g,"{}"))g=r?g:g.slice(0,-2),f=JSON.stringify(f);else if(R.isArray(f)&&gw(f)||(R.isFileList(f)||R.endsWith(g,"[]"))&&(y=R.toArray(f)))return g=Ey(g),y.forEach(function(x,N){!(R.isUndefined(x)||x===null)&&t.append(l===!0?zf([g],N,i):l===null?g:g+"[]",u(x))}),!1}return Gu(f)?!0:(t.append(zf(b,g,i),u(f)),!1)}const m=[],p=Object.assign(xw,{defaultVisitor:d,convertValue:u,isVisitable:Gu});function h(f,g){if(!R.isUndefined(f)){if(m.indexOf(f)!==-1)throw Error("Circular reference detected in "+g.join("."));m.push(f),R.forEach(f,function(y,v){(!(R.isUndefined(y)||y===null)&&a.call(t,y,R.isString(v)?v.trim():v,g,p))===!0&&h(y,g?g.concat(v):[v])}),m.pop()}}if(!R.isObject(e))throw new TypeError("data must be an object");return h(e),t}function Uf(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function lh(e,t){this._pairs=[],e&&Vo(e,this,t)}const Dy=lh.prototype;Dy.append=function(t,s){this._pairs.push([t,s])};Dy.toString=function(t){const s=t?function(r){return t.call(this,r,Uf)}:Uf;return this._pairs.map(function(a){return s(a[0])+"="+s(a[1])},"").join("&")};function yw(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function Py(e,t,s){if(!t)return e;const r=s&&s.encode||yw;R.isFunction(s)&&(s={serialize:s});const a=s&&s.serialize;let i;if(a?i=a(t,s):i=R.isURLSearchParams(t)?t.toString():new lh(t,s).toString(r),i){const l=e.indexOf("#");l!==-1&&(e=e.slice(0,l)),e+=(e.indexOf("?")===-1?"?":"&")+i}return e}class $f{constructor(){this.handlers=[]}use(t,s,r){return this.handlers.push({fulfilled:t,rejected:s,synchronous:r?r.synchronous:!1,runWhen:r?r.runWhen:null}),this.handlers.length-1}eject(t){this.handlers[t]&&(this.handlers[t]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(t){R.forEach(this.handlers,function(r){r!==null&&t(r)})}}const Ay={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},vw=typeof URLSearchParams<"u"?URLSearchParams:lh,jw=typeof FormData<"u"?FormData:null,bw=typeof Blob<"u"?Blob:null,Nw={isBrowser:!0,classes:{URLSearchParams:vw,FormData:jw,Blob:bw},protocols:["http","https","file","blob","url","data"]},oh=typeof window<"u"&&typeof document<"u",Zu=typeof navigator=="object"&&navigator||void 0,ww=oh&&(!Zu||["ReactNative","NativeScript","NS"].indexOf(Zu.product)<0),Sw=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",kw=oh&&window.location.href||"http://localhost",Cw=Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:oh,hasStandardBrowserEnv:ww,hasStandardBrowserWebWorkerEnv:Sw,navigator:Zu,origin:kw},Symbol.toStringTag,{value:"Module"})),Dt={...Cw,...Nw};function Ew(e,t){return Vo(e,new Dt.classes.URLSearchParams,{visitor:function(s,r,a,i){return Dt.isNode&&R.isBuffer(s)?(this.append(r,s.toString("base64")),!1):i.defaultVisitor.apply(this,arguments)},...t})}function Dw(e){return R.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Pw(e){const t={},s=Object.keys(e);let r;const a=s.length;let i;for(r=0;r=s.length;return l=!l&&R.isArray(a)?a.length:l,c?(R.hasOwnProp(a,l)?a[l]=[a[l],r]:a[l]=r,!o):((!a[l]||!R.isObject(a[l]))&&(a[l]=[]),t(s,r,a[l],i)&&R.isArray(a[l])&&(a[l]=Pw(a[l])),!o)}if(R.isFormData(e)&&R.isFunction(e.entries)){const s={};return R.forEachEntry(e,(r,a)=>{t(Dw(r),a,s,0)}),s}return null}function Aw(e,t,s){if(R.isString(e))try{return(t||JSON.parse)(e),R.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(s||JSON.stringify)(e)}const Gi={transitional:Ay,adapter:["xhr","http","fetch"],transformRequest:[function(t,s){const r=s.getContentType()||"",a=r.indexOf("application/json")>-1,i=R.isObject(t);if(i&&R.isHTMLForm(t)&&(t=new FormData(t)),R.isFormData(t))return a?JSON.stringify(Ty(t)):t;if(R.isArrayBuffer(t)||R.isBuffer(t)||R.isStream(t)||R.isFile(t)||R.isBlob(t)||R.isReadableStream(t))return t;if(R.isArrayBufferView(t))return t.buffer;if(R.isURLSearchParams(t))return s.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),t.toString();let o;if(i){if(r.indexOf("application/x-www-form-urlencoded")>-1)return Ew(t,this.formSerializer).toString();if((o=R.isFileList(t))||r.indexOf("multipart/form-data")>-1){const c=this.env&&this.env.FormData;return Vo(o?{"files[]":t}:t,c&&new c,this.formSerializer)}}return i||a?(s.setContentType("application/json",!1),Aw(t)):t}],transformResponse:[function(t){const s=this.transitional||Gi.transitional,r=s&&s.forcedJSONParsing,a=this.responseType==="json";if(R.isResponse(t)||R.isReadableStream(t))return t;if(t&&R.isString(t)&&(r&&!this.responseType||a)){const l=!(s&&s.silentJSONParsing)&&a;try{return JSON.parse(t,this.parseReviver)}catch(o){if(l)throw o.name==="SyntaxError"?xe.from(o,xe.ERR_BAD_RESPONSE,this,null,this.response):o}}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:Dt.classes.FormData,Blob:Dt.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};R.forEach(["delete","get","head","post","put","patch"],e=>{Gi.headers[e]={}});const Tw=R.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),Fw=e=>{const t={};let s,r,a;return e&&e.split(` `).forEach(function(l){a=l.indexOf(":"),s=l.substring(0,a).trim().toLowerCase(),r=l.substring(a+1).trim(),!(!s||t[s]&&Tw[s])&&(s==="set-cookie"?t[s]?t[s].push(r):t[s]=[r]:t[s]=t[s]?t[s]+", "+r:r)}),t},Bf=Symbol("internals");function Ka(e){return e&&String(e).trim().toLowerCase()}function Rl(e){return e===!1||e==null?e:R.isArray(e)?e.map(Rl):String(e)}function Iw(e){const t=Object.create(null),s=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let r;for(;r=s.exec(e);)t[r[1]]=r[2];return t}const Mw=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function Ec(e,t,s,r,a){if(R.isFunction(r))return r.call(this,t,s);if(a&&(t=s),!!R.isString(t)){if(R.isString(r))return t.indexOf(r)!==-1;if(R.isRegExp(r))return r.test(t)}}function Lw(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,s,r)=>s.toUpperCase()+r)}function Rw(e,t){const s=R.toCamelCase(" "+t);["get","set","has"].forEach(r=>{Object.defineProperty(e,r+s,{value:function(a,i,l){return this[r].call(this,t,a,i,l)},configurable:!0})})}let Yt=class{constructor(t){t&&this.set(t)}set(t,s,r){const a=this;function i(o,c,u){const d=Ka(c);if(!d)throw new Error("header name must be a non-empty string");const m=R.findKey(a,d);(!m||a[m]===void 0||u===!0||u===void 0&&a[m]!==!1)&&(a[m||c]=Rl(o))}const l=(o,c)=>R.forEach(o,(u,d)=>i(u,d,c));if(R.isPlainObject(t)||t instanceof this.constructor)l(t,s);else if(R.isString(t)&&(t=t.trim())&&!Mw(t))l(Fw(t),s);else if(R.isObject(t)&&R.isIterable(t)){let o={},c,u;for(const d of t){if(!R.isArray(d))throw TypeError("Object iterator must return a key-value pair");o[u=d[0]]=(c=o[u])?R.isArray(c)?[...c,d[1]]:[c,d[1]]:d[1]}l(o,s)}else t!=null&&i(s,t,r);return this}get(t,s){if(t=Ka(t),t){const r=R.findKey(this,t);if(r){const a=this[r];if(!s)return a;if(s===!0)return Iw(a);if(R.isFunction(s))return s.call(this,a,r);if(R.isRegExp(s))return s.exec(a);throw new TypeError("parser must be boolean|regexp|function")}}}has(t,s){if(t=Ka(t),t){const r=R.findKey(this,t);return!!(r&&this[r]!==void 0&&(!s||Ec(this,this[r],r,s)))}return!1}delete(t,s){const r=this;let a=!1;function i(l){if(l=Ka(l),l){const o=R.findKey(r,l);o&&(!s||Ec(r,r[o],o,s))&&(delete r[o],a=!0)}}return R.isArray(t)?t.forEach(i):i(t),a}clear(t){const s=Object.keys(this);let r=s.length,a=!1;for(;r--;){const i=s[r];(!t||Ec(this,this[i],i,t,!0))&&(delete this[i],a=!0)}return a}normalize(t){const s=this,r={};return R.forEach(this,(a,i)=>{const l=R.findKey(r,i);if(l){s[l]=Rl(a),delete s[i];return}const o=t?Lw(i):String(i).trim();o!==i&&delete s[i],s[o]=Rl(a),r[o]=!0}),this}concat(...t){return this.constructor.concat(this,...t)}toJSON(t){const s=Object.create(null);return R.forEach(this,(r,a)=>{r!=null&&r!==!1&&(s[a]=t&&R.isArray(r)?r.join(", "):r)}),s}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map(([t,s])=>t+": "+s).join(` `)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...s){const r=new this(t);return s.forEach(a=>r.set(a)),r}static accessor(t){const r=(this[Bf]=this[Bf]={accessors:{}}).accessors,a=this.prototype;function i(l){const o=Ka(l);r[o]||(Rw(a,l),r[o]=!0)}return R.isArray(t)?t.forEach(i):i(t),this}};Yt.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]);R.reduceDescriptors(Yt.prototype,({value:e},t)=>{let s=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[s]=r}}});R.freezeMethods(Yt);function Dc(e,t){const s=this||Gi,r=t||s,a=Yt.from(r.headers);let i=r.data;return R.forEach(e,function(o){i=o.call(s,i,a.normalize(),t?t.status:void 0)}),a.normalize(),i}function Fy(e){return!!(e&&e.__CANCEL__)}function Ta(e,t,s){xe.call(this,e??"canceled",xe.ERR_CANCELED,t,s),this.name="CanceledError"}R.inherits(Ta,xe,{__CANCEL__:!0});function Iy(e,t,s){const r=s.config.validateStatus;!s.status||!r||r(s.status)?e(s):t(new xe("Request failed with status code "+s.status,[xe.ERR_BAD_REQUEST,xe.ERR_BAD_RESPONSE][Math.floor(s.status/100)-4],s.config,s.request,s))}function Ow(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function _w(e,t){e=e||10;const s=new Array(e),r=new Array(e);let a=0,i=0,l;return t=t!==void 0?t:1e3,function(c){const u=Date.now(),d=r[i];l||(l=u),s[a]=c,r[a]=u;let m=i,p=0;for(;m!==a;)p+=s[m++],m=m%e;if(a=(a+1)%e,a===i&&(i=(i+1)%e),u-l{s=d,a=null,i&&(clearTimeout(i),i=null),e(...u)};return[(...u)=>{const d=Date.now(),m=d-s;m>=r?l(u,d):(a=u,i||(i=setTimeout(()=>{i=null,l(a)},r-m)))},()=>a&&l(a)]}const fo=(e,t,s=3)=>{let r=0;const a=_w(50,250);return zw(i=>{const l=i.loaded,o=i.lengthComputable?i.total:void 0,c=l-r,u=a(c),d=l<=o;r=l;const m={loaded:l,total:o,progress:o?l/o:void 0,bytes:c,rate:u||void 0,estimated:u&&o&&d?(o-l)/u:void 0,event:i,lengthComputable:o!=null,[t?"download":"upload"]:!0};e(m)},s)},Kf=(e,t)=>{const s=e!=null;return[r=>t[0]({lengthComputable:s,total:e,loaded:r}),t[1]]},Vf=e=>(...t)=>R.asap(()=>e(...t)),Uw=Dt.hasStandardBrowserEnv?((e,t)=>s=>(s=new URL(s,Dt.origin),e.protocol===s.protocol&&e.host===s.host&&(t||e.port===s.port)))(new URL(Dt.origin),Dt.navigator&&/(msie|trident)/i.test(Dt.navigator.userAgent)):()=>!0,$w=Dt.hasStandardBrowserEnv?{write(e,t,s,r,a,i,l){if(typeof document>"u")return;const o=[`${e}=${encodeURIComponent(t)}`];R.isNumber(s)&&o.push(`expires=${new Date(s).toUTCString()}`),R.isString(r)&&o.push(`path=${r}`),R.isString(a)&&o.push(`domain=${a}`),i===!0&&o.push("secure"),R.isString(l)&&o.push(`SameSite=${l}`),document.cookie=o.join("; ")},read(e){if(typeof document>"u")return null;const t=document.cookie.match(new RegExp("(?:^|; )"+e+"=([^;]*)"));return t?decodeURIComponent(t[1]):null},remove(e){this.write(e,"",Date.now()-864e5,"/")}}:{write(){},read(){return null},remove(){}};function Bw(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function Kw(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function My(e,t,s){let r=!Bw(t);return e&&(r||s==!1)?Kw(e,t):t}const qf=e=>e instanceof Yt?{...e}:e;function wr(e,t){t=t||{};const s={};function r(u,d,m,p){return R.isPlainObject(u)&&R.isPlainObject(d)?R.merge.call({caseless:p},u,d):R.isPlainObject(d)?R.merge({},d):R.isArray(d)?d.slice():d}function a(u,d,m,p){if(R.isUndefined(d)){if(!R.isUndefined(u))return r(void 0,u,m,p)}else return r(u,d,m,p)}function i(u,d){if(!R.isUndefined(d))return r(void 0,d)}function l(u,d){if(R.isUndefined(d)){if(!R.isUndefined(u))return r(void 0,u)}else return r(void 0,d)}function o(u,d,m){if(m in t)return r(u,d);if(m in e)return r(void 0,u)}const c={url:i,method:i,data:i,baseURL:l,transformRequest:l,transformResponse:l,paramsSerializer:l,timeout:l,timeoutMessage:l,withCredentials:l,withXSRFToken:l,adapter:l,responseType:l,xsrfCookieName:l,xsrfHeaderName:l,onUploadProgress:l,onDownloadProgress:l,decompress:l,maxContentLength:l,maxBodyLength:l,beforeRedirect:l,transport:l,httpAgent:l,httpsAgent:l,cancelToken:l,socketPath:l,responseEncoding:l,validateStatus:o,headers:(u,d,m)=>a(qf(u),qf(d),m,!0)};return R.forEach(Object.keys({...e,...t}),function(d){const m=c[d]||a,p=m(e[d],t[d],d);R.isUndefined(p)&&m!==o||(s[d]=p)}),s}const Ly=e=>{const t=wr({},e);let{data:s,withXSRFToken:r,xsrfHeaderName:a,xsrfCookieName:i,headers:l,auth:o}=t;if(t.headers=l=Yt.from(l),t.url=Py(My(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),o&&l.set("Authorization","Basic "+btoa((o.username||"")+":"+(o.password?unescape(encodeURIComponent(o.password)):""))),R.isFormData(s)){if(Dt.hasStandardBrowserEnv||Dt.hasStandardBrowserWebWorkerEnv)l.setContentType(void 0);else if(R.isFunction(s.getHeaders)){const c=s.getHeaders(),u=["content-type","content-length"];Object.entries(c).forEach(([d,m])=>{u.includes(d.toLowerCase())&&l.set(d,m)})}}if(Dt.hasStandardBrowserEnv&&(r&&R.isFunction(r)&&(r=r(t)),r||r!==!1&&Uw(t.url))){const c=a&&i&&$w.read(i);c&&l.set(a,c)}return t},Vw=typeof XMLHttpRequest<"u",qw=Vw&&function(e){return new Promise(function(s,r){const a=Ly(e);let i=a.data;const l=Yt.from(a.headers).normalize();let{responseType:o,onUploadProgress:c,onDownloadProgress:u}=a,d,m,p,h,f;function g(){h&&h(),f&&f(),a.cancelToken&&a.cancelToken.unsubscribe(d),a.signal&&a.signal.removeEventListener("abort",d)}let b=new XMLHttpRequest;b.open(a.method.toUpperCase(),a.url,!0),b.timeout=a.timeout;function y(){if(!b)return;const x=Yt.from("getAllResponseHeaders"in b&&b.getAllResponseHeaders()),k={data:!o||o==="text"||o==="json"?b.responseText:b.response,status:b.status,statusText:b.statusText,headers:x,config:e,request:b};Iy(function(F){s(F),g()},function(F){r(F),g()},k),b=null}"onloadend"in b?b.onloadend=y:b.onreadystatechange=function(){!b||b.readyState!==4||b.status===0&&!(b.responseURL&&b.responseURL.indexOf("file:")===0)||setTimeout(y)},b.onabort=function(){b&&(r(new xe("Request aborted",xe.ECONNABORTED,e,b)),b=null)},b.onerror=function(N){const k=N&&N.message?N.message:"Network Error",D=new xe(k,xe.ERR_NETWORK,e,b);D.event=N||null,r(D),b=null},b.ontimeout=function(){let N=a.timeout?"timeout of "+a.timeout+"ms exceeded":"timeout exceeded";const k=a.transitional||Ay;a.timeoutErrorMessage&&(N=a.timeoutErrorMessage),r(new xe(N,k.clarifyTimeoutError?xe.ETIMEDOUT:xe.ECONNABORTED,e,b)),b=null},i===void 0&&l.setContentType(null),"setRequestHeader"in b&&R.forEach(l.toJSON(),function(N,k){b.setRequestHeader(k,N)}),R.isUndefined(a.withCredentials)||(b.withCredentials=!!a.withCredentials),o&&o!=="json"&&(b.responseType=a.responseType),u&&([p,f]=fo(u,!0),b.addEventListener("progress",p)),c&&b.upload&&([m,h]=fo(c),b.upload.addEventListener("progress",m),b.upload.addEventListener("loadend",h)),(a.cancelToken||a.signal)&&(d=x=>{b&&(r(!x||x.type?new Ta(null,e,b):x),b.abort(),b=null)},a.cancelToken&&a.cancelToken.subscribe(d),a.signal&&(a.signal.aborted?d():a.signal.addEventListener("abort",d)));const v=Ow(a.url);if(v&&Dt.protocols.indexOf(v)===-1){r(new xe("Unsupported protocol "+v+":",xe.ERR_BAD_REQUEST,e));return}b.send(i||null)})},Qw=(e,t)=>{const{length:s}=e=e?e.filter(Boolean):[];if(t||s){let r=new AbortController,a;const i=function(u){if(!a){a=!0,o();const d=u instanceof Error?u:this.reason;r.abort(d instanceof xe?d:new Ta(d instanceof Error?d.message:d))}};let l=t&&setTimeout(()=>{l=null,i(new xe(`timeout ${t} of ms exceeded`,xe.ETIMEDOUT))},t);const o=()=>{e&&(l&&clearTimeout(l),l=null,e.forEach(u=>{u.unsubscribe?u.unsubscribe(i):u.removeEventListener("abort",i)}),e=null)};e.forEach(u=>u.addEventListener("abort",i));const{signal:c}=r;return c.unsubscribe=()=>R.asap(o),c}},Hw=function*(e,t){let s=e.byteLength;if(s{const a=Ww(e,t);let i=0,l,o=c=>{l||(l=!0,r&&r(c))};return new ReadableStream({async pull(c){try{const{done:u,value:d}=await a.next();if(u){o(),c.close();return}let m=d.byteLength;if(s){let p=i+=m;s(p)}c.enqueue(new Uint8Array(d))}catch(u){throw o(u),u}},cancel(c){return o(c),a.return()}},{highWaterMark:2})},Hf=64*1024,{isFunction:jl}=R,Zw=(({Request:e,Response:t})=>({Request:e,Response:t}))(R.global),{ReadableStream:Wf,TextEncoder:Gf}=R.global,Zf=(e,...t)=>{try{return!!e(...t)}catch{return!1}},Yw=e=>{e=R.merge.call({skipUndefined:!0},Zw,e);const{fetch:t,Request:s,Response:r}=e,a=t?jl(t):typeof fetch=="function",i=jl(s),l=jl(r);if(!a)return!1;const o=a&&jl(Wf),c=a&&(typeof Gf=="function"?(f=>g=>f.encode(g))(new Gf):async f=>new Uint8Array(await new s(f).arrayBuffer())),u=i&&o&&Zf(()=>{let f=!1;const g=new s(Dt.origin,{body:new Wf,method:"POST",get duplex(){return f=!0,"half"}}).headers.has("Content-Type");return f&&!g}),d=l&&o&&Zf(()=>R.isReadableStream(new r("").body)),m={stream:d&&(f=>f.body)};a&&["text","arrayBuffer","blob","formData","stream"].forEach(f=>{!m[f]&&(m[f]=(g,b)=>{let y=g&&g[f];if(y)return y.call(g);throw new xe(`Response type '${f}' is not supported`,xe.ERR_NOT_SUPPORT,b)})});const p=async f=>{if(f==null)return 0;if(R.isBlob(f))return f.size;if(R.isSpecCompliantForm(f))return(await new s(Dt.origin,{method:"POST",body:f}).arrayBuffer()).byteLength;if(R.isArrayBufferView(f)||R.isArrayBuffer(f))return f.byteLength;if(R.isURLSearchParams(f)&&(f=f+""),R.isString(f))return(await c(f)).byteLength},h=async(f,g)=>{const b=R.toFiniteNumber(f.getContentLength());return b??p(g)};return async f=>{let{url:g,method:b,data:y,signal:v,cancelToken:x,timeout:N,onDownloadProgress:k,onUploadProgress:D,responseType:F,headers:S,withCredentials:L="same-origin",fetchOptions:T}=Ly(f),_=t||fetch;F=F?(F+"").toLowerCase():"text";let K=Qw([v,x&&x.toAbortSignal()],N),W=null;const Q=K&&K.unsubscribe&&(()=>{K.unsubscribe()});let z;try{if(D&&u&&b!=="get"&&b!=="head"&&(z=await h(S,y))!==0){let me=new s(g,{method:"POST",body:y,duplex:"half"}),ve;if(R.isFormData(y)&&(ve=me.headers.get("content-type"))&&S.setContentType(ve),me.body){const[it,V]=Kf(z,fo(Vf(D)));y=Qf(me.body,Hf,it,V)}}R.isString(L)||(L=L?"include":"omit");const P=i&&"credentials"in s.prototype,j={...T,signal:K,method:b.toUpperCase(),headers:S.normalize().toJSON(),body:y,duplex:"half",credentials:P?L:void 0};W=i&&new s(g,j);let B=await(i?_(W,T):_(g,j));const J=d&&(F==="stream"||F==="response");if(d&&(k||J&&Q)){const me={};["status","statusText","headers"].forEach(Ce=>{me[Ce]=B[Ce]});const ve=R.toFiniteNumber(B.headers.get("content-length")),[it,V]=k&&Kf(ve,fo(Vf(k),!0))||[];B=new r(Qf(B.body,Hf,it,()=>{V&&V(),Q&&Q()}),me)}F=F||"text";let ee=await m[R.findKey(m,F)||"text"](B,f);return!J&&Q&&Q(),await new Promise((me,ve)=>{Iy(me,ve,{data:ee,headers:Yt.from(B.headers),status:B.status,statusText:B.statusText,config:f,request:W})})}catch(P){throw Q&&Q(),P&&P.name==="TypeError"&&/Load failed|fetch/i.test(P.message)?Object.assign(new xe("Network Error",xe.ERR_NETWORK,f,W),{cause:P.cause||P}):xe.from(P,P&&P.code,f,W)}}},Jw=new Map,Ry=e=>{let t=e&&e.env||{};const{fetch:s,Request:r,Response:a}=t,i=[r,a,s];let l=i.length,o=l,c,u,d=Jw;for(;o--;)c=i[o],u=d.get(c),u===void 0&&d.set(c,u=o?new Map:Yw(t)),d=u;return u};Ry();const ch={http:pw,xhr:qw,fetch:{get:Ry}};R.forEach(ch,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Yf=e=>`- ${e}`,Xw=e=>R.isFunction(e)||e===null||e===!1;function e1(e,t){e=R.isArray(e)?e:[e];const{length:s}=e;let r,a;const i={};for(let l=0;l`adapter ${c} `+(u===!1?"is not supported by the environment":"is not available in the build"));let o=s?l.length>1?`since : `+l.map(Yf).join(` `):" "+Yf(l[0]):"as no adapter specified";throw new xe("There is no suitable adapter to dispatch the request "+o,"ERR_NOT_SUPPORT")}return a}const Oy={getAdapter:e1,adapters:ch};function Pc(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new Ta(null,e)}function Jf(e){return Pc(e),e.headers=Yt.from(e.headers),e.data=Dc.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),Oy.getAdapter(e.adapter||Gi.adapter,e)(e).then(function(r){return Pc(e),r.data=Dc.call(e,e.transformResponse,r),r.headers=Yt.from(r.headers),r},function(r){return Fy(r)||(Pc(e),r&&r.response&&(r.response.data=Dc.call(e,e.transformResponse,r.response),r.response.headers=Yt.from(r.response.headers))),Promise.reject(r)})}const _y="1.13.2",qo={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{qo[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const Xf={};qo.transitional=function(t,s,r){function a(i,l){return"[Axios v"+_y+"] Transitional option '"+i+"'"+l+(r?". "+r:"")}return(i,l,o)=>{if(t===!1)throw new xe(a(l," has been removed"+(s?" in "+s:"")),xe.ERR_DEPRECATED);return s&&!Xf[l]&&(Xf[l]=!0,console.warn(a(l," has been deprecated since v"+s+" and will be removed in the near future"))),t?t(i,l,o):!0}};qo.spelling=function(t){return(s,r)=>(console.warn(`${r} is likely a misspelling of ${t}`),!0)};function t1(e,t,s){if(typeof e!="object")throw new xe("options must be an object",xe.ERR_BAD_OPTION_VALUE);const r=Object.keys(e);let a=r.length;for(;a-- >0;){const i=r[a],l=t[i];if(l){const o=e[i],c=o===void 0||l(o,i,e);if(c!==!0)throw new xe("option "+i+" must be "+c,xe.ERR_BAD_OPTION_VALUE);continue}if(s!==!0)throw new xe("Unknown option "+i,xe.ERR_BAD_OPTION)}}const Ol={assertOptions:t1,validators:qo},As=Ol.validators;let pr=class{constructor(t){this.defaults=t||{},this.interceptors={request:new $f,response:new $f}}async request(t,s){try{return await this._request(t,s)}catch(r){if(r instanceof Error){let a={};Error.captureStackTrace?Error.captureStackTrace(a):a=new Error;const i=a.stack?a.stack.replace(/^.+\n/,""):"";try{r.stack?i&&!String(r.stack).endsWith(i.replace(/^.+\n.+\n/,""))&&(r.stack+=` `+i):r.stack=i}catch{}}throw r}}_request(t,s){typeof t=="string"?(s=s||{},s.url=t):s=t||{},s=wr(this.defaults,s);const{transitional:r,paramsSerializer:a,headers:i}=s;r!==void 0&&Ol.assertOptions(r,{silentJSONParsing:As.transitional(As.boolean),forcedJSONParsing:As.transitional(As.boolean),clarifyTimeoutError:As.transitional(As.boolean)},!1),a!=null&&(R.isFunction(a)?s.paramsSerializer={serialize:a}:Ol.assertOptions(a,{encode:As.function,serialize:As.function},!0)),s.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?s.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:s.allowAbsoluteUrls=!0),Ol.assertOptions(s,{baseUrl:As.spelling("baseURL"),withXsrfToken:As.spelling("withXSRFToken")},!0),s.method=(s.method||this.defaults.method||"get").toLowerCase();let l=i&&R.merge(i.common,i[s.method]);i&&R.forEach(["delete","get","head","post","put","patch","common"],f=>{delete i[f]}),s.headers=Yt.concat(l,i);const o=[];let c=!0;this.interceptors.request.forEach(function(g){typeof g.runWhen=="function"&&g.runWhen(s)===!1||(c=c&&g.synchronous,o.unshift(g.fulfilled,g.rejected))});const u=[];this.interceptors.response.forEach(function(g){u.push(g.fulfilled,g.rejected)});let d,m=0,p;if(!c){const f=[Jf.bind(this),void 0];for(f.unshift(...o),f.push(...u),p=f.length,d=Promise.resolve(s);m{if(!r._listeners)return;let i=r._listeners.length;for(;i-- >0;)r._listeners[i](a);r._listeners=null}),this.promise.then=a=>{let i;const l=new Promise(o=>{r.subscribe(o),i=o}).then(a);return l.cancel=function(){r.unsubscribe(i)},l},t(function(i,l,o){r.reason||(r.reason=new Ta(i,l,o),s(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const s=this._listeners.indexOf(t);s!==-1&&this._listeners.splice(s,1)}toAbortSignal(){const t=new AbortController,s=r=>{t.abort(r)};return this.subscribe(s),t.signal.unsubscribe=()=>this.unsubscribe(s),t.signal}static source(){let t;return{token:new zy(function(a){t=a}),cancel:t}}};function n1(e){return function(s){return e.apply(null,s)}}function r1(e){return R.isObject(e)&&e.isAxiosError===!0}const Yu={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511,WebServerIsDown:521,ConnectionTimedOut:522,OriginIsUnreachable:523,TimeoutOccurred:524,SslHandshakeFailed:525,InvalidSslCertificate:526};Object.entries(Yu).forEach(([e,t])=>{Yu[t]=e});function Uy(e){const t=new pr(e),s=xy(pr.prototype.request,t);return R.extend(s,pr.prototype,t,{allOwnKeys:!0}),R.extend(s,t,null,{allOwnKeys:!0}),s.create=function(a){return Uy(wr(e,a))},s}const tt=Uy(Gi);tt.Axios=pr;tt.CanceledError=Ta;tt.CancelToken=s1;tt.isCancel=Fy;tt.VERSION=_y;tt.toFormData=Vo;tt.AxiosError=xe;tt.Cancel=tt.CanceledError;tt.all=function(t){return Promise.all(t)};tt.spread=n1;tt.isAxiosError=r1;tt.mergeConfig=wr;tt.AxiosHeaders=Yt;tt.formToJSON=e=>Ty(R.isHTMLForm(e)?new FormData(e):e);tt.getAdapter=Oy.getAdapter;tt.HttpStatusCode=Yu;tt.default=tt;const{Axios:S2,AxiosError:k2,CanceledError:C2,isCancel:E2,CancelToken:D2,VERSION:P2,all:A2,Cancel:T2,isAxiosError:F2,spread:I2,toFormData:M2,AxiosHeaders:L2,HttpStatusCode:R2,formToJSON:O2,getAdapter:_2,mergeConfig:z2}=tt,O=tt.create({baseURL:"/api",headers:{"Content-Type":"application/json"}});O.interceptors.request.use(e=>{const t=localStorage.getItem("token");return t&&(e.headers.Authorization=`Bearer ${t}`),e});O.interceptors.response.use(e=>e,e=>{var a,i,l,o,c,u,d;const t=((i=(a=e.config)==null?void 0:a.url)==null?void 0:i.includes("/auth/login"))||((o=(l=e.config)==null?void 0:l.url)==null?void 0:o.includes("/auth/customer-login"));((c=e.response)==null?void 0:c.status)===401&&!t&&(localStorage.removeItem("token"),localStorage.removeItem("user"),window.location.href="/login");const s=((d=(u=e.response)==null?void 0:u.data)==null?void 0:d.error)||e.message||"Ein Fehler ist aufgetreten",r=new Error(s);return Promise.reject(r)});const bl={login:async(e,t)=>(await O.post("/auth/login",{email:e,password:t})).data,customerLogin:async(e,t)=>(await O.post("/auth/customer-login",{email:e,password:t})).data,me:async()=>(await O.get("/auth/me")).data},yt={getAll:async e=>(await O.get("/customers",{params:e})).data,getById:async e=>(await O.get(`/customers/${e}`)).data,create:async e=>(await O.post("/customers",e)).data,update:async(e,t)=>(await O.put(`/customers/${e}`,t)).data,delete:async e=>(await O.delete(`/customers/${e}`)).data,getPortalSettings:async e=>(await O.get(`/customers/${e}/portal`)).data,updatePortalSettings:async(e,t)=>(await O.put(`/customers/${e}/portal`,t)).data,setPortalPassword:async(e,t)=>(await O.post(`/customers/${e}/portal/password`,{password:t})).data,getPortalPassword:async e=>(await O.get(`/customers/${e}/portal/password`)).data,getRepresentatives:async e=>(await O.get(`/customers/${e}/representatives`)).data,addRepresentative:async(e,t,s)=>(await O.post(`/customers/${e}/representatives`,{representativeId:t,notes:s})).data,removeRepresentative:async(e,t)=>(await O.delete(`/customers/${e}/representatives/${t}`)).data,searchForRepresentative:async(e,t)=>(await O.get(`/customers/${e}/representatives/search`,{params:{search:t}})).data},Ju={getByCustomer:async e=>(await O.get(`/customers/${e}/addresses`)).data,create:async(e,t)=>(await O.post(`/customers/${e}/addresses`,t)).data,update:async(e,t)=>(await O.put(`/addresses/${e}`,t)).data,delete:async e=>(await O.delete(`/addresses/${e}`)).data},po={getByCustomer:async(e,t=!1)=>(await O.get(`/customers/${e}/bank-cards`,{params:{showInactive:t}})).data,create:async(e,t)=>(await O.post(`/customers/${e}/bank-cards`,t)).data,update:async(e,t)=>(await O.put(`/bank-cards/${e}`,t)).data,delete:async e=>(await O.delete(`/bank-cards/${e}`)).data},go={getByCustomer:async(e,t=!1)=>(await O.get(`/customers/${e}/documents`,{params:{showInactive:t}})).data,create:async(e,t)=>(await O.post(`/customers/${e}/documents`,t)).data,update:async(e,t)=>(await O.put(`/documents/${e}`,t)).data,delete:async e=>(await O.delete(`/documents/${e}`)).data},zs={getByCustomer:async(e,t=!1)=>(await O.get(`/customers/${e}/meters`,{params:{showInactive:t}})).data,create:async(e,t)=>(await O.post(`/customers/${e}/meters`,t)).data,update:async(e,t)=>(await O.put(`/meters/${e}`,t)).data,delete:async e=>(await O.delete(`/meters/${e}`)).data,getReadings:async e=>(await O.get(`/meters/${e}/readings`)).data,addReading:async(e,t)=>(await O.post(`/meters/${e}/readings`,t)).data,updateReading:async(e,t,s)=>(await O.put(`/meters/${e}/readings/${t}`,s)).data,deleteReading:async(e,t)=>(await O.delete(`/meters/${e}/readings/${t}`)).data},xo={getByCustomer:async(e,t=!1)=>(await O.get(`/customers/${e}/stressfrei-emails`,{params:{includeInactive:t}})).data,create:async(e,t)=>(await O.post(`/customers/${e}/stressfrei-emails`,t)).data,update:async(e,t)=>(await O.put(`/stressfrei-emails/${e}`,t)).data,delete:async e=>(await O.delete(`/stressfrei-emails/${e}`)).data},$e={getAll:async e=>(await O.get("/contracts",{params:e})).data,getById:async e=>(await O.get(`/contracts/${e}`)).data,create:async e=>(await O.post("/contracts",e)).data,update:async(e,t)=>(await O.put(`/contracts/${e}`,t)).data,delete:async e=>(await O.delete(`/contracts/${e}`)).data,createFollowUp:async e=>(await O.post(`/contracts/${e}/follow-up`)).data,getPassword:async e=>(await O.get(`/contracts/${e}/password`)).data,getSimCardCredentials:async e=>(await O.get(`/contracts/simcard/${e}/credentials`)).data,getInternetCredentials:async e=>(await O.get(`/contracts/${e}/internet-credentials`)).data,getSipCredentials:async e=>(await O.get(`/contracts/phonenumber/${e}/sip-credentials`)).data,getCockpit:async()=>(await O.get("/contracts/cockpit")).data},Xe={getAll:async e=>(await O.get("/tasks",{params:e})).data,getStats:async()=>(await O.get("/tasks/stats")).data,getByContract:async(e,t)=>(await O.get(`/contracts/${e}/tasks`,{params:{status:t}})).data,create:async(e,t)=>(await O.post(`/contracts/${e}/tasks`,t)).data,update:async(e,t)=>(await O.put(`/tasks/${e}`,t)).data,complete:async e=>(await O.post(`/tasks/${e}/complete`)).data,reopen:async e=>(await O.post(`/tasks/${e}/reopen`)).data,delete:async e=>(await O.delete(`/tasks/${e}`)).data,createSubtask:async(e,t)=>(await O.post(`/tasks/${e}/subtasks`,{title:t})).data,createReply:async(e,t)=>(await O.post(`/tasks/${e}/reply`,{title:t})).data,updateSubtask:async(e,t)=>(await O.put(`/subtasks/${e}`,{title:t})).data,completeSubtask:async e=>(await O.post(`/subtasks/${e}/complete`)).data,reopenSubtask:async e=>(await O.post(`/subtasks/${e}/reopen`)).data,deleteSubtask:async e=>(await O.delete(`/subtasks/${e}`)).data,createSupportTicket:async(e,t)=>(await O.post(`/contracts/${e}/support-ticket`,t)).data},Sr={getPublic:async()=>(await O.get("/settings/public")).data,getAll:async()=>(await O.get("/settings")).data,update:async e=>(await O.put("/settings",e)).data,updateOne:async(e,t)=>(await O.put(`/settings/${e}`,{value:t})).data},Pi={getAll:async(e=!1)=>(await O.get("/platforms",{params:{includeInactive:e}})).data,getById:async e=>(await O.get(`/platforms/${e}`)).data,create:async e=>(await O.post("/platforms",e)).data,update:async(e,t)=>(await O.put(`/platforms/${e}`,t)).data,delete:async e=>(await O.delete(`/platforms/${e}`)).data},Ai={getAll:async(e=!1)=>(await O.get("/cancellation-periods",{params:{includeInactive:e}})).data,getById:async e=>(await O.get(`/cancellation-periods/${e}`)).data,create:async e=>(await O.post("/cancellation-periods",e)).data,update:async(e,t)=>(await O.put(`/cancellation-periods/${e}`,t)).data,delete:async e=>(await O.delete(`/cancellation-periods/${e}`)).data},Ti={getAll:async(e=!1)=>(await O.get("/contract-durations",{params:{includeInactive:e}})).data,getById:async e=>(await O.get(`/contract-durations/${e}`)).data,create:async e=>(await O.post("/contract-durations",e)).data,update:async(e,t)=>(await O.put(`/contract-durations/${e}`,t)).data,delete:async e=>(await O.delete(`/contract-durations/${e}`)).data},Fi={getAll:async(e=!1)=>(await O.get("/contract-categories",{params:{includeInactive:e}})).data,getById:async e=>(await O.get(`/contract-categories/${e}`)).data,create:async e=>(await O.post("/contract-categories",e)).data,update:async(e,t)=>(await O.put(`/contract-categories/${e}`,t)).data,delete:async e=>(await O.delete(`/contract-categories/${e}`)).data},Na={getAll:async(e=!1)=>(await O.get("/providers",{params:{includeInactive:e}})).data,getById:async e=>(await O.get(`/providers/${e}`)).data,create:async e=>(await O.post("/providers",e)).data,update:async(e,t)=>(await O.put(`/providers/${e}`,t)).data,delete:async e=>(await O.delete(`/providers/${e}`)).data,getTariffs:async(e,t=!1)=>(await O.get(`/providers/${e}/tariffs`,{params:{includeInactive:t}})).data,createTariff:async(e,t)=>(await O.post(`/providers/${e}/tariffs`,t)).data},$y={getById:async e=>(await O.get(`/tariffs/${e}`)).data,update:async(e,t)=>(await O.put(`/tariffs/${e}`,t)).data,delete:async e=>(await O.delete(`/tariffs/${e}`)).data},Ye={uploadBankCardDocument:async(e,t)=>{const s=new FormData;return s.append("document",t),(await O.post(`/upload/bank-cards/${e}`,s,{headers:{"Content-Type":"multipart/form-data"}})).data},uploadIdentityDocument:async(e,t)=>{const s=new FormData;return s.append("document",t),(await O.post(`/upload/documents/${e}`,s,{headers:{"Content-Type":"multipart/form-data"}})).data},deleteBankCardDocument:async e=>(await O.delete(`/upload/bank-cards/${e}`)).data,deleteIdentityDocument:async e=>(await O.delete(`/upload/documents/${e}`)).data,uploadBusinessRegistration:async(e,t)=>{const s=new FormData;return s.append("document",t),(await O.post(`/upload/customers/${e}/business-registration`,s,{headers:{"Content-Type":"multipart/form-data"}})).data},deleteBusinessRegistration:async e=>(await O.delete(`/upload/customers/${e}/business-registration`)).data,uploadCommercialRegister:async(e,t)=>{const s=new FormData;return s.append("document",t),(await O.post(`/upload/customers/${e}/commercial-register`,s,{headers:{"Content-Type":"multipart/form-data"}})).data},deleteCommercialRegister:async e=>(await O.delete(`/upload/customers/${e}/commercial-register`)).data,uploadPrivacyPolicy:async(e,t)=>{const s=new FormData;return s.append("document",t),(await O.post(`/upload/customers/${e}/privacy-policy`,s,{headers:{"Content-Type":"multipart/form-data"}})).data},deletePrivacyPolicy:async e=>(await O.delete(`/upload/customers/${e}/privacy-policy`)).data,uploadCancellationLetter:async(e,t)=>{const s=new FormData;return s.append("document",t),(await O.post(`/upload/contracts/${e}/cancellation-letter`,s,{headers:{"Content-Type":"multipart/form-data"}})).data},deleteCancellationLetter:async e=>(await O.delete(`/upload/contracts/${e}/cancellation-letter`)).data,uploadCancellationConfirmation:async(e,t)=>{const s=new FormData;return s.append("document",t),(await O.post(`/upload/contracts/${e}/cancellation-confirmation`,s,{headers:{"Content-Type":"multipart/form-data"}})).data},deleteCancellationConfirmation:async e=>(await O.delete(`/upload/contracts/${e}/cancellation-confirmation`)).data,uploadCancellationLetterOptions:async(e,t)=>{const s=new FormData;return s.append("document",t),(await O.post(`/upload/contracts/${e}/cancellation-letter-options`,s,{headers:{"Content-Type":"multipart/form-data"}})).data},deleteCancellationLetterOptions:async e=>(await O.delete(`/upload/contracts/${e}/cancellation-letter-options`)).data,uploadCancellationConfirmationOptions:async(e,t)=>{const s=new FormData;return s.append("document",t),(await O.post(`/upload/contracts/${e}/cancellation-confirmation-options`,s,{headers:{"Content-Type":"multipart/form-data"}})).data},deleteCancellationConfirmationOptions:async e=>(await O.delete(`/upload/contracts/${e}/cancellation-confirmation-options`)).data},ii={getAll:async e=>(await O.get("/users",{params:e})).data,getById:async e=>(await O.get(`/users/${e}`)).data,create:async e=>(await O.post("/users",e)).data,update:async(e,t)=>(await O.put(`/users/${e}`,t)).data,delete:async e=>(await O.delete(`/users/${e}`)).data,getRoles:async()=>(await O.get("/users/roles/list")).data},Za={getSchema:async()=>(await O.get("/developer/schema")).data,getTableData:async(e,t=1,s=50)=>(await O.get(`/developer/table/${e}`,{params:{page:t,limit:s}})).data,updateRow:async(e,t,s)=>(await O.put(`/developer/table/${e}/${t}`,s)).data,deleteRow:async(e,t)=>(await O.delete(`/developer/table/${e}/${t}`)).data,getReference:async e=>(await O.get(`/developer/reference/${e}`)).data},xn={getConfigs:async()=>(await O.get("/email-providers/configs")).data,getConfig:async e=>(await O.get(`/email-providers/configs/${e}`)).data,createConfig:async e=>(await O.post("/email-providers/configs",e)).data,updateConfig:async(e,t)=>(await O.put(`/email-providers/configs/${e}`,t)).data,deleteConfig:async e=>(await O.delete(`/email-providers/configs/${e}`)).data,testConnection:async e=>{const t=e!=null&&e.testData?{...e.testData}:e!=null&&e.id?{id:e.id}:{};return(await O.post("/email-providers/test-connection",t)).data},getDomain:async()=>(await O.get("/email-providers/domain")).data,checkEmailExists:async e=>(await O.get(`/email-providers/check/${e}`)).data,provisionEmail:async(e,t)=>(await O.post("/email-providers/provision",{localPart:e,customerEmail:t})).data,deprovisionEmail:async e=>(await O.delete(`/email-providers/deprovision/${e}`)).data},By=w.createContext(null);function a1({children:e}){const[t,s]=w.useState(null),[r,a]=w.useState(!0),[i,l]=w.useState(()=>localStorage.getItem("developerMode")==="true"),o=g=>{l(g),localStorage.setItem("developerMode",String(g))};w.useEffect(()=>{var g;console.log("useEffect check - user:",t==null?void 0:t.email,"developerMode:",i,"has developer:access:",(g=t==null?void 0:t.permissions)==null?void 0:g.includes("developer:access")),t&&i&&!t.permissions.includes("developer:access")&&(console.log("Disabling developer mode because user lacks developer:access permission"),o(!1))},[t,i]),w.useEffect(()=>{localStorage.getItem("token")?bl.me().then(b=>{b.success&&b.data?s(b.data):localStorage.removeItem("token")}).catch(()=>{localStorage.removeItem("token")}).finally(()=>{a(!1)}):a(!1)},[]);const c=async(g,b)=>{const y=await bl.login(g,b);if(y.success&&y.data)localStorage.setItem("token",y.data.token),s(y.data.user);else throw new Error(y.error||"Login fehlgeschlagen")},u=async(g,b)=>{const y=await bl.customerLogin(g,b);if(y.success&&y.data)localStorage.setItem("token",y.data.token),s(y.data.user);else throw new Error(y.error||"Login fehlgeschlagen")},d=()=>{localStorage.removeItem("token"),s(null)},m=async()=>{var b;if(localStorage.getItem("token"))try{const y=await bl.me();console.log("refreshUser response:",y),console.log("permissions:",(b=y.data)==null?void 0:b.permissions),y.success&&y.data&&s(y.data)}catch(y){console.error("refreshUser error:",y)}},p=g=>t?t.permissions.includes(g):!1,h=!!(t!=null&&t.customerId),f=!!(t!=null&&t.isCustomerPortal);return n.jsx(By.Provider,{value:{user:t,isLoading:r,isAuthenticated:!!t,login:c,customerLogin:u,logout:d,hasPermission:p,isCustomer:h,isCustomerPortal:f,developerMode:i,setDeveloperMode:o,refreshUser:m},children:e})}function st(){const e=w.useContext(By);if(!e)throw new Error("useAuth must be used within an AuthProvider");return e}const Ac={scrollToTopThreshold:.7},Ky=w.createContext(void 0),ep="opencrm_app_settings";function i1({children:e}){const[t,s]=w.useState(()=>{const a=localStorage.getItem(ep);if(a)try{return{...Ac,...JSON.parse(a)}}catch{return Ac}return Ac});w.useEffect(()=>{localStorage.setItem(ep,JSON.stringify(t))},[t]);const r=a=>{s(i=>({...i,...a}))};return n.jsx(Ky.Provider,{value:{settings:t,updateSettings:r},children:e})}function Vy(){const e=w.useContext(Ky);if(!e)throw new Error("useAppSettings must be used within AppSettingsProvider");return e}function l1(){const{pathname:e}=dn();return w.useEffect(()=>{window.scrollTo(0,0)},[e]),null}/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const o1=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),qy=(...e)=>e.filter((t,s,r)=>!!t&&t.trim()!==""&&r.indexOf(t)===s).join(" ").trim();/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */var c1={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const u1=w.forwardRef(({color:e="currentColor",size:t=24,strokeWidth:s=2,absoluteStrokeWidth:r,className:a="",children:i,iconNode:l,...o},c)=>w.createElement("svg",{ref:c,...c1,width:t,height:t,stroke:e,strokeWidth:r?Number(s)*24/Number(t):s,className:qy("lucide",a),...o},[...l.map(([u,d])=>w.createElement(u,d)),...Array.isArray(i)?i:[i]]));/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const ae=(e,t)=>{const s=w.forwardRef(({className:r,...a},i)=>w.createElement(u1,{ref:i,iconNode:t,className:qy(`lucide-${o1(e)}`,r),...a}));return s.displayName=`${e}`,s};/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const $s=ae("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const d1=ae("ArrowRight",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const h1=ae("Building2",[["path",{d:"M6 22V4a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v18Z",key:"1b4qmf"}],["path",{d:"M6 12H4a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2h2",key:"i71pzd"}],["path",{d:"M18 9h2a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2h-2",key:"10jefs"}],["path",{d:"M10 6h4",key:"1itunk"}],["path",{d:"M10 10h4",key:"tcdvrf"}],["path",{d:"M10 14h4",key:"kelpxr"}],["path",{d:"M10 18h4",key:"1ulq68"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const m1=ae("Cable",[["path",{d:"M17 21v-2a1 1 0 0 1-1-1v-1a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v1a1 1 0 0 1-1 1",key:"10bnsj"}],["path",{d:"M19 15V6.5a1 1 0 0 0-7 0v11a1 1 0 0 1-7 0V9",key:"1eqmu1"}],["path",{d:"M21 21v-2h-4",key:"14zm7j"}],["path",{d:"M3 5h4V3",key:"z442eg"}],["path",{d:"M7 5a1 1 0 0 1 1 1v1a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V6a1 1 0 0 1 1-1V3",key:"ebdjd7"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Qy=ae("Calendar",[["path",{d:"M8 2v4",key:"1cmpym"}],["path",{d:"M16 2v4",key:"4m81vk"}],["rect",{width:"18",height:"18",x:"3",y:"4",rx:"2",key:"1hopcy"}],["path",{d:"M3 10h18",key:"8toen8"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Hy=ae("Car",[["path",{d:"M19 17h2c.6 0 1-.4 1-1v-3c0-.9-.7-1.7-1.5-1.9C18.7 10.6 16 10 16 10s-1.3-1.4-2.2-2.3c-.5-.4-1.1-.7-1.8-.7H5c-.6 0-1.1.4-1.4.9l-1.4 2.9A3.7 3.7 0 0 0 2 12v4c0 .6.4 1 1 1h2",key:"5owen"}],["circle",{cx:"7",cy:"17",r:"2",key:"u2ysq9"}],["path",{d:"M9 17h6",key:"r8uit2"}],["circle",{cx:"17",cy:"17",r:"2",key:"axvx0g"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Xu=ae("Check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Qo=ae("ChevronDown",[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const f1=ae("ChevronLeft",[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Ys=ae("ChevronRight",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Wy=ae("ChevronUp",[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const en=ae("CircleAlert",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const hs=ae("CircleCheckBig",[["path",{d:"M21.801 10A10 10 0 1 1 17 3.335",key:"yps3ct"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const tp=ae("CircleX",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const _l=ae("Circle",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Ii=ae("ClipboardList",[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2",key:"116196"}],["path",{d:"M12 11h4",key:"1jrz19"}],["path",{d:"M12 16h4",key:"n85exb"}],["path",{d:"M8 11h.01",key:"1dfujw"}],["path",{d:"M8 16h.01",key:"18s6g9"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const qn=ae("Clock",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Ho=ae("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Gy=ae("Copy",[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const p1=ae("CreditCard",[["rect",{width:"20",height:"14",x:"2",y:"5",rx:"2",key:"ynyp8z"}],["line",{x1:"2",x2:"22",y1:"10",y2:"10",key:"1b3vmo"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Zy=ae("Database",[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const tn=ae("Download",[["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["polyline",{points:"7 10 12 15 17 10",key:"2ggqvy"}],["line",{x1:"12",x2:"12",y1:"15",y2:"3",key:"1vk2je"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Yy=ae("ExternalLink",[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"M10 14 21 3",key:"gplh6r"}],["path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6",key:"a6xqqp"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Pt=ae("EyeOff",[["path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49",key:"ct8e1f"}],["path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242",key:"151rxh"}],["path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143",key:"13bj9a"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Ee=ae("Eye",[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0",key:"1nclc0"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const vt=ae("FileText",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const g1=ae("FileType",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M9 13v-1h6v1",key:"1bb014"}],["path",{d:"M12 12v6",key:"3ahymv"}],["path",{d:"M11 18h2",key:"12mj7e"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Jy=ae("Flame",[["path",{d:"M8.5 14.5A2.5 2.5 0 0 0 11 12c0-1.38-.5-2-1-3-1.072-2.143-.224-4.054 2-6 .5 2.5 2 4.9 4 6.5 2 1.6 3 3.5 3 5.5a7 7 0 1 1-14 0c0-1.153.433-2.294 1-3a2.5 2.5 0 0 0 2.5 2.5z",key:"96xj49"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Xy=ae("Gauge",[["path",{d:"m12 14 4-4",key:"9kzdfg"}],["path",{d:"M3.34 19a10 10 0 1 1 17.32 0",key:"19p75a"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const sp=ae("GitBranch",[["line",{x1:"6",x2:"6",y1:"3",y2:"15",key:"17qcm7"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["path",{d:"M18 9a9 9 0 0 1-9 9",key:"n2h4wq"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const uh=ae("Globe",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20",key:"13o1zl"}],["path",{d:"M2 12h20",key:"9i4pu4"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const x1=ae("GripVertical",[["circle",{cx:"9",cy:"12",r:"1",key:"1vctgf"}],["circle",{cx:"9",cy:"5",r:"1",key:"hp0tcf"}],["circle",{cx:"9",cy:"19",r:"1",key:"fkjjf6"}],["circle",{cx:"15",cy:"12",r:"1",key:"1tmaij"}],["circle",{cx:"15",cy:"5",r:"1",key:"19l28e"}],["circle",{cx:"15",cy:"19",r:"1",key:"f4zoj3"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const y1=ae("Key",[["path",{d:"m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4",key:"g0fldk"}],["path",{d:"m21 2-9.6 9.6",key:"1j0ho8"}],["circle",{cx:"7.5",cy:"15.5",r:"5.5",key:"yqb3hr"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const v1=ae("LayoutDashboard",[["rect",{width:"7",height:"9",x:"3",y:"3",rx:"1",key:"10lvy0"}],["rect",{width:"7",height:"5",x:"14",y:"3",rx:"1",key:"16une8"}],["rect",{width:"7",height:"9",x:"14",y:"12",rx:"1",key:"1hutg5"}],["rect",{width:"7",height:"5",x:"3",y:"16",rx:"1",key:"ldoo1y"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const j1=ae("LogOut",[["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}],["polyline",{points:"16 17 21 12 16 7",key:"1gabdz"}],["line",{x1:"21",x2:"9",y1:"12",y2:"12",key:"1uyos4"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const ev=ae("Mail",[["rect",{width:"20",height:"16",x:"2",y:"4",rx:"2",key:"18n3k1"}],["path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7",key:"1ocrg3"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const b1=ae("MapPin",[["path",{d:"M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0",key:"1r0f0z"}],["circle",{cx:"12",cy:"10",r:"3",key:"ilqhr7"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const N1=ae("Maximize2",[["polyline",{points:"15 3 21 3 21 9",key:"mznyad"}],["polyline",{points:"9 21 3 21 3 15",key:"1avn1i"}],["line",{x1:"21",x2:"14",y1:"3",y2:"10",key:"ota7mn"}],["line",{x1:"3",x2:"10",y1:"21",y2:"14",key:"1atl0r"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Mi=ae("MessageSquare",[["path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",key:"1lielz"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const w1=ae("Move",[["path",{d:"M12 2v20",key:"t6zp3m"}],["path",{d:"m15 19-3 3-3-3",key:"11eu04"}],["path",{d:"m19 9 3 3-3 3",key:"1mg7y2"}],["path",{d:"M2 12h20",key:"9i4pu4"}],["path",{d:"m5 9-3 3 3 3",key:"j64kie"}],["path",{d:"m9 5 3-3 3 3",key:"l8vdw6"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Oe=ae("Plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const S1=ae("Save",[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Wo=ae("Search",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["path",{d:"m21 21-4.3-4.3",key:"1qie3q"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const k1=ae("Send",[["path",{d:"M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z",key:"1ffxy3"}],["path",{d:"m21.854 2.147-10.94 10.939",key:"12cjpa"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const tv=ae("Settings",[["path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z",key:"1qme2f"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const dh=ae("Smartphone",[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2",key:"1yt0o3"}],["path",{d:"M12 18h.01",key:"mhygvu"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const We=ae("SquarePen",[["path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7",key:"1m0v6g"}],["path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z",key:"ohrbg2"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const C1=ae("Store",[["path",{d:"m2 7 4.41-4.41A2 2 0 0 1 7.83 2h8.34a2 2 0 0 1 1.42.59L22 7",key:"ztvudi"}],["path",{d:"M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8",key:"1b2hhj"}],["path",{d:"M15 22v-4a2 2 0 0 0-2-2h-2a2 2 0 0 0-2 2v4",key:"2ebpfo"}],["path",{d:"M2 7h20",key:"1fcdvo"}],["path",{d:"M22 7v3a2 2 0 0 1-2 2a2.7 2.7 0 0 1-1.59-.63.7.7 0 0 0-.82 0A2.7 2.7 0 0 1 16 12a2.7 2.7 0 0 1-1.59-.63.7.7 0 0 0-.82 0A2.7 2.7 0 0 1 12 12a2.7 2.7 0 0 1-1.59-.63.7.7 0 0 0-.82 0A2.7 2.7 0 0 1 8 12a2.7 2.7 0 0 1-1.59-.63.7.7 0 0 0-.82 0A2.7 2.7 0 0 1 4 12a2 2 0 0 1-2-2V7",key:"6c3vgh"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const E1=ae("Table",[["path",{d:"M12 3v18",key:"108xh3"}],["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"M3 15h18",key:"5xshup"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const be=ae("Trash2",[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}],["line",{x1:"10",x2:"10",y1:"11",y2:"17",key:"1uufr5"}],["line",{x1:"14",x2:"14",y1:"11",y2:"17",key:"xtxkd"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Li=ae("TriangleAlert",[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const sv=ae("Tv",[["rect",{width:"20",height:"15",x:"2",y:"7",rx:"2",ry:"2",key:"10ag99"}],["polyline",{points:"17 2 12 7 7 2",key:"11pgbg"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const D1=ae("Upload",[["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["polyline",{points:"17 8 12 3 7 8",key:"t8dd8p"}],["line",{x1:"12",x2:"12",y1:"3",y2:"15",key:"widbto"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const P1=ae("UserCog",[["circle",{cx:"18",cy:"15",r:"3",key:"gjjjvw"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["path",{d:"M10 15H6a4 4 0 0 0-4 4v2",key:"1nfge6"}],["path",{d:"m21.7 16.4-.9-.3",key:"12j9ji"}],["path",{d:"m15.2 13.9-.9-.3",key:"1fdjdi"}],["path",{d:"m16.6 18.7.3-.9",key:"heedtr"}],["path",{d:"m19.1 12.2.3-.9",key:"1af3ki"}],["path",{d:"m19.6 18.7-.4-1",key:"1x9vze"}],["path",{d:"m16.8 12.3-.4-1",key:"vqeiwj"}],["path",{d:"m14.3 16.6 1-.4",key:"1qlj63"}],["path",{d:"m20.7 13.8 1-.4",key:"1v5t8k"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const A1=ae("UserPlus",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["line",{x1:"19",x2:"19",y1:"8",y2:"14",key:"1bvyxn"}],["line",{x1:"22",x2:"16",y1:"11",y2:"11",key:"1shjgl"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const hh=ae("User",[["path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2",key:"975kel"}],["circle",{cx:"12",cy:"7",r:"4",key:"17ys0d"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Xr=ae("Users",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["path",{d:"M16 3.13a4 4 0 0 1 0 7.75",key:"1da9ce"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const np=ae("WifiOff",[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}],["path",{d:"M5 12.859a10 10 0 0 1 5.17-2.69",key:"1dl1wf"}],["path",{d:"M19 12.859a10 10 0 0 0-2.007-1.523",key:"4k23kn"}],["path",{d:"M2 8.82a15 15 0 0 1 4.177-2.643",key:"1grhjp"}],["path",{d:"M22 8.82a15 15 0 0 0-11.288-3.764",key:"z3jwby"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const ea=ae("Wifi",[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M2 8.82a15 15 0 0 1 20 0",key:"dnpr2z"}],["path",{d:"M5 12.859a10 10 0 0 1 14 0",key:"1x1e6c"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const wa=ae("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const mh=ae("Zap",[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const T1=ae("ZoomIn",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"11",x2:"11",y1:"8",y2:"14",key:"1vmskp"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]]);/** * @license lucide-react v0.454.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const F1=ae("ZoomOut",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]]);function I1(){const{user:e,logout:t,hasPermission:s,isCustomer:r,developerMode:a}=st(),i=[{to:"/",icon:v1,label:"Dashboard",show:!0,end:!0},{to:"/customers",icon:Xr,label:"Kunden",show:s("customers:read")&&!r},{to:"/contracts",icon:vt,label:"Verträge",show:s("contracts:read"),end:!0},{to:"/contracts/cockpit",icon:en,label:"Vertrags-Cockpit",show:s("contracts:read")&&!r},{to:"/tasks",icon:r?Mi:Ii,label:r?"Support-Anfragen":"Aufgaben",show:s("contracts:read")}],l=[{to:"/developer/database",icon:Zy,label:"Datenbankstruktur"}];return n.jsxs("aside",{className:"w-64 bg-gray-900 text-white min-h-screen flex flex-col",children:[n.jsx("div",{className:"p-4 border-b border-gray-800",children:n.jsx("h1",{className:"text-xl font-bold",children:"OpenCRM"})}),n.jsxs("nav",{className:"flex-1 p-4 overflow-y-auto",children:[n.jsx("ul",{className:"space-y-2",children:i.filter(o=>o.show).map(o=>n.jsx("li",{children:n.jsxs(Cc,{to:o.to,end:o.end,className:({isActive:c})=>`flex items-center gap-3 px-4 py-2 rounded-lg transition-colors ${c?"bg-blue-600 text-white":"text-gray-300 hover:bg-gray-800"}`,children:[n.jsx(o.icon,{className:"w-5 h-5"}),o.label]})},o.to))}),a&&s("developer:access")&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"mt-6 mb-2 px-4",children:n.jsxs("p",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wider flex items-center gap-2",children:[n.jsx(Ho,{className:"w-3 h-3"}),"Entwickler"]})}),n.jsx("ul",{className:"space-y-2",children:l.map(o=>n.jsx("li",{children:n.jsxs(Cc,{to:o.to,className:({isActive:c})=>`flex items-center gap-3 px-4 py-2 rounded-lg transition-colors ${c?"bg-purple-600 text-white":"text-purple-300 hover:bg-gray-800"}`,children:[n.jsx(o.icon,{className:"w-5 h-5"}),o.label]})},o.to))})]}),n.jsx("div",{className:"mt-6 pt-6 border-t border-gray-800",children:n.jsxs(Cc,{to:"/settings",className:({isActive:o})=>`flex items-center gap-3 px-4 py-2 rounded-lg transition-colors ${o?"bg-blue-600 text-white":"text-gray-300 hover:bg-gray-800"}`,children:[n.jsx(tv,{className:"w-5 h-5"}),"Einstellungen"]})})]}),n.jsxs("div",{className:"p-4 border-t border-gray-800",children:[n.jsxs("div",{className:"mb-4 text-sm",children:[n.jsx("p",{className:"text-gray-400",children:"Angemeldet als"}),n.jsxs("p",{className:"font-medium",children:[e==null?void 0:e.firstName," ",e==null?void 0:e.lastName]})]}),n.jsxs("button",{onClick:t,className:"flex items-center gap-3 w-full px-4 py-2 text-gray-300 hover:bg-gray-800 rounded-lg transition-colors",children:[n.jsx(j1,{className:"w-5 h-5"}),"Abmelden"]})]})]})}function M1(){const{settings:e}=Vy(),[t,s]=w.useState(!1);w.useEffect(()=>{const a=()=>{window.scrollY>window.innerHeight*e.scrollToTopThreshold?s(!0):s(!1)};return window.addEventListener("scroll",a),()=>window.removeEventListener("scroll",a)},[e.scrollToTopThreshold]);const r=()=>{window.scrollTo({top:0,behavior:"smooth"})};return t?n.jsx("button",{onClick:r,className:"fixed bottom-6 right-6 p-3 bg-gray-200 hover:bg-gray-300 text-gray-600 rounded-full shadow-md transition-all duration-300 opacity-70 hover:opacity-100 z-50","aria-label":"Nach oben scrollen",title:"Nach oben",children:n.jsx(Wy,{className:"w-5 h-5"})}):null}function L1(){return n.jsxs("div",{className:"flex min-h-screen",children:[n.jsx(I1,{}),n.jsx("main",{className:"flex-1 p-8 overflow-auto",children:n.jsx(Tb,{})}),n.jsx(M1,{})]})}const I=w.forwardRef(({className:e="",variant:t="primary",size:s="md",children:r,disabled:a,...i},l)=>{const o="inline-flex items-center justify-center font-medium rounded-lg transition-colors focus:outline-none focus:ring-2 focus:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed",c={primary:"bg-blue-600 text-white hover:bg-blue-700 focus:ring-blue-500",secondary:"bg-gray-200 text-gray-900 hover:bg-gray-300 focus:ring-gray-500",danger:"bg-red-600 text-white hover:bg-red-700 focus:ring-red-500",ghost:"bg-transparent text-gray-700 hover:bg-gray-100 focus:ring-gray-500"},u={sm:"px-3 py-1.5 text-sm",md:"px-4 py-2 text-sm",lg:"px-6 py-3 text-base"};return n.jsx("button",{ref:l,className:`${o} ${c[t]} ${u[s]} ${e}`,disabled:a,...i,children:r})});I.displayName="Button";const $=w.forwardRef(({className:e="",label:t,error:s,id:r,onClear:a,...i},l)=>{const o=r||i.name,c=i.type==="date",u=i.value!==void 0&&i.value!==null&&i.value!=="",d=c&&a&&u;return n.jsxs("div",{className:"w-full",children:[t&&n.jsx("label",{htmlFor:o,className:"block text-sm font-medium text-gray-700 mb-1",children:t}),n.jsxs("div",{className:d?"flex gap-2":"",children:[n.jsx("input",{ref:l,id:o,className:`block w-full px-3 py-2 border rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 ${s?"border-red-500":"border-gray-300"} ${e}`,...i}),d&&n.jsx("button",{type:"button",onClick:a,className:"px-3 py-2 text-gray-400 hover:text-red-500 hover:bg-red-50 border border-gray-300 rounded-lg transition-colors",title:"Datum löschen",children:n.jsx(be,{className:"w-4 h-4"})})]}),s&&n.jsx("p",{className:"mt-1 text-sm text-red-600",children:s})]})});$.displayName="Input";function Z({children:e,className:t="",title:s,actions:r}){return n.jsxs("div",{className:`bg-white rounded-lg shadow ${t}`,children:[(s||r)&&n.jsxs("div",{className:"px-6 py-4 border-b border-gray-200 flex items-center justify-between",children:[s&&n.jsx("h3",{className:"text-lg font-medium text-gray-900",children:s}),r&&n.jsx("div",{className:"flex items-center gap-2",children:r})]}),n.jsx("div",{className:"p-6",children:e})]})}function R1(){const[e,t]=w.useState(""),[s,r]=w.useState(""),[a,i]=w.useState(""),[l,o]=w.useState(!1),{login:c,customerLogin:u}=st(),d=Ut(),m=async p=>{p.preventDefault(),i(""),o(!0);try{await c(e,s),d("/");return}catch{}try{await u(e,s),d("/")}catch{i("Ungültige Anmeldedaten"),o(!1)}};return n.jsx("div",{className:"min-h-screen flex items-center justify-center bg-gray-100",children:n.jsxs(Z,{className:"w-full max-w-md",children:[n.jsxs("div",{className:"text-center mb-8",children:[n.jsx("h1",{className:"text-2xl font-bold text-gray-900",children:"OpenCRM"}),n.jsx("p",{className:"text-gray-600 mt-2",children:"Melden Sie sich an"})]}),a&&n.jsx("div",{className:"mb-4 p-4 bg-red-50 border border-red-200 text-red-700 rounded-lg",children:a}),n.jsxs("form",{onSubmit:m,className:"space-y-4",children:[n.jsx($,{label:"E-Mail",type:"email",value:e,onChange:p=>t(p.target.value),required:!0,autoComplete:"email"}),n.jsx($,{label:"Passwort",type:"password",value:s,onChange:p=>r(p.target.value),required:!0,autoComplete:"current-password"}),n.jsx(I,{type:"submit",className:"w-full",disabled:l,children:l?"Anmeldung...":"Anmelden"})]})]})})}function dt({isOpen:e,onClose:t,title:s,children:r,size:a="md"}){if(w.useEffect(()=>(e?document.body.style.overflow="hidden":document.body.style.overflow="",()=>{document.body.style.overflow=""}),[e]),!e)return null;const i={sm:"max-w-md",md:"max-w-lg",lg:"max-w-2xl",xl:"max-w-4xl"};return n.jsx("div",{className:"fixed inset-0 z-50 overflow-y-auto",children:n.jsxs("div",{className:"flex min-h-full items-center justify-center p-4",children:[n.jsx("div",{className:"fixed inset-0 bg-black/50",onClick:t}),n.jsxs("div",{className:`relative bg-white rounded-lg shadow-xl w-full ${i[a]}`,children:[n.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b",children:[n.jsx("h2",{className:"text-lg font-semibold",children:s}),n.jsx(I,{variant:"ghost",size:"sm",onClick:t,children:n.jsx(wa,{className:"w-5 h-5"})})]}),n.jsx("div",{className:"p-6",children:r})]})]})})}function O1(){var S,L,T,_,K,W;const{user:e,isCustomer:t,isCustomerPortal:s}=st(),[r,a]=w.useState(!1),{data:i,isLoading:l}=ge({queryKey:["app-settings-public"],queryFn:()=>Sr.getPublic(),enabled:s,staleTime:0}),o=!l&&((S=i==null?void 0:i.data)==null?void 0:S.customerSupportTicketsEnabled)==="true",{data:c}=ge({queryKey:["customers-count"],queryFn:()=>yt.getAll({limit:1}),enabled:!t}),{data:u}=ge({queryKey:["contracts",t?e==null?void 0:e.customerId:void 0],queryFn:()=>$e.getAll(t?{customerId:e==null?void 0:e.customerId}:{limit:1})}),{data:d}=ge({queryKey:["contracts-active",t?e==null?void 0:e.customerId:void 0],queryFn:()=>$e.getAll({status:"ACTIVE",...t?{customerId:e==null?void 0:e.customerId}:{limit:1}})}),{data:m}=ge({queryKey:["contracts-pending",t?e==null?void 0:e.customerId:void 0],queryFn:()=>$e.getAll({status:"PENDING",...t?{customerId:e==null?void 0:e.customerId}:{limit:1}})}),{data:p}=ge({queryKey:["task-stats"],queryFn:()=>Xe.getStats()}),{data:h}=ge({queryKey:["contract-cockpit"],queryFn:()=>$e.getCockpit(),enabled:!t,staleTime:0}),{ownContracts:f,representedContracts:g}=w.useMemo(()=>{if(!s||!(u!=null&&u.data))return{ownContracts:[],representedContracts:[]};const Q=[],z={};for(const P of u.data)if(P.customerId===(e==null?void 0:e.customerId))Q.push(P);else{const j=P.customerId;if(!z[j]){const B=P.customer?P.customer.companyName||`${P.customer.firstName} ${P.customer.lastName}`:`Kunde ${j}`;z[j]={customerName:B,contracts:[]}}z[j].contracts.push(P)}return{ownContracts:Q,representedContracts:Object.values(z).sort((P,j)=>P.customerName.localeCompare(j.customerName))}},[u==null?void 0:u.data,s,e==null?void 0:e.customerId]),b=w.useMemo(()=>f.filter(Q=>Q.status==="ACTIVE").length,[f]),y=w.useMemo(()=>f.filter(Q=>Q.status==="PENDING").length,[f]),v=w.useMemo(()=>f.filter(Q=>Q.status==="EXPIRED").length,[f]),x=w.useMemo(()=>g.reduce((Q,z)=>Q+z.contracts.length,0),[g]),N=w.useMemo(()=>g.reduce((Q,z)=>Q+z.contracts.filter(P=>P.status==="ACTIVE").length,0),[g]),k=w.useMemo(()=>g.reduce((Q,z)=>Q+z.contracts.filter(P=>P.status==="EXPIRED").length,0),[g]),D=((L=p==null?void 0:p.data)==null?void 0:L.openCount)||0,F=Q=>n.jsx(Z,{className:Q.link?"cursor-pointer hover:shadow-md transition-shadow":"",children:Q.link?n.jsx(Se,{to:Q.link,className:"block",children:n.jsxs("div",{className:"flex items-center",children:[n.jsx("div",{className:`p-3 rounded-lg ${Q.color}`,children:n.jsx(Q.icon,{className:"w-6 h-6 text-white"})}),n.jsxs("div",{className:"ml-4",children:[n.jsx("p",{className:"text-sm text-gray-500",children:Q.label}),n.jsx("p",{className:"text-2xl font-bold",children:Q.value})]})]})}):n.jsxs("div",{className:"flex items-center",children:[n.jsx("div",{className:`p-3 rounded-lg ${Q.color}`,children:n.jsx(Q.icon,{className:"w-6 h-6 text-white"})}),n.jsxs("div",{className:"ml-4",children:[n.jsx("p",{className:"text-sm text-gray-500",children:Q.label}),n.jsx("p",{className:"text-2xl font-bold",children:Q.value})]})]})},Q.label);return n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center justify-between mb-6",children:[n.jsxs("h1",{className:"text-2xl font-bold",children:["Willkommen, ",e==null?void 0:e.firstName,"!"]}),s&&o&&n.jsxs(I,{onClick:()=>a(!0),children:[n.jsx(Oe,{className:"w-4 h-4 mr-2"}),"Support-Anfrage"]})]}),s?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"mb-6",children:[n.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[n.jsx(hh,{className:"w-5 h-5 text-blue-600"}),n.jsx("h2",{className:"text-lg font-semibold",children:"Meine Verträge"})]}),n.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:[F({label:"Eigene Verträge",value:f.length,icon:vt,color:"bg-blue-500",link:"/contracts"}),F({label:"Davon aktiv",value:b,icon:hs,color:"bg-green-500"}),F({label:"Davon ausstehend",value:y,icon:qn,color:"bg-yellow-500"}),F({label:"Davon abgelaufen",value:v,icon:tp,color:"bg-red-500"})]})]}),x>0&&n.jsxs("div",{className:"mb-6",children:[n.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[n.jsx(Xr,{className:"w-5 h-5 text-purple-600"}),n.jsx("h2",{className:"text-lg font-semibold",children:"Fremdverträge"})]}),n.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:[F({label:"Fremdverträge",value:x,icon:Xr,color:"bg-purple-500",link:"/contracts"}),F({label:"Davon aktiv",value:N,icon:hs,color:"bg-green-500"}),n.jsx("div",{className:"hidden lg:block"}),F({label:"Davon abgelaufen",value:k,icon:tp,color:"bg-red-500"})]})]}),n.jsxs("div",{className:"mb-6",children:[n.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[n.jsx(Mi,{className:"w-5 h-5 text-orange-600"}),n.jsx("h2",{className:"text-lg font-semibold",children:"Support-Anfragen"})]}),n.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:F({label:"Offene Anfragen",value:D,icon:Mi,color:"bg-orange-500",link:"/tasks"})})]})]}):n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-6",children:[F({label:"Kunden",value:((T=c==null?void 0:c.pagination)==null?void 0:T.total)||0,icon:Xr,color:"bg-blue-500",link:"/customers"}),F({label:"Verträge gesamt",value:((_=u==null?void 0:u.pagination)==null?void 0:_.total)||0,icon:vt,color:"bg-purple-500",link:"/contracts"}),F({label:"Aktive Verträge",value:((K=d==null?void 0:d.pagination)==null?void 0:K.total)||0,icon:hs,color:"bg-green-500"}),F({label:"Ausstehende Verträge",value:((W=m==null?void 0:m.pagination)==null?void 0:W.total)||0,icon:en,color:"bg-yellow-500"})]}),(h==null?void 0:h.data)&&n.jsxs("div",{className:"mb-6",children:[n.jsxs("div",{className:"flex items-center justify-between mb-3",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(en,{className:"w-5 h-5 text-red-500"}),n.jsx("h2",{className:"text-lg font-semibold",children:"Vertrags-Cockpit"})]}),n.jsx(Se,{to:"/contracts/cockpit",className:"text-sm text-blue-600 hover:underline",children:"Alle anzeigen"})]}),n.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:[n.jsx(Z,{className:"cursor-pointer hover:shadow-md transition-shadow",children:n.jsx(Se,{to:"/contracts/cockpit?filter=critical",className:"block",children:n.jsxs("div",{className:"flex items-center",children:[n.jsx("div",{className:"p-3 rounded-lg bg-red-100",children:n.jsx(en,{className:"w-6 h-6 text-red-500"})}),n.jsxs("div",{className:"ml-4",children:[n.jsxs("p",{className:"text-sm text-gray-500",children:["Kritisch (<",h.data.thresholds.criticalDays," Tage)"]}),n.jsx("p",{className:"text-2xl font-bold text-red-600",children:h.data.summary.criticalCount})]})]})})}),n.jsx(Z,{className:"cursor-pointer hover:shadow-md transition-shadow",children:n.jsx(Se,{to:"/contracts/cockpit?filter=warning",className:"block",children:n.jsxs("div",{className:"flex items-center",children:[n.jsx("div",{className:"p-3 rounded-lg bg-yellow-100",children:n.jsx(Li,{className:"w-6 h-6 text-yellow-500"})}),n.jsxs("div",{className:"ml-4",children:[n.jsxs("p",{className:"text-sm text-gray-500",children:["Warnung (<",h.data.thresholds.warningDays," Tage)"]}),n.jsx("p",{className:"text-2xl font-bold text-yellow-600",children:h.data.summary.warningCount})]})]})})}),n.jsx(Z,{className:"cursor-pointer hover:shadow-md transition-shadow",children:n.jsx(Se,{to:"/contracts/cockpit?filter=ok",className:"block",children:n.jsxs("div",{className:"flex items-center",children:[n.jsx("div",{className:"p-3 rounded-lg bg-green-100",children:n.jsx(hs,{className:"w-6 h-6 text-green-500"})}),n.jsxs("div",{className:"ml-4",children:[n.jsxs("p",{className:"text-sm text-gray-500",children:["OK (<",h.data.thresholds.okDays," Tage)"]}),n.jsx("p",{className:"text-2xl font-bold text-green-600",children:h.data.summary.okCount})]})]})})}),n.jsx(Z,{className:"cursor-pointer hover:shadow-md transition-shadow",children:n.jsx(Se,{to:"/contracts/cockpit",className:"block",children:n.jsxs("div",{className:"flex items-center",children:[n.jsx("div",{className:"p-3 rounded-lg bg-gray-100",children:n.jsx(vt,{className:"w-6 h-6 text-gray-500"})}),n.jsxs("div",{className:"ml-4",children:[n.jsx("p",{className:"text-sm text-gray-500",children:"Handlungsbedarf"}),n.jsx("p",{className:"text-2xl font-bold text-gray-600",children:h.data.summary.totalContracts})]})]})})})]})]}),n.jsxs("div",{className:"mb-6",children:[n.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[n.jsx(Ii,{className:"w-5 h-5 text-orange-600"}),n.jsx("h2",{className:"text-lg font-semibold",children:"Aufgaben"})]}),n.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:F({label:"Offene Aufgaben",value:D,icon:Ii,color:"bg-orange-500",link:"/tasks"})})]})]}),s&&n.jsx(_1,{isOpen:r,onClose:()=>a(!1)})]})}function _1({isOpen:e,onClose:t}){const{user:s}=st(),r=Ut(),a=pe(),[i,l]=w.useState("own"),[o,c]=w.useState(null),[u,d]=w.useState(""),[m,p]=w.useState(""),[h,f]=w.useState(!1),[g,b]=w.useState(""),{data:y}=ge({queryKey:["contracts",s==null?void 0:s.customerId],queryFn:()=>$e.getAll({customerId:s==null?void 0:s.customerId}),enabled:e}),v=w.useMemo(()=>{if(!(y!=null&&y.data))return{own:[],represented:{}};const S=[],L={};for(const T of y.data)if(T.customerId===(s==null?void 0:s.customerId))S.push(T);else{if(!L[T.customerId]){const _=T.customer?T.customer.companyName||`${T.customer.firstName} ${T.customer.lastName}`:`Kunde ${T.customerId}`;L[T.customerId]={name:_,contracts:[]}}L[T.customerId].contracts.push(T)}return{own:S,represented:L}},[y==null?void 0:y.data,s==null?void 0:s.customerId]),x=Object.keys(v.represented).length>0,N=w.useMemo(()=>{var S;return i==="own"?v.own:((S=v.represented[i])==null?void 0:S.contracts)||[]},[i,v]),k=w.useMemo(()=>{if(!g)return N;const S=g.toLowerCase();return N.filter(L=>L.contractNumber.toLowerCase().includes(S)||(L.providerName||"").toLowerCase().includes(S)||(L.tariffName||"").toLowerCase().includes(S))},[N,g]),D=async()=>{if(!(!o||!u.trim())){f(!0);try{await Xe.createSupportTicket(o,{title:u.trim(),description:m.trim()||void 0}),a.invalidateQueries({queryKey:["task-stats"]}),a.invalidateQueries({queryKey:["all-tasks"]}),t(),d(""),p(""),c(null),l("own"),r(`/contracts/${o}`)}catch(S){console.error("Fehler beim Erstellen der Support-Anfrage:",S),alert("Fehler beim Erstellen der Support-Anfrage. Bitte versuchen Sie es erneut.")}finally{f(!1)}}},F=()=>{d(""),p(""),c(null),l("own"),b(""),t()};return n.jsx(dt,{isOpen:e,onClose:F,title:"Neue Support-Anfrage",children:n.jsxs("div",{className:"space-y-4",children:[x&&n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Kunde"}),n.jsxs("select",{value:i,onChange:S=>{const L=S.target.value;l(L==="own"?"own":parseInt(L)),c(null),b("")},className:"w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500",children:[n.jsx("option",{value:"own",children:"Eigene Verträge"}),Object.entries(v.represented).map(([S,{name:L}])=>n.jsx("option",{value:S,children:L},S))]})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Vertrag *"}),n.jsx($,{placeholder:"Vertrag suchen...",value:g,onChange:S=>b(S.target.value),className:"mb-2"}),n.jsx("div",{className:"max-h-48 overflow-y-auto border rounded-lg",children:k.length>0?k.map(S=>n.jsxs("div",{onClick:()=>c(S.id),className:`p-3 cursor-pointer border-b last:border-b-0 hover:bg-gray-50 ${o===S.id?"bg-blue-50 border-blue-200":""}`,children:[n.jsx("div",{className:"font-medium",children:S.contractNumber}),n.jsxs("div",{className:"text-sm text-gray-500",children:[S.providerName||"Kein Anbieter",S.tariffName&&` - ${S.tariffName}`]})]},S.id)):n.jsx("div",{className:"p-3 text-gray-500 text-center",children:"Keine Verträge gefunden."})})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Titel *"}),n.jsx($,{value:u,onChange:S=>d(S.target.value),placeholder:"Kurze Beschreibung Ihres Anliegens"})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Beschreibung"}),n.jsx("textarea",{value:m,onChange:S=>p(S.target.value),placeholder:"Detaillierte Beschreibung (optional)",rows:4,className:"w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),n.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[n.jsx(I,{variant:"secondary",onClick:F,children:"Abbrechen"}),n.jsx(I,{onClick:D,disabled:!o||!u.trim()||h,children:h?"Wird erstellt...":"Anfrage erstellen"})]})]})})}function he({children:e,variant:t="default",className:s="",onClick:r}){const a={default:"bg-gray-100 text-gray-800",success:"bg-green-100 text-green-800",warning:"bg-yellow-100 text-yellow-800",danger:"bg-red-100 text-red-800",info:"bg-blue-100 text-blue-800"};return n.jsx("span",{className:`inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium ${a[t]} ${s}`,onClick:r,children:e})}function z1(){const[e,t]=w.useState(""),[s,r]=w.useState(""),[a,i]=w.useState(1),{hasPermission:l}=st(),{data:o,isLoading:c}=ge({queryKey:["customers",e,s,a],queryFn:()=>yt.getAll({search:e,type:s||void 0,page:a,limit:20})});return n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center justify-between mb-6",children:[n.jsx("h1",{className:"text-2xl font-bold",children:"Kunden"}),l("customers:create")&&n.jsx(Se,{to:"/customers/new",children:n.jsxs(I,{children:[n.jsx(Oe,{className:"w-4 h-4 mr-2"}),"Neuer Kunde"]})})]}),n.jsx(Z,{className:"mb-6",children:n.jsxs("div",{className:"flex gap-2 items-center",children:[n.jsx($,{placeholder:"Suchen...",value:e,onChange:u=>t(u.target.value),className:"flex-1"}),n.jsxs("select",{value:s,onChange:u=>r(u.target.value),className:"px-3 py-2 border border-gray-300 rounded-lg w-28 flex-shrink-0",children:[n.jsx("option",{value:"",children:"Alle"}),n.jsx("option",{value:"PRIVATE",children:"Privat"}),n.jsx("option",{value:"BUSINESS",children:"Firma"})]}),n.jsx(I,{variant:"secondary",className:"flex-shrink-0",children:n.jsx(Wo,{className:"w-4 h-4"})})]})}),n.jsx(Z,{children:c?n.jsx("div",{className:"text-center py-8 text-gray-500",children:"Laden..."}):o!=null&&o.data&&o.data.length>0?n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"overflow-x-auto",children:n.jsxs("table",{className:"w-full",children:[n.jsx("thead",{children:n.jsxs("tr",{className:"border-b",children:[n.jsx("th",{className:"text-left py-3 px-4 font-medium text-gray-600",children:"Kundennr."}),n.jsx("th",{className:"text-left py-3 px-4 font-medium text-gray-600",children:"Name"}),n.jsx("th",{className:"text-left py-3 px-4 font-medium text-gray-600",children:"Typ"}),n.jsx("th",{className:"text-left py-3 px-4 font-medium text-gray-600",children:"E-Mail"}),n.jsx("th",{className:"text-left py-3 px-4 font-medium text-gray-600",children:"Verträge"}),n.jsx("th",{className:"text-right py-3 px-4 font-medium text-gray-600",children:"Aktionen"})]})}),n.jsx("tbody",{children:o.data.map(u=>{var d;return n.jsxs("tr",{className:"border-b hover:bg-gray-50",children:[n.jsx("td",{className:"py-3 px-4 font-mono text-sm",children:u.customerNumber}),n.jsx("td",{className:"py-3 px-4",children:u.type==="BUSINESS"&&u.companyName?u.companyName:`${u.firstName} ${u.lastName}`}),n.jsx("td",{className:"py-3 px-4",children:n.jsx(he,{variant:u.type==="BUSINESS"?"info":"default",children:u.type==="BUSINESS"?"Firma":"Privat"})}),n.jsx("td",{className:"py-3 px-4",children:u.email||"-"}),n.jsx("td",{className:"py-3 px-4",children:((d=u._count)==null?void 0:d.contracts)||0}),n.jsx("td",{className:"py-3 px-4 text-right",children:n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx(Se,{to:`/customers/${u.id}`,children:n.jsx(I,{variant:"ghost",size:"sm",children:n.jsx(Ee,{className:"w-4 h-4"})})}),l("customers:update")&&n.jsx(Se,{to:`/customers/${u.id}/edit`,children:n.jsx(I,{variant:"ghost",size:"sm",children:n.jsx(We,{className:"w-4 h-4"})})})]})})]},u.id)})})]})}),o.pagination&&o.pagination.totalPages>1&&n.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[n.jsxs("p",{className:"text-sm text-gray-500",children:["Seite ",o.pagination.page," von ",o.pagination.totalPages," (",o.pagination.total," Einträge)"]}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx(I,{variant:"secondary",size:"sm",onClick:()=>i(u=>Math.max(1,u-1)),disabled:a===1,children:"Zurück"}),n.jsx(I,{variant:"secondary",size:"sm",onClick:()=>i(u=>u+1),disabled:a>=o.pagination.totalPages,children:"Weiter"})]})]})]}):n.jsx("div",{className:"text-center py-8 text-gray-500",children:"Keine Kunden gefunden."})})]})}function U1({tabs:e,defaultTab:t}){var a,i;const[s,r]=w.useState(t||((a=e[0])==null?void 0:a.id));return n.jsxs("div",{children:[n.jsx("div",{className:"border-b border-gray-200",children:n.jsx("nav",{className:"flex -mb-px space-x-8",children:e.map(l=>n.jsx("button",{onClick:()=>r(l.id),className:`py-4 px-1 border-b-2 font-medium text-sm whitespace-nowrap ${s===l.id?"border-blue-500 text-blue-600":"border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300"}`,children:l.label},l.id))})}),n.jsx("div",{className:"mt-4",children:(i=e.find(l=>l.id===s))==null?void 0:i.content})]})}const Le=w.forwardRef(({className:e="",label:t,error:s,options:r,id:a,placeholder:i="Bitte wählen...",...l},o)=>{const c=a||l.name,u=/\bw-\d+\b|\bw-\[|\bflex-/.test(e);return n.jsxs("div",{className:u?e:"w-full",children:[t&&n.jsx("label",{htmlFor:c,className:"block text-sm font-medium text-gray-700 mb-1",children:t}),n.jsxs("select",{ref:o,id:c,className:`block w-full px-3 py-2 border rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 ${s?"border-red-500":"border-gray-300"}`,...l,children:[n.jsx("option",{value:"",children:i}),r.map(d=>n.jsx("option",{value:d.value,children:d.label},d.value))]}),s&&n.jsx("p",{className:"mt-1 text-sm text-red-600",children:s})]})});Le.displayName="Select";function xt({onUpload:e,existingFile:t,accept:s=".pdf,.jpg,.jpeg,.png",label:r="Dokument hochladen",disabled:a=!1}){const i=w.useRef(null),[l,o]=w.useState(!1),[c,u]=w.useState(!1),d=async g=>{if(g){o(!0);try{await e(g)}catch(b){console.error("Upload failed:",b),alert("Upload fehlgeschlagen")}finally{o(!1)}}},m=g=>{var y;const b=(y=g.target.files)==null?void 0:y[0];b&&d(b)},p=g=>{var y;g.preventDefault(),u(!1);const b=(y=g.dataTransfer.files)==null?void 0:y[0];b&&d(b)},h=g=>{g.preventDefault(),u(!0)},f=()=>{u(!1)};return n.jsxs("div",{className:"space-y-2",children:[t?!a&&n.jsx(I,{variant:"secondary",size:"sm",onClick:()=>{var g;return(g=i.current)==null?void 0:g.click()},disabled:l,children:l?"Wird hochgeladen...":"Ersetzen"}):n.jsx("div",{className:`border-2 border-dashed rounded-lg p-4 text-center cursor-pointer transition-colors ${c?"border-blue-500 bg-blue-50":"border-gray-300 hover:border-gray-400"} ${a?"opacity-50 cursor-not-allowed":""}`,onClick:()=>{var g;return!a&&((g=i.current)==null?void 0:g.click())},onDrop:a?void 0:p,onDragOver:a?void 0:h,onDragLeave:a?void 0:f,children:l?n.jsxs("div",{className:"text-gray-500",children:[n.jsx("div",{className:"animate-spin w-6 h-6 border-2 border-blue-500 border-t-transparent rounded-full mx-auto mb-2"}),"Wird hochgeladen..."]}):n.jsxs(n.Fragment,{children:[n.jsx(D1,{className:"w-6 h-6 text-gray-400 mx-auto mb-2"}),n.jsx("p",{className:"text-sm text-gray-600",children:r}),n.jsx("p",{className:"text-xs text-gray-400 mt-1",children:"PDF, JPG oder PNG (max. 10MB)"})]})}),n.jsx("input",{ref:i,type:"file",accept:s,onChange:m,className:"hidden",disabled:a||l})]})}function oe({value:e,className:t="",size:s="sm",title:r="In Zwischenablage kopieren"}){const[a,i]=w.useState(!1),l=async c=>{c.preventDefault(),c.stopPropagation();try{await navigator.clipboard.writeText(e),i(!0),setTimeout(()=>i(!1),1500)}catch(u){console.error("Failed to copy:",u)}},o=s==="sm"?"w-3.5 h-3.5":"w-4 h-4";return n.jsx("button",{type:"button",onClick:l,className:`inline-flex items-center justify-center p-1 rounded transition-colors ${a?"text-green-600 bg-green-50":"text-gray-400 hover:text-blue-600 hover:bg-blue-50"} ${t}`,title:a?"Kopiert!":r,children:a?n.jsx(Xu,{className:o}):n.jsx(Gy,{className:o})})}function nv({values:e,separator:t=` `,children:s,className:r=""}){const a=e.filter(i=>i!=null&&i!=="").map(String).join(t);return a?n.jsxs("div",{className:`relative group ${r}`,children:[s,n.jsx(oe,{value:a,className:"absolute top-0 right-0 opacity-60 group-hover:opacity-100",title:"Alles kopieren"})]}):n.jsx(n.Fragment,{children:s})}function $1(){var B,J;const{id:e}=_o(),t=Ut(),s=pe(),{hasPermission:r}=st(),[a]=Uo(),i=parseInt(e),l=a.get("tab")||"addresses",[o,c]=w.useState(!1),[u,d]=w.useState(!1),[m,p]=w.useState(!1),[h,f]=w.useState(!1),[g,b]=w.useState(!1),[y,v]=w.useState(!1),[x,N]=w.useState(null),[k,D]=w.useState(null),[F,S]=w.useState(null),[L,T]=w.useState(null),[_,K]=w.useState(null),{data:W,isLoading:Q}=ge({queryKey:["customer",e],queryFn:()=>yt.getById(i)}),z=Y({mutationFn:()=>yt.delete(i),onSuccess:()=>{t("/customers")}});if(Q)return n.jsx("div",{className:"text-center py-8",children:"Laden..."});if(!(W!=null&&W.data))return n.jsx("div",{className:"text-center py-8 text-red-600",children:"Kunde nicht gefunden"});const P=W.data,j=[{id:"addresses",label:"Adressen",content:n.jsx(V1,{customerId:i,addresses:P.addresses||[],canEdit:r("customers:update"),onAdd:()=>c(!0),onEdit:ee=>S(ee)})},{id:"bankcards",label:"Bankkarten",content:n.jsx(q1,{customerId:i,bankCards:P.bankCards||[],canEdit:r("customers:update"),showInactive:y,onToggleInactive:()=>v(!y),onAdd:()=>d(!0),onEdit:ee=>N(ee)})},{id:"documents",label:"Ausweise",content:n.jsx(Q1,{customerId:i,documents:P.identityDocuments||[],canEdit:r("customers:update"),showInactive:y,onToggleInactive:()=>v(!y),onAdd:()=>p(!0),onEdit:ee=>D(ee)})},{id:"meters",label:"Zähler",content:n.jsx(H1,{customerId:i,meters:P.meters||[],canEdit:r("customers:update"),showInactive:y,onToggleInactive:()=>v(!y),onAdd:()=>f(!0),onEdit:ee=>T(ee)})},{id:"stressfrei",label:"Stressfrei-Wechseln",content:n.jsx(Y1,{customerId:i,emails:P.stressfreiEmails||[],canEdit:r("customers:update"),showInactive:y,onToggleInactive:()=>v(!y),onAdd:()=>b(!0),onEdit:ee=>K(ee)})},{id:"contracts",label:"Verträge",content:n.jsx(W1,{customerId:i,contracts:P.contracts||[]})},...r("customers:update")?[{id:"portal",label:"Portal",content:n.jsx(Z1,{customerId:i,canEdit:r("customers:update")})}]:[]];return n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center justify-between mb-6",children:[n.jsxs("div",{children:[n.jsx("h1",{className:"text-2xl font-bold",children:P.type==="BUSINESS"&&P.companyName?P.companyName:`${P.firstName} ${P.lastName}`}),n.jsxs("p",{className:"text-gray-500 font-mono flex items-center gap-1",children:[P.customerNumber,n.jsx(oe,{value:P.customerNumber})]})]}),n.jsxs("div",{className:"flex gap-2",children:[r("customers:update")&&n.jsx(Se,{to:`/customers/${e}/edit`,children:n.jsxs(I,{variant:"secondary",children:[n.jsx(We,{className:"w-4 h-4 mr-2"}),"Bearbeiten"]})}),r("customers:delete")&&n.jsxs(I,{variant:"danger",onClick:()=>{confirm("Kunde wirklich löschen?")&&z.mutate()},children:[n.jsx(be,{className:"w-4 h-4 mr-2"}),"Löschen"]})]})]}),n.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6 mb-6",children:[n.jsx(Z,{title:"Stammdaten",className:"lg:col-span-2",children:n.jsxs("dl",{className:"grid grid-cols-2 gap-4",children:[n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Typ"}),n.jsx("dd",{children:n.jsx(he,{variant:P.type==="BUSINESS"?"info":"default",children:P.type==="BUSINESS"?"Geschäftskunde":"Privatkunde"})})]}),P.salutation&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Anrede"}),n.jsxs("dd",{className:"flex items-center gap-1",children:[P.salutation,n.jsx(oe,{value:P.salutation})]})]}),n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Vorname"}),n.jsxs("dd",{className:"flex items-center gap-1",children:[P.firstName,n.jsx(oe,{value:P.firstName})]})]}),n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Nachname"}),n.jsxs("dd",{className:"flex items-center gap-1",children:[P.lastName,n.jsx(oe,{value:P.lastName})]})]}),P.companyName&&n.jsxs("div",{className:"col-span-2",children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Firma"}),n.jsxs("dd",{className:"flex items-center gap-1",children:[P.companyName,n.jsx(oe,{value:P.companyName})]})]}),P.foundingDate&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Gründungsdatum"}),n.jsxs("dd",{className:"flex items-center gap-1",children:[new Date(P.foundingDate).toLocaleDateString("de-DE",{day:"2-digit",month:"2-digit",year:"numeric"}),n.jsx(oe,{value:new Date(P.foundingDate).toLocaleDateString("de-DE",{day:"2-digit",month:"2-digit",year:"numeric"})})]})]}),P.birthDate&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Geburtsdatum"}),n.jsxs("dd",{className:"flex items-center gap-1",children:[new Date(P.birthDate).toLocaleDateString("de-DE",{day:"2-digit",month:"2-digit",year:"numeric"}),n.jsx(oe,{value:new Date(P.birthDate).toLocaleDateString("de-DE",{day:"2-digit",month:"2-digit",year:"numeric"})})]})]}),P.birthPlace&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Geburtsort"}),n.jsxs("dd",{className:"flex items-center gap-1",children:[P.birthPlace,n.jsx(oe,{value:P.birthPlace})]})]})]})}),n.jsx(Z,{title:"Kontakt",children:n.jsxs("dl",{className:"space-y-3",children:[P.email&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"E-Mail"}),n.jsxs("dd",{className:"flex items-center gap-1",children:[n.jsx("a",{href:`mailto:${P.email}`,className:"text-blue-600 hover:underline",children:P.email}),n.jsx(oe,{value:P.email})]})]}),P.phone&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Telefon"}),n.jsxs("dd",{className:"flex items-center gap-1",children:[n.jsx("a",{href:`tel:${P.phone}`,className:"text-blue-600 hover:underline",children:P.phone}),n.jsx(oe,{value:P.phone})]})]}),P.mobile&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Mobil"}),n.jsxs("dd",{className:"flex items-center gap-1",children:[n.jsx("a",{href:`tel:${P.mobile}`,className:"text-blue-600 hover:underline",children:P.mobile}),n.jsx(oe,{value:P.mobile})]})]})]})})]}),P.type==="BUSINESS"&&n.jsx(B1,{customer:P,canEdit:r("customers:update"),onUpdate:()=>s.invalidateQueries({queryKey:["customer",e]})}),n.jsx(K1,{customer:P,canEdit:r("customers:update"),onUpdate:()=>s.invalidateQueries({queryKey:["customer",e]})}),P.notes&&n.jsx(Z,{title:"Notizen",className:"mb-6",children:n.jsx("p",{className:"whitespace-pre-wrap",children:P.notes})}),n.jsx(Z,{children:n.jsx(U1,{tabs:j,defaultTab:l})}),n.jsx(rp,{isOpen:o,onClose:()=>c(!1),customerId:i}),n.jsx(rp,{isOpen:!!F,onClose:()=>S(null),customerId:i,address:F}),n.jsx(ap,{isOpen:u,onClose:()=>d(!1),customerId:i}),n.jsx(ap,{isOpen:!!x,onClose:()=>N(null),customerId:i,bankCard:x}),n.jsx(ip,{isOpen:m,onClose:()=>p(!1),customerId:i}),n.jsx(ip,{isOpen:!!k,onClose:()=>D(null),customerId:i,document:k}),n.jsx(lp,{isOpen:h,onClose:()=>f(!1),customerId:i}),n.jsx(lp,{isOpen:!!L,onClose:()=>T(null),customerId:i,meter:L}),n.jsx(cp,{isOpen:g,onClose:()=>b(!1),customerId:i,customerEmail:(B=W==null?void 0:W.data)==null?void 0:B.email}),n.jsx(cp,{isOpen:!!_,onClose:()=>K(null),customerId:i,email:_,customerEmail:(J=W==null?void 0:W.data)==null?void 0:J.email})]})}function B1({customer:e,canEdit:t,onUpdate:s}){const r=async c=>{try{await Ye.uploadBusinessRegistration(e.id,c),s()}catch(u){console.error("Upload fehlgeschlagen:",u),alert("Upload fehlgeschlagen")}},a=async()=>{if(confirm("Gewerbeanmeldung wirklich löschen?"))try{await Ye.deleteBusinessRegistration(e.id),s()}catch(c){console.error("Löschen fehlgeschlagen:",c),alert("Löschen fehlgeschlagen")}},i=async c=>{try{await Ye.uploadCommercialRegister(e.id,c),s()}catch(u){console.error("Upload fehlgeschlagen:",u),alert("Upload fehlgeschlagen")}},l=async()=>{if(confirm("Handelsregisterauszug wirklich löschen?"))try{await Ye.deleteCommercialRegister(e.id),s()}catch(c){console.error("Löschen fehlgeschlagen:",c),alert("Löschen fehlgeschlagen")}};return!(e.taxNumber||e.commercialRegisterNumber||e.businessRegistrationPath||e.commercialRegisterPath)&&!t?null:n.jsxs(Z,{title:"Geschäftsdaten",className:"mb-6",children:[n.jsxs("dl",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.taxNumber&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Steuernummer"}),n.jsxs("dd",{className:"flex items-center gap-1",children:[e.taxNumber,n.jsx(oe,{value:e.taxNumber})]})]}),e.commercialRegisterNumber&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Handelsregisternummer"}),n.jsxs("dd",{className:"flex items-center gap-1",children:[e.commercialRegisterNumber,n.jsx(oe,{value:e.commercialRegisterNumber})]})]})]}),n.jsxs("div",{className:"mt-4 pt-4 border-t grid grid-cols-1 md:grid-cols-2 gap-6",children:[n.jsxs("div",{children:[n.jsx("h4",{className:"text-sm font-medium text-gray-700 mb-2",children:"Gewerbeanmeldung"}),e.businessRegistrationPath?n.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[n.jsxs("a",{href:`/api${e.businessRegistrationPath}`,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:underline text-sm flex items-center gap-1",children:[n.jsx(Ee,{className:"w-4 h-4"}),"Anzeigen"]}),n.jsxs("a",{href:`/api${e.businessRegistrationPath}`,download:!0,className:"text-blue-600 hover:underline text-sm flex items-center gap-1",children:[n.jsx(tn,{className:"w-4 h-4"}),"Download"]}),t&&n.jsxs(n.Fragment,{children:[n.jsx(xt,{onUpload:r,existingFile:e.businessRegistrationPath,accept:".pdf",label:"Ersetzen"}),n.jsxs("button",{onClick:a,className:"text-red-600 hover:underline text-sm flex items-center gap-1",children:[n.jsx(be,{className:"w-4 h-4"}),"Löschen"]})]})]}):t?n.jsx(xt,{onUpload:r,accept:".pdf",label:"PDF hochladen"}):n.jsx("p",{className:"text-sm text-gray-400",children:"Nicht vorhanden"})]}),n.jsxs("div",{children:[n.jsx("h4",{className:"text-sm font-medium text-gray-700 mb-2",children:"Handelsregisterauszug"}),e.commercialRegisterPath?n.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[n.jsxs("a",{href:`/api${e.commercialRegisterPath}`,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:underline text-sm flex items-center gap-1",children:[n.jsx(Ee,{className:"w-4 h-4"}),"Anzeigen"]}),n.jsxs("a",{href:`/api${e.commercialRegisterPath}`,download:!0,className:"text-blue-600 hover:underline text-sm flex items-center gap-1",children:[n.jsx(tn,{className:"w-4 h-4"}),"Download"]}),t&&n.jsxs(n.Fragment,{children:[n.jsx(xt,{onUpload:i,existingFile:e.commercialRegisterPath,accept:".pdf",label:"Ersetzen"}),n.jsxs("button",{onClick:l,className:"text-red-600 hover:underline text-sm flex items-center gap-1",children:[n.jsx(be,{className:"w-4 h-4"}),"Löschen"]})]})]}):t?n.jsx(xt,{onUpload:i,accept:".pdf",label:"PDF hochladen"}):n.jsx("p",{className:"text-sm text-gray-400",children:"Nicht vorhanden"})]})]})]})}function K1({customer:e,canEdit:t,onUpdate:s}){const r=async i=>{try{await Ye.uploadPrivacyPolicy(e.id,i),s()}catch(l){console.error("Upload fehlgeschlagen:",l),alert("Upload fehlgeschlagen")}},a=async()=>{if(confirm("Datenschutzerklärung wirklich löschen?"))try{await Ye.deletePrivacyPolicy(e.id),s()}catch(i){console.error("Löschen fehlgeschlagen:",i),alert("Löschen fehlgeschlagen")}};return!e.privacyPolicyPath&&!t?null:n.jsx(Z,{title:"Dokumente",className:"mb-6",children:n.jsxs("div",{children:[n.jsx("h4",{className:"text-sm font-medium text-gray-700 mb-2",children:"Datenschutzerklärung"}),e.privacyPolicyPath?n.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[n.jsxs("a",{href:`/api${e.privacyPolicyPath}`,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:underline text-sm flex items-center gap-1",children:[n.jsx(Ee,{className:"w-4 h-4"}),"Anzeigen"]}),n.jsxs("a",{href:`/api${e.privacyPolicyPath}`,download:!0,className:"text-blue-600 hover:underline text-sm flex items-center gap-1",children:[n.jsx(tn,{className:"w-4 h-4"}),"Download"]}),t&&n.jsxs(n.Fragment,{children:[n.jsx(xt,{onUpload:r,existingFile:e.privacyPolicyPath,accept:".pdf",label:"Ersetzen"}),n.jsxs("button",{onClick:a,className:"text-red-600 hover:underline text-sm flex items-center gap-1",children:[n.jsx(be,{className:"w-4 h-4"}),"Löschen"]})]})]}):t?n.jsx(xt,{onUpload:r,accept:".pdf",label:"PDF hochladen"}):n.jsx("p",{className:"text-sm text-gray-400",children:"Nicht vorhanden"})]})})}function V1({customerId:e,addresses:t,canEdit:s,onAdd:r,onEdit:a}){const i=pe(),l=Y({mutationFn:Ju.delete,onSuccess:()=>i.invalidateQueries({queryKey:["customer",e.toString()]})});return n.jsxs("div",{children:[s&&n.jsx("div",{className:"mb-4",children:n.jsxs(I,{size:"sm",onClick:r,children:[n.jsx(Oe,{className:"w-4 h-4 mr-2"}),"Adresse hinzufügen"]})}),t.length>0?n.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:t.map(o=>n.jsxs("div",{className:"border rounded-lg p-4",children:[n.jsxs("div",{className:"flex items-start justify-between",children:[n.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[n.jsx(b1,{className:"w-4 h-4 text-gray-400"}),n.jsx(he,{variant:o.type==="BILLING"?"info":"default",children:o.type==="BILLING"?"Rechnung":"Liefer-/Meldeadresse"}),o.isDefault&&n.jsx(he,{variant:"success",children:"Standard"})]}),s&&n.jsxs("div",{className:"flex gap-1",children:[n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>a(o),title:"Bearbeiten",children:n.jsx(We,{className:"w-4 h-4"})}),n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{confirm("Adresse wirklich löschen?")&&l.mutate(o.id)},title:"Löschen",children:n.jsx(be,{className:"w-4 h-4 text-red-500"})})]})]}),n.jsxs(nv,{values:[`${o.street} ${o.houseNumber}`,`${o.postalCode} ${o.city}`,o.country],children:[n.jsxs("p",{children:[o.street," ",o.houseNumber]}),n.jsxs("p",{children:[o.postalCode," ",o.city]}),n.jsx("p",{className:"text-gray-500",children:o.country})]})]},o.id))}):n.jsx("p",{className:"text-gray-500",children:"Keine Adressen vorhanden."})]})}function q1({customerId:e,bankCards:t,canEdit:s,showInactive:r,onToggleInactive:a,onAdd:i,onEdit:l}){const o=pe(),c=Y({mutationFn:({id:h,data:f})=>po.update(h,f),onSuccess:()=>o.invalidateQueries({queryKey:["customer",e.toString()]})}),u=Y({mutationFn:po.delete,onSuccess:()=>o.invalidateQueries({queryKey:["customer",e.toString()]})}),d=async(h,f)=>{try{await Ye.uploadBankCardDocument(h,f),o.invalidateQueries({queryKey:["customer",e.toString()]})}catch(g){console.error("Upload fehlgeschlagen:",g),alert("Upload fehlgeschlagen")}},m=async h=>{if(confirm("Dokument wirklich löschen?"))try{await Ye.deleteBankCardDocument(h),o.invalidateQueries({queryKey:["customer",e.toString()]})}catch(f){console.error("Löschen fehlgeschlagen:",f),alert("Löschen fehlgeschlagen")}},p=r?t:t.filter(h=>h.isActive);return n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-4 mb-4",children:[s&&n.jsxs(I,{size:"sm",onClick:i,children:[n.jsx(Oe,{className:"w-4 h-4 mr-2"}),"Bankkarte hinzufügen"]}),n.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[n.jsx("input",{type:"checkbox",checked:r,onChange:a,className:"rounded"}),"Inaktive anzeigen"]})]}),p.length>0?n.jsx("div",{className:"space-y-4",children:p.map(h=>n.jsxs("div",{className:`border rounded-lg p-4 ${h.isActive?"":"opacity-50 bg-gray-50"}`,children:[n.jsxs("div",{className:"flex items-start justify-between",children:[n.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[n.jsx(p1,{className:"w-4 h-4 text-gray-400"}),!h.isActive&&n.jsx(he,{variant:"danger",children:"Inaktiv"}),h.expiryDate&&new Date(h.expiryDate)l(h),title:"Bearbeiten",children:n.jsx(We,{className:"w-4 h-4"})}),h.isActive?n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{confirm("Bankkarte deaktivieren?")&&c.mutate({id:h.id,data:{isActive:!1}})},title:"Deaktivieren",children:n.jsx(Pt,{className:"w-4 h-4"})}):n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{confirm("Bankkarte wieder aktivieren?")&&c.mutate({id:h.id,data:{isActive:!0}})},title:"Aktivieren",children:n.jsx(Ee,{className:"w-4 h-4"})}),n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{confirm("Bankkarte wirklich löschen?")&&u.mutate(h.id)},title:"Löschen",children:n.jsx(be,{className:"w-4 h-4 text-red-500"})})]})]}),n.jsxs("p",{className:"font-medium flex items-center gap-1",children:[h.accountHolder,n.jsx(oe,{value:h.accountHolder})]}),n.jsxs("p",{className:"font-mono flex items-center gap-1",children:[h.iban,n.jsx(oe,{value:h.iban})]}),h.bic&&n.jsxs("p",{className:"text-sm text-gray-500 flex items-center gap-1",children:["BIC: ",h.bic,n.jsx(oe,{value:h.bic})]}),h.bankName&&n.jsxs("p",{className:"text-sm text-gray-500 flex items-center gap-1",children:[h.bankName,n.jsx(oe,{value:h.bankName})]}),h.expiryDate&&n.jsxs("p",{className:"text-sm text-gray-500",children:["Gültig bis: ",new Date(h.expiryDate).toLocaleDateString("de-DE")]}),n.jsx("div",{className:"mt-3 pt-3 border-t",children:h.documentPath?n.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[n.jsxs("a",{href:`/api${h.documentPath}`,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:underline text-sm flex items-center gap-1",children:[n.jsx(Ee,{className:"w-4 h-4"}),"Anzeigen"]}),n.jsxs("a",{href:`/api${h.documentPath}`,download:!0,className:"text-blue-600 hover:underline text-sm flex items-center gap-1",children:[n.jsx(tn,{className:"w-4 h-4"}),"Download"]}),s&&n.jsxs(n.Fragment,{children:[n.jsx(xt,{onUpload:f=>d(h.id,f),existingFile:h.documentPath,accept:".pdf",label:"Ersetzen",disabled:!h.isActive}),n.jsxs("button",{onClick:()=>m(h.id),className:"text-red-600 hover:underline text-sm flex items-center gap-1",title:"Dokument löschen",children:[n.jsx(be,{className:"w-4 h-4"}),"Löschen"]})]})]}):s&&h.isActive&&n.jsx(xt,{onUpload:f=>d(h.id,f),accept:".pdf",label:"PDF hochladen"})})]},h.id))}):n.jsx("p",{className:"text-gray-500",children:"Keine Bankkarten vorhanden."})]})}function Q1({customerId:e,documents:t,canEdit:s,showInactive:r,onToggleInactive:a,onAdd:i,onEdit:l}){const o=pe(),c=Y({mutationFn:({id:f,data:g})=>go.update(f,g),onSuccess:()=>o.invalidateQueries({queryKey:["customer",e.toString()]})}),u=Y({mutationFn:go.delete,onSuccess:()=>o.invalidateQueries({queryKey:["customer",e.toString()]})}),d=async(f,g)=>{try{await Ye.uploadIdentityDocument(f,g),o.invalidateQueries({queryKey:["customer",e.toString()]})}catch(b){console.error("Upload fehlgeschlagen:",b),alert("Upload fehlgeschlagen")}},m=async f=>{if(confirm("Dokument wirklich löschen?"))try{await Ye.deleteIdentityDocument(f),o.invalidateQueries({queryKey:["customer",e.toString()]})}catch(g){console.error("Löschen fehlgeschlagen:",g),alert("Löschen fehlgeschlagen")}},p=r?t:t.filter(f=>f.isActive),h={ID_CARD:"Personalausweis",PASSPORT:"Reisepass",DRIVERS_LICENSE:"Führerschein",OTHER:"Sonstiges"};return n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-4 mb-4",children:[s&&n.jsxs(I,{size:"sm",onClick:i,children:[n.jsx(Oe,{className:"w-4 h-4 mr-2"}),"Ausweis hinzufügen"]}),n.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[n.jsx("input",{type:"checkbox",checked:r,onChange:a,className:"rounded"}),"Inaktive anzeigen"]})]}),p.length>0?n.jsx("div",{className:"space-y-4",children:p.map(f=>n.jsxs("div",{className:`border rounded-lg p-4 ${f.isActive?"":"opacity-50 bg-gray-50"}`,children:[n.jsxs("div",{className:"flex items-start justify-between",children:[n.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[n.jsx(vt,{className:"w-4 h-4 text-gray-400"}),n.jsx(he,{children:h[f.type]}),!f.isActive&&n.jsx(he,{variant:"danger",children:"Inaktiv"}),f.expiryDate&&new Date(f.expiryDate)l(f),title:"Bearbeiten",children:n.jsx(We,{className:"w-4 h-4"})}),f.isActive?n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{confirm("Ausweis deaktivieren?")&&c.mutate({id:f.id,data:{isActive:!1}})},title:"Deaktivieren",children:n.jsx(Pt,{className:"w-4 h-4"})}):n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{confirm("Ausweis wieder aktivieren?")&&c.mutate({id:f.id,data:{isActive:!0}})},title:"Aktivieren",children:n.jsx(Ee,{className:"w-4 h-4"})}),n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{confirm("Ausweis wirklich löschen?")&&u.mutate(f.id)},title:"Löschen",children:n.jsx(be,{className:"w-4 h-4 text-red-500"})})]})]}),n.jsxs("p",{className:"font-mono flex items-center gap-1",children:[f.documentNumber,n.jsx(oe,{value:f.documentNumber})]}),f.issuingAuthority&&n.jsxs("p",{className:"text-sm text-gray-500 flex items-center gap-1",children:["Ausgestellt von: ",f.issuingAuthority,n.jsx(oe,{value:f.issuingAuthority})]}),f.expiryDate&&n.jsxs("p",{className:"text-sm text-gray-500",children:["Gültig bis: ",new Date(f.expiryDate).toLocaleDateString("de-DE",{day:"2-digit",month:"2-digit",year:"numeric"})]}),f.type==="DRIVERS_LICENSE"&&f.licenseClasses&&n.jsxs("p",{className:"text-sm text-gray-500 flex items-center gap-1",children:["Klassen: ",f.licenseClasses,n.jsx(oe,{value:f.licenseClasses})]}),f.type==="DRIVERS_LICENSE"&&f.licenseIssueDate&&n.jsxs("p",{className:"text-sm text-gray-500",children:["Klasse B seit: ",new Date(f.licenseIssueDate).toLocaleDateString("de-DE",{day:"2-digit",month:"2-digit",year:"numeric"})]}),n.jsx("div",{className:"mt-3 pt-3 border-t",children:f.documentPath?n.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[n.jsxs("a",{href:`/api${f.documentPath}`,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:underline text-sm flex items-center gap-1",children:[n.jsx(Ee,{className:"w-4 h-4"}),"Anzeigen"]}),n.jsxs("a",{href:`/api${f.documentPath}`,download:!0,className:"text-blue-600 hover:underline text-sm flex items-center gap-1",children:[n.jsx(tn,{className:"w-4 h-4"}),"Download"]}),s&&n.jsxs(n.Fragment,{children:[n.jsx(xt,{onUpload:g=>d(f.id,g),existingFile:f.documentPath,accept:".pdf",label:"Ersetzen",disabled:!f.isActive}),n.jsxs("button",{onClick:()=>m(f.id),className:"text-red-600 hover:underline text-sm flex items-center gap-1",title:"Dokument löschen",children:[n.jsx(be,{className:"w-4 h-4"}),"Löschen"]})]})]}):s&&f.isActive&&n.jsx(xt,{onUpload:g=>d(f.id,g),accept:".pdf",label:"PDF hochladen"})})]},f.id))}):n.jsx("p",{className:"text-gray-500",children:"Keine Ausweise vorhanden."})]})}function H1({customerId:e,meters:t,canEdit:s,showInactive:r,onToggleInactive:a,onAdd:i,onEdit:l}){const[o,c]=w.useState(null),[u,d]=w.useState(null),[m,p]=w.useState(null),h=pe(),f=Y({mutationFn:({id:x,data:N})=>zs.update(x,N),onSuccess:()=>h.invalidateQueries({queryKey:["customer",e.toString()]})}),g=Y({mutationFn:zs.delete,onSuccess:()=>h.invalidateQueries({queryKey:["customer",e.toString()]})}),b=Y({mutationFn:({meterId:x,readingId:N})=>zs.deleteReading(x,N),onSuccess:()=>h.invalidateQueries({queryKey:["customer",e.toString()]})}),y=r?t:t.filter(x=>x.isActive),v=x=>x?[...x].sort((N,k)=>new Date(k.readingDate).getTime()-new Date(N.readingDate).getTime()):[];return n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-4 mb-4",children:[s&&n.jsxs(I,{size:"sm",onClick:i,children:[n.jsx(Oe,{className:"w-4 h-4 mr-2"}),"Zähler hinzufügen"]}),n.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[n.jsx("input",{type:"checkbox",checked:r,onChange:a,className:"rounded"}),"Inaktive anzeigen"]})]}),y.length>0?n.jsx("div",{className:"space-y-4",children:y.map(x=>{const N=v(x.readings),k=u===x.id;return n.jsxs("div",{className:`border rounded-lg p-4 ${x.isActive?"":"opacity-50 bg-gray-50"}`,children:[n.jsxs("div",{className:"flex items-start justify-between",children:[n.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[n.jsx(Xy,{className:"w-4 h-4 text-gray-400"}),n.jsx(he,{variant:x.type==="ELECTRICITY"?"warning":"info",children:x.type==="ELECTRICITY"?"Strom":"Gas"}),!x.isActive&&n.jsx(he,{variant:"danger",children:"Inaktiv"})]}),s&&n.jsxs("div",{className:"flex gap-1",children:[x.isActive&&n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>c(x.id),title:"Zählerstand hinzufügen",children:n.jsx(Oe,{className:"w-4 h-4"})}),n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>l(x),title:"Bearbeiten",children:n.jsx(We,{className:"w-4 h-4"})}),x.isActive?n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{confirm("Zähler deaktivieren?")&&f.mutate({id:x.id,data:{isActive:!1}})},title:"Deaktivieren",children:n.jsx(Pt,{className:"w-4 h-4"})}):n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{confirm("Zähler wieder aktivieren?")&&f.mutate({id:x.id,data:{isActive:!0}})},title:"Aktivieren",children:n.jsx(Ee,{className:"w-4 h-4"})}),n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{confirm("Zähler wirklich löschen? Alle Zählerstände werden ebenfalls gelöscht.")&&g.mutate(x.id)},title:"Löschen",children:n.jsx(be,{className:"w-4 h-4 text-red-500"})})]})]}),n.jsxs("p",{className:"font-mono text-lg flex items-center gap-1",children:[x.meterNumber,n.jsx(oe,{value:x.meterNumber})]}),x.location&&n.jsxs("p",{className:"text-sm text-gray-500 flex items-center gap-1",children:["Standort: ",x.location,n.jsx(oe,{value:x.location})]}),N.length>0&&n.jsxs("div",{className:"mt-3 pt-3 border-t",children:[n.jsxs("div",{className:"flex items-center justify-between mb-2",children:[n.jsx("p",{className:"text-sm font-medium",children:"Zählerstände:"}),N.length>3&&n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>d(k?null:x.id),children:k?"Weniger anzeigen":`Alle ${N.length} anzeigen`})]}),n.jsx("div",{className:"space-y-1",children:(k?N:N.slice(0,3)).map(D=>n.jsxs("div",{className:"flex justify-between items-center text-sm group",children:[n.jsxs("span",{className:"text-gray-500 flex items-center gap-1",children:[new Date(D.readingDate).toLocaleDateString("de-DE"),n.jsx(oe,{value:new Date(D.readingDate).toLocaleDateString("de-DE")})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("span",{className:"font-mono flex items-center gap-1",children:[D.value.toLocaleString("de-DE")," ",D.unit,n.jsx(oe,{value:D.value.toString(),title:"Nur Wert kopieren"}),n.jsx(oe,{value:`${D.value.toLocaleString("de-DE")} ${D.unit}`,title:"Mit Einheit kopieren"})]}),s&&n.jsxs("div",{className:"opacity-0 group-hover:opacity-100 flex gap-1",children:[n.jsx("button",{onClick:()=>p({meterId:x.id,reading:D}),className:"text-gray-400 hover:text-blue-600",title:"Bearbeiten",children:n.jsx(We,{className:"w-3 h-3"})}),n.jsx("button",{onClick:()=>{confirm("Zählerstand wirklich löschen?")&&b.mutate({meterId:x.id,readingId:D.id})},className:"text-gray-400 hover:text-red-600",title:"Löschen",children:n.jsx(be,{className:"w-3 h-3"})})]})]})]},D.id))})]})]},x.id)})}):n.jsx("p",{className:"text-gray-500",children:"Keine Zähler vorhanden."}),o&&n.jsx(op,{isOpen:!0,onClose:()=>c(null),meterId:o,customerId:e}),m&&n.jsx(op,{isOpen:!0,onClose:()=>p(null),meterId:m.meterId,customerId:e,reading:m.reading})]})}function W1({customerId:e,contracts:t}){const{hasPermission:s}=st(),r=Ut(),a=pe(),i=Y({mutationFn:$e.delete,onSuccess:()=>{a.invalidateQueries({queryKey:["customer",e.toString()]}),a.invalidateQueries({queryKey:["customers"]}),a.invalidateQueries({queryKey:["contracts"]})},onError:c=>{alert((c==null?void 0:c.message)||"Fehler beim Löschen des Vertrags")}}),l={ELECTRICITY:"Strom",GAS:"Gas",DSL:"DSL",FIBER:"Glasfaser",MOBILE:"Mobilfunk",TV:"TV",CAR_INSURANCE:"KFZ-Versicherung"},o={ACTIVE:"success",PENDING:"warning",CANCELLED:"danger",EXPIRED:"danger",DRAFT:"default"};return n.jsxs("div",{children:[s("contracts:create")&&n.jsx("div",{className:"mb-4",children:n.jsx(Se,{to:`/contracts/new?customerId=${e}`,children:n.jsxs(I,{size:"sm",children:[n.jsx(Oe,{className:"w-4 h-4 mr-2"}),"Vertrag anlegen"]})})}),t.length>0?n.jsx("div",{className:"space-y-4",children:t.map(c=>n.jsxs("div",{className:"border rounded-lg p-4 hover:bg-gray-50 transition-colors",children:[n.jsxs("div",{className:"flex items-center justify-between mb-2",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("span",{className:"font-mono flex items-center gap-1",children:[c.contractNumber,n.jsx(oe,{value:c.contractNumber})]}),n.jsx(he,{children:l[c.type]}),n.jsx(he,{variant:o[c.status],children:c.status})]}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>r(`/contracts/${c.id}`,{state:{from:"customer",customerId:e.toString()}}),title:"Ansehen",children:n.jsx(Ee,{className:"w-4 h-4"})}),s("contracts:update")&&n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>r(`/contracts/${c.id}/edit`),title:"Bearbeiten",children:n.jsx(We,{className:"w-4 h-4"})}),s("contracts:delete")&&n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{confirm("Vertrag wirklich löschen?")&&i.mutate(c.id)},title:"Löschen",children:n.jsx(be,{className:"w-4 h-4 text-red-500"})})]})]}),c.providerName&&n.jsxs("p",{className:"flex items-center gap-1",children:[c.providerName,c.tariffName&&` - ${c.tariffName}`,n.jsx(oe,{value:c.providerName+(c.tariffName?` - ${c.tariffName}`:"")})]}),c.startDate&&n.jsxs("p",{className:"text-sm text-gray-500",children:["Beginn: ",new Date(c.startDate).toLocaleDateString("de-DE"),c.endDate&&` | Ende: ${new Date(c.endDate).toLocaleDateString("de-DE")}`]})]},c.id))}):n.jsx("p",{className:"text-gray-500",children:"Keine Verträge vorhanden."})]})}function G1({customerId:e}){const[t,s]=w.useState(!1),[r,a]=w.useState(null),[i,l]=w.useState(!1),o=async()=>{var c;if(t){s(!1);return}l(!0);try{const u=await yt.getPortalPassword(e);a(((c=u.data)==null?void 0:c.password)||null),s(!0)}catch(u){console.error("Fehler beim Laden des Passworts:",u),alert("Fehler beim Laden des Passworts")}finally{l(!1)}};return n.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[n.jsx("p",{className:"text-xs text-green-600",children:"Passwort ist gesetzt"}),n.jsx("button",{type:"button",onClick:o,className:"text-xs text-blue-600 hover:underline flex items-center gap-1",disabled:i,children:i?"Laden...":t?n.jsxs(n.Fragment,{children:[n.jsx(Pt,{className:"w-3 h-3"}),"Verbergen"]}):n.jsxs(n.Fragment,{children:[n.jsx(Ee,{className:"w-3 h-3"}),"Anzeigen"]})}),t&&r&&n.jsxs("span",{className:"text-xs font-mono bg-gray-100 px-2 py-1 rounded flex items-center gap-1",children:[r,n.jsx(oe,{value:r})]}),t&&!r&&n.jsx("span",{className:"text-xs text-gray-500",children:"(Passwort nicht verfügbar)"})]})}function Z1({customerId:e,canEdit:t}){const s=pe(),[r,a]=w.useState(!1),[i,l]=w.useState(""),[o,c]=w.useState(""),[u,d]=w.useState([]),[m,p]=w.useState(!1),{data:h,isLoading:f}=ge({queryKey:["customer-portal",e],queryFn:()=>yt.getPortalSettings(e)}),{data:g,isLoading:b}=ge({queryKey:["customer-representatives",e],queryFn:()=>yt.getRepresentatives(e)}),y=Y({mutationFn:S=>yt.updatePortalSettings(e,S),onSuccess:()=>{s.invalidateQueries({queryKey:["customer-portal",e]})}}),v=Y({mutationFn:S=>yt.setPortalPassword(e,S),onSuccess:()=>{l(""),s.invalidateQueries({queryKey:["customer-portal",e]}),alert("Passwort wurde gesetzt")},onError:S=>{alert(S.message)}}),x=Y({mutationFn:S=>yt.addRepresentative(e,S),onSuccess:()=>{s.invalidateQueries({queryKey:["customer-representatives",e]}),c(""),d([])},onError:S=>{alert(S.message)}}),N=Y({mutationFn:S=>yt.removeRepresentative(e,S),onSuccess:()=>{s.invalidateQueries({queryKey:["customer-representatives",e]})}}),k=async()=>{if(!(o.length<2)){p(!0);try{const S=await yt.searchForRepresentative(e,o);d(S.data||[])}catch(S){console.error("Suche fehlgeschlagen:",S)}finally{p(!1)}}};if(f||b)return n.jsx("div",{className:"text-center py-4 text-gray-500",children:"Laden..."});const D=h==null?void 0:h.data,F=(g==null?void 0:g.data)||[];return n.jsxs("div",{className:"space-y-6",children:[n.jsxs("div",{className:"border rounded-lg p-4",children:[n.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[n.jsx(uh,{className:"w-5 h-5 text-gray-400"}),n.jsx("h3",{className:"font-medium",children:"Portal-Zugang"})]}),n.jsxs("div",{className:"space-y-4",children:[n.jsxs("label",{className:"flex items-center gap-3",children:[n.jsx("input",{type:"checkbox",checked:(D==null?void 0:D.portalEnabled)||!1,onChange:S=>y.mutate({portalEnabled:S.target.checked}),className:"rounded w-5 h-5",disabled:!t}),n.jsx("span",{children:"Portal aktiviert"}),(D==null?void 0:D.portalEnabled)&&n.jsx(he,{variant:"success",children:"Aktiv"})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Portal E-Mail"}),n.jsx("div",{className:"flex gap-2",children:n.jsx($,{value:(D==null?void 0:D.portalEmail)||"",onChange:S=>y.mutate({portalEmail:S.target.value||null}),placeholder:"portal@example.com",disabled:!t||!(D!=null&&D.portalEnabled),className:"flex-1"})}),n.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"Diese E-Mail wird für den Login ins Kundenportal verwendet."})]}),(D==null?void 0:D.portalEnabled)&&n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:D!=null&&D.hasPassword?"Neues Passwort setzen":"Passwort setzen"}),n.jsxs("div",{className:"flex gap-2",children:[n.jsxs("div",{className:"relative flex-1",children:[n.jsx($,{type:r?"text":"password",value:i,onChange:S=>l(S.target.value),placeholder:"Mindestens 6 Zeichen",disabled:!t}),n.jsx("button",{type:"button",onClick:()=>a(!r),className:"absolute right-3 top-1/2 -translate-y-1/2 text-gray-400",children:r?n.jsx(Pt,{className:"w-4 h-4"}):n.jsx(Ee,{className:"w-4 h-4"})})]}),n.jsx(I,{onClick:()=>v.mutate(i),disabled:!t||i.length<6||v.isPending,children:v.isPending?"Speichern...":"Setzen"})]}),(D==null?void 0:D.hasPassword)&&n.jsx(G1,{customerId:e})]}),(D==null?void 0:D.portalLastLogin)&&n.jsxs("p",{className:"text-sm text-gray-500",children:["Letzte Anmeldung: ",new Date(D.portalLastLogin).toLocaleString("de-DE")]})]})]}),n.jsxs("div",{className:"border rounded-lg p-4",children:[n.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[n.jsx(A1,{className:"w-5 h-5 text-gray-400"}),n.jsx("h3",{className:"font-medium",children:"Vertreter (können Verträge einsehen)"})]}),n.jsx("p",{className:"text-sm text-gray-500 mb-4",children:"Hier können Sie anderen Kunden erlauben, die Verträge dieses Kunden einzusehen. Beispiel: Der Sohn kann die Verträge seiner Mutter einsehen."}),t&&n.jsxs("div",{className:"mb-4",children:[n.jsxs("div",{className:"flex gap-2",children:[n.jsx($,{value:o,onChange:S=>c(S.target.value),placeholder:"Kunden suchen (Name, Kundennummer)...",onKeyDown:S=>S.key==="Enter"&&k(),className:"flex-1"}),n.jsx(I,{variant:"secondary",onClick:k,disabled:o.length<2||m,children:n.jsx(Wo,{className:"w-4 h-4"})})]}),n.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"Nur Kunden mit aktiviertem Portal können als Vertreter hinzugefügt werden."}),u.length>0&&n.jsx("div",{className:"mt-2 border rounded-lg divide-y",children:u.map(S=>n.jsxs("div",{className:"flex items-center justify-between p-3 hover:bg-gray-50",children:[n.jsxs("div",{children:[n.jsx("p",{className:"font-medium",children:S.companyName||`${S.firstName} ${S.lastName}`}),n.jsx("p",{className:"text-sm text-gray-500",children:S.customerNumber})]}),n.jsxs(I,{size:"sm",onClick:()=>x.mutate(S.id),disabled:x.isPending,children:[n.jsx(Oe,{className:"w-4 h-4 mr-1"}),"Hinzufügen"]})]},S.id))})]}),F.length>0?n.jsx("div",{className:"space-y-2",children:F.map(S=>{var L,T,_,K;return n.jsxs("div",{className:"flex items-center justify-between p-3 bg-gray-50 rounded-lg",children:[n.jsxs("div",{children:[n.jsx("p",{className:"font-medium",children:((L=S.representative)==null?void 0:L.companyName)||`${(T=S.representative)==null?void 0:T.firstName} ${(_=S.representative)==null?void 0:_.lastName}`}),n.jsx("p",{className:"text-sm text-gray-500",children:(K=S.representative)==null?void 0:K.customerNumber})]}),t&&n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{confirm("Vertreter wirklich entfernen?")&&N.mutate(S.representativeId)},children:n.jsx(wa,{className:"w-4 h-4 text-red-500"})})]},S.id)})}):n.jsx("p",{className:"text-gray-500 text-sm",children:"Keine Vertreter konfiguriert."})]})]})}function rp({isOpen:e,onClose:t,customerId:s,address:r}){const a=pe(),i=!!r,l=()=>({type:(r==null?void 0:r.type)||"DELIVERY_RESIDENCE",street:(r==null?void 0:r.street)||"",houseNumber:(r==null?void 0:r.houseNumber)||"",postalCode:(r==null?void 0:r.postalCode)||"",city:(r==null?void 0:r.city)||"",country:(r==null?void 0:r.country)||"Deutschland",isDefault:(r==null?void 0:r.isDefault)||!1}),[o,c]=w.useState(l),u=Y({mutationFn:h=>Ju.create(s,h),onSuccess:()=>{a.invalidateQueries({queryKey:["customer",s.toString()]}),t(),c({type:"DELIVERY_RESIDENCE",street:"",houseNumber:"",postalCode:"",city:"",country:"Deutschland",isDefault:!1})}}),d=Y({mutationFn:h=>Ju.update(r.id,h),onSuccess:()=>{a.invalidateQueries({queryKey:["customer",s.toString()]}),t()}}),m=h=>{h.preventDefault(),i?d.mutate(o):u.mutate(o)},p=u.isPending||d.isPending;return i&&o.street!==r.street&&c(l()),n.jsx(dt,{isOpen:e,onClose:t,title:i?"Adresse bearbeiten":"Adresse hinzufügen",children:n.jsxs("form",{onSubmit:m,className:"space-y-4",children:[n.jsx(Le,{label:"Adresstyp",value:o.type,onChange:h=>c({...o,type:h.target.value}),options:[{value:"DELIVERY_RESIDENCE",label:"Liefer-/Meldeadresse"},{value:"BILLING",label:"Rechnungsadresse"}]}),n.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[n.jsx("div",{className:"col-span-2",children:n.jsx($,{label:"Straße",value:o.street,onChange:h=>c({...o,street:h.target.value}),required:!0})}),n.jsx($,{label:"Hausnr.",value:o.houseNumber,onChange:h=>c({...o,houseNumber:h.target.value}),required:!0})]}),n.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[n.jsx($,{label:"PLZ",value:o.postalCode,onChange:h=>c({...o,postalCode:h.target.value}),required:!0}),n.jsx("div",{className:"col-span-2",children:n.jsx($,{label:"Ort",value:o.city,onChange:h=>c({...o,city:h.target.value}),required:!0})})]}),n.jsx($,{label:"Land",value:o.country,onChange:h=>c({...o,country:h.target.value})}),n.jsxs("label",{className:"flex items-center gap-2",children:[n.jsx("input",{type:"checkbox",checked:o.isDefault,onChange:h=>c({...o,isDefault:h.target.checked}),className:"rounded"}),"Als Standard setzen"]}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx(I,{type:"button",variant:"secondary",onClick:t,children:"Abbrechen"}),n.jsx(I,{type:"submit",disabled:p,children:p?"Speichern...":"Speichern"})]})]})})}function ap({isOpen:e,onClose:t,customerId:s,bankCard:r}){const a=pe(),i=!!r,l=()=>({accountHolder:(r==null?void 0:r.accountHolder)||"",iban:(r==null?void 0:r.iban)||"",bic:(r==null?void 0:r.bic)||"",bankName:(r==null?void 0:r.bankName)||"",expiryDate:r!=null&&r.expiryDate?new Date(r.expiryDate).toISOString().split("T")[0]:"",isActive:(r==null?void 0:r.isActive)??!0}),[o,c]=w.useState(l);w.useState(()=>{c(l())});const u=Y({mutationFn:h=>po.create(s,h),onSuccess:()=>{a.invalidateQueries({queryKey:["customer",s.toString()]}),t(),c({accountHolder:"",iban:"",bic:"",bankName:"",expiryDate:"",isActive:!0})}}),d=Y({mutationFn:h=>po.update(r.id,h),onSuccess:()=>{a.invalidateQueries({queryKey:["customer",s.toString()]}),t()}}),m=h=>{h.preventDefault();const f={...o,expiryDate:o.expiryDate?new Date(o.expiryDate):void 0};i?d.mutate(f):u.mutate(f)},p=u.isPending||d.isPending;return i&&o.iban!==r.iban&&c(l()),n.jsx(dt,{isOpen:e,onClose:t,title:i?"Bankkarte bearbeiten":"Bankkarte hinzufügen",children:n.jsxs("form",{onSubmit:m,className:"space-y-4",children:[n.jsx($,{label:"Kontoinhaber",value:o.accountHolder,onChange:h=>c({...o,accountHolder:h.target.value}),required:!0}),n.jsx($,{label:"IBAN",value:o.iban,onChange:h=>c({...o,iban:h.target.value}),required:!0}),n.jsx($,{label:"BIC",value:o.bic,onChange:h=>c({...o,bic:h.target.value})}),n.jsx($,{label:"Bank",value:o.bankName,onChange:h=>c({...o,bankName:h.target.value})}),n.jsx($,{label:"Ablaufdatum",type:"date",value:o.expiryDate,onChange:h=>c({...o,expiryDate:h.target.value}),onClear:()=>c({...o,expiryDate:""})}),i&&n.jsxs("label",{className:"flex items-center gap-2",children:[n.jsx("input",{type:"checkbox",checked:o.isActive,onChange:h=>c({...o,isActive:h.target.checked}),className:"rounded"}),"Aktiv"]}),!i&&n.jsx("p",{className:"text-sm text-gray-500 bg-gray-50 p-3 rounded",children:"Dokument-Upload ist nach dem Speichern in der Übersicht möglich."}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx(I,{type:"button",variant:"secondary",onClick:t,children:"Abbrechen"}),n.jsx(I,{type:"submit",disabled:p,children:p?"Speichern...":"Speichern"})]})]})})}function ip({isOpen:e,onClose:t,customerId:s,document:r}){const a=pe(),i=!!r,l=()=>({type:(r==null?void 0:r.type)||"ID_CARD",documentNumber:(r==null?void 0:r.documentNumber)||"",issuingAuthority:(r==null?void 0:r.issuingAuthority)||"",issueDate:r!=null&&r.issueDate?new Date(r.issueDate).toISOString().split("T")[0]:"",expiryDate:r!=null&&r.expiryDate?new Date(r.expiryDate).toISOString().split("T")[0]:"",isActive:(r==null?void 0:r.isActive)??!0,licenseClasses:(r==null?void 0:r.licenseClasses)||"",licenseIssueDate:r!=null&&r.licenseIssueDate?new Date(r.licenseIssueDate).toISOString().split("T")[0]:""}),[o,c]=w.useState(l),u=Y({mutationFn:h=>go.create(s,h),onSuccess:()=>{a.invalidateQueries({queryKey:["customer",s.toString()]}),t(),c({type:"ID_CARD",documentNumber:"",issuingAuthority:"",issueDate:"",expiryDate:"",isActive:!0,licenseClasses:"",licenseIssueDate:""})}}),d=Y({mutationFn:h=>go.update(r.id,h),onSuccess:()=>{a.invalidateQueries({queryKey:["customer",s.toString()]}),t()}}),m=h=>{h.preventDefault();const f={...o,issueDate:o.issueDate?new Date(o.issueDate):void 0,expiryDate:o.expiryDate?new Date(o.expiryDate):void 0};o.type==="DRIVERS_LICENSE"?(f.licenseClasses=o.licenseClasses||void 0,f.licenseIssueDate=o.licenseIssueDate?new Date(o.licenseIssueDate):void 0):(delete f.licenseClasses,delete f.licenseIssueDate),i?d.mutate(f):u.mutate(f)},p=u.isPending||d.isPending;return i&&o.documentNumber!==r.documentNumber&&c(l()),n.jsx(dt,{isOpen:e,onClose:t,title:i?"Ausweis bearbeiten":"Ausweis hinzufügen",children:n.jsxs("form",{onSubmit:m,className:"space-y-4",children:[n.jsx(Le,{label:"Ausweistyp",value:o.type,onChange:h=>c({...o,type:h.target.value}),options:[{value:"ID_CARD",label:"Personalausweis"},{value:"PASSPORT",label:"Reisepass"},{value:"DRIVERS_LICENSE",label:"Führerschein"},{value:"OTHER",label:"Sonstiges"}]}),n.jsx($,{label:"Ausweisnummer",value:o.documentNumber,onChange:h=>c({...o,documentNumber:h.target.value}),required:!0}),n.jsx($,{label:"Ausstellende Behörde",value:o.issuingAuthority,onChange:h=>c({...o,issuingAuthority:h.target.value})}),n.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[n.jsx($,{label:"Ausstellungsdatum",type:"date",value:o.issueDate,onChange:h=>c({...o,issueDate:h.target.value}),onClear:()=>c({...o,issueDate:""})}),n.jsx($,{label:"Ablaufdatum",type:"date",value:o.expiryDate,onChange:h=>c({...o,expiryDate:h.target.value}),onClear:()=>c({...o,expiryDate:""})})]}),o.type==="DRIVERS_LICENSE"&&n.jsxs(n.Fragment,{children:[n.jsx($,{label:"Führerscheinklassen",value:o.licenseClasses,onChange:h=>c({...o,licenseClasses:h.target.value}),placeholder:"z.B. B, BE, AM, L"}),n.jsx($,{label:"Erwerb Klasse B (Pkw)",type:"date",value:o.licenseIssueDate,onChange:h=>c({...o,licenseIssueDate:h.target.value}),onClear:()=>c({...o,licenseIssueDate:""})})]}),i&&n.jsxs("label",{className:"flex items-center gap-2",children:[n.jsx("input",{type:"checkbox",checked:o.isActive,onChange:h=>c({...o,isActive:h.target.checked}),className:"rounded"}),"Aktiv"]}),!i&&n.jsx("p",{className:"text-sm text-gray-500 bg-gray-50 p-3 rounded",children:"Dokument-Upload ist nach dem Speichern in der Übersicht möglich."}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx(I,{type:"button",variant:"secondary",onClick:t,children:"Abbrechen"}),n.jsx(I,{type:"submit",disabled:p,children:p?"Speichern...":"Speichern"})]})]})})}function lp({isOpen:e,onClose:t,customerId:s,meter:r}){const a=pe(),i=!!r,l=()=>({meterNumber:(r==null?void 0:r.meterNumber)||"",type:(r==null?void 0:r.type)||"ELECTRICITY",location:(r==null?void 0:r.location)||"",isActive:(r==null?void 0:r.isActive)??!0}),[o,c]=w.useState(l),u=Y({mutationFn:h=>zs.create(s,h),onSuccess:()=>{a.invalidateQueries({queryKey:["customer",s.toString()]}),t(),c({meterNumber:"",type:"ELECTRICITY",location:"",isActive:!0})}}),d=Y({mutationFn:h=>zs.update(r.id,h),onSuccess:()=>{a.invalidateQueries({queryKey:["customer",s.toString()]}),t()}}),m=h=>{h.preventDefault(),i?d.mutate(o):u.mutate(o)},p=u.isPending||d.isPending;return i&&o.meterNumber!==r.meterNumber&&c(l()),n.jsx(dt,{isOpen:e,onClose:t,title:i?"Zähler bearbeiten":"Zähler hinzufügen",children:n.jsxs("form",{onSubmit:m,className:"space-y-4",children:[n.jsx($,{label:"Zählernummer",value:o.meterNumber,onChange:h=>c({...o,meterNumber:h.target.value}),required:!0}),n.jsx(Le,{label:"Zählertyp",value:o.type,onChange:h=>c({...o,type:h.target.value}),options:[{value:"ELECTRICITY",label:"Strom"},{value:"GAS",label:"Gas"}]}),n.jsx($,{label:"Standort",value:o.location,onChange:h=>c({...o,location:h.target.value}),placeholder:"z.B. Keller, Wohnung"}),i&&n.jsxs("label",{className:"flex items-center gap-2",children:[n.jsx("input",{type:"checkbox",checked:o.isActive,onChange:h=>c({...o,isActive:h.target.checked}),className:"rounded"}),"Aktiv"]}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx(I,{type:"button",variant:"secondary",onClick:t,children:"Abbrechen"}),n.jsx(I,{type:"submit",disabled:p,children:p?"Speichern...":"Speichern"})]})]})})}function op({isOpen:e,onClose:t,meterId:s,customerId:r,reading:a}){const i=pe(),l=!!a,o=()=>{var f;return{readingDate:a!=null&&a.readingDate?new Date(a.readingDate).toISOString().split("T")[0]:new Date().toISOString().split("T")[0],value:((f=a==null?void 0:a.value)==null?void 0:f.toString())||"",unit:(a==null?void 0:a.unit)||"kWh",notes:(a==null?void 0:a.notes)||""}},[c,u]=w.useState(o),d=Y({mutationFn:f=>zs.addReading(s,f),onSuccess:()=>{i.invalidateQueries({queryKey:["customer",r.toString()]}),t()}}),m=Y({mutationFn:f=>zs.updateReading(s,a.id,f),onSuccess:()=>{i.invalidateQueries({queryKey:["customer",r.toString()]}),t()}}),p=f=>{f.preventDefault();const g={readingDate:new Date(c.readingDate),value:parseFloat(c.value),unit:c.unit,notes:c.notes||void 0};l?m.mutate(g):d.mutate(g)},h=d.isPending||m.isPending;return l&&c.value!==a.value.toString()&&u(o()),n.jsx(dt,{isOpen:e,onClose:t,title:l?"Zählerstand bearbeiten":"Zählerstand erfassen",children:n.jsxs("form",{onSubmit:p,className:"space-y-4",children:[n.jsx($,{label:"Ablesedatum",type:"date",value:c.readingDate,onChange:f=>u({...c,readingDate:f.target.value}),required:!0}),n.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[n.jsx("div",{className:"col-span-2",children:n.jsx($,{label:"Zählerstand",type:"number",step:"0.01",value:c.value,onChange:f=>u({...c,value:f.target.value}),required:!0})}),n.jsx(Le,{label:"Einheit",value:c.unit,onChange:f=>u({...c,unit:f.target.value}),options:[{value:"kWh",label:"kWh"},{value:"m³",label:"m³"}]})]}),n.jsx($,{label:"Notizen",value:c.notes,onChange:f=>u({...c,notes:f.target.value}),placeholder:"Optionale Notizen..."}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx(I,{type:"button",variant:"secondary",onClick:t,children:"Abbrechen"}),n.jsx(I,{type:"submit",disabled:h,children:h?"Speichern...":"Speichern"})]})]})})}const Tc="@stressfrei-wechseln.de";function Y1({customerId:e,emails:t,canEdit:s,showInactive:r,onToggleInactive:a,onAdd:i,onEdit:l}){const o=pe(),c=Y({mutationFn:({id:m,data:p})=>xo.update(m,p),onSuccess:()=>o.invalidateQueries({queryKey:["customer",e.toString()]})}),u=Y({mutationFn:xo.delete,onSuccess:()=>o.invalidateQueries({queryKey:["customer",e.toString()]})}),d=r?t:t.filter(m=>m.isActive);return n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-4 mb-4",children:[s&&n.jsxs(I,{size:"sm",onClick:i,children:[n.jsx(Oe,{className:"w-4 h-4 mr-2"}),"Adresse hinzufügen"]}),n.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[n.jsx("input",{type:"checkbox",checked:r,onChange:a,className:"rounded"}),"Inaktive anzeigen"]})]}),n.jsxs("p",{className:"text-sm text-gray-500 mb-4 bg-blue-50 border border-blue-200 rounded-lg p-3",children:[n.jsx("strong",{children:"Hinweis:"})," Hier werden E-Mail-Weiterleitungsadressen verwaltet, die für die Registrierung bei Anbietern verwendet werden. E-Mails an diese Adressen werden sowohl an den Kunden als auch an Sie weitergeleitet."]}),d.length>0?n.jsx("div",{className:"space-y-3",children:d.map(m=>n.jsx("div",{className:`border rounded-lg p-4 ${m.isActive?"":"opacity-50 bg-gray-50"}`,children:n.jsxs("div",{className:"flex items-start justify-between",children:[n.jsxs("div",{className:"flex-1",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(ev,{className:"w-4 h-4 text-gray-400"}),n.jsx("span",{className:"font-mono text-sm",children:m.email}),n.jsx(oe,{value:m.email}),!m.isActive&&n.jsx(he,{variant:"danger",children:"Inaktiv"})]}),m.notes&&n.jsxs("div",{className:"flex items-center gap-2 mt-1 text-sm text-gray-500",children:[n.jsx(vt,{className:"w-4 h-4 flex-shrink-0"}),n.jsx("span",{children:m.notes})]})]}),s&&n.jsxs("div",{className:"flex gap-1",children:[n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>l(m),title:"Bearbeiten",children:n.jsx(We,{className:"w-4 h-4"})}),m.isActive?n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{confirm("Adresse deaktivieren?")&&c.mutate({id:m.id,data:{isActive:!1}})},title:"Deaktivieren",children:n.jsx(Pt,{className:"w-4 h-4"})}):n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{confirm("Adresse wieder aktivieren?")&&c.mutate({id:m.id,data:{isActive:!0}})},title:"Aktivieren",children:n.jsx(Ee,{className:"w-4 h-4"})}),n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{confirm("Adresse wirklich löschen?")&&u.mutate(m.id)},title:"Löschen",children:n.jsx(be,{className:"w-4 h-4 text-red-500"})})]})]})},m.id))}):n.jsx("p",{className:"text-gray-500",children:"Keine Stressfrei-Wechseln Adressen vorhanden."})]})}function cp({isOpen:e,onClose:t,customerId:s,email:r,customerEmail:a}){const[i,l]=w.useState(""),[o,c]=w.useState(""),[u,d]=w.useState(!1),[m,p]=w.useState(null),h=pe(),f=!!r,{data:g}=ge({queryKey:["email-provider-configs"],queryFn:()=>xn.getConfigs(),enabled:e&&!f}),b=((g==null?void 0:g.data)||[]).some(D=>D.isActive&&D.isDefault),y=D=>{if(!D)return"";const F=D.indexOf("@");return F>0?D.substring(0,F):D};w.useEffect(()=>{e&&(r?(l(y(r.email)),c(r.notes||"")):(l(""),c(""),d(!1)),p(null))},[e,r]);const v=Y({mutationFn:async D=>{var F,S,L;if(D.provision&&a){const T=await xn.provisionEmail(i,a);if(!((F=T.data)!=null&&F.success))throw new Error(((S=T.data)==null?void 0:S.error)||((L=T.data)==null?void 0:L.message)||"Provisionierung fehlgeschlagen")}return xo.create(s,{email:D.email,notes:D.notes})},onSuccess:()=>{h.invalidateQueries({queryKey:["customer",s.toString()]}),l(""),c(""),d(!1),t()},onError:D=>{p(D instanceof Error?D.message:"Fehler bei der Provisionierung")}}),x=Y({mutationFn:D=>xo.update(r.id,D),onSuccess:()=>{h.invalidateQueries({queryKey:["customer",s.toString()]}),t()}}),N=D=>{D.preventDefault(),p(null);const F=i+Tc;f?x.mutate({email:F,notes:o||void 0}):v.mutate({email:F,notes:o||void 0,provision:u})},k=v.isPending||x.isPending;return n.jsx(dt,{isOpen:e,onClose:t,title:f?"Adresse bearbeiten":"Adresse hinzufügen",children:n.jsxs("form",{onSubmit:N,className:"space-y-4",children:[n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"E-Mail-Adresse"}),n.jsxs("div",{className:"flex",children:[n.jsx("input",{type:"text",value:i,onChange:D=>l(D.target.value.toLowerCase().replace(/[^a-z0-9._-]/g,"")),placeholder:"kunde-freenet",required:!0,className:"block w-full px-3 py-2 border border-gray-300 rounded-l-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"}),n.jsx("span",{className:"inline-flex items-center px-3 py-2 border border-l-0 border-gray-300 bg-gray-100 text-gray-600 rounded-r-lg text-sm",children:Tc})]}),n.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:["Vollständige Adresse: ",n.jsxs("span",{className:"font-mono",children:[i||"...",Tc]})]})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Notizen (optional)"}),n.jsx("textarea",{value:o,onChange:D=>c(D.target.value),rows:3,className:"block w-full px-3 py-2 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",placeholder:"z.B. für Freenet-Konten, für Klarmobil..."})]}),!f&&b&&a&&n.jsx("div",{className:"bg-blue-50 p-3 rounded-lg",children:n.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[n.jsx("input",{type:"checkbox",checked:u,onChange:D=>d(D.target.checked),className:"mt-1 rounded border-gray-300"}),n.jsxs("div",{children:[n.jsx("span",{className:"text-sm font-medium text-gray-700",children:"Beim E-Mail-Provider anlegen"}),n.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:["Die E-Mail-Weiterleitung wird automatisch auf dem konfigurierten Server erstellt. Weiterleitungsziel: ",a]})]})]})}),m&&n.jsx("div",{className:"bg-red-50 p-3 rounded-lg text-red-700 text-sm",children:m}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx(I,{type:"button",variant:"secondary",onClick:t,children:"Abbrechen"}),n.jsx(I,{type:"submit",disabled:k||!i,children:k?"Speichern...":"Speichern"})]})]})})}var Zi=e=>e.type==="checkbox",nr=e=>e instanceof Date,Vt=e=>e==null;const rv=e=>typeof e=="object";var at=e=>!Vt(e)&&!Array.isArray(e)&&rv(e)&&!nr(e),J1=e=>at(e)&&e.target?Zi(e.target)?e.target.checked:e.target.value:e,X1=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,eS=(e,t)=>e.has(X1(t)),tS=e=>{const t=e.constructor&&e.constructor.prototype;return at(t)&&t.hasOwnProperty("isPrototypeOf")},fh=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function lt(e){if(e instanceof Date)return new Date(e);const t=typeof FileList<"u"&&e instanceof FileList;if(fh&&(e instanceof Blob||t))return e;const s=Array.isArray(e);if(!s&&!(at(e)&&tS(e)))return e;const r=s?[]:Object.create(Object.getPrototypeOf(e));for(const a in e)Object.prototype.hasOwnProperty.call(e,a)&&(r[a]=lt(e[a]));return r}var Go=e=>/^\w*$/.test(e),Ke=e=>e===void 0,ph=e=>Array.isArray(e)?e.filter(Boolean):[],gh=e=>ph(e.replace(/["|']|\]/g,"").split(/\.|\[/)),le=(e,t,s)=>{if(!t||!at(e))return s;const r=(Go(t)?[t]:gh(t)).reduce((a,i)=>Vt(a)?a:a[i],e);return Ke(r)||r===e?Ke(e[t])?s:e[t]:r},Fs=e=>typeof e=="boolean",ws=e=>typeof e=="function",Ue=(e,t,s)=>{let r=-1;const a=Go(t)?[t]:gh(t),i=a.length,l=i-1;for(;++r{const a={defaultValues:t._defaultValues};for(const i in e)Object.defineProperty(a,i,{get:()=>{const l=i;return t._proxyFormState[l]!==Ss.all&&(t._proxyFormState[l]=!r||Ss.all),e[l]}});return a};const rS=typeof window<"u"?Nt.useLayoutEffect:Nt.useEffect;var ts=e=>typeof e=="string",aS=(e,t,s,r,a)=>ts(e)?(r&&t.watch.add(e),le(s,e,a)):Array.isArray(e)?e.map(i=>(r&&t.watch.add(i),le(s,i))):(r&&(t.watchAll=!0),s),ed=e=>Vt(e)||!rv(e);function jn(e,t,s=new WeakSet){if(ed(e)||ed(t))return Object.is(e,t);if(nr(e)&&nr(t))return Object.is(e.getTime(),t.getTime());const r=Object.keys(e),a=Object.keys(t);if(r.length!==a.length)return!1;if(s.has(e)||s.has(t))return!0;s.add(e),s.add(t);for(const i of r){const l=e[i];if(!a.includes(i))return!1;if(i!=="ref"){const o=t[i];if(nr(l)&&nr(o)||at(l)&&at(o)||Array.isArray(l)&&Array.isArray(o)?!jn(l,o,s):!Object.is(l,o))return!1}}return!0}const iS=Nt.createContext(null);iS.displayName="HookFormContext";var lS=(e,t,s,r,a)=>t?{...s[e],types:{...s[e]&&s[e].types?s[e].types:{},[r]:a||!0}}:{},li=e=>Array.isArray(e)?e:[e],dp=()=>{let e=[];return{get observers(){return e},next:a=>{for(const i of e)i.next&&i.next(a)},subscribe:a=>(e.push(a),{unsubscribe:()=>{e=e.filter(i=>i!==a)}}),unsubscribe:()=>{e=[]}}};function av(e,t){const s={};for(const r in e)if(e.hasOwnProperty(r)){const a=e[r],i=t[r];if(a&&at(a)&&i){const l=av(a,i);at(l)&&(s[r]=l)}else e[r]&&(s[r]=i)}return s}var Mt=e=>at(e)&&!Object.keys(e).length,xh=e=>e.type==="file",yo=e=>{if(!fh)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},iv=e=>e.type==="select-multiple",yh=e=>e.type==="radio",oS=e=>yh(e)||Zi(e),Fc=e=>yo(e)&&e.isConnected;function cS(e,t){const s=t.slice(0,-1).length;let r=0;for(;r{for(const t in e)if(ws(e[t]))return!0;return!1};function lv(e){return Array.isArray(e)||at(e)&&!dS(e)}function td(e,t={}){for(const s in e){const r=e[s];lv(r)?(t[s]=Array.isArray(r)?[]:{},td(r,t[s])):Ke(r)||(t[s]=!0)}return t}function Ir(e,t,s){s||(s=td(t));for(const r in e){const a=e[r];if(lv(a))Ke(t)||ed(s[r])?s[r]=td(a,Array.isArray(a)?[]:{}):Ir(a,Vt(t)?{}:t[r],s[r]);else{const i=t[r];s[r]=!jn(a,i)}}return s}const hp={value:!1,isValid:!1},mp={value:!0,isValid:!0};var ov=e=>{if(Array.isArray(e)){if(e.length>1){const t=e.filter(s=>s&&s.checked&&!s.disabled).map(s=>s.value);return{value:t,isValid:!!t.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!Ke(e[0].attributes.value)?Ke(e[0].value)||e[0].value===""?mp:{value:e[0].value,isValid:!0}:mp:hp}return hp},cv=(e,{valueAsNumber:t,valueAsDate:s,setValueAs:r})=>Ke(e)?e:t?e===""?NaN:e&&+e:s&&ts(e)?new Date(e):r?r(e):e;const fp={isValid:!1,value:null};var uv=e=>Array.isArray(e)?e.reduce((t,s)=>s&&s.checked&&!s.disabled?{isValid:!0,value:s.value}:t,fp):fp;function pp(e){const t=e.ref;return xh(t)?t.files:yh(t)?uv(e.refs).value:iv(t)?[...t.selectedOptions].map(({value:s})=>s):Zi(t)?ov(e.refs).value:cv(Ke(t.value)?e.ref.value:t.value,e)}var hS=(e,t,s,r)=>{const a={};for(const i of e){const l=le(t,i);l&&Ue(a,i,l._f)}return{criteriaMode:s,names:[...e],fields:a,shouldUseNativeValidation:r}},vo=e=>e instanceof RegExp,Va=e=>Ke(e)?e:vo(e)?e.source:at(e)?vo(e.value)?e.value.source:e.value:e,gp=e=>({isOnSubmit:!e||e===Ss.onSubmit,isOnBlur:e===Ss.onBlur,isOnChange:e===Ss.onChange,isOnAll:e===Ss.all,isOnTouch:e===Ss.onTouched});const xp="AsyncFunction";var mS=e=>!!e&&!!e.validate&&!!(ws(e.validate)&&e.validate.constructor.name===xp||at(e.validate)&&Object.values(e.validate).find(t=>t.constructor.name===xp)),fS=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate),yp=(e,t,s)=>!s&&(t.watchAll||t.watch.has(e)||[...t.watch].some(r=>e.startsWith(r)&&/^\.\w+/.test(e.slice(r.length))));const oi=(e,t,s,r)=>{for(const a of s||Object.keys(e)){const i=le(e,a);if(i){const{_f:l,...o}=i;if(l){if(l.refs&&l.refs[0]&&t(l.refs[0],a)&&!r)return!0;if(l.ref&&t(l.ref,l.name)&&!r)return!0;if(oi(o,t))break}else if(at(o)&&oi(o,t))break}}};function vp(e,t,s){const r=le(e,s);if(r||Go(s))return{error:r,name:s};const a=s.split(".");for(;a.length;){const i=a.join("."),l=le(t,i),o=le(e,i);if(l&&!Array.isArray(l)&&s!==i)return{name:s};if(o&&o.type)return{name:i,error:o};if(o&&o.root&&o.root.type)return{name:`${i}.root`,error:o.root};a.pop()}return{name:s}}var pS=(e,t,s,r)=>{s(e);const{name:a,...i}=e;return Mt(i)||Object.keys(i).length>=Object.keys(t).length||Object.keys(i).find(l=>t[l]===(!r||Ss.all))},gS=(e,t,s)=>!e||!t||e===t||li(e).some(r=>r&&(s?r===t:r.startsWith(t)||t.startsWith(r))),xS=(e,t,s,r,a)=>a.isOnAll?!1:!s&&a.isOnTouch?!(t||e):(s?r.isOnBlur:a.isOnBlur)?!e:(s?r.isOnChange:a.isOnChange)?e:!0,yS=(e,t)=>!ph(le(e,t)).length&&nt(e,t),vS=(e,t,s)=>{const r=li(le(e,s));return Ue(r,"root",t[s]),Ue(e,s,r),e};function jp(e,t,s="validate"){if(ts(e)||Array.isArray(e)&&e.every(ts)||Fs(e)&&!e)return{type:s,message:ts(e)?e:"",ref:t}}var Fr=e=>at(e)&&!vo(e)?e:{value:e,message:""},bp=async(e,t,s,r,a,i)=>{const{ref:l,refs:o,required:c,maxLength:u,minLength:d,min:m,max:p,pattern:h,validate:f,name:g,valueAsNumber:b,mount:y}=e._f,v=le(s,g);if(!y||t.has(g))return{};const x=o?o[0]:l,N=K=>{a&&x.reportValidity&&(x.setCustomValidity(Fs(K)?"":K||""),x.reportValidity())},k={},D=yh(l),F=Zi(l),S=D||F,L=(b||xh(l))&&Ke(l.value)&&Ke(v)||yo(l)&&l.value===""||v===""||Array.isArray(v)&&!v.length,T=lS.bind(null,g,r,k),_=(K,W,Q,z=Ks.maxLength,P=Ks.minLength)=>{const j=K?W:Q;k[g]={type:K?z:P,message:j,ref:l,...T(K?z:P,j)}};if(i?!Array.isArray(v)||!v.length:c&&(!S&&(L||Vt(v))||Fs(v)&&!v||F&&!ov(o).isValid||D&&!uv(o).isValid)){const{value:K,message:W}=ts(c)?{value:!!c,message:c}:Fr(c);if(K&&(k[g]={type:Ks.required,message:W,ref:x,...T(Ks.required,W)},!r))return N(W),k}if(!L&&(!Vt(m)||!Vt(p))){let K,W;const Q=Fr(p),z=Fr(m);if(!Vt(v)&&!isNaN(v)){const P=l.valueAsNumber||v&&+v;Vt(Q.value)||(K=P>Q.value),Vt(z.value)||(W=Pnew Date(new Date().toDateString()+" "+ee),B=l.type=="time",J=l.type=="week";ts(Q.value)&&v&&(K=B?j(v)>j(Q.value):J?v>Q.value:P>new Date(Q.value)),ts(z.value)&&v&&(W=B?j(v)+K.value,z=!Vt(W.value)&&v.length<+W.value;if((Q||z)&&(_(Q,K.message,W.message),!r))return N(k[g].message),k}if(h&&!L&&ts(v)){const{value:K,message:W}=Fr(h);if(vo(K)&&!v.match(K)&&(k[g]={type:Ks.pattern,message:W,ref:l,...T(Ks.pattern,W)},!r))return N(W),k}if(f){if(ws(f)){const K=await f(v,s),W=jp(K,x);if(W&&(k[g]={...W,...T(Ks.validate,W.message)},!r))return N(W.message),k}else if(at(f)){let K={};for(const W in f){if(!Mt(K)&&!r)break;const Q=jp(await f[W](v,s),x,W);Q&&(K={...Q,...T(W,Q.message)},N(Q.message),r&&(k[g]=K))}if(!Mt(K)&&(k[g]={ref:x,...K},!r))return k}}return N(!0),k};const jS={mode:Ss.onSubmit,reValidateMode:Ss.onChange,shouldFocusError:!0};function bS(e={}){let t={...jS,...e},s={submitCount:0,isDirty:!1,isReady:!1,isLoading:ws(t.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{},errors:t.errors||{},disabled:t.disabled||!1},r={},a=at(t.defaultValues)||at(t.values)?lt(t.defaultValues||t.values)||{}:{},i=t.shouldUnregister?{}:lt(a),l={action:!1,mount:!1,watch:!1,keepIsValid:!1},o={mount:new Set,disabled:new Set,unMount:new Set,array:new Set,watch:new Set},c,u=0;const d={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},m={...d};let p={...m};const h={array:dp(),state:dp()},f=t.criteriaMode===Ss.all,g=E=>M=>{clearTimeout(u),u=setTimeout(E,M)},b=async E=>{if(!l.keepIsValid&&!t.disabled&&(m.isValid||p.isValid||E)){let M;t.resolver?(M=Mt((await S()).errors),y()):M=await T(r,!0),M!==s.isValid&&h.state.next({isValid:M})}},y=(E,M)=>{!t.disabled&&(m.isValidating||m.validatingFields||p.isValidating||p.validatingFields)&&((E||Array.from(o.mount)).forEach(U=>{U&&(M?Ue(s.validatingFields,U,M):nt(s.validatingFields,U))}),h.state.next({validatingFields:s.validatingFields,isValidating:!Mt(s.validatingFields)}))},v=(E,M=[],U,se,G=!0,H=!0)=>{if(se&&U&&!t.disabled){if(l.action=!0,H&&Array.isArray(le(r,E))){const ce=U(le(r,E),se.argA,se.argB);G&&Ue(r,E,ce)}if(H&&Array.isArray(le(s.errors,E))){const ce=U(le(s.errors,E),se.argA,se.argB);G&&Ue(s.errors,E,ce),yS(s.errors,E)}if((m.touchedFields||p.touchedFields)&&H&&Array.isArray(le(s.touchedFields,E))){const ce=U(le(s.touchedFields,E),se.argA,se.argB);G&&Ue(s.touchedFields,E,ce)}(m.dirtyFields||p.dirtyFields)&&(s.dirtyFields=Ir(a,i)),h.state.next({name:E,isDirty:K(E,M),dirtyFields:s.dirtyFields,errors:s.errors,isValid:s.isValid})}else Ue(i,E,M)},x=(E,M)=>{Ue(s.errors,E,M),h.state.next({errors:s.errors})},N=E=>{s.errors=E,h.state.next({errors:s.errors,isValid:!1})},k=(E,M,U,se)=>{const G=le(r,E);if(G){const H=le(i,E,Ke(U)?le(a,E):U);Ke(H)||se&&se.defaultChecked||M?Ue(i,E,M?H:pp(G._f)):z(E,H),l.mount&&!l.action&&b()}},D=(E,M,U,se,G)=>{let H=!1,ce=!1;const we={name:E};if(!t.disabled){if(!U||se){(m.isDirty||p.isDirty)&&(ce=s.isDirty,s.isDirty=we.isDirty=K(),H=ce!==we.isDirty);const Ae=jn(le(a,E),M);ce=!!le(s.dirtyFields,E),Ae?nt(s.dirtyFields,E):Ue(s.dirtyFields,E,!0),we.dirtyFields=s.dirtyFields,H=H||(m.dirtyFields||p.dirtyFields)&&ce!==!Ae}if(U){const Ae=le(s.touchedFields,E);Ae||(Ue(s.touchedFields,E,U),we.touchedFields=s.touchedFields,H=H||(m.touchedFields||p.touchedFields)&&Ae!==U)}H&&G&&h.state.next(we)}return H?we:{}},F=(E,M,U,se)=>{const G=le(s.errors,E),H=(m.isValid||p.isValid)&&Fs(M)&&s.isValid!==M;if(t.delayError&&U?(c=g(()=>x(E,U)),c(t.delayError)):(clearTimeout(u),c=null,U?Ue(s.errors,E,U):nt(s.errors,E)),(U?!jn(G,U):G)||!Mt(se)||H){const ce={...se,...H&&Fs(M)?{isValid:M}:{},errors:s.errors,name:E};s={...s,...ce},h.state.next(ce)}},S=async E=>(y(E,!0),await t.resolver(i,t.context,hS(E||o.mount,r,t.criteriaMode,t.shouldUseNativeValidation))),L=async E=>{const{errors:M}=await S(E);if(y(E),E)for(const U of E){const se=le(M,U);se?Ue(s.errors,U,se):nt(s.errors,U)}else s.errors=M;return M},T=async(E,M,U={valid:!0})=>{for(const se in E){const G=E[se];if(G){const{_f:H,...ce}=G;if(H){const we=o.array.has(H.name),Ae=G._f&&mS(G._f);Ae&&m.validatingFields&&y([H.name],!0);const ft=await bp(G,o.disabled,i,f,t.shouldUseNativeValidation&&!M,we);if(Ae&&m.validatingFields&&y([H.name]),ft[H.name]&&(U.valid=!1,M||e.shouldUseNativeValidation))break;!M&&(le(ft,H.name)?we?vS(s.errors,ft,H.name):Ue(s.errors,H.name,ft[H.name]):nt(s.errors,H.name))}!Mt(ce)&&await T(ce,M,U)}}return U.valid},_=()=>{for(const E of o.unMount){const M=le(r,E);M&&(M._f.refs?M._f.refs.every(U=>!Fc(U)):!Fc(M._f.ref))&&Tt(E)}o.unMount=new Set},K=(E,M)=>!t.disabled&&(E&&M&&Ue(i,E,M),!jn(me(),a)),W=(E,M,U)=>aS(E,o,{...l.mount?i:Ke(M)?a:ts(E)?{[E]:M}:M},U,M),Q=E=>ph(le(l.mount?i:a,E,t.shouldUnregister?le(a,E,[]):[])),z=(E,M,U={})=>{const se=le(r,E);let G=M;if(se){const H=se._f;H&&(!H.disabled&&Ue(i,E,cv(M,H)),G=yo(H.ref)&&Vt(M)?"":M,iv(H.ref)?[...H.ref.options].forEach(ce=>ce.selected=G.includes(ce.value)):H.refs?Zi(H.ref)?H.refs.forEach(ce=>{(!ce.defaultChecked||!ce.disabled)&&(Array.isArray(G)?ce.checked=!!G.find(we=>we===ce.value):ce.checked=G===ce.value||!!G)}):H.refs.forEach(ce=>ce.checked=ce.value===G):xh(H.ref)?H.ref.value="":(H.ref.value=G,H.ref.type||h.state.next({name:E,values:lt(i)})))}(U.shouldDirty||U.shouldTouch)&&D(E,G,U.shouldTouch,U.shouldDirty,!0),U.shouldValidate&&ee(E)},P=(E,M,U)=>{for(const se in M){if(!M.hasOwnProperty(se))return;const G=M[se],H=E+"."+se,ce=le(r,H);(o.array.has(E)||at(G)||ce&&!ce._f)&&!nr(G)?P(H,G,U):z(H,G,U)}},j=(E,M,U={})=>{const se=le(r,E),G=o.array.has(E),H=lt(M);Ue(i,E,H),G?(h.array.next({name:E,values:lt(i)}),(m.isDirty||m.dirtyFields||p.isDirty||p.dirtyFields)&&U.shouldDirty&&h.state.next({name:E,dirtyFields:Ir(a,i),isDirty:K(E,H)})):se&&!se._f&&!Vt(H)?P(E,H,U):z(E,H,U),yp(E,o)?h.state.next({...s,name:E,values:lt(i)}):h.state.next({name:l.mount?E:void 0,values:lt(i)})},B=async E=>{l.mount=!0;const M=E.target;let U=M.name,se=!0;const G=le(r,U),H=Ae=>{se=Number.isNaN(Ae)||nr(Ae)&&isNaN(Ae.getTime())||jn(Ae,le(i,U,Ae))},ce=gp(t.mode),we=gp(t.reValidateMode);if(G){let Ae,ft;const Bs=M.type?pp(G._f):J1(E),gs=E.type===up.BLUR||E.type===up.FOCUS_OUT,Ji=!fS(G._f)&&!t.resolver&&!le(s.errors,U)&&!G._f.deps||xS(gs,le(s.touchedFields,U),s.isSubmitted,we,ce),Pr=yp(U,o,gs);Ue(i,U,Bs),gs?(!M||!M.readOnly)&&(G._f.onBlur&&G._f.onBlur(E),c&&c(0)):G._f.onChange&&G._f.onChange(E);const Ar=D(U,Bs,gs),Xi=!Mt(Ar)||Pr;if(!gs&&h.state.next({name:U,type:E.type,values:lt(i)}),Ji)return(m.isValid||p.isValid)&&(t.mode==="onBlur"?gs&&b():gs||b()),Xi&&h.state.next({name:U,...Pr?{}:Ar});if(!gs&&Pr&&h.state.next({...s}),t.resolver){const{errors:Fa}=await S([U]);if(y([U]),H(Bs),se){const el=vp(s.errors,r,U),Ia=vp(Fa,r,el.name||U);Ae=Ia.error,U=Ia.name,ft=Mt(Fa)}}else y([U],!0),Ae=(await bp(G,o.disabled,i,f,t.shouldUseNativeValidation))[U],y([U]),H(Bs),se&&(Ae?ft=!1:(m.isValid||p.isValid)&&(ft=await T(r,!0)));se&&(G._f.deps&&(!Array.isArray(G._f.deps)||G._f.deps.length>0)&&ee(G._f.deps),F(U,ft,Ae,Ar))}},J=(E,M)=>{if(le(s.errors,M)&&E.focus)return E.focus(),1},ee=async(E,M={})=>{let U,se;const G=li(E);if(t.resolver){const H=await L(Ke(E)?E:G);U=Mt(H),se=E?!G.some(ce=>le(H,ce)):U}else E?(se=(await Promise.all(G.map(async H=>{const ce=le(r,H);return await T(ce&&ce._f?{[H]:ce}:ce)}))).every(Boolean),!(!se&&!s.isValid)&&b()):se=U=await T(r);return h.state.next({...!ts(E)||(m.isValid||p.isValid)&&U!==s.isValid?{}:{name:E},...t.resolver||!E?{isValid:U}:{},errors:s.errors}),M.shouldFocus&&!se&&oi(r,J,E?G:o.mount),se},me=(E,M)=>{let U={...l.mount?i:a};return M&&(U=av(M.dirtyFields?s.dirtyFields:s.touchedFields,U)),Ke(E)?U:ts(E)?le(U,E):E.map(se=>le(U,se))},ve=(E,M)=>({invalid:!!le((M||s).errors,E),isDirty:!!le((M||s).dirtyFields,E),error:le((M||s).errors,E),isValidating:!!le(s.validatingFields,E),isTouched:!!le((M||s).touchedFields,E)}),it=E=>{E&&li(E).forEach(M=>nt(s.errors,M)),h.state.next({errors:E?s.errors:{}})},V=(E,M,U)=>{const se=(le(r,E,{_f:{}})._f||{}).ref,G=le(s.errors,E)||{},{ref:H,message:ce,type:we,...Ae}=G;Ue(s.errors,E,{...Ae,...M,ref:se}),h.state.next({name:E,errors:s.errors,isValid:!1}),U&&U.shouldFocus&&se&&se.focus&&se.focus()},Ce=(E,M)=>ws(E)?h.state.subscribe({next:U=>"values"in U&&E(W(void 0,M),U)}):W(E,M,!0),Me=E=>h.state.subscribe({next:M=>{gS(E.name,M.name,E.exact)&&pS(M,E.formState||m,Yo,E.reRenderRoot)&&E.callback({values:{...i},...s,...M,defaultValues:a})}}).unsubscribe,ht=E=>(l.mount=!0,p={...p,...E.formState},Me({...E,formState:{...d,...E.formState}})),Tt=(E,M={})=>{for(const U of E?li(E):o.mount)o.mount.delete(U),o.array.delete(U),M.keepValue||(nt(r,U),nt(i,U)),!M.keepError&&nt(s.errors,U),!M.keepDirty&&nt(s.dirtyFields,U),!M.keepTouched&&nt(s.touchedFields,U),!M.keepIsValidating&&nt(s.validatingFields,U),!t.shouldUnregister&&!M.keepDefaultValue&&nt(a,U);h.state.next({values:lt(i)}),h.state.next({...s,...M.keepDirty?{isDirty:K()}:{}}),!M.keepIsValid&&b()},Jt=({disabled:E,name:M})=>{if(Fs(E)&&l.mount||E||o.disabled.has(M)){const G=o.disabled.has(M)!==!!E;E?o.disabled.add(M):o.disabled.delete(M),G&&l.mount&&!l.action&&b()}},Pe=(E,M={})=>{let U=le(r,E);const se=Fs(M.disabled)||Fs(t.disabled);return Ue(r,E,{...U||{},_f:{...U&&U._f?U._f:{ref:{name:E}},name:E,mount:!0,...M}}),o.mount.add(E),U?Jt({disabled:Fs(M.disabled)?M.disabled:t.disabled,name:E}):k(E,!0,M.value),{...se?{disabled:M.disabled||t.disabled}:{},...t.progressive?{required:!!M.required,min:Va(M.min),max:Va(M.max),minLength:Va(M.minLength),maxLength:Va(M.maxLength),pattern:Va(M.pattern)}:{},name:E,onChange:B,onBlur:B,ref:G=>{if(G){Pe(E,M),U=le(r,E);const H=Ke(G.value)&&G.querySelectorAll&&G.querySelectorAll("input,select,textarea")[0]||G,ce=oS(H),we=U._f.refs||[];if(ce?we.find(Ae=>Ae===H):H===U._f.ref)return;Ue(r,E,{_f:{...U._f,...ce?{refs:[...we.filter(Fc),H,...Array.isArray(le(a,E))?[{}]:[]],ref:{type:H.type,name:E}}:{ref:H}}}),k(E,!1,void 0,H)}else U=le(r,E,{}),U._f&&(U._f.mount=!1),(t.shouldUnregister||M.shouldUnregister)&&!(eS(o.array,E)&&l.action)&&o.unMount.add(E)}}},Xt=()=>t.shouldFocusError&&oi(r,J,o.mount),Gn=E=>{Fs(E)&&(h.state.next({disabled:E}),oi(r,(M,U)=>{const se=le(r,U);se&&(M.disabled=se._f.disabled||E,Array.isArray(se._f.refs)&&se._f.refs.forEach(G=>{G.disabled=se._f.disabled||E}))},0,!1))},Er=(E,M)=>async U=>{let se;U&&(U.preventDefault&&U.preventDefault(),U.persist&&U.persist());let G=lt(i);if(h.state.next({isSubmitting:!0}),t.resolver){const{errors:H,values:ce}=await S();y(),s.errors=H,G=lt(ce)}else await T(r);if(o.disabled.size)for(const H of o.disabled)nt(G,H);if(nt(s.errors,"root"),Mt(s.errors)){h.state.next({errors:{}});try{await E(G,U)}catch(H){se=H}}else M&&await M({...s.errors},U),Xt(),setTimeout(Xt);if(h.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:Mt(s.errors)&&!se,submitCount:s.submitCount+1,errors:s.errors}),se)throw se},hn=(E,M={})=>{le(r,E)&&(Ke(M.defaultValue)?j(E,lt(le(a,E))):(j(E,M.defaultValue),Ue(a,E,lt(M.defaultValue))),M.keepTouched||nt(s.touchedFields,E),M.keepDirty||(nt(s.dirtyFields,E),s.isDirty=M.defaultValue?K(E,lt(le(a,E))):K()),M.keepError||(nt(s.errors,E),m.isValid&&b()),h.state.next({...s}))},Dr=(E,M={})=>{const U=E?lt(E):a,se=lt(U),G=Mt(E),H=G?a:se;if(M.keepDefaultValues||(a=U),!M.keepValues){if(M.keepDirtyValues){const ce=new Set([...o.mount,...Object.keys(Ir(a,i))]);for(const we of Array.from(ce)){const Ae=le(s.dirtyFields,we),ft=le(i,we),Bs=le(H,we);Ae&&!Ke(ft)?Ue(H,we,ft):!Ae&&!Ke(Bs)&&j(we,Bs)}}else{if(fh&&Ke(E))for(const ce of o.mount){const we=le(r,ce);if(we&&we._f){const Ae=Array.isArray(we._f.refs)?we._f.refs[0]:we._f.ref;if(yo(Ae)){const ft=Ae.closest("form");if(ft){ft.reset();break}}}}if(M.keepFieldsRef)for(const ce of o.mount)j(ce,le(H,ce));else r={}}i=t.shouldUnregister?M.keepDefaultValues?lt(a):{}:lt(H),h.array.next({values:{...H}}),h.state.next({values:{...H}})}o={mount:M.keepDirtyValues?o.mount:new Set,unMount:new Set,array:new Set,disabled:new Set,watch:new Set,watchAll:!1,focus:""},l.mount=!m.isValid||!!M.keepIsValid||!!M.keepDirtyValues||!t.shouldUnregister&&!Mt(H),l.watch=!!t.shouldUnregister,l.keepIsValid=!!M.keepIsValid,l.action=!1,M.keepErrors||(s.errors={}),h.state.next({submitCount:M.keepSubmitCount?s.submitCount:0,isDirty:G?!1:M.keepDirty?s.isDirty:!!(M.keepDefaultValues&&!jn(E,a)),isSubmitted:M.keepIsSubmitted?s.isSubmitted:!1,dirtyFields:G?{}:M.keepDirtyValues?M.keepDefaultValues&&i?Ir(a,i):s.dirtyFields:M.keepDefaultValues&&E?Ir(a,E):M.keepDirty?s.dirtyFields:{},touchedFields:M.keepTouched?s.touchedFields:{},errors:M.keepErrors?s.errors:{},isSubmitSuccessful:M.keepIsSubmitSuccessful?s.isSubmitSuccessful:!1,isSubmitting:!1,defaultValues:a})},mt=(E,M)=>Dr(ws(E)?E(i):E,{...t.resetOptions,...M}),Zo=(E,M={})=>{const U=le(r,E),se=U&&U._f;if(se){const G=se.refs?se.refs[0]:se.ref;G.focus&&setTimeout(()=>{G.focus(),M.shouldSelect&&ws(G.select)&&G.select()})}},Yo=E=>{s={...s,...E}},Yi={control:{register:Pe,unregister:Tt,getFieldState:ve,handleSubmit:Er,setError:V,_subscribe:Me,_runSchema:S,_updateIsValidating:y,_focusError:Xt,_getWatch:W,_getDirty:K,_setValid:b,_setFieldArray:v,_setDisabledField:Jt,_setErrors:N,_getFieldArray:Q,_reset:Dr,_resetDefaultValues:()=>ws(t.defaultValues)&&t.defaultValues().then(E=>{mt(E,t.resetOptions),h.state.next({isLoading:!1})}),_removeUnmounted:_,_disableForm:Gn,_subjects:h,_proxyFormState:m,get _fields(){return r},get _formValues(){return i},get _state(){return l},set _state(E){l=E},get _defaultValues(){return a},get _names(){return o},set _names(E){o=E},get _formState(){return s},get _options(){return t},set _options(E){t={...t,...E}}},subscribe:ht,trigger:ee,register:Pe,handleSubmit:Er,watch:Ce,setValue:j,getValues:me,reset:mt,resetField:hn,clearErrors:it,unregister:Tt,setError:V,setFocus:Zo,getFieldState:ve};return{...Yi,formControl:Yi}}function dv(e={}){const t=Nt.useRef(void 0),s=Nt.useRef(void 0),[r,a]=Nt.useState({isDirty:!1,isValidating:!1,isLoading:ws(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},validatingFields:{},errors:e.errors||{},disabled:e.disabled||!1,isReady:!1,defaultValues:ws(e.defaultValues)?void 0:e.defaultValues});if(!t.current)if(e.formControl)t.current={...e.formControl,formState:r},e.defaultValues&&!ws(e.defaultValues)&&e.formControl.reset(e.defaultValues,e.resetOptions);else{const{formControl:l,...o}=bS(e);t.current={...o,formState:r}}const i=t.current.control;return i._options=e,rS(()=>{const l=i._subscribe({formState:i._proxyFormState,callback:()=>a({...i._formState}),reRenderRoot:!0});return a(o=>({...o,isReady:!0})),i._formState.isReady=!0,l},[i]),Nt.useEffect(()=>i._disableForm(e.disabled),[i,e.disabled]),Nt.useEffect(()=>{e.mode&&(i._options.mode=e.mode),e.reValidateMode&&(i._options.reValidateMode=e.reValidateMode)},[i,e.mode,e.reValidateMode]),Nt.useEffect(()=>{e.errors&&(i._setErrors(e.errors),i._focusError())},[i,e.errors]),Nt.useEffect(()=>{e.shouldUnregister&&i._subjects.state.next({values:i._getWatch()})},[i,e.shouldUnregister]),Nt.useEffect(()=>{if(i._proxyFormState.isDirty){const l=i._getDirty();l!==r.isDirty&&i._subjects.state.next({isDirty:l})}},[i,r.isDirty]),Nt.useEffect(()=>{var l;e.values&&!jn(e.values,s.current)?(i._reset(e.values,{keepFieldsRef:!0,...i._options.resetOptions}),!((l=i._options.resetOptions)===null||l===void 0)&&l.keepIsValid||i._setValid(),s.current=e.values,a(o=>({...o}))):i._resetDefaultValues()},[i,e.values]),Nt.useEffect(()=>{i._state.mount||(i._setValid(),i._state.mount=!0),i._state.watch&&(i._state.watch=!1,i._subjects.state.next({...i._formState})),i._removeUnmounted()}),t.current.formState=Nt.useMemo(()=>nS(r,i),[i,r]),t.current}function Np(){var y,v;const{id:e}=_o(),t=Ut(),s=pe(),r=!!e,{register:a,handleSubmit:i,reset:l,watch:o,setValue:c,formState:{errors:u}}=dv(),d=o("type"),{data:m}=ge({queryKey:["customer",e],queryFn:()=>yt.getById(parseInt(e)),enabled:r});w.useEffect(()=>{if(m!=null&&m.data){const x={...m.data};x.birthDate&&(x.birthDate=x.birthDate.split("T")[0]),x.foundingDate&&(x.foundingDate=x.foundingDate.split("T")[0]),l(x)}},[m,l]);const p=Y({mutationFn:yt.create,onSuccess:()=>{s.invalidateQueries({queryKey:["customers"]}),t("/customers")}}),h=Y({mutationFn:x=>yt.update(parseInt(e),x),onSuccess:()=>{s.invalidateQueries({queryKey:["customers"]}),s.invalidateQueries({queryKey:["customer",e]}),t(`/customers/${e}`)}}),f=x=>{const N={type:x.type,salutation:x.salutation||void 0,firstName:x.firstName,lastName:x.lastName,companyName:x.companyName||void 0,email:x.email||void 0,phone:x.phone||void 0,mobile:x.mobile||void 0,taxNumber:x.taxNumber||void 0,commercialRegisterNumber:x.commercialRegisterNumber||void 0,notes:x.notes||void 0,birthPlace:x.birthPlace||void 0};x.birthDate&&typeof x.birthDate=="string"&&x.birthDate.trim()!==""?N.birthDate=new Date(x.birthDate).toISOString():N.birthDate=null,x.foundingDate&&typeof x.foundingDate=="string"&&x.foundingDate.trim()!==""?N.foundingDate=new Date(x.foundingDate).toISOString():N.foundingDate=null,r?h.mutate(N):p.mutate(N)},g=p.isPending||h.isPending,b=p.error||h.error;return n.jsxs("div",{children:[n.jsx("h1",{className:"text-2xl font-bold mb-6",children:r?"Kunde bearbeiten":"Neuer Kunde"}),b&&n.jsx("div",{className:"mb-4 p-4 bg-red-50 border border-red-200 text-red-700 rounded-lg",children:b instanceof Error?b.message:"Ein Fehler ist aufgetreten"}),n.jsxs("form",{onSubmit:i(f),children:[n.jsx(Z,{className:"mb-6",title:"Stammdaten",children:n.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[n.jsx(Le,{label:"Kundentyp",...a("type"),options:[{value:"PRIVATE",label:"Privatkunde"},{value:"BUSINESS",label:"Geschäftskunde"}]}),n.jsx(Le,{label:"Anrede",...a("salutation"),options:[{value:"Herr",label:"Herr"},{value:"Frau",label:"Frau"},{value:"Divers",label:"Divers"}]}),n.jsx($,{label:"Vorname",...a("firstName",{required:"Vorname erforderlich"}),error:(y=u.firstName)==null?void 0:y.message}),n.jsx($,{label:"Nachname",...a("lastName",{required:"Nachname erforderlich"}),error:(v=u.lastName)==null?void 0:v.message}),d==="BUSINESS"&&n.jsxs(n.Fragment,{children:[n.jsx($,{label:"Firmenname",...a("companyName"),className:"md:col-span-2"}),n.jsx($,{label:"Gründungsdatum",type:"date",...a("foundingDate"),value:o("foundingDate")||"",onClear:()=>c("foundingDate","")})]}),d!=="BUSINESS"&&n.jsxs(n.Fragment,{children:[n.jsx($,{label:"Geburtsdatum",type:"date",...a("birthDate"),value:o("birthDate")||"",onClear:()=>c("birthDate","")}),n.jsx($,{label:"Geburtsort",...a("birthPlace")})]})]})}),n.jsx(Z,{className:"mb-6",title:"Kontaktdaten",children:n.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[n.jsx($,{label:"E-Mail",type:"email",...a("email")}),n.jsx($,{label:"Telefon",...a("phone")}),n.jsx($,{label:"Mobil",...a("mobile")})]})}),d==="BUSINESS"&&n.jsxs(Z,{className:"mb-6",title:"Geschäftsdaten",children:[n.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[n.jsx($,{label:"Steuernummer",...a("taxNumber")}),n.jsx($,{label:"Handelsregisternummer",...a("commercialRegisterNumber"),placeholder:"z.B. HRB 12345"})]}),r&&n.jsx("p",{className:"mt-4 text-sm text-gray-500",children:"Dokumente (Gewerbeanmeldung, Handelsregisterauszug) können nach dem Speichern in der Kundendetailansicht hochgeladen werden."})]}),n.jsx(Z,{className:"mb-6",title:"Notizen",children:n.jsx("textarea",{...a("notes"),rows:4,className:"block w-full px-3 py-2 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",placeholder:"Interne Notizen..."})}),n.jsxs("div",{className:"flex justify-end gap-4",children:[n.jsx(I,{type:"button",variant:"secondary",onClick:()=>t(-1),children:"Abbrechen"}),n.jsx(I,{type:"submit",disabled:g,children:g?"Speichern...":"Speichern"})]})]})]})}const Ic={ELECTRICITY:"Strom",GAS:"Gas",DSL:"DSL",CABLE:"Kabelinternet",FIBER:"Glasfaser",MOBILE:"Mobilfunk",TV:"TV",CAR_INSURANCE:"KFZ-Versicherung"},Mc={DRAFT:"Entwurf",PENDING:"Ausstehend",ACTIVE:"Aktiv",CANCELLED:"Gekündigt",EXPIRED:"Abgelaufen"},wp={ACTIVE:"success",PENDING:"warning",CANCELLED:"danger",EXPIRED:"danger",DRAFT:"default"};function NS(){const[e,t]=Uo(),s=Ut(),[r,a]=w.useState(e.get("search")||""),[i,l]=w.useState(e.get("type")||""),[o,c]=w.useState(e.get("status")||""),[u,d]=w.useState(parseInt(e.get("page")||"1",10)),{hasPermission:m,isCustomer:p,isCustomerPortal:h,user:f}=st(),g=pe();w.useEffect(()=>{const N=new URLSearchParams;r&&N.set("search",r),i&&N.set("type",i),o&&N.set("status",o),u>1&&N.set("page",u.toString()),t(N,{replace:!0})},[r,i,o,u,t]);const b=Y({mutationFn:$e.delete,onSuccess:()=>{g.invalidateQueries({queryKey:["contracts"]})}}),{data:y,isLoading:v}=ge({queryKey:["contracts",r,i,o,u,p?f==null?void 0:f.customerId:null],queryFn:()=>$e.getAll({search:r||void 0,type:i||void 0,status:o||void 0,page:u,limit:20,customerId:p?f==null?void 0:f.customerId:void 0})}),x=w.useMemo(()=>{if(!h||!(y!=null&&y.data))return null;const N={};for(const k of y.data){const D=k.customerId;if(!N[D]){const F=k.customer?k.customer.companyName||`${k.customer.firstName} ${k.customer.lastName}`:`Kunde ${D}`;N[D]={customerName:F,isOwn:D===(f==null?void 0:f.customerId),contracts:[]}}N[D].contracts.push(k)}return Object.values(N).sort((k,D)=>k.isOwn&&!D.isOwn?-1:!k.isOwn&&D.isOwn?1:k.customerName.localeCompare(D.customerName))},[y==null?void 0:y.data,h,f==null?void 0:f.customerId]);return n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center justify-between mb-6",children:[n.jsx("h1",{className:"text-2xl font-bold",children:"Verträge"}),m("contracts:create")&&!p&&n.jsx(Se,{to:"/contracts/new",children:n.jsxs(I,{children:[n.jsx(Oe,{className:"w-4 h-4 mr-2"}),"Neuer Vertrag"]})})]}),n.jsx(Z,{className:"mb-6",children:n.jsxs("div",{className:"flex gap-4 flex-wrap",children:[n.jsx("div",{className:"flex-1 min-w-[200px]",children:n.jsx($,{placeholder:"Suchen...",value:r,onChange:N=>a(N.target.value)})}),n.jsx(Le,{value:i,onChange:N=>l(N.target.value),options:Object.entries(Ic).map(([N,k])=>({value:N,label:k})),className:"w-48"}),n.jsx(Le,{value:o,onChange:N=>c(N.target.value),options:Object.entries(Mc).map(([N,k])=>({value:N,label:k})),className:"w-48"}),n.jsx(I,{variant:"secondary",children:n.jsx(Wo,{className:"w-4 h-4"})})]})}),v?n.jsx(Z,{children:n.jsx("div",{className:"text-center py-8 text-gray-500",children:"Laden..."})}):y!=null&&y.data&&y.data.length>0?n.jsx(n.Fragment,{children:h&&x?n.jsx("div",{className:"space-y-6",children:x.map(N=>n.jsxs(Z,{children:[n.jsx("div",{className:"flex items-center gap-3 mb-4 pb-3 border-b",children:N.isOwn?n.jsxs(n.Fragment,{children:[n.jsx(hh,{className:"w-5 h-5 text-blue-600"}),n.jsx("h2",{className:"text-lg font-semibold text-gray-900",children:"Meine Verträge"}),n.jsx(he,{variant:"default",children:N.contracts.length})]}):n.jsxs(n.Fragment,{children:[n.jsx(Xr,{className:"w-5 h-5 text-purple-600"}),n.jsxs("h2",{className:"text-lg font-semibold text-gray-900",children:["Verträge von ",N.customerName]}),n.jsx(he,{variant:"default",children:N.contracts.length})]})}),n.jsx("div",{className:"overflow-x-auto",children:n.jsxs("table",{className:"w-full",children:[n.jsx("thead",{children:n.jsxs("tr",{className:"border-b",children:[n.jsx("th",{className:"text-left py-3 px-4 font-medium text-gray-600",children:"Vertragsnr."}),n.jsx("th",{className:"text-left py-3 px-4 font-medium text-gray-600",children:"Typ"}),n.jsx("th",{className:"text-left py-3 px-4 font-medium text-gray-600",children:"Anbieter / Tarif"}),n.jsx("th",{className:"text-left py-3 px-4 font-medium text-gray-600",children:"Status"}),n.jsx("th",{className:"text-left py-3 px-4 font-medium text-gray-600",children:"Beginn"}),n.jsx("th",{className:"text-right py-3 px-4 font-medium text-gray-600",children:"Aktionen"})]})}),n.jsx("tbody",{children:N.contracts.map(k=>n.jsxs("tr",{className:"border-b hover:bg-gray-50",children:[n.jsx("td",{className:"py-3 px-4 font-mono text-sm",children:k.contractNumber}),n.jsx("td",{className:"py-3 px-4",children:n.jsx(he,{children:Ic[k.type]})}),n.jsxs("td",{className:"py-3 px-4",children:[k.providerName||"-",k.tariffName&&n.jsxs("span",{className:"text-gray-500",children:[" / ",k.tariffName]})]}),n.jsx("td",{className:"py-3 px-4",children:n.jsx(he,{variant:wp[k.status],children:Mc[k.status]})}),n.jsx("td",{className:"py-3 px-4",children:k.startDate?new Date(k.startDate).toLocaleDateString("de-DE"):"-"}),n.jsx("td",{className:"py-3 px-4 text-right",children:n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>s(`/contracts/${k.id}`,{state:{from:"contracts"}}),children:n.jsx(Ee,{className:"w-4 h-4"})})})]},k.id))})]})})]},N.isOwn?"own":N.customerName))}):n.jsxs(Z,{children:[n.jsx("div",{className:"overflow-x-auto",children:n.jsxs("table",{className:"w-full",children:[n.jsx("thead",{children:n.jsxs("tr",{className:"border-b",children:[n.jsx("th",{className:"text-left py-3 px-4 font-medium text-gray-600",children:"Vertragsnr."}),!p&&n.jsx("th",{className:"text-left py-3 px-4 font-medium text-gray-600",children:"Kunde"}),n.jsx("th",{className:"text-left py-3 px-4 font-medium text-gray-600",children:"Typ"}),n.jsx("th",{className:"text-left py-3 px-4 font-medium text-gray-600",children:"Anbieter / Tarif"}),n.jsx("th",{className:"text-left py-3 px-4 font-medium text-gray-600",children:"Status"}),n.jsx("th",{className:"text-left py-3 px-4 font-medium text-gray-600",children:"Beginn"}),n.jsx("th",{className:"text-right py-3 px-4 font-medium text-gray-600",children:"Aktionen"})]})}),n.jsx("tbody",{children:y.data.map(N=>n.jsxs("tr",{className:"border-b hover:bg-gray-50",children:[n.jsx("td",{className:"py-3 px-4 font-mono text-sm",children:N.contractNumber}),!p&&n.jsx("td",{className:"py-3 px-4",children:N.customer&&n.jsx(Se,{to:`/customers/${N.customer.id}`,className:"text-blue-600 hover:underline",children:N.customer.companyName||`${N.customer.firstName} ${N.customer.lastName}`})}),n.jsx("td",{className:"py-3 px-4",children:n.jsx(he,{children:Ic[N.type]})}),n.jsxs("td",{className:"py-3 px-4",children:[N.providerName||"-",N.tariffName&&n.jsxs("span",{className:"text-gray-500",children:[" / ",N.tariffName]})]}),n.jsx("td",{className:"py-3 px-4",children:n.jsx(he,{variant:wp[N.status],children:Mc[N.status]})}),n.jsx("td",{className:"py-3 px-4",children:N.startDate?new Date(N.startDate).toLocaleDateString("de-DE"):"-"}),n.jsx("td",{className:"py-3 px-4 text-right",children:n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>s(`/contracts/${N.id}`,{state:{from:"contracts"}}),children:n.jsx(Ee,{className:"w-4 h-4"})}),m("contracts:update")&&!p&&n.jsx(Se,{to:`/contracts/${N.id}/edit`,children:n.jsx(I,{variant:"ghost",size:"sm",children:n.jsx(We,{className:"w-4 h-4"})})}),m("contracts:delete")&&!p&&n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{confirm("Vertrag wirklich löschen?")&&b.mutate(N.id)},children:n.jsx(be,{className:"w-4 h-4 text-red-500"})})]})})]},N.id))})]})}),y.pagination&&y.pagination.totalPages>1&&n.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[n.jsxs("p",{className:"text-sm text-gray-500",children:["Seite ",y.pagination.page," von ",y.pagination.totalPages," (",y.pagination.total," Einträge)"]}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx(I,{variant:"secondary",size:"sm",onClick:()=>d(N=>Math.max(1,N-1)),disabled:u===1,children:"Zurück"}),n.jsx(I,{variant:"secondary",size:"sm",onClick:()=>d(N=>N+1),disabled:u>=y.pagination.totalPages,children:"Weiter"})]})]})]})}):n.jsx(Z,{children:n.jsx("div",{className:"text-center py-8 text-gray-500",children:"Keine Verträge gefunden."})})]})}const wS={ELECTRICITY:"Strom",GAS:"Gas",DSL:"DSL",CABLE:"Kabelinternet",FIBER:"Glasfaser",MOBILE:"Mobilfunk",TV:"TV",CAR_INSURANCE:"KFZ-Versicherung"},SS={DRAFT:"Entwurf",PENDING:"Ausstehend",ACTIVE:"Aktiv",CANCELLED:"Gekündigt",EXPIRED:"Abgelaufen"},kS={ACTIVE:"success",PENDING:"warning",CANCELLED:"danger",EXPIRED:"danger",DRAFT:"default"};function CS(e){const t=e.match(/^(\d+)([TMWJ])$/);if(!t)return!1;const s=parseInt(t[1]),r=t[2];let a=0;return r==="T"?a=s:r==="W"?a=s*7:r==="M"?a=s*30:r==="J"&&(a=s*365),a<=30}function ES({simCard:e}){const[t,s]=w.useState(!1),[r,a]=w.useState(null),[i,l]=w.useState(!1),o=async()=>{if(t)s(!1),a(null);else{l(!0);try{const c=await $e.getSimCardCredentials(e.id);c.data&&(a(c.data),s(!0))}catch{alert("PIN/PUK konnte nicht geladen werden")}finally{l(!1)}}};return n.jsxs("div",{className:"p-3 bg-gray-50 rounded-lg border",children:[n.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.isMain&&n.jsx(he,{variant:"success",children:"Hauptkarte"}),e.isMultisim&&n.jsx(he,{variant:"warning",children:"Multisim"})]}),n.jsxs("dl",{className:"grid grid-cols-2 md:grid-cols-4 gap-3 text-sm",children:[e.phoneNumber&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-gray-500",children:"Rufnummer"}),n.jsxs("dd",{className:"font-mono flex items-center gap-1",children:[e.phoneNumber,n.jsx(oe,{value:e.phoneNumber})]})]}),e.simCardNumber&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-gray-500",children:"SIM-Nr."}),n.jsxs("dd",{className:"font-mono text-xs flex items-center gap-1",children:[e.simCardNumber,n.jsx(oe,{value:e.simCardNumber})]})]}),n.jsxs("div",{children:[n.jsx("dt",{className:"text-gray-500",children:"PIN"}),n.jsx("dd",{className:"font-mono flex items-center gap-1",children:t&&(r!=null&&r.pin)?n.jsxs(n.Fragment,{children:[r.pin,n.jsx(oe,{value:r.pin})]}):"••••"})]}),n.jsxs("div",{children:[n.jsx("dt",{className:"text-gray-500",children:"PUK"}),n.jsx("dd",{className:"font-mono flex items-center gap-1",children:t&&(r!=null&&r.puk)?n.jsxs(n.Fragment,{children:[r.puk,n.jsx(oe,{value:r.puk})]}):"••••••••"})]})]}),n.jsx("div",{className:"mt-2",children:n.jsx(I,{variant:"ghost",size:"sm",onClick:o,disabled:i,children:i?"Laden...":t?n.jsxs(n.Fragment,{children:[n.jsx(Pt,{className:"w-4 h-4 mr-1"})," PIN/PUK verbergen"]}):n.jsxs(n.Fragment,{children:[n.jsx(Ee,{className:"w-4 h-4 mr-1"})," PIN/PUK anzeigen"]})})})]})}function DS({meterId:e,meterType:t,readings:s,contractId:r,canEdit:a}){const[i,l]=w.useState(!1),[o,c]=w.useState(!1),[u,d]=w.useState(null),m=pe(),p=Y({mutationFn:g=>zs.deleteReading(e,g),onSuccess:()=>{m.invalidateQueries({queryKey:["contract",r.toString()]})}}),h=[...s].sort((g,b)=>new Date(b.readingDate).getTime()-new Date(g.readingDate).getTime()),f=t==="ELECTRICITY"?"kWh":"m³";return n.jsxs("div",{className:"mt-4 pt-4 border-t",children:[n.jsxs("div",{className:"flex items-center justify-between mb-3",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(Xy,{className:"w-4 h-4 text-gray-500"}),n.jsx("h4",{className:"text-sm font-medium text-gray-700",children:"Zählerstände"}),n.jsx(he,{variant:"default",children:s.length})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[a&&n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>c(!0),title:"Zählerstand erfassen",children:n.jsx(Oe,{className:"w-4 h-4"})}),s.length>0&&n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>l(!i),children:i?n.jsx(Wy,{className:"w-4 h-4"}):n.jsx(Qo,{className:"w-4 h-4"})})]})]}),i&&s.length>0&&n.jsx("div",{className:"space-y-2 bg-gray-50 rounded-lg p-3",children:h.map(g=>n.jsxs("div",{className:"flex justify-between items-center text-sm group py-1 border-b border-gray-200 last:border-0",children:[n.jsxs("span",{className:"text-gray-500 flex items-center gap-1",children:[new Date(g.readingDate).toLocaleDateString("de-DE"),n.jsx(oe,{value:new Date(g.readingDate).toLocaleDateString("de-DE")})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("span",{className:"font-mono flex items-center gap-1",children:[g.value.toLocaleString("de-DE")," ",g.unit,n.jsx(oe,{value:g.value.toString(),title:"Nur Wert kopieren"})]}),a&&n.jsxs("div",{className:"opacity-0 group-hover:opacity-100 flex gap-1",children:[n.jsx("button",{onClick:()=>d(g),className:"text-gray-400 hover:text-blue-600",title:"Bearbeiten",children:n.jsx(We,{className:"w-3 h-3"})}),n.jsx("button",{onClick:()=>{confirm("Zählerstand wirklich löschen?")&&p.mutate(g.id)},className:"text-gray-400 hover:text-red-600",title:"Löschen",children:n.jsx(be,{className:"w-3 h-3"})})]})]})]},g.id))}),!i&&s.length>0&&n.jsxs("p",{className:"text-sm text-gray-500",children:["Letzter Stand: ",h[0].value.toLocaleString("de-DE")," ",h[0].unit," (",new Date(h[0].readingDate).toLocaleDateString("de-DE"),")"]}),s.length===0&&n.jsx("p",{className:"text-sm text-gray-500",children:"Keine Zählerstände vorhanden."}),(o||u)&&n.jsx(PS,{isOpen:!0,onClose:()=>{c(!1),d(null)},meterId:e,contractId:r,reading:u,defaultUnit:f})]})}function PS({isOpen:e,onClose:t,meterId:s,contractId:r,reading:a,defaultUnit:i}){var f;const l=pe(),o=!!a,[c,u]=w.useState({readingDate:a!=null&&a.readingDate?new Date(a.readingDate).toISOString().split("T")[0]:new Date().toISOString().split("T")[0],value:((f=a==null?void 0:a.value)==null?void 0:f.toString())||"",unit:(a==null?void 0:a.unit)||i,notes:(a==null?void 0:a.notes)||""}),d=Y({mutationFn:g=>zs.addReading(s,g),onSuccess:()=>{l.invalidateQueries({queryKey:["contract",r.toString()]}),t()}}),m=Y({mutationFn:g=>zs.updateReading(s,a.id,g),onSuccess:()=>{l.invalidateQueries({queryKey:["contract",r.toString()]}),t()}}),p=g=>{g.preventDefault();const b={readingDate:new Date(c.readingDate),value:parseFloat(c.value),unit:c.unit,notes:c.notes||void 0};o?m.mutate(b):d.mutate(b)},h=d.isPending||m.isPending;return n.jsx(dt,{isOpen:e,onClose:t,title:o?"Zählerstand bearbeiten":"Zählerstand erfassen",children:n.jsxs("form",{onSubmit:p,className:"space-y-4",children:[n.jsx($,{label:"Ablesedatum",type:"date",value:c.readingDate,onChange:g=>u({...c,readingDate:g.target.value}),required:!0}),n.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[n.jsx("div",{className:"col-span-2",children:n.jsx($,{label:"Zählerstand",type:"number",step:"0.01",value:c.value,onChange:g=>u({...c,value:g.target.value}),required:!0})}),n.jsx(Le,{label:"Einheit",value:c.unit,onChange:g=>u({...c,unit:g.target.value}),options:[{value:"kWh",label:"kWh"},{value:"m³",label:"m³"}]})]}),n.jsx($,{label:"Notizen (optional)",value:c.notes,onChange:g=>u({...c,notes:g.target.value})}),n.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[n.jsx(I,{type:"button",variant:"secondary",onClick:t,children:"Abbrechen"}),n.jsx(I,{type:"submit",disabled:h||!c.value,children:h?"Speichern...":o?"Speichern":"Erfassen"})]})]})})}function Sp({task:e,contractId:t,canEdit:s,isCustomerPortal:r,isCompleted:a,onEdit:i}){const[l,o]=w.useState(""),[c,u]=w.useState(!1),[d,m]=w.useState(null),[p,h]=w.useState(""),f=pe(),g=Y({mutationFn:j=>Xe.complete(j),onSuccess:async()=>{await f.refetchQueries({queryKey:["contract-tasks",t]})}}),b=Y({mutationFn:j=>Xe.reopen(j),onSuccess:async()=>{await f.refetchQueries({queryKey:["contract-tasks",t]})}}),y=Y({mutationFn:j=>Xe.delete(j),onSuccess:async()=>{await f.refetchQueries({queryKey:["contract-tasks",t]})}}),v=Y({mutationFn:j=>Xe.createSubtask(e.id,j),onSuccess:async()=>{await f.refetchQueries({queryKey:["contract-tasks",t]}),o(""),u(!1)},onError:j=>{console.error("Fehler beim Erstellen der Unteraufgabe:",j),alert("Fehler beim Erstellen der Unteraufgabe. Bitte versuchen Sie es erneut.")}}),x=Y({mutationFn:j=>Xe.createReply(e.id,j),onSuccess:async()=>{await f.refetchQueries({queryKey:["contract-tasks",t]}),o(""),u(!1)},onError:j=>{console.error("Fehler beim Erstellen der Antwort:",j),alert("Fehler beim Erstellen der Antwort. Bitte versuchen Sie es erneut.")}}),N=Y({mutationFn:({id:j,title:B})=>Xe.updateSubtask(j,B),onSuccess:async()=>{await f.refetchQueries({queryKey:["contract-tasks",t]}),m(null),h("")}}),k=Y({mutationFn:j=>Xe.completeSubtask(j),onSuccess:async()=>{await f.refetchQueries({queryKey:["contract-tasks",t]})}}),D=Y({mutationFn:j=>Xe.reopenSubtask(j),onSuccess:async()=>{await f.refetchQueries({queryKey:["contract-tasks",t]})}}),F=Y({mutationFn:j=>Xe.deleteSubtask(j),onSuccess:async()=>{await f.refetchQueries({queryKey:["contract-tasks",t]})}}),S=j=>{j.preventDefault(),l.trim()&&(r?x.mutate(l.trim()):v.mutate(l.trim()))},L=j=>{j.preventDefault(),p.trim()&&d&&N.mutate({id:d,title:p.trim()})},T=(j,B)=>{m(j),h(B)},_=()=>{m(null),h("")},K=e.subtasks||[],W=K.filter(j=>j.status==="OPEN"),Q=K.filter(j=>j.status==="COMPLETED"),z=r?{singular:"Antwort",placeholder:"Antwort...",deleteConfirm:"Antwort löschen?"}:{singular:"Unteraufgabe",placeholder:"Unteraufgabe...",deleteConfirm:"Unteraufgabe löschen?"},P=(j,B)=>d===j.id?n.jsx("div",{className:"py-1",children:n.jsxs("form",{onSubmit:L,className:"flex items-center gap-2",children:[n.jsx(_l,{className:"w-4 h-4 text-gray-300 flex-shrink-0"}),n.jsx("input",{type:"text",value:p,onChange:ee=>h(ee.target.value),className:"flex-1 text-sm px-2 py-1 border rounded focus:outline-none focus:ring-1 focus:ring-blue-500",autoFocus:!0}),n.jsx(I,{type:"submit",size:"sm",disabled:!p.trim()||N.isPending,children:"✓"}),n.jsx(I,{type:"button",variant:"ghost",size:"sm",onClick:_,children:"×"})]})},j.id):n.jsx("div",{className:`py-1 group/subtask ${B?"opacity-60":""}`,children:n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx("button",{onClick:()=>B?D.mutate(j.id):k.mutate(j.id),disabled:k.isPending||D.isPending||r,className:`flex-shrink-0 mt-0.5 ${r?"cursor-default":B?"hover:text-yellow-600":"hover:text-green-600"}`,children:B?n.jsx(hs,{className:"w-4 h-4 text-green-500"}):n.jsx(_l,{className:"w-4 h-4 text-gray-400"})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx("span",{className:`text-sm ${B?"line-through text-gray-500":""}`,children:j.title}),s&&!r&&!B&&n.jsxs("div",{className:"flex items-center gap-0.5 opacity-0 group-hover/subtask:opacity-100",children:[n.jsx("button",{onClick:()=>T(j.id,j.title),className:"text-gray-400 hover:text-blue-600 p-0.5",title:"Bearbeiten",children:n.jsx(We,{className:"w-3 h-3"})}),n.jsx("button",{onClick:()=>{confirm(z.deleteConfirm)&&F.mutate(j.id)},className:"text-gray-400 hover:text-red-600 p-0.5",title:"Löschen",children:n.jsx(be,{className:"w-3 h-3"})})]}),s&&!r&&B&&n.jsx("button",{onClick:()=>{confirm(z.deleteConfirm)&&F.mutate(j.id)},className:"text-gray-400 hover:text-red-600 p-0.5 opacity-0 group-hover/subtask:opacity-100",title:"Löschen",children:n.jsx(be,{className:"w-3 h-3"})})]}),n.jsxs("p",{className:"text-xs text-gray-400",children:[j.createdBy&&`${j.createdBy} • `,B?`Erledigt am ${j.completedAt?new Date(j.completedAt).toLocaleDateString("de-DE"):new Date(j.updatedAt).toLocaleDateString("de-DE")}`:new Date(j.createdAt).toLocaleDateString("de-DE")]})]})]})},j.id);return n.jsx("div",{className:`p-3 bg-gray-50 rounded-lg group ${a?"bg-gray-50/50 opacity-70":""}`,children:n.jsxs("div",{className:"flex items-start gap-3",children:[n.jsx("button",{onClick:()=>a?b.mutate(e.id):g.mutate(e.id),disabled:g.isPending||b.isPending||r,className:`mt-0.5 flex-shrink-0 ${r?"cursor-default":a?"hover:text-yellow-600":"hover:text-green-600"}`,title:r?void 0:a?"Wieder öffnen":"Als erledigt markieren",children:a?n.jsx(hs,{className:"w-5 h-5 text-green-500"}):n.jsx(_l,{className:"w-5 h-5 text-gray-400"})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:`font-medium ${a?"line-through text-gray-500":""}`,children:e.title}),e.visibleInPortal&&n.jsx(he,{variant:"default",className:"text-xs",children:"Portal"}),K.length>0&&n.jsxs("span",{className:"text-xs text-gray-400",children:["(",Q.length,"/",K.length,")"]})]}),e.description&&n.jsx("p",{className:`text-sm mt-1 whitespace-pre-wrap ${a?"text-gray-500":"text-gray-600"}`,children:e.description}),n.jsxs("p",{className:"text-xs text-gray-400 mt-1",children:[e.createdBy&&`${e.createdBy} • `,a?`Erledigt am ${e.completedAt?new Date(e.completedAt).toLocaleDateString("de-DE"):"-"}`:new Date(e.createdAt).toLocaleDateString("de-DE")]}),K.length>0&&n.jsxs("div",{className:"mt-3 ml-2 space-y-0 border-l-2 border-gray-200 pl-3",children:[W.map(j=>P(j,!1)),Q.map(j=>P(j,!0))]}),!a&&(s&&!r||r)&&n.jsx("div",{className:"mt-2 ml-2",children:c?n.jsxs("form",{onSubmit:S,className:"flex items-center gap-2",children:[n.jsx("input",{type:"text",value:l,onChange:j=>o(j.target.value),placeholder:z.placeholder,className:"flex-1 text-sm px-2 py-1 border rounded focus:outline-none focus:ring-1 focus:ring-blue-500",autoFocus:!0}),n.jsx(I,{type:"submit",size:"sm",disabled:!l.trim()||v.isPending||x.isPending,children:n.jsx(Oe,{className:"w-3 h-3"})}),n.jsx(I,{type:"button",variant:"ghost",size:"sm",onClick:()=>{u(!1),o("")},children:"×"})]}):n.jsxs("button",{onClick:()=>u(!0),className:"text-xs text-gray-400 hover:text-blue-600 flex items-center gap-1",children:[n.jsx(Oe,{className:"w-3 h-3"}),z.singular]})})]}),s&&!r&&n.jsxs("div",{className:"flex gap-1 opacity-0 group-hover:opacity-100",children:[!a&&n.jsx("button",{onClick:i,className:"text-gray-400 hover:text-blue-600 p-1",title:"Bearbeiten",children:n.jsx(We,{className:"w-4 h-4"})}),n.jsx("button",{onClick:()=>{confirm("Aufgabe wirklich löschen?")&&y.mutate(e.id)},className:"text-gray-400 hover:text-red-600 p-1",title:"Löschen",children:n.jsx(be,{className:"w-4 h-4"})})]})]})})}function AS({contractId:e,canEdit:t,isCustomerPortal:s}){var x;const[r,a]=w.useState(!1),[i,l]=w.useState(null),{data:o,isLoading:c}=ge({queryKey:["contract-tasks",e],queryFn:()=>Xe.getByContract(e),staleTime:0,gcTime:0,refetchOnMount:"always"}),{data:u,isLoading:d}=ge({queryKey:["app-settings-public"],queryFn:()=>Sr.getPublic(),enabled:s,staleTime:0}),m=!d&&((x=u==null?void 0:u.data)==null?void 0:x.customerSupportTicketsEnabled)==="true",p=(o==null?void 0:o.data)||[],h=p.filter(N=>N.status==="OPEN"),f=p.filter(N=>N.status==="COMPLETED"),g=s?{title:"Support-Anfragen",button:"Anfrage erstellen",empty:"Keine Support-Anfragen vorhanden."}:{title:"Aufgaben",button:"Aufgabe",empty:"Keine Aufgaben vorhanden."},b=s?Mi:Ii;if(c||s&&d)return n.jsx(Z,{className:"mb-6",title:g.title,children:n.jsx("div",{className:"text-center py-4 text-gray-500",children:"Laden..."})});const v=t&&!s||s&&m;return n.jsxs(Z,{className:"mb-6",title:g.title,children:[n.jsxs("div",{className:"flex items-center justify-between mb-4",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(b,{className:"w-5 h-5 text-gray-500"}),n.jsxs("span",{className:"text-sm text-gray-600",children:[h.length," offen, ",f.length," erledigt"]})]}),v&&n.jsxs(I,{size:"sm",onClick:()=>a(!0),children:[n.jsx(Oe,{className:"w-4 h-4 mr-1"}),g.button]})]}),p.length===0?n.jsx("p",{className:"text-center py-4 text-gray-500",children:g.empty}):n.jsxs("div",{className:"space-y-2",children:[h.map(N=>n.jsx(Sp,{task:N,contractId:e,canEdit:t,isCustomerPortal:s,isCompleted:!1,onEdit:()=>l(N)},N.id)),f.length>0&&h.length>0&&n.jsx("div",{className:"border-t my-3"}),f.map(N=>n.jsx(Sp,{task:N,contractId:e,canEdit:t,isCustomerPortal:s,isCompleted:!0,onEdit:()=>{}},N.id))]}),(r||i)&&n.jsx(TS,{isOpen:!0,onClose:()=>{a(!1),l(null)},contractId:e,task:i,isCustomerPortal:s})]})}function TS({isOpen:e,onClose:t,contractId:s,task:r,isCustomerPortal:a=!1}){const i=pe(),l=!!r,[o,c]=w.useState({title:(r==null?void 0:r.title)||"",description:(r==null?void 0:r.description)||"",visibleInPortal:(r==null?void 0:r.visibleInPortal)||!1});w.useEffect(()=>{e&&c({title:(r==null?void 0:r.title)||"",description:(r==null?void 0:r.description)||"",visibleInPortal:(r==null?void 0:r.visibleInPortal)||!1})},[e,r]);const u=Y({mutationFn:g=>Xe.create(s,g),onSuccess:async()=>{await i.refetchQueries({queryKey:["contract-tasks",s]}),t()}}),d=Y({mutationFn:g=>Xe.createSupportTicket(s,g),onSuccess:async()=>{await i.refetchQueries({queryKey:["contract-tasks",s]}),t()}}),m=Y({mutationFn:g=>Xe.update(r.id,g),onSuccess:async()=>{await i.refetchQueries({queryKey:["contract-tasks",s]}),t()}}),p=g=>{g.preventDefault(),l?m.mutate({title:o.title,description:o.description||void 0,visibleInPortal:o.visibleInPortal}):a?d.mutate({title:o.title,description:o.description||void 0}):u.mutate({title:o.title,description:o.description||void 0,visibleInPortal:o.visibleInPortal})},h=u.isPending||d.isPending||m.isPending,f=a?{modalTitle:l?"Anfrage bearbeiten":"Neue Support-Anfrage",titleLabel:"Betreff",titlePlaceholder:"Kurze Beschreibung Ihrer Anfrage",descLabel:"Ihre Nachricht",descPlaceholder:"Beschreiben Sie Ihr Anliegen...",submitBtn:l?"Speichern":"Anfrage senden"}:{modalTitle:l?"Aufgabe bearbeiten":"Neue Aufgabe",titleLabel:"Titel",titlePlaceholder:"Kurze Beschreibung der Aufgabe",descLabel:"Beschreibung (optional)",descPlaceholder:"Details zur Aufgabe...",submitBtn:l?"Speichern":"Erstellen"};return n.jsx(dt,{isOpen:e,onClose:t,title:f.modalTitle,children:n.jsxs("form",{onSubmit:p,className:"space-y-4",children:[n.jsx($,{label:f.titleLabel,value:o.title,onChange:g=>c({...o,title:g.target.value}),required:!0,placeholder:f.titlePlaceholder}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:f.descLabel}),n.jsx("textarea",{value:o.description,onChange:g=>c({...o,description:g.target.value}),className:"w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500",rows:a?5:3,placeholder:f.descPlaceholder})]}),!a&&n.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[n.jsx("input",{type:"checkbox",checked:o.visibleInPortal,onChange:g=>c({...o,visibleInPortal:g.target.checked}),className:"w-4 h-4 rounded border-gray-300 text-blue-600 focus:ring-blue-500"}),n.jsx("span",{className:"text-sm text-gray-700",children:"Im Kundenportal sichtbar"})]}),n.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[n.jsx(I,{type:"button",variant:"secondary",onClick:t,children:"Abbrechen"}),n.jsx(I,{type:"submit",disabled:h||!o.title.trim(),children:h?"Speichern...":f.submitBtn})]})]})})}function FS(){var B,J,ee,me,ve,it;const{id:e}=_o(),t=Ut(),r=dn().state,a=pe(),{hasPermission:i,isCustomer:l,isCustomerPortal:o}=st(),c=parseInt(e),[u,d]=w.useState(!1),[m,p]=w.useState(null),[h,f]=w.useState(!1),[g,b]=w.useState(!1),[y,v]=w.useState(null),[x,N]=w.useState({}),[k,D]=w.useState({}),{data:F,isLoading:S}=ge({queryKey:["contract",e],queryFn:()=>$e.getById(c)}),L=Y({mutationFn:()=>$e.delete(c),onSuccess:()=>{a.invalidateQueries({queryKey:["contracts"]}),t("/contracts")}}),T=Y({mutationFn:()=>$e.createFollowUp(c),onSuccess:V=>{a.invalidateQueries({queryKey:["contracts"]}),V.data&&t(`/contracts/${V.data.id}/edit`)}}),_=Y({mutationFn:V=>{const Me={cancellationConfirmationDate:V?new Date(V).toISOString():null};return $e.update(c,Me)},onSuccess:()=>{a.invalidateQueries({queryKey:["contract",e]}),a.invalidateQueries({queryKey:["contract-cockpit"]})},onError:V=>{console.error("Fehler beim Speichern des Datums:",V),alert("Fehler beim Speichern des Datums")}}),K=Y({mutationFn:V=>{const Me={cancellationConfirmationOptionsDate:V?new Date(V).toISOString():null};return $e.update(c,Me)},onSuccess:()=>{a.invalidateQueries({queryKey:["contract",e]}),a.invalidateQueries({queryKey:["contract-cockpit"]})},onError:V=>{console.error("Fehler beim Speichern des Datums:",V),alert("Fehler beim Speichern des Datums")}}),W=async()=>{var V;if(u)d(!1),p(null);else try{const Ce=await $e.getPassword(c);(V=Ce.data)!=null&&V.password&&(p(Ce.data.password),d(!0))}catch{alert("Passwort konnte nicht entschlüsselt werden")}},Q=async()=>{var V;if(g)b(!1),v(null);else try{const Ce=await $e.getInternetCredentials(c);(V=Ce.data)!=null&&V.password&&(v(Ce.data.password),b(!0))}catch{alert("Internet-Passwort konnte nicht entschlüsselt werden")}},z=async V=>{var Ce;if(x[V])N(Me=>({...Me,[V]:!1})),D(Me=>({...Me,[V]:null}));else try{const ht=(Ce=(await $e.getSipCredentials(V)).data)==null?void 0:Ce.password;ht&&(D(Tt=>({...Tt,[V]:ht})),N(Tt=>({...Tt,[V]:!0})))}catch{alert("SIP-Passwort konnte nicht entschlüsselt werden")}},P=async()=>{var Me,ht,Tt;const V=F==null?void 0:F.data,Ce=((Me=V==null?void 0:V.stressfreiEmail)==null?void 0:Me.email)||(V==null?void 0:V.portalUsername);if(!((ht=V==null?void 0:V.provider)!=null&&ht.portalUrl)||!Ce){alert("Portal-URL oder Benutzername fehlt");return}f(!0);try{const Jt=await $e.getPassword(c);if(!((Tt=Jt.data)!=null&&Tt.password)){alert("Passwort konnte nicht entschlüsselt werden");return}const Pe=V.provider,Xt=Pe.portalUrl,Gn=Pe.usernameFieldName||"username",Er=Pe.passwordFieldName||"password",hn=new URL(Xt);hn.searchParams.set(Gn,Ce),hn.searchParams.set(Er,Jt.data.password),window.open(hn.toString(),"_blank")}catch{alert("Fehler beim Auto-Login")}finally{f(!1)}};if(S)return n.jsx("div",{className:"text-center py-8",children:"Laden..."});if(!(F!=null&&F.data))return n.jsx("div",{className:"text-center py-8 text-red-600",children:"Vertrag nicht gefunden"});const j=F.data;return n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center justify-between mb-6",children:[n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-4 mb-2",children:[n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{if((r==null?void 0:r.from)==="customer"&&(r!=null&&r.customerId))t(`/customers/${r.customerId}?tab=contracts`);else if((r==null?void 0:r.from)==="cockpit"){const V=r.filter?`?filter=${r.filter}`:"";t(`/contracts/cockpit${V}`)}else(r==null?void 0:r.from)==="contracts"?t("/contracts"):j.customer?t(`/customers/${j.customer.id}?tab=contracts`):t("/contracts")},children:n.jsx($s,{className:"w-4 h-4"})}),n.jsx("h1",{className:"text-2xl font-bold",children:j.contractNumber}),n.jsx(he,{children:wS[j.type]}),n.jsx(he,{variant:kS[j.status],children:SS[j.status]})]}),j.customer&&n.jsxs("p",{className:"text-gray-500 ml-10",children:["Kunde:"," ",n.jsx(Se,{to:`/customers/${j.customer.id}`,className:"text-blue-600 hover:underline",children:j.customer.companyName||`${j.customer.firstName} ${j.customer.lastName}`})]})]}),!l&&n.jsxs("div",{className:"flex gap-2",children:[i("contracts:create")&&n.jsxs(I,{variant:"secondary",onClick:()=>T.mutate(),disabled:T.isPending,children:[n.jsx(Gy,{className:"w-4 h-4 mr-2"}),"Folgevertrag"]}),i("contracts:update")&&n.jsx(Se,{to:`/contracts/${e}/edit`,children:n.jsxs(I,{variant:"secondary",children:[n.jsx(We,{className:"w-4 h-4 mr-2"}),"Bearbeiten"]})}),i("contracts:delete")&&n.jsxs(I,{variant:"danger",onClick:()=>{confirm("Vertrag wirklich löschen?")&&L.mutate()},children:[n.jsx(be,{className:"w-4 h-4 mr-2"}),"Löschen"]})]})]}),j.previousContract&&n.jsx(Z,{className:"mb-6 border-l-4 border-l-blue-500",title:"Vorgängervertrag",children:n.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Vertragsnummer"}),n.jsx("dd",{children:n.jsx(Se,{to:`/contracts/${j.previousContract.id}`,className:"text-blue-600 hover:underline",children:j.previousContract.contractNumber})})]}),j.previousContract.providerName&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Anbieter"}),n.jsx("dd",{children:j.previousContract.providerName})]}),j.previousContract.customerNumberAtProvider&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Kundennummer"}),n.jsx("dd",{className:"font-mono",children:j.previousContract.customerNumberAtProvider})]}),j.previousContract.portalUsername&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Zugangsdaten"}),n.jsx("dd",{children:j.previousContract.portalUsername})]})]})}),j.cancellationConfirmationDate&&n.jsxs("div",{className:"mb-6 p-4 bg-red-50 border-2 border-red-400 rounded-lg flex items-start gap-3",children:[n.jsx("span",{className:"text-red-600 text-xl font-bold",children:"!"}),n.jsxs("div",{children:[n.jsx("p",{className:"font-semibold text-red-800",children:"Kündigungsbestätigung vorhanden"}),n.jsxs("p",{className:"text-sm text-red-700 mt-1",children:["Dieser Vertrag hat eine Kündigungsbestätigung vom"," ",n.jsx("strong",{children:new Date(j.cancellationConfirmationDate).toLocaleDateString("de-DE",{day:"2-digit",month:"2-digit",year:"numeric"})}),".",j.cancellationConfirmationOptionsDate&&n.jsxs(n.Fragment,{children:[" Optionen-Bestätigung: ",n.jsx("strong",{children:new Date(j.cancellationConfirmationOptionsDate).toLocaleDateString("de-DE",{day:"2-digit",month:"2-digit",year:"numeric"})}),"."]})]})]})]}),j.type==="MOBILE"&&((B=j.mobileDetails)==null?void 0:B.requiresMultisim)&&n.jsxs("div",{className:"mb-6 p-4 bg-amber-50 border border-amber-300 rounded-lg flex items-start gap-3",children:[n.jsx("span",{className:"text-amber-600 text-xl font-bold",children:"!"}),n.jsxs("div",{children:[n.jsx("p",{className:"font-semibold text-amber-800",children:"Multisim erforderlich"}),n.jsx("p",{className:"text-sm text-amber-700 mt-1",children:"Dieser Kunde benötigt eine Multisim-Karte. Multisim ist bei Klarmobil, Congstar und Otelo nicht buchbar. Bitte einen Anbieter wie Freenet oder vergleichbar wählen."})]})]}),n.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6 mb-6",children:[n.jsx(Z,{title:"Anbieter & Tarif",children:n.jsxs("dl",{className:"space-y-3",children:[(j.provider||j.providerName)&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Anbieter"}),n.jsx("dd",{className:"font-medium",children:((J=j.provider)==null?void 0:J.name)||j.providerName})]}),(j.tariff||j.tariffName)&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Tarif"}),n.jsx("dd",{children:((ee=j.tariff)==null?void 0:ee.name)||j.tariffName})]}),j.customerNumberAtProvider&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Kundennummer"}),n.jsxs("dd",{className:"font-mono flex items-center gap-1",children:[j.customerNumberAtProvider,n.jsx(oe,{value:j.customerNumberAtProvider})]})]}),j.salesPlatform&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Vertriebsplattform"}),n.jsx("dd",{children:j.salesPlatform.name})]}),j.commission!==null&&j.commission!==void 0&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Provision"}),n.jsx("dd",{children:j.commission.toLocaleString("de-DE",{style:"currency",currency:"EUR"})})]}),j.priceFirst12Months&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Preis erste 12 Monate"}),n.jsx("dd",{children:j.priceFirst12Months})]}),j.priceFrom13Months&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Preis ab 13. Monat"}),n.jsx("dd",{children:j.priceFrom13Months})]}),j.priceAfter24Months&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Preis nach 24 Monaten"}),n.jsx("dd",{children:j.priceAfter24Months})]})]})}),n.jsxs(Z,{title:"Laufzeit und Kündigung",className:j.cancellationConfirmationDate?"border-2 border-red-400":"",children:[j.contractDuration&&CS(j.contractDuration.code)&&n.jsxs("p",{className:"text-sm text-gray-500 mb-4 bg-blue-50 border border-blue-200 rounded-lg p-3",children:[n.jsx("strong",{children:"Hinweis:"})," Dieser Vertrag gilt als unbefristet mit der jeweiligen Kündigungsfrist."]}),n.jsxs("dl",{className:"space-y-3",children:[j.startDate&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Vertragsbeginn"}),n.jsx("dd",{children:new Date(j.startDate).toLocaleDateString("de-DE",{day:"2-digit",month:"2-digit",year:"numeric"})})]}),j.endDate&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Vertragsende"}),n.jsx("dd",{children:new Date(j.endDate).toLocaleDateString("de-DE",{day:"2-digit",month:"2-digit",year:"numeric"})})]}),j.contractDuration&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Vertragslaufzeit"}),n.jsx("dd",{children:j.contractDuration.description})]}),j.cancellationPeriod&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Kündigungsfrist"}),n.jsx("dd",{children:j.cancellationPeriod.description})]}),j.cancellationConfirmationDate&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Kündigungsbestätigungsdatum"}),n.jsx("dd",{children:new Date(j.cancellationConfirmationDate).toLocaleDateString("de-DE",{day:"2-digit",month:"2-digit",year:"numeric"})})]}),j.cancellationConfirmationOptionsDate&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Kündigungsbestätigungsoptionendatum"}),n.jsx("dd",{children:new Date(j.cancellationConfirmationOptionsDate).toLocaleDateString("de-DE",{day:"2-digit",month:"2-digit",year:"numeric"})})]}),j.wasSpecialCancellation&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Sonderkündigung"}),n.jsx("dd",{children:n.jsx(he,{variant:"warning",children:"Ja"})})]})]}),i("contracts:update")&&n.jsxs("div",{className:"mt-6 pt-6 border-t",children:[n.jsx("h4",{className:"font-medium mb-4",children:"Kündigungsdokumente"}),n.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500 mb-1",children:"Kündigungsschreiben"}),j.cancellationLetterPath?n.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[n.jsxs("a",{href:`/api${j.cancellationLetterPath}`,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:underline text-sm flex items-center gap-1",children:[n.jsx(Ee,{className:"w-4 h-4"}),"Anzeigen"]}),n.jsxs("a",{href:`/api${j.cancellationLetterPath}`,download:!0,className:"text-blue-600 hover:underline text-sm flex items-center gap-1",children:[n.jsx(tn,{className:"w-4 h-4"}),"Download"]}),n.jsx(xt,{onUpload:async V=>{await Ye.uploadCancellationLetter(c,V),a.invalidateQueries({queryKey:["contract",e]})},existingFile:j.cancellationLetterPath,accept:".pdf",label:"Ersetzen"}),n.jsxs("button",{onClick:async()=>{confirm("Dokument wirklich löschen?")&&(await Ye.deleteCancellationLetter(c),a.invalidateQueries({queryKey:["contract",e]}))},className:"text-red-600 hover:underline text-sm flex items-center gap-1",children:[n.jsx(be,{className:"w-4 h-4"}),"Löschen"]})]}):n.jsx(xt,{onUpload:async V=>{await Ye.uploadCancellationLetter(c,V),a.invalidateQueries({queryKey:["contract",e]})},accept:".pdf",label:"PDF hochladen"})]}),n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500 mb-1",children:"Kündigungsbestätigung"}),j.cancellationConfirmationPath?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[n.jsxs("a",{href:`/api${j.cancellationConfirmationPath}`,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:underline text-sm flex items-center gap-1",children:[n.jsx(Ee,{className:"w-4 h-4"}),"Anzeigen"]}),n.jsxs("a",{href:`/api${j.cancellationConfirmationPath}`,download:!0,className:"text-blue-600 hover:underline text-sm flex items-center gap-1",children:[n.jsx(tn,{className:"w-4 h-4"}),"Download"]}),n.jsx(xt,{onUpload:async V=>{await Ye.uploadCancellationConfirmation(c,V),a.invalidateQueries({queryKey:["contract",e]})},existingFile:j.cancellationConfirmationPath,accept:".pdf",label:"Ersetzen"}),n.jsxs("button",{onClick:async()=>{confirm("Dokument wirklich löschen?")&&(await Ye.deleteCancellationConfirmation(c),a.invalidateQueries({queryKey:["contract",e]}))},className:"text-red-600 hover:underline text-sm flex items-center gap-1",children:[n.jsx(be,{className:"w-4 h-4"}),"Löschen"]})]}),n.jsxs("div",{className:"mt-2",children:[n.jsx("label",{className:"text-xs text-gray-500 block mb-1",children:"Bestätigung erhalten am"}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("input",{type:"date",value:j.cancellationConfirmationDate?j.cancellationConfirmationDate.split("T")[0]:"",onChange:V=>{const Ce=V.target.value||null;_.mutate(Ce)},className:"block w-full max-w-[180px] px-2 py-1 text-sm border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-blue-500"}),j.cancellationConfirmationDate&&n.jsx("button",{onClick:()=>_.mutate(null),className:"p-1 text-red-500 hover:text-red-700 hover:bg-red-50 rounded",title:"Datum löschen",children:n.jsx(be,{className:"w-4 h-4"})})]})]})]}):n.jsx(xt,{onUpload:async V=>{await Ye.uploadCancellationConfirmation(c,V),a.invalidateQueries({queryKey:["contract",e]})},accept:".pdf",label:"PDF hochladen"})]}),n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500 mb-1",children:"Kündigungsschreiben Optionen"}),j.cancellationLetterOptionsPath?n.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[n.jsxs("a",{href:`/api${j.cancellationLetterOptionsPath}`,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:underline text-sm flex items-center gap-1",children:[n.jsx(Ee,{className:"w-4 h-4"}),"Anzeigen"]}),n.jsxs("a",{href:`/api${j.cancellationLetterOptionsPath}`,download:!0,className:"text-blue-600 hover:underline text-sm flex items-center gap-1",children:[n.jsx(tn,{className:"w-4 h-4"}),"Download"]}),n.jsx(xt,{onUpload:async V=>{await Ye.uploadCancellationLetterOptions(c,V),a.invalidateQueries({queryKey:["contract",e]})},existingFile:j.cancellationLetterOptionsPath,accept:".pdf",label:"Ersetzen"}),n.jsxs("button",{onClick:async()=>{confirm("Dokument wirklich löschen?")&&(await Ye.deleteCancellationLetterOptions(c),a.invalidateQueries({queryKey:["contract",e]}))},className:"text-red-600 hover:underline text-sm flex items-center gap-1",children:[n.jsx(be,{className:"w-4 h-4"}),"Löschen"]})]}):n.jsx(xt,{onUpload:async V=>{await Ye.uploadCancellationLetterOptions(c,V),a.invalidateQueries({queryKey:["contract",e]})},accept:".pdf",label:"PDF hochladen"})]}),n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500 mb-1",children:"Kündigungsbestätigung Optionen"}),j.cancellationConfirmationOptionsPath?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[n.jsxs("a",{href:`/api${j.cancellationConfirmationOptionsPath}`,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:underline text-sm flex items-center gap-1",children:[n.jsx(Ee,{className:"w-4 h-4"}),"Anzeigen"]}),n.jsxs("a",{href:`/api${j.cancellationConfirmationOptionsPath}`,download:!0,className:"text-blue-600 hover:underline text-sm flex items-center gap-1",children:[n.jsx(tn,{className:"w-4 h-4"}),"Download"]}),n.jsx(xt,{onUpload:async V=>{await Ye.uploadCancellationConfirmationOptions(c,V),a.invalidateQueries({queryKey:["contract",e]})},existingFile:j.cancellationConfirmationOptionsPath,accept:".pdf",label:"Ersetzen"}),n.jsxs("button",{onClick:async()=>{confirm("Dokument wirklich löschen?")&&(await Ye.deleteCancellationConfirmationOptions(c),a.invalidateQueries({queryKey:["contract",e]}))},className:"text-red-600 hover:underline text-sm flex items-center gap-1",children:[n.jsx(be,{className:"w-4 h-4"}),"Löschen"]})]}),n.jsxs("div",{className:"mt-2",children:[n.jsx("label",{className:"text-xs text-gray-500 block mb-1",children:"Bestätigung erhalten am"}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("input",{type:"date",value:j.cancellationConfirmationOptionsDate?j.cancellationConfirmationOptionsDate.split("T")[0]:"",onChange:V=>{const Ce=V.target.value||null;K.mutate(Ce)},className:"block w-full max-w-[180px] px-2 py-1 text-sm border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-blue-500"}),j.cancellationConfirmationOptionsDate&&n.jsx("button",{onClick:()=>K.mutate(null),className:"p-1 text-red-500 hover:text-red-700 hover:bg-red-50 rounded",title:"Datum löschen",children:n.jsx(be,{className:"w-4 h-4"})})]})]})]}):n.jsx(xt,{onUpload:async V=>{await Ye.uploadCancellationConfirmationOptions(c,V),a.invalidateQueries({queryKey:["contract",e]})},accept:".pdf",label:"PDF hochladen"})]})]})]})]})]}),(j.portalUsername||j.stressfreiEmail||j.portalPasswordEncrypted)&&n.jsxs(Z,{className:"mb-6",title:"Zugangsdaten",children:[n.jsxs("dl",{className:"grid grid-cols-2 gap-4",children:[(j.portalUsername||j.stressfreiEmail)&&n.jsxs("div",{children:[n.jsxs("dt",{className:"text-sm text-gray-500",children:["Benutzername",j.stressfreiEmail&&n.jsx("span",{className:"ml-2 text-xs text-blue-600",children:"(Stressfrei-Wechseln)"})]}),n.jsxs("dd",{className:"font-mono flex items-center gap-1",children:[((me=j.stressfreiEmail)==null?void 0:me.email)||j.portalUsername,n.jsx(oe,{value:((ve=j.stressfreiEmail)==null?void 0:ve.email)||j.portalUsername||""})]})]}),j.portalPasswordEncrypted&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Passwort"}),n.jsxs("dd",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"font-mono",children:u&&m?m:"••••••••"}),u&&m&&n.jsx(oe,{value:m}),n.jsx(I,{variant:"ghost",size:"sm",onClick:W,children:u?n.jsx(Pt,{className:"w-4 h-4"}):n.jsx(Ee,{className:"w-4 h-4"})})]})]})]}),((it=j.provider)==null?void 0:it.portalUrl)&&(j.portalUsername||j.stressfreiEmail)&&j.portalPasswordEncrypted&&n.jsxs("div",{className:"mt-4 pt-4 border-t",children:[n.jsxs(I,{onClick:P,disabled:h,className:"w-full sm:w-auto",children:[n.jsx(Yy,{className:"w-4 h-4 mr-2"}),h?"Wird geöffnet...":"Zum Kundenportal (Auto-Login)"]}),n.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"Öffnet das Portal mit vorausgefüllten Zugangsdaten"})]})]}),n.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6 mb-6",children:[j.address&&n.jsx(Z,{title:"Adresse",children:n.jsxs(nv,{values:[`${j.address.street} ${j.address.houseNumber}`,`${j.address.postalCode} ${j.address.city}`,j.address.country],children:[n.jsxs("p",{children:[j.address.street," ",j.address.houseNumber]}),n.jsxs("p",{children:[j.address.postalCode," ",j.address.city]}),n.jsx("p",{className:"text-gray-500",children:j.address.country})]})}),j.bankCard&&n.jsxs(Z,{title:"Bankkarte",children:[n.jsx("p",{className:"font-medium",children:j.bankCard.accountHolder}),n.jsxs("p",{className:"font-mono flex items-center gap-1",children:[j.bankCard.iban,n.jsx(oe,{value:j.bankCard.iban})]}),j.bankCard.bankName&&n.jsx("p",{className:"text-gray-500",children:j.bankCard.bankName})]}),j.identityDocument&&n.jsxs(Z,{title:"Ausweis",children:[n.jsxs("p",{className:"font-mono flex items-center gap-1",children:[j.identityDocument.documentNumber,n.jsx(oe,{value:j.identityDocument.documentNumber})]}),n.jsx("p",{className:"text-gray-500",children:j.identityDocument.type})]})]}),j.energyDetails&&n.jsxs(Z,{className:"mb-6",title:j.type==="ELECTRICITY"?"Strom-Details":"Gas-Details",children:[n.jsxs("dl",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[j.energyDetails.meter&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Zählernummer"}),n.jsxs("dd",{className:"font-mono flex items-center gap-1",children:[j.energyDetails.meter.meterNumber,n.jsx(oe,{value:j.energyDetails.meter.meterNumber})]})]}),j.energyDetails.annualConsumption&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Jahresverbrauch"}),n.jsxs("dd",{children:[j.energyDetails.annualConsumption.toLocaleString("de-DE")," ",j.type==="ELECTRICITY"?"kWh":"m³"]})]}),j.energyDetails.basePrice&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Grundpreis"}),n.jsxs("dd",{children:[j.energyDetails.basePrice.toLocaleString("de-DE")," €/Monat"]})]}),j.energyDetails.unitPrice&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Arbeitspreis"}),n.jsxs("dd",{children:[j.energyDetails.unitPrice.toLocaleString("de-DE")," ct/",j.type==="ELECTRICITY"?"kWh":"m³"]})]}),j.energyDetails.bonus&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Bonus"}),n.jsxs("dd",{children:[j.energyDetails.bonus.toLocaleString("de-DE")," €"]})]}),j.energyDetails.previousProviderName&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Vorversorger"}),n.jsx("dd",{children:j.energyDetails.previousProviderName})]}),j.energyDetails.previousCustomerNumber&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Vorherige Kundennr."}),n.jsxs("dd",{className:"font-mono flex items-center gap-1",children:[j.energyDetails.previousCustomerNumber,n.jsx(oe,{value:j.energyDetails.previousCustomerNumber})]})]})]}),j.energyDetails.meter&&n.jsx(DS,{meterId:j.energyDetails.meter.id,meterType:j.energyDetails.meter.type,readings:j.energyDetails.meter.readings||[],contractId:c,canEdit:i("contracts:update")&&!l})]}),j.internetDetails&&n.jsxs(Z,{className:"mb-6",title:j.type==="DSL"?"DSL-Details":j.type==="CABLE"?"Kabelinternet-Details":"Glasfaser-Details",children:[n.jsxs("dl",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[j.internetDetails.downloadSpeed&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Download"}),n.jsxs("dd",{children:[j.internetDetails.downloadSpeed," Mbit/s"]})]}),j.internetDetails.uploadSpeed&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Upload"}),n.jsxs("dd",{children:[j.internetDetails.uploadSpeed," Mbit/s"]})]}),j.internetDetails.routerModel&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Router"}),n.jsx("dd",{children:j.internetDetails.routerModel})]}),j.internetDetails.routerSerialNumber&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Router S/N"}),n.jsxs("dd",{className:"font-mono flex items-center gap-1",children:[j.internetDetails.routerSerialNumber,n.jsx(oe,{value:j.internetDetails.routerSerialNumber})]})]}),j.internetDetails.installationDate&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Installation"}),n.jsx("dd",{children:new Date(j.internetDetails.installationDate).toLocaleDateString("de-DE")})]}),j.internetDetails.homeId&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Home-ID"}),n.jsxs("dd",{className:"font-mono flex items-center gap-1",children:[j.internetDetails.homeId,n.jsx(oe,{value:j.internetDetails.homeId})]})]}),j.internetDetails.activationCode&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Aktivierungscode"}),n.jsxs("dd",{className:"font-mono flex items-center gap-1",children:[j.internetDetails.activationCode,n.jsx(oe,{value:j.internetDetails.activationCode})]})]})]}),(j.internetDetails.internetUsername||j.internetDetails.internetPasswordEncrypted)&&n.jsxs("div",{className:"mt-4 pt-4 border-t",children:[n.jsx("h4",{className:"text-sm font-medium text-gray-700 mb-3",children:"Internet-Zugangsdaten"}),n.jsxs("dl",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[j.internetDetails.internetUsername&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Benutzername"}),n.jsxs("dd",{className:"font-mono flex items-center gap-1",children:[j.internetDetails.internetUsername,n.jsx(oe,{value:j.internetDetails.internetUsername})]})]}),j.internetDetails.internetPasswordEncrypted&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Passwort"}),n.jsxs("dd",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"font-mono",children:g&&y?y:"••••••••"}),g&&y&&n.jsx(oe,{value:y}),n.jsx(I,{variant:"ghost",size:"sm",onClick:Q,children:g?n.jsx(Pt,{className:"w-4 h-4"}):n.jsx(Ee,{className:"w-4 h-4"})})]})]})]})]}),j.internetDetails.phoneNumbers&&j.internetDetails.phoneNumbers.length>0&&n.jsxs("div",{className:"mt-4 pt-4 border-t",children:[n.jsx("h4",{className:"text-sm font-medium text-gray-700 mb-3",children:"Rufnummern & SIP-Zugangsdaten"}),n.jsx("div",{className:"space-y-3",children:j.internetDetails.phoneNumbers.map(V=>n.jsxs("div",{className:"p-3 bg-gray-50 rounded-lg",children:[n.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[n.jsxs("span",{className:"font-mono font-medium flex items-center gap-1",children:[V.phoneNumber,n.jsx(oe,{value:V.phoneNumber})]}),V.isMain&&n.jsx(he,{variant:"success",children:"Hauptnummer"})]}),(V.sipUsername||V.sipPasswordEncrypted||V.sipServer)&&n.jsxs("dl",{className:"grid grid-cols-2 md:grid-cols-4 gap-3 text-sm",children:[V.sipUsername&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-gray-500",children:"SIP-Benutzer"}),n.jsxs("dd",{className:"font-mono flex items-center gap-1",children:[V.sipUsername,n.jsx(oe,{value:V.sipUsername})]})]}),V.sipPasswordEncrypted&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-gray-500",children:"SIP-Passwort"}),n.jsxs("dd",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"font-mono",children:x[V.id]&&k[V.id]?k[V.id]:"••••••••"}),x[V.id]&&k[V.id]&&n.jsx(oe,{value:k[V.id]}),n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>z(V.id),children:x[V.id]?n.jsx(Pt,{className:"w-3 h-3"}):n.jsx(Ee,{className:"w-3 h-3"})})]})]}),V.sipServer&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-gray-500",children:"SIP-Server"}),n.jsxs("dd",{className:"font-mono flex items-center gap-1",children:[V.sipServer,n.jsx(oe,{value:V.sipServer})]})]})]})]},V.id))})]})]}),j.mobileDetails&&n.jsxs(Z,{className:"mb-6",title:"Mobilfunk-Details",children:[n.jsxs("dl",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[j.mobileDetails.dataVolume&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Datenvolumen"}),n.jsxs("dd",{children:[j.mobileDetails.dataVolume," GB"]})]}),j.mobileDetails.includedMinutes&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Inklusiv-Minuten"}),n.jsx("dd",{children:j.mobileDetails.includedMinutes})]}),j.mobileDetails.includedSMS&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Inklusiv-SMS"}),n.jsx("dd",{children:j.mobileDetails.includedSMS})]}),j.mobileDetails.deviceModel&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Gerät"}),n.jsx("dd",{children:j.mobileDetails.deviceModel})]}),j.mobileDetails.deviceImei&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"IMEI"}),n.jsxs("dd",{className:"font-mono flex items-center gap-1",children:[j.mobileDetails.deviceImei,n.jsx(oe,{value:j.mobileDetails.deviceImei})]})]}),j.mobileDetails.requiresMultisim&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Multisim"}),n.jsx("dd",{children:n.jsx(he,{variant:"warning",children:"Erforderlich"})})]})]}),j.mobileDetails.simCards&&j.mobileDetails.simCards.length>0&&n.jsxs("div",{className:"mt-6 pt-6 border-t",children:[n.jsx("h4",{className:"font-medium mb-4",children:"SIM-Karten"}),n.jsx("div",{className:"space-y-3",children:j.mobileDetails.simCards.map(V=>n.jsx(ES,{simCard:V},V.id))})]}),(!j.mobileDetails.simCards||j.mobileDetails.simCards.length===0)&&(j.mobileDetails.phoneNumber||j.mobileDetails.simCardNumber)&&n.jsxs("div",{className:"mt-6 pt-6 border-t",children:[n.jsx("h4",{className:"font-medium mb-4",children:"SIM-Karte (Legacy)"}),n.jsxs("dl",{className:"grid grid-cols-2 gap-4",children:[j.mobileDetails.phoneNumber&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Rufnummer"}),n.jsxs("dd",{className:"font-mono flex items-center gap-1",children:[j.mobileDetails.phoneNumber,n.jsx(oe,{value:j.mobileDetails.phoneNumber})]})]}),j.mobileDetails.simCardNumber&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"SIM-Kartennummer"}),n.jsxs("dd",{className:"font-mono flex items-center gap-1",children:[j.mobileDetails.simCardNumber,n.jsx(oe,{value:j.mobileDetails.simCardNumber})]})]})]})]})]}),j.tvDetails&&n.jsx(Z,{className:"mb-6",title:"TV-Details",children:n.jsxs("dl",{className:"grid grid-cols-2 md:grid-cols-3 gap-4",children:[j.tvDetails.receiverModel&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Receiver"}),n.jsx("dd",{children:j.tvDetails.receiverModel})]}),j.tvDetails.smartcardNumber&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Smartcard"}),n.jsxs("dd",{className:"font-mono flex items-center gap-1",children:[j.tvDetails.smartcardNumber,n.jsx(oe,{value:j.tvDetails.smartcardNumber})]})]}),j.tvDetails.package&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Paket"}),n.jsx("dd",{children:j.tvDetails.package})]})]})}),j.carInsuranceDetails&&n.jsx(Z,{className:"mb-6",title:"KFZ-Versicherung Details",children:n.jsxs("dl",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[j.carInsuranceDetails.licensePlate&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Kennzeichen"}),n.jsxs("dd",{className:"font-mono font-bold flex items-center gap-1",children:[j.carInsuranceDetails.licensePlate,n.jsx(oe,{value:j.carInsuranceDetails.licensePlate})]})]}),j.carInsuranceDetails.vehicleType&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Fahrzeug"}),n.jsx("dd",{children:j.carInsuranceDetails.vehicleType})]}),j.carInsuranceDetails.hsn&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"HSN/TSN"}),n.jsxs("dd",{className:"font-mono flex items-center gap-1",children:[j.carInsuranceDetails.hsn,"/",j.carInsuranceDetails.tsn,n.jsx(oe,{value:`${j.carInsuranceDetails.hsn}/${j.carInsuranceDetails.tsn}`})]})]}),j.carInsuranceDetails.vin&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"FIN"}),n.jsxs("dd",{className:"font-mono text-sm flex items-center gap-1",children:[j.carInsuranceDetails.vin,n.jsx(oe,{value:j.carInsuranceDetails.vin})]})]}),j.carInsuranceDetails.firstRegistration&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Erstzulassung"}),n.jsx("dd",{children:new Date(j.carInsuranceDetails.firstRegistration).toLocaleDateString("de-DE")})]}),j.carInsuranceDetails.noClaimsClass&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"SF-Klasse"}),n.jsx("dd",{children:j.carInsuranceDetails.noClaimsClass})]}),n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Versicherungsart"}),n.jsx("dd",{children:n.jsx(he,{variant:j.carInsuranceDetails.insuranceType==="FULL"?"success":j.carInsuranceDetails.insuranceType==="PARTIAL"?"warning":"default",children:j.carInsuranceDetails.insuranceType==="FULL"?"Vollkasko":j.carInsuranceDetails.insuranceType==="PARTIAL"?"Teilkasko":"Haftpflicht"})})]}),j.carInsuranceDetails.deductiblePartial&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"SB Teilkasko"}),n.jsxs("dd",{children:[j.carInsuranceDetails.deductiblePartial," €"]})]}),j.carInsuranceDetails.deductibleFull&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"SB Vollkasko"}),n.jsxs("dd",{children:[j.carInsuranceDetails.deductibleFull," €"]})]}),j.carInsuranceDetails.policyNumber&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Versicherungsschein-Nr."}),n.jsxs("dd",{className:"font-mono flex items-center gap-1",children:[j.carInsuranceDetails.policyNumber,n.jsx(oe,{value:j.carInsuranceDetails.policyNumber})]})]}),j.carInsuranceDetails.previousInsurer&&n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Vorversicherer"}),n.jsx("dd",{children:j.carInsuranceDetails.previousInsurer})]})]})}),n.jsx(AS,{contractId:c,canEdit:i("contracts:update"),isCustomerPortal:o}),j.notes&&n.jsx(Z,{title:"Notizen",children:n.jsx("p",{className:"whitespace-pre-wrap",children:j.notes})})]})}const IS=[{value:"DRAFT",label:"Entwurf"},{value:"PENDING",label:"Ausstehend"},{value:"ACTIVE",label:"Aktiv"},{value:"CANCELLED",label:"Gekündigt"},{value:"EXPIRED",label:"Abgelaufen"}];function kp(){var gs,Ji,Pr,Ar,Xi,Fa,el,Ia,jh;const{id:e}=_o(),[t]=Uo(),s=Ut(),r=pe(),a=!!e,i=t.get("customerId"),{register:l,handleSubmit:o,reset:c,watch:u,setValue:d,formState:{errors:m}}=dv({defaultValues:{customerId:i||"",type:"ELECTRICITY",status:"DRAFT"}}),p=u("type"),h=u("customerId"),{data:f}=ge({queryKey:["contract",e],queryFn:()=>$e.getById(parseInt(e)),enabled:a}),{data:g}=ge({queryKey:["customers-all"],queryFn:()=>yt.getAll({limit:1e3})}),{data:b}=ge({queryKey:["customer",h],queryFn:()=>yt.getById(parseInt(h)),enabled:!!h}),{data:y}=ge({queryKey:["platforms"],queryFn:()=>Pi.getAll()}),{data:v}=ge({queryKey:["cancellation-periods"],queryFn:()=>Ai.getAll()}),{data:x}=ge({queryKey:["contract-durations"],queryFn:()=>Ti.getAll()}),{data:N}=ge({queryKey:["providers"],queryFn:()=>Na.getAll()}),{data:k}=ge({queryKey:["contract-categories"],queryFn:()=>Fi.getAll()}),D=u("providerId"),[F,S]=w.useState(null),[L,T]=w.useState([]),[_,K]=w.useState([]),[W,Q]=w.useState(!1),[z,P]=w.useState("manual"),[j,B]=w.useState(""),[J,ee]=w.useState(!1),[me,ve]=w.useState(!1),[it,V]=w.useState({}),[Ce,Me]=w.useState({}),[ht,Tt]=w.useState({});w.useEffect(()=>{a||Q(!0)},[a]),w.useEffect(()=>{W&&F!==null&&D!==F&&d("tariffId",""),S(D)},[D,F,d,W]),w.useEffect(()=>{if(!a&&(k!=null&&k.data)&&k.data.length>0){const A=u("type"),ne=k.data.filter(ie=>ie.isActive),fe=ne.some(ie=>ie.code===A);if(!A||!fe){const ie=ne.sort((de,Ge)=>de.sortOrder-Ge.sortOrder)[0];ie&&d("type",ie.code)}}},[k,a,d,u]),w.useEffect(()=>{var A,ne,fe,ie,de,Ge,je,Ma,bh,Nh,wh,Sh,kh,Ch,Eh,Dh,Ph,Ah,Th,Fh,Ih,Mh,Lh,Rh,Oh,_h,zh,Uh,$h,Bh,Kh,Vh,qh,Qh,Hh,Wh,Gh,Zh,Yh,Jh,Xh,em,tm,sm,nm,rm,am,im,lm;if(f!=null&&f.data){const X=f.data;c({customerId:X.customerId.toString(),type:X.type,status:X.status,addressId:((A=X.addressId)==null?void 0:A.toString())||"",bankCardId:((ne=X.bankCardId)==null?void 0:ne.toString())||"",identityDocumentId:((fe=X.identityDocumentId)==null?void 0:fe.toString())||"",salesPlatformId:((ie=X.salesPlatformId)==null?void 0:ie.toString())||"",providerId:((de=X.providerId)==null?void 0:de.toString())||"",tariffId:((Ge=X.tariffId)==null?void 0:Ge.toString())||"",providerName:X.providerName||"",tariffName:X.tariffName||"",customerNumberAtProvider:X.customerNumberAtProvider||"",priceFirst12Months:X.priceFirst12Months||"",priceFrom13Months:X.priceFrom13Months||"",priceAfter24Months:X.priceAfter24Months||"",startDate:X.startDate?X.startDate.split("T")[0]:"",endDate:X.endDate?X.endDate.split("T")[0]:"",cancellationPeriodId:((je=X.cancellationPeriodId)==null?void 0:je.toString())||"",contractDurationId:((Ma=X.contractDurationId)==null?void 0:Ma.toString())||"",commission:X.commission||"",portalUsername:X.portalUsername||"",notes:X.notes||"",meterId:((Nh=(bh=X.energyDetails)==null?void 0:bh.meterId)==null?void 0:Nh.toString())||"",annualConsumption:((wh=X.energyDetails)==null?void 0:wh.annualConsumption)||"",basePrice:((Sh=X.energyDetails)==null?void 0:Sh.basePrice)||"",unitPrice:((kh=X.energyDetails)==null?void 0:kh.unitPrice)||"",bonus:((Ch=X.energyDetails)==null?void 0:Ch.bonus)||"",previousProviderName:((Eh=X.energyDetails)==null?void 0:Eh.previousProviderName)||"",previousCustomerNumber:((Dh=X.energyDetails)==null?void 0:Dh.previousCustomerNumber)||"",downloadSpeed:((Ph=X.internetDetails)==null?void 0:Ph.downloadSpeed)||"",uploadSpeed:((Ah=X.internetDetails)==null?void 0:Ah.uploadSpeed)||"",routerModel:((Th=X.internetDetails)==null?void 0:Th.routerModel)||"",routerSerialNumber:((Fh=X.internetDetails)==null?void 0:Fh.routerSerialNumber)||"",installationDate:(Ih=X.internetDetails)!=null&&Ih.installationDate?X.internetDetails.installationDate.split("T")[0]:"",internetUsername:((Mh=X.internetDetails)==null?void 0:Mh.internetUsername)||"",homeId:((Lh=X.internetDetails)==null?void 0:Lh.homeId)||"",activationCode:((Rh=X.internetDetails)==null?void 0:Rh.activationCode)||"",requiresMultisim:((Oh=X.mobileDetails)==null?void 0:Oh.requiresMultisim)||!1,dataVolume:((_h=X.mobileDetails)==null?void 0:_h.dataVolume)||"",includedMinutes:((zh=X.mobileDetails)==null?void 0:zh.includedMinutes)||"",includedSMS:((Uh=X.mobileDetails)==null?void 0:Uh.includedSMS)||"",deviceModel:(($h=X.mobileDetails)==null?void 0:$h.deviceModel)||"",deviceImei:((Bh=X.mobileDetails)==null?void 0:Bh.deviceImei)||"",phoneNumber:((Kh=X.mobileDetails)==null?void 0:Kh.phoneNumber)||"",simCardNumber:((Vh=X.mobileDetails)==null?void 0:Vh.simCardNumber)||"",receiverModel:((qh=X.tvDetails)==null?void 0:qh.receiverModel)||"",smartcardNumber:((Qh=X.tvDetails)==null?void 0:Qh.smartcardNumber)||"",tvPackage:((Hh=X.tvDetails)==null?void 0:Hh.package)||"",licensePlate:((Wh=X.carInsuranceDetails)==null?void 0:Wh.licensePlate)||"",hsn:((Gh=X.carInsuranceDetails)==null?void 0:Gh.hsn)||"",tsn:((Zh=X.carInsuranceDetails)==null?void 0:Zh.tsn)||"",vin:((Yh=X.carInsuranceDetails)==null?void 0:Yh.vin)||"",vehicleType:((Jh=X.carInsuranceDetails)==null?void 0:Jh.vehicleType)||"",firstRegistration:(Xh=X.carInsuranceDetails)!=null&&Xh.firstRegistration?X.carInsuranceDetails.firstRegistration.split("T")[0]:"",noClaimsClass:((em=X.carInsuranceDetails)==null?void 0:em.noClaimsClass)||"",insuranceType:((tm=X.carInsuranceDetails)==null?void 0:tm.insuranceType)||"LIABILITY",deductiblePartial:((sm=X.carInsuranceDetails)==null?void 0:sm.deductiblePartial)||"",deductibleFull:((nm=X.carInsuranceDetails)==null?void 0:nm.deductibleFull)||"",policyNumber:((rm=X.carInsuranceDetails)==null?void 0:rm.policyNumber)||"",previousInsurer:((am=X.carInsuranceDetails)==null?void 0:am.previousInsurer)||"",cancellationConfirmationDate:X.cancellationConfirmationDate?X.cancellationConfirmationDate.split("T")[0]:"",cancellationConfirmationOptionsDate:X.cancellationConfirmationOptionsDate?X.cancellationConfirmationOptionsDate.split("T")[0]:"",wasSpecialCancellation:X.wasSpecialCancellation||!1}),(im=X.mobileDetails)!=null&&im.simCards&&X.mobileDetails.simCards.length>0?T(X.mobileDetails.simCards.map($t=>({id:$t.id,phoneNumber:$t.phoneNumber||"",simCardNumber:$t.simCardNumber||"",pin:"",puk:"",hasExistingPin:!!$t.pin,hasExistingPuk:!!$t.puk,isMultisim:$t.isMultisim,isMain:$t.isMain}))):T([]),(lm=X.internetDetails)!=null&&lm.phoneNumbers&&X.internetDetails.phoneNumbers.length>0?K(X.internetDetails.phoneNumbers.map($t=>({id:$t.id,phoneNumber:$t.phoneNumber||"",sipUsername:$t.sipUsername||"",sipPassword:"",hasExistingSipPassword:!!$t.sipPasswordEncrypted,sipServer:$t.sipServer||"",isMain:$t.isMain}))):K([]),X.stressfreiEmailId?(P("stressfrei"),B(X.stressfreiEmailId.toString())):(P("manual"),B("")),Q(!0)}},[f,c]);const Jt=u("startDate"),Pe=u("contractDurationId");w.useEffect(()=>{if(Jt&&Pe&&(x!=null&&x.data)){const A=x.data.find(ne=>ne.id===parseInt(Pe));if(A){const ne=new Date(Jt),ie=A.code.match(/^(\d+)([MTJ])$/);if(ie){const de=parseInt(ie[1]),Ge=ie[2];let je=new Date(ne);Ge==="T"?je.setDate(je.getDate()+de):Ge==="M"?je.setMonth(je.getMonth()+de):Ge==="J"&&je.setFullYear(je.getFullYear()+de),d("endDate",je.toISOString().split("T")[0])}}}},[Jt,Pe,x,d]);const Xt=Y({mutationFn:$e.create,onSuccess:(A,ne)=>{r.invalidateQueries({queryKey:["contracts"]}),ne.customerId&&r.invalidateQueries({queryKey:["customer",ne.customerId.toString()]}),r.invalidateQueries({queryKey:["customers"]}),s(i?`/customers/${i}?tab=contracts`:"/contracts")}}),Gn=Y({mutationFn:A=>$e.update(parseInt(e),A),onSuccess:(A,ne)=>{r.invalidateQueries({queryKey:["contracts"]}),r.invalidateQueries({queryKey:["contract",e]}),ne.customerId&&r.invalidateQueries({queryKey:["customer",ne.customerId.toString()]}),r.invalidateQueries({queryKey:["customers"]}),s(`/contracts/${e}`)}}),Er=A=>{const ne=je=>{if(je==null||je==="")return;const Ma=parseInt(String(je));return isNaN(Ma)?void 0:Ma},fe=H.find(je=>je.code===A.type),ie=ne(A.customerId);if(!ie){alert("Bitte wählen Sie einen Kunden aus");return}if(!A.type||!fe){alert("Bitte wählen Sie einen Vertragstyp aus");return}const de=je=>je==null||je===""?null:je,Ge={customerId:ie,type:A.type,contractCategoryId:fe.id,status:A.status,addressId:ne(A.addressId)??null,bankCardId:ne(A.bankCardId)??null,identityDocumentId:ne(A.identityDocumentId)??null,salesPlatformId:ne(A.salesPlatformId)??null,providerId:ne(A.providerId)??null,tariffId:ne(A.tariffId)??null,providerName:de(A.providerName),tariffName:de(A.tariffName),customerNumberAtProvider:de(A.customerNumberAtProvider),priceFirst12Months:de(A.priceFirst12Months),priceFrom13Months:de(A.priceFrom13Months),priceAfter24Months:de(A.priceAfter24Months),startDate:A.startDate?new Date(A.startDate):null,endDate:A.endDate?new Date(A.endDate):null,cancellationPeriodId:ne(A.cancellationPeriodId)??null,contractDurationId:ne(A.contractDurationId)??null,commission:A.commission?parseFloat(A.commission):null,portalUsername:z==="manual"?de(A.portalUsername):null,stressfreiEmailId:z==="stressfrei"&&j?parseInt(j):null,portalPassword:A.portalPassword||void 0,notes:de(A.notes),cancellationConfirmationDate:A.cancellationConfirmationDate?new Date(A.cancellationConfirmationDate):null,cancellationConfirmationOptionsDate:A.cancellationConfirmationOptionsDate?new Date(A.cancellationConfirmationOptionsDate):null,wasSpecialCancellation:A.wasSpecialCancellation||!1};["ELECTRICITY","GAS"].includes(A.type)&&(Ge.energyDetails={meterId:ne(A.meterId)??null,annualConsumption:A.annualConsumption?parseFloat(A.annualConsumption):null,basePrice:A.basePrice?parseFloat(A.basePrice):null,unitPrice:A.unitPrice?parseFloat(A.unitPrice):null,bonus:A.bonus?parseFloat(A.bonus):null,previousProviderName:de(A.previousProviderName),previousCustomerNumber:de(A.previousCustomerNumber)}),["DSL","CABLE","FIBER"].includes(A.type)&&(Ge.internetDetails={downloadSpeed:ne(A.downloadSpeed)??null,uploadSpeed:ne(A.uploadSpeed)??null,routerModel:de(A.routerModel),routerSerialNumber:de(A.routerSerialNumber),installationDate:A.installationDate?new Date(A.installationDate):null,internetUsername:de(A.internetUsername),internetPassword:A.internetPassword||void 0,homeId:de(A.homeId),activationCode:de(A.activationCode),phoneNumbers:_.length>0?_.map(je=>({id:je.id,phoneNumber:je.phoneNumber||"",isMain:je.isMain??!1,sipUsername:de(je.sipUsername),sipPassword:je.sipPassword||void 0,sipServer:de(je.sipServer)})):void 0}),A.type==="MOBILE"&&(Ge.mobileDetails={requiresMultisim:A.requiresMultisim||!1,dataVolume:A.dataVolume?parseFloat(A.dataVolume):null,includedMinutes:ne(A.includedMinutes)??null,includedSMS:ne(A.includedSMS)??null,deviceModel:de(A.deviceModel),deviceImei:de(A.deviceImei),phoneNumber:de(A.phoneNumber),simCardNumber:de(A.simCardNumber),simCards:L.length>0?L.map(je=>({id:je.id,phoneNumber:de(je.phoneNumber),simCardNumber:de(je.simCardNumber),pin:je.pin||void 0,puk:je.puk||void 0,isMultisim:je.isMultisim,isMain:je.isMain})):void 0}),A.type==="TV"&&(Ge.tvDetails={receiverModel:de(A.receiverModel),smartcardNumber:de(A.smartcardNumber),package:de(A.tvPackage)}),A.type==="CAR_INSURANCE"&&(Ge.carInsuranceDetails={licensePlate:de(A.licensePlate),hsn:de(A.hsn),tsn:de(A.tsn),vin:de(A.vin),vehicleType:de(A.vehicleType),firstRegistration:A.firstRegistration?new Date(A.firstRegistration):null,noClaimsClass:de(A.noClaimsClass),insuranceType:A.insuranceType,deductiblePartial:A.deductiblePartial?parseFloat(A.deductiblePartial):null,deductibleFull:A.deductibleFull?parseFloat(A.deductibleFull):null,policyNumber:de(A.policyNumber),previousInsurer:de(A.previousInsurer)}),a?Gn.mutate(Ge):Xt.mutate(Ge)},hn=Xt.isPending||Gn.isPending,Dr=Xt.error||Gn.error,mt=b==null?void 0:b.data,Zo=(mt==null?void 0:mt.addresses)||[],Yo=((gs=mt==null?void 0:mt.bankCards)==null?void 0:gs.filter(A=>A.isActive))||[],vh=((Ji=mt==null?void 0:mt.identityDocuments)==null?void 0:Ji.filter(A=>A.isActive))||[],Yi=((Pr=mt==null?void 0:mt.meters)==null?void 0:Pr.filter(A=>A.isActive))||[],E=((Ar=mt==null?void 0:mt.stressfreiEmails)==null?void 0:Ar.filter(A=>A.isActive))||[],M=(y==null?void 0:y.data)||[],U=(v==null?void 0:v.data)||[],se=(x==null?void 0:x.data)||[],G=((Xi=N==null?void 0:N.data)==null?void 0:Xi.filter(A=>A.isActive))||[],H=((Fa=k==null?void 0:k.data)==null?void 0:Fa.filter(A=>A.isActive).sort((A,ne)=>A.sortOrder-ne.sortOrder))||[],ce=H.map(A=>({value:A.code,label:A.name})),we=G.find(A=>A.id===parseInt(D||"0")),Ae=((el=we==null?void 0:we.tariffs)==null?void 0:el.filter(A=>A.isActive))||[],ft=A=>{const ne=A.companyName||`${A.firstName} ${A.lastName}`,fe=A.birthDate?` (geb. ${new Date(A.birthDate).toLocaleDateString("de-DE",{day:"2-digit",month:"2-digit",year:"numeric"})})`:"";return`${A.customerNumber} - ${ne}${fe}`},Bs=(()=>{var fe;const ne=((g==null?void 0:g.data)||[]).map(ie=>({value:ie.id.toString(),label:ft(ie)}));if(a&&((fe=f==null?void 0:f.data)!=null&&fe.customer)){const ie=f.data.customer;ne.some(Ge=>Ge.value===ie.id.toString())||ne.unshift({value:ie.id.toString(),label:ft(ie)})}return ne})();return n.jsxs("div",{children:[n.jsx("h1",{className:"text-2xl font-bold mb-6",children:a?"Vertrag bearbeiten":"Neuer Vertrag"}),Dr&&n.jsx("div",{className:"mb-4 p-4 bg-red-50 border border-red-200 text-red-700 rounded-lg",children:Dr instanceof Error?Dr.message:"Ein Fehler ist aufgetreten"}),n.jsxs("form",{onSubmit:o(Er),children:[n.jsx(Z,{className:"mb-6",title:"Vertragsdaten",children:n.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[n.jsx(Le,{label:"Kunde *",...l("customerId",{required:"Kunde erforderlich"}),options:Bs,error:(Ia=m.customerId)==null?void 0:Ia.message}),n.jsx(Le,{label:"Vertragstyp *",...l("type",{required:"Typ erforderlich"}),options:ce}),n.jsx(Le,{label:"Status",...l("status"),options:IS}),n.jsx(Le,{label:"Vertriebsplattform",...l("salesPlatformId"),options:M.map(A=>({value:A.id,label:A.name}))})]})}),h&&n.jsx(Z,{className:"mb-6",title:"Kundendaten verknüpfen",children:n.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[n.jsx(Le,{label:"Adresse",...l("addressId"),options:Zo.map(A=>({value:A.id,label:`${A.street} ${A.houseNumber}, ${A.postalCode} ${A.city} (${A.type==="BILLING"?"Rechnung":"Liefer"})`}))}),n.jsx(Le,{label:"Bankkarte",...l("bankCardId"),options:Yo.map(A=>({value:A.id,label:`${A.iban} (${A.accountHolder})`}))}),n.jsx(Le,{label:"Ausweis",...l("identityDocumentId"),options:vh.map(A=>({value:A.id,label:`${A.documentNumber} (${A.type})`}))})]})}),n.jsx(Z,{className:"mb-6",title:"Anbieter & Tarif",children:n.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[n.jsx(Le,{label:"Anbieter",...l("providerId"),options:G.map(A=>({value:A.id,label:A.name}))}),n.jsx(Le,{label:"Tarif",...l("tariffId"),options:Ae.map(A=>({value:A.id,label:A.name})),disabled:!D}),n.jsx($,{label:"Kundennummer beim Anbieter",...l("customerNumberAtProvider")}),n.jsx($,{label:"Provision (€)",type:"number",step:"0.01",...l("commission")}),n.jsx($,{label:"Preis erste 12 Monate",...l("priceFirst12Months"),placeholder:"z.B. 29,99 €/Monat"}),n.jsx($,{label:"Preis ab 13. Monat",...l("priceFrom13Months"),placeholder:"z.B. 39,99 €/Monat"}),n.jsx($,{label:"Preis nach 24 Monaten",...l("priceAfter24Months"),placeholder:"z.B. 49,99 €/Monat"})]})}),n.jsxs(Z,{className:"mb-6",title:"Laufzeit und Kündigung",children:[n.jsxs("p",{className:"text-sm text-gray-500 mb-4 bg-blue-50 border border-blue-200 rounded-lg p-3",children:[n.jsx("strong",{children:"Hinweis:"})," Ist die Laufzeit ≤ 4 Wochen, 1 Monat oder 30 Tage, gilt der Vertrag als unbefristet mit der jeweiligen Kündigungsfrist."]}),n.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[n.jsx($,{label:"Vertragsbeginn",type:"date",...l("startDate"),value:u("startDate")||"",onClear:()=>d("startDate","")}),n.jsx($,{label:"Vertragsende (berechnet)",type:"date",...l("endDate"),disabled:!0,className:"bg-gray-50"}),n.jsx(Le,{label:"Vertragslaufzeit",...l("contractDurationId"),options:se.map(A=>({value:A.id,label:A.description}))}),n.jsx(Le,{label:"Kündigungsfrist",...l("cancellationPeriodId"),options:U.map(A=>({value:A.id,label:A.description}))}),n.jsx($,{label:"Kündigungsbestätigungsdatum",type:"date",...l("cancellationConfirmationDate"),value:u("cancellationConfirmationDate")||"",onClear:()=>d("cancellationConfirmationDate","")}),n.jsx($,{label:"Kündigungsbestätigungsoptionendatum",type:"date",...l("cancellationConfirmationOptionsDate"),value:u("cancellationConfirmationOptionsDate")||"",onClear:()=>d("cancellationConfirmationOptionsDate","")}),n.jsx("div",{className:"col-span-2",children:n.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[n.jsx("input",{type:"checkbox",...l("wasSpecialCancellation"),className:"rounded border-gray-300"}),n.jsx("span",{children:"Wurde sondergekündigt?"})]})})]})]}),n.jsx(Z,{className:"mb-6",title:"Zugangsdaten (verschlüsselt gespeichert)",children:n.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Portal Benutzername"}),n.jsxs("div",{className:"space-y-2",children:[n.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[n.jsx("input",{type:"radio",name:"usernameType",checked:z==="manual",onChange:()=>{P("manual"),B("")},className:"text-blue-600"}),n.jsx("span",{className:"text-sm",children:"Manuell eingeben"})]}),z==="manual"&&n.jsx($,{...l("portalUsername"),placeholder:"Benutzername eingeben..."}),n.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[n.jsx("input",{type:"radio",name:"usernameType",checked:z==="stressfrei",onChange:()=>{P("stressfrei"),d("portalUsername","")},className:"text-blue-600"}),n.jsx("span",{className:"text-sm",children:"Stressfrei-Wechseln Adresse"})]}),z==="stressfrei"&&n.jsx(Le,{value:j,onChange:A=>B(A.target.value),options:E.map(A=>({value:A.id,label:A.email+(A.notes?` (${A.notes})`:"")})),placeholder:E.length===0?"Keine Stressfrei-Adressen vorhanden":"Adresse auswählen..."}),z==="stressfrei"&&E.length===0&&n.jsx("p",{className:"text-xs text-amber-600",children:"Keine Stressfrei-Wechseln Adressen für diesen Kunden vorhanden. Bitte zuerst beim Kunden anlegen."})]})]}),n.jsxs("div",{className:"mt-8",children:[n.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:a?"Neues Passwort (leer lassen = unverändert)":"Portal Passwort"}),n.jsxs("div",{className:"relative",children:[n.jsx("input",{type:J?"text":"password",...l("portalPassword"),className:"block w-full px-3 py-2 pr-10 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"}),n.jsx("button",{type:"button",onClick:()=>ee(!J),className:"absolute inset-y-0 right-0 flex items-center pr-3 text-gray-400 hover:text-gray-600",children:J?n.jsx(Pt,{className:"w-4 h-4"}):n.jsx(Ee,{className:"w-4 h-4"})})]})]})]})}),["ELECTRICITY","GAS"].includes(p)&&n.jsx(Z,{className:"mb-6",title:p==="ELECTRICITY"?"Strom-Details":"Gas-Details",children:n.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[n.jsx(Le,{label:"Zähler",...l("meterId"),options:Yi.filter(A=>A.type===p).map(A=>({value:A.id,label:`${A.meterNumber}${A.location?` (${A.location})`:""}`}))}),n.jsx($,{label:`Jahresverbrauch (${p==="ELECTRICITY"?"kWh":"m³"})`,type:"number",...l("annualConsumption")}),n.jsx($,{label:"Grundpreis (€/Monat)",type:"number",step:"0.01",...l("basePrice")}),n.jsx($,{label:`Arbeitspreis (ct/${p==="ELECTRICITY"?"kWh":"m³"})`,type:"number",step:"0.01",...l("unitPrice")}),n.jsx($,{label:"Bonus (€)",type:"number",step:"0.01",...l("bonus")}),n.jsx($,{label:"Vorversorger",...l("previousProviderName")}),n.jsx($,{label:"Kundennr. beim Vorversorger",...l("previousCustomerNumber")})]})}),["DSL","CABLE","FIBER"].includes(p)&&n.jsxs(n.Fragment,{children:[n.jsx(Z,{className:"mb-6",title:p==="DSL"?"DSL-Details":p==="CABLE"?"Kabelinternet-Details":"Glasfaser-Details",children:n.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[n.jsx($,{label:"Download (Mbit/s)",type:"number",...l("downloadSpeed")}),n.jsx($,{label:"Upload (Mbit/s)",type:"number",...l("uploadSpeed")}),n.jsx($,{label:"Router Modell",...l("routerModel")}),n.jsx($,{label:"Router Seriennummer",...l("routerSerialNumber")}),n.jsx($,{label:"Installationsdatum",type:"date",...l("installationDate"),value:u("installationDate")||"",onClear:()=>d("installationDate","")}),p==="FIBER"&&n.jsx($,{label:"Home-ID",...l("homeId")}),((jh=we==null?void 0:we.name)==null?void 0:jh.toLowerCase().includes("vodafone"))&&["DSL","CABLE"].includes(p)&&n.jsx($,{label:"Aktivierungscode",...l("activationCode")})]})}),n.jsx(Z,{className:"mb-6",title:"Internet-Zugangsdaten (verschlüsselt)",children:n.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[n.jsx($,{label:"Benutzername",...l("internetUsername")}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:a?"Neues Passwort (leer = beibehalten)":"Passwort"}),n.jsxs("div",{className:"relative",children:[n.jsx("input",{type:me?"text":"password",...l("internetPassword"),className:"block w-full px-3 py-2 pr-10 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"}),n.jsx("button",{type:"button",onClick:()=>ve(!me),className:"absolute inset-y-0 right-0 flex items-center pr-3 text-gray-400 hover:text-gray-600",children:me?n.jsx(Pt,{className:"w-4 h-4"}):n.jsx(Ee,{className:"w-4 h-4"})})]})]})]})}),n.jsxs(Z,{className:"mb-6",title:"Rufnummern & SIP-Zugangsdaten",children:[n.jsx("p",{className:"text-sm text-gray-500 mb-4",children:"Hier können Sie Festnetz-Rufnummern mit SIP-Zugangsdaten erfassen."}),_.length>0&&n.jsx("div",{className:"space-y-4 mb-4",children:_.map((A,ne)=>n.jsxs("div",{className:"p-4 border rounded-lg bg-gray-50",children:[n.jsxs("div",{className:"flex justify-between items-center mb-3",children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsxs("span",{className:"font-medium",children:["Rufnummer ",ne+1]}),n.jsxs("label",{className:"flex items-center gap-1 text-sm",children:[n.jsx("input",{type:"checkbox",checked:A.isMain,onChange:fe=>{const ie=[..._];fe.target.checked?ie.forEach((de,Ge)=>de.isMain=Ge===ne):ie[ne].isMain=!1,K(ie)},className:"rounded border-gray-300"}),"Hauptnummer"]})]}),n.jsx(I,{type:"button",variant:"ghost",size:"sm",onClick:()=>{K(_.filter((fe,ie)=>ie!==ne))},children:n.jsx(be,{className:"w-4 h-4 text-red-500"})})]}),n.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-3",children:[n.jsx($,{label:"Rufnummer",value:A.phoneNumber,onChange:fe=>{const ie=[..._];ie[ne].phoneNumber=fe.target.value,K(ie)},placeholder:"z.B. 030 123456"}),n.jsx($,{label:"SIP-Benutzername",value:A.sipUsername,onChange:fe=>{const ie=[..._];ie[ne].sipUsername=fe.target.value,K(ie)}}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:A.hasExistingSipPassword?"SIP-Passwort (bereits hinterlegt)":"SIP-Passwort"}),n.jsxs("div",{className:"relative",children:[n.jsx("input",{type:it[ne]?"text":"password",value:A.sipPassword,onChange:fe=>{const ie=[..._];ie[ne].sipPassword=fe.target.value,K(ie)},placeholder:A.hasExistingSipPassword?"Leer = beibehalten":"",className:"block w-full px-3 py-2 pr-10 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"}),n.jsx("button",{type:"button",onClick:()=>V(fe=>({...fe,[ne]:!fe[ne]})),className:"absolute inset-y-0 right-0 flex items-center pr-3 text-gray-400 hover:text-gray-600",children:it[ne]?n.jsx(Pt,{className:"w-4 h-4"}):n.jsx(Ee,{className:"w-4 h-4"})})]})]}),n.jsx($,{label:"SIP-Server",value:A.sipServer,onChange:fe=>{const ie=[..._];ie[ne].sipServer=fe.target.value,K(ie)},placeholder:"z.B. sip.provider.de"})]})]},ne))}),n.jsxs(I,{type:"button",variant:"secondary",onClick:()=>{K([..._,{phoneNumber:"",sipUsername:"",sipPassword:"",sipServer:"",isMain:_.length===0}])},children:[n.jsx(Oe,{className:"w-4 h-4 mr-2"}),"Rufnummer hinzufügen"]})]})]}),p==="MOBILE"&&n.jsxs(n.Fragment,{children:[n.jsxs(Z,{className:"mb-6",title:"Mobilfunk-Details",children:[n.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[n.jsx($,{label:"Datenvolumen (GB)",type:"number",...l("dataVolume")}),n.jsx($,{label:"Inklusiv-Minuten",type:"number",...l("includedMinutes")}),n.jsx($,{label:"Inklusiv-SMS",type:"number",...l("includedSMS")}),n.jsx($,{label:"Gerät (Modell)",...l("deviceModel")}),n.jsx($,{label:"Gerät (IMEI)",...l("deviceImei")})]}),n.jsx("div",{className:"mt-4 pt-4 border-t",children:n.jsxs("label",{className:"flex items-start gap-3 cursor-pointer",children:[n.jsx("input",{type:"checkbox",...l("requiresMultisim"),className:"mt-1 rounded border-gray-300"}),n.jsxs("div",{children:[n.jsx("span",{className:"font-medium",children:"Multisim erforderlich"}),n.jsx("p",{className:"text-sm text-amber-600 mt-1",children:"Hinweis: Multisim ist bei Klarmobil, Congstar und Otelo nicht buchbar. Muss Freenet oder vergleichbar sein."})]})]})})]}),n.jsxs(Z,{className:"mb-6",title:"SIM-Karten",children:[n.jsx("p",{className:"text-sm text-gray-500 mb-4",children:"Hier können Sie alle SIM-Karten zum Vertrag erfassen (Hauptkarte und Multisim-Karten)."}),L.length>0&&n.jsx("div",{className:"space-y-4 mb-4",children:L.map((A,ne)=>n.jsxs("div",{className:"p-4 border rounded-lg bg-gray-50",children:[n.jsxs("div",{className:"flex justify-between items-center mb-3",children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsxs("span",{className:"font-medium",children:["SIM-Karte ",ne+1]}),n.jsxs("label",{className:"flex items-center gap-1 text-sm",children:[n.jsx("input",{type:"checkbox",checked:A.isMain,onChange:fe=>{const ie=[...L];fe.target.checked?ie.forEach((de,Ge)=>de.isMain=Ge===ne):ie[ne].isMain=!1,T(ie)},className:"rounded border-gray-300"}),"Hauptkarte"]}),n.jsxs("label",{className:"flex items-center gap-1 text-sm",children:[n.jsx("input",{type:"checkbox",checked:A.isMultisim,onChange:fe=>{const ie=[...L];ie[ne].isMultisim=fe.target.checked,T(ie)},className:"rounded border-gray-300"}),"Multisim"]})]}),n.jsx(I,{type:"button",variant:"ghost",size:"sm",onClick:()=>{T(L.filter((fe,ie)=>ie!==ne))},children:n.jsx(be,{className:"w-4 h-4 text-red-500"})})]}),n.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-3",children:[n.jsx($,{label:"Rufnummer",value:A.phoneNumber,onChange:fe=>{const ie=[...L];ie[ne].phoneNumber=fe.target.value,T(ie)},placeholder:"z.B. 0171 1234567"}),n.jsx($,{label:"SIM-Kartennummer",value:A.simCardNumber,onChange:fe=>{const ie=[...L];ie[ne].simCardNumber=fe.target.value,T(ie)},placeholder:"ICCID"}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:A.hasExistingPin?"PIN (bereits hinterlegt)":"PIN"}),n.jsxs("div",{className:"relative",children:[n.jsx("input",{type:Ce[ne]?"text":"password",value:A.pin,onChange:fe=>{const ie=[...L];ie[ne].pin=fe.target.value,T(ie)},placeholder:A.hasExistingPin?"Leer = beibehalten":"4-stellig",className:"block w-full px-3 py-2 pr-10 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"}),n.jsx("button",{type:"button",onClick:()=>Me(fe=>({...fe,[ne]:!fe[ne]})),className:"absolute inset-y-0 right-0 flex items-center pr-3 text-gray-400 hover:text-gray-600",children:Ce[ne]?n.jsx(Pt,{className:"w-4 h-4"}):n.jsx(Ee,{className:"w-4 h-4"})})]})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:A.hasExistingPuk?"PUK (bereits hinterlegt)":"PUK"}),n.jsxs("div",{className:"relative",children:[n.jsx("input",{type:ht[ne]?"text":"password",value:A.puk,onChange:fe=>{const ie=[...L];ie[ne].puk=fe.target.value,T(ie)},placeholder:A.hasExistingPuk?"Leer = beibehalten":"8-stellig",className:"block w-full px-3 py-2 pr-10 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"}),n.jsx("button",{type:"button",onClick:()=>Tt(fe=>({...fe,[ne]:!fe[ne]})),className:"absolute inset-y-0 right-0 flex items-center pr-3 text-gray-400 hover:text-gray-600",children:ht[ne]?n.jsx(Pt,{className:"w-4 h-4"}):n.jsx(Ee,{className:"w-4 h-4"})})]})]})]})]},ne))}),n.jsxs(I,{type:"button",variant:"secondary",onClick:()=>{T([...L,{phoneNumber:"",simCardNumber:"",pin:"",puk:"",isMultisim:!1,isMain:L.length===0}])},children:[n.jsx(Oe,{className:"w-4 h-4 mr-2"}),"SIM-Karte hinzufügen"]})]})]}),p==="TV"&&n.jsx(Z,{className:"mb-6",title:"TV-Details",children:n.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[n.jsx($,{label:"Receiver Modell",...l("receiverModel")}),n.jsx($,{label:"Smartcard-Nummer",...l("smartcardNumber")}),n.jsx($,{label:"Paket",...l("tvPackage"),placeholder:"z.B. Basis, Premium, Sport"})]})}),p==="CAR_INSURANCE"&&n.jsx(Z,{className:"mb-6",title:"KFZ-Versicherung Details",children:n.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[n.jsx($,{label:"Kennzeichen",...l("licensePlate")}),n.jsx($,{label:"HSN",...l("hsn")}),n.jsx($,{label:"TSN",...l("tsn")}),n.jsx($,{label:"FIN (VIN)",...l("vin")}),n.jsx($,{label:"Fahrzeugtyp",...l("vehicleType")}),n.jsx($,{label:"Erstzulassung",type:"date",...l("firstRegistration"),value:u("firstRegistration")||"",onClear:()=>d("firstRegistration","")}),n.jsx($,{label:"SF-Klasse",...l("noClaimsClass")}),n.jsx(Le,{label:"Versicherungsart",...l("insuranceType"),options:[{value:"LIABILITY",label:"Haftpflicht"},{value:"PARTIAL",label:"Teilkasko"},{value:"FULL",label:"Vollkasko"}]}),n.jsx($,{label:"SB Teilkasko (€)",type:"number",...l("deductiblePartial")}),n.jsx($,{label:"SB Vollkasko (€)",type:"number",...l("deductibleFull")}),n.jsx($,{label:"Versicherungsscheinnummer",...l("policyNumber")}),n.jsx($,{label:"Vorversicherer",...l("previousInsurer")})]})}),n.jsx(Z,{className:"mb-6",title:"Notizen",children:n.jsx("textarea",{...l("notes"),rows:4,className:"block w-full px-3 py-2 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",placeholder:"Interne Notizen..."})}),n.jsxs("div",{className:"flex justify-end gap-4",children:[n.jsx(I,{type:"button",variant:"secondary",onClick:()=>s(-1),children:"Abbrechen"}),n.jsx(I,{type:"submit",disabled:hn,children:hn?"Speichern...":"Speichern"})]})]})]})}const MS={ELECTRICITY:mh,GAS:Jy,DSL:ea,CABLE:ea,FIBER:ea,MOBILE:dh,TV:sv,CAR_INSURANCE:Hy},LS={ELECTRICITY:"Strom",GAS:"Gas",DSL:"DSL",CABLE:"Kabel",FIBER:"Glasfaser",MOBILE:"Mobilfunk",TV:"TV",CAR_INSURANCE:"KFZ"},RS={critical:"bg-red-100 border-red-300 text-red-800",warning:"bg-yellow-100 border-yellow-300 text-yellow-800",ok:"bg-green-100 border-green-300 text-green-800",none:"bg-gray-100 border-gray-300 text-gray-800"},OS={critical:"danger",warning:"warning",ok:"success",none:"default"},_S={cancellation_deadline:Qy,contract_ending:qn,missing_cancellation_letter:vt,missing_cancellation_confirmation:vt,missing_portal_credentials:y1,missing_customer_number:vt,missing_provider:vt,missing_address:vt,missing_bank:vt,missing_meter:mh,missing_sim:dh,open_tasks:Ii,pending_status:qn,draft_status:vt},zS={cancellationDeadlines:"Kündigungsfristen",contractEnding:"Vertragsenden",missingCredentials:"Fehlende Zugangsdaten",missingData:"Fehlende Daten",openTasks:"Offene Aufgaben",pendingContracts:"Wartende Verträge"};function US(){var g;const[e,t]=Uo(),[s,r]=w.useState(new Set),a=e.get("filter"),[i,l]=w.useState(a||"all");w.useEffect(()=>{i==="all"?e.delete("filter"):e.set("filter",i),t(e,{replace:!0})},[i,e,t]);const{data:o,isLoading:c,error:u}=ge({queryKey:["contract-cockpit"],queryFn:()=>$e.getCockpit(),staleTime:0}),d=b=>{r(y=>{const v=new Set(y);return v.has(b)?v.delete(b):v.add(b),v})},m=w.useMemo(()=>{var y;if(!((y=o==null?void 0:o.data)!=null&&y.contracts))return[];const b=o.data.contracts;switch(i){case"critical":return b.filter(v=>v.highestUrgency==="critical");case"warning":return b.filter(v=>v.highestUrgency==="warning");case"ok":return b.filter(v=>v.highestUrgency==="ok");case"deadlines":return b.filter(v=>v.issues.some(x=>["cancellation_deadline","contract_ending"].includes(x.type)));case"credentials":return b.filter(v=>v.issues.some(x=>x.type.includes("credentials")));case"data":return b.filter(v=>v.issues.some(x=>x.type.startsWith("missing_")&&!x.type.includes("credentials")));case"tasks":return b.filter(v=>v.issues.some(x=>["open_tasks","pending_status","draft_status"].includes(x.type)));default:return b}},[(g=o==null?void 0:o.data)==null?void 0:g.contracts,i]);if(c)return n.jsx("div",{className:"flex items-center justify-center py-12",children:n.jsx("div",{className:"text-gray-500",children:"Laden..."})});if(u||!(o!=null&&o.data))return n.jsx("div",{className:"text-center py-12",children:n.jsx("p",{className:"text-red-500",children:"Fehler beim Laden des Cockpits"})});const{summary:p,thresholds:h}=o.data,f=b=>{var x,N,k,D;const y=s.has(b.id),v=MS[b.type]||vt;return n.jsxs("div",{className:`border rounded-lg mb-2 ${RS[b.highestUrgency]}`,children:[n.jsxs("div",{className:"flex items-center p-4 cursor-pointer hover:bg-opacity-50",onClick:()=>d(b.id),children:[n.jsx("div",{className:"w-6 mr-2",children:y?n.jsx(Qo,{className:"w-5 h-5"}):n.jsx(Ys,{className:"w-5 h-5"})}),n.jsx(v,{className:"w-5 h-5 mr-3"}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[n.jsx(Se,{to:`/contracts/${b.id}`,state:{from:"cockpit",filter:i!=="all"?i:void 0},className:"font-medium hover:underline",onClick:F=>F.stopPropagation(),children:b.contractNumber}),n.jsxs(he,{variant:OS[b.highestUrgency],children:[b.issues.length," ",b.highestUrgency==="ok"?b.issues.length===1?"Hinweis":"Hinweise":b.issues.length===1?"Problem":"Probleme"]}),n.jsx("span",{className:"text-sm",children:LS[b.type]})]}),n.jsxs("div",{className:"text-sm mt-1",children:[n.jsxs(Se,{to:`/customers/${b.customer.id}`,className:"hover:underline",onClick:F=>F.stopPropagation(),children:[b.customer.customerNumber," - ",b.customer.name]}),(((x=b.provider)==null?void 0:x.name)||b.providerName)&&n.jsxs("span",{className:"ml-2",children:["| ",((N=b.provider)==null?void 0:N.name)||b.providerName,(((k=b.tariff)==null?void 0:k.name)||b.tariffName)&&` - ${((D=b.tariff)==null?void 0:D.name)||b.tariffName}`]})]})]}),n.jsx(Se,{to:`/contracts/${b.id}`,state:{from:"cockpit",filter:i!=="all"?i:void 0},className:"ml-4 p-2 hover:bg-white hover:bg-opacity-50 rounded",onClick:F=>F.stopPropagation(),title:"Zum Vertrag",children:n.jsx(Ee,{className:"w-4 h-4"})})]}),y&&n.jsx("div",{className:"border-t px-4 py-3 bg-white bg-opacity-50",children:n.jsx("div",{className:"space-y-2",children:b.issues.map((F,S)=>{const L=_S[F.type]||en,T=F.urgency==="critical"?en:F.urgency==="warning"?Li:F.urgency==="ok"?hs:qn;return n.jsxs("div",{className:"flex items-start gap-3 text-sm",children:[n.jsx(T,{className:`w-4 h-4 mt-0.5 flex-shrink-0 ${F.urgency==="critical"?"text-red-500":F.urgency==="warning"?"text-yellow-500":F.urgency==="ok"?"text-green-500":"text-gray-500"}`}),n.jsx(L,{className:"w-4 h-4 mt-0.5 flex-shrink-0 text-gray-500"}),n.jsxs("div",{children:[n.jsx("span",{className:"font-medium",children:F.label}),F.details&&n.jsx("span",{className:"text-gray-600 ml-2",children:F.details})]})]},S)})})})]},b.id)};return n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center justify-between mb-6",children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(en,{className:"w-6 h-6 text-red-500"}),n.jsx("h1",{className:"text-2xl font-bold",children:"Vertrags-Cockpit"})]}),n.jsx(Se,{to:"/settings/deadlines",className:"text-sm text-blue-600 hover:underline",children:"Fristenschwellen anpassen"})]}),n.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4 mb-6",children:[n.jsx(Z,{className:"!p-4",children:n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("div",{className:"p-2 bg-red-100 rounded-lg",children:n.jsx(en,{className:"w-6 h-6 text-red-500"})}),n.jsxs("div",{children:[n.jsx("p",{className:"text-2xl font-bold text-red-600",children:p.criticalCount}),n.jsxs("p",{className:"text-sm text-gray-500",children:["Kritisch (<",h.criticalDays," Tage)"]})]})]})}),n.jsx(Z,{className:"!p-4",children:n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("div",{className:"p-2 bg-yellow-100 rounded-lg",children:n.jsx(Li,{className:"w-6 h-6 text-yellow-500"})}),n.jsxs("div",{children:[n.jsx("p",{className:"text-2xl font-bold text-yellow-600",children:p.warningCount}),n.jsxs("p",{className:"text-sm text-gray-500",children:["Warnung (<",h.warningDays," Tage)"]})]})]})}),n.jsx(Z,{className:"!p-4",children:n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("div",{className:"p-2 bg-green-100 rounded-lg",children:n.jsx(hs,{className:"w-6 h-6 text-green-500"})}),n.jsxs("div",{children:[n.jsx("p",{className:"text-2xl font-bold text-green-600",children:p.okCount}),n.jsxs("p",{className:"text-sm text-gray-500",children:["OK (<",h.okDays," Tage)"]})]})]})}),n.jsx(Z,{className:"!p-4",children:n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("div",{className:"p-2 bg-gray-100 rounded-lg",children:n.jsx(vt,{className:"w-6 h-6 text-gray-500"})}),n.jsxs("div",{children:[n.jsx("p",{className:"text-2xl font-bold text-gray-600",children:p.totalContracts}),n.jsx("p",{className:"text-sm text-gray-500",children:"Verträge mit Handlungsbedarf"})]})]})})]}),n.jsx(Z,{className:"mb-6",children:n.jsx("div",{className:"flex flex-wrap gap-4",children:Object.entries(p.byCategory).map(([b,y])=>y>0&&n.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[n.jsxs("span",{className:"font-medium",children:[zS[b]||b,":"]}),n.jsx(he,{variant:"default",children:y})]},b))})}),n.jsx(Z,{className:"mb-6",children:n.jsxs("div",{className:"flex items-center gap-4",children:[n.jsx("span",{className:"text-sm text-gray-600",children:"Filter:"}),n.jsx(Le,{value:i,onChange:b=>l(b.target.value),options:[{value:"all",label:`Alle (${o.data.contracts.length})`},{value:"critical",label:`Kritisch (${p.criticalCount})`},{value:"warning",label:`Warnung (${p.warningCount})`},{value:"ok",label:`OK (${p.okCount})`},{value:"deadlines",label:`Fristen (${p.byCategory.cancellationDeadlines+p.byCategory.contractEnding})`},{value:"credentials",label:`Zugangsdaten (${p.byCategory.missingCredentials})`},{value:"data",label:`Fehlende Daten (${p.byCategory.missingData})`},{value:"tasks",label:`Aufgaben/Status (${p.byCategory.openTasks+p.byCategory.pendingContracts})`}],className:"w-64"}),n.jsxs("span",{className:"text-sm text-gray-500",children:[m.length," Verträge angezeigt"]})]})}),m.length===0?n.jsx(Z,{children:n.jsx("div",{className:"text-center py-8 text-gray-500",children:i==="all"?n.jsxs(n.Fragment,{children:[n.jsx(hs,{className:"w-12 h-12 mx-auto mb-4 text-green-500"}),n.jsx("p",{className:"text-lg font-medium",children:"Alles in Ordnung!"}),n.jsx("p",{children:"Keine Verträge mit Handlungsbedarf gefunden."})]}):n.jsx("p",{children:"Keine Verträge für diesen Filter gefunden."})})}):n.jsx("div",{children:m.map(f)})]})}const Cp={OPEN:"Offen",COMPLETED:"Erledigt"},$S={OPEN:"warning",COMPLETED:"success"};function BS(){var Q;const e=Ut(),t=pe(),{isCustomerPortal:s,user:r,hasPermission:a}=st(),[i,l]=w.useState("OPEN"),[o,c]=w.useState(new Set),[u,d]=w.useState(!1),[m,p]=w.useState({}),h=s?"Support-Anfragen":"Aufgaben",f=s?"Anfrage":"Aufgabe",{data:g,isLoading:b}=ge({queryKey:["app-settings-public"],queryFn:()=>Sr.getPublic(),enabled:s,staleTime:0}),y=!b&&((Q=g==null?void 0:g.data)==null?void 0:Q.customerSupportTicketsEnabled)==="true",{data:v,isLoading:x}=ge({queryKey:["all-tasks",i],queryFn:()=>Xe.getAll({status:i||void 0}),staleTime:0}),N=Y({mutationFn:z=>Xe.completeSubtask(z),onSuccess:()=>{t.invalidateQueries({queryKey:["all-tasks"]}),t.invalidateQueries({queryKey:["task-stats"]})}}),k=Y({mutationFn:z=>Xe.reopenSubtask(z),onSuccess:()=>{t.invalidateQueries({queryKey:["all-tasks"]}),t.invalidateQueries({queryKey:["task-stats"]})}}),D=Y({mutationFn:({taskId:z,title:P})=>s?Xe.createReply(z,P):Xe.createSubtask(z,P),onSuccess:(z,{taskId:P})=>{t.invalidateQueries({queryKey:["all-tasks"]}),p(j=>({...j,[P]:""}))}}),F=w.useMemo(()=>{var B;if(!(v!=null&&v.data))return{ownTasks:[],representedTasks:[],allTasks:[]};const z=v.data;if(!s)return{allTasks:z,ownTasks:[],representedTasks:[]};const P=[],j=[];for(const J of z)((B=J.contract)==null?void 0:B.customerId)===(r==null?void 0:r.customerId)?P.push(J):j.push(J);return{ownTasks:P,representedTasks:j,allTasks:[]}},[v==null?void 0:v.data,s,r==null?void 0:r.customerId]),S=z=>{c(P=>{const j=new Set(P);return j.has(z)?j.delete(z):j.add(z),j})},L=z=>{N.isPending||k.isPending||(z.status==="COMPLETED"?k.mutate(z.id):N.mutate(z.id))},T=z=>{var j;const P=(j=m[z])==null?void 0:j.trim();P&&D.mutate({taskId:z,title:P})},_=!s&&a("contracts:update"),K=(z,P=!1)=>{var V,Ce,Me,ht,Tt,Jt;const j=o.has(z.id),B=z.subtasks&&z.subtasks.length>0,J=((V=z.subtasks)==null?void 0:V.filter(Pe=>Pe.status==="COMPLETED").length)||0,ee=((Ce=z.subtasks)==null?void 0:Ce.length)||0,me=z.status==="COMPLETED",ve=z.contract?`${z.contract.contractNumber} - ${((Me=z.contract.provider)==null?void 0:Me.name)||z.contract.providerName||"Kein Anbieter"}`:`Vertrag #${z.contractId}`,it=(ht=z.contract)!=null&&ht.customer?z.contract.customer.companyName||`${z.contract.customer.firstName} ${z.contract.customer.lastName}`:"";return n.jsxs("div",{className:"border rounded-lg mb-2",children:[n.jsxs("div",{className:"flex items-center p-4 hover:bg-gray-50 cursor-pointer",onClick:()=>S(z.id),children:[n.jsx("div",{className:"w-6 mr-2",children:j?n.jsx(Qo,{className:"w-5 h-5 text-gray-400"}):n.jsx(Ys,{className:"w-5 h-5 text-gray-400"})}),n.jsx("div",{className:"mr-3",children:z.status==="COMPLETED"?n.jsx(hs,{className:"w-5 h-5 text-green-500"}):n.jsx(qn,{className:"w-5 h-5 text-yellow-500"})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[n.jsx("span",{className:"font-medium",children:z.title}),n.jsx(he,{variant:$S[z.status],children:Cp[z.status]}),B&&n.jsxs("span",{className:"text-xs text-gray-500",children:["(",J,"/",ee," erledigt)"]})]}),n.jsxs("div",{className:"text-sm text-gray-500 mt-1 flex items-center gap-2",children:[n.jsx(vt,{className:"w-4 h-4"}),n.jsx(Se,{to:`/contracts/${z.contractId}`,className:"text-blue-600 hover:underline",onClick:Pe=>Pe.stopPropagation(),children:ve}),P&&it&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"text-gray-400",children:"|"}),n.jsx("span",{children:it})]})]}),z.description&&n.jsx("p",{className:"text-sm text-gray-600 mt-1 line-clamp-2",children:z.description})]}),n.jsx("div",{className:"ml-4 flex gap-2",children:n.jsx(I,{variant:"ghost",size:"sm",onClick:Pe=>{Pe.stopPropagation(),e(`/contracts/${z.contractId}`)},title:"Zum Vertrag",children:n.jsx(Ee,{className:"w-4 h-4"})})})]}),j&&n.jsxs("div",{className:"border-t bg-gray-50 px-4 py-3",children:[B&&n.jsx("div",{className:"space-y-2 mb-4",children:(Tt=z.subtasks)==null?void 0:Tt.map(Pe=>{const Xt=new Date(Pe.createdAt).toLocaleDateString("de-DE",{day:"2-digit",month:"2-digit",year:"numeric"});return n.jsxs("div",{className:`flex items-start gap-2 text-sm ml-6 ${_?"cursor-pointer hover:bg-gray-100 rounded px-2 py-1 -mx-2":""}`,onClick:_?()=>L(Pe):void 0,children:[n.jsx("span",{className:"flex-shrink-0 mt-0.5",children:Pe.status==="COMPLETED"?n.jsx(hs,{className:"w-4 h-4 text-green-500"}):n.jsx(_l,{className:"w-4 h-4 text-gray-400"})}),n.jsxs("span",{className:Pe.status==="COMPLETED"?"text-gray-500 line-through":"",children:[Pe.title,n.jsxs("span",{className:"text-xs text-gray-400 ml-2",children:[Pe.createdBy," • ",Xt]})]})]},Pe.id)})}),!me&&(_||s)&&n.jsxs("div",{className:"flex gap-2 ml-6",children:[n.jsx($,{placeholder:s?"Antwort schreiben...":"Neue Unteraufgabe...",value:m[z.id]||"",onChange:Pe=>p(Xt=>({...Xt,[z.id]:Pe.target.value})),onKeyDown:Pe=>{Pe.key==="Enter"&&!Pe.shiftKey&&(Pe.preventDefault(),T(z.id))},className:"flex-1"}),n.jsx(I,{size:"sm",onClick:()=>T(z.id),disabled:!((Jt=m[z.id])!=null&&Jt.trim())||D.isPending,children:n.jsx(k1,{className:"w-4 h-4"})})]}),!B&&me&&n.jsx("p",{className:"text-gray-500 text-sm text-center py-2",children:"Keine Unteraufgaben vorhanden."})]})]},z.id)},W=s?y:a("contracts:update");return n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center justify-between mb-6",children:[n.jsx("h1",{className:"text-2xl font-bold",children:h}),W&&n.jsxs(I,{onClick:()=>d(!0),children:[n.jsx(Oe,{className:"w-4 h-4 mr-2"}),"Neue ",f]})]}),n.jsx(Z,{className:"mb-6",children:n.jsx("div",{className:"flex gap-4 flex-wrap items-center",children:n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-sm text-gray-600",children:"Status:"}),n.jsx(Le,{value:i,onChange:z=>l(z.target.value),options:[{value:"",label:"Alle"},...Object.entries(Cp).map(([z,P])=>({value:z,label:P}))],className:"w-40"})]})})}),x?n.jsx(Z,{children:n.jsx("div",{className:"text-center py-8 text-gray-500",children:"Laden..."})}):n.jsx(n.Fragment,{children:s?n.jsxs("div",{className:"space-y-6",children:[n.jsxs(Z,{children:[n.jsxs("div",{className:"flex items-center gap-3 mb-4 pb-3 border-b",children:[n.jsx(hh,{className:"w-5 h-5 text-blue-600"}),n.jsxs("h2",{className:"text-lg font-semibold text-gray-900",children:["Meine ",h]}),n.jsx(he,{variant:"default",children:F.ownTasks.length})]}),F.ownTasks.length>0?n.jsx("div",{children:F.ownTasks.map(z=>K(z,!1))}):n.jsxs("p",{className:"text-gray-500 text-center py-4",children:["Keine eigenen ",h.toLowerCase()," vorhanden."]})]}),F.representedTasks.length>0&&n.jsxs(Z,{children:[n.jsxs("div",{className:"flex items-center gap-3 mb-4 pb-3 border-b",children:[n.jsx(Xr,{className:"w-5 h-5 text-purple-600"}),n.jsxs("h2",{className:"text-lg font-semibold text-gray-900",children:[h," freigegebener Kunden"]}),n.jsx(he,{variant:"default",children:F.representedTasks.length})]}),n.jsx("div",{children:F.representedTasks.map(z=>K(z,!0))})]})]}):n.jsx(Z,{children:F.allTasks&&F.allTasks.length>0?n.jsx("div",{children:F.allTasks.map(z=>K(z,!0))}):n.jsxs("div",{className:"text-center py-8 text-gray-500",children:["Keine ",h.toLowerCase()," gefunden."]})})}),s?n.jsx(KS,{isOpen:u,onClose:()=>d(!1)}):n.jsx(VS,{isOpen:u,onClose:()=>d(!1)})]})}function KS({isOpen:e,onClose:t}){const{user:s}=st(),r=Ut(),a=pe(),[i,l]=w.useState("own"),[o,c]=w.useState(null),[u,d]=w.useState(""),[m,p]=w.useState(""),[h,f]=w.useState(!1),[g,b]=w.useState(""),{data:y}=ge({queryKey:["contracts",s==null?void 0:s.customerId],queryFn:()=>$e.getAll({customerId:s==null?void 0:s.customerId}),enabled:e}),v=w.useMemo(()=>{if(!(y!=null&&y.data))return{own:[],represented:{}};const S=[],L={};for(const T of y.data)if(T.customerId===(s==null?void 0:s.customerId))S.push(T);else{if(!L[T.customerId]){const _=T.customer?T.customer.companyName||`${T.customer.firstName} ${T.customer.lastName}`:`Kunde ${T.customerId}`;L[T.customerId]={name:_,contracts:[]}}L[T.customerId].contracts.push(T)}return{own:S,represented:L}},[y==null?void 0:y.data,s==null?void 0:s.customerId]),x=Object.keys(v.represented).length>0,N=w.useMemo(()=>{var S;return i==="own"?v.own:((S=v.represented[i])==null?void 0:S.contracts)||[]},[i,v]),k=w.useMemo(()=>{if(!g)return N;const S=g.toLowerCase();return N.filter(L=>L.contractNumber.toLowerCase().includes(S)||(L.providerName||"").toLowerCase().includes(S)||(L.tariffName||"").toLowerCase().includes(S))},[N,g]),D=async()=>{if(!(!o||!u.trim())){f(!0);try{await Xe.createSupportTicket(o,{title:u.trim(),description:m.trim()||void 0}),a.invalidateQueries({queryKey:["all-tasks"]}),a.invalidateQueries({queryKey:["task-stats"]}),t(),d(""),p(""),c(null),l("own"),r(`/contracts/${o}`)}catch(S){console.error("Fehler beim Erstellen der Support-Anfrage:",S),alert("Fehler beim Erstellen der Support-Anfrage. Bitte versuchen Sie es erneut.")}finally{f(!1)}}},F=()=>{d(""),p(""),c(null),l("own"),b(""),t()};return n.jsx(dt,{isOpen:e,onClose:F,title:"Neue Support-Anfrage",children:n.jsxs("div",{className:"space-y-4",children:[x&&n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Kunde"}),n.jsxs("select",{value:i,onChange:S=>{const L=S.target.value;l(L==="own"?"own":parseInt(L)),c(null),b("")},className:"w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500",children:[n.jsx("option",{value:"own",children:"Eigene Verträge"}),Object.entries(v.represented).map(([S,{name:L}])=>n.jsx("option",{value:S,children:L},S))]})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Vertrag *"}),n.jsx($,{placeholder:"Vertrag suchen...",value:g,onChange:S=>b(S.target.value),className:"mb-2"}),n.jsx("div",{className:"max-h-48 overflow-y-auto border rounded-lg",children:k.length>0?k.map(S=>n.jsxs("div",{onClick:()=>c(S.id),className:`p-3 cursor-pointer border-b last:border-b-0 hover:bg-gray-50 ${o===S.id?"bg-blue-50 border-blue-200":""}`,children:[n.jsx("div",{className:"font-medium",children:S.contractNumber}),n.jsxs("div",{className:"text-sm text-gray-500",children:[S.providerName||"Kein Anbieter",S.tariffName&&` - ${S.tariffName}`]})]},S.id)):n.jsx("div",{className:"p-3 text-gray-500 text-center",children:"Keine Verträge gefunden."})})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Titel *"}),n.jsx($,{value:u,onChange:S=>d(S.target.value),placeholder:"Kurze Beschreibung Ihres Anliegens"})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Beschreibung"}),n.jsx("textarea",{value:m,onChange:S=>p(S.target.value),placeholder:"Detaillierte Beschreibung (optional)",rows:4,className:"w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),n.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[n.jsx(I,{variant:"secondary",onClick:F,children:"Abbrechen"}),n.jsx(I,{onClick:D,disabled:!o||!u.trim()||h,children:h?"Wird erstellt...":"Anfrage erstellen"})]})]})})}function VS({isOpen:e,onClose:t}){const s=Ut(),r=pe(),[a,i]=w.useState(null),[l,o]=w.useState(null),[c,u]=w.useState(""),[d,m]=w.useState(""),[p,h]=w.useState(!1),[f,g]=w.useState(!1),[b,y]=w.useState(""),[v,x]=w.useState(""),{data:N}=ge({queryKey:["customers-for-task"],queryFn:()=>yt.getAll({limit:100}),enabled:e}),{data:k}=ge({queryKey:["contracts-for-task",a],queryFn:()=>$e.getAll({customerId:a}),enabled:e&&a!==null}),D=w.useMemo(()=>{if(!(N!=null&&N.data))return[];if(!b)return N.data;const _=b.toLowerCase();return N.data.filter(K=>K.customerNumber.toLowerCase().includes(_)||K.firstName.toLowerCase().includes(_)||K.lastName.toLowerCase().includes(_)||(K.companyName||"").toLowerCase().includes(_))},[N==null?void 0:N.data,b]),F=w.useMemo(()=>{if(!(k!=null&&k.data))return[];if(!v)return k.data;const _=v.toLowerCase();return k.data.filter(K=>K.contractNumber.toLowerCase().includes(_)||(K.providerName||"").toLowerCase().includes(_)||(K.tariffName||"").toLowerCase().includes(_))},[k==null?void 0:k.data,v]),S=async()=>{if(!(!l||!c.trim())){g(!0);try{await Xe.create(l,{title:c.trim(),description:d.trim()||void 0,visibleInPortal:p}),r.invalidateQueries({queryKey:["all-tasks"]}),r.invalidateQueries({queryKey:["task-stats"]}),t(),u(""),m(""),h(!1),o(null),i(null),s(`/contracts/${l}`)}catch(_){console.error("Fehler beim Erstellen der Aufgabe:",_),alert("Fehler beim Erstellen der Aufgabe. Bitte versuchen Sie es erneut.")}finally{g(!1)}}},L=()=>{u(""),m(""),h(!1),o(null),i(null),y(""),x(""),t()},T=_=>{const K=_.companyName||`${_.firstName} ${_.lastName}`;return`${_.customerNumber} - ${K}`};return n.jsx(dt,{isOpen:e,onClose:L,title:"Neue Aufgabe",children:n.jsxs("div",{className:"space-y-4",children:[n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Kunde *"}),n.jsx($,{placeholder:"Kunde suchen...",value:b,onChange:_=>y(_.target.value),className:"mb-2"}),n.jsx("div",{className:"max-h-40 overflow-y-auto border rounded-lg",children:D.length>0?D.map(_=>n.jsx("div",{onClick:()=>{i(_.id),o(null),x("")},className:`p-3 cursor-pointer border-b last:border-b-0 hover:bg-gray-50 ${a===_.id?"bg-blue-50 border-blue-200":""}`,children:n.jsx("div",{className:"font-medium",children:T(_)})},_.id)):n.jsx("div",{className:"p-3 text-gray-500 text-center",children:"Keine Kunden gefunden."})})]}),a&&n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Vertrag *"}),n.jsx($,{placeholder:"Vertrag suchen...",value:v,onChange:_=>x(_.target.value),className:"mb-2"}),n.jsx("div",{className:"max-h-40 overflow-y-auto border rounded-lg",children:F.length>0?F.map(_=>n.jsxs("div",{onClick:()=>o(_.id),className:`p-3 cursor-pointer border-b last:border-b-0 hover:bg-gray-50 ${l===_.id?"bg-blue-50 border-blue-200":""}`,children:[n.jsx("div",{className:"font-medium",children:_.contractNumber}),n.jsxs("div",{className:"text-sm text-gray-500",children:[_.providerName||"Kein Anbieter",_.tariffName&&` - ${_.tariffName}`]})]},_.id)):n.jsx("div",{className:"p-3 text-gray-500 text-center",children:k?"Keine Verträge gefunden.":"Laden..."})})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Titel *"}),n.jsx($,{value:c,onChange:_=>u(_.target.value),placeholder:"Aufgabentitel"})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Beschreibung"}),n.jsx("textarea",{value:d,onChange:_=>m(_.target.value),placeholder:"Detaillierte Beschreibung (optional)",rows:3,className:"w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),n.jsx("div",{children:n.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[n.jsx("input",{type:"checkbox",checked:p,onChange:_=>h(_.target.checked),className:"rounded border-gray-300 text-blue-600 focus:ring-blue-500"}),n.jsx("span",{className:"text-sm text-gray-700",children:"Im Kundenportal sichtbar"})]})}),n.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[n.jsx(I,{variant:"secondary",onClick:L,children:"Abbrechen"}),n.jsx(I,{onClick:S,disabled:!l||!c.trim()||f,children:f?"Wird erstellt...":"Aufgabe erstellen"})]})]})})}function qS(){const[e,t]=w.useState(!1),[s,r]=w.useState(null),[a,i]=w.useState(!1),{hasPermission:l}=st(),o=pe(),{data:c,isLoading:u}=ge({queryKey:["platforms",a],queryFn:()=>Pi.getAll(a)}),d=Y({mutationFn:Pi.delete,onSuccess:()=>{o.invalidateQueries({queryKey:["platforms"]})}}),m=h=>{r(h),t(!0)},p=()=>{t(!1),r(null)};return n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center justify-between mb-6",children:[n.jsx("h1",{className:"text-2xl font-bold",children:"Vertriebsplattformen"}),l("platforms:create")&&n.jsxs(I,{onClick:()=>t(!0),children:[n.jsx(Oe,{className:"w-4 h-4 mr-2"}),"Neue Plattform"]})]}),n.jsxs(Z,{children:[n.jsx("div",{className:"mb-4",children:n.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[n.jsx("input",{type:"checkbox",checked:a,onChange:h=>i(h.target.checked),className:"rounded"}),"Inaktive anzeigen"]})}),u?n.jsx("div",{className:"text-center py-8 text-gray-500",children:"Laden..."}):c!=null&&c.data&&c.data.length>0?n.jsx("div",{className:"overflow-x-auto",children:n.jsxs("table",{className:"w-full",children:[n.jsx("thead",{children:n.jsxs("tr",{className:"border-b",children:[n.jsx("th",{className:"text-left py-3 px-4 font-medium text-gray-600",children:"Name"}),n.jsx("th",{className:"text-left py-3 px-4 font-medium text-gray-600",children:"Kontakt"}),n.jsx("th",{className:"text-left py-3 px-4 font-medium text-gray-600",children:"Status"}),n.jsx("th",{className:"text-right py-3 px-4 font-medium text-gray-600",children:"Aktionen"})]})}),n.jsx("tbody",{children:c.data.map(h=>n.jsxs("tr",{className:"border-b hover:bg-gray-50",children:[n.jsx("td",{className:"py-3 px-4 font-medium",children:h.name}),n.jsx("td",{className:"py-3 px-4 text-gray-500",children:h.contactInfo||"-"}),n.jsx("td",{className:"py-3 px-4",children:n.jsx(he,{variant:h.isActive?"success":"danger",children:h.isActive?"Aktiv":"Inaktiv"})}),n.jsx("td",{className:"py-3 px-4 text-right",children:n.jsxs("div",{className:"flex justify-end gap-2",children:[l("platforms:update")&&n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>m(h),children:n.jsx(We,{className:"w-4 h-4"})}),l("platforms:delete")&&n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{confirm("Plattform wirklich löschen?")&&d.mutate(h.id)},children:n.jsx(be,{className:"w-4 h-4 text-red-500"})})]})})]},h.id))})]})}):n.jsx("div",{className:"text-center py-8 text-gray-500",children:"Keine Plattformen vorhanden."})]}),n.jsx(QS,{isOpen:e,onClose:p,platform:s})]})}function QS({isOpen:e,onClose:t,platform:s}){const r=pe(),[a,i]=w.useState({name:"",contactInfo:"",isActive:!0});w.useState(()=>{i(s?{name:s.name,contactInfo:s.contactInfo||"",isActive:s.isActive}:{name:"",contactInfo:"",isActive:!0})}),s&&a.name!==s.name?i({name:s.name,contactInfo:s.contactInfo||"",isActive:s.isActive}):!s&&a.name;const l=Y({mutationFn:Pi.create,onSuccess:()=>{r.invalidateQueries({queryKey:["platforms"]}),t(),i({name:"",contactInfo:"",isActive:!0})}}),o=Y({mutationFn:d=>Pi.update(s.id,d),onSuccess:()=>{r.invalidateQueries({queryKey:["platforms"]}),t()}}),c=d=>{d.preventDefault(),s?o.mutate(a):l.mutate(a)},u=l.isPending||o.isPending;return n.jsx(dt,{isOpen:e,onClose:t,title:s?"Plattform bearbeiten":"Neue Plattform",children:n.jsxs("form",{onSubmit:c,className:"space-y-4",children:[n.jsx($,{label:"Name *",value:a.name,onChange:d=>i({...a,name:d.target.value}),required:!0}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Kontaktinformationen"}),n.jsx("textarea",{value:a.contactInfo,onChange:d=>i({...a,contactInfo:d.target.value}),rows:3,className:"block w-full px-3 py-2 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",placeholder:"E-Mail, Telefon, Ansprechpartner..."})]}),s&&n.jsxs("label",{className:"flex items-center gap-2",children:[n.jsx("input",{type:"checkbox",checked:a.isActive,onChange:d=>i({...a,isActive:d.target.checked}),className:"rounded"}),"Aktiv"]}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx(I,{type:"button",variant:"secondary",onClick:t,children:"Abbrechen"}),n.jsx(I,{type:"submit",disabled:u,children:u?"Speichern...":"Speichern"})]})]})})}function HS(){const[e,t]=w.useState(!1),[s,r]=w.useState(null),[a,i]=w.useState(!1),{hasPermission:l}=st(),o=pe(),{data:c,isLoading:u}=ge({queryKey:["cancellation-periods",a],queryFn:()=>Ai.getAll(a)}),d=Y({mutationFn:Ai.delete,onSuccess:()=>{o.invalidateQueries({queryKey:["cancellation-periods"]})}}),m=h=>{r(h),t(!0)},p=()=>{t(!1),r(null)};return n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-4 mb-6",children:[n.jsx(Se,{to:"/settings",children:n.jsx(I,{variant:"ghost",size:"sm",children:n.jsx($s,{className:"w-4 h-4"})})}),n.jsx("h1",{className:"text-2xl font-bold flex-1",children:"Kündigungsfristen"}),l("platforms:create")&&n.jsxs(I,{onClick:()=>t(!0),children:[n.jsx(Oe,{className:"w-4 h-4 mr-2"}),"Neue Frist"]})]}),n.jsxs(Z,{children:[n.jsx("div",{className:"mb-4",children:n.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[n.jsx("input",{type:"checkbox",checked:a,onChange:h=>i(h.target.checked),className:"rounded"}),"Inaktive anzeigen"]})}),n.jsxs("div",{className:"mb-4 p-4 bg-blue-50 border border-blue-200 rounded-lg text-sm",children:[n.jsx("strong",{children:"Code-Format:"})," Zahl + Buchstabe (T=Tage, M=Monate, J=Jahre)",n.jsx("br",{}),n.jsx("strong",{children:"Beispiele:"})," 14T = 14 Tage, 3M = 3 Monate, 1J = 1 Jahr"]}),u?n.jsx("div",{className:"text-center py-8 text-gray-500",children:"Laden..."}):c!=null&&c.data&&c.data.length>0?n.jsx("div",{className:"overflow-x-auto",children:n.jsxs("table",{className:"w-full",children:[n.jsx("thead",{children:n.jsxs("tr",{className:"border-b",children:[n.jsx("th",{className:"text-left py-3 px-4 font-medium text-gray-600",children:"Code"}),n.jsx("th",{className:"text-left py-3 px-4 font-medium text-gray-600",children:"Beschreibung"}),n.jsx("th",{className:"text-left py-3 px-4 font-medium text-gray-600",children:"Status"}),n.jsx("th",{className:"text-right py-3 px-4 font-medium text-gray-600",children:"Aktionen"})]})}),n.jsx("tbody",{children:c.data.map(h=>n.jsxs("tr",{className:"border-b hover:bg-gray-50",children:[n.jsx("td",{className:"py-3 px-4 font-mono font-medium",children:h.code}),n.jsx("td",{className:"py-3 px-4",children:h.description}),n.jsx("td",{className:"py-3 px-4",children:n.jsx(he,{variant:h.isActive?"success":"danger",children:h.isActive?"Aktiv":"Inaktiv"})}),n.jsx("td",{className:"py-3 px-4 text-right",children:n.jsxs("div",{className:"flex justify-end gap-2",children:[l("platforms:update")&&n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>m(h),children:n.jsx(We,{className:"w-4 h-4"})}),l("platforms:delete")&&n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{confirm("Kündigungsfrist wirklich löschen?")&&d.mutate(h.id)},children:n.jsx(be,{className:"w-4 h-4 text-red-500"})})]})})]},h.id))})]})}):n.jsx("div",{className:"text-center py-8 text-gray-500",children:"Keine Kündigungsfristen vorhanden."})]}),n.jsx(WS,{isOpen:e,onClose:p,period:s})]})}function WS({isOpen:e,onClose:t,period:s}){const r=pe(),[a,i]=w.useState({code:"",description:"",isActive:!0});w.useEffect(()=>{e&&i(s?{code:s.code,description:s.description,isActive:s.isActive}:{code:"",description:"",isActive:!0})},[e,s]);const l=Y({mutationFn:Ai.create,onSuccess:()=>{r.invalidateQueries({queryKey:["cancellation-periods"]}),t(),i({code:"",description:"",isActive:!0})}}),o=Y({mutationFn:d=>Ai.update(s.id,d),onSuccess:()=>{r.invalidateQueries({queryKey:["cancellation-periods"]}),t()}}),c=d=>{d.preventDefault(),s?o.mutate(a):l.mutate(a)},u=l.isPending||o.isPending;return n.jsx(dt,{isOpen:e,onClose:t,title:s?"Kündigungsfrist bearbeiten":"Neue Kündigungsfrist",children:n.jsxs("form",{onSubmit:c,className:"space-y-4",children:[n.jsx($,{label:"Code *",value:a.code,onChange:d=>i({...a,code:d.target.value.toUpperCase()}),required:!0,placeholder:"z.B. 14T, 3M, 1J"}),n.jsx($,{label:"Beschreibung *",value:a.description,onChange:d=>i({...a,description:d.target.value}),required:!0,placeholder:"z.B. 14 Tage, 3 Monate, 1 Jahr"}),s&&n.jsxs("label",{className:"flex items-center gap-2",children:[n.jsx("input",{type:"checkbox",checked:a.isActive,onChange:d=>i({...a,isActive:d.target.checked}),className:"rounded"}),"Aktiv"]}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx(I,{type:"button",variant:"secondary",onClick:t,children:"Abbrechen"}),n.jsx(I,{type:"submit",disabled:u,children:u?"Speichern...":"Speichern"})]})]})})}function GS(){const[e,t]=w.useState(!1),[s,r]=w.useState(null),[a,i]=w.useState(!1),{hasPermission:l}=st(),o=pe(),{data:c,isLoading:u}=ge({queryKey:["contract-durations",a],queryFn:()=>Ti.getAll(a)}),d=Y({mutationFn:Ti.delete,onSuccess:()=>{o.invalidateQueries({queryKey:["contract-durations"]})}}),m=h=>{r(h),t(!0)},p=()=>{t(!1),r(null)};return n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-4 mb-6",children:[n.jsx(Se,{to:"/settings",children:n.jsx(I,{variant:"ghost",size:"sm",children:n.jsx($s,{className:"w-4 h-4"})})}),n.jsx("h1",{className:"text-2xl font-bold flex-1",children:"Vertragslaufzeiten"}),l("platforms:create")&&n.jsxs(I,{onClick:()=>t(!0),children:[n.jsx(Oe,{className:"w-4 h-4 mr-2"}),"Neue Laufzeit"]})]}),n.jsxs(Z,{children:[n.jsx("div",{className:"mb-4",children:n.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[n.jsx("input",{type:"checkbox",checked:a,onChange:h=>i(h.target.checked),className:"rounded"}),"Inaktive anzeigen"]})}),n.jsxs("div",{className:"mb-4 p-4 bg-blue-50 border border-blue-200 rounded-lg text-sm",children:[n.jsx("strong",{children:"Code-Format:"})," Zahl + Buchstabe (T=Tage, M=Monate, J=Jahre)",n.jsx("br",{}),n.jsx("strong",{children:"Beispiele:"})," 12M = 12 Monate, 24M = 24 Monate, 2J = 2 Jahre"]}),u?n.jsx("div",{className:"text-center py-8 text-gray-500",children:"Laden..."}):c!=null&&c.data&&c.data.length>0?n.jsx("div",{className:"overflow-x-auto",children:n.jsxs("table",{className:"w-full",children:[n.jsx("thead",{children:n.jsxs("tr",{className:"border-b",children:[n.jsx("th",{className:"text-left py-3 px-4 font-medium text-gray-600",children:"Code"}),n.jsx("th",{className:"text-left py-3 px-4 font-medium text-gray-600",children:"Beschreibung"}),n.jsx("th",{className:"text-left py-3 px-4 font-medium text-gray-600",children:"Status"}),n.jsx("th",{className:"text-right py-3 px-4 font-medium text-gray-600",children:"Aktionen"})]})}),n.jsx("tbody",{children:c.data.map(h=>n.jsxs("tr",{className:"border-b hover:bg-gray-50",children:[n.jsx("td",{className:"py-3 px-4 font-mono font-medium",children:h.code}),n.jsx("td",{className:"py-3 px-4",children:h.description}),n.jsx("td",{className:"py-3 px-4",children:n.jsx(he,{variant:h.isActive?"success":"danger",children:h.isActive?"Aktiv":"Inaktiv"})}),n.jsx("td",{className:"py-3 px-4 text-right",children:n.jsxs("div",{className:"flex justify-end gap-2",children:[l("platforms:update")&&n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>m(h),children:n.jsx(We,{className:"w-4 h-4"})}),l("platforms:delete")&&n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{confirm("Laufzeit wirklich löschen?")&&d.mutate(h.id)},children:n.jsx(be,{className:"w-4 h-4 text-red-500"})})]})})]},h.id))})]})}):n.jsx("div",{className:"text-center py-8 text-gray-500",children:"Keine Laufzeiten vorhanden."})]}),n.jsx(ZS,{isOpen:e,onClose:p,duration:s})]})}function ZS({isOpen:e,onClose:t,duration:s}){const r=pe(),[a,i]=w.useState({code:"",description:"",isActive:!0});w.useEffect(()=>{e&&i(s?{code:s.code,description:s.description,isActive:s.isActive}:{code:"",description:"",isActive:!0})},[e,s]);const l=Y({mutationFn:Ti.create,onSuccess:()=>{r.invalidateQueries({queryKey:["contract-durations"]}),t(),i({code:"",description:"",isActive:!0})}}),o=Y({mutationFn:d=>Ti.update(s.id,d),onSuccess:()=>{r.invalidateQueries({queryKey:["contract-durations"]}),t()}}),c=d=>{d.preventDefault(),s?o.mutate(a):l.mutate(a)},u=l.isPending||o.isPending;return n.jsx(dt,{isOpen:e,onClose:t,title:s?"Laufzeit bearbeiten":"Neue Laufzeit",children:n.jsxs("form",{onSubmit:c,className:"space-y-4",children:[n.jsx($,{label:"Code *",value:a.code,onChange:d=>i({...a,code:d.target.value.toUpperCase()}),required:!0,placeholder:"z.B. 12M, 24M, 2J"}),n.jsx($,{label:"Beschreibung *",value:a.description,onChange:d=>i({...a,description:d.target.value}),required:!0,placeholder:"z.B. 12 Monate, 24 Monate, 2 Jahre"}),s&&n.jsxs("label",{className:"flex items-center gap-2",children:[n.jsx("input",{type:"checkbox",checked:a.isActive,onChange:d=>i({...a,isActive:d.target.checked}),className:"rounded"}),"Aktiv"]}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx(I,{type:"button",variant:"secondary",onClick:t,children:"Abbrechen"}),n.jsx(I,{type:"submit",disabled:u,children:u?"Speichern...":"Speichern"})]})]})})}function YS(){const[e,t]=w.useState(!1),[s,r]=w.useState(null),[a,i]=w.useState(!1),[l,o]=w.useState(new Set),{hasPermission:c}=st(),u=pe(),{data:d,isLoading:m}=ge({queryKey:["providers",a],queryFn:()=>Na.getAll(a)}),p=Y({mutationFn:Na.delete,onSuccess:()=>{u.invalidateQueries({queryKey:["providers"]})},onError:b=>{alert(b.message)}}),h=b=>{o(y=>{const v=new Set(y);return v.has(b)?v.delete(b):v.add(b),v})},f=b=>{r(b),t(!0)},g=()=>{t(!1),r(null)};return n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-4 mb-6",children:[n.jsx(Se,{to:"/settings",children:n.jsx(I,{variant:"ghost",size:"sm",children:n.jsx($s,{className:"w-4 h-4"})})}),n.jsx("h1",{className:"text-2xl font-bold flex-1",children:"Anbieter & Tarife"}),c("providers:create")&&n.jsxs(I,{onClick:()=>t(!0),children:[n.jsx(Oe,{className:"w-4 h-4 mr-2"}),"Neuer Anbieter"]})]}),n.jsxs(Z,{children:[n.jsx("div",{className:"mb-4",children:n.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[n.jsx("input",{type:"checkbox",checked:a,onChange:b=>i(b.target.checked),className:"rounded"}),"Inaktive anzeigen"]})}),m?n.jsx("div",{className:"text-center py-8 text-gray-500",children:"Laden..."}):d!=null&&d.data&&d.data.length>0?n.jsx("div",{className:"space-y-2",children:d.data.map(b=>n.jsx(JS,{provider:b,isExpanded:l.has(b.id),onToggle:()=>h(b.id),onEdit:()=>f(b),onDelete:()=>{confirm("Anbieter wirklich löschen?")&&p.mutate(b.id)},hasPermission:c,showInactive:a},b.id))}):n.jsx("div",{className:"text-center py-8 text-gray-500",children:"Keine Anbieter vorhanden."})]}),n.jsx(XS,{isOpen:e,onClose:g,provider:s})]})}function JS({provider:e,isExpanded:t,onToggle:s,onEdit:r,onDelete:a,hasPermission:i,showInactive:l}){var f,g;const[o,c]=w.useState(!1),[u,d]=w.useState(null),m=pe(),p=Y({mutationFn:$y.delete,onSuccess:()=>{m.invalidateQueries({queryKey:["providers"]})},onError:b=>{alert(b.message)}}),h=((f=e.tariffs)==null?void 0:f.filter(b=>l||b.isActive))||[];return n.jsxs("div",{className:"border rounded-lg",children:[n.jsxs("div",{className:"flex items-center p-4 hover:bg-gray-50",children:[n.jsx("button",{onClick:s,className:"mr-3 p-1 hover:bg-gray-200 rounded",children:t?n.jsx(Qo,{className:"w-5 h-5 text-gray-400"}):n.jsx(Ys,{className:"w-5 h-5 text-gray-400"})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[n.jsx("span",{className:"font-medium",children:e.name}),n.jsx(he,{variant:e.isActive?"success":"danger",children:e.isActive?"Aktiv":"Inaktiv"}),n.jsxs("span",{className:"text-sm text-gray-500",children:["(",h.length," Tarife, ",((g=e._count)==null?void 0:g.contracts)||0," Verträge)"]})]}),e.portalUrl&&n.jsxs("a",{href:e.portalUrl,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-blue-600 hover:underline flex items-center gap-1 mt-1",children:[n.jsx(Yy,{className:"w-3 h-3"}),e.portalUrl]})]}),n.jsxs("div",{className:"flex gap-2 ml-4",children:[i("providers:update")&&n.jsx(I,{variant:"ghost",size:"sm",onClick:r,title:"Bearbeiten",children:n.jsx(We,{className:"w-4 h-4"})}),i("providers:delete")&&n.jsx(I,{variant:"ghost",size:"sm",onClick:a,title:"Löschen",children:n.jsx(be,{className:"w-4 h-4 text-red-500"})})]})]}),t&&n.jsxs("div",{className:"border-t bg-gray-50 p-4",children:[n.jsxs("div",{className:"flex justify-between items-center mb-3",children:[n.jsx("h4",{className:"font-medium text-gray-700",children:"Tarife"}),i("providers:create")&&n.jsxs(I,{size:"sm",onClick:()=>c(!0),children:[n.jsx(Oe,{className:"w-4 h-4 mr-1"}),"Tarif hinzufügen"]})]}),h.length>0?n.jsx("div",{className:"space-y-2",children:h.map(b=>{var y;return n.jsxs("div",{className:"flex items-center justify-between bg-white p-3 rounded border",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{children:b.name}),n.jsx(he,{variant:b.isActive?"success":"danger",className:"text-xs",children:b.isActive?"Aktiv":"Inaktiv"}),((y=b._count)==null?void 0:y.contracts)!==void 0&&n.jsxs("span",{className:"text-xs text-gray-500",children:["(",b._count.contracts," Verträge)"]})]}),n.jsxs("div",{className:"flex gap-1",children:[i("providers:update")&&n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{d(b),c(!0)},title:"Bearbeiten",children:n.jsx(We,{className:"w-3 h-3"})}),i("providers:delete")&&n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{confirm("Tarif wirklich löschen?")&&p.mutate(b.id)},title:"Löschen",children:n.jsx(be,{className:"w-3 h-3 text-red-500"})})]})]},b.id)})}):n.jsx("p",{className:"text-sm text-gray-500",children:"Keine Tarife vorhanden."})]}),n.jsx(e2,{isOpen:o,onClose:()=>{c(!1),d(null)},providerId:e.id,tariff:u})]})}function XS({isOpen:e,onClose:t,provider:s}){const r=pe(),[a,i]=w.useState({name:"",portalUrl:"",usernameFieldName:"",passwordFieldName:"",isActive:!0});w.useEffect(()=>{e&&i(s?{name:s.name,portalUrl:s.portalUrl||"",usernameFieldName:s.usernameFieldName||"",passwordFieldName:s.passwordFieldName||"",isActive:s.isActive}:{name:"",portalUrl:"",usernameFieldName:"",passwordFieldName:"",isActive:!0})},[e,s]);const l=Y({mutationFn:Na.create,onSuccess:()=>{r.invalidateQueries({queryKey:["providers"]}),t()},onError:d=>{alert(d.message)}}),o=Y({mutationFn:d=>Na.update(s.id,d),onSuccess:()=>{r.invalidateQueries({queryKey:["providers"]}),t()},onError:d=>{alert(d.message)}}),c=d=>{d.preventDefault(),s?o.mutate(a):l.mutate(a)},u=l.isPending||o.isPending;return n.jsx(dt,{isOpen:e,onClose:t,title:s?"Anbieter bearbeiten":"Neuer Anbieter",children:n.jsxs("form",{onSubmit:c,className:"space-y-4",children:[n.jsx($,{label:"Anbietername *",value:a.name,onChange:d=>i({...a,name:d.target.value}),required:!0,placeholder:"z.B. Vodafone, E.ON, Allianz"}),n.jsx($,{label:"Portal-URL (Login-Seite)",value:a.portalUrl,onChange:d=>i({...a,portalUrl:d.target.value}),placeholder:"https://kundenportal.anbieter.de/login"}),n.jsxs("div",{className:"p-3 bg-gray-50 rounded-lg space-y-3",children:[n.jsxs("p",{className:"text-sm text-gray-600",children:[n.jsx("strong",{children:"Auto-Login Felder"})," (optional)",n.jsx("br",{}),"Feldnamen für URL-Parameter beim Auto-Login:"]}),n.jsx($,{label:"Benutzername-Feldname",value:a.usernameFieldName,onChange:d=>i({...a,usernameFieldName:d.target.value}),placeholder:"z.B. username, email, login"}),n.jsx($,{label:"Passwort-Feldname",value:a.passwordFieldName,onChange:d=>i({...a,passwordFieldName:d.target.value}),placeholder:"z.B. password, pwd, kennwort"})]}),s&&n.jsxs("label",{className:"flex items-center gap-2",children:[n.jsx("input",{type:"checkbox",checked:a.isActive,onChange:d=>i({...a,isActive:d.target.checked}),className:"rounded"}),"Aktiv"]}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx(I,{type:"button",variant:"secondary",onClick:t,children:"Abbrechen"}),n.jsx(I,{type:"submit",disabled:u,children:u?"Speichern...":"Speichern"})]})]})})}function e2({isOpen:e,onClose:t,providerId:s,tariff:r}){const a=pe(),[i,l]=w.useState({name:"",isActive:!0});w.useEffect(()=>{e&&l(r?{name:r.name,isActive:r.isActive}:{name:"",isActive:!0})},[e,r]);const o=Y({mutationFn:m=>Na.createTariff(s,m),onSuccess:()=>{a.invalidateQueries({queryKey:["providers"]}),t()},onError:m=>{alert(m.message)}}),c=Y({mutationFn:m=>$y.update(r.id,m),onSuccess:()=>{a.invalidateQueries({queryKey:["providers"]}),t()},onError:m=>{alert(m.message)}}),u=m=>{m.preventDefault(),r?c.mutate(i):o.mutate(i)},d=o.isPending||c.isPending;return n.jsx(dt,{isOpen:e,onClose:t,title:r?"Tarif bearbeiten":"Neuer Tarif",children:n.jsxs("form",{onSubmit:u,className:"space-y-4",children:[n.jsx($,{label:"Tarifname *",value:i.name,onChange:m=>l({...i,name:m.target.value}),required:!0,placeholder:"z.B. Comfort Plus, Basic 100"}),r&&n.jsxs("label",{className:"flex items-center gap-2",children:[n.jsx("input",{type:"checkbox",checked:i.isActive,onChange:m=>l({...i,isActive:m.target.checked}),className:"rounded"}),"Aktiv"]}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx(I,{type:"button",variant:"secondary",onClick:t,children:"Abbrechen"}),n.jsx(I,{type:"submit",disabled:d,children:d?"Speichern...":"Speichern"})]})]})})}const sd={Zap:n.jsx(mh,{className:"w-5 h-5"}),Flame:n.jsx(Jy,{className:"w-5 h-5"}),Wifi:n.jsx(ea,{className:"w-5 h-5"}),Cable:n.jsx(m1,{className:"w-5 h-5"}),Smartphone:n.jsx(dh,{className:"w-5 h-5"}),Tv:n.jsx(sv,{className:"w-5 h-5"}),Car:n.jsx(Hy,{className:"w-5 h-5"}),FileText:n.jsx(vt,{className:"w-5 h-5"})},t2=[{value:"Zap",label:"Blitz (Strom)"},{value:"Flame",label:"Flamme (Gas)"},{value:"Wifi",label:"WLAN (DSL)"},{value:"Cable",label:"Kabel (Glasfaser)"},{value:"Smartphone",label:"Smartphone (Mobilfunk)"},{value:"Tv",label:"TV"},{value:"Car",label:"Auto (KFZ)"},{value:"FileText",label:"Dokument (Sonstige)"}],s2=[{value:"#FFC107",label:"Gelb"},{value:"#FF5722",label:"Orange"},{value:"#2196F3",label:"Blau"},{value:"#9C27B0",label:"Lila"},{value:"#4CAF50",label:"Grün"},{value:"#E91E63",label:"Pink"},{value:"#607D8B",label:"Grau"},{value:"#795548",label:"Braun"},{value:"#00BCD4",label:"Cyan"},{value:"#F44336",label:"Rot"}];function n2(){const[e,t]=w.useState(!1),[s,r]=w.useState(null),[a,i]=w.useState(!1),{hasPermission:l}=st(),o=pe(),{data:c,isLoading:u}=ge({queryKey:["contract-categories",a],queryFn:()=>Fi.getAll(a)}),d=Y({mutationFn:Fi.delete,onSuccess:()=>{o.invalidateQueries({queryKey:["contract-categories"]})},onError:h=>{alert(h.message)}}),m=h=>{r(h),t(!0)},p=()=>{t(!1),r(null)};return n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-4 mb-6",children:[n.jsx(Se,{to:"/settings",children:n.jsx(I,{variant:"ghost",size:"sm",children:n.jsx($s,{className:"w-4 h-4"})})}),n.jsx("h1",{className:"text-2xl font-bold flex-1",children:"Vertragstypen"}),l("platforms:create")&&n.jsxs(I,{onClick:()=>t(!0),children:[n.jsx(Oe,{className:"w-4 h-4 mr-2"}),"Neuer Vertragstyp"]})]}),n.jsxs(Z,{children:[n.jsx("div",{className:"mb-4",children:n.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[n.jsx("input",{type:"checkbox",checked:a,onChange:h=>i(h.target.checked),className:"rounded"}),"Inaktive anzeigen"]})}),u?n.jsx("div",{className:"text-center py-8 text-gray-500",children:"Laden..."}):c!=null&&c.data&&c.data.length>0?n.jsx("div",{className:"space-y-2",children:c.data.map(h=>{var f;return n.jsxs("div",{className:"flex items-center p-4 border rounded-lg hover:bg-gray-50",children:[n.jsx("div",{className:"mr-3 text-gray-400",children:n.jsx(x1,{className:"w-5 h-5"})}),n.jsx("div",{className:"w-10 h-10 rounded-lg flex items-center justify-center mr-4",style:{backgroundColor:h.color||"#E5E7EB",color:"#fff"},children:h.icon&&sd[h.icon]?sd[h.icon]:n.jsx(vt,{className:"w-5 h-5"})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[n.jsx("span",{className:"font-medium",children:h.name}),n.jsx(he,{variant:h.isActive?"success":"danger",children:h.isActive?"Aktiv":"Inaktiv"}),n.jsxs("span",{className:"text-sm text-gray-500",children:["(",((f=h._count)==null?void 0:f.contracts)||0," Verträge)"]})]}),n.jsxs("div",{className:"text-sm text-gray-500",children:["Code: ",n.jsx("span",{className:"font-mono",children:h.code})]})]}),n.jsxs("div",{className:"flex gap-2 ml-4",children:[l("platforms:update")&&n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>m(h),title:"Bearbeiten",children:n.jsx(We,{className:"w-4 h-4"})}),l("platforms:delete")&&n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{confirm("Vertragstyp wirklich löschen?")&&d.mutate(h.id)},title:"Löschen",children:n.jsx(be,{className:"w-4 h-4 text-red-500"})})]})]},h.id)})}):n.jsx("div",{className:"text-center py-8 text-gray-500",children:"Keine Vertragstypen vorhanden."})]}),n.jsx(r2,{isOpen:e,onClose:p,category:s})]})}function r2({isOpen:e,onClose:t,category:s}){const r=pe(),[a,i]=w.useState({code:"",name:"",icon:"FileText",color:"#607D8B",sortOrder:0,isActive:!0});w.useEffect(()=>{e&&i(s?{code:s.code,name:s.name,icon:s.icon||"FileText",color:s.color||"#607D8B",sortOrder:s.sortOrder,isActive:s.isActive}:{code:"",name:"",icon:"FileText",color:"#607D8B",sortOrder:0,isActive:!0})},[e,s]);const l=Y({mutationFn:Fi.create,onSuccess:()=>{r.invalidateQueries({queryKey:["contract-categories"]}),t()},onError:d=>{alert(d.message)}}),o=Y({mutationFn:d=>Fi.update(s.id,d),onSuccess:()=>{r.invalidateQueries({queryKey:["contract-categories"]}),t()},onError:d=>{alert(d.message)}}),c=d=>{d.preventDefault(),s?o.mutate(a):l.mutate(a)},u=l.isPending||o.isPending;return n.jsx(dt,{isOpen:e,onClose:t,title:s?"Vertragstyp bearbeiten":"Neuer Vertragstyp",children:n.jsxs("form",{onSubmit:c,className:"space-y-4",children:[n.jsx($,{label:"Code (technisch) *",value:a.code,onChange:d=>i({...a,code:d.target.value.toUpperCase().replace(/[^A-Z0-9_]/g,"")}),required:!0,placeholder:"z.B. ELECTRICITY, MOBILE_BUSINESS",disabled:!!s}),n.jsx($,{label:"Anzeigename *",value:a.name,onChange:d=>i({...a,name:d.target.value}),required:!0,placeholder:"z.B. Strom, Mobilfunk Business"}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Icon"}),n.jsx("div",{className:"grid grid-cols-4 gap-2",children:t2.map(d=>n.jsxs("button",{type:"button",onClick:()=>i({...a,icon:d.value}),className:`p-3 border rounded-lg flex flex-col items-center gap-1 text-xs ${a.icon===d.value?"border-blue-500 bg-blue-50":"border-gray-200 hover:bg-gray-50"}`,children:[sd[d.value],n.jsx("span",{className:"truncate w-full text-center",children:d.label.split(" ")[0]})]},d.value))})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Farbe"}),n.jsx("div",{className:"flex flex-wrap gap-2",children:s2.map(d=>n.jsx("button",{type:"button",onClick:()=>i({...a,color:d.value}),className:`w-8 h-8 rounded-full border-2 ${a.color===d.value?"border-gray-800 ring-2 ring-offset-2 ring-gray-400":"border-transparent"}`,style:{backgroundColor:d.value},title:d.label},d.value))})]}),n.jsx($,{label:"Sortierung",type:"number",value:a.sortOrder,onChange:d=>i({...a,sortOrder:parseInt(d.target.value)||0}),placeholder:"0"}),s&&n.jsxs("label",{className:"flex items-center gap-2",children:[n.jsx("input",{type:"checkbox",checked:a.isActive,onChange:d=>i({...a,isActive:d.target.checked}),className:"rounded"}),"Aktiv"]}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx(I,{type:"button",variant:"secondary",onClick:t,children:"Abbrechen"}),n.jsx(I,{type:"submit",disabled:u,children:u?"Speichern...":"Speichern"})]})]})})}const a2=[{value:"0.1",label:"10%"},{value:"0.2",label:"20%"},{value:"0.3",label:"30%"},{value:"0.4",label:"40%"},{value:"0.5",label:"50%"},{value:"0.6",label:"60%"},{value:"0.7",label:"70% (Standard)"},{value:"0.8",label:"80%"},{value:"0.9",label:"90%"},{value:"999",label:"Deaktiviert"}];function i2(){const{settings:e,updateSettings:t}=Vy();return n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-4 mb-6",children:[n.jsx(Se,{to:"/settings",className:"p-2 hover:bg-gray-100 rounded-lg transition-colors",children:n.jsx($s,{className:"w-5 h-5"})}),n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(Ee,{className:"w-6 h-6"}),n.jsx("h1",{className:"text-2xl font-bold",children:"Ansicht"})]})]}),n.jsx(Z,{title:"Scroll-Verhalten",children:n.jsx("div",{className:"space-y-6",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{children:[n.jsx("p",{className:"font-medium",children:"Nach-oben-Button"}),n.jsx("p",{className:"text-sm text-gray-500",children:"Ab welcher Scroll-Position der Button unten rechts erscheinen soll"})]}),n.jsx("div",{className:"w-48",children:n.jsx(Le,{options:a2,value:e.scrollToTopThreshold.toString(),onChange:s=>t({scrollToTopThreshold:parseFloat(s.target.value)})})})]})})})]})}function l2(){const e=pe(),{data:t,isLoading:s}=ge({queryKey:["app-settings"],queryFn:()=>Sr.getAll()}),[r,a]=w.useState(!1);w.useEffect(()=>{t!=null&&t.data&&a(t.data.customerSupportTicketsEnabled==="true")},[t]);const i=Y({mutationFn:o=>Sr.update(o),onSuccess:()=>{e.invalidateQueries({queryKey:["app-settings"]}),e.invalidateQueries({queryKey:["app-settings-public"]})}}),l=o=>{a(o),i.mutate({customerSupportTicketsEnabled:o?"true":"false"})};return s?n.jsx("div",{className:"flex items-center justify-center py-12",children:n.jsx("div",{className:"text-gray-500",children:"Laden..."})}):n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-4 mb-6",children:[n.jsx(Se,{to:"/settings",className:"text-gray-500 hover:text-gray-700",children:n.jsx($s,{className:"w-5 h-5"})}),n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(uh,{className:"w-6 h-6"}),n.jsx("h1",{className:"text-2xl font-bold",children:"Kundenportal"})]})]}),n.jsxs(Z,{title:"Support-Anfragen",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(Mi,{className:"w-5 h-5 text-gray-500"}),n.jsxs("div",{children:[n.jsx("p",{className:"font-medium",children:"Kunden können Support-Anfragen erstellen"}),n.jsx("p",{className:"text-sm text-gray-500",children:"Wenn aktiviert, können Kunden im Portal Support-Anfragen zu ihren Verträgen erstellen. Diese erscheinen als Aufgaben in der Vertragsdetailansicht."})]})]}),n.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[n.jsx("input",{type:"checkbox",checked:r,onChange:o=>l(o.target.checked),disabled:i.isPending,className:"sr-only peer"}),n.jsx("div",{className:"w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-blue-300 rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-blue-600"})]})]}),r&&n.jsx("div",{className:"mt-4 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:n.jsxs("p",{className:"text-sm text-blue-800",children:[n.jsx("strong",{children:"Hinweis:"}),' Kunden sehen diese Anfragen als "Support-Anfragen" in ihrem Portal. Sie können die Anfrage mit einem Titel und einer Beschreibung erstellen. Ihre Mitarbeiter können dann mit Antworten (Unteraufgaben) reagieren.']})})]})]})}function o2(){const e=pe(),{data:t,isLoading:s}=ge({queryKey:["app-settings"],queryFn:()=>Sr.getAll()}),[r,a]=w.useState("14"),[i,l]=w.useState("42"),[o,c]=w.useState("90"),[u,d]=w.useState(!1);w.useEffect(()=>{t!=null&&t.data&&(a(t.data.deadlineCriticalDays||"14"),l(t.data.deadlineWarningDays||"42"),c(t.data.deadlineOkDays||"90"),d(!1))},[t]);const m=Y({mutationFn:f=>Sr.update(f),onSuccess:()=>{e.invalidateQueries({queryKey:["app-settings"]}),e.invalidateQueries({queryKey:["contract-cockpit"]}),d(!1)}}),p=()=>{const f=parseInt(r),g=parseInt(i),b=parseInt(o);if(isNaN(f)||isNaN(g)||isNaN(b)){alert("Bitte gültige Zahlen eingeben");return}if(f>=g||g>=b){alert("Die Werte müssen aufsteigend sein: Kritisch < Warnung < OK");return}m.mutate({deadlineCriticalDays:r,deadlineWarningDays:i,deadlineOkDays:o})},h=(f,g)=>{f(g),d(!0)};return s?n.jsx("div",{className:"flex items-center justify-center py-12",children:n.jsx("div",{className:"text-gray-500",children:"Laden..."})}):n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-4 mb-6",children:[n.jsx(Se,{to:"/settings",className:"text-gray-500 hover:text-gray-700",children:n.jsx($s,{className:"w-5 h-5"})}),n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(qn,{className:"w-6 h-6"}),n.jsx("h1",{className:"text-2xl font-bold",children:"Fristenschwellen"})]})]}),n.jsxs(Z,{title:"Farbkodierung für Fristen",children:[n.jsx("p",{className:"text-gray-600 mb-6",children:"Definiere, ab wann Vertragsfristen als kritisch (rot), Warnung (gelb) oder OK (grün) angezeigt werden sollen. Die Werte geben die Anzahl der Tage bis zur Frist an."}),n.jsxs("div",{className:"space-y-6",children:[n.jsxs("div",{className:"flex items-center gap-4 p-4 bg-red-50 border border-red-200 rounded-lg",children:[n.jsx(en,{className:"w-8 h-8 text-red-500 flex-shrink-0"}),n.jsxs("div",{className:"flex-1",children:[n.jsx("label",{className:"block font-medium text-red-800 mb-1",children:"Kritisch (Rot)"}),n.jsx("p",{className:"text-sm text-red-600 mb-2",children:"Fristen mit weniger als X Tagen werden rot markiert"}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx($,{type:"number",min:"1",value:r,onChange:f=>h(a,f.target.value),className:"w-24"}),n.jsx("span",{className:"text-red-700",children:"Tage"})]})]})]}),n.jsxs("div",{className:"flex items-center gap-4 p-4 bg-yellow-50 border border-yellow-200 rounded-lg",children:[n.jsx(Li,{className:"w-8 h-8 text-yellow-500 flex-shrink-0"}),n.jsxs("div",{className:"flex-1",children:[n.jsx("label",{className:"block font-medium text-yellow-800 mb-1",children:"Warnung (Gelb)"}),n.jsx("p",{className:"text-sm text-yellow-600 mb-2",children:"Fristen mit weniger als X Tagen werden gelb markiert"}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx($,{type:"number",min:"1",value:i,onChange:f=>h(l,f.target.value),className:"w-24"}),n.jsx("span",{className:"text-yellow-700",children:"Tage"})]})]})]}),n.jsxs("div",{className:"flex items-center gap-4 p-4 bg-green-50 border border-green-200 rounded-lg",children:[n.jsx(hs,{className:"w-8 h-8 text-green-500 flex-shrink-0"}),n.jsxs("div",{className:"flex-1",children:[n.jsx("label",{className:"block font-medium text-green-800 mb-1",children:"OK (Grün)"}),n.jsx("p",{className:"text-sm text-green-600 mb-2",children:"Fristen mit weniger als X Tagen werden grün markiert (darüber nicht angezeigt)"}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx($,{type:"number",min:"1",value:o,onChange:f=>h(c,f.target.value),className:"w-24"}),n.jsx("span",{className:"text-green-700",children:"Tage"})]})]})]})]}),n.jsxs("div",{className:"mt-6 pt-4 border-t flex justify-between items-center",children:[n.jsx("p",{className:"text-sm text-gray-500",children:"Beispiel: Bei 14/42/90 Tagen wird eine Frist die in 10 Tagen abläuft rot, eine in 30 Tagen gelb, und eine in 60 Tagen grün markiert."}),n.jsx(I,{onClick:p,disabled:!u||m.isPending,children:m.isPending?"Speichere...":"Speichern"})]})]})]})}const c2=[{value:"PLESK",label:"Plesk"},{value:"CPANEL",label:"cPanel"},{value:"DIRECTADMIN",label:"DirectAdmin"}],Lc={name:"",type:"PLESK",apiUrl:"",apiKey:"",username:"",password:"",domain:"stressfrei-wechseln.de",defaultForwardEmail:"",isActive:!0,isDefault:!1};function u2(){const e=Ut(),t=pe(),[s,r]=w.useState(!1),[a,i]=w.useState(null),[l,o]=w.useState(Lc),[c,u]=w.useState(!1),[d,m]=w.useState(null),[p,h]=w.useState(!1),[f,g]=w.useState({}),[b,y]=w.useState(null),{data:v,isLoading:x}=ge({queryKey:["email-provider-configs"],queryFn:()=>xn.getConfigs()}),N=Y({mutationFn:P=>xn.createConfig(P),onSuccess:()=>{t.invalidateQueries({queryKey:["email-provider-configs"]}),T()}}),k=Y({mutationFn:({id:P,data:j})=>xn.updateConfig(P,j),onSuccess:()=>{t.invalidateQueries({queryKey:["email-provider-configs"]}),T()}}),D=Y({mutationFn:P=>xn.deleteConfig(P),onSuccess:()=>{t.invalidateQueries({queryKey:["email-provider-configs"]})}}),F=(v==null?void 0:v.data)||[],S=()=>{o(Lc),i(null),u(!1),m(null),r(!0)},L=P=>{o({name:P.name,type:P.type,apiUrl:P.apiUrl,apiKey:P.apiKey||"",username:P.username||"",password:"",domain:P.domain,defaultForwardEmail:P.defaultForwardEmail||"",isActive:P.isActive,isDefault:P.isDefault}),i(P.id),u(!1),m(null),r(!0)},T=()=>{r(!1),i(null),o(Lc),u(!1),m(null)},_=async P=>{var j,B,J;y(P.id),g(ee=>({...ee,[P.id]:null}));try{const ee=await xn.testConnection({id:P.id}),me={success:((j=ee.data)==null?void 0:j.success)||!1,message:(B=ee.data)==null?void 0:B.message,error:(J=ee.data)==null?void 0:J.error};g(ve=>({...ve,[P.id]:me}))}catch(ee){g(me=>({...me,[P.id]:{success:!1,error:ee instanceof Error?ee.message:"Unbekannter Fehler beim Testen"}}))}finally{y(null)}},K=async()=>{var P,j,B;if(!l.apiUrl||!l.domain){m({success:!1,error:"Bitte geben Sie API-URL und Domain ein."});return}if(a&&!l.password&&!l.apiKey){m({success:!1,error:"Um die Verbindung zu testen, geben Sie bitte entweder einen API-Key oder das Passwort ein."});return}if(!a&&!l.apiKey&&(!l.username||!l.password)){m({success:!1,error:"Bitte geben Sie entweder einen API-Key oder Benutzername und Passwort ein."});return}h(!0),m(null);try{const J=await xn.testConnection({testData:{type:l.type,apiUrl:l.apiUrl,apiKey:l.apiKey||void 0,username:l.username||void 0,password:l.password||void 0,domain:l.domain}});m({success:((P=J.data)==null?void 0:P.success)||!1,message:(j=J.data)==null?void 0:j.message,error:(B=J.data)==null?void 0:B.error})}catch(J){m({success:!1,error:J instanceof Error?J.message:"Unbekannter Fehler beim Verbindungstest"})}finally{h(!1)}},W=P=>{P.preventDefault();const j={name:l.name,type:l.type,apiUrl:l.apiUrl,apiKey:l.apiKey||void 0,username:l.username||void 0,domain:l.domain,defaultForwardEmail:l.defaultForwardEmail||void 0,isActive:l.isActive,isDefault:l.isDefault};l.password&&(j.password=l.password),a?k.mutate({id:a,data:j}):N.mutate(j)},Q=(P,j)=>{confirm(`Möchten Sie den Provider "${j}" wirklich löschen?`)&&D.mutate(P)},z=P=>P.error?P.error:P.message?P.message:"Verbindung fehlgeschlagen";return n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-4 mb-6",children:[n.jsxs(I,{variant:"ghost",onClick:()=>e("/settings"),children:[n.jsx($s,{className:"w-4 h-4 mr-2"}),"Zurück"]}),n.jsx("h1",{className:"text-2xl font-bold",children:"Email-Provisionierung"})]}),n.jsxs(Z,{className:"mb-6",children:[n.jsx("p",{className:"text-gray-600 mb-4",children:'Hier konfigurieren Sie die automatische Erstellung von Stressfrei-Wechseln E-Mail-Adressen. Wenn beim Anlegen einer Stressfrei-Adresse die Option "Bei Provider anlegen" aktiviert ist, wird die E-Mail-Weiterleitung automatisch erstellt.'}),n.jsxs(I,{onClick:S,children:[n.jsx(Oe,{className:"w-4 h-4 mr-2"}),"Provider hinzufügen"]})]}),x?n.jsx("div",{className:"text-center py-8",children:"Laden..."}):F.length===0?n.jsx(Z,{children:n.jsx("div",{className:"text-center py-8 text-gray-500",children:"Noch keine Email-Provider konfiguriert."})}):n.jsx("div",{className:"space-y-4",children:F.map(P=>{const j=f[P.id],B=b===P.id;return n.jsx(Z,{children:n.jsxs("div",{className:"flex items-start justify-between",children:[n.jsxs("div",{className:"flex-1",children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("h3",{className:"font-semibold text-lg",children:P.name}),n.jsx("span",{className:"px-2 py-1 text-xs rounded bg-blue-100 text-blue-800",children:P.type}),P.isDefault&&n.jsx("span",{className:"px-2 py-1 text-xs rounded bg-green-100 text-green-800",children:"Standard"}),!P.isActive&&n.jsx("span",{className:"px-2 py-1 text-xs rounded bg-gray-100 text-gray-600",children:"Inaktiv"})]}),n.jsxs("dl",{className:"mt-3 grid grid-cols-2 md:grid-cols-4 gap-4 text-sm",children:[n.jsxs("div",{children:[n.jsx("dt",{className:"text-gray-500",children:"API-URL"}),n.jsx("dd",{className:"font-mono text-xs truncate",children:P.apiUrl})]}),n.jsxs("div",{children:[n.jsx("dt",{className:"text-gray-500",children:"Domain"}),n.jsx("dd",{children:P.domain})]}),n.jsxs("div",{children:[n.jsx("dt",{className:"text-gray-500",children:"Benutzer"}),n.jsx("dd",{children:P.username||"-"})]}),n.jsxs("div",{children:[n.jsx("dt",{className:"text-gray-500",children:"Standard-Weiterleitung"}),n.jsx("dd",{className:"truncate",children:P.defaultForwardEmail||"-"})]})]}),j&&n.jsx("div",{className:`mt-3 p-3 rounded-lg text-sm ${j.success?"bg-green-50 text-green-800":"bg-red-50 text-red-800"}`,children:j.success?n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(Xu,{className:"w-4 h-4 flex-shrink-0"}),n.jsx("span",{children:"Verbindung erfolgreich!"})]}):n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx(np,{className:"w-4 h-4 flex-shrink-0 mt-0.5"}),n.jsx("span",{children:z(j)})]})})]}),n.jsxs("div",{className:"flex gap-2 ml-4",children:[n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>_(P),disabled:B,title:"Verbindung testen",children:B?n.jsx("span",{className:"w-4 h-4 border-2 border-gray-400 border-t-transparent rounded-full animate-spin"}):n.jsx(ea,{className:"w-4 h-4 text-blue-500"})}),n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>L(P),children:n.jsx(We,{className:"w-4 h-4"})}),n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>Q(P.id,P.name),children:n.jsx(be,{className:"w-4 h-4 text-red-500"})})]})]})},P.id)})}),s&&n.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",children:n.jsx("div",{className:"bg-white rounded-lg shadow-xl w-full max-w-lg mx-4 max-h-[90vh] overflow-y-auto",children:n.jsxs("div",{className:"p-6",children:[n.jsxs("div",{className:"flex items-center justify-between mb-4",children:[n.jsx("h2",{className:"text-xl font-semibold",children:a?"Provider bearbeiten":"Neuer Provider"}),n.jsx("button",{onClick:T,className:"text-gray-400 hover:text-gray-600",children:n.jsx(wa,{className:"w-5 h-5"})})]}),(N.error||k.error)&&n.jsx("div",{className:"mb-4 p-3 rounded-lg bg-red-50 text-red-800 text-sm",children:n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx(wa,{className:"w-4 h-4 flex-shrink-0 mt-0.5"}),n.jsx("span",{children:N.error instanceof Error?N.error.message:k.error instanceof Error?k.error.message:"Fehler beim Speichern"})]})}),n.jsxs("form",{onSubmit:W,className:"space-y-4",children:[n.jsx($,{label:"Name *",value:l.name,onChange:P=>o({...l,name:P.target.value}),placeholder:"z.B. Plesk Hauptserver",required:!0}),n.jsx(Le,{label:"Provider-Typ *",value:l.type,onChange:P=>o({...l,type:P.target.value}),options:c2}),n.jsx($,{label:"API-URL *",value:l.apiUrl,onChange:P=>o({...l,apiUrl:P.target.value}),placeholder:"https://server.de:8443",required:!0}),n.jsx($,{label:"API-Key",value:l.apiKey,onChange:P=>o({...l,apiKey:P.target.value}),placeholder:"Optional - alternativ zu Benutzername/Passwort"}),n.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[n.jsx($,{label:"Benutzername",value:l.username,onChange:P=>o({...l,username:P.target.value}),placeholder:"admin"}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:a?"Neues Passwort (leer = beibehalten)":"Passwort"}),n.jsxs("div",{className:"relative",children:[n.jsx("input",{type:c?"text":"password",value:l.password,onChange:P=>o({...l,password:P.target.value}),className:"block w-full px-3 py-2 pr-10 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"}),n.jsx("button",{type:"button",onClick:()=>u(!c),className:"absolute inset-y-0 right-0 flex items-center pr-3 text-gray-400 hover:text-gray-600",children:c?n.jsx(Pt,{className:"w-4 h-4"}):n.jsx(Ee,{className:"w-4 h-4"})})]})]})]}),n.jsx($,{label:"Domain *",value:l.domain,onChange:P=>o({...l,domain:P.target.value}),placeholder:"stressfrei-wechseln.de",required:!0}),n.jsx($,{label:"Standard-Weiterleitungsadresse",value:l.defaultForwardEmail,onChange:P=>o({...l,defaultForwardEmail:P.target.value}),placeholder:"info@meinefirma.de",type:"email"}),n.jsx("p",{className:"text-xs text-gray-500 -mt-2",children:"Diese E-Mail-Adresse wird zusätzlich zur Kunden-E-Mail als Weiterleitungsziel hinzugefügt."}),n.jsxs("div",{className:"flex gap-4",children:[n.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[n.jsx("input",{type:"checkbox",checked:l.isActive,onChange:P=>o({...l,isActive:P.target.checked}),className:"rounded border-gray-300"}),n.jsx("span",{className:"text-sm",children:"Aktiv"})]}),n.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[n.jsx("input",{type:"checkbox",checked:l.isDefault,onChange:P=>o({...l,isDefault:P.target.checked}),className:"rounded border-gray-300"}),n.jsx("span",{className:"text-sm",children:"Als Standard verwenden"})]})]}),n.jsxs("div",{className:"pt-4 border-t",children:[n.jsx(I,{type:"button",variant:"secondary",onClick:K,disabled:p,className:"w-full",children:p?"Teste Verbindung...":n.jsxs(n.Fragment,{children:[n.jsx(ea,{className:"w-4 h-4 mr-2"}),"Verbindung testen"]})}),d&&n.jsx("div",{className:`mt-2 p-3 rounded-lg text-sm ${d.success?"bg-green-50 text-green-800":"bg-red-50 text-red-800"}`,children:d.success?n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(Xu,{className:"w-4 h-4 flex-shrink-0"}),n.jsx("span",{children:"Verbindung erfolgreich!"})]}):n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx(np,{className:"w-4 h-4 flex-shrink-0 mt-0.5"}),n.jsx("span",{children:z(d)})]})})]}),n.jsxs("div",{className:"flex justify-end gap-3 pt-4 border-t",children:[n.jsx(I,{type:"button",variant:"secondary",onClick:T,children:"Abbrechen"}),n.jsx(I,{type:"submit",disabled:N.isPending||k.isPending,children:N.isPending||k.isPending?"Speichern...":"Speichern"})]})]})]})})})]})}function d2(){var v;const[e,t]=w.useState(""),[s,r]=w.useState(1),[a,i]=w.useState(!1),[l,o]=w.useState(null),c=pe(),{refreshUser:u}=st(),{data:d,isLoading:m}=ge({queryKey:["users",e,s],queryFn:()=>ii.getAll({search:e||void 0,page:s,limit:20})}),{data:p}=ge({queryKey:["roles"],queryFn:()=>ii.getRoles()}),h=Y({mutationFn:ii.delete,onSuccess:()=>{c.invalidateQueries({queryKey:["users"]})},onError:x=>{alert((x==null?void 0:x.message)||"Fehler beim Löschen des Benutzers")}}),f=x=>{var N;return(N=x.roles)==null?void 0:N.some(k=>k.name==="Admin")},g=((v=d==null?void 0:d.data)==null?void 0:v.filter(x=>x.isActive&&f(x)).length)||0,b=x=>{o(x),i(!0)},y=()=>{i(!1),o(null)};return n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-4 mb-6",children:[n.jsx(Se,{to:"/settings",children:n.jsx(I,{variant:"ghost",size:"sm",children:n.jsx($s,{className:"w-4 h-4"})})}),n.jsx("h1",{className:"text-2xl font-bold flex-1",children:"Benutzer"}),n.jsxs(I,{onClick:()=>i(!0),children:[n.jsx(Oe,{className:"w-4 h-4 mr-2"}),"Neuer Benutzer"]})]}),n.jsx(Z,{className:"mb-6",children:n.jsxs("div",{className:"flex gap-4",children:[n.jsx("div",{className:"flex-1",children:n.jsx($,{placeholder:"Suchen...",value:e,onChange:x=>t(x.target.value)})}),n.jsx(I,{variant:"secondary",children:n.jsx(Wo,{className:"w-4 h-4"})})]})}),n.jsx(Z,{children:m?n.jsx("div",{className:"text-center py-8 text-gray-500",children:"Laden..."}):d!=null&&d.data&&d.data.length>0?n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"overflow-x-auto",children:n.jsxs("table",{className:"w-full",children:[n.jsx("thead",{children:n.jsxs("tr",{className:"border-b",children:[n.jsx("th",{className:"text-left py-3 px-4 font-medium text-gray-600",children:"Name"}),n.jsx("th",{className:"text-left py-3 px-4 font-medium text-gray-600",children:"E-Mail"}),n.jsx("th",{className:"text-left py-3 px-4 font-medium text-gray-600",children:"Rollen"}),n.jsx("th",{className:"text-left py-3 px-4 font-medium text-gray-600",children:"Status"}),n.jsx("th",{className:"text-right py-3 px-4 font-medium text-gray-600",children:"Aktionen"})]})}),n.jsx("tbody",{children:d.data.map(x=>{var N;return n.jsxs("tr",{className:"border-b hover:bg-gray-50",children:[n.jsxs("td",{className:"py-3 px-4",children:[x.firstName," ",x.lastName]}),n.jsx("td",{className:"py-3 px-4",children:x.email}),n.jsx("td",{className:"py-3 px-4",children:n.jsx("div",{className:"flex gap-1 flex-wrap",children:(N=x.roles)==null?void 0:N.filter(k=>k.name!=="Developer").map(k=>n.jsx(he,{variant:"info",children:k.name},k.id||k.name))})}),n.jsx("td",{className:"py-3 px-4",children:n.jsxs("div",{className:"flex gap-2",children:[n.jsx(he,{variant:x.isActive?"success":"danger",children:x.isActive?"Aktiv":"Inaktiv"}),x.hasDeveloperAccess&&n.jsxs(he,{variant:"warning",className:"flex items-center gap-1",children:[n.jsx(Ho,{className:"w-3 h-3"}),"Dev"]})]})}),n.jsx("td",{className:"py-3 px-4 text-right",children:n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>b(x),children:n.jsx(We,{className:"w-4 h-4"})}),(()=>{const k=f(x)&&x.isActive&&g<=1;return n.jsx(I,{variant:"ghost",size:"sm",disabled:k,title:k?"Letzter Administrator kann nicht gelöscht werden":void 0,onClick:()=>{confirm("Benutzer wirklich löschen?")&&h.mutate(x.id)},children:n.jsx(be,{className:`w-4 h-4 ${k?"text-gray-300":"text-red-500"}`})})})()]})})]},x.id)})})]})}),d.pagination&&d.pagination.totalPages>1&&n.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[n.jsxs("p",{className:"text-sm text-gray-500",children:["Seite ",d.pagination.page," von ",d.pagination.totalPages]}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx(I,{variant:"secondary",size:"sm",onClick:()=>r(x=>Math.max(1,x-1)),disabled:s===1,children:"Zurück"}),n.jsx(I,{variant:"secondary",size:"sm",onClick:()=>r(x=>x+1),disabled:s>=d.pagination.totalPages,children:"Weiter"})]})]})]}):n.jsx("div",{className:"text-center py-8 text-gray-500",children:"Keine Benutzer gefunden."})}),n.jsx(h2,{isOpen:a,onClose:y,user:l,roles:(p==null?void 0:p.data)||[],onUserUpdated:u})]})}function h2({isOpen:e,onClose:t,user:s,roles:r,onUserUpdated:a}){const i=pe(),[l,o]=w.useState(null),[c,u]=w.useState({email:"",password:"",firstName:"",lastName:"",roleIds:[],isActive:!0,hasDeveloperAccess:!1});w.useEffect(()=>{var g;e&&(o(null),u(s?{email:s.email,password:"",firstName:s.firstName,lastName:s.lastName,roleIds:((g=s.roles)==null?void 0:g.filter(b=>b.name!=="Developer").map(b=>b.id))||[],isActive:s.isActive??!0,hasDeveloperAccess:s.hasDeveloperAccess??!1}:{email:"",password:"",firstName:"",lastName:"",roleIds:[],isActive:!0,hasDeveloperAccess:!1}))},[e,s]);const d=Y({mutationFn:ii.create,onSuccess:()=>{i.invalidateQueries({queryKey:["users"]}),t()},onError:g=>{o((g==null?void 0:g.message)||"Fehler beim Erstellen des Benutzers")}}),m=Y({mutationFn:g=>ii.update(s.id,g),onSuccess:async()=>{i.invalidateQueries({queryKey:["users"]}),await a(),t()},onError:g=>{o((g==null?void 0:g.message)||"Fehler beim Aktualisieren des Benutzers")}}),p=g=>{if(g.preventDefault(),s){const b={email:c.email,firstName:c.firstName,lastName:c.lastName,roleIds:c.roleIds,isActive:c.isActive,hasDeveloperAccess:c.hasDeveloperAccess};c.password&&(b.password=c.password),m.mutate(b)}else d.mutate({email:c.email,password:c.password,firstName:c.firstName,lastName:c.lastName,roleIds:c.roleIds})},h=g=>{u(b=>({...b,roleIds:b.roleIds.includes(g)?b.roleIds.filter(y=>y!==g):[...b.roleIds,g]}))},f=d.isPending||m.isPending;return n.jsx(dt,{isOpen:e,onClose:t,title:s?"Benutzer bearbeiten":"Neuer Benutzer",children:n.jsxs("form",{onSubmit:p,className:"space-y-4",children:[l&&n.jsxs("div",{className:"bg-red-50 border border-red-200 rounded-lg p-3 flex items-start gap-2",children:[n.jsx(Li,{className:"w-5 h-5 text-red-500 flex-shrink-0 mt-0.5"}),n.jsx("p",{className:"text-red-700 text-sm",children:l})]}),n.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[n.jsx($,{label:"Vorname *",value:c.firstName,onChange:g=>u({...c,firstName:g.target.value}),required:!0}),n.jsx($,{label:"Nachname *",value:c.lastName,onChange:g=>u({...c,lastName:g.target.value}),required:!0})]}),n.jsx($,{label:"E-Mail *",type:"email",value:c.email,onChange:g=>u({...c,email:g.target.value}),required:!0}),n.jsx($,{label:s?"Neues Passwort (leer = unverändert)":"Passwort *",type:"password",value:c.password,onChange:g=>u({...c,password:g.target.value}),required:!s}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Rollen"}),n.jsx("div",{className:"space-y-2",children:r.filter(g=>g.name!=="Developer").map(g=>n.jsxs("label",{className:"flex items-center gap-2",children:[n.jsx("input",{type:"checkbox",checked:c.roleIds.includes(g.id),onChange:()=>h(g.id),className:"rounded"}),n.jsx("span",{children:g.name}),g.description&&n.jsxs("span",{className:"text-sm text-gray-500",children:["(",g.description,")"]})]},g.id))})]}),s&&n.jsxs("div",{className:"space-y-3 pt-3 border-t",children:[n.jsxs("label",{className:"flex items-center gap-2",children:[n.jsx("input",{type:"checkbox",checked:c.isActive,onChange:g=>u({...c,isActive:g.target.checked}),className:"rounded"}),"Aktiv"]}),n.jsxs("label",{className:"flex items-center gap-2",children:[n.jsx("input",{type:"checkbox",checked:c.hasDeveloperAccess,onChange:g=>u({...c,hasDeveloperAccess:g.target.checked}),className:"rounded border-purple-300 text-purple-600 focus:ring-purple-500"}),n.jsxs("span",{className:"flex items-center gap-1",children:[n.jsx(Ho,{className:"w-4 h-4 text-purple-600"}),"Entwicklerzugriff"]}),n.jsx("span",{className:"text-sm text-gray-500",children:"(Datenbanktools)"})]})]}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx(I,{type:"button",variant:"secondary",onClick:t,children:"Abbrechen"}),n.jsx(I,{type:"submit",disabled:f,children:f?"Speichern...":"Speichern"})]})]})})}function m2(){const{hasPermission:e,developerMode:t,setDeveloperMode:s}=st(),r=[{to:"/settings/users",icon:P1,title:"Benutzer",description:"Verwalten Sie Benutzerkonten, Rollen und Berechtigungen.",show:e("users:read")},{to:"/settings/platforms",icon:C1,title:"Vertriebsplattformen",description:"Verwalten Sie die Plattformen, über die Verträge abgeschlossen werden.",show:e("platforms:read")},{to:"/settings/cancellation-periods",icon:qn,title:"Kündigungsfristen",description:"Konfigurieren Sie die verfügbaren Kündigungsfristen für Verträge.",show:e("platforms:read")},{to:"/settings/contract-durations",icon:Qy,title:"Vertragslaufzeiten",description:"Konfigurieren Sie die verfügbaren Laufzeiten für Verträge.",show:e("platforms:read")},{to:"/settings/providers",icon:h1,title:"Anbieter & Tarife",description:"Verwalten Sie Anbieter und deren Tarife für Verträge.",show:e("providers:read")||e("platforms:read")},{to:"/settings/contract-categories",icon:g1,title:"Vertragstypen",description:"Konfigurieren Sie die verfügbaren Vertragstypen (Strom, Gas, Mobilfunk, etc.).",show:e("platforms:read")}];return n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[n.jsx(tv,{className:"w-6 h-6"}),n.jsx("h1",{className:"text-2xl font-bold",children:"Einstellungen"})]}),n.jsxs("div",{className:"mb-8",children:[n.jsx("h2",{className:"text-lg font-semibold mb-4 text-gray-700",children:"Stammdaten"}),n.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:r.filter(a=>a.show).map(a=>n.jsx(Se,{to:a.to,className:"block p-4 bg-white border border-gray-200 rounded-lg shadow-sm hover:shadow-md hover:border-blue-300 transition-all group",children:n.jsxs("div",{className:"flex items-start gap-4",children:[n.jsx("div",{className:"p-2 bg-blue-50 rounded-lg group-hover:bg-blue-100 transition-colors",children:n.jsx(a.icon,{className:"w-6 h-6 text-blue-600"})}),n.jsxs("div",{className:"flex-1",children:[n.jsxs("h3",{className:"font-semibold text-gray-900 group-hover:text-blue-600 transition-colors flex items-center gap-2",children:[a.title,n.jsx(Ys,{className:"w-4 h-4 opacity-0 group-hover:opacity-100 transition-opacity"})]}),n.jsx("p",{className:"text-sm text-gray-500 mt-1",children:a.description})]})]})},a.to))})]}),e("settings:update")&&n.jsxs("div",{className:"mb-8",children:[n.jsx("h2",{className:"text-lg font-semibold mb-4 text-gray-700",children:"System"}),n.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[n.jsx(Se,{to:"/settings/portal",className:"block p-4 bg-white border border-gray-200 rounded-lg shadow-sm hover:shadow-md hover:border-blue-300 transition-all group",children:n.jsxs("div",{className:"flex items-start gap-4",children:[n.jsx("div",{className:"p-2 bg-blue-50 rounded-lg group-hover:bg-blue-100 transition-colors",children:n.jsx(uh,{className:"w-6 h-6 text-blue-600"})}),n.jsxs("div",{className:"flex-1",children:[n.jsxs("h3",{className:"font-semibold text-gray-900 group-hover:text-blue-600 transition-colors flex items-center gap-2",children:["Kundenportal",n.jsx(Ys,{className:"w-4 h-4 opacity-0 group-hover:opacity-100 transition-opacity"})]}),n.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"Konfigurieren Sie das Kundenportal und Support-Anfragen."})]})]})}),n.jsx(Se,{to:"/settings/deadlines",className:"block p-4 bg-white border border-gray-200 rounded-lg shadow-sm hover:shadow-md hover:border-blue-300 transition-all group",children:n.jsxs("div",{className:"flex items-start gap-4",children:[n.jsx("div",{className:"p-2 bg-blue-50 rounded-lg group-hover:bg-blue-100 transition-colors",children:n.jsx(qn,{className:"w-6 h-6 text-blue-600"})}),n.jsxs("div",{className:"flex-1",children:[n.jsxs("h3",{className:"font-semibold text-gray-900 group-hover:text-blue-600 transition-colors flex items-center gap-2",children:["Fristenschwellen",n.jsx(Ys,{className:"w-4 h-4 opacity-0 group-hover:opacity-100 transition-opacity"})]}),n.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"Konfigurieren Sie die Farbkodierung für Vertragsfristen im Cockpit."})]})]})}),n.jsx(Se,{to:"/settings/email-providers",className:"block p-4 bg-white border border-gray-200 rounded-lg shadow-sm hover:shadow-md hover:border-blue-300 transition-all group",children:n.jsxs("div",{className:"flex items-start gap-4",children:[n.jsx("div",{className:"p-2 bg-blue-50 rounded-lg group-hover:bg-blue-100 transition-colors",children:n.jsx(ev,{className:"w-6 h-6 text-blue-600"})}),n.jsxs("div",{className:"flex-1",children:[n.jsxs("h3",{className:"font-semibold text-gray-900 group-hover:text-blue-600 transition-colors flex items-center gap-2",children:["Email-Provisionierung",n.jsx(Ys,{className:"w-4 h-4 opacity-0 group-hover:opacity-100 transition-opacity"})]}),n.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"Konfigurieren Sie die automatische E-Mail-Erstellung für Stressfrei-Wechseln Adressen."})]})]})})]})]}),n.jsxs("div",{className:"mb-8",children:[n.jsx("h2",{className:"text-lg font-semibold mb-4 text-gray-700",children:"Persönlich"}),n.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:n.jsx(Se,{to:"/settings/view",className:"block p-4 bg-white border border-gray-200 rounded-lg shadow-sm hover:shadow-md hover:border-blue-300 transition-all group",children:n.jsxs("div",{className:"flex items-start gap-4",children:[n.jsx("div",{className:"p-2 bg-blue-50 rounded-lg group-hover:bg-blue-100 transition-colors",children:n.jsx(Ee,{className:"w-6 h-6 text-blue-600"})}),n.jsxs("div",{className:"flex-1",children:[n.jsxs("h3",{className:"font-semibold text-gray-900 group-hover:text-blue-600 transition-colors flex items-center gap-2",children:["Ansicht",n.jsx(Ys,{className:"w-4 h-4 opacity-0 group-hover:opacity-100 transition-opacity"})]}),n.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"Passen Sie die Darstellung der Anwendung an."})]})]})})})]}),e("developer:access")&&n.jsxs(Z,{title:"Entwickleroptionen",className:"mb-6",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(Ho,{className:"w-5 h-5 text-gray-500"}),n.jsxs("div",{children:[n.jsx("p",{className:"font-medium",children:"Entwicklermodus"}),n.jsx("p",{className:"text-sm text-gray-500",children:"Aktiviert erweiterte Funktionen wie direkten Datenbankzugriff"})]})]}),n.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[n.jsx("input",{type:"checkbox",checked:t,onChange:a=>s(a.target.checked),className:"sr-only peer"}),n.jsx("div",{className:"w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-blue-300 rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-blue-600"})]})]}),t&&n.jsx("div",{className:"mt-4 p-3 bg-yellow-50 border border-yellow-200 rounded-lg",children:n.jsxs("p",{className:"text-sm text-yellow-800",children:[n.jsx("strong",{children:"Warnung:"})," Der Entwicklermodus ermöglicht direkten Zugriff auf die Datenbank. Unsachgemäße Änderungen können zu Datenverlust oder Inkonsistenzen führen."]})})]}),n.jsx(Z,{title:"Über",children:n.jsxs("dl",{className:"space-y-3",children:[n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"Version"}),n.jsx("dd",{children:"1.0.0"})]}),n.jsxs("div",{children:[n.jsx("dt",{className:"text-sm text-gray-500",children:"System"}),n.jsx("dd",{children:"OpenCRM"})]})]})})]})}function f2({onSelectTable:e}){const t=w.useRef(null),[s,r]=w.useState(1),[a,i]=w.useState({x:0,y:0}),[l,o]=w.useState(!1),[c,u]=w.useState({x:0,y:0}),[d,m]=w.useState({}),[p,h]=w.useState(null),{data:f,isLoading:g}=ge({queryKey:["developer-schema"],queryFn:Za.getSchema}),b=(f==null?void 0:f.data)||[];w.useEffect(()=>{if(b.length>0&&Object.keys(d).length===0){const S=Math.ceil(Math.sqrt(b.length)),L={x:280,y:200},T={};b.forEach((_,K)=>{const W=K%S,Q=Math.floor(K/S);T[_.name]={x:50+W*L.x,y:50+Q*L.y}}),m(T)}},[b,d]);const y=w.useCallback(S=>{(S.target===S.currentTarget||S.target.tagName==="svg")&&(o(!0),u({x:S.clientX-a.x,y:S.clientY-a.y}))},[a]),v=w.useCallback(S=>{var L;if(l&&!p)i({x:S.clientX-c.x,y:S.clientY-c.y});else if(p){const T=(L=t.current)==null?void 0:L.getBoundingClientRect();T&&m(_=>({..._,[p]:{x:(S.clientX-T.left-a.x)/s-100,y:(S.clientY-T.top-a.y)/s-20}}))}},[l,p,c,a,s]),x=w.useCallback(()=>{o(!1),h(null)},[]),N=S=>{r(L=>Math.min(2,Math.max(.3,L+S)))},k=()=>{r(1),i({x:0,y:0})},D=w.useCallback(()=>{const S=[];return b.forEach(L=>{const T=d[L.name];T&&L.foreignKeys.forEach(_=>{const K=d[_.targetTable];if(!K)return;const W=b.find(z=>z.name===_.targetTable),Q=W==null?void 0:W.relations.find(z=>z.targetTable===L.name);S.push({from:{table:L.name,x:T.x+100,y:T.y+60},to:{table:_.targetTable,x:K.x+100,y:K.y+60},type:(Q==null?void 0:Q.type)||"one",label:_.field})})}),S},[b,d]);if(g)return n.jsx("div",{className:"flex items-center justify-center h-full",children:"Laden..."});const F=D();return n.jsxs("div",{className:"relative h-full w-full bg-gray-50 overflow-hidden",ref:t,children:[n.jsxs("div",{className:"absolute top-4 right-4 z-10 flex gap-2 bg-white rounded-lg shadow-md p-2",children:[n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>N(.1),title:"Vergrößern",children:n.jsx(T1,{className:"w-4 h-4"})}),n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>N(-.1),title:"Verkleinern",children:n.jsx(F1,{className:"w-4 h-4"})}),n.jsx(I,{variant:"ghost",size:"sm",onClick:k,title:"Zurücksetzen",children:n.jsx(N1,{className:"w-4 h-4"})}),n.jsxs("div",{className:"text-xs text-gray-500 flex items-center px-2",children:[Math.round(s*100),"%"]})]}),n.jsxs("div",{className:"absolute top-4 left-4 z-10 bg-white rounded-lg shadow-md p-2 text-xs text-gray-500",children:[n.jsx(w1,{className:"w-3 h-3 inline mr-1"}),"Tabellen ziehen zum Verschieben"]}),n.jsx("svg",{className:"w-full h-full cursor-grab",style:{cursor:l?"grabbing":"grab"},onMouseDown:y,onMouseMove:v,onMouseUp:x,onMouseLeave:x,children:n.jsxs("g",{transform:`translate(${a.x}, ${a.y}) scale(${s})`,children:[n.jsxs("defs",{children:[n.jsx("marker",{id:"arrowhead",markerWidth:"10",markerHeight:"7",refX:"9",refY:"3.5",orient:"auto",children:n.jsx("polygon",{points:"0 0, 10 3.5, 0 7",fill:"#6b7280"})}),n.jsx("marker",{id:"many-marker",markerWidth:"12",markerHeight:"12",refX:"6",refY:"6",orient:"auto",children:n.jsx("circle",{cx:"6",cy:"6",r:"3",fill:"#6b7280"})})]}),F.map((S,L)=>{const T=S.to.x-S.from.x,_=S.to.y-S.from.y,K=S.from.x+T/2,W=S.from.y+_/2,Q=S.from.x+T*.25,z=S.from.y,P=S.from.x+T*.75,j=S.to.y;return n.jsxs("g",{children:[n.jsx("path",{d:`M ${S.from.x} ${S.from.y} C ${Q} ${z}, ${P} ${j}, ${S.to.x} ${S.to.y}`,fill:"none",stroke:"#9ca3af",strokeWidth:"2",markerEnd:"url(#arrowhead)"}),n.jsx("text",{x:K,y:W-8,fontSize:"10",fill:"#6b7280",textAnchor:"middle",className:"select-none",children:S.type==="many"?"1:n":"1:1"})]},L)}),b.map(S=>{const L=d[S.name];if(!L)return null;const T=200,_=32,K=20,W=[...new Set([S.primaryKey,...S.foreignKeys.map(z=>z.field)])],Q=_+Math.min(W.length,5)*K+8;return n.jsxs("g",{transform:`translate(${L.x}, ${L.y})`,style:{cursor:"move"},onMouseDown:z=>{z.stopPropagation(),h(S.name)},children:[n.jsx("rect",{x:"3",y:"3",width:T,height:Q,rx:"6",fill:"rgba(0,0,0,0.1)"}),n.jsx("rect",{x:"0",y:"0",width:T,height:Q,rx:"6",fill:"white",stroke:"#e5e7eb",strokeWidth:"1"}),n.jsx("rect",{x:"0",y:"0",width:T,height:_,rx:"6",fill:"#3b82f6",className:"cursor-pointer",onClick:()=>e==null?void 0:e(S.name)}),n.jsx("rect",{x:"0",y:_-6,width:T,height:"6",fill:"#3b82f6"}),n.jsx("text",{x:T/2,y:"21",fontSize:"13",fontWeight:"bold",fill:"white",textAnchor:"middle",className:"select-none pointer-events-none",children:S.name}),W.slice(0,5).map((z,P)=>{const j=z===S.primaryKey||S.primaryKey.includes(z),B=S.foreignKeys.some(J=>J.field===z);return n.jsx("g",{transform:`translate(8, ${_+4+P*K})`,children:n.jsxs("text",{x:"0",y:"14",fontSize:"11",fill:j?"#dc2626":B?"#2563eb":"#374151",fontFamily:"monospace",className:"select-none",children:[j&&"🔑 ",B&&!j&&"🔗 ",z]})},z)}),W.length>5&&n.jsxs("text",{x:T/2,y:Q-4,fontSize:"10",fill:"#9ca3af",textAnchor:"middle",className:"select-none",children:["+",W.length-5," mehr..."]})]},S.name)})]})}),n.jsxs("div",{className:"absolute bottom-4 left-4 bg-white rounded-lg shadow-md p-3 text-xs",children:[n.jsx("div",{className:"font-medium mb-2",children:"Legende"}),n.jsxs("div",{className:"space-y-1",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-red-600",children:"🔑"}),n.jsx("span",{children:"Primary Key"})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-blue-600",children:"🔗"}),n.jsx("span",{children:"Foreign Key"})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("div",{className:"w-6 h-0.5 bg-gray-400"}),n.jsx("span",{children:"Beziehung"})]})]})]})]})}function p2(){var F;const[e,t]=w.useState(null),[s,r]=w.useState(1),[a,i]=w.useState(null),[l,o]=w.useState(!1),c=pe(),{data:u,isLoading:d,error:m}=ge({queryKey:["developer-schema"],queryFn:Za.getSchema});console.log("Schema data:",u),console.log("Schema error:",m);const{data:p,isLoading:h}=ge({queryKey:["developer-table",e,s],queryFn:()=>Za.getTableData(e,s),enabled:!!e}),f=Y({mutationFn:({tableName:S,id:L,data:T})=>Za.updateRow(S,L,T),onSuccess:()=>{c.invalidateQueries({queryKey:["developer-table",e]}),i(null)},onError:S=>{var L,T;alert(((T=(L=S.response)==null?void 0:L.data)==null?void 0:T.error)||"Fehler beim Speichern")}}),g=Y({mutationFn:({tableName:S,id:L})=>Za.deleteRow(S,L),onSuccess:()=>{c.invalidateQueries({queryKey:["developer-table",e]})},onError:S=>{var L,T;alert(((T=(L=S.response)==null?void 0:L.data)==null?void 0:T.error)||"Fehler beim Löschen")}}),b=(u==null?void 0:u.data)||[],y=b.find(S=>S.name===e),v=(S,L)=>L.primaryKey.includes(",")?L.primaryKey.split(",").map(T=>S[T]).join("-"):String(S[L.primaryKey]),x=S=>S==null?"-":typeof S=="boolean"?S?"Ja":"Nein":typeof S=="object"?S instanceof Date||typeof S=="string"&&S.match(/^\d{4}-\d{2}-\d{2}/)?new Date(S).toLocaleString("de-DE"):JSON.stringify(S):String(S),N=()=>{!a||!e||f.mutate({tableName:e,id:a.id,data:a.data})},k=S=>{e&&confirm("Datensatz wirklich löschen?")&&g.mutate({tableName:e,id:S})};if(d)return n.jsx("div",{className:"text-center py-8",children:"Laden..."});const D=S=>{t(S),r(1),o(!1)};return n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center justify-between mb-6",children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(Zy,{className:"w-6 h-6"}),n.jsx("h1",{className:"text-2xl font-bold",children:"Datenbankstruktur"})]}),n.jsxs(I,{onClick:()=>o(!0),children:[n.jsx(sp,{className:"w-4 h-4 mr-2"}),"ER-Diagramm"]})]}),n.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-4 gap-6",children:[n.jsx(Z,{title:"Tabellen",className:"lg:col-span-1",children:n.jsx("div",{className:"space-y-1 max-h-[600px] overflow-y-auto",children:b.map(S=>n.jsxs("button",{onClick:()=>{t(S.name),r(1)},className:`w-full text-left px-3 py-2 rounded-lg flex items-center gap-2 transition-colors ${e===S.name?"bg-blue-100 text-blue-700":"hover:bg-gray-100"}`,children:[n.jsx(E1,{className:"w-4 h-4"}),n.jsx("span",{className:"text-sm font-mono",children:S.name})]},S.name))})}),n.jsx("div",{className:"lg:col-span-3 space-y-6",children:e&&y?n.jsxs(n.Fragment,{children:[n.jsxs(Z,{title:`${e} - Beziehungen`,children:[n.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[n.jsxs("div",{children:[n.jsx("h4",{className:"text-sm font-medium text-gray-500 mb-2",children:"Fremdschlüssel (referenziert)"}),y.foreignKeys.length>0?n.jsx("div",{className:"space-y-1",children:y.foreignKeys.map(S=>n.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[n.jsx("span",{className:"font-mono text-gray-600",children:S.field}),n.jsx(d1,{className:"w-4 h-4 text-gray-400"}),n.jsx(he,{variant:"info",className:"cursor-pointer",onClick:()=>{t(S.targetTable),r(1)},children:S.targetTable})]},S.field))}):n.jsx("p",{className:"text-sm text-gray-400",children:"Keine"})]}),n.jsxs("div",{children:[n.jsx("h4",{className:"text-sm font-medium text-gray-500 mb-2",children:"Relationen (wird referenziert von)"}),y.relations.length>0?n.jsx("div",{className:"space-y-1",children:y.relations.map(S=>n.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[n.jsx("span",{className:"font-mono text-gray-600",children:S.field}),n.jsx(he,{variant:S.type==="many"?"warning":"default",children:S.type==="many"?"1:n":"1:1"}),n.jsx(he,{variant:"info",className:"cursor-pointer",onClick:()=>{t(S.targetTable),r(1)},children:S.targetTable})]},S.field))}):n.jsx("p",{className:"text-sm text-gray-400",children:"Keine"})]})]}),n.jsx("div",{className:"mt-4 pt-4 border-t",children:n.jsxs("div",{className:"flex gap-4 text-sm",children:[n.jsxs("div",{children:[n.jsx("span",{className:"text-gray-500",children:"Primary Key:"})," ",n.jsx("span",{className:"font-mono",children:y.primaryKey})]}),n.jsxs("div",{children:[n.jsx("span",{className:"text-gray-500",children:"Readonly:"})," ",n.jsx("span",{className:"font-mono text-red-600",children:y.readonlyFields.join(", ")||"-"})]}),n.jsxs("div",{children:[n.jsx("span",{className:"text-gray-500",children:"Required:"})," ",n.jsx("span",{className:"font-mono text-green-600",children:y.requiredFields.join(", ")||"-"})]})]})})]}),n.jsx(Z,{title:`${e} - Daten`,children:h?n.jsx("div",{className:"text-center py-4",children:"Laden..."}):n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"overflow-x-auto",children:n.jsxs("table",{className:"w-full text-sm",children:[n.jsx("thead",{children:n.jsxs("tr",{className:"border-b bg-gray-50",children:[(p==null?void 0:p.data)&&p.data.length>0&&Object.keys(p.data[0]).map(S=>n.jsxs("th",{className:"text-left py-2 px-3 font-medium text-gray-600 whitespace-nowrap",children:[S,y.readonlyFields.includes(S)&&n.jsx("span",{className:"ml-1 text-red-400 text-xs",children:"*"}),y.requiredFields.includes(S)&&n.jsx("span",{className:"ml-1 text-green-400 text-xs",children:"!"})]},S)),n.jsx("th",{className:"text-right py-2 px-3 font-medium text-gray-600",children:"Aktionen"})]})}),n.jsxs("tbody",{children:[(F=p==null?void 0:p.data)==null?void 0:F.map(S=>{const L=v(S,y);return n.jsxs("tr",{className:"border-b hover:bg-gray-50",children:[Object.entries(S).map(([T,_])=>n.jsx("td",{className:"py-2 px-3 font-mono text-xs max-w-[200px] truncate",children:x(_)},T)),n.jsx("td",{className:"py-2 px-3 text-right whitespace-nowrap",children:n.jsxs("div",{className:"flex justify-end gap-1",children:[n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>i({id:L,data:{...S}}),children:n.jsx(We,{className:"w-4 h-4"})}),n.jsx(I,{variant:"ghost",size:"sm",onClick:()=>k(L),children:n.jsx(be,{className:"w-4 h-4 text-red-500"})})]})})]},L)}),(!(p!=null&&p.data)||p.data.length===0)&&n.jsx("tr",{children:n.jsx("td",{colSpan:100,className:"py-4 text-center text-gray-500",children:"Keine Daten vorhanden"})})]})]})}),(p==null?void 0:p.pagination)&&p.pagination.totalPages>1&&n.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[n.jsxs("p",{className:"text-sm text-gray-500",children:["Seite ",p.pagination.page," von ",p.pagination.totalPages," (",p.pagination.total," Einträge)"]}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx(I,{variant:"secondary",size:"sm",onClick:()=>r(S=>Math.max(1,S-1)),disabled:s===1,children:n.jsx(f1,{className:"w-4 h-4"})}),n.jsx(I,{variant:"secondary",size:"sm",onClick:()=>r(S=>S+1),disabled:s>=p.pagination.totalPages,children:n.jsx(Ys,{className:"w-4 h-4"})})]})]})]})})]}):n.jsx(Z,{children:n.jsx("div",{className:"text-center py-8 text-gray-500",children:"Wähle eine Tabelle aus der Liste aus"})})})]}),n.jsx(dt,{isOpen:!!a,onClose:()=>i(null),title:`${e} bearbeiten`,children:a&&y&&n.jsxs("div",{className:"space-y-4 max-h-[60vh] overflow-y-auto",children:[Object.entries(a.data).map(([S,L])=>{const T=y.readonlyFields.includes(S),_=y.requiredFields.includes(S);return n.jsxs("div",{children:[n.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[S,T&&n.jsx("span",{className:"ml-1 text-red-400",children:"(readonly)"}),_&&n.jsx("span",{className:"ml-1 text-green-600",children:"*"})]}),T?n.jsx("div",{className:"px-3 py-2 bg-gray-100 rounded-lg font-mono text-sm",children:x(L)}):typeof L=="boolean"?n.jsxs("select",{value:String(a.data[S]),onChange:K=>i({...a,data:{...a.data,[S]:K.target.value==="true"}}),className:"w-full px-3 py-2 border rounded-lg",children:[n.jsx("option",{value:"true",children:"Ja"}),n.jsx("option",{value:"false",children:"Nein"})]}):n.jsx("input",{type:typeof L=="number"?"number":"text",value:a.data[S]??"",onChange:K=>i({...a,data:{...a.data,[S]:typeof L=="number"?K.target.value?Number(K.target.value):null:K.target.value||null}}),className:"w-full px-3 py-2 border rounded-lg font-mono text-sm",disabled:T})]},S)}),n.jsxs("div",{className:"flex justify-end gap-2 pt-4 border-t",children:[n.jsxs(I,{variant:"secondary",onClick:()=>i(null),children:[n.jsx(wa,{className:"w-4 h-4 mr-2"}),"Abbrechen"]}),n.jsxs(I,{onClick:N,disabled:f.isPending,children:[n.jsx(S1,{className:"w-4 h-4 mr-2"}),f.isPending?"Speichern...":"Speichern"]})]})]})}),l&&n.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[n.jsx("div",{className:"absolute inset-0 bg-black/50",onClick:()=>o(!1)}),n.jsxs("div",{className:"relative bg-white rounded-xl shadow-2xl w-[90vw] h-[85vh] flex flex-col",children:[n.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b",children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(sp,{className:"w-5 h-5 text-blue-600"}),n.jsx("h2",{className:"text-lg font-semibold",children:"ER-Diagramm - Datenbankbeziehungen"})]}),n.jsx("button",{onClick:()=>o(!1),className:"p-2 hover:bg-gray-100 rounded-lg transition-colors",children:n.jsx(wa,{className:"w-5 h-5"})})]}),n.jsx("div",{className:"flex-1 overflow-hidden",children:n.jsx(f2,{onSelectTable:D})})]})]})]})}function g2({children:e}){const{isAuthenticated:t,isLoading:s}=st();return s?n.jsx("div",{className:"min-h-screen flex items-center justify-center",children:n.jsx("div",{className:"text-gray-500",children:"Laden..."})}):t?n.jsx(n.Fragment,{children:e}):n.jsx(Qr,{to:"/login",replace:!0})}function x2({children:e}){const{hasPermission:t,developerMode:s}=st();return!t("developer:access")||!s?n.jsx(Qr,{to:"/",replace:!0}):n.jsx(n.Fragment,{children:e})}function y2(){const{isAuthenticated:e,isLoading:t}=st();return t?n.jsx("div",{className:"min-h-screen flex items-center justify-center",children:n.jsx("div",{className:"text-gray-500",children:"Laden..."})}):n.jsxs(n.Fragment,{children:[n.jsx(l1,{}),n.jsxs(Ib,{children:[n.jsx(Fe,{path:"/login",element:e?n.jsx(Qr,{to:"/",replace:!0}):n.jsx(R1,{})}),n.jsxs(Fe,{path:"/",element:n.jsx(g2,{children:n.jsx(L1,{})}),children:[n.jsx(Fe,{index:!0,element:n.jsx(O1,{})}),n.jsx(Fe,{path:"customers",element:n.jsx(z1,{})}),n.jsx(Fe,{path:"customers/new",element:n.jsx(Np,{})}),n.jsx(Fe,{path:"customers/:id",element:n.jsx($1,{})}),n.jsx(Fe,{path:"customers/:id/edit",element:n.jsx(Np,{})}),n.jsx(Fe,{path:"contracts",element:n.jsx(NS,{})}),n.jsx(Fe,{path:"contracts/cockpit",element:n.jsx(US,{})}),n.jsx(Fe,{path:"contracts/new",element:n.jsx(kp,{})}),n.jsx(Fe,{path:"contracts/:id",element:n.jsx(FS,{})}),n.jsx(Fe,{path:"contracts/:id/edit",element:n.jsx(kp,{})}),n.jsx(Fe,{path:"tasks",element:n.jsx(BS,{})}),n.jsx(Fe,{path:"settings",element:n.jsx(m2,{})}),n.jsx(Fe,{path:"settings/users",element:n.jsx(d2,{})}),n.jsx(Fe,{path:"settings/platforms",element:n.jsx(qS,{})}),n.jsx(Fe,{path:"settings/cancellation-periods",element:n.jsx(HS,{})}),n.jsx(Fe,{path:"settings/contract-durations",element:n.jsx(GS,{})}),n.jsx(Fe,{path:"settings/providers",element:n.jsx(YS,{})}),n.jsx(Fe,{path:"settings/contract-categories",element:n.jsx(n2,{})}),n.jsx(Fe,{path:"settings/view",element:n.jsx(i2,{})}),n.jsx(Fe,{path:"settings/portal",element:n.jsx(l2,{})}),n.jsx(Fe,{path:"settings/deadlines",element:n.jsx(o2,{})}),n.jsx(Fe,{path:"settings/email-providers",element:n.jsx(u2,{})}),n.jsx(Fe,{path:"users",element:n.jsx(Qr,{to:"/settings/users",replace:!0})}),n.jsx(Fe,{path:"platforms",element:n.jsx(Qr,{to:"/settings/platforms",replace:!0})}),n.jsx(Fe,{path:"developer/database",element:n.jsx(x2,{children:n.jsx(p2,{})})})]}),n.jsx(Fe,{path:"*",element:n.jsx(Qr,{to:"/",replace:!0})})]})]})}const v2=new xN({defaultOptions:{queries:{retry:1,staleTime:5*60*1e3}}});Rc.createRoot(document.getElementById("root")).render(n.jsx(Nt.StrictMode,{children:n.jsx(yN,{client:v2,children:n.jsx(Bb,{children:n.jsx(i1,{children:n.jsx(a1,{children:n.jsx(y2,{})})})})})}));