function vh(e,t){for(var n=0;nr[s]})}}}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 s of document.querySelectorAll('link[rel="modulepreload"]'))r(s);new MutationObserver(s=>{for(const o of s)if(o.type==="childList")for(const a of o.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&r(a)}).observe(document,{childList:!0,subtree:!0});function n(s){const o={};return s.integrity&&(o.integrity=s.integrity),s.referrerPolicy&&(o.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?o.credentials="include":s.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function r(s){if(s.ep)return;s.ep=!0;const o=n(s);fetch(s.href,o)}})();function yh(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var _c={exports:{}},Ks={},Dc={exports:{}},R={};/** * @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 zr=Symbol.for("react.element"),wh=Symbol.for("react.portal"),bh=Symbol.for("react.fragment"),jh=Symbol.for("react.strict_mode"),Nh=Symbol.for("react.profiler"),kh=Symbol.for("react.provider"),Sh=Symbol.for("react.context"),Ch=Symbol.for("react.forward_ref"),Eh=Symbol.for("react.suspense"),Th=Symbol.for("react.memo"),Ph=Symbol.for("react.lazy"),Ja=Symbol.iterator;function _h(e){return e===null||typeof e!="object"?null:(e=Ja&&e[Ja]||e["@@iterator"],typeof e=="function"?e:null)}var Ic={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},Ac=Object.assign,zc={};function $n(e,t,n){this.props=e,this.context=t,this.refs=zc,this.updater=n||Ic}$n.prototype.isReactComponent={};$n.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")};$n.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function Oc(){}Oc.prototype=$n.prototype;function Bo(e,t,n){this.props=e,this.context=t,this.refs=zc,this.updater=n||Ic}var Ko=Bo.prototype=new Oc;Ko.constructor=Bo;Ac(Ko,$n.prototype);Ko.isPureReactComponent=!0;var Xa=Array.isArray,Lc=Object.prototype.hasOwnProperty,Ho={current:null},Rc={key:!0,ref:!0,__self:!0,__source:!0};function $c(e,t,n){var r,s={},o=null,a=null;if(t!=null)for(r in t.ref!==void 0&&(a=t.ref),t.key!==void 0&&(o=""+t.key),t)Lc.call(t,r)&&!Rc.hasOwnProperty(r)&&(s[r]=t[r]);var l=arguments.length-2;if(l===1)s.children=n;else if(1>>1,F=E[$];if(0>>1;$s(Le,O))Wes(Vt,Le)?(E[$]=Vt,E[We]=O,$=We):(E[$]=Le,E[ue]=O,$=ue);else if(Wes(Vt,O))E[$]=Vt,E[We]=O,$=We;else break e}}return D}function s(E,D){var O=E.sortIndex-D.sortIndex;return O!==0?O:E.id-D.id}if(typeof performance=="object"&&typeof performance.now=="function"){var o=performance;e.unstable_now=function(){return o.now()}}else{var a=Date,l=a.now();e.unstable_now=function(){return a.now()-l}}var c=[],d=[],m=1,p=null,f=3,g=!1,b=!1,w=!1,j=typeof setTimeout=="function"?setTimeout:null,x=typeof clearTimeout=="function"?clearTimeout:null,u=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function h(E){for(var D=n(d);D!==null;){if(D.callback===null)r(d);else if(D.startTime<=E)r(d),D.sortIndex=D.expirationTime,t(c,D);else break;D=n(d)}}function y(E){if(w=!1,h(E),!b)if(n(c)!==null)b=!0,P(v);else{var D=n(d);D!==null&&L(y,D.startTime-E)}}function v(E,D){b=!1,w&&(w=!1,x(C),C=-1),g=!0;var O=f;try{for(h(D),p=n(c);p!==null&&(!(p.expirationTime>D)||E&&!I());){var $=p.callback;if(typeof $=="function"){p.callback=null,f=p.priorityLevel;var F=$(p.expirationTime<=D);D=e.unstable_now(),typeof F=="function"?p.callback=F:p===n(c)&&r(c),h(D)}else r(c);p=n(c)}if(p!==null)var ie=!0;else{var ue=n(d);ue!==null&&L(y,ue.startTime-D),ie=!1}return ie}finally{p=null,f=O,g=!1}}var N=!1,k=null,C=-1,z=5,A=-1;function I(){return!(e.unstable_now()-AE||125$?(E.sortIndex=O,t(d,E),n(c)===null&&E===n(d)&&(w?(x(C),C=-1):w=!0,L(y,O-$))):(E.sortIndex=F,t(c,E),b||g||(b=!0,P(v))),E},e.unstable_shouldYield=I,e.unstable_wrapCallback=function(E){var D=f;return function(){var O=f;f=D;try{return E.apply(this,arguments)}finally{f=O}}}})(Wc);Uc.exports=Wc;var Uh=Uc.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 Wh=S,Ae=Uh;function T(e){for(var t="https://reactjs.org/docs/error-decoder.html?invariant="+e,n=1;n"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),Ki=Object.prototype.hasOwnProperty,Bh=/^[: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]*$/,Qa={},qa={};function Kh(e){return Ki.call(qa,e)?!0:Ki.call(Qa,e)?!1:Bh.test(e)?qa[e]=!0:(Qa[e]=!0,!1)}function Hh(e,t,n,r){if(n!==null&&n.type===0)return!1;switch(typeof t){case"function":case"symbol":return!0;case"boolean":return r?!1:n!==null?!n.acceptsBooleans:(e=e.toLowerCase().slice(0,5),e!=="data-"&&e!=="aria-");default:return!1}}function Gh(e,t,n,r){if(t===null||typeof t>"u"||Hh(e,t,n,r))return!0;if(r)return!1;if(n!==null)switch(n.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 Ne(e,t,n,r,s,o,a){this.acceptsBooleans=t===2||t===3||t===4,this.attributeName=r,this.attributeNamespace=s,this.mustUseProperty=n,this.propertyName=e,this.type=t,this.sanitizeURL=o,this.removeEmptyString=a}var pe={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){pe[e]=new Ne(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var t=e[0];pe[t]=new Ne(t,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){pe[e]=new Ne(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){pe[e]=new Ne(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){pe[e]=new Ne(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){pe[e]=new Ne(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){pe[e]=new Ne(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){pe[e]=new Ne(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){pe[e]=new Ne(e,5,!1,e.toLowerCase(),null,!1,!1)});var Jo=/[\-:]([a-z])/g;function Xo(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(Jo,Xo);pe[t]=new Ne(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(Jo,Xo);pe[t]=new Ne(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(Jo,Xo);pe[t]=new Ne(t,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){pe[e]=new Ne(e,1,!1,e.toLowerCase(),null,!1,!1)});pe.xlinkHref=new Ne("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){pe[e]=new Ne(e,1,!1,e.toLowerCase(),null,!0,!0)});function Yo(e,t,n,r){var s=pe.hasOwnProperty(t)?pe[t]:null;(s!==null?s.type!==0:r||!(2l||s[a]!==o[l]){var c=` `+s[a].replace(" at new "," at ");return e.displayName&&c.includes("")&&(c=c.replace("",e.displayName)),c}while(1<=a&&0<=l);break}}}finally{pi=!1,Error.prepareStackTrace=n}return(e=e?e.displayName||e.name:"")?qn(e):""}function Zh(e){switch(e.tag){case 5:return qn(e.type);case 16:return qn("Lazy");case 13:return qn("Suspense");case 19:return qn("SuspenseList");case 0:case 2:case 15:return e=fi(e.type,!1),e;case 11:return e=fi(e.type.render,!1),e;case 1:return e=fi(e.type,!0),e;default:return""}}function Ji(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 mn:return"Fragment";case hn:return"Portal";case Hi:return"Profiler";case Qo:return"StrictMode";case Gi:return"Suspense";case Zi:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case Hc:return(e.displayName||"Context")+".Consumer";case Kc:return(e._context.displayName||"Context")+".Provider";case qo:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case ea:return t=e.displayName||null,t!==null?t:Ji(e.type)||"Memo";case gt:t=e._payload,e=e._init;try{return Ji(e(t))}catch{}}return null}function Jh(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 Ji(t);case 8:return t===Qo?"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 zt(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function Zc(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(t==="checkbox"||t==="radio")}function Xh(e){var t=Zc(e)?"checked":"value",n=Object.getOwnPropertyDescriptor(e.constructor.prototype,t),r=""+e[t];if(!e.hasOwnProperty(t)&&typeof n<"u"&&typeof n.get=="function"&&typeof n.set=="function"){var s=n.get,o=n.set;return Object.defineProperty(e,t,{configurable:!0,get:function(){return s.call(this)},set:function(a){r=""+a,o.call(this,a)}}),Object.defineProperty(e,t,{enumerable:n.enumerable}),{getValue:function(){return r},setValue:function(a){r=""+a},stopTracking:function(){e._valueTracker=null,delete e[t]}}}}function Ur(e){e._valueTracker||(e._valueTracker=Xh(e))}function Jc(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var n=t.getValue(),r="";return e&&(r=Zc(e)?e.checked?"true":"false":e.value),e=r,e!==n?(t.setValue(e),!0):!1}function gs(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 Xi(e,t){var n=t.checked;return q({},t,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:n??e._wrapperState.initialChecked})}function tl(e,t){var n=t.defaultValue==null?"":t.defaultValue,r=t.checked!=null?t.checked:t.defaultChecked;n=zt(t.value!=null?t.value:n),e._wrapperState={initialChecked:r,initialValue:n,controlled:t.type==="checkbox"||t.type==="radio"?t.checked!=null:t.value!=null}}function Xc(e,t){t=t.checked,t!=null&&Yo(e,"checked",t,!1)}function Yi(e,t){Xc(e,t);var n=zt(t.value),r=t.type;if(n!=null)r==="number"?(n===0&&e.value===""||e.value!=n)&&(e.value=""+n):e.value!==""+n&&(e.value=""+n);else if(r==="submit"||r==="reset"){e.removeAttribute("value");return}t.hasOwnProperty("value")?Qi(e,t.type,n):t.hasOwnProperty("defaultValue")&&Qi(e,t.type,zt(t.defaultValue)),t.checked==null&&t.defaultChecked!=null&&(e.defaultChecked=!!t.defaultChecked)}function nl(e,t,n){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,n||t===e.value||(e.value=t),e.defaultValue=t}n=e.name,n!==""&&(e.name=""),e.defaultChecked=!!e._wrapperState.initialChecked,n!==""&&(e.name=n)}function Qi(e,t,n){(t!=="number"||gs(e.ownerDocument)!==e)&&(n==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+n&&(e.defaultValue=""+n))}var er=Array.isArray;function Sn(e,t,n,r){if(e=e.options,t){t={};for(var s=0;s"+t.valueOf().toString()+"",t=Wr.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)}});function fr(e,t){if(t){var n=e.firstChild;if(n&&n===e.lastChild&&n.nodeType===3){n.nodeValue=t;return}}e.textContent=t}var rr={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},Yh=["Webkit","ms","Moz","O"];Object.keys(rr).forEach(function(e){Yh.forEach(function(t){t=t+e.charAt(0).toUpperCase()+e.substring(1),rr[t]=rr[e]})});function ed(e,t,n){return t==null||typeof t=="boolean"||t===""?"":n||typeof t!="number"||t===0||rr.hasOwnProperty(e)&&rr[e]?(""+t).trim():t+"px"}function td(e,t){e=e.style;for(var n in t)if(t.hasOwnProperty(n)){var r=n.indexOf("--")===0,s=ed(n,t[n],r);n==="float"&&(n="cssFloat"),r?e.setProperty(n,s):e[n]=s}}var Qh=q({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 to(e,t){if(t){if(Qh[e]&&(t.children!=null||t.dangerouslySetInnerHTML!=null))throw Error(T(137,e));if(t.dangerouslySetInnerHTML!=null){if(t.children!=null)throw Error(T(60));if(typeof t.dangerouslySetInnerHTML!="object"||!("__html"in t.dangerouslySetInnerHTML))throw Error(T(61))}if(t.style!=null&&typeof t.style!="object")throw Error(T(62))}}function no(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 ro=null;function ta(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var so=null,Cn=null,En=null;function il(e){if(e=Rr(e)){if(typeof so!="function")throw Error(T(280));var t=e.stateNode;t&&(t=Xs(t),so(e.stateNode,e.type,t))}}function nd(e){Cn?En?En.push(e):En=[e]:Cn=e}function rd(){if(Cn){var e=Cn,t=En;if(En=Cn=null,il(e),t)for(e=0;e>>=0,e===0?32:31-(cm(e)/dm|0)|0}var Br=64,Kr=4194304;function tr(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 ws(e,t){var n=e.pendingLanes;if(n===0)return 0;var r=0,s=e.suspendedLanes,o=e.pingedLanes,a=n&268435455;if(a!==0){var l=a&~s;l!==0?r=tr(l):(o&=a,o!==0&&(r=tr(o)))}else a=n&~s,a!==0?r=tr(a):o!==0&&(r=tr(o));if(r===0)return 0;if(t!==0&&t!==r&&!(t&s)&&(s=r&-r,o=t&-t,s>=o||s===16&&(o&4194240)!==0))return t;if(r&4&&(r|=n&16),t=e.entangledLanes,t!==0)for(e=e.entanglements,t&=r;0n;n++)t.push(e);return t}function Or(e,t,n){e.pendingLanes|=t,t!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,t=31-Je(t),e[t]=n}function pm(e,t){var n=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=ir),pl=String.fromCharCode(32),fl=!1;function Nd(e,t){switch(e){case"keyup":return Um.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function kd(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var pn=!1;function Bm(e,t){switch(e){case"compositionend":return kd(t);case"keypress":return t.which!==32?null:(fl=!0,pl);case"textInput":return e=t.data,e===pl&&fl?null:e;default:return null}}function Km(e,t){if(pn)return e==="compositionend"||!ca&&Nd(e,t)?(e=bd(),as=oa=jt=null,pn=!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:n,offset:t-e};e=r}e:{for(;n;){if(n.nextSibling){n=n.nextSibling;break e}n=n.parentNode}n=void 0}n=yl(n)}}function Td(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?Td(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function Pd(){for(var e=window,t=gs();t instanceof e.HTMLIFrameElement;){try{var n=typeof t.contentWindow.location.href=="string"}catch{n=!1}if(n)e=t.contentWindow;else break;t=gs(e.document)}return t}function da(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 ep(e){var t=Pd(),n=e.focusedElem,r=e.selectionRange;if(t!==n&&n&&n.ownerDocument&&Td(n.ownerDocument.documentElement,n)){if(r!==null&&da(n)){if(t=r.start,e=r.end,e===void 0&&(e=t),"selectionStart"in n)n.selectionStart=t,n.selectionEnd=Math.min(e,n.value.length);else if(e=(t=n.ownerDocument||document)&&t.defaultView||window,e.getSelection){e=e.getSelection();var s=n.textContent.length,o=Math.min(r.start,s);r=r.end===void 0?o:Math.min(r.end,s),!e.extend&&o>r&&(s=r,r=o,o=s),s=wl(n,o);var a=wl(n,r);s&&a&&(e.rangeCount!==1||e.anchorNode!==s.node||e.anchorOffset!==s.offset||e.focusNode!==a.node||e.focusOffset!==a.offset)&&(t=t.createRange(),t.setStart(s.node,s.offset),e.removeAllRanges(),o>r?(e.addRange(t),e.extend(a.node,a.offset)):(t.setEnd(a.node,a.offset),e.addRange(t)))}}for(t=[],e=n;e=e.parentNode;)e.nodeType===1&&t.push({element:e,left:e.scrollLeft,top:e.scrollTop});for(typeof n.focus=="function"&&n.focus(),n=0;n=document.documentMode,fn=null,uo=null,ar=null,ho=!1;function bl(e,t,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;ho||fn==null||fn!==gs(r)||(r=fn,"selectionStart"in r&&da(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}),ar&&br(ar,r)||(ar=r,r=Ns(uo,"onSelect"),0vn||(e.current=vo[vn],vo[vn]=null,vn--)}function H(e,t){vn++,vo[vn]=e.current,e.current=t}var Ot={},ve=Rt(Ot),Ee=Rt(!1),qt=Ot;function In(e,t){var n=e.type.contextTypes;if(!n)return Ot;var r=e.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===t)return r.__reactInternalMemoizedMaskedChildContext;var s={},o;for(o in n)s[o]=t[o];return r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=t,e.__reactInternalMemoizedMaskedChildContext=s),s}function Te(e){return e=e.childContextTypes,e!=null}function Ss(){J(Ee),J(ve)}function Tl(e,t,n){if(ve.current!==Ot)throw Error(T(168));H(ve,t),H(Ee,n)}function $d(e,t,n){var r=e.stateNode;if(t=t.childContextTypes,typeof r.getChildContext!="function")return n;r=r.getChildContext();for(var s in r)if(!(s in t))throw Error(T(108,Jh(e)||"Unknown",s));return q({},n,r)}function Cs(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||Ot,qt=ve.current,H(ve,e),H(Ee,Ee.current),!0}function Pl(e,t,n){var r=e.stateNode;if(!r)throw Error(T(169));n?(e=$d(e,t,qt),r.__reactInternalMemoizedMergedChildContext=e,J(Ee),J(ve),H(ve,e)):J(Ee),H(Ee,n)}var it=null,Ys=!1,Pi=!1;function Fd(e){it===null?it=[e]:it.push(e)}function hp(e){Ys=!0,Fd(e)}function $t(){if(!Pi&&it!==null){Pi=!0;var e=0,t=B;try{var n=it;for(B=1;e>=a,s-=a,ot=1<<32-Je(t)+s|n<C?(z=k,k=null):z=k.sibling;var A=f(x,k,h[C],y);if(A===null){k===null&&(k=z);break}e&&k&&A.alternate===null&&t(x,k),u=o(A,u,C),N===null?v=A:N.sibling=A,N=A,k=z}if(C===h.length)return n(x,k),X&&Ut(x,C),v;if(k===null){for(;CC?(z=k,k=null):z=k.sibling;var I=f(x,k,A.value,y);if(I===null){k===null&&(k=z);break}e&&k&&I.alternate===null&&t(x,k),u=o(I,u,C),N===null?v=I:N.sibling=I,N=I,k=z}if(A.done)return n(x,k),X&&Ut(x,C),v;if(k===null){for(;!A.done;C++,A=h.next())A=p(x,A.value,y),A!==null&&(u=o(A,u,C),N===null?v=A:N.sibling=A,N=A);return X&&Ut(x,C),v}for(k=r(x,k);!A.done;C++,A=h.next())A=g(k,x,C,A.value,y),A!==null&&(e&&A.alternate!==null&&k.delete(A.key===null?C:A.key),u=o(A,u,C),N===null?v=A:N.sibling=A,N=A);return e&&k.forEach(function(M){return t(x,M)}),X&&Ut(x,C),v}function j(x,u,h,y){if(typeof h=="object"&&h!==null&&h.type===mn&&h.key===null&&(h=h.props.children),typeof h=="object"&&h!==null){switch(h.$$typeof){case Mr:e:{for(var v=h.key,N=u;N!==null;){if(N.key===v){if(v=h.type,v===mn){if(N.tag===7){n(x,N.sibling),u=s(N,h.props.children),u.return=x,x=u;break e}}else if(N.elementType===v||typeof v=="object"&&v!==null&&v.$$typeof===gt&&Il(v)===N.type){n(x,N.sibling),u=s(N,h.props),u.ref=Gn(x,N,h),u.return=x,x=u;break e}n(x,N);break}else t(x,N);N=N.sibling}h.type===mn?(u=Qt(h.props.children,x.mode,y,h.key),u.return=x,x=u):(y=fs(h.type,h.key,h.props,null,x.mode,y),y.ref=Gn(x,u,h),y.return=x,x=y)}return a(x);case hn:e:{for(N=h.key;u!==null;){if(u.key===N)if(u.tag===4&&u.stateNode.containerInfo===h.containerInfo&&u.stateNode.implementation===h.implementation){n(x,u.sibling),u=s(u,h.children||[]),u.return=x,x=u;break e}else{n(x,u);break}else t(x,u);u=u.sibling}u=Ri(h,x.mode,y),u.return=x,x=u}return a(x);case gt:return N=h._init,j(x,u,N(h._payload),y)}if(er(h))return b(x,u,h,y);if(Un(h))return w(x,u,h,y);Qr(x,h)}return typeof h=="string"&&h!==""||typeof h=="number"?(h=""+h,u!==null&&u.tag===6?(n(x,u.sibling),u=s(u,h),u.return=x,x=u):(n(x,u),u=Li(h,x.mode,y),u.return=x,x=u),a(x)):n(x,u)}return j}var zn=Wd(!0),Bd=Wd(!1),Ps=Rt(null),_s=null,bn=null,pa=null;function fa(){pa=bn=_s=null}function ga(e){var t=Ps.current;J(Ps),e._currentValue=t}function bo(e,t,n){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===n)break;e=e.return}}function Pn(e,t){_s=e,pa=bn=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&t&&(Ce=!0),e.firstContext=null)}function Me(e){var t=e._currentValue;if(pa!==e)if(e={context:e,memoizedValue:t,next:null},bn===null){if(_s===null)throw Error(T(308));bn=e,_s.dependencies={lanes:0,firstContext:e}}else bn=bn.next=e;return t}var Gt=null;function xa(e){Gt===null?Gt=[e]:Gt.push(e)}function Kd(e,t,n,r){var s=t.interleaved;return s===null?(n.next=n,xa(t)):(n.next=s.next,s.next=n),t.interleaved=n,ut(e,r)}function ut(e,t){e.lanes|=t;var n=e.alternate;for(n!==null&&(n.lanes|=t),n=e,e=e.return;e!==null;)e.childLanes|=t,n=e.alternate,n!==null&&(n.childLanes|=t),n=e,e=e.return;return n.tag===3?n.stateNode:null}var xt=!1;function va(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function Hd(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 lt(e,t){return{eventTime:e,lane:t,tag:0,payload:null,callback:null,next:null}}function Pt(e,t,n){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,V&2){var s=r.pending;return s===null?t.next=t:(t.next=s.next,s.next=t),r.pending=t,ut(e,n)}return s=r.interleaved,s===null?(t.next=t,xa(r)):(t.next=s.next,s.next=t),r.interleaved=t,ut(e,n)}function cs(e,t,n){if(t=t.updateQueue,t!==null&&(t=t.shared,(n&4194240)!==0)){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,ra(e,n)}}function Al(e,t){var n=e.updateQueue,r=e.alternate;if(r!==null&&(r=r.updateQueue,n===r)){var s=null,o=null;if(n=n.firstBaseUpdate,n!==null){do{var a={eventTime:n.eventTime,lane:n.lane,tag:n.tag,payload:n.payload,callback:n.callback,next:null};o===null?s=o=a:o=o.next=a,n=n.next}while(n!==null);o===null?s=o=t:o=o.next=t}else s=o=t;n={baseState:r.baseState,firstBaseUpdate:s,lastBaseUpdate:o,shared:r.shared,effects:r.effects},e.updateQueue=n;return}e=n.lastBaseUpdate,e===null?n.firstBaseUpdate=t:e.next=t,n.lastBaseUpdate=t}function Ds(e,t,n,r){var s=e.updateQueue;xt=!1;var o=s.firstBaseUpdate,a=s.lastBaseUpdate,l=s.shared.pending;if(l!==null){s.shared.pending=null;var c=l,d=c.next;c.next=null,a===null?o=d:a.next=d,a=c;var m=e.alternate;m!==null&&(m=m.updateQueue,l=m.lastBaseUpdate,l!==a&&(l===null?m.firstBaseUpdate=d:l.next=d,m.lastBaseUpdate=c))}if(o!==null){var p=s.baseState;a=0,m=d=c=null,l=o;do{var f=l.lane,g=l.eventTime;if((r&f)===f){m!==null&&(m=m.next={eventTime:g,lane:0,tag:l.tag,payload:l.payload,callback:l.callback,next:null});e:{var b=e,w=l;switch(f=t,g=n,w.tag){case 1:if(b=w.payload,typeof b=="function"){p=b.call(g,p,f);break e}p=b;break e;case 3:b.flags=b.flags&-65537|128;case 0:if(b=w.payload,f=typeof b=="function"?b.call(g,p,f):b,f==null)break e;p=q({},p,f);break e;case 2:xt=!0}}l.callback!==null&&l.lane!==0&&(e.flags|=64,f=s.effects,f===null?s.effects=[l]:f.push(l))}else g={eventTime:g,lane:f,tag:l.tag,payload:l.payload,callback:l.callback,next:null},m===null?(d=m=g,c=p):m=m.next=g,a|=f;if(l=l.next,l===null){if(l=s.shared.pending,l===null)break;f=l,l=f.next,f.next=null,s.lastBaseUpdate=f,s.shared.pending=null}}while(1);if(m===null&&(c=p),s.baseState=c,s.firstBaseUpdate=d,s.lastBaseUpdate=m,t=s.shared.interleaved,t!==null){s=t;do a|=s.lane,s=s.next;while(s!==t)}else o===null&&(s.shared.lanes=0);nn|=a,e.lanes=a,e.memoizedState=p}}function zl(e,t,n){if(e=t.effects,t.effects=null,e!==null)for(t=0;tn?n:4,e(!0);var r=Di.transition;Di.transition={};try{e(!1),t()}finally{B=n,Di.transition=r}}function cu(){return Ue().memoizedState}function gp(e,t,n){var r=Dt(e);if(n={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null},du(e))uu(t,n);else if(n=Kd(e,t,n,r),n!==null){var s=be();Xe(n,e,r,s),hu(n,t,r)}}function xp(e,t,n){var r=Dt(e),s={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null};if(du(e))uu(t,s);else{var o=e.alternate;if(e.lanes===0&&(o===null||o.lanes===0)&&(o=t.lastRenderedReducer,o!==null))try{var a=t.lastRenderedState,l=o(a,n);if(s.hasEagerState=!0,s.eagerState=l,Ye(l,a)){var c=t.interleaved;c===null?(s.next=s,xa(t)):(s.next=c.next,c.next=s),t.interleaved=s;return}}catch{}finally{}n=Kd(e,t,s,r),n!==null&&(s=be(),Xe(n,e,r,s),hu(n,t,r))}}function du(e){var t=e.alternate;return e===Q||t!==null&&t===Q}function uu(e,t){lr=As=!0;var n=e.pending;n===null?t.next=t:(t.next=n.next,n.next=t),e.pending=t}function hu(e,t,n){if(n&4194240){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,ra(e,n)}}var zs={readContext:Me,useCallback:fe,useContext:fe,useEffect:fe,useImperativeHandle:fe,useInsertionEffect:fe,useLayoutEffect:fe,useMemo:fe,useReducer:fe,useRef:fe,useState:fe,useDebugValue:fe,useDeferredValue:fe,useTransition:fe,useMutableSource:fe,useSyncExternalStore:fe,useId:fe,unstable_isNewReconciler:!1},vp={readContext:Me,useCallback:function(e,t){return qe().memoizedState=[e,t===void 0?null:t],e},useContext:Me,useEffect:Ll,useImperativeHandle:function(e,t,n){return n=n!=null?n.concat([e]):null,us(4194308,4,su.bind(null,t,e),n)},useLayoutEffect:function(e,t){return us(4194308,4,e,t)},useInsertionEffect:function(e,t){return us(4,2,e,t)},useMemo:function(e,t){var n=qe();return t=t===void 0?null:t,e=e(),n.memoizedState=[e,t],e},useReducer:function(e,t,n){var r=qe();return t=n!==void 0?n(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=gp.bind(null,Q,e),[r.memoizedState,e]},useRef:function(e){var t=qe();return e={current:e},t.memoizedState=e},useState:Ol,useDebugValue:Ca,useDeferredValue:function(e){return qe().memoizedState=e},useTransition:function(){var e=Ol(!1),t=e[0];return e=fp.bind(null,e[1]),qe().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,n){var r=Q,s=qe();if(X){if(n===void 0)throw Error(T(407));n=n()}else{if(n=t(),de===null)throw Error(T(349));tn&30||Xd(r,t,n)}s.memoizedState=n;var o={value:n,getSnapshot:t};return s.queue=o,Ll(Qd.bind(null,r,o,e),[e]),r.flags|=2048,Pr(9,Yd.bind(null,r,o,n,t),void 0,null),n},useId:function(){var e=qe(),t=de.identifierPrefix;if(X){var n=at,r=ot;n=(r&~(1<<32-Je(r)-1)).toString(32)+n,t=":"+t+"R"+n,n=Er++,0<\/script>",e=e.removeChild(e.firstChild)):typeof r.is=="string"?e=a.createElement(n,{is:r.is}):(e=a.createElement(n),n==="select"&&(a=e,r.multiple?a.multiple=!0:r.size&&(a.size=r.size))):e=a.createElementNS(e,n),e[tt]=t,e[kr]=r,ju(e,t,!1,!1),t.stateNode=e;e:{switch(a=no(n,r),n){case"dialog":Z("cancel",e),Z("close",e),s=r;break;case"iframe":case"object":case"embed":Z("load",e),s=r;break;case"video":case"audio":for(s=0;sRn&&(t.flags|=128,r=!0,Zn(o,!1),t.lanes=4194304)}else{if(!r)if(e=Is(a),e!==null){if(t.flags|=128,r=!0,n=e.updateQueue,n!==null&&(t.updateQueue=n,t.flags|=4),Zn(o,!0),o.tail===null&&o.tailMode==="hidden"&&!a.alternate&&!X)return ge(t),null}else 2*ne()-o.renderingStartTime>Rn&&n!==1073741824&&(t.flags|=128,r=!0,Zn(o,!1),t.lanes=4194304);o.isBackwards?(a.sibling=t.child,t.child=a):(n=o.last,n!==null?n.sibling=a:t.child=a,o.last=a)}return o.tail!==null?(t=o.tail,o.rendering=t,o.tail=t.sibling,o.renderingStartTime=ne(),t.sibling=null,n=Y.current,H(Y,r?n&1|2:n&1),t):(ge(t),null);case 22:case 23:return Ia(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&t.mode&1?_e&1073741824&&(ge(t),t.subtreeFlags&6&&(t.flags|=8192)):ge(t),null;case 24:return null;case 25:return null}throw Error(T(156,t.tag))}function Cp(e,t){switch(ha(t),t.tag){case 1:return Te(t.type)&&Ss(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return On(),J(Ee),J(ve),ba(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return wa(t),null;case 13:if(J(Y),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(T(340));An()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return J(Y),null;case 4:return On(),null;case 10:return ga(t.type._context),null;case 22:case 23:return Ia(),null;case 24:return null;default:return null}}var es=!1,xe=!1,Ep=typeof WeakSet=="function"?WeakSet:Set,_=null;function jn(e,t){var n=e.ref;if(n!==null)if(typeof n=="function")try{n(null)}catch(r){ee(e,t,r)}else n.current=null}function _o(e,t,n){try{n()}catch(r){ee(e,t,r)}}var Gl=!1;function Tp(e,t){if(mo=bs,e=Pd(),da(e)){if("selectionStart"in e)var n={start:e.selectionStart,end:e.selectionEnd};else e:{n=(n=e.ownerDocument)&&n.defaultView||window;var r=n.getSelection&&n.getSelection();if(r&&r.rangeCount!==0){n=r.anchorNode;var s=r.anchorOffset,o=r.focusNode;r=r.focusOffset;try{n.nodeType,o.nodeType}catch{n=null;break e}var a=0,l=-1,c=-1,d=0,m=0,p=e,f=null;t:for(;;){for(var g;p!==n||s!==0&&p.nodeType!==3||(l=a+s),p!==o||r!==0&&p.nodeType!==3||(c=a+r),p.nodeType===3&&(a+=p.nodeValue.length),(g=p.firstChild)!==null;)f=p,p=g;for(;;){if(p===e)break t;if(f===n&&++d===s&&(l=a),f===o&&++m===r&&(c=a),(g=p.nextSibling)!==null)break;p=f,f=p.parentNode}p=g}n=l===-1||c===-1?null:{start:l,end:c}}else n=null}n=n||{start:0,end:0}}else n=null;for(po={focusedElem:e,selectionRange:n},bs=!1,_=t;_!==null;)if(t=_,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,_=e;else for(;_!==null;){t=_;try{var b=t.alternate;if(t.flags&1024)switch(t.tag){case 0:case 11:case 15:break;case 1:if(b!==null){var w=b.memoizedProps,j=b.memoizedState,x=t.stateNode,u=x.getSnapshotBeforeUpdate(t.elementType===t.type?w:Ke(t.type,w),j);x.__reactInternalSnapshotBeforeUpdate=u}break;case 3:var h=t.stateNode.containerInfo;h.nodeType===1?h.textContent="":h.nodeType===9&&h.documentElement&&h.removeChild(h.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(T(163))}}catch(y){ee(t,t.return,y)}if(e=t.sibling,e!==null){e.return=t.return,_=e;break}_=t.return}return b=Gl,Gl=!1,b}function cr(e,t,n){var r=t.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var s=r=r.next;do{if((s.tag&e)===e){var o=s.destroy;s.destroy=void 0,o!==void 0&&_o(t,n,o)}s=s.next}while(s!==r)}}function ei(e,t){if(t=t.updateQueue,t=t!==null?t.lastEffect:null,t!==null){var n=t=t.next;do{if((n.tag&e)===e){var r=n.create;n.destroy=r()}n=n.next}while(n!==t)}}function Do(e){var t=e.ref;if(t!==null){var n=e.stateNode;switch(e.tag){case 5:e=n;break;default:e=n}typeof t=="function"?t(e):t.current=e}}function Su(e){var t=e.alternate;t!==null&&(e.alternate=null,Su(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[tt],delete t[kr],delete t[xo],delete t[dp],delete t[up])),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 Cu(e){return e.tag===5||e.tag===3||e.tag===4}function Zl(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||Cu(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 Io(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.nodeType===8?n.parentNode.insertBefore(e,t):n.insertBefore(e,t):(n.nodeType===8?(t=n.parentNode,t.insertBefore(e,n)):(t=n,t.appendChild(e)),n=n._reactRootContainer,n!=null||t.onclick!==null||(t.onclick=ks));else if(r!==4&&(e=e.child,e!==null))for(Io(e,t,n),e=e.sibling;e!==null;)Io(e,t,n),e=e.sibling}function Ao(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.insertBefore(e,t):n.appendChild(e);else if(r!==4&&(e=e.child,e!==null))for(Ao(e,t,n),e=e.sibling;e!==null;)Ao(e,t,n),e=e.sibling}var he=null,He=!1;function pt(e,t,n){for(n=n.child;n!==null;)Eu(e,t,n),n=n.sibling}function Eu(e,t,n){if(nt&&typeof nt.onCommitFiberUnmount=="function")try{nt.onCommitFiberUnmount(Hs,n)}catch{}switch(n.tag){case 5:xe||jn(n,t);case 6:var r=he,s=He;he=null,pt(e,t,n),he=r,He=s,he!==null&&(He?(e=he,n=n.stateNode,e.nodeType===8?e.parentNode.removeChild(n):e.removeChild(n)):he.removeChild(n.stateNode));break;case 18:he!==null&&(He?(e=he,n=n.stateNode,e.nodeType===8?Ti(e.parentNode,n):e.nodeType===1&&Ti(e,n),yr(e)):Ti(he,n.stateNode));break;case 4:r=he,s=He,he=n.stateNode.containerInfo,He=!0,pt(e,t,n),he=r,He=s;break;case 0:case 11:case 14:case 15:if(!xe&&(r=n.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){s=r=r.next;do{var o=s,a=o.destroy;o=o.tag,a!==void 0&&(o&2||o&4)&&_o(n,t,a),s=s.next}while(s!==r)}pt(e,t,n);break;case 1:if(!xe&&(jn(n,t),r=n.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(l){ee(n,t,l)}pt(e,t,n);break;case 21:pt(e,t,n);break;case 22:n.mode&1?(xe=(r=xe)||n.memoizedState!==null,pt(e,t,n),xe=r):pt(e,t,n);break;default:pt(e,t,n)}}function Jl(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var n=e.stateNode;n===null&&(n=e.stateNode=new Ep),t.forEach(function(r){var s=Rp.bind(null,e,r);n.has(r)||(n.add(r),r.then(s,s))})}}function Be(e,t){var n=t.deletions;if(n!==null)for(var r=0;rs&&(s=a),r&=~o}if(r=s,r=ne()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*_p(r/1960))-r,10e?16:e,Nt===null)var r=!1;else{if(e=Nt,Nt=null,Rs=0,V&6)throw Error(T(331));var s=V;for(V|=4,_=e.current;_!==null;){var o=_,a=o.child;if(_.flags&16){var l=o.deletions;if(l!==null){for(var c=0;cne()-_a?Yt(e,0):Pa|=n),Pe(e,t)}function Ou(e,t){t===0&&(e.mode&1?(t=Kr,Kr<<=1,!(Kr&130023424)&&(Kr=4194304)):t=1);var n=be();e=ut(e,t),e!==null&&(Or(e,t,n),Pe(e,n))}function Lp(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),Ou(e,n)}function Rp(e,t){var n=0;switch(e.tag){case 13:var r=e.stateNode,s=e.memoizedState;s!==null&&(n=s.retryLane);break;case 19:r=e.stateNode;break;default:throw Error(T(314))}r!==null&&r.delete(t),Ou(e,n)}var Lu;Lu=function(e,t,n){if(e!==null)if(e.memoizedProps!==t.pendingProps||Ee.current)Ce=!0;else{if(!(e.lanes&n)&&!(t.flags&128))return Ce=!1,kp(e,t,n);Ce=!!(e.flags&131072)}else Ce=!1,X&&t.flags&1048576&&Vd(t,Ts,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;hs(e,t),e=t.pendingProps;var s=In(t,ve.current);Pn(t,n),s=Na(null,t,r,e,s,n);var o=ka();return t.flags|=1,typeof s=="object"&&s!==null&&typeof s.render=="function"&&s.$$typeof===void 0?(t.tag=1,t.memoizedState=null,t.updateQueue=null,Te(r)?(o=!0,Cs(t)):o=!1,t.memoizedState=s.state!==null&&s.state!==void 0?s.state:null,va(t),s.updater=qs,t.stateNode=s,s._reactInternals=t,No(t,r,e,n),t=Co(null,t,r,!0,o,n)):(t.tag=0,X&&o&&ua(t),ye(null,t,s,n),t=t.child),t;case 16:r=t.elementType;e:{switch(hs(e,t),e=t.pendingProps,s=r._init,r=s(r._payload),t.type=r,s=t.tag=Fp(r),e=Ke(r,e),s){case 0:t=So(null,t,r,e,n);break e;case 1:t=Bl(null,t,r,e,n);break e;case 11:t=Ul(null,t,r,e,n);break e;case 14:t=Wl(null,t,r,Ke(r.type,e),n);break e}throw Error(T(306,r,""))}return t;case 0:return r=t.type,s=t.pendingProps,s=t.elementType===r?s:Ke(r,s),So(e,t,r,s,n);case 1:return r=t.type,s=t.pendingProps,s=t.elementType===r?s:Ke(r,s),Bl(e,t,r,s,n);case 3:e:{if(yu(t),e===null)throw Error(T(387));r=t.pendingProps,o=t.memoizedState,s=o.element,Hd(e,t),Ds(t,r,null,n);var a=t.memoizedState;if(r=a.element,o.isDehydrated)if(o={element:r,isDehydrated:!1,cache:a.cache,pendingSuspenseBoundaries:a.pendingSuspenseBoundaries,transitions:a.transitions},t.updateQueue.baseState=o,t.memoizedState=o,t.flags&256){s=Ln(Error(T(423)),t),t=Kl(e,t,r,n,s);break e}else if(r!==s){s=Ln(Error(T(424)),t),t=Kl(e,t,r,n,s);break e}else for(De=Tt(t.stateNode.containerInfo.firstChild),Ie=t,X=!0,Ge=null,n=Bd(t,null,r,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if(An(),r===s){t=ht(e,t,n);break e}ye(e,t,r,n)}t=t.child}return t;case 5:return Gd(t),e===null&&wo(t),r=t.type,s=t.pendingProps,o=e!==null?e.memoizedProps:null,a=s.children,fo(r,s)?a=null:o!==null&&fo(r,o)&&(t.flags|=32),vu(e,t),ye(e,t,a,n),t.child;case 6:return e===null&&wo(t),null;case 13:return wu(e,t,n);case 4:return ya(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=zn(t,null,r,n):ye(e,t,r,n),t.child;case 11:return r=t.type,s=t.pendingProps,s=t.elementType===r?s:Ke(r,s),Ul(e,t,r,s,n);case 7:return ye(e,t,t.pendingProps,n),t.child;case 8:return ye(e,t,t.pendingProps.children,n),t.child;case 12:return ye(e,t,t.pendingProps.children,n),t.child;case 10:e:{if(r=t.type._context,s=t.pendingProps,o=t.memoizedProps,a=s.value,H(Ps,r._currentValue),r._currentValue=a,o!==null)if(Ye(o.value,a)){if(o.children===s.children&&!Ee.current){t=ht(e,t,n);break e}}else for(o=t.child,o!==null&&(o.return=t);o!==null;){var l=o.dependencies;if(l!==null){a=o.child;for(var c=l.firstContext;c!==null;){if(c.context===r){if(o.tag===1){c=lt(-1,n&-n),c.tag=2;var d=o.updateQueue;if(d!==null){d=d.shared;var m=d.pending;m===null?c.next=c:(c.next=m.next,m.next=c),d.pending=c}}o.lanes|=n,c=o.alternate,c!==null&&(c.lanes|=n),bo(o.return,n,t),l.lanes|=n;break}c=c.next}}else if(o.tag===10)a=o.type===t.type?null:o.child;else if(o.tag===18){if(a=o.return,a===null)throw Error(T(341));a.lanes|=n,l=a.alternate,l!==null&&(l.lanes|=n),bo(a,n,t),a=o.sibling}else a=o.child;if(a!==null)a.return=o;else for(a=o;a!==null;){if(a===t){a=null;break}if(o=a.sibling,o!==null){o.return=a.return,a=o;break}a=a.return}o=a}ye(e,t,s.children,n),t=t.child}return t;case 9:return s=t.type,r=t.pendingProps.children,Pn(t,n),s=Me(s),r=r(s),t.flags|=1,ye(e,t,r,n),t.child;case 14:return r=t.type,s=Ke(r,t.pendingProps),s=Ke(r.type,s),Wl(e,t,r,s,n);case 15:return gu(e,t,t.type,t.pendingProps,n);case 17:return r=t.type,s=t.pendingProps,s=t.elementType===r?s:Ke(r,s),hs(e,t),t.tag=1,Te(r)?(e=!0,Cs(t)):e=!1,Pn(t,n),mu(t,r,s),No(t,r,s,n),Co(null,t,r,!0,e,n);case 19:return bu(e,t,n);case 22:return xu(e,t,n)}throw Error(T(156,t.tag))};function Ru(e,t){return dd(e,t)}function $p(e,t,n,r){this.tag=e,this.key=n,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 Fe(e,t,n,r){return new $p(e,t,n,r)}function za(e){return e=e.prototype,!(!e||!e.isReactComponent)}function Fp(e){if(typeof e=="function")return za(e)?1:0;if(e!=null){if(e=e.$$typeof,e===qo)return 11;if(e===ea)return 14}return 2}function It(e,t){var n=e.alternate;return n===null?(n=Fe(e.tag,t,e.key,e.mode),n.elementType=e.elementType,n.type=e.type,n.stateNode=e.stateNode,n.alternate=e,e.alternate=n):(n.pendingProps=t,n.type=e.type,n.flags=0,n.subtreeFlags=0,n.deletions=null),n.flags=e.flags&14680064,n.childLanes=e.childLanes,n.lanes=e.lanes,n.child=e.child,n.memoizedProps=e.memoizedProps,n.memoizedState=e.memoizedState,n.updateQueue=e.updateQueue,t=e.dependencies,n.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext},n.sibling=e.sibling,n.index=e.index,n.ref=e.ref,n}function fs(e,t,n,r,s,o){var a=2;if(r=e,typeof e=="function")za(e)&&(a=1);else if(typeof e=="string")a=5;else e:switch(e){case mn:return Qt(n.children,s,o,t);case Qo:a=8,s|=8;break;case Hi:return e=Fe(12,n,t,s|2),e.elementType=Hi,e.lanes=o,e;case Gi:return e=Fe(13,n,t,s),e.elementType=Gi,e.lanes=o,e;case Zi:return e=Fe(19,n,t,s),e.elementType=Zi,e.lanes=o,e;case Gc:return ni(n,s,o,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case Kc:a=10;break e;case Hc:a=9;break e;case qo:a=11;break e;case ea:a=14;break e;case gt:a=16,r=null;break e}throw Error(T(130,e==null?e:typeof e,""))}return t=Fe(a,n,t,s),t.elementType=e,t.type=r,t.lanes=o,t}function Qt(e,t,n,r){return e=Fe(7,e,r,t),e.lanes=n,e}function ni(e,t,n,r){return e=Fe(22,e,r,t),e.elementType=Gc,e.lanes=n,e.stateNode={isHidden:!1},e}function Li(e,t,n){return e=Fe(6,e,null,t),e.lanes=n,e}function Ri(e,t,n){return t=Fe(4,e.children!==null?e.children:[],e.key,t),t.lanes=n,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function Vp(e,t,n,r,s){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=xi(0),this.expirationTimes=xi(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=xi(0),this.identifierPrefix=r,this.onRecoverableError=s,this.mutableSourceEagerHydrationData=null}function Oa(e,t,n,r,s,o,a,l,c){return e=new Vp(e,t,n,l,c),t===1?(t=1,o===!0&&(t|=8)):t=0,o=Fe(3,null,null,t),e.current=o,o.stateNode=e,o.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},va(o),e}function Mp(e,t,n){var r=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(Mu)}catch(e){console.error(e)}}Mu(),Mc.exports=ze;var Hp=Mc.exports,rc=Hp;Bi.createRoot=rc.createRoot,Bi.hydrateRoot=rc.hydrateRoot;var $o=function(e,t){return $o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,r){n.__proto__=r}||function(n,r){for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(n[s]=r[s])},$o(e,t)};function Gp(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");$o(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}var le=function(){return le=Object.assign||function(t){for(var n,r=1,s=arguments.length;r0&&o[o.length-1])&&(d[0]===6||d[0]===2)){n=0;continue}if(d[0]===3&&(!o||d[1]>o[0]&&d[1]0&&b[b.length-1])||y[0]!==6&&y[0]!==2)){j=0;continue}if(y[0]===3&&(!b||y[1]>b[0]&&y[1]0?setTimeout(g,h):g(null)}}window.addEventListener("storage",x),m.addToWaiting(x);var u=setTimeout(x,Math.max(0,p-Date.now()))})];case 1:return f.sent(),[2]}})})},m.addToWaiting=function(p){this.removeFromWaiting(p),m.waiters!==void 0&&m.waiters.push(p)},m.removeFromWaiting=function(p){m.waiters!==void 0&&(m.waiters=m.waiters.filter(function(f){return f!==p}))},m.notifyWaiters=function(){m.waiters!==void 0&&m.waiters.slice().forEach(function(p){return p()})},m.prototype.releaseLock=function(p){return n(this,void 0,void 0,function(){return r(this,function(f){switch(f.label){case 0:return[4,this.releaseLock__private__(p)];case 1:return[2,f.sent()]}})})},m.prototype.releaseLock__private__=function(p){return n(this,void 0,void 0,function(){var f,g,b,w;return r(this,function(j){switch(j.label){case 0:return f=this.storageHandler===void 0?a:this.storageHandler,g=o+"-"+p,(b=f.getItemSync(g))===null?[2]:(w=JSON.parse(b)).id!==this.id?[3,2]:[4,Bt.default().lock(w.iat)];case 1:j.sent(),this.acquiredIatSet.delete(w.iat),f.removeItemSync(g),Bt.default().unlock(w.iat),m.notifyWaiters(),j.label=2;case 2:return[2]}})})},m.lockCorrector=function(p){for(var f=Date.now()-5e3,g=p,b=[],w=0;;){var j=g.keySync(w);if(j===null)break;b.push(j),w++}for(var x=!1,u=0;uDate.now();class te extends Error{constructor(t,n){super(n),this.error=t,this.error_description=n,Object.setPrototypeOf(this,te.prototype)}static fromPayload({error:t,error_description:n}){return new te(t,n)}}class Ma extends te{constructor(t,n,r,s=null){super(t,n),this.state=r,this.appState=s,Object.setPrototypeOf(this,Ma.prototype)}}class Ua extends te{constructor(t,n,r,s,o=null){super(t,n),this.connection=r,this.state=s,this.appState=o,Object.setPrototypeOf(this,Ua.prototype)}}class Dr extends te{constructor(){super("timeout","Timeout"),Object.setPrototypeOf(this,Dr.prototype)}}class Wa extends Dr{constructor(t){super(),this.popup=t,Object.setPrototypeOf(this,Wa.prototype)}}class Ba extends te{constructor(t){super("cancelled","Popup closed"),this.popup=t,Object.setPrototypeOf(this,Ba.prototype)}}class Ka extends te{constructor(t,n,r){super(t,n),this.mfa_token=r,Object.setPrototypeOf(this,Ka.prototype)}}class ai extends te{constructor(t,n){super("missing_refresh_token",`Missing Refresh Token (audience: '${Vs(t,["default"])}', scope: '${Vs(n)}')`),this.audience=t,this.scope=n,Object.setPrototypeOf(this,ai.prototype)}}class Ha extends te{constructor(t,n){super("missing_scopes",`Missing requested scopes after refresh (audience: '${Vs(t,["default"])}', missing scope: '${Vs(n)}')`),this.audience=t,this.scope=n,Object.setPrototypeOf(this,Ha.prototype)}}class li extends te{constructor(t){super("use_dpop_nonce","Server rejected DPoP proof: wrong nonce"),this.newDpopNonce=t,Object.setPrototypeOf(this,li.prototype)}}function Vs(e,t=[]){return e&&!t.includes(e)?e:""}const Ms=()=>window.crypto,Xn=()=>{const e="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_~.";let t="";return Array.from(Ms().getRandomValues(new Uint8Array(43))).forEach(n=>t+=e[n%e.length]),t},$i=e=>btoa(e),Fo=e=>{var{clientId:t}=e,n=et(e,["clientId"]);return new URLSearchParams((r=>Object.keys(r).filter(s=>r[s]!==void 0).reduce((s,o)=>Object.assign(Object.assign({},s),{[o]:r[o]}),{}))(Object.assign({client_id:t},n))).toString()},ic=async e=>await Ms().subtle.digest({name:"SHA-256"},new TextEncoder().encode(e)),oc=e=>(t=>decodeURIComponent(atob(t).split("").map(n=>"%"+("00"+n.charCodeAt(0).toString(16)).slice(-2)).join("")))(e.replace(/_/g,"/").replace(/-/g,"+")),ac=e=>{const t=new Uint8Array(e);return(n=>{const r={"+":"-","/":"_","=":""};return n.replace(/[+/=]/g,s=>r[s])})(window.btoa(String.fromCharCode(...Array.from(t))))},Yp=new TextEncoder,Qp=new TextDecoder;function hr(e){return typeof e=="string"?Yp.encode(e):Qp.decode(e)}function lc(e){if(typeof e.modulusLength!="number"||e.modulusLength<2048)throw new ef(`${e.name} modulusLength must be at least 2048 bits`)}async function qp(e,t,n){if(n.usages.includes("sign")===!1)throw new TypeError('private CryptoKey instances used for signing assertions must include "sign" in their "usages"');const r=`${mr(hr(JSON.stringify(e)))}.${mr(hr(JSON.stringify(t)))}`;return`${r}.${mr(await crypto.subtle.sign(function(s){switch(s.algorithm.name){case"ECDSA":return{name:s.algorithm.name,hash:"SHA-256"};case"RSA-PSS":return lc(s.algorithm),{name:s.algorithm.name,saltLength:32};case"RSASSA-PKCS1-v1_5":return lc(s.algorithm),{name:s.algorithm.name};case"Ed25519":return{name:s.algorithm.name}}throw new Jt}(n),n,hr(r)))}`}let Vo;Uint8Array.prototype.toBase64?Vo=e=>(e instanceof ArrayBuffer&&(e=new Uint8Array(e)),e.toBase64({alphabet:"base64url",omitPadding:!0})):Vo=t=>{t instanceof ArrayBuffer&&(t=new Uint8Array(t));const n=[];for(let r=0;r{const n=await fetch(e,t);return{ok:n.ok,json:await n.json(),headers:(r=n.headers,[...r].reduce((s,[o,a])=>(s[o]=a,s),{}))};var r},cf=async(e,t,n)=>{const r=new AbortController;let s;return t.signal=r.signal,Promise.race([lf(e,t),new Promise((o,a)=>{s=setTimeout(()=>{r.abort(),a(new Error("Timeout when executing 'fetch'"))},n)})]).finally(()=>{clearTimeout(s)})},df=async(e,t,n,r,s,o,a,l)=>{return c={auth:{audience:t,scope:n},timeout:s,fetchUrl:e,fetchOptions:r,useFormData:a,useMrrt:l},d=o,new Promise(function(m,p){const f=new MessageChannel;f.port1.onmessage=function(g){g.data.error?p(new Error(g.data.error)):m(g.data),f.port1.close()},d.postMessage(c,[f.port2])});var c,d},uf=async(e,t,n,r,s,o,a=1e4,l)=>s?df(e,t,n,r,a,s,o,l):cf(e,r,a);async function Gu(e,t,n,r,s,o,a,l,c,d){if(c){const h=await c.generateProof({url:e,method:s.method||"GET",nonce:await c.getNonce()});s.headers=Object.assign(Object.assign({},s.headers),{dpop:h})}let m,p=null;for(let h=0;h<3;h++)try{m=await uf(e,n,r,s,o,a,t,l),p=null;break}catch(y){p=y}if(p)throw p;const f=m.json,{error:g,error_description:b}=f,w=et(f,["error","error_description"]),{headers:j,ok:x}=m;let u;if(c&&(u=j["dpop-nonce"],u&&await c.setNonce(u)),!x){const h=b||`HTTP error. Unable to fetch ${e}`;if(g==="mfa_required")throw new Ka(g,h,w.mfa_token);if(g==="missing_refresh_token")throw new ai(n,r);if(g==="use_dpop_nonce"){if(!c||!u||d)throw new li(u);return Gu(e,t,n,r,s,o,a,l,c,!0)}throw new te(g||"request_error",h)}return w}async function hf(e,t){var{baseUrl:n,timeout:r,audience:s,scope:o,auth0Client:a,useFormData:l,useMrrt:c,dpop:d}=e,m=et(e,["baseUrl","timeout","audience","scope","auth0Client","useFormData","useMrrt","dpop"]);const p=m.grant_type==="urn:ietf:params:oauth:grant-type:token-exchange",f=m.grant_type==="refresh_token"&&c,g=Object.assign(Object.assign(Object.assign(Object.assign({},m),p&&s&&{audience:s}),p&&o&&{scope:o}),f&&{audience:s,scope:o}),b=l?Fo(g):JSON.stringify(g),w=(j=m.grant_type,rf.includes(j));var j;return await Gu(`${n}/oauth/token`,r,s||"default",o,{method:"POST",body:b,headers:{"Content-Type":l?"application/x-www-form-urlencoded":"application/json","Auth0-Client":btoa(JSON.stringify(a||Uu))}},t,l,c,w?d:void 0)}const Yn=(...e)=>{return(t=e.filter(Boolean).join(" ").trim().split(/\s+/),Array.from(new Set(t))).join(" ");var t};class Ze{constructor(t,n="@@auth0spajs@@",r){this.prefix=n,this.suffix=r,this.clientId=t.clientId,this.scope=t.scope,this.audience=t.audience}toKey(){return[this.prefix,this.clientId,this.audience,this.scope,this.suffix].filter(Boolean).join("::")}static fromKey(t){const[n,r,s,o]=t.split("::");return new Ze({clientId:r,scope:o,audience:s},n)}static fromCacheEntry(t){const{scope:n,audience:r,client_id:s}=t;return new Ze({scope:n,audience:r,clientId:s})}}class mf{set(t,n){localStorage.setItem(t,JSON.stringify(n))}get(t){const n=window.localStorage.getItem(t);if(n)try{return JSON.parse(n)}catch{return}}remove(t){localStorage.removeItem(t)}allKeys(){return Object.keys(window.localStorage).filter(t=>t.startsWith("@@auth0spajs@@"))}}class Zu{constructor(){this.enclosedCache=function(){let t={};return{set(n,r){t[n]=r},get(n){const r=t[n];if(r)return r},remove(n){delete t[n]},allKeys:()=>Object.keys(t)}}()}}class pf{constructor(t,n,r){this.cache=t,this.keyManifest=n,this.nowProvider=r||Wu}async setIdToken(t,n,r){var s;const o=this.getIdTokenCacheKey(t);await this.cache.set(o,{id_token:n,decodedToken:r}),await((s=this.keyManifest)===null||s===void 0?void 0:s.add(o))}async getIdToken(t){const n=await this.cache.get(this.getIdTokenCacheKey(t.clientId));if(!n&&t.scope&&t.audience){const r=await this.get(t);return!r||!r.id_token||!r.decodedToken?void 0:{id_token:r.id_token,decodedToken:r.decodedToken}}if(n)return{id_token:n.id_token,decodedToken:n.decodedToken}}async get(t,n=0,r=!1,s){var o;let a=await this.cache.get(t.toKey());if(!a){const d=await this.getCacheKeys();if(!d)return;const m=this.matchExistingCacheKey(t,d);if(m&&(a=await this.cache.get(m)),!m&&r&&s!=="cache-only")return this.getEntryWithRefreshToken(t,d)}if(!a)return;const l=await this.nowProvider(),c=Math.floor(l/1e3);return a.expiresAt-n!t||s.includes(t)).reduce(async(s,o)=>{await s,await this.cache.remove(o)},Promise.resolve()),await((n=this.keyManifest)===null||n===void 0?void 0:n.clear()))}async wrapCacheEntry(t){const n=await this.nowProvider();return{body:t,expiresAt:Math.floor(n/1e3)+t.expires_in}}async getCacheKeys(){var t;return this.keyManifest?(t=await this.keyManifest.get())===null||t===void 0?void 0:t.keys:this.cache.allKeys?this.cache.allKeys():void 0}getIdTokenCacheKey(t){return new Ze({clientId:t},"@@auth0spajs@@","@@user@@").toKey()}matchExistingCacheKey(t,n){return n.filter(r=>{var s;const o=Ze.fromKey(r),a=new Set(o.scope&&o.scope.split(" ")),l=((s=t.scope)===null||s===void 0?void 0:s.split(" "))||[],c=o.scope&&l.reduce((d,m)=>d&&a.has(m),!0);return o.prefix==="@@auth0spajs@@"&&o.clientId===t.clientId&&o.audience===t.audience&&c})[0]}async getEntryWithRefreshToken(t,n){var r;for(const s of n){const o=Ze.fromKey(s);if(o.prefix==="@@auth0spajs@@"&&o.clientId===t.clientId){const a=await this.cache.get(s);if(!((r=a==null?void 0:a.body)===null||r===void 0)&&r.refresh_token)return this.modifiedCachedEntry(a,t)}}}async updateEntry(t,n){var r;const s=await this.getCacheKeys();if(s)for(const o of s){const a=await this.cache.get(o);if(((r=a==null?void 0:a.body)===null||r===void 0?void 0:r.refresh_token)===t){const l=Object.assign(Object.assign({},a.body),{refresh_token:n});await this.set(l)}}}}class ff{constructor(t,n,r){this.storage=t,this.clientId=n,this.cookieDomain=r,this.storageKey=`a0.spajs.txs.${this.clientId}`}create(t){this.storage.save(this.storageKey,t,{daysUntilExpire:1,cookieDomain:this.cookieDomain})}get(){return this.storage.get(this.storageKey)}remove(){this.storage.remove(this.storageKey,{cookieDomain:this.cookieDomain})}}const Qn=e=>typeof e=="number",gf=["iss","aud","exp","nbf","iat","jti","azp","nonce","auth_time","at_hash","c_hash","acr","amr","sub_jwk","cnf","sip_from_tag","sip_date","sip_callid","sip_cseq_num","sip_via_branch","orig","dest","mky","events","toe","txn","rph","sid","vot","vtm"],xf=e=>{if(!e.id_token)throw new Error("ID token is required but missing");const t=(o=>{const a=o.split("."),[l,c,d]=a;if(a.length!==3||!l||!c||!d)throw new Error("ID token could not be decoded");const m=JSON.parse(oc(c)),p={__raw:o},f={};return Object.keys(m).forEach(g=>{p[g]=m[g],gf.includes(g)||(f[g]=m[g])}),{encoded:{header:l,payload:c,signature:d},header:JSON.parse(oc(l)),claims:p,user:f}})(e.id_token);if(!t.claims.iss)throw new Error("Issuer (iss) claim must be a string present in the ID token");if(t.claims.iss!==e.iss)throw new Error(`Issuer (iss) claim mismatch in the ID token; expected "${e.iss}", found "${t.claims.iss}"`);if(!t.user.sub)throw new Error("Subject (sub) claim must be a string present in the ID token");if(t.header.alg!=="RS256")throw new Error(`Signature algorithm of "${t.header.alg}" is not supported. Expected the ID token to be signed with "RS256".`);if(!t.claims.aud||typeof t.claims.aud!="string"&&!Array.isArray(t.claims.aud))throw new Error("Audience (aud) claim must be a string or array of strings present in the ID token");if(Array.isArray(t.claims.aud)){if(!t.claims.aud.includes(e.aud))throw new Error(`Audience (aud) claim mismatch in the ID token; expected "${e.aud}" but was not one of "${t.claims.aud.join(", ")}"`);if(t.claims.aud.length>1){if(!t.claims.azp)throw new Error("Authorized Party (azp) claim must be a string present in the ID token when Audience (aud) claim has multiple values");if(t.claims.azp!==e.aud)throw new Error(`Authorized Party (azp) claim mismatch in the ID token; expected "${e.aud}", found "${t.claims.azp}"`)}}else if(t.claims.aud!==e.aud)throw new Error(`Audience (aud) claim mismatch in the ID token; expected "${e.aud}" but found "${t.claims.aud}"`);if(e.nonce){if(!t.claims.nonce)throw new Error("Nonce (nonce) claim must be a string present in the ID token");if(t.claims.nonce!==e.nonce)throw new Error(`Nonce (nonce) claim mismatch in the ID token; expected "${e.nonce}", found "${t.claims.nonce}"`)}if(e.max_age&&!Qn(t.claims.auth_time))throw new Error("Authentication Time (auth_time) claim must be a number present in the ID token when Max Age (max_age) is specified");if(t.claims.exp==null||!Qn(t.claims.exp))throw new Error("Expiration Time (exp) claim must be a number present in the ID token");if(!Qn(t.claims.iat))throw new Error("Issued At (iat) claim must be a number present in the ID token");const n=e.leeway||60,r=new Date(e.now||Date.now()),s=new Date(0);if(s.setUTCSeconds(t.claims.exp+n),r>s)throw new Error(`Expiration Time (exp) claim error in the ID token; current time (${r}) is after expiration time (${s})`);if(t.claims.nbf!=null&&Qn(t.claims.nbf)){const o=new Date(0);if(o.setUTCSeconds(t.claims.nbf-n),ro)throw new Error(`Authentication Time (auth_time) claim in the ID token indicates that too much time has passed since the last end-user authentication. Current time (${r}) is after last auth at ${o}`)}if(e.organization){const o=e.organization.trim();if(o.startsWith("org_")){const a=o;if(!t.claims.org_id)throw new Error("Organization ID (org_id) claim must be a string present in the ID token");if(a!==t.claims.org_id)throw new Error(`Organization ID (org_id) claim mismatch in the ID token; expected "${a}", found "${t.claims.org_id}"`)}else{const a=o.toLowerCase();if(!t.claims.org_name)throw new Error("Organization Name (org_name) claim must be a string present in the ID token");if(a!==t.claims.org_name)throw new Error(`Organization Name (org_name) claim mismatch in the ID token; expected "${a}", found "${t.claims.org_name}"`)}}return t};var Xt=Va(function(e,t){var n=Kt&&Kt.__assign||function(){return n=Object.assign||function(c){for(var d,m=1,p=arguments.length;m"u")return;const t=sessionStorage.getItem(e);return t!=null?JSON.parse(t):void 0},save(e,t){sessionStorage.setItem(e,JSON.stringify(t))},remove(e){sessionStorage.removeItem(e)}};var bt;(function(e){e.Code="code",e.ConnectCode="connect_code"})(bt||(bt={}));function bf(e,t,n){var r=t===void 0?null:t,s=function(c,d){var m=atob(c);if(d){for(var p=new Uint8Array(m.length),f=0,g=m.length;f0?await this.cache.set(this.manifestKey,{keys:[...r]}):await this.cache.remove(this.manifestKey)}}get(){return this.cache.get(this.manifestKey)}clear(){return this.cache.remove(this.manifestKey)}createManifestKeyFrom(t){return`@@auth0spajs@@::${t}`}}const kf={memory:()=>new Zu().enclosedCache,localstorage:()=>new mf},hc=e=>kf[e],mc=e=>{const{openUrl:t,onRedirect:n}=e,r=et(e,["openUrl","onRedirect"]);return Object.assign(Object.assign({},r),{openUrl:t===!1||t?t:n})},pc=(e,t)=>{const n=(t==null?void 0:t.split(" "))||[];return((e==null?void 0:e.split(" "))||[]).every(r=>n.includes(r))},Mt={NONCE:"nonce",KEYPAIR:"keypair"};class Sf{constructor(t){this.clientId=t}getVersion(){return 1}createDbHandle(){const t=window.indexedDB.open("auth0-spa-js",this.getVersion());return new Promise((n,r)=>{t.onupgradeneeded=()=>Object.values(Mt).forEach(s=>t.result.createObjectStore(s)),t.onerror=()=>r(t.error),t.onsuccess=()=>n(t.result)})}async getDbHandle(){return this.dbHandle||(this.dbHandle=await this.createDbHandle()),this.dbHandle}async executeDbRequest(t,n,r){const s=r((await this.getDbHandle()).transaction(t,n).objectStore(t));return new Promise((o,a)=>{s.onsuccess=()=>o(s.result),s.onerror=()=>a(s.error)})}buildKey(t){const n=t?`_${t}`:"auth0";return`${this.clientId}::${n}`}setNonce(t,n){return this.save(Mt.NONCE,this.buildKey(n),t)}setKeyPair(t){return this.save(Mt.KEYPAIR,this.buildKey(),t)}async save(t,n,r){await this.executeDbRequest(t,"readwrite",s=>s.put(r,n))}findNonce(t){return this.find(Mt.NONCE,this.buildKey(t))}findKeyPair(){return this.find(Mt.KEYPAIR,this.buildKey())}find(t,n){return this.executeDbRequest(t,"readonly",r=>r.get(n))}async deleteBy(t,n){const r=await this.executeDbRequest(t,"readonly",s=>s.getAllKeys());r==null||r.filter(n).map(s=>this.executeDbRequest(t,"readwrite",o=>o.delete(s)))}deleteByClientId(t,n){return this.deleteBy(t,r=>typeof r=="string"&&r.startsWith(`${n}::`))}clearNonces(){return this.deleteByClientId(Mt.NONCE,this.clientId)}clearKeyPairs(){return this.deleteByClientId(Mt.KEYPAIR,this.clientId)}}class Cf{constructor(t){this.storage=new Sf(t)}getNonce(t){return this.storage.findNonce(t)}setNonce(t,n){return this.storage.setNonce(t,n)}async getOrGenerateKeyPair(){let t=await this.storage.findKeyPair();return t||(t=await sf(),await this.storage.setKeyPair(t)),t}async generateProof(t){const n=await this.getOrGenerateKeyPair();return af(Object.assign({keyPair:n},t))}async calculateThumbprint(){return of(await this.getOrGenerateKeyPair())}async clear(){await Promise.all([this.storage.clearNonces(),this.storage.clearKeyPairs()])}}var kn;(function(e){e.Bearer="Bearer",e.DPoP="DPoP"})(kn||(kn={}));class Ef{constructor(t,n){this.hooks=n,this.config=Object.assign(Object.assign({},t),{fetch:t.fetch||(typeof window>"u"?fetch:window.fetch.bind(window))})}isAbsoluteUrl(t){return/^(https?:)?\/\//i.test(t)}buildUrl(t,n){if(n){if(this.isAbsoluteUrl(n))return n;if(t)return`${t.replace(/\/?\/$/,"")}/${n.replace(/^\/+/,"")}`}throw new TypeError("`url` must be absolute or `baseUrl` non-empty.")}getAccessToken(t){return this.config.getAccessToken?this.config.getAccessToken(t):this.hooks.getAccessToken(t)}extractUrl(t){return typeof t=="string"?t:t instanceof URL?t.href:t.url}buildBaseRequest(t,n){if(!this.config.baseUrl)return new Request(t,n);const r=this.buildUrl(this.config.baseUrl,this.extractUrl(t)),s=t instanceof Request?new Request(r,t):r;return new Request(s,n)}setAuthorizationHeader(t,n,r=kn.Bearer){t.headers.set("authorization",`${r} ${n}`)}async setDpopProofHeader(t,n){if(!this.config.dpopNonceId)return;const r=await this.hooks.getDpopNonce(),s=await this.hooks.generateDpopProof({accessToken:n,method:t.method,nonce:r,url:t.url});t.headers.set("dpop",s)}async prepareRequest(t,n){const r=await this.getAccessToken(n);let s,o;typeof r=="string"?(s=this.config.dpopNonceId?kn.DPoP:kn.Bearer,o=r):(s=r.token_type,o=r.access_token),this.setAuthorizationHeader(t,o,s),s===kn.DPoP&&await this.setDpopProofHeader(t,o)}getHeader(t,n){return Array.isArray(t)?new Headers(t).get(n)||"":typeof t.get=="function"?t.get(n)||"":t[n]||""}hasUseDpopNonceError(t){if(t.status!==401)return!1;const n=this.getHeader(t.headers,"www-authenticate");return n.includes("invalid_dpop_nonce")||n.includes("use_dpop_nonce")}async handleResponse(t,n){const r=this.getHeader(t.headers,"dpop-nonce");if(r&&await this.hooks.setDpopNonce(r),!this.hasUseDpopNonceError(t))return t;if(!r||!n.onUseDpopNonceError)throw new li(r);return n.onUseDpopNonceError()}async internalFetchWithAuth(t,n,r,s){const o=this.buildBaseRequest(t,n);await this.prepareRequest(o,s);const a=await this.config.fetch(o);return this.handleResponse(a,r)}fetchWithAuth(t,n,r){const s={onUseDpopNonceError:()=>this.internalFetchWithAuth(t,n,Object.assign(Object.assign({},s),{onUseDpopNonceError:void 0}),r)};return this.internalFetchWithAuth(t,n,s,r)}}class Tf{constructor(t,n){this.myAccountFetcher=t,this.apiBase=n}async connectAccount(t){const n=await this.myAccountFetcher.fetchWithAuth(`${this.apiBase}v1/connected-accounts/connect`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});return this._handleResponse(n)}async completeAccount(t){const n=await this.myAccountFetcher.fetchWithAuth(`${this.apiBase}v1/connected-accounts/complete`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});return this._handleResponse(n)}async _handleResponse(t){let n;try{n=await t.text(),n=JSON.parse(n)}catch(r){throw new Us({type:"invalid_json",status:t.status,title:"Invalid JSON response",detail:n||String(r)})}if(t.ok)return n;throw new Us(n)}}class Us extends Error{constructor({type:t,status:n,title:r,detail:s,validation_errors:o}){super(s),this.name="MyAccountApiError",this.type=t,this.status=n,this.title=r,this.detail=s,this.validation_errors=o,Object.setPrototypeOf(this,Us.prototype)}}const Mi=new Jp;class Pf{constructor(t){let n,r;if(this.userCache=new Zu().enclosedCache,this.defaultOptions={authorizationParams:{scope:"openid profile email"},useRefreshTokensFallback:!1,useFormData:!0},this._releaseLockOnPageHide=async()=>{await Mi.releaseLock("auth0.lock.getTokenSilently"),window.removeEventListener("pagehide",this._releaseLockOnPageHide)},this.options=Object.assign(Object.assign(Object.assign({},this.defaultOptions),t),{authorizationParams:Object.assign(Object.assign({},this.defaultOptions.authorizationParams),t.authorizationParams)}),typeof window<"u"&&(()=>{if(!Ms())throw new Error("For security reasons, `window.crypto` is required to run `auth0-spa-js`.");if(Ms().subtle===void 0)throw new Error(` auth0-spa-js must run on a secure origin. See https://github.com/auth0/auth0-spa-js/blob/main/FAQ.md#why-do-i-get-auth0-spa-js-must-run-on-a-secure-origin for more information. `)})(),t.cache&&t.cacheLocation&&console.warn("Both `cache` and `cacheLocation` options have been specified in the Auth0Client configuration; ignoring `cacheLocation` and using `cache`."),t.cache)r=t.cache;else{if(n=t.cacheLocation||"memory",!hc(n))throw new Error(`Invalid cache location "${n}"`);r=hc(n)()}this.httpTimeoutMs=t.httpTimeoutInSeconds?1e3*t.httpTimeoutInSeconds:1e4,this.cookieStorage=t.legacySameSiteCookie===!1?un:yf,this.orgHintCookieName=`auth0.${this.options.clientId}.organization_hint`,this.isAuthenticatedCookieName=(c=>`auth0.${c}.is.authenticated`)(this.options.clientId),this.sessionCheckExpiryDays=t.sessionCheckExpiryDays||1;const s=t.useCookiesForTransactions?this.cookieStorage:wf;var o;this.scope=Yn("openid",this.options.authorizationParams.scope,this.options.useRefreshTokens?"offline_access":""),this.transactionManager=new ff(s,this.options.clientId,this.options.cookieDomain),this.nowProvider=this.options.nowProvider||Wu,this.cacheManager=new pf(r,r.allKeys?void 0:new Nf(r,this.options.clientId),this.nowProvider),this.dpop=this.options.useDpop?new Cf(this.options.clientId):void 0,this.domainUrl=(o=this.options.domain,/^https?:\/\//.test(o)?o:`https://${o}`),this.tokenIssuer=((c,d)=>c?c.startsWith("https://")?c:`https://${c}/`:`${d}/`)(this.options.issuer,this.domainUrl);const a=`${this.domainUrl}/me/`,l=this.createFetcher(Object.assign(Object.assign({},this.options.useDpop&&{dpopNonceId:"__auth0_my_account_api__"}),{getAccessToken:()=>this.getTokenSilently({authorizationParams:{scope:"create:me:connected_accounts",audience:a},detailedResponse:!0})}));this.myAccountApi=new Tf(l,a),typeof window<"u"&&window.Worker&&this.options.useRefreshTokens&&n==="memory"&&(this.options.workerUrl?this.worker=new Worker(this.options.workerUrl):this.worker=new jf)}_url(t){const n=encodeURIComponent(btoa(JSON.stringify(this.options.auth0Client||Uu)));return`${this.domainUrl}${t}&auth0Client=${n}`}_authorizeUrl(t){return this._url(`/authorize?${Fo(t)}`)}async _verifyIdToken(t,n,r){const s=await this.nowProvider();return xf({iss:this.tokenIssuer,aud:this.options.clientId,id_token:t,nonce:n,organization:r,leeway:this.options.leeway,max_age:(o=this.options.authorizationParams.max_age,typeof o!="string"?o:parseInt(o,10)||void 0),now:s});var o}_processOrgHint(t){t?this.cookieStorage.save(this.orgHintCookieName,t,{daysUntilExpire:this.sessionCheckExpiryDays,cookieDomain:this.options.cookieDomain}):this.cookieStorage.remove(this.orgHintCookieName,{cookieDomain:this.options.cookieDomain})}async _prepareAuthorizeUrl(t,n,r){var s;const o=$i(Xn()),a=$i(Xn()),l=Xn(),c=await ic(l),d=ac(c),m=await((s=this.dpop)===null||s===void 0?void 0:s.calculateThumbprint()),p=((g,b,w,j,x,u,h,y,v)=>Object.assign(Object.assign(Object.assign({client_id:g.clientId},g.authorizationParams),w),{scope:Yn(b,w.scope),response_type:"code",response_mode:y||"query",state:j,nonce:x,redirect_uri:h||g.authorizationParams.redirect_uri,code_challenge:u,code_challenge_method:"S256",dpop_jkt:v}))(this.options,this.scope,t,o,a,d,t.redirect_uri||this.options.authorizationParams.redirect_uri||r,n==null?void 0:n.response_mode,m),f=this._authorizeUrl(p);return{nonce:a,code_verifier:l,scope:p.scope,audience:p.audience||"default",redirect_uri:p.redirect_uri,state:o,url:f}}async loginWithPopup(t,n){var r;if(t=t||{},!(n=n||{}).popup&&(n.popup=(l=>{const c=window.screenX+(window.innerWidth-400)/2,d=window.screenY+(window.innerHeight-600)/2;return window.open(l,"auth0:authorize:popup",`left=${c},top=${d},width=400,height=600,resizable,scrollbars=yes,status=1`)})(""),!n.popup))throw new Error("Unable to open a popup for loginWithPopup - window.open returned `null`");const s=await this._prepareAuthorizeUrl(t.authorizationParams||{},{response_mode:"web_message"},window.location.origin);n.popup.location.href=s.url;const o=await(l=>new Promise((c,d)=>{let m;const p=setInterval(()=>{l.popup&&l.popup.closed&&(clearInterval(p),clearTimeout(f),window.removeEventListener("message",m,!1),d(new Ba(l.popup)))},1e3),f=setTimeout(()=>{clearInterval(p),d(new Wa(l.popup)),window.removeEventListener("message",m,!1)},1e3*(l.timeoutInSeconds||60));m=function(g){if(g.data&&g.data.type==="authorization_response"){if(clearTimeout(f),clearInterval(p),window.removeEventListener("message",m,!1),l.popup.close(),g.data.response.error)return d(te.fromPayload(g.data.response));c(g.data.response)}},window.addEventListener("message",m)}))(Object.assign(Object.assign({},n),{timeoutInSeconds:n.timeoutInSeconds||this.options.authorizeTimeoutInSeconds||60}));if(s.state!==o.state)throw new te("state_mismatch","Invalid state");const a=((r=t.authorizationParams)===null||r===void 0?void 0:r.organization)||this.options.authorizationParams.organization;await this._requestToken({audience:s.audience,scope:s.scope,code_verifier:s.code_verifier,grant_type:"authorization_code",code:o.code,redirect_uri:s.redirect_uri},{nonceIn:s.nonce,organization:a})}async getUser(){var t;const n=await this._getIdTokenFromCache();return(t=n==null?void 0:n.decodedToken)===null||t===void 0?void 0:t.user}async getIdTokenClaims(){var t;const n=await this._getIdTokenFromCache();return(t=n==null?void 0:n.decodedToken)===null||t===void 0?void 0:t.claims}async loginWithRedirect(t={}){var n;const r=mc(t),{openUrl:s,fragment:o,appState:a}=r,l=et(r,["openUrl","fragment","appState"]),c=((n=l.authorizationParams)===null||n===void 0?void 0:n.organization)||this.options.authorizationParams.organization,d=await this._prepareAuthorizeUrl(l.authorizationParams||{}),{url:m}=d,p=et(d,["url"]);this.transactionManager.create(Object.assign(Object.assign(Object.assign({},p),{appState:a,response_type:bt.Code}),c&&{organization:c}));const f=o?`${m}#${o}`:m;s?await s(f):window.location.assign(f)}async handleRedirectCallback(t=window.location.href){const n=t.split("?").slice(1);if(n.length===0)throw new Error("There are no query params available for parsing.");const r=this.transactionManager.get();if(!r)throw new te("missing_transaction","Invalid state");this.transactionManager.remove();const s=(o=>{o.indexOf("#")>-1&&(o=o.substring(0,o.indexOf("#")));const a=new URLSearchParams(o);return{state:a.get("state"),code:a.get("code")||void 0,connect_code:a.get("connect_code")||void 0,error:a.get("error")||void 0,error_description:a.get("error_description")||void 0}})(n.join(""));return r.response_type===bt.ConnectCode?this._handleConnectAccountRedirectCallback(s,r):this._handleLoginRedirectCallback(s,r)}async _handleLoginRedirectCallback(t,n){const{code:r,state:s,error:o,error_description:a}=t;if(o)throw new Ma(o,a||o,s,n.appState);if(!n.code_verifier||n.state&&n.state!==s)throw new te("state_mismatch","Invalid state");const l=n.organization,c=n.nonce,d=n.redirect_uri;return await this._requestToken(Object.assign({audience:n.audience,scope:n.scope,code_verifier:n.code_verifier,grant_type:"authorization_code",code:r},d?{redirect_uri:d}:{}),{nonceIn:c,organization:l}),{appState:n.appState,response_type:bt.Code}}async _handleConnectAccountRedirectCallback(t,n){const{connect_code:r,state:s,error:o,error_description:a}=t;if(o)throw new Ua(o,a||o,n.connection,s,n.appState);if(!r)throw new te("missing_connect_code","Missing connect code");if(!(n.code_verifier&&n.state&&n.auth_session&&n.redirect_uri&&n.state===s))throw new te("state_mismatch","Invalid state");const l=await this.myAccountApi.completeAccount({auth_session:n.auth_session,connect_code:r,redirect_uri:n.redirect_uri,code_verifier:n.code_verifier});return Object.assign(Object.assign({},l),{appState:n.appState,response_type:bt.ConnectCode})}async checkSession(t){if(!this.cookieStorage.get(this.isAuthenticatedCookieName)){if(!this.cookieStorage.get("auth0.is.authenticated"))return;this.cookieStorage.save(this.isAuthenticatedCookieName,!0,{daysUntilExpire:this.sessionCheckExpiryDays,cookieDomain:this.options.cookieDomain}),this.cookieStorage.remove("auth0.is.authenticated")}try{await this.getTokenSilently(t)}catch{}}async getTokenSilently(t={}){var n;const r=Object.assign(Object.assign({cacheMode:"on"},t),{authorizationParams:Object.assign(Object.assign(Object.assign({},this.options.authorizationParams),t.authorizationParams),{scope:Yn(this.scope,(n=t.authorizationParams)===null||n===void 0?void 0:n.scope)})}),s=await((o,a)=>{let l=Vi[a];return l||(l=o().finally(()=>{delete Vi[a],l=null}),Vi[a]=l),l})(()=>this._getTokenSilently(r),`${this.options.clientId}::${r.authorizationParams.audience}::${r.authorizationParams.scope}`);return t.detailedResponse?s:s==null?void 0:s.access_token}async _getTokenSilently(t){const{cacheMode:n}=t,r=et(t,["cacheMode"]);if(n!=="off"){const s=await this._getEntryFromCache({scope:r.authorizationParams.scope,audience:r.authorizationParams.audience||"default",clientId:this.options.clientId,cacheMode:n});if(s)return s}if(n!=="cache-only"){if(!await(async(s,o=3)=>{for(let a=0;aMi.acquireLock("auth0.lock.getTokenSilently",5e3),10))throw new Dr;try{if(window.addEventListener("pagehide",this._releaseLockOnPageHide),n!=="off"){const m=await this._getEntryFromCache({scope:r.authorizationParams.scope,audience:r.authorizationParams.audience||"default",clientId:this.options.clientId});if(m)return m}const s=this.options.useRefreshTokens?await this._getTokenUsingRefreshToken(r):await this._getTokenFromIFrame(r),{id_token:o,token_type:a,access_token:l,oauthTokenScope:c,expires_in:d}=s;return Object.assign(Object.assign({id_token:o,token_type:a,access_token:l},c?{scope:c}:null),{expires_in:d})}finally{await Mi.releaseLock("auth0.lock.getTokenSilently"),window.removeEventListener("pagehide",this._releaseLockOnPageHide)}}}async getTokenWithPopup(t={},n={}){var r;const s=Object.assign(Object.assign({},t),{authorizationParams:Object.assign(Object.assign(Object.assign({},this.options.authorizationParams),t.authorizationParams),{scope:Yn(this.scope,(r=t.authorizationParams)===null||r===void 0?void 0:r.scope)})});return n=Object.assign(Object.assign({},Xp),n),await this.loginWithPopup(s,n),(await this.cacheManager.get(new Ze({scope:s.authorizationParams.scope,audience:s.authorizationParams.audience||"default",clientId:this.options.clientId}),void 0,this.options.useMrrt)).access_token}async isAuthenticated(){return!!await this.getUser()}_buildLogoutUrl(t){t.clientId!==null?t.clientId=t.clientId||this.options.clientId:delete t.clientId;const n=t.logoutParams||{},{federated:r}=n,s=et(n,["federated"]),o=r?"&federated":"";return this._url(`/v2/logout?${Fo(Object.assign({clientId:t.clientId},s))}`)+o}async logout(t={}){var n;const r=mc(t),{openUrl:s}=r,o=et(r,["openUrl"]);t.clientId===null?await this.cacheManager.clear():await this.cacheManager.clear(t.clientId||this.options.clientId),this.cookieStorage.remove(this.orgHintCookieName,{cookieDomain:this.options.cookieDomain}),this.cookieStorage.remove(this.isAuthenticatedCookieName,{cookieDomain:this.options.cookieDomain}),this.userCache.remove("@@user@@"),await((n=this.dpop)===null||n===void 0?void 0:n.clear());const a=this._buildLogoutUrl(o);s?await s(a):s!==!1&&window.location.assign(a)}async _getTokenFromIFrame(t){const n=Object.assign(Object.assign({},t.authorizationParams),{prompt:"none"}),r=this.cookieStorage.get(this.orgHintCookieName);r&&!n.organization&&(n.organization=r);const{url:s,state:o,nonce:a,code_verifier:l,redirect_uri:c,scope:d,audience:m}=await this._prepareAuthorizeUrl(n,{response_mode:"web_message"},window.location.origin);try{if(window.crossOriginIsolated)throw new te("login_required","The application is running in a Cross-Origin Isolated context, silently retrieving a token without refresh token is not possible.");const p=t.timeoutInSeconds||this.options.authorizeTimeoutInSeconds;let f;try{f=new URL(this.domainUrl).origin}catch{f=this.domainUrl}const g=await((w,j,x=60)=>new Promise((u,h)=>{const y=window.document.createElement("iframe");y.setAttribute("width","0"),y.setAttribute("height","0"),y.style.display="none";const v=()=>{window.document.body.contains(y)&&(window.document.body.removeChild(y),window.removeEventListener("message",N,!1))};let N;const k=setTimeout(()=>{h(new Dr),v()},1e3*x);N=function(C){if(C.origin!=j||!C.data||C.data.type!=="authorization_response")return;const z=C.source;z&&z.close(),C.data.response.error?h(te.fromPayload(C.data.response)):u(C.data.response),clearTimeout(k),window.removeEventListener("message",N,!1),setTimeout(v,2e3)},window.addEventListener("message",N,!1),window.document.body.appendChild(y),y.setAttribute("src",w)}))(s,f,p);if(o!==g.state)throw new te("state_mismatch","Invalid state");const b=await this._requestToken(Object.assign(Object.assign({},t.authorizationParams),{code_verifier:l,code:g.code,grant_type:"authorization_code",redirect_uri:c,timeout:t.authorizationParams.timeout||this.httpTimeoutMs}),{nonceIn:a,organization:n.organization});return Object.assign(Object.assign({},b),{scope:d,oauthTokenScope:b.scope,audience:m})}catch(p){throw p.error==="login_required"&&this.logout({openUrl:!1}),p}}async _getTokenUsingRefreshToken(t){const n=await this.cacheManager.get(new Ze({scope:t.authorizationParams.scope,audience:t.authorizationParams.audience||"default",clientId:this.options.clientId}),void 0,this.options.useMrrt);if(!(n&&n.refresh_token||this.worker)){if(this.options.useRefreshTokensFallback)return await this._getTokenFromIFrame(t);throw new ai(t.authorizationParams.audience||"default",t.authorizationParams.scope)}const r=t.authorizationParams.redirect_uri||this.options.authorizationParams.redirect_uri||window.location.origin,s=typeof t.timeoutInSeconds=="number"?1e3*t.timeoutInSeconds:null,o=((m,p,f,g)=>{var b;if(m&&f&&g){if(p.audience!==f)return p.scope;const w=g.split(" "),j=((b=p.scope)===null||b===void 0?void 0:b.split(" "))||[],x=j.every(u=>w.includes(u));return w.length>=j.length&&x?g:p.scope}return p.scope})(this.options.useMrrt,t.authorizationParams,n==null?void 0:n.audience,n==null?void 0:n.scope);try{const m=await this._requestToken(Object.assign(Object.assign(Object.assign({},t.authorizationParams),{grant_type:"refresh_token",refresh_token:n&&n.refresh_token,redirect_uri:r}),s&&{timeout:s}),{scopesToRequest:o});if(m.refresh_token&&this.options.useMrrt&&(n!=null&&n.refresh_token)&&await this.cacheManager.updateEntry(n.refresh_token,m.refresh_token),this.options.useMrrt&&(a=n==null?void 0:n.audience,l=n==null?void 0:n.scope,c=t.authorizationParams.audience,d=t.authorizationParams.scope,(a!==c||!pc(d,l))&&!pc(o,m.scope))){if(this.options.useRefreshTokensFallback)return await this._getTokenFromIFrame(t);const p=((f,g)=>{const b=(f==null?void 0:f.split(" "))||[],w=(g==null?void 0:g.split(" "))||[];return b.filter(j=>w.indexOf(j)==-1).join(",")})(o,m.scope);throw new Ha(t.authorizationParams.audience||"default",p)}return Object.assign(Object.assign({},m),{scope:t.authorizationParams.scope,oauthTokenScope:m.scope,audience:t.authorizationParams.audience||"default"})}catch(m){if((m.message.indexOf("Missing Refresh Token")>-1||m.message&&m.message.indexOf("invalid refresh token")>-1)&&this.options.useRefreshTokensFallback)return await this._getTokenFromIFrame(t);throw m}var a,l,c,d}async _saveEntryInCache(t){const{id_token:n,decodedToken:r}=t,s=et(t,["id_token","decodedToken"]);this.userCache.set("@@user@@",{id_token:n,decodedToken:r}),await this.cacheManager.setIdToken(this.options.clientId,t.id_token,t.decodedToken),await this.cacheManager.set(s)}async _getIdTokenFromCache(){const t=this.options.authorizationParams.audience||"default",n=await this.cacheManager.getIdToken(new Ze({clientId:this.options.clientId,audience:t,scope:this.scope})),r=this.userCache.get("@@user@@");return n&&n.id_token===(r==null?void 0:r.id_token)?r:(this.userCache.set("@@user@@",n),n)}async _getEntryFromCache({scope:t,audience:n,clientId:r,cacheMode:s}){const o=await this.cacheManager.get(new Ze({scope:t,audience:n,clientId:r}),60,this.options.useMrrt,s);if(o&&o.access_token){const{token_type:a,access_token:l,oauthTokenScope:c,expires_in:d}=o,m=await this._getIdTokenFromCache();return m&&Object.assign(Object.assign({id_token:m.id_token,token_type:a||"Bearer",access_token:l},c?{scope:c}:null),{expires_in:d})}}async _requestToken(t,n){const{nonceIn:r,organization:s,scopesToRequest:o}=n||{},a=await hf(Object.assign(Object.assign({baseUrl:this.domainUrl,client_id:this.options.clientId,auth0Client:this.options.auth0Client,useFormData:this.options.useFormData,timeout:this.httpTimeoutMs,useMrrt:this.options.useMrrt,dpop:this.dpop},t),{scope:o||t.scope}),this.worker),l=await this._verifyIdToken(a.id_token,r,s);return await this._saveEntryInCache(Object.assign(Object.assign(Object.assign(Object.assign({},a),{decodedToken:l,scope:t.scope,audience:t.audience||"default"}),a.scope?{oauthTokenScope:a.scope}:null),{client_id:this.options.clientId})),this.cookieStorage.save(this.isAuthenticatedCookieName,!0,{daysUntilExpire:this.sessionCheckExpiryDays,cookieDomain:this.options.cookieDomain}),this._processOrgHint(s||l.claims.org_id),Object.assign(Object.assign({},a),{decodedToken:l})}async exchangeToken(t){return this._requestToken({grant_type:"urn:ietf:params:oauth:grant-type:token-exchange",subject_token:t.subject_token,subject_token_type:t.subject_token_type,scope:Yn(t.scope,this.scope),audience:t.audience||this.options.authorizationParams.audience})}_assertDpop(t){if(!t)throw new Error("`useDpop` option must be enabled before using DPoP.")}getDpopNonce(t){return this._assertDpop(this.dpop),this.dpop.getNonce(t)}setDpopNonce(t,n){return this._assertDpop(this.dpop),this.dpop.setNonce(t,n)}generateDpopProof(t){return this._assertDpop(this.dpop),this.dpop.generateProof(t)}createFetcher(t={}){return new Ef(t,{isDpopEnabled:()=>!!this.options.useDpop,getAccessToken:n=>{var r;return this.getTokenSilently({authorizationParams:{scope:(r=n==null?void 0:n.scope)===null||r===void 0?void 0:r.join(" "),audience:n==null?void 0:n.audience},detailedResponse:!0})},getDpopNonce:()=>this.getDpopNonce(t.dpopNonceId),setDpopNonce:n=>this.setDpopNonce(n,t.dpopNonceId),generateDpopProof:n=>this.generateDpopProof(n)})}async connectAccountWithRedirect(t){const{openUrl:n,appState:r,connection:s,authorization_params:o,redirectUri:a=this.options.authorizationParams.redirect_uri||window.location.origin}=t;if(!s)throw new Error("connection is required");const l=$i(Xn()),c=Xn(),d=await ic(c),m=ac(d),{connect_uri:p,connect_params:f,auth_session:g}=await this.myAccountApi.connectAccount({connection:s,redirect_uri:a,state:l,code_challenge:m,code_challenge_method:"S256",authorization_params:o});this.transactionManager.create({state:l,code_verifier:c,auth_session:g,redirect_uri:a,appState:r,connection:s,response_type:bt.ConnectCode});const b=new URL(p);b.searchParams.set("ticket",f.ticket),n?await n(b.toString()):window.location.assign(b)}}var Yu={isAuthenticated:!1,isLoading:!0,error:void 0,user:void 0},ke=function(){throw new Error("You forgot to wrap your component in .")},_f=le(le({},Yu),{buildAuthorizeUrl:ke,buildLogoutUrl:ke,getAccessTokenSilently:ke,getAccessTokenWithPopup:ke,getIdTokenClaims:ke,loginWithRedirect:ke,loginWithPopup:ke,connectAccountWithRedirect:ke,logout:ke,handleRedirectCallback:ke,getDpopNonce:ke,setDpopNonce:ke,generateDpopProof:ke,createFetcher:ke}),Qu=S.createContext(_f),fc=function(e){Gp(t,e);function t(n,r){var s=e.call(this,r??n)||this;return s.error=n,s.error_description=r,Object.setPrototypeOf(s,t.prototype),s}return t}(Error),Df=/[?&](?:connect_)?code=[^&]+/,If=/[?&]state=[^&]+/,Af=/[?&]error=[^&]+/,zf=function(e){return e===void 0&&(e=window.location.search),(Df.test(e)||Af.test(e))&&If.test(e)},qu=function(e){return function(t){if(t instanceof Error)return t;if(t!==null&&typeof t=="object"&&"error"in t&&typeof t.error=="string"){if("error_description"in t&&typeof t.error_description=="string"){var n=t;return new fc(n.error,n.error_description)}var r=t;return new fc(r.error)}return new Error(e)}},gc=qu("Login failed"),Ui=qu("Get access token failed"),eh=function(e){var t,n;e!=null&&e.redirectUri&&(console.warn("Using `redirectUri` has been deprecated, please use `authorizationParams.redirect_uri` instead as `redirectUri` will be no longer supported in a future version"),e.authorizationParams=(t=e.authorizationParams)!==null&&t!==void 0?t:{},e.authorizationParams.redirect_uri=e.redirectUri,delete e.redirectUri),!((n=e==null?void 0:e.authorizationParams)===null||n===void 0)&&n.redirectUri&&(console.warn("Using `authorizationParams.redirectUri` has been deprecated, please use `authorizationParams.redirect_uri` instead as `authorizationParams.redirectUri` will be removed in a future version"),e.authorizationParams.redirect_uri=e.authorizationParams.redirectUri,delete e.authorizationParams.redirectUri)},Of=function(e,t){switch(t.type){case"LOGIN_POPUP_STARTED":return le(le({},e),{isLoading:!0});case"LOGIN_POPUP_COMPLETE":case"INITIALISED":return le(le({},e),{isAuthenticated:!!t.user,user:t.user,isLoading:!1,error:void 0});case"HANDLE_REDIRECT_COMPLETE":case"GET_ACCESS_TOKEN_COMPLETE":return e.user===t.user?e:le(le({},e),{isAuthenticated:!!t.user,user:t.user});case"LOGOUT":return le(le({},e),{isAuthenticated:!1,user:void 0});case"ERROR":return le(le({},e),{isLoading:!1,error:t.error})}},Lf=function(e){return eh(e),le(le({},e),{auth0Client:{name:"auth0-react",version:"2.8.0"}})},Rf=function(e){var t;window.history.replaceState({},document.title,(t=e.returnTo)!==null&&t!==void 0?t:window.location.pathname)},$f=function(e){var t=e.children,n=e.skipRedirectCallback,r=e.onRedirectCallback,s=r===void 0?Rf:r,o=e.context,a=o===void 0?Qu:o,l=sc(e,["children","skipRedirectCallback","onRedirectCallback","context"]),c=S.useState(function(){return new Pf(Lf(l))})[0],d=S.useReducer(Of,Yu),m=d[0],p=d[1],f=S.useRef(!1),g=S.useCallback(function(I){return p({type:"ERROR",error:I}),I},[]);S.useEffect(function(){f.current||(f.current=!0,function(){return cn(void 0,void 0,void 0,function(){var I,M,W,G,K,P,L;return dn(this,function(E){switch(E.label){case 0:return E.trys.push([0,7,,8]),I=void 0,zf()&&!n?[4,c.handleRedirectCallback()]:[3,3];case 1:return M=E.sent(),W=M.appState,G=W===void 0?{}:W,K=M.response_type,P=sc(M,["appState","response_type"]),[4,c.getUser()];case 2:return I=E.sent(),G.response_type=K,K===bt.ConnectCode&&(G.connectedAccount=P),s(G,I),[3,6];case 3:return[4,c.checkSession()];case 4:return E.sent(),[4,c.getUser()];case 5:I=E.sent(),E.label=6;case 6:return p({type:"INITIALISED",user:I}),[3,8];case 7:return L=E.sent(),g(gc(L)),[3,8];case 8:return[2]}})})}())},[c,s,n,g]);var b=S.useCallback(function(I){return eh(I),c.loginWithRedirect(I)},[c]),w=S.useCallback(function(I,M){return cn(void 0,void 0,void 0,function(){var W,G;return dn(this,function(K){switch(K.label){case 0:p({type:"LOGIN_POPUP_STARTED"}),K.label=1;case 1:return K.trys.push([1,3,,4]),[4,c.loginWithPopup(I,M)];case 2:return K.sent(),[3,4];case 3:return W=K.sent(),g(gc(W)),[2];case 4:return[4,c.getUser()];case 5:return G=K.sent(),p({type:"LOGIN_POPUP_COMPLETE",user:G}),[2]}})})},[c,g]),j=S.useCallback(function(){for(var I=[],M=0;M"u")throw new Error(t)}function th(e,t){if(!e){typeof console<"u"&&console.warn(t);try{throw new Error(t)}catch{}}}function Mf(){return Math.random().toString(36).substr(2,8)}function vc(e,t){return{usr:e.state,key:e.key,idx:t}}function Mo(e,t,n,r){return n===void 0&&(n=null),Ir({pathname:typeof e=="string"?e:e.pathname,search:"",hash:""},typeof t=="string"?Mn(t):t,{state:n,key:t&&t.key||r||Mf()})}function Ws(e){let{pathname:t="/",search:n="",hash:r=""}=e;return n&&n!=="?"&&(t+=n.charAt(0)==="?"?n:"?"+n),r&&r!=="#"&&(t+=r.charAt(0)==="#"?r:"#"+r),t}function Mn(e){let t={};if(e){let n=e.indexOf("#");n>=0&&(t.hash=e.substr(n),e=e.substr(0,n));let r=e.indexOf("?");r>=0&&(t.search=e.substr(r),e=e.substr(0,r)),e&&(t.pathname=e)}return t}function Uf(e,t,n,r){r===void 0&&(r={});let{window:s=document.defaultView,v5Compat:o=!1}=r,a=s.history,l=kt.Pop,c=null,d=m();d==null&&(d=0,a.replaceState(Ir({},a.state,{idx:d}),""));function m(){return(a.state||{idx:null}).idx}function p(){l=kt.Pop;let j=m(),x=j==null?null:j-d;d=j,c&&c({action:l,location:w.location,delta:x})}function f(j,x){l=kt.Push;let u=Mo(w.location,j,x);n&&n(u,j),d=m()+1;let h=vc(u,d),y=w.createHref(u);try{a.pushState(h,"",y)}catch(v){if(v instanceof DOMException&&v.name==="DataCloneError")throw v;s.location.assign(y)}o&&c&&c({action:l,location:w.location,delta:1})}function g(j,x){l=kt.Replace;let u=Mo(w.location,j,x);n&&n(u,j),d=m();let h=vc(u,d),y=w.createHref(u);a.replaceState(h,"",y),o&&c&&c({action:l,location:w.location,delta:0})}function b(j){let x=s.location.origin!=="null"?s.location.origin:s.location.href,u=typeof j=="string"?j:Ws(j);return u=u.replace(/ $/,"%20"),se(x,"No window.location.(origin|href) available to create URL for href: "+u),new URL(u,x)}let w={get action(){return l},get location(){return e(s,a)},listen(j){if(c)throw new Error("A history only accepts one active listener");return s.addEventListener(xc,p),c=j,()=>{s.removeEventListener(xc,p),c=null}},createHref(j){return t(s,j)},createURL:b,encodeLocation(j){let x=b(j);return{pathname:x.pathname,search:x.search,hash:x.hash}},push:f,replace:g,go(j){return a.go(j)}};return w}var yc;(function(e){e.data="data",e.deferred="deferred",e.redirect="redirect",e.error="error"})(yc||(yc={}));function Wf(e,t,n){return n===void 0&&(n="/"),Bf(e,t,n,!1)}function Bf(e,t,n,r){let s=typeof t=="string"?Mn(t):t,o=Ga(s.pathname||"/",n);if(o==null)return null;let a=nh(e);Kf(a);let l=null;for(let c=0;l==null&&c{let c={relativePath:l===void 0?o.path||"":l,caseSensitive:o.caseSensitive===!0,childrenIndex:a,route:o};c.relativePath.startsWith("/")&&(se(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 d=At([r,c.relativePath]),m=n.concat(c);o.children&&o.children.length>0&&(se(o.index!==!0,"Index routes must not have child routes. Please remove "+('all child routes from route path "'+d+'".')),nh(o.children,t,m,d)),!(o.path==null&&!o.index)&&t.push({path:d,score:Qf(d,o.index),routesMeta:m})};return e.forEach((o,a)=>{var l;if(o.path===""||!((l=o.path)!=null&&l.includes("?")))s(o,a);else for(let c of rh(o.path))s(o,a,c)}),t}function rh(e){let t=e.split("/");if(t.length===0)return[];let[n,...r]=t,s=n.endsWith("?"),o=n.replace(/\?$/,"");if(r.length===0)return s?[o,""]:[o];let a=rh(r.join("/")),l=[];return l.push(...a.map(c=>c===""?o:[o,c].join("/"))),s&&l.push(...a),l.map(c=>e.startsWith("/")&&c===""?"/":c)}function Kf(e){e.sort((t,n)=>t.score!==n.score?n.score-t.score:qf(t.routesMeta.map(r=>r.childrenIndex),n.routesMeta.map(r=>r.childrenIndex)))}const Hf=/^:[\w-]+$/,Gf=3,Zf=2,Jf=1,Xf=10,Yf=-2,wc=e=>e==="*";function Qf(e,t){let n=e.split("/"),r=n.length;return n.some(wc)&&(r+=Yf),t&&(r+=Zf),n.filter(s=>!wc(s)).reduce((s,o)=>s+(Hf.test(o)?Gf:o===""?Jf:Xf),r)}function qf(e,t){return e.length===t.length&&e.slice(0,-1).every((r,s)=>r===t[s])?e[e.length-1]-t[t.length-1]:0}function eg(e,t,n){n===void 0&&(n=!1);let{routesMeta:r}=e,s={},o="/",a=[];for(let l=0;l{let{paramName:f,isOptional:g}=m;if(f==="*"){let w=l[p]||"";a=o.slice(0,o.length-w.length).replace(/(.)\/+$/,"$1")}const b=l[p];return g&&!b?d[f]=void 0:d[f]=(b||"").replace(/%2F/g,"/"),d},{}),pathname:o,pathnameBase:a,pattern:e}}function tg(e,t,n){t===void 0&&(t=!1),n===void 0&&(n=!0),th(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=[],s="^"+e.replace(/\/*\*?$/,"").replace(/^\/*/,"/").replace(/[\\.*+^${}|()[\]]/g,"\\$&").replace(/\/:([\w-]+)(\?)?/g,(a,l,c)=>(r.push({paramName:l,isOptional:c!=null}),c?"/?([^\\/]+)?":"/([^\\/]+)"));return e.endsWith("*")?(r.push({paramName:"*"}),s+=e==="*"||e==="/*"?"(.*)$":"(?:\\/(.+)|\\/*)$"):n?s+="\\/*$":e!==""&&e!=="/"&&(s+="(?:(?=\\/|$))"),[new RegExp(s,t?void 0:"i"),r]}function ng(e){try{return e.split("/").map(t=>decodeURIComponent(t).replace(/\//g,"%2F")).join("/")}catch(t){return th(!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 Ga(e,t){if(t==="/")return e;if(!e.toLowerCase().startsWith(t.toLowerCase()))return null;let n=t.endsWith("/")?t.length-1:t.length,r=e.charAt(n);return r&&r!=="/"?null:e.slice(n)||"/"}function rg(e,t){t===void 0&&(t="/");let{pathname:n,search:r="",hash:s=""}=typeof e=="string"?Mn(e):e;return{pathname:n?n.startsWith("/")?n:sg(n,t):t,search:ag(r),hash:lg(s)}}function sg(e,t){let n=t.replace(/\/+$/,"").split("/");return e.split("/").forEach(s=>{s===".."?n.length>1&&n.pop():s!=="."&&n.push(s)}),n.length>1?n.join("/"):"/"}function Wi(e,t,n,r){return"Cannot include a '"+e+"' character in a manually specified "+("`to."+t+"` field ["+JSON.stringify(r)+"]. Please separate it out to the ")+("`to."+n+"` field. Alternatively you may provide the full path as ")+'a string in and the router will parse it for you.'}function ig(e){return e.filter((t,n)=>n===0||t.route.path&&t.route.path.length>0)}function sh(e,t){let n=ig(e);return t?n.map((r,s)=>s===n.length-1?r.pathname:r.pathnameBase):n.map(r=>r.pathnameBase)}function ih(e,t,n,r){r===void 0&&(r=!1);let s;typeof e=="string"?s=Mn(e):(s=Ir({},e),se(!s.pathname||!s.pathname.includes("?"),Wi("?","pathname","search",s)),se(!s.pathname||!s.pathname.includes("#"),Wi("#","pathname","hash",s)),se(!s.search||!s.search.includes("#"),Wi("#","search","hash",s)));let o=e===""||s.pathname==="",a=o?"/":s.pathname,l;if(a==null)l=n;else{let p=t.length-1;if(!r&&a.startsWith("..")){let f=a.split("/");for(;f[0]==="..";)f.shift(),p-=1;s.pathname=f.join("/")}l=p>=0?t[p]:"/"}let c=rg(s,l),d=a&&a!=="/"&&a.endsWith("/"),m=(o||a===".")&&n.endsWith("/");return!c.pathname.endsWith("/")&&(d||m)&&(c.pathname+="/"),c}const At=e=>e.join("/").replace(/\/\/+/g,"/"),og=e=>e.replace(/\/+$/,"").replace(/^\/*/,"/"),ag=e=>!e||e==="?"?"":e.startsWith("?")?e:"?"+e,lg=e=>!e||e==="#"?"":e.startsWith("#")?e:"#"+e;function cg(e){return e!=null&&typeof e.status=="number"&&typeof e.statusText=="string"&&typeof e.internal=="boolean"&&"data"in e}const oh=["post","put","patch","delete"];new Set(oh);const dg=["get",...oh];new Set(dg);/** * React Router v6.30.1 * * 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 Ar(){return Ar=Object.assign?Object.assign.bind():function(e){for(var t=1;t{l.current=!0}),S.useCallback(function(d,m){if(m===void 0&&(m={}),!l.current)return;if(typeof d=="number"){r.go(d);return}let p=ih(d,JSON.parse(a),o,m.relative==="path");e==null&&t!=="/"&&(p.pathname=p.pathname==="/"?t:At([t,p.pathname])),(m.replace?r.replace:r.push)(p,m.state,m)},[t,r,a,o,e])}function dh(){let{matches:e}=S.useContext(Ft),t=e[e.length-1];return t?t.params:{}}function uh(e,t){let{relative:n}=t===void 0?{}:t,{future:r}=S.useContext(an),{matches:s}=S.useContext(Ft),{pathname:o}=di(),a=JSON.stringify(sh(s,r.v7_relativeSplatPath));return S.useMemo(()=>ih(e,JSON.parse(a),o,n==="path"),[e,a,o,n])}function pg(e,t){return fg(e,t)}function fg(e,t,n,r){Fr()||se(!1);let{navigator:s}=S.useContext(an),{matches:o}=S.useContext(Ft),a=o[o.length-1],l=a?a.params:{};a&&a.pathname;let c=a?a.pathnameBase:"/";a&&a.route;let d=di(),m;if(t){var p;let j=typeof t=="string"?Mn(t):t;c==="/"||(p=j.pathname)!=null&&p.startsWith(c)||se(!1),m=j}else m=d;let f=m.pathname||"/",g=f;if(c!=="/"){let j=c.replace(/^\//,"").split("/");g="/"+f.replace(/^\//,"").split("/").slice(j.length).join("/")}let b=Wf(e,{pathname:g}),w=wg(b&&b.map(j=>Object.assign({},j,{params:Object.assign({},l,j.params),pathname:At([c,s.encodeLocation?s.encodeLocation(j.pathname).pathname:j.pathname]),pathnameBase:j.pathnameBase==="/"?c:At([c,s.encodeLocation?s.encodeLocation(j.pathnameBase).pathname:j.pathnameBase])})),o,n,r);return t&&w?S.createElement(ci.Provider,{value:{location:Ar({pathname:"/",search:"",hash:"",state:null,key:"default"},m),navigationType:kt.Pop}},w):w}function gg(){let e=kg(),t=cg(e)?e.status+" "+e.statusText:e instanceof Error?e.message:JSON.stringify(e),n=e instanceof Error?e.stack:null,s={padding:"0.5rem",backgroundColor:"rgba(200,200,200, 0.5)"},o=null;return S.createElement(S.Fragment,null,S.createElement("h2",null,"Unexpected Application Error!"),S.createElement("h3",{style:{fontStyle:"italic"}},t),n?S.createElement("pre",{style:s},n):null,o)}const xg=S.createElement(gg,null);class vg extends S.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,n){return n.location!==t.location||n.revalidation!=="idle"&&t.revalidation==="idle"?{error:t.error,location:t.location,revalidation:t.revalidation}:{error:t.error!==void 0?t.error:n.error,location:n.location,revalidation:t.revalidation||n.revalidation}}componentDidCatch(t,n){console.error("React Router caught the following error during render",t,n)}render(){return this.state.error!==void 0?S.createElement(Ft.Provider,{value:this.props.routeContext},S.createElement(ah.Provider,{value:this.state.error,children:this.props.component})):this.props.children}}function yg(e){let{routeContext:t,match:n,children:r}=e,s=S.useContext(Za);return s&&s.static&&s.staticContext&&(n.route.errorElement||n.route.ErrorBoundary)&&(s.staticContext._deepestRenderedBoundaryId=n.route.id),S.createElement(Ft.Provider,{value:t},r)}function wg(e,t,n,r){var s;if(t===void 0&&(t=[]),n===void 0&&(n=null),r===void 0&&(r=null),e==null){var o;if(!n)return null;if(n.errors)e=n.matches;else if((o=r)!=null&&o.v7_partialHydration&&t.length===0&&!n.initialized&&n.matches.length>0)e=n.matches;else return null}let a=e,l=(s=n)==null?void 0:s.errors;if(l!=null){let m=a.findIndex(p=>p.route.id&&(l==null?void 0:l[p.route.id])!==void 0);m>=0||se(!1),a=a.slice(0,Math.min(a.length,m+1))}let c=!1,d=-1;if(n&&r&&r.v7_partialHydration)for(let m=0;m=0?a=a.slice(0,d+1):a=[a[0]];break}}}return a.reduceRight((m,p,f)=>{let g,b=!1,w=null,j=null;n&&(g=l&&p.route.id?l[p.route.id]:void 0,w=p.route.errorElement||xg,c&&(d<0&&f===0?(Cg("route-fallback",!1),b=!0,j=null):d===f&&(b=!0,j=p.route.hydrateFallbackElement||null)));let x=t.concat(a.slice(0,f+1)),u=()=>{let h;return g?h=w:b?h=j:p.route.Component?h=S.createElement(p.route.Component,null):p.route.element?h=p.route.element:h=m,S.createElement(yg,{match:p,routeContext:{outlet:m,matches:x,isDataRoute:n!=null},children:h})};return n&&(p.route.ErrorBoundary||p.route.errorElement||f===0)?S.createElement(vg,{location:n.location,revalidation:n.revalidation,component:w,error:g,children:u(),routeContext:{outlet:null,matches:x,isDataRoute:!0}}):u()},null)}var hh=function(e){return e.UseBlocker="useBlocker",e.UseRevalidator="useRevalidator",e.UseNavigateStable="useNavigate",e}(hh||{}),Bs=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}(Bs||{});function bg(e){let t=S.useContext(Za);return t||se(!1),t}function jg(e){let t=S.useContext(ug);return t||se(!1),t}function Ng(e){let t=S.useContext(Ft);return t||se(!1),t}function mh(e){let t=Ng(),n=t.matches[t.matches.length-1];return n.route.id||se(!1),n.route.id}function kg(){var e;let t=S.useContext(ah),n=jg(Bs.UseRouteError),r=mh(Bs.UseRouteError);return t!==void 0?t:(e=n.errors)==null?void 0:e[r]}function Sg(){let{router:e}=bg(hh.UseNavigateStable),t=mh(Bs.UseNavigateStable),n=S.useRef(!1);return lh(()=>{n.current=!0}),S.useCallback(function(s,o){o===void 0&&(o={}),n.current&&(typeof s=="number"?e.navigate(s):e.navigate(s,Ar({fromRouteId:t},o)))},[e,t])}const jc={};function Cg(e,t,n){!t&&!jc[e]&&(jc[e]=!0)}function Eg(e,t){e==null||e.v7_startTransition,(e==null?void 0:e.v7_relativeSplatPath)===void 0&&(!t||t.v7_relativeSplatPath),t&&(t.v7_fetcherPersist,t.v7_normalizeFormMethod,t.v7_partialHydration,t.v7_skipActionErrorRevalidation)}function ft(e){se(!1)}function Tg(e){let{basename:t="/",children:n=null,location:r,navigationType:s=kt.Pop,navigator:o,static:a=!1,future:l}=e;Fr()&&se(!1);let c=t.replace(/^\/*/,"/"),d=S.useMemo(()=>({basename:c,navigator:o,static:a,future:Ar({v7_relativeSplatPath:!1},l)}),[c,l,o,a]);typeof r=="string"&&(r=Mn(r));let{pathname:m="/",search:p="",hash:f="",state:g=null,key:b="default"}=r,w=S.useMemo(()=>{let j=Ga(m,c);return j==null?null:{location:{pathname:j,search:p,hash:f,state:g,key:b},navigationType:s}},[c,m,p,f,g,b,s]);return w==null?null:S.createElement(an.Provider,{value:d},S.createElement(ci.Provider,{children:n,value:w}))}function Pg(e){let{children:t,location:n}=e;return pg(Uo(t),n)}new Promise(()=>{});function Uo(e,t){t===void 0&&(t=[]);let n=[];return S.Children.forEach(e,(r,s)=>{if(!S.isValidElement(r))return;let o=[...t,s];if(r.type===S.Fragment){n.push.apply(n,Uo(r.props.children,o));return}r.type!==ft&&se(!1),!r.props.index||!r.props.children||se(!1);let a={id:r.props.id||o.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&&(a.children=Uo(r.props.children,o)),n.push(a)}),n}/** * React Router DOM v6.30.1 * * 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 Wo(){return Wo=Object.assign?Object.assign.bind():function(e){for(var t=1;t=0)&&(n[s]=e[s]);return n}function Dg(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function Ig(e,t){return e.button===0&&(!t||t==="_self")&&!Dg(e)}const Ag=["onClick","relative","reloadDocument","replace","state","target","to","preventScrollReset","viewTransition"],zg="6";try{window.__reactRouterVersion=zg}catch{}const Og="startTransition",Nc=Oh[Og];function Lg(e){let{basename:t,children:n,future:r,window:s}=e,o=S.useRef();o.current==null&&(o.current=Vf({window:s,v5Compat:!0}));let a=o.current,[l,c]=S.useState({action:a.action,location:a.location}),{v7_startTransition:d}=r||{},m=S.useCallback(p=>{d&&Nc?Nc(()=>c(p)):c(p)},[c,d]);return S.useLayoutEffect(()=>a.listen(m),[a,m]),S.useEffect(()=>Eg(r),[r]),S.createElement(Tg,{basename:t,children:n,location:l.location,navigationType:l.action,navigator:a,future:r})}const Rg=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",$g=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,we=S.forwardRef(function(t,n){let{onClick:r,relative:s,reloadDocument:o,replace:a,state:l,target:c,to:d,preventScrollReset:m,viewTransition:p}=t,f=_g(t,Ag),{basename:g}=S.useContext(an),b,w=!1;if(typeof d=="string"&&$g.test(d)&&(b=d,Rg))try{let h=new URL(window.location.href),y=d.startsWith("//")?new URL(h.protocol+d):new URL(d),v=Ga(y.pathname,g);y.origin===h.origin&&v!=null?d=v+y.search+y.hash:w=!0}catch{}let j=hg(d,{relative:s}),x=Fg(d,{replace:a,state:l,target:c,preventScrollReset:m,relative:s,viewTransition:p});function u(h){r&&r(h),h.defaultPrevented||x(h)}return S.createElement("a",Wo({},f,{href:b||j,onClick:w||o?r:u,ref:n,target:c}))});var kc;(function(e){e.UseScrollRestoration="useScrollRestoration",e.UseSubmit="useSubmit",e.UseSubmitFetcher="useSubmitFetcher",e.UseFetcher="useFetcher",e.useViewTransitionState="useViewTransitionState"})(kc||(kc={}));var Sc;(function(e){e.UseFetcher="useFetcher",e.UseFetchers="useFetchers",e.UseScrollRestoration="useScrollRestoration"})(Sc||(Sc={}));function Fg(e,t){let{target:n,replace:r,state:s,preventScrollReset:o,relative:a,viewTransition:l}=t===void 0?{}:t,c=ch(),d=di(),m=uh(e,{relative:a});return S.useCallback(p=>{if(Ig(p,n)){p.preventDefault();let f=r!==void 0?r:Ws(d)===Ws(m);c(e,{replace:f,state:s,preventScrollReset:o,relative:a,viewTransition:l})}},[d,c,m,r,s,n,e,o,a,l])}const Vg=typeof window<"u"?window.location.origin:"http://localhost:3000";var Pc;const vt=((Pc={}.VITE_API_URL)==null?void 0:Pc.replace(/\/$/,""))||Vg,U=(e,t)=>{const n=/^https?:\/\//.test(e)?e:`${vt}${e}`;return fetch(n,t)},Mg=({onSubmit:e,onCancel:t})=>{const[n,r]=S.useState({name:"",organization:"",department:"Office of Development",transportMode:"flight",flights:[{flightNumber:"",flightDate:"",segment:1}],expectedArrival:"",needsAirportPickup:!0,needsVenueTransport:!0,notes:""}),[s,o]=S.useState({}),[a,l]=S.useState({}),c=w=>{var x;w.preventDefault();const j=((x=n.flights)==null?void 0:x.filter(u=>u.flightNumber))||[];e({...n,flights:j.length>0?j:void 0})},d=w=>{const{name:j,value:x,type:u}=w.target;if(u==="checkbox"){const h=w.target.checked;r(y=>({...y,[j]:h}))}else r(h=>({...h,[j]:x}))},m=w=>{r(j=>({...j,transportMode:w,flights:w==="flight"?[{flightNumber:"",flightDate:"",segment:1}]:void 0,expectedArrival:w==="self-driving"?j.expectedArrival:"",needsAirportPickup:w==="flight"})),w!=="flight"&&l({})},p=(w,j,x)=>{r(u=>{var h;return{...u,flights:((h=u.flights)==null?void 0:h.map((y,v)=>v===w?{...y,[j]:x,validated:!1}:y))||[]}}),l(u=>({...u,[w]:""}))},f=()=>{const w=n.flights||[];w.length<3&&r(j=>{var x;return{...j,flights:[...w,{flightNumber:"",flightDate:((x=w[w.length-1])==null?void 0:x.flightDate)||"",segment:w.length+1}]}})},g=w=>{r(j=>{var x;return{...j,flights:((x=j.flights)==null?void 0:x.filter((u,h)=>h!==w).map((u,h)=>({...u,segment:h+1})))||[]}}),l(j=>{const x={...j};return delete x[w],x})},b=async w=>{var x;const j=(x=n.flights)==null?void 0:x[w];if(!j||!j.flightNumber||!j.flightDate){l(u=>({...u,[w]:"Please enter flight number and date"}));return}o(u=>({...u,[w]:!0})),l(u=>({...u,[w]:""}));try{const u=`/api/flights/${j.flightNumber}?date=${j.flightDate}`,h=await fetch(u);if(h.ok){const y=await h.json();r(v=>{var N;return{...v,flights:((N=v.flights)==null?void 0:N.map((k,C)=>C===w?{...k,validated:!0,validationData:y}:k))||[]}}),l(v=>({...v,[w]:""}))}else{const y=await h.json();l(v=>({...v,[w]:y.error||"Invalid flight number"}))}}catch{l(h=>({...h,[w]:"Error validating flight"}))}finally{o(u=>({...u,[w]:!1}))}};return i.jsx("div",{className:"modal-overlay",children:i.jsxs("div",{className:"modal-content",children:[i.jsxs("div",{className:"modal-header",children:[i.jsx("h2",{className:"text-2xl font-bold text-slate-800",children:"Add New VIP"}),i.jsx("p",{className:"text-slate-600 mt-2",children:"Enter VIP details and travel information"})]}),i.jsx("div",{className:"modal-body",children:i.jsxs("form",{onSubmit:c,className:"space-y-8",children:[i.jsxs("div",{className:"form-section",children:[i.jsx("div",{className:"form-section-header",children:i.jsx("h3",{className:"form-section-title",children:"Basic Information"})}),i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[i.jsxs("div",{className:"form-group",children:[i.jsx("label",{htmlFor:"name",className:"form-label",children:"Full Name *"}),i.jsx("input",{type:"text",id:"name",name:"name",value:n.name,onChange:d,className:"form-input",placeholder:"Enter full name",required:!0})]}),i.jsxs("div",{className:"form-group",children:[i.jsx("label",{htmlFor:"organization",className:"form-label",children:"Organization *"}),i.jsx("input",{type:"text",id:"organization",name:"organization",value:n.organization,onChange:d,className:"form-input",placeholder:"Enter organization name",required:!0})]})]}),i.jsxs("div",{className:"form-group",children:[i.jsx("label",{htmlFor:"department",className:"form-label",children:"Department *"}),i.jsxs("select",{id:"department",name:"department",value:n.department,onChange:d,className:"form-select",required:!0,children:[i.jsx("option",{value:"Office of Development",children:"Office of Development"}),i.jsx("option",{value:"Admin",children:"Admin"})]})]})]}),i.jsxs("div",{className:"form-section",children:[i.jsx("div",{className:"form-section-header",children:i.jsx("h3",{className:"form-section-title",children:"Transportation Details"})}),i.jsxs("div",{className:"form-group",children:[i.jsx("label",{className:"form-label",children:"How are you arriving? *"}),i.jsxs("div",{className:"radio-group",children:[i.jsxs("div",{className:`radio-option ${n.transportMode==="flight"?"selected":""}`,onClick:()=>m("flight"),children:[i.jsx("input",{type:"radio",name:"transportMode",value:"flight",checked:n.transportMode==="flight",onChange:()=>m("flight"),className:"form-radio mr-3"}),i.jsx("span",{className:"font-medium",children:"Arriving by Flight"})]}),i.jsxs("div",{className:`radio-option ${n.transportMode==="self-driving"?"selected":""}`,onClick:()=>m("self-driving"),children:[i.jsx("input",{type:"radio",name:"transportMode",value:"self-driving",checked:n.transportMode==="self-driving",onChange:()=>m("self-driving"),className:"form-radio mr-3"}),i.jsx("span",{className:"font-medium",children:"Self-Driving"})]})]})]}),n.transportMode==="flight"&&n.flights&&i.jsxs("div",{className:"space-y-6",children:[n.flights.map((w,j)=>{var x,u;return i.jsxs("div",{className:"bg-white border-2 border-blue-200 rounded-xl p-6 shadow-sm",children:[i.jsxs("div",{className:"flex justify-between items-center mb-4",children:[i.jsx("h4",{className:"text-lg font-bold text-slate-800",children:j===0?"Primary Flight":`Connecting Flight ${j}`}),j>0&&i.jsx("button",{type:"button",onClick:()=>g(j),className:"text-red-500 hover:text-red-700 font-medium text-sm bg-red-50 hover:bg-red-100 px-3 py-1 rounded-lg transition-colors duration-200",children:"Remove"})]}),i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 mb-4",children:[i.jsxs("div",{className:"form-group",children:[i.jsx("label",{htmlFor:`flightNumber-${j}`,className:"form-label",children:"Flight Number *"}),i.jsx("input",{type:"text",id:`flightNumber-${j}`,value:w.flightNumber,onChange:h=>p(j,"flightNumber",h.target.value),className:"form-input",placeholder:"e.g., AA123",required:j===0})]}),i.jsxs("div",{className:"form-group",children:[i.jsx("label",{htmlFor:`flightDate-${j}`,className:"form-label",children:"Flight Date *"}),i.jsx("input",{type:"date",id:`flightDate-${j}`,value:w.flightDate,onChange:h=>p(j,"flightDate",h.target.value),className:"form-input",required:j===0,min:new Date().toISOString().split("T")[0]})]})]}),i.jsx("button",{type:"button",className:"btn btn-secondary w-full",onClick:()=>b(j),disabled:s[j]||!w.flightNumber||!w.flightDate,children:s[j]?i.jsxs(i.Fragment,{children:[i.jsx("span",{className:"animate-spin inline-block w-4 h-4 border-2 border-white border-t-transparent rounded-full mr-2"}),"Validating Flight..."]}):i.jsx(i.Fragment,{children:"Validate Flight"})}),a[j]&&i.jsx("div",{className:"mt-4 bg-red-50 border border-red-200 rounded-lg p-4",children:i.jsx("div",{className:"text-red-700 font-medium",children:a[j]})}),w.validated&&w.validationData&&i.jsxs("div",{className:"mt-4 bg-green-50 border border-green-200 rounded-lg p-4",children:[i.jsxs("div",{className:"text-green-700 font-medium mb-2",children:["Valid: ",w.validationData.airline||"Flight"," - ",(x=w.validationData.departure)==null?void 0:x.airport," β†’ ",(u=w.validationData.arrival)==null?void 0:u.airport]}),w.validationData.flightDate!==w.flightDate&&i.jsxs("div",{className:"text-sm text-green-600",children:["Live tracking starts 4 hours before departure on ",new Date(w.flightDate).toLocaleDateString()]})]})]},j)}),n.flights.length<3&&i.jsx("button",{type:"button",className:"btn btn-secondary w-full",onClick:f,children:"Add Connecting Flight"}),i.jsxs("div",{className:"checkbox-option checked",children:[i.jsx("input",{type:"checkbox",name:"needsAirportPickup",checked:n.needsAirportPickup||!1,onChange:d,className:"form-checkbox mr-3"}),i.jsx("span",{className:"font-medium",children:"Needs Airport Pickup (from final destination)"})]})]}),n.transportMode==="self-driving"&&i.jsxs("div",{className:"form-group",children:[i.jsx("label",{htmlFor:"expectedArrival",className:"form-label",children:"Expected Arrival *"}),i.jsx("input",{type:"datetime-local",id:"expectedArrival",name:"expectedArrival",value:n.expectedArrival,onChange:d,className:"form-input",required:!0})]}),i.jsxs("div",{className:`checkbox-option ${n.needsVenueTransport?"checked":""}`,children:[i.jsx("input",{type:"checkbox",name:"needsVenueTransport",checked:n.needsVenueTransport,onChange:d,className:"form-checkbox mr-3"}),i.jsxs("div",{children:[i.jsx("span",{className:"font-medium",children:"Needs Transportation Between Venues"}),i.jsx("div",{className:"text-sm text-slate-500 mt-1",children:"Check this if the VIP needs rides between different event locations"})]})]})]}),i.jsxs("div",{className:"form-section",children:[i.jsx("div",{className:"form-section-header",children:i.jsx("h3",{className:"form-section-title",children:"Additional Information"})}),i.jsxs("div",{className:"form-group",children:[i.jsx("label",{htmlFor:"notes",className:"form-label",children:"Additional Notes"}),i.jsx("textarea",{id:"notes",name:"notes",value:n.notes,onChange:d,rows:4,className:"form-textarea",placeholder:"Special requirements, dietary restrictions, accessibility needs, etc."})]})]}),i.jsxs("div",{className:"form-actions",children:[i.jsx("button",{type:"button",className:"btn btn-secondary",onClick:t,children:"Cancel"}),i.jsx("button",{type:"submit",className:"btn btn-primary",children:"Add VIP"})]})]})})]})})},Ug=({vip:e,onSubmit:t,onCancel:n})=>{const r=e.flights||(e.flightNumber?[{flightNumber:e.flightNumber,flightDate:e.flightDate||"",segment:1}]:[{flightNumber:"",flightDate:"",segment:1}]),[s,o]=S.useState({id:e.id,name:e.name,organization:e.organization,transportMode:e.transportMode||"flight",flights:r,expectedArrival:e.expectedArrival?e.expectedArrival.slice(0,16):"",arrivalTime:e.arrivalTime?e.arrivalTime.slice(0,16):"",needsAirportPickup:e.needsAirportPickup!==!1,needsVenueTransport:e.needsVenueTransport!==!1,notes:e.notes||""}),[a,l]=S.useState({}),[c,d]=S.useState({}),[m,p]=S.useState(!1),f=async h=>{var y;h.preventDefault(),p(!0);try{const v=((y=s.flights)==null?void 0:y.filter(N=>N.flightNumber))||[];await t({...s,flights:v.length>0?v:void 0})}catch(v){console.error("Error updating VIP:",v)}finally{p(!1)}},g=h=>{const{name:y,value:v,type:N}=h.target;if(N==="checkbox"){const k=h.target.checked;o(C=>({...C,[y]:k}))}else o(k=>({...k,[y]:v}))},b=h=>{o(y=>({...y,transportMode:h,flights:h==="flight"?y.flights||[{flightNumber:"",flightDate:"",segment:1}]:void 0,expectedArrival:h==="self-driving"?y.expectedArrival:"",needsAirportPickup:h==="flight"})),h!=="flight"&&d({})},w=(h,y,v)=>{o(N=>{var k;return{...N,flights:((k=N.flights)==null?void 0:k.map((C,z)=>z===h?{...C,[y]:v,validated:!1}:C))||[]}}),d(N=>({...N,[h]:""}))},j=()=>{const h=s.flights||[];h.length<3&&o(y=>{var v;return{...y,flights:[...h,{flightNumber:"",flightDate:((v=h[h.length-1])==null?void 0:v.flightDate)||"",segment:h.length+1}]}})},x=h=>{o(y=>{var v;return{...y,flights:((v=y.flights)==null?void 0:v.filter((N,k)=>k!==h).map((N,k)=>({...N,segment:k+1})))||[]}}),d(y=>{const v={...y};return delete v[h],v})},u=async h=>{var v;const y=(v=s.flights)==null?void 0:v[h];if(!y||!y.flightNumber||!y.flightDate){d(N=>({...N,[h]:"Please enter flight number and date"}));return}l(N=>({...N,[h]:!0})),d(N=>({...N,[h]:""}));try{const N=`/api/flights/${y.flightNumber}?date=${y.flightDate}`,k=await fetch(N);if(k.ok){const C=await k.json();o(z=>{var A;return{...z,flights:((A=z.flights)==null?void 0:A.map((I,M)=>M===h?{...I,validated:!0,validationData:C}:I))||[]}}),d(z=>({...z,[h]:""}))}else{const C=await k.json();d(z=>({...z,[h]:C.error||"Invalid flight number"}))}}catch{d(k=>({...k,[h]:"Error validating flight"}))}finally{l(N=>({...N,[h]:!1}))}};return i.jsx("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-sm flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-white rounded-2xl shadow-2xl border border-slate-200/60 w-full max-w-4xl max-h-[90vh] overflow-y-auto",children:[i.jsxs("div",{className:"bg-gradient-to-r from-blue-50 to-indigo-50 px-8 py-6 border-b border-slate-200/60",children:[i.jsxs("h2",{className:"text-2xl font-bold text-slate-800 flex items-center gap-2",children:["✏️ Edit VIP: ",e.name]}),i.jsx("p",{className:"text-slate-600 mt-1",children:"Update VIP information and travel arrangements"})]}),i.jsxs("form",{onSubmit:f,className:"p-8 space-y-8",children:[i.jsxs("div",{className:"bg-slate-50 rounded-xl p-6 border border-slate-200/60",children:[i.jsx("h3",{className:"text-lg font-bold text-slate-800 mb-4 flex items-center gap-2",children:"πŸ‘€ Basic Information"}),i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[i.jsxs("div",{children:[i.jsx("label",{htmlFor:"name",className:"block text-sm font-medium text-slate-700 mb-2",children:"Full Name"}),i.jsx("input",{type:"text",id:"name",name:"name",value:s.name,onChange:g,className:"w-full px-4 py-3 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition-colors",placeholder:"Enter full name",required:!0})]}),i.jsxs("div",{children:[i.jsx("label",{htmlFor:"organization",className:"block text-sm font-medium text-slate-700 mb-2",children:"Organization"}),i.jsx("input",{type:"text",id:"organization",name:"organization",value:s.organization,onChange:g,className:"w-full px-4 py-3 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition-colors",placeholder:"Enter organization",required:!0})]})]})]}),i.jsxs("div",{className:"bg-slate-50 rounded-xl p-6 border border-slate-200/60",children:[i.jsx("h3",{className:"text-lg font-bold text-slate-800 mb-4 flex items-center gap-2",children:"πŸš— Transportation"}),i.jsx("div",{className:"space-y-4",children:i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-slate-700 mb-3",children:"How are you arriving?"}),i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[i.jsxs("label",{className:`relative flex items-center p-4 border-2 rounded-xl cursor-pointer transition-all duration-200 ${s.transportMode==="flight"?"border-blue-500 bg-blue-50":"border-slate-300 bg-white hover:border-slate-400"}`,children:[i.jsx("input",{type:"radio",name:"transportMode",value:"flight",checked:s.transportMode==="flight",onChange:()=>b("flight"),className:"sr-only"}),i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("span",{className:"text-2xl",children:"✈️"}),i.jsxs("div",{children:[i.jsx("div",{className:"font-semibold text-slate-900",children:"Arriving by Flight"}),i.jsx("div",{className:"text-sm text-slate-600",children:"Commercial airline travel"})]})]}),s.transportMode==="flight"&&i.jsx("div",{className:"absolute top-2 right-2 w-5 h-5 bg-blue-500 rounded-full flex items-center justify-center",children:i.jsx("span",{className:"text-white text-xs",children:"βœ“"})})]}),i.jsxs("label",{className:`relative flex items-center p-4 border-2 rounded-xl cursor-pointer transition-all duration-200 ${s.transportMode==="self-driving"?"border-green-500 bg-green-50":"border-slate-300 bg-white hover:border-slate-400"}`,children:[i.jsx("input",{type:"radio",name:"transportMode",value:"self-driving",checked:s.transportMode==="self-driving",onChange:()=>b("self-driving"),className:"sr-only"}),i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("span",{className:"text-2xl",children:"πŸš—"}),i.jsxs("div",{children:[i.jsx("div",{className:"font-semibold text-slate-900",children:"Self-Driving"}),i.jsx("div",{className:"text-sm text-slate-600",children:"Personal vehicle"})]})]}),s.transportMode==="self-driving"&&i.jsx("div",{className:"absolute top-2 right-2 w-5 h-5 bg-green-500 rounded-full flex items-center justify-center",children:i.jsx("span",{className:"text-white text-xs",children:"βœ“"})})]})]})]})})]}),s.transportMode==="flight"&&s.flights&&i.jsxs("div",{className:"bg-blue-50 rounded-xl p-6 border border-blue-200/60",children:[i.jsx("h3",{className:"text-lg font-bold text-slate-800 mb-4 flex items-center gap-2",children:"✈️ Flight Information"}),i.jsxs("div",{className:"space-y-6",children:[s.flights.map((h,y)=>{var v,N;return i.jsxs("div",{className:"bg-white rounded-xl border border-blue-200 p-6",children:[i.jsxs("div",{className:"flex justify-between items-center mb-4",children:[i.jsx("h4",{className:"text-lg font-semibold text-slate-900 flex items-center gap-2",children:y===0?i.jsx(i.Fragment,{children:"✈️ Primary Flight"}):i.jsxs(i.Fragment,{children:["πŸ”„ Connecting Flight ",y]})}),y>0&&i.jsx("button",{type:"button",onClick:()=>x(y),className:"text-red-600 hover:text-red-700 font-medium text-sm flex items-center gap-1",children:"βœ• Remove"})]}),i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 mb-4",children:[i.jsxs("div",{children:[i.jsx("label",{htmlFor:`flightNumber-${y}`,className:"block text-sm font-medium text-slate-700 mb-2",children:"Flight Number"}),i.jsx("input",{type:"text",id:`flightNumber-${y}`,value:h.flightNumber,onChange:k=>w(y,"flightNumber",k.target.value),className:"w-full px-4 py-3 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition-colors",placeholder:"e.g., AA123",required:y===0})]}),i.jsxs("div",{children:[i.jsx("label",{htmlFor:`flightDate-${y}`,className:"block text-sm font-medium text-slate-700 mb-2",children:"Flight Date"}),i.jsx("input",{type:"date",id:`flightDate-${y}`,value:h.flightDate,onChange:k=>w(y,"flightDate",k.target.value),className:"w-full px-4 py-3 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition-colors",required:y===0,min:new Date().toISOString().split("T")[0]})]})]}),i.jsx("button",{type:"button",onClick:()=>u(y),disabled:a[y]||!h.flightNumber||!h.flightDate,className:"w-full bg-gradient-to-r from-blue-500 to-blue-600 hover:from-blue-600 hover:to-blue-700 disabled:from-slate-400 disabled:to-slate-500 text-white px-4 py-3 rounded-lg font-medium transition-all duration-200 shadow-lg hover:shadow-xl disabled:cursor-not-allowed",children:a[y]?i.jsxs("span",{className:"flex items-center justify-center gap-2",children:[i.jsx("div",{className:"w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin"}),"πŸ” Validating..."]}):"πŸ” Validate Flight"}),c[y]&&i.jsx("div",{className:"mt-4 bg-red-50 border border-red-200 rounded-xl p-4",children:i.jsxs("div",{className:"text-red-800 font-medium flex items-center gap-2",children:["❌ ",c[y]]})}),h.validated&&h.validationData&&i.jsxs("div",{className:"mt-4 bg-green-50 border border-green-200 rounded-xl p-4",children:[i.jsxs("div",{className:"text-green-800 font-medium flex items-center gap-2 mb-2",children:["βœ… Valid Flight: ",h.validationData.airline||"Flight"," - ",(v=h.validationData.departure)==null?void 0:v.airport," β†’ ",(N=h.validationData.arrival)==null?void 0:N.airport]}),h.validationData.flightDate!==h.flightDate&&i.jsxs("div",{className:"text-green-700 text-sm",children:["ℹ️ Live tracking starts 4 hours before departure on ",new Date(h.flightDate).toLocaleDateString()]})]})]},y)}),s.flights.length<3&&i.jsx("button",{type:"button",onClick:j,className:"w-full bg-gradient-to-r from-slate-500 to-slate-600 hover:from-slate-600 hover:to-slate-700 text-white px-4 py-3 rounded-lg font-medium transition-all duration-200 shadow-lg hover:shadow-xl",children:"+ Add Connecting Flight"}),i.jsx("div",{className:"bg-white rounded-xl border border-blue-200 p-4",children:i.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[i.jsx("input",{type:"checkbox",name:"needsAirportPickup",checked:s.needsAirportPickup||!1,onChange:g,className:"w-5 h-5 text-blue-600 border-slate-300 rounded focus:ring-blue-500"}),i.jsxs("div",{children:[i.jsx("div",{className:"font-medium text-slate-900",children:"βœ… Needs Airport Pickup"}),i.jsx("div",{className:"text-sm text-slate-600",children:"Pickup from final destination airport"})]})]})})]})]}),s.transportMode==="self-driving"&&i.jsxs("div",{className:"bg-green-50 rounded-xl p-6 border border-green-200/60",children:[i.jsx("h3",{className:"text-lg font-bold text-slate-800 mb-4 flex items-center gap-2",children:"πŸš— Arrival Information"}),i.jsxs("div",{children:[i.jsx("label",{htmlFor:"expectedArrival",className:"block text-sm font-medium text-slate-700 mb-2",children:"Expected Arrival Time"}),i.jsx("input",{type:"datetime-local",id:"expectedArrival",name:"expectedArrival",value:s.expectedArrival,onChange:g,className:"w-full px-4 py-3 border border-slate-300 rounded-lg focus:ring-2 focus:ring-green-500 focus:border-green-500 transition-colors",required:!0})]})]}),i.jsxs("div",{className:"bg-slate-50 rounded-xl p-6 border border-slate-200/60",children:[i.jsx("h3",{className:"text-lg font-bold text-slate-800 mb-4 flex items-center gap-2",children:"🚐 Transportation Options"}),i.jsx("div",{className:"bg-white rounded-xl border border-slate-200 p-4",children:i.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[i.jsx("input",{type:"checkbox",name:"needsVenueTransport",checked:s.needsVenueTransport,onChange:g,className:"w-5 h-5 text-blue-600 border-slate-300 rounded focus:ring-blue-500"}),i.jsxs("div",{children:[i.jsx("div",{className:"font-medium text-slate-900",children:"🚐 Needs Transportation Between Venues"}),i.jsx("div",{className:"text-sm text-slate-600",children:"Check this if the VIP needs rides between different event locations"})]})]})})]}),i.jsxs("div",{className:"bg-slate-50 rounded-xl p-6 border border-slate-200/60",children:[i.jsx("h3",{className:"text-lg font-bold text-slate-800 mb-4 flex items-center gap-2",children:"πŸ“ Additional Notes"}),i.jsxs("div",{children:[i.jsx("label",{htmlFor:"notes",className:"block text-sm font-medium text-slate-700 mb-2",children:"Special Requirements"}),i.jsx("textarea",{id:"notes",name:"notes",value:s.notes,onChange:g,rows:4,className:"w-full px-4 py-3 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition-colors",placeholder:"Special requirements, dietary restrictions, accessibility needs, security details, etc."})]})]}),i.jsxs("div",{className:"flex justify-end gap-4 pt-6 border-t border-slate-200",children:[i.jsx("button",{type:"button",className:"px-6 py-3 border border-slate-300 text-slate-700 rounded-lg hover:bg-slate-50 transition-colors font-medium",onClick:n,disabled:m,children:"Cancel"}),i.jsx("button",{type:"submit",className:"bg-gradient-to-r from-blue-500 to-blue-600 hover:from-blue-600 hover:to-blue-700 text-white px-6 py-3 rounded-lg font-medium transition-all duration-200 shadow-lg hover:shadow-xl disabled:opacity-50 disabled:cursor-not-allowed",disabled:m,children:m?i.jsxs("span",{className:"flex items-center gap-2",children:[i.jsx("div",{className:"w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin"}),"Updating VIP..."]}):"✏️ Update VIP"})]})]})]})})},ph=({flightNumber:e,flightDate:t})=>{const[n,r]=S.useState(null),[s,o]=S.useState(!0),[a,l]=S.useState(null);if(S.useEffect(()=>{const m=async()=>{try{o(!0);const p=t?`/api/flights/${e}?date=${t}`:`/api/flights/${e}`,f=await fetch(p);if(f.ok){const g=await f.json();r(g),l(null)}else l("Flight not found")}catch{l("Failed to fetch flight data")}finally{o(!1)}};if(e){m();const p=setInterval(m,5*60*1e3);return()=>clearInterval(p)}},[e,t]),s)return i.jsx("div",{className:"flight-status loading",children:"Loading flight data..."});if(a)return i.jsxs("div",{className:"flight-status error",children:["⚠️ ",a]});if(!n)return null;const c=m=>{switch(m.toLowerCase()){case"active":return"#2ecc71";case"scheduled":return"#3498db";case"delayed":return"#f39c12";case"cancelled":return"#e74c3c";default:return"#95a5a6"}},d=m=>new Date(m).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});return i.jsxs("div",{className:"flight-status",children:[i.jsxs("div",{className:"flight-header",children:[i.jsxs("h4",{children:["✈️ Flight ",n.flightNumber]}),i.jsx("span",{className:"flight-status-badge",style:{backgroundColor:c(n.status),color:"white",padding:"0.25rem 0.5rem",borderRadius:"4px",fontSize:"0.8rem",textTransform:"uppercase"},children:n.status})]}),i.jsxs("div",{className:"flight-details",children:[i.jsxs("div",{className:"flight-route",children:[i.jsxs("div",{className:"departure",children:[i.jsx("strong",{children:n.departure.airport}),i.jsxs("div",{children:["Scheduled: ",d(n.departure.scheduled)]}),n.departure.estimated&&i.jsxs("div",{children:["Estimated: ",d(n.departure.estimated)]})]}),i.jsx("div",{className:"route-arrow",children:"β†’"}),i.jsxs("div",{className:"arrival",children:[i.jsx("strong",{children:n.arrival.airport}),i.jsxs("div",{children:["Scheduled: ",d(n.arrival.scheduled)]}),n.arrival.estimated&&i.jsxs("div",{children:["Estimated: ",d(n.arrival.estimated)]})]})]}),n.delay&&n.delay>0&&i.jsxs("div",{className:"delay-info",style:{color:"#f39c12",marginTop:"0.5rem"},children:["⚠️ Delayed by ",n.delay," minutes"]}),n.gate&&i.jsxs("div",{className:"gate-info",style:{marginTop:"0.5rem"},children:["πŸšͺ Gate: ",n.gate]})]})]})},Wg=()=>{const[e,t]=S.useState([]),[n,r]=S.useState(!0),[s,o]=S.useState(!1),[a,l]=S.useState(null),c=g=>{const b=g.trim().split(" ");return b[b.length-1].toLowerCase()},d=g=>[...g].sort((b,w)=>{const j=c(b.name),x=c(w.name);return j.localeCompare(x)});S.useEffect(()=>{(async()=>{try{const b=localStorage.getItem("authToken"),w=await U("/api/vips",{headers:{Authorization:`Bearer ${b}`,"Content-Type":"application/json"}});if(w.ok){const j=await w.json(),x=d(j);t(x)}else console.error("Failed to fetch VIPs:",w.status)}catch(b){console.error("Error fetching VIPs:",b)}finally{r(!1)}})()},[]);const m=async g=>{try{const b=localStorage.getItem("authToken"),w=await U("/api/vips",{method:"POST",headers:{Authorization:`Bearer ${b}`,"Content-Type":"application/json"},body:JSON.stringify(g)});if(w.ok){const j=await w.json();t(x=>d([...x,j])),o(!1)}else console.error("Failed to add VIP:",w.status)}catch(b){console.error("Error adding VIP:",b)}},p=async g=>{try{const b=localStorage.getItem("authToken"),w=await U(`/api/vips/${g.id}`,{method:"PUT",headers:{Authorization:`Bearer ${b}`,"Content-Type":"application/json"},body:JSON.stringify(g)});if(w.ok){const j=await w.json();t(x=>d(x.map(u=>u.id===j.id?j:u))),l(null)}else console.error("Failed to update VIP:",w.status)}catch(b){console.error("Error updating VIP:",b)}},f=async g=>{if(confirm("Are you sure you want to delete this VIP?"))try{const b=localStorage.getItem("authToken"),w=await U(`/api/vips/${g}`,{method:"DELETE",headers:{Authorization:`Bearer ${b}`,"Content-Type":"application/json"}});w.ok?t(j=>j.filter(x=>x.id!==g)):console.error("Failed to delete VIP:",w.status)}catch(b){console.error("Error deleting VIP:",b)}};return n?i.jsx("div",{className:"flex justify-center items-center min-h-64",children:i.jsxs("div",{className:"bg-white rounded-2xl shadow-lg p-8 flex items-center space-x-4",children:[i.jsx("div",{className:"w-8 h-8 border-4 border-blue-600 border-t-transparent rounded-full animate-spin"}),i.jsx("span",{className:"text-lg font-medium text-slate-700",children:"Loading VIPs..."})]})}):i.jsxs("div",{className:"space-y-8",children:[i.jsx("div",{className:"bg-white rounded-2xl shadow-lg p-8 border border-slate-200/60",children:i.jsxs("div",{className:"flex justify-between items-center",children:[i.jsxs("div",{children:[i.jsx("h1",{className:"text-3xl font-bold bg-gradient-to-r from-slate-800 to-slate-600 bg-clip-text text-transparent",children:"VIP Management"}),i.jsx("p",{className:"text-slate-600 mt-2",children:"Manage VIP profiles and travel arrangements"})]}),i.jsx("button",{className:"btn btn-primary",onClick:()=>o(!0),children:"Add New VIP"})]})}),e.length===0?i.jsxs("div",{className:"bg-white rounded-2xl shadow-lg p-12 border border-slate-200/60 text-center",children:[i.jsx("div",{className:"w-16 h-16 bg-slate-100 rounded-full flex items-center justify-center mx-auto mb-4",children:i.jsx("div",{className:"w-8 h-8 bg-slate-300 rounded-full"})}),i.jsx("h3",{className:"text-lg font-semibold text-slate-800 mb-2",children:"No VIPs Found"}),i.jsx("p",{className:"text-slate-600 mb-6",children:"Get started by adding your first VIP"}),i.jsx("button",{className:"btn btn-primary",onClick:()=>o(!0),children:"Add New VIP"})]}):i.jsx("div",{className:"space-y-4",children:e.map(g=>i.jsx("div",{className:"bg-white rounded-2xl shadow-lg border border-slate-200/60 overflow-hidden hover:shadow-xl transition-shadow duration-200",children:i.jsxs("div",{className:"p-6",children:[i.jsxs("div",{className:"flex justify-between items-start",children:[i.jsxs("div",{className:"flex-1",children:[i.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[i.jsx("h3",{className:"text-xl font-bold text-slate-900",children:g.name}),i.jsx("span",{className:"bg-blue-100 text-blue-800 text-xs font-medium px-2.5 py-0.5 rounded-full",children:g.department})]}),i.jsx("p",{className:"text-slate-600 text-sm mb-4",children:g.organization}),i.jsxs("div",{className:"bg-slate-50 rounded-lg p-4 mb-4",children:[g.transportMode==="flight"?i.jsxs("div",{className:"space-y-2",children:[i.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[i.jsx("span",{className:"font-medium text-slate-700",children:"Flight:"}),i.jsx("span",{className:"text-slate-600",children:g.flights&&g.flights.length>0?g.flights.map(b=>b.flightNumber).join(" β†’ "):g.flightNumber||"No flight"})]}),i.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[i.jsx("span",{className:"font-medium text-slate-700",children:"Airport Pickup:"}),i.jsx("span",{className:`px-2 py-1 rounded-full text-xs font-medium ${g.needsAirportPickup?"bg-green-100 text-green-800":"bg-red-100 text-red-800"}`,children:g.needsAirportPickup?"Required":"Not needed"})]})]}):i.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[i.jsx("span",{className:"font-medium text-slate-700",children:"Self-driving, Expected:"}),i.jsx("span",{className:"text-slate-600",children:g.expectedArrival?new Date(g.expectedArrival).toLocaleString():"TBD"})]}),i.jsxs("div",{className:"flex items-center gap-2 text-sm mt-2",children:[i.jsx("span",{className:"font-medium text-slate-700",children:"Venue Transport:"}),i.jsx("span",{className:`px-2 py-1 rounded-full text-xs font-medium ${g.needsVenueTransport?"bg-blue-100 text-blue-800":"bg-gray-100 text-gray-800"}`,children:g.needsVenueTransport?"Required":"Not needed"})]})]})]}),i.jsxs("div",{className:"flex flex-col gap-2 ml-6",children:[i.jsx(we,{to:`/vips/${g.id}`,className:"btn btn-success text-center",children:"View Details"}),i.jsx("button",{className:"btn btn-secondary",onClick:()=>l(g),children:"Edit"}),i.jsx("button",{className:"btn btn-danger",onClick:()=>f(g.id),children:"Delete"})]})]}),g.transportMode==="flight"&&g.flightNumber&&i.jsx("div",{className:"mt-4 pt-4 border-t border-slate-200",children:i.jsx(ph,{flightNumber:g.flightNumber})})]})},g.id))}),s&&i.jsx(Mg,{onSubmit:m,onCancel:()=>o(!1)}),a&&i.jsx(Ug,{vip:{...a,notes:a.notes||""},onSubmit:p,onCancel:()=>l(null)})]})},Bg=({selectedDriverId:e,onDriverSelect:t,eventTime:n})=>{const[r,s]=S.useState([]),[o,a]=S.useState(!1),[l,c]=S.useState(!1),[d,m]=S.useState(null);S.useEffect(()=>{n.startTime&&n.endTime&&p()},[n.startTime,n.endTime,n.location]);const p=async()=>{a(!0);try{const u=localStorage.getItem("authToken"),h=await U("/api/drivers/availability",{method:"POST",headers:{Authorization:`Bearer ${u}`,"Content-Type":"application/json"},body:JSON.stringify(n)});if(h.ok){const y=await h.json();s(y)}}catch(u){console.error("Error checking driver availability:",u)}finally{a(!1)}},f=u=>{switch(u){case"available":return"🟒";case"scheduled":return"🟑";case"tight_turnaround":return"⚑";case"overlapping":return"πŸ”΄";default:return"βšͺ"}},g=u=>{switch(u){case"available":return"bg-green-50 border-green-200 text-green-800";case"scheduled":return"bg-amber-50 border-amber-200 text-amber-800";case"tight_turnaround":return"bg-orange-50 border-orange-200 text-orange-800";case"overlapping":return"bg-red-50 border-red-200 text-red-800";default:return"bg-slate-50 border-slate-200 text-slate-800"}},b=u=>{switch(u){case"available":return"Available";case"scheduled":return"Busy";case"tight_turnaround":return"Tight Schedule";case"overlapping":return"Conflict";default:return"Unknown"}},w=u=>{u.conflicts.length>0?(m(u),c(!0)):t(u.driverId)},j=()=>{d&&(t(d.driverId),c(!1),m(null))},x=u=>new Date(u).toLocaleString([],{hour:"2-digit",minute:"2-digit"});return o?i.jsx("div",{className:"bg-slate-50 rounded-xl p-6 border border-slate-200/60",children:i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"w-6 h-6 border-2 border-blue-600 border-t-transparent rounded-full animate-spin"}),i.jsx("span",{className:"text-slate-700 font-medium",children:"Checking driver availability..."})]})}):i.jsxs("div",{className:"bg-slate-50 rounded-xl p-6 border border-slate-200/60",children:[i.jsx("h3",{className:"text-lg font-bold text-slate-800 mb-4 flex items-center gap-2",children:"πŸš— Assign Driver"}),r.length===0?i.jsxs("div",{className:"text-center py-8",children:[i.jsx("div",{className:"w-12 h-12 bg-slate-200 rounded-full flex items-center justify-center mx-auto mb-3",children:i.jsx("span",{className:"text-xl",children:"πŸš—"})}),i.jsx("p",{className:"text-slate-500 font-medium",children:"No drivers available"}),i.jsx("p",{className:"text-slate-400 text-sm",children:"Check the time and try again"})]}):i.jsxs("div",{className:"space-y-3",children:[r.map(u=>{var h,y;return i.jsxs("div",{className:`relative rounded-xl border-2 p-4 cursor-pointer transition-all duration-200 hover:shadow-lg ${e===u.driverId?"border-blue-500 bg-blue-50 shadow-lg":"border-slate-200 bg-white hover:border-slate-300"}`,onClick:()=>w(u),children:[e===u.driverId&&i.jsx("div",{className:"absolute top-2 right-2 w-6 h-6 bg-blue-500 rounded-full flex items-center justify-center",children:i.jsx("span",{className:"text-white text-xs font-bold",children:"βœ“"})}),i.jsxs("div",{className:"flex items-start justify-between",children:[i.jsxs("div",{className:"flex-1",children:[i.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[i.jsx("span",{className:"text-xl",children:f(u.status)}),i.jsxs("div",{children:[i.jsx("h4",{className:"font-bold text-slate-900",children:u.driverName}),i.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[i.jsx("span",{className:`px-2 py-1 rounded-full text-xs font-medium border ${g(u.status)}`,children:b(u.status)}),i.jsxs("span",{className:"bg-slate-100 text-slate-700 px-2 py-1 rounded-full text-xs font-medium",children:["πŸš— ",u.vehicleCapacity," seats"]}),i.jsxs("span",{className:"bg-blue-100 text-blue-800 px-2 py-1 rounded-full text-xs font-medium",children:[u.assignmentCount," assignments"]})]})]})]}),u.conflicts.length>0&&i.jsx("div",{className:"space-y-2 mb-3",children:u.conflicts.map((v,N)=>i.jsxs("div",{className:`p-3 rounded-lg border ${v.severity==="high"?"bg-red-50 border-red-200":"bg-amber-50 border-amber-200"}`,children:[i.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[i.jsx("span",{className:"text-sm",children:v.type==="overlap"?"πŸ”΄":"⚑"}),i.jsx("span",{className:`text-sm font-medium ${v.severity==="high"?"text-red-800":"text-amber-800"}`,children:v.type==="overlap"?"Time Overlap":"Tight Turnaround"})]}),i.jsx("p",{className:`text-sm ${v.severity==="high"?"text-red-700":"text-amber-700"}`,children:v.message})]},N))}),u.currentAssignments.length>0&&u.conflicts.length===0&&i.jsxs("div",{className:"bg-slate-100 rounded-lg p-3",children:[i.jsx("p",{className:"text-sm font-medium text-slate-700 mb-1",children:"Next Assignment:"}),i.jsxs("p",{className:"text-sm text-slate-600",children:[(h=u.currentAssignments[0])==null?void 0:h.title," at ",x((y=u.currentAssignments[0])==null?void 0:y.startTime)]})]})]}),u.conflicts.length>0&&i.jsx("div",{className:"ml-4",children:i.jsx("span",{className:"bg-amber-100 text-amber-800 px-3 py-1 rounded-full text-xs font-bold",children:"⚠️ CONFLICTS"})})]})]},u.driverId)}),e&&i.jsx("button",{onClick:()=>t(""),className:"w-full bg-slate-100 hover:bg-slate-200 text-slate-700 px-4 py-3 rounded-lg font-medium transition-colors border border-slate-200",children:"❌ Clear Driver Assignment"})]}),l&&d&&i.jsx("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-sm flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-white rounded-2xl shadow-2xl border border-slate-200/60 w-full max-w-2xl max-h-[90vh] overflow-y-auto",children:[i.jsxs("div",{className:"bg-gradient-to-r from-amber-50 to-orange-50 px-8 py-6 border-b border-slate-200/60",children:[i.jsx("h3",{className:"text-xl font-bold text-slate-800 flex items-center gap-2",children:"⚠️ Driver Assignment Conflict"}),i.jsxs("p",{className:"text-slate-600 mt-1",children:[i.jsx("strong",{children:d.driverName})," has scheduling conflicts that need your attention"]})]}),i.jsxs("div",{className:"p-8 space-y-6",children:[i.jsx("div",{className:"bg-slate-50 rounded-xl p-4 border border-slate-200",children:i.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[i.jsx("span",{className:"text-2xl",children:"πŸš—"}),i.jsxs("div",{children:[i.jsx("h4",{className:"font-bold text-slate-900",children:d.driverName}),i.jsxs("p",{className:"text-sm text-slate-600",children:["Vehicle Capacity: ",d.vehicleCapacity," passengers β€’ Current Assignments: ",d.assignmentCount]})]})]})}),i.jsxs("div",{children:[i.jsx("h4",{className:"font-bold text-slate-800 mb-3",children:"Scheduling Conflicts:"}),i.jsx("div",{className:"space-y-3",children:d.conflicts.map((u,h)=>i.jsxs("div",{className:`p-4 rounded-xl border ${u.severity==="high"?"bg-red-50 border-red-200":"bg-amber-50 border-amber-200"}`,children:[i.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[i.jsx("span",{className:"text-lg",children:u.type==="overlap"?"πŸ”΄":"⚑"}),i.jsx("span",{className:`font-bold ${u.severity==="high"?"text-red-800":"text-amber-800"}`,children:u.type==="overlap"?"Time Overlap":"Tight Turnaround"})]}),i.jsx("p",{className:`mb-2 ${u.severity==="high"?"text-red-700":"text-amber-700"}`,children:u.message}),i.jsxs("div",{className:"text-sm text-slate-600 bg-white/50 rounded-lg p-2",children:[i.jsx("strong",{children:"Conflicting event:"})," ",u.conflictingEvent.title,i.jsx("br",{}),i.jsx("strong",{children:"Time:"})," ",x(u.conflictingEvent.startTime)," - ",x(u.conflictingEvent.endTime),i.jsx("br",{}),i.jsx("strong",{children:"VIP:"})," ",u.conflictingEvent.vipName]})]},h))})]}),i.jsxs("div",{children:[i.jsx("h4",{className:"font-bold text-slate-800 mb-3",children:"Current Schedule:"}),i.jsx("div",{className:"bg-slate-50 rounded-xl p-4 border border-slate-200",children:d.currentAssignments.length===0?i.jsx("p",{className:"text-slate-500 text-sm",children:"No current assignments"}):i.jsx("div",{className:"space-y-2",children:d.currentAssignments.map((u,h)=>i.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[i.jsx("span",{className:"w-2 h-2 bg-blue-500 rounded-full"}),i.jsx("span",{className:"font-medium",children:u.title}),i.jsxs("span",{className:"text-slate-500",children:["(",x(u.startTime)," - ",x(u.endTime),")"]}),i.jsxs("span",{className:"text-slate-400",children:["β€’ ",u.vipName]})]},h))})})]})]}),i.jsxs("div",{className:"flex justify-end gap-4 p-8 border-t border-slate-200",children:[i.jsx("button",{className:"px-6 py-3 border border-slate-300 text-slate-700 rounded-lg hover:bg-slate-50 transition-colors font-medium",onClick:()=>c(!1),children:"Choose Different Driver"}),i.jsx("button",{className:"bg-gradient-to-r from-red-500 to-red-600 hover:from-red-600 hover:to-red-700 text-white px-6 py-3 rounded-lg font-medium transition-all duration-200 shadow-lg hover:shadow-xl",onClick:j,children:"⚠️ Assign Anyway"})]})]})})]})},Kg=({vipId:e,vipName:t})=>{const[n,r]=S.useState([]),[s,o]=S.useState(!1),[a,l]=S.useState(null),[c,d]=S.useState([]);S.useEffect(()=>{m(),p()},[e]);const m=async()=>{try{const v=localStorage.getItem("authToken"),N=await U(`/api/vips/${e}/schedule`,{headers:{Authorization:`Bearer ${v}`,"Content-Type":"application/json"}});if(N.ok){const k=await N.json();r(k)}}catch(v){console.error("Error fetching schedule:",v)}},p=async()=>{try{const v=localStorage.getItem("authToken"),N=await U("/api/drivers",{headers:{Authorization:`Bearer ${v}`,"Content-Type":"application/json"}});if(N.ok){const k=await N.json();d(k)}}catch(v){console.error("Error fetching drivers:",v)}},f=v=>{const N=c.find(k=>k.id===v);return N?N.name:`Driver ID: ${v}`},g=v=>{switch(v){case"scheduled":return"#3498db";case"in-progress":return"#f39c12";case"completed":return"#2ecc71";case"cancelled":return"#e74c3c";default:return"#95a5a6"}},b=v=>{switch(v){case"transport":return"πŸš—";case"meeting":return"🀝";case"event":return"πŸŽ‰";case"meal":return"🍽️";case"accommodation":return"🏨";default:return"πŸ“…"}},w=v=>{try{const N=new Date(v);if(isNaN(N.getTime()))return"Invalid Time";const k=N.getHours(),C=N.getMinutes(),z=k>=12?"PM":"AM",A=k%12||12,I=C.toString().padStart(2,"0");return`${A}:${I} ${z}`}catch(N){return console.error("Error formatting time:",N,v),"Time Error"}},x=(v=>{const N={};return v.forEach(k=>{const C=new Date(k.startTime).toDateString();N[C]||(N[C]=[]),N[C].push(k)}),Object.keys(N).forEach(k=>{N[k].sort((C,z)=>new Date(C.startTime).getTime()-new Date(z.startTime).getTime())}),N})(n);return i.jsxs("div",{className:"bg-white rounded-2xl shadow-lg border border-slate-200/60 overflow-hidden",children:[i.jsx("div",{className:"bg-gradient-to-r from-purple-50 to-pink-50 px-8 py-6 border-b border-slate-200/60",children:i.jsxs("div",{className:"flex justify-between items-center",children:[i.jsxs("div",{children:[i.jsxs("h2",{className:"text-xl font-bold text-slate-800 flex items-center gap-2",children:["πŸ“… Schedule for ",t]}),i.jsx("p",{className:"text-slate-600 mt-1",children:"Manage daily events and activities"})]}),i.jsx("button",{className:"bg-gradient-to-r from-blue-500 to-blue-600 hover:from-blue-600 hover:to-blue-700 text-white px-6 py-3 rounded-lg font-medium transition-all duration-200 shadow-lg hover:shadow-xl flex items-center gap-2",onClick:()=>o(!0),children:"βž• Add Event"})]})}),i.jsx("div",{className:"p-8",children:Object.keys(x).length===0?i.jsxs("div",{className:"text-center py-12",children:[i.jsx("div",{className:"w-16 h-16 bg-slate-100 rounded-full flex items-center justify-center mx-auto mb-4",children:i.jsx("span",{className:"text-2xl",children:"πŸ“…"})}),i.jsx("p",{className:"text-slate-500 font-medium mb-2",children:"No scheduled events"}),i.jsx("p",{className:"text-slate-400 text-sm",children:'Click "Add Event" to get started with scheduling'})]}):i.jsx("div",{className:"space-y-8",children:Object.entries(x).map(([v,N])=>i.jsxs("div",{className:"space-y-4",children:[i.jsx("div",{className:"bg-gradient-to-r from-slate-600 to-slate-700 text-white px-6 py-3 rounded-xl shadow-lg",children:i.jsx("h3",{className:"text-lg font-bold",children:new Date(v).toLocaleDateString([],{weekday:"long",year:"numeric",month:"long",day:"numeric"})})}),i.jsx("div",{className:"grid gap-4",children:N.map(k=>i.jsx("div",{className:"bg-gradient-to-r from-slate-50 to-slate-100 rounded-xl border border-slate-200/60 p-6 hover:shadow-lg transition-all duration-200",children:i.jsxs("div",{className:"flex items-start gap-6",children:[i.jsx("div",{className:"flex-shrink-0 text-center",children:i.jsxs("div",{className:"bg-white rounded-lg border border-slate-200 p-3 shadow-sm",children:[i.jsx("div",{className:"text-sm font-bold text-slate-900",children:w(k.startTime)}),i.jsx("div",{className:"text-xs text-slate-500 mt-1",children:"to"}),i.jsx("div",{className:"text-sm font-bold text-slate-900",children:w(k.endTime)})]})}),i.jsxs("div",{className:"flex-1",children:[i.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[i.jsx("span",{className:"text-2xl",children:b(k.type)}),i.jsx("h4",{className:"text-lg font-bold text-slate-900",children:k.title}),i.jsx("span",{className:"px-3 py-1 rounded-full text-xs font-bold text-white shadow-sm",style:{backgroundColor:g(k.status)},children:k.status.toUpperCase()})]}),i.jsxs("div",{className:"flex items-center gap-2 text-slate-600 mb-2",children:[i.jsx("span",{children:"πŸ“"}),i.jsx("span",{className:"font-medium",children:k.location})]}),k.description&&i.jsx("div",{className:"text-slate-600 mb-3 bg-white/50 rounded-lg p-3 border border-slate-200/50",children:k.description}),k.assignedDriverId?i.jsxs("div",{className:"flex items-center gap-2 text-slate-600 mb-4",children:[i.jsx("span",{children:"πŸ‘€"}),i.jsxs("span",{className:"font-medium",children:["Driver: ",f(k.assignedDriverId)]})]}):i.jsxs("div",{className:"bg-amber-50 border border-amber-200 rounded-lg p-3 mb-4",children:[i.jsxs("div",{className:"flex items-center gap-2 text-amber-800 mb-2",children:[i.jsx("span",{children:"⚠️"}),i.jsx("span",{className:"font-medium text-sm",children:"No Driver Assigned"})]}),i.jsx("p",{className:"text-amber-700 text-xs mb-2",children:"This event needs a driver to ensure VIP transportation"}),i.jsx("button",{className:"bg-gradient-to-r from-amber-500 to-orange-500 hover:from-amber-600 hover:to-orange-600 text-white px-3 py-1 rounded-lg text-xs font-medium transition-all duration-200 shadow-sm hover:shadow-md",onClick:()=>l(k),children:"πŸš— Assign Driver"})]}),i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("button",{className:"bg-gradient-to-r from-slate-500 to-slate-600 hover:from-slate-600 hover:to-slate-700 text-white px-4 py-2 rounded-lg text-sm font-medium transition-all duration-200 shadow-lg hover:shadow-xl",onClick:()=>l(k),children:"✏️ Edit"}),k.status==="scheduled"&&i.jsx("button",{className:"bg-gradient-to-r from-amber-500 to-orange-500 hover:from-amber-600 hover:to-orange-600 text-white px-4 py-2 rounded-lg text-sm font-medium transition-all duration-200 shadow-lg hover:shadow-xl",onClick:()=>y(k.id,"in-progress"),children:"▢️ Start"}),k.status==="in-progress"&&i.jsx("button",{className:"bg-gradient-to-r from-green-500 to-green-600 hover:from-green-600 hover:to-green-700 text-white px-4 py-2 rounded-lg text-sm font-medium transition-all duration-200 shadow-lg hover:shadow-xl",onClick:()=>y(k.id,"completed"),children:"βœ… Complete"}),k.status==="completed"&&i.jsx("span",{className:"bg-green-100 text-green-800 px-3 py-1 rounded-full text-xs font-medium",children:"βœ… Completed"})]})]})]})},k.id))})]},v))})}),s&&i.jsx(Cc,{vipId:e,onSubmit:u,onCancel:()=>o(!1)}),a&&i.jsx(Cc,{vipId:e,event:a,onSubmit:h,onCancel:()=>l(null)})]});async function u(v){try{const N=localStorage.getItem("authToken"),k=await U(`/api/vips/${e}/schedule`,{method:"POST",headers:{Authorization:`Bearer ${N}`,"Content-Type":"application/json"},body:JSON.stringify(v)});if(k.ok)await m(),o(!1);else throw await k.json()}catch(N){throw console.error("Error adding event:",N),N}}async function h(v){try{const N=localStorage.getItem("authToken"),k=await U(`/api/vips/${e}/schedule/${v.id}`,{method:"PUT",headers:{Authorization:`Bearer ${N}`,"Content-Type":"application/json"},body:JSON.stringify(v)});if(k.ok)await m(),l(null);else throw await k.json()}catch(N){throw console.error("Error updating event:",N),N}}async function y(v,N){try{const k=localStorage.getItem("authToken");(await U(`/api/vips/${e}/schedule/${v}/status`,{method:"PATCH",headers:{Authorization:`Bearer ${k}`,"Content-Type":"application/json"},body:JSON.stringify({status:N})})).ok&&await m()}catch(k){console.error("Error updating event status:",k)}}},Cc=({vipId:e,event:t,onSubmit:n,onCancel:r})=>{var b,w;const[s,o]=S.useState({title:(t==null?void 0:t.title)||"",location:(t==null?void 0:t.location)||"",startTime:((b=t==null?void 0:t.startTime)==null?void 0:b.slice(0,16))||"",endTime:((w=t==null?void 0:t.endTime)==null?void 0:w.slice(0,16))||"",description:(t==null?void 0:t.description)||"",type:(t==null?void 0:t.type)||"event",assignedDriverId:(t==null?void 0:t.assignedDriverId)||""}),[a,l]=S.useState([]),[c,d]=S.useState([]),[m,p]=S.useState(!1),f=async j=>{j.preventDefault(),p(!0),l([]),d([]);try{await n({...s,id:t==null?void 0:t.id,startTime:new Date(s.startTime).toISOString(),endTime:new Date(s.endTime).toISOString(),status:(t==null?void 0:t.status)||"scheduled"})}catch(x){x.validationErrors&&l(x.validationErrors),x.warnings&&d(x.warnings)}finally{p(!1)}},g=j=>{const{name:x,value:u}=j.target;o(h=>({...h,[x]:u}))};return i.jsx("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-sm flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-white rounded-2xl shadow-2xl border border-slate-200/60 w-full max-w-2xl max-h-[90vh] overflow-y-auto",children:[i.jsxs("div",{className:"bg-gradient-to-r from-blue-50 to-indigo-50 px-8 py-6 border-b border-slate-200/60",children:[i.jsx("h2",{className:"text-xl font-bold text-slate-800",children:t?"✏️ Edit Event":"βž• Add New Event"}),i.jsx("p",{className:"text-slate-600 mt-1",children:t?"Update event details":"Create a new schedule event"})]}),i.jsxs("form",{onSubmit:f,className:"p-8 space-y-6",children:[a.length>0&&i.jsxs("div",{className:"bg-red-50 border border-red-200 rounded-xl p-4",children:[i.jsx("h4",{className:"text-red-800 font-semibold mb-2",children:"❌ Validation Errors:"}),i.jsx("ul",{className:"text-red-700 space-y-1",children:a.map((j,x)=>i.jsxs("li",{className:"text-sm",children:["β€’ ",j.message]},x))})]}),c.length>0&&i.jsxs("div",{className:"bg-amber-50 border border-amber-200 rounded-xl p-4",children:[i.jsx("h4",{className:"text-amber-800 font-semibold mb-2",children:"⚠️ Warnings:"}),i.jsx("ul",{className:"text-amber-700 space-y-1",children:c.map((j,x)=>i.jsxs("li",{className:"text-sm",children:["β€’ ",j.message]},x))})]}),i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[i.jsxs("div",{className:"md:col-span-2",children:[i.jsx("label",{htmlFor:"title",className:"block text-sm font-medium text-slate-700 mb-2",children:"Event Title"}),i.jsx("input",{type:"text",id:"title",name:"title",value:s.title,onChange:g,className:"w-full px-4 py-3 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition-colors",placeholder:"Enter event title",required:!0})]}),i.jsxs("div",{children:[i.jsx("label",{htmlFor:"type",className:"block text-sm font-medium text-slate-700 mb-2",children:"Event Type"}),i.jsxs("select",{id:"type",name:"type",value:s.type,onChange:g,className:"w-full px-4 py-3 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition-colors",required:!0,children:[i.jsx("option",{value:"transport",children:"πŸš— Transport"}),i.jsx("option",{value:"meeting",children:"🀝 Meeting"}),i.jsx("option",{value:"event",children:"πŸŽ‰ Event"}),i.jsx("option",{value:"meal",children:"🍽️ Meal"}),i.jsx("option",{value:"accommodation",children:"🏨 Accommodation"})]})]}),i.jsxs("div",{children:[i.jsx("label",{htmlFor:"location",className:"block text-sm font-medium text-slate-700 mb-2",children:"Location"}),i.jsx("input",{type:"text",id:"location",name:"location",value:s.location,onChange:g,className:"w-full px-4 py-3 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition-colors",placeholder:"Enter location",required:!0})]}),i.jsxs("div",{children:[i.jsx("label",{htmlFor:"startTime",className:"block text-sm font-medium text-slate-700 mb-2",children:"Start Time"}),i.jsx("input",{type:"datetime-local",id:"startTime",name:"startTime",value:s.startTime,onChange:g,className:"w-full px-4 py-3 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition-colors",required:!0})]}),i.jsxs("div",{children:[i.jsx("label",{htmlFor:"endTime",className:"block text-sm font-medium text-slate-700 mb-2",children:"End Time"}),i.jsx("input",{type:"datetime-local",id:"endTime",name:"endTime",value:s.endTime,onChange:g,className:"w-full px-4 py-3 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition-colors",required:!0})]}),i.jsxs("div",{className:"md:col-span-2",children:[i.jsx("label",{htmlFor:"description",className:"block text-sm font-medium text-slate-700 mb-2",children:"Description"}),i.jsx("textarea",{id:"description",name:"description",value:s.description,onChange:g,rows:3,className:"w-full px-4 py-3 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition-colors",placeholder:"Enter event description (optional)"})]}),i.jsx("div",{className:"md:col-span-2",children:i.jsx(Bg,{selectedDriverId:s.assignedDriverId,onDriverSelect:j=>o(x=>({...x,assignedDriverId:j})),eventTime:{startTime:s.startTime?new Date(s.startTime).toISOString():"",endTime:s.endTime?new Date(s.endTime).toISOString():"",location:s.location}})})]}),i.jsxs("div",{className:"flex justify-end gap-4 pt-6 border-t border-slate-200",children:[i.jsx("button",{type:"button",className:"px-6 py-3 border border-slate-300 text-slate-700 rounded-lg hover:bg-slate-50 transition-colors font-medium",onClick:r,disabled:m,children:"Cancel"}),i.jsx("button",{type:"submit",className:"bg-gradient-to-r from-blue-500 to-blue-600 hover:from-blue-600 hover:to-blue-700 text-white px-6 py-3 rounded-lg font-medium transition-all duration-200 shadow-lg hover:shadow-xl disabled:opacity-50 disabled:cursor-not-allowed",disabled:m,children:m?i.jsxs("span",{className:"flex items-center gap-2",children:[i.jsx("div",{className:"w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin"}),t?"Updating...":"Creating..."]}):t?"✏️ Update Event":"βž• Create Event"})]})]})]})})},Hg=()=>{const{id:e}=dh(),[t,n]=S.useState(null),[r,s]=S.useState(!0),[o,a]=S.useState(null),[l,c]=S.useState([]);S.useEffect(()=>{e&&(async()=>{try{const g=localStorage.getItem("authToken"),b=await U("/api/vips",{headers:{Authorization:`Bearer ${g}`,"Content-Type":"application/json"}});if(b.ok){const j=(await b.json()).find(x=>x.id===e);j?n(j):a("VIP not found")}else a("Failed to fetch VIP data")}catch{a("Error loading VIP data")}finally{s(!1)}})()},[e]),S.useEffect(()=>{(async()=>{if(t)try{const g=localStorage.getItem("authToken"),b=await U(`/api/vips/${t.id}/schedule`,{headers:{Authorization:`Bearer ${g}`,"Content-Type":"application/json"}});if(b.ok){const w=await b.json();c(w)}}catch(g){console.error("Error fetching schedule:",g)}})()},[t]),S.useEffect(()=>{t&&window.location.hash==="#schedule"&&setTimeout(()=>{const f=document.getElementById("schedule-section");f&&f.scrollIntoView({behavior:"smooth"})},100)},[t]);const d=()=>{if(!t)return null;if(t.transportMode==="flight"){if(t.flights&&t.flights.length>0)return{flights:t.flights,primaryFlight:t.flights[0]};if(t.flightNumber)return{flights:[{flightNumber:t.flightNumber,flightDate:t.flightDate||"",segment:1}],primaryFlight:{flightNumber:t.flightNumber,flightDate:t.flightDate||"",segment:1}}}return null},m=()=>{if(!t)return;const f=window.open("","_blank");if(!f)return;const g=h=>{const y={};return h.forEach(v=>{const N=new Date(v.startTime).toDateString();y[N]||(y[N]=[]),y[N].push(v)}),Object.keys(y).forEach(v=>{y[v].sort((N,k)=>new Date(N.startTime).getTime()-new Date(k.startTime).getTime())}),y},b=h=>new Date(h).toLocaleString([],{hour:"2-digit",minute:"2-digit"}),w=h=>{switch(h){case"transport":return"πŸš—";case"meeting":return"🀝";case"event":return"πŸŽ‰";case"meal":return"🍽️";case"accommodation":return"🏨";default:return"πŸ“…"}},j=g(l),x=d(),u=` VIP Schedule - ${t.name}

πŸ“… VIP Schedule

${t.name}

Organization: ${t.organization}

${t.transportMode==="flight"&&x?`

Flight Information: ${x.flights.map(h=>h.flightNumber).join(" β†’ ")}

Flight Date: ${x.primaryFlight.flightDate?new Date(x.primaryFlight.flightDate).toLocaleDateString():"TBD"}

`:t.transportMode==="self-driving"?`

Transport Mode: πŸš— Self-Driving

Expected Arrival: ${t.expectedArrival?new Date(t.expectedArrival).toLocaleString():"TBD"}

`:""}

Airport Pickup: ${t.needsAirportPickup?"βœ… Required":"❌ Not Required"}

Venue Transport: ${t.needsVenueTransport?"βœ… Required":"❌ Not Required"}

${t.notes?`

Special Notes: ${t.notes}

`:""}
${Object.entries(j).map(([h,y])=>`
${new Date(h).toLocaleDateString([],{weekday:"long",year:"numeric",month:"long",day:"numeric"})}
${y.map(v=>`
${b(v.startTime)}
to
${b(v.endTime)}
${w(v.type)} ${v.title} ${v.status}
πŸ“ ${v.location}
${v.description?`
${v.description}
`:""} ${v.assignedDriverId?`
πŸ‘€ Driver: ${v.assignedDriverId}
`:""}
`).join("")}
`).join("")}
`;f.document.write(u),f.document.close(),f.focus(),setTimeout(()=>{f.print(),f.close()},250)};if(r)return i.jsx("div",{children:"Loading VIP details..."});if(o||!t)return i.jsxs("div",{children:[i.jsx("h1",{children:"Error"}),i.jsx("p",{children:o||"VIP not found"}),i.jsx(we,{to:"/vips",className:"btn",children:"Back to VIP List"})]});const p=d();return i.jsxs("div",{className:"space-y-8",children:[i.jsx("div",{className:"bg-white rounded-2xl shadow-lg p-8 border border-slate-200/60",children:i.jsxs("div",{className:"flex justify-between items-center",children:[i.jsxs("div",{children:[i.jsxs("h1",{className:"text-3xl font-bold bg-gradient-to-r from-slate-800 to-slate-600 bg-clip-text text-transparent",children:["VIP Details: ",t.name]}),i.jsx("p",{className:"text-slate-600 mt-2",children:"Complete profile and schedule management"})]}),i.jsxs("div",{className:"flex items-center space-x-4",children:[i.jsx("button",{className:"bg-gradient-to-r from-purple-500 to-purple-600 hover:from-purple-600 hover:to-purple-700 text-white px-6 py-3 rounded-lg font-medium transition-all duration-200 shadow-lg hover:shadow-xl flex items-center gap-2",onClick:m,children:"πŸ–¨οΈ Print Schedule"}),i.jsx(we,{to:"/vips",className:"bg-gradient-to-r from-slate-500 to-slate-600 hover:from-slate-600 hover:to-slate-700 text-white px-6 py-3 rounded-lg font-medium transition-all duration-200 shadow-lg hover:shadow-xl",children:"Back to VIP List"})]})]})}),i.jsxs("div",{className:"bg-white rounded-2xl shadow-lg border border-slate-200/60 overflow-hidden",children:[i.jsxs("div",{className:"bg-gradient-to-r from-blue-50 to-indigo-50 px-8 py-6 border-b border-slate-200/60",children:[i.jsx("h2",{className:"text-xl font-bold text-slate-800 flex items-center gap-2",children:"πŸ“‹ VIP Information"}),i.jsx("p",{className:"text-slate-600 mt-1",children:"Personal details and travel arrangements"})]}),i.jsxs("div",{className:"p-8",children:[i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[i.jsxs("div",{className:"bg-slate-50 rounded-xl p-4 border border-slate-200/60",children:[i.jsx("div",{className:"text-sm font-medium text-slate-500 mb-1",children:"Name"}),i.jsx("div",{className:"text-lg font-bold text-slate-900",children:t.name})]}),i.jsxs("div",{className:"bg-slate-50 rounded-xl p-4 border border-slate-200/60",children:[i.jsx("div",{className:"text-sm font-medium text-slate-500 mb-1",children:"Organization"}),i.jsx("div",{className:"text-lg font-bold text-slate-900",children:t.organization})]}),t.transportMode==="flight"&&p?i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"bg-blue-50 rounded-xl p-4 border border-blue-200/60",children:[i.jsxs("div",{className:"text-sm font-medium text-blue-600 mb-1",children:["Flight",p.flights.length>1?"s":""]}),i.jsx("div",{className:"text-lg font-bold text-blue-900",children:p.flights.map(f=>f.flightNumber).join(" β†’ ")})]}),i.jsxs("div",{className:"bg-blue-50 rounded-xl p-4 border border-blue-200/60",children:[i.jsx("div",{className:"text-sm font-medium text-blue-600 mb-1",children:"Flight Date"}),i.jsx("div",{className:"text-lg font-bold text-blue-900",children:p.primaryFlight.flightDate?new Date(p.primaryFlight.flightDate).toLocaleDateString():"TBD"})]})]}):t.transportMode==="self-driving"?i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"bg-green-50 rounded-xl p-4 border border-green-200/60",children:[i.jsx("div",{className:"text-sm font-medium text-green-600 mb-1",children:"Transport Mode"}),i.jsx("div",{className:"text-lg font-bold text-green-900 flex items-center gap-2",children:"πŸš— Self-Driving"})]}),i.jsxs("div",{className:"bg-green-50 rounded-xl p-4 border border-green-200/60",children:[i.jsx("div",{className:"text-sm font-medium text-green-600 mb-1",children:"Expected Arrival"}),i.jsx("div",{className:"text-lg font-bold text-green-900",children:t.expectedArrival?new Date(t.expectedArrival).toLocaleString():"TBD"})]})]}):null,i.jsxs("div",{className:`rounded-xl p-4 border ${t.needsAirportPickup?"bg-green-50 border-green-200/60":"bg-red-50 border-red-200/60"}`,children:[i.jsx("div",{className:`text-sm font-medium mb-1 ${t.needsAirportPickup?"text-green-600":"text-red-600"}`,children:"Airport Pickup"}),i.jsx("div",{className:`text-lg font-bold flex items-center gap-2 ${t.needsAirportPickup?"text-green-900":"text-red-900"}`,children:t.needsAirportPickup?"βœ… Required":"❌ Not Required"})]}),i.jsxs("div",{className:`rounded-xl p-4 border ${t.needsVenueTransport?"bg-green-50 border-green-200/60":"bg-red-50 border-red-200/60"}`,children:[i.jsx("div",{className:`text-sm font-medium mb-1 ${t.needsVenueTransport?"text-green-600":"text-red-600"}`,children:"Venue Transport"}),i.jsx("div",{className:`text-lg font-bold flex items-center gap-2 ${t.needsVenueTransport?"text-green-900":"text-red-900"}`,children:t.needsVenueTransport?"βœ… Required":"❌ Not Required"})]})]}),t.notes&&i.jsxs("div",{className:"mt-6",children:[i.jsx("div",{className:"text-sm font-medium text-slate-500 mb-2",children:"Special Notes"}),i.jsx("div",{className:"bg-amber-50 border border-amber-200 rounded-xl p-4",children:i.jsx("p",{className:"text-amber-800",children:t.notes})})]}),t.assignedDriverIds&&t.assignedDriverIds.length>0&&i.jsxs("div",{className:"mt-6",children:[i.jsx("div",{className:"text-sm font-medium text-slate-500 mb-2",children:"Assigned Drivers"}),i.jsx("div",{className:"flex flex-wrap gap-2",children:t.assignedDriverIds.map(f=>i.jsxs("span",{className:"bg-gradient-to-r from-blue-500 to-blue-600 text-white px-4 py-2 rounded-full text-sm font-medium flex items-center gap-2",children:["πŸ‘€ ",f]},f))})]})]})]}),t.transportMode==="flight"&&p&&i.jsxs("div",{className:"bg-white rounded-2xl shadow-lg border border-slate-200/60 overflow-hidden",children:[i.jsxs("div",{className:"bg-gradient-to-r from-sky-50 to-blue-50 px-8 py-6 border-b border-slate-200/60",children:[i.jsx("h2",{className:"text-xl font-bold text-slate-800 flex items-center gap-2",children:"✈️ Flight Information"}),i.jsx("p",{className:"text-slate-600 mt-1",children:"Real-time flight status and details"})]}),i.jsx("div",{className:"p-8 space-y-6",children:p.flights.map((f,g)=>i.jsxs("div",{className:"bg-slate-50 rounded-xl p-6 border border-slate-200/60",children:[i.jsxs("h3",{className:"text-lg font-bold text-slate-900 mb-4",children:[g===0?"Primary Flight":`Connecting Flight ${g}`,": ",f.flightNumber]}),i.jsx(ph,{flightNumber:f.flightNumber,flightDate:f.flightDate})]},g))})]}),i.jsx("div",{id:"schedule-section",children:i.jsx(Kg,{vipId:t.id,vipName:t.name})})]})},Gg=({onSubmit:e,onCancel:t})=>{const[n,r]=S.useState({name:"",phone:"",vehicleCapacity:4}),s=a=>{a.preventDefault(),e(n)},o=a=>{const{name:l,value:c,type:d}=a.target;r(m=>({...m,[l]:d==="number"||l==="vehicleCapacity"?parseInt(c)||0:c}))};return i.jsx("div",{className:"modal-overlay",children:i.jsxs("div",{className:"modal-content",children:[i.jsxs("div",{className:"modal-header",children:[i.jsx("h2",{className:"text-2xl font-bold text-slate-800",children:"Add New Driver"}),i.jsx("p",{className:"text-slate-600 mt-2",children:"Enter driver contact information"})]}),i.jsx("div",{className:"modal-body",children:i.jsxs("form",{onSubmit:s,className:"space-y-6",children:[i.jsxs("div",{className:"form-group",children:[i.jsx("label",{htmlFor:"name",className:"form-label",children:"Driver Name *"}),i.jsx("input",{type:"text",id:"name",name:"name",value:n.name,onChange:o,className:"form-input",placeholder:"Enter driver's full name",required:!0})]}),i.jsxs("div",{className:"form-group",children:[i.jsx("label",{htmlFor:"phone",className:"form-label",children:"Phone Number *"}),i.jsx("input",{type:"tel",id:"phone",name:"phone",value:n.phone,onChange:o,className:"form-input",placeholder:"Enter phone number",required:!0})]}),i.jsxs("div",{className:"form-group",children:[i.jsx("label",{htmlFor:"vehicleCapacity",className:"form-label",children:"Vehicle Capacity *"}),i.jsxs("select",{id:"vehicleCapacity",name:"vehicleCapacity",value:n.vehicleCapacity,onChange:o,className:"form-input",required:!0,children:[i.jsx("option",{value:2,children:"2 passengers (Sedan/Coupe)"}),i.jsx("option",{value:4,children:"4 passengers (Standard Car)"}),i.jsx("option",{value:6,children:"6 passengers (SUV/Van)"}),i.jsx("option",{value:8,children:"8 passengers (Large Van)"}),i.jsx("option",{value:12,children:"12 passengers (Mini Bus)"})]}),i.jsx("p",{className:"text-sm text-slate-600 mt-1",children:"πŸš— Select the maximum number of passengers this vehicle can accommodate"})]}),i.jsxs("div",{className:"form-actions",children:[i.jsx("button",{type:"button",className:"btn btn-secondary",onClick:t,children:"Cancel"}),i.jsx("button",{type:"submit",className:"btn btn-primary",children:"Add Driver"})]})]})})]})})},Zg=({driver:e,onSubmit:t,onCancel:n})=>{const[r,s]=S.useState({name:e.name,phone:e.phone,vehicleCapacity:e.vehicleCapacity||4,currentLocation:{lat:e.currentLocation.lat,lng:e.currentLocation.lng}}),o=l=>{l.preventDefault(),t({...r,id:e.id})},a=l=>{const{name:c,value:d,type:m}=l.target;s(c==="lat"||c==="lng"?p=>({...p,currentLocation:{...p.currentLocation,[c]:parseFloat(d)||0}}):c==="vehicleCapacity"?p=>({...p,[c]:parseInt(d)||0}):p=>({...p,[c]:d}))};return i.jsx("div",{className:"modal-overlay",children:i.jsxs("div",{className:"modal-content",children:[i.jsxs("div",{className:"modal-header",children:[i.jsx("h2",{className:"text-2xl font-bold text-slate-800",children:"Edit Driver"}),i.jsxs("p",{className:"text-slate-600 mt-2",children:["Update driver information for ",e.name]})]}),i.jsx("div",{className:"modal-body",children:i.jsxs("form",{onSubmit:o,className:"space-y-8",children:[i.jsxs("div",{className:"form-section",children:[i.jsx("div",{className:"form-section-header",children:i.jsx("h3",{className:"form-section-title",children:"Basic Information"})}),i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[i.jsxs("div",{className:"form-group",children:[i.jsx("label",{htmlFor:"name",className:"form-label",children:"Driver Name *"}),i.jsx("input",{type:"text",id:"name",name:"name",value:r.name,onChange:a,className:"form-input",placeholder:"Enter driver's full name",required:!0})]}),i.jsxs("div",{className:"form-group",children:[i.jsx("label",{htmlFor:"phone",className:"form-label",children:"Phone Number *"}),i.jsx("input",{type:"tel",id:"phone",name:"phone",value:r.phone,onChange:a,className:"form-input",placeholder:"Enter phone number",required:!0})]})]}),i.jsxs("div",{className:"form-group",children:[i.jsx("label",{htmlFor:"vehicleCapacity",className:"form-label",children:"Vehicle Capacity *"}),i.jsxs("select",{id:"vehicleCapacity",name:"vehicleCapacity",value:r.vehicleCapacity,onChange:a,className:"form-input",required:!0,children:[i.jsx("option",{value:2,children:"2 passengers (Sedan/Coupe)"}),i.jsx("option",{value:4,children:"4 passengers (Standard Car)"}),i.jsx("option",{value:6,children:"6 passengers (SUV/Van)"}),i.jsx("option",{value:8,children:"8 passengers (Large Van)"}),i.jsx("option",{value:12,children:"12 passengers (Mini Bus)"})]}),i.jsx("p",{className:"text-sm text-slate-600 mt-1",children:"πŸš— Select the maximum number of passengers this vehicle can accommodate"})]})]}),i.jsxs("div",{className:"form-section",children:[i.jsx("div",{className:"form-section-header",children:i.jsx("h3",{className:"form-section-title",children:"Current Location"})}),i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[i.jsxs("div",{className:"form-group",children:[i.jsx("label",{htmlFor:"lat",className:"form-label",children:"Latitude *"}),i.jsx("input",{type:"number",id:"lat",name:"lat",value:r.currentLocation.lat,onChange:a,className:"form-input",placeholder:"Enter latitude",step:"any",required:!0})]}),i.jsxs("div",{className:"form-group",children:[i.jsx("label",{htmlFor:"lng",className:"form-label",children:"Longitude *"}),i.jsx("input",{type:"number",id:"lng",name:"lng",value:r.currentLocation.lng,onChange:a,className:"form-input",placeholder:"Enter longitude",step:"any",required:!0})]})]}),i.jsxs("div",{className:"mt-4 p-4 bg-blue-50 border border-blue-200 rounded-lg",children:[i.jsxs("p",{className:"text-sm text-blue-700",children:[i.jsx("strong",{children:"Current coordinates:"})," ",r.currentLocation.lat.toFixed(6),", ",r.currentLocation.lng.toFixed(6)]}),i.jsx("p",{className:"text-xs text-blue-600 mt-1",children:"You can use GPS coordinates or get them from a mapping service"})]})]}),i.jsxs("div",{className:"form-actions",children:[i.jsx("button",{type:"button",className:"btn btn-secondary",onClick:n,children:"Cancel"}),i.jsx("button",{type:"submit",className:"btn btn-primary",children:"Update Driver"})]})]})})]})})},Jg=()=>{const[e,t]=S.useState([]),[n,r]=S.useState(!0),[s,o]=S.useState(!1),[a,l]=S.useState(null),c=g=>{const b=g.trim().split(" ");return b[b.length-1].toLowerCase()},d=g=>[...g].sort((b,w)=>{const j=c(b.name),x=c(w.name);return j.localeCompare(x)});S.useEffect(()=>{(async()=>{try{const b=localStorage.getItem("authToken"),w=await U("/api/drivers",{headers:{Authorization:`Bearer ${b}`,"Content-Type":"application/json"}});if(w.ok){const j=await w.json(),x=d(j);t(x)}else console.error("Failed to fetch drivers:",w.status)}catch(b){console.error("Error fetching drivers:",b)}finally{r(!1)}})()},[]);const m=async g=>{try{const b=localStorage.getItem("authToken"),w=await U("/api/drivers",{method:"POST",headers:{Authorization:`Bearer ${b}`,"Content-Type":"application/json"},body:JSON.stringify(g)});if(w.ok){const j=await w.json();t(x=>d([...x,j])),o(!1)}else console.error("Failed to add driver:",w.status)}catch(b){console.error("Error adding driver:",b)}},p=async g=>{try{const b=localStorage.getItem("authToken"),w=await U(`/api/drivers/${g.id}`,{method:"PUT",headers:{Authorization:`Bearer ${b}`,"Content-Type":"application/json"},body:JSON.stringify(g)});if(w.ok){const j=await w.json();t(x=>d(x.map(u=>u.id===j.id?j:u))),l(null)}else console.error("Failed to update driver:",w.status)}catch(b){console.error("Error updating driver:",b)}},f=async g=>{if(confirm("Are you sure you want to delete this driver?"))try{const b=localStorage.getItem("authToken"),w=await U(`/api/drivers/${g}`,{method:"DELETE",headers:{Authorization:`Bearer ${b}`,"Content-Type":"application/json"}});w.ok?t(j=>j.filter(x=>x.id!==g)):console.error("Failed to delete driver:",w.status)}catch(b){console.error("Error deleting driver:",b)}};return n?i.jsx("div",{className:"flex justify-center items-center min-h-64",children:i.jsxs("div",{className:"bg-white rounded-2xl shadow-lg p-8 flex items-center space-x-4",children:[i.jsx("div",{className:"w-8 h-8 border-4 border-blue-600 border-t-transparent rounded-full animate-spin"}),i.jsx("span",{className:"text-lg font-medium text-slate-700",children:"Loading drivers..."})]})}):i.jsxs("div",{className:"space-y-8",children:[i.jsx("div",{className:"bg-white rounded-2xl shadow-lg p-8 border border-slate-200/60",children:i.jsxs("div",{className:"flex justify-between items-center",children:[i.jsxs("div",{children:[i.jsx("h1",{className:"text-3xl font-bold bg-gradient-to-r from-slate-800 to-slate-600 bg-clip-text text-transparent",children:"Driver Management"}),i.jsx("p",{className:"text-slate-600 mt-2",children:"Manage driver profiles and assignments"})]}),i.jsxs("div",{className:"flex items-center space-x-4",children:[i.jsxs("div",{className:"bg-gradient-to-r from-green-500 to-green-600 text-white px-4 py-2 rounded-lg text-sm font-medium",children:[e.length," Active Drivers"]}),i.jsx("button",{className:"btn btn-primary",onClick:()=>o(!0),children:"Add New Driver"})]})]})}),e.length===0?i.jsxs("div",{className:"bg-white rounded-2xl shadow-lg p-12 border border-slate-200/60 text-center",children:[i.jsx("div",{className:"w-16 h-16 bg-slate-100 rounded-full flex items-center justify-center mx-auto mb-4",children:i.jsx("div",{className:"w-8 h-8 bg-slate-300 rounded-full"})}),i.jsx("h3",{className:"text-lg font-semibold text-slate-800 mb-2",children:"No Drivers Found"}),i.jsx("p",{className:"text-slate-600 mb-6",children:"Get started by adding your first driver"}),i.jsx("button",{className:"btn btn-primary",onClick:()=>o(!0),children:"Add New Driver"})]}):i.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:e.map(g=>i.jsx("div",{className:"bg-white rounded-2xl shadow-lg border border-slate-200/60 overflow-hidden hover:shadow-xl transition-shadow duration-200",children:i.jsxs("div",{className:"p-6",children:[i.jsxs("div",{className:"flex items-center justify-between mb-4",children:[i.jsx("h3",{className:"text-xl font-bold text-slate-900",children:g.name}),i.jsx("div",{className:"w-10 h-10 bg-gradient-to-br from-green-400 to-green-600 rounded-full flex items-center justify-center",children:i.jsx("span",{className:"text-white text-sm font-bold",children:g.name.charAt(0).toUpperCase()})})]}),i.jsxs("div",{className:"space-y-3 mb-6",children:[i.jsxs("div",{className:"bg-slate-50 rounded-lg p-3",children:[i.jsx("div",{className:"text-sm font-medium text-slate-700 mb-1",children:"Contact"}),i.jsx("div",{className:"text-slate-600",children:g.phone})]}),i.jsxs("div",{className:"bg-slate-50 rounded-lg p-3",children:[i.jsx("div",{className:"text-sm font-medium text-slate-700 mb-1",children:"Current Location"}),i.jsxs("div",{className:"text-slate-600 text-sm",children:[g.currentLocation.lat.toFixed(4),", ",g.currentLocation.lng.toFixed(4)]})]}),i.jsxs("div",{className:"bg-slate-50 rounded-lg p-3",children:[i.jsx("div",{className:"text-sm font-medium text-slate-700 mb-1",children:"Vehicle Capacity"}),i.jsxs("div",{className:"flex items-center gap-2 text-slate-600",children:[i.jsx("span",{children:"πŸš—"}),i.jsxs("span",{className:"font-medium",children:[g.vehicleCapacity||4," passengers"]})]})]}),i.jsxs("div",{className:"bg-slate-50 rounded-lg p-3",children:[i.jsx("div",{className:"text-sm font-medium text-slate-700 mb-1",children:"Assignments"}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("span",{className:"bg-blue-100 text-blue-800 text-xs font-medium px-2 py-1 rounded-full",children:[g.assignedVipIds.length," VIPs"]}),i.jsx("span",{className:`text-xs font-medium px-2 py-1 rounded-full ${g.assignedVipIds.length===0?"bg-green-100 text-green-800":"bg-amber-100 text-amber-800"}`,children:g.assignedVipIds.length===0?"Available":"Assigned"})]})]})]}),i.jsxs("div",{className:"space-y-3",children:[i.jsx(we,{to:`/drivers/${g.id}`,className:"bg-gradient-to-r from-green-500 to-green-600 hover:from-green-600 hover:to-green-700 text-white px-4 py-2 rounded-lg text-sm font-medium transition-all duration-200 shadow-sm hover:shadow-md w-full text-center block",children:"View Dashboard"}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx("button",{className:"bg-gradient-to-r from-slate-500 to-slate-600 hover:from-slate-600 hover:to-slate-700 text-white px-3 py-2 rounded-lg text-xs font-medium transition-all duration-200 shadow-sm hover:shadow-md flex-1",onClick:()=>l(g),children:"Edit"}),i.jsx("button",{className:"bg-gradient-to-r from-red-500 to-red-600 hover:from-red-600 hover:to-red-700 text-white px-3 py-2 rounded-lg text-xs font-medium transition-all duration-200 shadow-sm hover:shadow-md flex-1",onClick:()=>f(g.id),children:"Delete"})]})]})]})},g.id))}),s&&i.jsx(Gg,{onSubmit:m,onCancel:()=>o(!1)}),a&&i.jsx(Zg,{driver:a,onSubmit:p,onCancel:()=>l(null)})]})},Xg=({events:e,driverName:t})=>{const n=f=>{switch(f){case"transport":return"#3498db";case"meeting":return"#9b59b6";case"event":return"#e74c3c";case"meal":return"#f39c12";case"accommodation":return"#2ecc71";default:return"#95a5a6"}},r=f=>{switch(f){case"completed":return .5;case"cancelled":return .3;case"in-progress":return 1;case"scheduled":return .8;default:return .8}},s=f=>{switch(f){case"transport":return"πŸš—";case"meeting":return"🀝";case"event":return"πŸŽ‰";case"meal":return"🍽️";case"accommodation":return"🏨";default:return"πŸ“…"}},o=f=>new Date(f).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),a=()=>{if(e.length===0)return{start:new Date,end:new Date};const f=e.flatMap(x=>[new Date(x.startTime),new Date(x.endTime)]),g=new Date(Math.min(...f.map(x=>x.getTime()))),b=new Date(Math.max(...f.map(x=>x.getTime()))),w=new Date(g.getTime()-30*60*1e3),j=new Date(b.getTime()+30*60*1e3);return{start:w,end:j}},l=(f,g)=>{const b=g.end.getTime()-g.start.getTime(),w=new Date(f.startTime),j=new Date(f.endTime),x=w.getTime()-g.start.getTime(),u=j.getTime()-w.getTime(),h=x/b*100,y=u/b*100;return{left:h,width:y}},c=f=>{const g=[],b=new Date(f.start);for(b.setMinutes(0,0,0);b<=f.end;)g.push(new Date(b)),b.setHours(b.getHours()+1);return g};if(e.length===0)return i.jsxs("div",{className:"card",children:[i.jsx("h3",{children:"πŸ“Š Schedule Gantt Chart"}),i.jsx("p",{children:"No events to display in Gantt chart."})]});const d=a(),m=c(d),p=d.end.getTime()-d.start.getTime();return i.jsxs("div",{className:"card",children:[i.jsxs("h3",{children:["πŸ“Š Schedule Gantt Chart - ",t]}),i.jsxs("div",{style:{marginBottom:"1rem",fontSize:"0.9rem",color:"#666"},children:["Timeline: ",d.start.toLocaleDateString()," ",o(d.start.toISOString())," - ",o(d.end.toISOString())]}),i.jsxs("div",{style:{border:"1px solid #ddd",borderRadius:"6px",overflow:"hidden",backgroundColor:"#fff"},children:[i.jsx("div",{style:{display:"flex",borderBottom:"2px solid #333",backgroundColor:"#f8f9fa",position:"relative",height:"40px",alignItems:"center"},children:m.map((f,g)=>{const b=(f.getTime()-d.start.getTime())/p*100;return i.jsx("div",{style:{position:"absolute",left:`${b}%`,transform:"translateX(-50%)",fontSize:"0.8rem",fontWeight:"bold",color:"#333",whiteSpace:"nowrap"},children:o(f.toISOString())},g)})}),i.jsx("div",{style:{padding:"1rem 0"},children:e.map((f,g)=>{const b=l(f,d);return i.jsxs("div",{style:{position:"relative",height:"60px",marginBottom:"8px",borderRadius:"4px",border:"1px solid #e9ecef"},children:[i.jsxs("div",{style:{position:"absolute",left:`${b.left}%`,width:`${b.width}%`,height:"100%",backgroundColor:n(f.type),opacity:r(f.status),borderRadius:"4px",display:"flex",alignItems:"center",padding:"0 8px",color:"white",fontSize:"0.8rem",fontWeight:"bold",overflow:"hidden",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",cursor:"pointer",transition:"transform 0.2s ease"},onMouseEnter:w=>{w.currentTarget.style.transform="scale(1.02)",w.currentTarget.style.zIndex="10"},onMouseLeave:w=>{w.currentTarget.style.transform="scale(1)",w.currentTarget.style.zIndex="1"},title:`${f.title} ${f.location} ${f.vipName} ${o(f.startTime)} - ${o(f.endTime)}`,children:[i.jsx("span",{style:{marginRight:"4px"},children:s(f.type)}),i.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:f.title})]}),b.width<15&&i.jsxs("div",{style:{position:"absolute",left:`${b.left+b.width+1}%`,top:"50%",transform:"translateY(-50%)",fontSize:"0.7rem",color:"#666",whiteSpace:"nowrap",backgroundColor:"#f8f9fa",padding:"2px 6px",borderRadius:"3px",border:"1px solid #e9ecef"},children:[s(f.type)," ",f.title," - ",f.vipName]})]},f.id)})}),i.jsxs("div",{style:{borderTop:"1px solid #ddd",padding:"1rem",backgroundColor:"#f8f9fa"},children:[i.jsx("div",{style:{fontSize:"0.8rem",fontWeight:"bold",marginBottom:"0.5rem"},children:"Event Types:"}),i.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"1rem"},children:[{type:"transport",label:"Transport"},{type:"meeting",label:"Meetings"},{type:"meal",label:"Meals"},{type:"event",label:"Events"},{type:"accommodation",label:"Accommodation"}].map(({type:f,label:g})=>i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.25rem"},children:[i.jsx("div",{style:{width:"16px",height:"16px",backgroundColor:n(f),borderRadius:"2px"}}),i.jsxs("span",{style:{fontSize:"0.7rem"},children:[s(f)," ",g]})]},f))})]})]})]})},Yg=()=>{const{driverId:e}=dh(),[t,n]=S.useState(null),[r,s]=S.useState(!0),[o,a]=S.useState(null);S.useEffect(()=>{e&&l()},[e]);const l=async()=>{try{const h=localStorage.getItem("authToken"),y=await U(`/api/drivers/${e}/schedule`,{headers:{Authorization:`Bearer ${h}`,"Content-Type":"application/json"}});if(y.ok){const v=await y.json();n(v)}else a("Driver not found")}catch{a("Error loading driver schedule")}finally{s(!1)}},c=h=>{switch(h){case"scheduled":return"#3498db";case"in-progress":return"#f39c12";case"completed":return"#2ecc71";case"cancelled":return"#e74c3c";default:return"#95a5a6"}},d=h=>{switch(h){case"transport":return"πŸš—";case"meeting":return"🀝";case"event":return"πŸŽ‰";case"meal":return"🍽️";case"accommodation":return"🏨";default:return"πŸ“…"}},m=h=>new Date(h).toLocaleString([],{hour:"2-digit",minute:"2-digit"}),p=()=>{if(!(t!=null&&t.schedule))return null;const h=new Date,y=t.schedule.filter(v=>new Date(v.startTime)>h&&v.status==="scheduled").sort((v,N)=>new Date(v.startTime).getTime()-new Date(N.startTime).getTime());return y.length>0?y[0]:null},f=()=>{if(!(t!=null&&t.schedule))return null;const h=new Date;return t.schedule.find(y=>new Date(y.startTime)<=h&&new Date(y.endTime)>h&&y.status==="in-progress")||null},g=h=>{const y={};return h.forEach(v=>{const N=new Date(v.startTime).toDateString();y[N]||(y[N]=[]),y[N].push(v)}),Object.keys(y).forEach(v=>{y[v].sort((N,k)=>new Date(N.startTime).getTime()-new Date(k.startTime).getTime())}),y},b=()=>{if(!t)return;const h=window.open("","_blank");if(!h)return;const y=g(t.schedule),v=` Driver Schedule - ${t.driver.name}

Driver Schedule

${t.driver.name}

Driver: ${t.driver.name}

Phone: ${t.driver.phone}

Total Assignments: ${t.schedule.length}

${Object.entries(y).map(([N,k])=>`
${new Date(N).toLocaleDateString([],{weekday:"long",year:"numeric",month:"long",day:"numeric"})}
${k.map(C=>`
${m(C.startTime)}
to
${m(C.endTime)}
${d(C.type)} ${C.title}
πŸ‘€ VIP: ${C.vipName}
πŸ“ ${C.location}
${C.description?`
${C.description}
`:""}
`).join("")}
`).join("")}
`;h.document.write(v),h.document.close(),h.focus(),setTimeout(()=>{h.print(),h.close()},250)};async function w(h,y){if(!t)return;const v=t.schedule.find(N=>N.id===h);if(v)try{const N=localStorage.getItem("authToken");(await U(`/api/vips/${v.vipId}/schedule/${h}/status`,{method:"PATCH",headers:{Authorization:`Bearer ${N}`,"Content-Type":"application/json"},body:JSON.stringify({status:y})})).ok&&await l()}catch(N){console.error("Error updating event status:",N)}}if(r)return i.jsx("div",{className:"flex justify-center items-center min-h-64",children:i.jsxs("div",{className:"bg-white rounded-2xl shadow-lg p-8 flex items-center space-x-4",children:[i.jsx("div",{className:"w-8 h-8 border-4 border-red-600 border-t-transparent rounded-full animate-spin"}),i.jsx("span",{className:"text-lg font-medium text-slate-700",children:"Loading driver schedule..."})]})});if(o||!t)return i.jsx("div",{className:"space-y-8",children:i.jsxs("div",{className:"bg-white rounded-2xl shadow-lg p-8 border border-slate-200/60 text-center",children:[i.jsx("div",{className:"w-16 h-16 bg-red-100 rounded-full flex items-center justify-center mx-auto mb-4",children:i.jsx("span",{className:"text-2xl",children:"❌"})}),i.jsx("h1",{className:"text-2xl font-bold text-slate-800 mb-2",children:"Error"}),i.jsx("p",{className:"text-slate-600 mb-6",children:o||"Driver not found"}),i.jsx(we,{to:"/drivers",className:"bg-gradient-to-r from-slate-500 to-slate-600 hover:from-slate-600 hover:to-slate-700 text-white px-6 py-3 rounded-lg font-medium transition-all duration-200 shadow-lg hover:shadow-xl",children:"Back to Drivers"})]})});const j=p(),x=f(),u=g(t.schedule);return i.jsxs("div",{className:"space-y-8",children:[i.jsx("div",{className:"bg-white rounded-2xl shadow-lg p-8 border border-slate-200/60",children:i.jsxs("div",{className:"flex justify-between items-center",children:[i.jsxs("div",{children:[i.jsxs("h1",{className:"text-3xl font-bold bg-gradient-to-r from-slate-800 to-slate-600 bg-clip-text text-transparent flex items-center gap-3",children:["πŸš— Driver Dashboard: ",t.driver.name]}),i.jsx("p",{className:"text-slate-600 mt-2",children:"Real-time schedule and assignment management"})]}),i.jsxs("div",{className:"flex items-center space-x-4",children:[i.jsx("button",{className:"bg-gradient-to-r from-red-500 to-red-600 hover:from-red-600 hover:to-red-700 text-white px-6 py-3 rounded-lg font-medium transition-all duration-200 shadow-lg hover:shadow-xl flex items-center gap-2",onClick:b,children:"πŸ–¨οΈ Print Schedule"}),i.jsx(we,{to:"/drivers",className:"bg-gradient-to-r from-slate-500 to-slate-600 hover:from-slate-600 hover:to-slate-700 text-white px-6 py-3 rounded-lg font-medium transition-all duration-200 shadow-lg hover:shadow-xl",children:"Back to Drivers"})]})]})}),i.jsxs("div",{className:"bg-white rounded-2xl shadow-lg border border-slate-200/60 overflow-hidden",children:[i.jsxs("div",{className:"bg-gradient-to-r from-green-50 to-emerald-50 px-8 py-6 border-b border-slate-200/60",children:[i.jsx("h2",{className:"text-xl font-bold text-slate-800 flex items-center gap-2",children:"πŸ“ Current Status"}),i.jsx("p",{className:"text-slate-600 mt-1",children:"Real-time driver activity and next assignment"})]}),i.jsxs("div",{className:"p-8 space-y-6",children:[x?i.jsxs("div",{className:"bg-gradient-to-r from-amber-50 to-orange-50 border border-amber-200 rounded-xl p-6",children:[i.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[i.jsx("span",{className:"text-2xl",children:d(x.type)}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-lg font-bold text-amber-900",children:"Currently Active"}),i.jsx("p",{className:"text-amber-700 font-semibold",children:x.title})]}),i.jsx("span",{className:"ml-auto px-3 py-1 rounded-full text-xs font-bold text-white",style:{backgroundColor:c(x.status)},children:x.status.toUpperCase()})]}),i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 text-sm",children:[i.jsxs("div",{className:"flex items-center gap-2 text-amber-800",children:[i.jsx("span",{children:"πŸ“"}),i.jsx("span",{children:x.location})]}),i.jsxs("div",{className:"flex items-center gap-2 text-amber-800",children:[i.jsx("span",{children:"πŸ‘€"}),i.jsxs("span",{children:["VIP: ",x.vipName]})]}),i.jsxs("div",{className:"flex items-center gap-2 text-amber-800",children:[i.jsx("span",{children:"⏰"}),i.jsxs("span",{children:["Until ",m(x.endTime)]})]})]})]}):i.jsx("div",{className:"bg-gradient-to-r from-green-50 to-emerald-50 border border-green-200 rounded-xl p-6",children:i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("span",{className:"text-2xl",children:"βœ…"}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-lg font-bold text-green-900",children:"Currently Available"}),i.jsx("p",{className:"text-green-700",children:"Ready for next assignment"})]})]})}),j&&i.jsxs("div",{className:"bg-gradient-to-r from-blue-50 to-indigo-50 border border-blue-200 rounded-xl p-6",children:[i.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[i.jsx("span",{className:"text-2xl",children:d(j.type)}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-lg font-bold text-blue-900",children:"Next Assignment"}),i.jsx("p",{className:"text-blue-700 font-semibold",children:j.title})]})]}),i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 text-sm mb-4",children:[i.jsxs("div",{className:"flex items-center gap-2 text-blue-800",children:[i.jsx("span",{children:"πŸ“"}),i.jsx("span",{children:j.location})]}),i.jsxs("div",{className:"flex items-center gap-2 text-blue-800",children:[i.jsx("span",{children:"πŸ‘€"}),i.jsxs("span",{children:["VIP: ",j.vipName]})]}),i.jsxs("div",{className:"flex items-center gap-2 text-blue-800",children:[i.jsx("span",{children:"⏰"}),i.jsxs("span",{children:[m(j.startTime)," - ",m(j.endTime)]})]})]}),i.jsx("button",{className:"bg-gradient-to-r from-blue-500 to-blue-600 hover:from-blue-600 hover:to-blue-700 text-white px-4 py-2 rounded-lg text-sm font-medium transition-all duration-200 shadow-lg hover:shadow-xl flex items-center gap-2",onClick:()=>window.open(`https://maps.google.com/?q=${encodeURIComponent(j.location)}`,"_blank"),children:"πŸ—ΊοΈ Get Directions"})]})]})]}),i.jsxs("div",{className:"bg-white rounded-2xl shadow-lg border border-slate-200/60 overflow-hidden",children:[i.jsxs("div",{className:"bg-gradient-to-r from-purple-50 to-pink-50 px-8 py-6 border-b border-slate-200/60",children:[i.jsxs("h2",{className:"text-xl font-bold text-slate-800 flex items-center gap-2",children:["πŸ“… Complete Schedule",i.jsxs("span",{className:"bg-purple-100 text-purple-800 text-sm font-medium px-2.5 py-0.5 rounded-full",children:[t.schedule.length," assignments"]})]}),i.jsx("p",{className:"text-slate-600 mt-1",children:"All scheduled events and assignments"})]}),i.jsx("div",{className:"p-8",children:t.schedule.length===0?i.jsxs("div",{className:"text-center py-12",children:[i.jsx("div",{className:"w-16 h-16 bg-slate-100 rounded-full flex items-center justify-center mx-auto mb-4",children:i.jsx("span",{className:"text-2xl",children:"πŸ“…"})}),i.jsx("p",{className:"text-slate-500 font-medium",children:"No assignments scheduled"})]}):i.jsx("div",{className:"space-y-8",children:Object.entries(u).map(([h,y])=>i.jsxs("div",{className:"space-y-4",children:[i.jsx("div",{className:"bg-gradient-to-r from-slate-600 to-slate-700 text-white px-6 py-3 rounded-xl shadow-lg",children:i.jsx("h3",{className:"text-lg font-bold",children:new Date(h).toLocaleDateString([],{weekday:"long",year:"numeric",month:"long",day:"numeric"})})}),i.jsx("div",{className:"grid gap-4",children:y.map(v=>i.jsx("div",{className:"bg-gradient-to-r from-slate-50 to-slate-100 rounded-xl border border-slate-200/60 p-6 hover:shadow-lg transition-all duration-200",children:i.jsxs("div",{className:"flex items-start gap-6",children:[i.jsx("div",{className:"flex-shrink-0 text-center",children:i.jsxs("div",{className:"bg-white rounded-lg border border-slate-200 p-3 shadow-sm",children:[i.jsx("div",{className:"text-sm font-bold text-slate-900",children:m(v.startTime)}),i.jsx("div",{className:"text-xs text-slate-500 mt-1",children:"to"}),i.jsx("div",{className:"text-sm font-bold text-slate-900",children:m(v.endTime)})]})}),i.jsxs("div",{className:"flex-1",children:[i.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[i.jsx("span",{className:"text-2xl",children:d(v.type)}),i.jsx("h4",{className:"text-lg font-bold text-slate-900",children:v.title}),i.jsx("span",{className:"px-3 py-1 rounded-full text-xs font-bold text-white shadow-sm",style:{backgroundColor:c(v.status)},children:v.status.toUpperCase()})]}),i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3 mb-4",children:[i.jsxs("div",{className:"flex items-center gap-2 text-slate-600",children:[i.jsx("span",{children:"πŸ“"}),i.jsx("span",{className:"font-medium",children:v.location})]}),i.jsxs("div",{className:"flex items-center gap-2 text-slate-600",children:[i.jsx("span",{children:"πŸ‘€"}),i.jsxs("span",{className:"font-medium",children:["VIP: ",v.vipName]})]})]}),v.description&&i.jsx("div",{className:"text-slate-600 mb-4 bg-white/50 rounded-lg p-3 border border-slate-200/50",children:v.description}),i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("button",{className:"bg-gradient-to-r from-blue-500 to-blue-600 hover:from-blue-600 hover:to-blue-700 text-white px-4 py-2 rounded-lg text-sm font-medium transition-all duration-200 shadow-lg hover:shadow-xl flex items-center gap-2",onClick:()=>window.open(`https://maps.google.com/?q=${encodeURIComponent(v.location)}`,"_blank"),children:"πŸ—ΊοΈ Directions"}),v.status==="scheduled"&&i.jsx("button",{className:"bg-gradient-to-r from-amber-500 to-orange-500 hover:from-amber-600 hover:to-orange-600 text-white px-4 py-2 rounded-lg text-sm font-medium transition-all duration-200 shadow-lg hover:shadow-xl flex items-center gap-2",onClick:()=>w(v.id,"in-progress"),children:"▢️ Start"}),v.status==="in-progress"&&i.jsx("button",{className:"bg-gradient-to-r from-green-500 to-green-600 hover:from-green-600 hover:to-green-700 text-white px-4 py-2 rounded-lg text-sm font-medium transition-all duration-200 shadow-lg hover:shadow-xl flex items-center gap-2",onClick:()=>w(v.id,"completed"),children:"βœ… Complete"}),v.status==="completed"&&i.jsx("span",{className:"bg-green-100 text-green-800 px-3 py-1 rounded-full text-xs font-medium flex items-center gap-1",children:"βœ… Completed"})]})]})]})},v.id))})]},h))})})]}),i.jsxs("div",{className:"bg-white rounded-2xl shadow-lg border border-slate-200/60 overflow-hidden",children:[i.jsxs("div",{className:"bg-gradient-to-r from-indigo-50 to-purple-50 px-8 py-6 border-b border-slate-200/60",children:[i.jsx("h2",{className:"text-xl font-bold text-slate-800 flex items-center gap-2",children:"πŸ“Š Schedule Timeline"}),i.jsx("p",{className:"text-slate-600 mt-1",children:"Visual timeline of all assignments"})]}),i.jsx("div",{className:"p-8",children:i.jsx(Xg,{events:t.schedule,driverName:t.driver.name})})]})]})},Qg=()=>{const[e,t]=S.useState([]),[n,r]=S.useState([]),[s,o]=S.useState(!0),a=d=>{const m=new Date;return d.find(p=>new Date(p.startTime)<=m&&new Date(p.endTime)>m&&p.status==="in-progress")||null},l=d=>{const m=new Date,p=d.filter(f=>new Date(f.startTime)>m&&f.status==="scheduled").sort((f,g)=>new Date(f.startTime).getTime()-new Date(g.startTime).getTime());return p.length>0?p[0]:null},c=d=>new Date(d).toLocaleString([],{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"});return S.useEffect(()=>{(async()=>{try{const p={Authorization:`Bearer ${localStorage.getItem("authToken")}`,"Content-Type":"application/json"},[f,g]=await Promise.all([U("/api/vips",{headers:p}),U("/api/drivers",{headers:p})]);if(!f.ok||!g.ok)throw new Error("Failed to fetch data");const b=await f.json(),w=await g.json(),x=(await Promise.all(b.map(async u=>{try{const h=await U(`/api/vips/${u.id}/schedule`,{headers:p});if(h.ok){const y=await h.json(),v=a(y),N=l(y);return{...u,currentEvent:v,nextEvent:N,nextEventTime:N?N.startTime:null}}else return{...u,currentEvent:null,nextEvent:null,nextEventTime:null}}catch(h){return console.error(`Error fetching schedule for VIP ${u.id}:`,h),{...u,currentEvent:null,nextEvent:null,nextEventTime:null}}}))).sort((u,h)=>u.currentEvent&&!h.currentEvent?-1:!u.currentEvent&&h.currentEvent?1:u.nextEventTime&&h.nextEventTime?new Date(u.nextEventTime).getTime()-new Date(h.nextEventTime).getTime():u.nextEventTime&&!h.nextEventTime?-1:!u.nextEventTime&&h.nextEventTime?1:u.name.localeCompare(h.name));t(x),r(w)}catch(m){console.error("Error fetching data:",m)}finally{o(!1)}})()},[]),s?i.jsx("div",{className:"flex justify-center items-center min-h-64",children:i.jsxs("div",{className:"bg-white rounded-2xl shadow-lg p-8 flex items-center space-x-4",children:[i.jsx("div",{className:"w-8 h-8 border-4 border-blue-600 border-t-transparent rounded-full animate-spin"}),i.jsx("span",{className:"text-lg font-medium text-slate-700",children:"Loading dashboard..."})]})}):i.jsxs("div",{className:"space-y-8",children:[i.jsx("div",{className:"bg-white rounded-2xl shadow-lg p-8 border border-slate-200/60",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("h1",{className:"text-3xl font-bold bg-gradient-to-r from-slate-800 to-slate-600 bg-clip-text text-transparent",children:"VIP Coordinator Dashboard"}),i.jsx("p",{className:"text-slate-600 mt-2",children:"Real-time overview of VIP activities and coordination"})]}),i.jsxs("div",{className:"flex items-center space-x-4",children:[i.jsxs("div",{className:"bg-gradient-to-r from-blue-500 to-blue-600 text-white px-4 py-2 rounded-lg text-sm font-medium",children:[e.length," Active VIPs"]}),i.jsxs("div",{className:"bg-gradient-to-r from-green-500 to-green-600 text-white px-4 py-2 rounded-lg text-sm font-medium",children:[n.length," Drivers"]})]})]})}),i.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-3 gap-8",children:[i.jsx("div",{className:"xl:col-span-2",children:i.jsxs("div",{className:"bg-white rounded-2xl shadow-lg border border-slate-200/60 overflow-hidden",children:[i.jsx("div",{className:"bg-gradient-to-r from-blue-50 to-indigo-50 px-6 py-4 border-b border-slate-200/60",children:i.jsxs("h2",{className:"text-xl font-bold text-slate-800 flex items-center",children:["VIP Status Dashboard",i.jsxs("span",{className:"ml-2 bg-blue-100 text-blue-800 text-sm font-medium px-2.5 py-0.5 rounded-full",children:[e.length," VIPs"]})]})}),i.jsx("div",{className:"p-6",children:e.length===0?i.jsxs("div",{className:"text-center py-12",children:[i.jsx("div",{className:"w-16 h-16 bg-slate-100 rounded-full flex items-center justify-center mx-auto mb-4",children:i.jsx("div",{className:"w-8 h-8 bg-slate-300 rounded-full"})}),i.jsx("p",{className:"text-slate-500 font-medium",children:"No VIPs currently scheduled"})]}):i.jsx("div",{className:"space-y-4",children:e.map(d=>{const m=!!d.currentEvent,p=!!d.nextEvent;return i.jsx("div",{className:` relative rounded-xl border-2 p-6 transition-all duration-200 hover:shadow-lg ${m?"border-amber-300 bg-gradient-to-r from-amber-50 to-orange-50":p?"border-blue-300 bg-gradient-to-r from-blue-50 to-indigo-50":"border-slate-200 bg-slate-50"} `,children:i.jsxs("div",{className:"flex justify-between items-start",children:[i.jsxs("div",{className:"flex-1",children:[i.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[i.jsx("h3",{className:"text-lg font-bold text-slate-900",children:d.name}),m&&i.jsx("span",{className:"bg-gradient-to-r from-amber-500 to-orange-500 text-white px-3 py-1 rounded-full text-xs font-bold animate-pulse",children:"ACTIVE"})]}),i.jsx("p",{className:"text-slate-600 text-sm mb-4",children:d.organization}),d.currentEvent&&i.jsxs("div",{className:"bg-white border border-amber-200 rounded-lg p-4 mb-3 shadow-sm",children:[i.jsx("div",{className:"flex items-center gap-2 mb-2",children:i.jsx("span",{className:"text-amber-600 font-bold text-sm",children:"CURRENT EVENT"})}),i.jsx("div",{className:"flex items-center gap-2 mb-1",children:i.jsx("span",{className:"font-semibold text-slate-900",children:d.currentEvent.title})}),i.jsxs("p",{className:"text-slate-600 text-sm mb-1",children:["Location: ",d.currentEvent.location]}),i.jsxs("p",{className:"text-slate-500 text-xs",children:["Until ",c(d.currentEvent.endTime)]})]}),d.nextEvent&&i.jsxs("div",{className:"bg-white border border-blue-200 rounded-lg p-4 mb-3 shadow-sm",children:[i.jsx("div",{className:"flex items-center gap-2 mb-2",children:i.jsx("span",{className:"text-blue-600 font-bold text-sm",children:"NEXT EVENT"})}),i.jsx("div",{className:"flex items-center gap-2 mb-1",children:i.jsx("span",{className:"font-semibold text-slate-900",children:d.nextEvent.title})}),i.jsxs("p",{className:"text-slate-600 text-sm mb-1",children:["Location: ",d.nextEvent.location]}),i.jsxs("p",{className:"text-slate-500 text-xs",children:[c(d.nextEvent.startTime)," - ",c(d.nextEvent.endTime)]})]}),!d.currentEvent&&!d.nextEvent&&i.jsx("div",{className:"bg-white border border-slate-200 rounded-lg p-4 mb-3",children:i.jsx("p",{className:"text-slate-500 text-sm italic",children:"No scheduled events"})}),i.jsx("div",{className:"flex items-center gap-2 text-xs text-slate-500 bg-white/50 rounded-lg px-3 py-2",children:d.transportMode==="flight"?i.jsxs("span",{children:["Flight: ",d.flights&&d.flights.length>0?d.flights.map(f=>f.flightNumber).join(" β†’ "):d.flightNumber||"TBD"]}):i.jsxs("span",{children:["Self-driving | Expected: ",d.expectedArrival?c(d.expectedArrival):"TBD"]})})]}),i.jsxs("div",{className:"flex flex-col gap-2 ml-6",children:[i.jsx(we,{to:`/vips/${d.id}`,className:"bg-gradient-to-r from-green-500 to-green-600 hover:from-green-600 hover:to-green-700 text-white px-4 py-2 rounded-lg text-sm font-medium transition-all duration-200 text-center shadow-lg hover:shadow-xl",children:"Details"}),i.jsx(we,{to:`/vips/${d.id}#schedule`,className:"bg-gradient-to-r from-slate-500 to-slate-600 hover:from-slate-600 hover:to-slate-700 text-white px-4 py-2 rounded-lg text-sm font-medium transition-all duration-200 text-center shadow-lg hover:shadow-xl",children:"Schedule"})]})]})},d.id)})})})]})}),i.jsxs("div",{className:"space-y-6",children:[i.jsxs("div",{className:"bg-white rounded-2xl shadow-lg border border-slate-200/60 overflow-hidden",children:[i.jsx("div",{className:"bg-gradient-to-r from-green-50 to-emerald-50 px-6 py-4 border-b border-slate-200/60",children:i.jsxs("h2",{className:"text-lg font-bold text-slate-800 flex items-center",children:["Available Drivers",i.jsx("span",{className:"ml-2 bg-green-100 text-green-800 text-sm font-medium px-2.5 py-0.5 rounded-full",children:n.length})]})}),i.jsx("div",{className:"p-6",children:n.length===0?i.jsxs("div",{className:"text-center py-8",children:[i.jsx("div",{className:"w-12 h-12 bg-slate-100 rounded-full flex items-center justify-center mx-auto mb-3",children:i.jsx("div",{className:"w-6 h-6 bg-slate-300 rounded-full"})}),i.jsx("p",{className:"text-slate-500 text-sm",children:"No drivers available"})]}):i.jsx("div",{className:"space-y-3",children:n.map(d=>i.jsx("div",{className:"bg-slate-50 rounded-lg p-4 border border-slate-200",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("h4",{className:"font-semibold text-slate-900",children:d.name}),i.jsx("p",{className:"text-slate-600 text-sm",children:d.phone})]}),i.jsx("div",{className:"text-right",children:i.jsxs("span",{className:"bg-blue-100 text-blue-800 text-xs font-medium px-2 py-1 rounded-full",children:[d.assignedVipIds.length," VIPs"]})})]})},d.id))})})]}),i.jsxs("div",{className:"bg-white rounded-2xl shadow-lg border border-slate-200/60 overflow-hidden",children:[i.jsx("div",{className:"bg-gradient-to-r from-purple-50 to-pink-50 px-6 py-4 border-b border-slate-200/60",children:i.jsx("h2",{className:"text-lg font-bold text-slate-800",children:"Quick Actions"})}),i.jsxs("div",{className:"p-6 space-y-3",children:[i.jsx(we,{to:"/vips",className:"block w-full bg-gradient-to-r from-blue-500 to-blue-600 hover:from-blue-600 hover:to-blue-700 text-white px-4 py-3 rounded-lg font-medium transition-all duration-200 text-center shadow-lg hover:shadow-xl",children:"Manage VIPs"}),i.jsx(we,{to:"/drivers",className:"block w-full bg-gradient-to-r from-green-500 to-green-600 hover:from-green-600 hover:to-green-700 text-white px-4 py-3 rounded-lg font-medium transition-all duration-200 text-center shadow-lg hover:shadow-xl",children:"Manage Drivers"})]})]})]})]})]})},qg=()=>{const e=new Date,t=new Date(e);t.setDate(t.getDate()+1);const n=new Date(e);n.setDate(n.getDate()+2);const r=o=>o.toISOString().split("T")[0],s=o=>{const a=new Date(o);return a.setHours(14,30,0,0),a.toISOString().slice(0,16)};return[{name:"Dr. Sarah Chen",organization:"Stanford University",department:"Admin",transportMode:"flight",flights:[{flightNumber:"UA1234",flightDate:r(t),segment:1},{flightNumber:"DL5678",flightDate:r(t),segment:2}],needsAirportPickup:!0,needsVenueTransport:!0,notes:"Vegetarian meals, requires wheelchair assistance"},{name:"Ambassador Michael Rodriguez",organization:"Embassy of Spain",department:"Admin",transportMode:"self-driving",expectedArrival:s(t),needsVenueTransport:!0,notes:"Security detail required, diplomatic immunity"},{name:"Prof. Aisha Patel",organization:"MIT Technology Review",department:"Admin",transportMode:"flight",flights:[{flightNumber:"AA9876",flightDate:r(n),segment:1}],needsAirportPickup:!0,needsVenueTransport:!1,notes:"Allergic to shellfish, prefers ground floor rooms"},{name:"CEO James Thompson",organization:"TechCorp Industries",department:"Admin",transportMode:"flight",flights:[{flightNumber:"SW2468",flightDate:r(t),segment:1}],needsAirportPickup:!1,needsVenueTransport:!0,notes:"Private jet arrival, has own security team"},{name:"Dr. Elena Volkov",organization:"Russian Academy of Sciences",department:"Admin",transportMode:"self-driving",expectedArrival:s(n),needsVenueTransport:!0,notes:"Interpreter required, kosher meals"},{name:"Minister David Kim",organization:"South Korean Ministry of Education",department:"Admin",transportMode:"flight",flights:[{flightNumber:"KE0123",flightDate:r(t),segment:1},{flightNumber:"UA7890",flightDate:r(t),segment:2},{flightNumber:"DL3456",flightDate:r(t),segment:3}],needsAirportPickup:!0,needsVenueTransport:!0,notes:"Long international flight, may need rest upon arrival"},{name:"Dr. Maria Santos",organization:"University of SΓ£o Paulo",department:"Admin",transportMode:"flight",flights:[{flightNumber:"LH4567",flightDate:r(n),segment:1}],needsAirportPickup:!0,needsVenueTransport:!1,notes:"Speaks Portuguese and English, lactose intolerant"},{name:"Sheikh Ahmed Al-Rashid",organization:"UAE University",department:"Admin",transportMode:"self-driving",expectedArrival:s(t),needsVenueTransport:!0,notes:"Halal meals required, prayer room access needed"},{name:"Prof. Catherine Williams",organization:"Oxford University",department:"Admin",transportMode:"flight",flights:[{flightNumber:"BA1357",flightDate:r(t),segment:1}],needsAirportPickup:!1,needsVenueTransport:!0,notes:"Prefers tea over coffee, has mobility issues"},{name:"Dr. Hiroshi Tanaka",organization:"Tokyo Institute of Technology",department:"Admin",transportMode:"flight",flights:[{flightNumber:"NH0246",flightDate:r(n),segment:1},{flightNumber:"UA8642",flightDate:r(n),segment:2}],needsAirportPickup:!0,needsVenueTransport:!0,notes:"Jet lag concerns, prefers Japanese cuisine when available"},{name:"Ms. Jennifer Walsh",organization:"Walsh Foundation",department:"Office of Development",transportMode:"self-driving",expectedArrival:s(t),needsVenueTransport:!1,notes:"Major donor, prefers informal settings"},{name:"Mr. Robert Sterling",organization:"Sterling Philanthropies",department:"Office of Development",transportMode:"flight",flights:[{flightNumber:"JB1122",flightDate:r(t),segment:1}],needsAirportPickup:!0,needsVenueTransport:!0,notes:"Potential $10M donation, wine enthusiast"},{name:"Mrs. Elizabeth Hartwell",organization:"Hartwell Family Trust",department:"Office of Development",transportMode:"flight",flights:[{flightNumber:"AS3344",flightDate:r(n),segment:1}],needsAirportPickup:!1,needsVenueTransport:!0,notes:"Alumni donor, interested in scholarship programs"},{name:"Mr. Charles Montgomery",organization:"Montgomery Industries",department:"Office of Development",transportMode:"self-driving",expectedArrival:s(n),needsVenueTransport:!0,notes:"Corporate partnership opportunity, golf enthusiast"},{name:"Dr. Patricia Lee",organization:"Lee Medical Foundation",department:"Office of Development",transportMode:"flight",flights:[{flightNumber:"F91234",flightDate:r(t),segment:1},{flightNumber:"UA5555",flightDate:r(t),segment:2}],needsAirportPickup:!0,needsVenueTransport:!1,notes:"Medical research funding, diabetic dietary needs"},{name:"Mr. Thomas Anderson",organization:"Anderson Capital Group",department:"Office of Development",transportMode:"flight",flights:[{flightNumber:"VX7788",flightDate:r(t),segment:1}],needsAirportPickup:!0,needsVenueTransport:!0,notes:"Venture capital investor, tech startup focus"},{name:"Mrs. Grace Chen-Williams",organization:"Chen-Williams Foundation",department:"Office of Development",transportMode:"self-driving",expectedArrival:s(t),needsVenueTransport:!0,notes:"Arts and culture patron, vegan diet"},{name:"Mr. Daniel Foster",organization:"Foster Energy Solutions",department:"Office of Development",transportMode:"flight",flights:[{flightNumber:"WN9999",flightDate:r(n),segment:1}],needsAirportPickup:!1,needsVenueTransport:!1,notes:"Renewable energy focus, environmental sustainability"},{name:"Mrs. Victoria Blackstone",organization:"Blackstone Charitable Trust",department:"Office of Development",transportMode:"flight",flights:[{flightNumber:"B61111",flightDate:r(n),segment:1},{flightNumber:"AA2222",flightDate:r(n),segment:2}],needsAirportPickup:!0,needsVenueTransport:!0,notes:"Education advocate, prefers luxury accommodations"},{name:"Mr. Alexander Petrov",organization:"Petrov International Holdings",department:"Office of Development",transportMode:"self-driving",expectedArrival:s(n),needsVenueTransport:!0,notes:"International business, speaks Russian and English"}]},Ec=()=>["Stanford University","Embassy of Spain","MIT Technology Review","TechCorp Industries","Russian Academy of Sciences","South Korean Ministry of Education","University of SΓ£o Paulo","UAE University","Oxford University","Tokyo Institute of Technology","Walsh Foundation","Sterling Philanthropies","Hartwell Family Trust","Montgomery Industries","Lee Medical Foundation","Anderson Capital Group","Chen-Williams Foundation","Foster Energy Solutions","Blackstone Charitable Trust","Petrov International Holdings"],e0=(e,t,n)=>{const r=new Date,s=new Date(r);s.setDate(s.getDate()+1);const o=(l,c=0)=>{const d=new Date(s);return d.setHours(l,c,0,0),d.toISOString()},a=[{title:n==="flight"?"Airport Pickup":"Arrival Check-in",location:n==="flight"?"Airport Terminal":"Hotel Lobby",startTime:o(8,0),endTime:o(9,0),description:n==="flight"?"Meet and greet at airport, transport to hotel":"Check-in and welcome briefing",type:"transport",status:"scheduled"},{title:"Welcome Breakfast",location:"Executive Dining Room",startTime:o(9,0),endTime:o(10,0),description:"Welcome breakfast with key stakeholders and orientation materials",type:"meal",status:"scheduled"}];return t==="Admin"?[...a,{title:"Academic Leadership Meeting",location:"Board Room A",startTime:o(10,30),endTime:o(12,0),description:"Strategic planning session with academic leadership team",type:"meeting",status:"scheduled"},{title:"Working Lunch",location:"Faculty Club",startTime:o(12,0),endTime:o(13,30),description:"Lunch meeting with department heads and key faculty",type:"meal",status:"scheduled"},{title:"Campus Tour",location:"Main Campus",startTime:o(14,0),endTime:o(15,30),description:"Guided tour of campus facilities and research centers",type:"event",status:"scheduled"},{title:"Research Presentation",location:"Auditorium B",startTime:o(16,0),endTime:o(17,30),description:"Presentation of current research initiatives and future plans",type:"meeting",status:"scheduled"},{title:"Reception Dinner",location:"University Club",startTime:o(19,0),endTime:o(21,0),description:"Formal dinner reception with university leadership",type:"event",status:"scheduled"}]:[...a,{title:"Donor Relations Meeting",location:"Development Office",startTime:o(10,30),endTime:o(12,0),description:"Private meeting with development team about giving opportunities",type:"meeting",status:"scheduled"},{title:"Scholarship Recipients Lunch",location:"Student Center",startTime:o(12,0),endTime:o(13,30),description:"Meet with current scholarship recipients and hear their stories",type:"meal",status:"scheduled"},{title:"Facility Naming Ceremony",location:"New Science Building",startTime:o(14,0),endTime:o(15,0),description:"Dedication ceremony for newly named facility",type:"event",status:"scheduled"},{title:"Impact Presentation",location:"Conference Room C",startTime:o(15,30),endTime:o(16,30),description:"Presentation on the impact of philanthropic giving",type:"meeting",status:"scheduled"},{title:"Private Dinner",location:"Presidents House",startTime:o(18,30),endTime:o(20,30),description:"Intimate dinner with university president and spouse",type:"meal",status:"scheduled"},{title:"Evening Cultural Event",location:"Arts Center",startTime:o(21,0),endTime:o(22,30),description:"Special performance by university arts programs",type:"event",status:"scheduled"}]},t0=()=>{const e=ch(),[t,n]=S.useState({}),[r,s]=S.useState({}),[o,a]=S.useState({}),[l,c]=S.useState(!0),[d,m]=S.useState(!1),[p,f]=S.useState(null),[g,b]=S.useState({}),[w,j]=S.useState({}),[x,u]=S.useState(!1),[h,y]=S.useState(null),[v,N]=S.useState(null),k=(P=!1)=>{const L={},E=typeof window<"u"?localStorage.getItem("authToken"):null;return E&&(L.Authorization=`Bearer ${E}`),P&&(L["Content-Type"]="application/json"),L},C=async()=>{try{c(!0),N(null);const P=await U("/api/admin/settings",{headers:k()});if(P.ok){const L=await P.json(),E={},D={},O={};L.apiKeys&&Object.entries(L.apiKeys).forEach(([$,F])=>{F&&F.startsWith("***")?(E[$]=!0,D[$]=F):F&&(O[$]=F)}),b(E),j(D),n(O),s(L.systemSettings||{})}else P.status===403?N("You need administrator access to view this page."):P.status===401?N("Authentication required. Please sign in again."):N("Failed to load admin settings.")}catch(P){console.error("Failed to load settings:",P),N("Failed to load admin settings.")}finally{c(!1)}};S.useEffect(()=>{C()},[]);const z=(P,L)=>{n(E=>({...E,[P]:L})),L&&!L.startsWith("***")&&(b(E=>({...E,[P]:!1})),j(E=>{const D={...E};return delete D[P],D}))},A=(P,L)=>{s(E=>({...E,[P]:L}))},I=async P=>{a(L=>({...L,[P]:"Testing..."}));try{const L=await U(`/api/admin/test-api/${P}`,{method:"POST",headers:k(!0),body:JSON.stringify({apiKey:t[P]})}),E=await L.json();L.ok?a(D=>({...D,[P]:`Success: ${E.message}`})):a(D=>({...D,[P]:`Failed: ${E.error}`}))}catch{a(E=>({...E,[P]:"Connection error"}))}},M=async()=>{m(!0),f(null);try{(await U("/api/admin/settings",{method:"POST",headers:k(!0),body:JSON.stringify({apiKeys:t,systemSettings:r})})).ok?(f("Settings saved successfully!"),await C(),setTimeout(()=>f(null),3e3)):f("Failed to save settings")}catch{f("Error saving settings")}finally{m(!1)}},W=()=>{localStorage.removeItem("authToken"),e("/"),window.location.reload()},G=async()=>{u(!0),y("Creating test VIPs and schedules...");try{const P=localStorage.getItem("authToken"),L=qg();let E=0,D=0,O=0,$=0;const F=[];for(const ie of L)try{const ue=await U("/api/vips",{method:"POST",headers:{Authorization:`Bearer ${P}`,"Content-Type":"application/json"},body:JSON.stringify(ie)});if(ue.ok){const Le=await ue.json();F.push(Le.id),E++}else D++,console.error(`Failed to create VIP: ${ie.name}`)}catch(ue){D++,console.error(`Error creating VIP ${ie.name}:`,ue)}y(`Created ${E} VIPs, now creating schedules...`);for(let ie=0;ie0||$>0?`(${D+$} failed)`:""}`)}catch(P){y("❌ Failed to create test VIPs and schedules"),console.error("Error creating test data:",P)}finally{u(!1),setTimeout(()=>y(null),8e3)}},K=async()=>{if(confirm("Are you sure you want to remove all test VIPs? This will delete VIPs from the test organizations.")){u(!0),y("Removing test VIPs...");try{const P=localStorage.getItem("authToken"),L=await U("/api/vips",{headers:{Authorization:`Bearer ${P}`,"Content-Type":"application/json"}});if(!L.ok)throw new Error("Failed to fetch VIPs");const E=await L.json(),D=Ec(),O=E.filter(ie=>D.includes(ie.organization));let $=0,F=0;for(const ie of O)try{(await U(`/api/vips/${ie.id}`,{method:"DELETE",headers:{Authorization:`Bearer ${P}`,"Content-Type":"application/json"}})).ok?$++:(F++,console.error(`Failed to delete VIP: ${ie.name}`))}catch(ue){F++,console.error(`Error deleting VIP ${ie.name}:`,ue)}y(`πŸ—‘οΈ Removed ${$} test VIPs successfully! ${F>0?`(${F} failed)`:""}`)}catch(P){y("❌ Failed to remove test VIPs"),console.error("Error removing test VIPs:",P)}finally{u(!1),setTimeout(()=>y(null),5e3)}}};return l?i.jsx("div",{className:"min-h-screen bg-gradient-to-br from-slate-50 to-slate-100 flex justify-center items-center",children:i.jsxs("div",{className:"bg-white rounded-2xl shadow-xl p-8 flex items-center space-x-4 border border-slate-200/60",children:[i.jsx("div",{className:"w-8 h-8 border-4 border-blue-600 border-t-transparent rounded-full animate-spin"}),i.jsx("span",{className:"text-lg font-medium text-slate-700",children:"Loading admin settings..."})]})}):v?i.jsx("div",{className:"min-h-screen bg-gradient-to-br from-slate-50 to-slate-100 flex justify-center items-center",children:i.jsxs("div",{className:"bg-white rounded-2xl shadow-xl p-8 w-full max-w-xl border border-rose-200/70",children:[i.jsx("h2",{className:"text-2xl font-bold text-rose-700 mb-4",children:"Admin access required"}),i.jsx("p",{className:"text-slate-600 mb-6",children:v}),i.jsx("button",{className:"btn btn-primary",onClick:()=>e("/"),children:"Return to dashboard"})]})}):i.jsxs("div",{className:"space-y-8",children:[i.jsx("div",{className:"bg-white rounded-2xl shadow-lg p-8 border border-slate-200/60",children:i.jsxs("div",{className:"flex justify-between items-center",children:[i.jsxs("div",{children:[i.jsx("h1",{className:"text-3xl font-bold bg-gradient-to-r from-slate-800 to-slate-600 bg-clip-text text-transparent",children:"Admin Dashboard"}),i.jsx("p",{className:"text-slate-600 mt-2",children:"System configuration and API management"})]}),i.jsxs("div",{className:"flex items-center space-x-4",children:[i.jsx("button",{className:"btn btn-secondary",onClick:()=>e("/"),children:"Back to Dashboard"}),i.jsx("button",{className:"btn btn-danger",onClick:W,children:"Logout"})]})]})}),i.jsxs("div",{className:"bg-white rounded-2xl shadow-lg border border-slate-200/60 overflow-hidden",children:[i.jsxs("div",{className:"bg-gradient-to-r from-blue-50 to-indigo-50 px-8 py-6 border-b border-slate-200/60",children:[i.jsx("h2",{className:"text-xl font-bold text-slate-800",children:"API Key Management"}),i.jsx("p",{className:"text-slate-600 mt-1",children:"Configure external service integrations"})]}),i.jsxs("div",{className:"p-8 space-y-8",children:[i.jsxs("div",{className:"form-section",children:[i.jsxs("div",{className:"form-section-header",children:[i.jsx("h3",{className:"form-section-title",children:"AviationStack API"}),g.aviationStackKey&&i.jsx("span",{className:"bg-green-100 text-green-800 text-xs font-medium px-2.5 py-0.5 rounded-full",children:"Configured"})]}),i.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-4 gap-4 items-end",children:[i.jsxs("div",{className:"lg:col-span-2",children:[i.jsx("label",{className:"form-label",children:"API Key"}),i.jsx("input",{type:"password",placeholder:g.aviationStackKey&&w.aviationStackKey?`Saved (${w.aviationStackKey.slice(-4)})`:"Enter AviationStack API key",value:t.aviationStackKey||"",onChange:P=>z("aviationStackKey",P.target.value),className:"form-input"}),g.aviationStackKey&&w.aviationStackKey&&!t.aviationStackKey&&i.jsxs("p",{className:"text-xs text-slate-500 mt-1",children:["Currently saved key ends with ",w.aviationStackKey.slice(-4),". Enter a new value to replace it."]}),i.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Get your key from: https://aviationstack.com/dashboard"})]}),i.jsx("div",{children:i.jsx("button",{className:"btn btn-secondary w-full",onClick:()=>I("aviationStackKey"),children:"Test Connection"})}),i.jsx("div",{children:o.aviationStackKey&&i.jsx("div",{className:`p-3 rounded-lg text-sm ${o.aviationStackKey.includes("Success")?"bg-green-50 text-green-700 border border-green-200":"bg-red-50 text-red-700 border border-red-200"}`,children:o.aviationStackKey})})]})]}),i.jsxs("div",{className:"form-section",children:[i.jsxs("div",{className:"form-section-header",children:[i.jsx("h3",{className:"form-section-title",children:"Auth0 Configuration"}),(g.auth0Domain||g.auth0ClientId||g.auth0ClientSecret)&&i.jsx("span",{className:"bg-green-100 text-green-800 text-xs font-medium px-2.5 py-0.5 rounded-full",children:"Configured"})]}),i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[i.jsxs("div",{className:"form-group",children:[i.jsx("label",{className:"form-label",children:"Auth0 Domain"}),i.jsx("input",{type:"text",placeholder:g.auth0Domain&&w.auth0Domain?`Saved (${w.auth0Domain.slice(-4)})`:"e.g. dev-1234abcd.us.auth0.com",value:t.auth0Domain||"",onChange:P=>z("auth0Domain",P.target.value),className:"form-input"})]}),i.jsxs("div",{className:"form-group",children:[i.jsx("label",{className:"form-label",children:"Client ID"}),i.jsx("input",{type:"password",placeholder:g.auth0ClientId&&w.auth0ClientId?`Saved (${w.auth0ClientId.slice(-4)})`:"Enter Auth0 application Client ID",value:t.auth0ClientId||"",onChange:P=>z("auth0ClientId",P.target.value),className:"form-input"}),g.auth0ClientId&&w.auth0ClientId&&!t.auth0ClientId&&i.jsxs("p",{className:"text-xs text-slate-500 mt-1",children:["Saved client ID ends with ",w.auth0ClientId.slice(-4),". Provide a new ID to update it."]})]}),i.jsxs("div",{className:"form-group",children:[i.jsx("label",{className:"form-label",children:"Client Secret"}),i.jsx("input",{type:"password",placeholder:g.auth0ClientSecret&&w.auth0ClientSecret?`Saved (${w.auth0ClientSecret.slice(-4)})`:"Enter Auth0 application Client Secret",value:t.auth0ClientSecret||"",onChange:P=>z("auth0ClientSecret",P.target.value),className:"form-input"}),g.auth0ClientSecret&&w.auth0ClientSecret&&!t.auth0ClientSecret&&i.jsxs("p",{className:"text-xs text-slate-500 mt-1",children:["Saved client secret ends with ",w.auth0ClientSecret.slice(-4),". Provide a new secret to rotate it."]})]}),i.jsxs("div",{className:"form-group",children:[i.jsx("label",{className:"form-label",children:"API Audience (Identifier)"}),i.jsx("input",{type:"text",placeholder:t.auth0Audience||"https://your-api-identifier",value:t.auth0Audience||"",onChange:P=>z("auth0Audience",P.target.value),className:"form-input"}),i.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Create an API in Auth0 and use its Identifier here (e.g. https://vip-coordinator-api)."})]})]}),i.jsxs("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-4 mt-4",children:[i.jsx("h4",{className:"font-semibold text-blue-900 mb-2",children:"Setup Instructions"}),i.jsxs("ol",{className:"text-sm text-blue-800 space-y-1 list-decimal list-inside",children:[i.jsx("li",{children:"Sign in to the Auth0 Dashboard"}),i.jsxs("li",{children:["Create a ",i.jsx("strong",{children:"Single Page Application"})," for the frontend"]}),i.jsxs("li",{children:["Set Allowed Callback URL to ",i.jsx("code",{children:"https://bsa.madeamess.online/auth/callback"})]}),i.jsxs("li",{children:["Set Allowed Logout URL to ",i.jsx("code",{children:"https://bsa.madeamess.online/"})]}),i.jsxs("li",{children:["Set Allowed Web Origins to ",i.jsx("code",{children:"https://bsa.madeamess.online"})]}),i.jsxs("li",{children:["Create an ",i.jsx("strong",{children:"API"})," in Auth0 for the backend and use its Identifier as the audience"]})]})]})]}),i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6 opacity-50",children:[i.jsxs("div",{className:"form-section",children:[i.jsxs("div",{className:"form-section-header",children:[i.jsx("h3",{className:"form-section-title",children:"Google Maps API"}),i.jsx("span",{className:"bg-gray-100 text-gray-600 text-xs font-medium px-2.5 py-0.5 rounded-full",children:"Coming Soon"})]}),i.jsx("input",{type:"password",placeholder:"Google Maps API key (not yet implemented)",disabled:!0,className:"form-input"})]}),i.jsxs("div",{className:"form-section",children:[i.jsxs("div",{className:"form-section-header",children:[i.jsx("h3",{className:"form-section-title",children:"Twilio API"}),i.jsx("span",{className:"bg-gray-100 text-gray-600 text-xs font-medium px-2.5 py-0.5 rounded-full",children:"Coming Soon"})]}),i.jsx("input",{type:"password",placeholder:"Twilio API key (not yet implemented)",disabled:!0,className:"form-input"})]})]})]})]}),i.jsxs("div",{className:"bg-white rounded-2xl shadow-lg border border-slate-200/60 overflow-hidden",children:[i.jsxs("div",{className:"bg-gradient-to-r from-green-50 to-emerald-50 px-8 py-6 border-b border-slate-200/60",children:[i.jsx("h2",{className:"text-xl font-bold text-slate-800",children:"System Settings"}),i.jsx("p",{className:"text-slate-600 mt-1",children:"Configure default system behavior"})]}),i.jsx("div",{className:"p-8",children:i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[i.jsxs("div",{className:"form-group",children:[i.jsx("label",{htmlFor:"defaultPickup",className:"form-label",children:"Default Pickup Location"}),i.jsx("input",{type:"text",id:"defaultPickup",value:r.defaultPickupLocation||"",onChange:P=>A("defaultPickupLocation",P.target.value),placeholder:"e.g., JFK Airport Terminal 4",className:"form-input"})]}),i.jsxs("div",{className:"form-group",children:[i.jsx("label",{htmlFor:"defaultDropoff",className:"form-label",children:"Default Dropoff Location"}),i.jsx("input",{type:"text",id:"defaultDropoff",value:r.defaultDropoffLocation||"",onChange:P=>A("defaultDropoffLocation",P.target.value),placeholder:"e.g., Hilton Downtown",className:"form-input"})]}),i.jsxs("div",{className:"form-group",children:[i.jsx("label",{htmlFor:"timezone",className:"form-label",children:"Time Zone"}),i.jsxs("select",{id:"timezone",value:r.timeZone||"America/New_York",onChange:P=>A("timeZone",P.target.value),className:"form-select",children:[i.jsx("option",{value:"America/New_York",children:"Eastern Time"}),i.jsx("option",{value:"America/Chicago",children:"Central Time"}),i.jsx("option",{value:"America/Denver",children:"Mountain Time"}),i.jsx("option",{value:"America/Los_Angeles",children:"Pacific Time"}),i.jsx("option",{value:"UTC",children:"UTC"})]})]}),i.jsx("div",{className:"form-group",children:i.jsxs("div",{className:"checkbox-option",children:[i.jsx("input",{type:"checkbox",checked:r.notificationsEnabled||!1,onChange:P=>A("notificationsEnabled",P.target.checked),className:"form-checkbox mr-3"}),i.jsx("span",{className:"font-medium",children:"Enable Email/SMS Notifications"})]})})]})})]}),i.jsxs("div",{className:"bg-white rounded-2xl shadow-lg border border-slate-200/60 overflow-hidden",children:[i.jsxs("div",{className:"bg-gradient-to-r from-orange-50 to-red-50 px-8 py-6 border-b border-slate-200/60",children:[i.jsx("h2",{className:"text-xl font-bold text-slate-800",children:"Test VIP Data Management"}),i.jsx("p",{className:"text-slate-600 mt-1",children:"Create and manage test VIP data for application testing"})]}),i.jsxs("div",{className:"p-8",children:[i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[i.jsxs("div",{className:"bg-green-50 border border-green-200 rounded-xl p-6",children:[i.jsx("h3",{className:"text-lg font-bold text-slate-800 mb-3",children:"Create Test VIPs"}),i.jsx("p",{className:"text-slate-600 mb-4",children:"Generate 20 diverse test VIPs (10 Admin department, 10 Office of Development) with realistic data including flights, transport modes, and special requirements."}),i.jsxs("ul",{className:"text-sm text-slate-600 mb-4 space-y-1",children:[i.jsx("li",{children:"β€’ Mixed flight and self-driving transport modes"}),i.jsx("li",{children:"β€’ Single flights, connecting flights, and multi-segment journeys"}),i.jsx("li",{children:"β€’ Diverse organizations and special requirements"}),i.jsx("li",{children:"β€’ Realistic arrival dates (tomorrow and day after)"})]}),i.jsx("button",{className:"btn btn-success w-full",onClick:G,disabled:x,children:x?i.jsxs(i.Fragment,{children:[i.jsx("span",{className:"animate-spin inline-block w-4 h-4 border-2 border-white border-t-transparent rounded-full mr-2"}),"Creating Test VIPs..."]}):"🎭 Create 20 Test VIPs"})]}),i.jsxs("div",{className:"bg-red-50 border border-red-200 rounded-xl p-6",children:[i.jsx("h3",{className:"text-lg font-bold text-slate-800 mb-3",children:"Remove Test VIPs"}),i.jsx("p",{className:"text-slate-600 mb-4",children:"Remove all test VIPs from the system. This will delete VIPs from the following test organizations:"}),i.jsx("div",{className:"text-xs text-slate-500 mb-4 max-h-20 overflow-y-auto",children:i.jsxs("div",{className:"grid grid-cols-1 gap-1",children:[Ec().slice(0,8).map(P=>i.jsxs("div",{children:["β€’ ",P]},P)),i.jsx("div",{className:"text-slate-400",children:"... and 12 more organizations"})]})}),i.jsx("button",{className:"btn btn-danger w-full",onClick:K,disabled:x,children:x?i.jsxs(i.Fragment,{children:[i.jsx("span",{className:"animate-spin inline-block w-4 h-4 border-2 border-white border-t-transparent rounded-full mr-2"}),"Removing Test VIPs..."]}):"πŸ—‘οΈ Remove All Test VIPs"})]})]}),h&&i.jsx("div",{className:`mt-6 p-4 rounded-lg text-center font-medium ${h.includes("βœ…")||h.includes("πŸ—‘οΈ")?"bg-green-50 text-green-700 border border-green-200":"bg-red-50 text-red-700 border border-red-200"}`,children:h}),i.jsxs("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-4 mt-6",children:[i.jsx("h4",{className:"font-semibold text-blue-900 mb-2",children:"πŸ’‘ Test Data Details"}),i.jsxs("div",{className:"text-sm text-blue-800 space-y-1",children:[i.jsxs("p",{children:[i.jsx("strong",{children:"Admin Department (10 VIPs):"})," University officials, ambassadors, ministers, and executives"]}),i.jsxs("p",{children:[i.jsx("strong",{children:"Office of Development (10 VIPs):"})," Donors, foundation leaders, and philanthropists"]}),i.jsxs("p",{children:[i.jsx("strong",{children:"Transport Modes:"})," Mix of flights (single, connecting, multi-segment) and self-driving"]}),i.jsxs("p",{children:[i.jsx("strong",{children:"Special Requirements:"})," Dietary restrictions, accessibility needs, security details, interpreters"]}),i.jsxs("p",{children:[i.jsx("strong",{children:"Full Day Schedules:"})," Each VIP gets 5-7 realistic events including meetings, meals, tours, and presentations"]}),i.jsxs("p",{children:[i.jsx("strong",{children:"Schedule Types:"})," Airport pickup, welcome breakfast, department meetings, working lunches, campus tours, receptions"]})]})]})]})]}),i.jsxs("div",{className:"bg-white rounded-2xl shadow-lg border border-slate-200/60 overflow-hidden",children:[i.jsxs("div",{className:"bg-gradient-to-r from-purple-50 to-pink-50 px-8 py-6 border-b border-slate-200/60",children:[i.jsx("h2",{className:"text-xl font-bold text-slate-800",children:"API Documentation"}),i.jsx("p",{className:"text-slate-600 mt-1",children:"Developer resources and API testing"})]}),i.jsxs("div",{className:"p-8",children:[i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[i.jsxs("div",{className:"bg-blue-50 border border-blue-200 rounded-xl p-6",children:[i.jsx("h3",{className:"text-lg font-bold text-slate-800 mb-3",children:"Interactive API Documentation"}),i.jsx("p",{className:"text-slate-600 mb-4",children:"Explore and test all API endpoints with the interactive Swagger UI documentation."}),i.jsx("button",{className:"btn btn-primary w-full mb-2",onClick:()=>window.open(`${vt}/api-docs.html`,"_blank"),children:"Open API Documentation"}),i.jsx("p",{className:"text-xs text-slate-500",children:"Opens in a new tab with full endpoint documentation and testing capabilities"})]}),i.jsxs("div",{className:"bg-green-50 border border-green-200 rounded-xl p-6",children:[i.jsx("h3",{className:"text-lg font-bold text-slate-800 mb-3",children:"Quick API Examples"}),i.jsxs("div",{className:"space-y-2 text-sm",children:[i.jsxs("div",{children:[i.jsx("span",{className:"font-medium",children:"Health Check:"}),i.jsx("code",{className:"ml-2 bg-white px-2 py-1 rounded text-xs",children:"GET /api/health"})]}),i.jsxs("div",{children:[i.jsx("span",{className:"font-medium",children:"Get VIPs:"}),i.jsx("code",{className:"ml-2 bg-white px-2 py-1 rounded text-xs",children:"GET /api/vips"})]}),i.jsxs("div",{children:[i.jsx("span",{className:"font-medium",children:"Get Drivers:"}),i.jsx("code",{className:"ml-2 bg-white px-2 py-1 rounded text-xs",children:"GET /api/drivers"})]}),i.jsxs("div",{children:[i.jsx("span",{className:"font-medium",children:"Flight Info:"}),i.jsx("code",{className:"ml-2 bg-white px-2 py-1 rounded text-xs",children:"GET /api/flights/UA1234"})]})]}),i.jsx("button",{className:"btn btn-secondary w-full mt-4",onClick:()=>window.open("/README-API.md","_blank"),children:"View API Guide"})]})]}),i.jsx("div",{className:"bg-amber-50 border border-amber-200 rounded-lg p-4 mt-6",children:i.jsxs("p",{className:"text-amber-800",children:[i.jsx("strong",{children:"Pro Tip:"})," The interactive documentation allows you to test API endpoints directly in your browser. Perfect for developers integrating with the VIP Coordinator system!"]})})]})]}),i.jsxs("div",{className:"text-center",children:[i.jsx("button",{className:"btn btn-success text-lg px-8 py-4",onClick:M,disabled:d,children:d?"Saving...":"Save All Settings"}),p&&i.jsx("div",{className:`mt-4 p-4 rounded-lg ${p.includes("successfully")?"bg-green-50 text-green-700 border border-green-200":"bg-red-50 text-red-700 border border-red-200"}`,children:p})]})]})},n0=({currentUser:e})=>{const[t,n]=S.useState([]),[r,s]=S.useState([]),[o,a]=S.useState(!0),[l,c]=S.useState(null),[d,m]=S.useState("all"),[p,f]=S.useState(null);if((e==null?void 0:e.role)!=="administrator")return i.jsxs("div",{className:"p-6 bg-red-50 border border-red-200 rounded-lg",children:[i.jsx("h2",{className:"text-xl font-semibold text-red-800 mb-2",children:"Access Denied"}),i.jsx("p",{className:"text-red-600",children:"You need administrator privileges to access user management."})]});const g=async()=>{try{const v=localStorage.getItem("authToken"),N=await fetch(`${vt}/auth/users`,{headers:{Authorization:`Bearer ${v}`,"Content-Type":"application/json"}});if(!N.ok)throw new Error("Failed to fetch users");const k=await N.json();n(k)}catch(v){c(v instanceof Error?v.message:"Failed to fetch users")}finally{a(!1)}},b=async()=>{try{const v=localStorage.getItem("authToken"),N=await fetch(`${vt}/auth/users/pending/list`,{headers:{Authorization:`Bearer ${v}`,"Content-Type":"application/json"}});if(!N.ok)throw new Error("Failed to fetch pending users");const k=await N.json();s(k)}catch(v){c(v instanceof Error?v.message:"Failed to fetch pending users")}},w=async(v,N)=>{f(v);try{const k=localStorage.getItem("authToken");if(!(await fetch(`${vt}/auth/users/${v}/role`,{method:"PATCH",headers:{Authorization:`Bearer ${k}`,"Content-Type":"application/json"},body:JSON.stringify({role:N})})).ok)throw new Error("Failed to update user role");await g()}catch(k){c(k instanceof Error?k.message:"Failed to update user role")}finally{f(null)}},j=async(v,N)=>{if(confirm(`Are you sure you want to delete user "${N}"? This action cannot be undone.`))try{const k=localStorage.getItem("authToken");if(!(await fetch(`${vt}/auth/users/${v}`,{method:"DELETE",headers:{Authorization:`Bearer ${k}`,"Content-Type":"application/json"}})).ok)throw new Error("Failed to delete user");await g(),await b()}catch(k){c(k instanceof Error?k.message:"Failed to delete user")}},x=async(v,N)=>{f(v);try{const k=localStorage.getItem("authToken");if(!(await fetch(`${vt}/auth/users/${v}/approval`,{method:"PATCH",headers:{Authorization:`Bearer ${k}`,"Content-Type":"application/json"},body:JSON.stringify({status:"approved"})})).ok)throw new Error("Failed to approve user");await g(),await b()}catch(k){c(k instanceof Error?k.message:"Failed to approve user")}finally{f(null)}},u=async(v,N)=>{if(confirm(`Are you sure you want to deny access for "${N}"?`)){f(v);try{const k=localStorage.getItem("authToken");if(!(await fetch(`${vt}/auth/users/${v}/approval`,{method:"PATCH",headers:{Authorization:`Bearer ${k}`,"Content-Type":"application/json"},body:JSON.stringify({status:"denied"})})).ok)throw new Error("Failed to deny user");await g(),await b()}catch(k){c(k instanceof Error?k.message:"Failed to deny user")}finally{f(null)}}};S.useEffect(()=>{g(),b()},[]),S.useEffect(()=>{d==="pending"&&b()},[d]);const h=v=>new Date(v).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}),y=v=>{switch(v){case"administrator":return"bg-red-100 text-red-800 border-red-200";case"coordinator":return"bg-blue-100 text-blue-800 border-blue-200";case"driver":return"bg-green-100 text-green-800 border-green-200";default:return"bg-gray-100 text-gray-800 border-gray-200"}};return o?i.jsx("div",{className:"p-6",children:i.jsxs("div",{className:"animate-pulse",children:[i.jsx("div",{className:"h-8 bg-gray-200 rounded-lg w-1/4 mb-6"}),i.jsx("div",{className:"space-y-4",children:[1,2,3].map(v=>i.jsx("div",{className:"h-20 bg-gray-200 rounded-lg"},v))})]})}):i.jsxs("div",{className:"p-6",children:[i.jsxs("div",{className:"mb-6",children:[i.jsx("h2",{className:"text-2xl font-bold text-gray-900 mb-2",children:"User Management"}),i.jsx("p",{className:"text-gray-600",children:"Manage user accounts and permissions (PostgreSQL Database)"})]}),l&&i.jsxs("div",{className:"mb-6 p-4 bg-red-50 border border-red-200 rounded-lg",children:[i.jsx("p",{className:"text-red-600",children:l}),i.jsx("button",{onClick:()=>c(null),className:"mt-2 text-sm text-red-500 hover:text-red-700",children:"Dismiss"})]}),i.jsx("div",{className:"mb-6",children:i.jsx("div",{className:"border-b border-gray-200",children:i.jsxs("nav",{className:"-mb-px flex space-x-8",children:[i.jsxs("button",{onClick:()=>m("all"),className:`py-2 px-1 border-b-2 font-medium text-sm ${d==="all"?"border-blue-500 text-blue-600":"border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300"}`,children:["πŸ‘₯ All Users (",t.length,")"]}),i.jsxs("button",{onClick:()=>m("pending"),className:`py-2 px-1 border-b-2 font-medium text-sm ${d==="pending"?"border-orange-500 text-orange-600":"border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300"}`,children:["⏳ Pending Approval (",r.length,")",r.length>0&&i.jsx("span",{className:"ml-2 inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-orange-100 text-orange-800",children:r.length})]})]})})}),d==="all"&&i.jsxs("div",{className:"bg-white shadow-sm border border-gray-200 rounded-lg overflow-hidden",children:[i.jsx("div",{className:"px-6 py-4 border-b border-gray-200 bg-gray-50",children:i.jsxs("h3",{className:"text-lg font-medium text-gray-900",children:["All Users (",t.length,")"]})}),i.jsx("div",{className:"divide-y divide-gray-200",children:t.map(v=>i.jsx("div",{className:"p-6 hover:bg-gray-50",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center space-x-4",children:[v.picture?i.jsx("img",{src:v.picture,alt:v.name,className:"w-12 h-12 rounded-full"}):i.jsx("div",{className:"w-12 h-12 rounded-full bg-gray-300 flex items-center justify-center",children:i.jsx("span",{className:"text-gray-600 font-medium",children:v.name.charAt(0).toUpperCase()})}),i.jsxs("div",{children:[i.jsx("h4",{className:"text-lg font-medium text-gray-900",children:v.name}),i.jsx("p",{className:"text-gray-600",children:v.email}),i.jsxs("div",{className:"flex items-center space-x-4 mt-1 text-sm text-gray-500",children:[i.jsxs("span",{children:["Joined: ",h(v.created_at)]}),v.last_sign_in_at&&i.jsxs("span",{children:["Last login: ",h(v.last_sign_in_at)]}),i.jsxs("span",{className:"capitalize",children:["via ",v.provider]})]})]})]}),i.jsxs("div",{className:"flex items-center space-x-4",children:[i.jsxs("div",{className:"flex items-center space-x-2",children:[i.jsx("span",{className:"text-sm text-gray-600",children:"Role:"}),i.jsxs("select",{value:v.role,onChange:N=>w(v.email,N.target.value),disabled:p===v.email||v.email===e.email,className:`px-3 py-1 border rounded-md text-sm font-medium ${y(v.role)} ${p===v.email?"opacity-50 cursor-not-allowed":"cursor-pointer hover:bg-opacity-80"}`,children:[i.jsx("option",{value:"coordinator",children:"Coordinator"}),i.jsx("option",{value:"administrator",children:"Administrator"}),i.jsx("option",{value:"driver",children:"Driver"})]})]}),v.email!==e.email&&i.jsx("button",{onClick:()=>j(v.email,v.name),className:"px-3 py-1 text-sm text-red-600 hover:text-red-800 hover:bg-red-50 rounded-md border border-red-200 transition-colors",children:"πŸ—‘οΈ Delete"}),v.email===e.email&&i.jsx("span",{className:"px-3 py-1 text-sm text-blue-600 bg-blue-50 rounded-md border border-blue-200",children:"πŸ‘€ You"})]})]})},v.email))}),t.length===0&&i.jsx("div",{className:"p-6 text-center text-gray-500",children:"No users found."})]}),d==="pending"&&i.jsxs("div",{className:"bg-white shadow-sm border border-gray-200 rounded-lg overflow-hidden",children:[i.jsxs("div",{className:"px-6 py-4 border-b border-gray-200 bg-orange-50",children:[i.jsxs("h3",{className:"text-lg font-medium text-gray-900",children:["Pending Approval (",r.length,")"]}),i.jsx("p",{className:"text-sm text-gray-600 mt-1",children:"Users waiting for administrator approval to access the system"})]}),i.jsx("div",{className:"divide-y divide-gray-200",children:r.map(v=>i.jsx("div",{className:"p-6 hover:bg-gray-50",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center space-x-4",children:[v.picture?i.jsx("img",{src:v.picture,alt:v.name,className:"w-12 h-12 rounded-full"}):i.jsx("div",{className:"w-12 h-12 rounded-full bg-gray-300 flex items-center justify-center",children:i.jsx("span",{className:"text-gray-600 font-medium",children:v.name.charAt(0).toUpperCase()})}),i.jsxs("div",{children:[i.jsx("h4",{className:"text-lg font-medium text-gray-900",children:v.name}),i.jsx("p",{className:"text-gray-600",children:v.email}),i.jsxs("div",{className:"flex items-center space-x-4 mt-1 text-sm text-gray-500",children:[i.jsxs("span",{children:["Requested: ",h(v.created_at)]}),i.jsxs("span",{className:"capitalize",children:["via ",v.provider]}),i.jsx("span",{className:`px-2 py-1 rounded-full text-xs font-medium ${y(v.role)}`,children:v.role})]})]})]}),i.jsxs("div",{className:"flex items-center space-x-3",children:[i.jsx("button",{onClick:()=>x(v.email,v.name),disabled:p===v.email,className:`px-4 py-2 text-sm font-medium text-white bg-green-600 hover:bg-green-700 rounded-md transition-colors ${p===v.email?"opacity-50 cursor-not-allowed":""}`,children:p===v.email?"⏳ Approving...":"βœ… Approve"}),i.jsx("button",{onClick:()=>u(v.email,v.name),disabled:p===v.email,className:`px-4 py-2 text-sm font-medium text-white bg-red-600 hover:bg-red-700 rounded-md transition-colors ${p===v.email?"opacity-50 cursor-not-allowed":""}`,children:p===v.email?"⏳ Denying...":"❌ Deny"})]})]})},v.email))}),r.length===0&&i.jsxs("div",{className:"p-6 text-center text-gray-500",children:[i.jsx("div",{className:"text-6xl mb-4",children:"βœ…"}),i.jsx("p",{className:"text-lg font-medium mb-2",children:"No pending approvals"}),i.jsx("p",{className:"text-sm",children:"All users have been processed."})]})]}),i.jsxs("div",{className:"mt-6 p-4 bg-blue-50 border border-blue-200 rounded-lg",children:[i.jsx("h4",{className:"font-medium text-blue-900 mb-2",children:"Role Descriptions:"}),i.jsxs("ul",{className:"text-sm text-blue-800 space-y-1",children:[i.jsxs("li",{children:[i.jsx("strong",{children:"Administrator:"})," Full access to all features including user management"]}),i.jsxs("li",{children:[i.jsx("strong",{children:"Coordinator:"})," Can manage VIPs, drivers, and schedules"]}),i.jsxs("li",{children:[i.jsx("strong",{children:"Driver:"})," Can view assigned schedules and update status"]})]})]}),i.jsxs("div",{className:"mt-4 p-4 bg-orange-50 border border-orange-200 rounded-lg",children:[i.jsx("h4",{className:"font-medium text-orange-900 mb-2",children:"πŸ” User Approval System:"}),i.jsx("p",{className:"text-sm text-orange-800",children:'New users (except the first administrator) require approval before accessing the system. Users with pending approval will see a "pending approval" message when they try to sign in.'})]}),i.jsxs("div",{className:"mt-4 p-4 bg-green-50 border border-green-200 rounded-lg",children:[i.jsx("h4",{className:"font-medium text-green-900 mb-2",children:"βœ… PostgreSQL Database:"}),i.jsx("p",{className:"text-sm text-green-800",children:"User data is stored in your PostgreSQL database with proper indexing and relationships. All user management operations are transactional and fully persistent across server restarts."})]})]})};const r0=({onLogin:e,errorMessage:t})=>{const[n,r]=S.useState(null),[s,o]=S.useState(!0);return S.useEffect(()=>{U("/auth/setup").then(a=>a.json()).then(a=>{r(a),o(!1)}).catch(a=>{console.error("Error checking setup status:",a),o(!1)})},[]),s?i.jsx("div",{className:"login-container",children:i.jsx("div",{className:"login-card",children:i.jsx("div",{className:"loading",children:"Loading..."})})}):i.jsx("div",{className:"login-container",children:i.jsxs("div",{className:"login-card",children:[i.jsxs("div",{className:"login-header",children:[i.jsx("h1",{children:"VIP Coordinator"}),i.jsx("p",{children:"Secure access required"})]}),!(n!=null&&n.firstAdminCreated)&&i.jsxs("div",{className:"setup-notice",children:[i.jsx("h3",{children:"πŸš€ First Time Setup"}),i.jsx("p",{children:"The first person to sign in will be promoted to administrator automatically."})]}),i.jsxs("div",{className:"login-content",children:[i.jsxs("button",{className:"google-login-btn",onClick:e,children:[i.jsx("svg",{className:"google-icon",viewBox:"0 0 24 24",children:i.jsx("path",{fill:"#635dff",d:"M22 12.07c0-5.52-4.48-10-10-10s-10 4.48-10 10a9.97 9.97 0 006.85 9.48.73.73 0 00.95-.7v-3.05c-2.79.61-3.38-1.19-3.38-1.19-.46-1.17-1.12-1.49-1.12-1.49-.91-.62.07-.61.07-.61 1 .07 1.53 1.03 1.53 1.03.9 1.53 2.37 1.09 2.96.83.09-.65.35-1.09.63-1.34-2.23-.25-4.57-1.12-4.57-4.96 0-1.1.39-2 1.03-2.7-.1-.25-.45-1.25.1-2.6 0 0 .84-.27 2.75 1.02a9.53 9.53 0 015 0c1.91-1.29 2.75-1.02 2.75-1.02.55 1.35.2 2.35.1 2.6.64.7 1.03 1.6 1.03 2.7 0 3.85-2.34 4.71-4.58 4.95.36.31.69.92.69 1.86v2.75c0 .39.27.71.66.79a10 10 0 007.61-9.71z"})}),"Continue with Auth0"]}),i.jsx("div",{className:"login-info",children:i.jsx("p",{children:(n==null?void 0:n.authProvider)==="auth0"?"Sign in with your organisation account. We use Auth0 for secure authentication.":"Authentication service is being configured. Please try again later."})}),t&&i.jsx("div",{className:"dev-login-error",style:{marginTop:"1rem"},children:t})]}),i.jsx("div",{className:"login-footer",children:i.jsx("p",{children:"Secure authentication powered by Auth0"})})]})})};const rs={}.VITE_AUTH0_AUDIENCE;function s0(){const{isLoading:e,isAuthenticated:t,loginWithRedirect:n,logout:r,getAccessTokenSilently:s,user:o,error:a}=Ff(),[l,c]=S.useState(null),[d,m]=S.useState(!0),[p,f]=S.useState(null),[g,b]=S.useState(!1);S.useEffect(()=>{e||(async()=>{if(!t){c(null),f(null),b(!1),m(!1);return}m(!0),b(!1),f(null);try{const v=await s({authorizationParams:{...rs?{audience:rs}:{},scope:"openid profile email"}});localStorage.setItem("authToken",v);const N=await U("/auth/me",{headers:{Authorization:`Bearer ${v}`}});if(N.status===403){const A=await N.json();c(null),b(!0),f(A.message||"Your account is pending administrator approval.");return}if(!N.ok)throw new Error(`Failed to load profile (${N.status})`);const k=await N.json(),C=k.user||k,z=C.name||(o==null?void 0:o.name)||(o==null?void 0:o.nickname)||(o==null?void 0:o.email)||C.email;c({...C,name:z,role:C.role,picture:C.picture||(o==null?void 0:o.picture)})}catch(v){console.error("Authentication bootstrap failed:",v),c(null),f("Authentication failed. Please try signing in again.")}finally{m(!1)}})()},[t,e,s,o]);const w=()=>{localStorage.removeItem("authToken"),r({logoutParams:{returnTo:window.location.origin}})};if(e||d)return i.jsx("div",{className:"min-h-screen bg-gradient-to-br from-slate-50 to-slate-100 flex justify-center items-center",children:i.jsxs("div",{className:"bg-white rounded-2xl shadow-xl p-8 flex items-center space-x-4",children:[i.jsx("div",{className:"w-8 h-8 border-4 border-blue-600 border-t-transparent rounded-full animate-spin"}),i.jsx("span",{className:"text-lg font-medium text-slate-700",children:"Loading VIP Coordinator..."})]})});if(g)return i.jsx("div",{className:"min-h-screen bg-gradient-to-br from-amber-50 to-rose-50 flex justify-center items-center px-4",children:i.jsxs("div",{className:"bg-white border border-amber-200/60 rounded-2xl shadow-xl max-w-xl w-full p-8 space-y-4 text-center",children:[i.jsx("div",{className:"flex justify-center",children:i.jsx("div",{className:"w-16 h-16 rounded-full bg-amber-100 text-amber-600 flex items-center justify-center text-3xl",children:"⏳"})}),i.jsx("h1",{className:"text-2xl font-bold text-slate-800",children:"Awaiting Administrator Approval"}),i.jsx("p",{className:"text-slate-600",children:p||"Thanks for signing in. An administrator needs to approve your account before you can access the dashboard."}),i.jsx("button",{onClick:w,className:"btn btn-secondary mt-4",children:"Sign out"})]})});const j=async()=>{try{await n({authorizationParams:{...rs?{audience:rs}:{},scope:"openid profile email",redirect_uri:`${window.location.origin}/auth/callback`}})}catch(y){console.error("Auth0 login failed:",y),f((y==null?void 0:y.message)||"Authentication failed. Please try again.")}};if(!t||!l)return i.jsx(r0,{onLogin:j,errorMessage:p||(a==null?void 0:a.message)});const x=l.name&&l.name.trim().length>0?l.name:l.email||"User",u=x.trim().charAt(0).toUpperCase(),h=l.role||"user";return i.jsx(Lg,{children:i.jsxs("div",{className:"min-h-screen bg-gradient-to-br from-slate-50 via-blue-50 to-indigo-50",children:[i.jsx("nav",{className:"bg-white/80 backdrop-blur-lg border-b border-slate-200/60 sticky top-0 z-50",children:i.jsx("div",{className:"max-w-7xl mx-auto px-6 lg:px-8",children:i.jsxs("div",{className:"flex justify-between items-center h-16",children:[i.jsxs("div",{className:"flex items-center space-x-3",children:[i.jsx("div",{className:"w-8 h-8 bg-gradient-to-br from-blue-600 to-indigo-600 rounded-lg flex items-center justify-center",children:i.jsx("span",{className:"text-white font-bold text-sm",children:"VC"})}),i.jsx("h1",{className:"text-xl font-bold bg-gradient-to-r from-slate-800 to-slate-600 bg-clip-text text-transparent",children:"VIP Coordinator"})]}),i.jsxs("div",{className:"hidden md:flex items-center space-x-1",children:[i.jsx(we,{to:"/",className:"px-4 py-2 text-sm font-medium text-slate-700 hover:text-blue-600 hover:bg-blue-50 rounded-lg transition-all duration-200",children:"Dashboard"}),i.jsx(we,{to:"/vips",className:"px-4 py-2 text-sm font-medium text-slate-700 hover:text-blue-600 hover:bg-blue-50 rounded-lg transition-all duration-200",children:"VIPs"}),i.jsx(we,{to:"/drivers",className:"px-4 py-2 text-sm font-medium text-slate-700 hover:text-blue-600 hover:bg-blue-50 rounded-lg transition-all duration-200",children:"Drivers"}),h==="administrator"&&i.jsx(we,{to:"/admin",className:"px-4 py-2 text-sm font-medium text-slate-700 hover:text-amber-600 hover:bg-amber-50 rounded-lg transition-all duration-200",children:"Admin"}),h==="administrator"&&i.jsx(we,{to:"/users",className:"px-4 py-2 text-sm font-medium text-slate-700 hover:text-purple-600 hover:bg-purple-50 rounded-lg transition-all duration-200",children:"Users"})]}),i.jsxs("div",{className:"flex items-center space-x-4",children:[i.jsxs("div",{className:"hidden sm:flex items-center space-x-3",children:[i.jsx("div",{className:"w-8 h-8 bg-gradient-to-br from-slate-400 to-slate-600 rounded-full flex items-center justify-center overflow-hidden",children:l.picture?i.jsx("img",{src:l.picture,alt:x,className:"w-8 h-8 object-cover"}):i.jsx("span",{className:"text-white text-xs font-medium",children:u})}),i.jsxs("div",{className:"text-sm",children:[i.jsx("div",{className:"font-medium text-slate-900",children:x}),i.jsx("div",{className:"text-slate-500 capitalize",children:h})]})]}),i.jsx("button",{onClick:w,className:"bg-gradient-to-r from-red-500 to-red-600 hover:from-red-600 hover:to-red-700 text-white px-4 py-2 rounded-lg text-sm font-medium transition-all duration-200 shadow-lg hover:shadow-xl",children:"Logout"})]})]})})}),i.jsx("main",{className:"max-w-7xl mx-auto px-6 lg:px-8 py-8",children:i.jsxs(Pg,{children:[i.jsx(ft,{path:"/",element:i.jsx(Qg,{})}),i.jsx(ft,{path:"/vips",element:i.jsx(Wg,{})}),i.jsx(ft,{path:"/vips/:id",element:i.jsx(Hg,{})}),i.jsx(ft,{path:"/drivers",element:i.jsx(Jg,{})}),i.jsx(ft,{path:"/drivers/:driverId",element:i.jsx(Yg,{})}),i.jsx(ft,{path:"/admin",element:i.jsx(t0,{})}),i.jsx(ft,{path:"/users",element:i.jsx(n0,{currentUser:l})})]})})]})})}const fh={}.VITE_AUTH0_DOMAIN,gh={}.VITE_AUTH0_CLIENT_ID,Tc={}.VITE_AUTH0_AUDIENCE;if(!fh||!gh)throw new Error("Auth0 environment variables are missing. Please set VITE_AUTH0_DOMAIN and VITE_AUTH0_CLIENT_ID.");const xh={redirect_uri:`${window.location.origin}/auth/callback`,scope:"openid profile email"};Tc&&(xh.audience=Tc);Bi.createRoot(document.getElementById("root")).render(i.jsx(Zo.StrictMode,{children:i.jsx($f,{domain:fh,clientId:gh,authorizationParams:xh,cacheLocation:"localstorage",useRefreshTokens:!0,children:i.jsx(s0,{})})}));