(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 l of s)if(l.type==="childList")for(const o of l.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&r(o)}).observe(document,{childList:!0,subtree:!0});function n(s){const l={};return s.integrity&&(l.integrity=s.integrity),s.referrerPolicy&&(l.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?l.credentials="include":s.crossOrigin==="anonymous"?l.credentials="omit":l.credentials="same-origin",l}function r(s){if(s.ep)return;s.ep=!0;const l=n(s);fetch(s.href,l)}})();var cc={exports:{}},Ci={},dc={exports:{}},Q={};/** * @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 is=Symbol.for("react.element"),lp=Symbol.for("react.portal"),op=Symbol.for("react.fragment"),ap=Symbol.for("react.strict_mode"),up=Symbol.for("react.profiler"),cp=Symbol.for("react.provider"),dp=Symbol.for("react.context"),fp=Symbol.for("react.forward_ref"),pp=Symbol.for("react.suspense"),hp=Symbol.for("react.memo"),mp=Symbol.for("react.lazy"),Fa=Symbol.iterator;function xp(e){return e===null||typeof e!="object"?null:(e=Fa&&e[Fa]||e["@@iterator"],typeof e=="function"?e:null)}var fc={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},pc=Object.assign,hc={};function ur(e,t,n){this.props=e,this.context=t,this.refs=hc,this.updater=n||fc}ur.prototype.isReactComponent={};ur.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")};ur.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function mc(){}mc.prototype=ur.prototype;function Co(e,t,n){this.props=e,this.context=t,this.refs=hc,this.updater=n||fc}var Eo=Co.prototype=new mc;Eo.constructor=Co;pc(Eo,ur.prototype);Eo.isPureReactComponent=!0;var Ua=Array.isArray,xc=Object.prototype.hasOwnProperty,_o={current:null},gc={key:!0,ref:!0,__self:!0,__source:!0};function yc(e,t,n){var r,s={},l=null,o=null;if(t!=null)for(r in t.ref!==void 0&&(o=t.ref),t.key!==void 0&&(l=""+t.key),t)xc.call(t,r)&&!gc.hasOwnProperty(r)&&(s[r]=t[r]);var u=arguments.length-2;if(u===1)s.children=n;else if(1>>1,W=$[H];if(0>>1;Hs(Ve,I))bes(Se,Ve)?($[H]=Se,$[be]=I,H=be):($[H]=Ve,$[ve]=I,H=ve);else if(bes(Se,I))$[H]=Se,$[be]=I,H=be;else break e}}return D}function s($,D){var I=$.sortIndex-D.sortIndex;return I!==0?I:$.id-D.id}if(typeof performance=="object"&&typeof performance.now=="function"){var l=performance;e.unstable_now=function(){return l.now()}}else{var o=Date,u=o.now();e.unstable_now=function(){return o.now()-u}}var a=[],d=[],g=1,m=null,y=3,v=!1,h=!1,N=!1,P=typeof setTimeout=="function"?setTimeout:null,p=typeof clearTimeout=="function"?clearTimeout:null,c=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function f($){for(var D=n(d);D!==null;){if(D.callback===null)r(d);else if(D.startTime<=$)r(d),D.sortIndex=D.expirationTime,t(a,D);else break;D=n(d)}}function x($){if(N=!1,f($),!h)if(n(a)!==null)h=!0,V(b);else{var D=n(d);D!==null&&Z(x,D.startTime-$)}}function b($,D){h=!1,N&&(N=!1,p(L),L=-1),v=!0;var I=y;try{for(f(D),m=n(a);m!==null&&(!(m.expirationTime>D)||$&&!w());){var H=m.callback;if(typeof H=="function"){m.callback=null,y=m.priorityLevel;var W=H(m.expirationTime<=D);D=e.unstable_now(),typeof W=="function"?m.callback=W:m===n(a)&&r(a),f(D)}else r(a);m=n(a)}if(m!==null)var ae=!0;else{var ve=n(d);ve!==null&&Z(x,ve.startTime-D),ae=!1}return ae}finally{m=null,y=I,v=!1}}var E=!1,z=null,L=-1,U=5,j=-1;function w(){return!(e.unstable_now()-j$||125<$?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):U=0<$?Math.floor(1e3/$):5},e.unstable_getCurrentPriorityLevel=function(){return y},e.unstable_getFirstCallbackNode=function(){return n(a)},e.unstable_next=function($){switch(y){case 1:case 2:case 3:var D=3;break;default:D=y}var I=y;y=D;try{return $()}finally{y=I}},e.unstable_pauseExecution=function(){},e.unstable_requestPaint=function(){},e.unstable_runWithPriority=function($,D){switch($){case 1:case 2:case 3:case 4:case 5:break;default:$=3}var I=y;y=$;try{return D()}finally{y=I}},e.unstable_scheduleCallback=function($,D,I){var H=e.unstable_now();switch(typeof I=="object"&&I!==null?(I=I.delay,I=typeof I=="number"&&0H?($.sortIndex=I,t(d,$),n(a)===null&&$===n(d)&&(N?(p(L),L=-1):N=!0,Z(x,I-H))):($.sortIndex=W,t(a,$),h||v||(h=!0,V(b))),$},e.unstable_shouldYield=w,e.unstable_wrapCallback=function($){var D=y;return function(){var I=y;y=D;try{return $.apply(this,arguments)}finally{y=I}}}})(jc);Nc.exports=jc;var Ep=Nc.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 _p=C,rt=Ep;function R(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"),Cl=Object.prototype.hasOwnProperty,Tp=/^[: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]*$/,Ha={},qa={};function Pp(e){return Cl.call(qa,e)?!0:Cl.call(Ha,e)?!1:Tp.test(e)?qa[e]=!0:(Ha[e]=!0,!1)}function Op(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 Ap(e,t,n,r){if(t===null||typeof t>"u"||Op(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 Ue(e,t,n,r,s,l,o){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=l,this.removeEmptyString=o}var Le={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){Le[e]=new Ue(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var t=e[0];Le[t]=new Ue(t,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){Le[e]=new Ue(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){Le[e]=new Ue(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){Le[e]=new Ue(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){Le[e]=new Ue(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){Le[e]=new Ue(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){Le[e]=new Ue(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){Le[e]=new Ue(e,5,!1,e.toLowerCase(),null,!1,!1)});var Po=/[\-:]([a-z])/g;function Oo(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(Po,Oo);Le[t]=new Ue(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(Po,Oo);Le[t]=new Ue(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(Po,Oo);Le[t]=new Ue(t,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){Le[e]=new Ue(e,1,!1,e.toLowerCase(),null,!1,!1)});Le.xlinkHref=new Ue("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){Le[e]=new Ue(e,1,!1,e.toLowerCase(),null,!0,!0)});function Ao(e,t,n,r){var s=Le.hasOwnProperty(t)?Le[t]:null;(s!==null?s.type!==0:r||!(2u||s[o]!==l[u]){var a=` `+s[o].replace(" at new "," at ");return e.displayName&&a.includes("")&&(a=a.replace("",e.displayName)),a}while(1<=o&&0<=u);break}}}finally{Zi=!1,Error.prepareStackTrace=n}return(e=e?e.displayName||e.name:"")?Sr(e):""}function Rp(e){switch(e.tag){case 5:return Sr(e.type);case 16:return Sr("Lazy");case 13:return Sr("Suspense");case 19:return Sr("SuspenseList");case 0:case 2:case 15:return e=el(e.type,!1),e;case 11:return e=el(e.type.render,!1),e;case 1:return e=el(e.type,!0),e;default:return""}}function Pl(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 $n:return"Portal";case El:return"Profiler";case Ro:return"StrictMode";case _l:return"Suspense";case Tl:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case Cc:return(e.displayName||"Context")+".Consumer";case Sc:return(e._context.displayName||"Context")+".Provider";case Lo:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case zo:return t=e.displayName||null,t!==null?t:Pl(e.type)||"Memo";case Xt:t=e._payload,e=e._init;try{return Pl(e(t))}catch{}}return null}function Lp(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 Pl(t);case 8:return t===Ro?"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 pn(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function _c(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(t==="checkbox"||t==="radio")}function zp(e){var t=_c(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,l=n.set;return Object.defineProperty(e,t,{configurable:!0,get:function(){return s.call(this)},set:function(o){r=""+o,l.call(this,o)}}),Object.defineProperty(e,t,{enumerable:n.enumerable}),{getValue:function(){return r},setValue:function(o){r=""+o},stopTracking:function(){e._valueTracker=null,delete e[t]}}}}function gs(e){e._valueTracker||(e._valueTracker=zp(e))}function Tc(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var n=t.getValue(),r="";return e&&(r=_c(e)?e.checked?"true":"false":e.value),e=r,e!==n?(t.setValue(e),!0):!1}function Zs(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 Ol(e,t){var n=t.checked;return xe({},t,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:n??e._wrapperState.initialChecked})}function Ka(e,t){var n=t.defaultValue==null?"":t.defaultValue,r=t.checked!=null?t.checked:t.defaultChecked;n=pn(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 Pc(e,t){t=t.checked,t!=null&&Ao(e,"checked",t,!1)}function Al(e,t){Pc(e,t);var n=pn(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")?Rl(e,t.type,n):t.hasOwnProperty("defaultValue")&&Rl(e,t.type,pn(t.defaultValue)),t.checked==null&&t.defaultChecked!=null&&(e.defaultChecked=!!t.defaultChecked)}function Qa(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 Rl(e,t,n){(t!=="number"||Zs(e.ownerDocument)!==e)&&(n==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+n&&(e.defaultValue=""+n))}var Cr=Array.isArray;function Gn(e,t,n,r){if(e=e.options,t){t={};for(var s=0;s"+t.valueOf().toString()+"",t=ys.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)}});function Br(e,t){if(t){var n=e.firstChild;if(n&&n===e.lastChild&&n.nodeType===3){n.nodeValue=t;return}}e.textContent=t}var Pr={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},$p=["Webkit","ms","Moz","O"];Object.keys(Pr).forEach(function(e){$p.forEach(function(t){t=t+e.charAt(0).toUpperCase()+e.substring(1),Pr[t]=Pr[e]})});function Lc(e,t,n){return t==null||typeof t=="boolean"||t===""?"":n||typeof t!="number"||t===0||Pr.hasOwnProperty(e)&&Pr[e]?(""+t).trim():t+"px"}function zc(e,t){e=e.style;for(var n in t)if(t.hasOwnProperty(n)){var r=n.indexOf("--")===0,s=Lc(n,t[n],r);n==="float"&&(n="cssFloat"),r?e.setProperty(n,s):e[n]=s}}var Mp=xe({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 $l(e,t){if(t){if(Mp[e]&&(t.children!=null||t.dangerouslySetInnerHTML!=null))throw Error(R(137,e));if(t.dangerouslySetInnerHTML!=null){if(t.children!=null)throw Error(R(60));if(typeof t.dangerouslySetInnerHTML!="object"||!("__html"in t.dangerouslySetInnerHTML))throw Error(R(61))}if(t.style!=null&&typeof t.style!="object")throw Error(R(62))}}function Ml(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 Dl=null;function $o(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var Il=null,Yn=null,Xn=null;function Xa(e){if(e=as(e)){if(typeof Il!="function")throw Error(R(280));var t=e.stateNode;t&&(t=Oi(t),Il(e.stateNode,e.type,t))}}function $c(e){Yn?Xn?Xn.push(e):Xn=[e]:Yn=e}function Mc(){if(Yn){var e=Yn,t=Xn;if(Xn=Yn=null,Xa(e),t)for(e=0;e>>=0,e===0?32:31-(Qp(e)/Gp|0)|0}var vs=64,ws=4194304;function Er(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 ri(e,t){var n=e.pendingLanes;if(n===0)return 0;var r=0,s=e.suspendedLanes,l=e.pingedLanes,o=n&268435455;if(o!==0){var u=o&~s;u!==0?r=Er(u):(l&=o,l!==0&&(r=Er(l)))}else o=n&~s,o!==0?r=Er(o):l!==0&&(r=Er(l));if(r===0)return 0;if(t!==0&&t!==r&&!(t&s)&&(s=r&-r,l=t&-t,s>=l||s===16&&(l&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 ls(e,t,n){e.pendingLanes|=t,t!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,t=31-jt(t),e[t]=n}function Zp(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=Ar),lu=" ",ou=!1;function rd(e,t){switch(e){case"keyup":return Eh.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function sd(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var Dn=!1;function Th(e,t){switch(e){case"compositionend":return sd(t);case"keypress":return t.which!==32?null:(ou=!0,lu);case"textInput":return e=t.data,e===lu&&ou?null:e;default:return null}}function Ph(e,t){if(Dn)return e==="compositionend"||!Ho&&rd(e,t)?(e=td(),Bs=Fo=tn=null,Dn=!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=du(n)}}function ad(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?ad(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function ud(){for(var e=window,t=Zs();t instanceof e.HTMLIFrameElement;){try{var n=typeof t.contentWindow.location.href=="string"}catch{n=!1}if(n)e=t.contentWindow;else break;t=Zs(e.document)}return t}function qo(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 Ih(e){var t=ud(),n=e.focusedElem,r=e.selectionRange;if(t!==n&&n&&n.ownerDocument&&ad(n.ownerDocument.documentElement,n)){if(r!==null&&qo(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,l=Math.min(r.start,s);r=r.end===void 0?l:Math.min(r.end,s),!e.extend&&l>r&&(s=r,r=l,l=s),s=fu(n,l);var o=fu(n,r);s&&o&&(e.rangeCount!==1||e.anchorNode!==s.node||e.anchorOffset!==s.offset||e.focusNode!==o.node||e.focusOffset!==o.offset)&&(t=t.createRange(),t.setStart(s.node,s.offset),e.removeAllRanges(),l>r?(e.addRange(t),e.extend(o.node,o.offset)):(t.setEnd(o.node,o.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,In=null,ql=null,Lr=null,Wl=!1;function pu(e,t,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;Wl||In==null||In!==Zs(r)||(r=In,"selectionStart"in r&&qo(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}),Lr&&Wr(Lr,r)||(Lr=r,r=li(ql,"onSelect"),0Un||(e.current=Jl[Un],Jl[Un]=null,Un--)}function le(e,t){Un++,Jl[Un]=e.current,e.current=t}var hn={},De=gn(hn),Ye=gn(!1),En=hn;function nr(e,t){var n=e.type.contextTypes;if(!n)return hn;var r=e.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===t)return r.__reactInternalMemoizedMaskedChildContext;var s={},l;for(l in n)s[l]=t[l];return r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=t,e.__reactInternalMemoizedMaskedChildContext=s),s}function Xe(e){return e=e.childContextTypes,e!=null}function ai(){de(Ye),de(De)}function wu(e,t,n){if(De.current!==hn)throw Error(R(168));le(De,t),le(Ye,n)}function yd(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(R(108,Lp(e)||"Unknown",s));return xe({},n,r)}function ui(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||hn,En=De.current,le(De,e),le(Ye,Ye.current),!0}function ku(e,t,n){var r=e.stateNode;if(!r)throw Error(R(169));n?(e=yd(e,t,En),r.__reactInternalMemoizedMergedChildContext=e,de(Ye),de(De),le(De,e)):de(Ye),le(Ye,n)}var $t=null,Ai=!1,hl=!1;function vd(e){$t===null?$t=[e]:$t.push(e)}function Xh(e){Ai=!0,vd(e)}function yn(){if(!hl&&$t!==null){hl=!0;var e=0,t=se;try{var n=$t;for(se=1;e>=o,s-=o,Dt=1<<32-jt(t)+s|n<L?(U=z,z=null):U=z.sibling;var j=y(p,z,f[L],x);if(j===null){z===null&&(z=U);break}e&&z&&j.alternate===null&&t(p,z),c=l(j,c,L),E===null?b=j:E.sibling=j,E=j,z=U}if(L===f.length)return n(p,z),fe&&wn(p,L),b;if(z===null){for(;LL?(U=z,z=null):U=z.sibling;var w=y(p,z,j.value,x);if(w===null){z===null&&(z=U);break}e&&z&&w.alternate===null&&t(p,z),c=l(w,c,L),E===null?b=w:E.sibling=w,E=w,z=U}if(j.done)return n(p,z),fe&&wn(p,L),b;if(z===null){for(;!j.done;L++,j=f.next())j=m(p,j.value,x),j!==null&&(c=l(j,c,L),E===null?b=j:E.sibling=j,E=j);return fe&&wn(p,L),b}for(z=r(p,z);!j.done;L++,j=f.next())j=v(z,p,L,j.value,x),j!==null&&(e&&j.alternate!==null&&z.delete(j.key===null?L:j.key),c=l(j,c,L),E===null?b=j:E.sibling=j,E=j);return e&&z.forEach(function(A){return t(p,A)}),fe&&wn(p,L),b}function P(p,c,f,x){if(typeof f=="object"&&f!==null&&f.type===Mn&&f.key===null&&(f=f.props.children),typeof f=="object"&&f!==null){switch(f.$$typeof){case xs:e:{for(var b=f.key,E=c;E!==null;){if(E.key===b){if(b=f.type,b===Mn){if(E.tag===7){n(p,E.sibling),c=s(E,f.props.children),c.return=p,p=c;break e}}else if(E.elementType===b||typeof b=="object"&&b!==null&&b.$$typeof===Xt&&bu(b)===E.type){n(p,E.sibling),c=s(E,f.props),c.ref=wr(p,E,f),c.return=p,p=c;break e}n(p,E);break}else t(p,E);E=E.sibling}f.type===Mn?(c=Cn(f.props.children,p.mode,x,f.key),c.return=p,p=c):(x=Qs(f.type,f.key,f.props,null,p.mode,x),x.ref=wr(p,c,f),x.return=p,p=x)}return o(p);case $n:e:{for(E=f.key;c!==null;){if(c.key===E)if(c.tag===4&&c.stateNode.containerInfo===f.containerInfo&&c.stateNode.implementation===f.implementation){n(p,c.sibling),c=s(c,f.children||[]),c.return=p,p=c;break e}else{n(p,c);break}else t(p,c);c=c.sibling}c=Nl(f,p.mode,x),c.return=p,p=c}return o(p);case Xt:return E=f._init,P(p,c,E(f._payload),x)}if(Cr(f))return h(p,c,f,x);if(mr(f))return N(p,c,f,x);Es(p,f)}return typeof f=="string"&&f!==""||typeof f=="number"?(f=""+f,c!==null&&c.tag===6?(n(p,c.sibling),c=s(c,f),c.return=p,p=c):(n(p,c),c=kl(f,p.mode,x),c.return=p,p=c),o(p)):n(p,c)}return P}var sr=jd(!0),bd=jd(!1),fi=gn(null),pi=null,qn=null,Go=null;function Yo(){Go=qn=pi=null}function Xo(e){var t=fi.current;de(fi),e._currentValue=t}function to(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 Zn(e,t){pi=e,Go=qn=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&t&&(Ge=!0),e.firstContext=null)}function ht(e){var t=e._currentValue;if(Go!==e)if(e={context:e,memoizedValue:t,next:null},qn===null){if(pi===null)throw Error(R(308));qn=e,pi.dependencies={lanes:0,firstContext:e}}else qn=qn.next=e;return t}var jn=null;function Jo(e){jn===null?jn=[e]:jn.push(e)}function Sd(e,t,n,r){var s=t.interleaved;return s===null?(n.next=n,Jo(t)):(n.next=s.next,s.next=n),t.interleaved=n,Ht(e,r)}function Ht(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 Jt=!1;function Zo(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function Cd(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 Ft(e,t){return{eventTime:e,lane:t,tag:0,payload:null,callback:null,next:null}}function un(e,t,n){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,re&2){var s=r.pending;return s===null?t.next=t:(t.next=s.next,s.next=t),r.pending=t,Ht(e,n)}return s=r.interleaved,s===null?(t.next=t,Jo(r)):(t.next=s.next,s.next=t),r.interleaved=t,Ht(e,n)}function Us(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,Do(e,n)}}function Su(e,t){var n=e.updateQueue,r=e.alternate;if(r!==null&&(r=r.updateQueue,n===r)){var s=null,l=null;if(n=n.firstBaseUpdate,n!==null){do{var o={eventTime:n.eventTime,lane:n.lane,tag:n.tag,payload:n.payload,callback:n.callback,next:null};l===null?s=l=o:l=l.next=o,n=n.next}while(n!==null);l===null?s=l=t:l=l.next=t}else s=l=t;n={baseState:r.baseState,firstBaseUpdate:s,lastBaseUpdate:l,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 hi(e,t,n,r){var s=e.updateQueue;Jt=!1;var l=s.firstBaseUpdate,o=s.lastBaseUpdate,u=s.shared.pending;if(u!==null){s.shared.pending=null;var a=u,d=a.next;a.next=null,o===null?l=d:o.next=d,o=a;var g=e.alternate;g!==null&&(g=g.updateQueue,u=g.lastBaseUpdate,u!==o&&(u===null?g.firstBaseUpdate=d:u.next=d,g.lastBaseUpdate=a))}if(l!==null){var m=s.baseState;o=0,g=d=a=null,u=l;do{var y=u.lane,v=u.eventTime;if((r&y)===y){g!==null&&(g=g.next={eventTime:v,lane:0,tag:u.tag,payload:u.payload,callback:u.callback,next:null});e:{var h=e,N=u;switch(y=t,v=n,N.tag){case 1:if(h=N.payload,typeof h=="function"){m=h.call(v,m,y);break e}m=h;break e;case 3:h.flags=h.flags&-65537|128;case 0:if(h=N.payload,y=typeof h=="function"?h.call(v,m,y):h,y==null)break e;m=xe({},m,y);break e;case 2:Jt=!0}}u.callback!==null&&u.lane!==0&&(e.flags|=64,y=s.effects,y===null?s.effects=[u]:y.push(u))}else v={eventTime:v,lane:y,tag:u.tag,payload:u.payload,callback:u.callback,next:null},g===null?(d=g=v,a=m):g=g.next=v,o|=y;if(u=u.next,u===null){if(u=s.shared.pending,u===null)break;y=u,u=y.next,y.next=null,s.lastBaseUpdate=y,s.shared.pending=null}}while(!0);if(g===null&&(a=m),s.baseState=a,s.firstBaseUpdate=d,s.lastBaseUpdate=g,t=s.shared.interleaved,t!==null){s=t;do o|=s.lane,s=s.next;while(s!==t)}else l===null&&(s.shared.lanes=0);Pn|=o,e.lanes=o,e.memoizedState=m}}function Cu(e,t,n){if(e=t.effects,t.effects=null,e!==null)for(t=0;tn?n:4,e(!0);var r=xl.transition;xl.transition={};try{e(!1),t()}finally{se=n,xl.transition=r}}function Vd(){return mt().memoizedState}function tm(e,t,n){var r=dn(e);if(n={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null},Hd(e))qd(t,n);else if(n=Sd(e,t,n,r),n!==null){var s=Be();bt(n,e,r,s),Wd(n,t,r)}}function nm(e,t,n){var r=dn(e),s={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null};if(Hd(e))qd(t,s);else{var l=e.alternate;if(e.lanes===0&&(l===null||l.lanes===0)&&(l=t.lastRenderedReducer,l!==null))try{var o=t.lastRenderedState,u=l(o,n);if(s.hasEagerState=!0,s.eagerState=u,St(u,o)){var a=t.interleaved;a===null?(s.next=s,Jo(t)):(s.next=a.next,a.next=s),t.interleaved=s;return}}catch{}finally{}n=Sd(e,t,s,r),n!==null&&(s=Be(),bt(n,e,r,s),Wd(n,t,r))}}function Hd(e){var t=e.alternate;return e===me||t!==null&&t===me}function qd(e,t){zr=xi=!0;var n=e.pending;n===null?t.next=t:(t.next=n.next,n.next=t),e.pending=t}function Wd(e,t,n){if(n&4194240){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,Do(e,n)}}var gi={readContext:ht,useCallback:ze,useContext:ze,useEffect:ze,useImperativeHandle:ze,useInsertionEffect:ze,useLayoutEffect:ze,useMemo:ze,useReducer:ze,useRef:ze,useState:ze,useDebugValue:ze,useDeferredValue:ze,useTransition:ze,useMutableSource:ze,useSyncExternalStore:ze,useId:ze,unstable_isNewReconciler:!1},rm={readContext:ht,useCallback:function(e,t){return Tt().memoizedState=[e,t===void 0?null:t],e},useContext:ht,useEffect:_u,useImperativeHandle:function(e,t,n){return n=n!=null?n.concat([e]):null,Hs(4194308,4,Dd.bind(null,t,e),n)},useLayoutEffect:function(e,t){return Hs(4194308,4,e,t)},useInsertionEffect:function(e,t){return Hs(4,2,e,t)},useMemo:function(e,t){var n=Tt();return t=t===void 0?null:t,e=e(),n.memoizedState=[e,t],e},useReducer:function(e,t,n){var r=Tt();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=tm.bind(null,me,e),[r.memoizedState,e]},useRef:function(e){var t=Tt();return e={current:e},t.memoizedState=e},useState:Eu,useDebugValue:oa,useDeferredValue:function(e){return Tt().memoizedState=e},useTransition:function(){var e=Eu(!1),t=e[0];return e=em.bind(null,e[1]),Tt().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,n){var r=me,s=Tt();if(fe){if(n===void 0)throw Error(R(407));n=n()}else{if(n=t(),Oe===null)throw Error(R(349));Tn&30||Pd(r,t,n)}s.memoizedState=n;var l={value:n,getSnapshot:t};return s.queue=l,_u(Ad.bind(null,r,l,e),[e]),r.flags|=2048,es(9,Od.bind(null,r,l,n,t),void 0,null),n},useId:function(){var e=Tt(),t=Oe.identifierPrefix;if(fe){var n=It,r=Dt;n=(r&~(1<<32-jt(r)-1)).toString(32)+n,t=":"+t+"R"+n,n=Jr++,0<\/script>",e=e.removeChild(e.firstChild)):typeof r.is=="string"?e=o.createElement(n,{is:r.is}):(e=o.createElement(n),n==="select"&&(o=e,r.multiple?o.multiple=!0:r.size&&(o.size=r.size))):e=o.createElementNS(e,n),e[Pt]=t,e[Gr]=r,nf(e,t,!1,!1),t.stateNode=e;e:{switch(o=Ml(n,r),n){case"dialog":ue("cancel",e),ue("close",e),s=r;break;case"iframe":case"object":case"embed":ue("load",e),s=r;break;case"video":case"audio":for(s=0;s<_r.length;s++)ue(_r[s],e);s=r;break;case"source":ue("error",e),s=r;break;case"img":case"image":case"link":ue("error",e),ue("load",e),s=r;break;case"details":ue("toggle",e),s=r;break;case"input":Ka(e,r),s=Ol(e,r),ue("invalid",e);break;case"option":s=r;break;case"select":e._wrapperState={wasMultiple:!!r.multiple},s=xe({},r,{value:void 0}),ue("invalid",e);break;case"textarea":Ga(e,r),s=Ll(e,r),ue("invalid",e);break;default:s=r}$l(n,s),u=s;for(l in u)if(u.hasOwnProperty(l)){var a=u[l];l==="style"?zc(e,a):l==="dangerouslySetInnerHTML"?(a=a?a.__html:void 0,a!=null&&Rc(e,a)):l==="children"?typeof a=="string"?(n!=="textarea"||a!=="")&&Br(e,a):typeof a=="number"&&Br(e,""+a):l!=="suppressContentEditableWarning"&&l!=="suppressHydrationWarning"&&l!=="autoFocus"&&(Ir.hasOwnProperty(l)?a!=null&&l==="onScroll"&&ue("scroll",e):a!=null&&Ao(e,l,a,o))}switch(n){case"input":gs(e),Qa(e,r,!1);break;case"textarea":gs(e),Ya(e);break;case"option":r.value!=null&&e.setAttribute("value",""+pn(r.value));break;case"select":e.multiple=!!r.multiple,l=r.value,l!=null?Gn(e,!!r.multiple,l,!1):r.defaultValue!=null&&Gn(e,!!r.multiple,r.defaultValue,!0);break;default:typeof s.onClick=="function"&&(e.onclick=oi)}switch(n){case"button":case"input":case"select":case"textarea":r=!!r.autoFocus;break e;case"img":r=!0;break e;default:r=!1}}r&&(t.flags|=4)}t.ref!==null&&(t.flags|=512,t.flags|=2097152)}return $e(t),null;case 6:if(e&&t.stateNode!=null)sf(e,t,e.memoizedProps,r);else{if(typeof r!="string"&&t.stateNode===null)throw Error(R(166));if(n=bn(Xr.current),bn(At.current),Cs(t)){if(r=t.stateNode,n=t.memoizedProps,r[Pt]=t,(l=r.nodeValue!==n)&&(e=nt,e!==null))switch(e.tag){case 3:Ss(r.nodeValue,n,(e.mode&1)!==0);break;case 5:e.memoizedProps.suppressHydrationWarning!==!0&&Ss(r.nodeValue,n,(e.mode&1)!==0)}l&&(t.flags|=4)}else r=(n.nodeType===9?n:n.ownerDocument).createTextNode(r),r[Pt]=t,t.stateNode=r}return $e(t),null;case 13:if(de(he),r=t.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(fe&&tt!==null&&t.mode&1&&!(t.flags&128))Nd(),rr(),t.flags|=98560,l=!1;else if(l=Cs(t),r!==null&&r.dehydrated!==null){if(e===null){if(!l)throw Error(R(318));if(l=t.memoizedState,l=l!==null?l.dehydrated:null,!l)throw Error(R(317));l[Pt]=t}else rr(),!(t.flags&128)&&(t.memoizedState=null),t.flags|=4;$e(t),l=!1}else Nt!==null&&(yo(Nt),Nt=null),l=!0;if(!l)return t.flags&65536?t:null}return t.flags&128?(t.lanes=n,t):(r=r!==null,r!==(e!==null&&e.memoizedState!==null)&&r&&(t.child.flags|=8192,t.mode&1&&(e===null||he.current&1?_e===0&&(_e=3):ha())),t.updateQueue!==null&&(t.flags|=4),$e(t),null);case 4:return ir(),uo(e,t),e===null&&Kr(t.stateNode.containerInfo),$e(t),null;case 10:return Xo(t.type._context),$e(t),null;case 17:return Xe(t.type)&&ai(),$e(t),null;case 19:if(de(he),l=t.memoizedState,l===null)return $e(t),null;if(r=(t.flags&128)!==0,o=l.rendering,o===null)if(r)kr(l,!1);else{if(_e!==0||e!==null&&e.flags&128)for(e=t.child;e!==null;){if(o=mi(e),o!==null){for(t.flags|=128,kr(l,!1),r=o.updateQueue,r!==null&&(t.updateQueue=r,t.flags|=4),t.subtreeFlags=0,r=n,n=t.child;n!==null;)l=n,e=r,l.flags&=14680066,o=l.alternate,o===null?(l.childLanes=0,l.lanes=e,l.child=null,l.subtreeFlags=0,l.memoizedProps=null,l.memoizedState=null,l.updateQueue=null,l.dependencies=null,l.stateNode=null):(l.childLanes=o.childLanes,l.lanes=o.lanes,l.child=o.child,l.subtreeFlags=0,l.deletions=null,l.memoizedProps=o.memoizedProps,l.memoizedState=o.memoizedState,l.updateQueue=o.updateQueue,l.type=o.type,e=o.dependencies,l.dependencies=e===null?null:{lanes:e.lanes,firstContext:e.firstContext}),n=n.sibling;return le(he,he.current&1|2),t.child}e=e.sibling}l.tail!==null&&ye()>or&&(t.flags|=128,r=!0,kr(l,!1),t.lanes=4194304)}else{if(!r)if(e=mi(o),e!==null){if(t.flags|=128,r=!0,n=e.updateQueue,n!==null&&(t.updateQueue=n,t.flags|=4),kr(l,!0),l.tail===null&&l.tailMode==="hidden"&&!o.alternate&&!fe)return $e(t),null}else 2*ye()-l.renderingStartTime>or&&n!==1073741824&&(t.flags|=128,r=!0,kr(l,!1),t.lanes=4194304);l.isBackwards?(o.sibling=t.child,t.child=o):(n=l.last,n!==null?n.sibling=o:t.child=o,l.last=o)}return l.tail!==null?(t=l.tail,l.rendering=t,l.tail=t.sibling,l.renderingStartTime=ye(),t.sibling=null,n=he.current,le(he,r?n&1|2:n&1),t):($e(t),null);case 22:case 23:return pa(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&t.mode&1?et&1073741824&&($e(t),t.subtreeFlags&6&&(t.flags|=8192)):$e(t),null;case 24:return null;case 25:return null}throw Error(R(156,t.tag))}function dm(e,t){switch(Ko(t),t.tag){case 1:return Xe(t.type)&&ai(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return ir(),de(Ye),de(De),na(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return ta(t),null;case 13:if(de(he),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(R(340));rr()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return de(he),null;case 4:return ir(),null;case 10:return Xo(t.type._context),null;case 22:case 23:return pa(),null;case 24:return null;default:return null}}var Ts=!1,Me=!1,fm=typeof WeakSet=="function"?WeakSet:Set,B=null;function Wn(e,t){var n=e.ref;if(n!==null)if(typeof n=="function")try{n(null)}catch(r){ge(e,t,r)}else n.current=null}function co(e,t,n){try{n()}catch(r){ge(e,t,r)}}var Iu=!1;function pm(e,t){if(Kl=si,e=ud(),qo(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,l=r.focusNode;r=r.focusOffset;try{n.nodeType,l.nodeType}catch{n=null;break e}var o=0,u=-1,a=-1,d=0,g=0,m=e,y=null;t:for(;;){for(var v;m!==n||s!==0&&m.nodeType!==3||(u=o+s),m!==l||r!==0&&m.nodeType!==3||(a=o+r),m.nodeType===3&&(o+=m.nodeValue.length),(v=m.firstChild)!==null;)y=m,m=v;for(;;){if(m===e)break t;if(y===n&&++d===s&&(u=o),y===l&&++g===r&&(a=o),(v=m.nextSibling)!==null)break;m=y,y=m.parentNode}m=v}n=u===-1||a===-1?null:{start:u,end:a}}else n=null}n=n||{start:0,end:0}}else n=null;for(Ql={focusedElem:e,selectionRange:n},si=!1,B=t;B!==null;)if(t=B,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,B=e;else for(;B!==null;){t=B;try{var h=t.alternate;if(t.flags&1024)switch(t.tag){case 0:case 11:case 15:break;case 1:if(h!==null){var N=h.memoizedProps,P=h.memoizedState,p=t.stateNode,c=p.getSnapshotBeforeUpdate(t.elementType===t.type?N:vt(t.type,N),P);p.__reactInternalSnapshotBeforeUpdate=c}break;case 3:var f=t.stateNode.containerInfo;f.nodeType===1?f.textContent="":f.nodeType===9&&f.documentElement&&f.removeChild(f.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(R(163))}}catch(x){ge(t,t.return,x)}if(e=t.sibling,e!==null){e.return=t.return,B=e;break}B=t.return}return h=Iu,Iu=!1,h}function $r(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 l=s.destroy;s.destroy=void 0,l!==void 0&&co(t,n,l)}s=s.next}while(s!==r)}}function zi(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 fo(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 lf(e){var t=e.alternate;t!==null&&(e.alternate=null,lf(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[Pt],delete t[Gr],delete t[Xl],delete t[Gh],delete t[Yh])),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 of(e){return e.tag===5||e.tag===3||e.tag===4}function Bu(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||of(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 po(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=oi));else if(r!==4&&(e=e.child,e!==null))for(po(e,t,n),e=e.sibling;e!==null;)po(e,t,n),e=e.sibling}function ho(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(ho(e,t,n),e=e.sibling;e!==null;)ho(e,t,n),e=e.sibling}var Ae=null,wt=!1;function Yt(e,t,n){for(n=n.child;n!==null;)af(e,t,n),n=n.sibling}function af(e,t,n){if(Ot&&typeof Ot.onCommitFiberUnmount=="function")try{Ot.onCommitFiberUnmount(Ei,n)}catch{}switch(n.tag){case 5:Me||Wn(n,t);case 6:var r=Ae,s=wt;Ae=null,Yt(e,t,n),Ae=r,wt=s,Ae!==null&&(wt?(e=Ae,n=n.stateNode,e.nodeType===8?e.parentNode.removeChild(n):e.removeChild(n)):Ae.removeChild(n.stateNode));break;case 18:Ae!==null&&(wt?(e=Ae,n=n.stateNode,e.nodeType===8?pl(e.parentNode,n):e.nodeType===1&&pl(e,n),Hr(e)):pl(Ae,n.stateNode));break;case 4:r=Ae,s=wt,Ae=n.stateNode.containerInfo,wt=!0,Yt(e,t,n),Ae=r,wt=s;break;case 0:case 11:case 14:case 15:if(!Me&&(r=n.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){s=r=r.next;do{var l=s,o=l.destroy;l=l.tag,o!==void 0&&(l&2||l&4)&&co(n,t,o),s=s.next}while(s!==r)}Yt(e,t,n);break;case 1:if(!Me&&(Wn(n,t),r=n.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(u){ge(n,t,u)}Yt(e,t,n);break;case 21:Yt(e,t,n);break;case 22:n.mode&1?(Me=(r=Me)||n.memoizedState!==null,Yt(e,t,n),Me=r):Yt(e,t,n);break;default:Yt(e,t,n)}}function Fu(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var n=e.stateNode;n===null&&(n=e.stateNode=new fm),t.forEach(function(r){var s=Nm.bind(null,e,r);n.has(r)||(n.add(r),r.then(s,s))})}}function yt(e,t){var n=t.deletions;if(n!==null)for(var r=0;rs&&(s=o),r&=~l}if(r=s,r=ye()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*mm(r/1960))-r,10e?16:e,nn===null)var r=!1;else{if(e=nn,nn=null,wi=0,re&6)throw Error(R(331));var s=re;for(re|=4,B=e.current;B!==null;){var l=B,o=l.child;if(B.flags&16){var u=l.deletions;if(u!==null){for(var a=0;aye()-da?Sn(e,0):ca|=n),Je(e,t)}function xf(e,t){t===0&&(e.mode&1?(t=ws,ws<<=1,!(ws&130023424)&&(ws=4194304)):t=1);var n=Be();e=Ht(e,t),e!==null&&(ls(e,t,n),Je(e,n))}function km(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),xf(e,n)}function Nm(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(R(314))}r!==null&&r.delete(t),xf(e,n)}var gf;gf=function(e,t,n){if(e!==null)if(e.memoizedProps!==t.pendingProps||Ye.current)Ge=!0;else{if(!(e.lanes&n)&&!(t.flags&128))return Ge=!1,um(e,t,n);Ge=!!(e.flags&131072)}else Ge=!1,fe&&t.flags&1048576&&wd(t,di,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;qs(e,t),e=t.pendingProps;var s=nr(t,De.current);Zn(t,n),s=sa(null,t,r,e,s,n);var l=ia();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,Xe(r)?(l=!0,ui(t)):l=!1,t.memoizedState=s.state!==null&&s.state!==void 0?s.state:null,Zo(t),s.updater=Li,t.stateNode=s,s._reactInternals=t,ro(t,r,e,n),t=lo(null,t,r,!0,l,n)):(t.tag=0,fe&&l&&Wo(t),Ie(null,t,s,n),t=t.child),t;case 16:r=t.elementType;e:{switch(qs(e,t),e=t.pendingProps,s=r._init,r=s(r._payload),t.type=r,s=t.tag=bm(r),e=vt(r,e),s){case 0:t=io(null,t,r,e,n);break e;case 1:t=$u(null,t,r,e,n);break e;case 11:t=Lu(null,t,r,e,n);break e;case 14:t=zu(null,t,r,vt(r.type,e),n);break e}throw Error(R(306,r,""))}return t;case 0:return r=t.type,s=t.pendingProps,s=t.elementType===r?s:vt(r,s),io(e,t,r,s,n);case 1:return r=t.type,s=t.pendingProps,s=t.elementType===r?s:vt(r,s),$u(e,t,r,s,n);case 3:e:{if(Zd(t),e===null)throw Error(R(387));r=t.pendingProps,l=t.memoizedState,s=l.element,Cd(e,t),hi(t,r,null,n);var o=t.memoizedState;if(r=o.element,l.isDehydrated)if(l={element:r,isDehydrated:!1,cache:o.cache,pendingSuspenseBoundaries:o.pendingSuspenseBoundaries,transitions:o.transitions},t.updateQueue.baseState=l,t.memoizedState=l,t.flags&256){s=lr(Error(R(423)),t),t=Mu(e,t,r,n,s);break e}else if(r!==s){s=lr(Error(R(424)),t),t=Mu(e,t,r,n,s);break e}else for(tt=an(t.stateNode.containerInfo.firstChild),nt=t,fe=!0,Nt=null,n=bd(t,null,r,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if(rr(),r===s){t=qt(e,t,n);break e}Ie(e,t,r,n)}t=t.child}return t;case 5:return Ed(t),e===null&&eo(t),r=t.type,s=t.pendingProps,l=e!==null?e.memoizedProps:null,o=s.children,Gl(r,s)?o=null:l!==null&&Gl(r,l)&&(t.flags|=32),Jd(e,t),Ie(e,t,o,n),t.child;case 6:return e===null&&eo(t),null;case 13:return ef(e,t,n);case 4:return ea(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=sr(t,null,r,n):Ie(e,t,r,n),t.child;case 11:return r=t.type,s=t.pendingProps,s=t.elementType===r?s:vt(r,s),Lu(e,t,r,s,n);case 7:return Ie(e,t,t.pendingProps,n),t.child;case 8:return Ie(e,t,t.pendingProps.children,n),t.child;case 12:return Ie(e,t,t.pendingProps.children,n),t.child;case 10:e:{if(r=t.type._context,s=t.pendingProps,l=t.memoizedProps,o=s.value,le(fi,r._currentValue),r._currentValue=o,l!==null)if(St(l.value,o)){if(l.children===s.children&&!Ye.current){t=qt(e,t,n);break e}}else for(l=t.child,l!==null&&(l.return=t);l!==null;){var u=l.dependencies;if(u!==null){o=l.child;for(var a=u.firstContext;a!==null;){if(a.context===r){if(l.tag===1){a=Ft(-1,n&-n),a.tag=2;var d=l.updateQueue;if(d!==null){d=d.shared;var g=d.pending;g===null?a.next=a:(a.next=g.next,g.next=a),d.pending=a}}l.lanes|=n,a=l.alternate,a!==null&&(a.lanes|=n),to(l.return,n,t),u.lanes|=n;break}a=a.next}}else if(l.tag===10)o=l.type===t.type?null:l.child;else if(l.tag===18){if(o=l.return,o===null)throw Error(R(341));o.lanes|=n,u=o.alternate,u!==null&&(u.lanes|=n),to(o,n,t),o=l.sibling}else o=l.child;if(o!==null)o.return=l;else for(o=l;o!==null;){if(o===t){o=null;break}if(l=o.sibling,l!==null){l.return=o.return,o=l;break}o=o.return}l=o}Ie(e,t,s.children,n),t=t.child}return t;case 9:return s=t.type,r=t.pendingProps.children,Zn(t,n),s=ht(s),r=r(s),t.flags|=1,Ie(e,t,r,n),t.child;case 14:return r=t.type,s=vt(r,t.pendingProps),s=vt(r.type,s),zu(e,t,r,s,n);case 15:return Yd(e,t,t.type,t.pendingProps,n);case 17:return r=t.type,s=t.pendingProps,s=t.elementType===r?s:vt(r,s),qs(e,t),t.tag=1,Xe(r)?(e=!0,ui(t)):e=!1,Zn(t,n),Kd(t,r,s),ro(t,r,s,n),lo(null,t,r,!0,e,n);case 19:return tf(e,t,n);case 22:return Xd(e,t,n)}throw Error(R(156,t.tag))};function yf(e,t){return Hc(e,t)}function jm(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 dt(e,t,n,r){return new jm(e,t,n,r)}function ma(e){return e=e.prototype,!(!e||!e.isReactComponent)}function bm(e){if(typeof e=="function")return ma(e)?1:0;if(e!=null){if(e=e.$$typeof,e===Lo)return 11;if(e===zo)return 14}return 2}function fn(e,t){var n=e.alternate;return n===null?(n=dt(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 Qs(e,t,n,r,s,l){var o=2;if(r=e,typeof e=="function")ma(e)&&(o=1);else if(typeof e=="string")o=5;else e:switch(e){case Mn:return Cn(n.children,s,l,t);case Ro:o=8,s|=8;break;case El:return e=dt(12,n,t,s|2),e.elementType=El,e.lanes=l,e;case _l:return e=dt(13,n,t,s),e.elementType=_l,e.lanes=l,e;case Tl:return e=dt(19,n,t,s),e.elementType=Tl,e.lanes=l,e;case Ec:return Mi(n,s,l,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case Sc:o=10;break e;case Cc:o=9;break e;case Lo:o=11;break e;case zo:o=14;break e;case Xt:o=16,r=null;break e}throw Error(R(130,e==null?e:typeof e,""))}return t=dt(o,n,t,s),t.elementType=e,t.type=r,t.lanes=l,t}function Cn(e,t,n,r){return e=dt(7,e,r,t),e.lanes=n,e}function Mi(e,t,n,r){return e=dt(22,e,r,t),e.elementType=Ec,e.lanes=n,e.stateNode={isHidden:!1},e}function kl(e,t,n){return e=dt(6,e,null,t),e.lanes=n,e}function Nl(e,t,n){return t=dt(4,e.children!==null?e.children:[],e.key,t),t.lanes=n,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function Sm(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=nl(0),this.expirationTimes=nl(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=nl(0),this.identifierPrefix=r,this.onRecoverableError=s,this.mutableSourceEagerHydrationData=null}function xa(e,t,n,r,s,l,o,u,a){return e=new Sm(e,t,n,u,a),t===1?(t=1,l===!0&&(t|=8)):t=0,l=dt(3,null,null,t),e.current=l,l.stateNode=e,l.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},Zo(l),e}function Cm(e,t,n){var r=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(Nf)}catch(e){console.error(e)}}Nf(),kc.exports=it;var Om=kc.exports,jf,Gu=Om;jf=Gu.createRoot,Gu.hydrateRoot;const Lt=Object.create(null);Lt.open="0";Lt.close="1";Lt.ping="2";Lt.pong="3";Lt.message="4";Lt.upgrade="5";Lt.noop="6";const Gs=Object.create(null);Object.keys(Lt).forEach(e=>{Gs[Lt[e]]=e});const vo={type:"error",data:"parser error"},bf=typeof Blob=="function"||typeof Blob<"u"&&Object.prototype.toString.call(Blob)==="[object BlobConstructor]",Sf=typeof ArrayBuffer=="function",Cf=e=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(e):e&&e.buffer instanceof ArrayBuffer,wa=({type:e,data:t},n,r)=>bf&&t instanceof Blob?n?r(t):Yu(t,r):Sf&&(t instanceof ArrayBuffer||Cf(t))?n?r(t):Yu(new Blob([t]),r):r(Lt[e]+(t||"")),Yu=(e,t)=>{const n=new FileReader;return n.onload=function(){const r=n.result.split(",")[1];t("b"+(r||""))},n.readAsDataURL(e)};function Xu(e){return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}let jl;function Am(e,t){if(bf&&e.data instanceof Blob)return e.data.arrayBuffer().then(Xu).then(t);if(Sf&&(e.data instanceof ArrayBuffer||Cf(e.data)))return t(Xu(e.data));wa(e,!1,n=>{jl||(jl=new TextEncoder),t(jl.encode(n))})}const Ju="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Tr=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let e=0;e{let t=e.length*.75,n=e.length,r,s=0,l,o,u,a;e[e.length-1]==="="&&(t--,e[e.length-2]==="="&&t--);const d=new ArrayBuffer(t),g=new Uint8Array(d);for(r=0;r>4,g[s++]=(o&15)<<4|u>>2,g[s++]=(u&3)<<6|a&63;return d},Lm=typeof ArrayBuffer=="function",ka=(e,t)=>{if(typeof e!="string")return{type:"message",data:Ef(e,t)};const n=e.charAt(0);return n==="b"?{type:"message",data:zm(e.substring(1),t)}:Gs[n]?e.length>1?{type:Gs[n],data:e.substring(1)}:{type:Gs[n]}:vo},zm=(e,t)=>{if(Lm){const n=Rm(e);return Ef(n,t)}else return{base64:!0,data:e}},Ef=(e,t)=>{switch(t){case"blob":return e instanceof Blob?e:new Blob([e]);case"arraybuffer":default:return e instanceof ArrayBuffer?e:e.buffer}},_f="",$m=(e,t)=>{const n=e.length,r=new Array(n);let s=0;e.forEach((l,o)=>{wa(l,!1,u=>{r[o]=u,++s===n&&t(r.join(_f))})})},Mm=(e,t)=>{const n=e.split(_f),r=[];for(let s=0;s{const r=n.length;let s;if(r<126)s=new Uint8Array(1),new DataView(s.buffer).setUint8(0,r);else if(r<65536){s=new Uint8Array(3);const l=new DataView(s.buffer);l.setUint8(0,126),l.setUint16(1,r)}else{s=new Uint8Array(9);const l=new DataView(s.buffer);l.setUint8(0,127),l.setBigUint64(1,BigInt(r))}e.data&&typeof e.data!="string"&&(s[0]|=128),t.enqueue(s),t.enqueue(n)})}})}let bl;function As(e){return e.reduce((t,n)=>t+n.length,0)}function Rs(e,t){if(e[0].length===t)return e.shift();const n=new Uint8Array(t);let r=0;for(let s=0;sMath.pow(2,21)-1){u.enqueue(vo);break}s=g*Math.pow(2,32)+d.getUint32(4),r=3}else{if(As(n)e){u.enqueue(vo);break}}}})}const Tf=4;function je(e){if(e)return Bm(e)}function Bm(e){for(var t in je.prototype)e[t]=je.prototype[t];return e}je.prototype.on=je.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(t),this};je.prototype.once=function(e,t){function n(){this.off(e,n),t.apply(this,arguments)}return n.fn=t,this.on(e,n),this};je.prototype.off=je.prototype.removeListener=je.prototype.removeAllListeners=je.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},arguments.length==0)return this._callbacks={},this;var n=this._callbacks["$"+e];if(!n)return this;if(arguments.length==1)return delete this._callbacks["$"+e],this;for(var r,s=0;s(e.hasOwnProperty(r)&&(n[r]=e[r]),n),{})}const Fm=ct.setTimeout,Um=ct.clearTimeout;function Ui(e,t){t.useNativeTimers?(e.setTimeoutFn=Fm.bind(ct),e.clearTimeoutFn=Um.bind(ct)):(e.setTimeoutFn=ct.setTimeout.bind(ct),e.clearTimeoutFn=ct.clearTimeout.bind(ct))}const Vm=1.33;function Hm(e){return typeof e=="string"?qm(e):Math.ceil((e.byteLength||e.size)*Vm)}function qm(e){let t=0,n=0;for(let r=0,s=e.length;r=57344?n+=3:(r++,n+=4);return n}function Wm(e){let t="";for(let n in e)e.hasOwnProperty(n)&&(t.length&&(t+="&"),t+=encodeURIComponent(n)+"="+encodeURIComponent(e[n]));return t}function Km(e){let t={},n=e.split("&");for(let r=0,s=n.length;r0);return t}function Af(){const e=tc(+new Date);return e!==ec?(Zu=0,ec=e):e+"."+tc(Zu++)}for(;Ls{this.readyState="paused",t()};if(this.polling||!this.writable){let r=0;this.polling&&(r++,this.once("pollComplete",function(){--r||n()})),this.writable||(r++,this.once("drain",function(){--r||n()}))}else n()}poll(){this.polling=!0,this.doPoll(),this.emitReserved("poll")}onData(t){const n=r=>{if(this.readyState==="opening"&&r.type==="open"&&this.onOpen(),r.type==="close")return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(r)};Mm(t,this.socket.binaryType).forEach(n),this.readyState!=="closed"&&(this.polling=!1,this.emitReserved("pollComplete"),this.readyState==="open"&&this.poll())}doClose(){const t=()=>{this.write([{type:"close"}])};this.readyState==="open"?t():this.once("open",t)}write(t){this.writable=!1,$m(t,n=>{this.doWrite(n,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){const t=this.opts.secure?"https":"http",n=this.query||{};return this.opts.timestampRequests!==!1&&(n[this.opts.timestampParam]=Af()),!this.supportsBinary&&!n.sid&&(n.b64=1),this.createUri(t,n)}request(t={}){return Object.assign(t,{xd:this.xd,cookieJar:this.cookieJar},this.opts),new Rt(this.uri(),t)}doWrite(t,n){const r=this.request({method:"POST",data:t});r.on("success",n),r.on("error",(s,l)=>{this.onError("xhr post error",s,l)})}doPoll(){const t=this.request();t.on("data",this.onData.bind(this)),t.on("error",(n,r)=>{this.onError("xhr poll error",n,r)}),this.pollXhr=t}}class Rt extends je{constructor(t,n){super(),Ui(this,n),this.opts=n,this.method=n.method||"GET",this.uri=t,this.data=n.data!==void 0?n.data:null,this.create()}create(){var t;const n=Pf(this.opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");n.xdomain=!!this.opts.xd;const r=this.xhr=new Lf(n);try{r.open(this.method,this.uri,!0);try{if(this.opts.extraHeaders){r.setDisableHeaderCheck&&r.setDisableHeaderCheck(!0);for(let s in this.opts.extraHeaders)this.opts.extraHeaders.hasOwnProperty(s)&&r.setRequestHeader(s,this.opts.extraHeaders[s])}}catch{}if(this.method==="POST")try{r.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch{}try{r.setRequestHeader("Accept","*/*")}catch{}(t=this.opts.cookieJar)===null||t===void 0||t.addCookies(r),"withCredentials"in r&&(r.withCredentials=this.opts.withCredentials),this.opts.requestTimeout&&(r.timeout=this.opts.requestTimeout),r.onreadystatechange=()=>{var s;r.readyState===3&&((s=this.opts.cookieJar)===null||s===void 0||s.parseCookies(r)),r.readyState===4&&(r.status===200||r.status===1223?this.onLoad():this.setTimeoutFn(()=>{this.onError(typeof r.status=="number"?r.status:0)},0))},r.send(this.data)}catch(s){this.setTimeoutFn(()=>{this.onError(s)},0);return}typeof document<"u"&&(this.index=Rt.requestsCount++,Rt.requests[this.index]=this)}onError(t){this.emitReserved("error",t,this.xhr),this.cleanup(!0)}cleanup(t){if(!(typeof this.xhr>"u"||this.xhr===null)){if(this.xhr.onreadystatechange=Xm,t)try{this.xhr.abort()}catch{}typeof document<"u"&&delete Rt.requests[this.index],this.xhr=null}}onLoad(){const t=this.xhr.responseText;t!==null&&(this.emitReserved("data",t),this.emitReserved("success"),this.cleanup())}abort(){this.cleanup()}}Rt.requestsCount=0;Rt.requests={};if(typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",nc);else if(typeof addEventListener=="function"){const e="onpagehide"in ct?"pagehide":"unload";addEventListener(e,nc,!1)}}function nc(){for(let e in Rt.requests)Rt.requests.hasOwnProperty(e)&&Rt.requests[e].abort()}const ja=typeof Promise=="function"&&typeof Promise.resolve=="function"?t=>Promise.resolve().then(t):(t,n)=>n(t,0),zs=ct.WebSocket||ct.MozWebSocket,rc=!0,e0="arraybuffer",sc=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative";class t0 extends Na{constructor(t){super(t),this.supportsBinary=!t.forceBase64}get name(){return"websocket"}doOpen(){if(!this.check())return;const t=this.uri(),n=this.opts.protocols,r=sc?{}:Pf(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(r.headers=this.opts.extraHeaders);try{this.ws=rc&&!sc?n?new zs(t,n):new zs(t):new zs(t,n,r)}catch(s){return this.emitReserved("error",s)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=t=>this.onClose({description:"websocket connection closed",context:t}),this.ws.onmessage=t=>this.onData(t.data),this.ws.onerror=t=>this.onError("websocket error",t)}write(t){this.writable=!1;for(let n=0;n{const o={};try{rc&&this.ws.send(l)}catch{}s&&ja(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){typeof this.ws<"u"&&(this.ws.close(),this.ws=null)}uri(){const t=this.opts.secure?"wss":"ws",n=this.query||{};return this.opts.timestampRequests&&(n[this.opts.timestampParam]=Af()),this.supportsBinary||(n.b64=1),this.createUri(t,n)}check(){return!!zs}}class n0 extends Na{get name(){return"webtransport"}doOpen(){typeof WebTransport=="function"&&(this.transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name]),this.transport.closed.then(()=>{this.onClose()}).catch(t=>{this.onError("webtransport error",t)}),this.transport.ready.then(()=>{this.transport.createBidirectionalStream().then(t=>{const n=Im(Number.MAX_SAFE_INTEGER,this.socket.binaryType),r=t.readable.pipeThrough(n).getReader(),s=Dm();s.readable.pipeTo(t.writable),this.writer=s.writable.getWriter();const l=()=>{r.read().then(({done:u,value:a})=>{u||(this.onPacket(a),l())}).catch(u=>{})};l();const o={type:"open"};this.query.sid&&(o.data=`{"sid":"${this.query.sid}"}`),this.writer.write(o).then(()=>this.onOpen())})}))}write(t){this.writable=!1;for(let n=0;n{s&&ja(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var t;(t=this.transport)===null||t===void 0||t.close()}}const r0={websocket:t0,webtransport:n0,polling:Zm},s0=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,i0=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function ko(e){if(e.length>2e3)throw"URI too long";const t=e,n=e.indexOf("["),r=e.indexOf("]");n!=-1&&r!=-1&&(e=e.substring(0,n)+e.substring(n,r).replace(/:/g,";")+e.substring(r,e.length));let s=s0.exec(e||""),l={},o=14;for(;o--;)l[i0[o]]=s[o]||"";return n!=-1&&r!=-1&&(l.source=t,l.host=l.host.substring(1,l.host.length-1).replace(/;/g,":"),l.authority=l.authority.replace("[","").replace("]","").replace(/;/g,":"),l.ipv6uri=!0),l.pathNames=l0(l,l.path),l.queryKey=o0(l,l.query),l}function l0(e,t){const n=/\/{2,9}/g,r=t.replace(n,"/").split("/");return(t.slice(0,1)=="/"||t.length===0)&&r.splice(0,1),t.slice(-1)=="/"&&r.splice(r.length-1,1),r}function o0(e,t){const n={};return t.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(r,s,l){s&&(n[s]=l)}),n}let zf=class zn extends je{constructor(t,n={}){super(),this.binaryType=e0,this.writeBuffer=[],t&&typeof t=="object"&&(n=t,t=null),t?(t=ko(t),n.hostname=t.host,n.secure=t.protocol==="https"||t.protocol==="wss",n.port=t.port,t.query&&(n.query=t.query)):n.host&&(n.hostname=ko(n.host).host),Ui(this,n),this.secure=n.secure!=null?n.secure:typeof location<"u"&&location.protocol==="https:",n.hostname&&!n.port&&(n.port=this.secure?"443":"80"),this.hostname=n.hostname||(typeof location<"u"?location.hostname:"localhost"),this.port=n.port||(typeof location<"u"&&location.port?location.port:this.secure?"443":"80"),this.transports=n.transports||["polling","websocket","webtransport"],this.writeBuffer=[],this.prevBufferLen=0,this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},n),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),typeof this.opts.query=="string"&&(this.opts.query=Km(this.opts.query)),this.id=null,this.upgrades=null,this.pingInterval=null,this.pingTimeout=null,this.pingTimeoutTimer=null,typeof addEventListener=="function"&&(this.opts.closeOnBeforeunload&&(this.beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this.beforeunloadEventListener,!1)),this.hostname!=="localhost"&&(this.offlineEventListener=()=>{this.onClose("transport close",{description:"network connection lost"})},addEventListener("offline",this.offlineEventListener,!1))),this.open()}createTransport(t){const n=Object.assign({},this.opts.query);n.EIO=Tf,n.transport=t,this.id&&(n.sid=this.id);const r=Object.assign({},this.opts,{query:n,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[t]);return new r0[t](r)}open(){let t;if(this.opts.rememberUpgrade&&zn.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1)t="websocket";else if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);return}else t=this.transports[0];this.readyState="opening";try{t=this.createTransport(t)}catch{this.transports.shift(),this.open();return}t.open(),this.setTransport(t)}setTransport(t){this.transport&&this.transport.removeAllListeners(),this.transport=t,t.on("drain",this.onDrain.bind(this)).on("packet",this.onPacket.bind(this)).on("error",this.onError.bind(this)).on("close",n=>this.onClose("transport close",n))}probe(t){let n=this.createTransport(t),r=!1;zn.priorWebsocketSuccess=!1;const s=()=>{r||(n.send([{type:"ping",data:"probe"}]),n.once("packet",m=>{if(!r)if(m.type==="pong"&&m.data==="probe"){if(this.upgrading=!0,this.emitReserved("upgrading",n),!n)return;zn.priorWebsocketSuccess=n.name==="websocket",this.transport.pause(()=>{r||this.readyState!=="closed"&&(g(),this.setTransport(n),n.send([{type:"upgrade"}]),this.emitReserved("upgrade",n),n=null,this.upgrading=!1,this.flush())})}else{const y=new Error("probe error");y.transport=n.name,this.emitReserved("upgradeError",y)}}))};function l(){r||(r=!0,g(),n.close(),n=null)}const o=m=>{const y=new Error("probe error: "+m);y.transport=n.name,l(),this.emitReserved("upgradeError",y)};function u(){o("transport closed")}function a(){o("socket closed")}function d(m){n&&m.name!==n.name&&l()}const g=()=>{n.removeListener("open",s),n.removeListener("error",o),n.removeListener("close",u),this.off("close",a),this.off("upgrading",d)};n.once("open",s),n.once("error",o),n.once("close",u),this.once("close",a),this.once("upgrading",d),this.upgrades.indexOf("webtransport")!==-1&&t!=="webtransport"?this.setTimeoutFn(()=>{r||n.open()},200):n.open()}onOpen(){if(this.readyState="open",zn.priorWebsocketSuccess=this.transport.name==="websocket",this.emitReserved("open"),this.flush(),this.readyState==="open"&&this.opts.upgrade){let t=0;const n=this.upgrades.length;for(;t{this.onClose("ping timeout")},this.pingInterval+this.pingTimeout),this.opts.autoUnref&&this.pingTimeoutTimer.unref()}onDrain(){this.writeBuffer.splice(0,this.prevBufferLen),this.prevBufferLen=0,this.writeBuffer.length===0?this.emitReserved("drain"):this.flush()}flush(){if(this.readyState!=="closed"&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const t=this.getWritablePackets();this.transport.send(t),this.prevBufferLen=t.length,this.emitReserved("flush")}}getWritablePackets(){if(!(this.maxPayload&&this.transport.name==="polling"&&this.writeBuffer.length>1))return this.writeBuffer;let n=1;for(let r=0;r0&&n>this.maxPayload)return this.writeBuffer.slice(0,r);n+=2}return this.writeBuffer}write(t,n,r){return this.sendPacket("message",t,n,r),this}send(t,n,r){return this.sendPacket("message",t,n,r),this}sendPacket(t,n,r,s){if(typeof n=="function"&&(s=n,n=void 0),typeof r=="function"&&(s=r,r=null),this.readyState==="closing"||this.readyState==="closed")return;r=r||{},r.compress=r.compress!==!1;const l={type:t,data:n,options:r};this.emitReserved("packetCreate",l),this.writeBuffer.push(l),s&&this.once("flush",s),this.flush()}close(){const t=()=>{this.onClose("forced close"),this.transport.close()},n=()=>{this.off("upgrade",n),this.off("upgradeError",n),t()},r=()=>{this.once("upgrade",n),this.once("upgradeError",n)};return(this.readyState==="opening"||this.readyState==="open")&&(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?r():t()}):this.upgrading?r():t()),this}onError(t){zn.priorWebsocketSuccess=!1,this.emitReserved("error",t),this.onClose("transport error",t)}onClose(t,n){(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")&&(this.clearTimeoutFn(this.pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),typeof removeEventListener=="function"&&(removeEventListener("beforeunload",this.beforeunloadEventListener,!1),removeEventListener("offline",this.offlineEventListener,!1)),this.readyState="closed",this.id=null,this.emitReserved("close",t,n),this.writeBuffer=[],this.prevBufferLen=0)}filterUpgrades(t){const n=[];let r=0;const s=t.length;for(;rtypeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(e):e.buffer instanceof ArrayBuffer,$f=Object.prototype.toString,d0=typeof Blob=="function"||typeof Blob<"u"&&$f.call(Blob)==="[object BlobConstructor]",f0=typeof File=="function"||typeof File<"u"&&$f.call(File)==="[object FileConstructor]";function ba(e){return u0&&(e instanceof ArrayBuffer||c0(e))||d0&&e instanceof Blob||f0&&e instanceof File}function Ys(e,t){if(!e||typeof e!="object")return!1;if(Array.isArray(e)){for(let n=0,r=e.length;n=0&&e.numthis.opts.maxAttachments)throw new Error("too many attachments");r.attachments=u}if(t.charAt(n+1)==="/"){const l=n+1;for(;++n&&!(t.charAt(n)===","||n===t.length););r.nsp=t.substring(l,n)}else r.nsp="/";const s=t.charAt(n+1);if(s!==""&&Number(s)==s){const l=n+1;for(;++n;){const o=t.charAt(n);if(o==null||Number(o)!=o){--n;break}if(n===t.length)break}r.id=Number(t.substring(l,n+1))}if(t.charAt(++n)){const l=this.tryParse(t.substr(n));if(Sa.isPayloadValid(r.type,l))r.data=l;else throw new Error("invalid payload")}return r}tryParse(t){try{return JSON.parse(t,this.opts.reviver)}catch{return!1}}static isPayloadValid(t,n){switch(t){case J.CONNECT:return ic(n);case J.DISCONNECT:return n===void 0;case J.CONNECT_ERROR:return typeof n=="string"||ic(n);case J.EVENT:case J.BINARY_EVENT:return Array.isArray(n)&&(typeof n[0]=="number"||typeof n[0]=="string"&&m0.indexOf(n[0])===-1);case J.ACK:case J.BINARY_ACK:return Array.isArray(n)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}class g0{constructor(t){this.packet=t,this.buffers=[],this.reconPack=t}takeBinaryData(t){if(this.buffers.push(t),this.buffers.length===this.reconPack.attachments){const n=h0(this.reconPack,this.buffers);return this.finishedReconstruction(),n}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}const y0=Number.isInteger||function(e){return typeof e=="number"&&isFinite(e)&&Math.floor(e)===e};function ic(e){return Object.prototype.toString.call(e)==="[object Object]"}const v0=Object.freeze(Object.defineProperty({__proto__:null,Decoder:Sa,Encoder:x0,get PacketType(){return J}},Symbol.toStringTag,{value:"Module"}));function kt(e,t,n){return e.on(t,n),function(){e.off(t,n)}}const w0=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});class Mf extends je{constructor(t,n,r){super(),this.connected=!1,this.recovered=!1,this.receiveBuffer=[],this.sendBuffer=[],this._queue=[],this._queueSeq=0,this.ids=0,this.acks={},this.flags={},this.io=t,this.nsp=n,r&&r.auth&&(this.auth=r.auth),this._opts=Object.assign({},r),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;const t=this.io;this.subs=[kt(t,"open",this.onopen.bind(this)),kt(t,"packet",this.onpacket.bind(this)),kt(t,"error",this.onerror.bind(this)),kt(t,"close",this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected?this:(this.subEvents(),this.io._reconnecting||this.io.open(),this.io._readyState==="open"&&this.onopen(),this)}open(){return this.connect()}send(...t){return t.unshift("message"),this.emit.apply(this,t),this}emit(t,...n){if(w0.hasOwnProperty(t))throw new Error('"'+t.toString()+'" is a reserved event name');if(n.unshift(t),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(n),this;const r={type:J.EVENT,data:n};if(r.options={},r.options.compress=this.flags.compress!==!1,typeof n[n.length-1]=="function"){const o=this.ids++,u=n.pop();this._registerAckCallback(o,u),r.id=o}const s=this.io.engine&&this.io.engine.transport&&this.io.engine.transport.writable;return this.flags.volatile&&(!s||!this.connected)||(this.connected?(this.notifyOutgoingListeners(r),this.packet(r)):this.sendBuffer.push(r)),this.flags={},this}_registerAckCallback(t,n){var r;const s=(r=this.flags.timeout)!==null&&r!==void 0?r:this._opts.ackTimeout;if(s===void 0){this.acks[t]=n;return}const l=this.io.setTimeoutFn(()=>{delete this.acks[t];for(let u=0;u{this.io.clearTimeoutFn(l),n.apply(this,u)};o.withError=!0,this.acks[t]=o}emitWithAck(t,...n){return new Promise((r,s)=>{const l=(o,u)=>o?s(o):r(u);l.withError=!0,n.push(l),this.emit(t,...n)})}_addToQueue(t){let n;typeof t[t.length-1]=="function"&&(n=t.pop());const r={id:this._queueSeq++,tryCount:0,pending:!1,args:t,flags:Object.assign({fromQueue:!0},this.flags)};t.push((s,...l)=>r!==this._queue[0]?void 0:(s!==null?r.tryCount>this._opts.retries&&(this._queue.shift(),n&&n(s)):(this._queue.shift(),n&&n(null,...l)),r.pending=!1,this._drainQueue())),this._queue.push(r),this._drainQueue()}_drainQueue(t=!1){if(!this.connected||this._queue.length===0)return;const n=this._queue[0];n.pending&&!t||(n.pending=!0,n.tryCount++,this.flags=n.flags,this.emit.apply(this,n.args))}packet(t){t.nsp=this.nsp,this.io._packet(t)}onopen(){typeof this.auth=="function"?this.auth(t=>{this._sendConnectPacket(t)}):this._sendConnectPacket(this.auth)}_sendConnectPacket(t){this.packet({type:J.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},t):t})}onerror(t){this.connected||this.emitReserved("connect_error",t)}onclose(t,n){this.connected=!1,delete this.id,this.emitReserved("disconnect",t,n),this._clearAcks()}_clearAcks(){Object.keys(this.acks).forEach(t=>{if(!this.sendBuffer.some(r=>String(r.id)===t)){const r=this.acks[t];delete this.acks[t],r.withError&&r.call(this,new Error("socket has been disconnected"))}})}onpacket(t){if(t.nsp===this.nsp)switch(t.type){case J.CONNECT:t.data&&t.data.sid?this.onconnect(t.data.sid,t.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case J.EVENT:case J.BINARY_EVENT:this.onevent(t);break;case J.ACK:case J.BINARY_ACK:this.onack(t);break;case J.DISCONNECT:this.ondisconnect();break;case J.CONNECT_ERROR:this.destroy();const r=new Error(t.data.message);r.data=t.data.data,this.emitReserved("connect_error",r);break}}onevent(t){const n=t.data||[];t.id!=null&&n.push(this.ack(t.id)),this.connected?this.emitEvent(n):this.receiveBuffer.push(Object.freeze(n))}emitEvent(t){if(this._anyListeners&&this._anyListeners.length){const n=this._anyListeners.slice();for(const r of n)r.apply(this,t)}super.emit.apply(this,t),this._pid&&t.length&&typeof t[t.length-1]=="string"&&(this._lastOffset=t[t.length-1])}ack(t){const n=this;let r=!1;return function(...s){r||(r=!0,n.packet({type:J.ACK,id:t,data:s}))}}onack(t){const n=this.acks[t.id];typeof n=="function"&&(delete this.acks[t.id],n.withError&&t.data.unshift(null),n.apply(this,t.data))}onconnect(t,n){this.id=t,this.recovered=n&&this._pid===n,this._pid=n,this.connected=!0,this.emitBuffered(),this.emitReserved("connect"),this._drainQueue(!0)}emitBuffered(){this.receiveBuffer.forEach(t=>this.emitEvent(t)),this.receiveBuffer=[],this.sendBuffer.forEach(t=>{this.notifyOutgoingListeners(t),this.packet(t)}),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach(t=>t()),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:J.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(t){return this.flags.compress=t,this}get volatile(){return this.flags.volatile=!0,this}timeout(t){return this.flags.timeout=t,this}onAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(t),this}prependAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(t),this}offAny(t){if(!this._anyListeners)return this;if(t){const n=this._anyListeners;for(let r=0;r0&&e.jitter<=1?e.jitter:0,this.attempts=0}fr.prototype.duration=function(){var e=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var t=Math.random(),n=Math.floor(t*this.jitter*e);e=Math.floor(t*10)&1?e+n:e-n}return Math.min(e,this.max)|0};fr.prototype.reset=function(){this.attempts=0};fr.prototype.setMin=function(e){this.ms=e};fr.prototype.setMax=function(e){this.max=e};fr.prototype.setJitter=function(e){this.jitter=e};class bo extends je{constructor(t,n){var r;super(),this.nsps={},this.subs=[],t&&typeof t=="object"&&(n=t,t=void 0),n=n||{},n.path=n.path||"/socket.io",this.opts=n,Ui(this,n),this.reconnection(n.reconnection!==!1),this.reconnectionAttempts(n.reconnectionAttempts||1/0),this.reconnectionDelay(n.reconnectionDelay||1e3),this.reconnectionDelayMax(n.reconnectionDelayMax||5e3),this.randomizationFactor((r=n.randomizationFactor)!==null&&r!==void 0?r:.5),this.backoff=new fr({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(n.timeout==null?2e4:n.timeout),this._readyState="closed",this.uri=t;const s=n.parser||v0;this.encoder=new s.Encoder,this.decoder=new s.Decoder,this._autoConnect=n.autoConnect!==!1,this._autoConnect&&this.open()}reconnection(t){return arguments.length?(this._reconnection=!!t,this):this._reconnection}reconnectionAttempts(t){return t===void 0?this._reconnectionAttempts:(this._reconnectionAttempts=t,this)}reconnectionDelay(t){var n;return t===void 0?this._reconnectionDelay:(this._reconnectionDelay=t,(n=this.backoff)===null||n===void 0||n.setMin(t),this)}randomizationFactor(t){var n;return t===void 0?this._randomizationFactor:(this._randomizationFactor=t,(n=this.backoff)===null||n===void 0||n.setJitter(t),this)}reconnectionDelayMax(t){var n;return t===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=t,(n=this.backoff)===null||n===void 0||n.setMax(t),this)}timeout(t){return arguments.length?(this._timeout=t,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&this.backoff.attempts===0&&this.reconnect()}open(t){if(~this._readyState.indexOf("open"))return this;this.engine=new zf(this.uri,this.opts);const n=this.engine,r=this;this._readyState="opening",this.skipReconnect=!1;const s=kt(n,"open",function(){r.onopen(),t&&t()}),l=u=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",u),t?t(u):this.maybeReconnectOnOpen()},o=kt(n,"error",l);if(this._timeout!==!1){const u=this._timeout,a=this.setTimeoutFn(()=>{s(),l(new Error("timeout")),n.close()},u);this.opts.autoUnref&&a.unref(),this.subs.push(()=>{this.clearTimeoutFn(a)})}return this.subs.push(s),this.subs.push(o),this}connect(t){return this.open(t)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const t=this.engine;this.subs.push(kt(t,"ping",this.onping.bind(this)),kt(t,"data",this.ondata.bind(this)),kt(t,"error",this.onerror.bind(this)),kt(t,"close",this.onclose.bind(this)),kt(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(t){try{this.decoder.add(t)}catch(n){this.onclose("parse error",n)}}ondecoded(t){ja(()=>{this.emitReserved("packet",t)},this.setTimeoutFn)}onerror(t){this.emitReserved("error",t)}socket(t,n){let r=this.nsps[t];return r?this._autoConnect&&!r.active&&r.connect():(r=new Mf(this,t,n),this.nsps[t]=r),r}_destroy(t){const n=Object.keys(this.nsps);for(const r of n)if(this.nsps[r].active)return;this._close()}_packet(t){const n=this.encoder.encode(t);for(let r=0;rt()),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close"),this.engine&&this.engine.close()}disconnect(){return this._close()}onclose(t,n){this.cleanup(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",t,n),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const t=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const n=this.backoff.duration();this._reconnecting=!0;const r=this.setTimeoutFn(()=>{t.skipReconnect||(this.emitReserved("reconnect_attempt",t.backoff.attempts),!t.skipReconnect&&t.open(s=>{s?(t._reconnecting=!1,t.reconnect(),this.emitReserved("reconnect_error",s)):t.onreconnect()}))},n);this.opts.autoUnref&&r.unref(),this.subs.push(()=>{this.clearTimeoutFn(r)})}}onreconnect(){const t=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",t)}}const jr={};function Xs(e,t){typeof e=="object"&&(t=e,e=void 0),t=t||{};const n=a0(e,t.path||"/socket.io"),r=n.source,s=n.id,l=n.path,o=jr[s]&&l in jr[s].nsps,u=t.forceNew||t["force new connection"]||t.multiplex===!1||o;let a;return u?a=new bo(r,t):(jr[s]||(jr[s]=new bo(r,t)),a=jr[s]),n.query&&!t.query&&(t.query=n.queryKey),a.socket(n.path,t)}Object.assign(Xs,{Manager:bo,Socket:Mf,io:Xs,connect:Xs});const Sl={},Ca=(Sl==null?void 0:Sl.VITE_API)||"";let mn=localStorage.getItem("nk_token")||"",ji=JSON.parse(localStorage.getItem("nk_tenant")||"null"),ar={},Qn=null;const Ea=(e,t)=>{mn=e,ji=t,localStorage.setItem("nk_token",e),localStorage.setItem("nk_tenant",JSON.stringify(t))},Df=()=>mn&&ji?{token:mn,tenant:ji}:null;function If(){mn="",ji=null,localStorage.removeItem("nk_token"),localStorage.removeItem("nk_tenant"),Qn&&Qn.disconnect()}async function cs(e,t){const n=await fetch(`${Ca}${e}`,{method:"POST",headers:{"Content-Type":"application/json",...mn?{Authorization:`Bearer ${mn}`}:{}},body:JSON.stringify(t)}),r=await n.json().catch(()=>({}));if(!n.ok)throw new Error(r.error||"request failed");return r}async function k0(e){const t=await cs("/api/register",e);return Ea(t.token,t.tenant),t.tenant}async function N0(e,t){const n=await cs("/api/login",{email:e,password:t});return Ea(n.token,n.tenant),n.tenant}async function j0(e,t){const n=await cs("/api/staff-login",{code:e,pin:t});return Ea(n.token,n.tenant),n.tenant}async function lc(){const e=await fetch(`${Ca}/api/state`,{headers:{Authorization:`Bearer ${mn}`}});if(e.status===401)throw If(),new Error("relogin");return ar=await e.json(),ar}async function Ce(e,t){return e in ar?ar[e]:t}async function ke(e,t){ar[e]=t;try{await cs("/api/state",{key:e,value:t})}catch{}}async function b0(e,t,n=700){return((await cs("/api/ai",{messages:e,system:t,max_tokens:n})).content||[]).filter(s=>s.type==="text").map(s=>s.text).join(` `).trim()}function S0(e){return Qn=Xs(Ca||void 0,{auth:{token:mn}}),Qn.on("state",({key:t,value:n})=>{ar[t]=n,e({key:t,value:n})}),()=>Qn&&Qn.disconnect()}const _t=e=>i.jsxs("label",{className:"block mb-3",children:[i.jsx("span",{className:"text-xs text-stone-500",children:e.label}),i.jsx("input",{...e,label:void 0,className:"mt-1 w-full bg-stone-50 border border-stone-300 rounded-xl px-3 py-2.5 text-stone-800 outline-none focus:border-rose-800"})]});function C0({children:e}){const[t,n]=C.useState(!1),[r,s]=C.useState(!1),[l,o]=C.useState("register"),[u,a]=C.useState(!1),[d,g]=C.useState(""),[m,y]=C.useState({name:"",owner:"",email:"",password:"",phone:"",city:"",code:"",pin:""}),v=N=>P=>y(p=>({...p,[N]:P.target.value}));C.useEffect(()=>{(async()=>{if(Df())try{await lc(),s(!0)}catch{If()}n(!0)})()},[]);const h=async()=>{a(!0),g("");try{l==="register"?await k0({name:m.name,owner:m.owner,email:m.email,password:m.password,phone:m.phone,city:m.city}):l==="login"?await N0(m.email,m.password):await j0(m.code,m.pin),await lc(),s(!0)}catch(N){g(N.message||"Something went wrong")}a(!1)};return t?r?e:i.jsx("div",{className:"min-h-screen bg-stone-100 text-stone-800 flex flex-col items-center justify-center p-5",children:i.jsxs("div",{className:"w-full max-w-sm",children:[i.jsxs("div",{className:"flex flex-col items-center mb-6",children:[i.jsx("div",{className:"w-14 h-14 rounded-2xl bg-gradient-to-br from-rose-700 to-rose-900 flex items-center justify-center text-white text-2xl shadow-lg shadow-rose-900/20",children:"🍽️"}),i.jsx("h1",{className:"text-2xl font-bold mt-3 tracking-tight",children:"NamakPOS"}),i.jsx("p",{className:"text-sm text-stone-500",children:"Apne restaurant ka poora hisaab — ek jagah."})]}),i.jsxs("div",{className:"bg-white border border-stone-200 rounded-3xl p-5 shadow-sm",children:[i.jsx("div",{className:"flex gap-1 bg-stone-100 rounded-2xl p-1 mb-4 text-sm",children:[["register","Register"],["login","Login"],["staff","Staff"]].map(([N,P])=>i.jsx("button",{onClick:()=>{o(N),g("")},className:`flex-1 py-2 rounded-xl transition ${l===N?"bg-white shadow-sm text-rose-800 font-semibold":"text-stone-500"}`,children:P},N))}),l==="register"&&i.jsxs(i.Fragment,{children:[i.jsx(_t,{label:"Restaurant name",value:m.name,onChange:v("name"),placeholder:"Namak Kitchen"}),i.jsx(_t,{label:"Your name (owner)",value:m.owner,onChange:v("owner"),placeholder:"Ashish"}),i.jsx(_t,{label:"Email",type:"email",value:m.email,onChange:v("email"),placeholder:"you@email.com"}),i.jsx(_t,{label:"Password",type:"password",value:m.password,onChange:v("password"),placeholder:"••••••"}),i.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[i.jsx(_t,{label:"Phone",value:m.phone,onChange:v("phone"),placeholder:"98xxxxxxxx"}),i.jsx(_t,{label:"City",value:m.city,onChange:v("city"),placeholder:"Lucknow"})]})]}),l==="login"&&i.jsxs(i.Fragment,{children:[i.jsx(_t,{label:"Email",type:"email",value:m.email,onChange:v("email"),placeholder:"you@email.com"}),i.jsx(_t,{label:"Password",type:"password",value:m.password,onChange:v("password"),placeholder:"••••••"})]}),l==="staff"&&i.jsxs(i.Fragment,{children:[i.jsxs("p",{className:"text-xs text-stone-500 mb-3",children:["Owner se restaurant ",i.jsx("b",{children:"code"})," aur ",i.jsx("b",{children:"staff PIN"})," lo (POS → Settings me dikhega)."]}),i.jsx(_t,{label:"Restaurant code",value:m.code,onChange:v("code"),placeholder:"A1B2C3"}),i.jsx(_t,{label:"Staff PIN",value:m.pin,onChange:v("pin"),placeholder:"0000"})]}),d&&i.jsx("div",{className:"text-sm text-red-600 mb-3",children:d}),i.jsx("button",{onClick:h,disabled:u,className:"w-full bg-gradient-to-br from-rose-700 to-rose-900 text-white font-bold rounded-2xl py-3 shadow-lg shadow-rose-900/20 disabled:opacity-50",children:u?"…":l==="register"?"Create account & start →":l==="login"?"Login →":"Join →"})]}),i.jsx("p",{className:"text-center text-[11px] text-stone-400 mt-4",children:"Aapka data aapke restaurant tak seemit — private aur secure."})]})}):i.jsx("div",{className:"min-h-screen bg-stone-100 flex items-center justify-center text-rose-800 font-mono",children:"loading…"})}/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const E0=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),Bf=(...e)=>e.filter((t,n,r)=>!!t&&r.indexOf(t)===n).join(" ");/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */var _0={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const T0=C.forwardRef(({color:e="currentColor",size:t=24,strokeWidth:n=2,absoluteStrokeWidth:r,className:s="",children:l,iconNode:o,...u},a)=>C.createElement("svg",{ref:a,..._0,width:t,height:t,stroke:e,strokeWidth:r?Number(n)*24/Number(t):n,className:Bf("lucide",s),...u},[...o.map(([d,g])=>C.createElement(d,g)),...Array.isArray(l)?l:[l]]));/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Y=(e,t)=>{const n=C.forwardRef(({className:r,...s},l)=>C.createElement(T0,{ref:l,iconNode:t,className:Bf(`lucide-${E0(e)}`,r),...s}));return n.displayName=`${e}`,n};/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const P0=Y("ArrowDownLeft",[["path",{d:"M17 7 7 17",key:"15tmo1"}],["path",{d:"M17 17H7V7",key:"1org7z"}]]);/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const O0=Y("ArrowRightLeft",[["path",{d:"m16 3 4 4-4 4",key:"1x1c3m"}],["path",{d:"M20 7H4",key:"zbl0bi"}],["path",{d:"m8 21-4-4 4-4",key:"h9nckh"}],["path",{d:"M4 17h16",key:"g4d7ey"}]]);/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const oc=Y("ArrowUpRight",[["path",{d:"M7 7h10v10",key:"1tivn9"}],["path",{d:"M7 17 17 7",key:"1vkiza"}]]);/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const ns=Y("Ban",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m4.9 4.9 14.2 14.2",key:"1m5liu"}]]);/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Ff=Y("Banknote",[["rect",{width:"20",height:"12",x:"2",y:"6",rx:"2",key:"9lu3g6"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}],["path",{d:"M6 12h.01M18 12h.01",key:"113zkx"}]]);/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const A0=Y("Bell",[["path",{d:"M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9",key:"1qo2s2"}],["path",{d:"M10.3 21a1.94 1.94 0 0 0 3.4 0",key:"qgo35s"}]]);/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Uf=Y("Boxes",[["path",{d:"M2.97 12.92A2 2 0 0 0 2 14.63v3.24a2 2 0 0 0 .97 1.71l3 1.8a2 2 0 0 0 2.06 0L12 19v-5.5l-5-3-4.03 2.42Z",key:"lc1i9w"}],["path",{d:"m7 16.5-4.74-2.85",key:"1o9zyk"}],["path",{d:"m7 16.5 5-3",key:"va8pkn"}],["path",{d:"M7 16.5v5.17",key:"jnp8gn"}],["path",{d:"M12 13.5V19l3.97 2.38a2 2 0 0 0 2.06 0l3-1.8a2 2 0 0 0 .97-1.71v-3.24a2 2 0 0 0-.97-1.71L17 10.5l-5 3Z",key:"8zsnat"}],["path",{d:"m17 16.5-5-3",key:"8arw3v"}],["path",{d:"m17 16.5 4.74-2.85",key:"8rfmw"}],["path",{d:"M17 16.5v5.17",key:"k6z78m"}],["path",{d:"M7.97 4.42A2 2 0 0 0 7 6.13v4.37l5 3 5-3V6.13a2 2 0 0 0-.97-1.71l-3-1.8a2 2 0 0 0-2.06 0l-3 1.8Z",key:"1xygjf"}],["path",{d:"M12 8 7.26 5.15",key:"1vbdud"}],["path",{d:"m12 8 4.74-2.85",key:"3rx089"}],["path",{d:"M12 13.5V8",key:"1io7kd"}]]);/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Vf=Y("Check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]);/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Vi=Y("ChefHat",[["path",{d:"M17 21a1 1 0 0 0 1-1v-5.35c0-.457.316-.844.727-1.041a4 4 0 0 0-2.134-7.589 5 5 0 0 0-9.186 0 4 4 0 0 0-2.134 7.588c.411.198.727.585.727 1.041V20a1 1 0 0 0 1 1Z",key:"1qvrer"}],["path",{d:"M6 17h12",key:"1jwigz"}]]);/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const _a=Y("ClipboardList",[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2",key:"116196"}],["path",{d:"M12 11h4",key:"1jrz19"}],["path",{d:"M12 16h4",key:"n85exb"}],["path",{d:"M8 11h.01",key:"1dfujw"}],["path",{d:"M8 16h.01",key:"18s6g9"}]]);/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const bi=Y("Clock",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]]);/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Hf=Y("CreditCard",[["rect",{width:"20",height:"14",x:"2",y:"5",rx:"2",key:"ynyp8z"}],["line",{x1:"2",x2:"22",y1:"10",y2:"10",key:"1b3vmo"}]]);/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const ac=Y("Flame",[["path",{d:"M8.5 14.5A2.5 2.5 0 0 0 11 12c0-1.38-.5-2-1-3-1.072-2.143-.224-4.054 2-6 .5 2.5 2 4.9 4 6.5 2 1.6 3 3.5 3 5.5a7 7 0 1 1-14 0c0-1.153.433-2.294 1-3a2.5 2.5 0 0 0 2.5 2.5z",key:"96xj49"}]]);/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Ta=Y("Grid3x3",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"M3 15h18",key:"5xshup"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"M15 3v18",key:"14nvp0"}]]);/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const R0=Y("LayoutGrid",[["rect",{width:"7",height:"7",x:"3",y:"3",rx:"1",key:"1g98yp"}],["rect",{width:"7",height:"7",x:"14",y:"3",rx:"1",key:"6d4xhi"}],["rect",{width:"7",height:"7",x:"14",y:"14",rx:"1",key:"nxv5o0"}],["rect",{width:"7",height:"7",x:"3",y:"14",rx:"1",key:"1bb6yr"}]]);/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const rs=Y("Minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const qf=Y("Package",[["path",{d:"m7.5 4.27 9 5.15",key:"1c824w"}],["path",{d:"M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z",key:"hh9hay"}],["path",{d:"m3.3 7 8.7 5 8.7-5",key:"g66t2b"}],["path",{d:"M12 22V12",key:"d0xqtd"}]]);/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const st=Y("Plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]);/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Pa=Y("Printer",[["path",{d:"M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2",key:"143wyd"}],["path",{d:"M6 9V3a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v6",key:"1itne7"}],["rect",{x:"6",y:"14",width:"12",height:"8",rx:"1",key:"1ue0tg"}]]);/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Oa=Y("Receipt",[["path",{d:"M4 2v20l2-1 2 1 2-1 2 1 2-1 2 1 2-1 2 1V2l-2 1-2-1-2 1-2-1-2 1-2-1-2 1Z",key:"q3az6g"}],["path",{d:"M16 8h-6a2 2 0 1 0 0 4h4a2 2 0 1 1 0 4H8",key:"1h4pet"}],["path",{d:"M12 17.5v-11",key:"1jc1ny"}]]);/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Wf=Y("Search",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["path",{d:"m21 21-4.3-4.3",key:"1qie3q"}]]);/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Kf=Y("Settings",[["path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z",key:"1qme2f"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Aa=Y("Share2",[["circle",{cx:"18",cy:"5",r:"3",key:"gq8acd"}],["circle",{cx:"6",cy:"12",r:"3",key:"w7nqdw"}],["circle",{cx:"18",cy:"19",r:"3",key:"1xt0gg"}],["line",{x1:"8.59",x2:"15.42",y1:"13.51",y2:"17.49",key:"47mynk"}],["line",{x1:"15.41",x2:"8.59",y1:"6.51",y2:"10.49",key:"1n3mei"}]]);/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Si=Y("ShoppingCart",[["circle",{cx:"8",cy:"21",r:"1",key:"jimo8o"}],["circle",{cx:"19",cy:"21",r:"1",key:"13723u"}],["path",{d:"M2.05 2.05h2l2.66 12.42a2 2 0 0 0 2 1.58h9.78a2 2 0 0 0 1.95-1.57l1.65-7.43H5.12",key:"9zh506"}]]);/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const ss=Y("Smartphone",[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2",key:"1yt0o3"}],["path",{d:"M12 18h.01",key:"mhygvu"}]]);/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const L0=Y("Split",[["path",{d:"M16 3h5v5",key:"1806ms"}],["path",{d:"M8 3H3v5",key:"15dfkv"}],["path",{d:"M12 22v-8.3a4 4 0 0 0-1.172-2.872L3 3",key:"1qrqzj"}],["path",{d:"m15 9 6-6",key:"ko1vev"}]]);/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const z0=Y("Star",[["polygon",{points:"12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2",key:"8f66p6"}]]);/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const $0=Y("StickyNote",[["path",{d:"M16 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V8Z",key:"qazsjp"}],["path",{d:"M15 3v4a2 2 0 0 0 2 2h4",key:"40519r"}]]);/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Hi=Y("Trash2",[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}],["line",{x1:"10",x2:"10",y1:"11",y2:"17",key:"1uufr5"}],["line",{x1:"14",x2:"14",y1:"11",y2:"17",key:"xtxkd"}]]);/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const M0=Y("TrendingUp",[["polyline",{points:"22 7 13.5 15.5 8.5 10.5 2 17",key:"126l90"}],["polyline",{points:"16 7 22 7 22 13",key:"kwv8wd"}]]);/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Qf=Y("UserPlus",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["line",{x1:"19",x2:"19",y1:"8",y2:"14",key:"1bvyxn"}],["line",{x1:"22",x2:"16",y1:"11",y2:"11",key:"1shjgl"}]]);/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const So=Y("UsersRound",[["path",{d:"M18 21a8 8 0 0 0-16 0",key:"3ypg7q"}],["circle",{cx:"10",cy:"8",r:"5",key:"o932ke"}],["path",{d:"M22 20c0-3.37-2-6.5-4-8a5 5 0 0 0-.45-8.3",key:"10s06x"}]]);/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Gf=Y("Users",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["path",{d:"M16 3.13a4 4 0 0 1 0 7.75",key:"1da9ce"}]]);/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Ra=Y("Utensils",[["path",{d:"M3 2v7c0 1.1.9 2 2 2h4a2 2 0 0 0 2-2V2",key:"cjf0a3"}],["path",{d:"M7 2v20",key:"1473qp"}],["path",{d:"M21 15V2v0a5 5 0 0 0-5 5v6c0 1.1.9 2 2 2h3Zm0 0v7",key:"1ogz0v"}]]);/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Yf=Y("Wallet",[["path",{d:"M19 7V4a1 1 0 0 0-1-1H5a2 2 0 0 0 0 4h15a1 1 0 0 1 1 1v4h-3a2 2 0 0 0 0 4h3a1 1 0 0 0 1-1v-2a1 1 0 0 0-1-1",key:"18etb6"}],["path",{d:"M3 5v14a2 2 0 0 0 2 2h15a1 1 0 0 0 1-1v-4",key:"xoc0q4"}]]);/** * @license lucide-react v0.383.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const pr=Y("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]),K=()=>Date.now().toString(36)+Math.random().toString(36).slice(2,6),O=e=>"₹"+(Math.round((e||0)*100)/100).toLocaleString("en-IN"),ce=()=>Date.now(),Xf=e=>new Date(e).toDateString(),Mt=e=>Xf(e)===new Date().toDateString(),qi=e=>new Date(e).toLocaleTimeString("en-IN",{hour:"2-digit",minute:"2-digit"});function xt(e="ok"){try{const t=new(window.AudioContext||window.webkitAudioContext),n=t.createOscillator(),r=t.createGain();n.connect(r),r.connect(t.destination),e==="ok"?n.frequency.value=880:e==="money"?n.frequency.value=1320:n.frequency.value=440,r.gain.setValueAtTime(1e-4,t.currentTime),r.gain.exponentialRampToValueAtTime(.25,t.currentTime+.01),r.gain.exponentialRampToValueAtTime(1e-4,t.currentTime+.18),n.start(),n.stop(t.currentTime+.2)}catch{}}function La(){return new Promise(e=>{const t=document.createElement("input");t.type="file",t.accept="image/*",t.capture="environment",t.onchange=()=>{var s;const n=(s=t.files)==null?void 0:s[0];if(!n)return e(null);const r=new FileReader;r.onload=()=>{const l=new Image;l.onload=()=>{const u=Math.min(1,900/Math.max(l.width,l.height)),a=document.createElement("canvas");a.width=l.width*u,a.height=l.height*u,a.getContext("2d").drawImage(l,0,0,a.width,a.height),e(a.toDataURL("image/jpeg",.6))},l.onerror=()=>e(null),l.src=r.result},r.onerror=()=>e(null),r.readAsDataURL(n)},t.click()})}function D0(e,t){const n=new Blob([JSON.stringify(e,null,2)],{type:"application/json"}),r=URL.createObjectURL(n),s=document.createElement("a");s.href=r,s.download=t,s.click(),setTimeout(()=>URL.revokeObjectURL(r),1e3)}const Bt=e=>new Date(e).toLocaleString("en-IN",{day:"2-digit",month:"short",hour:"2-digit",minute:"2-digit"});async function Jf(e,t,n=700){return b0(e,t,n)}function I0(e){try{return JSON.parse(e.replace(/```json|```/g,"").trim())}catch{return null}}async function B0(){var e;return(e=window.jspdf)!=null&&e.jsPDF||await new Promise((t,n)=>{const r=document.createElement("script");r.src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js",r.onload=t,r.onerror=n,document.head.appendChild(r)}),window.jspdf.jsPDF}function F0(e,t,n){const r=t.items.map(s=>`${s.name}${s.qty}${O(s.price*s.qty)}`).join("");return`Bill ${t.invNo||""}

${e.name}

${n?'
DUPLICATE COPY
':""}${e.gstin?`
GSTIN: ${e.gstin}
`:""}${e.fssai?`
FSSAI: ${e.fssai}
`:""}
Bill #${t.invNo||"-"}${t.table?" · "+t.table:""} · ${Bt(t.ts||Date.now())}

${r}

${t.disc?``:""} ${t.svc?``:""}${t.tip?``:""}
Subtotal${O(t.gross??t.sub)}
Discount-${O(t.disc)}
GST ${e.gst}%${O(t.gst)}
Service${O(t.svc)}
Tip${O(t.tip)}
TOTAL${O(t.total)}

Paid via ${t.mode} · ${t.type||""}
Dhanyawaad! Aana firse 🙏
`}async function za(e,t,n,r){try{const s=await B0(),l=new s({unit:"mm",format:[80,250]});let o=8;const u=4,a=76,d=40,g=(h,N)=>{l.setFont("courier",h?"bold":"normal"),l.setFontSize(N)},m=(h,N=!1,P=9)=>{g(N,P),l.text(String(h),d,o,{align:"center"}),o+=P*.55},y=(h,N,P=!1,p=9)=>{g(P,p),l.text(String(h),u,o),l.text(String(N),a,o,{align:"right"}),o+=p*.55},v=()=>{l.setLineDashPattern([1,1],0),l.line(u,o,a,o),o+=3};return m(e.name,!0,13),r&&(o+=1,l.setLineDashPattern([],0),l.rect(u+18,o-3.5,44,5),m("DUPLICATE COPY",!0,9)),e.gstin&&m("GSTIN: "+e.gstin,!1,7),e.fssai&&m("FSSAI: "+e.fssai,!1,7),m(`Bill #${t.invNo||"-"}${t.table?" · "+t.table:""}`,!1,8),m(Bt(t.ts||Date.now()),!1,8),v(),t.items.forEach(h=>y(`${h.qty}x ${h.name}`.slice(0,26),O(h.price*h.qty),!1,8)),v(),y("Subtotal",O(t.gross??t.sub),!1,8),t.disc&&y("Discount","-"+O(t.disc),!1,8),y(`GST ${e.gst}%`,O(t.gst),!1,8),t.svc&&y("Service",O(t.svc),!1,8),t.tip&&y("Tip",O(t.tip),!1,8),y("TOTAL",O(t.total),!0,11),v(),m(`Paid via ${t.mode} · ${t.type||""}`,!1,8),o+=1,m("Dhanyawaad! Aana firse",!1,8),l.save(`Bill-${t.invNo||Date.now()}.pdf`),n&&n("PDF bill ban gaya ✓"),!0}catch{const l=window.open("","_blank","width=300,height=600");return l?(l.document.write(F0(e,t,r)),l.document.close(),l.focus(),l.print(),!0):(n&&n("Pop-up allow karo (PDF/print)"),!1)}}const uc={g:{base:"g",k:1},kg:{base:"g",k:1e3},ml:{base:"ml",k:1},l:{base:"ml",k:1e3},ltr:{base:"ml",k:1e3},pcs:{base:"pcs",k:1},nos:{base:"pcs",k:1}};function Zf(e,t,n){const r=uc[t],s=uc[n];return r&&s&&r.base===s.base?e*r.k/s.k:e}function ep(e,t){var n;if(e.off)return"off";if((n=e.recipe)!=null&&n.length)for(const r of e.recipe){const s=t.find(o=>o.id===r.invId);if(!s)continue;const l=Zf(Number(r.qty)||0,r.unit||s.unit,s.unit);if(s.stock+ New Order dabao → Dine-in ya Takeaway chuno.",g2:"Dish pe tap karo → green button se paisa lo. Bas.",g3:"Baaki sab (stock, kitchen, report) More me — jab chahiye tab.",guideHint:"Upar ? dabao to yeh guide phir dikh jayega.",guideStart:"Chalu karo →",helpTitle:"Kaise chalayein",tabsOrder:"Order",tabsAdd:"+ Add",tabsShift:"Shift",tabsSettle:"Settle",tapSeat:"tap to seat",lang:"Language / भाषा"},en:{todaySale:"Today",drawer:"Drawer",navHome:"Home",navTables:"Tables",navCounter:"Counter",navOnline:"Online",navMore:"More",newOrder:"New Order",startOrder:"Start a new order",dinein:"Dine-in",takeaway:"Takeaway",dineinSub:`Table → order → KOT. Pay later.`,takeawaySub:`Order → payment → print KOT.`,pickTable:"Pick a free table → take order",counterHeader:"Takeaway / Counter — pay first, then KOT",searchDish:"Search dish…",sendKitchen:"Send %n to Kitchen",allSent:"All sent",settlePrint:"Settle & Print Bill",collect:"Collect",markPaid:"Mark Paid ✓",newOrderBtn:"New Order",guideTitle:"Run it in 3 steps 👇",g1:"Tap + New Order below → choose Dine-in or Takeaway.",g2:"Tap a dish → take money with the green button. Done.",g3:"Everything else (stock, kitchen, reports) lives in More — when you need it.",guideHint:"Tap ? up top to see this guide again.",guideStart:"Get started →",helpTitle:"How to use",tabsOrder:"Order",tabsAdd:"+ Add",tabsShift:"Shift",tabsSettle:"Settle",tapSeat:"tap to seat",lang:"Language / भाषा"}},ne=e=>br[Js]&&br[Js][e]!=null?br[Js][e]:br.hi[e]!=null?br.hi[e]:e,U0=[{id:K(),name:"Masala Chai",price:20,cost:6,cat:"Beverages",veg:!0},{id:K(),name:"Cold Coffee",price:90,cost:32,cat:"Beverages",veg:!0},{id:K(),name:"Veg Sandwich",price:70,cost:28,cat:"Snacks",veg:!0},{id:K(),name:"Paneer Tikka",price:220,cost:95,cat:"Starters",veg:!0},{id:K(),name:"Chicken Tikka",price:260,cost:130,cat:"Starters",veg:!1},{id:K(),name:"Butter Naan",price:45,cost:12,cat:"Breads",veg:!0},{id:K(),name:"Dal Makhani",price:190,cost:60,cat:"Main Course",veg:!0},{id:K(),name:"Butter Chicken",price:320,cost:145,cat:"Main Course",veg:!1},{id:K(),name:"Veg Biryani",price:180,cost:65,cat:"Main Course",veg:!0},{id:K(),name:"Gulab Jamun",price:60,cost:18,cat:"Desserts",veg:!0}],V0=[{id:K(),name:"Paneer",unit:"kg",stock:8,lowAt:3},{id:K(),name:"Chicken",unit:"kg",stock:12,lowAt:5},{id:K(),name:"Milk",unit:"ltr",stock:20,lowAt:8},{id:K(),name:"Atta",unit:"kg",stock:25,lowAt:10}],H0=[{id:K(),name:"Ramesh",role:"Chef",salary:22e3,advance:0},{id:K(),name:"Suresh",role:"Waiter",salary:14e3,advance:2e3}],q0=["T1","T2","T3","T4","T5","T6","AC-1","AC-2"].map(e=>({id:K(),name:e,status:"free",pax:0,steward:"",openedAt:null,items:[],kots:0})),oe=({children:e,className:t=""})=>i.jsx("div",{className:`bg-white border border-stone-200 rounded-2xl ${t}`,children:e}),rn=({label:e,value:t,sub:n,accent:r="text-stone-800"})=>i.jsxs(oe,{className:"p-4 flex-1 min-w-0",children:[i.jsx("div",{className:"text-[11px] uppercase tracking-wider text-stone-500 truncate",children:e}),i.jsx("div",{className:`text-2xl font-mono font-bold mt-1 tabular-nums ${r}`,children:t}),n&&i.jsx("div",{className:"text-xs text-stone-500 mt-0.5 truncate",children:n})]});function pt({open:e,onClose:t,title:n,children:r}){return e?i.jsx("div",{className:"fixed inset-0 z-50 flex items-end sm:items-center justify-center bg-stone-900/40 p-0 sm:p-4",onClick:t,children:i.jsxs("div",{className:"bg-white border border-stone-200 w-full sm:max-w-md rounded-t-3xl sm:rounded-2xl max-h-[88vh] overflow-y-auto",onClick:s=>s.stopPropagation(),children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-stone-200 sticky top-0 bg-white",children:[i.jsx("h3",{className:"font-semibold text-stone-800",children:n}),i.jsx("button",{onClick:t,className:"p-1.5 rounded-lg hover:bg-stone-100 text-stone-500",children:i.jsx(pr,{size:18})})]}),i.jsx("div",{className:"p-4",children:r})]})}):null}const G=({label:e,...t})=>i.jsxs("label",{className:"block mb-3",children:[i.jsx("span",{className:"text-xs text-stone-500",children:e}),i.jsx("input",{...t,className:"mt-1 w-full bg-stone-100 border border-stone-300 rounded-xl px-3 py-2.5 text-stone-800 outline-none focus:border-rose-800"})]});function W0(){const[e,t]=C.useState(!1),[n,r]=C.useState("bill"),[s,l]=C.useState({name:"Namak Kitchen",gst:5,upi:"namak@upi",adminPin:"1234",gstin:"",fssai:"",easy:!0,lang:"hi",staffPin:"0000"}),[o,u]=C.useState(!1),[a,d]=C.useState([]),[g,m]=C.useState([]),[y,v]=C.useState([]),[h,N]=C.useState([]),[P,p]=C.useState([]),[c,f]=C.useState([]),[x,b]=C.useState([]),[E,z]=C.useState([]),[L,U]=C.useState([]),[j,w]=C.useState([]),[A,k]=C.useState([]),[T,_]=C.useState({inv:1,tok:1}),[V,Z]=C.useState([]),[$,D]=C.useState([]),[I,H]=C.useState([]),[W,ae]=C.useState([]),[ve,Ve]=C.useState([]),[be,Se]=C.useState(!1),[ee,F]=C.useState(!1),[X,ie]=C.useState(!1),[He,Ze]=C.useState(null);C.useEffect(()=>{(async()=>(l(await Ce("cfg",{name:"Namak Kitchen",gst:5,upi:"namak@upi",adminPin:"1234",gstin:"",fssai:"",easy:!0,lang:"hi",staffPin:"0000"})),d(await Ce("menu",U0)),m(await Ce("inv",V0)),v(await Ce("staff",H0)),N(await Ce("sales",[])),p(await Ce("exp",[])),f(await Ce("cash",[])),b(await Ce("cust",[])),z(await Ce("online",[])),U(await Ce("tables",q0)),w(await Ce("audit",[])),k(await Ce("wastage",[])),_(await Ce("counters",{inv:1,tok:1})),Z(await Ce("closings",[])),D(await Ce("suppliers",[{id:K(),name:"Local Sabzi Mandi",phone:""}])),H(await Ce("purchases",[])),ae(await Ce("kds",[])),Ve(await Ce("reservations",[])),await Ce("seenGuide",!1)||Se(!0),t(!0)))()},[]),C.useEffect(()=>{e&&ke("cfg",s)},[s,e]),C.useEffect(()=>{e&&ke("menu",a)},[a,e]),C.useEffect(()=>{e&&ke("inv",g)},[g,e]),C.useEffect(()=>{e&&ke("staff",y)},[y,e]),C.useEffect(()=>{e&&ke("sales",h)},[h,e]),C.useEffect(()=>{e&&ke("exp",P)},[P,e]),C.useEffect(()=>{e&&ke("cash",c)},[c,e]),C.useEffect(()=>{e&&ke("cust",x)},[x,e]),C.useEffect(()=>{e&&ke("online",E)},[E,e]),C.useEffect(()=>{e&&ke("tables",L)},[L,e]),C.useEffect(()=>{e&&ke("audit",j)},[j,e]),C.useEffect(()=>{e&&ke("wastage",A)},[A,e]),C.useEffect(()=>{e&&ke("counters",T)},[T,e]),C.useEffect(()=>{e&&ke("closings",V)},[V,e]),C.useEffect(()=>{e&&ke("suppliers",$)},[$,e]),C.useEffect(()=>{e&&ke("purchases",I)},[I,e]),C.useEffect(()=>{e&&ke("kds",W)},[W,e]),C.useEffect(()=>{e&&ke("reservations",ve)},[ve,e]);const S=C.useCallback(M=>{Ze(M),setTimeout(()=>Ze(null),1800)},[]),q=C.useCallback(({key:M,value:we})=>{const pe={cfg:l,menu:d,inv:m,staff:v,sales:N,exp:p,cash:f,cust:b,online:z,tables:U,audit:w,wastage:k,counters:_,closings:Z,suppliers:D,purchases:H,kds:ae,reservations:Ve};pe[M]&&pe[M](we)},[]);C.useEffect(()=>{if(e)return S0(q)},[e,q]);const Te=C.useCallback(()=>{if(o)return!0;const M=prompt("Admin PIN (owner only) — for discount / void:");return M===null?!1:M===(s.adminPin||"1234")?(u(!0),S("Admin unlocked"),!0):(S("Galat PIN"),!1)},[o,s.adminPin,S]),ot=C.useCallback((M,we)=>{w(pe=>[{id:K(),ts:ce(),type:M,detail:we,by:o?"admin":"staff"},...pe])},[o]),Wi=C.useCallback((M,we)=>{const pe=we.filter(te=>!te.void).map(te=>{const Ct=a.find(Qt=>Qt.id===(te.mid||te.id))||a.find(Qt=>Qt.name===te.name);return{name:te.name,qty:te.qty,note:te.note||"",station:(Ct==null?void 0:Ct.station)||"General",tags:(Ct==null?void 0:Ct.tags)||[]}});if(!pe.length)return;const qe=T.tok||1;ae(te=>[{id:K(),ts:ce(),token:qe,source:M,items:pe,status:"new"},...te]),_(te=>({...te,tok:(te.tok||1)+1}))},[a,T.tok]),tp=C.useCallback((M,we)=>{ae(pe=>[{id:K(),ts:ce(),token:0,source:M,cancel:!0,items:[{name:we.name,qty:we.qty,note:"CANCELLED",station:""}],status:"new"},...pe])},[]),$a=C.useMemo(()=>h.filter(M=>Mt(M.ts)),[h]),ds=$a.reduce((M,we)=>M+we.total,0),Ki=P.filter(M=>Mt(M.ts)).reduce((M,we)=>M+we.amount,0),fs=C.useMemo(()=>{const M=h.filter(qe=>qe.mode==="Cash").reduce((qe,te)=>qe+te.total,0),we=c.reduce((qe,te)=>qe+(te.type==="in"?te.amount:-te.amount),0),pe=P.filter(qe=>qe.paid==="Cash").reduce((qe,te)=>qe+te.amount,0);return M+we-pe},[h,c,P]),Qi=C.useCallback((M,we,pe,qe,te={})=>{const Ct=M.reduce((We,vn)=>We+vn.price*vn.qty,0),Qt=Math.min(Ct,+(te.disc||0)),Gi=Ct-Qt,Ma=+(Gi*s.gst/100).toFixed(2),Da=+(te.svc||0),ps=+(te.tip||0),Ia=T.inv,hr={id:K(),invNo:Ia,ts:ce(),items:M,gross:Ct,disc:Qt,sub:Gi,gst:Ma,svc:Da,tip:ps,total:+(Gi+Ma+Da+ps).toFixed(2),mode:we,type:qe,cust:(pe==null?void 0:pe.phone)||null,table:te.table||null,covers:te.covers||null,steward:te.steward||null,discBy:te.discBy||null,comp:te.comp||null};return N(We=>[hr,...We]),_(We=>({...We,inv:We.inv+1})),m(We=>{let vn=We;return M.forEach(gt=>{var Ba;const hs=a.find(Gt=>Gt.id===gt.id);(Ba=hs==null?void 0:hs.recipe)!=null&&Ba.length&&(vn=vn.map(Gt=>{const Yi=hs.recipe.find(ip=>ip.invId===Gt.id);if(!Yi)return Gt;const sp=Zf(Number(Yi.qty)||0,Yi.unit||Gt.unit,Gt.unit)*gt.qty;return{...Gt,stock:Math.max(0,+(Gt.stock-sp).toFixed(3))}}))}),vn}),w(We=>[{id:K(),ts:ce(),type:te.comp?"COMP":"SALE",detail:`Bill #${Ia} · ${qe} · ${we} · ₹${hr.total}${te.comp?` · COMP: ${te.comp}`:Qt?` · disc ₹${Qt}`:""}${ps?` · tip ₹${ps}`:""}`,by:o?"admin":"staff"},...We]),pe!=null&&pe.phone&&b(We=>We.find(gt=>gt.phone===pe.phone)?We.map(gt=>gt.phone===pe.phone?{...gt,name:pe.name||gt.name,orders:gt.orders+1,spent:gt.spent+hr.total,last:ce()}:gt):[{phone:pe.phone,name:pe.name||"",orders:1,spent:hr.total,last:ce()},...We]),xt("money"),hr},[s.gst,T.inv,o,a]);if(!e)return i.jsx("div",{className:"min-h-screen bg-stone-100 flex items-center justify-center text-rose-800 font-mono",children:"loading POS…"});Js=s.lang||"hi";const np=L.filter(M=>M.status==="running").length,rp=[{id:"home",icon:R0,label:ne("navHome")},{id:"tables",icon:Ta,label:ne("navTables"),badge:np},{id:"bill",icon:Si,label:ne("navCounter")},{id:"kot",icon:_a,label:ne("navOnline"),badge:E.filter(M=>M.status==="new").length},{id:"more",icon:Uf,label:ne("navMore")}];return i.jsxs("div",{className:"min-h-screen bg-stone-100 text-stone-800 flex flex-col",style:{WebkitTapHighlightColor:"transparent"},children:[i.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-stone-200 bg-gradient-to-b from-white to-stone-100 sticky top-0 z-30 backdrop-blur",children:[i.jsxs("div",{className:"flex items-center gap-2.5",children:[i.jsx("div",{className:"w-9 h-9 rounded-2xl bg-gradient-to-br from-rose-700 to-rose-900 flex items-center justify-center text-white shadow-lg shadow-rose-900/20",children:i.jsx(ac,{size:19})}),i.jsxs("div",{children:[i.jsx("div",{className:"font-bold leading-tight tracking-tight",children:s.name}),i.jsxs("div",{className:"text-[10px] text-stone-500 leading-tight",children:[ne("todaySale")," ",O(ds)," · ",ne("drawer")," ",O(fs)]})]})]}),i.jsxs("div",{className:"flex items-center gap-1.5",children:[i.jsx("button",{onClick:()=>F(!0),className:"w-8 h-8 rounded-xl bg-gradient-to-br from-rose-700 to-rose-900 text-white text-sm font-bold flex items-center justify-center shadow shadow-rose-900/20",children:"✨"}),i.jsx("button",{onClick:()=>{o?(u(!1),S("Admin locked")):Te()},className:`w-8 h-8 rounded-xl flex items-center justify-center ${o?"bg-emerald-600/10 text-emerald-700":"bg-stone-100 text-stone-500"}`,children:o?i.jsx(Vf,{size:16}):i.jsx(ns,{size:16})}),i.jsx("button",{onClick:()=>r("settings"),className:"w-8 h-8 rounded-xl bg-stone-100 text-stone-500 flex items-center justify-center",children:i.jsx(Kf,{size:16})})]})]}),i.jsxs("div",{className:"flex-1 overflow-y-auto pb-24",children:[n==="home"&&i.jsx(K0,{sales:h,todayCollection:ds,todayExp:Ki,cashInDrawer:fs,todaySales:$a,menu:a,online:E,customers:x,tables:L,setTab:r}),n==="tables"&&i.jsx(Q0,{tables:L,setTables:U,menu:a,settings:s,recordSale:Qi,notify:S,requireAdmin:Te,logAudit:ot,addKds:Wi,inv:g,kdsCancel:tp}),n==="bill"&&i.jsx(Y0,{menu:a,settings:s,recordSale:Qi,notify:S,inv:g,setInv:m,requireAdmin:Te,logAudit:ot,addKds:Wi}),n==="kot"&&i.jsx(J0,{online:E,setOnline:z,menu:a,recordSale:Qi,notify:S,addKds:Wi}),n==="kds"&&i.jsx(ax,{kds:W,setKds:ae,notify:S}),n==="money"&&i.jsx(Z0,{expenses:P,setExpenses:p,cashLog:c,setCashLog:f,cashInDrawer:fs,todayCollection:ds,todayExp:Ki,sales:h,notify:S,logAudit:ot}),n==="more"&&i.jsx(ex,{setTab:r,kds:W,easy:s.easy}),n==="reserve"&&i.jsx(cx,{reservations:ve,setReservations:Ve,tables:L,notify:S,setTab:r}),n==="menu"&&i.jsx(tx,{menu:a,setMenu:d,notify:S,setTab:r,requireAdmin:Te,logAudit:ot,inv:g}),n==="inv"&&i.jsx(nx,{inv:g,setInv:m,notify:S,setTab:r,wastage:A,setWastage:k,requireAdmin:Te,logAudit:ot}),n==="suppliers"&&i.jsx(ux,{suppliers:$,setSuppliers:D,purchases:I,setPurchases:H,inv:g,setInv:m,expenses:P,setExpenses:p,notify:S,setTab:r,requireAdmin:Te,logAudit:ot}),n==="staff"&&i.jsx(rx,{staff:y,setStaff:v,cashLog:c,setCashLog:f,notify:S,setTab:r}),n==="cust"&&i.jsx(sx,{customers:x,sales:h,setTab:r}),n==="share"&&i.jsx(lx,{menu:a,settings:s,online:E,setOnline:z,notify:S,setTab:r}),n==="reports"&&i.jsx(ox,{sales:h,expenses:P,cashLog:c,wastage:A,audit:j,cashInDrawer:fs,todayCollection:ds,todayExp:Ki,closings:V,setClosings:Z,notify:S,setTab:r,requireAdmin:Te,logAudit:ot,settings:s,allData:{settings:s,menu:a,inv:g,staff:y,sales:h,expenses:P,cashLog:c,customers:x,online:E,tables:L,audit:j,wastage:A,counters:T,closings:V,suppliers:$,purchases:I,kds:W},restore:M=>{M.settings&&l(M.settings),M.menu&&d(M.menu),M.inv&&m(M.inv),M.staff&&v(M.staff),M.sales&&N(M.sales),M.expenses&&p(M.expenses),M.cashLog&&f(M.cashLog),M.customers&&b(M.customers),M.online&&z(M.online),M.tables&&U(M.tables),M.audit&&w(M.audit),M.wastage&&k(M.wastage),M.counters&&_(M.counters),M.closings&&Z(M.closings),M.suppliers&&D(M.suppliers),M.purchases&&H(M.purchases),M.kds&&ae(M.kds)}}),n==="settings"&&i.jsx(fx,{settings:s,setSettings:l,notify:S,setTab:r})]}),["home","tables","bill"].includes(n)&&i.jsxs("button",{onClick:()=>ie(!0),className:"fixed bottom-20 right-4 z-40 bg-gradient-to-br from-rose-700 to-rose-900 text-white font-bold rounded-full pl-4 pr-5 py-3.5 shadow-xl shadow-rose-900/20 flex items-center gap-2 active:scale-95 transition",children:[i.jsx(st,{size:20})," ",ne("newOrderBtn")]}),i.jsx(pt,{open:X,onClose:()=>ie(!1),title:ne("startOrder"),children:i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("button",{onClick:()=>{ie(!1),r("tables"),S(ne("pickTable"))},className:"flex flex-col items-center gap-2 bg-emerald-600/10 border border-emerald-600/30 rounded-2xl py-6",children:[i.jsx(Ra,{size:28,className:"text-emerald-700"}),i.jsx("span",{className:"font-semibold text-emerald-700",children:ne("dinein")}),i.jsx("span",{className:"text-[10px] text-stone-500 text-center px-2 whitespace-pre-line",children:ne("dineinSub")})]}),i.jsxs("button",{onClick:()=>{ie(!1),r("bill")},className:"flex flex-col items-center gap-2 bg-rose-800/10 border border-rose-800/30 rounded-2xl py-6",children:[i.jsx(Si,{size:28,className:"text-rose-800"}),i.jsx("span",{className:"font-semibold text-rose-700",children:ne("takeaway")}),i.jsx("span",{className:"text-[10px] text-stone-500 text-center px-2 whitespace-pre-line",children:ne("takeawaySub")})]})]})}),be&&i.jsx("div",{className:"fixed inset-0 z-50 bg-stone-900/50 flex items-center justify-center p-6",onClick:()=>{Se(!1),ke("seenGuide",!0)},children:i.jsxs("div",{className:"bg-white border border-stone-200 rounded-3xl p-6 max-w-sm w-full text-center",onClick:M=>M.stopPropagation(),children:[i.jsx("div",{className:"w-14 h-14 rounded-2xl bg-rose-800 mx-auto flex items-center justify-center text-white mb-3",children:i.jsx(ac,{size:26})}),i.jsx("h3",{className:"text-lg font-bold mb-1",children:ne("guideTitle")}),i.jsxs("div",{className:"text-sm text-stone-600 space-y-2.5 text-left my-4",children:[i.jsxs("div",{className:"flex gap-2",children:[i.jsx("span",{className:"text-rose-800 font-bold shrink-0",children:"1"}),i.jsx("span",{dangerouslySetInnerHTML:{__html:ne("g1")}})]}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx("span",{className:"text-rose-800 font-bold shrink-0",children:"2"}),i.jsx("span",{dangerouslySetInnerHTML:{__html:ne("g2")}})]}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx("span",{className:"text-rose-800 font-bold shrink-0",children:"3"}),i.jsx("span",{dangerouslySetInnerHTML:{__html:ne("g3")}})]})]}),i.jsx("div",{className:"text-[11px] text-stone-500 mb-3",dangerouslySetInnerHTML:{__html:ne("guideHint")}}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx("button",{onClick:()=>l(M=>({...M,lang:M.lang==="en"?"hi":"en"})),className:"px-3 py-3 rounded-xl border border-stone-300 text-stone-600 text-sm",children:s.lang==="en"?"हिं":"EN"}),i.jsx("button",{onClick:()=>{Se(!1),ke("seenGuide",!0)},className:"flex-1 bg-gradient-to-br from-rose-700 to-rose-900 text-white font-bold rounded-2xl py-3 shadow-lg shadow-rose-900/20",children:ne("guideStart")})]})]})}),i.jsx(dx,{open:ee,onClose:()=>F(!1),lang:s.lang,restName:s.name}),He&&i.jsx("div",{className:"fixed bottom-24 left-1/2 -translate-x-1/2 z-50 bg-emerald-600 text-white font-semibold px-4 py-2 rounded-full shadow-lg text-sm animate-pulse",children:He}),i.jsx("div",{className:"fixed bottom-0 inset-x-0 bg-white/90 backdrop-blur border-t border-stone-200 grid grid-cols-5 z-30",children:rp.map(M=>{const we=n===M.id||M.id==="more"&&["menu","inv","staff","cust","share","settings","money","reports","kds","suppliers","reserve"].includes(n);return i.jsxs("button",{onClick:()=>r(M.id),className:"relative flex flex-col items-center gap-0.5 py-2.5",children:[i.jsx("div",{className:`flex items-center justify-center w-11 h-7 rounded-full transition ${we?"bg-gradient-to-br from-rose-800/15 to-rose-900/10 text-rose-800":"text-stone-500"}`,children:i.jsx(M.icon,{size:20})}),i.jsx("span",{className:`text-[10px] ${we?"text-rose-800 font-medium":"text-stone-500"}`,children:M.label}),M.badge>0&&i.jsx("span",{className:"absolute top-1 right-1/4 bg-red-600 text-white text-[9px] w-4 h-4 rounded-full flex items-center justify-center",children:M.badge})]},M.id)})})]})}function K0({todayCollection:e,todayExp:t,cashInDrawer:n,todaySales:r,sales:s,menu:l,online:o,customers:u,tables:a=[],setTab:d}){const g=a.filter(p=>p.status==="running"),m=g.reduce((p,c)=>p+c.items.filter(f=>!f.void).reduce((f,x)=>f+x.price*x.qty,0),0),y=r.length,v=y?e/y:0,h=C.useMemo(()=>{var f;const p={};return r.forEach(x=>x.items.forEach(b=>{p[b.name]=(p[b.name]||0)+b.qty})),((f=Object.entries(p).sort((x,b)=>b[1]-x[1])[0])==null?void 0:f[0])||"—"},[r]),N=C.useMemo(()=>{const p=[];for(let c=6;c>=0;c--){const f=new Date;f.setDate(f.getDate()-c);const x=f.toDateString(),b=s.filter(E=>Xf(E.ts)===x).reduce((E,z)=>E+z.total,0);p.push({label:f.toLocaleDateString("en-IN",{weekday:"short"}),tot:b})}return p},[s]),P=Math.max(1,...N.map(p=>p.tot));return i.jsxs("div",{className:"p-4 space-y-4",children:[i.jsxs("div",{className:"flex gap-3",children:[i.jsx(rn,{label:"Today's Sale",value:O(e),sub:`${y} orders`,accent:"text-emerald-700"}),i.jsx(rn,{label:"Cash in Drawer",value:O(n),sub:"live",accent:"text-rose-800"})]}),i.jsxs("div",{className:"flex gap-3",children:[i.jsx(rn,{label:"Expenses",value:O(t),sub:"today",accent:"text-red-600"}),i.jsx(rn,{label:"Avg Bill",value:O(v),sub:`Top: ${h}`})]}),i.jsxs(oe,{className:"p-4",children:[i.jsxs("div",{className:"flex items-center gap-2 text-sm text-stone-500 mb-3",children:[i.jsx(M0,{size:16})," Last 7 days"]}),i.jsx("div",{className:"flex items-end justify-between gap-2 h-28",children:N.map((p,c)=>i.jsxs("div",{className:"flex-1 flex flex-col items-center gap-1",children:[i.jsx("div",{className:"text-[9px] text-stone-500 font-mono",children:p.tot?Math.round(p.tot/1e3)+"k":""}),i.jsx("div",{className:"w-full bg-gradient-to-t from-rose-800 to-rose-700 rounded-t transition-all",style:{height:`${p.tot/P*100}%`,minHeight:p.tot?4:0}}),i.jsx("div",{className:"text-[10px] text-stone-500",children:p.label})]},c))})]}),g.length>0&&i.jsxs("button",{onClick:()=>d("tables"),className:"w-full bg-emerald-600/10 border border-emerald-600/30 rounded-2xl p-4 flex items-center gap-3 text-left",children:[i.jsx(Ta,{className:"text-emerald-700",size:22}),i.jsxs("div",{className:"flex-1",children:[i.jsxs("div",{className:"font-semibold text-emerald-700",children:[g.length," table",g.length>1?"s":""," running"]}),i.jsxs("div",{className:"text-xs text-stone-500",children:[O(m)," on the floor · tap to manage"]})]})]}),o.filter(p=>p.status==="new").length>0&&i.jsxs("button",{onClick:()=>d("kot"),className:"w-full bg-red-600/10 border border-red-600/30 rounded-2xl p-4 flex items-center gap-3 text-left",children:[i.jsx(A0,{className:"text-red-600",size:22}),i.jsxs("div",{className:"flex-1",children:[i.jsxs("div",{className:"font-semibold text-red-600",children:[o.filter(p=>p.status==="new").length," new online order(s)"]}),i.jsx("div",{className:"text-xs text-stone-500",children:"Tap to accept & print KOT"})]})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsx($s,{icon:Aa,label:"Share Order Link",onClick:()=>d("share")}),i.jsx($s,{icon:Gf,label:`${u.length} Customers`,onClick:()=>d("cust")}),i.jsx($s,{icon:Ra,label:`${l.length} Menu Items`,onClick:()=>d("menu")}),i.jsx($s,{icon:qf,label:"Inventory",onClick:()=>d("inv")})]})]})}const $s=({icon:e,label:t,onClick:n})=>i.jsxs("button",{onClick:n,className:"bg-white border border-stone-200 rounded-2xl p-4 flex flex-col gap-2 items-start active:scale-95 transition",children:[i.jsx(e,{size:20,className:"text-rose-800"}),i.jsx("span",{className:"text-sm text-stone-600 text-left",children:t})]});function Q0({tables:e,setTables:t,menu:n,settings:r,recordSale:s,notify:l,requireAdmin:o,logAudit:u,addKds:a,inv:d,kdsCancel:g}){const[m,y]=C.useState(null),v=e.find(j=>j.id===m),h=(j,w)=>t(A=>A.map(k=>k.id===j?w(k):k)),N=j=>{h(j.id,w=>({...w,status:"running",openedAt:w.openedAt||ce()})),y(j.id)},P=j=>h(m,w=>{const A=w.items.find(k=>k.mid===j.id&&!k.sent&&!k.note);return A?{...w,items:w.items.map(k=>k===A?{...k,qty:k.qty+1}:k)}:{...w,items:[...w.items,{lid:K(),mid:j.id,name:j.name,price:j.price,qty:1,sent:!1,note:""}]}}),p=(j,w)=>h(m,A=>{let k=A.items.map(T=>{if(T.lid!==j)return T;const _=T.qty+w;return T.sent&&_<1?T:{...T,qty:_}}).filter(T=>T.sent||T.qty>0);return{...A,items:k}}),c=(j,w)=>h(m,A=>({...A,items:A.items.map(k=>k.lid===j?{...k,note:w}:k)})),f=j=>{if(!o())return;const w=e.find(T=>T.id===m),A=w==null?void 0:w.items.find(T=>T.lid===j),k=prompt("Void reason? (wastage / customer cancel / wrong order)","customer cancel");k!==null&&(h(m,T=>({...T,items:T.items.map(_=>_.lid===j?{..._,void:!0,voidReason:k}:_)})),A!=null&&A.sent&&g&&g((w==null?void 0:w.name)||"Table",A),u&&u("VOID",`${w==null?void 0:w.name} · ${A==null?void 0:A.name} ×${A==null?void 0:A.qty} · ${k}`),l("Item voided"))},x=()=>{const j=e.find(k=>k.id===m),w=j.items.filter(k=>!k.sent&&!k.void&&!k.hold);if(!w.length){l("Kuch naya nahi (ya sab hold pe hai)");return}const A=window.open("","_blank","width=300,height=600");if(A){const k=w.map(T=>`${T.qty} ×${T.name}${T.note?`
↳ ${T.note}`:""}`).join("");A.document.write(`KOT

KOT #${j.kots+1}

${j.name} · ${j.pax||"-"} pax · ${j.steward||""}

${k}

${qi(ce())} · ** Not a bill **
`),A.document.close(),A.print()}h(m,k=>({...k,kots:k.kots+1,items:k.items.map(T=>T.void||T.hold||T.sent?T:{...T,sent:!0})})),a&&a(j.name,w),xt("ok"),l(`KOT #${j.kots+1} kitchen ko gaya`)},b=j=>{const w=e.find(k=>k.id===m),A=e.find(k=>k.id===j);A&&(t(k=>k.map(T=>T.id===j?A.status==="free"?{...T,status:"running",openedAt:w.openedAt,pax:w.pax,steward:w.steward,items:w.items,kots:w.kots}:{...T,items:[...T.items,...w.items],kots:T.kots+w.kots,pax:T.pax+w.pax}:T.id===w.id?{...T,status:"free",openedAt:null,pax:0,steward:"",items:[],kots:0}:T)),y(j),l(A.status==="free"?`Shifted to ${A.name}`:`Merged into ${A.name}`))},E=()=>y(null),z=j=>{h(j,w=>({...w,status:"free",openedAt:null,pax:0,steward:"",items:[],kots:0})),E()},L=j=>j.items.filter(w=>!w.void).reduce((w,A)=>w+A.price*A.qty,0),U=j=>j.openedAt?Math.floor((ce()-j.openedAt)/6e4):0;return i.jsxs("div",{className:"p-4",children:[i.jsxs("div",{className:"flex items-center justify-between mb-3",children:[i.jsxs("h2",{className:"text-lg font-bold flex items-center gap-2",children:[i.jsx(Ta,{size:20,className:"text-rose-800"})," Floor"]}),i.jsxs("div",{className:"text-xs text-stone-500",children:[e.filter(j=>j.status==="running").length," running · ",e.filter(j=>j.status==="free").length," free"]})]}),i.jsx("div",{className:"grid grid-cols-3 gap-2.5",children:e.map(j=>{const w=j.status==="running",A=U(j),k=A>=60;return i.jsxs("button",{onClick:()=>w?y(j.id):N(j),className:`aspect-square rounded-2xl border p-2.5 flex flex-col justify-between active:scale-95 transition ${w?k?"bg-red-600/10 border-red-600/30":"bg-emerald-600/10 border-emerald-600/30":"bg-white border-stone-200"}`,children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:`font-bold ${w?"text-stone-800":"text-stone-500"}`,children:j.name}),w&&i.jsxs("span",{className:`text-[10px] font-mono flex items-center gap-0.5 ${k?"text-red-600":"text-emerald-700"}`,children:[i.jsx(bi,{size:10}),A,"m"]})]}),w?i.jsxs("div",{className:"text-left",children:[i.jsxs("div",{className:"text-[10px] text-stone-500",children:[j.pax||"-"," pax"]}),i.jsx("div",{className:"font-mono font-bold text-sm text-emerald-700",children:O(L(j))})]}):i.jsx("div",{className:"text-[10px] text-stone-400",children:ne("tapSeat")})]},j.id)})}),v&&i.jsx(G0,{table:e.find(j=>j.id===m),menu:n,settings:r,close:E,addItem:P,chQty:p,setNote:c,voidItem:f,fireKOT:x,move:b,tables:e,recordSale:s,notify:l,patch:h,clearFree:z,liveTotal:L,requireAdmin:o,logAudit:u,inv:d})]})}function G0({table:e,menu:t,settings:n,close:r,addItem:s,chQty:l,setNote:o,voidItem:u,fireKOT:a,move:d,tables:g,recordSale:m,notify:y,patch:v,clearFree:h,liveTotal:N,requireAdmin:P,logAudit:p,inv:c=[]}){const[f,x]=C.useState("order"),[b,E]=C.useState("All"),[z,L]=C.useState(null),[U,j]=C.useState(!1),[w,A]=C.useState(0),[k,T]=C.useState(0),[_,V]=C.useState("Cash"),[Z,$]=C.useState(2),D=["All",...Array.from(new Set(t.map(S=>S.cat)))],I=t.filter(S=>b==="All"||S.cat===b),H=e.items.filter(S=>!S.void),W=H.reduce((S,q)=>S+q.price*q.qty,0),ae=Math.min(W,w),ve=W-ae,Ve=+(ve*n.gst/100).toFixed(2),be=U?+(ve*.05).toFixed(2):0,Se=+(ve+Ve+be+(Number(k)||0)).toFixed(2),ee=e.items.filter(S=>!S.sent&&!S.void).length,F=e.items.filter(S=>!S.sent&&!S.void&&!S.hold).length,X=()=>{if(!P())return;const S=prompt("Discount amount ₹ (ya '10%' likho percent ke liye):","");if(S===null)return;let q=0;String(S).includes("%")?q=+(W*(parseFloat(S)/100)).toFixed(2):q=Number(S)||0,A(q),y(q?`Discount ${O(q)} applied`:"Discount cleared"),q&&p&&p("DISCOUNT",`${e.name} · ${O(q)} on ${O(W)}`)},ie=S=>{if(S&&!P())return;const q=H.map(ot=>({id:ot.mid,name:ot.name,price:ot.price,qty:ot.qty})),Te=m(q,S?"Comp":_,null,"Dine-in",{svc:S?0:be,disc:S?W:ae,tip:S?0:Number(k)||0,comp:S||null,covers:e.pax,steward:e.steward,table:e.name});S||za(n,{...Te,table:e.name},y),h(e.id),y(S?`${e.name} comped (free)`:`${e.name} settled · ${O(Te.total)}`)},He=g.filter(S=>S.id!==e.id&&S.status==="free"),Ze=g.filter(S=>S.id!==e.id&&S.status==="running");return i.jsxs("div",{className:"fixed inset-0 z-50 bg-stone-100 flex flex-col",children:[i.jsxs("div",{className:"px-4 py-3 border-b border-stone-200 flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsxs("div",{className:"font-bold flex items-center gap-2",children:[e.name,i.jsxs("span",{className:"text-xs text-stone-500 font-normal flex items-center gap-1",children:[i.jsx(bi,{size:11}),e.openedAt?Math.floor((ce()-e.openedAt)/6e4):0,"m · KOT ",e.kots]})]}),i.jsxs("div",{className:"flex items-center gap-3 mt-0.5",children:[i.jsxs("button",{onClick:()=>{const S=prompt("Number of guests (pax):",e.pax||"");S!==null&&v(e.id,q=>({...q,pax:Number(S)||0}))},className:"text-[11px] text-stone-500 flex items-center gap-1",children:[i.jsx(So,{size:12}),e.pax||"set"," pax"]}),i.jsxs("button",{onClick:()=>{const S=prompt("Steward / waiter name:",e.steward||"");S!==null&&v(e.id,q=>({...q,steward:S}))},className:"text-[11px] text-stone-500 flex items-center gap-1",children:[i.jsx(Vi,{size:12}),e.steward||"assign"]})]})]}),i.jsx("button",{onClick:r,className:"p-2 rounded-lg bg-stone-100 text-stone-500",children:i.jsx(pr,{size:18})})]}),i.jsx("div",{className:"flex gap-1 px-3 py-2 border-b border-stone-200 text-sm",children:[["order",ne("tabsOrder")],["add",ne("tabsAdd")],["move",ne("tabsShift")],["settle",ne("tabsSettle")]].map(([S,q])=>i.jsx("button",{onClick:()=>x(S),className:`px-3 py-1.5 rounded-lg ${f===S?"bg-rose-800 text-white font-semibold":"text-stone-500"}`,children:q},S))}),i.jsxs("div",{className:"flex-1 overflow-y-auto",children:[f==="order"&&i.jsxs("div",{className:"p-4 space-y-2",children:[e.items.length===0&&i.jsx("div",{className:"text-center text-stone-400 py-8 text-sm",children:'Order khali. "+ Add" se dish daalo.'}),e.items.map(S=>i.jsxs("div",{className:`rounded-xl border p-3 ${S.void?"border-stone-200 opacity-40 line-through":S.sent?"border-stone-200 bg-white":"border-rose-800/30 bg-rose-800/5"}`,children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("div",{className:"flex-1",children:[i.jsxs("div",{className:"text-sm font-medium",children:[S.name," ",!S.sent&&!S.void&&!S.hold&&i.jsx("span",{className:"text-[9px] bg-rose-800 text-white px-1.5 rounded-full align-middle",children:"NEW"}),S.hold&&i.jsx("span",{className:"text-[9px] bg-sky-600/20 text-sky-600 px-1.5 rounded-full align-middle",children:"HOLD"})]}),i.jsxs("div",{className:"text-[11px] text-stone-500 font-mono",children:[O(S.price)," × ",S.qty," = ",O(S.price*S.qty)]}),S.note&&i.jsxs("div",{className:"text-[11px] text-rose-800",children:["↳ ",S.note]}),S.void&&i.jsxs("div",{className:"text-[11px] text-red-600",children:["void: ",S.voidReason]})]}),!S.void&&i.jsxs("div",{className:"flex items-center gap-2 bg-stone-100 rounded-full border border-stone-300 px-1",children:[i.jsx("button",{onClick:()=>l(S.lid,-1),className:"p-1.5 text-rose-800",children:i.jsx(rs,{size:13})}),i.jsx("span",{className:"w-5 text-center font-mono text-sm",children:S.qty}),i.jsx("button",{onClick:()=>l(S.lid,1),className:"p-1.5 text-rose-800",children:i.jsx(st,{size:13})})]})]}),!S.void&&i.jsxs("div",{className:"flex gap-3 mt-2",children:[i.jsxs("button",{onClick:()=>L(S.lid),className:"text-[11px] text-stone-500 flex items-center gap-1",children:[i.jsx($0,{size:11})," Note"]}),!S.sent&&i.jsxs("button",{onClick:()=>v(e.id,q=>({...q,items:q.items.map(Te=>Te.lid===S.lid?{...Te,hold:!Te.hold}:Te)})),className:`text-[11px] flex items-center gap-1 ${S.hold?"text-sky-600":"text-stone-500"}`,children:[i.jsx(bi,{size:11})," ",S.hold?"Held — tap to fire":"Hold"]}),i.jsxs("button",{onClick:()=>u(S.lid),className:"text-[11px] text-red-600 flex items-center gap-1",children:[i.jsx(ns,{size:11})," Void"]})]}),z===S.lid&&i.jsxs("div",{className:"mt-2 flex gap-2",children:[i.jsx("input",{autoFocus:!0,defaultValue:S.note,onBlur:q=>{o(S.lid,q.target.value),L(null)},placeholder:"No onion / Jain / extra spicy",className:"flex-1 bg-stone-100 border border-stone-300 rounded-lg px-2 py-1.5 text-xs outline-none"}),i.jsx("div",{className:"flex gap-1",children:["No onion","Jain","Spicy"].map(q=>i.jsx("button",{onClick:()=>{o(S.lid,q),L(null)},className:"text-[10px] bg-stone-100 rounded px-1.5",children:q},q))})]})]},S.lid)),H.length>0&&i.jsxs("div",{className:"text-right font-mono text-sm text-stone-500 pt-1",children:["Running: ",i.jsx("b",{className:"text-emerald-700",children:O(ve)})]})]}),f==="add"&&i.jsxs("div",{children:[i.jsx("div",{className:"flex gap-2 overflow-x-auto no-scrollbar px-3 py-2 sticky top-0 bg-stone-100",children:D.map(S=>i.jsx("button",{onClick:()=>E(S),className:`whitespace-nowrap px-3 py-1.5 rounded-full text-xs border ${b===S?"bg-rose-800 text-white border-rose-800 font-semibold":"bg-white border-stone-200 text-stone-500"}`,children:S},S))}),i.jsx("div",{className:"grid grid-cols-2 gap-2.5 px-3 pb-4",children:I.map(S=>{const q=ep(S,c),Te=q!=="ok";return i.jsxs("button",{disabled:Te,onClick:()=>{s(S),xt("ok")},className:`text-left bg-white border rounded-2xl p-3 transition ${Te?"border-stone-200 opacity-45":"border-stone-200 active:scale-95 active:border-rose-800"}`,children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:`w-2.5 h-2.5 rounded-full inline-block ${S.veg?"bg-emerald-600":"bg-red-600"}`}),q==="off"&&i.jsx("span",{className:"text-[9px] bg-stone-200 text-stone-600 px-1.5 rounded-full",children:"86"}),q==="out"&&i.jsx("span",{className:"text-[9px] bg-red-600/15 text-red-600 px-1.5 rounded-full",children:"OUT"})]}),i.jsx("div",{className:"text-sm font-medium mt-1.5",children:S.name}),i.jsx("div",{className:"text-rose-800 font-mono font-bold mt-1",children:O(S.price)})]},S.id)})})]}),f==="move"&&i.jsxs("div",{className:"p-4 space-y-4",children:[i.jsxs("div",{children:[i.jsxs("div",{className:"text-xs text-stone-500 uppercase mb-2 flex items-center gap-1",children:[i.jsx(O0,{size:12})," Shift to empty table"]}),i.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[He.map(S=>i.jsx("button",{onClick:()=>d(S.id),className:"py-3 rounded-xl bg-white border border-stone-200 font-semibold",children:S.name},S.id)),!He.length&&i.jsx("div",{className:"col-span-3 text-stone-400 text-sm",children:"No free table."})]})]}),i.jsxs("div",{children:[i.jsxs("div",{className:"text-xs text-stone-500 uppercase mb-2 flex items-center gap-1",children:[i.jsx(So,{size:12})," Merge into running table"]}),i.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[Ze.map(S=>i.jsx("button",{onClick:()=>d(S.id),className:"py-3 rounded-xl bg-emerald-600/10 border border-emerald-600/30 text-emerald-700 font-semibold",children:S.name},S.id)),!Ze.length&&i.jsx("div",{className:"col-span-3 text-stone-400 text-sm",children:"No other running table."})]})]})]}),f==="settle"&&i.jsxs("div",{className:"p-4",children:[ee>0&&i.jsxs("div",{className:"bg-red-600/10 border border-red-600/30 rounded-xl p-3 text-sm text-red-600 mb-3",children:["⚠ ",ee," item abhi kitchen ko nahi gaya. Settle karne se pehle KOT bhejo."]}),i.jsxs("div",{className:"space-y-1 text-sm",children:[i.jsx(Ke,{k:"Subtotal",v:O(W)}),i.jsxs("div",{className:"flex items-center justify-between py-1",children:[i.jsxs("button",{onClick:X,className:"text-rose-800 flex items-center gap-1 text-xs",children:[i.jsx(ns,{size:12,className:"rotate-45"})," ",ae?"Edit discount":"Add discount (admin)"]}),ae>0&&i.jsxs("span",{className:"font-mono text-rose-800",children:["-",O(ae)]})]}),i.jsx(Ke,{k:`GST ${n.gst}%`,v:O(Ve)}),i.jsxs("label",{className:"flex items-center justify-between py-1 text-stone-500",children:[i.jsxs("span",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"checkbox",checked:U,onChange:S=>j(S.target.checked),className:"accent-rose-800"})," Service charge 5%"]}),i.jsx("span",{className:"font-mono",children:O(be)})]}),i.jsxs("div",{className:"flex items-center justify-between py-1",children:[i.jsx("span",{className:"text-stone-500 flex items-center gap-1",children:"Tip"}),i.jsxs("div",{className:"flex items-center gap-1",children:[[0,20,50].map(S=>i.jsx("button",{onClick:()=>T(S),className:`text-xs px-2 py-1 rounded-lg border ${Number(k)===S?"bg-rose-800 text-white border-rose-800":"bg-stone-100 border-stone-300 text-stone-500"}`,children:S?`₹${S}`:"0"},S)),i.jsx("input",{type:"number",value:k||"",onChange:S=>T(S.target.value),placeholder:"₹",className:"w-14 bg-stone-100 border border-stone-300 rounded-lg px-2 py-1 text-sm outline-none"})]})]}),i.jsx(Ke,{k:"TOTAL",v:O(Se),big:!0}),e.pax>0&&i.jsxs("div",{className:"text-right text-[11px] text-stone-500",children:["≈ ",O(Se/e.pax)," per head"]})]}),i.jsx("div",{className:"grid grid-cols-3 gap-2 my-4",children:[["Cash",Ff],["UPI",ss],["Card",Hf]].map(([S,q])=>i.jsxs("button",{onClick:()=>V(S),className:`flex flex-col items-center gap-1 py-3 rounded-xl border ${_===S?"bg-rose-800 text-white border-rose-800 font-semibold":"bg-stone-100 border-stone-300 text-stone-500"}`,children:[i.jsx(q,{size:18}),i.jsx("span",{className:"text-xs",children:S})]},S))}),i.jsxs("details",{className:"mb-3",children:[i.jsxs("summary",{className:"text-xs text-stone-500 cursor-pointer flex items-center gap-1",children:[i.jsx(L0,{size:12})," Split the bill equally"]}),i.jsxs("div",{className:"mt-2 flex items-center gap-3",children:[i.jsx("button",{onClick:()=>$(S=>Math.max(2,S-1)),className:"w-8 h-8 rounded-full bg-stone-100 text-rose-800",children:i.jsx(rs,{size:14})}),i.jsxs("span",{className:"font-mono",children:[Z," ways"]}),i.jsx("button",{onClick:()=>$(S=>S+1),className:"w-8 h-8 rounded-full bg-stone-100 text-rose-800",children:i.jsx(st,{size:14})}),i.jsxs("span",{className:"ml-auto font-mono text-rose-800",children:[O(Se/Z)," each"]})]})]}),i.jsxs("button",{onClick:()=>ie(),disabled:!H.length,className:"w-full bg-gradient-to-br from-emerald-600 to-emerald-700 disabled:opacity-40 text-white font-bold rounded-2xl py-3.5 text-lg shadow-lg shadow-emerald-600/20",children:[ne("settlePrint")," · ",O(Se)]}),i.jsx("button",{onClick:()=>{const S=prompt("Comp (free) reason — service recovery / owner guest:");S&&ie(S)},className:"w-full mt-2 text-xs text-stone-500 py-2",children:"Comp entire bill (free · admin)"})]})]}),f!=="settle"&&i.jsxs("div",{className:"p-3 border-t border-stone-200 flex gap-2",children:[i.jsxs("button",{onClick:a,className:`flex-1 rounded-2xl py-3 font-semibold flex items-center justify-center gap-2 ${F?"bg-gradient-to-br from-red-600 to-red-700 text-white shadow-lg shadow-red-600/20":"bg-stone-100 text-stone-500"}`,children:[i.jsx(Pa,{size:16})," ",F?ne("sendKitchen").replace("%n",F):ne("allSent")]}),i.jsxs("button",{onClick:()=>x("settle"),className:"flex-1 bg-emerald-600 text-white rounded-xl py-3 font-semibold flex items-center justify-center gap-2",children:[i.jsx(Oa,{size:16})," ",O(Se)]})]})]})}function Y0({menu:e,settings:t,recordSale:n,notify:r,inv:s,setInv:l,requireAdmin:o,logAudit:u,addKds:a}){const[d,g]=C.useState({}),[m,y]=C.useState("All"),[v,h]=C.useState(""),[N,P]=C.useState(!1),[p,c]=C.useState(null),f=["All",...Array.from(new Set(e.map(k=>k.cat)))],x=e.filter(k=>(m==="All"||k.cat===m)&&k.name.toLowerCase().includes(v.toLowerCase())),b=Object.values(d),E=b.reduce((k,T)=>k+T.price*T.qty,0),z=+(E*t.gst/100).toFixed(2),L=E+z,U=b.reduce((k,T)=>k+T.qty,0),j=k=>{g(T=>{var _;return{...T,[k.id]:{...k,qty:(((_=T[k.id])==null?void 0:_.qty)||0)+1}}}),c(k.id),setTimeout(()=>c(null),200),xt("ok")},w=k=>g(T=>{var Z;const _=(((Z=T[k])==null?void 0:Z.qty)||0)-1,V={...T};return _<=0?delete V[k]:V[k]={...V[k],qty:_},V}),A=()=>g({});return i.jsxs("div",{className:"flex flex-col h-full",children:[i.jsxs("div",{className:"p-3 space-y-2 sticky top-0 bg-stone-100 z-10",children:[i.jsxs("div",{className:"flex items-center gap-2 text-xs text-rose-800",children:[i.jsx(Si,{size:14})," ",ne("counterHeader")]}),i.jsxs("div",{className:"relative",children:[i.jsx(Wf,{size:16,className:"absolute left-3 top-3 text-stone-500"}),i.jsx("input",{value:v,onChange:k=>h(k.target.value),placeholder:ne("searchDish"),className:"w-full bg-white border border-stone-200 rounded-xl pl-9 pr-3 py-2.5 text-sm outline-none focus:border-rose-800"})]}),i.jsx("div",{className:"flex gap-2 overflow-x-auto no-scrollbar pb-1",children:f.map(k=>i.jsx("button",{onClick:()=>y(k),className:`whitespace-nowrap px-3 py-1.5 rounded-full text-xs border ${m===k?"bg-rose-800 text-white border-rose-800 font-semibold":"bg-white border-stone-200 text-stone-500"}`,children:k},k))})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-2.5 px-3 pb-40",children:[x.map(k=>{var V;const T=ep(k,s),_=T!=="ok";return i.jsxs("button",{disabled:_,onClick:()=>j(k),className:`relative text-left bg-white border rounded-2xl p-3 transition ${_?"opacity-45 border-stone-200":"active:scale-95"} ${p===k.id?"border-rose-800 scale-95":"border-stone-200"}`,children:[i.jsxs("div",{className:"flex items-start justify-between",children:[i.jsx("span",{className:`w-2.5 h-2.5 rounded-full mt-1 ${k.veg?"bg-emerald-600":"bg-red-600"}`}),T==="off"?i.jsx("span",{className:"text-[9px] bg-stone-200 text-stone-600 px-1.5 rounded-full",children:"86"}):T==="out"?i.jsx("span",{className:"text-[9px] bg-red-600/15 text-red-600 px-1.5 rounded-full",children:"OUT"}):((V=d[k.id])==null?void 0:V.qty)>0&&i.jsx("span",{className:"bg-rose-800 text-white text-xs font-bold px-2 rounded-full",children:d[k.id].qty})]}),i.jsx("div",{className:"text-sm font-medium mt-1.5 leading-tight",children:k.name}),i.jsx("div",{className:"text-rose-800 font-mono font-bold mt-1",children:O(k.price)})]},k.id)}),x.length===0&&i.jsx("div",{className:"col-span-2 text-center text-stone-400 py-10 text-sm",children:"No dish found. Add one from More → Menu."})]}),U>0&&i.jsx("div",{className:"fixed bottom-16 inset-x-0 px-3 z-20",children:i.jsxs("button",{onClick:()=>P(!0),className:"w-full bg-gradient-to-br from-emerald-600 to-emerald-700 text-white rounded-2xl px-4 py-3.5 flex items-center justify-between shadow-xl shadow-emerald-600/20 active:scale-[0.98] transition",children:[i.jsxs("span",{className:"flex items-center gap-2 font-semibold",children:[i.jsx(Si,{size:18})," ",U," item",U>1?"s":""]}),i.jsxs("span",{className:"font-mono font-bold text-lg tabular-nums",children:[O(L)," →"]})]})}),i.jsx(X0,{open:N,onClose:()=>P(!1),lines:b,sub:E,settings:t,recordSale:n,notify:r,clear:A,cart:d,inv:s,setInv:l,menu:e,dec:w,add:j,requireAdmin:o,logAudit:u,addKds:a})]})}function X0({open:e,onClose:t,lines:n,sub:r,settings:s,recordSale:l,notify:o,clear:u,dec:a,add:d,inv:g,setInv:m,menu:y,requireAdmin:v,logAudit:h,addKds:N}){const[P,p]=C.useState("cart"),[c,f]=C.useState("Cash"),[x,b]=C.useState(0),[E,z]=C.useState(""),[L,U]=C.useState(""),[j,w]=C.useState(""),A="Takeaway",[k,T]=C.useState(null),[_,V]=C.useState(null),[Z,$]=C.useState(!1);C.useEffect(()=>{e&&(p("cart"),w(""),b(0),V(null))},[e]);const D=async()=>{$(!0);const F=n.map(ie=>`${ie.qty}x ${ie.name}`).join(", "),X=y.filter(ie=>!ie.off).map(ie=>`${ie.name} (₹${ie.price}, ${ie.cat})`).join("; ");try{const ie=await Jf([{role:"user",content:`Current order: ${F}. Menu: ${X}. Suggest up to 2 smart upsell/cross-sell items from the menu that pair well and lift the bill. Return ONLY JSON array like [{"name":"exact menu name","pitch":"one short persuasive line in Hinglish"}]. No item already in the order.`}],"You are a sharp restaurant upsell strategist. Suggest natural pairings (drink with spicy food, dessert to finish, sides). Only use exact names from the provided menu. Output strictly JSON, nothing else.",300),He=I0(ie),Ze=(Array.isArray(He)?He:[]).map(S=>({...S,item:y.find(q=>q.name===S.name&&!q.off)})).filter(S=>S.item&&!n.some(q=>q.id===S.item.id)).slice(0,2);V(Ze.length?Ze:[{pitch:"Sab set hai — koi add-on zaroori nahi.",item:null}])}catch{const ie=y.find(He=>!He.off&&["Beverages","Desserts"].includes(He.cat)&&!n.some(Ze=>Ze.id===He.id));V(ie?[{item:ie,pitch:`${ie.name} saath me achha lagega`}]:[{pitch:"Sab set hai.",item:null}])}$(!1)},I=Math.min(r,x),H=r-I,W=+(H*s.gst/100).toFixed(2),ae=+(H+W).toFixed(2),ve=()=>{if(!v())return;const F=prompt("Discount amount ₹ (ya '10%' for percent):","");if(F===null)return;const X=String(F).includes("%")?+(r*(parseFloat(F)/100)).toFixed(2):Number(F)||0;b(X),o(X?`Discount ${O(X)}`:"Discount cleared"),X&&h&&h("DISCOUNT",`Takeaway · ${O(X)} on ${O(r)}`)},Ve=()=>{const F=n.map(ie=>({id:ie.id,name:ie.name,price:ie.price,qty:ie.qty})),X=l(F,c,E?{phone:E,name:L}:null,A,{disc:I});T({...X,tendered:c==="Cash"&&Number(j)||X.total}),p("done"),o("Paid · "+O(X.total)),N&&N("Takeaway",F),setTimeout(()=>Se(F),300)},be=c==="Cash"&&j?Math.max(0,Number(j)-ae):0,Se=F=>{const X=window.open("","_blank","width=300,height=600");if(!X){o("Allow pop-ups to print KOT");return}const He=(F||(k==null?void 0:k.items)||n).map(Ze=>`${Ze.qty} ×${Ze.name}`).join("");X.document.write(`KOT

KITCHEN ORDER

${s.name}

${A} · ${qi(ce())}

${He}

** Not a bill **
`),X.document.close(),X.focus(),X.print()},ee=()=>{k&&za(s,k,o)};return i.jsxs(pt,{open:e,onClose:t,title:P==="done"?"Payment done":P==="pay"?"Collect payment":"Order",children:[P==="cart"&&i.jsxs("div",{children:[n.length===0&&i.jsx("div",{className:"text-stone-500 text-sm text-center py-6",children:"Cart empty"}),i.jsx("div",{className:"space-y-2 mb-4",children:n.map(F=>i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("div",{className:"flex-1",children:[i.jsx("div",{className:"text-sm",children:F.name}),i.jsxs("div",{className:"text-xs text-stone-500 font-mono",children:[O(F.price)," × ",F.qty," = ",O(F.price*F.qty)]})]}),i.jsxs("div",{className:"flex items-center gap-2 bg-stone-100 rounded-full border border-stone-300 px-1",children:[i.jsx("button",{onClick:()=>a(F.id),className:"p-1.5 text-rose-800",children:i.jsx(rs,{size:14})}),i.jsx("span",{className:"w-5 text-center font-mono text-sm",children:F.qty}),i.jsx("button",{onClick:()=>d(F),className:"p-1.5 text-rose-800",children:i.jsx(st,{size:14})})]})]},F.id))}),i.jsxs("div",{className:"border-t border-stone-200 pt-3 space-y-1 text-sm",children:[i.jsx(Ke,{k:"Subtotal",v:O(r)}),i.jsx(Ke,{k:`GST ${s.gst}%`,v:O(W)}),i.jsx(Ke,{k:"TOTAL",v:O(ae),big:!0})]}),_?i.jsx("div",{className:"mt-3 space-y-2",children:_.map((F,X)=>F.item?i.jsxs("button",{onClick:()=>d(F.item),className:"w-full text-left bg-gradient-to-r from-rose-800/10 to-rose-900/5 border border-rose-800/30 rounded-2xl px-3 py-2.5 flex items-center gap-2 active:scale-[0.98]",children:[i.jsx("span",{className:"text-lg",children:"✨"}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("div",{className:"text-sm text-rose-800",children:F.pitch}),i.jsxs("div",{className:"text-[11px] text-stone-500",children:[F.item.name," · +",O(F.item.price)]})]}),i.jsx(st,{size:16,className:"text-rose-800"})]},X):i.jsx("div",{className:"text-xs text-stone-500 text-center py-1",children:F.pitch},X))}):i.jsx("button",{onClick:D,disabled:Z||!n.length,className:"mt-3 w-full bg-white border border-stone-200 rounded-2xl py-2.5 text-sm text-rose-700 flex items-center justify-center gap-2 disabled:opacity-50 active:scale-[0.98]",children:Z?"✨ soch raha hoon…":"✨ AI se add-on suggest karo"}),i.jsxs("button",{disabled:!n.length,onClick:()=>p("pay"),className:"mt-3 w-full bg-gradient-to-br from-emerald-600 to-emerald-700 disabled:opacity-40 text-white font-semibold rounded-2xl py-3 shadow-lg shadow-emerald-600/20",children:[ne("collect")," ",O(ae)]})]}),P==="pay"&&i.jsxs("div",{children:[i.jsxs("div",{className:"text-center mb-4",children:[i.jsx("div",{className:"text-xs text-stone-500",children:"Amount to collect"}),i.jsx("div",{className:"text-4xl font-mono font-bold text-emerald-700 tabular-nums",children:O(ae)})]}),i.jsx("div",{className:"grid grid-cols-3 gap-2 mb-3",children:[["Cash",Ff],["UPI",ss],["Card",Hf]].map(([F,X])=>i.jsxs("button",{onClick:()=>f(F),className:`flex flex-col items-center gap-1 py-3 rounded-xl border ${c===F?"bg-rose-800 text-white border-rose-800 font-semibold":"bg-stone-100 border-stone-300 text-stone-500"}`,children:[i.jsx(X,{size:18}),i.jsx("span",{className:"text-xs",children:F})]},F))}),i.jsxs("div",{className:"flex items-center justify-between mb-3 bg-stone-100 border border-stone-300 rounded-xl px-3 py-2.5",children:[i.jsxs("button",{onClick:ve,className:"text-rose-800 flex items-center gap-1 text-sm",children:[i.jsx(ns,{size:13,className:"rotate-45"})," ",I?"Edit discount":"Add discount (admin)"]}),I>0&&i.jsxs("span",{className:"font-mono text-rose-800 text-sm",children:["-",O(I)]})]}),c==="Cash"&&i.jsxs("div",{className:"mb-3",children:[i.jsx(G,{label:"Cash received (optional)",type:"number",value:j,onChange:F=>w(F.target.value),placeholder:String(Math.ceil(ae))}),be>0&&i.jsxs("div",{className:"text-sm text-rose-800 -mt-1",children:["Return change: ",i.jsx("b",{className:"font-mono",children:O(be)})]})]}),i.jsxs("details",{className:"mb-3",children:[i.jsx("summary",{className:"text-xs text-stone-500 cursor-pointer",children:"+ Add customer (for CRM & repeat)"}),i.jsxs("div",{className:"mt-2",children:[i.jsx(G,{label:"Phone",value:E,onChange:F=>z(F.target.value),placeholder:"98xxxxxxxx"}),i.jsx(G,{label:"Name",value:L,onChange:F=>U(F.target.value),placeholder:"Optional"})]})]}),i.jsx("button",{onClick:Ve,className:"w-full bg-gradient-to-br from-emerald-600 to-emerald-700 text-white font-bold rounded-2xl py-3.5 text-lg shadow-lg shadow-emerald-600/20",children:ne("markPaid")})]}),P==="done"&&k&&i.jsxs("div",{className:"text-center",children:[i.jsx("div",{className:"w-16 h-16 rounded-full bg-emerald-600 mx-auto flex items-center justify-center mb-3",children:i.jsx(Vf,{size:32,className:"text-white"})}),i.jsx("div",{className:"text-2xl font-mono font-bold text-emerald-700",children:O(k.total)}),i.jsxs("div",{className:"text-sm text-stone-500",children:["collected via ",k.mode]}),k.mode==="Cash"&&k.tendered>k.total&&i.jsxs("div",{className:"text-rose-800 mt-1",children:["Change: ",O(k.tendered-k.total)]}),i.jsxs("div",{className:"grid grid-cols-2 gap-2 mt-5",children:[i.jsxs("button",{onClick:()=>Se(),className:"flex items-center justify-center gap-2 bg-red-600/10 border border-red-600/30 text-red-600 rounded-xl py-3",children:[i.jsx(Vi,{size:16})," Reprint KOT"]}),i.jsxs("button",{onClick:()=>ee(),className:"flex items-center justify-center gap-2 bg-stone-100 border border-stone-300 rounded-xl py-3",children:[i.jsx(Oa,{size:16})," Bill (PDF)"]})]}),i.jsx("button",{onClick:()=>{u(),t()},className:"mt-3 w-full bg-rose-800 text-white font-semibold rounded-xl py-3",children:"New Order"})]})]})}const Ke=({k:e,v:t,big:n})=>i.jsxs("div",{className:`flex justify-between ${n?"text-lg font-bold pt-1":"text-stone-500"}`,children:[i.jsx("span",{children:e}),i.jsx("span",{className:`font-mono tabular-nums ${n?"text-emerald-700":"text-stone-700"}`,children:t})]});function J0({online:e,setOnline:t,recordSale:n,notify:r,addKds:s}){const l=d=>{var m,y;n(d.items,"UPI",d.cust,"Online"),t(v=>v.map(h=>h.id===d.id?{...h,status:"accepted"}:h)),s&&s("Online",d.items);const g=window.open("","_blank","width=300,height=600");if(g){const v=d.items.map(h=>`${h.qty} ×${h.name}`).join("");g.document.write(`KOT

ONLINE KOT

${((m=d.cust)==null?void 0:m.name)||"Guest"} · ${((y=d.cust)==null?void 0:y.phone)||""}

${v}

** Not a bill **
`),g.document.close(),g.print()}r("Order accepted · KOT sent")},o=d=>t(g=>g.map(m=>m.id===d.id?{...m,status:"rejected"}:m)),u=e.filter(d=>d.status==="new"),a=e.filter(d=>d.status!=="new");return i.jsxs("div",{className:"p-4 space-y-4",children:[i.jsxs("h2",{className:"text-lg font-bold flex items-center gap-2",children:[i.jsx(_a,{size:20,className:"text-rose-800"})," Online Orders"]}),u.length===0&&i.jsx(oe,{className:"p-6 text-center text-stone-500 text-sm",children:"No pending orders. Share your order link from Home → Share Order Link."}),u.map(d=>{var g,m;return i.jsxs(oe,{className:"p-4 border-red-600/30",children:[i.jsxs("div",{className:"flex justify-between items-start",children:[i.jsxs("div",{children:[i.jsxs("div",{className:"font-semibold",children:[((g=d.cust)==null?void 0:g.name)||"Guest"," ",i.jsx("span",{className:"text-xs text-stone-500",children:(m=d.cust)==null?void 0:m.phone})]}),i.jsx("div",{className:"text-[11px] text-stone-500",children:qi(d.ts)})]}),i.jsx("div",{className:"font-mono font-bold text-emerald-700",children:O(d.items.reduce((y,v)=>y+v.price*v.qty,0))})]}),i.jsx("div",{className:"text-sm text-stone-600 mt-2 space-y-0.5",children:d.items.map((y,v)=>i.jsxs("div",{children:[y.qty," × ",y.name]},v))}),i.jsxs("div",{className:"grid grid-cols-2 gap-2 mt-3",children:[i.jsxs("button",{onClick:()=>l(d),className:"bg-emerald-600 text-white font-semibold rounded-xl py-2.5 flex items-center justify-center gap-1",children:[i.jsx(Pa,{size:15})," Accept & KOT"]}),i.jsx("button",{onClick:()=>o(d),className:"bg-stone-100 text-stone-500 rounded-xl py-2.5",children:"Reject"})]})]},d.id)}),a.length>0&&i.jsxs("div",{children:[i.jsx("div",{className:"text-xs text-stone-500 uppercase tracking-wider mb-2",children:"History"}),i.jsx("div",{className:"space-y-2",children:a.slice(0,15).map(d=>{var g;return i.jsxs("div",{className:"flex justify-between text-sm bg-white border border-stone-200 rounded-xl px-3 py-2",children:[i.jsxs("span",{className:"text-stone-500",children:[((g=d.cust)==null?void 0:g.name)||"Guest"," · ",d.items.length," items"]}),i.jsx("span",{className:d.status==="accepted"?"text-emerald-700":"text-red-600",children:d.status})]},d.id)})})]})]})}function Z0({expenses:e,setExpenses:t,cashLog:n,setCashLog:r,cashInDrawer:s,todayCollection:l,todayExp:o,sales:u,notify:a,logAudit:d}){const[g,m]=C.useState("cash"),[y,v]=C.useState(!1),[h,N]=C.useState(!1),[P,p]=C.useState(null),[c,f]=C.useState({category:"Vegetables",amount:"",note:"",paid:"Cash",billNo:"",photo:null}),[x,b]=C.useState({type:"in",amount:"",note:""}),E=async()=>{const j=await La();j&&(f(w=>({...w,photo:j})),a("Bill attached"))},z=()=>{c.amount&&(t(j=>[{id:K(),ts:ce(),...c,amount:Number(c.amount)},...j]),d&&d("EXPENSE",`${c.category} ₹${c.amount} · ${c.paid}${c.photo?" · bill 📎":" · NO BILL"}`),v(!1),f({category:"Vegetables",amount:"",note:"",paid:"Cash",billNo:"",photo:null}),a("Expense added"),xt("ok"))},L=()=>{x.amount&&(r(j=>[{id:K(),ts:ce(),...x,amount:Number(x.amount)},...j]),d&&d("CASH",`${x.type==="in"?"IN":"OUT"} ₹${x.amount} · ${x.note||"-"}`),N(!1),b({type:"in",amount:"",note:""}),a("Cash entry saved"),xt("ok"))},U=C.useMemo(()=>{const j=u.filter(w=>Mt(w.ts));return{Cash:j.filter(w=>w.mode==="Cash").reduce((w,A)=>w+A.total,0),UPI:j.filter(w=>w.mode==="UPI").reduce((w,A)=>w+A.total,0),Card:j.filter(w=>w.mode==="Card").reduce((w,A)=>w+A.total,0)}},[u]);return i.jsxs("div",{className:"p-4 space-y-4",children:[i.jsxs("div",{className:"flex gap-3",children:[i.jsx(rn,{label:"Cash in Drawer",value:O(s),accent:"text-rose-800"}),i.jsx(rn,{label:"Net Today",value:O(l-o),accent:"text-emerald-700",sub:`Sale ${O(l)} − Exp ${O(o)}`})]}),i.jsxs(oe,{className:"p-4",children:[i.jsx("div",{className:"text-xs text-stone-500 uppercase tracking-wider mb-2",children:"Today's collection by mode"}),i.jsx("div",{className:"grid grid-cols-3 gap-2 text-center",children:Object.entries(U).map(([j,w])=>i.jsxs("div",{className:"bg-stone-100 rounded-xl py-2",children:[i.jsx("div",{className:"text-[10px] text-stone-500",children:j}),i.jsx("div",{className:"font-mono font-bold text-sm",children:O(w)})]},j))})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[i.jsxs("button",{onClick:()=>N(!0),className:"bg-rose-800 text-white font-semibold rounded-xl py-3 flex items-center justify-center gap-2",children:[i.jsx(Yf,{size:16})," Cash In/Out"]}),i.jsxs("button",{onClick:()=>v(!0),className:"bg-red-600/10 border border-red-600/30 text-red-600 font-semibold rounded-xl py-3 flex items-center justify-center gap-2",children:[i.jsx(oc,{size:16})," Add Expense"]})]}),i.jsx("div",{className:"flex gap-2",children:["cash","exp"].map(j=>i.jsx("button",{onClick:()=>m(j),className:`text-sm px-3 py-1.5 rounded-full ${g===j?"bg-stone-100 text-rose-800":"text-stone-500"}`,children:j==="cash"?"Cash Ledger":"Expenses"},j))}),g==="cash"&&i.jsxs("div",{className:"space-y-2",children:[n.length===0&&i.jsx("div",{className:"text-stone-400 text-sm text-center py-6",children:"No manual cash entries yet."}),n.slice(0,30).map(j=>i.jsxs("div",{className:"flex items-center justify-between bg-white border border-stone-200 rounded-xl px-3 py-2.5",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[j.type==="in"?i.jsx(P0,{size:16,className:"text-emerald-700"}):i.jsx(oc,{size:16,className:"text-red-600"}),i.jsxs("div",{children:[i.jsx("div",{className:"text-sm",children:j.note||(j.type==="in"?"Cash in":"Cash out")}),i.jsx("div",{className:"text-[10px] text-stone-500",children:qi(j.ts)})]})]}),i.jsxs("div",{className:`font-mono font-bold ${j.type==="in"?"text-emerald-700":"text-red-600"}`,children:[j.type==="in"?"+":"−",O(j.amount)]})]},j.id))]}),g==="exp"&&i.jsxs("div",{className:"space-y-2",children:[e.length===0&&i.jsx("div",{className:"text-stone-400 text-sm text-center py-6",children:"No expenses logged."}),e.slice(0,30).map(j=>i.jsxs("div",{className:"flex items-center justify-between bg-white border border-stone-200 rounded-xl px-3 py-2.5",children:[i.jsxs("div",{className:"flex items-center gap-2.5",children:[j.photo?i.jsx("img",{src:j.photo,onClick:()=>p(j.photo),className:"w-9 h-9 rounded-lg object-cover border border-stone-300"}):i.jsx("span",{className:"w-9 h-9 rounded-lg bg-red-600/10 border border-red-600/30 flex items-center justify-center text-red-600 text-[9px]",children:"no bill"}),i.jsxs("div",{children:[i.jsxs("div",{className:"text-sm",children:[j.category,j.billNo?` · #${j.billNo}`:""]}),i.jsxs("div",{className:"text-[10px] text-stone-500",children:[j.note," · ",j.paid," · ",Bt(j.ts)]})]})]}),i.jsxs("div",{className:"font-mono font-bold text-red-600",children:["−",O(j.amount)]})]},j.id))]}),i.jsxs(pt,{open:y,onClose:()=>v(!1),title:"Add Expense",children:[i.jsx("div",{className:"grid grid-cols-3 gap-2 mb-3",children:["Vegetables","Groceries","Gas","Rent","Salary","Misc"].map(j=>i.jsx("button",{onClick:()=>f(w=>({...w,category:j})),className:`text-xs py-2 rounded-lg border ${c.category===j?"bg-rose-800 text-white border-rose-800":"bg-stone-100 border-stone-300 text-stone-500"}`,children:j},j))}),i.jsx(G,{label:"Amount",type:"number",value:c.amount,onChange:j=>f(w=>({...w,amount:j.target.value})),placeholder:"0"}),i.jsx(G,{label:"Note",value:c.note,onChange:j=>f(w=>({...w,note:j.target.value})),placeholder:"Optional"}),i.jsx(G,{label:"Bill / Invoice No (optional)",value:c.billNo,onChange:j=>f(w=>({...w,billNo:j.target.value})),placeholder:"Supplier bill no."}),i.jsx("button",{onClick:E,className:"w-full mb-3 border border-dashed border-stone-300 rounded-xl py-3 flex items-center justify-center gap-2 text-sm text-stone-600",children:c.photo?i.jsxs(i.Fragment,{children:[i.jsx("img",{src:c.photo,className:"w-8 h-8 rounded object-cover"})," Bill attached — retake"]}):i.jsx(i.Fragment,{children:"📷 Attach bill photo"})}),i.jsx("div",{className:"flex gap-2 mb-4",children:["Cash","UPI"].map(j=>i.jsx("button",{onClick:()=>f(w=>({...w,paid:j})),className:`flex-1 py-2 rounded-lg border text-sm ${c.paid===j?"bg-stone-100 border-rose-800 text-rose-800":"bg-stone-100 border-stone-300 text-stone-500"}`,children:j},j))}),i.jsx("button",{onClick:z,className:"w-full bg-red-600 text-white font-semibold rounded-xl py-3",children:"Save Expense"})]}),i.jsx(pt,{open:!!P,onClose:()=>p(null),title:"Bill photo",children:P&&i.jsx("img",{src:P,className:"w-full rounded-xl"})}),i.jsxs(pt,{open:h,onClose:()=>N(!1),title:"Cash In / Out",children:[i.jsxs("div",{className:"grid grid-cols-2 gap-2 mb-3",children:[i.jsx("button",{onClick:()=>b(j=>({...j,type:"in"})),className:`py-2.5 rounded-xl border ${x.type==="in"?"bg-emerald-600 text-white border-emerald-600 font-semibold":"bg-stone-100 border-stone-300 text-stone-500"}`,children:"Cash In"}),i.jsx("button",{onClick:()=>b(j=>({...j,type:"out"})),className:`py-2.5 rounded-xl border ${x.type==="out"?"bg-red-600 text-white border-red-600 font-semibold":"bg-stone-100 border-stone-300 text-stone-500"}`,children:"Cash Out"})]}),i.jsx(G,{label:"Amount",type:"number",value:x.amount,onChange:j=>b(w=>({...w,amount:j.target.value})),placeholder:"0"}),i.jsx(G,{label:"Note",value:x.note,onChange:j=>b(w=>({...w,note:j.target.value})),placeholder:"Opening float / drawer withdraw etc."}),i.jsx("button",{onClick:L,className:"w-full bg-rose-800 text-white font-semibold rounded-xl py-3",children:"Save"})]})]})}function ex({setTab:e,kds:t=[],easy:n=!0}){const[r,s]=C.useState(!n),l=t.filter(d=>d.status!=="served").length,o=[{id:"kds",icon:Vi,label:"Kitchen Display (KDS)",desc:"Live tickets, cooking→ready",badge:l},{id:"reports",icon:Oa,label:"Reports & Day Close",desc:"Z-report, insights, backup"},{id:"money",icon:Yf,label:"Money & Cash",desc:"Drawer, expenses, in/out"},{id:"inv",icon:qf,label:"Inventory / Store",desc:"Stock, expiry, wastage"},{id:"menu",icon:Ra,label:"Menu & Recipe",desc:"Dishes, cost, recipe→stock"}],u=[{id:"reserve",icon:_a,label:"Reservations & Waitlist",desc:"Bookings, walk-in queue"},{id:"suppliers",icon:Uf,label:"Suppliers & Purchase",desc:"GRN, stock-in, payables"},{id:"staff",icon:So,label:"Staff & Salary",desc:"Team, salary, advance"},{id:"cust",icon:Gf,label:"Customers",desc:"CRM & repeat"},{id:"share",icon:Aa,label:"Share Order Link",desc:"WhatsApp ordering"},{id:"settings",icon:Kf,label:"Settings",desc:"Name, GST, PIN, Easy Mode"}],a=d=>i.jsxs("button",{onClick:()=>e(d.id),className:"w-full flex items-center gap-3 bg-white border border-stone-200 rounded-2xl p-4 active:scale-[0.98] transition",children:[i.jsxs("div",{className:"w-10 h-10 rounded-xl bg-stone-100 flex items-center justify-center text-rose-800 relative",children:[i.jsx(d.icon,{size:20}),d.badge>0&&i.jsx("span",{className:"absolute -top-1 -right-1 bg-red-600 text-white text-[9px] w-4 h-4 rounded-full flex items-center justify-center",children:d.badge})]}),i.jsxs("div",{className:"text-left flex-1",children:[i.jsx("div",{className:"font-medium",children:d.label}),i.jsx("div",{className:"text-xs text-stone-500",children:d.desc})]}),i.jsx("span",{className:"text-stone-400",children:"›"})]},d.id);return i.jsxs("div",{className:"p-4 space-y-2",children:[o.map(a),n&&!r?i.jsx("button",{onClick:()=>s(!0),className:"w-full text-sm text-stone-500 py-3 border border-dashed border-stone-300 rounded-2xl",children:"+ Advanced options (suppliers, staff, bookings, settings)"}):i.jsxs(i.Fragment,{children:[n&&i.jsx("div",{className:"text-[11px] text-stone-400 uppercase tracking-wider pt-2 pb-1",children:"Advanced"}),u.map(a)]})]})}function tx({menu:e,setMenu:t,notify:n,setTab:r,requireAdmin:s,logAudit:l,inv:o=[]}){const[u,a]=C.useState(!1),[d,g]=C.useState(null),[m,y]=C.useState({name:"",price:"",cost:"",cat:"Main Course",veg:!0,recipe:[],station:"General",off:!1,tags:[]}),v=x=>{x?(g(x.id),y({recipe:[],station:"General",off:!1,tags:[],...x})):(g(null),y({name:"",price:"",cost:"",cat:"Main Course",veg:!0,recipe:[],station:"General",off:!1,tags:[]})),a(!0)},h=x=>y(b=>({...b,tags:(b.tags||[]).includes(x)?b.tags.filter(E=>E!==x):[...b.tags||[],x]})),N=()=>{if(!m.name||!m.price)return;const x={...m,price:Number(m.price),cost:Number(m.cost)||0,recipe:(m.recipe||[]).filter(b=>b.invId&&Number(b.qty)>0).map(b=>({invId:b.invId,qty:Number(b.qty),unit:b.unit||""}))};t(d?b=>b.map(E=>E.id===d?{...E,...x}:E):b=>[{id:K(),...x},...b]),a(!1),n("Menu updated"),xt("ok")},P=x=>t(b=>b.filter(E=>E.id!==x)),p=()=>y(x=>({...x,recipe:[...x.recipe||[],{invId:"",qty:""}]})),c=(x,b,E)=>y(z=>({...z,recipe:z.recipe.map((L,U)=>U===x?{...L,[b]:E}:L)})),f=x=>y(b=>({...b,recipe:b.recipe.filter((E,z)=>z!==x)}));return i.jsxs("div",{className:"p-4 space-y-3",children:[i.jsx(Kt,{setTab:r,title:"Menu & Recipe"}),i.jsxs("button",{onClick:()=>v(null),className:"w-full bg-rose-800 text-white font-semibold rounded-xl py-3 flex items-center justify-center gap-2",children:[i.jsx(st,{size:16})," Add Dish"]}),i.jsx("div",{className:"space-y-2",children:e.map(x=>{var E;const b=x.price?Math.round((1-x.cost/x.price)*100):0;return i.jsxs(oe,{className:"p-3 flex items-center gap-3",children:[i.jsx("span",{className:`w-2.5 h-2.5 rounded-full ${x.veg?"bg-emerald-600":"bg-red-600"}`}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"font-medium truncate",children:[x.name," ",(E=x.recipe)!=null&&E.length?i.jsx("span",{className:"text-[9px] bg-sky-600/15 text-sky-600 px-1.5 rounded-full",children:"recipe"}):i.jsx("span",{className:"text-[9px] bg-stone-200 text-stone-500 px-1.5 rounded-full",children:"no recipe"})]}),i.jsxs("div",{className:"text-[11px] text-stone-500",children:[x.cat," · Cost ",O(x.cost)," · ",i.jsxs("span",{className:b>=60?"text-emerald-700":b>=40?"text-rose-800":"text-red-600",children:["Margin ",b,"%"]})]})]}),i.jsx("div",{className:"font-mono font-bold text-rose-800",children:O(x.price)}),i.jsx("button",{onClick:()=>t(z=>z.map(L=>L.id===x.id?{...L,off:!L.off}:L)),className:`text-[10px] px-2 py-1 rounded-lg border ${x.off?"bg-red-600/10 border-red-600/30 text-red-600":"bg-stone-100 border-stone-300 text-stone-500"}`,children:x.off?"86":"ON"}),i.jsx("button",{onClick:()=>v(x),className:"p-2 text-stone-500",children:"✎"}),i.jsx("button",{onClick:()=>P(x.id),className:"p-2 text-stone-400",children:i.jsx(Hi,{size:15})})]},x.id)})}),i.jsxs(pt,{open:u,onClose:()=>a(!1),title:d?"Edit Dish":"Add Dish",children:[i.jsx(G,{label:"Dish name",value:m.name,onChange:x=>y(b=>({...b,name:x.target.value}))}),i.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[i.jsx(G,{label:"Selling Price ₹",type:"number",value:m.price,onChange:x=>y(b=>({...b,price:x.target.value}))}),i.jsx(G,{label:"Cost / COGS ₹",type:"number",value:m.cost,onChange:x=>y(b=>({...b,cost:x.target.value}))})]}),m.price>0&&m.cost>0&&i.jsxs("div",{className:"text-sm text-emerald-700 -mt-1 mb-3",children:["Margin: ",Math.round((1-m.cost/m.price)*100),"% · Profit ",O(m.price-m.cost),"/plate"]}),i.jsx(G,{label:"Category",value:m.cat,onChange:x=>y(b=>({...b,cat:x.target.value}))}),i.jsxs("label",{className:"block mb-3",children:[i.jsx("span",{className:"text-xs text-stone-500",children:"Kitchen station (for KDS routing)"}),i.jsx("select",{value:m.station,onChange:x=>y(b=>({...b,station:x.target.value})),className:"mt-1 w-full bg-stone-100 border border-stone-300 rounded-xl px-3 py-2.5 text-stone-800 outline-none",children:["General","Tandoor","Curry","Chinese","Cold/Salad","Bar","Dessert","Bakery"].map(x=>i.jsx("option",{value:x,children:x},x))})]}),i.jsx("div",{className:"flex gap-2 mb-4",children:[["Veg",!0],["Non-veg",!1]].map(([x,b])=>i.jsx("button",{onClick:()=>y(E=>({...E,veg:b})),className:`flex-1 py-2 rounded-lg border text-sm ${m.veg===b?"bg-stone-100 border-rose-800 text-rose-800":"bg-stone-100 border-stone-300 text-stone-500"}`,children:x},x))}),i.jsxs("div",{className:"mb-3",children:[i.jsx("div",{className:"text-xs text-stone-500 mb-1.5",children:"Tags (allergen / diet — kitchen & guest safety)"}),i.jsx("div",{className:"flex flex-wrap gap-2",children:["Jain","Nuts","Gluten","Dairy","Spicy","Egg"].map(x=>i.jsx("button",{onClick:()=>h(x),className:`text-xs px-3 py-1.5 rounded-full border ${(m.tags||[]).includes(x)?"bg-rose-800 text-white border-rose-800 font-semibold":"bg-stone-100 border-stone-300 text-stone-500"}`,children:x},x))})]}),i.jsxs("div",{className:"border-t border-stone-200 pt-3 mb-3",children:[i.jsx("div",{className:"text-xs text-stone-500 mb-2",children:"Recipe (auto-deduct stock per plate sold)"}),(m.recipe||[]).map((x,b)=>i.jsxs("div",{className:"flex gap-2 items-center mb-2",children:[i.jsxs("select",{value:x.invId,onChange:E=>c(b,"invId",E.target.value),className:"flex-1 bg-stone-100 border border-stone-300 rounded-lg px-2 py-2 text-sm outline-none",children:[i.jsx("option",{value:"",children:"Select raw material…"}),o.map(E=>i.jsxs("option",{value:E.id,children:[E.name," (",E.unit,")"]},E.id))]}),i.jsx("input",{value:x.qty,onChange:E=>c(b,"qty",E.target.value),type:"number",placeholder:"qty",className:"w-14 bg-stone-100 border border-stone-300 rounded-lg px-2 py-2 text-sm outline-none"}),i.jsxs("select",{value:x.unit||"",onChange:E=>c(b,"unit",E.target.value),className:"w-16 bg-stone-100 border border-stone-300 rounded-lg px-1 py-2 text-sm outline-none",children:[i.jsx("option",{value:"",children:"unit"}),["g","kg","ml","l","pcs"].map(E=>i.jsx("option",{value:E,children:E},E))]}),i.jsx("button",{onClick:()=>f(b),className:"p-1.5 text-stone-400",children:i.jsx(pr,{size:14})})]},b)),i.jsxs("button",{onClick:p,className:"text-xs text-rose-800 flex items-center gap-1",children:[i.jsx(st,{size:12})," Add ingredient"]}),o.length===0&&i.jsx("div",{className:"text-[11px] text-stone-400 mt-1",children:"Pehle Inventory me raw material add karo."})]}),i.jsx("button",{onClick:N,className:"w-full bg-rose-800 text-white font-semibold rounded-xl py-3",children:"Save Dish"})]})]})}function nx({inv:e,setInv:t,notify:n,setTab:r,wastage:s,setWastage:l,requireAdmin:o,logAudit:u}){const[a,d]=C.useState(!1),[g,m]=C.useState(null),[y,v]=C.useState("stock"),[h,N]=C.useState({name:"",unit:"kg",stock:"",lowAt:"",expiry:""}),[P,p]=C.useState({qty:"",reason:"Spoiled",photo:null}),c=()=>{h.name&&(t(w=>[{id:K(),name:h.name,unit:h.unit,stock:Number(h.stock)||0,lowAt:Number(h.lowAt)||0,expiry:h.expiry||null},...w]),d(!1),N({name:"",unit:"kg",stock:"",lowAt:"",expiry:""}),n("Item added"),xt("ok"))},f=(w,A)=>t(k=>k.map(T=>T.id===w?{...T,stock:Math.max(0,+(T.stock+A).toFixed(2))}:T)),x=w=>t(A=>A.filter(k=>k.id!==w)),b=w=>{p({qty:"",reason:"Spoiled",photo:null}),m(w)},E=async()=>{const w=await La();w&&p(A=>({...A,photo:w}))},z=()=>{if(!o())return;const w=Number(P.qty);if(!w){n("Quantity daalo");return}const A={id:K(),ts:ce(),itemId:g.id,name:g.name,unit:g.unit,qty:w,reason:P.reason,photo:P.photo||null};l(k=>[A,...k]),t(k=>k.map(T=>T.id===g.id?{...T,stock:Math.max(0,+(T.stock-w).toFixed(2))}:T)),u&&u("WASTAGE",`${g.name} ${w}${g.unit} · ${P.reason}${P.photo?" · 📎":""}`),m(null),n("Wastage logged · stock updated"),xt("ok")},L=e.filter(w=>w.stock<=w.lowAt),U=w=>Math.ceil((new Date(w)-new Date)/864e5),j=e.filter(w=>w.expiry&&U(w.expiry)<=3);return i.jsxs("div",{className:"p-4 space-y-3",children:[i.jsx(Kt,{setTab:r,title:"Inventory / Store"}),i.jsx("div",{className:"flex gap-2",children:[["stock","Stock"],["waste",`Wastage (${s.length})`]].map(([w,A])=>i.jsx("button",{onClick:()=>v(w),className:`text-sm px-3 py-1.5 rounded-full ${y===w?"bg-stone-100 text-rose-800":"text-stone-500"}`,children:A},w))}),y==="stock"&&i.jsxs(i.Fragment,{children:[L.length>0&&i.jsxs("div",{className:"bg-red-600/10 border border-red-600/30 rounded-xl p-3 text-sm text-red-600",children:["⚠ Low: ",L.map(w=>w.name).join(", "),". Reorder karo."]}),j.length>0&&i.jsxs("div",{className:"bg-rose-800/10 border border-rose-800/30 rounded-xl p-3 text-sm text-rose-700",children:["⏳ Expiring ≤3 days: ",j.map(w=>`${w.name} (${U(w.expiry)}d)`).join(", ")]}),i.jsxs("button",{onClick:()=>d(!0),className:"w-full bg-rose-800 text-white font-semibold rounded-xl py-3 flex items-center justify-center gap-2",children:[i.jsx(st,{size:16})," Add Stock Item"]}),i.jsx("div",{className:"space-y-2",children:e.map(w=>{const A=w.expiry?U(w.expiry):null,k=A!==null&&A<0;return i.jsxs(oe,{className:`p-3 ${w.stock<=w.lowAt||k?"border-red-600/30":""}`,children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("div",{className:"font-medium",children:w.name}),i.jsxs("div",{className:"text-[11px] text-stone-500",children:["low at ",w.lowAt," ",w.unit,w.expiry?` · exp ${new Date(w.expiry).toLocaleDateString("en-IN")}`:"",k?" · EXPIRED":A!==null&&A<=3?` · ${A}d left`:""]})]}),i.jsx("button",{onClick:()=>f(w.id,-1),className:"w-8 h-8 rounded-full bg-stone-100 text-red-600 flex items-center justify-center",children:i.jsx(rs,{size:14})}),i.jsxs("div",{className:"w-14 text-center",children:[i.jsx("span",{className:`font-mono font-bold ${w.stock<=w.lowAt?"text-red-600":"text-stone-800"}`,children:w.stock}),i.jsxs("span",{className:"text-xs text-stone-500",children:[" ",w.unit]})]}),i.jsx("button",{onClick:()=>f(w.id,1),className:"w-8 h-8 rounded-full bg-stone-100 text-emerald-700 flex items-center justify-center",children:i.jsx(st,{size:14})})]}),i.jsxs("div",{className:"flex gap-2 mt-2.5",children:[i.jsx("button",{onClick:()=>b(w),className:"flex-1 text-[11px] bg-red-600/10 border border-red-600/30 rounded-lg py-1.5 text-red-600",children:"Log Wastage"}),i.jsx("button",{onClick:()=>x(w.id),className:"p-1.5 text-stone-400",children:i.jsx(Hi,{size:14})})]})]},w.id)})})]}),y==="waste"&&i.jsxs("div",{className:"space-y-2",children:[s.length===0&&i.jsx("div",{className:"text-stone-400 text-sm text-center py-6",children:"Koi wastage log nahi. Har dump/waste yahan timestamp + photo ke saath dikhega."}),s.map(w=>i.jsxs(oe,{className:"p-3 flex items-center gap-3",children:[w.photo?i.jsx("img",{src:w.photo,className:"w-11 h-11 rounded-lg object-cover border border-stone-300"}):i.jsx("span",{className:"w-11 h-11 rounded-lg bg-stone-100 flex items-center justify-center text-[9px] text-stone-500",children:"no pic"}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("div",{className:"text-sm font-medium",children:w.name}),i.jsxs("div",{className:"text-[11px] text-stone-500",children:[w.qty," ",w.unit," · ",w.reason," · ",Bt(w.ts)]})]})]},w.id))]}),i.jsxs(pt,{open:a,onClose:()=>d(!1),title:"Add Stock Item",children:[i.jsx(G,{label:"Item name",value:h.name,onChange:w=>N(A=>({...A,name:w.target.value}))}),i.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[i.jsx(G,{label:"Stock",type:"number",value:h.stock,onChange:w=>N(A=>({...A,stock:w.target.value}))}),i.jsx(G,{label:"Unit",value:h.unit,onChange:w=>N(A=>({...A,unit:w.target.value}))}),i.jsx(G,{label:"Low at",type:"number",value:h.lowAt,onChange:w=>N(A=>({...A,lowAt:w.target.value}))})]}),i.jsx(G,{label:"Expiry date (optional)",type:"date",value:h.expiry,onChange:w=>N(A=>({...A,expiry:w.target.value}))}),i.jsx("button",{onClick:c,className:"w-full bg-rose-800 text-white font-semibold rounded-xl py-3 mt-2",children:"Add"})]}),i.jsx(pt,{open:!!g,onClose:()=>m(null),title:g?`Log Wastage — ${g.name}`:"",children:g&&i.jsxs(i.Fragment,{children:[i.jsx(G,{label:`Quantity (${g.unit}) — current stock ${g.stock}`,type:"number",value:P.qty,onChange:w=>p(A=>({...A,qty:w.target.value})),placeholder:"0"}),i.jsxs("label",{className:"block mb-3",children:[i.jsx("span",{className:"text-xs text-stone-500",children:"Reason"}),i.jsx("select",{value:P.reason,onChange:w=>p(A=>({...A,reason:w.target.value})),className:"mt-1 w-full bg-stone-100 border border-stone-300 rounded-xl px-3 py-2.5 text-stone-800 outline-none",children:["Expired","Spoiled","Spillage","Breakage","Over-prep","Staff meal","Other"].map(w=>i.jsx("option",{value:w,children:w},w))})]}),i.jsx("button",{onClick:E,className:"w-full mb-3 border border-dashed border-stone-300 rounded-xl py-3 flex items-center justify-center gap-2 text-sm text-stone-600",children:P.photo?i.jsxs(i.Fragment,{children:[i.jsx("img",{src:P.photo,className:"w-8 h-8 rounded object-cover"})," Photo attached — retake"]}):i.jsx(i.Fragment,{children:"📷 Attach photo (proof)"})}),i.jsx("div",{className:"text-[11px] text-stone-500 mb-3",children:"Admin PIN lagega. Stock auto-minus hoga, audit + wastage log me timestamp ke saath jayega."}),i.jsx("button",{onClick:z,className:"w-full bg-red-600 text-white font-semibold rounded-xl py-3",children:"Log & Deduct Stock"})]})})]})}function rx({staff:e,setStaff:t,cashLog:n,setCashLog:r,notify:s,setTab:l}){const[o,u]=C.useState(!1),[a,d]=C.useState({name:"",role:"Waiter",salary:""}),g=()=>{a.name&&(t(h=>[{id:K(),name:a.name,role:a.role,salary:Number(a.salary)||0,advance:0},...h]),u(!1),d({name:"",role:"Waiter",salary:""}),s("Staff added"),xt("ok"))},m=h=>{const N=Number(prompt(`Advance/payment to ${h.name} (₹):`,"1000"));N&&(t(P=>P.map(p=>p.id===h.id?{...p,advance:p.advance+N}:p)),r(P=>[{id:K(),ts:ce(),type:"out",amount:N,note:`Advance ${h.name}`},...P]),s("Advance recorded & cash out"))},y=h=>t(N=>N.map(P=>P.id===h.id?{...P,advance:0}:P)),v=h=>t(N=>N.filter(P=>P.id!==h));return i.jsxs("div",{className:"p-4 space-y-3",children:[i.jsx(Kt,{setTab:l,title:"Staff & Salary"}),i.jsxs("button",{onClick:()=>u(!0),className:"w-full bg-rose-800 text-white font-semibold rounded-xl py-3 flex items-center justify-center gap-2",children:[i.jsx(Qf,{size:16})," Add Staff"]}),i.jsx("div",{className:"space-y-2",children:e.map(h=>i.jsxs(oe,{className:"p-4",children:[i.jsxs("div",{className:"flex justify-between items-start",children:[i.jsxs("div",{children:[i.jsx("div",{className:"font-semibold",children:h.name}),i.jsxs("div",{className:"text-xs text-stone-500",children:[h.role," · Salary ",O(h.salary),"/mo"]})]}),i.jsx("button",{onClick:()=>v(h.id),className:"text-stone-400",children:i.jsx(Hi,{size:15})})]}),i.jsxs("div",{className:"flex items-center justify-between mt-3",children:[i.jsxs("div",{className:"text-sm",children:["Advance taken: ",i.jsx("span",{className:`font-mono font-bold ${h.advance?"text-red-600":"text-stone-500"}`,children:O(h.advance)})]}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx("button",{onClick:()=>m(h),className:"text-xs bg-stone-100 border border-stone-300 rounded-lg px-3 py-1.5",children:"Give Advance"}),h.advance>0&&i.jsx("button",{onClick:()=>y(h),className:"text-xs bg-emerald-600/10 border border-emerald-600/30 text-emerald-700 rounded-lg px-3 py-1.5",children:"Settle"})]})]})]},h.id))}),i.jsxs(pt,{open:o,onClose:()=>u(!1),title:"Add Staff",children:[i.jsx(G,{label:"Name",value:a.name,onChange:h=>d(N=>({...N,name:h.target.value}))}),i.jsx(G,{label:"Role",value:a.role,onChange:h=>d(N=>({...N,role:h.target.value}))}),i.jsx(G,{label:"Monthly Salary ₹",type:"number",value:a.salary,onChange:h=>d(N=>({...N,salary:h.target.value}))}),i.jsx("button",{onClick:g,className:"w-full bg-rose-800 text-white font-semibold rounded-xl py-3",children:"Add"})]})]})}function sx({customers:e,sales:t,setTab:n}){const[r,s]=C.useState(""),[l,o]=C.useState(null),u=864e5,a=C.useMemo(()=>e.map(v=>{const h=t.filter(x=>x.cust===v.phone).sort((x,b)=>x.ts-b.ts),N=h.map(x=>x.ts);let P=[];for(let x=1;xx+b,0)/P.length:0,c=ce()-v.last,f=v.orders>=2&&p>0&&c>Math.max(p*2,10*u);return{...v,visits:h,avgGap:p,sinceLast:c,missing:f,avgSpend:v.orders?v.spent/v.orders:0}}),[e,t]),d=a.filter(v=>v.missing).sort((v,h)=>h.spent-v.spent),g=[...a].sort((v,h)=>h.spent-v.spent).filter(v=>(v.name+v.phone).toLowerCase().includes(r.toLowerCase())),m=v=>`https://wa.me/91${v.phone}?text=${encodeURIComponent(`Namaste ${v.name||""}! 🙏 Aapko miss kar rahe hain. Wapas aaiye — aapke liye ek special treat ready hai! 🍽️`)}`,y=v=>`https://wa.me/91${v.phone}?text=${encodeURIComponent(`Namaste ${v.name||""}! Aaj ka special aa gaya hai 🍽️ Order karein.`)}`;return i.jsxs("div",{className:"p-4 space-y-3",children:[i.jsx(Kt,{setTab:n,title:"Customers"}),d.length>0&&i.jsxs("div",{className:"rounded-2xl p-4 bg-gradient-to-br from-red-600/10 to-rose-900/5 border border-red-600/30",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[i.jsx("span",{className:"text-lg",children:"💔"}),i.jsxs("span",{className:"font-semibold text-red-700",children:[d.length," regular",d.length>1?"s":""," slipping away"]})]}),i.jsx("div",{className:"text-[11px] text-stone-500 mb-3",children:'Ye pehle aate the, ab ruk gaye. Ek "miss you" bhejo, wapas aayenge.'}),i.jsx("div",{className:"space-y-2",children:d.slice(0,5).map(v=>i.jsxs("div",{className:"flex items-center gap-2 bg-stone-50 rounded-xl px-3 py-2",children:[i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("div",{className:"text-sm truncate",children:v.name||v.phone}),i.jsxs("div",{className:"text-[10px] text-stone-500",children:[Math.round(v.sinceLast/u)," din se nahi aaye · ",O(v.spent)," lifetime"]})]}),i.jsxs("a",{href:m(v),target:"_blank",rel:"noreferrer",className:"text-xs bg-gradient-to-br from-emerald-600 to-emerald-700 text-white font-semibold rounded-lg px-3 py-1.5 flex items-center gap-1",children:[i.jsx(ss,{size:13})," Miss you"]})]},v.phone))})]}),i.jsxs("div",{className:"relative",children:[i.jsx(Wf,{size:16,className:"absolute left-3 top-3 text-stone-500"}),i.jsx("input",{value:r,onChange:v=>s(v.target.value),placeholder:"Search name / phone",className:"w-full bg-white border border-stone-200 rounded-2xl pl-9 pr-3 py-2.5 text-sm outline-none focus:border-rose-800"})]}),g.length===0&&i.jsx(oe,{className:"p-6 text-center text-stone-500 text-sm",children:"No customers yet. Add phone at billing to build your CRM."}),g.map((v,h)=>i.jsx("button",{onClick:()=>o(v),className:"w-full text-left",children:i.jsxs(oe,{className:`p-3 flex items-center gap-3 ${v.missing?"border-red-600/30":""}`,children:[h<3&&!r?i.jsx(z0,{size:16,className:"text-rose-800 fill-rose-800 shrink-0"}):i.jsx("span",{className:"w-4 shrink-0"}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"font-medium truncate",children:[v.name||v.phone," ",v.missing&&i.jsx("span",{className:"text-[9px] bg-red-600/15 text-red-600 px-1.5 rounded-full",children:"slipping"})]}),i.jsxs("div",{className:"text-[11px] text-stone-500",children:[v.orders," orders · avg ",O(v.avgSpend)," · last ",new Date(v.last).toLocaleDateString("en-IN")]})]}),i.jsx(ix,{data:v.visits.slice(-8).map(N=>N.total)}),i.jsx("div",{className:"text-right ml-1",children:i.jsx("div",{className:"font-mono font-bold text-emerald-700",children:O(v.spent)})})]})},v.phone)),i.jsx(pt,{open:!!l,onClose:()=>o(null),title:l?l.name||l.phone:"",children:l&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"grid grid-cols-3 gap-2 mb-3 text-center",children:[i.jsxs("div",{className:"bg-stone-100 rounded-xl py-2",children:[i.jsx("div",{className:"text-[10px] text-stone-500",children:"Orders"}),i.jsx("div",{className:"font-mono font-bold",children:l.orders})]}),i.jsxs("div",{className:"bg-stone-100 rounded-xl py-2",children:[i.jsx("div",{className:"text-[10px] text-stone-500",children:"Lifetime"}),i.jsx("div",{className:"font-mono font-bold text-emerald-700",children:O(l.spent)})]}),i.jsxs("div",{className:"bg-stone-100 rounded-xl py-2",children:[i.jsx("div",{className:"text-[10px] text-stone-500",children:"Avg bill"}),i.jsx("div",{className:"font-mono font-bold",children:O(l.avgSpend)})]})]}),i.jsxs("div",{className:"text-xs text-stone-500 mb-1",children:["Spend trend (last ",Math.min(l.visits.length,10)," visits)"]}),i.jsx("div",{className:"flex items-end gap-1 h-16 mb-3",children:l.visits.slice(-10).map((v,h)=>{const N=Math.max(1,...l.visits.slice(-10).map(P=>P.total));return i.jsx("div",{className:"flex-1 bg-gradient-to-t from-rose-800 to-rose-700 rounded-t",style:{height:`${v.total/N*100}%`,minHeight:3}},h)})}),l.missing&&i.jsxs("div",{className:"bg-red-600/10 border border-red-600/30 rounded-xl p-2.5 text-xs text-red-700 mb-3",children:["⚠ ",Math.round(l.sinceLast/u)," din se nahi aaye. Normally har ~",Math.round(l.avgGap/u)," din me aate the."]}),i.jsx("div",{className:"text-xs text-stone-500 mb-1",children:"Recent orders"}),i.jsx("div",{className:"space-y-1 mb-4 max-h-40 overflow-y-auto",children:l.visits.slice().reverse().slice(0,8).map(v=>{var h,N;return i.jsxs("div",{className:"flex justify-between text-sm bg-stone-100 rounded-lg px-3 py-1.5",children:[i.jsxs("span",{className:"text-stone-500 text-xs",children:[(h=v.items)==null?void 0:h.map(P=>P.name).slice(0,2).join(", "),((N=v.items)==null?void 0:N.length)>2?"…":""]}),i.jsx("span",{className:"font-mono text-xs",children:O(v.total)})]},v.id)})}),i.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[i.jsxs("a",{href:l.missing?m(l):y(l),target:"_blank",rel:"noreferrer",className:"bg-gradient-to-br from-emerald-600 to-emerald-700 text-white font-semibold rounded-xl py-2.5 text-center text-sm flex items-center justify-center gap-1",children:[i.jsx(ss,{size:14})," ",l.missing?"Miss you msg":"Send offer"]}),i.jsx("a",{href:`tel:${l.phone}`,className:"bg-stone-100 border border-stone-300 rounded-xl py-2.5 text-center text-sm",children:"Call"})]})]})})]})}function ix({data:e=[]}){if(e.length<2)return i.jsx("span",{className:"w-12"});const t=Math.max(...e),n=Math.min(...e),r=t-n||1;return i.jsx("div",{className:"flex items-end gap-0.5 h-6 w-12 shrink-0",children:e.map((s,l)=>i.jsx("div",{className:"flex-1 bg-rose-800 rounded-sm",style:{height:`${20+(s-n)/r*80}%`}},l))})}function lx({menu:e,settings:t,online:n,setOnline:r,notify:s,setTab:l}){const[o,u]=C.useState(!1),[a,d]=C.useState({}),[g,m]=C.useState(""),[y,v]=C.useState(""),h=Object.values(a),N=h.reduce((c,f)=>c+f.price*f.qty,0),P=()=>{if(!h.length||!y){s("Add items & phone");return}const c={id:K(),ts:ce(),status:"new",cust:{name:g,phone:y},items:h.map(f=>({id:f.id,name:f.name,price:f.price,qty:f.qty}))};r(f=>[c,...f]),d({}),m(""),v(""),u(!1),s("Order placed! Owner ko dikhega ✓")},p=()=>{const c=encodeURIComponent(`🍽️ *${t.name}* ka menu Order karne ke liye humein WhatsApp karein ya yeh menu dekhein: ${e.slice(0,8).map(f=>`• ${f.name} — ${O(f.price)}`).join(` `)} Reply karein apna order 📲`);window.open(`https://wa.me/?text=${c}`,"_blank")};return i.jsxs("div",{className:"p-4 space-y-4",children:[i.jsx(Kt,{setTab:l,title:"Share Order Link"}),i.jsxs(oe,{className:"p-4 space-y-3",children:[i.jsxs("div",{className:"text-sm text-stone-600",children:["Customers ko menu bhejo WhatsApp pe. Woh order reply karein → yahan ",i.jsx("b",{children:"Orders"})," tab me KOT ban jayega."]}),i.jsxs("button",{onClick:p,className:"w-full bg-emerald-600 text-white font-semibold rounded-xl py-3 flex items-center justify-center gap-2",children:[i.jsx(Aa,{size:16})," Share Menu on WhatsApp"]}),i.jsxs("button",{onClick:()=>u(!0),className:"w-full bg-stone-100 border border-stone-300 rounded-xl py-3 flex items-center justify-center gap-2 text-stone-600",children:[i.jsx(ss,{size:16})," Open Customer Order Screen (demo)"]})]}),i.jsxs("div",{className:"text-xs text-stone-500 leading-relaxed",children:[i.jsx("b",{className:"text-stone-500",children:"Note:"})," Yeh in-app demo customer-order flow hai — jaisa hi customer link kholega, waisa dikhta hai, aur order seedha Orders tab me girta hai. Ek asli public link jo koi bhi bina Claude ke khol sake — uske liye ise apne server (Hostinger/Render) pe deploy karna hoga. Wahi backend hook main neeche note me de raha hoon."]}),o&&i.jsxs("div",{className:"fixed inset-0 z-50 bg-stone-100 overflow-y-auto",children:[i.jsxs("div",{className:"sticky top-0 bg-rose-800 text-white px-4 py-3 flex items-center justify-between",children:[i.jsx("div",{className:"font-bold",children:t.name}),i.jsx("button",{onClick:()=>u(!1),children:i.jsx(pr,{size:20})})]}),i.jsxs("div",{className:"p-4 space-y-2 pb-40",children:[i.jsx("div",{className:"text-sm text-stone-500 mb-2",children:"Apna order chunein 👇"}),e.map(c=>{var f;return i.jsxs("div",{className:"flex items-center gap-3 bg-white border border-stone-200 rounded-xl p-3",children:[i.jsx("span",{className:`w-2.5 h-2.5 rounded-full ${c.veg?"bg-emerald-600":"bg-red-600"}`}),i.jsxs("div",{className:"flex-1",children:[i.jsx("div",{className:"text-sm font-medium",children:c.name}),i.jsx("div",{className:"text-rose-800 font-mono text-sm",children:O(c.price)})]}),(f=a[c.id])!=null&&f.qty?i.jsxs("div",{className:"flex items-center gap-2 bg-stone-100 rounded-full border border-stone-300 px-1",children:[i.jsx("button",{onClick:()=>d(x=>{const b=x[c.id].qty-1,E={...x};return b<=0?delete E[c.id]:E[c.id]={...E[c.id],qty:b},E}),className:"p-1.5 text-rose-800",children:i.jsx(rs,{size:14})}),i.jsx("span",{className:"w-5 text-center font-mono text-sm",children:a[c.id].qty}),i.jsx("button",{onClick:()=>d(x=>({...x,[c.id]:{...c,qty:x[c.id].qty+1}})),className:"p-1.5 text-rose-800",children:i.jsx(st,{size:14})})]}):i.jsx("button",{onClick:()=>d(x=>({...x,[c.id]:{...c,qty:1}})),className:"bg-rose-800 text-white text-sm font-semibold rounded-lg px-3 py-1.5",children:"Add"})]},c.id)})]}),h.length>0&&i.jsxs("div",{className:"fixed bottom-0 inset-x-0 bg-white border-t border-stone-200 p-4 space-y-2",children:[i.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[i.jsx("input",{value:g,onChange:c=>m(c.target.value),placeholder:"Your name",className:"bg-stone-100 border border-stone-300 rounded-lg px-3 py-2 text-sm outline-none"}),i.jsx("input",{value:y,onChange:c=>v(c.target.value),placeholder:"Phone*",className:"bg-stone-100 border border-stone-300 rounded-lg px-3 py-2 text-sm outline-none"})]}),i.jsxs("button",{onClick:P,className:"w-full bg-emerald-600 text-white font-bold rounded-xl py-3 flex items-center justify-between px-4",children:[i.jsx("span",{children:"Place Order"}),i.jsxs("span",{className:"font-mono",children:[O(N)," →"]})]})]})]})]})}function ox({sales:e,expenses:t,cashLog:n,wastage:r,audit:s,cashInDrawer:l,todayCollection:o,todayExp:u,closings:a,setClosings:d,notify:g,setTab:m,requireAdmin:y,logAudit:v,settings:h,allData:N,restore:P}){const[p,c]=C.useState("close"),f=_=>{y()&&(za(h,_,g,!0),v&&v("REPRINT",`Bill #${_.invNo} · ${O(_.total)} duplicate`))},x=e.filter(_=>Mt(_.ts)),b={Cash:0,UPI:0,Card:0};x.forEach(_=>{b[_.mode]=(b[_.mode]||0)+_.total});const E=x.reduce((_,V)=>_+(V.disc||0),0),z=x.reduce((_,V)=>_+(V.tip||0),0),L=s.filter(_=>_.type==="VOID"&&Mt(_.ts)).length,U=r.filter(_=>Mt(_.ts)).length,j=t.filter(_=>Mt(_.ts)&&_.paid==="Cash").reduce((_,V)=>_+V.amount,0),w=t.filter(_=>Mt(_.ts)&&!_.photo).length,A=()=>{if(!y())return;const _=Number(prompt(`Drawer me expected cash: ${O(l)} Actual gina hua cash daalo (₹):`,String(Math.round(l))));if(!_&&_!==0)return;const V={id:K(),ts:ce(),orders:x.length,collection:o,modeSplit:{...b},discTotal:E,voids:L,expToday:u,expected:l,counted:_,variance:+(_-l).toFixed(2)};d($=>[V,...$]);const Z=window.open("","_blank","width=320,height=700");Z&&(Z.document.write(`Z-Report

Z-REPORT · DAY CLOSE

${Bt(ce())}

Orders${x.length}
Gross Sale${O(o)}
  Cash${O(b.Cash)}
  UPI${O(b.UPI)}
  Card${O(b.Card)}
Discounts${O(E)}
Voids${L}
Wastage logs${U}
Expenses (cash)${O(j)}

Expected drawer${O(l)}
Counted${O(_)}
Variance${O(_-l)}

Signed: ________________
`),Z.document.close(),Z.print()),g(`Day closed · variance ${O(_-l)}`)},k=()=>{y()&&(D0(N,`pos-backup-${new Date().toISOString().slice(0,10)}.json`),g("Backup downloaded"))},T=()=>{if(!y())return;const _=document.createElement("input");_.type="file",_.accept="application/json",_.onchange=()=>{var $;const V=($=_.files)==null?void 0:$[0];if(!V)return;const Z=new FileReader;Z.onload=()=>{try{P(JSON.parse(Z.result)),g("Data restored")}catch{g("Bad file")}},Z.readAsText(V)},_.click()};return i.jsxs("div",{className:"p-4 space-y-3",children:[i.jsx(Kt,{setTab:m,title:"Reports & Day Close"}),i.jsx("div",{className:"flex gap-2 overflow-x-auto no-scrollbar",children:[["close","Day Close"],["insights","Insights"],["bills",`Bills (${e.length})`],["audit",`Audit (${s.length})`],["backup","Backup"]].map(([_,V])=>i.jsx("button",{onClick:()=>c(_),className:`whitespace-nowrap text-sm px-3 py-1.5 rounded-full ${p===_?"bg-stone-100 text-rose-800":"text-stone-500"}`,children:V},_))}),p==="close"&&i.jsxs("div",{className:"space-y-3",children:[i.jsxs(oe,{className:"p-4 space-y-1.5 text-sm",children:[i.jsx("div",{className:"text-xs text-stone-500 uppercase tracking-wider mb-1",children:"Today so far"}),i.jsx(Ke,{k:"Orders",v:x.length}),i.jsx(Ke,{k:"Gross sale",v:O(o),big:!0}),i.jsx(Ke,{k:"Cash / UPI / Card",v:`${O(b.Cash)} / ${O(b.UPI)} / ${O(b.Card)}`}),i.jsx(Ke,{k:"Discounts given",v:O(E)}),i.jsx(Ke,{k:"Tips collected",v:O(z)}),i.jsx(Ke,{k:"Voids / Wastage",v:`${L} / ${U}`}),i.jsx(Ke,{k:"Cash expenses",v:O(j)}),i.jsx(Ke,{k:"Expected in drawer",v:O(l)})]}),w>0&&i.jsxs("div",{className:"bg-rose-800/10 border border-rose-800/30 rounded-xl p-3 text-sm text-rose-700",children:["⚠ ",w," expense(s) today without a bill photo. Auditor red flag — attach bills."]}),i.jsx("button",{onClick:A,className:"w-full bg-emerald-600 text-white font-bold rounded-xl py-3.5",children:"Close Day & Print Z-Report"}),a.length>0&&i.jsxs("div",{className:"space-y-2 pt-2",children:[i.jsx("div",{className:"text-xs text-stone-500 uppercase tracking-wider",children:"Past closings"}),a.slice(0,10).map(_=>i.jsxs("div",{className:"flex justify-between text-sm bg-white border border-stone-200 rounded-xl px-3 py-2",children:[i.jsxs("span",{className:"text-stone-500",children:[Bt(_.ts)," · ",_.orders," ord"]}),i.jsxs("span",{className:"font-mono",children:[O(_.collection)," ",i.jsxs("span",{className:_.variance===0?"text-emerald-700":"text-red-600",children:["(",_.variance>=0?"+":"",O(_.variance),")"]})]})]},_.id))]})]}),p==="bills"&&i.jsxs("div",{className:"space-y-2",children:[i.jsx("div",{className:"text-[11px] text-stone-500",children:'Purana bill dobara chahiye? Reprint karo — "DUPLICATE" mark ke saath, aur audit log me chadhta hai.'}),e.length===0&&i.jsx("div",{className:"text-stone-400 text-sm text-center py-6",children:"No bills yet."}),e.slice(0,60).map(_=>i.jsxs("div",{className:"flex items-center justify-between bg-white border border-stone-200 rounded-xl px-3 py-2.5",children:[i.jsxs("div",{children:[i.jsxs("div",{className:"text-sm font-medium",children:["#",_.invNo||"-"," · ",O(_.total)]}),i.jsxs("div",{className:"text-[10px] text-stone-500",children:[_.type," · ",_.mode,_.table?` · ${_.table}`:""," · ",Bt(_.ts)]})]}),i.jsxs("button",{onClick:()=>f(_),className:"flex items-center gap-1 text-xs bg-stone-100 border border-stone-300 rounded-lg px-3 py-2 text-stone-600",children:[i.jsx(Pa,{size:13})," Reprint"]})]},_.id))]}),p==="insights"&&(()=>{const _=e.filter(ee=>Mt(ee.ts)),V=Array(24).fill(0);_.forEach(ee=>{V[new Date(ee.ts).getHours()]+=ee.total});const Z=8,D=V.slice(Z,24),I=Math.max(1,...D),H=(()=>{const ee={};return e.forEach(F=>F.items.forEach(X=>{ee[X.name]=(ee[X.name]||0)+X.qty})),Object.entries(ee).sort((F,X)=>X[1]-F[1]).slice(0,5)})(),W=_.filter(ee=>ee.type==="Dine-in").length,ae=_.filter(ee=>ee.type==="Takeaway").length,ve=_.filter(ee=>ee.type==="Online").length,Ve=_.reduce((ee,F)=>ee+(F.tip||0),0),be=_.filter(ee=>ee.comp).length,Se=_.length?o/_.length:0;return i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{className:"flex gap-3",children:[i.jsx(rn,{label:"Avg Bill",value:O(Se)}),i.jsx(rn,{label:"Tips today",value:O(Ve),accent:"text-emerald-700"})]}),i.jsxs(oe,{className:"p-4",children:[i.jsx("div",{className:"text-xs text-stone-500 uppercase tracking-wider mb-3",children:"Aaj ka rush (hourly)"}),i.jsx("div",{className:"flex items-end gap-1 h-24",children:D.map((ee,F)=>i.jsxs("div",{className:"flex-1 flex flex-col items-center justify-end",children:[i.jsx("div",{className:"w-full bg-rose-800 rounded-t",style:{height:`${ee/I*100}%`,minHeight:ee?3:0}}),F%3===0&&i.jsx("div",{className:"text-[8px] text-stone-400 mt-0.5",children:Z+F})]},F))})]}),i.jsxs(oe,{className:"p-4",children:[i.jsx("div",{className:"text-xs text-stone-500 uppercase tracking-wider mb-2",children:"Top items (all time)"}),H.length===0&&i.jsx("div",{className:"text-stone-400 text-sm",children:"No data."}),H.map(([ee,F],X)=>i.jsxs("div",{className:"flex items-center gap-2 py-1",children:[i.jsx("span",{className:"text-rose-800 font-mono text-sm w-4",children:X+1}),i.jsx("span",{className:"flex-1 text-sm",children:ee}),i.jsxs("span",{className:"font-mono text-sm text-stone-500",children:[F," sold"]})]},ee))]}),i.jsxs(oe,{className:"p-4",children:[i.jsx("div",{className:"text-xs text-stone-500 uppercase tracking-wider mb-2",children:"Today mix"}),i.jsx("div",{className:"grid grid-cols-3 gap-2 text-center",children:[["Dine-in",W],["Takeaway",ae],["Online",ve]].map(([ee,F])=>i.jsxs("div",{className:"bg-stone-100 rounded-xl py-2",children:[i.jsx("div",{className:"text-[10px] text-stone-500",children:ee}),i.jsx("div",{className:"font-mono font-bold",children:F})]},ee))}),be>0&&i.jsxs("div",{className:"text-[11px] text-rose-800 mt-2",children:["Comps today: ",be," (free bills — owner review)"]})]})]})})(),p==="audit"&&i.jsxs("div",{className:"space-y-1.5",children:[i.jsx("div",{className:"text-[11px] text-stone-500",children:"Append-only trail. Sale, void, discount, cash, expense, wastage — sab yahan timestamp + who ke saath. Delete nahi hota."}),s.length===0&&i.jsx("div",{className:"text-stone-400 text-sm text-center py-6",children:"No entries yet."}),s.slice(0,80).map(_=>i.jsxs("div",{className:"flex items-start gap-2 bg-white border border-stone-200 rounded-lg px-3 py-2 text-sm",children:[i.jsx("span",{className:`text-[9px] font-bold px-1.5 py-0.5 rounded mt-0.5 ${_.type==="VOID"||_.type==="WASTAGE"?"bg-red-600/15 text-red-600":_.type==="DISCOUNT"?"bg-rose-800/15 text-rose-700":_.type==="SALE"?"bg-emerald-600/15 text-emerald-700":"bg-stone-200 text-stone-600"}`,children:_.type}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("div",{className:"text-stone-600 leading-tight",children:_.detail}),i.jsxs("div",{className:"text-[10px] text-stone-400",children:[Bt(_.ts)," · ",_.by]})]})]},_.id))]}),p==="backup"&&i.jsxs("div",{className:"space-y-3",children:[i.jsxs(oe,{className:"p-4 text-sm text-stone-500",children:["Yeh app browser me data rakhta hai. Phone kho gaya / cache saaf → data gaya. Isliye ",i.jsx("b",{className:"text-stone-700",children:"roz backup"})," lo (JSON file). Restore se wapas load."]}),i.jsx("button",{onClick:k,className:"w-full bg-rose-800 text-white font-semibold rounded-xl py-3",children:"⬇ Download Backup (JSON)"}),i.jsx("button",{onClick:T,className:"w-full bg-stone-100 border border-stone-300 rounded-xl py-3 text-stone-600",children:"⬆ Restore from Backup"}),i.jsx("div",{className:"text-[11px] text-red-600/80",children:"Restore poora data replace kar dega. Sambhal ke."})]})]})}function ax({kds:e,setKds:t,notify:n}){const[r,s]=C.useState("All"),l={new:"cooking",cooking:"ready",ready:"served"},o={new:"Start cooking",cooking:"Mark ready",ready:"Served ✓"},u=h=>t(N=>N.map(P=>P.id===h?{...P,status:l[P.status]||"served"}:P)),a=h=>t(N=>N.filter(P=>P.id!==h)),d=e.filter(h=>h.status!=="served"),g=["All",...Array.from(new Set(e.flatMap(h=>h.items.map(N=>N.station)).filter(Boolean)))],m=r==="All"?d:d.filter(h=>h.cancel||h.items.some(N=>N.station===r)),y=h=>Math.floor((ce()-h)/6e4),v=()=>t(h=>h.filter(N=>N.status!=="served"));return i.jsxs("div",{className:"p-4 space-y-3",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("h2",{className:"text-lg font-bold flex items-center gap-2",children:[i.jsx(Vi,{size:20,className:"text-rose-800"})," Kitchen (KDS)"]}),i.jsxs("div",{className:"text-xs text-stone-500",children:[d.length," live"]})]}),g.length>2&&i.jsx("div",{className:"flex gap-2 overflow-x-auto no-scrollbar",children:g.map(h=>i.jsx("button",{onClick:()=>s(h),className:`whitespace-nowrap text-xs px-3 py-1.5 rounded-full border ${r===h?"bg-rose-800 text-white border-rose-800 font-semibold":"bg-white border-stone-200 text-stone-500"}`,children:h},h))}),m.length===0&&i.jsx(oe,{className:"p-8 text-center text-stone-500 text-sm",children:"Kitchen saaf hai 🍳 Naya KOT aate hi ticket + token yahan."}),i.jsx("div",{className:"grid grid-cols-1 gap-3",children:m.map(h=>{if(h.cancel)return i.jsxs(oe,{className:"p-4 border-red-600/40 bg-red-600/10",children:[i.jsxs("div",{className:"flex justify-between items-center",children:[i.jsxs("div",{className:"font-bold text-red-600 flex items-center gap-2",children:[i.jsx(ns,{size:16})," CANCEL · ",h.source]}),i.jsx("button",{onClick:()=>a(h.id),className:"text-xs bg-stone-100 rounded-lg px-3 py-1.5 text-stone-600",children:"Got it"})]}),i.jsxs("div",{className:"text-sm text-red-700 mt-1",children:[h.items.map(f=>`${f.qty}× ${f.name}`).join(", ")," — line se hatao"]})]},h.id);const N=y(h.ts),P=N>=15&&h.status!=="ready",p=h.status==="new"?"border-rose-800/30 bg-rose-800/5":h.status==="cooking"?"border-sky-600/30 bg-sky-600/5":"border-emerald-600/30 bg-emerald-600/5",c=r==="All"?h.items:h.items.filter(f=>f.station===r);return i.jsxs(oe,{className:`p-4 ${P?"border-red-600/40 bg-red-600/5":p}`,children:[i.jsxs("div",{className:"flex justify-between items-center mb-2",children:[i.jsxs("div",{className:"font-bold flex items-center gap-2",children:[i.jsxs("span",{className:"bg-stone-800 text-white rounded-lg px-2 py-0.5 font-mono text-sm",children:["#",h.token]}),h.source,i.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full uppercase ${h.status==="new"?"bg-rose-800/15 text-rose-700":h.status==="cooking"?"bg-sky-600/15 text-sky-600":"bg-emerald-600/15 text-emerald-700"}`,children:h.status})]}),i.jsxs("span",{className:`text-xs font-mono flex items-center gap-1 ${P?"text-red-600":"text-stone-500"}`,children:[i.jsx(bi,{size:11}),N,"m"]})]}),i.jsx("div",{className:"space-y-1 mb-3",children:c.map((f,x)=>{var b;return i.jsxs("div",{className:"text-sm",children:[i.jsxs("span",{className:"font-mono font-bold text-stone-800",children:[f.qty,"×"]})," ",f.name,f.station&&f.station!=="General"?i.jsxs("span",{className:"text-[10px] text-stone-500",children:[" · ",f.station]}):"",(b=f.tags)!=null&&b.length?i.jsxs("span",{className:"text-[10px] text-red-600",children:[" ⚠ ",f.tags.join("/")]}):"",f.note?i.jsxs("span",{className:"text-rose-800 text-xs",children:[" ↳ ",f.note]}):""]},x)})}),i.jsx("button",{onClick:()=>u(h.id),className:`w-full rounded-xl py-2.5 font-semibold text-sm ${h.status==="ready"?"bg-emerald-600 text-white":h.status==="cooking"?"bg-sky-600 text-white":"bg-rose-800 text-white"}`,children:o[h.status]})]},h.id)})}),e.some(h=>h.status==="served")&&i.jsx("button",{onClick:v,className:"w-full text-xs text-stone-500 py-2",children:"Clear served tickets"})]})}function ux({suppliers:e,setSuppliers:t,purchases:n,setPurchases:r,inv:s,setInv:l,expenses:o,setExpenses:u,notify:a,setTab:d,requireAdmin:g,logAudit:m}){var A;const[y,v]=C.useState("purchase"),[h,N]=C.useState(!1),[P,p]=C.useState({name:"",phone:""}),[c,f]=C.useState({supplierId:((A=e[0])==null?void 0:A.id)||"",lines:[{invId:"",qty:"",rate:""}],paid:"Cash",billNo:"",photo:null}),x=()=>{P.name&&(t(k=>[{id:K(),name:P.name,phone:P.phone},...k]),N(!1),p({name:"",phone:""}),a("Supplier added"))},b=(k,T,_)=>f(V=>({...V,lines:V.lines.map((Z,$)=>$===k?{...Z,[T]:_}:Z)})),E=()=>f(k=>({...k,lines:[...k.lines,{invId:"",qty:"",rate:""}]})),z=k=>f(T=>({...T,lines:T.lines.filter((_,V)=>V!==k)})),L=async()=>{const k=await La();k&&f(T=>({...T,photo:k}))},U=c.lines.reduce((k,T)=>k+(Number(T.qty)||0)*(Number(T.rate)||0),0),j=()=>{var $;if(!g())return;const k=c.lines.filter(D=>D.invId&&Number(D.qty)>0);if(!k.length){a("Item + qty daalo");return}const T=e.find(D=>D.id===c.supplierId),_=k.map(D=>{const I=s.find(H=>H.id===D.invId);return{invId:D.invId,name:(I==null?void 0:I.name)||"?",unit:(I==null?void 0:I.unit)||"",qty:Number(D.qty),rate:Number(D.rate)||0,amount:(Number(D.qty)||0)*(Number(D.rate)||0)}}),V=_.reduce((D,I)=>D+I.amount,0),Z={id:K(),ts:ce(),supplierId:c.supplierId,supplierName:(T==null?void 0:T.name)||"",lines:_,total:V,paid:c.paid,billNo:c.billNo,photo:c.photo||null};r(D=>[Z,...D]),l(D=>D.map(I=>{const H=_.find(W=>W.invId===I.id);return H?{...I,stock:+(I.stock+H.qty).toFixed(3)}:I})),c.paid!=="Credit"&&u(D=>[{id:K(),ts:ce(),category:"Purchase",amount:V,note:(T==null?void 0:T.name)||"Supplier",paid:c.paid,billNo:c.billNo,photo:c.photo||null},...D]),m&&m("PURCHASE",`${T==null?void 0:T.name} · ${O(V)} · ${c.paid}${c.paid==="Credit"?" (payable)":""}`),f({supplierId:(($=e[0])==null?void 0:$.id)||"",lines:[{invId:"",qty:"",rate:""}],paid:"Cash",billNo:"",photo:null}),v("history"),a("Purchase saved · stock updated"),xt("ok")},w=n.filter(k=>k.paid==="Credit").reduce((k,T)=>k+T.total,0);return i.jsxs("div",{className:"p-4 space-y-3",children:[i.jsx(Kt,{setTab:d,title:"Suppliers & Purchase"}),i.jsx("div",{className:"flex gap-2",children:[["purchase","New Purchase"],["history",`History (${n.length})`],["list","Suppliers"]].map(([k,T])=>i.jsx("button",{onClick:()=>v(k),className:`text-sm px-3 py-1.5 rounded-full ${y===k?"bg-stone-100 text-rose-800":"text-stone-500"}`,children:T},k))}),w>0&&i.jsxs("div",{className:"bg-rose-800/10 border border-rose-800/30 rounded-xl p-3 text-sm text-rose-700",children:["Udhaar (payable to suppliers): ",i.jsx("b",{children:O(w)})]}),y==="purchase"&&i.jsxs("div",{className:"space-y-3",children:[i.jsxs(oe,{className:"p-4 space-y-3",children:[i.jsxs("label",{className:"block",children:[i.jsx("span",{className:"text-xs text-stone-500",children:"Supplier"}),i.jsx("select",{value:c.supplierId,onChange:k=>f(T=>({...T,supplierId:k.target.value})),className:"mt-1 w-full bg-stone-100 border border-stone-300 rounded-xl px-3 py-2.5 text-stone-800 outline-none",children:e.map(k=>i.jsx("option",{value:k.id,children:k.name},k.id))})]}),c.lines.map((k,T)=>i.jsxs("div",{className:"flex gap-2 items-end",children:[i.jsxs("label",{className:"flex-1",children:[i.jsx("span",{className:"text-[10px] text-stone-500",children:"Item"}),i.jsxs("select",{value:k.invId,onChange:_=>b(T,"invId",_.target.value),className:"mt-0.5 w-full bg-stone-100 border border-stone-300 rounded-lg px-2 py-2 text-sm outline-none",children:[i.jsx("option",{value:"",children:"Select…"}),s.map(_=>i.jsx("option",{value:_.id,children:_.name},_.id))]})]}),i.jsx("input",{value:k.qty,onChange:_=>b(T,"qty",_.target.value),type:"number",placeholder:"qty",className:"w-14 bg-stone-100 border border-stone-300 rounded-lg px-2 py-2 text-sm outline-none"}),i.jsx("input",{value:k.rate,onChange:_=>b(T,"rate",_.target.value),type:"number",placeholder:"rate",className:"w-16 bg-stone-100 border border-stone-300 rounded-lg px-2 py-2 text-sm outline-none"}),c.lines.length>1&&i.jsx("button",{onClick:()=>z(T),className:"p-2 text-stone-400",children:i.jsx(pr,{size:14})})]},T)),i.jsxs("button",{onClick:E,className:"text-xs text-rose-800 flex items-center gap-1",children:[i.jsx(st,{size:12})," Add line"]})]}),i.jsxs("div",{className:"flex items-center justify-between px-1",children:[i.jsx("span",{className:"text-stone-500",children:"Total"}),i.jsx("span",{className:"font-mono font-bold text-lg text-emerald-700",children:O(U)})]}),i.jsx("div",{className:"grid grid-cols-3 gap-2",children:["Cash","UPI","Credit"].map(k=>i.jsx("button",{onClick:()=>f(T=>({...T,paid:k})),className:`py-2.5 rounded-xl border text-sm ${c.paid===k?"bg-rose-800 text-white border-rose-800 font-semibold":"bg-stone-100 border-stone-300 text-stone-500"}`,children:k},k))}),i.jsx(G,{label:"Supplier bill no (optional)",value:c.billNo,onChange:k=>f(T=>({...T,billNo:k.target.value}))}),i.jsx("button",{onClick:L,className:"w-full border border-dashed border-stone-300 rounded-xl py-3 flex items-center justify-center gap-2 text-sm text-stone-600",children:c.photo?i.jsxs(i.Fragment,{children:[i.jsx("img",{src:c.photo,className:"w-8 h-8 rounded object-cover"})," Bill attached"]}):i.jsx(i.Fragment,{children:"📷 Attach supplier bill"})}),i.jsx("button",{onClick:j,className:"w-full bg-emerald-600 text-white font-bold rounded-xl py-3",children:"Save Purchase & Add Stock"})]}),y==="history"&&i.jsxs("div",{className:"space-y-2",children:[n.length===0&&i.jsx("div",{className:"text-stone-400 text-sm text-center py-6",children:"No purchases yet."}),n.map(k=>i.jsxs(oe,{className:"p-3",children:[i.jsxs("div",{className:"flex justify-between items-start",children:[i.jsxs("div",{children:[i.jsx("div",{className:"font-medium",children:k.supplierName}),i.jsxs("div",{className:"text-[11px] text-stone-500",children:[Bt(k.ts)," · ",k.paid,k.billNo?` · #${k.billNo}`:""]})]}),i.jsxs("div",{className:"text-right",children:[i.jsx("div",{className:"font-mono font-bold text-red-600",children:O(k.total)}),k.photo&&i.jsx("span",{className:"text-[10px] text-emerald-700",children:"📎 bill"})]})]}),i.jsx("div",{className:"text-[11px] text-stone-500 mt-1",children:k.lines.map(T=>`${T.name} ${T.qty}${T.unit}`).join(", ")})]},k.id))]}),y==="list"&&i.jsxs("div",{className:"space-y-2",children:[i.jsxs("button",{onClick:()=>N(!0),className:"w-full bg-rose-800 text-white font-semibold rounded-xl py-3 flex items-center justify-center gap-2",children:[i.jsx(Qf,{size:16})," Add Supplier"]}),e.map(k=>i.jsxs(oe,{className:"p-3 flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("div",{className:"font-medium",children:k.name}),k.phone&&i.jsx("div",{className:"text-[11px] text-stone-500",children:k.phone})]}),k.phone&&i.jsx("a",{href:`tel:${k.phone}`,className:"text-emerald-700 text-sm",children:"Call"})]},k.id))]}),i.jsxs(pt,{open:h,onClose:()=>N(!1),title:"Add Supplier",children:[i.jsx(G,{label:"Supplier name",value:P.name,onChange:k=>p(T=>({...T,name:k.target.value}))}),i.jsx(G,{label:"Phone (optional)",value:P.phone,onChange:k=>p(T=>({...T,phone:k.target.value}))}),i.jsx("button",{onClick:x,className:"w-full bg-rose-800 text-white font-semibold rounded-xl py-3",children:"Add"})]})]})}function cx({reservations:e,setReservations:t,tables:n,notify:r,setTab:s}){const[l,o]=C.useState("book"),[u,a]=C.useState(!1),[d,g]=C.useState({kind:"booking",name:"",phone:"",pax:"",when:"",note:""}),m=c=>{g({kind:c,name:"",phone:"",pax:"",when:"",note:""}),a(!0)},y=()=>{d.name&&(t(c=>[{id:K(),ts:ce(),kind:d.kind,name:d.name,phone:d.phone,pax:Number(d.pax)||0,when:d.when,note:d.note,status:d.kind==="booking"?"booked":"waiting"},...c]),a(!1),r(d.kind==="booking"?"Booking added":"Added to waitlist"),xt("ok"))},v=(c,f)=>t(x=>x.map(b=>b.id===c?{...b,status:f}:b)),h=c=>t(f=>f.filter(x=>x.id!==c)),N=c=>{c.phone&&window.open(`https://wa.me/91${c.phone}?text=${encodeURIComponent(`Namaste ${c.name}, aapki table ready hai! Aa jaiye 🍽️`)}`,"_blank"),r("Table-ready msg")},P=e.filter(c=>c.kind==="booking"&&!["seated","cancelled","noshow"].includes(c.status)),p=e.filter(c=>c.kind==="waitlist"&&c.status==="waiting");return i.jsxs("div",{className:"p-4 space-y-3",children:[i.jsx(Kt,{setTab:s,title:"Reservations & Waitlist"}),i.jsx("div",{className:"flex gap-2",children:[["book",`Bookings (${P.length})`],["wait",`Waitlist (${p.length})`]].map(([c,f])=>i.jsx("button",{onClick:()=>o(c),className:`text-sm px-3 py-1.5 rounded-full ${l===c?"bg-stone-100 text-rose-800":"text-stone-500"}`,children:f},c))}),l==="book"&&i.jsxs(i.Fragment,{children:[i.jsxs("button",{onClick:()=>m("booking"),className:"w-full bg-rose-800 text-white font-semibold rounded-xl py-3 flex items-center justify-center gap-2",children:[i.jsx(st,{size:16})," New Booking"]}),P.length===0&&i.jsx("div",{className:"text-stone-400 text-sm text-center py-6",children:"Koi booking nahi."}),P.map(c=>i.jsxs(oe,{className:"p-3",children:[i.jsxs("div",{className:"flex justify-between",children:[i.jsxs("div",{children:[i.jsxs("div",{className:"font-medium",children:[c.name," · ",c.pax," pax"]}),i.jsxs("div",{className:"text-[11px] text-stone-500",children:[c.when||"time N/A"," · ",c.phone,c.note?` · ${c.note}`:""]})]}),i.jsx("div",{className:"font-mono text-xs text-rose-800",children:c.status})]}),i.jsxs("div",{className:"flex gap-2 mt-2.5",children:[i.jsx("button",{onClick:()=>{v(c.id,"seated"),r("Seated")},className:"flex-1 text-xs bg-emerald-600/10 border border-emerald-600/30 text-emerald-700 rounded-lg py-1.5",children:"Seat"}),i.jsx("button",{onClick:()=>v(c.id,"noshow"),className:"flex-1 text-xs bg-red-600/10 border border-red-600/30 text-red-600 rounded-lg py-1.5",children:"No-show"}),i.jsx("button",{onClick:()=>h(c.id),className:"px-3 text-stone-400",children:i.jsx(Hi,{size:14})})]})]},c.id))]}),l==="wait"&&i.jsxs(i.Fragment,{children:[i.jsxs("button",{onClick:()=>m("waitlist"),className:"w-full bg-rose-800 text-white font-semibold rounded-xl py-3 flex items-center justify-center gap-2",children:[i.jsx(st,{size:16})," Add Walk-in"]}),p.length===0&&i.jsx("div",{className:"text-stone-400 text-sm text-center py-6",children:"Waitlist khali."}),p.map((c,f)=>i.jsxs(oe,{className:"p-3 flex items-center gap-3",children:[i.jsx("span",{className:"w-7 h-7 rounded-full bg-stone-100 flex items-center justify-center font-mono text-sm",children:f+1}),i.jsxs("div",{className:"flex-1",children:[i.jsxs("div",{className:"font-medium",children:[c.name," · ",c.pax," pax"]}),i.jsxs("div",{className:"text-[11px] text-stone-500",children:["waiting ",Math.floor((ce()-c.ts)/6e4),"m · ",c.phone]})]}),i.jsx("button",{onClick:()=>N(c),className:"text-xs bg-emerald-600/10 border border-emerald-600/30 text-emerald-700 rounded-lg px-2.5 py-1.5",children:"Ready"}),i.jsx("button",{onClick:()=>{v(c.id,"seated"),r("Seated")},className:"text-xs bg-stone-100 border border-stone-300 rounded-lg px-2.5 py-1.5",children:"Seat"})]},c.id))]}),i.jsxs(pt,{open:u,onClose:()=>a(!1),title:d.kind==="booking"?"New Booking":"Add Walk-in",children:[i.jsx(G,{label:"Name",value:d.name,onChange:c=>g(f=>({...f,name:c.target.value}))}),i.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[i.jsx(G,{label:"Phone",value:d.phone,onChange:c=>g(f=>({...f,phone:c.target.value}))}),i.jsx(G,{label:"Pax",type:"number",value:d.pax,onChange:c=>g(f=>({...f,pax:c.target.value}))})]}),d.kind==="booking"&&i.jsx(G,{label:"When (e.g. Today 8:30 PM)",value:d.when,onChange:c=>g(f=>({...f,when:c.target.value}))}),i.jsx(G,{label:"Note (optional)",value:d.note,onChange:c=>g(f=>({...f,note:c.target.value}))}),i.jsx("button",{onClick:y,className:"w-full bg-rose-800 text-white font-semibold rounded-xl py-3",children:"Save"})]})]})}function dx({open:e,onClose:t,lang:n,restName:r}){const s=n!=="en",[l,o]=C.useState([]),[u,a]=C.useState(""),[d,g]=C.useState(!1),m=C.useRef(null);C.useEffect(()=>{var N;(N=m.current)==null||N.scrollIntoView({behavior:"smooth"})},[l,d]);const y=s?["Bill kaise banau?","Dine-in kaise chalega?","Discount kaise du?","Din end kaise karu?","Stock kaise add karu?"]:["How do I bill?","How does dine-in work?","How to give a discount?","How to close the day?","How to add stock?"],v=`You are the warm, patient in-app help assistant inside "NamakPOS" (restaurant name: ${r}), a very simple restaurant POS app. Teach a brand-new, non-technical staff member. Reply in ${s?"Hinglish (Roman script, friendly Indian tone)":"simple English"}, 2-5 short sentences, concrete steps. Only answer about using THIS app; if unrelated, gently steer back. Key flows: - New Order: big "+ New Order" button (bottom-right) → choose Dine-in or Takeaway. - Dine-in: pick a free table → tap dishes → "Send to Kitchen" (fires KOT) → "Settle" when guests leave (payment is at the end). - Takeaway/Counter: tap dishes → take payment (Cash/UPI/Card) → KOT prints automatically. - Discount / Void: owner-only, needs Admin PIN (lock icon top-right). - Hold & Fire: on a dine-in item tap "Hold" to send it to kitchen later (coursing). - Kitchen (KDS): More → Kitchen shows live tickets with tokens; tap to move cooking→ready. - Inventory: More → Inventory (stock, expiry, Log Wastage). Recipes in Menu auto-deduct stock on sale. - Reports: More → Reports → Day Close prints a Z-report and checks cash. Also Bills reprint, Insights, Backup. - Customers: phone captured at billing builds a CRM with repeat + win-back. Never invent features that don't exist. Keep it encouraging.`,h=async N=>{const P=(N??u).trim();if(!P||d)return;const p=[...l,{role:"user",content:P}];o(p),a(""),g(!0);try{const c=await Jf(p.map(f=>({role:f.role,content:f.content})),v,500);o(f=>[...f,{role:"assistant",content:c||(s?"Fir se poochho?":"Try again?")}])}catch{o(c=>[...c,{role:"assistant",content:s?"AI abhi offline hai. Jaldi se: neeche + New Order → Dine-in ya Takeaway → dish tap → paisa lo. Discount/void ke liye upar lock (Admin PIN). Din end: More → Reports → Day Close.":"AI is offline right now. Quick version: tap + New Order → Dine-in or Takeaway → tap dishes → take payment. Discount/void via the lock (Admin PIN). End of day: More → Reports → Day Close."}])}g(!1)};return e?i.jsxs("div",{className:"fixed inset-0 z-50 bg-stone-100 flex flex-col",children:[i.jsxs("div",{className:"px-4 py-3 border-b border-stone-200 flex items-center justify-between bg-gradient-to-r from-rose-800/10 to-transparent",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("div",{className:"w-8 h-8 rounded-xl bg-gradient-to-br from-rose-700 to-rose-900 flex items-center justify-center text-white",children:"✨"}),i.jsxs("div",{children:[i.jsx("div",{className:"font-bold leading-tight",children:s?"Madad (AI)":"Help (AI)"}),i.jsx("div",{className:"text-[10px] text-stone-500",children:s?"Kuch bhi poochho — kaise chalau?":"Ask me anything about the app"})]})]}),i.jsx("button",{onClick:t,className:"p-2 rounded-lg bg-stone-100 text-stone-500",children:i.jsx(pr,{size:18})})]}),i.jsxs("div",{className:"flex-1 overflow-y-auto p-4 space-y-3",children:[l.length===0&&i.jsx("div",{className:"text-center text-stone-500 text-sm mt-6 mb-3",children:s?"Namaste! Main aapki madad ke liye hoon. Neeche se ek sawaal chuno ya likho 👇":"Hi! I'm here to help. Pick a question below or type your own 👇"}),l.map((N,P)=>i.jsx("div",{className:`flex ${N.role==="user"?"justify-end":"justify-start"}`,children:i.jsx("div",{className:`max-w-[85%] px-3.5 py-2.5 rounded-2xl text-sm whitespace-pre-wrap ${N.role==="user"?"bg-gradient-to-br from-rose-700 to-rose-900 text-white rounded-br-md":"bg-white border border-stone-200 text-stone-700 rounded-bl-md"}`,children:N.content})},P)),d&&i.jsx("div",{className:"flex justify-start",children:i.jsx("div",{className:"bg-white border border-stone-200 rounded-2xl px-4 py-3 text-stone-500 text-sm",children:"•••"})}),i.jsx("div",{ref:m})]}),l.length===0&&i.jsx("div",{className:"px-4 pb-2 flex flex-wrap gap-2",children:y.map(N=>i.jsx("button",{onClick:()=>h(N),className:"text-xs bg-white border border-stone-200 rounded-full px-3 py-1.5 text-stone-600 active:scale-95",children:N},N))}),i.jsxs("div",{className:"p-3 border-t border-stone-200 flex gap-2",children:[i.jsx("input",{value:u,onChange:N=>a(N.target.value),onKeyDown:N=>N.key==="Enter"&&h(),placeholder:s?"Apna sawaal likho…":"Type your question…",className:"flex-1 bg-white border border-stone-200 rounded-full px-4 py-2.5 text-sm outline-none focus:border-rose-800"}),i.jsx("button",{onClick:()=>h(),disabled:d,className:"w-11 h-11 rounded-full bg-gradient-to-br from-rose-700 to-rose-900 text-white flex items-center justify-center disabled:opacity-50 shrink-0",children:"→"})]})]}):null}function fx({settings:e,setSettings:t,notify:n,setTab:r}){var o,u;const[s,l]=C.useState(e);return i.jsxs("div",{className:"p-4 space-y-3",children:[i.jsx(Kt,{setTab:r,title:"Settings"}),i.jsxs(oe,{className:"p-4",children:[i.jsxs("label",{className:"block mb-3",children:[i.jsx("span",{className:"text-xs text-stone-500",children:ne("lang")}),i.jsx("div",{className:"flex gap-2 mt-1.5",children:[["hi","Hinglish"],["en","English"]].map(([a,d])=>i.jsx("button",{onClick:()=>l(g=>({...g,lang:a})),className:`flex-1 py-2.5 rounded-xl border text-sm ${(s.lang||"hi")===a?"bg-rose-800 text-white border-rose-800 font-semibold":"bg-stone-100 border-stone-300 text-stone-500"}`,children:d},a))})]}),i.jsx(G,{label:"Restaurant Name",value:s.name,onChange:a=>l(d=>({...d,name:a.target.value}))}),i.jsx(G,{label:"GST %",type:"number",value:s.gst,onChange:a=>l(d=>({...d,gst:Number(a.target.value)}))}),i.jsx(G,{label:"UPI ID",value:s.upi,onChange:a=>l(d=>({...d,upi:a.target.value}))}),i.jsxs("div",{className:"mb-3 p-3 rounded-xl bg-stone-50 border border-stone-200",children:[i.jsx("div",{className:"text-xs text-stone-500",children:'Staff ko jodne ke liye — apna Restaurant Code aur Staff PIN do (woh app me "Staff" tab se login karein):'}),i.jsxs("div",{className:"text-sm mt-1",children:["Restaurant Code: ",i.jsx("b",{className:"font-mono text-rose-800",children:((u=(o=Df())==null?void 0:o.tenant)==null?void 0:u.code)||"—"})]})]}),i.jsx(G,{label:"Admin PIN (for discount / void)",value:s.adminPin||"",onChange:a=>l(d=>({...d,adminPin:a.target.value})),placeholder:"1234"}),i.jsx(G,{label:"Staff PIN (for staff login)",value:s.staffPin||"",onChange:a=>l(d=>({...d,staffPin:a.target.value})),placeholder:"0000"}),i.jsx(G,{label:"GSTIN (prints on bill)",value:s.gstin||"",onChange:a=>l(d=>({...d,gstin:a.target.value})),placeholder:"09XXXXX...Z1"}),i.jsx(G,{label:"FSSAI License No",value:s.fssai||"",onChange:a=>l(d=>({...d,fssai:a.target.value})),placeholder:"12345678901234"}),i.jsxs("label",{className:"flex items-center justify-between py-2 mb-2",children:[i.jsxs("span",{className:"text-sm text-stone-600",children:["Easy Mode ",i.jsx("span",{className:"text-[11px] text-stone-500",children:"(chhupao advanced — bachcha bhi chalaye)"})]}),i.jsx("button",{onClick:()=>l(a=>({...a,easy:!a.easy})),className:`w-12 h-7 rounded-full transition relative ${s.easy?"bg-emerald-600":"bg-stone-200"}`,children:i.jsx("span",{className:`absolute top-1 w-5 h-5 rounded-full bg-white transition-all ${s.easy?"left-6":"left-1"}`})})]}),i.jsx("button",{onClick:()=>{t(s),n("Settings saved")},className:"w-full bg-rose-800 text-white font-semibold rounded-xl py-3",children:"Save"})]}),i.jsx("div",{className:"text-xs text-stone-400 text-center",children:"Data browser me save hota hai (auto). Naya device = fresh start jab tak deploy na ho."})]})}const Kt=({setTab:e,title:t})=>i.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[i.jsx("button",{onClick:()=>e("more"),className:"p-1.5 rounded-lg hover:bg-stone-100 text-stone-500",children:"‹"}),i.jsx("h2",{className:"text-lg font-bold",children:t})]});jf(document.getElementById("root")).render(i.jsx(C0,{children:i.jsx(W0,{})}));