1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/exceljs.min-DP_NmrKk.js","assets/vendor-react-BElMhwq3.js","assets/vendor-excel-BjsAGXdV.js"])))=>i.map(i=>d[i]); 2var oo=Object.defineProperty;var co=(t,s,n)=>s in t?oo(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var Jt=(t,s,n)=>co(t,typeof s!="symbol"?s+"":s,n);import{u as qt,j as e,l as wr,r as Re,n as hi,s as At,k as uo,B as bi,o as xo,p as mo,h as po,e as ds,a as Je,b as st,g as yt,d as Qt,m as ll,f as Ln,q as fo,t as ho,v as bo,x as go,y as _o,P as yo,z as il,C as ol,D as jo,i as en,E as Ts,F as vo,V as No}from"./index-D7N7AVCq.js";import{r as a,a as wo,g as Jn,d as gi,R as ct}from"./vendor-react-BElMhwq3.js";import{X as bt,aC as _i,N as Kt,aD as cl,P as js,av as Sa,f as un,Y as zr,e as Xs,l as an,g as Ea,ai as gs,t as So,au as Qn,aE as $a,i as Lt,W as Ds,v as _s,x as Eo,q as dl,r as Sr,s as Mn,aF as Co,a as Fs,C as as,aG as Ca,L as ln,E as Fa,b as Xn,c as rt,am as Ba,aH as zn,a8 as xn,$ as ko,O as Yr,T as hs,Z as ss,R as vr,D as rs,I as On,a9 as Us,a3 as mn,K as Gr,a4 as Ss,a5 as Zn,af as qr,u as er,aI as ka,ap as $s,Q as dr,a7 as Un,a6 as is,a1 as $n,an as yi,aJ as Ya,ad as tn,k as Ro,V as To,ac as Ga,w as on,ag as ji,ah as vi,aj as Do,ak as Ni,ab as wi,S as Oo,ar as Si,aK as Io,aL as Po,aM as Fn,al as jn,aN as ul,aO as Ao,aP as Lo,aw as Mo,aQ as zo,aR as aa,aA as Uo,aS as $o,M as Ur,aT as $r,aB as xl,_ as Bn,aU as Fo,aV as Bo,as as vn,aW as Yo,J as Go,aX as qo,aY as Wo,aZ as Ei,a_ as Ho,a$ as Vo,U as Ra,b0 as Ci,b1 as Ko,b2 as Jo}from"./vendor-lucide-8_LGzjd8.js";import{d as tr,R as or,j as Qo,k as Xo,C as ml,O as Zo,H as Fr,f as ec,x as Ta,m as tc,g as pl,c as Nn,t as ki,h as Er,n as Ar,I as cn,o as Da,J as sc,q as qa,K as rc,i as nc,s as ac,u as lc,L as ic,G as In,p as Pr,y as oc,B as Ri,M as fl,N as cc,D as Lr,E as wn,P as hl,v as la,r as dc}from"./tariffsCache-DD_cwXlg.js";import{_ as uc}from"./vendor-supabase-BSWir601.js";import{i as Ti,c as ia,g as xc,s as mc}from"./reviewBonus-CSpBqJS-.js";import{E as pc}from"./EmojiPickerButton-CeX2ZKwW.js";import{u as fc,f as hc}from"./useKeyboardViewport-By_FG-an.js";const bc=({isOpen:t,onClose:s,onStart:n})=>{const{t:r}=qt();return t?e.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-slate-900/60 backdrop-blur-sm p-4",children:e.jsxs("div",{className:"bg-white rounded-2xl w-full max-w-md
2shadow-2xl p-6 relative",children:[e.jsx("button",{onClick:s,className:"absolute top-4 right-4 p-2 text-slate-400 hover:bg-slate-50 rounded-full",children:e.jsx(bt,{size:20})}),e.jsx("div",{className:"w-14 h-14 bg-blue-50 text-blue-600 rounded-2xl flex items-center justify-center mb-4",children:e.jsx(_i,{size:28})}),e.jsx("h2",{className:"text-xl font-bold text-slate-900 mb-2",children:r("onboarding_welcome_title")}),e.jsx("p",{className:"text-sm text-slate-500 leading-relaxed mb-6",children:r("onboarding_welcome_body")}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("button",{onClick:n,className:"w-full py-3 bg-blue-600 text-white rounded-xl font-bold text-sm hover:bg-blue-700 transition-all",children:r("onboarding_welcome_start")}),e.jsx("button",{onClick:s,className:"w-full py-3 bg-slate-50 text-slate-500 rounded-xl font-bold text-sm hover:bg-slate-100 transition-all",children:r("onboarding_welcome_later")})]})]})}):null};function Di(t){return s=>typeof s===t}var gc=Di("function"),_c=t=>t===null,bl=t=>Object.prototype.toString.call(t).slice(8,-1)==="RegExp",gl=t=>!yc(t)&&!_c(t)&&(gc(t)||typeof t=="object"),yc=Di("undefined");function jc(t,s,n){return kc(n,t,s)?!0:(Rc(n,t,s),t.constructor!==s.constructor?!1:Array.isArray(t)&&Array.isArray(s)?vc(t,s,n):t instanceof Map&&s instanceof Map?Sc(t,s,n):t instanceof Set&&s instanceof Set?Cc(t,s):t instanceof WeakMap||t instanceof WeakSet?!1:ArrayBuffer.isView(t)&&ArrayBuffer.isView(s)?Nc(t,s):bl(t)&&bl(s)?t.source===s.source&&t.flags===s.flags:t instanceof Error&&s instanceof Error?wc(t,s,n):t.valueOf!==Object.prototype.valueOf?t.valueOf()===s.valueOf():t.toString!==Object.prototype.toString?t.toString()===s.toString():Ec(t,s,n))}function hn(t,s,n){return t===s||Number.isNaN(t)&&Number.isNaN(s)?!0:!t||!gl(t)||!s||!gl(s)?!1:jc(t,s,n)}function vc(t,s,n){const{length:r}=t;if(r!==s.length)return!1;for(let l=r;l--!==0;)if(!hn(t[l],s[l],n))return!1;return!0}function Nc(t,s){if(t.byteLength!==s.byteLength)return!1;const n=new DataView(t.buffer),r=new DataView(s.buffer);let l=t.byteLength;for(;l--;)if(n.getUint8(l)!==r.getUint8(l))return!1;return!0}function wc(t,s,n){return t.message===s.message&&t.name===s.name&&hn(t.cause,s.cause,n)}function Sc(t,s,n){if(t.size!==s.size)return!1;for(const r of t.entries())if(!s.has(r[0]))return!1;for(const r of t.entries())if(!hn(r[1],s.get(r[0]),n))return!1;return!0}function Ec(t,s,n){const r=Object.keys(t);if(r.length!==Object.keys(s).length)return!1;for(let l=r.length;l--!==0;)if(!Object.prototype.hasOwnProperty.call(s,r[l]))return!1;for(let l=r.length;l--!==0;){const c=r[l];if(!(c==="_owner"&&t.$$typeof)&&!hn(t[c],s[c],n))return!1}return!0}function Cc(t,s){if(t.size!==s.size)return!1;for(const n of t.entries())if(!s.has(n[0]))return!1;return!0}function kc(t,s,n){return t.get(s)?.has(n)??!1}function Rc(t,s,n){let r=t.get(s);r||(r=new WeakSet,t.set(s,r)),r.add(n)}function Wa(t,s){return hn(t,s,new WeakMap)}function oa(){return!!(typeof window<"u"&&window?.document?.createElement)}function Tc(t,...s){t&&t.removeEventListener&&t.removeEventListener(...s)}function Dc(t,...s){t&&t.addEventListener&&t.addEventListener(...s)}function Oc(){const t=a.useRef(!0);return t.current?(t.current=!1,!0):t.current}function Ic(t,s){const n=Oc();a.useEffect(()=>{if(!n)return t()},s)}function Oi(t){const s=a.useRef(void 0);return a.useEffect(()=>{s.current=t}),s.current}function Pc(t,s){const n=a.useRef(s);return Wa(s,n.current)||(n.current=s),a.useMemo(t,n.current)}function Ac(t){a.useEffect(()=>{t()},[])}function Lc(t=0){const[s,n]=a.useState({height:oa()?window.innerHeight:0,width:oa()?window.innerWidth:0}),r=a.useRef(0),l=a.useRef(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(()=>{n({width:window.innerWidth,height:window.innerHeight})},t)});return a.useEffect(()=>{if(!oa())return()=>{};const c=l.current;return n({height:window.innerHeight,width:window.innerWidth}),Dc(window,"resize",c),()=>{Tc(window,"resize",c)}},[]),s}var ca={exports:{}},da={};/** 3 * @license React 4 * use-sync-external-store-shim.production.js 5 * 6 * Copyright (c) Meta Platforms, Inc. and affiliates. 7 * 8 * This source code is licensed under the MIT license found in the 9 * LICENSE file in the root directory of this source tree. 10 */var _l;function Mc(){if(_l)return da;_l=1;var t=wo();function s(b,h){return b===h&&(b!==0||1/b===1/h)||b!==b&&h!==h}var n=typeof Object.is=="function"?Object.is:s,r=t.useState,l=t.useEffect,c=t.useLayoutEffect,o=t.useDebugValue;function d(b,h){var v=h(),i=r({inst:{value:v,getSnapshot:h}}),x=i[0].inst,m=i[1];return c(function(){x.value=v,x.getSnapshot=h,p(x)&&m({inst:x})},[b,v,h]),l(function(){return p(x)&&m({inst:x}),b(function(){p(x)&&m({inst:x})})},[b]),o(v),v}function p(b){var h=b.getSnapshot;b=b.value;try{var v=h();return!n(b,v)}catch{return!0}}function y(b,h){return h()}var j=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?y:d;return da.useSyncExternalStore=t.useSyncExternalStore!==void 0?t.useSyncExternalStore:j,da}var yl;function zc(){return yl||(yl=1,ca.exports=Mc()),ca.exports}var Uc=zc(),$c=["Array","ArrayBuffer","AsyncFunction","AsyncGenerator","AsyncGeneratorFunction","Date","Error","Function","Generator","GeneratorFunction","HTMLElement","Map","Object","Promise","RegExp","Set","URL","WeakMap","WeakSet"],Fc=["b
10igint","boolean","null","number","string","symbol","undefined"];function bn(t){const s=Object.prototype.toString.call(t).slice(8,-1);if(/HTML\w+Element/.test(s))return"HTMLElement";if(Bc(s))return s}function Ps(t){return s=>bn(s)===t}function Bc(t){return $c.includes(t)}function Vr(t){return s=>typeof s===t}function Yc(t){return Fc.includes(t)}var Gc=["innerHTML","ownerDocument","style","attributes","nodeValue"],gn=t=>Array.isArray(t),qc=t=>bn(t)==="AsyncGeneratorFunction",Wc=Ps("AsyncFunction"),Hc=Vr("bigint"),Vc=t=>t===!0||t===!1,Kc=Ps("Date"),Jc=Ps("Error"),xr=Vr("function"),Qc=Ps("GeneratorFunction"),Xc=t=>typeof t=="number"&&Number.isInteger(t),Oa=Ps("Map"),Ii=t=>Number.isNaN(t),Ha=t=>t===null,Pi=Ps("Function"),Zc=Ps("Promise"),ed=Ps("RegExp"),Ia=Ps("Set"),_n=Vr("string"),td=Vr("symbol"),Va=Vr("undefined"),sd=Ps("WeakMap"),rd=Ps("WeakSet"),Ka=t=>Ha(t)||Va(t),Ai=t=>!Va(t),nd=t=>Vr("number")(t)&&!Ii(t),ad=t=>_n(t)&&t.trim().length>0,ld=t=>{if(!_n(t)||t.length===0)return!1;const s=t.trim();return s.length>0&&Number.isFinite(Number(s))},ea=t=>!Ka(t)&&(xr(t)||typeof t=="object"),Li=t=>{if(bn(t)!=="Object")return!1;const s=Object.getPrototypeOf(t);return s===null||s===Object.getPrototypeOf({})},id=t=>Ha(t)||Yc(typeof t),od=t=>bn(t)==="URL",Mi=t=>!Ka(t)&&xr(t[Symbol.iterator]),cd=t=>Mi(t)&&xr(t.next)&&xr(t.throw),dd=t=>xr(t)&&/^class\s/.test(t.toString()),ud=(t,s)=>!gn(t)||!xr(s)?!1:t.every(n=>s(n)),xd=t=>ea(t)&&!Li(t)&&t.nodeType===1&&_n(t.nodeName)&&Gc.every(s=>s in t),md=t=>_n(t)&&t.length===0||gn(t)&&t.length===0||ea(t)&&!Oa(t)&&!Ia(t)&&Object.keys(t).length===0||Ia(t)&&t.size===0||Oa(t)&&t.size===0,pd=(t,s)=>!t||!s?!1:Object.getPrototypeOf(t)===s.prototype,fd=(t,s)=>gn(t)?t.indexOf(s)>-1:!1,hd=(t,s,n)=>{if(!ea(t)||!s)return!1;const r=t[s];return xr(n)?n(r):Ai(r)};function Ot(t){if(t===null)return"null";switch(typeof t){case"bigint":return"bigint";case"boolean":return"boolean";case"number":return"number";case"string":return"string";case"symbol":return"symbol";case"undefined":return"undefined"}if(gn(t))return"Array";if(Pi(t))return"Function";const s=bn(t);return s||"Object"}Ot.array=gn;Ot.arrayOf=ud;Ot.asyncGeneratorFunction=qc;Ot.asyncFunction=Wc;Ot.bigint=Hc;Ot.boolean=Vc;Ot.class=dd;Ot.date=Kc;Ot.defined=Ai;Ot.domElement=xd;Ot.empty=md;Ot.error=Jc;Ot.function=xr;Ot.generator=cd;Ot.generatorFunction=Qc;Ot.instanceOf=pd;Ot.integer=Xc;Ot.iterable=Mi;Ot.map=Oa;Ot.nan=Ii;Ot.null=Ha;Ot.nullOrUndefined=Ka;Ot.nonEmptyString=ad;Ot.number=nd;Ot.numericString=ld;Ot.object=ea;Ot.oneOf=fd;Ot.plainFunction=Pi;Ot.plainObject=Li;Ot.primitive=id;Ot.promise=Zc;Ot.propertyOf=hd;Ot.regexp=ed;Ot.set=Ia;Ot.string=_n;Ot.symbol=td;Ot.undefined=Va;Ot.url=od;Ot.weakMap=sd;Ot.weakSet=rd;var us=Ot;/* v8 ignore next -- @preserve */var ua,jl;function bd(){if(jl)return ua;jl=1;var t=function(r){return Object.prototype.hasOwnProperty.call(r,"props")},s=function(r,l){return r+n(l)},n=function(r){return r===null||typeof r=="boolean"||typeof r>"u"?"":typeof r=="number"?r.toString():typeof r=="string"?r:Array.isArray(r)?r.reduce(s,""):t(r)&&Object.prototype.hasOwnProperty.call(r.props,"children")?n(r.props.children):""};return n.default=n,ua=n,ua}var gd=bd();const xa=Jn(gd);var ma={exports:{}},vl;function _d(){return vl||(vl=1,(function(t){const s=Object.getPrototypeOf({});function n(){return function(c){return typeof c=="object"&&c!==null&&!(c instanceof RegExp)&&!(c instanceof Date)}}function r(l){function c(L){return L!=="constructor"&&L!=="prototype"&&L!=="__proto__"}function o(L){let U=0;const W=L.length,re=new Array(W);for(U;U<W;++U)re[U]=N(L[U]);return re}function d(L){const U={};if(h&&Object.getPrototypeOf(L)!==s)return h(L);const W=b(L);let re,Z,O;for(re=0,Z=W.length;re<Z;++re)c(O=W[re])&&(U[O]=N(L[O]));return U}function p(L,U){const W=L.length,re=U.length;let Z=0;const O=new Array(W+re);for(Z;Z<W;++Z)O[Z]=N(L[Z]);for(Z=0;Z<re;++Z)O[Z+W]=N(U[Z]);return O}const y=Object.prototype.propertyIsEnumerable;function j(L){const U=Object.keys(L),W=Object.getOwnPropertySymbols(L);for(let re=0,Z=W.length;re<Z;++re)y.call(L,W[re])&&U.push(W[re]);return U}const b=l?.symbols?j:Object.keys,h=typeof l?.cloneProtoObject=="function"?l.cloneProtoObject:void 0,v=typeof l?.isMergeableObject=="function"?l.isMergeableObject:n(),i=l?.onlyDefinedProperties===!0;function x(L){return typeof L!="object"||L===null}const m=l&&typeof l.mergeArray=="function"?l.mergeArray({clone:N,deepmerge:S,getKeys:b,isMergeableObject:v}):p;function N(L){return v(L)?Array.isArray(L)?o(L):d(L):L}function R(L,U){const W={},re=b(L),Z=b(U);let O,F,D;for(O=0,F=re.length;O<F;++O)c(D=re[O])&&Z.indexOf(D)===-1&&(W[D]=N(L[D]));for(O=0,F=Z.length;O<F;++O)if(c(D=Z[O]))if(D in L)re.indexOf(D)!==-1&&(h&&v(U[D])&&Object.getPrototypeOf(U[D])!==s?W[D]=h(U[D]):W[D]=S(L[D],U[D]));else{if(i&&typeof U[D]>"u")continue;W[D]=N(U[D])}return W}function S(L,U){if(i&&typeof U>"u")return N(L);const W=Array.isArray(U),re=Array.isArray(L);return x(U)?U:v(L)?W&&re?m(L,U):W!==re?N(U):R(L,U):N(U)}function C(){switch(arguments.length){case 0:return{};case 1:return N(arguments[0]);case 2:return S(arguments[0],arguments[1])}let L;for(let U=0,W=arguments.length;U<W;++U)L=S(L,arguments[U]);return L}return l?.all?C:S}t.exports=r,t.exports.default=r,t.exports.deepmerge=r,Object.defineProperty(t.exports,"isMergeableObject",{get:n})})(ma)),ma.exports}var yd=_d();const jd=Jn(yd);var pa,Nl;function vd(){if(Nl)return pa;Nl=1;var t=new Error("Element already at target scroll position"),s=new Error("Scroll cancelled"),n=Math.min,r=Date.now;pa={left:l("scrollLeft"),top:l("scrollTop")};function l(d){return function(y,j,b,h){b=b||{},typeof b=="function"&&(h=b,b={}),typeof h!="function"&&(h=o);var v=r(),i=y[d],x=b.ease||c,m=isNaN(b.duration)?350:+b.duration,N=!1;return i===j?h(t,y[d]):requestAnimationFrame(S),R;function R(){N=!0}function S(C){if(N)return h(s,y[d]);var L=r(),U=n(1,(L-v)/m),W=x(U);y[d]=W*(j-i)+i,U<1?requestAnimationFrame(S):requestAnimationFrame(function(){h(null,y[d])})}}}function c(d){return .5*(1-Math.cos(Math.PI*d))}function o(){}return pa}var Nd=vd();const wd=Jn(Nd);var Pn={exports:{}},Sd=Pn.exports,wl;function Ed(){return wl||(wl=1,(function(t){(function(s,n){t.exports?t.exports=n():s.Scrollparent=n()})(Sd,function(){function s(r){var l=getComputedStyle(r,null).getPropertyValue("overflow");return l.indexOf("scroll")>-1||l.indexOf("auto")>-1}function n(r){if(r instanceof HTMLElement||r instanceof SVGElement){for(var l=r.parentNode;l.parentNode;){if(s(l))return l;l=l.parentNode}return document.scrollingElement||document.documentElement}}return n})})(Pn)),Pn.exports}var Cd=Ed();const zi=Jn(Cd),kd=["top","right","bottom","left"],Sl=["start","end"],El=kd.reduce((t,s)=>t.concat(s,s+"-"+Sl[0],s+"-"+Sl[1]),[]),Wr=Math.min,Nr=Math.max,Yn=Math.round,Sn=Math.floor,Bs=t=>({x:t,y:t}
10),Rd={left:"right",right:"left",bottom:"top",top:"bottom"};function Pa(t,s,n){return Nr(t,Wr(s,n))}function Kr(t,s){return typeof t=="function"?t(s):t}function sr(t){return t.split("-")[0]}function Ys(t){return t.split("-")[1]}function Ui(t){return t==="x"?"y":"x"}function Ja(t){return t==="y"?"height":"width"}function ur(t){const s=t[0];return s==="t"||s==="b"?"y":"x"}function Qa(t){return Ui(ur(t))}function $i(t,s,n){n===void 0&&(n=!1);const r=Ys(t),l=Qa(t),c=Ja(l);let o=l==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return s.reference[c]>s.floating[c]&&(o=qn(o)),[o,qn(o)]}function Td(t){const s=qn(t);return[Gn(t),s,Gn(s)]}function Gn(t){return t.includes("start")?t.replace("start","end"):t.replace("end","start")}const Cl=["left","right"],kl=["right","left"],Dd=["top","bottom"],Od=["bottom","top"];function Id(t,s,n){switch(t){case"top":case"bottom":return n?s?kl:Cl:s?Cl:kl;case"left":case"right":return s?Dd:Od;default:return[]}}function Pd(t,s,n,r){const l=Ys(t);let c=Id(sr(t),n==="start",r);return l&&(c=c.map(o=>o+"-"+l),s&&(c=c.concat(c.map(Gn)))),c}function qn(t){const s=sr(t);return Rd[s]+t.slice(s.length)}function Ad(t){return{top:0,right:0,bottom:0,left:0,...t}}function Fi(t){return typeof t!="number"?Ad(t):{top:t,right:t,bottom:t,left:t}}function Wn(t){const{x:s,y:n,width:r,height:l}=t;return{width:r,height:l,top:n,left:s,right:s+r,bottom:n+l,x:s,y:n}}function Rl(t,s,n){let{reference:r,floating:l}=t;const c=ur(s),o=Qa(s),d=Ja(o),p=sr(s),y=c==="y",j=r.x+r.width/2-l.width/2,b=r.y+r.height/2-l.height/2,h=r[d]/2-l[d]/2;let v;switch(p){case"top":v={x:j,y:r.y-l.height};break;case"bottom":v={x:j,y:r.y+r.height};break;case"right":v={x:r.x+r.width,y:b};break;case"left":v={x:r.x-l.width,y:b};break;default:v={x:r.x,y:r.y}}switch(Ys(s)){case"start":v[o]-=h*(n&&y?-1:1);break;case"end":v[o]+=h*(n&&y?-1:1);break}return v}async function Ld(t,s){var n;s===void 0&&(s={});const{x:r,y:l,platform:c,rects:o,elements:d,strategy:p}=t,{boundary:y="clippingAncestors",rootBoundary:j="viewport",elementContext:b="floating",altBoundary:h=!1,padding:v=0}=Kr(s,t),i=Fi(v),m=d[h?b==="floating"?"reference":"floating":b],N=Wn(await c.getClippingRect({element:(n=await(c.isElement==null?void 0:c.isElement(m)))==null||n?m:m.contextElement||await(c.getDocumentElement==null?void 0:c.getDocumentElement(d.floating)),boundary:y,rootBoundary:j,strategy:p})),R=b==="floating"?{x:r,y:l,width:o.floating.width,height:o.floating.height}:o.reference,S=await(c.getOffsetParent==null?void 0:c.getOffsetParent(d.floating)),C=await(c.isElement==null?void 0:c.isElement(S))?await(c.getScale==null?void 0:c.getScale(S))||{x:1,y:1}:{x:1,y:1},L=Wn(c.convertOffsetParentRelativeRectToViewportRelativeRect?await c.convertOffsetParentRelativeRectToViewportRelativeRect({elements:d,rect:R,offsetParent:S,strategy:p}):R);return{top:(N.top-L.top+i.top)/C.y,bottom:(L.bottom-N.bottom+i.bottom)/C.y,left:(N.left-L.left+i.left)/C.x,right:(L.right-N.right+i.right)/C.x}}const Md=50,zd=async(t,s,n)=>{const{placement:r="bottom",strategy:l="absolute",middleware:c=[],platform:o}=n,d=o.detectOverflow?o:{...o,detectOverflow:Ld},p=await(o.isRTL==null?void 0:o.isRTL(s));let y=await o.getElementRects({reference:t,floating:s,strategy:l}),{x:j,y:b}=Rl(y,r,p),h=r,v=0;const i={};for(let x=0;x<c.length;x++){const m=c[x];if(!m)continue;const{name:N,fn:R}=m,{x:S,y:C,data:L,reset:U}=await R({x:j,y:b,initialPlacement:r,placement:h,strategy:l,middlewareData:i,rects:y,platform:d,elements:{reference:t,floating:s}});j=S??j,b=C??b,i[N]={...i[N],...L},U&&v<Md&&(v++,typeof U=="object"&&(U.placement&&(h=U.placement),U.rects&&(y=U.rects===!0?await o.getElementRects({reference:t,floating:s,strategy:l}):U.rects),{x:j,y:b}=Rl(y,h,p)),x=-1)}return{x:j,y:b,placement:h,strategy:l,middlewareData:i}},Ud=t=>({name:"arrow",options:t,async fn(s){const{x:n,y:r,placement:l,rects:c,platform:o,elements:d,middlewareData:p}=s,{element:y,padding:j=0}=Kr(t,s)||{};if(y==null)return{};const b=Fi(j),h={x:n,y:r},v=Qa(l),i=Ja(v),x=await o.getDimensions(y),m=v==="y",N=m?"top":"left",R=m?"bottom":"right",S=m?"clientHeight":"clientWidth",C=c.reference[i]+c.reference[v]-h[v]-c.floating[i],L=h[v]-c.reference[v],U=await(o.getOffsetParent==null?void 0:o.getOffsetParent(y));let W=U?U[S]:0;(!W||!await(o.isElement==null?void 0:o.isElement(U)))&&(W=d.floating[S]||c.floating[i]);const re=C/2-L/2,Z=W/2-x[i]/2-1,O=Wr(b[N],Z),F=Wr(b[R],Z),D=O,$=W-x[i]-F,z=W/2-x[i]/2+re,me=Pa(D,z,$),K=!p.arrow&&Ys(l)!=null&&z!==me&&c.reference[i]/2-(z<D?O:F)-x[i]/2<0,te=K?z<D?z-D:z-$:0;return{[v]:h[v]+te,data:{[v]:me,centerOffset:z-me-te,...K&&{alignmentOffset:te}},reset:K}}});function $d(t,s,n){return(t?[...n.filter(l=>Ys(l)===t),...n.filter(l=>Ys(l)!==t)]:n.filter(l=>sr(l)===l)).filter(l=>t?Ys(l)===t||(s?Gn(l)!==l:!1):!0)}const Fd=function(t){return t===void 0&&(t={}),{name:"autoPlacement",options:t,async fn(s){var n,r,l;const{rects:c,middlewareData:o,placement:d,platform:p,elements:y}=s,{crossAxis:j=!1,alignment:b,allowedPlacements:h=El,autoAlignment:v=!0,...i}=Kr(t,s),x=b!==void 0||h===El?$d(b||null,v,h):h,m=await p.detectOverflow(s,i),N=((n=o.autoPlacement)==null?void 0:n.index)||0,R=x[N];if(R==null)return{};const S=$i(R,c,await(p.isRTL==null?void 0:p.isRTL(y.floating)));
10if(d!==R)return{reset:{placement:x[0]}};const C=[m[sr(R)],m[S[0]],m[S[1]]],L=[...((r=o.autoPlacement)==null?void 0:r.overflows)||[],{placement:R,overflows:C}],U=x[N+1];if(U)return{data:{index:N+1,overflows:L},reset:{placement:U}};const W=L.map(O=>{const F=Ys(O.placement);return[O.placement,F&&j?O.overflows.slice(0,2).reduce((D,$)=>D+$,0):O.overflows[0],O.overflows]}).sort((O,F)=>O[1]-F[1]),Z=((l=W.filter(O=>O[2].slice(0,Ys(O[0])?2:3).every(F=>F<=0))[0])==null?void 0:l[0])||W[0][0];return Z!==d?{data:{index:N+1,overflows:L},reset:{placement:Z}}:{}}}},Bd=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(s){var n,r;const{placement:l,middlewareData:c,rects:o,initialPlacement:d,platform:p,elements:y}=s,{mainAxis:j=!0,crossAxis:b=!0,fallbackPlacements:h,fallbackStrategy:v="bestFit",fallbackAxisSideDirection:i="none",flipAlignment:x=!0,...m}=Kr(t,s);if((n=c.arrow)!=null&&n.alignmentOffset)return{};const N=sr(l),R=ur(d),S=sr(d)===d,C=await(p.isRTL==null?void 0:p.isRTL(y.floating)),L=h||(S||!x?[qn(d)]:Td(d)),U=i!=="none";!h&&U&&L.push(...Pd(d,x,i,C));const W=[d,...L],re=await p.detectOverflow(s,m),Z=[];let O=((r=c.flip)==null?void 0:r.overflows)||[];if(j&&Z.push(re[N]),b){const z=$i(l,o,C);Z.push(re[z[0]],re[z[1]])}if(O=[...O,{placement:l,overflows:Z}],!Z.every(z=>z<=0)){var F,D;const z=(((F=c.flip)==null?void 0:F.index)||0)+1,me=W[z];if(me&&(!(b==="alignment"?R!==ur(me):!1)||O.every(I=>ur(I.placement)===R?I.overflows[0]>0:!0)))return{data:{index:z,overflows:O},reset:{placement:me}};let K=(D=O.filter(te=>te.overflows[0]<=0).sort((te,I)=>te.overflows[1]-I.overflows[1])[0])==null?void 0:D.placement;if(!K)switch(v){case"bestFit":{var $;const te=($=O.filter(I=>{if(U){const B=ur(I.placement);return B===R||B==="y"}return!0}).map(I=>[I.placement,I.overflows.filter(B=>B>0).reduce((B,Ne)=>B+Ne,0)]).sort((I,B)=>I[1]-B[1])[0])==null?void 0:$[0];te&&(K=te);break}case"initialPlacement":K=d;break}if(l!==K)return{reset:{placement:K}}}return{}}}},Yd=new Set(["left","top"]);async function Gd(t,s){const{placement:n,platform:r,elements:l}=t,c=await(r.isRTL==null?void 0:r.isRTL(l.floating)),o=sr(n),d=Ys(n),p=ur(n)==="y",y=Yd.has(o)?-1:1,j=c&&p?-1:1,b=Kr(s,t);let{mainAxis:h,crossAxis:v,alignmentAxis:i}=typeof b=="number"?{mainAxis:b,crossAxis:0,alignmentAxis:null}:{mainAxis:b.mainAxis||0,crossAxis:b.crossAxis||0,alignmentAxis:b.alignmentAxis};return d&&typeof i=="number"&&(v=d==="end"?i*-1:i),p?{x:v*j,y:h*y}:{x:h*y,y:v*j}}const qd=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(s){var n,r;const{x:l,y:c,placement:o,middlewareData:d}=s,p=await Gd(s,t);return o===((n=d.offset)==null?void 0:n.placement)&&(r=d.arrow)!=null&&r.alignmentOffset?{}:{x:l+p.x,y:c+p.y,data:{...p,placement:o}}}}},Wd=function(t){return t===void 0&&(t={}),{name:"shift",options:t,async fn(s){const{x:n,y:r,placement:l,platform:c}=s,{mainAxis:o=!0,crossAxis:d=!1,limiter:p={fn:N=>{let{x:R,y:S}=N;return{x:R,y:S}}},...y}=Kr(t,s),j={x:n,y:r},b=await c.detectOverflow(s,y),h=ur(sr(l)),v=Ui(h);let i=j[v],x=j[h];if(o){const N=v==="y"?"top":"left",R=v==="y"?"bottom":"right",S=i+b[N],C=i-b[R];i=Pa(S,i,C)}if(d){const N=h==="y"?"top":"left",R=h==="y"?"bottom":"right",S=x+b[N],C=x-b[R];x=Pa(S,x,C)}const m=p.fn({...s,[v]:i,[h]:x});return{...m,data:{x:m.x-n,y:m.y-r,enabled:{[v]:o,[h]:d}}}}}};function ta(){return typeof window<"u"}function Jr(t){return Bi(t)?(t.nodeName||"").toLowerCase():"#document"}function ys(t){var s;return(t==null||(s=t.ownerDocument)==null?void 0:s.defaultView)||window}function Gs(t){var s;return(s=(Bi(t)?t.ownerDocument:t.document)||window.document)==null?void 0:s.documentElement}function Bi(t){return ta()?t instanceof Node||t instanceof ys(t).Node:!1}function Os(t){return ta()?t instanceof Element||t instanceof ys(t).Element:!1}function rr(t){return ta()?t instanceof HTMLElement||t instanceof ys(t).HTMLElement:!1}function Tl(t){return!ta()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof ys(t).ShadowRoot}function yn(t){const{overflow:s,overflowX:n,overflowY:r,display:l}=Is(t);return/auto|scroll|overlay|hidden|clip/.test(s+r+n)&&l!=="inline"&&l!=="contents"}function Hd(t){return/^(table|td|th)$/.test(Jr(t))}function sa(t){try{if(t.matches(":popover-open"))return!0}catch{}try{return t.matches(":modal")}catch{return!1}}const Vd=/transform|translate|scale|rotate|perspective|filter/,Kd=/paint|layout|strict|content/,yr=t=>!!t&&t!=="none";let fa;function Xa(t){const s=Os(t)?Is(t):t;return yr(s.transform)||yr(s.translate)||yr(s.scale)||yr(s.rotate)||yr(s.perspective)||!Za()&&(yr(s.backdropFilter)||yr(s.filter))||Vd.test(s.willChange||"")||Kd.test(s.contain||"")}function Jd(t){let s=mr(t);for(;rr(s)&&!Hr(s);){if(Xa(s))return s;if(sa(s))return null;s=mr(s)}return null}function Za(){return fa==null&&(fa=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),fa}function Hr(t){return/^(html|body|#document)$/.test(Jr(t))}function Is(t){return ys(t).getComputedStyle(t)}function ra(t){return Os(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function mr(t){if(Jr(t)==="html")return t;const s=t.assignedSlot||t.parentNode||Tl(t)&&t.host||Gs(t);return Tl(s)?s.host:s}function Yi(t){const s=mr(t);return Hr(s)?t.ownerDocument?t.ownerDocument.body:t.body:rr(s)&&yn(s)?s:Yi(s)}function pn(t,s,n){var r;s===void 0&&(s=[]),n===void 0&&(n=!0);const l=Yi(t),c=l===((r=t.ownerDocument)==null?void 0:r.body),o=ys(l);if(c){const d=Aa(o);
vendor: 6,682 bytes, line 10
10return s.concat(o,o.visualViewport||[],yn(l)?l:[],d&&n?pn(d):[])}else return s.concat(l,pn(l,[],n))}function Aa(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function Gi(t){const s=Is(t);let n=parseFloat(s.width)||0,r=parseFloat(s.height)||0;const l=rr(t),c=l?t.offsetWidth:n,o=l?t.offsetHeight:r,d=Yn(n)!==c||Yn(r)!==o;return d&&(n=c,r=o),{width:n,height:r,$:d}}function el(t){return Os(t)?t:t.contextElement}function Br(t){const s=el(t);if(!rr(s))return Bs(1);const n=s.getBoundingClientRect(),{width:r,height:l,$:c}=Gi(s);let o=(c?Yn(n.width):n.width)/r,d=(c?Yn(n.height):n.height)/l;return(!o||!Number.isFinite(o))&&(o=1),(!d||!Number.isFinite(d))&&(d=1),{x:o,y:d}}const Qd=Bs(0);function qi(t){const s=ys(t);return!Za()||!s.visualViewport?Qd:{x:s.visualViewport.offsetLeft,y:s.visualViewport.offsetTop}}function Xd(t,s,n){return s===void 0&&(s=!1),!n||s&&n!==ys(t)?!1:s}function Cr(t,s,n,r){s===void 0&&(s=!1),n===void 0&&(n=!1);const l=t.getBoundingClientRect(),c=el(t);let o=Bs(1);s&&(r?Os(r)&&(o=Br(r)):o=Br(t));const d=Xd(c,n,r)?qi(c):Bs(0);let p=(l.left+d.x)/o.x,y=(l.top+d.y)/o.y,j=l.width/o.x,b=l.height/o.y;if(c){const h=ys(c),v=r&&Os(r)?ys(r):r;let i=h,x=Aa(i);for(;x&&r&&v!==i;){const m=Br(x),N=x.getBoundingClientRect(),R=Is(x),S=N.left+(x.clientLeft+parseFloat(R.paddingLeft))*m.x,C=N.top+(x.clientTop+parseFloat(R.paddingTop))*m.y;p*=m.x,y*=m.y,j*=m.x,b*=m.y,p+=S,y+=C,i=ys(x),x=Aa(i)}}return Wn({width:j,height:b,x:p,y})}function na(t,s){const n=ra(t).scrollLeft;return s?s.left+n:Cr(Gs(t)).left+n}function Wi(t,s){const n=t.getBoundingClientRect(),r=n.left+s.scrollLeft-na(t,n),l=n.top+s.scrollTop;return{x:r,y:l}}function Zd(t){let{elements:s,rect:n,offsetParent:r,strategy:l}=t;const c=l==="fixed",o=Gs(r),d=s?sa(s.floating):!1;if(r===o||d&&c)return n;let p={scrollLeft:0,scrollTop:0},y=Bs(1);const j=Bs(0),b=rr(r);if((b||!b&&!c)&&((Jr(r)!=="body"||yn(o))&&(p=ra(r)),b)){const v=Cr(r);y=Br(r),j.x=v.x+r.clientLeft,j.y=v.y+r.clientTop}const h=o&&!b&&!c?Wi(o,p):Bs(0);return{width:n.width*y.x,height:n.height*y.y,x:n.x*y.x-p.scrollLeft*y.x+j.x+h.x,y:n.y*y.y-p.scrollTop*y.y+j.y+h.y}}function eu(t){return Array.from(t.getClientRects())}function tu(t){const s=Gs(t),n=ra(t),r=t.ownerDocument.body,l=Nr(s.scrollWidth,s.clientWidth,r.scrollWidth,r.clientWidth),c=Nr(s.scrollHeight,s.clientHeight,r.scrollHeight,r.clientHeight);let o=-n.scrollLeft+na(t);const d=-n.scrollTop;return Is(r).direction==="rtl"&&(o+=Nr(s.clientWidth,r.clientWidth)-l),{width:l,height:c,x:o,y:d}}const Dl=25;function su(t,s){const n=ys(t),r=Gs(t),l=n.visualViewport;let c=r.clientWidth,o=r.clientHeight,d=0,p=0;if(l){c=l.width,o=l.height;const j=Za();(!j||j&&s==="fixed")&&(d=l.offsetLeft,p=l.offsetTop)}const y=na(r);if(y<=0){const j=r.ownerDocument,b=j.body,h=getComputedStyle(b),v=j.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,i=Math.abs(r.clientWidth-b.clientWidth-v);i<=Dl&&(c-=i)}else y<=Dl&&(c+=y);return{width:c,height:o,x:d,y:p}}function ru(t,s){const n=Cr(t,!0,s==="fixed"),r=n.top+t.clientTop,l=n.left+t.clientLeft,c=rr(t)?Br(t):Bs(1),o=t.clientWidth*c.x,d=t.clientHeight*c.y,p=l*c.x,y=r*c.y;return{width:o,height:d,x:p,y}}function Ol(t,s,n){let r;if(s==="viewport")r=su(t,n);else if(s==="document")r=tu(Gs(t));else if(Os(s))r=ru(s,n);else{const l=qi(t);r={x:s.x-l.x,y:s.y-l.y,width:s.width,height:s.height}}return Wn(r)}function Hi(t,s){const n=mr(t);return n===s||!Os(n)||Hr(n)?!1:Is(n).position==="fixed"||Hi(n,s)}function nu(t,s){const n=s.get(t);if(n)return n;let r=pn(t,[],!1).filter(d=>Os(d)&&Jr(d)!=="body"),l=null;const c=Is(t).position==="fixed";let o=c?mr(t):t;for(;Os(o)&&!Hr(o);){const d=Is(o),p=Xa(o);!p&&d.position==="fixed"&&(l=null),(c?!p&&!l:!p&&d.position==="static"&&!!l&&(l.position==="absolute"||l.position==="fixed")||yn(o)&&!p&&Hi(t,o))?r=r.filter(j=>j!==o):l=d,o=mr(o)}return s.set(t,r),r}function au(t){let{element:s,boundary:n,rootBoundary:r,strategy:l}=t;const o=[...n==="clippingAncestors"?sa(s)?[]:nu(s,this._c):[].concat(n),r],d=Ol(s,o[0],l);let p=d.top,y=d.right,j=d.bottom,b=d.left;for(let h=1;h<o.length;h++){const v=Ol(s,o[h],l);p=Nr(v.top,p),y=Wr(v.right,y),j=Wr(v.bottom,j),b=Nr(v.left,b)}return{width:y-b,height:j-p,x:b,y:p}}function lu(t){const{width:s,height:n}=Gi(t);return{width:s,height:n}}function iu(t,s,n){const r=rr(s),l=Gs(s),c=n==="fixed",o=Cr(t,!0,c,s);let d={scrollLeft:0,scrollTop:0};const p=Bs(0);function y(){p.x=na(l)}if(r||!r&&!c)if((Jr(s)!=="body"||yn(l))&&(d=ra(s)),r){const v=Cr(s,!0,c,s);p.x=v.x+s.clientLeft,p.y=v.y+s.clientTop}else l&&y();c&&!r&&l&&y();const j=l&&!r&&!c?Wi(l,d):Bs(0),b=o.left+d.scrollLeft-p.x-j.x,h=o.top+d.scrollTop-p.y-j.y;return{x:b,y:h,width:o.width,height:o.height}}function ha(t){return Is(t).position==="static"}function Il(t,s){if(!rr(t)||Is(t).position==="fixed")return null;if(s)return s(t);let n=t.offsetParent;return Gs(t)===n&&(n=n.ownerDocument.body),n}function Vi(t,s){const n=ys(t);if(sa(t))return n;if(!rr(t)){let l=mr(t);for(;l&&!Hr(l);){if(Os(l)&&!ha(l))return l;l=mr(l)}return n}let r=Il(t,s);for(;r&&Hd(r)&&ha(r);)r=Il(r,s);return r&&Hr(r)&&ha(r)&&!Xa(r)?n:r||Jd(t)||n}const ou=async function(t){const s=this.getOffsetParent||Vi,n=this.getDimensions,r=await n(t.floating);return{reference:iu(t.reference,await s(t.floating),t.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function cu(t){return Is(t).direction==="rtl"}const du={convertOffsetParentRelativeRectToViewportRelativeRect:Zd,getDocumentElement:Gs,getClippingRect:au,getOffsetParent:Vi,getElementRects:ou,getClientRects:eu,getDimensions:lu,getScale:Br,isElement:Os,isRTL:cu};function Ki(t,s){return t.x===s.x&&t.y===s.y&&t.width===s.width&&t.height===s.height}function uu(t,s){let n=null,r;const l=Gs(t);function c(){var d;clearTimeout(r),(d=n)==null||d.disconnect(),n=null}function o(d,p){d===void 0&&(d=!1),p===void 0&&(p=1),c();const y=t.getBoundingClientRect(),{left:j,top:b,width:h,height:v}=y;if(d||s(),!h||!v)return;const i=Sn(b),x=Sn(l.clientWidth-(j+h)),m=Sn(l.clientHeight-(b+v)),N=Sn(j),S={rootMargin:-i+"px "+-x+"px "+-m+"px "+-N+"px",threshold:Nr(0,Wr(1,p))||1};let C=!0;function L(U){const W=U[0].intersectionRatio;if(W!==p){if(!C)return o();W?o(!1,W):r=setTimeout(()=>{o(!1,1e-7)},1e3)}W===1&&!Ki(y,t.getBoundingClientRect())&&o(),C=!1}try{n=new IntersectionObserver(L,{...S,root:l.ownerDocument})}catch{n=new IntersectionObserver(L,S)}n.observe(t)}return o(!0),c}function Pl(t,s,n,r){r===void 0&&(r={});const{ancestorScroll:l=!0,ancestorResize:c=!0,elementResize:o=typeof ResizeObserver=="function",layoutShift:d=typeof IntersectionObserver=="function",animationFrame:p=!1}=r,y=el(t),j=l||c?[...y?pn(y):[],...s?pn(s):[]]:[];
vendor: 4,580 bytes, line 10
10j.forEach(N=>{l&&N.addEventListener("scroll",n,{passive:!0}),c&&N.addEventListener("resize",n)});const b=y&&d?uu(y,n):null;let h=-1,v=null;o&&(v=new ResizeObserver(N=>{let[R]=N;R&&R.target===y&&v&&s&&(v.unobserve(s),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var S;(S=v)==null||S.observe(s)})),n()}),y&&!p&&v.observe(y),s&&v.observe(s));let i,x=p?Cr(t):null;p&&m();function m(){const N=Cr(t);x&&!Ki(x,N)&&n(),x=N,i=requestAnimationFrame(m)}return n(),()=>{var N;j.forEach(R=>{l&&R.removeEventListener("scroll",n),c&&R.removeEventListener("resize",n)}),b?.(),(N=v)==null||N.disconnect(),v=null,p&&cancelAnimationFrame(i)}}const xu=qd,mu=Fd,pu=Wd,fu=Bd,Al=Ud,hu=(t,s,n)=>{const r=new Map,l={platform:du,...n},c={...l.platform,_c:r};return zd(t,s,{...l,platform:c})};var bu=typeof document<"u",gu=function(){},An=bu?a.useLayoutEffect:gu;function Hn(t,s){if(t===s)return!0;if(typeof t!=typeof s)return!1;if(typeof t=="function"&&t.toString()===s.toString())return!0;let n,r,l;if(t&&s&&typeof t=="object"){if(Array.isArray(t)){if(n=t.length,n!==s.length)return!1;for(r=n;r--!==0;)if(!Hn(t[r],s[r]))return!1;return!0}if(l=Object.keys(t),n=l.length,n!==Object.keys(s).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(s,l[r]))return!1;for(r=n;r--!==0;){const c=l[r];if(!(c==="_owner"&&t.$$typeof)&&!Hn(t[c],s[c]))return!1}return!0}return t!==t&&s!==s}function Ji(t){return typeof window>"u"?1:(t.ownerDocument.defaultView||window).devicePixelRatio||1}function Ll(t,s){const n=Ji(t);return Math.round(s*n)/n}function ba(t){const s=a.useRef(t);return An(()=>{s.current=t}),s}function Ml(t){t===void 0&&(t={});const{placement:s="bottom",strategy:n="absolute",middleware:r=[],platform:l,elements:{reference:c,floating:o}={},transform:d=!0,whileElementsMounted:p,open:y}=t,[j,b]=a.useState({x:0,y:0,strategy:n,placement:s,middlewareData:{},isPositioned:!1}),[h,v]=a.useState(r);Hn(h,r)||v(r);const[i,x]=a.useState(null),[m,N]=a.useState(null),R=a.useCallback(I=>{I!==U.current&&(U.current=I,x(I))},[]),S=a.useCallback(I=>{I!==W.current&&(W.current=I,N(I))},[]),C=c||i,L=o||m,U=a.useRef(null),W=a.useRef(null),re=a.useRef(j),Z=p!=null,O=ba(p),F=ba(l),D=ba(y),$=a.useCallback(()=>{if(!U.current||!W.current)return;const I={placement:s,strategy:n,middleware:h};F.current&&(I.platform=F.current),hu(U.current,W.current,I).then(B=>{const Ne={...B,isPositioned:D.current!==!1};z.current&&!Hn(re.current,Ne)&&(re.current=Ne,gi.flushSync(()=>{b(Ne)}))})},[h,s,n,F,D]);An(()=>{y===!1&&re.current.isPositioned&&(re.current.isPositioned=!1,b(I=>({...I,isPositioned:!1})))},[y]);const z=a.useRef(!1);An(()=>(z.current=!0,()=>{z.current=!1}),[]),An(()=>{if(C&&(U.current=C),L&&(W.current=L),C&&L){if(O.current)return O.current(C,L,$);$()}},[C,L,$,O,Z]);const me=a.useMemo(()=>({reference:U,floating:W,setReference:R,setFloating:S}),[R,S]),K=a.useMemo(()=>({reference:C,floating:L}),[C,L]),te=a.useMemo(()=>{const I={position:n,left:0,top:0};if(!K.floating)return I;const B=Ll(K.floating,j.x),Ne=Ll(K.floating,j.y);return d?{...I,transform:"translate("+B+"px, "+Ne+"px)",...Ji(K.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:B,top:Ne}},[n,d,K.floating,j.x,j.y]);return a.useMemo(()=>({...j,update:$,refs:me,elements:K,floatingStyles:te}),[j,$,me,K,te])}const _u=t=>{function s(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:t,fn(n){const{element:r,padding:l}=typeof t=="function"?t(n):t;return r&&s(r)?r.current!=null?Al({element:r.current,padding:l}).fn(n):{}:r?Al({element:r,padding:l}).fn(n):{}}}},zl=(t,s)=>{const n=xu(t);return{name:n.name,fn:n.fn,options:[t,s]}},yu=(t,s)=>{const n=pu(t);return{name:n.name,fn:n.fn,options:[t,s]}},ju=(t,s)=>{const n=fu(t);return{name:n.name,fn:n.fn,options:[t,s]}},vu=(t,s)=>{const n=mu(t);return{name:n.name,fn:n.fn,options:[t,s]}},Nu=(t,s)=>{const n=_u(t);return{name:n.name,fn:n.fn,options:[t,s]}},wu={arrowBase:32,arrowColor:"#ffffff",arrowSize:16,arrowSpacing:12,backgroundColor:"#ffffff",beaconSize:36,beaconTrigger:"click",beforeTimeout:5e3,blockTargetInteraction:!1,buttons:["back","close","primary"],closeButtonAction:"close",disableFocusTrap:!1,dismissKeyAction:"close",hideOverlay:!1,loaderDelay:300,offset:10,overlayClickAction:"close",overlayColor:"#00000080",primaryColor:"#000000",scrollDuration:300,scrollOffset:20,showProgress:!1,skipBeacon:!1,skipScroll:!1,spotlightPadding:10,spotlightRadius:4,targetWaitTimeout:1e3,textColor:"#000000",width:380,zIndex:100},Su={beaconOptions:{offset:-18}},Qi={back:"Back",close:"Close",last:"Last",next:"Next",nextWithProgress:"Next ({current} of {total}
10)",open:"Open the dialog",skip:"Skip"},Eu={isFixed:!1,locale:Qi,placement:"bottom"},Cu={continuous:!1,debug:!1,run:!1,scrollToFirstStep:!1,steps:[]},Et={INIT:"init",START:"start",STOP:"stop",RESET:"reset",PREV:"prev",NEXT:"next",GO:"go",CLOSE:"close",SKIP:"skip",REPLAY:"replay",UPDATE:"update",COMPLETE:"complete"},ts={TOUR_START:"tour:start",STEP_BEFORE_HOOK:"step:before_hook",STEP_BEFORE:"step:before",SCROLL_START:"scroll:start",SCROLL_END:"scroll:end",BEACON:"beacon",TOOLTIP:"tooltip",STEP_AFTER:"step:after",STEP_AFTER_HOOK:"step:after_hook",TOUR_END:"tour:end",TOUR_STATUS:"tour:status",TARGET_NOT_FOUND:"error:target_not_found",ERROR:"error"},Ye={INIT:"init",READY:"ready",BEACON_BEFORE:"beacon_before",BEACON:"beacon",TOOLTIP_BEFORE:"tooltip_before",TOOLTIP:"tooltip",COMPLETE:"complete"},bs={BUTTON_BACK:"button_back",BUTTON_CLOSE:"button_close",BUTTON_PRIMARY:"button_primary",BUTTON_SKIP:"button_skip",KEYBOARD:"keyboard",OVERLAY:"overlay"},Dt={IDLE:"idle",READY:"ready",WAITING:"waiting",RUNNING:"running",PAUSED:"paused",SKIPPED:"skipped",FINISHED:"finished"},ku="react-joyride-portal";function Ru(t){const s={};for(const n in t)t[n]!==void 0&&(s[n]=t[n]);return s}function Mr(...t){return jd({all:!0,isMergeableObject:s=>!(!us.plainObject(s)||a.isValidElement(s))})(...t)}function Xi(t){return Object.prototype.toString.call(t).slice(8,-1).toLowerCase()}function Js(t,s={}){const{defaultValue:n,step:r,steps:l}=s;let c=xa(t);if(c)(c.includes("{current}")||c.includes("{total}"))&&r&&l&&(c=c.replace("{current}",r.toString()).replace("{total}",l.toString()));else if(a.isValidElement(t)&&!Object.values(t.props).length&&Xi(t.type)==="function")try{c=Js(t.type({}),s)}catch{c=xa(n)}else c=xa(n);return c}function ls(t,s,n,...r){if(!t)return;const l=new Date,c=`${String(l.getHours()).padStart(2,"0")}:${String(l.getMinutes()).padStart(2,"0")}:${String(l.getSeconds()).padStart(2,"0")}.${String(l.getMilliseconds()).padStart(3,"0")}`}function Tu(t,s){const n=Ru(s);return{...t,...n}}function fn(){}function Du(t){return Object.keys(t)}function Vn(t,...s){if(!us.plainObject(t))throw new TypeError("Expected an object");const n={};for(const r in t)({}).hasOwnProperty.call(t,r)&&!s.includes(r)&&(n[r]=t[r]);return n}function Ul(t,...s){if(!us.plainObject(t))throw new TypeError("Expected an object");if(!s.length)return t;const n={};for(const r in t)({}).hasOwnProperty.call(t,r)&&s.includes(r)&&(n[r]=t[r]);return n}function La(t,s,n){const r=c=>c.replace("{current}",String(s)).replace("{total}",String(n));if(Xi(t)==="string")return r(t);if(!a.isValidElement(t))return t;const{children:l}=t.props;if(us.string(l)&&l.includes("{current}"))return a.cloneElement(t,{children:r(l)});if(Array.isArray(l))return a.cloneElement(t,{children:l.map(c=>typeof c=="string"?r(c):La(c,s,n))});if(us.function(t.type)&&!Object.values(t.props).length)try{return La(t.type({}),s,n)}catch{return t}return t}function $l(t){return Du(t).sort().reduce((s,n)=>(s[n]=t[n],s),{})}function tl(){return!!(typeof window<"u"&&window.document?.createElement)}function Fl(t){let s=0,n=0,r=t;for(;r;)s+=r.offsetTop,n+=r.offsetLeft,r=r.offsetParent;return{left:n,top:s}}function sl(t){return t?t.getBoundingClientRect():null}function Ou(t=!1){const{body:s,documentElement:n}=document;if(!s||!n)return 0;if(t){const r=[s.scrollHeight,s.offsetHeight,n.clientHeight,n.scrollHeight,n.offsetHeight].sort((c,o)=>c-o),l=Math.floor(r.length/2);return r.length%2===0?(r[l-1]+r[l])/2:r[l]}return Math.max(s.scrollHeight,s.offsetHeight,n.clientHeight,n.scrollHeight,n.offsetHeight)}function ws(t){if(!t)return null;if(typeof t=="function")try{return t()}catch{return null}if(typeof t=="object"&&"current"in t)return t.current;if(typeof t=="string")try{return document.querySelector(t)}catch{return null}return t}function Iu(t,s,n){const r=sl(t),l=Qr(t),c=l?!l.isSameNode(ms()):!1,o=n??Xr(t);let d=0,p=r?.top??0;return c&&o?p=r?.top??0:l instanceof HTMLElement&&(d=l.scrollTop,!c&&!o&&(p+=d),l.isSameNode(ms())||(p+=ms().scrollTop)),Math.floor(p-s)}function Qr(t,s){if(!t)return ms();const n=zi(t);if(n){if(n.isSameNode(ms()))return s?document:ms();if(!(n.scrollHeight>n.offsetHeight))return ms()}return n}function Pu(t){const s=t.getBoundingClientRect(),n=ms(),r=s.top+s.height/2,l=window.innerHeight/2;return Math.max(0,n.scrollTop+r-l)}function Au(t,s){if(!t)return 0;const n=zi(t)??ms(),r=parseFloat(getComputedStyle(t).scrollMarginTop)||0,l=sl(n),c=n.scrollTop??0,{offsetTop:o=0,scrollTop:d=0}=n;let p=t.getBoundingClientRect().top+d;if(o&&(Zi(t)||Lu(t))){const j=t.getBoundingClientRect(),b=j.top-(l?.top??0),h=b
10+j.height,v=n.clientHeight,i=v*.2;b>=i&&h<=v-i?p=c:p=b+c}const y=Math.floor(p-s-r);return y<0?0:y}function Lu(t){return t.offsetParent!==document.body}function Zi(t){if(!t)return!1;const s=Qr(t);return s?!s.isSameNode(ms()):!1}function Xr(t,s="fixed"){if(!t||!(t instanceof Element))return!1;const{nodeName:n}=t;return n==="BODY"||n==="HTML"?!1:getComputedStyle(t).position===s?!0:t.parentNode?Xr(t.parentNode,s):!1}function En(t){if(!t)return!1;let s=t;for(;s&&s!==document.body;){if(s instanceof HTMLElement){const{display:n,visibility:r}=getComputedStyle(s);if(n==="none"||r==="hidden")return!1}s=s.parentElement??null}return!0}function Bl(t){const{isFirstStep:s,scrollToFirstStep:n,step:r,target:l,targetLifecycle:c}=t;if(r.skipScroll||s&&!n&&c!==Ye.TOOLTIP||r.placement==="center")return!1;const o=l?.isConnected?Qr(l):ms(),d=o?!o.isSameNode(ms()):!1;return(r.isFixed||Xr(l))&&!d?!1:o.scrollHeight>o.clientHeight}function ms(){return document.scrollingElement??document.documentElement}function Yl(t,s){const{duration:n,element:r}=s;let l=()=>{};const c=new Promise(o=>{const{scrollTop:d}=r,p=t>d?t-d:d-t;l=wd.top(r,t,{duration:p<100?50:n},()=>{o()})});return{cancel:l,promise:c}}function Mu(t){const s=t.replace(/^#?([\da-f])([\da-f])([\da-f])$/i,(r,l,c,o)=>l+l+c+c+o+o),n=/^#?([\da-f]{2})([\da-f]{2})([\da-f]{2})/i.exec(s);return n?[parseInt(n[1],16),parseInt(n[2],16),parseInt(n[3],16)]:[]}const eo={backgroundColor:"transparent",border:0,borderRadius:0,color:"#555555",cursor:"pointer",fontSize:16,lineHeight:1,padding:0,WebkitAppearance:"none"},Cn={...eo,borderRadius:4,padding:8};function zu(t,s){const{styles:n}=t,r=Mr(n??{},s.styles??{});let{width:l}=s;tl()&&(l=typeof l=="number"&&window.innerWidth<l?window.innerWidth-30:l);const c={bottom:0,left:0,overflow:"hidden",position:"absolute",right:0,top:0,zIndex:s.zIndex};return Mr({arrow:{alignItems:"center",color:s.arrowColor,display:"inline-flex",justifyContent:"center",position:"absolute"},beaconWrapper:{...eo,display:"inline-flex",borderRadius:"50%",position:"relative"},beacon:{height:s.beaconSize,width:s.beaconSize},beaconInner:{animation:"joyride-beacon-inner 1.2s infinite ease-in-out",backgroundColor:s.primaryColor,borderRadius:"50%",display:"block",height:"50%",left:"50%",opacity:.7,position:"absolute",top:"50%",transform:"translate(-50%, -50%)",width:"50%"},beaconOuter:{animation:"joyride-beacon-outer 1.2s infinite ease-in-out",backgroundColor:`rgba(${Mu(s.primaryColor).join(",")}, 0.2)`,border:`2px solid ${s.primaryColor}`,borderRadius:"50%",boxSizing:"border-box",display:"block",height:"100%",left:0,opacity:.9,position:"absolute",top:0,transformOrigin:"center",width:"100%"},buttonBack:{...Cn,color:s.primaryColor,marginLeft:"auto",marginRight:5},buttonClose:{...Cn,color:s.textColor,height:12,padding:8,position:"absolute",right:0,top:0,width:12},buttonPrimary:{...Cn,backgroundColor:s.primaryColor,color:s.backgroundColor},buttonSkip:{...Cn,color:s.textColor,fontSize:14},floater:{display:"inline-block",filter:"drop-shadow(0 0 3px rgba(0, 0, 0, 0.3))",maxWidth:"100%",transition:"opacity 0.3s"},loader:{alignItems:"center",display:"flex",height:48,inset:0,justifyContent:"center",pointerEvents:"none",position:"fixed",width:48,zIndex:s.zIndex+1},overlay:{...c,backgroundColor:s.overlayColor},spotlight:{},tooltip:{backgroundColor:s.backgroundColor,borderRadius:5,boxSizing:"border-box",color:s.textColor,fontSize:16,maxWidth:"100%",padding:12,position:"relative",width:l},tooltipContainer:{lineHeight:1.4,textAlign:"center"},tooltipTitle:{fontSize:18,margin:0},tooltipContent:{paddingBottom:12,paddingTop:12},tooltipFooter:{alignItems:"center",display:"flex",justifyContent:"flex-end"},tooltipFooterSpacer:{flex:1}},r)}const Uu=["after","arrowBase","arrowColor","arrowSize","arrowSpacing","backgroundColor","beaconSize","beaconTrigger","before","beforeTimeout","buttons","closeButtonAction","skipBeacon","dismissKeyAction","disableFocusTrap","hideOverlay","skipScroll","blockTargetInteraction","loaderDelay","offset","overlayClickAction","overlayColor","primaryColor","scrollDuration","scrollOffset","showProgress","spotlightPadding","spotlightRadius","targetWaitTimeout","textColor","width","zIndex"];function rl(t,s){if(!s)return null;const n=Mr(Eu,Ul(t,"arrowComponent","beaconComponent","floatingOptions","loaderComponent","locale","styles","tooltipComponent"),s),r=Mr(wu,t.options??{},Ul(s,...Uu)),l=zu(t,{...n,...r}),c=Mr(Su,t.floatingOptions??{},n.floatingOptions??{});return{...n,...r,locale:Mr(Qi,t.locale??{},n.locale||{}),floatingOptions:c,spotlightPadding:$u(r.spotlightPadding),styles:l}}function $u(t){return typeof t=="number"?{top:t,right:t,bottom:t,left:t}:{top:t?.top??0,right:t?.right??0,bottom:t?.bottom??0,left:t?.left??0}}function Fu(t,s,n){const{action:r}=s,l=n&&[Et.PREV,Et.NEXT].includes(r);return t.skipBeacon||t.placement==="center"||l}function to(t,s=!1){return us.plainObject(t)?t.target?!0:(ls(s,"tour","target is missing from the step"),!1):(ls(s,"tour","step must be an object"),!1)}function so(t,s=!1){return us.array(t)?t.every(n=>to(n,s)):(ls(s,"tour","steps must be an array"),!1)}var Bu=class{constructor(t){Jt(this,"beaconPosition",null);Jt(this,"debug");Jt(this,"eventListeners",new Map);Jt(this,"listeners",new Set);Jt(this,"props");Jt(this,"snapshot");Jt(this,"state");Jt(this,"steps");Jt(this,"tooltipPosition",null);Jt(this,"cleanupPositionData",()=>{this.beaconPosition=null,this.tooltipPosition=null});Jt(this,"getPositionData",t=>t==="beacon"?this.beaconPosition:this.tooltipPosition);Jt(this,"getServerSnapshot",()=>this.snapshot);Jt(this,"getSnapshot",()=>this.snapshot);Jt(this,"getEventState",()=>Vn(this.snapshot,"positioned"));Jt(this,"getState",()=>Vn(this.snapshot,"positioned"));Jt(this,"setPositionData",(t,s)=>{(t==="beacon"?this.beaconPosition:this.tooltipPosition)?.placement!==s.placement&&ls(this.debug,`step:${this.state.index}`,"positioned",`${t} ${s.placement}`),t==="beacon"?this.beaconPosition=s:this.tooltipPosition=s,(this.state.lifecycle===Ye.BEACON_BEFORE||this.state.lifecycle===Ye.TOOLTIP_BEFORE)&&!this.state.positioned&&this.updateState({positioned:!0});const n=this.getStep()?.floatingOptions?.onPosition;n&&n(s)});Jt(this,"setSteps",t=>{this.steps=t,this.updateState({size:t.length})});Jt(this,"dispatch",(t,s)=>{const n=this.eventListeners.get(t.type);if(n)for(const r of n)try{r(t,s)}catch{}});Jt(this,"on",(t,s)=>{let n=this.eventListeners.get(t);return n||(n=new Set,this.eventListeners.set(t,n)),n.add(s),()=>{n.delete(s)}});Jt(this,"subscribe",t=>(this.listeners.add(t),()=>{this.listeners.delete(t)}));Jt(this,"updateState",(t,s=!1)=>{const{controlled:n,index:r}=this.state,l=this.snapshot,c=n&&!s&&t.index!==void 0?r:t.index??r,o={action:t.action??this.state.action,controlled:n,index:c,lifecycle:t.lifecycle??this.state.lifecycle,origin:t.origin??null,positioned:t.positioned??this.state.positioned,scrolling:t.scrolling??this.state.scrolling,size:t.size??this.state.size,status:t.status??this.state.status,waiting:t.waiting??this.state.waiting},d=this.applyTransitions(o);if(this.state=d,!Wa(l,d)){this.snapshot=Object.freeze({...d});for(const p of this.listeners)p(this.snapshot)}});const{initialStepIndex:s,stepIndex:n,steps:r=[]}=t??{},l=us.number(n);let c=0;this.debug=t?.debug??!1,l?(c=n,us.number(s)&&ls(this.debug,"tour","initialStepIndex is ignored in controlled mode")):us.number(s)&&(s>=0&&s<r.length?c=s:r.length>0&&ls(this.debug,"tour","initialStepIndex is out of bounds")),this.props=t??{steps:[]},this.steps=r,this.state={action:Et.INIT,controlled:l,index:c,lifecycle:Ye.INIT,origin:null,positioned:!1,scrolling:!1,size:r.length,status:r.length?Dt.READY:Dt.IDLE,waiting:!1},this.snapshot=Object.freeze({...this.state})}applyTransitions(t){return t.status===Dt.WAITING&&t.size>0?{...t,status:Dt.RUNNING}:t}getStep(t){return rl(this.props,this.steps[t??this.state.index])}};function Yu(t){return new Bu(t)}function Gl(t,s){return Math.min(Math.max(t,0),s)}function Gu(t,s,n){const r=a.useRef(s),l=a.useRef(n);return r.current=s,l.current=n,a.useMemo(()=>{const c=()=>t.current.getSnapshot();return{close:(N=null)=>{const{index:R,status:S}=c();S===Dt.RUNNING&&t.current.updateState({action:Et.CLOSE,index:R+1,origin:N,lifecycle:Ye.COMPLETE,positioned:!1,scrolling:!1,waiting:!1})},go:N=>{const{controlled:R,size:S,status:C}=c();if(R){ls(r.current,"tour","go() is not supported in controlled mode");return}C===Dt.RUNNING&&t.current.updateState({action:Et.GO,index:N,lifecycle:Ye.COMPLETE,positioned:!1,scrolling:!1,status:N<S?C:Dt.FINISHED,waiting:!1})},info:()=>Vn(t.current.getSnapshot(),"positioned"),next:N=>{const{index:R,size:S,status:C}=c();C===Dt.RUNNING&&t.current.updateState({action:Et.NEXT,index:Gl(R+1,S),lifecycle:Ye.COMPLETE,origin:N,positioned:!1,scrolling:!1,waiting:!1})},open:()=>{const{status:N}=c();N===Dt.RUNNING&&t.current.updateState({action:Et.UPDATE,lifecycle:Ye.TOOLTIP_BEFORE,positioned:!1,scrolling:!1,waiting:!1})},prev:N=>{const{index:R,size:S,status:C}=c();C===Dt.RUNNING&&t.current.updateState({action:Et.PREV,index:Gl(R-1,S),lifecycle:Ye.COMPLETE,origin:N,positioned:!1,scrolling:!1,waiting:!1})},replay:N=>{const{lifecycle:R,status:S}=c();S!==Dt.RUNNING||R!==Ye.TOOLTIP||t.current.updateState({action:Et.REPLAY,lifecycle:Ye.COMPLETE,origin:N,positioned:!1,scrolling:!1,waiting:!1})},reset:(N=!1)=>{const{controlled:R}=c();if(R){ls(r.current,"tour","reset() is not supported in controlled mode");return}l.current(),t.current.updateState({action:Et.RESET,index:0,lifecycle:Ye.INIT,positioned:!1,scrolling:!1,status:N?Dt.RUNNING:Dt.READY,waiting:!1})},skip:N=>{const{status:R}=c();R===Dt.RUNNING&&t.current.updateState({action:Et.SKIP,lifecycle:Ye.COMPLETE,origin:N,positioned:!1,scrolling:!1,status:Dt.SKIPPED,waiting:!1})},start:N=>{const{index:R,size:S}=c();l.current(),t.current.updateState({action:Et.START,index:us.number(N)?N:R,lifecycle:Ye.INIT,positioned:!1,scrolling:!1,status:S?Dt.RUNNING:Dt.WAITING,waiting:!1},!0)},stop:(N=!1)=>{const{index:R,status:S}=c();[Dt.FINISHED,Dt.SKIPPED].includes(S)||t.current.updateState({action:Et.STOP,index:R+(N?1:0),lifecycle:Ye.COMPLETE,positioned:!1,scrolling:!1,status:Dt.PAUSED,waiting:!1})}}},[t])}const qu=new Set(["origin","positioned"]);function Wu(t,s){const n=a.useRef(null);a.useEffect(()=>{if(!s)return;const r=t.current.getSnapshot();return ls(!0,"tour","init",r),n.current=r,t.current.subscribe(l=>{const c=n.current;if(n.current=l,!c)return;const o={};let d=!1;for(const p of Object.keys(l))l[p]!==c[p]&&!qu.has(p)&&(o[p]={from:c[p],to:l[p]},(p==="status"||p==="size")&&(d=!0));Object.keys(o).length&&(!d&&l.index>=l.size||ls(!0,d?"tour":`step:${l.index}`,"state",o))})},[s,t])}function Hu(t,s,n){const r=a.useRef(t),l=a.useRef(s);return r.current=t,l.current=s,a.useCallback((c,o,d)=>{const p={...n.current.getEventState(),error:null,scroll:null,step:o,type:c,...d};r.current?.(p,l.current),n.current.dispatch(p,l.current)},[n])}function cr(t,s){return{hasChanged(n){return t[n]!==s[n]},hasChangedTo(n,r){const l=t[n],c=s[n];return Array.isArray(r)?r.includes(l)&&!r.includes(c):l===r&&c!==r},previous:s}}function Vu(t){const{addFailure:s,controls:n,emitEvent:r,previousState:l,props:c,state:o,step:d,store:p}=t,{action:y,index:j,lifecycle:b,positioned:h,scrolling:v,size:i,status:x}=o,m=Oi(d)??null,N=a.useRef(null),R=a.useRef(c),S=a.useRef(o),C=a.useRef(l),L=a.useRef(d),U=a.useRef(m),W=a.useRef(n),re=a.useRef(null),Z=a.useRef(null),O=a.useRef(null);R.current=c,S.current=o,C.current=l,L.current=d,U.current=m,W.current=n;const F=()=>{re.current&&(clearInterval(re.current),re.current=null),Z.current=null,O.current&&(O.current.cancel(),O.current=null)};a.useEffect(()=>{if(!C.current)return;const{hasChangedTo:D}=cr(S.current,C.current),$=D("action",[Et.NEXT,Et.PREV,Et.SKIP,Et.CLOSE,Et.REPLAY]),z=y===Et.START&&(N.current===Et.CLOSE||N.current===Et.REPLAY);($||z)&&(N.current=y)},[y]),a.useEffect(()=>{if(!C.current)return()=>{F()};const{hasChanged:D}=cr(S.current,C.current),$=L.current;if(D("index")&&F(),x!==Dt.RUNNING||!$||b!==Ye.INIT)return()=>{F()};const{hasChangedTo:z}=cr(S.current,C.current);z("status",Dt.RUNNING)&&[Dt.IDLE,Dt.READY,Dt.PAUSED].includes(C.current.status)&&r(ts.TOUR_START,$),p.current.cleanupPositionData();const{debug:me}=R.current;if($.before&&!O.current){ls(me,`step:${j}`,"before()",$),O.current={cancel:()=>{}},p.current.updateState({waiting:!0}),r(ts.STEP_BEFORE_HOOK,$,{action:N.current??S.current.action});const K=()=>{O.current=null,p.current.updateState({action:N.current??S.current.action,waiting:!1,lifecycle:Ye.READY})},te=new AbortController,I=$.beforeTimeout;O.current={cancel:()=>te.abort()};const B=I?setTimeout(()=>{te.signal.aborted||(ls(me,`step:${j}`,"before()","timed out",`${I}ms`),te.abort(),s($,"before_hook"),r(ts.ERROR,$,{error:new Error("Step before hook timed out")}),K())},I):null;$.before({...p.current.getState(),action:N.current??p.current.getState().action,step:$}).then(()=>{te.signal.aborted||(B&&clearTimeout(B),K())}).catch(Ne=>
10{te.signal.aborted||(B&&clearTimeout(B),s($,"before_hook"),r(ts.ERROR,$,{error:Ne instanceof Error?Ne:new Error(String(Ne))}),K())})}else if(!O.current){re.current&&Z.current!==$.target&&F();const K=ws($.target);if(K&&En(K))F(),p.current.updateState({action:N.current??Et.UPDATE,lifecycle:Ye.READY,waiting:!1});else if($.targetWaitTimeout===0)p.current.updateState({action:N.current??Et.UPDATE,lifecycle:Ye.READY,waiting:!1});else if(!re.current){const{targetWaitTimeout:te}=$,I=Date.now();Z.current=$.target,ls(me,`step:${j}`,"polling","started",`${te}ms`),p.current.updateState({waiting:!0}),re.current=setInterval(()=>{const B=ws($.target),Ne=Date.now()-I,Ue=Ne>=te;(B&&En(B)||Ue)&&(ls(me,`step:${j}`,"polling",B&&En(B)?"found":"timed out",`${Ne}ms`),F(),p.current.updateState({action:N.current??Et.UPDATE,lifecycle:Ye.READY,waiting:!1}))},100)}}return()=>{F()}},[s,r,j,b,x,p]),a.useEffect(()=>{if(!C.current)return;const{hasChanged:D,hasChangedTo:$,previous:z}=cr(S.current,C.current),me=L.current;if(!me)return;const K=ws(me.target),te=!!K;if(te&&En(K)){if($("lifecycle",Ye.READY)&&z.lifecycle===Ye.INIT&&r(ts.STEP_BEFORE,me,{action:N.current??S.current.action}),$("lifecycle",Ye.READY)){const I=S.current,B=Fu(me,I,R.current.continuous)?Ye.TOOLTIP:Ye.BEACON,Ne=ws(me.scrollTarget??me.spotlightTarget??me.target),Ue=Bl({isFirstStep:I.index===0,scrollToFirstStep:R.current.scrollToFirstStep,step:me,target:Ne,targetLifecycle:B}),$e=B===Ye.TOOLTIP?Ye.TOOLTIP_BEFORE:Ye.BEACON_BEFORE;ls(R.current.debug,`step:${j}`,"scroll",Ue?"needed":"skipped"),p.current.updateState({action:Et.UPDATE,lifecycle:$e,scrolling:Ue})}}else if(S.current.status===Dt.RUNNING&&b!==Ye.INIT&&b!==Ye.COMPLETE&&D("lifecycle")){ls(R.current.debug,`step:${j}`,te?"Target not visible":"Target not mounted",me),s(me,"target_not_found"),r(ts.TARGET_NOT_FOUND,me);const I=S.current;I.controlled||p.current.updateState({action:Et.UPDATE,index:I.index+(I.action===Et.PREV?-1:1),lifecycle:Ye.INIT})}},[s,r,j,b,p]),a.useEffect(()=>{if(!C.current)return;const{hasChangedTo:D,previous:$}=cr(S.current,C.current),z=L.current,me=U.current;if(z&&D("lifecycle",Ye.TOOLTIP_BEFORE)&&$.lifecycle===Ye.BEACON){const I=ws(z.scrollTarget??z.spotlightTarget??z.target);if(Bl({isFirstStep:S.current.index===0,scrollToFirstStep:R.current.scrollToFirstStep,step:z,target:I,targetLifecycle:Ye.TOOLTIP})){p.current.updateState({scrolling:!0,positioned:!1});return}}const K=b===Ye.BEACON_BEFORE||b===Ye.TOOLTIP_BEFORE;if(z&&K&&!v){const I=b===Ye.TOOLTIP_BEFORE?Ye.TOOLTIP:Ye.BEACON;p.current.updateState({action:Et.UPDATE,lifecycle:I})}z&&D("lifecycle",Ye.BEACON)&&r(ts.BEACON,z),z&&D("lifecycle",Ye.TOOLTIP)&&r(ts.TOOLTIP,z);const te=S.current;if((te.status===Dt.RUNNING||te.controlled&&te.status===Dt.PAUSED&&z)&&me&&D("lifecycle",Ye.COMPLETE)&&$.lifecycle===Ye.TOOLTIP&&(r(ts.STEP_AFTER,me,{action:N.current??Et.UPDATE,index:$.index??te.index,lifecycle:te.lifecycle}),me.after)){r(ts.STEP_AFTER_HOOK,me,{action:N.current??Et.UPDATE,index:$.index??te.index,lifecycle:te.lifecycle});try{me.after({...p.current.getState(),action:N.current??Et.UPDATE,index:$.index??te.index,lifecycle:te.lifecycle,step:me})}catch{}}},[r,b,h,v,p]),a.useEffect(()=>{if(!C.current)return;const{hasChangedTo:D,previous:$}=cr(S.current,C.current),z=L.current,me=U.current;if(D("action",Et.REPLAY)&&D("lifecycle",Ye.COMPLETE)){p.current.updateState({lifecycle:Ye.INIT});return}i&&!z&&b===Ye.INIT&&p.current.updateState({action:Et.UPDATE,lifecycle:Ye.COMPLETE,status:Dt.FINISHED}),!S.current.controlled&&x===Dt.RUNNING&&D("lifecycle",Ye.COMPLETE)&&j<i&&p.current.updateState({action:Et.UPDATE,lifecycle:Ye.INIT}),D("lifecycle",Ye.COMPLETE)&&j>=i&&p.current.updateState({action:Et.UPDATE,lifecycle:Ye.COMPLETE,status:Dt.FINISHED});const K=z??me??rl(R.current,R.current.steps[j-1]);if(K&&D("status",[Dt.FINISHED,Dt.SKIPPED])){let te;z?te=j:me?te=$.index??j:te=j-1,r(ts.TOUR_END,K,{index:te}),S.current.controlled||W.current.reset(),N.current=null}z&&D("action",Et.STOP)&&(N.current=null,r(ts.TOUR_STATUS,z)),z&&D("action",Et.RESET)&&(r(ts.TOUR_STATUS,z),N.current=null)}
10,[y,r,j,b,i,x,p])}function Ku({controls:t,emitEvent:s,props:n,state:r,store:l}){const{debug:c,initialStepIndex:o,run:d,stepIndex:p,steps:y}=n,j=a.useRef(void 0),b=a.useRef(r),h=a.useRef(t);b.current=r,h.current=t,a.useEffect(()=>{const v=j.current;if(j.current=n,!v||n===v)return;const{hasChanged:i}=cr(n,v);if(Wa(v.steps,y)||(so(y,c)?l.current.setSteps(y):(ls(c,"tour","Steps are not valid",y),s(ts.ERROR,y[0]??{target:"",content:""},{error:new Error("Steps are not valid")}))),i("run"))d?l.current.getState().size&&h.current.start(p??o):h.current.stop();else if(us.number(p)&&i("stepIndex")){const x=us.number(v.stepIndex)&&v.stepIndex<p?Et.NEXT:Et.PREV;[Dt.FINISHED,Dt.SKIPPED].includes(b.current.status)||l.current.updateState({action:x,index:p,lifecycle:Ye.INIT,positioned:!1},!0)}},[c,s,o,n,d,p,y,l])}function Ju(t,s){const{beaconPosition:n,lifecycle:r,scrollOffset:l,step:c}=s;if(c.scrollTarget||c.spotlightTarget)return Math.max(0,t);let o=t-c.spotlightPadding.top;if(r===Ye.BEACON_BEFORE&&n?.placement){const d=Qu(n);["bottom"].includes(n.placement)||(o+=Math.floor(d-l))}else if(r===Ye.TOOLTIP_BEFORE){const{placement:d}=c;if(d==="top"){const p=document.querySelector(".react-joyride__floater")?.getBoundingClientRect().height??0,y=c.floatingOptions?.hideArrow?0:c.arrowSize,j=c.offset+c.spotlightPadding.top+y;o-=p+j}else if(d==="left"||d==="right"){const p=document.querySelector(".react-joyride__floater")?.getBoundingClientRect().height??0,y=ws(c.target)?.getBoundingClientRect().height??0,j=l+c.spotlightPadding.top+y/2-p/2;j<l&&(o-=l-j)}}return Math.max(0,o)}function Qu(t){const s=t.middlewareData?.offset;return s?["left","right"].some(n=>t.placement.startsWith(n))?s.x:s.y:0}function Xu({emitEvent:t,previousState:s,props:n,state:r,step:l,store:c}){const{index:o,lifecycle:d,positioned:p,scrolling:y,status:j}=r,b=a.useRef(null),h=a.useRef(r),v=a.useRef(s),i=a.useRef(n),x=a.useRef(l);h.current=r,v.current=s,i.current=n,x.current=l,a.useEffect(()=>()=>{b.current?.()},[]),a.useEffect(()=>{if(!v.current||!x.current)return;const{hasChangedTo:m}=cr(h.current,v.current),N=x.current,{debug:R}=i.current,{scrollDuration:S}=N,C=d===Ye.BEACON_BEFORE||d===Ye.TOOLTIP_BEFORE;if(j===Dt.RUNNING&&C&&y&&m("positioned",!0)){const L=ws(N.scrollTarget??N.spotlightTarget??N.target),U=c.current.getPositionData("beacon"),W=Qr(L),re=W?!W.isSameNode(ms()):!1;b.current?.(),(async()=>{if(re&&!Xr(W)){const K=ms(),te=Pu(W),I={initial:K.scrollTop,target:te,element:K,duration:S};t(ts.SCROLL_START,N,{scroll:I});const{cancel:B,promise:Ne}=Yl(te,{element:K,duration:S});b.current=B,await Ne,t(ts.SCROLL_END,N,{scroll:I})}const O=Math.floor(Au(L,N.scrollOffset))||0,F=re?O:Ju(O,{beaconPosition:U,lifecycle:d,scrollOffset:N.scrollOffset,step:N});ls(R,`step:${o}
10`,"scroll",re?"custom":"document",`${O} â ${F}`);const D=W,$={initial:D.scrollTop,target:F,element:D,duration:S};t(ts.SCROLL_START,N,{scroll:$});const{cancel:z,promise:me}=Yl(F,{element:D,duration:S});b.current=z,await me,t(ts.SCROLL_END,N,{scroll:$}),c.current.updateState({scrolling:!1})})().catch(()=>{c.current.updateState({scrolling:!1})})}},[t,o,d,p,y,j,c])}function Zu(t){const s=Pc(()=>Tu(Cu,t),[t]),{debug:n,initialStepIndex:r,onEvent:l,run:c,stepIndex:o,steps:d}=s,p=a.useRef(Yu(s)),y=Uc.useSyncExternalStore(p.current.subscribe,p.current.getSnapshot,p.current.getServerSnapshot),[j,b]=a.useState([]),h=a.useCallback((L,U)=>{b(W=>[...W,{reason:U,step:L}])},[]),v=a.useCallback(()=>{b([])},[]);Wu(p,n);const i=Gu(p,n,v),x=Hu(l,i,p),{index:m,size:N,status:R}=y,S=Oi(y),C=a.useMemo(()=>rl(s,d[m]),[m,s,d]);return Ac(()=>{c&&N&&so(d,n)&&i.start(o??r)}),Ic(()=>{c&&N&&R===Dt.IDLE&&p.current.updateState({status:Dt.READY})},[c,N,R]),Ku({controls:i,emitEvent:x,props:s,state:y,store:p}),Vu({addFailure:h,controls:i,emitEvent:x,previousState:S,props:s,state:y,step:C,store:p}),Xu({emitEvent:x,previousState:S,props:s,state:y,step:C,store:p}),{controls:i,failures:j,mergedProps:s,state:y,step:C,store:p}}function ex(t){const[s,n]=a.useState(null);return a.useEffect(()=>{let r=null,l=!1;if(t)if(us.domElement(t))r=t,l=!0;else{const c=document.querySelector(t);c&&(r=c)}else{const c=document.createElement("div");c.id=ku,document.body.appendChild(c),r=c}return n(r),()=>{!r||l||r.parentNode===document.body&&document.body.removeChild(r)}},[t]),s}const tx={animation:"joyride-loader-spin 1s linear infinite",border:"5px solid rgba(0, 0, 0, 0.1)",borderRadius:"50%",borderTopColor:"#555"};function sx({nonce:t,step:s}){const{loaderComponent:n}=s,r=!!n;if(a.useEffect(()=>{if(r||document.getElementById("joyride-loader-animation"))return fn;const p=document.createElement("style");return p.id="joyride-loader-animation",t&&p.setAttribute("nonce",t),p.appendChild(document.createTextNode(` 11 @keyframes joyride-loader-spin { 12 to { transform: rotate(360deg); } 13 } 14 `)),document.head.appendChild(p),()=>{const y=document.getElementById("joyride-loader-animation");y?.parentNode&&y.parentNode.removeChild(y)}},[r,t]),n===null)return null;const{height:l,width:c,...o}=s.styles.loader;let d;if(n){const p=n;d=ct.createElement(p,{step:s})}else d=ct.createElement("div",{style:{...tx,height:l,width:c,borderTopColor:s.primaryColor}});return ct.createElement("div",{className:"react-joyride__loader","data-testid":"loader",style:o},d)}const rx={height:0,isFixed:!1,left:0,top:0,width:0};function sn(t,s){const n=ws(t);if(!n)return rx;const r=sl(n),l=Xr(n),c=Iu(n,s.top,l);return{height:Math.round((r?.height??0)+s.top+s.bottom),isFixed:l,left:Math.round((r?.left??0)-s.left),top:c,width:Math.round((r?.width??0)+s.left+s.right)}}function nx(t,s,n){const[r,l]=a.useState(()=>sn(t,s)),c=a.useRef(void 0),o=a.useRef(null),d=a.useRef(n),p=a.useRef(null),y=a.useCallback(()=>{clearTimeout(c.current),c.current=window.setTimeout(()=>{l(b=>{const h=sn(t,s);return b.top===h.top&&b.left===h.left&&b.width===h.width&&b.height===h.height&&b.isFixed===h.isFixed?b:h})},100)},[t,s]);a.useEffect(()=>{let b=null;const h=i=>{o.current=Qr(i,!0),o.current&&o.current.addEventListener("scroll",y,{passive:!0}),window.addEventListener("scroll",y,{passive:!0}),window.addEventListener("resize",y),typeof ResizeObserver<"u"&&(p.current=new ResizeObserver(y),p.current.observe(i)),l(sn(t,s))},v=ws(t);return v?h(v):(b=new MutationObserver(()=>{const i=ws(t);i&&(b?.disconnect(),b=null,h(i))}),b.observe(document.body,{childList:!0,subtree:!0})),()=>{b?.disconnect(),o.current&&o.current.removeEventListener("scroll",y),window.removeEventListener("scroll",y),window.removeEventListener("resize",y),p.current?.disconnect(),clearTimeout(c.current)}},[t,s,y]),a.useEffect(()=>{d.current&&!n&&l(sn(t,s)),d.current=n},[n,t,s]);let j=r;return d.current&&!n&&(j=sn(t,s)),j}function ax(t,s,n){let r=`M0 0H${t}V${s}H0Z`;return n&&(r+=` ${n}`),r}function ql(t,s,n,r,l){if(n<=0||r<=0)return"";const c=Math.max(0,Math.min(l,n/2,r/2));let o=`M${t+c} ${s}`;return o+=`H${t+n-c}`,o+=`A${c} ${c} 0 0 1 ${t+n} ${s+c}`,o+=`V${s+r-c}`,o+=`A${c} ${c} 0 0 1 ${t+n-c} ${s+r}`,o+=`H${t+c}`,o+=`A${c} ${c} 0 0 1 ${t} ${s+r-c}`,o+=`V${s+c}`,o+=`A${c} ${c} 0 0 1 ${t+c} ${s}Z`,o}const lx=[Ye.BEACON_BEFORE,Ye.BEACON];function ix(t){const{blockTargetInteraction:s,continuous:n,hideOverlay:r,lifecycle:l,onClickOverlay:c,overlayClickAction:o,placement:d,portalElement:p,scrolling:y,spotlightPadding:j,spotlightRadius:b,spotlightTarget:h,styles:v,target:i,waiting:x}=t,m=Lc(),N=nx(h??i,j,y||x),R=a.useRef(null),S=(l===Ye.TOOLTIP||l===Ye.TOOLTIP_BEFORE)&&d!=="center",[C,L]=a.useState(!1),U=p?R.current?.offsetParent:null,W=U?.clientWidth??m.width,re=U?.clientHeight??Ou()??m.height,Z=v.overlay?.backgroundColor??"rgba(0, 0, 0, 0.5)",O=a.useMemo(()=>{const{backgroundColor:K,mixBlendMode:te,...I}=v.overlay;return{height:re,pointerEvents:"none",...I}},[re,v.overlay]),F=S&&!y&&!x;a.useEffect(()=>{F?requestAnimationFrame(()=>L(!0)):L(!1)},[F]);const D=n&&lx.includes(l),$=!n&&l!==Ye.TOOLTIP;if(r||!x&&(D||$))return null;let z="";if(F)if(p&&U){const K=ws(h??i);if(K){const te=Fl(K),I=Fl(U);z=ql(te.left-I.left-j.left,te.top-I.top-j.top,K.offsetWidth+j.left+j.right,K.offsetHeight+j.top+j.bottom,b)}}else z=ql(N.left,N.top,N.width,N.height,b);const me=ax(W,re,z);return ct.createElement("div",{ref:R,"aria-hidden":"true",className:"react-joyride__overlay","data-testid":"overlay",style:O},ct.createElement("svg",{className:"react-joyride__spotlight","data-testid":"spotlight",style:{height:re,left:0,position:N.isFixed?"fixed":"absolute",top:0,width:W}},ct.createElement("path",{d:me,fill:Z,fillRule:"evenodd",onClick:c,style:{cursor:o?"pointer":"default",pointerEvents:"auto"}}),z&&ct.createElement("path",{d:z,fill:Z,style:{opacity:C?0:1,pointerEvents:s?"auto":"none",transition:"opacity 0.2s"}}),z&&Object.keys(v.spotlight).length>0&&ct.createElement("path",{d:z,fill:"none",style:{pointerEvents:"none"},...v.spotlight})))}function ro(t){const{children:s,element:n}=t;return n?gi.createPortal(s,n):null}const ox='a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), area[href], [tabindex]:not
14([tabindex="-1"]), [contenteditable]';function cx(t,s){const n=a.useRef(null);a.useEffect(()=>{if(!t)return fn;n.current=document.activeElement;const r=c=>{if(c.key!=="Tab")return;const o=[...t.querySelectorAll(ox)],{shiftKey:d}=c;if(!o.length)return;c.preventDefault();let p=document.activeElement?o.indexOf(document.activeElement):0;p===-1||!d&&p+1===o.length?p=0:d&&p===0?p=o.length-1:p+=d?-1:1,o[p].focus()};t.addEventListener("keydown",r,!1);let l;{const c=t.querySelector(s);c&&(l=setTimeout(()=>{c.focus({preventScroll:!0})},100))}return()=>{t.removeEventListener("keydown",r),l!==void 0&&clearTimeout(l),n.current?.focus({preventScroll:!0})}},[t,s])}function Zs(t,s,n){const[r]=t.split("-");switch(r){case"top":case"bottom":return{width:s,height:n};case"left":case"right":return{width:n,height:s};default:return null}}function dx(t,s,n){const[r]=t.split("-");switch(r){case"top":return{points:`0,0 ${s/2},${n} ${s},0`,...Zs(t,s,n)};case"bottom":return{points:`${s},${n} ${s/2},0 0,${n}`,...Zs(t,s,n)};case"left":return{points:`0,0 ${n},${s/2} 0,${s}`,...Zs(t,s,n)};case"right":return{points:`${n},${s} ${n},0 0,${s/2}`,...Zs(t,s,n)};default:return null}}function ux(t,s,n,r){if(!s)return{};const[l]=t.split("-");switch(l){case"top":return{bottom:-n,left:s.x??0,...Zs(t,r,n)};case"bottom":return{top:-n,left:s.x??0,...Zs(t,r,n)};case"left":return{right:-n,top:s.y??0,...Zs(t,r,n)};case"right":return{left:-n,top:s.y??0,...Zs(t,r,n)};default:return{}}}function xx({arrowComponent:t,arrowRef:s,base:n,placement:r,position:l,size:c,styles:o}){const d=t;let p=null;if(d){if(!Zs(r,n,c))return null;p=ct.createElement("span",{style:{flexShrink:0}},ct.createElement(d,{base:n,placement:r,size:c}))}else{const y=dx(r,n,c);if(!y)return null;p=ct.createElement("svg",{height:y.height,width:y.width,xmlns:"http://www.w3.org/2000/svg"},ct.createElement("polygon",{fill:"currentColor",points:y.points}))}return ct.createElement("span",{ref:s,className:"react-joyride__arrow","data-testid":"arrow",style:{...o,...ux(r,l,c,n),...l?{}:{visibility:"hidden"}}},p)}function mx(t){const{beaconComponent:s,continuous:n,index:r,isLastStep:l,locale:c,nonce:o,onInteract:d,shouldFocus:p,size:y,step:j,styles:b}=t,h=a.useRef(null),v=!!s;a.useEffect(()=>{if(v||document.getElementById("joyride-beacon-animation"))return fn;const m=document.createElement("style");m.id="joyride-beacon-animation",o&&m.setAttribute("nonce",o),m.appendChild(document.createTextNode(` 15 @keyframes joyride-beacon-inner { 16 20% { 17 opacity: 0.9; 18 } 19 20 90% { 21 opacity: 0.7; 22 } 23 } 24 25 @keyframes joyride-beacon-outer { 26 0% { 27 transform: scale(1); 28 } 29 30 45% { 31 opacity: 0.7; 32 transform: scale(0.75); 33 } 34 35 100% { 36 opacity: 0.9; 37 transform: scale(1); 38 } 39 } 40 `)),document.head.appendChild(m);const N=setTimeout(()=>{us.domElement(h.current)&&p&&h.current.focus()},0);return()=>{clearTimeout(N);const R=document.getElementById("joyride-beacon-animation");R?.parentNode&&R.parentNode.removeChild(R)}},[v,o,p]);const i=Js(c.open);let x;if(s){const m=s;x=ct.createElement(m,{continuous:n,index:r,isLastStep:l,size:y,step:j})}else x=ct.createElement("span",{style:b.beacon},ct.createElement("span",{style:b.beaconOuter}),ct.createElement("span",{style:b.beaconInner}));return ct.createElement("button",{ref:h,"aria-label":i,className:"react-joyride__beacon","data-testid":"button-beacon",onClick:d,onMouseEnter:d,style:b.beaconWrapper,title:i,type:"button"},x)}function px({styles:t,...s}){const{color:n,height:r,width:l,...c}=t;return ct.createElement("button",{style:c,type:"button",...s},ct.createElement("svg",{height:typeof r=="number"?`${r}px`:r,preserveAspectRatio:"xMidYMid",version:"1.1",viewBox:"0 0 18 18",width:typeof l=="number"?`${l}px`:l,xmlns:"http://www.w3.org/2000/svg"},ct.createElement("g",null,ct.createElement("path",{d:"M8.13911129,9.00268191 L0.171521827,17.0258467 C-0.0498027049,17.248715 -0.0498027049,17.6098394 0.171521827,17.8327545 C0.28204354,17.9443526 0.427188206,17.9998706 0.572051765,17.9998706 C0.71714958,17.9998706 0.862013139,17.9443526 0.972581703,17.8327545 L9.0000937,9.74924618 L17.0276057,17.8327545 C17.1384085,17.9443526 17.2832721,17.9998706 17.4281356,17.9998706 C17.5729992,17.9998706 17.718097,17.9443526 17.8286656,17.8327545 C18.0499901,17.6098862 18.0499901,17.2487618 17.8286656,17.0258467 L9.86135722,9.00268191 L17.8340066,0.973848225 C18.0553311,0.750979934 18.0553311,0.389855532 17.8340066,0.16694039 C17.6126821,-0.0556467968 17.254037,-0.0556467968 17.0329467,0.16694039 L9.00042166,8.25611765 L0.967006424,0.167268345 C0.745681892,-0.0553188426 0.387317931,-0.0553188426 0.165993399,0.167268345 C-0.0553311331,0.390136635 -0.0553311331,0.751261038 0.165993399,0.974176179 L8.13920499,9.00268191 L8.13911129,9.00268191 Z",fill:n}))))}function fx(t){const{backProps:s,closeProps:n,index:r,isLastStep:l,primaryProps:c,skipProps:o,step:d,tooltipProps:p}=t,{buttons:y,content:j,styles:b,title:h}=d,v={};y.includes("primary")&&(v.primary=ct.createElement("button",{"data-testid":"button-primary",style:b.buttonPrimary,type:"button",...c})),y.includes("skip")&&!l&&(v.skip=ct.createElement("button",{"aria-live":"off","data-testid":"button-skip",style:b.buttonSkip,type:"button",...o})),y.includes("back")&&r>0&&(v.back=ct.createElement("button",{"data-testid":"button-back",style:b.buttonBack,type:"button",...s})),v.close=y.includes("close")&&ct.createElement(px,{"data-testid":"button-close",styles:b.buttonClose,...n});const i=h?{"aria-labelledby":"joyride-tooltip-title","aria-describedby":"joyride-tooltip-content"}:{"aria-label":Js(j),"aria-describedby":"joyride-tooltip-content"};return ct.createElement("div",{key:"JoyrideTooltip",className:"react-joyride__tooltip","data-joyride-step":r,...d.id&&{"data-joyride-id":d.id},style:b.tooltip,...p,...i},ct.createElement("div",{style:b.tooltipContainer},h&&ct.createElement("h4",{id:"joyride-tooltip-title",style:b.tooltipTitle},h),ct.createElement("div",{id:"joyride-tooltip-content",style:b.tooltipContent},j)),y.some(x=>x==="back"||x==="primary"||x==="skip")&&ct.createElement("div",{style:b.tooltipFooter},ct.createElement("div",{style:b.tooltipFooterSpacer},v.skip),v.back,v.primary),v.close)}function hx(t){const{continuous:s,controls:n,index:r,isLastStep:l,size:c,step:o}=t,d=N=>{N.preventDefault(),n.prev(bs.BUTTON_BACK)},p=N=>{N.preventDefault(),o.closeButtonAction==="skip"?n.skip(bs.BUTTON_CLOSE):o.closeButtonAction==="replay"?n.replay(bs.BUTTON_CLOSE):n.close(bs.BUTTON_CLOSE)},y=N=>{if(N.preventDefault(),!s){n.close(bs.BUTTON_PRIMARY);return}n.next(bs.BUTTON_PRIMARY)},j=N=>{N.preventDefault(),n.skip(bs.BUTTON_SKIP)},b=()=>{const{back:N,close:R,last:S,next:C,nextWithProgress:L,skip:U}=o.locale,W=Js(N),re=Js(R),Z=Js(S),O=Js(C),F=Js(U);let D=R,$=re;if(s){if(D=C,$=O,o.showProgress&&!l){const z=Js(L,{step:r+1,steps:c});D=La(L,r+1,c),$=z}l&&(D=S,$=Z)}return{backProps:{"aria-label":W,children:N,"data-action":"back",onClick:d,role:"button",title:W},closeProps:{"aria-label":re,children:R,"data-action":"close",onClick:p,role:"button",title:re},primaryProps:{"aria-label":$,children:D,"data-action":"primary",onClick:y,role:"button",title:$},skipProps:{"aria-label":F,children:U,"data-action":"skip",onClick:j,role:"button",title:F},tooltipProps:{"aria-modal":!0,role:"alertdialog"}}},{arrowComponent:h,beaconComponent:v,tooltipComponent:i,...x}=o;let m;if(i){const N=i;m=ct.createElement(N,{...b(),continuous:s,controls:n,index:r,isLastStep:l,size:c,step:x})}else m=ct.createElement(fx,{...b(),continuous:s,controls:n,index:r,isLastStep:l,size:c,step:x});return m}function bx(t){if(t.startsWith("left"))return["top","bottom"];if(t.startsWith("right"))return["bottom","top"]}function gx(t,s,n){return t?[vu()]:s.floatingOptions?.flipOptions===!1?[]:[ju({crossAxis:!1,fallbackPlacements:bx(n),padding:20,...s.floatingOptions?.flipOptions})]}function _x(t){const{continuous:s,controls:n,index:r,lifecycle:l,nonce:c,open:o,portalElement:d,setPositionData:p,setTooltipRef:y,shouldScroll:j,size:b,step:
40h,target:v,updateState:i}=t,x=a.useRef(null),m=a.useRef({}),N=a.useRef({}),R=h.placement==="center",S=h.placement==="auto",C=a.useMemo(()=>({getBoundingClientRect:()=>({x:window.innerWidth/2,y:window.innerHeight/2,top:window.innerHeight/2,left:window.innerWidth/2,bottom:window.innerHeight/2,right:window.innerWidth/2,width:0,height:0})}),[]),L=a.useMemo(()=>Zi(v)?Qr(v):void 0,[v]),U=a.useMemo(()=>Xr(v),[v]),W=a.useMemo(()=>L?{boundary:L,rootBoundary:"viewport"}:{},[L]),re=R||S?"bottom":h.placement,Z=R?"fixed":h.floatingOptions?.strategy??(h.isFixed||U?"fixed":"absolute"),O=a.useMemo(()=>R?[{name:"center",fn:({rects:B})=>({x:(window.innerWidth-B.floating.width)/2,y:(window.innerHeight-B.floating.height)/2})}]:[zl(({placement:B})=>{let Ne="right";B.startsWith("top")?Ne="top":B.startsWith("bottom")?Ne="bottom":B.startsWith("left")&&(Ne="left");const Ue=h.spotlightTarget?0:h.spotlightPadding[Ne];return h.offset+Ue+(h.floatingOptions?.hideArrow?0:h.arrowSize)},[h.offset,h.spotlightPadding,h.spotlightTarget,h.arrowSize,h.floatingOptions?.hideArrow]),...gx(S,h,re),yu({padding:10,...W,...h.floatingOptions?.shiftOptions}),...h.floatingOptions?.hideArrow?[]:[Nu({element:x,padding:h.arrowSpacing},[h.arrowSpacing,h.arrowBase])],...h.floatingOptions?.middleware??[]],[R,h,S,re,W]),F=Ml({...R?{elements:{reference:C}}:{},placement:re,strategy:Z,middleware:O}),D=Ml({strategy:Z,placement:h.beaconPlacement??(S||R?"bottom":h.placement),middleware:a.useMemo(()=>[zl(h.floatingOptions?.beaconOptions?.offset??-18)],[h.floatingOptions?.beaconOptions?.offset]),whileElementsMounted:Pl});N.current=F.middlewareData,m.current=D.middlewareData,a.useEffect(()=>{const{floating:B,reference:Ne}=F.elements;if(!(!Ne||!B||l!==Ye.TOOLTIP))return Pl(Ne,B,F.update,h.floatingOptions?.autoUpdate)},[l,F.update,h.floatingOptions?.autoUpdate,h.target,F.elements]),a.useEffect(()=>{!R&&v&&F.refs.setReference(v),v&&D.refs.setReference(v)},[D.refs,R,v,F.refs]),a.useEffect(()=>{F.isPositioned&&p("tooltip",{placement:F.placement,x:F.x??0,y:F.y??0,middlewareData:N.current})},[p,F.isPositioned,F.placement,F.x,F.y]),a.useEffect(()=>{D.isPositioned&&p("beacon",{placement:D.placement,x:D.x??0,y:D.y??0,middlewareData:m.current})},[p,D.isPositioned,D.placement,D.x,D.y]);const $=h.zIndex+1,z=a.useCallback(B=>{B.type==="mouseenter"&&h.beaconTrigger!=="hover"||i({lifecycle:Ye.TOOLTIP_BEFORE,positioned:!1})},[h.beaconTrigger,i]),me=a.useCallback(B=>{B&&(F.refs.setFloating(B),y(B))},[F.refs,y]),{arrow:K,floater:te}=h.styles;let I=null;if(l===Ye.TOOLTIP||l===Ye.TOOLTIP_BEFORE){const B=$l({...te,...F.floatingStyles,zIndex:$,opacity:o&&F.isPositioned?1:0,...!o&&{transition:"none"}});I=ct.createElement("div",{ref:me,className:"react-joyride__floater","data-testid":"floater",id:`react-joyride-step-${r}`,style:B},ct.createElement(hx,{continuous:s,controls:n,index:r,isLastStep:r+1===b,size:b,step:h}),!R&&!h.floatingOptions?.hideArrow&&ct.createElement(xx,{arrowComponent:h.arrowComponent,arrowRef:x,base:h.arrowBase,placement:F.placement,position:F.middlewareData.arrow,size:h.arrowSize,styles:K}))}else(l===Ye.BEACON||l===Ye.BEACON_BEFORE)&&(I=ct.createElement("div",{ref:D.refs.setFloating,className:"react-joyride__floater","data-testid":"floater-beacon",id:`react-joyride-step-${r}-beacon`,style:$l({...D.floatingStyles,zIndex:$})},ct.createElement(mx,{beaconComponent:h.beaconComponent,continuous:s,index:r,isLastStep:r+1===b,locale:h.locale,nonce:c,onInteract:z,shouldFocus:j,size:b,step:h,styles:h.styles})));return ct.createElement(ro,{element:d},I)}function yx(t){const{continuous:s,controls:n,index:r,lifecycle:l,nonce:c,portalElement:o,setPositionData:d,shouldScroll:p,size:y,step:j,updateState:b}=t,[h,v]=a.useState(null);cx(j.disableFocusTrap?null:h,"[data-action=primary]");const i=ws(j.target),x=l===Ye.TOOLTIP;return!to(j)||!us.domElement(i)?null:ct.createElement(_x,{key:`JoyrideStep-${r}`,continuous:s,controls:n,index:r,lifecycle:l,nonce:c,open:x,portalElement:o,setPositionData:d,setTooltipRef:v,shouldScroll:p,size:y,step:j,target:i,updateState:b})}function jx({controls:t,mergedProps:s,state:n,step:r,store:l}
40){const{continuous:c,debug:o,nonce:d,portalElement:p,scrollToFirstStep:y}=s,j=ex(p),{index:b,lifecycle:h,status:v}=n,i=v===Dt.RUNNING,[x,m]=a.useState(!1),N=a.useRef(null),R=r?.loaderDelay??0;a.useEffect(()=>(n.waiting?R===0?m(!0):N.current=setTimeout(()=>{m(!0)},R):m(!1),()=>{N.current&&(clearTimeout(N.current),N.current=null)}),[R,n.waiting]),a.useEffect(()=>{if(!i)return;const L=U=>{!r||h!==Ye.TOOLTIP||U.key==="Escape"&&r.dismissKeyAction&&(r.dismissKeyAction==="next"?t.next(bs.KEYBOARD):r.dismissKeyAction==="replay"?t.replay(bs.KEYBOARD):t.close(bs.KEYBOARD))};return document.body.addEventListener("keydown",L,{passive:!0}),()=>{document.body.removeEventListener("keydown",L)}},[t,i,h,r]);const S=a.useCallback(()=>{switch(r?.overlayClickAction){case"close":t.close(bs.OVERLAY);break;case"next":t.next(bs.OVERLAY);break;case"replay":t.replay(bs.OVERLAY);break}},[t,r?.overlayClickAction]);if(!r||!i)return null;const C=n.action===Et.START&&!r.skipBeacon&&r.placement!=="center";return ct.createElement(ct.Fragment,null,h!==Ye.INIT&&ct.createElement(yx,{...n,continuous:c,controls:t,debug:o,nonce:d,portalElement:j,setPositionData:l.current.setPositionData,shouldScroll:!r.skipScroll&&(b!==0||y),step:r,updateState:l.current.updateState}),ct.createElement(ro,{element:j},ct.createElement(ct.Fragment,null,x&&ct.createElement(sx,{nonce:d,step:r}),!C&&ct.createElement(ix,{...r,continuous:c,lifecycle:h,onClickOverlay:S,portalElement:p?j:null,scrolling:n.scrolling,waiting:n.waiting}))))}function vx(t){const{controls:s,failures:n,mergedProps:r,state:l,step:c,store:o}=Zu(t);return{controls:s,failures:n,on:a.useCallback((d,p)=>o.current.on(d,p),[o]),state:a.useMemo(()=>Vn(l,"positioned"),[l]),step:c,Tour:tl()?ct.createElement(jx,{controls:s,mergedProps:r,state:l,step:c,store:o}):null}}function Nx(t){const{Tour:s}=vx(t);return s}function wx(t){return tl()?ct.createElement(Nx,t):null}const Sx=6e3,Ex={options:{primaryColor:"#2563eb",textColor:"#0f172a",zIndex:1e4,arrowColor:"#ffffff",backgroundColor:"#ffffff",overlayColor:"rgba(15, 23, 42, 0.4)"},tooltip:{borderRadius:16,fontSize:14},buttonPrimary:{backgroundColor:"#2563eb",color:"#ffffff",borderRadius:10,fontWeight:700,padding:"8px 16px"},buttonBack:{color:"#94a3b8"},buttonSkip:{color:"#94a3b8"},spotlight:{fill:"transparent",stroke:"#f97316",strokeWidth:3,strokeDasharray:"6 4"}},Cx=t=>({back:t("not_found_back"),close:t("profile_close_button"),last:t("topup_understood"),next:t("onboarding_next"),skip:t("onboarding_skip")}),kx=t=>[{target:'[data-tour="nav-import"]',title:t("import_title"),content:t("onboarding_import0_content"),skipBeacon:!0,buttons:[],placement:"right",spotlightPadding:4,spotlightRadius:12},{target:'[data-tour="nav-import"]',title:t("onboarding_great"),content:t("onboarding_import1_content"),skipBeacon:!0,placement:"right",spotlightPadding:4,spotlightRadius:12,buttons:["primary"]},{target:'[data-tour="nav-marketplaces"]',title:t("onboarding_import2_title"),content:t("onboarding_import2_content"),skipBeacon:!0,placement:"bottom",spotlightPadding:8,spotlightRadius:12,buttons:["back","primary"]},{target:'[data-tour="nav-extension-link"]',title:t("onboarding_import3_title"),content:t("onboarding_import3_content"),skipBeacon:!0,placement:"top",spotlightPadding:6,spotlightRadius:8,buttons:["back","primary"]},{target:"body",placement:"center",title:t("onboarding_import4_title"),content:e.jsxs("div",{children:[e.jsx("img",{src:wr("/onboarding/extension-widget.png"),alt:t("onboarding_import4_img_alt"),style:{width:"100%",borderRadius:8,marginBottom:12}}),e.jsx("p",{children:t("onboarding_import4_p1")}),e.jsx("p",{style:{marginTop:8},children:t("onboarding_import4_p2")})]}),skipBeacon:!0,width:420,buttons:["back","primary"]}],Rx=t=>({target:"body",placement:"center",title:t("onboarding_guest_title"),content:t("onboarding_guest_content"),skipBeacon:!0,buttons:["back","primary"]}),Tx=t=>[{target:'[data-tour="nav-orders"]',title:t("layout_nav_orders"),content:t("onboarding_orders_content"),skipBeacon:!0,placement:"right",spotlightPadding:4,spotlightRadius:12,buttons:["primary"]},{target:'[data-tour="order-stats"]',title:t("onboarding_stats_title"),content:t("onboarding_stats_content"),skipBeacon:!0,placement:"bottom",spotlightPadding:8,spotlightRadius:12,buttons:["primary"]},{target:'[data-tour="order-tabs"]',title:t("onboarding_statuses_title"),content:e.jsxs("div",{children:[e.jsx("p",{children:t("onboarding_statuses_p1")}),e.jsx("p",{style:{marginTop:8},children:t("onboarding_statuses_p2")})]}),skipBeacon:!0,placement:"bottom",spotlightPadding:8,spotlightRadius:12,buttons:["back","primary"]},{target:'[data-tour="nav-payments"]',title:t("layout_nav_payments"),content:t("onboarding_payments_content"),skipBeacon:!0,placement:"right",spotlightPadding:4,spotlightRadius:12,buttons:["primary"]},{target:'[data-tour="payment-history-list"]',title:t("onboarding_topups_title"),content:e.jsxs("div",{children:[e.jsx("p",{children:t("onboarding_topups_p1")}),e.jsx("p",{style:{marginTop:8},children:t("onboarding_topups_p2")})]}),skipBeacon:!0,placement:"bottom",spotlightPadding:8,spotlightRadius:12,buttons:["primary"]},{target:'[data-tour="header-rates"]',title:t("onboarding_rates_title"),content:t("onboarding_rates_content"),skipBeacon:!0,placement:"bottom",spotlightPadding:6,spotlightRadius:12,buttons:["back","primary"]},{target:'[data-tour="header-balance"]',title:t("onboarding_balance_title"),content:e.jsxs("div",{children:[e.jsxs("p",{children:[e.jsx("b",{children:t("layout_label_bonus")})," ",t("onboarding_balance_bonus_desc")]}),e.jsxs("p",{style:{marginTop:8},children:[e.jsx("b",{children:t("layout_label_delivery")})," ",t("onboarding_balance_delivery_desc")]}),e.jsxs("p",{style:{marginTop:8},children:[e.jsx("b",{children:t("layout_label_balance")})," ",t("onboarding_balance_balance_desc")]})]}),skipBeacon:!0,placement:"bottom",spotlightPadding:6,spotlightRadius:12,buttons:["back","primary"]},{target:'[data-tour="nav-messages"]',title:t("layout_nav_messages"),content:t("onboarding_messages_content"),skipBeacon:!0,placement:"right",spotlightPadding:4,spotlightRadius:12,buttons:["primary"]},{target:'[data-tour="notifications-panel"]',title:t("messages_tab_notifications"),content:t("onboarding_notifications_content"),skipBeacon:!0,placement:"left",spotlightPadding:8,spotlightRadius:12,buttons:["primary"]}],Dx={5:"ORDERS",8:"PAYMENTS",12:"MESSAGES"},Ox=({run:t,currentView:s,isAuthenticated:n,onNavigate:r,onFinish:l,onStalled:c})=>{const{t:o,lang:d}=qt(),[p,y]=a.useState(0),j=a.useMemo(()=>{const v=kx(o),i=Tx(o),x=Rx(o);return(n?[...v,...i]:[...v,x]).map(N=>({...N,disableScrolling:!0}))},[n,d]),b=a.useMemo(()=>Cx(o),[d]);if(a.useEffect(()=>{if(!t)return;const v=(i,x)=>{const m=setInterval(()=>{document.querySelector(i)&&(clearInterval(m),clearTimeout(N),y(x))},150),N=setTimeout(()=>{clearInterval(m),c()},Sx);return()=>{clearInterval(m),clearTimeout(N)}};if(p===0&&s==="IMPORT")y(1);else{if(p===5&&s==="ORDERS")return v('[data-tour="order-stats"]',6);if(p===8&&s==="PAYMENTS")return v('[data-tour="payment-history-list"]',9);if(p===12&&s==="MESSAGES")return v('[data-tour="notifications-panel"]',13)}},[t,p,s,c]),a.useEffect(()=>{t||y(0)},[t]),a.useEffect(()=>{if(!t)return;const v=j[p];if(!v||v.target==="body")return;const i=setTimeout(()=>{document.querySelector(v.target)?.scrollIntoView({behavior:"smooth",block:"center"})},80);return()=>clearTimeout(i)},[t,p,j]),!t)return null;const h=v=>{if(v.status===Dt.FINISHED||v.status===Dt.SKIPPED||v.action===Et.CLOSE){l();return}if(v.type===ts.TARGET_NOT_FOUND){c();return}if(v.type===ts.STEP_AFTER)if(v.action===Et.NEXT){const i=Dx[v.index];if(i){r(i);return}y(v.index+1)}else v.action===Et.PREV&&y(v.index-1)};return e.jsx(wx,{run:t,stepIndex:p,steps:j,continuous:!0,styles:Ex,locale:b,onEvent:h})},Wl={ru:e.jsxs(e.Fragment,{children:[e.jsx("rect",{width:"3",height:"0.667",fill:"#fff"}),e.jsx("rect",{y:"0.667",width:"3",height:"0.667",fill:"#0039A6"}),e.jsx("rect",{y:"1.333",width:"3",height:"0.667",fill:"#D52B1E"})]}),kk:e.jsxs(e.Fragment,{children:[e.jsx("rect",{width:"3",height:"2",fill:"#00AFCA"}),e.jsx("circle",{cx:"1.5",cy:"1",r:"0.46",fill:"#FEC50C"}),e.jsx("circle",{cx:"1.5",cy:"1",r:"0.3",fill:"#00AFCA"})]}),ky:e.jsxs(e.Fragment,{children:[e.jsx("rect",{width:"3",height:"2",fill:"#E8112D"}),e.jsx("circle",{cx:"1.5",cy:"1",r:"0.5",fill:"#FFEF00"}),e.jsx("circle",{cx:"1.5",cy:"1",r:"0.2",fill:"#E8112D"})]}),be:e.jsxs(e.Fragment,{children:[e.jsx("rect",{width:"3",height:"2",fill:"#D22730"}),e.jsx("rect",{y:"1.333",width:"3",height:"0.667",fill:"#007A3D"}),e.jsx("rect",{width:"0.3",height:"2",fill:"#fff"})]})};function Hl({code:t,className:s}){return e.jsx("svg",{viewBox:"0 0 3 2",className:s||"w-5 h-3.5 rounded-sm shrink-0",children:Wl[t]||Wl.ru})}function Ma({compact:t=!1}){const{lang:s,setLang:n,languages:r,t:l}
40=qt(),[c,o]=a.useState(!1),d=a.useRef(null);a.useEffect(()=>{if(!c)return;const y=j=>{d.current&&!d.current.contains(j.target)&&o(!1)};return document.addEventListener("mousedown",y),()=>document.removeEventListener("mousedown",y)},[c]);const p=r.find(y=>y.code===s)||r[0];return e.jsxs("div",{className:"relative",ref:d,children:[e.jsxs("button",{onClick:()=>o(y=>!y),title:l("layout_language_switcher_title"),className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg border border-slate-200 text-slate-600 hover:bg-slate-50 transition-colors text-sm font-bold",children:[e.jsx("span",{className:"text-base leading-none md:hidden",children:p.flag}),e.jsx(Hl,{code:p.code,className:"hidden md:block w-6 h-4 rounded-sm shadow-sm shrink-0"}),!t&&e.jsx("span",{className:"hidden sm:inline",children:p.nativeName})]}),c&&e.jsx("div",{className:"absolute right-0 mt-1.5 w-40 bg-white border border-slate-200 rounded-xl shadow-lg z-50 overflow-hidden",children:r.map(y=>e.jsxs("button",{onClick:()=>{n(y.code),o(!1)},className:`w-full flex items-center gap-2 px-3 py-2.5 text-sm font-medium hover:bg-slate-50 transition-colors ${y.code===s?"text-blue-600 bg-blue-50":"text-slate-700"}`,children:[e.jsx("span",{className:"text-base leading-none md:hidden",children:y.flag}),e.jsx(Hl,{code:y.code,className:"hidden md:block w-6 h-4 rounded-sm shadow-sm shrink-0"}),e.jsx("span",{className:"flex-1 text-left",children:y.nativeName}),y.code===s&&e.jsx(Kt,{size:14})]},y.code))})]})}function Ix(t,s){let n=0;for(const r of t){if(!r.delivery_invoice||r.delivery_paid||r.status==="RECEIVED")continue;const l=Math.round((r.delivery_invoice.totalUSD??0)*s),c=r.delivery_prepaid_amount??0,o=l-c;o>0&&(n+=o)}return n}function no(t,s){const[n,r]=a.useState([]),l=18e4,c=a.useRef(0);return a.useEffect(()=>{if(!t){r([]);return}let o=!1,d=!1;const p=async(b=!1)=>{if(!d&&!(!b&&Date.now()-c.current<l)){c.current=Date.now();try{const{data:h,error:v}=await Re("orders",{user_id:t},{select:"delivery_invoice,delivery_prepaid_amount,delivery_paid,status"});if(hi(v)){d=!0,clearInterval(y);return}o||r(h||[])}catch{}}};p(!0);const y=setInterval(()=>{document.visibilityState==="visible"&&p()},l),j=()=>{document.visibilityState==="visible"&&p()};return document.addEventListener("visibilitychange",j),window.addEventListener("focus",j),()=>{o=!0,clearInterval(y),document.removeEventListener("visibilitychange",j),window.removeEventListener("focus",j)}},[t]),a.useMemo(()=>Ix(n,s),[n,s])}const Vl="tradehub_onboarding_seen",Qs=t=>Number(t.rate)||0,Px=()=>{try{const t=localStorage.getItem("tradehub_currencies");if(t){const s=JSON.parse(t);if(Array.isArray(s)&&s.length>0)return{cny:Qs(s.find(n=>n.code==="CNY")||{rate:13.5}),usd:Qs(s.find(n=>n.code==="USD")||{rate:92}),usdt:Qs(s.find(n=>n.code==="USDT")||{rate:93})}}}catch{}return{cny:13.5,usd:92,usdt:93.5}};function Ax({currentView:t,onChangeView:s,userProfile:n,children:r,unreadMessages:l=0,unreadNotifications:c=0,unreadSupport:o=0,cnyRate:d,usdRate:p,isAuthenticated:y=!0,onPayDelivery:j,onSearchOrder:b}){const{t:h}=qt(),[v,i]=a.useState(""),[x,m]=a.useState(!1),N=()=>{const V=v.trim();V&&b?.(V)},[R,S]=a.useState(!1),[C,L]=a.useState(()=>{try{return localStorage.getItem("tradehub_sidebar_collapsed")==="1"}catch{return!1}}),U=()=>{L(V=>{const ye=!V;try{localStorage.setItem("tradehub_sidebar_collapsed",ye?"1":"0")}catch{}return ye})},[W,re]=a.useState(Px),[Z,O]=a.useState(null),[F,D]=a.useState(!1);a.useEffect(()=>{try{y&&window.innerWidth>=768&&!localStorage.getItem(Vl)&&D(!0)}catch{}},[y]);const $=()=>{try{localStorage.setItem(Vl,"1")}catch{}D(!1)},[z,me]=a.useState(!1),[K,te]=a.useState(!1),I=()=>{te(!1),$(),me(!0)},B=()=>{me(!1),te(!0)},Ne=a.useRef(null);a.useEffect(()=>{const V=Ne.current;if(!V||!z)return;const ye=Ie=>Ie.preventDefault();return V.addEventListener("wheel",ye,{passive:!1}),V.addEventListener("touchmove",ye,{passive:!1}),()=>{V.removeEventListener("wheel",ye),V.removeEventListener("touchmove",ye)}},[z]),a.useEffect(()=>{d&&re(V=>({...V,cny:d}))},[d]),a.useEffect(()=>{p&&re(V=>({...V,usd:p}))},[p]);const[Ue,$e]=a.useState(0);a.useEffect(()=>{(async()=>{try{const{data:Oe}=await At.from("app_settings").select("currencies, updated_at").limit(1).single(),we=Oe?.currencies;if(Array.isArray(we)&&we.length>0){re({cny:Qs(we.find(Le=>Le.code==="CNY")||{rate:13.5}),usd:Qs(we.find(Le=>Le.code==="USD")||{rate:92}),usdt:Qs(we.find(Le=>Le.code==="USDT")||{rate:93})}),Oe?.updated_at&&O(Oe.updated_at);try{localStorage.setItem("tradehub_currencies",JSON.stringify(we)),Oe?.updated_at&&localStorage.setItem("tradehub_currencies_updated_at",Oe.updated_at)}catch{}return}}catch{}const ye=localStorage.getItem("tradehub_currencies");if(ye)try{const Oe=JSON.parse(ye);re({cny:Qs(Oe.find(we=>we.code==="CNY")||{rate:13.5}),usd:Qs(Oe.find(we=>we.code==="USD")||{rate:92}),usdt:Qs(Oe.find(we=>we.code==="USDT")||{rate:93})})}catch{}const Ie=localStorage.getItem("tradehub_currencies_updated_at");Ie&&O(Ie)})()},[]);const H=no(n?.id,W.usd),le=Math.max(c,Ue),Qe=[{id:"HOME",label:h("layout_nav_home"),icon:cl},{id:"ORDERS",label:h("layout_nav_orders"),icon:js},{id:"IMPORT",label:h("layout_nav_import"),icon:Sa},{id:"CALCULATOR",label:h("layout_nav_calculator"),icon:un},{id:"MESSAGES",label:h("layout_nav_messages"),icon:zr},{id:"PAYMENTS",label:h("layout_nav_payments"),icon:Xs},{id:"SELF_BUYOUT",label:h("layout_nav_selfbuyout"),icon:an},{id:"MY_QUESTIONS",label:h("layout_nav_my_questions"),icon:Ea},{id:"PROFILE",label:h("layout_nav_profile"),icon:gs}],k=()=>{uo(),At.auth.signOut().catch(()=>{}),window.location.href=bi},xe=n?.name||n?.email||h("layout_default_username");n?.friendly_id&&`${n.friendly_id}`;const de=n?.balance||0;return e.jsxs("div",{className:"h-screen overflow-hidden bg-slate-50 font-sans text-slate-900 flex flex-col",children:[e.jsxs("header",{className:"bg-white border-b border-slate-200 md:h-16 px-4 md:px-6 flex flex-col md:flex-row md:items-center md:justify-between sticky top-0 z-20 shadow-sm",children:[e.jsxs("div",{className:"flex items-center justify-between w-full h-14 md:h-16 md:flex-1",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("button",{className:"md:hidden p-1 text-slate-500",onClick:()=>S(!R),"aria-label":R?"ÐакÑÑÑÑ Ð¼ÐµÐ½Ñ":"ÐÑкÑÑÑÑ Ð¼ÐµÐ½Ñ",children:R?e.jsx(bt,{size:24}):e.jsx(So,{size:24})}),e.jsx("div",{className:"flex items-center gap-3 cursor-pointer",onClick:()=>s("HOME"),children:e.jsx("span",{className:"text-xl font-bold text-slate-900 tracking-tight",children:"GOODS CHINA"})}),e.jsxs("div",{className:"hidden md:flex flex-col items-start ml-3","data-tour":"header-rates",children:[e.jsxs("div",{className:"flex items-center border border-slate-200 rounded-xl overflow-hidden shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-1.5 px-3.5 py-2",children:[e.jsx("span",{className:"text-sm font-bold text-emerald-500",children:"Â¥"}),e.jsxs("span",{className:"text-[13px] font-bold text-slate-800",children:[W.cny.toFixed(2),"â½"]})]}),e.jsx("div",{className:"w-px h-5 bg-slate-200"}),e.jsxs("div",{className:"flex items-center gap-1.5 px-3.5 py-2",children:[e.jsx("span",{className:"text-sm font-bold text-emerald-500",children:"$"}),e.jsxs("span",{className:"text-[13px] font-bold text-slate-800",children:[W.usd.toFixed(2),"â½"]})]}),e.jsx("div",{className:"w-px h-5 bg-slate-200"}),e.jsxs("div",{className:"flex items-center gap-1.5 px-3.5 py-2",children:[e.jsx("span",{className:"text-[10px] font-extrabold text-emerald-500 tracking-tight",children:"USDT"}),e.jsxs("span",{className:"text-[13px] font-bold text-slate-800",children:[W.usdt.toFixed(2),"Â¥"]})]})]}),e.jsx("div",{className:`text-[11px] font-semibold text-emerald-500 px-1 mt-0.5 ${Z?"visible":"invisible"}`,children:Z?h("layout_rate_from",{date:new Date(Z).toLocaleDateString("ru-RU",{day:"numeric",month:"short",timeZone:"Europe/Moscow"}),time:new Date(Z).toLocaleTimeString("ru-RU",{hour:"2-digit",minute:"2-digit",timeZone:"Europe/Moscow"})}):h("layout_rate_unknown")})]})]}),e.jsxs("div",{className:"hidden md:flex flex-1 max-w-2xl mx-8 relative",children:[e.jsx("input",{type:"text",value:v,onCh
40ange:V=>i(V.target.value),onKeyDown:V=>{V.key==="Enter"&&N()},placeholder:h("layout_search_placeholder"),className:"w-full h-10 pl-4 pr-12 bg-slate-100 border-transparent focus:bg-white border focus:border-blue-500 rounded-lg text-sm outline-none transition-all placeholder:text-slate-400"}),e.jsx("button",{onClick:N,"aria-label":"ÐайÑи заказ",className:"absolute right-0 top-0 h-10 w-10 bg-blue-600 hover:bg-blue-700 text-white rounded-r-lg flex items-center justify-center transition-colors",children:e.jsx(Qn,{size:18})})]}),e.jsxs("div",{className:"flex items-center gap-5 md:gap-6",children:[e.jsxs("div",{className:"hidden md:flex items-center gap-3 mr-2","data-tour":"header-balance",children:[e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col items-end",children:[e.jsxs("div",{className:"flex items-center gap-1 mb-0.5",children:[e.jsx("div",{className:"text-[10px] font-bold text-amber-500 uppercase tracking-wider",children:h("layout_label_bonus")}),e.jsx("button",{type:"button",onClick:()=>m(!0),className:"w-4 h-4 rounded-full bg-orange-500 hover:bg-orange-600 text-white flex items-center justify-center text-[9px] font-bold leading-none transition-colors shrink-0",children:"!"})]}),e.jsxs("div",{className:`text-sm font-bold flex items-center gap-1.5 ${(n?.bonus_balance||0)>0?"text-amber-600":"text-slate-900"}`,children:[e.jsx($a,{size:16,className:(n?.bonus_balance||0)>0?"text-amber-400":"text-slate-300"}),(n?.bonus_balance||0).toLocaleString()," â½"]})]}),e.jsx("div",{className:"h-8 w-[1px] bg-slate-200"})]}),e.jsxs("div",{className:`flex flex-col items-end ${H>0&&j?"cursor-pointer hover:opacity-70 transition-opacity":""}`,onClick:H>0?j:void 0,title:H>0?h("layout_pay_delivery_title"):void 0,children:[e.jsx("div",{className:"text-[10px] font-bold text-slate-900 uppercase tracking-wider mb-0.5",children:h("layout_label_delivery")}),e.jsxs("div",{className:`text-sm font-bold flex items-center gap-1.5 ${H>0?"text-red-600":"text-slate-900"}`,children:[e.jsx(Lt,{size:16,className:H>0?"text-red-400":"text-slate-300"}),H>0?`-${H.toLocaleString()}`:"0"," â½"]})]}),e.jsx("div",{className:"h-8 w-[1px] bg-slate-200"}),e.jsxs("div",{className:"flex flex-col items-end",children:[e.jsx("div",{className:"text-[10px] font-bold text-slate-900 uppercase tracking-wider mb-0.5",children:h("layout_label_balance")}),e.jsxs("div",{className:`text-sm font-bold flex items-center gap-1.5 ${de<0?"text-red-600":"text-slate-900"}`,children:[e.jsx(Ds,{size:16,className:"text-slate-400"}),de.toLocaleString()," â½"]})]})]}),e.jsx("div",{className:"h-8 w-[1px] bg-slate-200 hidden md:block"}),e.jsxs("button",{onClick:()=>s("MESSAGES"),className:"relative text-slate-500 hover:text-blue-600 transition-colors","aria-label":"СообÑÐµÐ½Ð¸Ñ Ð¸ ÑведомлениÑ",children:[e.jsx(_s,{size:20}),le>0&&e.jsx("span",{className:"absolute -top-1 -right-1 w-2.5 h-2.5 bg-red-500 rounded-full border-2 border-white"})]}),e.jsx("div",{className:"h-8 w-[1px] bg-slate-200 hidden md:block"}),e.jsx(Ma,{compact:!0}),e.jsx("div",{className:"h-8 w-[1px] bg-slate-200 hidden md:block"}),e.jsxs("div",{className:"flex items-center gap-3 pr-1 md:pr-0",children:[e.jsx("span",{className:"hidden md:block text-sm font-bold text-slate-900 truncate max-w-[150px]",children:xe.split(" ")[0]}),e.jsx("button",{onClick:k,className:"text-slate-400 hover:text-red-600 transition-colors",title:h("layout_logout_title"),children:e.jsx(Eo,{size:20})})]})]})]}),t!=="MESSAGES"&&e.jsxs("div",{className:"md:hidden flex items-center justify-between pb-2.5 border-t border-slate-100",children:[e.jsxs("div",{className:"flex items-center border border-slate-200 rounded-xl overflow-hidden shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-1.5 px-3.5 py-1.5",children:[e.jsx("span",{className:"text-sm font-bold text-emerald-500",children:"Â¥"}),e.jsxs("span",{className:"text-sm font-bold text-slate-800",children:[W.cny.toFixed(2),"â½"]})]}),e.jsx("div",{className:"w-px h-4 bg-slate-200"}),e.jsxs("div",{className:"flex items-center gap-1.5 px-3.5 py-1.5",children:[e.jsx("span",{className:"text-sm font-bold text-emerald-500",children:"$"}),e.jsxs("span",{className:"text-sm font-bold text-slate-800",children:[W.usd.toFixed(2),"â½"]})]}),e.jsx("div",{className:"w-px h-4 bg-slate-200"}),e.jsxs("div",{className:"flex items-center gap-1.5 px-3.5 py-1.5",children:[e.jsx("span",{className:"text-[10px] font-extrabold text-emerald-500 tracking-tight",children:"USDT"}),e.jsxs("span",{className:"text-sm font-bold text-slate-800",children:[W.usdt.toFixed(2),"Â¥"]})]})]}),Z&&(()=>{const V=new Date(Z),ye=new Date,Oe=V.toLocaleDateString("ru-RU",{timeZone:"Europe/Moscow"})===ye.toLocaleDateString("ru-RU",{timeZone:"Europe/Moscow"})?V.toLocaleTimeString("ru-RU",{hour:"2-digit",minute:"2-digit",timeZone:"Europe/Moscow"}):V.toLocaleDateString("ru-RU",{day:"numeric",month:"short",timeZone:"Europe/Moscow"});return e.jsxs("div",{className:"flex flex-col items-end pr-1",children:[e.jsx("span",{className:"text-[9px] font-bold text-slate-400 uppercase tracking-wide",children:h("layout_rate_updated_label")}),e.jsx("span",{className:"text-xs font-bold text-slate-500",children:Oe})]})})()]}),H>0&&t!=="MESSAGES"&&e.jsx("div",{className:"md:hidden pb-2.5",children:e.jsxs("button",{onClick:j,className:"w-full flex items-center justify-center gap-2 py-2 bg-red-50 border border-red-200 rounded-xl text-red-600 font-bold text-xs",children:[e.jsx(Lt,{size:14}
40),h("layout_delivery_debt_banner",{amount:H.toLocaleString()})]})})]}),e.jsxs("div",{className:"flex flex-1 overflow-hidden relative",children:[e.jsxs("aside",{className:` 41 absolute md:relative z-30 h-full bg-white border-r border-slate-200 flex flex-col transition-all duration-300 42 ${C?"md:w-20":"md:w-64"} w-64 43 ${R?"translate-x-0":"-translate-x-full md:translate-x-0"} 44 `,children:[e.jsxs("div",{className:`p-6 pb-2 ${C?"md:hidden":""}`,children:[e.jsx("div",{className:"text-[10px] font-bold text-slate-400 uppercase tracking-wider mb-1",children:h("layout_your_id")}),n?.friendly_id?e.jsxs("div",{className:"text-xl font-bold text-slate-900",children:["CN-",n.friendly_id]}):e.jsx("div",{className:"h-7 w-24 bg-slate-200 rounded-md animate-pulse"})]}),e.jsx("nav",{className:"flex-1 p-4 space-y-1 overflow-y-auto",children:Qe.map(V=>e.jsxs("button",{"data-tour":V.id==="IMPORT"?"nav-import":V.id==="ORDERS"?"nav-orders":V.id==="PAYMENTS"?"nav-payments":V.id==="MESSAGES"?"nav-messages":void 0,onClick:()=>{s(V.id),S(!1)},title:C?V.label:void 0,className:`w-full flex items-center gap-3 px-4 py-3 rounded-lg text-sm font-medium transition-all ${C?"md:justify-center md:px-2":""} ${t===V.id?"bg-blue-50 text-blue-700 shadow-sm border border-blue-100":"text-slate-600 hover:bg-slate-50 hover:text-slate-900 border border-transparent"}`,children:[e.jsxs("div",{className:"relative",children:[e.jsx(V.icon,{size:20,className:t===V.id?"text-blue-600":"text-slate-400"}),V.id==="MESSAGES"&&C&&l+le>0&&e.jsx("span",{className:"hidden md:flex absolute -top-1.5 -right-1.5 w-4 h-4 bg-red-500 rounded-full text-white text-[9px] font-bold items-center justify-center border border-white",children:l+le>9?"9+":l+le}),V.id==="SELF_BUYOUT"&&C&&e.jsx("span",{className:"hidden md:block absolute -top-1 -right-1 w-2 h-2 bg-emerald-500 rounded-full border border-white"}),V.id==="CALCULATOR"&&C&&e.jsx("span",{className:"hidden md:block absolute -top-1 -right-1 w-2 h-2 bg-emerald-500 rounded-full border border-white"})]}),e.jsx("span",{className:C?"md:hidden":"",children:V.label}),V.id==="MESSAGES"&&e.jsxs("div",{className:`ml-auto flex items-center gap-1.5 ${C?"md:hidden":""}`,children:[l>0&&e.jsx("span",{className:"bg-blue-600 text-white text-[10px] font-bold h-5 w-5 flex items-center justify-center rounded-full shadow-sm shadow-blue-200",children:l}),le>0&&e.jsx("span",{className:"bg-red-500 text-white text-[10px] font-bold h-5 w-5 flex items-center justify-center rounded-full shadow-sm shadow-red-200",children:le})]}),V.id==="SELF_BUYOUT"&&e.jsx("span",{className:`ml-auto bg-emerald-500 text-white text-[9px] font-bold px-1.5 py-0.5 rounded-full tracking-wide ${C?"md:hidden":""}`,children:"NEW"}),V.id==="CALCULATOR"&&e.jsx("span",{className:`ml-auto bg-emerald-500 text-white text-[9px] font-bold px-1.5 py-0.5 rounded-full tracking-wide ${C?"md:hidden":""}`,children:"NEW"}),V.id==="SUPPORT"&&o>0&&e.jsx("span",{className:`ml-auto bg-red-500 text-white text-[10px] font-bold h-5 w-5 flex items-center justify-center rounded-full shadow-sm shadow-red-200 animate-pulse ${C?"md:hidden":""}`,children:o})]},V.id))}),e.jsx("div",{className:"p-4 pt-0",children:e.jsxs("div",{className:"border-t border-slate-100 pt-3 space-y-1.5",children:[e.jsxs("button",{onClick:()=>{s("SUPPORT"),S(!1)},title:C?h("layout_nav_support"):void 0,className:`w-full flex items-center gap-3 px-4 py-3 rounded-lg text-sm font-medium transition-all border ${C?"md:justify-center md:px-2":""} ${t==="SUPPORT"?"bg-violet-100 text-violet-800 border-violet-200 shadow-sm":"bg-violet-50 text-violet-700 border-violet-100 hover:bg-violet-100"}`,children:[e.jsxs("div",{className:"relative",children:[e.jsx(dl,{size:20,className:"text-violet-500"}),C&&o>0&&e.jsx("span",{className:"hidden md:flex absolute -top-1.5 -right-1.5 w-4 h-4 bg-red-500 rounded-full text-white text-[9px] font-bold items-center justify-center border border-white animate-pulse",children:o>9?"9+":o})]}),e.jsx("span",{className:C?"md:hidden":"",children:h("layout_nav_support")}),o>0&&e.jsx("span",{className:`ml-auto bg-red-500 text-white text-[10px] font-bold h-5 w-5 flex items-center justify-center rounded-full shadow-sm shadow-red-200 animate-pulse ${C?"md:hidden":""}`,children:o})]}),e.jsxs("button",{onClick:()=>{D(!0),S(!1)},title:C?h("layout_nav_learning"):void 0,className:`w-full flex items-center gap-3 px-4 py-3 rounded-lg text-sm font-medium transition-all border bg-blue-50 text-blue-700 border-blue-100 hover:bg-blue-100 ${C?"md:justify-center md:px-2":""}`,children:[e.jsx(_i,{size:20,className:"text-blue-500"}),e.jsx("span",{className:C?"md:hidden":"",children:h("layout_nav_learning")})]})]})})]}),e.jsx("button",{onClick:U,className:"hidden md:flex absolute z-40 top-4 w-7 h-7 items-center justify-center rounded-full bg-emerald-500 hover:bg-emerald-600 text-white shadow-md shadow-emerald-200 transition-all duration-300",style:{left:C?"68px":"244px"},title:h(C?"layout_expand_title":"layout_collapse_title"),children:C?e.jsx(Sr,{size:16}):e.jsx(Mn,{size:16})}),R&&e.jsx("div",{className:"absolute inset-0 bg-black/20 z-[25] md:hidden",onClick:()=>S(!1)}),e.jsx("main",{className:"flex-1 bg-slate-50 overflow-hidden flex flex-col",children:t==="MESSAGES"?e.jsx("div",{className:"flex-1 min-h-0 flex flex-col p-4 md:p-6 xl:p-8 pb-20 md:pb-6 xl:pb-8",children:r}):e.jsx("div",{ref:Ne,className:"flex-1 overflow-y-auto p-4 md:p-6 xl:p-8 pb-20 md:pb-6 xl:pb-8",children:r})})]}),e.jsxs("nav",{className:"md:hidden fixed bottom-0 left-0 right-0 bg-white border-t border-slate-200 z-20 flex items-stretch h-16",children:[[{id:"HOME",label:h("layout_nav_home"),icon:cl},{id:"ORDERS",label:h("layout_nav_orders_short"),icon:js},{id:"MESSAGES",label:h("layout_nav_chat_short"),icon:zr},{id:"IMPORT",label:h("layout_nav_import_short"),icon:Sa},{id:"PROFILE",label:h("layout_nav_profile"),icon:gs}].map(V=>{const ye=t===V.id,Ie=V.id==="MESSAGES"?l+le:0;return e.jsxs("button",{onClick:()=>{s(V.id),S(!1)},className:`flex-1 flex flex-col items-center justify-center gap-0.5 text-[10px] font-bold transition-colors ${ye?"text-blue-600":"text-slate-400"}`,children:[e.jsxs("div",{className:"relative",children:[e.jsx(V.icon,{size:22}),Ie>0&&e.jsx("span",{className:"absolute -top-1.5 -right-1.5 w-4 h-4 bg-red-500 rounded-full text-white text-[9px] font-bold flex items-center justify-center",children:Ie>9?"9+":Ie})]}),V.label]},V.id)}),e.jsxs("button",{onClick:()=>{s("SUPPORT"),S(!1)},className:`flex-1 flex flex-col items-center justify-center gap-0.5 text-[10px] font-bold transition-colors relative ${t==="SUPPORT"?"text-violet-700 bg-violet-50":"text-violet-500"}`,children:[e.jsx("div",{className:"absolute left-0 top-2 bottom-2 w-px bg-violet-100"}),e.jsxs("div",{className:"relative",children:[e.jsx(dl,{size:22}),o>0&&e.jsx("span",{className:"absolute -top-1.5 -right-1.5 w-4 h-4 bg-red-500 rounded-full text-white text-[9px] font-bold flex items-center justify-center animate-pulse",children:o>9?"9+":o})]}),h("layout_nav_help_short")]})]}),e.jsx(bc,{isOpen:F,onClose:$,onStart:I}),e.jsx(Ox,{run:z,currentView:t,isAuthenticated:y,onNavigate:s,onFinish:()=>me(!1),onStalled:B}),K&&e.jsxs("div",{className:"fixed bottom-6 left-1/2 -translate-x-1/2 z-[10001] bg-white border border-slate-200 shadow-2xl rounded-xl px-4 py-3.5 flex items-center gap-3 max-w-[calc(100vw-2rem)]",children:[e.jsx("p",{className:"text-sm text-slate-700",children:h("layout_tour_stalled_msg")}),e.jsx("button",{onClick:I,className:"shrink-0 px-3 py-1.5 bg-blue-600 hover:bg-blue-700 text-white text-xs font-bold rounded-lg transition-colors",children:h("layout_tour_retry")}),e.jsx("button",{onClick:()=>te(!1),className:"shrink-0 text-slate-400 hover:text-slate-600",children:e.jsx(bt,{size:16})})]}),x&&e.jsx("div",{className:"fixed inset-0 z-[300] flex items-center justify-center bg-black/50 p-4",onClick:()=>m(!1),children:e.jsxs("div",{className:"bg-white rounded-2xl shadow-2xl w-full max-w-sm p-6",onClick:V=>V.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-orange-100 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"text-orange-600 font-black text-lg leading-none",children:"!"})}),e.jsx("h3",{className:"font-bold text-slate-800 text-base",children:h("layout_label_bonus")})]}),e.jsx("p",{className:"text-sm text-slate-700 leading-relaxed",children:h("profile_bonus_tooltip")}),e.jsx("button",{onClick:()=>m(!1),className:"mt-5 w-full py-2.5 bg-slate-900 text-white rounded-xl font-bold text-sm hover:bg-slate-700 transition-colors",children:h("topup_understood")})]})})]})}function Kl({onLogin:t}){const{t:s}=qt(),[n,r]=a.useState("LOGIN"),[l,c]=a.useState(!1),[o,d]=a.use
44State(!1),[p,y]=a.useState(null),[j,b]=a.useState(null),[h,v]=a.useState(null),[i,x]=a.useState(""),[m,N]=a.useState(""),[R,S]=a.useState(""),[C,L]=a.useState(!1),[U,W]=a.useState(!1),re=async O=>{O.preventDefault(),d(!0),y(null),b(null);try{if(n==="LOGIN"){const{error:F}=await xo(i,m);if(F)throw new Error(F)}else if(n==="REGISTER"){const{user:F,hasSession:D,error:$}=await mo(i,m,{name:R});if($)throw new Error($);if(F){const z=new AbortController,me=setTimeout(()=>z.abort(),8e3);fetch("/pd/profile",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:F.id,email:i,name:R||null}),signal:z.signal}).then(()=>{}).catch(K=>{}).finally(()=>clearTimeout(me))}D?t():F&&v(i)}else if(n==="FORGOT_PASSWORD"){const{error:F}=await po(i,window.location.origin+bi+"?action=recovery");if(F)throw new Error(F);b(s("auth_reset_link_sent"))}}catch(F){y(F.message==="Invalid login credentials"?s("auth_error_invalid_credentials"):F.message==="timeout"?s("auth_error_timeout"):F.message==="Email not confirmed"?s("auth_error_email_not_confirmed"):F.message)}finally{d(!1)}},Z=()=>{y(null),b(null),N("")};return h?e.jsxs("div",{className:"min-h-screen bg-slate-50 flex flex-col items-center justify-center p-4 font-sans text-slate-900",children:[e.jsx("div",{className:"w-full max-w-md flex justify-end mb-2",children:e.jsx(Ma,{})}),e.jsxs("div",{className:"w-full max-w-md bg-white rounded-2xl shadow-xl border border-slate-100 p-10 text-center",children:[e.jsx("div",{className:"w-16 h-16 bg-green-100 rounded-full flex items-center justify-center mx-auto mb-5",children:e.jsx(Co,{className:"text-green-600",size:32})}),e.jsx("h2",{className:"text-2xl font-bold text-slate-900 mb-2",children:s("auth_confirm_title")}),e.jsxs("p",{className:"text-slate-500 mb-4 leading-relaxed",children:[s("auth_confirm_body_prefix")," ",e.jsx("span",{className:"font-semibold text-slate-800",children:h}),"."," ",s("auth_confirm_body_suffix")]}),e.jsx("p",{className:"text-xs text-slate-400 mb-6",children:s("auth_confirm_spam_hint")}),e.jsx("button",{type:"button",onClick:()=>{v(null),r("LOGIN"),Z()},className:"text-sm text-blue-600 hover:text-blue-700 font-semibold",children:s("auth_back_to_login")})]})]}):e.jsxs("div",{className:"min-h-screen bg-slate-50 flex flex-col items-center justify-center p-4 font-sans text-slate-900",children:[e.jsx("div",{className:"w-full max-w-md flex justify-end mb-2",children:e.jsx(Ma,{})}),e.jsxs("div",{className:"mb-8 text-center",children:[e.jsx("h1",{className:"text-3xl font-bold tracking-tight text-slate-900",children:s(n==="LOGIN"?"auth_title_login":n==="REGISTER"?"auth_title_register":"auth_title_recovery")}),e.jsx("p",{className:"text-slate-500 mt-2",children:s(n==="LOGIN"?"auth_subtitle_login":n==="REGISTER"?"auth_subtitle_register":"auth_subtitle_recovery")})]}),e.jsxs("div",{className:"w-full max-w-md bg-white rounded-2xl shadow-xl border border-slate-100 overflow-hidden",children:[n!=="FORGOT_PASSWORD"&&e.jsxs("div",{className:"flex p-2 m-2 bg-slate-50 rounded-xl border border-slate-200",children:[e.jsx("button",{type:"button",onClick:()=>{r("LOGIN"),Z()},className:`flex-1 py-2 text-sm font-bold rounded-lg transition-all ${n==="LOGIN"?"bg-white text-blue-600 shadow-sm":"text-slate-500 hover:text-slate-700"}`,children:s("auth_toggle_login")}),e.jsx("button",{type:"button",onClick:()=>{r("REGISTER"),Z()},className:`flex-1 py-2 text-sm font-bold rounded-lg transition-all ${n==="REGISTER"?"bg-white text-blue-600 shadow-sm":"text-slate-500 hover:text-slate-700"}`,children:s("auth_toggle_register")})]}),e.jsxs("form",{onSubmit:re,className:"p-5 sm:p-8 pt-4 space-y-5",children:[p&&e.jsxs("div",{className:"p-3 bg-red-50 border border-red-100 rounded-lg flex items-center gap-2 text-sm text-red-600",children:[e.jsx(Fs,{size:16}),p]}),j&&e.jsxs("div",{className:"p-3 bg-green-50 border border-green-100 rounded-lg flex items-center gap-2 text-sm text-green-600",children:[e.jsx(as,{size:16}),j]}),n==="REGISTER"&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-slate-500 uppercase mb-1.5 ml-1",children:s("auth_label_name")}
44),e.jsxs("div",{className:"relative group",children:[e.jsx(gs,{className:"absolute left-4 top-3.5 text-slate-400 group-focus-within:text-blue-500 transition-colors",size:20}),e.jsx("input",{type:"text",required:!0,placeholder:s("auth_placeholder_name"),value:R,onChange:O=>S(O.target.value),className:"ym-disable-keys ym-hide-content w-full pl-12 pr-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:bg-white focus:ring-2 focus:ring-blue-500 focus:border-transparent outline-none transition-all font-medium text-slate-700 placeholder:text-slate-400"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-slate-500 uppercase mb-1.5 ml-1",children:s("auth_label_email")}),e.jsxs("div",{className:"relative group",children:[e.jsx(Ca,{className:"absolute left-4 top-3.5 text-slate-400 group-focus-within:text-blue-500 transition-colors",size:20}),e.jsx("input",{type:"email",required:!0,placeholder:"[email protected]",value:i,onChange:O=>x(O.target.value),className:"ym-disable-keys ym-hide-content w-full pl-12 pr-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:bg-white focus:ring-2 focus:ring-blue-500 focus:border-transparent outline-none transition-all font-medium text-slate-700 placeholder:text-slate-400"})]})]}),n!=="FORGOT_PASSWORD"&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-1.5 ml-1",children:[e.jsx("label",{className:"block text-xs font-bold text-slate-500 uppercase",children:s("auth_label_password")}),n==="LOGIN"&&e.jsx("button",{type:"button",onClick:()=>{r("FORGOT_PASSWORD"),Z()},className:"text-xs font-bold text-blue-600 hover:text-blue-700",children:s("auth_forgot_password")})]}),e.jsxs("div",{className:"relative group",children:[e.jsx(ln,{className:"absolute left-4 top-3.5 text-slate-400 group-focus-within:text-blue-500 transition-colors",size:20}),e.jsx("input",{type:l?"text":"password",required:!0,placeholder:"â¢â¢â¢â¢â¢â¢â¢â¢",minLength:6,value:m,onChange:O=>N(O.target.value),className:"ym-disable-keys ym-hide-content w-full pl-12 pr-12 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:bg-white focus:ring-2 focus:ring-blue-500 focus:border-transparent outline-none transition-all font-medium text-slate-700 placeholder:text-slate-400"}),e.jsx("button",{type:"button",onClick:()=>c(!l),"aria-label":s(l?"auth_hide_password":"auth_show_password"),className:"absolute right-2 top-1.5 p-2 text-slate-400 hover:text-slate-600",children:l?e.jsx(Fa,{size:20}):e.jsx(Xn,{size:20})})]})]}),n==="REGISTER"&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"flex items-start gap-3 cursor-pointer select-none",children:[e.jsx("input",{type:"checkbox",checked:U,onChange:O=>W(O.target.checked),className:"mt-0.5 w-4 h-4 accent-blue-600 shrink-0 cursor-pointer"}),e.jsxs("span",{className:"text-xs text-slate-700 leading-relaxed",children:[s("auth_agree_oferta_prefix")," ",e.jsx("a",{href:wr("/oferta"),target:"_blank",rel:"noreferrer",className:"font-semibold underline hover:text-blue-600 transition-colors",children:s("auth_link_oferta")}),"."]})]}),e.jsxs("label",{className:"flex items-start gap-3 cursor-pointer select-none",children:[e.jsx("input",{type:"checkbox",checked:C,onChange:O=>L(O.target.checked),className:"mt-0.5 w-4 h-4 accent-blue-600 shrink-0 cursor-pointer"}),e.jsxs("span",{className:"text-xs text-slate-700 leading-relaxed",children:[s("auth_agree_pd_prefix")," ",e.jsx("a",{href:wr("/privacy"),target:"_blank",rel:"noreferrer",className:"font-semibold underline hover:text-blue-600 transition-colors",children:s("auth_link_privacy")}),"."]})]})]}),e.jsx("button",{type:"submit",disabled:o||n==="REGISTER"&&(!C||!U),className:"w-full py-3.5 px-4 bg-blue-600 hover:bg-blue-700 disabled:bg-slate-300 disabled:cursor-not-allowed text-white rounded-xl font-bold text-lg shadow-lg shadow-blue-200 transition-all active:scale-[0.98] mt-2 flex items-center justify-center gap-2",children:o?e.jsx(rt,{className:"animate-spin"}):s(n==="LOGIN"?"auth_submit_login":n==="REGISTER"?"auth_submit_register":"auth_submit_reset")}),n==="FORGOT_PASSWORD"&&e.jsxs("button",{type:"button",onClick:()=>{r("LOGIN"),Z()},className:"w-full py-2 text-slate-500 font-medium hover:text-slate-800 flex items-center justify-center gap-2",children:[e.jsx(Ba,{size:16}),s("auth_back")]})]}),(n==="LOGIN"||n==="REGISTER")&&e.jsxs("div",{className:"bg-slate-50 p-4 text-center border-t border-slate-100 space-y-2",children:[e.jsxs("p",{className:"text-sm text-slate-500",children:[s(n==="LOGIN"?"auth_no_account":"auth_has_account"),e.jsx("button",{type:"button",onClick:()=>{r(n==="LOGIN"?"REGISTER":"LOGIN"),Z()},className:"ml-2 font-bold text-blue-600 hover:text-blue-700",children:s(n==="LOGIN"?"auth_create_now":"auth_toggle_login")})]}),e.jsxs("p",{className:"text-xs text-slate-500",children:[s("auth_login_problems")," ",e.jsx("a",{href:"https://vk.me/goodschina1",target:"_blank",rel:"noreferrer",className:"hover:text-slate-700 underline transition-colors",children:"ÐÐонÑакÑе"})," · ",e.jsx("a",{href:"https://t.me/GOODSCHINAMR",target:"_blank",rel:"noreferrer",className:"hover:text-slate-700 underline transition-colors",children:"Telegram"})]})]})]})]})}const Lx="gc_first_marketing_touch",Mx=[1,2,3],zx=["version","captured_at","landing_path","ad_segment","yclid","utm_source","utm_medium","utm_campaign","utm_content","utm_term","gc_campaign_id","gc_group_id","gc_ad_id","gc_phrase_id"];function za(t){if(typeof t!="object"||t===null||Array.isArray(t))return!1;const s=t;return!(!Mx.includes(s.version)||typeof s.captured_at!="string"||s.captured_at.length===0||typeof s.landing_path!="string"||typeof s.ad_segment!="string")}function Jl(){try{if(typeof localStorage>"u")return null;const t=localStorage.getItem(Lx);if(!t)return null;const s=JSON.parse(t);return za(s)?s:null}catch{return null}}function Ux(t,s){return s?t==null:!1}function $x(t,s){return!za(t)||!s||!za(s)||t.metrica_client_id||!s.metrica_client_id?!1:zx.every(n=>t[n]===s[n])}function Ql({orderCounts:t,userProfile:s,usdRate:n,onNavigate:r,onPayDelivery:l,onNavigateToOrders:c}){const{t:o}=qt(),d=[{label:o("home_card_collecting"),value:t.collecting,icon:zn,color:"text-amber-600",bg:"bg-amber-50",border:"border-amber-200",tab:"COLLECTING_GROUP"},{label:o("home_card_shipping"),value:t.shipping,icon:Lt,color:"text-blue-600",bg:"bg-blue-50",border:"border-blue-200",tab:"SHIPPED"},{label:o("home_card_received"),value:t.received,icon:xn,color:"text-green-600",bg:"bg-green-50",border:"border-green-200",tab:"RECEIVED"},{label:o("home_card_total"),value:t.total,icon:ko,color:"text-slate-600",bg:"bg-slate-50",border:"border-slate-200",tab:"ALL"}],p=s?.balance||0,y=s?.bonus_balance||0,j=Number(s?.welcome_bonus_remaining)||0,b=(()=>{const i=s?.welcome_bonus_expires_at;if(j<=0||!i)return null;const x=new Date(i).getTime()-Date.now();return x<=0?null:Math.ceil(x/864e5)})(),h=t.photoWaiting||0,v=no(s?.id,n??0);return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("h1",{className:"text-2xl font-bold text-slate-800",children:[o("home_welcome"),s?.name?`, ${s.name.split(" ")[0]}`:""]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-3",children:[e.jsxs("div",{className:"bg-white border border-slate-200 p-4 rounded-2xl shadow-sm flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-xl bg-slate-100 flex items-center justify-center shrink-0",children:e.jsx(Ds,{size:18,className:p<0?"text-red-500":"text-slate-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] font-bold text-slate-400 uppercase tracking-wide",children:o("layout_label_balance")}),e.jsxs("p",{className:`text-lg font-black ${p<0?"text-red-600":"text-slate-900"}
44`,children:[p.toLocaleString()," â½"]})]})]}),e.jsxs("div",{className:"bg-white border border-slate-200 p-4 rounded-2xl shadow-sm flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-xl bg-amber-50 flex items-center justify-center shrink-0",children:e.jsx($a,{size:18,className:y>0?"text-amber-500":"text-slate-300"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] font-bold text-slate-400 uppercase tracking-wide",children:o("layout_label_bonus")}),e.jsxs("p",{className:`text-lg font-black ${y>0?"text-amber-600":"text-slate-400"}`,children:[y.toLocaleString()," â½"]}),b!==null&&e.jsxs("p",{className:"text-[10px] font-bold text-red-500 leading-tight mt-0.5",children:["ð¥ ",j.toLocaleString()," â½ ",b<=0?o("topup_bonus_expires_today"):o("topup_bonus_expires_in",{days:b})]})]})]}),e.jsxs("div",{className:`col-span-2 md:col-span-1 border p-4 rounded-2xl shadow-sm flex items-center gap-3 ${v>0?"bg-red-50 border-red-200":"bg-white border-slate-200"}`,children:[e.jsx("div",{className:`w-9 h-9 rounded-xl flex items-center justify-center shrink-0 ${v>0?"bg-red-100":"bg-slate-100"}`,children:e.jsx(Lt,{size:18,className:v>0?"text-red-500":"text-slate-400"})}),e.jsxs("div",{className:"flex-1 min-w-0 flex items-center justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] font-bold text-slate-400 uppercase tracking-wide",children:o("layout_label_delivery")}),e.jsxs("p",{className:`text-lg font-black ${v>0?"text-red-600":"text-slate-400"}`,children:[v>0?`-${v.toLocaleString()}`:"0"," â½"]})]}),v>2e4&&l&&e.jsx("button",{onClick:()=>l(),className:"shrink-0 bg-red-500 hover:bg-red-600 text-white text-xs font-bold px-3 py-2 rounded-xl shadow-sm shadow-red-200 transition-colors",children:o("home_pay_button")})]})]})]}),h>0&&e.jsxs("button",{onClick:()=>r?.("ORDERS"),className:"w-full bg-orange-50 border border-orange-200 rounded-2xl p-4 flex items-center gap-3 text-left hover:bg-orange-100 transition-colors active:scale-[0.99]",children:[e.jsx("div",{className:"w-9 h-9 rounded-xl bg-orange-100 flex items-center justify-center shrink-0 animate-pulse",children:e.jsx(Yr,{size:18,className:"text-orange-600"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-bold text-orange-800 text-sm",children:o("home_photo_title")}),e.jsx("p",{className:"text-xs text-orange-600 mt-0.5",children:h===1?o("home_photo_body_one"):o("home_photo_body_many",{count:h})})]}),e.jsx(Sr,{size:18,className:"text-orange-400 shrink-0"})]}),t.total===0?e.jsxs("button",{onClick:()=>r?.("IMPORT"),className:"w-full bg-indigo-50 border border-indigo-200 rounded-2xl p-5 flex items-center gap-4 text-left hover:bg-indigo-100 transition-colors active:scale-[0.99]",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-indigo-100 flex items-center justify-center shrink-0",children:e.jsx(zn,{size:22,className:"text-indigo-600"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-bold text-indigo-800",children:o("home_first_order_title")}),e.jsx("p",{className:"text-sm text-indigo-600 mt-0.5",children:o("home_first_order_body")})]}),e.jsx(Sr,{size:20,className:"text-indigo-400 shrink-0"})]}):e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3 sm:gap-4",children:d.map(({label:i,value:x,icon:m,color:N,bg:R,border:S,tab:C})=>e.jsxs("button",{type:"button",onClick:()=>c?.(C),className:`${R} border ${S} p-4 sm:p-5 rounded-2xl shadow-sm text-left transition-transform hover:brightness-95 active:scale-[0.98] cursor-pointer`,children:[e.jsx("div",{className:`w-9 h-9 sm:w-10 sm:h-10 rounded-xl ${R} border ${S} flex items-center justify-center mb-2 sm:mb-3`,children:e.jsx(m,{size:18,className:N})}),e.jsx("p",{className:"text-[10px] sm:text-xs font-bold text-slate-400 uppercase tracking-wide",children:i}),e.jsx("p",{className:`text-2xl sm:text-3xl font-black mt-1 ${N}`,children:x})]},i))})]})}const Fx=14,Bx=23;function ao(t=new Date){const s=Number(new Intl.DateTimeFormat("en-US",{timeZone:"Asia/Shanghai",hour:"numeric",hour12:!1}).format(t)),n=s===24?0:s;return n>=Fx&&n<Bx}const kn=30,Yx=(t,s,n,r)=>{const l=`payment_req_${s}${r?.transactionType==="DELIVERY_PAYMENT"?"_delivery":""}
44`,[c,o]=a.useState("loading"),[d,p]=a.useState(kn*60),[y,j]=a.useState(null),[b,h]=a.useState(null),v=a.useRef(!1),i=a.useRef(!1),x=a.useRef(!1),m=a.useRef(null);a.useEffect(()=>{if(!y||i.current||v.current)return;const O=setInterval(()=>{if(v.current||x.current)return;if(i.current){clearInterval(O);return}const F=m.current;if(F==null)return;const D=Math.max(0,Math.round((F-Date.now())/1e3));if(p(D),D<=0){if(v.current||i.current||x.current)return;clearInterval(O),N()}},1e3);return()=>clearInterval(O)},[y]);const N=()=>{v.current||i.current||(localStorage.removeItem(l),o("expired"),m.current=null,b&&(ds("card_reservations",{id:b}).then(({error:O})=>{}),h(null)))};a.useEffect(()=>()=>{b&&!i.current&&!v.current&&ds("card_reservations",{id:b}).then(({error:O})=>{})},[b]);const R=async()=>!!localStorage.getItem(l),S=async()=>{if(!ao()){o("card_window_closed");return}v.current=!1,i.current=!1,o("loading"),p(kn*60);const O=setTimeout(()=>{o("no_cards_available")},8e3);try{const{data:F,error:D}=await Re("payment_cards",{is_active:!0});if(D)throw new Error(D);const $=(F||[]).find(Ne=>Ne.order_id===s&&Ne.limit-Ne.current_balance>=t);if($){clearTimeout(O),await C($);return}if(!F?.length){clearTimeout(O);const Ne=await R();o(Ne?"request_sent":"no_cards_available");return}const z=new Date().toISOString(),{data:me,error:K}=await Re("card_reservations",{}),te=(me||[]).filter(Ne=>Ne.expires_at>z),I=yt(),B=F.filter(Ne=>{if(Ne.user_id&&Ne.user_id!==I||r?.transactionType==="DELIVERY_PAYMENT"&&Ne.order_id||Ne.order_id&&Ne.order_id!==s)return!1;const Ue=te?.filter(H=>H.card_id===Ne.id).reduce((H,le)=>H+le.amount,0)||0;return Ne.limit-Ne.current_balance-Ue>=t});if(B.length>0)await C(B[0]);else{const Ne=await R();o(Ne?"request_sent":"no_cards_available")}}catch{o("no_cards_available")}finally{clearTimeout(O)}},C=async O=>{const F=Date.now()+kn*60*1e3,D=new Date(F).toISOString(),$=yt(),z=crypto.randomUUID(),{error:me}=await st("card_reservations",{id:z,card_id:O.id,order_id:s,amount:t,expires_at:D,user_id:$,order_display_id:n||"Unknown"});if(me)throw new Error(me);m.current=F,p(kn*60),j(O),h(z),o("payment")};return{step:c,setStep:o,timeLeft:d,activeCard:y,findBestCard:S,handleTransaction:async(O,F,D)=>{if(d<=0&&!F)throw new Error("ÐÑÐµÐ¼Ñ Ð±ÑониÑÐ¾Ð²Ð°Ð½Ð¸Ñ Ð²ÑÑло. ÐожалÑйÑÑа, обновиÑе ÑеквизиÑÑ.");if(!O.length)throw new Error("Чек не пÑикÑеплÑн.");v.current=!0;try{const $=yt();if(!$)throw new Error("User not found");const z=[];for(let I=0;I<O.length;I++){const B=O[I],Ne=B.name.split(".").pop(),Ue=`${s}_${Date.now()}_${I}.${Ne}`,{publicUrl:$e}=await tr("receipts",Ue,B);z.push($e)}const me=crypto.randomUUID(),{error:K}=await st("transactions",{id:me,user_id:$,order_id:s,amount:t,currency:F?"USDT":"RUB",amount_usdt:F?D:null,type:r?.transactionType||"ORDER_PAYMENT",status:"PENDING",description:r?.transactionType==="DELIVERY_PAYMENT"?`ÐÐ»Ð¸ÐµÐ½Ñ Ð¾Ð¿Ð»Ð°Ñил доÑÑÐ°Ð²ÐºÑ Ð·Ð°ÐºÐ°Ð·Ð° ${n} â ${t.toLocaleString("ru-RU")} â½${F?" (USDT)":""}`:`ÐÐ»Ð¸ÐµÐ½Ñ Ð¾Ð¿Ð»Ð°Ñил заказ ${n} â ${t.toLocaleString("ru-RU")} â½${F?" (USDT)":""}`,proof_image:z[0],proof_images:z,created_at:new Date().toISOString()});if(K)throw new Error(K);if(!F&&y&&Je("transactions",{id:me},{card_id:y.id}).then(({error:I})=>{}),!F&&y&&b){const{data:I}=await Re("payment_cards",{id:y.id},{select:"current_balance",single:!0});if(I){const B=I.current_balance+t,{error:Ne}=await Je("payment_cards",{id:y.id},{current_balance:B});y.order_id&&B>=y.limit&&Je("payment_cards",{id:y.id},{is_active:!1,is_archived:!0,archived_at:new Date().toISOString()}).then(()=>{}).catch(()=>{}),Je("payment_cards",{id:y.id},{last_order_display_id:n}).then(()=>{}).catch(()=>{});const{error:Ue}=await ds("card_reservations",{id:b})}}if(!r?.skipOrderUpdate){const{error:I}=await Je("orders",{id:s},{status:"PAID"});if(I)throw new Error(I)}const{error:te}=await st("notifications",{type:r?.transactionType==="DELIVERY_PAYMENT"?"DELIVERY_PAYMENT":"PAYMENT",title:r?.transactionType==="DELIVERY_PAYMENT"?`ÐплаÑа доÑÑавки â ${n}`:`ÐплаÑа заказа ${n}`,text:r?.transactionType==="DELIVERY_PAYMENT"?`ÐÐ»Ð¸ÐµÐ½Ñ Ð¾ÑпÑавил Ñек за доÑÑÐ°Ð²ÐºÑ Ð·Ð°ÐºÐ°Ð·Ð° ${n}.`:`ÐолÑзоваÑÐµÐ»Ñ Ð¾Ð¿Ð»Ð°Ñил заказ ${n}.`,date:new Date().toISOString(),is_read:!1,link:s});if(te)throw new Error(te);At.channel("admin-alerts").send({type:"broadcast",event:"payment",payload:{amount:t,orderId:n,orderUUID:s}}).catch(I=>{}),i.current=!0,o("processing")}catch($){throw v.current=!1,$}},handleRequestRequisites:async(O,F,D)=>{let $="";O==="SITE"?$="ÑеÑез Ñведомление на ÑайÑе":O==="TELEGRAM"?$=`в Telegram: ${F}`:O==="VK"?$=`ÐÐонÑакÑе: ${F}`:O==="EMAIL"&&($=`на поÑÑÑ: ${F}`);const z=D&&D.length>1,me=z?` [split:${D.join(",")}]`:"",K=z?` Ðожелание по Ñазбивке: ${D.map(le=>
44le.toLocaleString("ru-RU")+" â½").join(" + ")}.`:"",te=n&&n.length<20?n:"",I=r?.transactionType==="DELIVERY_PAYMENT",B=Math.max(0,Math.round(r?.goodsDebt||0)),Ne=B>0?` [debt:${B}]`:"",Ue=` [amount:${Math.round(t)}]`,{error:$e}=await st("notifications",{type:"PAYMENT_REQUEST",title:I?`ÐплаÑа доÑÑавки${te?` â ${te}`:""}: ${t.toLocaleString("ru-RU")} â½`:`ÐплаÑа заказа${te?` ${te}`:""}: ${t.toLocaleString("ru-RU")} â½`,text:`ÐÐ»Ð¸ÐµÐ½Ñ Ð¿ÑоÑÐ¸Ñ Ð¿Ð¾Ð´Ð³Ð¾ÑовиÑÑ ÑеквизиÑÑ${te?` Ð´Ð»Ñ Ð·Ð°ÐºÐ°Ð·Ð° ${te}`:""}. СвÑзаÑÑÑÑ ${$}.${K}${me}${Ne}${Ue}`,date:new Date().toISOString(),is_read:!1,link:s});if($e)throw new Error($e);const H=z?D.length:1;localStorage.setItem(l,`${Date.now()}:${H}`),At.channel("admin-alerts").send({type:"broadcast",event:"payment_request",payload:{amount:t,orderId:n}}).catch(le=>{}),At.functions.invoke("send-telegram",{body:{to_admin:!0,message:`ð <b>ÐапÑÐ¾Ñ ÑеквизиÑов</b> 45 46ð° СÑмма: <b>${t.toLocaleString("ru-RU")} â½</b> 47ð¦ Ðаказ: <b>${n}</b> 48ð¬ СвÑзаÑÑÑÑ: ${$}`}}).catch(()=>{}),o("request_sent")},handleCardBlocked:async()=>{if(y){const O=!!(y.order_id||y.user_id),{error:F}=await Je("payment_cards",{id:y.id},O?{is_active:!1,is_archived:!0,archived_at:new Date().toISOString()}:{is_active:!1})}if(b){const{error:O}=await ds("card_reservations",{id:b});h(null)}m.current=null,j(null),o("no_cards_available")},pauseTimer:()=>{x.current=!0},resumeTimer:()=>{x.current=!1}}},nl=({onClose:t,onPaymentSuccess:s,initialAmount:n,totalCNY:r,orderUUID:l,displayId:c,isDelivery:o=!1})=>{const{t:d}=qt(),p=2e4,y=1e3,j=`payment_req_${l}${o?"_delivery":""}`,b=`payment_goods_balance_${l}${o?"_delivery":""}`,h=`payment_bonus_${l}${o?"_delivery":""}`,[v,i]=a.useState(0),[x,m]=a.useState(0),[N,R]=a.useState(!1),[S,C]=a.useState(!1),[L,U]=a.useState(0),[W,re]=a.useState(null),Z=a.useMemo(()=>{if(L<=0||!W)return null;const X=new Date(W).getTime()-Date.now();return X<=0?null:Math.ceil(X/864e5)},[L,W]),[O,F]=a.useState(0),[D,$]=a.useState(0),[z,me]=a.useState([]),[K,te]=a.useState(0),[I,B]=a.useState(!1),[Ne,Ue]=a.useState(!1),[$e,H]=a.useState(!1),[le,Qe]=a.useState(!1),[k,xe]=a.useState(!1),[de,V]=a.useState(0),[ye,Ie]=a.useState(0),[Oe,we]=a.useState(!1),[Le,_t]=a.useState(n),jt=o?Le+K:Le,dt=Math.min(O,jt),gt=Math.min(v,jt),ht=Math.max(jt-x-de,0),qe=a.useMemo(()=>Math.max(ht,p),[ht]),it=ht<p,[Ge,St]=a.useState([]),[Pt,Ut]=a.useState(!0),[xt,zt]=a.useState([]),[J,We]=a.useState([]),[oe,Y]=a.useState([]),[Se,ve]=a.useState(!1),[T,ke]=a.useState(!1),[be,Ae]=a.useState(null),E=a.useRef(!1),[se,ee]=a.useState(0),u=a.useRef(!1),_=a.useRef(!1),P=a.useRef(!1),{step:A,setStep:M,timeLeft:ie,activeCard:ge,findBestCard:w,handleTransaction:fe,handleRequestRequisites:pe,handleCardBlocked:je,pauseTimer:ze,resumeTimer:mt}=Yx(qe,l,c,o?{transactionType:"DELIVERY_PAYMENT",skipOrderUpdate:!0,goodsDebt:K}:void 0),[Tt,G]=a.useState("card"),[q,he]=a.useState([]),[_e,Xe]=a.useState(!1),[Ct,Gt]=a.useState(null),[Nt,Wt]=a.useState("SITE"),os=1e5,As=2e4,cs=5,Xt=()=>{const X=localStorage.getItem(j)||"",Te=parseInt(X.split(":")[1]||"1",10);return Te>0?Te:1},[Mt,Ls]=a.useState(1),[Ft,Es]=a.useState(["",""]),Zt=a.useMemo(()=>{if(Mt===1||qe<os)return[qe];if(Mt===2){const lt=parseInt(Ft[0].replace(/\D/g,""),10)||Math.round(qe/2),Ce=Math.max(0,qe-lt);return[lt,Ce]}const X=parseInt(Ft[0].replace(/\D/g,""),10)||Math.round(qe/3),Te=parseInt(Ft[1].replace(/\D/g,""),10)||Math.round(qe/3),ce=Math.max(0,qe-X-Te);return[X,Te,ce]},[Mt,Ft,qe]),Ht=a.useMemo(()=>Mt===1||qe<os?!0:Zt.every(X=>X>=As),[Zt,Mt,qe]),kr=X=>{Ls(X),Es(X===2?[String(Math.round(qe/2)),""]:X===3?[String(Math.round(qe/3)),String(Math.round(qe/3))]:["",""])},[pr,Rr]=a.useState(!1),[xs,fr]=a.useState(""),[Cs,hr]=a.useState(null),[Tr,qs]=a.useState(!1),Ms=()=>{q.length>0||oe.length>0?qs(!0):t()},zs=a.useRef(null),ps=a.useRef(null);a.useEffect(()=>{const X=Te=>{const ce=Te.clipboardData?.items;if(ce){for(const lt of Array.from(ce))if(lt.type.startsWith("image/")){const Ce=lt.getAsFile();if(!Ce)continue;const He=lt.type.split("/")[1]||"png",Ve=new File([Ce],`Ñек_${Date.now()}.${He}`,{type:lt.type});Ge.length>0?(Y(tt=>tt.length<cs?[...tt,Ve]:tt),_.current=!0):(he(tt=>tt.length<cs?[...tt,Ve]:tt),ze());break}}};return document.addEventListener("paste",X),()=>document.removeEventListener("paste",X)},[Ge.length,ze]);const[Ws,br]=a.useState(()=>{try{return localStorage.getItem("tradehub_usdt_wallet")||"70b4afe3e31e23c17d15e4680ea307585d042f2a274eced74bbfe0f85b7affd2"}catch{return"70b4afe3e31e23c17d15e4680ea307585d042f2a274eced74bbfe0f85b7affd2"}}),[ks,nr]=a.useState(()=>{try{return localStorage.getItem("tradehub_usdt_qr")||""}catch{return""}}),[gr,_r]=a.useState(!1),[ar,Dr]=a.useState(null),[lr,g]=a.useState(null),Q=a.useMemo(()=>lr?r?(r/lr).toFixed(2):ar?(qe/(ar*lr)).toFixed(2):"...":"...",[qe,r,ar,lr]);a.useEffect(()=>{Re("app_settings",{},{select:"usdt_wallet,usdt_qr_image,currencies",limit:1,single:!0}).then(({data:X})=>{if(X?.usdt_wallet){br(X.usdt_wallet);try{localStorage.setItem("tradehub_usdt_wallet",X.usdt_wallet)}catch{}}if(X?.usdt_qr_image){nr(X.usdt_qr_image);try{localStorage.setItem("tradehub_usdt_qr",X.usdt_qr_image)}catch{}}else{nr("");try{localStorage.removeItem("tradehub_usdt_qr")}catch{}}const Te=X?.currencies;if(Array.isArray(Te)){const ce=Te.find(Ce=>Ce.code==="CNY"),lt=Te.find(Ce=>Ce.code==="USDT");ce?.rate&&Dr(Number(ce.rate)),lt?.rate&&g(Number(lt.rate))}})},[]);const[ne,De]=a.useState(null),[Ee,Pe]=a.useState(!1),[nt,ft]=a.useState(!1);a.useEffect(()=>{if(Number(Q)<=y){Pe(!0);return}Re("usdt_wallet_requests",{order_id:l,is_archived:!1},{select:"*",order:"created_at.desc",limit:1}).then(({data:Te})=>{const ce=Te?.[0];De(ce||null)}).finally(()=>Pe(!0));const X=At.channel(`usdt_request_${l}`).on("postgres_changes",{event:"*",schema:"public",table:"usdt_wallet_requests",filter:`order_id=eq.${l}`},Te=>{if(Te.new?.is_archived){De(null);return}
48Te.new?.id&&Re("usdt_wallet_requests",{id:Te.new.id},{select:"*",single:!0}).then(({data:ce})=>{ce&&De(ce)})}).subscribe();return()=>{At.removeChannel(X)}},[l,Q]);const It=async()=>{ft(!0);try{const X=yt(),Te=crypto.randomUUID(),{error:ce}=await st("usdt_wallet_requests",{id:Te,order_id:l,order_display_id:c,user_id:X,amount_usdt:Number(Q),status:"PENDING",created_at:new Date().toISOString()});if(ce)throw new Error(ce);await st("notifications",{type:"USDT_WALLET_REQUEST",title:`ÐапÑÐ¾Ñ USDT-коÑелÑка: ${Q} USDT`,text:`ÐÐ»Ð¸ÐµÐ½Ñ Ð·Ð°Ð¿ÑоÑил коÑелÑк USDT Ð´Ð»Ñ Ð·Ð°ÐºÐ°Ð·Ð° ${c}, ÑÑмма ${Q} USDT (>${y}).`,date:new Date().toISOString(),is_read:!1,link:l}),De({id:Te,status:"PENDING"})}catch(X){alert(d("common_error_prefix")+X.message)}finally{ft(!1)}},Vt=async X=>{const{data:Te}=await Re("orders",{user_id:X,status:"PAID"},{select:"id,display_id"}),ce=(Te||[]).filter(tt=>tt.id!==l);if(ce.length===0)return{committed:0,heldBy:[]};const lt=ce.map(tt=>tt.id),{data:Ce}=await Re("transactions",{},{select:"order_id,type,status,amount,description",inFilters:{order_id:lt}}),He=[];let Ve=0;for(const tt of ce){const Ke=(Ce||[]).filter(Rt=>Rt.order_id===tt.id&&Rt.status==="COMPLETED"),Be=Ke.filter(Rt=>Rt.type==="ORDER_PAYMENT"&&Rt.amount>0).reduce((Rt,Yt)=>Rt+Yt.amount,0),ut=Ke.filter(Rt=>Rt.type==="BALANCE_ADJUSTMENT"&&Rt.amount<0&&(Rt.description||"").includes("заказа")).reduce((Rt,Yt)=>Rt+Math.abs(Yt.amount),0),Ze=Math.max(Be-ut,0);Ze>0&&(Ve+=Ze,He.push({displayId:tt.display_id,amount:Ze}))}return{committed:Ve,heldBy:He}};a.useEffect(()=>{(async()=>{try{const Te=yt();if(!Te){C(!0),R(!0);return}const{data:ce,error:lt}=await Re("users",{id:Te},{select:"bonus_balance,balance,telegram_chat_id,welcome_bonus_remaining,welcome_bonus_expires_at",single:!0});if(lt)throw new Error(lt);ce?.telegram_chat_id&&hr(ce.telegram_chat_id);const Ce=Number(ce?.welcome_bonus_remaining)||0,He=ce?.welcome_bonus_expires_at||null,Ve=Ce>0&&!!He&&new Date(He).getTime()<=Date.now();U(Ve?0:Ce),re(He);const tt=Math.max(0,(ce?.bonus_balance||0)-(Ve?Ce:0)),Ke=ce?.balance||0;i(tt);let Be=Ke;if(Ke>0){const{committed:Rs,heldBy:ir}=await Vt(Te);Be=Math.max(Ke-Rs,0),$(Rs),me(ir)}o&&Ke<0?te(Math.abs(Ke)):Be>0&&F(Be);const ut=Be>0;let Ze=n;if(!o){try{const{data:Rs}=await Re("orders",{id:l},{select:"total_cny,commission_cny,client_preferences",single:!0});let ir=Rs?.client_preferences?.fixed_cny_rate;if(!ir){const{data:Zr}=await Re("app_settings",{},{select:"currencies",single:!0}),al=Zr?.currencies?.find(io=>io.code==="CNY");ir=al?Number(al.rate):null}if(Rs&&ir){const Zr=Math.round(((Rs.total_cny||0)+(Rs.commission_cny||
480))*ir);Zr>0&&Zr!==Ze&&(Ze=Zr)}}catch{}_t(Ze)}const Rt=o&&Ke<0?Math.abs(Ke):0,Yt=o?Ze+Rt:Ze,Ns=localStorage.getItem(b);Ns!==null&&ut&&(B(Ns==="1"),Ue(!0),Ns==="1"&&V(Math.min(Be>0?Be:0,Yt)));const Hs=localStorage.getItem(h);Hs!==null&&tt>0&&(xe(Hs==="1"),H(!0),Hs==="1"&&m(Math.min(tt,Yt))),(tt<=0&&!ut||localStorage.getItem(j))&&R(!0)}catch{R(!0)}finally{C(!0)}})()},[]),a.useEffect(()=>{const X=yt();if(!X)return;const Te=At.channel("topup_balance_sync").on("postgres_changes",{event:"UPDATE",schema:"public",table:"users",filter:`id=eq.${X}`},async ce=>{const lt=ce.new;if(lt.welcome_bonus_remaining!==void 0){const Ce=Number(lt.welcome_bonus_remaining)||0,He=lt.welcome_bonus_expires_at;U(He&&new Date(He).getTime()<=Date.now()?0:Ce)}if(lt.bonus_balance!==void 0&&i(lt.bonus_balance),lt.balance!==void 0){const Ce=lt.balance||0;if(Ce<0)te(Math.abs(Ce)),F(0),$(0),me([]);else{te(0);const{committed:He,heldBy:Ve}=await Vt(X);$(He),me(Ve),F(Math.max(Ce-He,0))}}}).subscribe();return()=>{At.removeChannel(Te)}},[]),a.useEffect(()=>{const X=At.channel(`card_replacement_${l}`).on("postgres_changes",{event:"INSERT",schema:"public",table:"notifications",filter:`link=eq.${l}`},Te=>{Te.new?.type==="CARD_AWAITING_REPLACEMENT"&&(St([]),M("awaiting_replacement"))}).subscribe();return()=>{At.removeChannel(X)}},[l]),a.useEffect(()=>{if(!N)return;(async()=>{Ut(!0);try{const Te=new Date().toISOString(),{data:ce,error:lt}=await Re("card_reservations",{order_id:l});if(lt)throw new Error(lt);const Ce=(ce||[]).filter(tt=>tt.expires_at>Te),He=(ce||[]).filter(tt=>tt.expires_at<=Te),Ve=(tt,Ke)=>{const Be=tt.map(Rt=>{const Yt=Ke.get(Rt.card_id)||{};return{id:Rt.id,card_id:Rt.card_id,amount:Rt.amount,card:{bank:Yt.bank||"",custom_bank_name:Yt.custom_bank_name||null,number:Yt.number||"",holder:Yt.holder||"",phone:Yt.phone||""}}});St(Be);const ut=tt[0].expires_at,Ze=Math.max(0,Math.floor((new Date(ut).getTime()-Date.now())/1e3));ee(Ze),u.current=!1};if(Ce.length>0){const{data:tt}=await Re("payment_cards",{}),Ke=new Map((tt||[]).filter(Ze=>Ze.is_active!==!1&&!Ze.is_archived).map(Ze=>[Ze.id,Ze])),Be=Ce.filter(Ze=>Ke.has(Ze.card_id));if(Be.length===0){for(const Ze of Ce)await ds("card_reservations",{id:Ze.id});localStorage.removeItem(j),localStorage.removeItem(b),localStorage.removeItem(h),R(!1),Ut(!1),C(!0);return}if((new Date(Be[0].expires_at).getTime()-Date.now())/1e3>3600){const Ze=new Date(Date.now()+18e5).toISOString(),Rt=[];for(const Yt of Be){await ds("card_reservations",{id:Yt.id});const Ns=crypto.randomUUID();await st("card_reservations",{id:Ns,card_id:Yt.card_id,order_id:l,order_display_id:Yt.order_display_id,amount:Yt.amount,expires_at:Ze,user_id:Yt.user_id}),Rt.push({...Yt,id:Ns,expires_at:Ze})}Ve(Rt,Ke)}else Ve(Be,Ke)}else if(He.length>0){const{data:tt}=await Re("payment_cards",{}),Ke=new Map((tt||[]).map(ut=>[ut.id,ut])),Be=He.filter(ut=>{const Ze=Ke.get(ut.card_id);return Ze&&Ze.is_active});if(Be.length===He.length&&Be.length>0){const ut=new Date(Date.now()+18e5).toISOString(),Ze=[];for(const Rt of He){await ds("card_reservations",{id:Rt.id});const Yt=crypto.randomUUID();await st("card_reservations",{id:Yt,card_id:Rt.card_id,order_id:l,order_display_id:Rt.order_display_id,amount:Rt.amount,expires_at:ut,user_id:Rt.user_id}),Ze.push({...Rt,id:Yt,expires_at:ut})}Ve(Ze,Ke)}else localStorage.removeItem(j),localStorage.removeItem(b),localStorage.removeItem(h),Tt==="card"?w():M("payment")}else if(localStorage.getItem(j)){const tt=yt(),Ke=parseInt(localStorage.getItem(j)||"0",10)||0,{data:Be}=tt?await Re("notifications",{user_id:tt,link:l}):{data:null};(Be||[]).some(Ze=>/оÑозван/i.test(Ze.title||"")&&new Date(Ze.date||Ze.created_at||0).getTime()>Ke)?(localStorage.removeItem(j),localStorage.removeItem(b),localStorage.removeItem(h),Tt==="card"?w():M("payment")):M("request_sent")}else Tt==="card"?w():M("payment")}catch{Tt==="card"&&w()}finally{Ut(!1)}})()},[l,N]),a.useEffect(()=>{if(Ge.length===0||se<=0)return;u.current=!1;const X=setInterval(()=>{_.current||P.current||ee(Te=>Te<=1?(clearInterval(X),u.current||(u.current=!0,localStorage.removeItem(j),M("expired")),0):Te-1)},1e3);return()=>clearInterval(X)},[Ge.length,se>0]),a.useEffect(()=>{A==="expired"&&(localStorage.removeItem(b),localStorage.removeItem(h))},[A]);const fs=X=>{Ge.length>0||(G(X),X==="card"?(mt(),w()):(ze(),M("payment")))},f=(X,Te)=>{navigator.clipboard.writeText(X),Gt(Te),setTimeout(()=>Gt(null),2e3)},ae=X=>`${Math.floor(X/60)}:${(X%60).toString().padStart(2,"0")}`,ue=()=>{E.current=!0,P.current||(_.current=!1),Y([]),ps.current&&(ps.current.value="")},Me=X=>{Y(Te=>{const ce=Te.filter((lt,Ce)=>Ce!==X);return ce.length===0&&!P.current&&(_.current=!1),ce}),ps.current&&(ps.current.value="")},Fe=X=>{he(Te=>{const ce=Te.filter((lt,Ce)=>Ce!==X);return ce.length===0&&mt(),ce}),zs.current&&(zs.current.value="")},ot=(X,Te)=>X.length+Te.length>=Ge.length,at=async(X,Te)=>{!o&&X.length>0&&Te.length===0&&await Je("orders",{id:l},{status:"PAID"}),await et(),await wt(),localStorage.removeItem(b),localStorage.removeItem(h),ke(!0)},vt=async X=>{if(!oe.length)return alert(d("topup_attach_receipt"));E.current=!1,ve(!0);try{const Te=yt();if(!Te)throw new Error("ÐолÑзоваÑÐµÐ»Ñ Ð½Ðµ найден");const ce=Ge.find(Ze=>Ze.id===X),lt=ce?.amount||0,Ce=xt.length+J.length+1,He=[];for(let Ze=0;Ze<oe.length;Ze++){const Rt=oe[Ze],Yt=Rt.name.split(".").pop(),Ns=`split_${l}_${X}_${Date.now()}_${Ze}.${Yt}`,{publicUrl:Hs}=await tr("receipts",Ns,Rt);He.push(Hs)}if(E.current)return;const Ve=crypto.randomUUID(),{error:tt}=await st("transactions",{id:Ve,user_id:Te,order_id:l,amount:lt,type:o?"DELIVERY_PAYMENT":"ORDER_PAYMENT",status:"PENDING",description:o?`ÐÐ»Ð¸ÐµÐ½Ñ Ð¾Ð¿Ð»Ð°Ñил доÑÑÐ°Ð²ÐºÑ Ð·Ð°ÐºÐ°Ð·Ð° ${c}
48 каÑÑой â ${lt.toLocaleString()} â½ (ÑаÑÑÑ ${Ce} из ${Ge.length})`:`ÐÐ»Ð¸ÐµÐ½Ñ Ð¾Ð¿Ð»Ð°Ñил заказ ${c} каÑÑой â ${lt.toLocaleString()} â½ (ÑаÑÑÑ ${Ce} из ${Ge.length})`,proof_image:He[0],proof_images:He,created_at:new Date().toISOString()});if(tt)throw new Error(tt);ce?.card_id&&Je("transactions",{id:Ve},{card_id:ce.card_id}).then(({error:Ze})=>{});const{error:Ke}=await st("notifications",{type:o?"DELIVERY_PAYMENT":"PAYMENT",title:o?`ÐплаÑа доÑÑавки â ${c}`:`ÐплаÑа заказа ${c}`,text:o?`ÐÐ»Ð¸ÐµÐ½Ñ Ð¾ÑпÑавил Ñек за доÑÑÐ°Ð²ÐºÑ Ð·Ð°ÐºÐ°Ð·Ð° ${c} â ÑаÑÑÑ ${Ce}/${Ge.length}.`:`ÐÐ»Ð¸ÐµÐ½Ñ Ð¾ÑпÑавил Ñек на ${lt.toLocaleString()} â½ (ÑаÑÑÑ ${Ce}/${Ge.length}).`,date:new Date().toISOString(),is_read:!1,link:l});if(ce?.card_id){const{data:Ze}=await Re("payment_cards",{id:ce.card_id},{select:"current_balance,daily_limit,limit,order_id",single:!0});if(Ze){const Rt=Ze.current_balance+lt;Ze.daily_limit&&Rt>Ze.daily_limit;const{error:Yt}=await Je("payment_cards",{id:ce.card_id},{current_balance:Rt,paid_at:new Date().toISOString()});Je("payment_cards",{id:ce.card_id},{last_order_display_id:c}).then(()=>{}).catch(()=>{}),Ze.order_id&&Ze.limit&&Rt>=Ze.limit&&Je("payment_cards",{id:ce.card_id},{is_active:!1,is_archived:!0,archived_at:new Date().toISOString()}).then(()=>{}).catch(()=>{})}}const{error:Be}=await ds("card_reservations",{id:X}),ut=[...xt,X];zt(ut),P.current=!0,ue(),ot(ut,J)&&await at(ut,J)}catch(Te){alert(d("topup_send_receipt_error_prefix")+Te.message)}finally{ve(!1)}},es=async X=>{ve(!0);try{const Te=Ge.find(He=>He.id===X),ce=Te?.amount||0,lt=xt.length+J.length+1;Te?.card_id&&await Je("payment_cards",{id:Te.card_id},{is_active:!1}),await st("notifications",{type:"PAYMENT_REQUEST",title:`ÐапÑÐ¾Ñ ÐºÐ°ÑÑÑ: ${ce.toLocaleString("ru-RU")} â½`,text:`ÐаÑÑа заблокиÑована клиенÑом. ÐÑжна замена Ð´Ð»Ñ Ð·Ð°ÐºÐ°Ð·Ð° ${c}, ÑÑмма ${ce.toLocaleString("ru-RU")} â½ (Ñаг ${lt}/${Ge.length}). [amount:${Math.round(ce)}]`,date:new Date().toISOString(),is_read:!1,link:l}),await ds("card_reservations",{id:X});const Ce=[...J,X];We(Ce),ue(),ot(xt,Ce)&&(xt.length===0?M("awaiting_replacement"):await at(xt,Ce))}catch(Te){alert(d("common_error_prefix")+Te.message)}finally{ve(!1)}},wt=async()=>{if(!(K<=0&&de<=0))try{if(!yt())return;if(K>0&&o){const Te=Ge.length<=1&&ge?ge.id:void 0,{error:ce}=await Qt("client_clear_goods_debt",{p_order_id:l,p_card_id:Te});if(ce)throw new Error(ce);Qt("ledger_shadow_client_goods_debt_clear",{p_order_id:l}).then(({error:lt})=>{}).catch(lt=>{})}if(de>0){const{error:Te}=await Qt("client_use_goods_balance",{p_order_id:l,p_amount:de,p_is_delivery:o});if(Te)throw new Error(Te);Qt("ledger_shadow_client_goods_balance_use",{p_order_id:l,p_amount:de}).then(({error:ce})=>{}).catch(ce=>{})}}catch{}},et=async()=>{if(!(x<=0))try{const X=yt();if(!X)return;const{error:Te}=await Qt("client_use_bonus",{p_order_id:l,p_amount:x});if(Te)throw new Error(Te);if(Qt("ledger_shadow_bonus_spend",{p_order_id:l,p_amount:x}).then(({error:ce})=>{}).catch(ce=>{}),L>0){const ce=Math.max(0,L-x),{error:lt}=await Je("users",{id:X},{welcome_bonus_remaining:ce});lt||U(ce)}}catch{}},kt=async()=>{if(!q.length)return alert(d("topup_attach_receipt"));if(Tt==="usdt"&&Q==="...")return alert("ÐÑÑÑ USDT еÑÑ Ð·Ð°Ð³ÑÑжаеÑÑÑ, подождиÑе ÑекÑÐ½Ð´Ñ Ð¸ попÑобÑйÑе Ñнова.");Xe(!0);try{await fe(q,Tt==="usdt",parseFloat(Q)),await et(),await wt(),localStorage.removeItem(b),localStorage.removeItem(h)}catch(X){alert(X.message)}finally{Xe(!1)}},pt=async()=>{if(Nt==="TELEGRAM"&&!Cs)return;if(Nt!=="SITE"&&Nt!=="TELEGRAM"&&!xs.trim())return alert(d("topup_specify_contacts"));if(!Ht)return alert(d("topup_min_split_amount",{amount:As.toLocaleString()}));Xe(!0),localStorage.setItem(b,I?"1":"0"),localStorage.setItem(h,k?"1":"0"),Ue(!0),H(!0);const X=Nt==="TELEGRAM"?Cs||"":xs,Te=qe>=os&&Mt>1?Zt:void 0;await pe(Nt,X,Te),Xe(!1)};if(T||A==="processing"){const X=J.length>0;return e.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-slate-900/60 backdrop-blur-md p-4",children:e.jsxs("div",{className:"bg-white rounded-3xl w-full max-w-md p-10 text-center shadow-2xl",children:[e.jsx("div",{className:`w-20 h-20 rounded-full flex items-center justify-center mx-auto mb-6 ${X?"bg-amber-100 text-amber-600":"bg-green-100 text-green-600"}`,children:X?e.jsx(hs,{size:44,strokeWidth:2}):e.jsx(ss,{size:44,strokeWidth:2})}),e.jsx("h3",{className:"text-2xl font-bold text-slate-900 mb-3",children:d(X?"topup_payments_sent":"topup_payment_accepted")}),e.jsx("p",{className:"text-slate-500 text-sm leading-relaxed mb-8",children:X?d("topup_paid_parts_summary",{paid:xt.length,total:Ge.length,problems:J.length}):ye>0?d("topup_balance_deducted_moscow_remainder",{amount:ye.toLocaleStr
48ing()}):d(le?o?"topup_balance_deducted_delivery_paid":"topup_balance_deducted_order_processing":"topup_status_updated_check_funds")}),e.jsx("button",{onClick:()=>{s?.(),t()},className:"w-full py-4 bg-slate-900 text-white rounded-2xl font-bold hover:bg-slate-800 transition-all",children:d("topup_understood")})]})})}if(!Pt&&Ge.length>0){if(A==="awaiting_replacement")return e.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-slate-900/60 backdrop-blur-sm p-4",children:e.jsxs("div",{className:"bg-white rounded-2xl w-full max-w-lg overflow-hidden shadow-2xl",children:[e.jsxs("div",{className:"px-6 py-5 border-b border-slate-100 flex justify-between items-center",children:[e.jsx("h2",{className:"text-xl font-bold text-slate-900",children:d("topup_order_payment_title")}),e.jsx("button",{onClick:Ms,className:"p-2 text-slate-400 hover:bg-slate-50 rounded-full",children:e.jsx(bt,{size:20})})]}),e.jsxs("div",{className:"p-6 py-10 text-center space-y-5",children:[e.jsx("div",{className:"w-16 h-16 bg-blue-100 text-blue-600 rounded-full flex items-center justify-center mx-auto animate-pulse",children:e.jsx(vr,{size:32})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-bold text-slate-900",children:d("topup_requisites_requested")}),e.jsxs("p",{className:"text-slate-500 text-sm mt-2 leading-relaxed",children:[d("topup_manager_will_send_new_card"),e.jsx("br",{}),d("topup_dont_transfer_old_card")]})]}),e.jsx("p",{className:"text-xs text-slate-400",children:d("topup_notification_will_arrive")})]})]})});if(A==="expired")return e.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-slate-900/60 backdrop-blur-sm p-4",children:e.jsxs("div",{className:"bg-white rounded-2xl w-full max-w-lg overflow-hidden shadow-2xl",children:[e.jsxs("div",{className:"px-6 py-5 border-b border-slate-100 flex justify-between items-center",children:[e.jsx("h2",{className:"text-xl font-bold text-slate-900",children:d("topup_order_payment_title")}),e.jsx("button",{onClick:Ms,className:"p-2 text-slate-400 hover:bg-slate-50 rounded-full",children:e.jsx(bt,{size:20})})]}),e.jsxs("div",{className:"p-6 py-8 text-center space-y-4",children:[e.jsx("div",{className:"w-16 h-16 bg-red-100 text-red-600 rounded-full flex items-center justify-center mx-auto",children:e.jsx(rs,{size:32})}),e.jsx("h3",{className:"text-xl font-bold text-slate-900",children:d("topup_reservation_expired")}),e.jsx("p",{className:"text-slate-500 text-sm",children:d("topup_dont_transfer_old_cards")}),e.jsxs("button",{onClick:async()=>{const{data:ce}=await Re("payment_cards",{}),lt=new Map((ce||[]).map(He=>[He.id,He])),Ce=Ge.filter(He=>{const Ve=lt.get(He.card_id);return Ve&&Ve.is_active});if(Ce.length===Ge.length&&Ce.length>0){const He=new Date(Date.now()+18e5).toISOString(),Ve=[];for(const tt of Ge){const Ke=crypto.randomUUID();await st("card_reservations",{id:Ke,card_id:tt.card_id,order_id:l,order_display_id:c||"",amount:tt.amount,expires_at:He,user_id:yt()}),Ve.push({id:Ke,card_id:tt.card_id,amount:tt.amount,card:tt.card})}St(Ve),ee(Math.floor((new Date(He).getTime()-Date.now())/1e3)),u.current=!1,_.current=!1,P.current=!1,M("loading")}else{for(const He of Ge)await ds("card_reservations",{id:He.id});St([]),M("no_cards_available")}},className:"w-full py-4 bg-slate-900 text-white rounded-xl font-bold hover:bg-slate-800 transition-all flex items-center justify-center gap-2",children:[e.jsx(vr,{size:18})," ",d("topup_get_requisites")]})]})]})});const X=new Set([...xt,...J]),Te=Ge.findIndex(ce=>!X.has(ce.id));return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-slate-900/60 backdrop-blur-sm p-4 overflow-y-auto",children:e.jsxs("div",{className:"bg-white rounded-[24px] sm:rounded-[32px] w-full max-w-lg shadow-2xl flex flex-col my-auto",children:[e.jsxs("div",{className:"px-5 sm:px-8 pt-6 sm:pt-7 pb-0 flex justify-between items-start",children:[e.jsxs("div",{className:"mb-4 sm:mb-5",children:[e.jsx("h2",{className:"text-xl sm:text-2xl font-black text-slate-900 tracking-tight",children:d("topup_order_payment_title")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mt-1",children:[e.jsx("span",{className:"text-sm font-bold text-blue-600 bg-blue-50 px-2 py-0.5 rounded-md",children:c}),e.jsx(Sr,{size:14,className:"text-slate-300"}),e.jsx("span",{className:"text-sm text-slate-500",children:d("topup_steps_done",{done:X.size,total:Ge.length})}),se>0&&e.jsxs("span",{className:`flex items-center gap-1 text-xs font-bold px-2 py-0.5 rounded-md ${se<=60?"bg-red-100 text-red-600":"bg-amber-50 text-amber-600"}`,children:[e.jsx(rs,{size:11}),Math.floor(se/60),":",String(se%60).padStart(2,"0")]})]})]}),e.jsx("button",{onClick:Ms,className:"p-2 text-slate-400 hover:bg-slate-100 rounded-full transition-colors mt-1",children:e.jsx(bt,{size:20})})]}),e.jsxs("div",{className:"px-8 pb-8 space-y-4",children:[e.jsxs("div",{className:"bg-amber-50 border border-amber-100 rounded-2xl p-4 flex gap-3 items-start",children:[e.jsx(hs,{className:"text-amber-500 shrink-0 mt-0.5",size:16}),e.jsx("p",{className:"text-xs font-semibold text-amber-800 leading-snug",children:d("topup_split_amount_note",{count:Ge.length})})]}),Xt()>Ge.length&&e.jsxs("div",{className:"bg-blue-50 border border-blue-100 rounded-2xl p-4 flex gap-3 items-start",children:[e.jsx(On,{className:"text-blue-500 shrink-0 mt-0.5",size:16}),e.jsx("p",{className:"text-xs font-semibold text-blue-800 leading-snug",children:d("topup_split_fewer_cards_note",{requested:Xt(),provided:Ge.length})})]}),e.jsx("div",{className:"space-y-3",children:Ge.map((ce,lt)=>{const Ce=xt.includes(ce.id),He=J.includes(ce.id),Ve=!Ce&&!He&<===Te;return e.jsx("div",{className:`rounded-2xl border-2 transition-all duration-300 ${Ce?"border-green-200 bg-green-50/50 opacity-70":He?"border-rose-200 bg-rose-50/50 opacity-70":Ve?"border-blue-500 bg-white shadow-xl shadow-blue-50":"border-slate-100 bg-slate-50 opacity-40"}`,children:e.jsxs("div",{className:"p-5",children:[e.jsxs("div",{className:"flex justify-between items-center mb-3",children:[e.jsx("span",{className:`text-[10px] font-black uppercase tracking-widest ${Ce?"text-green-600":He?"text-rose-500":Ve?"text-blue-600":"text-slate-400"}`,children:Ce?`â ${d("topup_receipt_sent")}`:He?`â ${d("topup_card_unavailable")}`:d("topup_step_n_of",{n:lt+1,total:Ge.length})}),e.jsxs("span",{className:"text-xl font-black text-slate-900",children:[ce.amount.toLocaleStr
48ing()," â½"]})]}),Ce&&e.jsx("p",{className:"text-xs text-green-700 font-medium",children:d("topup_awaiting_admin_confirmation")}),He&&e.jsx("p",{className:"text-xs text-rose-600 font-medium",children:d("topup_manager_will_send_new_requisites")}),Ve&&e.jsxs("div",{className:"space-y-4 mt-1",children:[e.jsxs("div",{className:"ym-hide-content bg-slate-900 rounded-2xl p-5 text-white relative overflow-hidden",children:[e.jsx("div",{className:"absolute top-0 right-0 p-4 opacity-10",children:e.jsx(Xs,{size:64})}),e.jsx("div",{className:"text-[10px] font-bold text-white/40 uppercase tracking-widest mb-2",children:ce.card.bank==="OTHER"&&ce.card.custom_bank_name?ce.card.custom_bank_name:ce.card.bank}),e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx("span",{className:"text-base font-mono font-bold tracking-wider",children:ce.card.number.replace(/\D/g,"").match(/.{1,4}/g)?.join(" ")||ce.card.number}),e.jsx("button",{onClick:()=>f(ce.card.number,`num-${ce.id}`),className:"p-1.5 bg-white/10 rounded-lg hover:bg-white/20 transition-colors",children:Ct===`
48num-${ce.id}`?e.jsx(Kt,{size:14}):e.jsx(Us,{size:14})})]}),ce.card.holder&&e.jsx("div",{className:"text-xs font-medium text-white/60 mb-1",children:ce.card.holder}),ce.card.phone&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs font-mono text-white/50",children:ce.card.phone}),e.jsx("button",{onClick:()=>f(ce.card.phone,`ph-${ce.id}`),className:"p-1 bg-white/10 rounded hover:bg-white/20 transition-colors",children:Ct===`ph-${ce.id}`?e.jsx(Kt,{size:12}):e.jsx(Us,{size:12})})]})]}),e.jsx("input",{type:"file",ref:ps,accept:"image/*,.pdf",multiple:!0,className:"hidden",onChange:tt=>{const Ke=Array.from(tt.target.files||[]);Ke.length&&(Y(Be=>[...Be,...Ke].slice(0,cs)),_.current=!0)}}),oe.length===0?e.jsxs("button",{onClick:()=>ps.current?.click(),className:"w-full py-4 border-2 border-dashed border-slate-200 rounded-2xl flex flex-col items-center gap-2 text-slate-400 hover:border-blue-400 hover:text-blue-600 hover:bg-blue-50/50 transition-all",children:[e.jsx(mn,{size:20}),e.jsx("span",{className:"text-sm font-bold",children:d("topup_attach_payment_receipt")}),e.jsx("span",{className:"text-xs text-slate-400",children:d("topup_or_paste_screenshot")})]}):e.jsxs("div",{className:"space-y-2",children:[oe.map((tt,Ke)=>e.jsxs("div",{className:"flex items-center justify-between p-3 bg-green-50 border border-green-100 rounded-2xl",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(Kt,{size:16,className:"text-green-600 shrink-0"}),e.jsx("span",{className:"text-xs font-bold text-slate-800 truncate",children:tt.name})]}),e.jsx("button",{onClick:()=>Me(Ke),className:"text-slate-400 hover:text-rose-500 ml-2 shrink-0",children:e.jsx(bt,{size:15})})]},Ke)),oe.length<cs&&e.jsxs("button",{onClick:()=>ps.current?.click(),className:"w-full py-2.5 border border-dashed border-slate-200 rounded-xl text-xs font-bold text-slate-400 hover:border-blue-400 hover:text-blue-600 hover:bg-blue-50/50 transition-all",children:["+ ",d("topup_add_another_receipt")]}),e.jsxs("div",{className:"flex justify-end gap-3 pt-1",children:[e.jsx("button",{onClick:ue,className:"text-slate-400 hover:text-rose-500 text-xs font-medium transition-colors",children:d("topup_remove")}),e.jsx("button",{disabled:Se,onClick:()=>vt(ce.id),className:"px-4 py-1.5 bg-blue-600 text-white rounded-xl text-xs font-bold hover:bg-blue-700 disabled:opacity-50 flex items-center gap-1.5 transition-all",children:Se?e.jsx(rt,{className:"animate-spin",size:13}):e.jsxs(e.Fragment,{children:[e.jsx(Kt,{size:13})," ",d("topup_send")]})})]})]}),e.jsxs("button",{disabled:Se,onClick:()=>Ae(ce.id),className:"w-full py-2.5 border border-rose-200 text-rose-500 bg-rose-50 hover:bg-rose-100 rounded-xl text-xs font-bold flex items-center justify-center gap-1.5 transition-all disabled:opacity-40",children:[e.jsx(Gr,{size:14})," ",d("topup_card_blocked_unavailable")]})]})]})},ce.id)})})]})]})}),be&&e.jsx(Xl,{onCancel:()=>Ae(null),onConfirm:()=>{const ce=be;Ae(null),ce==="regular"?je():es(ce)}})]})}const $t=()=>e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 gap-4",children:[e.jsx(rt,{className:"animate-spin text-blue-600",size:40}),e.jsx("p",{className:"text-slate-500 font-medium",children:d("topup_selecting_gateway")})]}),Bt=()=>e.jsxs("div",{className:"space-y-6 py-2",children:[e.jsxs("div",{className:"grid grid-cols-2 p-1 bg-slate-100 rounded-xl",children:[e.jsxs("button",{onClick:()=>fs("card"),className:`flex items-center justify-center gap-2 py-2.5 rounded-lg text-sm font-bold transition-all ${Tt==="card"?"bg-white text-blue-600 shadow-sm":"text-slate-500"}`,children:[e.jsx(Xs,{size:16})," ",d("topup_card_rf")]}),e.jsxs("button",{onClick:()=>fs("usdt"),className:`flex items-center justify-center gap-2 py-2.5 rounded-lg text-sm font-bold transition-all ${Tt==="usdt"?"bg-white text-green-600 shadow-sm":"text-slate-500"}`,children:[e.jsx(Ds,{size:16})," USDT TRC20"]})]}),e.jsxs("div",{className:"bg-amber-50 border border-amber-100 rounded-2xl p-5 text-center",children:[e.jsx("div",{className:"w-12 h-12 bg-amber-100 text-amber-600 rounded-full flex items-center justify-center mx-auto mb-3",children:e.jsx(Ss,{size:20})}),e.jsx("h3",{className:"text-base font-bold text-slate-900 mb-2",children:d("topup_selecting_card")}),e.jsxs("div",{className:"text-sm text-slate-500 space-y-1",children:[e.jsx("p",{children:d("topup_manager_will_select_card")}),e.jsx("p",{children:d("topup_requisites_in_notification")}),e.jsxs("p",{className:"pt-2 text-xs text-red-500 font-medium leading-snug",children:[d("topup_cards_hours"),e.jsx("br",{}),d("topup_cards_next_day")]}),e.jsxs("p",{className:"pt-2",children:[d("topup_or_pay_via_usdt_prefix")," ",e.jsx("strong",{className:"text-green-600",children:"USDT TRC20"})," ",d("topup_or_pay_via_usdt_suffix")]})]})]}),qe>=os&&e.jsxs("div",{className:"bg-slate-50 border border-slate-200 rounded-2xl p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Xs,{size:15,className:"text-slate-500 shrink-0"}),e.jsx("span",{className:"text-sm font-bold text-slate-700",children:d("topup_how_to_pay")})]}),e.jsx("div",{className:"grid grid-cols-3 gap-2",children:[1,2,3].map(X=>e.jsx("button",{onClick:()=>kr(X),className:`py-2.5 rounded-xl border text-sm font-bold transition-all ${Mt===X?"bg-slate-900 text-white border-slate-900":"bg-white text-slate-600 border-slate-200 hover:border-slate-400"}`,children:X===1?d("topup_whole_amount"):d("topup_n_parts",{n:X})},X))}),Mt>1&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs text-slate-500",children:d("topup_specify_amounts_note")}),Mt===2&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex-1 relative",children:[e.jsx("input",{type:"text",inputMode:"numeric",value:Ft[0],onChange:X=>Es([X.target.value.replace(/\D/g,""),Ft[1]]),className:"w-full px-3 py-2 bg-white border border-slate-200 rounded-xl text-sm font-medium focus:outline-none focus:border-blue-500",placeholder:String(Math.round(qe/2))}),e.jsx("span",{className:"absolute right-3 top-1/2 -translate-y-1/2 text-xs text-slate-400",children:"â½"})]}),e.jsx("span",{className:"text-slate-400 font-bold",children:"+"}),e.jsxs("div",{className:"flex-1 px-3 py-2 bg-slate-100 border border-slate-100 rounded-xl text-sm font-medium text-slate-500",children:[Math.max(0,qe-(parseInt(Ft[0].replace(/\D/g,""),10)||Math.round(qe/2))).toLocaleStr
48ing()," â½"]})]}),Mt===3&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex items-center gap-2",children:[0,1].map(X=>e.jsxs("div",{className:"flex-1 relative",children:[e.jsx("input",{type:"text",inputMode:"numeric",value:Ft[X],onChange:Te=>{const ce=[...Ft];ce[X]=Te.target.value.replace(/\D/g,""),Es(ce)},className:"w-full px-3 py-2 bg-white border border-slate-200 rounded-xl text-sm font-medium focus:outline-none focus:border-blue-500",placeholder:String(Math.round(qe/3))}),e.jsx("span",{className:"absolute right-3 top-1/2 -translate-y-1/2 text-xs text-slate-400",children:"â½"})]},X))}),e.jsxs("div",{className:"px-3 py-2 bg-slate-100 border border-slate-100 rounded-xl text-sm font-medium text-slate-500",children:["+ ",Math.max(0,qe-(parseInt(Ft[0].replace(/\D/g,""),10)||Math.round(qe/3))-(parseInt(Ft[1].replace(/\D/g,""),10)||Math.round(qe/3))).toLocaleString()," â½ (",d("topup_auto"),")"]})]}),Ht?e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-2 bg-blue-50 border border-blue-100 rounded-xl",children:[e.jsx(ss,{size:13,className:"text-blue-500 shrink-0"}),e.jsx("span",{className:"text-xs text-blue-700 font-medium",children:d("topup_manager_will_pick_cards",{amounts:Zt.map(X=>X.toLocaleString()+" â½").join(" + ")})})]}):e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-2 bg-red-50 border border-red-100 rounded-xl",children:[e.jsx(hs,{size:13,className:"text-red-500 shrink-0"}),e.jsx("span",{className:"text-xs text-red-600 font-medium",children:d("topup_min_split_amount",{amount:As.toLocaleString()})})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("label",{className:"block text-sm font-bold text-slate-700",children:d("topup_where_to_notify")}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("div",{className:"grid grid-cols-2 gap-3",children:[{id:"SITE",label:d("topup_on_site"),icon:e.jsx(_s,{size:15}),active:"bg-slate-900 text-white border-slate-900"},{id:"EMAIL",label:"Email",icon:e.jsx("span",{className:"font-bold text-xs",children:"@"}),active:"bg-slate-800 text-white border-slate-800"}].map(X=>e.jsxs("button",{onClick:()=>Wt(X.id),className:`p-3 rounded-xl border text-sm font-bold flex items-center gap-2 justify-center transition-all ${Nt===X.id?X.active:"bg-white text-slate-600 border-slate-200 hover:border-slate-300"}`,children:[X.icon," ",X.label]},X.id))}),e.jsxs("button",{onClick:()=>Wt("TELEGRAM"),className:`w-full p-3 rounded-xl border text-sm font-bold flex items-center gap-2 justify-center transition-all ${Nt==="TELEGRAM"?"bg-[#229ED9] text-white border-[#229ED9]":"bg-white text-slate-600 border-slate-200 hover:border-slate-300"}`,children:[e.jsx(Ss,{size:15})," Telegram",Cs&&e.jsx(ss,{size:13,className:"ml-auto opacity-80"})]})]}),Nt==="TELEGRAM"&&Cs&&e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 bg-blue-50 border border-blue-100 rounded-xl text-sm text-blue-700",children:[e.jsx(ss,{size:15,className:"shrink-0 text-blue-500"}),d("topup_telegram_auto_note")]}),Nt==="TELEGRAM"&&!Cs&&e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 bg-amber-50 border border-amber-200 rounded-xl text-sm text-amber-800",children:[e.jsx("span",{children:d("topup_connect_telegram_first")}),e.jsx("button",{type:"button",onClick:()=>{t(),window.dispatchEvent(new CustomEvent("tradehub:navigate",{detail:"PROFILE"}))},className:"font-bold underline underline-offset-2 hover:text-amber-900",children:d("topup_in_profile_arrow")})]}),Nt!=="SITE"&&Nt!=="TELEGRAM"&&e.jsx("input",{type:"text",value:xs,onChange:X=>fr(X.target.value),className:"w-full px-4 py-3 bg-slate-50 border border-slate-200 rounded-xl text-sm font-medium focus:outline-none focus:border-blue-500",placeholder:Nt==="EMAIL"?"[email protected]":"id123456"})]}),e.jsxs("div",{className:"pt-2 border-t border-slate-100 space-y-3",children:[e.jsx("button",{onClick:pt,disabled:_e||Nt==="TELEGRAM"&&!Cs||Nt!=="SITE"&&Nt!=="TELEGRAM"&&!xs||!Ht,className:"w-full py-4 bg-slate-900 text-white rounded-xl font-bold text-base hover:bg-slate-800 disabled:opacity-50 transition-all flex items-center justify-center gap-2",children:_e?e.jsx(rt,{className:"animate-spin",size:18}):d("topup_request_requisites")}),e.jsxs("button",{onClick:w,className:"w-full text-slate-400 hover:text-blue-600 text-sm font-medium flex items-center justify-center gap-1.5 transition-colors",children:[e.jsx(vr,{size:14})," ",d("topup_try_find_card_again")]})]})]}),ns=()=>e.jsxs("div",{className:"py-8 text-center space-y-4",children:[e.jsx("div",{className:"w-16 h-16 bg-red-100 text-red-600 rounded-full flex items-center justify-center mx-auto",children:e.jsx(rs,{size:32})}),e.jsx("h3",{className:"text-xl font-bold text-slate-900",children:d("topup_reservation_expired")}),e.jsx("p",{className:"text-slate-500 text-sm",children:d("topup_dont_transfer_old_card")}),e.jsxs("button",{onClick:w,className:"w-full py-4 bg-slate-900 text-white rounded-xl font-bold hover:bg-slate-800 transition-all flex items-center justify-center gap-2",children:[e.jsx(vr,{size:18})," ",d("topup_get_new_requisites")]})]}),vs=()=>e.jsxs("div",{className:"space-y-5",children:[it&&e.jsxs("div",{className:"bg-orange-50 border border-orange-200 rounded-xl p-4 text-sm text-orange-800 flex gap-3",children:[e.jsx(hs,{className:"shrink-0 mt-0.5 text-orange-500",size:18}),e.jsxs("span",{children:[e.jsx("strong",{children:d("topup_attention")})," ",d("topup_min_amount_note")]})]}),e.jsxs("div",{className:"text-center py-5 bg-slate-50 rounded-2xl border border-slate-100",children:[o&&K>0&&e.jsx("div",{className:"text-xs font-medium text-orange-600 mb-1",children:d("topup_goods_debt",{amount:K.toLocaleStr
48ing()})}),de>0&&e.jsx("div",{className:"text-xs font-bold text-blue-600 mb-1",children:d("topup_goods_balance_used",{amount:de.toLocaleString()})}),x>0&&e.jsx("div",{className:"text-xs font-bold text-amber-600 mb-1",children:d("topup_bonuses_used",{amount:x.toLocaleString()})}),e.jsx("p",{className:"text-[10px] font-black text-slate-400 uppercase tracking-widest mb-1",children:d("topup_to_pay")}),e.jsx("div",{className:"text-4xl font-bold text-slate-900 mb-2",children:Tt==="card"?`${qe.toLocaleString()} â½`:`${Q} USDT`}),Tt==="card"&&e.jsxs("div",{className:`inline-flex items-center gap-1.5 px-3 py-1 rounded-full text-xs font-bold border ${ie<30?"bg-red-50 text-red-600 border-red-100":"bg-amber-50 text-amber-700 border-amber-100"}`,children:[e.jsx(rs,{size:11,className:"animate-pulse"})," ",d("topup_reservation_label"),": ",ae(ie)]})]}),e.jsx("div",{className:"p-1 bg-slate-100 rounded-xl",children:e.jsxs("button",{onClick:()=>fs("card"),className:"w-full flex items-center justify-center gap-2 py-2.5 rounded-lg text-sm font-bold bg-white text-blue-600 shadow-sm",children:[e.jsx(Xs,{size:16})," ",d("topup_card_rf")]})}),e.jsx("div",{className:"ym-hide-content",children:Tt==="card"&&ge?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"p-5 border border-slate-200 rounded-2xl bg-white shadow-sm hover:border-blue-200 transition-all",children:[e.jsxs("div",{className:"text-xs font-bold text-slate-400 uppercase mb-2",children:[d("topup_card_number")," (",ge.bank==="OTHER"&&ge.custom_bank_name?ge.custom_bank_name:ge.bank,")"]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("div",{className:"font-mono text-xl font-bold text-slate-900 tracking-wider",children:ge.number.replace(/\D/g,"").match(/.{1,4}/g)?.join(" ")||ge.number}),e.jsx("button",{onClick:()=>f(ge.number,"card"),className:"p-2 text-slate-400 hover:text-blue-600 transition-colors",children:Ct==="card"?e.jsx(Kt,{size:20,className:"text-green-500"}):e.jsx(Us,{size:20})})]})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsxs("div",{className:"flex-1 p-3 border border-slate-200 rounded-xl bg-white",children:[e.jsx("div",{className:"text-[10px] font-bold text-slate-400 uppercase mb-1",children:d("order_details_recipient")}),e.jsx("div",{className:"text-sm font-bold text-slate-900 truncate",children:ge.holder})]}),ge.phone&&e.jsxs("div",{className:"flex-1 p-3 border border-slate-200 rounded-xl bg-white",children:[e.jsx("div",{className:"text-[10px] font-bold text-slate-400 uppercase mb-1",children:d("topup_phone_sbp")}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("div",{className:"text-sm font-bold text-slate-900",children:ge.phone}),e.jsx("button",{onClick:()=>f(ge.phone,"sbp"),className:"text-slate-400 hover:text-blue-600",children:Ct==="sbp"?e.jsx(Kt,{size:14,className:"text-green-500"}):e.jsx(Us,{size:14})})]})]})]}),e.jsxs("div",{className:"flex gap-2 items-start bg-red-50 border border-red-100 rounded-xl p-3",children:[e.jsx(hs,{className:"shrink-0 mt-0.5 text-red-500",size:16}),e.jsx("p",{className:"text-xs text-red-600 leading-snug font-medium",children:d("card_request_pay_ready_warning")})]})]}):Tt==="usdt"?Number(Q)>y?e.jsx("div",{className:"p-4 border border-slate-200 rounded-2xl bg-white space-y-3",children:Ee?ne?ne.status==="PENDING"?e.jsxs("div",{className:"text-center space-y-2 py-4",children:[e.jsx("div",{className:"w-12 h-12 bg-blue-50 text-blue-600 rounded-full flex items-center justify-center mx-auto animate-pulse",children:e.jsx(_s,{size:20})}),e.jsx("h3",{className:"text-sm font-bold text-slate-900",children:d("topup_wallet_requested")}),e.jsxs("p",{className:"text-xs text-slate-500 leading-relaxed",children:[d("topup_wallet_request_received",{amount:ne&&ne.amount_usdt?`${ne.amount_usdt} `:""}),d("topup_requisites_in_notification")]})]}):e.jsxs(e.Fragment,{children:[ne.qr_image&&e.jsxs("div",{className:"flex flex-col items-center gap-2 pb-3 border-b border-slate-100",children:[e.jsx("p",{className:"text-xs font-bold text-slate-400 uppercase",children:d("topup_scan_to_pay")}),e.jsx("button",{type:"button",onClick:()=>_r(!0),className:"cursor-zoom-in",children:e.jsx("img",{src:ne.qr_image,alt:"USDT QR",className:"w-44 h-44 object-contain rounded-xl border border-slate-200 bg-white p-1"})}),e.jsx("p",{className:"text-[11px] text-slate-400",children:d("topup_click_to_zoom")})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("div",{className:"text-xs font-bold text-slate-400 uppercase",children:d("topup_individual_wallet")}),e.jsxs("button",{onClick:()=>f(ne.wallet_address||"","usdt"),className:"text-blue-600 text-xs font-bold flex items-center gap-1",children:[Ct==="usdt"?e.jsx(Kt,{size:13}):e.jsx(Us,{size:13})," ",d("topup_copy")]})]}),e.jsx("div",{className:"font-mono text-xs break-all bg-slate-50 p-3 rounded-xl border border-slate-100 text-slate-700",children:ne.wallet_address})]}):e.jsxs("div",{className:"text-center space-y-3 py-2",children:[e.jsx("div",{className:"w-12 h-12 bg-amber-50 text-amber-600 rounded-full flex items-center justify-center mx-auto",children:e.jsx(hs,{size:20})}),e.jsxs("p",{className:"text-sm text-slate-600 leading-snug",children:[d("topup_amount_exceeds_prefix")," ",e.jsxs("strong",{children:[y," USDT"]})," ",d("topup_amount_exceeds_suffix")]}),e.jsxs("button",{onClick:It,disabled:nt,className:"w-full py-3 bg-slate-900 text-white rounded-xl font-bold text-sm hover:bg-slate-800 disabled:opacity-50 transition-all flex items-center justify-center gap-2",children:[nt?e.jsx(rt,{className:"animate-spin",size:16}):e.jsx(Ss,{size:16}),d("topup_request_wallet")]})]}):e.jsx("div",{className:"flex items-center justify-center py-6",children:e.jsx(rt,{className:"animate-spin text-slate-400",size:24})})}):e.jsxs("div",{className:"p-4 border border-slate-200 rounded-2xl bg-white space-y-3",children:[ks&&e.jsxs("div",{className:"flex flex-col items-center gap-2 pb-3 border-b border-slate-100",children:[e.jsx("p",{className:"text-xs font-bold text-slate-400 uppercase",children:d("topup_scan_to_pay")}),e.jsx("button",{type:"button",onClick:()=>_r(!0),className:"cursor-zoom-in",children:e.jsx("img",{src:ks,alt:"USDT QR",className:"w-44 h-44 object-contain rounded-xl border border-slate-200 bg-white p-1"})}),e.jsx("p",{className:"text-[11px] text-slate-400",children:d("topup_click_to_zoom")})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("div",{className:"text-xs font-bold text-slate-400 uppercase",children:d("topup_wallet_trc20")}),e.jsxs("button",{onClick:()=>f(Ws,"usdt"),className:"text-blue-600 text-xs font-bold flex items-center gap-1",children:[Ct==="usdt"?e.jsx(Kt,{size:13}):e.jsx(Us,{size:13})," ",d("topup_copy")]})]}),e.jsx("div",{className:"font-mono text-xs break-all bg-slate-50 p-3 rounded-xl border border-slate-100 text-slate-700",children:Ws})]}):null}),Tt==="card"&&Xt()>1&&e.jsxs("div",{className:"bg-blue-50 border border-blue-100 rounded-2xl p-4 flex gap-3 items-start",children:[e.jsx(On,{className:"text-blue-500 shrink-0 mt-0.5",size:16}),e.jsx("p",{className:"text-xs font-semibold text-blue-800 leading-snug",children:d("topup_split_fewer_cards_note",{requested:Xt(),provided:1})})]}),e.jsxs("div",{className:"border-t border-slate-100 pt-4",children:[e.jsx("input",{type:"file",ref:zs,multiple:!0,onChange:X=>{const Te=Array.from(X.target.files||[]);Te.length&&(he(ce=>[...ce,...Te].slice(0,cs)),ze())},className:"hidden",accept:".jpg,.jpeg,.png,.pdf"}),q.length===0?e.jsxs("button",{onClick:()=>zs.current?.click(),className:"w-full py-5 border-2 border-dashed border-slate-200 rounded-2xl flex flex-col items-center gap-2 text-slate-400 hover:border-blue-400 hover:text-blue-600 hover:bg-blue-50/50 transition-all",children:[e.jsx(mn,{size:22}),e.jsx("span",{className:"text-sm font-bold",children:d("topup_attach_payment_receipt")}),e.jsx("span",{className:"text-xs text-slate-400",children:d("topup_or_paste_screenshot")})]}):e.jsxs("div",{className:"space-y-2",children:[q.map((X,Te)=>e.jsxs("div",{className:"flex items-center justify-between p-3 bg-green-50 border border-green-200 rounded-xl",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(Kt,{size:18,className:"text-green-600 shrink-0"}),e.jsx("p",{className:"text-sm font-bold text-slate-900 truncate max-w-[180px]",children:X.name})]}),e.jsx("button",{onClick:()=>Fe(Te),className:"text-slate-400 hover:text-red-500 ml-2 shrink-0 transition-colors",children:e.jsx(bt,{size:18})})]},Te)),q.length<cs&&e.jsxs("button",{onClick:()=>zs.current?.click(),className:"w-full py-2.5 border border-dashed border-slate-200 rounded-xl text-xs font-bold text-slate-400 hover:border-blue-400 hover:text-blue-600 hover:bg-blue-50/50 transition-all",children:["+ ",d("topup_add_another_receipt")]})]})]}),e.jsx("button",{disabled:!q.length||_e||Tt==="card"&&ie<=0,onClick:kt,className:"w-full py-4 bg-slate-900 text-white rounded-2xl font-bold text-lg shadow-lg hover:bg-black disabled:opacity-40 disabled:cursor-not-allowed transition-all flex items-center justify-center gap-2",children:_e?e.jsx(rt,{className:"animate-spin",size:20}):e.jsxs(e.Fragment,{children:[e.jsx(Kt,{size:20})," ",d("topup_confirm_payment")]})}),Tt==="card"&&ge&&e.jsxs("button",{disabled:_e,onClick:()=>Ae("regular"),className:"w-full py-2.5 border border-rose-200 text-rose-500 bg-rose-50 hover:bg-rose-100 rounded-xl text-sm font-bold flex items-center justify-center gap-1.5 transition-all disabled:opacity-40",children:[e.jsx(Gr,{size:15})," ",d("topup_card_blocked_unavailable")]})]});if(S&&!N){const X=I&&O>0?dt:0,Te=k&&v>0?gt:0,ce=jt-X-Te,lt=ce<=0?0:Math.max(ce,p),Ce=o&&ce>0&&ce<p,He=async()=>
48{if(Oe)return;we(!0);const Ve=I&&O>0?dt:0,tt=k&&v>0?gt:0;if(V(Ve),m(tt),Ce){try{const Ke=yt();if(!Ke){we(!1);return}if(Ve>0){const{error:Ze}=await Qt("client_use_goods_balance",{p_order_id:l,p_amount:Ve,p_is_delivery:!0});if(Ze)throw new Error(Ze);Qt("ledger_shadow_client_goods_balance_use",{p_order_id:l,p_amount:Ve}).then(({error:Rt})=>{}).catch(Rt=>{})}const{error:Be}=await Je("orders",{id:l},{delivery_prepaid_amount:Ve});if(Be)throw new Error(Be);const{error:ut}=await st("transactions",{user_id:Ke,order_id:l,amount:Ve,type:"DELIVERY_PAYMENT",status:"COMPLETED",description:`ÐоÑÑавка ${c}: ${Ve.toLocaleString("ru-RU")} â½ ÑпиÑано Ñ Ð±Ð°Ð»Ð°Ð½Ñа ÑоваÑов, оÑÑаÑок ${ce.toLocaleString("ru-RU")} â½ â пÑи полÑÑении в ÐоÑкве`,created_at:new Date().toISOString()});if(ut)throw new Error(ut);await st("notifications",{type:"DELIVERY_PAYMENT",title:`ЧаÑÑиÑÐ½Ð°Ñ Ð¾Ð¿Ð»Ð°Ñа доÑÑавки â ${c}`,text:`ÐÐ°Ð»Ð°Ð½Ñ ${Ve.toLocaleString("ru-RU")} â½ ÑпиÑан. ÐÑÑаÑок ${ce.toLocaleString("ru-RU")} ⽠бÑÐ´ÐµÑ Ð¾Ð¿Ð»Ð°Ñен пÑи полÑÑении в ÐоÑкве.`,date:new Date().toISOString(),is_read:!1,link:l}),Ie(ce),ke(!0)}catch(Ke){alert(d("common_error_prefix")+Ke.message),we(!1)}return}if(lt===0){try{const Ke=yt();if(!Ke){we(!1);return}if(o){const{error:Be}=await st("transactions",{user_id:Ke,order_id:l,amount:jt,type:"DELIVERY_PAYMENT",status:"COMPLETED",description:`ÐоÑÑавка заказа ${c} оплаÑена Ñ Ð±Ð°Ð»Ð°Ð½Ñа ÑоваÑов â ${jt.toLocaleString("ru-RU")} â½`,created_at:new Date().toISOString()});if(Be)throw new Error(Be);const{error:ut}=await Je("orders",{id:l},{delivery_paid:!0,delivery_prepaid_amount:Ve});if(ut)throw new Error(ut);await st("notifications",{type:"DELIVERY_PAYMENT",title:`ÐплаÑа доÑÑавки â ${c}`,text:`ÐÐ»Ð¸ÐµÐ½Ñ Ð¾Ð¿Ð»Ð°Ñил доÑÑÐ°Ð²ÐºÑ Ð·Ð°ÐºÐ°Ð·Ð° ${c} из баланÑа ÑоваÑов (${jt.toLocaleString("ru-RU")} â½).`,date:new Date().toISOString(),is_read:!1,link:l}),await st("notifications",{user_id:Ke,type:"DELIVERY_PAYMENT",title:`ÐплаÑа доÑÑавки подÑвеÑждена â ${c}`,text:`ÐоÑÑавка заказа ${c} оплаÑена из баланÑа ÑоваÑов (${jt.toLocaleString("ru-RU")} â½).`,date:new Date().toISOString(),is_read:!1,link:l})}else{const{error:Be}=await st("transactions",{user_id:Ke,order_id:l,amount:Ve,type:"ORDER_PAYMENT",status:"COMPLETED",description:`Ðаказ ${c} оплаÑен Ñ Ð±Ð°Ð»Ð°Ð½Ñа ÑоваÑов â ${Ve.toLocaleString("ru-RU")} â½`,created_at:new Date().toISOString()});if(Be)throw new Error(Be);const{error:ut}=await Je("orders",{id:l},{status:"PAID"});if(ut)throw new Error(ut);await st("notifications",{type:"PAYMENT",title:`ÐплаÑа заказа â ${c}`,text:`ÐÐ»Ð¸ÐµÐ½Ñ Ð¾Ð¿Ð»Ð°Ñил заказ ${c} из баланÑа ÑоваÑов (${Ve.toLocaleString("ru-RU")} â½).`,date:new Date().toISOString(),is_read:!1,link:l})}if(Ve>0){const{error:Be}=await Qt("client_use_goods_balance",{p_order_id:l,p_amount:Ve,p_is_delivery:o});if(Be)throw new Error(Be);Qt("ledger_shadow_client_goods_balance_use",{p_order_id:l,p_amount:Ve}).then(({error:ut})=>{}).catch(ut=>{})}Qe(!0),ke(!0)}catch(Ke){alert(d("common_error_prefix")+Ke.message),we(!1)}return}we(!1),R(!0)};return e.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-slate-900/60 backdrop-blur-sm p-4",children:e.jsxs("div",{className:"bg-white rounded-2xl w-full max-w-md max-h-[90vh] overflow-hidden shadow-2xl flex flex-col",children:[e.jsxs("div",{className:"px-6 py-5 border-b border-slate-100 flex justify-between items-center shrink-0",children:[e.jsx("h2",{className:"text-xl font-bold text-slate-900",children:d(o?"topup_delivery_payment_title":"topup_order_payment_title")}),e.jsx("button",{onClick:Ms,className:"p-2 text-slate-400 hover:bg-slate-50 rounded-full",children:e.jsx(bt,{size:20})})]}),e.jsxs("div",{className:"p-6 space-y-4 overflow-y-auto",children:[K>0&&e.jsxs("div",{className:"bg-orange-50 border border-orange-200 rounded-xl p-4 flex gap-3 items-start",children:[e.jsx(hs,{className:"text-orange-500 shrink-0 mt-0.5",size:16}),e.jsxs("div",{className:"text-sm text-orange-800",children:[e.jsx("span",{className:"font-bold",children:d("topup_goods_debt_label",{amount:K.toLocaleStr
48ing()})}),e.jsx("br",{}),e.jsx("span",{className:"text-xs",children:d("topup_included_automatically")})]})]}),D>0&&e.jsxs("div",{className:"bg-slate-50 border border-slate-200 rounded-xl p-3 text-xs text-slate-600",children:[e.jsx("span",{className:"font-semibold text-slate-700",children:d("topup_goods_balance_total",{amount:(O+D).toLocaleString()})}),e.jsx("br",{}),d("topup_available_for_order"),": ",e.jsxs("span",{className:"font-semibold",children:[O.toLocaleString()," â½"]}),e.jsx("br",{}),d("topup_reserved_by_orders",{orders:z.map(Ve=>Ve.displayId).join(", "),amount:D.toLocaleString()})]}),O>0&&e.jsx("div",{className:`border-2 rounded-2xl p-4 transition-all ${Ne?"opacity-80":"cursor-pointer"} ${I?"border-blue-400 bg-blue-50":"border-slate-200 bg-white"}`,onClick:()=>{Ne||B(Ve=>!Ve)},children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-5 h-5 rounded-full border-2 flex items-center justify-center shrink-0 ${I?"border-blue-500 bg-blue-500":"border-slate-300"}`,children:I&&e.jsx(Kt,{size:12,className:"text-white"})}),e.jsx(Ds,{size:16,className:I?"text-blue-600":"text-slate-400"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-bold text-slate-900",children:d("topup_goods_balance")}),e.jsx("div",{className:"text-xs text-slate-500",children:d("topup_can_cover_up_to_100",{amount:O.toLocaleString()})}),Ne&&e.jsx("div",{className:"text-xs text-amber-600 font-medium mt-0.5",children:d("topup_locked_on_card_request")})]}),I&&e.jsxs("span",{className:"ml-auto text-sm font-bold text-blue-600",children:["â",dt.toLocaleString()," â½"]})]})}),v>0&&e.jsx("div",{className:`border-2 rounded-2xl p-4 transition-all ${$e?"opacity-80":"cursor-pointer"} ${k?"border-amber-300 bg-amber-50":"border-slate-200 bg-white"}`,onClick:()=>{$e||xe(Ve=>!Ve)},children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-5 h-5 rounded-full border-2 flex items-center justify-center shrink-0 ${k?"border-amber-500 bg-amber-500":"border-slate-300"}`,children:k&&e.jsx(Kt,{size:12,className:"text-white"})}),e.jsx("span",{className:"text-base",children:"ð"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-bold text-slate-900",children:d("topup_bonus_rubles")}),e.jsx("div",{className:"text-xs text-slate-500",children:d("topup_up_to_50_percent",{amount:v.toLocaleString()})}),Z!==null&&e.jsxs("div",{className:"text-xs font-bold text-red-500 mt-0.5",children:["ð¥ ",L.toLocaleString()," â½ ",Z<=0?d("topup_bonus_expires_today"):d("topup_bonus_expires_in",{days:Z})]}),$e&&e.jsx("div",{className:"text-xs text-amber-600 font-medium mt-0.5",children:d("topup_locked_on_card_request")})]}),k&&e.jsxs("span",{className:"ml-auto text-sm font-bold text-amber-600",children:["â",gt.toLocaleString()," â½"]})]})}),e.jsxs("div",{className:"bg-slate-50 border border-slate-100 rounded-xl p-4 space-y-2 text-sm",children:[e.jsxs("div",{className:"flex justify-between text-slate-600",children:[e.jsx("span",{children:d(o?"layout_label_delivery":"orders_tab_new")}),e.jsxs("span",{children:[Le.toLocaleString()," â½"]})]}),K>0&&e.jsxs("div",{className:"flex justify-between text-orange-700",children:[e.jsxs("span",{children:["+ ",d("topup_debt_short")]}),e.jsxs("span",{children:["+",K.toLocaleString()," â½"]})]}),I&&O>0&&e.jsxs("div",{className:"flex justify-between text-blue-700",children:[e.jsxs("span",{children:["â ",d("topup_goods_balance")]}),e.jsxs("span",{children:["â",dt.toLocaleString()," â½"]})]}),k&&v>0&&e.jsxs("div",{className:"flex justify-between text-amber-700",children:[e.jsxs("span",{children:["â ",d("layout_label_bonus")]}),e.jsxs("span",{children:["â",gt.toLocaleString()," â½"]})]}),e.jsxs("div",{className:`flex justify-between font-bold pt-2 border-t border-slate-200 ${lt===0?"text-green-700":Ce?"text-orange-700":"text-slate-900"}`,children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[d(Ce?"topup_pay_in_moscow":"topup_total_by_card"),!Ce&&ce>0&<>ce&&e.jsx("button",{type:"button",onClick:()=>Rr(Ve=>!Ve),className:"text-amber-500 hover:text-amber-600 transition-colors","aria-label":d("topup_why_20000"),children:e.jsx(On,{size:15})})]}
48),e.jsx("span",{children:lt===0?"0 â½":Ce?`${ce.toLocaleString()} â½`:`${lt.toLocaleString()} â½`})]}),!Ce&&ce>0&<>ce&&e.jsxs("div",{className:"text-xs text-slate-500 font-normal",children:[d("topup_actual_debt"),": ",e.jsxs("span",{className:"font-semibold text-slate-700",children:[ce.toLocaleString()," â½"]})," · ",d("topup_diff_to_goods_balance")]}),pr&&e.jsx("div",{className:"bg-amber-50 border border-amber-200 rounded-xl p-3 text-xs text-amber-800 leading-relaxed",children:d("topup_min_amount_explanation")}),lt===0&&e.jsx("div",{className:"text-xs text-green-600 font-medium text-center",children:d("topup_fully_covered_by_balance")}),Ce&&e.jsx("div",{className:"text-xs text-orange-600 font-medium text-center",children:d("topup_remainder_paid_in_moscow")})]}),(()=>{const Ve=Ce&&O>0&&!I,tt=Oe||Ve,Ke=(lt===0||Ce)&&!Ve;return e.jsx("button",{onClick:He,disabled:tt,className:`w-full py-3.5 text-white rounded-xl font-bold transition-all ${tt?"bg-slate-300 cursor-not-allowed":Ke?"bg-green-600 hover:bg-green-700":"bg-slate-900 hover:bg-black"}`,children:d(lt===0?"topup_deduct_from_balance":Ce?"orders_confirm_button":"topup_continue_to_payment")})})()]})]})})}return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-slate-900/60 backdrop-blur-sm p-4",children:e.jsxs("div",{className:"bg-white rounded-2xl w-full max-w-lg max-h-[90vh] overflow-hidden shadow-2xl flex flex-col",children:[e.jsxs("div",{className:"px-6 py-5 border-b border-slate-100 flex justify-between items-center shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[o&&e.jsx("div",{className:"w-10 h-10 bg-orange-50 rounded-xl flex items-center justify-center text-orange-500 shrink-0",children:e.jsx(Lt,{size:20})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold text-slate-900",children:d(o?"topup_delivery_payment_title":"topup_order_payment_title")}),e.jsxs("div",{className:"flex items-center gap-2 text-sm text-slate-500 mt-0.5",children:[e.jsx("span",{children:d("topup_order_label",{id:c||"..."})}),ge&&A==="payment"&&e.jsx("span",{className:"bg-green-100 text-green-700 text-[10px] px-2 py-0.5 rounded-full font-bold",children:d("topup_gateway_reserved")})]})]})]}),e.jsx("button",{onClick:Ms,className:"p-2 text-slate-400 hover:bg-slate-50 rounded-full",children:e.jsx(bt,{size:20})})]}),e.jsxs("div",{className:"p-6 overflow-y-auto",children:[Pt&&$t(),!Pt&&A==="loading"&&$t(),!Pt&&A==="no_cards_available"&&Bt(),!Pt&&A==="awaiting_replacement"&&e.jsxs("div",{className:"py-10 text-center space-y-5",children:[e.jsx("div",{className:"w-16 h-16 bg-blue-100 text-blue-600 rounded-full flex items-center justify-center mx-auto animate-pulse",children:e.jsx(vr,{size:32})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-bold text-slate-900",children:d("topup_changing_requisites")}),e.jsxs("p",{className:"text-slate-500 text-sm mt-2",children:[d("topup_replacing_card_wait"),e.jsx("br",{}),d("topup_new_requisites_auto")]})]}),e.jsx("p",{className:"text-xs text-slate-400",children:d("topup_dont_transfer_old_card")})]}),!Pt&&A==="expired"&&ns(),!Pt&&A==="card_window_closed"&&e.jsxs("div",{className:"py-10 text-center space-y-5",children:[e.jsx("div",{className:"w-16 h-16 bg-amber-100 text-amber-600 rounded-full flex items-center justify-center mx-auto",children:e.jsx(rs,{size:32})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-bold text-slate-900 mb-2",children:d("card_issue_window_closed_title")}),e.jsx("p",{className:"text-slate-500 text-sm max-w-xs mx-auto",children:d("card_issue_window_closed_text")})]}),e.jsx("button",{onClick:t,className:"px-8 py-3 bg-slate-900 text-white rounded-xl font-bold hover:bg-slate-800 transition-all",children:d("topup_understood")})]}),!Pt&&A==="request_sent"&&e.jsxs("div",{className:"py-10 text-center space-y-5",children:[e.jsx("div",{className:"w-16 h-16 bg-blue-100 text-blue-600 rounded-full flex items-center justify-center mx-auto",children:e.jsx(_s,{size:32})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-bold text-slate-900 mb-2",children:d("topup_requisites_already_requested")}),e.jsxs("div",{className:"text-slate-500 text-sm space-y-1 max-w-xs mx-auto",children:[e.jsx("p",{children:d("topup_request_received_preparing")}),e.jsx("p",{children:d("topup_notification_when_ready")})]})]}),e.jsx("button",{onClick:t,className:"px-8 py-3 bg-slate-900 text-white rounded-xl font-bold hover:bg-slate-800 transition-all",children:d("topup_understood")})]}),!Pt&&A==="payment"&&vs()]})]})}),be&&e.jsx(Xl,{onCancel:()=>Ae(null),onConfirm:()=>{const X=be;Ae(null),X==="regular"?je():es(X)}}),Tr&&e.jsx("div",{className:"fixed inset-0 z-[200] flex items-center justify-center bg-slate-900/70 p-4",children:e.jsxs("div",{className:"bg-white rounded-2xl p-6 max-w-sm w-full shadow-2xl",children:[e.jsx("h3",{className:"text-lg font-bold text-slate-900 mb-2",children:d("topup_close_payment_window")}),e.jsx("p",{className:"text-sm text-slate-500 leading-relaxed mb-6",children:d("topup_receipt_will_be_lost")}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{onClick:()=>qs(!1),className:"flex-1 py-2.5 border border-slate-200 rounded-xl text-sm font-bold text-slate-600 hover:bg-slate-50 transition-colors",children:d("topup_stay")}),e.jsx("button",{onClick:()=>{qs(!1),t()},className:"flex-1 py-2.5 bg-red-500 text-white rounded-xl text-sm font-bold hover:bg-red-600 transition-colors",children:d("topup_close_anyway")})]})]})}),gr&&ks&&e.jsx("div",{className:"fixed inset-0 z-[300] flex items-center justify-center bg-slate-900/80 p-4",onClick:()=>_r(!1),children:e.jsx("img",{src:ks,alt:"USDT QR",className:"w-full max-w-sm aspect-square object-contain rounded-2xl bg-white p-3"})})]})};function Xl({onCancel:t,onConfirm:s}){const{t:n}=qt();return e.jsx("div",{className:"fixed inset-0 z-[200] flex items-center justify-center bg-slate-900/70 p-4",children:e.jsxs("div",{className:"bg-white rounded-2xl p-6 max-w-sm w-full shadow-2xl",children:[e.jsx("h3",{className:"text-lg font-bold text-slate-900 mb-2",children:n("topup_card_unavailable_question")}),e.jsxs("p",{className:"text-sm text-slate-500 leading-relaxed mb-6",children:[n("topup_sure_cannot_pay"),e.jsx("br",{}),n("topup_manager_will_send_new_requisites")]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{onClick:t,className:"flex-1 py-2.5 border border-slate-200 rounded-xl text-sm font-bold text-slate-600 hover:bg-slate-50 transition-colors",children:n("orders_cancel_button")}),e.jsx("button",{onClick:s,className:"flex-1 py-2.5 bg-rose-500 text-white rounded-xl text-sm font-bold hover:bg-rose-600 transition-colors",children:n("topup_yes_blocked")})]})]})})}const Zl=({order:t,currentUsdRate:s,onClose:n,onSuccess:r})=>{const l=t.delivery_invoice;if(!l)return null;const c=Math.round((l.totalUSD||0)*s)||l.totalRUB||0,o=t.delivery_prepaid_amount??0,d=Math.max(c-o,0
48);return e.jsx(nl,{isDelivery:!0,onClose:n,onPaymentSuccess:r,initialAmount:d,orderUUID:t.id,displayId:t.display_id||t.displayId||""})};function ei(t,s){let n=Math.max(0,Math.round(s));return t.map(r=>{const l=Math.max(0,Math.round(r.amount)),c=Math.min(n,l);return n-=c,{...r,balanceShare:c,net:l-c}})}const Rn=2e4,ga=30,ti=1e3,Or="payment_req_combined_delivery",Tn="ÐÐ°Ð»Ð°Ð½Ñ ÑоваÑов",_a="Ðолг за ÑоваÑÑ",si=({orders:t,onClose:s,onSuccess:n})=>{const{t:r}=qt(),[l,c]=a.useState(new Set(t.map(T=>T.id))),[o,d]=a.useState("loading"),[p,y]=a.useState("card"),[j,b]=a.useState(null),[h,v]=a.useState([]),[i,x]=a.useState(0),[m,N]=a.useState(null),[R,S]=a.useState(null),[C,L]=a.useState(!1),[U,W]=a.useState(null),[re,Z]=a.useState(!1),O=a.useRef(null),F=a.useRef(!1),D=t.filter(T=>l.has(T.id)),$=D.reduce((T,ke)=>T+ke.amount,0),[z,me]=a.useState(0),[K,te]=a.useState(0),[I,B]=a.useState(!1);a.useEffect(()=>{const T=yt();T&&Re("users",{id:T},{select:"balance",single:!0}).then(async({data:ke})=>{const be=ke?.balance??0;if(be<0){me(Math.abs(be));return}if(be<=0)return;const{data:Ae}=await Re("orders",{user_id:T,status:"PAID"},{select:"id"}),E=(Ae||[]).map(u=>u.id);if(E.length===0){te(be);return}const{data:se}=await Re("transactions",{},{select:"order_id,type,status,amount,description",inFilters:{order_id:E}});let ee=0;for(const u of E){const _=(se||[]).filter(M=>M.order_id===u&&M.status==="COMPLETED"),P=_.filter(M=>M.type==="ORDER_PAYMENT"&&M.amount>0).reduce((M,ie)=>M+ie.amount,0),A=_.filter(M=>M.type==="BALANCE_ADJUSTMENT"&&M.amount<0&&(M.description||"").includes("заказа")).reduce((M,ie)=>M+Math.abs(ie.amount),0);ee+=Math.max(P-A,0)}te(Math.max(be-ee,0))}).catch(()=>{})},[]);const Ne=Math.min(K,$+z),[Ue,$e]=a.useState(0),[H,le]=a.useState(0),[Qe,k]=a.useState(0),xe=Qe>0?Qe:I?Ne:0,de=Math.max($+z-xe,0),[V,ye]=a.useState({}),Ie=T=>{const ke=V[T.id];return ke===void 0?T.amount:Math.max(ke,0)},Oe=de<=0&&xe>0&&D.length>0,[we,Le]=a.useState(()=>{try{return localStorage.getItem("tradehub_usdt_wallet")||""}catch{return""}}),[_t,jt]=a.useState(()=>{try{return localStorage.getItem("tradehub_usdt_qr")||""}catch{return""}}),[dt,gt]=a.useState(null),[ht,qe]=a.useState(null);a.useEffect(()=>{Re("app_settings",{},{select:"usdt_wallet,usdt_qr_image,currencies",limit:1,single:!0}).then(({data:T})=>{if(T?.usdt_wallet){Le(T.usdt_wallet);try{localStorage.setItem("tradehub_usdt_wallet",T.usdt_wallet)}catch{}}if(T?.usdt_qr_image){jt(T.usdt_qr_image);try{localStorage.setItem("tradehub_usdt_qr",T.usdt_qr_image)}catch{}}const ke=T?.currencies;if(Array.isArray(ke)){const be=ke.find(E=>E.code==="CNY"),Ae=ke.find(E=>E.code==="USDT");be?.rate&>(Number(be.rate)),Ae?.rate&&qe(Number(Ae.rate))}}).catch(()=>{})},[]);const it=dt&&ht?dt*ht:null,Ge=a.useMemo(()=>it?(de/it).toFixed(2):"...",[de,it]),St=Number(Ge)>ti;a.useEffect(()=>{let T=!1;return(async()=>{try{const ke=new Date().toISOString(),be=t.map(u=>u.id),{data:Ae}=await Re("card_reservations",{}),E=(Ae||[]).filter(u=>be.includes(u.order_id));if(T)return;const se=async(u,_,P)=>{const M=((P??(await Re("payment_cards",{})).data)||[]).find(pe=>pe.id===_);if(!M||M.is_active===!1||M.is_archived)return!1;if(T)return!0;const ie=u.filter(pe=>pe.order_display_id!==Tn&&pe.order_display_id!==_a),ge=u.find(pe=>pe.order_display_id===Tn),w=new Set(ie.map(pe=>pe.order_id));c(w),b(M),v(u.map(pe=>pe.id)),le(u.reduce((pe,je)=>pe+je.amount,0)),k(ge?Math.abs(ge.amount):0),ye(Object.fromEntries(ie.map(pe=>{const je=t.find(ze=>ze.id===pe.order_id);return[pe.order_id,je?Math.min(pe.amount,je.amount):pe.amount]})));const fe=Math.max(0,Math.floor((new Date(u[0].expires_at).getTime()-Date.now())/1e3));return x(fe),d("payment"),!0};if(E.length>0){const{data:u}=await Re("payment_cards",{}),_=new Map((u||[]).map(M=>[M.id,M])),P=M=>!!M&&M.is_active!==!1&&!M.is_archived,A=Array.from(new Set(E.map(M=>M.card_id))).find(M=>P(_.get(M)));if(A){const M=E.filter(w=>w.card_id===A),ie=M.filter(w=>w.expires_at>ke),ge=M.filter(w=>w.expires_at<=ke);if(T||ie.length>0&&await se(ie,A,u))return;if(ge.length>0){const w=new Date(Date.now()+ga*60*1e3).toISOString(),fe=[];for(const pe of ge){await ds("card_reservations",{id:pe.id});const je=crypto.randomUUID();await st("card_reservations",{id:je,card_id:pe.card_id,order_id:pe.order_id,order_display_id:pe.order_display_id,amount:pe.amount,expires_at:w,user_id:pe.user_id}),fe.push({...pe,id:je,expires_at:w})}if(T||await se(fe,A,u))return}}}const ee=localStorage.getItem(Or);if(ee){const u=parseInt(ee,10)||0,_=yt(),{data:P}=_?await Re("notifications",{user_id:_}):{data:null},A=(P||[]).some(M=>/оÑозван/i.test(M.title||"")&&new Date(M.date||M.created_at||0).getTime()>u);if(!T)if(A)localStorage.removeItem(Or);else{d("request_sent");return}}T||d("select")}catch{T||d("select")}})(),()=>{T=!0}},[]),a.useEffect(()=>
48{const T=ke=>{if(o!=="payment"&&o!=="usdt_payment")return;const be=ke.clipboardData?.items;if(be){for(const Ae of Array.from(be))if(Ae.type.startsWith("image/")){const E=Ae.getAsFile();if(!E)continue;const se=Ae.type.split("/")[1]||"png",ee=new File([E],`Ñек_${Date.now()}.${se}`,{type:Ae.type});N(ee);break}}};return document.addEventListener("paste",T),()=>document.removeEventListener("paste",T)},[o]);const Pt=T=>{c(ke=>{const be=new Set(ke);return be.has(T)?be.delete(T):be.add(T),be})};a.useEffect(()=>{if(o!=="payment"||i<=0)return;const T=setInterval(()=>{x(ke=>ke<=1?(clearInterval(T),F.current||Ut(),0):ke-1)},1e3);return()=>clearInterval(T)},[o,i>0]);const Ut=()=>{b(null),v([]),c(new Set(t.map(T=>T.id))),le(0),B(!1),localStorage.removeItem(Or),d("select"),W(r("combined_reservation_expired_retry"))},xt=async()=>{if(!(de<Rn)){if(!ao()){d("card_window_closed");return}W(null),d("loading");try{const T=new Date().toISOString(),{data:ke}=await Re("card_reservations",{}),be=D.map(je=>je.id),Ae=(ke||[]).filter(je=>je.expires_at>T&&be.includes(je.order_id));if(Ae.length>0){const{data:je}=await Re("payment_cards",{}),ze=(je||[]).find(mt=>mt.id===Ae[0].card_id);if(ze){const mt=Ae.find(G=>G.order_display_id===Tn);b(ze),v(Ae.map(G=>G.id)),le(Ae.reduce((G,q)=>G+q.amount,0)),k(mt?Math.abs(mt.amount):0),ye(Object.fromEntries(Ae.filter(G=>G.order_display_id!==Tn&&G.order_display_id!==_a).map(G=>{const q=t.find(he=>he.id===G.order_id);return[G.order_id,q?Math.min(G.amount,q.amount):G.amount]})));const Tt=Math.max(0,Math.floor((new Date(Ae[0].expires_at).getTime()-Date.now())/1e3));x(Tt),d("payment");return}}const E=yt();let se=Qe;const ee={...V};if(se===0&&xe>0){const je=ei(D,xe);try{for(const ze of je){if(ee[ze.id]=ze.net,ze.balanceShare<=0)continue;const{error:mt}=await Qt("client_use_goods_balance",{p_order_id:ze.id,p_amount:ze.balanceShare,p_is_delivery:!0});if(mt)throw new Error(mt);se+=ze.balanceShare;const{data:Tt}=await Re("orders",{id:ze.id},{select:"delivery_prepaid_amount",single:!0}),G=Number(Tt?.delivery_prepaid_amount??0),{error:q}=await Je("orders",{id:ze.id},{delivery_prepaid_amount:G+ze.balanceShare}),{error:he}=await st("transactions",{user_id:E,order_id:ze.id,amount:ze.balanceShare,currency:"RUB",type:"DELIVERY_PAYMENT",status:"COMPLETED",description:`ÐоÑÑавка заказа ${ze.displayId} оплаÑена Ñ Ð±Ð°Ð»Ð°Ð½Ñа ÑоваÑов â ${ze.balanceShare.toLocaleString("ru-RU")} â½`,created_at:new Date().toISOString()});Qt("ledger_shadow_client_goods_balance_use",{p_order_id:ze.id,p_amount:ze.balanceShare}).then(({error:_e})=>{}).catch(_e=>{})}}finally{ye(ee),k(se)}}const u=je=>{const ze=ee[je.id];return Math.max(ze===void 0?je.amount:ze,0)},_=D.map(je=>({...je,net:u(je)})).filter(je=>je.net>0),P=Math.max(_.reduce((je,ze)=>je+ze.net,0)+z,0),{data:A}=await Re("payment_cards",{is_active:!0}),M=(ke||[]).filter(je=>je.expires_at>T),ie=(A||[]).filter(je=>{if(je.order_id||je.user_id&&je.user_id!==E)return!1;const ze=M.filter(mt=>mt.card_id===je.id).reduce((mt,Tt)=>mt+Tt.amount,0);return je.limit-je.current_balance-ze>=P});if(ie.length===0){await zt(se,P,_);return}const ge=ie[0],w=new Date(Date.now()+ga*60*1e3).toISOString(),fe=E,pe=[];for(const je of _){const ze=crypto.randomUUID(),{error:mt}=await st("card_reservations",{id:ze,card_id:ge.id,order_id:je.id,amount:je.net,expires_at:w,user_id:fe,order_display_id:je.displayId});if(mt)throw new Error(mt);pe.push(ze)}if(z>0&&_[0]){const je=crypto.randomUUID(),{error:ze}=await st("card_reservations",{id:je,card_id:ge.id,order_id:_[0].id,amount:z,expires_at:w,user_id:fe,order_display_id:_a});if(ze)throw new Error(ze);pe.push(je)}b(ge),v(pe),le(P),x(ga*60),d("payment")}catch{d("select"),W(r("combined_could_not_find_card"))}}},zt=async(T,ke,be)=>{try{const Ae=be.map(P=>P.displayId).join(", "),E=`[combined:${be.map(P=>`${P.id}:${Math.round(P.net)}`).join(",")}]`,se=z>0?`[debt:${Math.round(z)}]`:"",ee=z>0?` (вклÑÑÐ°Ñ Ð¿Ð¾Ð³Ð°Ñение задолженноÑÑи за ÑоваÑ: ${z.toLocaleString("ru-RU")} â½)`:"",u=T>0?`[balance_applied:${Math.round(T)}]`:"",_=T>0?` (ÑпиÑано Ñ Ð±Ð°Ð»Ð°Ð½Ñа ÑоваÑов: ${T.toLocaleStr
48ing("ru-RU")} â½, Ñже ÑÑÑено в ÑÑммаÑ
заказов)`:"";await st("notifications",{type:"PAYMENT_REQUEST",title:`ÐапÑÐ¾Ñ ÐºÐ°ÑÑÑ (${be.length} заказа): ${ke.toLocaleString("ru-RU")} â½`,text:`ÐÐ»Ð¸ÐµÐ½Ñ Ð¿ÑоÑÐ¸Ñ ÑеквизиÑÑ Ð´Ð»Ñ ÑовмеÑÑной оплаÑÑ Ð´Ð¾ÑÑавки заказов: ${Ae}. СÑмма: ${ke.toLocaleString("ru-RU")} â½${ee}${_}.${E}${se}${u}`,date:new Date().toISOString(),is_read:!1,link:be[0]?.id||D[0]?.id}),At.channel("admin-alerts").send({type:"broadcast",event:"payment_request",payload:{amount:ke,orders:Ae}}).catch(()=>{}),localStorage.setItem(Or,Date.now().toString()),d("request_sent")}catch{}},J=async()=>{Z(!1);try{if(j){const T=!!(j.order_id||j.user_id),{error:ke}=await Je("payment_cards",{id:j.id},T?{is_active:!1,is_archived:!0,archived_at:new Date().toISOString()}:{is_active:!1})}for(const T of h){const{error:ke}=await ds("card_reservations",{id:T})}b(null),v([]),le(0),x(0),d("select")}catch{}},We=(T,ke)=>{navigator.clipboard.writeText(T),S(ke),setTimeout(()=>S(null),2e3)},oe=T=>`${Math.floor(T/60)}:${(T%60).toString().padStart(2,"0")}`,Y=async()=>{if(!(!m||!j)){L(!0),W(null);try{const T=yt();if(!T)throw new Error(r("combined_session_not_found"));const ke=m.name.split(".").pop(),be=`combined_${Date.now()}.${ke}`,{publicUrl:Ae}=await tr("receipts",be,m),E=D.map(u=>({...u,net:Ie(u)})).filter(u=>u.net>0);if(E.length===0)throw new Error(r("combined_receipt_send_failed"));const se=E.map(u=>u.displayId).join(", ");for(const u of E){const _=crypto.randomUUID(),{error:P}=await st("transactions",{id:_,user_id:T,order_id:u.id,amount:u.net,currency:"RUB",type:"DELIVERY_PAYMENT",status:"PENDING",description:`СовмеÑÑÐ½Ð°Ñ Ð¾Ð¿Ð»Ð°Ñа доÑÑавки каÑÑой â Ð·Ð°ÐºÐ°Ð·Ñ ${se}, ÑÑа ÑаÑÑÑ: ${u.net.toLocaleString("ru-RU")} â½`,proof_image:Ae,card_id:j.id,created_at:new Date().toISOString()});if(P)throw new Error(P);await st("notifications",{type:"DELIVERY_PAYMENT",title:`ÐплаÑа доÑÑавки â ${u.displayId} (ÑовмеÑÑнÑй плаÑÑж)`,text:`ÐÐ»Ð¸ÐµÐ½Ñ Ð¾ÑпÑавил Ñек за ÑовмеÑÑнÑÑ Ð¾Ð¿Ð»Ð°ÑÑ Ð´Ð¾ÑÑавки заказов: ${se}.`,date:new Date().toISOString(),is_read:!1,link:u.id})}const{data:ee}=await Re("payment_cards",{id:j.id},{select:"current_balance",single:!0});if(ee){const{error:u}=await Je("payment_cards",{id:j.id},{current_balance:ee.current_balance+H})}if(z>0){const u=E[0].id,{error:_}=await Qt("client_clear_goods_debt",{p_order_id:u,p_card_id:j.id});Qt("ledger_shadow_client_goods_debt_clear",{p_order_id:u}).then(({error:P})=>{}).catch(P=>{})}for(const u of h){const{error:_}=await ds("card_reservations",{id:u})}At.channel("admin-alerts").send({type:"broadcast",event:"payment",payload:{amount:H,orderId:se}}).catch(()=>{}),localStorage.removeItem(Or),F.current=!0,d("processing"),setTimeout(()=>n(),1200)}catch(T){W(T.message||r("combined_receipt_send_failed"))}finally{L(!1)}}},Se=async()=>{if(C||!Oe)return;const T=yt();if(!T){W(r("combined_session_not_found"));return}L(!0),W(null);const ke=[];try{for(const be of D){const{error:Ae}=await Qt("client_use_goods_balance",{p_order_id:be.id,p_amount:be.amount,p_is_delivery:!0});if(Ae)throw new Error(Ae);Qt("ledger_shadow_client_goods_balance_use",{p_order_id:be.id,p_amount:be.amount}).then(({error:_})=>{}).catch(_=>{});const{data:E}=await Re("orders",{id:be.id},{select:"delivery_prepaid_amount",single:!0}),se=Number(E?.delivery_prepaid_amount??0),{error:ee}=await Je("orders",{id:be.id},{delivery_paid:!0,delivery_prepaid_amount:se+be.amount});if(ee)throw new Error(ee);const{error:u}=await st("transactions",{user_id:T,order_id:be.id,amount:be.amount,type:"DELIVERY_PAYMENT",status:"COMPLETED",description:`ÐоÑÑавка заказа ${be.displayId} оплаÑена Ñ Ð±Ð°Ð»Ð°Ð½Ñа ÑоваÑов â ${be.amount.toLocaleString("ru-RU")} â½`,created_at:new Date().toISOString()});if(u)throw new Error(u);await st("notifications",{type:"DELIVERY_PAYMENT",title:`ÐплаÑа доÑÑавки â ${be.displayId}`,text:`ÐÐ»Ð¸ÐµÐ½Ñ Ð¾Ð¿Ð»Ð°Ñил доÑÑÐ°Ð²ÐºÑ Ð·Ð°ÐºÐ°Ð·Ð° ${be.displayId}
48 из баланÑа ÑоваÑов (${be.amount.toLocaleString("ru-RU")} â½).`,date:new Date().toISOString(),is_read:!1,link:be.id}),await st("notifications",{user_id:T,type:"DELIVERY_PAYMENT",title:`ÐплаÑа доÑÑавки подÑвеÑждена â ${be.displayId}`,text:`ÐоÑÑавка заказа ${be.displayId} оплаÑена из баланÑа ÑоваÑов (${be.amount.toLocaleString("ru-RU")} â½).`,date:new Date().toISOString(),is_read:!1,link:be.id}),ke.push(be.displayId)}$e($),F.current=!0,d("balance_paid"),setTimeout(()=>n(),1800)}catch(be){W(ke.length>0?`${r("combined_balance_pay_partial",{orders:ke.join(", ")})} ${be.message}`:`${r("combined_balance_pay_failed")}: ${be.message}`),L(!1)}},ve=async()=>{if(m){if(!it){W("ÐÑÑÑ USDT еÑÑ Ð·Ð°Ð³ÑÑжаеÑÑÑ, подождиÑе ÑекÑÐ½Ð´Ñ Ð¸ попÑобÑйÑе Ñнова.");return}L(!0),W(null);try{const T=yt();if(!T)throw new Error(r("combined_session_not_found"));const ke=m.name.split(".").pop(),be=`combined_usdt_${Date.now()}.${ke}`,{publicUrl:Ae}=await tr("receipts",be,m),E=ei(D,xe);let se=0;for(const _ of E){if(_.balanceShare<=0)continue;const{error:P}=await Qt("client_use_goods_balance",{p_order_id:_.id,p_amount:_.balanceShare,p_is_delivery:!0});if(P)continue;se+=_.balanceShare;const{data:A}=await Re("orders",{id:_.id},{select:"delivery_prepaid_amount",single:!0}),M=Number(A?.delivery_prepaid_amount??0),{error:ie}=await Je("orders",{id:_.id},{delivery_prepaid_amount:M+_.balanceShare}),{error:ge}=await st("transactions",{user_id:T,order_id:_.id,amount:_.balanceShare,currency:"RUB",type:"DELIVERY_PAYMENT",status:"COMPLETED",description:`ÐоÑÑавка заказа ${_.displayId} оплаÑена Ñ Ð±Ð°Ð»Ð°Ð½Ñа ÑоваÑов â ${_.balanceShare.toLocaleString("ru-RU")} â½`,created_at:new Date().toISOString()});Qt("ledger_shadow_client_goods_balance_use",{p_order_id:_.id,p_amount:_.balanceShare}).then(({error:w})=>{}).catch(w=>{})}se>0&&k(se);const ee=E.filter(_=>_.net>0);if(ee.length===0)throw new Error(r("combined_receipt_send_failed"));const u=ee.map(_=>_.displayId).join(", ");for(const _ of ee){const P=crypto.randomUUID(),A=Number((_.net/it).toFixed(2)),{error:M}=await st("transactions",{id:P,user_id:T,order_id:_.id,amount:_.net,currency:"USDT",amount_usdt:A,type:"DELIVERY_PAYMENT",status:"PENDING",description:`СовмеÑÑÐ½Ð°Ñ Ð¾Ð¿Ð»Ð°Ñа доÑÑавки USDT â Ð·Ð°ÐºÐ°Ð·Ñ ${u}, ÑÑа ÑаÑÑÑ: ${_.net.toLocaleString("ru-RU")} â½ (${A} USDT)`,proof_image:Ae,created_at:new Date().toISOString()});if(M)throw new Error(M);await st("notifications",{type:"DELIVERY_PAYMENT",title:`ÐплаÑа доÑÑавки â ${_.displayId} (ÑовмеÑÑнÑй плаÑÑж, USDT)`,text:`ÐÐ»Ð¸ÐµÐ½Ñ Ð¾ÑпÑавил Ñек за ÑовмеÑÑнÑÑ Ð¾Ð¿Ð»Ð°ÑÑ Ð´Ð¾ÑÑавки (USDT) заказов: ${u}.`,date:new Date().toISOString(),is_read:!1,link:_.id})}if(z>0){const _=ee[0].id,{error:P}=await Qt("client_clear_goods_debt",{p_order_id:_});Qt("ledger_shadow_client_goods_debt_clear",{p_order_id:_}).then(({error:A})=>{}).catch(A=>{})}At.channel("admin-alerts").send({type:"broadcast",event:"payment",payload:{amount:de,orderId:u}}).catch(()=>{}),localStorage.removeItem(Or),F.current=!0,d("processing"),setTimeout(()=>n(),1200)}catch(T){W(T.message||r("combined_receipt_send_failed"))}finally{L(!1)}}};return e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:e.jsxs("div",{className:"bg-white rounded-2xl shadow-xl max-w-md w-full max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"flex items-center justify-between p-5 border-b border-slate-100",children:[e.jsx("h2",{className:"text-lg font-bold text-slate-900",children:r("combined_title")}),e.jsx("button",{onClick:s,className:"text-slate-400 hover:text-slate-600",children:e.jsx(bt,{size:22})})]}),e.jsxs("div",{className:"p-5 space-y-4",children:[U&&e.jsx("div",{className:"p-3 bg-red-50 border border-red-100 rounded-lg text-sm text-red-600",children:U}),o==="select"&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm text-slate-500",children:r("combined_select_orders")}),e.jsx("div",{className:"space-y-2",children:t.map(T=>e.jsxs("label",{className:"flex items-center justify-between p-3 border border-slate-200 rounded-xl cursor-pointer hover:bg-slate-50",children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"checkbox",checked:l.has(T.id),onChange:()=>Pt(T.id),className:"w-4 h-4 accent-blue-600"}),e.jsx("span",{className:"text-sm font-bold text-slate-700",children:T.displayId})]}),e.jsxs("span",{className:"text-sm font-bold text-slate-900",children:[T.amount.toLocaleStr
48ing("ru-RU")," â½"]})]},T.id))}),e.jsxs("div",{className:"p-4 bg-slate-50 rounded-xl space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm font-bold text-slate-500",children:[r("combined_selected"),":"]}),e.jsxs("span",{className:"text-xl font-black text-slate-900",children:[de.toLocaleString("ru-RU")," â½"]})]}),z>0&&e.jsxs("div",{className:"flex items-center justify-between text-xs text-amber-600",children:[e.jsxs("span",{children:[r("combined_incl_goods_debt"),":"]}),e.jsxs("span",{className:"font-bold",children:[z.toLocaleString("ru-RU")," â½"]})]}),xe>0&&e.jsxs("div",{className:"flex items-center justify-between text-xs text-blue-600",children:[e.jsxs("span",{children:[r("combined_goods_balance_applied"),":"]}),e.jsxs("span",{className:"font-bold",children:["-",xe.toLocaleString("ru-RU")," â½"]})]})]}),de>0&&de<Rn&&e.jsx("div",{className:"text-xs text-orange-600 font-medium",children:r("combined_min_amount_note")}),Qe>0?e.jsx("div",{className:"border-2 border-blue-200 bg-blue-50 rounded-2xl p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-5 h-5 rounded-full border-2 border-blue-500 bg-blue-500 flex items-center justify-center shrink-0",children:e.jsx(Kt,{size:12,className:"text-white"})}),e.jsx(Ds,{size:16,className:"text-blue-600"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-sm font-bold text-slate-800",children:r("combined_use_goods_balance")}),e.jsxs("div",{className:"text-xs text-blue-600 font-bold",children:["-",Qe.toLocaleString("ru-RU")," â½ ",r("combined_goods_balance_applied")]})]})]})}):K>0&&e.jsx("div",{onClick:()=>B(T=>!T),className:`border-2 rounded-2xl p-4 cursor-pointer transition-all ${I?"border-blue-400 bg-blue-50":"border-slate-200 bg-white"}`,children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-5 h-5 rounded-full border-2 flex items-center justify-center shrink-0 ${I?"border-blue-500 bg-blue-500":"border-slate-300"}`,children:I&&e.jsx(Kt,{size:12,className:"text-white"})}),e.jsx(Ds,{size:16,className:I?"text-blue-600":"text-slate-400"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-sm font-bold text-slate-800",children:r("combined_use_goods_balance")}),e.jsx("div",{className:"text-xs text-slate-500",children:r("combined_goods_balance_available",{amount:K.toLocaleString("ru-RU")})})]})]})}),Oe?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-xs text-emerald-700 bg-emerald-50 border border-emerald-100 rounded-lg p-3",children:r("combined_fully_covered_ready")}),e.jsx("button",{onClick:Se,disabled:C,className:"w-full py-3.5 bg-emerald-600 hover:bg-emerald-700 disabled:bg-slate-300 disabled:cursor-not-allowed text-white rounded-xl font-bold transition-all flex items-center justify-center gap-2",children:C?e.jsxs(e.Fragment,{children:[e.jsx(rt,{size:16,className:"animate-spin"})," ",r("combined_paying_from_balance")]}):r("combined_pay_from_balance")})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"p-1 bg-slate-100 rounded-xl grid grid-cols-2 gap-1",children:[e.jsxs("button",{onClick:()=>y("card"),className:`flex items-center justify-center gap-2 py-2.5 rounded-lg text-sm font-bold transition-all ${p==="card"?"bg-white text-blue-600 shadow-sm":"text-slate-500"}`,children:[e.jsx(Xs,{size:16})," ",r("topup_card_rf")]}),e.jsxs("button",{onClick:()=>y("usdt"),className:`flex items-center justify-center gap-2 py-2.5 rounded-lg text-sm font-bold transition-all ${p==="usdt"?"bg-white text-green-600 shadow-sm":"text-slate-500"}`,children:[e.jsx(Ds,{size:16})," USDT TRC20"]})]}),p==="usdt"&&St&&$>=Rn&&e.jsx("div",{className:"text-xs text-amber-700 bg-amber-50 border border-amber-100 rounded-lg p-3",children:r("combined_usdt_over_threshold",{threshold:ti})}),p==="card"&&e.jsxs("div",{className:"flex gap-2 items-start bg-red-50 border border-red-100 rounded-xl p-3",children:[e.jsx(hs,{className:"shrink-0 mt-0.5 text-red-500",size:16}),e.jsx("p",{className:"text-xs text-red-600 leading-snug font-medium",children:r("card_request_pay_ready_warning")})]}),e.jsx("button",{onClick:()=>{p==="card"?xt():St||d("usdt_payment")},disabled:de<Rn||p==="usdt"&&St,className:"w-full py-3.5 bg-blue-600 hover:bg-blue-700 disabled:bg-slate-300 disabled:cursor-not-allowed text-white rounded-xl font-bold transition-all",children:r(p==="card"?"topup_request_requisites":"combined_pay_via_usdt")}
48)]})]}),o==="loading"&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-10 gap-3",children:[e.jsx(rt,{className:"animate-spin text-blue-500",size:32}),e.jsx("p",{className:"text-sm text-slate-500",children:r("combined_searching_card")})]}),o==="card_window_closed"&&e.jsxs("div",{className:"text-center space-y-3 py-6",children:[e.jsx("div",{className:"w-14 h-14 bg-amber-100 text-amber-600 rounded-full flex items-center justify-center mx-auto",children:e.jsx(rs,{size:24})}),e.jsx("h3",{className:"text-sm font-bold text-slate-900",children:r("card_issue_window_closed_title")}),e.jsx("p",{className:"text-xs text-slate-500 max-w-xs mx-auto",children:r("card_issue_window_closed_text")}),e.jsx("button",{onClick:()=>d("select"),className:"px-6 py-2.5 bg-slate-900 text-white rounded-xl font-bold text-sm hover:bg-slate-800 transition-all",children:r("topup_understood")})]}),o==="request_sent"&&e.jsxs("div",{className:"text-center space-y-3 py-6",children:[e.jsx("div",{className:"w-14 h-14 bg-blue-50 text-blue-600 rounded-full flex items-center justify-center mx-auto animate-pulse",children:e.jsx(_s,{size:24})}),e.jsx("h3",{className:"text-sm font-bold text-slate-900",children:r("topup_requisites_requested")}),e.jsxs("p",{className:"text-xs text-slate-500",children:[r("combined_admin_will_prepare",{amount:de.toLocaleString("ru-RU"),orders:D.map(T=>T.displayId).join(", ")}),z>0?` ${r("combined_incl_debt_paren",{amount:z.toLocaleString("ru-RU")})}`:"","."]})]}),o==="payment"&&j&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"text-center py-4 bg-slate-50 rounded-2xl border border-slate-100",children:[e.jsx("p",{className:"text-[10px] font-black text-slate-400 uppercase tracking-widest mb-1",children:r("combined_to_pay_for_n",{count:D.filter(T=>Ie(T)>0).length})}),e.jsxs("div",{className:"text-3xl font-bold text-slate-900 mb-2",children:[H.toLocaleString("ru-RU")," â½"]}),e.jsxs("div",{className:`inline-flex items-center gap-1.5 px-3 py-1 rounded-full text-xs font-bold border ${i<60?"bg-red-50 text-red-600 border-red-100":"bg-amber-50 text-amber-700 border-amber-100"}`,children:[e.jsx(rs,{size:11,className:"animate-pulse"})," ",r("topup_reservation_label"),": ",oe(i)]})]}),e.jsxs("div",{className:"text-xs text-slate-500 space-y-1",children:[D.filter(T=>Ie(T)>0).map(T=>e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:T.displayId}),e.jsxs("span",{className:"font-bold",children:[Ie(T).toLocaleString("ru-RU")," â½"]})]},T.id)),z>0&&e.jsxs("div",{className:"flex justify-between text-amber-600",children:[e.jsx("span",{children:r("topup_debt_short")}),e.jsxs("span",{className:"font-bold",children:[z.toLocaleString("ru-RU")," â½"]})]}),Qe>0&&e.jsxs("div",{className:"flex justify-between text-blue-600",children:[e.jsx("span",{children:r("combined_goods_balance_applied")}),e.jsxs("span",{className:"font-bold",children:["-",Qe.toLocaleString("ru-RU")," â½"]})]})]}),e.jsxs("div",{className:"ym-hide-content p-5 border border-slate-200 rounded-2xl bg-white shadow-sm",children:[e.jsxs("div",{className:"text-xs font-bold text-slate-400 uppercase mb-2",children:[r("topup_card_number")," (",j.bank==="OTHER"&&j.custom_bank_name?j.custom_bank_name:j.bank,")"]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("div",{className:"font-mono text-xl font-bold text-slate-900 tracking-wider",children:j.number.replace(/\D/g,"").match(/.{1,4}/g)?.join(" ")||j.number}),e.jsx("button",{onClick:()=>We(j.number,"card"),className:"p-2 text-slate-400 hover:text-blue-600",children:R==="card"?e.jsx(Kt,{size:20,className:"text-green-500"}):e.jsx(Us,{size:20})})]})]}),e.jsxs("div",{className:"ym-hide-content flex gap-3",children:[e.jsxs("div",{className:"flex-1 p-3 border border-slate-200 rounded-xl bg-white",children:[e.jsx("div",{className:"text-[10px] font-bold text-slate-400 uppercase mb-1",children:r("order_details_recipient")}),e.jsx("div",{className:"text-sm font-bold text-slate-900 truncate",children:j.holder})]}),j.phone&&e.jsxs("div",{className:"flex-1 p-3 border border-slate-200 rounded-xl bg-white",children:[e.jsx("div",{className:"text-[10px] font-bold text-slate-400 uppercase mb-1",children:r("topup_phone_sbp")}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("div",{className:"text-sm font-bold text-slate-900",children:j.phone}),e.jsx("button",{onClick:()=>We(j.phone,"sbp"),className:"text-slate-400 hover:text-blue-600",children:R==="sbp"?e.jsx(Kt,{size:14,className:"text-green-500"}):e.jsx(Us,{size:14})})]})]})]}),e.jsxs("div",{className:"border-t border-slate-100 pt-4",children:[e.jsx("input",{type:"file",ref:O,onChange:T=>
48N(T.target.files?.[0]||null),className:"hidden",accept:".jpg,.jpeg,.png,.pdf"}),m?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between p-3 bg-slate-50 rounded-xl",children:[e.jsx("span",{className:"text-sm font-bold text-slate-700 truncate",children:m.name}),e.jsx("button",{onClick:()=>N(null),className:"text-slate-400 hover:text-red-500",children:e.jsx(bt,{size:16})})]}),e.jsxs("button",{onClick:Y,disabled:C,className:"w-full py-3.5 bg-blue-600 hover:bg-blue-700 disabled:opacity-60 text-white rounded-xl font-bold flex items-center justify-center gap-2",children:[C?e.jsx(rt,{className:"animate-spin",size:18}):e.jsx(Ss,{size:18}),r("combined_send_receipt")]})]}):e.jsxs("button",{onClick:()=>O.current?.click(),className:"w-full py-5 border-2 border-dashed border-slate-200 rounded-2xl flex flex-col items-center gap-2 text-slate-400 hover:border-blue-400 hover:text-blue-600 hover:bg-blue-50/50 transition-all",children:[e.jsx(mn,{size:22}),e.jsx("span",{className:"text-sm font-bold",children:r("topup_attach_payment_receipt")})]})]}),e.jsxs("button",{disabled:C,onClick:()=>Z(!0),className:"w-full py-2.5 border border-rose-200 text-rose-500 bg-rose-50 hover:bg-rose-100 rounded-xl text-sm font-bold flex items-center justify-center gap-1.5 transition-all disabled:opacity-40",children:[e.jsx(Gr,{size:15})," ",r("topup_card_blocked_unavailable")]})]}),re&&e.jsx("div",{className:"fixed inset-0 z-[200] flex items-center justify-center bg-slate-900/70 p-4",children:e.jsxs("div",{className:"bg-white rounded-2xl p-6 max-w-sm w-full shadow-2xl",children:[e.jsx("h3",{className:"text-lg font-bold text-slate-900 mb-2",children:r("topup_card_unavailable_question")}),e.jsxs("p",{className:"text-sm text-slate-500 leading-relaxed mb-6",children:[r("topup_sure_cannot_pay"),e.jsx("br",{}),r("topup_manager_will_send_new_requisites")]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{onClick:()=>Z(!1),className:"flex-1 py-2.5 border border-slate-200 rounded-xl text-sm font-bold text-slate-600 hover:bg-slate-50 transition-colors",children:r("orders_cancel_button")}),e.jsx("button",{onClick:J,className:"flex-1 py-2.5 bg-rose-500 text-white rounded-xl text-sm font-bold hover:bg-rose-600 transition-colors",children:r("topup_yes_blocked")})]})]})}),o==="usdt_payment"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"text-center py-4 bg-slate-50 rounded-2xl border border-slate-100",children:[e.jsx("p",{className:"text-[10px] font-black text-slate-400 uppercase tracking-widest mb-1",children:r("combined_to_pay_for_n",{count:D.length})}),e.jsxs("div",{className:"text-3xl font-bold text-slate-900 mb-1",children:[Ge," USDT"]}),e.jsxs("div",{className:"text-xs text-slate-400",children:[de.toLocaleString("ru-RU")," â½"]})]}),e.jsxs("div",{className:"text-xs text-slate-500 space-y-1",children:[D.map(T=>e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:T.displayId}),e.jsxs("span",{className:"font-bold",children:[T.amount.toLocaleString("ru-RU")," â½"]})]},T.id)),z>0&&e.jsxs("div",{className:"flex justify-between text-amber-600",children:[e.jsx("span",{children:r("topup_debt_short")}),e.jsxs("span",{className:"font-bold",children:[z.toLocaleString("ru-RU")," â½"]})]}),xe>0&&e.jsxs("div",{className:"flex justify-between text-blue-600",children:[e.jsx("span",{children:r("combined_goods_balance_applied")}),e.jsxs("span",{className:"font-bold",children:["-",xe.toLocaleString("ru-RU")," â½"]})]})]}),e.jsxs("div",{className:"ym-hide-content p-4 border border-slate-200 rounded-2xl bg-white space-y-3",children:[_t&&e.jsxs("div",{className:"flex flex-col items-center gap-2 pb-3 border-b border-slate-100",children:[e.jsx("p",{className:"text-xs font-bold text-slate-400 uppercase",children:r("topup_scan_to_pay")}),e.jsx("img",{src:_t,alt:"USDT QR",className:"w-44 h-44 object-contain rounded-xl border border-slate-200 bg-white p-1"})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("div",{className:"text-xs font-bold text-slate-400 uppercase",children:r("topup_wallet_trc20")}),e.jsxs("button",{onClick:()=>We(we,"usdt"),className:"text-blue-600 text-xs font-bold flex items-center gap-1",children:[R==="usdt"?e.jsx(Kt,{size:13}):e.jsx(Us,{size:13})," ",r("topup_copy")]})]}),e.jsx("div",{className:"font-mono text-xs break-all bg-slate-50 p-3 rounded-xl border border-slate-100 text-slate-700",children:we})]}),e.jsxs("div",{className:"border-t border-slate-100 pt-4",children:[e.jsx("input",{type:"file",ref:O,onChange:T=>
48N(T.target.files?.[0]||null),className:"hidden",accept:".jpg,.jpeg,.png,.pdf"}),m?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between p-3 bg-slate-50 rounded-xl",children:[e.jsx("span",{className:"text-sm font-bold text-slate-700 truncate",children:m.name}),e.jsx("button",{onClick:()=>N(null),className:"text-slate-400 hover:text-red-500",children:e.jsx(bt,{size:16})})]}),e.jsxs("button",{onClick:ve,disabled:C,className:"w-full py-3.5 bg-blue-600 hover:bg-blue-700 disabled:opacity-60 text-white rounded-xl font-bold flex items-center justify-center gap-2",children:[C?e.jsx(rt,{className:"animate-spin",size:18}):e.jsx(Ss,{size:18}),r("combined_send_receipt")]})]}):e.jsxs("button",{onClick:()=>O.current?.click(),className:"w-full py-5 border-2 border-dashed border-slate-200 rounded-2xl flex flex-col items-center gap-2 text-slate-400 hover:border-blue-400 hover:text-blue-600 hover:bg-blue-50/50 transition-all",children:[e.jsx(mn,{size:22}),e.jsx("span",{className:"text-sm font-bold",children:r("topup_attach_payment_receipt")})]})]})]}),o==="processing"&&e.jsxs("div",{className:"text-center space-y-3 py-8",children:[e.jsx("div",{className:"w-16 h-16 bg-green-100 rounded-full flex items-center justify-center mx-auto",children:e.jsx(ss,{className:"text-green-600",size:32})}),e.jsx("h3",{className:"text-lg font-bold text-slate-900",children:r("topup_receipt_sent")}),e.jsx("p",{className:"text-sm text-slate-500",children:r("combined_admin_will_check")})]}),o==="balance_paid"&&e.jsxs("div",{className:"text-center space-y-3 py-8",children:[e.jsx("div",{className:"w-16 h-16 bg-emerald-100 rounded-full flex items-center justify-center mx-auto",children:e.jsx(ss,{className:"text-emerald-600",size:32})}),e.jsx("h3",{className:"text-lg font-bold text-slate-900",children:r("combined_balance_paid_title")}),e.jsx("p",{className:"text-sm text-slate-500",children:r("combined_balance_paid_text",{amount:Ue.toLocaleString("ru-RU"),orders:D.map(T=>T.displayId).join(", ")})})]})]})]})})},Gx={IN_TRANSIT:{labelKey:"tracking_status_in_transit",icon:e.jsx(Lt,{size:15}),color:"text-blue-600 bg-blue-50"},DELIVERED:{labelKey:"tracking_status_delivered",icon:e.jsx(as,{size:15}),color:"text-green-600 bg-green-50"},PICKUP:{labelKey:"tracking_status_pickup",icon:e.jsx(js,{size:15}),color:"text-amber-600 bg-amber-50"},UNDELIVERED:{labelKey:"tracking_status_undelivered",icon:e.jsx(rs,{size:15}),color:"text-red-600 bg-red-50"},EXPIRED:{labelKey:"tracking_status_expired",icon:e.jsx(rs,{size:15}),color:"text-slate-500 bg-slate-100"}};function qx(t){return Gx[t]??{labelKey:"tracking_status_default",icon:e.jsx(Lt,{size:15}),color:"text-blue-600 bg-blue-50"}}function Wx({entry:t}){const{t:s}=qt(),[n,r]=a.useState(!1),l=qx(t.status);return e.jsxs("div",{className:"border border-slate-200 rounded-xl overflow-hidden",children:[e.jsxs("div",{className:"px-4 py-3 flex items-center gap-3",children:[e.jsxs("div",{className:`flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-bold ${l.color}`,children:[l.icon,s(l.labelKey)]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-mono font-bold text-slate-800 text-sm",children:t.number}),t.carrier&&e.jsx("div",{className:"text-xs text-slate-400 mt-0.5",children:t.carrier})]}),e.jsx("a",{href:`https://t.17track.net/en#nums=${t.number}`,target:"_blank",rel:"noopener noreferrer",className:"p-1.5 text-slate-400 hover:text-blue-600 transition-colors",title:s("tracking_open_on_17track"),children:e.jsx(Zn,{size:14})}),t.events.length>0&&e.jsx("button",{onClick:()=>r(c=>!c),className:"p-1.5 text-slate-400 hover:text-slate-600 transition-colors",children:n?e.jsx(qr,{size:14}):e.jsx(er,{size:14})})]}),n&&t.events.length>0&&e.jsx("div",{className:"border-t border-slate-100 px-4 py-3 space-y-2 bg-slate-50",children:t.events.slice(0,8).map((c,o)=>e.jsxs("div",{className:"flex gap-3 text-xs",children:[e.jsx("div",{className:"text-slate-400 whitespace-nowrap w-32 flex-shrink-0",children:c.time}),e.jsxs("div",{className:"text-slate-600",children:[c.location&&e.jsxs("span",{className:"font-medium text-slate-700",children:["[",c.location,"] "]}),c.desc]})]},o))})]})}const Hx=({tracking:t})=>{const{t:s}=qt();return!t||t.length===0?null:e.jsxs("div",{className:"mt-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(Lt,{size:16,className:"text-blue-600"}),e.jsx("span",{className:"font-bold text-slate-700 text-sm",children:s("tracking_section_title")})]}),e.jsx("div",{className:"space-y-2",children:t.map((n,r)=>e.jsx(Wx,{entry:n},n.number||r))})]})},Vx=["image/jpeg","image/jpg","image/png","application/pdf","application/zip","application/x-zip-compressed","application/x-rar-compressed","application/vnd.rar","application/octet-stream","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.ms-excel"],Kx=".jpg,.jpeg,.png,.pdf,.zip,.rar,.xlsx,.xls",Jx=({item:t,shopItems:s,index:n,cnyRate:r,onViewImage:l,onClientDecision:c,isRefunded:o=!1,effectiveCommissionRate:d=.05,canEditOrder:p=!1,orderStatus:y,orderId:j,paymentLocked:b=!1,onItemUpdated:h,onItemRemoved:v})=>{const{t:i}
48=qt(),[x,m]=a.useState(!1),[N,R]=a.useState(!1),[S,C]=a.useState(null),[L,U]=a.useState(!1),[W,re]=a.useState(""),[Z,O]=a.useState(!1),[F,D]=a.useState(!1),[$,z]=a.useState(t.clientAttachments??[]),[me,K]=a.useState(!1),[te,I]=a.useState(!1),B=p&&(y==="NEW"||!y)&&!b,Ne=y==="NEW"&&!b,Ue=y==="NEW"||!y,[$e,H]=a.useState(!1),[le,Qe]=a.useState(""),[k,xe]=a.useState(!1),de=()=>{Qe(t.itemComment||""),H(!0)},V=async()=>{if(j){xe(!0);try{const{data:A,error:M}=await Re("orders",{id:j},{select:"items",single:!0});if(M)throw new Error(M);const ie=A.items.map(w=>w.id===t.id?{...w,itemComment:le.trim()}:w),{error:ge}=await Je("orders",{id:j},{items:ie});if(ge)throw new Error(ge);h?.(t.id,{itemComment:le.trim()}),H(!1)}catch(A){alert(i("delivery_save_error_prefix")+A.message)}finally{xe(!1)}}},ye=()=>{re(String(t.priceCNY??"")),z(t.clientAttachments??[]),U(!0)},Ie=async A=>{const M=A.target.files?.[0];if(!M)return;const ie=(M.name.split(".").pop()||"").toLowerCase(),ge=["jpg","jpeg","png","pdf","zip","rar","xlsx","xls"];if(!Vx.includes(M.type)&&!ge.includes(ie)){alert(i("item_allowed_files"));return}D(!0);try{const w=(M.name.split(".").pop()||ie).toLowerCase(),fe=`${t.id}/${Date.now()}_${Math.random().toString(36).slice(2)}.${w}`;try{const{publicUrl:pe}=await tr("client-attachments",fe,M);z(je=>[...je,pe])}catch(pe){pe.message?.includes("Bucket not found")?alert(i("item_bucket_not_found_error")):alert(i("item_upload_error_prefix")+pe.message);return}}catch(w){alert(i("item_upload_error_prefix")+w.message)}finally{D(!1),A.target.value=""}},Oe=async A=>{try{const M="/object/public/client-attachments/",ie=A.indexOf(M);if(ie!==-1){const ge=decodeURIComponent(A.slice(ie+M.length).split("?")[0]);await At.storage.from("client-attachments").remove([ge])}}catch{}z(M=>M.filter(ie=>ie!==A))},we=async()=>{if(j){O(!0);try{if(await Fr(j)){alert(i("order_details_cannot_edit_reserved"));return}const A=parseFloat(W);if(isNaN(A)||A<=0){alert(i("item_invalid_price"));return}const{data:M,error:ie}=await Re("orders",{id:j},{select:"items,commission_cny",single:!0});if(ie)throw new Error(ie);const ge={priceCNY:A,clientAttachments:$};t.clientOriginalPriceCNY?A!==t.priceCNY&&(ge.clientPriceEditedAt=new Date().toISOString()):(ge.clientOriginalPriceCNY=t.priceCNY,ge.clientPriceEditedAt=new Date().toISOString());const w=M.items.map(q=>q.id===t.id?{...q,...ge}:q),fe=M.items.reduce((q,he)=>q+(Number(he.priceCNY)||0)*(Number(he.quantity)||0),0),pe=w.reduce((q,he)=>q+(Number(he.priceCNY)||0)*(Number(he.quantity)||0),0),je=w.reduce((q,he)=>q+(Number(he.chinaDelivery)||0),0),ze=pe+je,mt=Number(M.commission_cny)||0,Tt=fe>0&&mt>0?parseFloat((mt/fe*pe).toFixed(4)):mt,{error:G}=await Je("orders",{id:j},{items:w,total_cny:ze,commission_cny:Tt});if(G)throw new Error(G);h?.(t.id,{...ge,_newTotalCNY:ze}),U(!1)}catch(A){alert(i("delivery_save_error_prefix")+A.message)}finally{O(!1)}}},Le=async A=>{if(!(!j||te)&&!(!Number.isFinite(A)||A<1||Math.round(A)!==A)&&A!==t.quantity){I(!0);try{if(await Fr(j)){alert(i("order_details_cannot_edit_reserved"));return}const{data:M,error:ie}=await Re("orders",{id:j},{select:"items,commission_cny",single:!0});if(ie)throw new Error(ie);const ge=M.items,w=ge.map(q=>q.id===t.id?{...q,quantity:A}:q),fe=ge.reduce((q,he)=>q+(Number(he.priceCNY)||0)*(Number(he.quantity)||0),0),pe=w.reduce((q,he)=>q+(Number(he.priceCNY)||0)*(Number(he.quantity)||0),0),je=w.reduce((q,he)=>q+(Number(he.chinaDelivery)||0),0),ze=pe+je,mt=Number(M.commission_cny)||0,Tt=fe>0&&mt>0?parseFloat((mt/fe*pe).toFixed(4)):mt,{error:G}=await Je("orders",{id:j},{items:w,total_cny:ze,commission_cny:Tt});if(G)throw new Error(G);h?.(t.id,{quantity:A,_newTotalCNY:ze})}catch(M){alert(i("delivery_save_error_prefix")+M.message)}finally{I(!1)}}},_t=A=>Le(t.quantity+A),[jt,dt]=a.useState(null),gt=()=>{if(jt===null)return;const A=parseInt(jt,10);dt(null),Number.isFinite(A)&&A>=1&&Le(A)},ht=async()=>{if(j&&window.confirm(i("item_delete_confirm",{name:t.name}))){K(!0);try{if(await Fr(j)){alert(i("order_details_cannot_edit_reserved"));return}const{data:A,error:M}=await Re("orders",{id:j},{select:"items,commission_cny",single:!0});if(M)throw new Error(M);const ie=A.items,ge=ie.filter(G=>G.id!==t.id);if(ge.length===0){alert(i("item_last_item_delete"));return}const w=ie.reduce((G,q)=>G+(Number(q.priceCNY)||0)*(Number(q.quantity)||0),0),fe=ge.reduce((G,q)=>G+(Number(q.priceCNY)||0)*(Number(q.quantity)||0),0),pe=ge.reduce((G,q)=>G+(Number(q.chinaDelivery)||0),0),je=fe+pe,ze=Number(A.commission_cny)||0,mt=w>0&&ze>0?parseFloat((ze/w*fe).toFixed(4)):ze,{error:Tt}=await Je("orders",{id:j},{items:ge,total_cny:je,commission_cny:mt,items_count:ge.length});if(Tt)throw new Error(Tt);v?.(t.id,je)}catch(A){alert(i("common_delete_error_prefix")+A.message)}finally{K(!1)}}};a.useEffect(()=>{t.clientDecision&&C(null)},[t.clientDecision]);const qe=A=>A==="PROCESSING"?i("item_status_processing"):A==="ON_WAY"?i("item_status_on_way"):A==="ARRIVED"?i("item_status_arr
48ived"):A==="RECEIVED"?i("item_status_received"):A==="PARTIALLY_RECEIVED"?i("item_status_partially_received"):A==="OUT_OF_STOCK"?i("item_status_out_of_stock"):A==="CANCELED"?i("item_status_canceled"):A==="PROBLEM"?i("item_status_problem"):A==="ASSEMBLED"?i("item_status_assembled"):Zo[A]||A,it=A=>A==="ON_WAY"||A==="ARRIVED"?"bg-indigo-100 text-indigo-700 border-indigo-200":A==="RECEIVED"?"bg-green-100 text-green-700 border-green-200":A==="OUT_OF_STOCK"?"bg-red-100 text-red-700 border-red-200":A==="CANCELED"?"bg-rose-100 text-rose-700 border-rose-200":A==="PROBLEM"?"bg-amber-100 text-amber-700 border-amber-200":"bg-slate-100 text-slate-600 border-slate-200",Ge=async(A,M)=>{R(!0),C(M);try{if(!j)throw new Error("orderId не пеÑедан в компоненÑ");const{data:ie,error:ge}=await Re("orders",{id:j},{single:!0});if(ge)throw new Error(ge);if(!ie)throw new Error("Ðаказ не найден");const w=ec(ie),fe=ie.items.map(je=>{if(je.id!==A)return je;const ze={...je,clientDecision:M};return M==="KEEP"&&(ze.status="RECEIVED"),ze}),{error:pe}=await Je("orders",{id:ie.id},{items:fe});if(pe)throw new Error(pe);M==="RETURN"&&await st("notifications",{type:"ORDER",title:`ÐÐ»Ð¸ÐµÐ½Ñ Ð¾ÑказалÑÑ Ð¾Ñ ÑоваÑа: Ðаказ ${w}`,text:`ТоваÑ: ${t.name}`,date:new Date().toISOString(),is_read:!1,link:ie.id}),c?.(A,M)}catch{C(null)}finally{R(!1)}},St=(t.priceCNY||0)*t.quantity,Pt=t.status?t.status.trim():"",Ut=Pt==="CANCELED"||Pt==="OUT_OF_STOCK",xt=S||t.clientDecision,zt=t.status==="PROBLEM"&&(!xt||xt==="WAITING"),J=t.status==="PROBLEM"&&xt==="RETURN",We=t.originalItemComment||t.itemComment||"",oe=We.includes(or.REFUND_APPROVED),Y=We.includes(or.FULL_REFUND);let Se=t.missingQuantity||0;if(Se===0&&We){const A=We.match(/(?:ÐедопоÑÑавка|ЧаÑÑиÑнÑй):\s*(\d+)/i);A&&(Se=parseInt(A[1],10))}const ve=Se>0&&Se<t.quantity;let T=0;if(oe||Y||Ut){const A=Se>0?Se:t.quantity,ie=(t.originalPriceCNY!==void 0&&t.price_confirm_decision!=="APPROVED"?t.originalPriceCNY:t.priceCNY)*A*(1+d);T=Math.round(ie*r)}a.useEffect(()=>{},[t.id,oe,Y,T,Se]);const[ke,be]=a.useState(!1),Ae=t.expectedArrivalDate?new Date(t.expectedArrivalDate).toLocaleDateString("ru-RU",{day:"numeric",month:"long"}):null,E=t.expectedWarehouseDate?new Date(t.expectedWarehouseDate):t.expectedArrivalDate?new Date(new Date(t.expectedArrivalDate).getTime()+6*864e5):null,se=E?E.toLocaleDateString("ru-RU",{day:"numeric",month:"long"}):null;t.expectedArrivalDate&&new Date(t.expectedArrivalDate).toLocaleDateString("ru-RU");const ee=Y||o,u=(oe||Ut)&&!Y&&!o,_=Qo(t)?Xo(t):null,P={title:i("china_leg_title"),shippedOn:i("china_leg_shipped_on"),shippedNoDate:i("china_leg_shipped_no_date"),selfShipped:i("china_leg_self_shipped"),carrier:i("china_leg_carrier"),trackingNo:i("china_leg_tracking_no"),copyTrackingNo:i("china_leg_copy_tracking_no"),noStepsYet:i("china_leg_no_steps_yet"),expand:i("china_leg_expand"),collapse:i("china_leg_collapse")};return e.jsxs("div",{className:"group/row border-b border-slate-100 last:border-0",children:[e.jsxs("div",{className:"md:hidden p-3 flex flex-col gap-2.5",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-14 h-14 shrink-0 rounded-xl border border-slate-200 overflow-hidden bg-slate-50 cursor-pointer",onClick:()=>t.image&&!x&&l?.(t.image),children:t.image&&!x?e.jsx("img",{src:t.image,alt:"",referrerPolicy:"no-referrer",className:"w-full h-full object-cover",onError:()=>m(!0)}):e.jsx("div",{className:"w-full h-full flex items-center justify-center text-slate-300",children:e.jsx(Yr,{size:18})})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-start gap-2 mb-1",children:[e.jsx("a",{href:t.url,target:"_blank",rel:"noreferrer",className:"text-sm font-bold text-slate-800 line-clamp-2 flex-1 leading-snug",children:t.name}),e.jsx("span",{className:`shrink-0 text-[9px] font-black px-2 py-0.5 rounded-full border ${it(Pt)}`,children:qe(Pt)})]}),t.specs&&e.jsx("span",{className:"text-[10px] text-slate-400 block",children:t.specs}),t.trackingNumber&&e.jsxs("span",{className:"text-[10px] font-bold text-blue-600 block",children:["TRK: ",t.trackingNumber]})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[(()=>{const A=t.originalPriceCNY!==void 0&&t.originalPriceCNY!==t.priceCNY,M=A&&t.priceCNY>t.originalPriceCNY,ie=A?Math.round((t.priceCNY-t.originalPriceCNY)*t.quantity*(1+d)*r):0;return e.jsxs("div",{className:`flex flex-col items-center rounded-xl py-2 border ${A?M?"bg-red-50 border-red-200":"bg-green-50 border-green-200":"bg-slate-50 border-slate-100"}`,children:[e.jsx("span",{className:"text-[9px] font-bold text-slate-400 uppercase mb-0.5",children:i("import_price_label")}),A&&e.jsxs("span",{className:"text-[9px] text-slate-400 line-through leading-tight",children:["Â¥",t.originalPriceCNY.toFixed(2)]}),e.jsxs("span",{className:`text-sm font-bold ${A?M?"text-red-700":"text-green-700":"text-slate-700"}`,children:["Â¥",t.priceCNY]}),A&&e.jsxs("span",{className:`text-[9px] font-bold leading-tight ${ie>0?"text-red-500":"text-green-600"}`,children:[ie>
480?"+":"",ie.toLocaleString("ru-RU")," â½"]})]})})(),e.jsxs("div",{className:"flex flex-col items-center bg-slate-50 rounded-xl py-2 border border-slate-100",children:[e.jsx("span",{className:"text-[9px] font-bold text-slate-400 uppercase mb-0.5",children:i("import_qty_label")}),Ne?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>_t(-1),disabled:te||t.quantity<=1,className:"w-5 h-5 flex items-center justify-center rounded-md bg-white border border-slate-200 text-slate-500 disabled:opacity-30 hover:bg-slate-100 transition-colors",children:e.jsx(ka,{size:11})}),te?e.jsx(rt,{size:12,className:"animate-spin mx-auto w-8"}):e.jsx("input",{type:"number",inputMode:"numeric",min:1,value:jt??t.quantity,onChange:A=>dt(A.target.value),onBlur:gt,onKeyDown:A=>{A.key==="Enter"&&A.target.blur()},className:"text-sm font-bold text-slate-700 w-8 text-center bg-transparent border-0 outline-none focus:ring-1 focus:ring-blue-300 rounded [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"}),e.jsx("button",{type:"button",onClick:()=>_t(1),disabled:te,className:"w-5 h-5 flex items-center justify-center rounded-md bg-white border border-slate-200 text-slate-500 disabled:opacity-30 hover:bg-slate-100 transition-colors",children:e.jsx($s,{size:11})})]}):e.jsxs("span",{className:"text-sm font-bold text-slate-700",children:[t.quantity," ",i("orders_unit_pcs")]})]}),e.jsxs("div",{className:"flex flex-col items-center bg-green-50 rounded-xl py-2 border border-green-100",children:[e.jsx("span",{className:"text-[9px] font-bold text-green-600 uppercase mb-0.5",children:i("item_total_label")}),e.jsxs("span",{className:"text-sm font-bold text-green-700",children:[Math.round(St*r).toLocaleString()," â½"]})]})]}),_&&e.jsx(ml,{tracking:_,labels:P,compact:!0}),Ue?$e?e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("textarea",{autoFocus:!0,rows:3,maxLength:500,placeholder:i("import_comment_placeholder"),className:"w-full text-xs px-3 py-2 border-2 border-blue-300 rounded-lg bg-white outline-none focus:border-blue-400 focus:ring-2 focus:ring-blue-100 resize-none transition-all",value:le,onChange:A=>Qe(A.target.value)}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-[10px] text-slate-400",children:[le.length,"/500"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>H(!1),className:"text-xs text-slate-400 hover:text-slate-600 px-2 py-1",children:i("orders_cancel_button")}),e.jsxs("button",{onClick:V,disabled:k,className:"flex items-center gap-1 text-xs font-bold text-white bg-blue-600 hover:bg-blue-700 px-3 py-1 rounded-lg disabled:opacity-60",children:[k?e.jsx(rt,{size:11,className:"animate-spin"}):e.jsx(as,{size:11}),i("profile_save_button")]})]})]})]}):e.jsxs("button",{onClick:de,className:`flex items-start gap-1.5 text-xs px-2 py-1.5 rounded-lg transition-colors border text-left w-full ${t.itemComment?"bg-blue-50 text-blue-700 border-blue-200":"bg-slate-50 text-slate-400 border-slate-200 hover:bg-blue-50 hover:border-blue-200 hover:text-blue-600"}`,children:[e.jsx(dr,{size:12,className:`shrink-0 mt-0.5 ${t.itemComment?"text-blue-500":"text-slate-300"}`}),e.jsx("span",{className:"break-words whitespace-normal",children:t.itemComment||i("import_add_comment")})]}):t.itemComment&&e.jsxs("div",{className:"text-xs bg-amber-50 text-amber-800 px-3 py-2 rounded-lg border border-amber-100 break-words whitespace-pre-wrap",children:[e.jsx("span",{className:"font-bold",children:i("item_note_label")})," ",t.itemComment]}),Ae&&t.status==="ON_WAY"&&e.jsxs("div",{className:"inline-flex items-center gap-2 px-3 py-1.5 bg-blue-50 border border-blue-100 rounded-lg",children:[e.jsx(Un,{size:13,className:"text-blue-500 shrink-0"}),e.jsxs("div",{className:"flex flex-col leading-tight",children:[e.jsx("span",{className:"text-[9px] uppercase font-bold text-blue-400",children:i("item_dispatch_short")}),e.jsx("span",{className:"text-sm font-black text-blue-700",children:Ae}),se&&e.jsxs("span",{className:"text-[10px] text-blue-400",children:[i("item_warehouse_approx_prefix"),se]})]}),e.jsx("button",{onClick:()=>be(!0),className:"w-5 h-5 rounded-full bg-orange-500 text-white flex items-center justify-center shrink-0 hover:bg-orange-600 transition-colors",title:i("order_details_more_about_dates"),children:e.jsx("span",{className:"text-[10px] font-black leading-none",children:"!"})})]}),ee&&e.jsxs("div",{className:"bg-green-50 border border-green-200 rounded-xl p-3 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-bold text-green-700",children:[e.jsx(as,{size:13}),i(ve?"item_partial_refund":"order_details_refund_done")]}),e.jsx("span",{className:"text-sm font-black text-green-800 shrink-0",children:ve?`${Se} ${i("item_qty_unit_short")}
48 (${T.toLocaleString()} â½)`:T>0?`${T.toLocaleString()} â½`:i("item_ready")})]}),u&&e.jsxs("div",{className:"bg-red-50 border border-red-200 rounded-xl p-3 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-bold text-red-700",children:[e.jsx(rs,{size:13}),i(ve?"item_partial_refund":"item_awaiting_payout")]}),e.jsx("span",{className:"text-sm font-black text-red-700 shrink-0",children:ve?`${Se} ${i("item_qty_unit_short")} (${T.toLocaleString()} â½)`:T>0?`${T.toLocaleString()} â½`:"0 â½"})]}),zt&&!oe&&e.jsx("div",{className:"text-xs text-slate-500 font-medium bg-slate-50 border border-slate-200 rounded-lg px-3 py-2",children:i("item_awaiting_decision")}),J&&!oe&&!Y&&e.jsxs("div",{className:"bg-blue-50 border border-blue-200 rounded-lg px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-bold text-blue-700 mb-0.5",children:[e.jsx(rs,{size:11})," ",i("item_refund_request_sent")]}),e.jsx("div",{className:"text-[10px] text-blue-600 leading-snug",children:i("item_refund_after_processing")})]}),B&&e.jsxs("button",{onClick:ye,className:"w-full flex items-center justify-center gap-1.5 py-2 rounded-xl border border-blue-200 bg-blue-50 text-blue-700 text-xs font-bold transition-colors hover:bg-blue-100",children:[e.jsx(dr,{size:12})," ",i("item_edit_price_button")]}),Ne&&e.jsxs("button",{onClick:ht,disabled:me,className:"w-full flex items-center justify-center gap-1.5 py-2 rounded-xl border border-red-200 bg-red-50 text-red-600 text-xs font-bold transition-colors hover:bg-red-100 disabled:opacity-50",children:[me?e.jsx(rt,{size:12,className:"animate-spin"}):e.jsx(is,{size:12})," ",i("import_delete_item_title")]}),t.warehousePhotos&&t.warehousePhotos.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"text-[9px] font-bold text-slate-400 uppercase mb-1.5",children:i("item_warehouse_photos")}),e.jsxs("div",{className:"grid grid-cols-4 gap-1.5",children:[t.warehousePhotos.slice(0,4).map((A,M)=>e.jsx("div",{className:"aspect-square rounded-lg border border-slate-200 overflow-hidden cursor-pointer",onClick:()=>l?.(A,t.warehousePhotos),children:e.jsx("img",{src:A,className:"w-full h-full object-cover",alt:"Wh"})},M)),t.warehousePhotos.length>4&&e.jsx("div",{className:"text-[9px] text-slate-400 col-span-4 text-center pt-1",children:i("item_more_photos",{count:t.warehousePhotos.length-4})})]})]})]}),e.jsxs("div",{className:"hidden md:flex flex-col gap-3 p-4 hover:bg-slate-50 transition-colors",children:[e.jsxs("a",{href:t.url,target:"_blank",rel:"noreferrer",className:"text-sm font-bold text-slate-800 hover:text-blue-600 transition-colors flex items-center gap-1 truncate",children:[t.name," ",e.jsx(Zn,{size:12,className:"opacity-30 shrink-0"})]}),e.jsxs("div",{className:"flex flex-row gap-4 items-start",children:[e.jsxs("div",{className:"w-24 shrink-0 relative self-start group",children:[e.jsx("div",{className:"absolute -top-2 -left-2 w-6 h-6 bg-slate-900 text-white rounded-lg flex items-center justify-center text-xs font-bold shadow-sm border-2 border-white z-10",children:n}),e.jsx("div",{className:"w-24 h-24 bg-white rounded-xl border border-slate-200 p-1 shadow-sm overflow-hidden relative cursor-pointer",onClick:()=>t.image&&!x&&l?.(t.image),children:t.image&&!x?e.jsxs(e.Fragment,{children:[e.jsx("img",{src:t.image,alt:"",referrerPolicy:"no-referrer",className:"w-full h-full object-cover rounded-lg",onError:()=>m(!0)}),e.jsx("div",{className:"absolute inset-0 bg-black/40 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center rounded-lg",children:e.jsx(Xn,{className:"text-white drop-shadow-md",size:24})})]}):e.jsx("div",{className:"w-full h-full bg-slate-50 rounded-lg flex items-center justify-center text-slate-300",children:e.jsx(Yr,{size:24})})})]}),e.jsxs("div",{className:"flex-1 min-w-0 self-start space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.specs&&e.jsx("span",{className:"text-[10px] font-bold bg-slate-100 text-slate-500 px-2 py-1 rounded border border-slate-200 uppercase tracking-wide",children:t.specs}),t.trackingNumber&&e.jsxs("span",{className:"text-[10px] font-bold bg-blue-50 text-blue-600 px-2 py-1 rounded border border-blue-100 uppercase tracking-wide flex items-center gap-1",children:["TRK: ",t.trackingNumber]})]}),_&&e.jsx(ml,{tracking:_,labels:P}),Ae&&t.status==="ON_WAY"&&e.jsxs("div",{className:"inline-flex items-center gap-2 px-3 py-1.5 bg-blue-50 border border-blue-100 rounded-lg text-blue-700 mt-1",children:[e.jsx(Un,{size:14,className:"text-blue-500 shrink-0"}),e.jsxs("div",{className:"flex flex-col leading-none",children:[e.jsx("span",{className:"text-[9px] uppercase font-bold text-blue-400",children:i("item_dispatch_from_seller")}),e.jsx("span",{className:"text-sm font-black",children:Ae}),se&&e.jsxs("span",{className:"text-[10px] text-blue-400 mt-0.5",children:[i("item_warehouse_approx_prefix"),se]})]}),e.jsx("button",{onClick:()=>be(!0),className:"w-5 h-5 rounded-full bg-orange-500 text-white flex items-center justify-center shrink-0 hover:bg-orange-600 transition-colors ml-1",title:i("order_details_more_about_dates"),children:e.jsx("span",{className:"text-[10px] font-black leading-none",children:"!"})})]}),Ue?$e?e.jsxs("div",{className:"mt-1 flex flex-col gap-1",children:[e.jsx("textarea",{autoFocus:!0,rows:3,maxLength:500,placeholder:i("import_comment_placeholder"),className:"w-full text-xs px-3 py-2 border-2 border-blue-300 rounded-lg bg-white outline-none focus:border-blue-400 focus:ring-2 focus:ring-blue-100 resize-none transition-all",value:le,onChange:A=>Qe(A.target.value)}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-[10px] text-slate-400",children:[le.length,"/500"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>H(!1),className:"text-xs text-slate-400 hover:text-slate-600 px-2 py-1",children:i("orders_cancel_button")}),e.jsxs("button",{onClick:V,disabled:k,className:"flex items-center gap-1 text-xs font-bold text-white bg-blue-600 hover:bg-blue-700 px-3 py-1 rounded-lg disabled:opacity-60",children:[k?e.jsx(rt,{size:11,className:"animate-spin"}):e.jsx(as,{size:11}),i("profile_save_button")]})]})]})]}):e.jsxs("button",{onClick:de,className:`mt-1 flex items-start gap-1.5 text-xs px-2 py-1.5 rounded-lg transition-colors border text-left w-full ${t.itemComment?"bg-blue-50 text-blue-700 border-blue-200":"bg-slate-50 text-slate-400 border-slate-200 hover:bg-blue-50 hover:border-blue-200 hover:text-blue-600"}`,children:[e.jsx(dr,{size:12,className:`shrink-0 mt-0.5 ${t.itemComment?"text-blue-500":"text-slate-300"}`}),e.jsx("span",{className:"break-words whitespace-normal",children:t.itemComment||i("import_add_comment")})]}):t.itemComment&&e.jsxs("div",{className:"mt-1 text-xs bg-amber-50 text-amber-800 px-3 py-2 rounded-lg border border-amber-100 break-words whitespace-pre-wrap",children:[e.jsx("span",{className:"font-bold",children:i("item_note_label")})," ",t.itemComment]})]}),(()=>{const A=t.originalPriceCNY!==void 0&&t.originalPriceCNY!==t.priceCNY,M=A&&t.priceCNY>t.originalPriceCNY,ie=A&&t.priceCNY<t.originalPriceCNY;return e.jsxs("div",{className:"w-[240px] shrink-0",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-2 mb-2 text-[10px] font-bold text-slate-400 uppercase text-center tracking-wider",children:[e.jsx("div",{children:i("import_price_label")}),e.jsx("div",{children:i("import_qty_label")}),e.jsx("div",{children:i("import_sum_label")})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 mb-2",children:[(()=>{const ge=A?Math.round((t.priceCNY-t.originalPriceCNY)*t.quantity*(1+d)*r):0;return e.jsxs("div",{className:`border rounded-lg py-1.5 text-center text-sm font-bold shadow-sm ${M?"bg-red-50 border-red-300 text-red-700":ie?"bg-green-50 border-green-300 text-green-700":"bg-white border-slate-200 text-slate-700"}`,children:[A&&e.jsxs("div",{className:"text-[10px] text-slate-400 line-through leading-tight",children:["Â¥",t.originalPriceCNY.toFixed(2)]}),e.jsx("div",{children:t.priceCNY}),A&&e.jsxs("div",{className:`text-[10px] font-bold leading-tight ${ge>0?"text-red-500":"text-green-600"}`,children:[ge>
480?"+":"",ge.toLocaleString("ru-RU")," â½"]})]})})(),e.jsx("div",{className:"bg-white border border-slate-200 rounded-lg py-1.5 text-center text-sm font-bold text-slate-700 shadow-sm",children:Ne?e.jsxs("div",{className:"flex items-center justify-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>_t(-1),disabled:te||t.quantity<=1,className:"w-5 h-5 flex items-center justify-center rounded-md bg-slate-50 border border-slate-200 text-slate-500 disabled:opacity-30 hover:bg-slate-100 transition-colors",children:e.jsx(ka,{size:11})}),te?e.jsx(rt,{size:12,className:"animate-spin mx-auto w-8"}):e.jsx("input",{type:"number",inputMode:"numeric",min:1,value:jt??t.quantity,onChange:ge=>dt(ge.target.value),onBlur:gt,onKeyDown:ge=>{ge.key==="Enter"&&ge.target.blur()},className:"w-8 text-center bg-transparent border-0 outline-none focus:ring-1 focus:ring-blue-300 rounded [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"}),e.jsx("button",{type:"button",onClick:()=>_t(1),disabled:te,className:"w-5 h-5 flex items-center justify-center rounded-md bg-slate-50 border border-slate-200 text-slate-500 disabled:opacity-30 hover:bg-slate-100 transition-colors",children:e.jsx($s,{size:11})})]}):t.quantity}),e.jsxs("div",{className:"bg-green-50 border border-green-200 rounded-lg py-1.5 text-center text-sm font-black text-green-700 shadow-sm",children:[Math.round(St*r).toLocaleString("ru-RU")," â½"]})]}),e.jsxs("div",{className:"flex justify-center items-center px-1",children:[e.jsx("span",{className:"text-xs font-bold text-slate-400",children:i("item_sum_no_delivery")}),e.jsxs("span",{className:"text-xs text-slate-400 ml-1.5",children:["Â¥",St.toFixed(2)]})]}),t.clientOriginalPriceCNY!==void 0&&t.clientOriginalPriceCNY!==t.priceCNY&&e.jsx("div",{className:"mt-1.5 px-2 py-1 bg-blue-50 border border-blue-200 rounded-lg text-[10px] text-blue-700 font-semibold text-center",children:i("item_price_changed_badge",{old:t.clientOriginalPriceCNY.toFixed(2),new:t.priceCNY.toFixed(2)})}),B&&e.jsxs("button",{onClick:ye,className:"mt-2 w-full flex items-center justify-center gap-1.5 py-1.5 rounded-lg border border-blue-200 bg-blue-50 hover:bg-blue-100 text-blue-700 text-xs font-bold transition-colors",children:[e.jsx(dr,{size:11}),i("orders_edit_button")]}),Ne&&e.jsxs("button",{onClick:ht,disabled:me,className:"mt-2 w-full flex items-center justify-center gap-1.5 py-1.5 rounded-lg border border-red-200 bg-red-50 hover:bg-red-100 text-red-600 text-xs font-bold transition-colors disabled:opacity-50",children:[me?e.jsx(rt,{size:11,className:"animate-spin"}):e.jsx(is,{size:11}),i("import_delete_button")]}),(t.clientAttachments?.length??0)>0&&e.jsxs("div",{className:"mt-1 flex items-center gap-1 text-[10px] text-slate-400",children:[e.jsx($n,{size:10}),i("item_files_count",{count:t.clientAttachments.length})]})]})})(),e.jsxs("div",{className:"w-36 shrink-0 flex flex-col items-center justify-center space-y-2",children:[e.jsx("div",{className:"text-[10px] font-bold text-slate-400 uppercase tracking-wider mb-0",children:i("item_status_label")}),e.jsx("div",{className:`w-full py-2.5 rounded-lg border text-xs font-black uppercase tracking-wider text-center shadow-sm ${it(Pt)}`,children:qe(Pt)}),ee&&e.jsxs("div",{className:"w-full bg-green-50 border border-green-200 rounded-lg p-2 flex flex-col items-center justify-center",children:[e.jsxs("div",{className:"flex items-center gap-1 text-[10px] font-bold text-green-700 uppercase tracking-tight",children:[e.jsx(as,{size:10,strokeWidth:3}),i(ve?"item_partial_refund":"order_details_refund_done")]}),ve?e.jsxs("div",{className:"text-base font-black text-green-800 leading-none mt-1",children:[Se," ",i("item_qty_unit_short")," (",T.toLocaleString()," â½)"]}):e.jsx("div",{className:"text-lg font-black text-green-800 leading-none mt-1",children:T>0?`${T.toLocaleString()} â½`:i("item_ready")})]}),u&&e.jsxs("div",{className:"w-full bg-red-50 border border-red-200 rounded-lg p-2 flex flex-col items-center justify-center shadow-sm animate-in fade-in zoom-in-95",children:[e.jsxs("div",{className:"flex items-center gap-1 text-[10px] font-bold text-red-700 uppercase tracking-tight",children:[e.jsx(rs,{size:10,strokeWidth:3}),i(ve?"item_partial_refund":"item_awaiting_payout")]}),ve?e.jsxs("div",{className:"text-base font-black text-red-700 leading-none tracking-tight mt-1",children:[Se," ",i("item_qty_unit_short")," (",T.toLocaleStr
48ing()," â½)"]}):e.jsx("div",{className:"text-lg font-black text-red-700 leading-none tracking-tight mt-1",children:T>0?`${T.toLocaleString()} â½`:"0 â½"})]}),zt&&!oe&&e.jsx("div",{className:"w-full bg-slate-50 border border-slate-200 rounded-lg p-2 flex flex-col items-center justify-center",children:e.jsx("div",{className:"text-xs text-slate-500 font-medium",children:i("item_awaiting_decision")})}),J&&!oe&&!Y&&e.jsxs("div",{className:"w-full bg-blue-50 border border-blue-200 rounded-lg p-2 flex flex-col items-center text-center",children:[e.jsxs("div",{className:"flex items-center gap-1 text-[10px] font-bold text-blue-700",children:[e.jsx(rs,{size:10})," ",i("item_refund_request_short")]}),e.jsx("div",{className:"text-[9px] text-blue-500 mt-0.5 leading-snug",children:i("item_refund_credited_soon")})]})]})]}),t.warehousePhotos&&t.warehousePhotos.length>0&&e.jsxs("div",{className:"flex flex-col items-start pl-4 border-l border-slate-100",children:[e.jsx("div",{className:"text-[10px] font-bold text-slate-400 uppercase tracking-wider mb-2",children:i("item_warehouse_photos")}),e.jsxs("div",{className:"grid grid-cols-6 gap-2 w-full",children:[t.warehousePhotos.slice(0,6).map((A,M)=>e.jsx("div",{className:"aspect-square rounded-lg border border-slate-200 overflow-hidden bg-white p-0.5 shadow-sm cursor-pointer hover:border-blue-400",onClick:()=>l?.(A,t.warehousePhotos),children:e.jsx("img",{src:A,className:"w-full h-full object-cover rounded-md",alt:"Wh"})},M)),t.warehousePhotos.length>6&&e.jsx("div",{className:"text-[9px] text-slate-400 col-span-6 text-center pt-1",children:i("item_more_short",{count:t.warehousePhotos.length-6})})]})]})]}),L&&B&&e.jsxs("div",{className:"mx-4 mb-4 border border-blue-200 rounded-xl bg-blue-50/60 p-4 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(dr,{size:14,className:"text-blue-600"}),e.jsxs("span",{className:"text-sm font-bold text-blue-800",children:[i("item_editing_prefix")," ",t.name.slice(0,40),t.name.length>40?"â¦":""]})]}),e.jsx("button",{onClick:()=>U(!1),className:"p-1 hover:bg-blue-100 rounded-lg",children:e.jsx(bt,{size:16,className:"text-slate-500"})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-bold text-slate-500 uppercase block mb-1.5",children:i("item_price_per_unit_label")}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-400 font-bold text-sm",children:"Â¥"}),e.jsx("input",{type:"number",min:"0.01",step:"0.01",value:W,onChange:A=>re(A.target.value),className:"pl-7 pr-3 py-2 w-36 border border-slate-200 rounded-xl text-sm font-bold text-slate-700 outline-none focus:border-blue-400 bg-white"})]}),t.clientOriginalPriceCNY!==void 0?e.jsx("span",{className:"text-xs text-slate-400",children:i("item_original_price",{price:t.clientOriginalPriceCNY.toFixed(2)})}):e.jsx("span",{className:"text-xs text-slate-400",children:i("item_current_price",{price:t.priceCNY.toFixed(2)})})]}),e.jsx("p",{className:"text-[10px] text-slate-400 mt-1",children:i("item_price_edit_hint")})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-bold text-slate-500 uppercase block mb-2",children:i("item_files_label")}),$.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 mb-3",children:$.map((A,M)=>{const ie=decodeURIComponent(A.split("/").pop()?.split("?")[0]??i("item_file_fallback_name",{n:M+1})),ge=/\.(jpg|jpeg|png)$/i.test(ie);return e.jsxs("div",{className:"flex items-center gap-1.5 bg-white border border-slate-200 rounded-lg px-2 py-1.5 group max-w-[200px]",children:[ge?e.jsx("img",{src:A,alt:"",className:"w-8 h-8 object-cover rounded flex-shrink-0",onClick:()=>l?.(A,$.filter(w=>/\.(jpg|jpeg|png)$/i.test(w.split("/").pop()?.split("?")[0]??"")))}):e.jsx($n,{size:16,className:"text-slate-400 flex-shrink-0"}),e.jsx("span",{className:"text-[10px] text-slate-600 truncate flex-1",children:ie.replace(/^\d+_[a-z0-9]+\./,"")}),e.jsx("button",{onClick:()=>Oe(A),className:"opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0",children:e.jsx(bt,{size:12,className:"text-red-400 hover:text-red-600"})})]},M)})}),e.jsxs("label",{className:`inline-flex cursor-pointer items-center gap-2 px-3 py-2 rounded-xl text-xs font-bold transition-colors ${F?"bg-slate-100 text-slate-400":"bg-white border border-slate-200 hover:bg-slate-50 text-slate-600"}`,children:[F?e.jsx(rt,{size:13,className:"animate-spin"}):e.jsx(yi,{size:13}),i(F?"item_uploading":"support_attach_file"),e.jsx("input",{type:"file",accept:Kx,className:"hidden",disabled:F,onChange:Ie})]}),e.jsx("span",{className:"ml-2 text-[10px] text-slate-400",children:"JPG, PNG, PDF, ZIP, RAR, XLSX"})]}),e.jsxs("div",{className:"flex items-center gap-3 pt-1 border-t border-blue-100",children:[e.jsxs("button",{onClick:we,disabled:Z||F,className:"flex items-center gap-2 px-4 py-2 bg-blue-600 hover:bg-blue-700 disabled:opacity-60 text-white rounded-xl text-sm font-bold transition-colors",children:[Z?e.jsx(rt,{size:14,className:"animate-spin"}):e.jsx(as,{size:14}),i(Z?"item_saving":"profile_save_button")]}),e.jsx("button",{onClick:()=>U(!1),className:"px-4 py-2 rounded-xl border border-slate-200 text-sm font-bold text-slate-500 hover:bg-slate-50 transition-colors",children:i("orders_cancel_button")})]})]}),zt&&e.jsx("div",{className:"px-4 pb-4",children:e.jsx("div",{className:"bg-amber-50 border border-amber-200 rounded-xl p-5 shadow-sm",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(hs,{size:20,className:"text-amber-600 mt-1"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"font-bold text-amber-900 text-lg mb-1",children:i("item_mismatch_title",{comment:t.itemComment})}),e.jsxs("div",{className:"flex gap-3 mt-4",children:[e.jsxs("button",{onClick:()=>Ge(t.id,"KEEP"),disabled:N,className:"flex items-center gap-2 px-6 py-2 bg-green-600 text-white rounded-lg font-bold hover:bg-green-700",children:[N&&S==="KEEP"?e.jsx(rt,{className:"animate-spin"}):e.jsx(as,{})," ",i("item_keep_button")]}),e.jsxs("button",{onClick:()=>Ge(t.id,"RETURN"),disabled:N,className:"flex items-center gap-2 px-6 py-2 bg-red-50 text-red-600 border border-red-200 rounded-lg font-bold hover:bg-red-100",children:[N&&S==="RETURN"?e.jsx(rt,{className:"animate-spin"}):e.jsx(Gr,{})," ",i("item_return_button")]})]})]})]})})}),ke&&Ae&&e.jsx("div",{className:"fixed inset-0 z-[300] flex items-center justify-center bg-black/50 p-4",onClick:()=>be(!1),children:e.jsxs("div",{className:"bg-white rounded-2xl shadow-2xl w-full max-w-sm p-6",onClick:A=>A.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-orange-100 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"text-orange-600 font-black text-lg leading-none",children:"!"})}),e.jsx("h3",{className:"font-bold text-slate-800 text-base",children:i("item_delivery_dates_title")})]}),e.jsxs("div",{className:"space-y-3 text-sm text-slate-700",children:[e.jsxs("p",{children:[i("item_seller_will_ship_prefix")," ",e.jsx("strong",{children:Ae}),"."]}),e.jsxs("p",{children:[i("item_avg_delivery_time_prefix")," ",e.jsx("strong",{children:i("item_avg_delivery_time_range")}),"."]}),se&&e.jsxs("p",{children:[i("item_expected_arrival_prefix")," ",e.jsx("strong",{children:i("item_expected_arrival_value",{date:se})}),"."]}),e.jsx("p",{className:"text-slate-500",children:i("item_delay_notice")})]}),e.jsx("button",{onClick:()=>be(!1),className:"mt-5 w-full py-2.5 bg-slate-900 text-white rounded-xl font-bold text-sm hover:bg-slate-700 transition-colors",children:i("topup_understood")})]})})]})},lo=({order:t,onClose:s})=>{const{t:n}=qt(),r=t.items||[],l=r.reduce((c,o)=>c+(Number(o.quantity)||0),0);return e.jsxs("div",{className:"order-print-overlay fixed inset-0 bg-black/50 z-[100] flex items-center justify-center p-4 animate-in fade-in duration-200",children:[e.jsx("style",{children:` 49 @media print { 50 body * { visibility: hidden; } 51 .order-print-area, .order-print-area * { visibility: visible; } 52 .order-print-overlay { position: static !important; } 53 .order-print-modal-outer, .order-print-modal-outer * { overflow: visible !important; max-height: none !important; } 54 .order-print-area { position: absolute; left: 0; top: 0; width: 100%; } 55 .no-print { display: none !important; } 56 } 57 `}),e.jsxs("div",{className:"order-print-modal-outer bg-white rounded-2xl shadow-xl max-w-2xl w-full max-h-[90vh] overflow-y-auto animate-in zoom-in-95 duration-200",children:[e.jsxs("div",{className:"no-print flex items-center justify-between px-5 py-4 border-b border-slate-200 sticky top-0 bg-white z-10",children:[e.jsx("h2",{className:"font-bold text-slate-800",children:n("order_print_title")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>window.print(),className:"flex items-center gap-1.5 px-3 py-2 rounded-xl font-bold text-sm bg-blue-600 text-white hover:bg-blue-700 transition-colors",children:[e.jsx(Ya,{size:15})," ",n("order_print_button")]}),e.jsx("button",{onClick:s,className:"text-slate-400 hover:text-slate-600 p-2",children:e.jsx(bt,{size:20})})]})]}),e.jsx("p",{className:"no-print px-5 pb-3 -mt-1 text-xs text-slate-400",children:n("order_print_pdf_hint")}),e.jsxs("div",{className:"order-print-area p-6",children:[e.jsxs("div",{className:"mb-4 pb-4 border-b border-slate-200",children:[e.jsxs("h1",{className:"text-lg font-bold text-slate-900",children:[n("order_print_order_label")," ",t.display_id||t.id]}),e.jsx("p",{className:"text-sm text-slate-500",children:Ta(t.created_at)}),e.jsx("p",{className:"text-sm text-slate-500",children:n("order_print_total_items",{count:r.length,qty:l})})]}),e.jsx("div",{className:"space-y-3",children:r.map((c,o)=>e.jsxs("div",{className:"flex items-center gap-3 border border-slate-200 rounded-xl p-3 break-inside-avoid",children:[e.jsx("div",{className:"w-16 h-16 shrink-0 rounded-lg overflow-hidden bg-slate-100 border border-slate-200",children:c.image?e.jsx("img",{src:c.image,alt:"",className:"w-full h-full object-cover"}):null}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold text-slate-800 line-clamp-2",children:c.name}),c.specs&&e.jsx("p",{className:"text-xs text-slate-500 mt-0.5",children:c.specs}),!!c.priceCNY&&e.jsxs("p",{className:"text-xs text-slate-400 mt-0.5",children:["Â¥",c.priceCNY," / ",n("order_print_qty_label").toLowerCase()]})]}),e.jsxs("div",{className:"shrink-0 text-right",children:[e.jsx("p",{className:"text-xs text-slate-400",children:n("order_print_qty_label")}),e.jsx("p",{className:"text-lg font-bold text-slate-900",children:c.quantity})]}),e.jsx("div",{className:"hidden print:block w-6 h-6 shrink-0 border-2 border-slate-400 rounded"})]},c.id||o))})]})]})]})},Qx={NEW:"orders_status_new",PAID:"orders_status_paid",PURCHASED:"orders_status_purchased",COLLECTING:"orders_status_collecting",ASSEMBLED:"orders_status_assembled",SHIPPED:"orders_status_shipped",RECEIVED:"orders_status_received",CANCELED:"orders_status_canceled"};function Kn(t,s){const n=Qx[t];return n?s(n):t}const Xx=({order:t,onClose:s,cnyRate:n,usdRate:r=90,commissionSettings:l,canEditOrders:c=!1,userBalance:o=0,onPaymentSuccess:d,onPayDelivery:p,onEditDelivery:y,onContactManager:j,onLabelSaved:b,initialShowPackingInfo:h=!1,onUngroup:v})=>{const{t:i}
57=qt(),[x,m]=a.useState(t),[N,R]=a.useState(!1);a.useEffect(()=>{m(t)},[t]),a.useEffect(()=>{h&&Oe(!0)},[h]);const[S,C]=a.useState(t?.client_label||""),[L,U]=a.useState(!1),[W,re]=a.useState(null),[Z,O]=a.useState(null),[F,D]=a.useState(!1),[$,z]=a.useState("ALL"),[me,K]=a.useState("ALL"),[te,I]=a.useState([]),[B,Ne]=a.useState(!0),[Ue,$e]=a.useState(null),H=a.useCallback((f,ae)=>{$e({url:f,gallery:ae&&ae.length>0?ae:[f]})},[]),le=Ue?Ue.gallery.indexOf(Ue.url):-1,Qe=a.useCallback(()=>{$e(f=>{if(!f||f.gallery.length<=1)return f;const ue=(f.gallery.indexOf(f.url)-1+f.gallery.length)%f.gallery.length;return{...f,url:f.gallery[ue]}})},[]),k=a.useCallback(()=>{$e(f=>{if(!f||f.gallery.length<=1)return f;const ue=(f.gallery.indexOf(f.url)+1)%f.gallery.length;return{...f,url:f.gallery[ue]}})},[]);a.useEffect(()=>{if(!Ue)return;const f=ae=>{ae.key==="ArrowLeft"?Qe():ae.key==="ArrowRight"?k():ae.key==="Escape"&&$e(null)};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[Ue,Qe,k]);const[xe,de]=a.useState(!1),[V,ye]=a.useState(!1),[Ie,Oe]=a.useState(!1),[we,Le]=a.useState(!1),[_t,jt]=a.useState(!1),[dt,gt]=a.useState(!1),[ht,qe]=a.useState(!1),[it,Ge]=a.useState(!1),[St,Pt]=a.useState(!1),[Ut,xt]=a.useState(!1),[zt,J]=a.useState(!1),[We,oe]=a.useState([]),[Y,Se]=a.useState(!0),[ve,T]=a.useState({}),[ke,be]=a.useState({}),[Ae,E]=a.useState(null),[se,ee]=a.useState(()=>localStorage.getItem("order_details_sidebar_collapsed")==="1"),u=()=>ee(f=>{const ae=!f;return localStorage.setItem("order_details_sidebar_collapsed",ae?"1":"0"),ae}),_=x?.clientPreferences||x?.client_preferences,P=_?.fixed_cny_rate||n,A=!!_?.fixed_cny_rate,M=tc(yt(),_?.deliveryData?.passport),[ie,ge]=a.useState(!1);if(a.useEffect(()=>{x?.id&&(Ne(!0),(async()=>{try{const{data:ae}=await Re("transactions",{order_id:x.id,status:"COMPLETED"},{select:"*"});ae&&I(ae.filter(ue=>["REFUND","PAYMENT"].includes(ue.type)))}finally{Ne(!1)}})())},[x?.id]),a.useEffect(()=>{if(!x?.id||x.status!=="NEW"){ye(!1);return}let f=!1;return Fr(x.id).then(ae=>{f||ye(ae)}),()=>{f=!0}},[x?.id,x?.status,xe]),a.useEffect(()=>{const f=x?.video_url,ae=x?.video_uploaded_at;if(!f||!ae)return;const ue=2880*60*1e3,Me=()=>{const ot=Date.now()-new Date(ae).getTime(),at=ue-ot;at<=0?(D(!0),O(null),Je("orders",{id:x.id},{video_url:null,video_uploaded_at:null}).then(({error:vt})=>{})):O({h:Math.floor(at/36e5),m:Math.floor(at%36e5/6e4)})};Me();const Fe=setInterval(Me,6e4);return()=>clearInterval(Fe)},[x?.video_url,x?.video_uploaded_at]),a.useEffect(()=>{x?.id&&Re("shipments",{order_id:x.id},{order:"created_at.asc"}).then(({data:f})=>{f&&oe(f)})},[x?.id]),!x)return null;const w=async()=>{if(!Ut){xt(!0);try{const{error:f}=await Je("orders",{id:x.id},{client_confirmed:!0});if(f)throw new Error(f);const{error:ae}=await st("notifications",{user_id:null,type:"SYSTEM",title:"ÐÐ»Ð¸ÐµÐ½Ñ Ð¿Ð¾Ð´ÑвеÑдил ÑоÑооÑÑÑÑ",text:`ÐÐ»Ð¸ÐµÐ½Ñ Ð¿Ð¾Ð´ÑвеÑдил ÑоÑо Ð´Ð»Ñ Ð·Ð°ÐºÐ°Ð·Ð° ${x.display_id||x.displayId||x.id}. Ðожно ÑпаковÑваÑÑ Ð¸ оÑпÑавлÑÑÑ.`,link:x.id,date:new Date().toISOString(),is_read:!1});m({...x,client_confirmed:!0})}catch(f){alert(i("common_error_prefix")+f.message)}finally{xt(!1)}}},fe=async()=>{const f=x?.shipment_group_id;if(!(!f||!v)){Pt(!0);try{await v(f),m({...x,shipment_group_id:null}),Ge(!1),gt(!0)}catch(ae){alert(i("common_error_prefix")+ae.message)}finally{Pt(!1)}}},pe=async()=>{qe(!0);try{const{error:f}=await Je("orders",{id:x.id},{partial_ship_requested:!0});if(f)throw new Error(f);const{error:ae}=await st("notifications",{user_id:null,type:"SYSTEM",title:"ÐапÑÐ¾Ñ ÑаÑÑиÑной оÑпÑавки",text:`ÐÐ»Ð¸ÐµÐ½Ñ Ð¿ÑоÑÐ¸Ñ Ð¾ÑпÑавиÑÑ Ð¸Ð¼ÐµÑÑиеÑÑ ÑоваÑÑ Ð´Ð»Ñ Ð·Ð°ÐºÐ°Ð·Ð° ${x.display_id||x.displayId||x.id}. УпакÑйÑе Ñо ÑÑо Ñже пÑинÑÑо.`,link:x.id,date:new Date().toISOString(),is_read:!1});m({...x,partial_ship_requested:!0}),gt(!1)}catch(f){alert(i("common_error_prefix")+f.message)}qe(!1)};(x.items||[]).flatMap(f=>f.warehousePhotos||[]);const je=x.items.filter(f=>f.status==="RECEIVED"),ze=x.items.filter(f=>["ON_WAY","PROCESSING","PURCHASED"].includes(f.status)),Tt=ze.length>0&&je.length>0&&!x.partial_ship_requested&&!["ASSEMBLED","SHIPPED","RECEIVED","CANCELED"].includes(x.status),G=f=>{const ae=f.chinaDelivery||f.china_delivery||f.delivery||f.deliveryFee||0;return Number(ae)||0},q=x.status==="PAID",he=a.useMemo(()=>x.items.map(f=>{const ae=f.status==="PARTIALLY_RECEIVED",ue=f.status==="PROBLEM"&&(f.itemComment||"").toLowerCase().includes("не пÑиÑел"),Me=f.itemComment||"",Fe=f.status;let ot=f.status;(ae||ue)&&(ot="ON_WAY"),f.status==="DELAYED"?ot="DELAYED":q&&(ot="PROCESSING");let at=f.itemComment||"";const vt=at.toLowerCase().includes("ÑаÑÑиÑнÑй возвÑаÑ");
57return at.includes("ÐÐÐÐÐ ÐТ ÐЫÐÐÐÐÐÐ")&&(at=at.replace(/\|?\s*ÐÐÐÐÐ ÐТ ÐЫÐÐÐÐÐÐ\s*\|\s*СÑмма:[^|]*/,"").trim(),at.endsWith("|")&&(at=at.slice(0,-1).trim())),!vt&&(at.startsWith("ÐÐÐÐÐУ:")||ae||ue)&&(at=""),q&&(at=""),{...f,status:ot,itemComment:at,originalItemComment:q?"":Me,originalStatus:q?"PROCESSING":Fe,realMissingQuantity:q?0:f.missingQuantity||0,priceCNY:f.priceCNY||f.price||0,chinaDelivery:G(f),chinaDeliveryActual:f.chinaDeliveryActual!==void 0?f.chinaDeliveryActual:G(f),clientDecision:q?null:f.clientDecision}}),[x.items,q]),_e=a.useMemo(()=>{const f=he.reduce((Ce,He)=>{const Ve=He.originalPriceCNY!==void 0&&He.price_confirm_decision!=="APPROVED"?He.originalPriceCNY:He.priceCNY;return Ce+Ve*He.quantity},0),ae=he.reduce((Ce,He)=>Ce+(He.chinaDelivery||0),0);let ue=0,Me=5,Fe=.05,ot=!1;const vt=(x.items||[]).some(Ce=>Ce.estimatedWeightPerUnit!=null&&Ce.estimatedWeightPerUnit>0||Ce.needsWeightRecalculation===!0),es=x.commission_cny??null;if(vt&&es!==null&&f>0)ue=es,Fe=es/f,Me=parseFloat((Fe*100).toFixed(2)),ot=!0;else if(_?.fixed_commission_pct!=null)Me=_.fixed_commission_pct,Fe=Me/100,ue=f*Fe;else if(l&&l.isEnabled){const Ce=l.rules.map(Ke=>({...Ke,minAmount:parseFloat(Ke.minAmount),maxAmount:Ke.maxAmount?parseFloat(Ke.maxAmount):null,rate:parseFloat(Ke.rate)})).sort((Ke,Be)=>Ke.minAmount-Be.minAmount);let He=Ce[0];for(const Ke of Ce){let Be=f;Ke.currency==="RUB"?Be=f*P:Ke.currency==="USD"&&(Be=f*P/92),Be>=Ke.minAmount&&(Ke.maxAmount===null||Be<=Ke.maxAmount)&&(He=Ke)}He?ue=f*(He.rate/100):ue=f*.05;let Ve=0;const tt=parseFloat(l.minCommission);tt>0&&(l.minCommissionCurrency==="USD"?Ve=tt*7.2:l.minCommissionCurrency==="RUB"?Ve=tt/P:Ve=tt),ue<Ve&&f>0&&(ue=Ve),f>0?Fe=ue/f:Fe=He?He.rate/100:.05,Me=parseFloat((Fe*100).toFixed(2))}else ue=f*.05,Fe=.05,Me=5;const wt=f+ae+ue,et=Math.round(wt*P),kt={};he.forEach(Ce=>{const He=Ce.shopName||"other";kt[He]||(kt[He]=[]),kt[He].push(Ce)});let pt=0,$t=0,Bt=0;Object.values(kt).forEach(Ce=>{const He=Ce.every(Be=>{const ut=Be.originalStatus,Ze=(Be.originalItemComment||"").toLowerCase().includes("не пÑиÑел");return ut==="OUT_OF_STOCK"||ut==="CANCELED"||ut==="PROBLEM"&&(Be.clientDecision==="RETURN"||Ze)}),Ve=Ce.every(Be=>{const ut=Be.originalStatus,Ze=Be.originalItemComment||"";return ut==="OUT_OF_STOCK"||ut==="CANCELED"?!0:ut==="PROBLEM"?Ze.includes(or.REFUND_APPROVED)||Ze.includes(or.FULL_REFUND):!0});Ce.forEach(Be=>{const ut=Be.originalStatus,Ze=(Be.originalItemComment||"").toLowerCase().includes("не пÑиÑел");ut==="OUT_OF_STOCK"||ut==="CANCELED"||ut==="PROBLEM"&&Be.clientDecision;const Rt=(Be.originalItemComment||"").includes(or.REFUND_APPROVED)||(Be.originalItemComment||"").includes(or.FULL_REFUND);if(ut==="OUT_OF_STOCK"||ut==="CANCELED"||ut==="PROBLEM"&&(Be.clientDecision==="RETURN"||Ze)&&Rt){Bt++;const Hs=(Be.originalPriceCNY!==void 0&&Be.price_confirm_decision!=="APPROVED"?Be.originalPriceCNY:Be.priceCNY)*Be.quantity*(1+Fe);pt+=Nn(Hs,P)}else{const Ns=Be.realMissingQuantity||0,Hs=ut==="PARTIALLY_RECEIVED";if(Ns>0&&!Hs){const Rs=Be.priceCNY*Ns,ir=Rs*Fe;pt+=Nn(Rs+ir,P)}}});const tt=Ce.reduce((Be,ut)=>Be+(ut.chinaDelivery||0),0),Ke=Ce.reduce((Be,ut)=>Be+(ut.chinaDeliveryActual!==void 0?ut.chinaDeliveryActual:ut.chinaDelivery||0),0);if($t+=tt-Ke,He&&Ve){const Be=Ke>0?Ke:tt;Be>0&&(pt+=Nn(Be,P))}});const ns=Math.round($t*P);let vs=0;he.forEach(Ce=>{if(Ce.originalPriceCNY!==void 0&&Ce.originalPriceCNY!==Ce.priceCNY&&Ce.originalStatus!=="CANCELED"&&Ce.originalStatus!=="OUT_OF_STOCK"){const He=(Ce.originalPriceCNY-Ce.priceCNY)*Ce.quantity*(1+Fe);vs+=Math.round(Nn(He,P))}});const X=pt+ns+vs;let Te=0;te.forEach(Ce=>{const He=(Ce.description||"").toLowerCase();He.includes("вÑкÑп")||He.includes("ÑпиÑание ÑÑедÑÑв")||Math.abs(Ce.amount)>et*.8||(Ce.type==="REFUND"&&(Te+=Math.abs(Ce.amount)),Ce.type==="PAYMENT"&&(Te-=Math.abs(Ce.amount)))});const ce=X-Te,lt=Math.abs(ce)<5;return{itemsGoodsTotal:f,commissionTotal:ue,appliedPercent:Me,effectiveRateFactor:Fe,isWeightBased:ot,totalChinaDeliveryClient:ae,totalCNY_Client:wt,totalRUB_Base:et,refundsFromItemsRUB:pt,deliveryProfitRUB:ns,priceDeltaRUB:vs,totalProjectedRefund:X,pendingDifference:ce,isBalanceSettled:lt,canceledCount:Bt}},[he,te,P,l,x]),Xe=f=>{const ae=(f.shopUrl||f.url||"").toLowerCase();return ae.includes("1688.com")?"1688":ae.includes("tmall.com")?"Tmall":ae.includes("taobao.c
57om")?"Таобао":"other"},Ct=he.some(f=>Xe(f)==="1688"),Gt=he.some(f=>Xe(f)==="Таобао"),Nt=he.some(f=>Xe(f)==="Tmall"),Wt=he.filter(f=>f.status==="DELAYED"),os=he.filter(f=>f.status!=="DELAYED"),As=["SHIPPED","RECEIVED","CANCELED"].includes(x.status),cs=he.filter(f=>f.vendorQuestionStatus==="ESCALATED"?!0:As?!1:f.vendorQuestionStatus==="PENDING"||f.vendorQuestionStatus==="ANSWERED"),Xt=he.filter(f=>f.price_confirm_decision!==void 0),Mt=Xt.length>0&&Xt.every(f=>f.price_confirm_decision==="APPROVED"||f.price_confirm_decision==="REJECTED");a.useEffect(()=>{Mt&&Se(!1)},[Mt]);const Ls=async(f,ae)=>{if(!ve[f]){T(ue=>({...ue,[f]:!0})),be(ue=>{const Me={...ue};return delete Me[f],Me});try{const ue=x.display_id||x.displayId||x.id,Me=x.items.find(vt=>vt.id===f);if(!Me)return;const Fe={...Me,price_confirm_decision:ae,...ae==="REJECTED"?{status:"CANCELED"}:{}},{error:ot}=await ll(x.id,[Fe]);if(ot)throw new Error(ot);const at=x.items.map(vt=>vt.id===f?Fe:vt);await st("notifications",{type:"SYSTEM",title:ae==="APPROVED"?`ÐÐ»Ð¸ÐµÐ½Ñ ÑоглаÑен на новÑÑ ÑÐµÐ½Ñ â ${ue}`:`ÐÐ»Ð¸ÐµÐ½Ñ Ð¾ÑказалÑÑ Ð¾Ñ ÑоваÑа â ${ue}`,text:ae==="APPROVED"?`ÐÐ»Ð¸ÐµÐ½Ñ ÑоглаÑен кÑпиÑÑ Ð¿Ð¾ новой Ñене: ${Me?.name||f}. Ðаказ: ${ue}`:`ÐÐ»Ð¸ÐµÐ½Ñ Ð¾ÑказалÑÑ Ð¾Ñ ÑоваÑа по новой Ñене: ${Me?.name||f}. УÑÑановиÑе ÑÑаÑÑÑ "ÐÑмена" и веÑниÑе денÑги. Ðаказ: ${ue}`,date:new Date().toISOString(),is_read:!1,link:x.id}),m({...x,items:at})}catch(ue){be(Me=>({...Me,[f]:ue.message||i("common_error_prefix")}))}finally{T(ue=>{const Me={...ue};return delete Me[f],Me})}}},Ft=os.filter(f=>$==="ALL"?!0:$==="PROCESSING"?!f.status||f.status==="PROCESSING":$==="OUT_OF_STOCK"?f.status==="OUT_OF_STOCK"||f.status==="CANCELED":$==="PURCHASED"?f.status==="ON_WAY":$==="WAREHOUSE"?["RECEIVED","PARTIALLY_RECEIVED","PROBLEM","ASSEMBLED"].includes(f.status||""):!0).filter(f=>me==="ALL"||Xe(f)===me),Es=a.useMemo(()=>{const f={};return Ft.forEach(ae=>{const ue=ae.shopName&&ae.shopName.trim()!==""?ae.shopName:i("order_details_no_shop");f[ue]||(f[ue]=[]),f[ue].push(ae)}),f},[Ft]),Zt={ALL:os.length,PROCESSING:os.filter(f=>!f.status||f.status==="PROCESSING").length,OUT_OF_STOCK:os.filter(f=>f.status==="OUT_OF_STOCK"||f.status==="CANCELED").length,PURCHASED:os.filter(f=>f.status==="ON_WAY").length,WAREHOUSE:os.filter(f=>["RECEIVED","PARTIALLY_RECEIVED","PROBLEM","ASSEMBLED"].includes(f.status||"")).length},Ht=f=>Kn(f,i),kr=()=>{const f=x.createdAt||x.created_at;if(!f)return i("order_details_unknown");const ae=new Date(f);return isNaN(ae.getTime())?i("order_details_invalid_date"):ae.toLocaleDateString()},pr=async()=>{if(!x)return;const f=S.trim().slice(0,40);C(f),U(!0),await Je("orders",{id:x.id},{client_label:f}),U(!1),b?.(x.id,f)},Rr=async(f,ae)=>{const ue=x.items.map(Me=>{if(Me.id!==f)return Me;const Fe={...Me,clientDecision:ae};return ae==="KEEP"&&(Fe.status="RECEIVED"),Fe});m({...x,items:ue})},[xs,fr]=a.useState(null),Cs=async(f,ae)=>{if(!xs){fr(f);try{const ue=x.display_id||x.displayId||x.id,Me=x.items.find(vt=>vt.id===f),Fe=ae==="CANCELED"?"CANCELED":"DELAYED",ot=x.items.map(vt=>vt.id!==f?vt:{...vt,delay_decision:ae,status:Fe}),{error:at}=await Je("orders",{id:x.id},{items:ot});if(at)throw new Error(at);await st("notifications",{type:"SYSTEM",title:ae==="CONFIRMED"?`ÐÐ»Ð¸ÐµÐ½Ñ ÑоглаÑен ждаÑÑ â ${ue}`:`ÐÐ»Ð¸ÐµÐ½Ñ Ð¾ÑменÑÐµÑ ÑÐ¾Ð²Ð°Ñ â ${ue}`,text:ae==="CONFIRMED"?`ÐÐ»Ð¸ÐµÐ½Ñ ÑоглаÑен ждаÑÑ Ð·Ð°Ð´ÐµÑжаннÑй ÑоваÑ: ${Me?.name||f}. Ðаказ: ${ue}`:`ÐÐ»Ð¸ÐµÐ½Ñ Ñ
оÑÐµÑ Ð¾ÑмениÑÑ Ð·Ð°Ð´ÐµÑжаннÑй ÑоваÑ: ${Me?.name||f}. Ðаказ: ${ue}`,date:new Date().toISOString(),is_read:!1,link:x.id}),m({...x,items:ot})}catch(ue){alert(i("common_error_prefix")+ue.message)}finally{fr(null)}}},[hr,Tr]=a.useState({}
57),[qs,Ms]=a.useState(null),[zs,ps]=a.useState({}),[Ws,br]=a.useState({}),[ks,nr]=a.useState(null),gr=a.useRef(null),_r=f=>{const ae=f.target.files?.[0];f.target.value="",!(!ae||!ks)&&(ps(ue=>({...ue,[ks]:ae})),br(ue=>({...ue,[ks]:URL.createObjectURL(ae)})))},ar=f=>{br(ae=>{ae[f]&&URL.revokeObjectURL(ae[f]);const ue={...ae};return delete ue[f],ue}),ps(ae=>{const ue={...ae};return delete ue[f],ue})},Dr=async f=>{const ae=(hr[f]||"").trim(),ue=zs[f];if(!(!ae&&!ue||qs)){Ms(f);try{const Me=x.items.find(pt=>pt.id===f);if(!Me)return;const Fe=ae?await ki(ae,"zh"):"";let ot;if(ue){const pt=await Er(ue,1600,.88),$t=pt.name.split(".").pop()||"jpg",Bt=`vendor-questions/${Date.now()}_${Math.random().toString(36).slice(2)}.${$t}`,{publicUrl:ns,error:vs}=await Ln("chat-files",Bt,pt);vs||(ot=ns)}const at=new Date().toISOString(),vt={from:"CLIENT",textRu:ae,textZh:Fe||void 0,at,imageUrl:ot},es=[...pl(Me),vt],wt={...Me,vendorQuestionThread:es,vendorAnswerRu:ae,vendorAnswerZh:Fe||void 0,vendorQuestionStatus:"ANSWERED",vendorAnswerAt:at},et=x.items.map(pt=>pt.id===f?wt:pt),{error:kt}=await ll(x.id,[wt]);if(kt)throw new Error(kt);if(Me.vendorQuestionAskedBy){const pt=x.display_id||x.displayId||x.id;await st("notifications",{user_id:Me.vendorQuestionAskedBy,type:"ORDER",title:`ÐÐ»Ð¸ÐµÐ½Ñ Ð¾ÑвеÑил â заказ ${pt}`,text:Fe||ae||"ÐÐ»Ð¸ÐµÐ½Ñ Ð¿ÑиÑлал ÑоÑо по ÑоваÑÑ",date:at,is_read:!1,link:x.id})}ar(f),m({...x,items:et}),Tr(pt=>{const $t={...pt};return delete $t[f],$t})}catch(Me){alert(i("common_error_prefix")+Me.message)}finally{Ms(null)}}},lr=async(f,ae)=>{const{data:ue}=await Re("orders",{id:x.id},{select:"*",single:!0});ue&&m(ue)},g=async(f,ae)=>{const{data:ue}=await Re("orders",{id:x.id},{select:"*",single:!0});ue&&m(ue)},Q=async(f,ae)=>{if(x?.id&&window.confirm(i("order_details_confirm_remove_shop",{shop:f,count:ae.length}))){re(f);try{if(await Fr(x.id)){alert(i("order_details_cannot_edit_reserved"));return}const{data:ue,error:Me}=await Re("orders",{id:x.id},{select:"items,commission_cny",single:!0});if(Me)throw new Error(Me);const Fe=ue.items,ot=Fe.filter(Bt=>!ae.includes(Bt.id));if(ot.length===0){alert(i("order_details_cannot_remove_last_shop"));return}const at=Fe.reduce((Bt,ns)=>Bt+(Number(ns.priceCNY)||0)*(Number(ns.quantity)||0),0),vt=ot.reduce((Bt,ns)=>Bt+(Number(ns.priceCNY)||0)*(Number(ns.quantity)||0),0),es=ot.reduce((Bt,ns)=>Bt+(Number(ns.chinaDelivery)||0),0),wt=vt+es,et=Number(ue.commission_cny)||0,kt=at>0&&et>0?parseFloat((et/at*vt).toFixed(4)):et,{error:pt}=await Je("orders",{id:x.id},{items:ot,total_cny:wt,commission_cny:kt,items_count:ot.length});if(pt)throw new Error(pt);const{data:$t}=await Re("orders",{id:x.id},{select:"*",single:!0});$t&&m($t)}catch(ue){alert(i("common_delete_error_prefix")+ue.message)}finally{re(null)}}},ne=()=>{x&&(m({...x,status:"PAID"}),d?.())},{isBalanceSettled:De,totalProjectedRefund:Ee,refundsFromItemsRUB:Pe,deliveryProfitRUB:nt,priceDeltaRUB:ft,canceledCount:It,pendingDifference:Vt}=_e,fs=Ee!==0||Pe>0||nt!==0||(ft??0)!==0;return e.jsxs("div",{className:"w-full max-w-full px-4 mx-auto space-y-6 pb-20 animate-in fade-in slide-in-from-right-4 duration-300",children:[Ue&&e.jsxs("div",{className:"fixed inset-0 z-[100] bg-black/90 flex items-center justify-center p-4 backdrop-blur-sm animate-in fade-in duration-200",onClick:()=>$e(null),children:[e.jsx("button",{className:"absolute top-6 right-6 text-white/70 hover:text-white transition-colors",onClick:()=>$e(null),children:e.jsx(bt,{size:32})}),Ue.gallery.length>1&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:f=>{f.stopPropagation(),Qe()},className:"absolute left-3 sm:left-6 top-1/2 -translate-y-1/2 p-2 sm:p-3 bg-white/10 hover:bg-white/20 text-white rounded-full transition-colors",children:e.jsx(Mn,{size:28})}),e.jsx("button",{onClick:f=>{f.stopPropagation(),k()},className:"absolute right-3 sm:right-6 top-1/2 -translate-y-1/2 p-2 sm:p-3 bg-white/10 hover:bg-white/20 text-white rounded-full transition-colors",children:e.jsx(Sr,{size:28})}),e.jsxs("div",{className:"absolute bottom-6 left-1/2 -translate-x-1/2 text-white/80 text-sm font-bold bg-black/40 px-3 py-1 rounded-full",children:[le+1," / ",Ue.gallery.length]})]}),e.jsx("img",{src:Ue.url,alt:"Full size",className:"max-w-full max-h-[90vh] object-contain rounded-lg shadow-2xl",onClick:f=>f.stopPropagation()})]}),xe&&x&&e.jsx(nl,{onClose:()=>de(!1),initialAmount:_e.totalRUB_Base,totalCNY:_e.totalCNY_Client,orderUUID:x.id,displayId:x.display_id||x.displayId||"",onPaymentSuccess:ne}),e.jsxs("div",{className:"flex items-center gap-4 mb-2 sm:mb-4 flex-wrap",children:[e.jsxs("button",{onClick:s,className:"flex items-center gap-2 px-4 py-2 bg-white border border-slate-200 rounded-xl text-slate-600 font-bold hover:bg-slate-50 hover:text-blue-600 transition-colors shadow-sm shrink-0",children:[e.jsx(Ba,{size:18})," ",i("order_details_back")]}),e.jsx("span",{className:"font-bold text-slate-500 text-sm shrink-0",children:x.display_id||x.displayId||x.id}),e.jsxs("div",{className:"hidden sm:flex items-center gap-1.5 min-w-0 flex-1",children:[e.jsx("input",{type:"text",value:S,onChange:f=>C(f.target.value),onBlur:pr,onKeyDown:f=>{f.key==="Enter"&&f.target.blur()},maxLength:40,placeholder:i("order_details_add_label"),className:`text-sm font-semibold rounded-lg px-2.5 py-1 outline-none border transition-all min-w-0
57w-full max-w-[220px] ${S?"bg-blue-50 border-blue-200 text-blue-800 placeholder-blue-300":"bg-sky-50 border-sky-200 text-sky-600 placeholder-sky-400 hover:border-sky-300"} focus:border-blue-400 focus:bg-white`}),L?e.jsx(rt,{size:12,className:"text-slate-400 animate-spin shrink-0"}):e.jsx(tn,{size:12,className:"text-sky-400 shrink-0"})]})]}),e.jsxs("div",{className:"flex sm:hidden items-center gap-1.5 mb-4",children:[e.jsx("input",{type:"text",value:S,onChange:f=>C(f.target.value),onBlur:pr,onKeyDown:f=>{f.key==="Enter"&&f.target.blur()},maxLength:40,placeholder:i("order_details_add_label"),className:`text-sm font-semibold rounded-lg px-2.5 py-2 outline-none border transition-all w-full ${S?"bg-blue-50 border-blue-200 text-blue-800 placeholder-blue-300":"bg-sky-50 border-sky-200 text-sky-600 placeholder-sky-400 hover:border-sky-300"} focus:border-blue-400 focus:bg-white`}),L?e.jsx(rt,{size:14,className:"text-slate-400 animate-spin shrink-0"}):e.jsx(tn,{size:14,className:"text-sky-400 shrink-0"})]}),x.photo_report_sent&&!x.client_confirmed&&e.jsxs("div",{className:"bg-orange-50 border-2 border-orange-300 rounded-2xl p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-12 h-12 bg-orange-100 rounded-full flex items-center justify-center shrink-0",children:e.jsx(Yr,{size:22,className:"text-orange-600"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-bold text-orange-900 text-base",children:i("order_details_photo_report_title")}),e.jsx("div",{className:"text-sm text-orange-700",children:i("order_details_photo_report_body")})]})]}),x.general_photo_url&&e.jsx("div",{className:"flex flex-col sm:flex-row gap-3",children:e.jsx("img",{src:x.general_photo_url,alt:i("order_details_order_photo_alt"),className:"max-h-64 rounded-xl object-cover border border-orange-200 cursor-pointer hover:opacity-90 transition-opacity",onClick:()=>H(x.general_photo_url)})}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[e.jsxs("button",{onClick:w,disabled:Ut,className:"flex-1 flex items-center justify-center gap-2 py-3 bg-green-600 hover:bg-green-700 text-white rounded-xl font-bold transition-colors shadow-sm disabled:opacity-60",children:[Ut?e.jsx(rt,{size:18,className:"animate-spin"}):e.jsx(as,{size:18}),i("order_details_confirm_photo_button")]}),e.jsx("button",{onClick:()=>{j?.(),s()},className:"sm:w-auto py-3 px-5 border-2 border-slate-200 bg-white hover:bg-slate-50 text-slate-700 rounded-xl font-bold transition-colors",children:i("order_details_write_manager")})]})]}),x.photo_report_sent&&x.client_confirmed&&e.jsxs("div",{className:"bg-green-50 border border-green-200 rounded-2xl p-4 flex items-center gap-3",children:[e.jsx(as,{size:20,className:"text-green-600 shrink-0"}),e.jsx("div",{className:"text-sm font-bold text-green-800",children:i("order_details_photo_confirmed")})]}),Tt&&e.jsxs("div",{className:"bg-amber-50 border-2 border-amber-200 rounded-2xl p-5 flex flex-col sm:flex-row items-start sm:items-center gap-4",children:[e.jsx("div",{className:"w-12 h-12 bg-amber-100 rounded-full flex items-center justify-center shrink-0",children:e.jsx(Lt,{size:22,className:"text-amber-600"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"font-bold text-amber-900",children:i("order_details_partial_ship_banner",{received:je.length,total:x.items.length})}),e.jsx("div",{className:"text-sm text-amber-700 mt-0.5",children:i("order_details_partial_ship_body")})]}),e.jsx("button",{onClick:()=>{x.shipment_group_id?Ge(!0):gt(!0)},className:"shrink-0 px-5 py-2.5 bg-amber-500 hover:bg-amber-600 text-white rounded-xl font-bold transition-colors shadow-sm text-sm",children:i("order_details_ship_received_button")})]}),x.partial_ship_requested&&e.jsxs("div",{className:"bg-blue-50 border border-blue-200 rounded-2xl p-4 flex items-center gap-3",children:[e.jsx(Lt,{size:20,className:"text-blue-600 shrink-0"}),e.jsx("div",{className:"text-sm font-bold text-blue-800",children:i("order_details_partial_ship_requested")})]}),it&&e.jsx("div",{className:"fixed inset-0 z-[200] flex items-center justify-center bg-black/60 p-4",children:e.jsxs("div",{className:"bg-white rounded-2xl shadow-2xl max-w-md w-full",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 pb-4",children:[e.jsx("h3",{className:"font-black text-slate-900 text-lg",children:i("order_details_group_conflict_title")}),e.jsx("button",{onClick:()=>Ge(!1),className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors",children:e.jsx(bt,{size:20,className:"text-slate-500"})})]}),e.jsx("div",{className:"px-6 pb-2 text-sm text-slate-600",children:i("order_details_group_conflict_body")}),e.jsxs("div",{className:"flex gap-3 p-6 pt-5",children:[e.jsxs("button",{onClick:fe,disabled:St,className:"flex-1 flex items-center justify-center gap-2 py-3 bg-amber-500 hover:bg-amber-600 disabled:opacity-50 text-white rounded-xl font-bold transition-colors",children:[St?e.jsx(rt,{size:18,className:"animate-spin"}):e.jsx(Lt,{size:18}),i("order_details_ungroup_and_ship")]}),e.jsx("button",{onClick:()=>Ge(!1),className:"px-5 py-3 border-2 border-slate-200 bg-white hover:bg-slate-50 text-slate-700 rounded-xl font-bold transition-colors",children:i("orders_cancel_button")})]})]})}),dt&&e.jsx("div",{className:"fixed inset-0 z-[200] flex items-center justify-center bg-black/60 p-4",children:e.jsxs("div",{className:"bg-white rounded-2xl shadow-2xl max-w-md w-full max-h-[85vh] flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 pb-4 shrink-0",children:[e.jsx("h3",{className:"font-black text-slate-900 text-lg",children:i("order_details_ship_received_question")}),e.jsx("button",{onClick:()=>gt(!1),className:"p-1.5 hover:bg-slate-100 rounded-lg transition-colors",children:e.jsx(bt,{size:20,className:"text-slate-500"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-6 space-y-5",children:[je.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-bold text-green-700 uppercase tracking-wider mb-2",children:i("order_details_will_be_shipped",{count:je.length})}),e.jsx("div",{className:"space-y-1.5",children:je.map(f=>e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("div",{className:"w-2 h-2 bg-green-500 rounded-full shrink-0"}),e.jsx("span",{className:"text-slate-700",children:f.name})]},f.id))})]}),ze.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-bold text-slate-400 uppercase tracking-wider mb-2",children:i("order_details_will_remain_waiting",{count:ze.length})}),e.jsx("div",{className:"space-y-1.5",children:ze.map(f=>e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("div",{className:"w-2 h-2 bg-slate-300 rounded-full shrink-0"}),e.jsx("span",{className:"text-slate-500",children:f.name})]},f.id))}),e.jsx("div",{className:"mt-2 text-xs text-slate-400 bg-slate-50 rounded-lg p-2.5",children:i("order_details_waiting_items_note")})]})]}),e.jsxs("div",{className:"flex gap-3 p-6 pt-4 border-t border-slate-100 shrink-0",children:[e.jsxs("button",{onClick:pe,disabled:ht,className:"flex-1 flex items-center justify-center gap-2 py-3 bg-amber-500 hover:bg-amber-600 disabled:opacity-50 text-white rounded-xl font-bold transition-colors",children:[ht?e.jsx(rt,{size:18,className:"animate-spin"}):e.jsx(Lt,{size:18}),i("orders_confirm_button")]}),e.jsx("button",{onClick:()=>gt(!1),className:"px-5 py-3 border-2 border-slate-200 bg-white hover:bg-slate-50 text-slate-700 rounded-xl font-bold transition-colors",children:i("orders_cancel_button")})]})]})}),e.jsxs("div",{className:"bg-white rounded-2xl shadow-sm border border-slate-200 overflow-hidden flex flex-col min-h-[600px]",children:[e.jsxs("div",{className:"px-6 py-6 border-b border-slate-100 flex justify-between items-center bg-slate-50/50",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsx("h2",{className:"text-lg md:text-3xl font-black text-slate-900 tracking-tight",children:i("order_details_order_number",{id:x.display_id||x.displayId||x.id.slice(0,8)})}),e.jsx("span",{className:`px-3 py-1 rounded-full text-xs md:text-sm font-bold border uppercase tracking-wide ${x.status==="PAID"?"bg-red-100 text-red-700 border-red-200":"bg-slate-200 text-slate-600"}`,children:Ht(x.status)})]}),e.jsxs("p",{className:"text-xs md:text-sm text-slate-500 mt-1 font-medium",children:[i("order_details_created_date"),": ",kr()]})]}),x.status==="RECEIVED"&&e.jsx("button",{onClick:()=>R(!0),title:i("order_print_title"),className:"inline-flex items-center justify-center w-9 h-9 rounded-lg bg-blue-600 text-white hover:bg-blue-700 shadow-sm shadow-blue-200 transition-colors shrink-0",children:e.jsx(Ya,{size:16})})]}),e.jsxs("div",{className:"flex flex-col xl:flex-row flex-1",children:[e.jsx("div",{className:"flex-1 p-0 xl:p-6 overflow-x-auto",children:e.jsxs("div",{className:"bg-white xl:rounded-xl xl:border border-slate-200 overflow-hidden flex flex-col",children:[Xt.length>0&&e.jsxs("div",{className:"border-b border-orange-200 bg-orange-50/70",children:[e.jsxs("button",{onClick:()=>Se(f=>!f),className:"w-full px-6 py-4 flex items-center justify-between gap-2 hover:bg-orange-100/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ro,{size:18,className:"text-orange-600 shrink-0"}),e.jsxs("h3",{className:"font-bold text-orange-900 text-base text-left",children:[Xt.length===1?i("order_details_price_up_one"):i("order_details_price_up_many",{count:Xt.length}),Mt&&e.jsx("span",{className:"ml-2 text-xs font-semibold text-green-700 bg-green-100 px-2 py-0.5 rounded-full",children:i("order_details_all_resolved")})]})]}),Y?e.jsx(qr,{size:18,className:"text-orange-600 shrink-0"}):e.jsx(er,{size:18,className:"text-orange-600 shrink-0"})]}),Y&&e.jsx("div",{className:"px-6 pb-5 space-y-3",children:Xt.map(f=>{const ae=!f.price_confirm_decision||f.price_confirm_decision==="PENDING",ue=f.price_confirm_decision==="APPROVED",Me=f.price_confirm_decision==="REJECTED",Fe=f.originalPriceCNY!==void 0?f.priceCNY-f.originalPriceCNY:0,ot=!!ve[f.id],at=ke[f.id];return e.jsxs("div",{className:"bg-white rounded-xl border border-orange-200 p-4 flex flex-col gap-2",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[f.image&&e.jsx("img",{src:f.image,alt:"",referrerPolicy:"no-referrer",className:"w-12 h-12 object-cover rounded-lg shrink-0 border border-slate-100"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-bold text-slate-800 truncate",children:f.name}),f.originalPriceCNY!==void 0&&e.jsxs("p",{className:"text-xs text-orange-700 mt-0.5 font-medium",children:["Â¥",f.originalPriceCNY.toFixed(2)," â Â¥",f.priceCNY.toFixed(2),e.jsxs("span",{className:"ml-1 text-red-600 font-bold",children:["+Â¥",Fe.toFixed(2)]}),f.quantity>1&&e.jsxs("span",{className:"text-slate-400 ml-1",children:["à ",f.quantity," ",i("orders_unit_pcs")]})]})]})]}),ae&&e.jsxs("div",{className:"flex gap-2 shrink-0",children:[e.jsxs("button",{onClick:()=>Ls(f.id,"APPROVED"),disabled:ot,className:"flex items-center gap-1.5 px-4 py-2 bg-green-600 hover:bg-green-700 disabled:opacity-60 disabled:cursor-not-allowed text-white text-sm font-bold rounded-xl transition-colors",children:[ot?e.jsx(rt,{size:15,className:"animate-spin"}):e.jsx(ss,{size:15})," ",i("order_details_buy_button")]}),e.jsxs("button",{onClick:()=>Ls(f.id,"REJECTED"),disabled:ot,className:"flex items-center gap-1.5 px-4 py-2 bg-red-100 hover:bg-red-200 disabled:opacity-60 disabled:cursor-not-allowed text-red-700 text-sm font-bold rounded-xl border border-red-200 transition-colors",children:[e.jsx(bt,{size:15})," ",i("order_details_dont_buy_button")]})]}),ue&&e.jsxs("div",{className:"flex items-center gap-2 shrink-0 px-3 py-2 bg-green-50 border border-green-200 rounded-xl",children:[e.jsx(ss,{size:15,className:"text-green-600"}),e.jsx("span",{className:"text-sm font-bold text-green-700",children:i("order_details_you_agreed")})]}),Me&&(f.status==="CANCELED"?e.jsxs("div",{className:"flex items-center gap-2 shrink-0 px-3 py-2 bg-green-50 border border-green-200 rounded-xl",children:[e.jsx(ss,{size:15,className:"text-green-600"}),e.jsx("span",{className:"text-sm font-bold text-green-700",children:i("order_details_refund_done")})]}):e.jsxs("div",{className:"flex items-center gap-2 shrink-0 px-3 py-2 bg-slate-100 border border-slate-200 rounded-xl",children:[e.jsx(hs,{size:15,className:"text-slate-500"}),e.jsx("span",{className:"text-sm font-bold text-slate-600",children:i("order_details_cancel_processing")})]}))]}),at&&e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-2 bg-red-50 border border-red-200 rounded-lg text-xs font-semibold text-red-600",children:[e.jsx(Fs,{size:13,className:"shrink-0"}),i("common_error_prefix"),at," â ",i("order_details_price_confirm_retry")]})]},f.id)})})]}),Wt.length>0&&e.jsxs("div",{className:"px-6 py-5 border-b border-amber-200 bg-amber-50/70",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(rs,{size:18,className:"text-amber-600"}),e.jsx("h3",{className:"font-bold text-amber-900 text-base",children:Wt.length===1?i("order_details_delayed_one"):i("order_details_delayed_many",{count:Wt.length})})]}),e.jsx("div",{className:"space-y-3",children:Wt.map(f=>{const ae=!f.delay_decision||f.delay_decision==="PENDING",ue=f.delay_decision==="CONFIRMED",Me=f.delay_decision==="CANCELED";return e.jsxs("div",{className:"bg-white rounded-xl border border-amber-200 p-4 flex flex-col sm:flex-row sm:items-center gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[f.image&&e.jsx("img",{src:f.image,alt:"",referrerPolicy:"no-referrer",className:"w-12 h-12 object-cover rounded-lg shrink-0 border border-slate-100"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-bold text-slate-800 truncate",children:f.name}),f.expectedArrivalDate&&(()=>{const Fe=new Date(f.expectedArrivalDate).toLocaleDateString("ru-RU",{day:"numeric",month:"long"}),at=(f.expectedWarehouseDate?new Date(f.expectedWarehouseDate):new Date(new Date(f.expectedArrivalDate).getTime()+6*864e5)).toLocaleDateString("ru-RU",{day:"numeric",month:"long"});return e.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5 flex-wrap",children:[e.jsxs("p",{className:"text-xs text-amber-700",children:[i("order_details_dis
57patch_label"),": ",e.jsx("strong",{children:Fe})," · ",i("order_details_warehouse_approx")," ~",at]}),e.jsx("button",{onClick:()=>E({dispatchDate:Fe,arrivalDate:at}),className:"w-4 h-4 rounded-full bg-orange-500 text-white flex items-center justify-center hover:bg-orange-600 transition-colors shrink-0",title:i("order_details_more_about_dates"),children:e.jsx("span",{className:"text-[9px] font-black leading-none",children:"!"})})]})})()]})]}),ae&&e.jsxs("div",{className:"flex gap-2 shrink-0",children:[e.jsxs("button",{onClick:()=>Cs(f.id,"CONFIRMED"),disabled:xs===f.id,className:"flex items-center gap-1.5 px-4 py-2 bg-green-600 hover:bg-green-700 disabled:opacity-60 text-white text-sm font-bold rounded-xl transition-colors",children:[e.jsx(ss,{size:15})," ",i("order_details_wait_button")]}),e.jsxs("button",{onClick:()=>Cs(f.id,"CANCELED"),disabled:xs===f.id,className:"flex items-center gap-1.5 px-4 py-2 bg-red-100 hover:bg-red-200 disabled:opacity-60 text-red-700 text-sm font-bold rounded-xl border border-red-200 transition-colors",children:[e.jsx(bt,{size:15})," ",i("order_details_cancel_item_button")]})]}),ue&&e.jsxs("div",{className:"flex items-center gap-2 shrink-0 px-3 py-2 bg-green-50 border border-green-200 rounded-xl",children:[e.jsx(ss,{size:15,className:"text-green-600"}),e.jsx("span",{className:"text-sm font-bold text-green-700",children:i("order_details_you_are_waiting")})]}),Me&&e.jsxs("div",{className:"flex items-center gap-2 shrink-0 px-3 py-2 bg-slate-100 border border-slate-200 rounded-xl",children:[e.jsx(hs,{size:15,className:"text-slate-500"}),e.jsx("span",{className:"text-sm font-bold text-slate-600",children:i("order_details_cancel_processing")})]})]},f.id)})})]}),cs.length>0&&e.jsxs("div",{className:"px-6 py-5 border-b border-purple-200 bg-purple-50/70",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(zr,{size:18,className:"text-purple-600"}),e.jsx("h3",{className:"font-bold text-purple-900 text-base",children:cs.length===1?i("order_details_vendor_q_one"):i("order_details_vendor_q_many",{count:cs.length})})]}),e.jsx("div",{className:"space-y-3",children:cs.map(f=>{const ae=f.vendorQuestionStatus==="PENDING",ue=f.vendorQuestionStatus==="ESCALATED",Me=pl(f);return e.jsxs("div",{className:"bg-white rounded-xl border border-purple-200 p-4 flex flex-col gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[f.image&&e.jsx("img",{src:f.image,alt:"",referrerPolicy:"no-referrer",className:"w-12 h-12 object-cover rounded-lg shrink-0 border border-slate-100"}),e.jsx("p",{className:"text-sm font-bold text-slate-800 truncate flex-1 min-w-0",children:f.name})]}),e.jsx("div",{className:"space-y-1.5",children:Me.map((Fe,ot)=>e.jsx("div",{className:`flex ${Fe.from==="OPERATOR"?"justify-start":"justify-end"}`,children:e.jsxs("div",{className:`max-w-[85%] rounded-xl overflow-hidden ${Fe.from==="OPERATOR"?"bg-purple-100":"bg-slate-700"}`,children:[Fe.imageUrl&&e.jsx("img",{src:Fe.imageUrl,alt:"",referrerPolicy:"no-referrer",onClick:()=>H(Fe.imageUrl,Me.map(at=>at.imageUrl).filter(at=>!!at)),className:"w-full max-h-56 object-cover cursor-pointer"}),Fe.textRu&&e.jsx("p",{className:`text-sm px-3 py-1.5 ${Fe.from==="OPERATOR"?"text-purple-900":"text-white"}`,children:Fe.textRu})]})},ot))}),ae?e.jsxs("div",{className:"space-y-2",children:[Ws[f.id]&&e.jsxs("div",{className:"relative inline-block",children:[e.jsx("img",{src:Ws[f.id],alt:"",className:"w-16 h-16 object-cover rounded-lg border border-purple-200"}),e.jsx("button",{onClick:()=>ar(f.id),className:"absolute -top-1.5 -right-1.5 bg-white rounded-full text-slate-400 hover:text-red-500 shadow border border-slate-200",children:e.jsx(Gr,{size:16})})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:hr[f.id]||"",onChange:Fe=>Tr(ot=>({...ot,[f.id]:Fe.target.value})),onKeyDown:Fe=>{Fe.key==="Enter"&&Dr(f.id)},placeholder:i("order_details_your_answer_placeholder"),className:"flex-1 px-3 py-2 text-sm border border-purple-200 rounded-xl outline-none focus:border-purple-400"}),e.jsx("button",{onClick:()=>{nr(f.id),gr.current?.click()},title:i("order_details_attach_photo"),className:"px-3 py-2 bg-white border border-purple-200 text-purple-600 hover:bg-purple-50 rounded-xl transition-colors",children:e.jsx(mn,{size:16})}),e.jsx("button",{onClick:()=>Dr(f.id),disabled:qs===f.id||!(hr[f.id]||"").trim()&&!zs[f.id],className:"px-4 py-2 bg-purple-600 hover:bg-purple-700 disabled:opacity-60 text-white text-sm font-bold rounded-xl transition-colors",children:qs===f.id?"...":i("order_details_reply_button")})]})]}):ue?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-slate-100 border border-slate-200 rounded-xl",children:[e.jsx(zr,{size:15,className:"text-slate-500 shrink-0"}),e.jsx("span",{className:"text-sm text-slate-600",children:i("order_details_escalated_note")})]}):e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-amber-50 border border-amber-200 rounded-xl",children:[e.jsx(rs,{size:15,className:"text-amber-600 shrink-0"}),e.jsx("span",{className:"text-sm text-amber-800",children:i("order_details_waiting_manager_reply")})]})]},f.id)})}),e.jsx("input",{ref:gr,type:"file",accept:"image/*",onChange:_r,className:"hidden"})]}),e.jsxs("div",{className:"px-6 py-4 bg-slate-50 border-b border-slate-200 flex flex-col gap-2 sticky top-0 z-20",children:[e.jsxs("div",{className:"md:hidden grid grid-cols-2 gap-2",children:[e.jsxs("button",{onClick:()=>{z("ALL"),Oe(!1),J(!1)},className:`py-2.5 px-3 rounded-xl text-sm font-bold transition-all border ${$==="ALL"&&!Ie?"bg-slate-800 text-white border-slate-800":"bg-white text-slate-600 border-slate-200"}`,children:[i("orders_tab_all")," (",Zt.ALL,")"]}),e.jsxs("button",{onClick:()=>{z("PROCESSING"),Oe(!1),J(!1)},className:`py-2.5 px-3 rounded-xl text-sm font-bold transition-all border ${$==="PROCESSING"&&!Ie?"bg-blue-600 text-white border-blue-600":"bg-white text-slate-600 border-slate-200"}`,children:[i("order_details_filter_processing")," (",Zt.PROCESSING,")"]}),e.jsxs("button",{onClick:()=>{z("OUT_OF_STOCK"),Oe(!1),J(!1)},className:`py-2.5 px-3 rounded-xl text-sm font-bold transition-all border ${$==="OUT_OF_STOCK"&&!Ie?"bg-red-500 text-white border-red-500":"bg-white text-slate-600 border-slate-200"}`,children:[i("order_details_filter_refund")," (",Zt.OUT_OF_STOCK,")"]}),e.jsxs("button",{onClick:()=>{z("PURCHASED"),Oe(!1),J(!1)},className:`py-2.5 px-3 rounded-xl text-sm font-bold transition-all border ${$==="PURCHASED"&&!Ie?"bg-green-600 text-white border-green-600":"bg-white text-slate-600 border-slate-200"}`,children:[i("order_details_filter_purchased")," (",Zt.PURCHASED,")"]}),e.jsxs("button",{onClick:()=>{z("WAREHOUSE"),Oe(!1),J(!1)},className:`py-2.5 px-3 rounded-xl text-sm font-bold transition-all border flex items-center justify-center gap-1.5 ${$==="WAREHOUSE"&&!Ie?"bg-green-600 text-white border-green-600":"bg-white text-slate-600 border-slate-200"}`,children:[e.jsx(xn,{size:15})," ",i("order_details_filter_warehouse")," (",Zt.WAREHOUSE,")"]}),(["ASSEMBLED","SHIPPED","RECEIVED"].includes(x.status)&&(x.shippingBoxes||x.shipping_boxes)||x.shipments?.length>0)&&e.jsxs("button",{onClick:()=>{Oe(!0),z("ALL")},className:`py-2.5 px-3 rounded-xl text-sm font-bold transition-all border flex items-center justify-center gap-1.5 ${Ie?"bg-orange-500 text-white border-orange-500":"bg-white text-orange-600 border-orange-200"}`,children:[e.jsx(js,{size:15})," ",i("order_details_filter_packed")]})]}),e.jsx("div",{className:"hidden md:flex flex-wrap gap-2 items-center",children:e.jsxs("div",{className:"flex bg-slate-200/50 p-1 rounded-lg flex-wrap",children:[e.jsxs("button",{onClick:()=>{z("ALL"),Oe(!1),J(!1)},className:`px-3 py-1.5 rounded text-xs font-bold transition-all ${$==="ALL"&&!Ie?"bg-white text-slate-800 shadow-sm":"text-slate-500 hover:text-slate-700"}`,children:[i("orders_tab_all")," (",Zt.ALL,")"]}),e.jsxs("button",{onClick:()=>{z("PROCESSING"),Oe(!1),J(!1)},className:`px-3 py-1.5 rounded text-xs font-bold transition-all ${$==="PROCESSING"&&!Ie?"bg-white text-blue-600 shadow-sm":"text-slate-500 hover:text-slate-700"}`,children:[i("order_details_filter_unprocessed")," (",Zt.PROCESSING,")"]}),e.jsxs("button",{onClick:()=>{z("OUT_OF_STOCK"),Oe(!1),J(!1)},className:`px-3 py-1.5 rounded text-xs font-bold transition-all ${$==="OUT_OF_STOCK"&&!Ie?"bg-white text-red-600 shadow-sm":"text-slate-500 hover:text-slate-700"}`,children:[i("order_details_filter_refund_no")," (",Zt.OUT_OF_STOCK,")"]}),e.jsxs("button",{onClick:()=>{z("PURCHASED"),Oe(!1),J(!1)},className:`px-3 py-1.5 rounded text-xs font-bold transition-all ${$==="PURCHASED"&&!Ie?"bg-white text-green-600 shadow-sm":"text-slate-500 hover:text-slate-700"}`,children:[i("order_details_filter_purchased")," (",Zt.PURCHASED,")"]}),e.jsxs("button",{onClick:()=>{z("WAREHOUSE"),Oe(!1),J(!1)},className:`px-3 py-1.5 rounded text-xs font-bold transition-all flex items-center gap-1 ${$==="WAREHOUSE"&&!Ie?"bg-green-100 text-green-700 shadow-sm ring-1 ring-green-200":"text-slate-500 hover:text-green-600 hover:bg-green-50"}`,children:[e.jsx(xn,{size:14})," ",i("order_details_filter_warehouse")," (",Zt.WAREHOUSE,")"]}),(["ASSEMBLED","SHIPPED","RECEIVED"].includes(x.status)&&(x.shippingBoxes||x.shipping_boxes)||x.shipments?.length>0)&&e.jsxs("button",{onClick:()=>{Oe(!0),z("ALL")},className:`px-3 py-1.5 rounded text-xs font-bold transition-all flex items-center gap-1 ${Ie?"bg-orange-500 text-white shadow-sm":"bg-orange-100 text-orange-700 hover:bg-orange-200"}`,children:[e.jsx(js,{size:14})," ",i("order_details_filter_packed"),x.shipments?.length>1&&e.jsx("span",{className:"ml-1 bg-white/30 text-inherit rounded-full px-1.5 text-[10px]",children:x.shipments.length})]})]})}),(Ct||Gt||Nt)&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-[10px] font-bold text-slate-400 uppercase tracking-wider",children:[i("order_details_platform_label"),":"]}),e.jsxs("div",{className:"flex bg-slate-200/50 p-1 rounded-lg",children:[e.jsx("button",{onClick:()=>
57K("ALL"),className:`px-2.5 py-1 rounded text-xs font-bold transition-all ${me==="ALL"?"bg-white text-slate-800 shadow-sm":"text-slate-500 hover:text-slate-700"}`,children:i("orders_tab_all")}),Ct&&e.jsx("button",{onClick:()=>K("1688"),className:`px-2.5 py-1 rounded text-xs font-bold transition-all ${me==="1688"?"bg-white text-slate-800 shadow-sm":"text-slate-500 hover:text-slate-700"}`,children:"1688"}),Gt&&e.jsx("button",{onClick:()=>K("Таобао"),className:`px-2.5 py-1 rounded text-xs font-bold transition-all ${me==="Таобао"?"bg-white text-slate-800 shadow-sm":"text-slate-500 hover:text-slate-700"}`,children:"Таобао"}),Nt&&e.jsx("button",{onClick:()=>K("Tmall"),className:`px-2.5 py-1 rounded text-xs font-bold transition-all ${me==="Tmall"?"bg-white text-slate-800 shadow-sm":"text-slate-500 hover:text-slate-700"}`,children:"Tmall"})]})]})]}),Ie?(()=>{const f=x.shippingBoxes||x.shipping_boxes||[],ae=f.reduce((et,kt)=>et+(kt.weight||0),0),ue=f.reduce((et,kt)=>et+(kt.length||0)*(kt.width||0)*(kt.height||0)/1e6,0),Me=x.weightKg??(ae>0?ae:null),Fe=x.volumeM3??(ue>0?ue:null),ot=x.display_id||x.displayId||(x.friendlyId?`CN-${x.friendlyId}`:x.id?.slice(0,8)||""),at=Me!=null&&Fe!=null&&Fe>0?Me/Fe:null,vt=x.delivery_invoice,es=["ASSEMBLED","SHIPPED"].includes(x.status)&&vt?(()=>{const et=x.status==="SHIPPED",kt=vt.date?new Date(vt.date+"T00:00:00").toLocaleDateString("ru-RU",{day:"2-digit",month:"2-digit",year:"numeric"}):"";return e.jsxs("div",{className:"bg-gradient-to-br from-slate-800 to-slate-900 rounded-2xl overflow-hidden shadow-lg",children:[e.jsxs("div",{className:"px-5 py-4 border-b border-white/10 flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-white font-black text-base",children:i(et?"order_details_cargo_shipped":"order_details_invoice_issued")}),kt&&e.jsx("div",{className:"text-slate-400 text-xs mt-0.5",children:kt})]}),e.jsx("div",{className:`rounded-full px-3 py-1 text-[11px] font-bold uppercase tracking-wide flex-shrink-0 ${et?"bg-green-500/20 border border-green-500/40 text-green-400":"bg-orange-500/20 border border-orange-500/40 text-orange-400"}`,children:i(et?"orders_status_shipped":"order_details_filter_packed")})]}),(vt.routeName||vt.typeName)&&e.jsxs("div",{className:"px-5 py-3 border-b border-white/10",children:[e.jsx("div",{className:"text-slate-400 text-[11px] uppercase tracking-wide mb-1",children:i("order_details_issuing_invoice")}),e.jsx("div",{className:"text-white text-sm font-semibold",children:[vt.routeName,vt.typeName].filter(Boolean).join(" · ")})]}),e.jsxs("div",{className:"px-5 py-4 space-y-3",children:[vt.lines?.map((pt,$t)=>{const Bt=pt.unit==="cbm",ns=Bt?(pt.vol||0)*(pt.pricePerCbm||0):pt.weight*pt.pricePerKg;return e.jsxs("div",{className:"bg-white/5 rounded-xl px-4 py-3",children:[e.jsx("div",{className:"text-white font-bold text-sm mb-2",children:pt.category}),e.jsxs("div",{className:"space-y-1 text-xs",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsxs("span",{className:"text-slate-400",children:[i("layout_label_delivery")," (",Bt?`${(pt.vol||0).toFixed(3)} м³ à $${(+pt.pricePerCbm).toFixed(1)}/м³`:`${pt.weight.toFixed(1)} ${i("orders_unit_kg")} à $${(+pt.pricePerKg).toFixed(1)}/${i("orders_unit_kg")}`,")"]}),e.jsxs("span",{className:"text-white font-semibold",children:["$",ns.toFixed(2)]})]}),pt.packagingUSD>0&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-slate-400",children:i("order_details_packaging")}),e.jsxs("span",{className:"text-white font-semibold",children:["$",pt.packagingUSD.toFixed(2)]})]}),pt.loadingUSD>0&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-slate-400",children:i("order_details_cargo_loading")}),e.jsxs("span",{className:"text-white font-semibold",children:["$",pt.loadingUSD.toFixed(2)]})]}),e.jsxs("div",{className:"flex justify-between border-t border-white/10 pt-1 mt-1",children:[e.jsx("span",{className:"text-slate-300 font-semibold",children:i("order_details_category_total")}),e.jsxs("span",{className:"text-emerald-400 font-black",children:["$",pt.subtotalUSD.toFixed(2)]})]})]})]},$t)}),vt.insuranceUSD>0&&e.jsxs("div",{className:"bg-white/5 rounded-xl px-4 py-3 flex justify-between items-center",children:[e.jsx("span",{className:"text-slate-300 text-xs font-semibold",children:i("order_details_cargo_insurance")}),e.jsxs("span",{className:"text-emerald-400 font-black text-sm",children:["$",vt.insuranceUSD.toFixed(2)]})]})]}),e.jsxs("div",{className:"px-5 py-4 bg-white/5 border-t border-white/10 space-y-2",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-slate-300 text-sm",children:i("order_details_total_usd")}),e.jsxs("span",{className:"text-white font-black text-lg",children:["$",vt.totalUSD.toFixed(2)]})]}),vt.usdRate>0&&e.jsxs("div",{className:"flex justify-between items-center text-xs text-slate-400",children:[e.jsxs("span",{children:["à ",Number(r).toFixed(2)," ",i("order_details_current_rate")]}),e.jsxs("span",{className:"text-slate-200 font-bold text-base",children:[Math.round((vt.totalUSD??0)*r).toLocaleStr
57ing("ru-RU")," â½"]})]})]}),et&&(()=>{const pt=x.delivery_prepaid_amount??0,$t=Math.round((vt.totalUSD??0)*r)-pt;return e.jsxs("div",{className:"px-5 pb-5 pt-3 space-y-2",children:[pt>0&&e.jsxs("div",{className:"flex justify-between text-xs text-slate-400 px-1",children:[e.jsx("span",{children:i("order_details_paid_from_balance")}),e.jsxs("span",{className:"text-emerald-400 font-bold",children:["â",pt.toLocaleString("ru-RU")," â½"]})]}),x.delivery_paid?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"w-full bg-emerald-500 text-white font-black py-3 rounded-xl text-sm tracking-wide flex items-center justify-center gap-2",children:[e.jsx(ss,{size:16})," ",i("orders_badge_delivery_paid")]}),x.status==="RECEIVED"&&e.jsxs("div",{className:"w-full bg-green-100 border border-green-200 text-green-800 font-bold py-2.5 rounded-xl text-sm flex items-center justify-center gap-2",children:[e.jsx(ss,{size:15})," ",i("order_details_order_received_thanks")]})]}):$t<=0?e.jsxs("div",{className:"w-full bg-emerald-500 text-white font-black py-3.5 rounded-xl text-sm tracking-wide flex items-center justify-center gap-2",children:[e.jsx(ss,{size:16})," ",i("orders_badge_delivery_paid")]}):e.jsxs(e.Fragment,{children:[$t<2e4&&e.jsxs("div",{className:"w-full bg-amber-50 border border-amber-200 text-amber-900 text-sm py-3 px-4 rounded-xl leading-relaxed space-y-1",children:[e.jsxs("div",{children:[i("order_details_delivery_sum"),": ",e.jsxs("strong",{className:"text-base",children:["$",Math.round($t/r)]})]}),e.jsx("div",{className:"font-bold text-amber-800",children:i("order_details_pay_moscow_staff")}),e.jsx("div",{className:"text-xs text-amber-700",children:i("order_details_usd_rounded_note",{rate:r.toFixed(2)})})]}),($t>=2e4||o>0)&&e.jsx("button",{onClick:p,className:"w-full bg-orange-500 hover:bg-orange-600 active:bg-orange-700 text-white font-black py-3.5 rounded-xl transition-colors text-sm tracking-wide shadow-lg",children:$t<2e4?i("order_details_use_goods_balance",{balance:o.toLocaleString("ru-RU")}):i("order_details_pay_delivery_amount",{amount:pt>0?` (${$t.toLocaleString("ru-RU")} â½)`:""})}),$t>=2e4&&e.jsx("p",{className:"text-xs text-slate-500 text-center leading-relaxed",children:i("order_details_pay_via_site_note")})]})]})})(),e.jsxs("div",{className:"px-5 pb-5",children:[e.jsxs("button",{onClick:()=>Le(pt=>!pt),className:"w-full flex items-center justify-between bg-orange-50 border border-orange-200 text-orange-800 font-bold text-sm px-4 py-3 rounded-xl transition-colors hover:bg-orange-100",children:[e.jsxs("span",{children:["â ï¸ ",i("order_details_mandatory_on_receipt")]}),e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:`transition-transform ${we?"rotate-180":""}`,children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),we&&e.jsxs("div",{className:"mt-2 bg-orange-50 border border-orange-200 rounded-xl px-4 py-4 space-y-4 text-sm text-orange-900 leading-relaxed",children:[e.jsxs("p",{children:[i("order_details_video_instruction_1_prefix")," ",e.jsx("strong",{children:i("order_details_video_instruction_1_bold")})," ",i("order_details_video_instruction_1_suffix")]}),e.jsxs("p",{children:[i("order_details_video_instruction_2")," ",e.jsx("strong",{children:i("order_details_video_instruction_2_bold")})]}),e.jsx("p",{className:"font-semibold",children:i("order_details_example_recording")}),e.jsxs("div",{className:"rounded-xl overflow-hidden relative",style:{height:260},children:[!_t&&e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center bg-orange-100 gap-3",children:[e.jsx("div",{className:"w-10 h-10 border-4 border-orange-300 border-t-orange-600 rounded-full animate-spin"}),e.jsx("span",{className:"text-orange-700 text-sm font-medium",children:i("order_details_video_loading")})]}),e.jsx("iframe",{src:"https://vk.com/video_ext.php?oid=-126987012&id=456240517&hash=d1ad55a9a4f3b764",width:"100%",height:"260",frameBorder:"0",allowFullScreen:!0,allow:"autoplay; encrypted-media; fullscreen; picture-in-picture",title:i("order_details_receipt_video_title"),onLoad:()=>jt(!0),style:{opacity:_t?1:0}})]}),e.jsxs("p",{className:"text-orange-700",children:[i("order_details_thanks_for_choosing_us")," ð"]})]})]})]})})():null,wt=["ASSEMBLED","SHIPPED"].includes(x.status)&&!x.delivery_invoice?e.jsxs("div",{className:"flex items-start gap-3 bg-emerald-50 border border-emerald-200 rounded-xl px-4 py-3.5",children:[e.jsx("div",{className:"flex-shrink-0 w-8 h-8 rounded-full bg-emerald-100 flex items-center justify-center mt-0.5",children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-emerald-600",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),e.jsx("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]})}),e.jsx("p",{className:"text-sm text-emerald-800 leading-relaxed",children:i("order_details_no_invoice_yet")})]}):null;return e.jsxs("div",{className:"p-6 space-y-6",children:[es,wt,x.tracking?.length>0&&e.jsx(Hx,{tracking:x.tracking}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsxs("div",{className:"bg-orange-50 border border-orange-100 rounded-xl p-4 text-center",children:[e.jsx("div",{className:"text-[10px] font-bold text-orange-400 uppercase mb-1",children:i("order_details_weight")}),e.jsxs("div",{className:"text-lg md:text-2xl font-black text-slate-800",children:[Me!=null?Me.toFixed(1):"â"," ",e.jsx("span",{className:"text-sm text-slate-500",children:i("orders_unit_kg")})]})]}),e.jsxs("div",{className:"bg-orange-50 border border-orange-100 rounded-xl p-4 text-center",children:[e.jsx("div",{className:"text-[10px] font-bold text-orange-400 uppercase mb-1",children:i("order_details_volume")}),e.jsxs("div",{className:"text-lg md:text-2xl font-black text-slate-800",children:[Fe!=null?Fe.toFixed(3):"â"," ",e.jsx("span",{className:"text-sm text-slate-500",children:i("order_details_unit_m3")})]})]}),e.jsxs("div",{className:"bg-orange-50 border border-orange-100 rounded-xl p-4 text-center",children:[e.jsx("div",{className:"text-[10px] font-bold text-orange-400 uppercase mb-1",children:i("order_details_boxes")}),e.jsx("div",{className:"text-lg md:text-2xl font-black text-slate-800",children:f.length})]}),e.jsxs("div",{className:"bg-orange-50 border border-orange-100 rounded-xl p-4 text-center",children:[e.jsx("div",{className:"text-[10px] font-bold text-orange-400 uppercase mb-1",children:i("order_details_density")}),e.jsxs("div",{className:"text-lg md:text-2xl font-black text-slate-800",children:[at!=null?at.toFixed(1):"â"," ",e.jsx("span",{className:"text-sm text-slate-500",children:i("order_details_unit_kg_m3")})]})]})]}),f.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-xs font-bold text-slate-500 uppercase tracking-wider",children:i("order_details_boxes")}),f.map((et,kt)=>{const pt=(et.items||[]).map(X=>{const Te=x.items.find(ce=>ce.id===X.itemId);return Te?{...Te,quantity:X.quantity}:null}
57).filter(Boolean),$t=(et.length||0)*(et.width||0)*(et.height||0)/1e6,Bt=We.find(X=>(X.box_ids||[]).includes(et.id)),ns=Bt&&f.findIndex(X=>(Bt.box_ids||[]).includes(X.id))===kt,vs=Bt?.status==="ARRIVED";return e.jsxs(ct.Fragment,{children:[ns&&e.jsxs("div",{className:`flex items-center gap-3 px-4 py-2.5 rounded-xl border ${vs?"bg-emerald-50 border-emerald-200":"bg-orange-50 border-orange-200"}`,children:[e.jsx(Lt,{size:14,className:vs?"text-emerald-600":"text-orange-500"}),e.jsx("span",{className:`font-bold text-sm ${vs?"text-emerald-700":"text-orange-700"}`,children:Bt.code}),Bt.shipped_at&&e.jsxs("span",{className:"text-[11px] text-slate-400",children:[i("order_details_shipped_label"),": ",new Date(Bt.shipped_at).toLocaleDateString("ru-RU",{day:"numeric",month:"short"})]}),vs&&Bt.arrival_date?e.jsxs("span",{className:"text-[11px] text-emerald-600 font-semibold ml-auto",children:["â ",i("order_details_arrived_label"),": ",new Date(Bt.arrival_date).toLocaleDateString("ru-RU",{day:"numeric",month:"short"})]}):e.jsx("span",{className:"text-[11px] text-slate-400 ml-auto",children:i("order_details_in_transit")})]}),e.jsxs("div",{className:"bg-white border border-slate-200 rounded-xl overflow-hidden",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 px-4 py-3 bg-slate-50 border-b border-slate-100",children:[e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx("div",{className:"w-6 h-6 rounded-full bg-orange-100 flex items-center justify-center text-xs font-black text-orange-600 shrink-0",children:kt+1}),e.jsxs("span",{className:"font-bold text-slate-700 text-sm",children:[ot,"/",kt+1]})]}),et.weight>0&&e.jsxs("span",{className:"text-xs font-semibold text-slate-500 bg-slate-100 px-2 py-0.5 rounded-full",children:[et.weight," ",i("orders_unit_kg")]}),$t>0&&e.jsxs("span",{className:"text-xs font-semibold text-slate-500 bg-slate-100 px-2 py-0.5 rounded-full",children:[$t.toFixed(4)," ",i("order_details_unit_m3")]}),et.weight>0&&$t>0&&e.jsxs("span",{className:"text-xs font-semibold text-orange-500 bg-orange-50 px-2 py-0.5 rounded-full",children:[(et.weight/$t).toFixed(1)," ",i("order_details_unit_kg_m3")]}),et.category&&e.jsx("span",{className:"text-xs font-bold text-blue-600 bg-blue-50 border border-blue-100 px-2 py-0.5 rounded-full sm:ml-auto",children:et.category})]}),e.jsxs("div",{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-4 gap-3 text-sm",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-[10px] text-slate-400 font-bold uppercase mb-0.5",children:i("order_details_weight")}),e.jsxs("div",{className:"font-bold text-slate-800",children:[et.weight," ",i("orders_unit_kg")]})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-[10px] text-slate-400 font-bold uppercase mb-0.5",children:i("order_details_length")}),e.jsxs("div",{className:"font-bold text-slate-800",children:[et.length," ",i("order_details_unit_cm")]})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-[10px] text-slate-400 font-bold uppercase mb-0.5",children:i("order_details_width")}),e.jsxs("div",{className:"font-bold text-slate-800",children:[et.width," ",i("order_details_unit_cm")]})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-[10px] text-slate-400 font-bold uppercase mb-0.5",children:i("order_details_height")}),e.jsxs("div",{className:"font-bold text-slate-800",children:[et.height," ",i("order_details_unit_cm")]})]})]}),pt.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2",children:i("order_details_contents")}),e.jsx("div",{className:"space-y-1.5",children:pt.map((X,Te)=>e.jsxs("div",{className:"flex items-center gap-2 bg-slate-50 rounded-lg px-3 py-2",children:[(X.imageUrl||X.image)&&e.jsx("img",{src:X.imageUrl||X.image,alt:"",className:"w-8 h-8 object-cover rounded flex-shrink-0"}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx("div",{className:"text-xs font-semibold text-slate-700 truncate",children:X.name})}),e.jsxs("div",{className:"text-xs font-bold text-orange-600 shrink-0",children:[X.quantity," ",i("orders_unit_pcs")]})]},Te))})]}
57),(et.photos||[]).length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2",children:i("order_details_cargo_photo")}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:(et.photos||[]).map((X,Te)=>e.jsx("img",{src:X,alt:i("order_details_place_num",{num:kt+1}),className:"w-20 h-20 object-cover rounded-xl border border-slate-200 cursor-pointer hover:opacity-90 hover:scale-105 transition-all shadow-sm",onClick:()=>H(X,et.photos||[])},Te))})]}),kt===f.length-1&&x.video_url&&!F&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx(To,{size:13,className:"text-purple-600 shrink-0"}),e.jsx("span",{className:"text-[10px] font-bold text-slate-400 uppercase",children:i("order_details_cargo_video")}),Z&&e.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-orange-500 bg-orange-50 border border-orange-200 px-1.5 py-0.5 rounded-full",children:[e.jsx(rs,{size:9})," ",i("order_details_hours_short",{h:Z.h})," ",i("order_details_minutes_short",{m:Z.m})]})]}),e.jsx("video",{src:x.video_url,controls:!0,playsInline:!0,className:"w-full max-h-64 rounded-xl border border-purple-200 bg-black"})]})]})]})]},et.id||kt)})]})]})})():e.jsxs(e.Fragment,{children:[x.status==="NEW"&&V&&e.jsxs("div",{className:"mx-6 mb-4 px-4 py-3 rounded-xl bg-amber-50 border border-amber-200 flex items-center gap-2.5 text-sm text-amber-800",children:[e.jsx(ln,{size:16,className:"shrink-0 text-amber-500"}),e.jsx("span",{children:i("order_details_cannot_edit_reserved")})]}),e.jsxs("div",{className:"hidden md:flex text-xs font-bold text-slate-400 uppercase tracking-wider mb-4 px-6 gap-4 sticky top-[70px] z-10 bg-white pb-2 border-b border-transparent",children:[e.jsx("div",{className:"w-24 shrink-0 text-center",children:i("order_details_photo")}),e.jsx("div",{className:"flex-1",children:i("order_details_product")}),e.jsx("div",{className:"w-[240px] text-center",children:i("order_details_calculation")}),e.jsx("div",{className:"w-36 text-center",children:i("orders_col_status")})]}),e.jsx("div",{className:"space-y-3 px-6 pb-6 bg-slate-100 rounded-xl pt-3",children:Object.entries(Es).map(([f,ae])=>{const ue=ae.reduce((wt,et)=>wt+(et.chinaDelivery||0),0),Me=ae.reduce((wt,et)=>wt+(et.chinaDeliveryActual!==void 0?et.chinaDeliveryActual:et.chinaDelivery||0),0),Fe=ue-Me,ot=ae.every(wt=>{const et=(wt.originalItemComment||"").toLowerCase().includes("не пÑиÑел");return wt.originalStatus==="OUT_OF_STOCK"||wt.originalStatus==="CANCELED"||wt.originalStatus==="PROBLEM"&&(wt.clientDecision==="RETURN"||et)}),at=ae.every(wt=>{const et=wt.originalStatus,kt=wt.originalItemComment||"";return et==="OUT_OF_STOCK"||et==="CANCELED"?!0:et==="PROBLEM"?kt.includes(or.REFUND_APPROVED)||kt.includes(or.FULL_REFUND):!0}),vt=ot&&at,es=Me>0?Me:ue;return e.jsxs("div",{className:"rounded-xl border border-slate-200 overflow-hidden bg-white shadow-sm",children:[e.jsxs("div",{className:"px-4 py-3 bg-blue-100 border-b border-blue-200 flex flex-wrap items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-slate-800",children:f}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("span",{className:"text-[10px] uppercase font-bold text-slate-400 bg-white px-1.5 py-0.5 rounded border border-slate-200",children:i("order_details_positions_short",{count:ae.length})})})]}),x.status==="NEW"&&!V&&e.jsx("button",{onClick:()=>Q(f,ae.map(wt=>wt.id)),disabled:W===f,title:i("order_details_remove_all_shop_items"),className:"p-1.5 rounded-lg text-red-500 hover:bg-red-50 transition-colors disabled:opacity-50",children:W===f?e.jsx(rt,{size:16,className:"animate-spin"}):e.jsx(is,{size:16})})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"hidden md:flex items-center gap-2 opacity-80",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-slate-500",children:[e.jsx(ln,{size:12}),e.jsxs("span",{className:"text-[10px] font-bold uppercase tracking-wide",children:[i("order_details_client_label"),":"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"absolute left-2 top-1/2 -translate-y-1/2 text-slate-400 font-bold text-xs",children:"Â¥"}),e.jsx("input",{type:"number",disabled:!0,className:"w-20 pl-5 pr-2 py-1.5 text-sm font-bold text-slate-600 bg-white border border-blue-200 rounded text-right cursor-not-allowed",value:ue.toFixed(2)})]}),Me>
570&&e.jsxs("span",{className:"text-xs font-bold text-orange-500 whitespace-nowrap",children:["â ",Math.round(Me*P).toLocaleString("ru-RU")," â½"]})]}),vt?e.jsxs("div",{className:"bg-red-500 text-white px-3 py-1.5 rounded shadow-sm shadow-red-200 flex items-center gap-2 mx-2",children:[e.jsx(Lt,{size:14,className:"opacity-80"}),e.jsxs("div",{className:"flex flex-col items-end leading-none",children:[e.jsx("span",{className:"text-[9px] font-bold uppercase opacity-80",children:i("order_details_delivery_refund")}),e.jsxs("span",{className:"text-sm font-bold",children:["+",Math.round(es*P)," â½"]})]})]}):e.jsxs("div",{className:"flex flex-col items-center w-16",children:[e.jsx(Ga,{size:14,className:"text-blue-300"}),Math.abs(Fe)>.01&&e.jsxs("span",{className:`text-[10px] font-bold ${Fe>0?"text-green-600":"text-red-500"}`,children:[Fe>0?"+":"â",Math.round(Math.abs(Fe)*P).toLocaleString("ru-RU")," â½"]})]}),e.jsxs("div",{className:"hidden md:flex items-center gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-slate-400",children:[e.jsx(tn,{size:12}),e.jsxs("span",{className:"text-[10px] font-bold uppercase tracking-wide",children:[i("order_details_actual_label"),":"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"absolute left-2 top-1/2 -translate-y-1/2 text-slate-400 font-bold text-xs",children:"Â¥"}),e.jsx("input",{type:"number",disabled:!0,className:"w-24 pl-5 pr-2 py-1.5 text-sm font-bold text-slate-600 bg-white border border-blue-200 rounded text-right cursor-not-allowed",value:Me>0?Me.toFixed(2):""})]})]})]})]}),e.jsx("div",{className:"divide-y divide-slate-100",children:ae.map(wt=>e.jsx(Jx,{item:wt,shopItems:ae,index:he.indexOf(wt)+1,cnyRate:P,onViewImage:H,onClientDecision:Rr,isRefunded:!!wt.originalItemComment?.includes("ÐÐÐÐÐ ÐТ ÐЫÐÐÐÐÐÐ"),effectiveCommissionRate:_e.effectiveRateFactor,canEditOrder:c,orderStatus:x.status,orderId:x.id,paymentLocked:V,onItemUpdated:lr,onItemRemoved:g},wt.id))})]},f)})})]})]})}),e.jsxs("div",{className:`relative shrink-0 flex transition-all duration-200 ${se?"xl:w-8":""}`,children:[e.jsx("button",{onClick:u,title:i(se?"order_details_expand_estimate":"order_details_collapse_estimate"),className:"hidden xl:flex absolute left-0 top-6 z-10 w-6 h-14 -translate-x-3 bg-emerald-500 hover:bg-emerald-600 rounded-full shadow-md shadow-emerald-200 items-center justify-center text-white transition-colors",children:se?e.jsx(Mn,{size:14}):e.jsx(Sr,{size:14})}),!se&&e.jsxs("div",{className:"w-full xl:w-96 bg-white xl:border-l border-slate-200 flex flex-col shrink-0 p-6 gap-6",children:[x.status==="NEW"&&e.jsxs("button",{onClick:()=>de(!0),className:"w-full py-4 bg-blue-600 hover:bg-blue-700 text-white rounded-xl font-bold text-lg shadow-lg shadow-blue-200 transition-all flex items-center justify-center gap-2",children:[e.jsx(Ds,{size:20}),i("home_pay_button")," ",_e.totalRUB_Base.toLocaleString()," â½"]}),fs&&!q&&B&&e.jsxs("div",{className:"rounded-xl border border-slate-200 bg-slate-50 p-5 animate-pulse",children:[e.jsx("div",{className:"h-3 w-24 bg-slate-200 rounded mb-3"}),e.jsx("div",{className:"h-8 w-32 bg-slate-200 rounded mb-4"}),e.jsx("div",{className:"h-3 w-full bg-slate-200 rounded"})]}),fs&&!q&&!B&&e.jsx("div",{className:`rounded-xl border transition-all duration-300 ${De?"bg-emerald-50 border-emerald-200":Vt>0?"bg-red-50 border-red-200":"bg-orange-50 border-orange-200"}`,children:e.jsxs("div",{className:"p-5",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("span",{className:`text-[10px] font-bold uppercase tracking-wider flex items-center gap-2 ${De?"text-emerald-700":Vt>0?"text-red-600":"text-orange-600"}`,children:De?i("order_details_balance_settled"):Vt>0?i("order_details_refund_pending"):i("order_details_payment_needed")}),De&&e.jsx(ss,{size:16,className:"text-emerald-500"})]}),e.jsxs("div",{className:"flex items-baseline gap-2 mb-4",children:[e.jsx("span",{className:`text-3xl font-bold ${De?"text-emerald-700":Vt>0?"text-red-600":"text-orange-600"}
57`,children:De?`${Math.abs(Ee).toLocaleString()} â½`:`${Math.abs(Vt).toLocaleString()} â½`}),!De&&Vt>0&&e.jsx("span",{className:"text-xs font-medium text-slate-500",children:i("order_details_to_balance")})]}),e.jsxs("div",{className:`space-y-1.5 py-3 border-t text-xs ${De?"border-emerald-100":"border-red-100"}`,children:[Pe>0&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-slate-500",children:i("order_details_items_refund",{count:It})}),e.jsxs("span",{className:"font-semibold text-emerald-600",children:["+",Pe," â½"]})]}),nt!==0&&e.jsxs("div",{className:"flex justify-between",children:[e.jsxs("span",{className:"text-slate-500",children:[i("order_details_delivery_adjustment"),":"]}),e.jsxs("span",{className:`font-semibold ${nt>0?"text-emerald-600":"text-red-500"}`,children:[nt>0?"+":"",nt," â½"]})]}),(ft??0)!==0&&e.jsxs("div",{className:"flex justify-between",children:[e.jsxs("span",{className:"text-slate-500",children:[i("order_details_price_adjustment"),":"]}),e.jsxs("span",{className:`font-semibold ${(ft??0)>0?"text-emerald-600":"text-red-500"}`,children:[(ft??0)>0?"+":"",(ft??0).toLocaleString("ru-RU")," â½"]})]})]}),De?e.jsxs("div",{className:"mt-2 pt-2 border-t border-emerald-100/50 flex items-center gap-2 text-xs text-emerald-700 font-medium opacity-80",children:[e.jsx(Kt,{size:14}),e.jsx("span",{children:i("order_details_all_tx_success")})]}):e.jsxs("div",{className:"mt-2 pt-2 border-t border-red-100/50 flex items-center gap-2 text-xs text-red-500 font-medium opacity-80",children:[e.jsx(Fs,{size:14}),e.jsx("span",{children:i("order_details_await_tx")})]})]})}),e.jsxs("div",{children:[e.jsxs("h3",{className:"font-bold text-slate-900 flex items-center gap-2 mb-4 uppercase text-xs tracking-wider",children:[e.jsx(un,{size:16,className:"text-slate-400"})," ",i("order_details_order_estimate")]}),e.jsxs("div",{className:"bg-slate-50 rounded-xl p-4 border border-slate-100 space-y-3 text-sm",children:[e.jsxs("div",{className:"flex justify-between items-end",children:[e.jsx("span",{className:"text-sm font-semibold text-slate-700",children:i("order_details_goods")}),e.jsxs("div",{className:"text-right",children:[e.jsxs("div",{className:"font-bold text-slate-800",children:[Math.round(_e.itemsGoodsTotal*P).toLocaleString("ru-RU")," â½"]}),e.jsxs("div",{className:"text-[11px] text-slate-400",children:[_e.itemsGoodsTotal.toFixed(2)," Â¥"]})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-end",children:[e.jsxs("span",{className:"text-sm font-semibold text-slate-700",children:[i("order_details_commission")," (",_e.appliedPercent,"%)",_e.isWeightBased&&e.jsx("span",{className:"ml-1 text-[10px] font-semibold text-blue-500 uppercase tracking-wide",children:i("order_details_by_weight")})]}),e.jsxs("div",{className:"text-right",children:[e.jsxs("div",{className:"font-bold text-slate-800",children:[Math.round(_e.commissionTotal*P).toLocaleString("ru-RU")," â½"]}),e.jsxs("div",{className:"text-[11px] text-slate-400",children:[_e.commissionTotal.toFixed(2)," Â¥"]})]})]}),_e.isWeightBased&&e.jsxs("p",{className:"text-[11px] text-green-600 mt-0.5 leading-snug",children:["â ",i("order_details_commission_by_weight_note")]})]}),e.jsxs("div",{className:"flex justify-between items-end",children:[e.jsx("span",{className:"text-sm font-semibold text-slate-600",children:i("order_details_china_delivery")}),e.jsxs("div",{className:"text-right",children:[e.jsxs("div",{className:"font-bold text-orange-600",children:[Math.round(_e.totalChinaDeliveryClient*P).toLocaleString("ru-RU")," â½"]}),e.jsxs("div",{className:"text-[11px] text-slate-400",children:[_e.totalChinaDeliveryClient.toFixed(2)," Â¥"]})]})]}),e.jsxs("div",{className:"border-t border-slate-200 pt-3 flex justify-between items-end",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] text-slate-400 font-bold uppercase",children:i("order_details_total_client")}),e.jsxs("div",{className:"text-lg font-bold text-blue-600",children:["Â¥",_e.totalCNY_Client.toFixed(2)]})]}),e.jsxs("div",{className:"text-right",children:[e.jsxs("div",{className:"text-[10px] text-slate-400 font-bold uppercase flex items-center justify-end gap-1",children:[i("order_details_rate_label")," ",A&&e.jsx(ln,{size:10,
57className:"text-slate-300"})]}),e.jsxs("div",{className:"font-bold text-slate-600",children:[Number(P).toFixed(2)," â½"]})]})]})]})]}),e.jsxs("div",{className:"bg-slate-900 rounded-xl p-5 text-white shadow-lg shadow-slate-200",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2 opacity-80",children:[e.jsx(Ds,{size:18}),e.jsx("span",{className:"text-xs font-bold uppercase tracking-wider",children:i("order_details_base_cost")})]}),e.jsxs("div",{className:"text-3xl font-bold",children:[_e.totalRUB_Base.toLocaleString()," â½"]}),e.jsxs("div",{className:"mt-2 text-[10px] text-slate-400 font-medium inline-flex items-center gap-1",children:[e.jsx(Fs,{size:10}),i("order_details_excl_adjustments")]})]}),(()=>{const f=x.clientPreferences||x.client_preferences,ae=f?.deliveryData,ue=f?.strategy==="MANUAL_CONFIRM"?{text:i("order_details_wait_confirmation"),color:"text-amber-700 bg-amber-50 border-amber-200",Icon:on,iconColor:"text-amber-500"}:{text:i("order_details_ship_immediately"),color:"text-blue-700 bg-blue-50 border-blue-200",Icon:ji,iconColor:"text-blue-500"},Me={SELLER_BOX:i("order_details_pkg_seller_box"),PLAIN_BOX:i("order_details_pkg_box"),BAG:i("order_details_pkg_bag_tape"),BOX:i("order_details_pkg_box_corners"),CRATE:i("order_details_pkg_crate"),PALLET:i("order_details_pkg_pallet")},Fe={CDEK:"СÐÐÐ",PEK:"ÐÐÐ",PEC:"ÐÐÐ",DL:"ÐеловÑе Ðинии",DELLIN:"ÐеловÑе Ðинии",KIT:"ÐÐТ (GTD)",BAIKAL:"Ðайкал СеÑвиÑ",ENERGIA:"ÐнеÑгиÑ",MAGIC_TRANS:"Magic Trans",ZHELDOR:"ÐелÐоÑÐкÑпедиÑиÑ",MEGATRANS:"Ðега ÑÑанÑ",VICTORIA:"ÐикÑоÑиÑ",VOZOVOZ:"Ðозовоз",GLAVTRASA:"ÐлавÑÑаÑа",PICKUP:"СамовÑвоз (ÐоÑква)"},ot=!!y&&["PAID","PURCHASED","COLLECTING","ASSEMBLED"].includes(x.status);return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("h3",{className:"font-bold text-slate-900 flex items-center gap-2 uppercase text-xs tracking-wider",children:[e.jsx(Lt,{size:16,className:"text-slate-400"})," ",i("layout_label_delivery")]}),ot&&ae&&e.jsxs("button",{onClick:y,className:"flex items-center gap-1 text-xs font-bold text-blue-600 bg-blue-50 hover:bg-blue-100 px-2.5 py-1 rounded-lg transition-colors border border-blue-100",children:[e.jsx(tn,{size:12})," ",i("order_details_change")]})]}),ae?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"bg-slate-50 rounded-xl border border-slate-200 overflow-hidden",children:[e.jsx("div",{className:"px-4 py-2 border-b border-slate-200 bg-white",children:e.jsx("span",{className:"text-[10px] font-bold uppercase tracking-wider text-slate-400",children:i("order_details_parameters")})}),e.jsxs("div",{className:"p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-xs text-slate-500 flex-shrink-0",children:i("order_details_mode")}),e.jsxs("span",{className:`flex items-center gap-1 text-xs font-bold px-2 py-0.5 rounded-full border ${ue.color}`,children:[e.jsx(ue.Icon,{size:11,className:ue.iconColor}),ue.text]})]}),f?.packaging&&e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-xs text-slate-500 flex-shrink-0",children:i("order_details_packaging")}),e.jsxs("span",{className:"flex items-center gap-1 text-xs font-bold text-slate-700 bg-white border border-slate-200 px-2 py-0.5 rounded-full",children:[e.jsx(vi,{size:11,className:"text-slate-400"}),Me[f.packaging]??f.packaging]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-xs text-slate-500 flex-shrink-0",children:i("order_details_insurance")}),ae.insurance?e.jsxs("span",{className:"flex items-center gap-1 text-xs font-bold text-green-700 bg-green-50 border border-green-200 px-2 py-0.5 rounded-full",children:[e.jsx(on,{size:11,className:"text-green-500"})," ",i("order_details_insurance_on")]}):e.jsxs("span",{className:"flex items-center gap-1 text-xs font-bold text-red-500 bg-red-50 border border-red-200 px-2 py-0.5 rounded-full",children:[e.jsx(bt,{size:10})," ",i("order_details_insurance_off")]})]})]})]}),e.jsxs("div",{className:"ym-hide-content bg-slate-50 rounded-xl border border-slate-200 overflow-hidden",children:[e.jsx("div",{className:"px-4 py-2 border-b border-slate-200 bg-white",children:e.jsx("span",{className:"text-[10px] font-bold uppercase tracking-wider text-slate-400",children:i("order_details_recipient")})}),e.jsxs("div",{className:"p-3 space-y-2",children:[ae.recipientName&&e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(gs,{size:13,className:"text-slate-400 mt-0.5 flex-shrink-0"}),e.jsx("span",{className:"text-xs font-semibold text-slate-700 break-words",children:ae.recipientName})]}),ae.phone&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Do,{size:13,className:"text-slate-400 flex-shrink-0"}),e.jsx("span",{className:"text-xs font-semibold text-slate-700",children:ae.phone})]}),ae.city&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ni,{size:13,className:"text-slate-400 flex-shrink-0"}),e.jsx("span",{className:"text-xs font-semibold text-slate-700",children:ae.city}),ae.transportCompany&&e.jsx("span",{className:"ml-auto text-[10px] font-bold text-blue-600 bg-blue-50 border border-blue-200 px-2 py-0.5 rounded-full flex-shrink-0",children:Fe[ae.transportCompany]??ae.transportCompany})]}),ae.address&&e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Lt,{size:13,className:"text-slate-400 mt-0.5 flex-shrink-0"}),e.jsx("span",{className:"text-xs text-slate-500 break-words",children:ae.address})]}),ae.passport&&e.jsxs("div",{className:"flex items-center gap-2 pt-1 border-t border-slate-200 mt-1",children:[e.jsx("span",{className:"text-[10px] font-bold uppercase tracking-wider text-slate-400",children:i("order_details_passport")}),e.jsx("span",{className:"text-xs font-mono font-semibold text-slate-600",children:M===null?"ð ÑаÑÑиÑÑовкаâ¦":ie?M:"â¢â¢â¢â¢ â¢â¢â¢â¢â¢â¢"}),M!==null&&e.jsx("button",{type:"button",onClick:()=>ge(at=>!at),className:"text-slate-400 hover:text-slate-600 transition-colors",children:ie?e.jsx(Fa,{size:13}):e.jsx(Xn,{size:13})})]}),ae.orderComment&&e.jsxs("div",{className:"flex items-start gap-2 pt-1 border-t border-slate-200 mt-1",children:[e.jsx(zr,{size:13,className:"text-slate-400 mt-0.5 flex-shrink-0"}),e.jsx("span",{className:"text-xs text-slate-600 break-words",children:ae.orderComment})]})]})]})]}):ot?e.jsxs("button",{onClick:y,className:"w-full flex flex-col items-center justify-center gap-2 text-sm font-bold text-blue-600 p-4 bg-blue-50 rounded-xl border border-dashed border-blue-200 hover:bg-blue-100 transition-colors",children:[e.jsx(tn,{size:18}),i("order_details_specify_delivery")]}):e.jsx("div",{className:"text-xs text-slate-400 text-center p-4 bg-slate-50 rounded-xl border border-dashed border-slate-200",children:i("order_details_no_delivery_data")})]})})()]})]})]})]}),Ae&&e.jsx("div",{className:"fixed inset-0 z-[300] flex items-center justify-center bg-black/50 p-4",onClick:()=>E(null),children:e.jsxs("div",{className:"bg-white rounded-2xl shadow-2xl w-full max-w-sm p-6",onClick:f=>f.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-orange-100 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"text-orange-600 font-black text-lg leading-none",children:"!"})}),e.jsx("h3",{className:"font-bold text-slate-800 text-base",children:"СÑоки доÑÑавки"})]}),e.jsxs("div",{className:"space-y-3 text-sm text-slate-700",children:[e.jsxs("p",{children:["ÐÑÐ¾Ð´Ð°Ð²ÐµÑ Ð¾ÑпÑÐ°Ð²Ð¸Ñ ÑÑÐ¾Ñ ÑÐ¾Ð²Ð°Ñ Ñ ÐºÐ¸ÑайÑкого Ñклада ",e.jsx("strong",{children:Ae.dispatchDate}),"."]}),e.jsxs("p",{children:["СÑеднее вÑÐµÐ¼Ñ Ð´Ð¾ÑÑавки из ÐиÑÐ°Ñ Ð´Ð¾ наÑего Ñклада в ÐоÑкве â ",e.jsx("strong",{children:"Ð¾Ñ 3 до 6 дней"}),"."]}),e.jsxs("p",{children:["Ðжидаемое поÑÑÑпление на Ð½Ð°Ñ Ñклад: ",e.jsxs("strong",{children:["около ",Ae.arrivalDate]}),"."]}),e.jsx("p",{className:"text-slate-500",children:"ÐÑли ÑÐ¾Ð²Ð°Ñ Ð½Ðµ поÑÑÑÐ¿Ð¸Ñ Ð² ÑÑок, Ð¼Ñ ÑообÑим вам об ÑÑом дополниÑелÑно."})]}),e.jsx("button",{onClick:()=>E(null),className:"mt-5 w-full py-2.5 bg-slate-900 text-white rounded-xl font-bold text-sm hover:bg-slate-700 transition-colors",children:"ÐонÑÑно"})]})}),N&&x&&e.jsx(lo,{order:x,onClose:()=>R(!1)})]})},Zx=({orderDisplayId:t,onConfirm:s,onCancel:n,isLoading:r})=>{const{t:l}=qt();return e.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-black/50 backdrop-blur-sm p-4 animate-in fade-in",children:e.jsxs("div",{className:"bg-white w-full max-w-sm rounded-2xl shadow-xl overflow-hidden p-6 text-center",children:[e.jsx("div",{className:"w-16 h-16 bg-red-50 text-red-500 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(is,{size:32})}),e.jsx("h3",{className:"text-xl font-bold text-slate-900 mb-2",children:l("delete_order_question")}),e.jsxs("p",{className:"text-sm text-slate-500 mb-6",children:[l("delete_order_confirm_prefix")," ",e.jsx("span",{className:"font-bold text-slate-800",children:t}),"?"," ",l("delete_order_confirm_suffix")]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{onClick:n,disabled:r,className:"flex-1 py-3 bg-slate-100 hover:bg-slate-200 text-slate-700 font-bold rounded-xl transition-colors",children:l("orders_cancel_button")}),e.jsx("button",{onClick:s,disabled:r,className:"flex-1 py-3 bg-red-600 hover:bg-red-700 text-white font-bold rounded-xl shadow-lg shadow-red-200 transition-colors flex items-center justify-center gap-2",children:l(r?"delete_order_deleting":"import_delete_button")})]})]})})},em=["ÐоÑква","СанкÑ-ÐеÑеÑбÑÑг","ÐовоÑибиÑÑк","ÐкаÑеÑинбÑÑг","ÐазанÑ","Ðижний ÐовгоÑод","ÐоÑ","ЧелÑбинÑк","СамаÑа","ÐмÑк","РоÑÑов-на-ÐоÐ
57½Ñ","УÑа","ÐÑаÑноÑÑÑк","ÐоÑонеж","ÐеÑмÑ","ÐолгогÑад","ÐÑаÑнодаÑ","СаÑаÑов","ТÑменÑ","ТолÑÑÑÑи","ÐжевÑк","ÐаÑнаÑл","УлÑÑновÑк","ÐÑкÑÑÑк","ХабаÑовÑк","ЯÑоÑлавлÑ","ÐладивоÑÑок","ÐаÑ
аÑкала","ТомÑк","ÐÑенбÑÑг","ÐемеÑово","ÐовокÑзнеÑк","Ð ÑзанÑ","ÐÑÑÑаÑ
анÑ","ÐабеÑежнÑе ЧелнÑ","Ðенза","ÐипеÑк","ТÑла","ÐиÑов","ЧебокÑаÑÑ","ÐалинингÑад","ÐÑÑнÑк","ÐÑÑÑк","Ðваново","ÐагниÑогоÑÑк","ТвеÑÑ","СÑавÑополÑ","ÐелгоÑод","Ðижний Тагил","ÐÑÑ
ангелÑÑк","ÐладимиÑ","СоÑи","ЧиÑа","СÑÑгÑÑ","СÑеÑлиÑамак","ÐижневаÑÑовÑк","ÐÑознÑй","ÐÑÑманÑк","ÐоÑÑÑома","СмоленÑк","ÐолжÑкий","ЧеÑеповеÑ","ЯкÑÑÑк","ÐÑÑл","СаÑанÑк","Уlan-УдÑ","Улан-УдÑ","Ðологда","Тамбов","СимÑеÑополÑ","СеваÑÑополÑ","ÐалÑга","ЧебокÑаÑÑ","ХаÑавÑÑÑ","ÐомÑомолÑÑк-на-ÐмÑÑе","ÐеÑÑозаводÑк","ТаганÑог","ÐалÑÑик","ÐÑÑган","ÐижнекамÑк","ШаÑ
ÑÑ","ÐлаговеÑенÑк","УÑÑÑÑийÑк","Ðеликий ÐовгоÑод","ÐÑков","СÑкÑÑвкаÑ","Ð ÑбинÑк","ÐалаÑиÑ
а","ÐÑаÑногоÑÑк","Химки","ÐодолÑÑк","ÐÑбеÑÑÑ","ÐÑÑиÑи","ÐлекÑÑоÑÑалÑ","Ðоломна","ÐдинÑово","СеÑпÑÑ
ов","ÐогинÑк","РаменÑкое","ÐÑковÑкий","ÐолгопÑÑднÑй","ÐоÑолÑв","ЩÑлково","Ðлин","ÐмиÑÑов","ÐоÑкÑеÑенÑк","ФÑÑзево","ÐбнинÑк","ÐÑеÑ
ово-ÐÑево","ÐoвомоÑковÑк","ÐовомоÑковÑк","ÐзеÑжинÑк","ÐÑÑом","ÐовÑов","ÐÑÑÑ-Ð¥ÑÑÑÑалÑнÑй","ÐÑÑигоÑÑк","ÐиÑловодÑк","ÐÑÑенÑÑки","ÐевинномÑÑÑк","ÐÑмавиÑ","ÐовоÑоÑÑийÑк","Ðнапа","Ðеленджик","ТÑапÑе","ÐопейÑк","ÐиаÑÑ","ÐлаÑоÑÑÑ","СаÑка","ТÑоиÑк","ÐзÑÑÑк","СнежинÑк","ÐеÑвоÑÑалÑÑк","СеÑов","ÐаменÑк-УÑалÑÑкий","ÐÑбеÑÑ","ÐолевÑкой","Ревда","Реж","ÐеÑÑ
нÑÑ ÐÑÑма","ÐÑамилÑ","ÐеÑÑзовÑкий","ТоболÑÑк","ÐÑим","ЯлÑÑоÑовÑк","ÐаводоÑковÑк","ХанÑÑ-ÐанÑийÑк","ÐеÑÑеÑганÑк","Ðегион","ÐангепаÑ","ÐÑÑÑ-ЯÑ
","ÐогалÑм","ÐÑганÑ","РадÑжнÑй","УÑай","ÐокаÑи","ÐелоÑÑÑкий","ÐийÑк","Ð ÑбÑовÑк","ÐовоалÑайÑк","ÐаÑинÑк","ÐлейÑк","ÐаменÑ-на-Ðби","ÐоÑно-ÐлÑайÑк","ÐÑокопÑевÑк","ÐиÑелÑвÑк","ÐенинÑк-ÐÑзнеÑкий","Ðелово","ÐÑÑÑевÑк","ТаÑÑагол","ÐÑÑки","ЮÑга","ÐнжеÑо-СÑдженÑк","ÐаÑиинÑк","Топки","ÐÑинники","ÐалÑан","ÐеÑÑзовÑкий","ÐÑаÑноÑÑÑк","ÐоÑилÑÑк","ÐÑинÑк","ÐанÑк","ÐелезногоÑÑк","ÐеленогоÑÑк","ÐинÑÑинÑк","ÐеÑоÑибиÑÑк","ÐазаÑово","ШаÑÑпово","СоÑновобоÑÑк","ÐивногоÑÑк","ÐогоÑол","УÑÑ","ÐнгаÑÑк","ÐÑаÑÑк","УÑÑÑ-ÐлимÑк","УÑолÑе-СибиÑÑкое","ШелеÑ
ов","СаÑнÑк","ЧеÑемÑ
ово","ТÑлÑн","ТайÑеÑ","Ðима","ЧиÑa","ÐÑаÑнокаменÑк","ÐоÑзÑ","ÐеÑÑовÑк-ÐабайкалÑÑкий","Ðалей","ÐеÑÑинÑк","СÑеÑенÑк","ХабаÑовÑк","ÐомÑомолÑÑк-на-ÐмÑÑе","ÐмÑÑÑк","Ðикин","ÐÑземÑкий","ÐиколаевÑк-на-ÐмÑÑе","СовеÑÑÐºÐ°Ñ ÐаванÑ","ÐладивоÑÑок","ÐаÑ
одка","ÐÑÑÑм","УÑÑÑÑийÑк","ÐÑÑенÑев","ÐалÑнегоÑÑк","ÐалÑнеÑеÑенÑк","ÐаÑÑизанÑк","СпаÑÑк-ÐалÑний","ÐеÑозаводÑк","ÐлаговеÑенÑк","ÐелогоÑÑк","ÐеÑ","СвободнÑй","ТÑнда","РайÑиÑ
инÑк","ÐавиÑинÑк","ÐÑÑеÑ","ШимановÑк","Ðагадан","СÑÑÑман","ÐеÑÑопавловÑк-ÐамÑаÑÑкий","Ðлизово","Южно-СаÑ
алинÑк","ХолмÑк","ÐоÑÑаков","ÐевелÑÑк","ÐÑ
а","Ðоглики","ЯкÑÑÑк","ÐиÑнÑй","ÐеÑÑнгÑи","Ðлдан","ÐенÑк","ÐлÑкминÑк","ÐокÑовÑк","ÐамÑÑÑ","Ðайкоп","ЧеÑкеÑÑк","Ðладикавказ","ÐагаÑ","ÐазÑанÑ","ÐалÑÑик","ÐлиÑÑа","Ðбакан","ЧеÑногоÑÑк","СаÑногоÑÑк","СоÑÑк","ÐÑзÑл","Ðк-ÐовÑÑак","ÐоÑно-ÐлÑайÑк","ÐиÑобиджан"],ri=t=>t.replace(/[^a-zA-Zа-ÑÐ-ЯÑÐ\s\-.']/g,""),tm=t=>t.replace(/[^\d+\s\-()]/g,"").replace(/(?!^)\+/g,""),sm=t=>t.replace(/[^\d\s]/g,""),Ua=({orderId:t,onClose:s,onSave:n})=>{const{t:r}
57=qt(),[l,c]=a.useState(!1),[o,d]=a.useState(!0),[p,y]=a.useState([]),[j,b]=a.useState(null),[h,v]=a.useState(!1),[i,x]=a.useState([]),[m,N]=a.useState(!1),[R,S]=a.useState(!1),[C,L]=a.useState(!1),[U,W]=a.useState(!1),[re,Z]=a.useState("AUTO_SHIP"),[O,F]=a.useState(null),[D,$]=a.useState(!1),[z,me]=a.useState(!1),[K,te]=a.useState(null),[I,B]=a.useState({recipientName:"",phone:"",city:"",address:"",passport:"",transportCompany:"CDEK",insurance:!1,orderComment:"",market:"SOUTH_GATE",orderValueCNY:""});a.useEffect(()=>{(async()=>{const le=yt(),{data:Qe}=await Re("orders",{id:t},{select:"client_preferences,is_self_buyout,shipment_group_id",single:!0});if($(!!Qe?.is_self_buyout),te(Qe?.shipment_group_id||null),me(!0),Qe?.client_preferences){const xe=Qe.client_preferences;if(Z(xe.strategy||"AUTO_SHIP"),F(xe.packaging||null),xe.deliveryData){const de=xe.deliveryData.passport,V=le&&Ar(de)?await cn(le,de)??de:de;B(ye=>({...ye,...xe.deliveryData,passport:V,insurance:xe.deliveryData?.insurance??!1}))}}if(!le){d(!1);return}const{data:k}=await Re("users",{id:le},{select:"delivery_recipients,surname,first_name,name,patronymic,phone,city,passport_series,passport_number,transport_company",single:!0});if(!k){d(!1);return}if(d(!1),Array.isArray(k.delivery_recipients)&&k.delivery_recipients.length>0){if(y(k.delivery_recipients),!Qe?.client_preferences?.deliveryData?.recipientName){const xe=k.delivery_recipients.find(de=>de.isDefault)||k.delivery_recipients[0];xe&&Ne(xe,!0)}}else if(k.surname||k.first_name||k.name){const xe=(k.surname||"").trim(),de=(k.first_name||k.name||"").trim(),ye={id:"profile",label:r("delivery_recipient_me"),isDefault:!0,surname:xe,name:de,patronymic:"",phoneCode:"+7",phone:k.phone||"",city:k.city||"",passportSeries:k.passport_series||"",passportNumber:k.passport_number||"",transportCompany:k.transport_company||"CDEK"};y([ye]),Qe?.client_preferences?.deliveryData?.recipientName||Ne(ye,!0)}})()},[t]);const Ne=async(H,le=!1)=>{const Qe=`${H.surname} ${H.name} ${H.patronymic}`.replace(/\s+/g," ").trim(),k=H.transportCompany||"CDEK",xe=H.market||"",de=k==="CDEK"&&xe==="SOUTH_GATE"?"LYUBLINO":xe||"SOUTH_GATE",V=yt(),[ye,Ie]=await Promise.all([V&&Ar(H.passportSeries)?cn(V,H.passportSeries):Promise.resolve(H.passportSeries),V&&Ar(H.passportNumber)?cn(V,H.passportNumber):Promise.resolve(H.passportNumber)]);B(Oe=>({...Oe,recipientName:Qe,phone:`${H.phoneCode||""}${H.phone||""}`.trim(),city:H.city||"",passport:`${ye??H.passportSeries??""} ${Ie??H.passportNumber??""}`.trim(),transportCompany:k,market:de})),le||b(H.id),v(!1)},Ue=I.transportCompany==="PICKUP",$e=async()=>{if(D&&I.insurance&&!(Number(I.orderValueCNY)>0)){alert(r("delivery_self_buyout_order_value_required"));return}if(!O){alert(r("delivery_choose_packaging"));return}if(!I.recipientName||!I.phone||!I.city||!I.market){alert(r("delivery_fill_required_fields"));return}c(!0);try{const H=yt();let le=I.passport;if(H&&I.passport&&!Ar(I.passport)){const ye=await Da(H,I.passport);if(ye===null){alert(r("profile_passport_encrypt_error")),c(!1);return}le=ye}const Qe={...I,passport:le},{data:k}=await Re("orders",{id:t},{select:"client_preferences,display_id",single:!0}),de={...k?.client_preferences||{},packaging:O,strategy:D?"AUTO_SHIP":re,deliveryData:Qe},{error:V}=await Je("orders",{id:t},{client_preferences:de});if(V)throw V;if(D&&await st("notifications",{user_id:null,type:"ORDER",title:"СамовÑкÑп гоÑов к оÑпÑавке",text:`${k?.display_id||t}: ÐºÐ»Ð¸ÐµÐ½Ñ Ñказал даннÑе доÑÑавки (гоÑод: ${Qe.city||"â"}). Ðожно оÑоÑмлÑÑÑ Ð¾ÑпÑавкÑ.`,is_read:!1,link:t,created_at:new Date().toISOString()}),K)try{const{data:ye}=await Re("orders",{shipment_group_id:K},{select:"id,client_preferences"});for(const Ie of ye||[]){if(Ie.id===t)continue;const Oe=Ie.client_preferences||{};await Je("orders",{id:Ie.id},{client_preferences:{...Oe,deliveryData:Qe}})}}catch{}n()}catch(H){alert(r("delivery_save_error_prefix")+H.message)}finally{c(!1)}};return e.jsxs("div",{className:"fixed inset-0 z-[110] flex items-center justify-center bg-black/60 backdrop-blur-sm p-4 animate-in fade-in zoom-in-95",children:[e.jsxs("div",{className:"ym-hide-content bg-white w-full max-w-2xl rounded-2xl shadow-2xl overflow-hidden flex flex-col max-h-[90vh]",children:[e.jsxs("div",{className:"bg-slate-900 text-white px-6 py-4 flex justify-between items-center shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Lt,{className:"text-blue-400"}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-bold text-lg",children:r("delivery_where_to_send")}),e.jsx("p",{className:"text-slate-400 text-xs",children:r("delivery_logistics_setup")})]})]}),e.jsx("button",{onClick:s,className:"text-slate-400 hover:text-white",children:e.jsx(bt,{})})]}),e.jsxs("div",{className:"overflow-y-auto overflow-x-hidden p-4 sm:p-6 space-y-6 bg-slate-50",children:[e.jsxs("div",{className:"bg-orange-50 border border-orange-200 rounded-xl px-4 py-3",children:[e.jsx("p",{className:"text-sm text-orange-800 font-medium",children:r("delivery_timeframe")}),e.jsx("p",{className:"text-sm text-orange-700 mt-0.5",children:r("delivery_route_individual")})]}),z&&!D&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"text-sm font-bold text-slate-900 uppercase tracking-wide block",children:r("order_details_mode")}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("label",{className:`curs
57or-pointer border-2 rounded-xl p-4 transition-all relative ${re==="AUTO_SHIP"?"border-blue-500 bg-blue-50":"border-white bg-white hover:border-blue-200"}`,children:[e.jsx("input",{type:"radio",name:"strategy",className:"hidden",checked:re==="AUTO_SHIP",onChange:()=>Z("AUTO_SHIP")}),e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("div",{className:`w-5 h-5 rounded-full border-2 flex items-center justify-center ${re==="AUTO_SHIP"?"border-blue-600":"border-slate-300"}`,children:re==="AUTO_SHIP"&&e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-blue-600"})}),e.jsx("span",{className:"font-bold text-slate-800",children:r("delivery_strategy_auto_label")})]}),e.jsx("p",{className:"text-xs text-slate-500 ml-8",children:r("delivery_strategy_auto_desc")}),e.jsx(ji,{className:"absolute top-4 right-4 text-blue-200",size:32})]}),e.jsxs("label",{className:`cursor-pointer border-2 rounded-xl p-4 transition-all relative ${re==="MANUAL_CONFIRM"?"border-amber-500 bg-amber-50":"border-white bg-white hover:border-amber-200"}`,children:[e.jsx("input",{type:"radio",name:"strategy",className:"hidden",checked:re==="MANUAL_CONFIRM",onChange:()=>Z("MANUAL_CONFIRM")}),e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("div",{className:`w-5 h-5 rounded-full border-2 flex items-center justify-center ${re==="MANUAL_CONFIRM"?"border-amber-600":"border-slate-300"}`,children:re==="MANUAL_CONFIRM"&&e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-amber-600"})}),e.jsx("span",{className:"font-bold text-slate-800",children:r("order_details_wait_confirmation")})]}),e.jsx("p",{className:"text-xs text-slate-500 ml-8",children:r("delivery_strategy_manual_desc")}),e.jsx(on,{className:"absolute top-4 right-4 text-amber-200",size:32})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-sm font-bold text-slate-900 uppercase tracking-wide block",children:r("order_details_packaging")}),e.jsx("button",{type:"button",onClick:()=>L(!0),title:r("delivery_how_to_choose_packaging"),className:"w-5 h-5 rounded-full bg-orange-500 hover:bg-orange-600 text-white flex items-center justify-center text-[11px] font-bold leading-none transition-colors shadow-sm",children:"!"})]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:[{id:"SELLER_BOX",label:r("delivery_pkg_seller_boxes"),price:r("delivery_pkg_price_none")},{id:"BAG",label:r("delivery_pkg_bag"),extra:r("delivery_pkg_tape"),price:r("delivery_pkg_price_economy")},{id:"PLAIN_BOX",label:r("order_details_pkg_box"),price:r("delivery_pkg_price_standard")},{id:"BOX",label:r("order_details_pkg_box"),extra:r("delivery_pkg_corners"),price:r("delivery_pkg_price_reinfor
57ced")},{id:"CRATE",label:r("order_details_pkg_crate"),price:r("delivery_pkg_price_fragile")},{id:"PALLET",label:r("order_details_pkg_pallet"),price:r("delivery_pkg_price_wholesale")}].map(H=>e.jsxs("button",{onClick:()=>F(H.id),className:`px-3 py-3 rounded-xl border-2 text-center transition-all ${O===H.id?"border-slate-800 bg-slate-800 text-white":"border-white bg-white text-slate-600 hover:border-slate-300"}`,children:[e.jsxs("div",{className:"font-bold text-xs sm:text-sm mb-1 leading-tight break-words",children:[H.label,H.extra&&e.jsxs(e.Fragment,{children:[e.jsx("br",{}),H.extra]})]}),e.jsx("div",{className:"text-[10px] text-slate-400",children:H.price})]},H.id))}),!O&&e.jsx("p",{className:"text-sm text-red-600 font-medium",children:r("delivery_choose_packaging")})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"bg-white p-4 rounded-xl border border-slate-200 shadow-sm flex flex-col gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-9 h-9 rounded-xl flex items-center justify-center flex-shrink-0 transition-colors ${I.insurance?"bg-green-100":"bg-slate-100"}`,children:e.jsx(on,{size:18,className:I.insurance?"text-green-600":"text-slate-400"})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"font-bold text-slate-800 text-sm",children:r("order_details_cargo_insurance")}),e.jsx("button",{type:"button",onClick:()=>S(!0),title:r("delivery_more_about_insurance"),className:"w-4 h-4 rounded-full bg-orange-500 hover:bg-orange-600 text-white flex items-center justify-center text-[10px] font-bold leading-none transition-colors shadow-sm flex-shrink-0",children:"!"})]}),e.jsx("div",{className:"text-xs text-slate-400 mt-0.5",children:r("delivery_insurance_protection")})]})]}),e.jsx("button",{type:"button",onClick:()=>B(H=>({...H,insurance:!H.insurance})),className:`relative flex-shrink-0 w-12 h-6 rounded-full transition-colors duration-200 focus:outline-none ${I.insurance?"bg-green-500":"bg-slate-200"}`,children:e.jsx("span",{className:`absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full shadow transition-transform duration-200 ${I.insurance?"translate-x-6":"translate-x-0"}`})})]}),D&&e.jsxs("div",{children:[e.jsxs("label",{className:"text-xs font-bold text-slate-400 block mb-1",children:[r("delivery_self_buyout_order_value_label"),I.insurance&&e.jsx("span",{className:"text-red-500",children:" *"})]}),e.jsx("input",{type:"number",inputMode:"decimal",min:"0",step:"0.01",className:"w-full border border-slate-200 rounded-lg p-2.5 text-sm outline-none focus:border-blue-500 focus:ring-2 focus:ring-blue-50 transition-all",placeholder:"0",value:I.orderValueCNY,onCh
57ange:H=>B({...I,orderValueCNY:H.target.value})})]})]}),e.jsxs("div",{className:"bg-white p-4 rounded-xl border border-slate-200 shadow-sm flex flex-col justify-center",children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[e.jsx("label",{className:"text-xs font-bold text-slate-400",children:r("delivery_passport_series_number")}),e.jsx("button",{type:"button",onClick:()=>W(!0),title:r("delivery_when_passport_needed"),className:"w-4 h-4 rounded-full bg-orange-500 hover:bg-orange-600 text-white flex items-center justify-center text-[10px] font-bold leading-none transition-colors shadow-sm flex-shrink-0",children:"!"})]}),e.jsx("input",{type:"text",inputMode:"numeric",className:"w-full border border-slate-200 rounded-lg p-2.5 text-sm outline-none focus:border-blue-500 focus:ring-2 focus:ring-blue-50 transition-all",placeholder:"1234 567890",value:I.passport,onChange:H=>B({...I,passport:sm(H.target.value)}),maxLength:11}),e.jsx("p",{className:"text-[10px] text-slate-400 mt-1",children:r("delivery_if_required_by_carrier")})]})]}),e.jsxs("div",{className:"bg-white p-5 rounded-xl border border-slate-200 shadow-sm",children:[e.jsx("div",{className:"flex justify-between items-center mb-4",children:e.jsxs("h4",{className:"font-bold flex items-center gap-2 text-slate-800",children:[e.jsx(gs,{size:18,className:"text-blue-600"})," ",r("delivery_recipient_data")]})}),o?e.jsxs("div",{className:"mb-5",children:[e.jsx("p",{className:"text-xs font-bold text-slate-400 uppercase tracking-wider mb-2",children:r("delivery_choose_from_profile")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("div",{className:"h-10 w-24 bg-slate-100 rounded-xl animate-pulse"}),e.jsx("div",{className:"h-10 w-20 bg-slate-100 rounded-xl animate-pulse"})]}),e.jsx("div",{className:"mt-3 border-t border-slate-100"})]}):p.length>0?e.jsxs("div",{className:"mb-5",children:[e.jsx("p",{className:"text-xs font-bold text-slate-400 uppercase tracking-wider mb-2",children:r("delivery_choose_from_profile")}),e.jsx("div",{className:"flex flex-wrap gap-2",children:p.map(H=>{const le=`${H.surname} ${H.name}`.trim()||H.label||r("delivery_no_name"),Qe=j===H.id;return e.jsxs("button",{type:"button",onClick:()=>Ne(H),className:`flex items-center gap-2 px-3 py-2 rounded-xl border-2 text-sm font-semibold transition-all ${Qe?"border-blue-500 bg-blue-50 text-blue-700":"border-slate-200 bg-white text-slate-600 hover:border-blue-300 hover:text-blue-600"}`,children:[e.jsx("div",{className:`w-6 h-6 rounded-full flex items-center justify-center text-xs font-bold shrink-0 ${Qe?"bg-blue-600 text-white":"bg-slate-100 text-slate-500"}`,children:(H.label||le).charAt(0).toUpperCase()}),e.jsxs("div",{className:"text-left",children:[e.jsx("div",{className:"leading-tight",children:H.label||le}),H.city&&e.jsx("div",{className:`text-[10px] font-normal ${Qe?"text-blue-400":"text-slate-400"}`,children:H.city})]}),H.isDefault&&e.jsx("span",{className:"text-[9px] font-bold bg-blue-100 text-blue-600 px-1.5 py-0.5 rounded-full ml-1",children:r("delivery_default")})]},H.id)})}),e.jsx("div",{className:"mt-3 border-t border-slate-100"})]}):null,e.jsxs("div",{className:"grid grid-cols-1 gap-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"text-xs font-bold text-slate-400 block mb-1",children:[r("delivery_recipient_fio")," ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",inputMode:"text",className:"w-full border border-slate-200 rounded-lg p-2.5 text-sm outline-none focus:border-blue-500 focus:ring-2 focus:ring-blue-50 transition-all",placeholder:r("delivery_fio_placeholder"),value:I.recipientName,onChange:H=>B({...I,recipientName:ri(H.target.value)})})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"text-xs font-bold text-slate-400 block mb-1",children:[r("delivery_phone_label")," ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"tel",inputMode:"tel",className:"w-full border border-slate-200 rounded-lg p-2.5 text-sm outline-none focus:border-blue-500 focus:ring-2 focus:ring-blue-50 transition-all",placeholder:"+7 (999) 000-00-00",value:I.phone,onChange:H=>B({...I,phone:tm(H.target.value)})})]}),e.jsxs("div",{className:"relative",children:[e.jsxs("label",{className:"text-xs font-bold text-slate-400 block mb-1",children:[r("delivery_city_label")," ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",inputMode:"text",autoComplete:"off",className:"w-full border border-slate-200 rounded-lg p-2.5 text-sm outline-none focus:border-blue-500 focus:ring-2 focus:ring-blue-50 transition-all",placeholder:r("delivery_city_placeholder"),value:
57I.city,onChange:H=>{const le=ri(H.target.value);if(B({...I,city:le}),le.length>=2){const Qe=le.toLowerCase(),k=em.filter(xe=>xe.toLowerCase().startsWith(Qe)).slice(0,7);x(k),N(k.length>0)}else N(!1)},onBlur:()=>setTimeout(()=>N(!1),150),onFocus:()=>{I.city.length>=2&&i.length>0&&N(!0)}}),m&&e.jsx("ul",{className:"absolute z-50 left-0 right-0 top-full mt-1 bg-white border border-slate-200 rounded-xl shadow-lg overflow-hidden",children:i.map(H=>e.jsx("li",{onMouseDown:()=>{B({...I,city:H}),N(!1)},className:"px-3 py-2.5 text-sm cursor-pointer hover:bg-blue-50 hover:text-blue-700 transition-colors",children:H},H))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-bold text-slate-400 block mb-1",children:r(Ue?"delivery_pickup_comment_label":"delivery_pvz_address_label")}),e.jsx("input",{type:"text",className:"w-full border border-slate-200 rounded-lg p-2.5 text-sm outline-none focus:border-blue-500 focus:ring-2 focus:ring-blue-50 transition-all",placeholder:r(Ue?"delivery_pickup_time_placeholder":"delivery_address_placeholder"),value:I.address,onChange:H=>B({...I,address:H.target.value})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-bold text-slate-400 block mb-1",children:r("delivery_transport_company")}),e.jsxs("select",{className:"w-full border border-slate-200 rounded-lg p-2.5 text-sm outline-none focus:border-blue-500 bg-white",value:I.transportCompany,onChange:H=>{const le=H.target.value,Qe=le==="CDEK"&&I.market==="SOUTH_GATE"?"LYUBLINO":I.market;B({...I,transportCompany:le,market:Qe})},children:[e.jsx("option",{value:"CDEK",children:"СÐÐÐ"}),e.jsx("option",{value:"PEK",children:"ÐÐÐ"}),e.jsx("option",{value:"DL",children:"ÐеловÑе Ðинии"}),e.jsx("option",{value:"KIT",children:"ÐÐТ (GTD)"}),e.jsx("option",{value:"BAIKAL",children:"Ðайкал СеÑвиÑ"}),e.jsx("option",{value:"ENERGIA",children:"ÐнеÑгиÑ"}),e.jsx("option",{value:"MAGIC_TRANS",children:"Magic Trans"}),e.jsx("option",{value:"ZHELDOR",children:"ÐелÐоÑÐкÑпедиÑиÑ"}),e.jsx("option",{value:"MEGATRANS",children:"Ðега ÑÑанÑ"}),e.jsx("option",{value:"VICTORIA",children:"ÐикÑоÑиÑ"}),e.jsx("option",{value:"VOZOVOZ",children:"Ðозовоз"}),e.jsx("option",{value:"GLAVTRASA",children:"ÐлавÑÑаÑа"}),e.jsx("option",{value:"PICKUP",children:r("delivery_pickup_option")})]}),Ue&&e.jsx("div",{className:"mt-2 flex items-start gap-1.5 bg-blue-50 border border-blue-100 rounded-lg px-3 py-2",children:e.jsx("p",{className:"text-xs text-blue-700",children:r("delivery_pickup_note")})})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"text-xs font-bold text-slate-400 block mb-1",children:[r("delivery_market_label")," ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsxs("select",{className:"w-full border border-slate-200 rounded-lg p-2.5 text-sm outline-none focus:border-blue-500 bg-white",value:I.market,onChange:H=>{const le=H.target.value;le==="SOUTH_GATE"&&I.transportCompany==="CDEK"||B({...I,market:le})},children:[e.jsx("option",{value:"SOUTH_GATE",disabled:I.transportCompany==="CDEK",children:r("delivery_market_south_gate")}),e.jsx("option",{value:"LYUBLINO",children:r("delivery_market_lyublino")})]}),I.transportCompany==="CDEK"&&e.jsx("div",{className:"mt-2 flex items-start gap-1.5 bg-orange-50 border border-orange-200 rounded-lg px-3 py-2",children:e.jsx("p",{className:"text-xs text-orange-700",children:r("delivery_cdek_market_note")})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-bold text-slate-400 block mb-1",children:r("delivery_general_comment_label")}),e.jsx("textarea",{rows:3,className:"w-full border border-slate-200 rounded-lg p-2.5 text-sm outline-none focus:border-blue-500 focus:ring-2 focus:ring-blue-50 transition-all resize-none",placeholder:r("delivery_comment_placeholder"),value:I.orderComment,onChange:H=>B({...I,orderComment:H.target.value})})]})]})]})]}),e.jsxs("div",{className:"p-6 border-t border-slate-200 bg-white flex justify-end gap-3 shrink-0",children:[e.jsx("button",{onClick:s,className:"px-6 py-3 rounded-xl font-bold text-slate-500 hover:bg-slate-50 transition-colors",children:r("delivery_fill_later")}),e.jsxs("button",{onClick:$e,disabled:l||!O,className:"px-8 py-3 rounded-xl font-bold bg-blue-600 text-white hover:bg-blue-700 transition-colors shadow-lg shadow-blue-200 flex items-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed",children:[l?e.jsx(rt,{className:"animate-spin"}):e.jsx(wi,{size:18}),r(l?"delivery_saving":"delivery_save_settings")]})]})]}),R&&e.jsx("div",{className:"fixed inset-0 z-[120] flex items-center justify-center bg-black/60 backdrop-blur-sm p-4",onClick:()=>S(!1),children:e.jsxs("div",{className:"bg-white w-full max-w-lg rounded-2xl shadow-2xl overflow-hidden flex flex-col max-h-[85vh]",onClick:H=>H.stopPropagation(),children:[e.jsxs("div",{className:"bg-orange-500 text-white px-5 py-4 flex justify-between items-center shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(on,{size:20}),e.jsx("h3",{className:"font-bold text-base",children:r("delivery_insurance_popup_title")})]}),e.jsx("button",{onClick:()=>S(!1),className:"text-white/80 hover:text-white",children:e.jsx(bt,{size:20})})]}),e.jsxs("div",{className:"overflow-y-auto p-5 space-y-4 text-sm text-slate-700",children:[e.jsx("p",{children:r("delivery_insurance_p1")}),e.jsxs("div",{className:"bg-orange-50 border border-orange-200 rounded-xl p-3",children:[e.jsx("p",{className:"font-bold text-orange-600",children:r("delivery_insurance_full_loss_only")}),e.jsx("p",{className:"text-orange-600 mt-1",children:r("delivery_insurance_not_for_damage")})]}),e.jsxs("ul",{className:"space-y-1",children:[e.jsxs("li",{className:"flex justify-between border-b border-slate-100 pb-1",children:[e.jsx("span",{children:r("delivery_insurance_tier_1")}),e.jsx("span",{className:"font-bold text-slate-900",children:"1%"})]}),e.jsxs("li",{className:"flex justify-between border-b border-slate-100 pb-1",children:[e.jsx("span",{children:r("delivery_insurance_tier_2")}),e.jsx("span",{className:"font-bold text-slate-900",children:"2%"})]}),e.jsxs("li",{className:"flex justify-between border-b border-slate-100 pb-1",children:[e.jsx("span",{children:r("delivery_insurance_tier_3")}),e.jsx("span",{className:"font-bold text-slate-900",children:"3%"})]}),e.jsxs("li",{className:"flex justify-between",children:[e.jsx("span",{children:r("delivery_insurance_tier_4")}),e.jsx("span",{className:"font-bold text-slate-900",children:"5%"})]})]}),e.jsxs("div",{className:"bg-slate-50 border border-slate-200 rounded-xl p-3",children:[e.jsx("p",{className:"font-bold text-slate-800 mb-1",children:r("delivery_rate_example_title")}),e.jsx("p",{children:r("delivery_rate_example_1")}),e.jsx("p",{className:"mt-1",children:r("delivery_rate_example_2")}),e.jsx("p",{children:r("delivery_rate_example_3")}),e.jsxs("p",{className:"mt-1",children:[r("delivery_rate_example_4_prefix")," ",e.jsx("strong",{children:"5%"})]})]}),e.jsx("p",{children:r("delivery_insurance_optional")}),e.jsx("p",{children:r("delivery_insurance_compensation_note")}),e.jsxs("div",{className:"bg-slate-50 border border-slate-200 rounded-xl p-3",children:[e.jsx("p",{className:"font-bold text-slate-800 mb-1",children:r("delivery_compensation_example_title")}),e.jsx("p",{children:r("delivery_compensation_example_1")}),e.jsx("p",{className:"mt-1",children:r("delivery_compensation_example_2")}),e.jsx("p",{children:r("delivery_compensation_example_3")}),e.jsxs("p",{className:"mt-1",children:[r("delivery_compensation_example_4_prefix")," ",e.jsxs("strong",{children:["20$ à 100 ",r("orders_unit_kg")," = 2 000$"]})]}),e.jsx("p",{className:"mt-2 text-slate-500",children:r("delivery_compensation_no_insurance_note")})]})]}),e.jsx("div",{className:"p-4 border-t border-slate-200 bg-white shrink-0",children:e.jsx("button",{onClick:()=>S(!1),className:"w-full px-6 py-2.5 rounded-xl font-bold bg-orange-500 text-white hover:bg-orange-600 transition-colors",children:r("topup_understood")})})]})}),C&&e.jsx("div",{className:"fixed inset-0 z-[120] flex items-center justify-center bg-black/60 backdrop-blur-sm p-4",onClick:()=>L(!1),children:e.jsxs("div",{className:"bg-white w-full max-w-lg rounded-2xl shadow-2xl overflow-hidden flex flex-col max-h-[85vh]",onClick:H=>H.stopPropagation(),children:[e.jsxs("div",{className:"bg-orange-500 text-white px-5 py-4 flex justify-between items-center shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(js,{size:20}),e.jsx("h3",{className:"font-bold text-base",children:r("delivery_packaging_popup_title")})]}),e.jsx("button",{onClick:()=>L(!1),className:"text-white/80 hover:text-white",children:e.jsx(bt,{size:20})})]}),e.jsxs("div",{className:"overflow-y-auto p-5 space-y-4 text-sm text-slate-700",children:[e.jsx("p",{children:r("delivery_packaging_p1")}),e.jsx("p",{children:r("delivery_packaging_p2")}),e.jsxs("div",{className:"bg-slate-50 border border-slate-200 rounded-xl p-3",children:[e.jsx("p",{className:"font-bold text-slate-800 mb-2",children:r("delivery_packaging_choose_note")}),e.jsxs("ul",{className:"space-y-1.5",children:[e.jsxs("li",{children:[e.jsxs("strong",{children:[r("delivery_pkg_seller_boxes")," / ",r("delivery_pkg_bag")," + ",r("delivery_pkg_tape")]})," â ",r("delivery_pkg_use_case_1")]}),e.jsxs("li",{children:[e.jsxs("strong",{children:[r("order_details_pkg_box")," / ",r("order_details_pkg_box")," + ",r("delivery_pkg_corners")]})," â ",r("delivery_pkg_use_case_2")]}),e.jsxs("li",{children:[e.jsx("strong",{children:r("order_details_pkg_crate")})," â ",r("delivery_pkg_use_case_3")]}),e.jsxs("li",{children:[e.jsx("strong",{children:r("order_details_pkg_pallet")})," â ",r("delivery_pkg_use_case_4")]})]})]}),e.jsx("p",{className:"font-bold text-orange-600",children:r("delivery_packaging_responsibility")})]}),e.jsx("div",{className:"p-4 border-t border-slate-200 bg-white shrink-0",children:e.jsx("button",{onClick:()=>L(!1),className:"w-full px-6 py-2.5 rounded-xl font-bold bg-orange-500 text-white hover:bg-orange-600 transition-colors",children:r("topup_understood")})})]})}),U&&e.jsx("div",{className:"fixed inset-0 z-[120] flex items-center justify-center bg-black/60 backdrop-blur-sm p-4",onClick:()=>W(!1),children:e.jsxs("div",{className:"bg-white w-full max-w-lg rounded-2xl shadow-2xl overflow-hidden flex flex-col max-h-[85vh]",onClick:H=>H.stopPropagation(),children:[e.jsxs("div",{className:"bg-orange-500 text-white px-5 py-4 flex justify-between items-center shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($n,{size:20}),e.jsx("h3",{className:"font-bold text-base",children:r("delivery_when_passport_needed")})]}),e.jsx("button",{onClick:()=>W(!1),className:"text-white/80 hover:text-white",children:e.jsx(bt,{size:20})})]}),e.jsxs("div",{className:"overflow-y-auto p-5 space-y-4 text-sm text-slate-700",children:[e.jsx("p",{children:r("delivery_passport_p1")}),e.jsx("div",{className:"bg-orange-50 border border-orange-200 rounded-xl p-3",children:e.jsx("p",{className:"font-bold text-orange-600",children:r("delivery_passport_example")})}),e.jsx("p",{children:r("delivery_passport_p2")})]}),e.jsx("div",{className:"p-4 border-t border-slate-200 bg-white shrink-0",children:e.jsx("button",{onClick:()=>W(!1),className:"w-full px-6 py-2.5 rounded-xl font-bold bg-orange-500 text-white hover:bg-orange-600 transition-colors",children:r("topup_understood")})})]})})]})},ni=["blue","purple","emerald","amber","rose","indigo"],rn=35,rm="https://yandex.com/ma
57ps/org/goods_china_997/162856034781/?add-review=true",nm=({orderId:t,orderLabel:s,weightKg:n,receivedAt:r,onClose:l})=>{const{t:c}=qt(),o=Ti(r),[d,p]=a.useState("SITE"),[y,j]=a.useState(5),[b,h]=a.useState(""),[v,i]=a.useState([]),[x,m]=a.useState(""),[N,R]=a.useState(null),[S,C]=a.useState(!1),[L,U]=a.useState(null),[W,re]=a.useState(!1),Z=3,O=D=>{if(!D)return;const $=Array.from(D).slice(0,Z-v.length).map(z=>({file:z,preview:URL.createObjectURL(z)}));i(z=>[...z,...$].slice(0,Z))},F=async()=>{if(d==="SITE"&&b.trim().length<rn){U(c("review_error_text_too_short",{min:rn}));return}if(d==="YANDEX"&&!x.trim()&&!N){U(c("review_error_proof_required"));return}C(!0),U(null);try{const D=yt();if(!D)throw new Error("no_user");const{data:$}=await Re("users",{id:D},{select:"name,city",single:!0}),z=$?.name||"ÐлиенÑ",me=ni[Math.floor(Math.random()*ni.length)];let K=[];d==="SITE"&&v.length>0&&(K=await Promise.all(v.map(async Ne=>{const Ue=await Er(Ne.file,1600,.85),$e=Ue.name.split(".").pop()||"jpg",H=`reviews/${Date.now()}_${Math.random().toString(36).slice(2)}.${$e}`,{publicUrl:le,error:Qe}=await Ln("chat-files",H,Ue);if(Qe)throw new Error(Qe);return{type:"image",src:le}})));let te=x.trim()||null;if(d==="YANDEX"&&N){const B=await Er(N.file,1600,.85),Ne=B.name.split(".").pop()||"jpg",Ue=`reviews/${Date.now()}_${Math.random().toString(36).slice(2)}.${Ne}`,{publicUrl:$e,error:H}=await Ln("chat-files",Ue,B);if(H)throw new Error(H);te=$e}const{error:I}=await st("reviews",{user_id:D,order_id:t,name:z,city:$?.city||null,rating:y,avatar:"",avatar_color:me,short_text:b.trim()?b.trim().slice(0,140):null,full_text:b.trim()||null,media:K,source:d,proof_url:te,category:(K.length>0,"text"),likes:0});if(I)throw new Error(I);re(!0)}catch(D){D.message?.includes("duplicate key")||D.message?.includes("idx_reviews_order_id_unique")?U(c("review_error_already_submitted")):U(c("review_error_generic"))}finally{C(!1)}};return e.jsx("div",{className:"fixed inset-0 z-[70] flex items-center justify-center bg-black/50 backdrop-blur-sm p-4 animate-in fade-in duration-200",children:e.jsxs("div",{className:"bg-white w-full max-w-md rounded-2xl shadow-2xl p-6 relative max-h-[90vh] overflow-y-auto animate-in zoom-in-95 duration-200",children:[e.jsx("button",{onClick:l,className:"absolute right-4 top-4 p-2 text-slate-400 hover:text-slate-700 rounded-full hover:bg-slate-100",children:e.jsx(bt,{size:20})}),W?e.jsxs("div",{className:"text-center py-6 space-y-3",children:[e.jsx("div",{className:"text-4xl",children:"ð"}),e.jsx("h3",{className:"text-lg font-bold text-slate-800",children:c("review_submitted_title")}),e.jsx("p",{className:"text-sm text-slate-500",children:c("review_submitted_text")}),e.jsx("button",{onClick:l,className:"mt-2 px-6 py-2.5 bg-blue-600 hover:bg-blue-700 text-white rounded-lg font-bold text-sm transition-colors",children:c("review_close_button")})]}):e.jsxs(e.Fragment,{children:[e.jsx("h3",{className:"text-lg font-bold text-slate-800 mb-1",children:c("review_modal_title")}),e.jsx("p",{className:"text-xs text-slate-400 mb-4",children:s}),e.jsxs("div",{className:"flex gap-2 mb-4",children:[e.jsx("button",{onClick:()=>p("SITE"),className:`flex-1 py-2 rounded-lg text-sm font-bold border transition-colors ${d==="SITE"?"bg-blue-50 border-blue-300 text-blue-700":"bg-white border-slate-200 text-slate-500"}`,children:c("review_mode_site")}),e.jsx("button",{onClick:()=>p("YANDEX"),className:`flex-1 py-2 rounded-lg text-sm font-bold border transition-colors ${d==="YANDEX"?"bg-red-50 border-red-300 text-red-700":"bg-white border-slate-200 text-slate-500"}`,children:c("review_mode_yandex")})]}),e.jsx("div",{className:"flex items-center gap-1 mb-4",children:Array.from({length:5}).map((D,$)=>e.jsx("button",{onClick:()=>j($+1),children:e.jsx(Oo,{size:26,className:$<y?"fill-amber-400 text-amber-400":"text-slate-200"})},$))}),d==="SITE"?e.jsxs("div",{className:"space-y-3",children:[e.jsx("textarea",{value:b,onChange:D=>h(D.target.value),rows:4,placeholder:c("review_text_placeholder"),className:"w-full px-3 py-2.5 border border-slate-200 rounded-lg text-sm outline-none focus:border-blue-400 resize-none"}),e.jsx("p",{className:`text-[11px] font-medium -mt-1 ${b.trim().length>=rn?"text-emerald-600":"text-slate-400"}`,children:b.trim().length>
57=rn?c("review_text_counter_ok"):c("review_text_counter",{count:b.trim().length,min:rn})}),e.jsx("p",{className:`text-xs font-bold rounded-lg px-3 py-2 border ${o?"text-emerald-700 bg-emerald-50 border-emerald-200":"text-amber-700 bg-amber-50 border-amber-200"}`,children:o?c("review_bonus_hint_site",{withPhoto:ia("SITE",!0,n),withoutPhoto:ia("SITE",!1,n)}):c("review_bonus_window_expired")}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[v.map((D,$)=>e.jsxs("div",{className:"relative w-16 h-16",children:[e.jsx("img",{src:D.preview,alt:"",className:"w-16 h-16 object-cover rounded-lg border border-slate-200"}),e.jsx("button",{onClick:()=>i(z=>z.filter((me,K)=>K!==$)),className:"absolute -top-1.5 -right-1.5 w-5 h-5 bg-slate-800 text-white rounded-full flex items-center justify-center",children:e.jsx(bt,{size:11})})]},$)),v.length<Z&&e.jsxs("label",{className:"w-16 h-16 border-2 border-dashed border-slate-200 rounded-lg flex items-center justify-center cursor-pointer hover:border-blue-300 transition-colors",children:[e.jsx(Yr,{size:18,className:"text-slate-400"}),e.jsx("input",{type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:D=>O(D.target.files)})]})]})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-xs text-slate-500 bg-slate-50 border border-slate-200 rounded-lg p-3 leading-relaxed",children:c("review_yandex_instructions")}),e.jsxs("a",{href:rm,target:"_blank",rel:"noopener noreferrer",className:"flex items-center justify-center gap-1.5 py-2.5 bg-red-50 hover:bg-red-100 border border-red-200 text-red-700 rounded-lg font-bold text-sm transition-colors",children:[e.jsx(Zn,{size:14})," ",c("review_yandex_open_button")]}),e.jsx("input",{type:"text",value:x,onChange:D=>m(D.target.value),placeholder:c("review_yandex_link_placeholder"),className:"w-full px-3 py-2.5 border border-slate-200 rounded-lg text-sm outline-none focus:border-red-400"}),e.jsx("div",{className:"text-center text-[11px] text-slate-400",children:c("review_or")}),N?e.jsxs("div",{className:"relative w-20 h-20 mx-auto",children:[e.jsx("img",{src:N.preview,alt:"",className:"w-20 h-20 object-cover rounded-lg border border-slate-200"}),e.jsx("button",{onClick:()=>R(null),className:"absolute -top-1.5 -right-1.5 w-5 h-5 bg-slate-800 text-white rounded-full flex items-center justify-center",children:e.jsx(bt,{size:11})})]}):e.jsxs("label",{className:"flex items-center justify-center gap-2 py-2.5 border-2 border-dashed border-slate-200 rounded-lg cursor-pointer hover:border-red-300 transition-colors text-xs text-slate-500 font-bold",children:[e.jsx(yi,{size:14})," ",c("review_yandex_upload_screenshot"),e.jsx("input",{type:"file",accept:"image/*",className:"hidden",onChange:D=>D.target.files?.[0]&&R({file:D.target.files[0],preview:URL.createObjectURL(D.target.files[0])})})]}),e.jsx("p",{className:`text-xs font-bold rounded-lg px-3 py-2 border ${o?"text-emerald-700 bg-emerald-50 border-emerald-200":"text-amber-700 bg-amber-50 border-amber-200"}`,children:o?c("review_bonus_hint_yandex",{amount:ia("YANDEX",!0,n)}):c("review_bonus_window_expired")})]}),L&&e.jsx("div",{className:"mt-3 px-3 py-2 bg-red-50 border border-red-200 rounded-lg text-xs text-red-600 font-medium",children:L}),e.jsxs("button",{onClick:F,disabled:S,className:"w-full mt-4 py-2.5 bg-blue-600 hover:bg-blue-700 text-white rounded-lg font-bold text-sm transition-colors disabled:opacity-50 flex items-center justify-center gap-2",children:[S&&e.jsx(rt,{size:14,className:"animate-spin"}),c("review_submit_button")]}),e.jsx("button",{onClick:l,className:"w-full mt-2 py-2 text-slate-400 hover:text-slate-600 text-xs font-medium",children:c("review_skip_button")})]})]})})},ya=["NEW","PAID","PURCHASED","COLLECTING","ASSEMBLED","SHIPPED","RECEIVED"],am={NEW:ss,PAID:Xs,PURCHASED:zn,COLLECTING:Io,ASSEMBLED:xn,SHIPPED:Lt,RECEIVED:Ni,CANCELED:Si},lm=({order:t,onClose:s})=>{const{t:n}=qt();if(!t)return null;const r=t.status==="CANCELED",l=ya.indexOf(t.status),c=!!t.delivery_paid,o=!!t.delivery_invoice,d=l>=ya.indexOf("SHIPPED")&&o;return e.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center bg-black/40 backdrop-blur-sm p-4 animate-in fade-in duration-200",children:e.jsxs("div",{className:"bg-white w-full max-w-lg rounded-2xl shadow-2xl p-6 relative animate-in zoom-in-95 duration-200 max-h-[90vh] overflow-y-auto",children:[e.jsx("button",{onClick:s,className:"absolute right-4 top-4 p-2 bg-slate-50 rounded-full hover:bg-slate-200 text-slate-500",children:e.jsx(bt,{size:20})}),e.jsx("h3",{className:"text-xl font-bold text-slate-800 mb-6",children:n("order_timeline_title")}),r?e.jsxs("div",{className:"flex items-center gap-3 bg-red-50 border border-red-200 rounded-xl p-4",children:[e.jsx(Si,{size:22,className:"text-red-500 shrink-0"}),e.jsx("span",{className:"font-bold text-red-700",children:n("order_timeline_canceled")})]}):e.jsxs("div",{className:"relative pl-4 space-y-7",children:[e.jsx("div",{className:"absolute left-[27px] top-3 bottom-8 w-0.5 bg-slate-200"}),ya.map((p,y)=>{const j=y<=l,b=am[p];return e.jsxs(ct.Fragment,{children:[e.jsxs("div",{className:"relative flex gap-4 items-center",children:[e.jsx("div",{className:`w-6 h-6 rounded-full border-2 border-white shadow-sm shrink-0 z-10 flex items-center justify-center ${j?"bg-green-500":"bg-slate-200"}`,children:j&&e.jsx(b,{size:14,className:"text-white"})}),e.jsx("div",{className:`font-bold text-sm ${j?"text-slate-800":"text-slate-400"}`,children:Kn(p,n)})]}),p==="SHIPPED"&&d&&e.jsxs("div",{className:"relative flex gap-4",children:[e.jsx("div",{className:`w-6 h-6 rounded-full border-2 border-white shadow-sm shrink-0 z-10 flex items-center justify-center ${c?"bg-green-500":"bg-amber-300"}`,children:e.jsx(Ds,{size:14,className:"text-white"})}),e.jsxs("div",{children:[e.jsx("div",{className:`font-bold text-sm ${c?"text-slate-800":"text-amber-600"}`,children:n("order_timeline_delivery_payment")}),e.jsx("div",{className:"text-xs text-slate-500",children:n(c?"order_timeline_delivery_payment_paid":"order_timeline_delivery_payment_pending")})]})]})]},p)})]})]})})},im=["id","display_id","created_at","status","items_count","weight_kg","total_cny","commission_cny","client_preferences","delivery_invoice","delivery_paid","delivery_prepaid_amount","delivery_transferred_at","shipment_group_id","parent_order_id","client_label","photo_report_sent","client_confirmed","partial_ship_requested","logistics_dates","re
57ceived_at","items"].join(","),om=3e4;let Vs=null,Ir=null;const ai=[{rowBg:"bg-indigo-50/70",borderL:"border-l-indigo-500",badgeCls:"bg-indigo-100 text-indigo-700 border-indigo-200",borderT:"border-t-indigo-400",borderB:"border-b-indigo-400"},{rowBg:"bg-emerald-50/70",borderL:"border-l-emerald-500",badgeCls:"bg-emerald-100 text-emerald-700 border-emerald-200",borderT:"border-t-emerald-400",borderB:"border-b-emerald-400"},{rowBg:"bg-violet-50/70",borderL:"border-l-violet-500",badgeCls:"bg-violet-100 text-violet-700 border-violet-200",borderT:"border-t-violet-400",borderB:"border-b-violet-400"},{rowBg:"bg-rose-50/70",borderL:"border-l-rose-500",badgeCls:"bg-rose-100 text-rose-700 border-rose-200",borderT:"border-t-rose-400",borderB:"border-b-rose-400"},{rowBg:"bg-sky-50/70",borderL:"border-l-sky-500",badgeCls:"bg-sky-100 text-sky-700 border-sky-200",borderT:"border-t-sky-400",borderB:"border-b-sky-400"},{rowBg:"bg-amber-50/70",borderL:"border-l-amber-500",badgeCls:"bg-amber-100 text-amber-700 border-amber-200",borderT:"border-t-amber-400",borderB:"border-b-amber-400"}];function cm({initialOrderId:t,initialOpenPacking:s=!1,onInitialOrderOpened:n,commissionSettings:r,cnyRate:l,usdRate:c,userBalance:o=0,onContactManager:d,onReorderOrder:p,resetKey:y,initialTab:j,onInitialTabApplied:b,autoOpenCombinedPayment:h=!1,onAutoOpenCombinedPaymentHandled:v,initialSearchQuery:i,onInitialSearchApplied:x}){const{t:m}=qt(),[N,R]=a.useState([]),[S,C]=a.useState(!0),[L,U]=a.useState("ALL"),[W,re]=a.useState(!1);a.useEffect(()=>{j&&(U(j),b?.())},[j]);const[Z,O]=a.useState(l??13.5),[F,D]=a.useState(!1),[$,z]=a.useState(new Set),[me,K]=a.useState(new Set),[te,I]=a.useState(new Set),[B,Ne]=a.useState(new Set),[Ue,$e]=a.useState(null),[H,le]=a.useState(null),[Qe,k]=a.useState(!1),[xe,de]=a.useState(null);a.useEffect(()=>{h&&L==="DELIVERY_PAYMENT"&&!S&&(k(!0),v?.())},[h,L,S]),a.useEffect(()=>{!Vs||S||Vs.userId===yt()&&(Vs.rows=N)},[N,S]);const[V,ye]=a.useState(null),[Ie,Oe]=a.useState(null),[we,Le]=a.useState(null),[_t,jt]=a.useState(null),[dt,gt]=a.useState(new Set),[ht,qe]=a.useState(()=>Date.now());a.useEffect(()=>{const g=setInterval(()=>qe(Date.now()),6e4);return()=>clearInterval(g)},[]);const[it,Ge]=a.useState(null),[St,Pt]=a.useState(!1);a.useEffect(()=>{y!==void 0&&y>0&&ye(null)},[y]),a.useEffect(()=>{const g=new URLSearchParams(window.location.search);V?g.set("orderId",V.id):g.delete("orderId");const Q=g.toString();window.history.replaceState({},"",window.location.pathname+(Q?`?${Q}`:""))},[V?.id]);const Ut=async g=>{const{data:Q}=await Re("orders",{id:g},{select:"*",single:!0});Q&&ye(ne=>ne&&ne.id===g?{...ne,...Q}:ne)},xt=g=>{ye(g),Ut(g.id)},zt=a.useRef(!1);a.useEffect(()=>{if(zt.current||S||V)return;const g=new URLSearchParams(window.location.search).get("orderId");if(!g){zt.current=!0;return}const Q=N.find(ne=>ne.id===g);Q&&xt(Q),zt.current=!0},[S,N,V]),a.useEffect(()=>()=>{const g=new URLSearchParams(window.location.search);if(g.has("orderId")){g.delete("orderId");const Q=g.toString();window.history.replaceState({},"",window.location.pathname+(Q?`?${Q}`:""))}},[]);const[J,We]=a.useState(null),[oe,Y]=a.useState(!1),[Se,ve]=a.useState(!1),[T,ke]=a.useState(new Set),[be,Ae]=a.useState(!1),E=["PAID","PURCHASED","COLLECTING"],[se,ee]=a.useState("");a.useEffect(()=>{i&&(ee(i),U("ALL"),x?.())},[i]);const[u,_]=a.useState(""),[P,A]=a.useState(""),[M,ie]=a.useState(null),[ge,w]=a.useState(null),fe=g=>{if(M!==g){ie(g),w("asc");return}if(ge==="asc"){w("desc");return}ie(null),w(null)},pe={NEW:0,PAID:1,PURCHASED:2,COLLECTING:3,ASSEMBLED:4,SHIPPED:5,RECEIVED:6,CANCELED:7},je=["PURCHASED","SHIPPED","RECEIVED","COLLECTING","ASSEMBLED"],ze=g=>je.includes(g.status)&&g.client_preferences?.fixed_cny_rate?g.client_preferences.fixed_cny_rate:Z,[mt,Tt]=a.useState(c??92);a.useEffect(()=>{l&&O(l)},[l]),a.useEffect(()=>{c&&Tt(c)},[c]),a.useEffect(()=>{const g=ne=>Number(ne.rate)||0;(!l||!c)&&(async()=>{try{const{data:ne}=await Re("app_settings",{},{select:"currencies",single:!0}),De=ne?.currencies;if(Array.isArray(De)&&De.length>0){const Ee=De.find(nt=>nt.code==="CNY");Ee&&O(g(Ee));const Pe=De.find(nt=>nt.code==="USD");Pe&&Tt(g(Pe));return}}catch{}try{const ne=localStorage.getItem("tradehub_currencies");if(ne){const De=JSON.parse(ne),Ee=De.find(nt=>nt.code==="CNY");Ee&&O(g(Ee));const Pe=De.find(nt=>nt.code==="USD");Pe&&Tt(g(Pe))}}catch{}})(),G({useCache:!0})},[]),a.useEffect(()=>{if(!t)return;const g=s;Re("orders",{id:t},{select:"*",single:!0}).then(({data:Q})=>{Q&&(R(ne=>ne.map(De=>De.id===t?Q:De)),ye(Q),Pt(!!g),n?.())})},[t]);const G=async(g={})=>{try{const Q=yt();if(!Q)return;const ne=(nt,ft)=>{R(nt),D(ft),C(!1),he(nt.map(It=>It.id)),_e(),q(Q,nt)};if(g.useCache&&Vs&&Vs.userId===Q&&Date.now()-Vs.fetchedAt<om){ne(Vs.rows,Vs.canEditOrders);return}if(g.useCache&&Ir&&Ir.userId===Q){const nt=await Ir.promise;nt&&ne(nt.rows,nt.canEditOrders);return}const De=(async()=>{try{const{data:nt}=await Re("users",{id:Q},{select:"can_edit_orders",single:!0}),ft=!!nt?.can_edit_orders,{data:It,error:Vt}
57=await Re("orders",{user_id:Q},{select:im,order:"created_at.desc",limit:50});return Vt||!It?null:(Vs={userId:Q,rows:It,canEditOrders:ft,fetchedAt:Date.now()},{rows:It,canEditOrders:ft})}catch{return null}})(),Ee={userId:Q,promise:De};Ir=Ee;const Pe=await De;Ir===Ee&&(Ir=null),Pe&&ne(Pe.rows,Pe.canEditOrders)}catch{}finally{C(!1)}},q=async(g,Q)=>{const ne=new Date().toISOString(),{data:De}=await Re("card_reservations",{user_id:g},{select:"order_id,expires_at"}),Ee=new Set((De||[]).filter(Pe=>Pe.order_id&&(!Pe.expires_at||Pe.expires_at>ne)).map(Pe=>Pe.order_id));for(const Pe of Q)Pe.status==="NEW"&&typeof window<"u"&&window.localStorage.getItem(`payment_req_${Pe.id}`)&&Ee.add(Pe.id);Ne(Ee)},he=async g=>{if(g.length===0)return;const Q=yt();if(!Q)return;const{data:ne}=await Re("transactions",{user_id:Q},{select:"order_id,status,type"}),De=ne?ne.filter(Ee=>g.includes(Ee.order_id)&&["COMPLETED","PENDING"].includes(Ee.status)&&["TOPUP","PAYMENT","ORDER_PAYMENT","DELIVERY_PAYMENT"].includes(Ee.type)):null;if(De){const Ee=new Set(De.filter(ft=>ft.status==="COMPLETED"&&ft.type!=="DELIVERY_PAYMENT").map(ft=>ft.order_id)),Pe=new Set(De.filter(ft=>ft.status==="PENDING"&&ft.type!=="DELIVERY_PAYMENT").map(ft=>ft.order_id)),nt=new Set(De.filter(ft=>ft.status==="PENDING"&&ft.type==="DELIVERY_PAYMENT").map(ft=>ft.order_id));z(Ee),K(Pe),I(nt)}},_e=async()=>{const g=yt();if(!g)return;const{data:Q}=await Re("reviews",{user_id:g},{select:"order_id"});Q&>(new Set(Q.map(ne=>ne.order_id).filter(Boolean)))},Xe=g=>{if(dt.has(g.id))return e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs font-bold text-emerald-600 bg-emerald-50 border border-emerald-100 px-3 py-1.5 rounded-lg",children:[e.jsx(ss,{size:13})," ",m("review_submitted_badge")]});const Q=g.received_at,ne=Ti(Q,new Date(ht)),De=ne?xc(Q,ht):null;return e.jsxs("div",{className:"flex flex-col items-center gap-1",children:[e.jsxs("div",{className:ne?"group flex flex-col items-center":"",children:[ne&&e.jsx("img",{src:wr("/button/gift-icon.webp"),alt:"",className:"w-8 h-8 mb-1 group-hover:animate-gift-wobble"}),e.jsx("button",{onClick:Ee=>{Ee.stopPropagation(),Oe(g)},className:`inline-flex items-center gap-1.5 px-4 py-2 rounded-lg text-xs font-bold transition-colors ${ne?"bg-orange-500 text-white hover:bg-orange-600 shadow-sm shadow-orange-200":"bg-slate-100 text-slate-600 hover:bg-slate-200"}`,children:m("review_cta_button")})]}),De!=null&&(()=>{const{days:Ee,hours:Pe,minutes:nt}=mc(De);return e.jsx("span",{className:"text-[10px] font-bold text-amber-600 whitespace-nowrap",children:Ee>0?m("review_bonus_remaining_days",{days:Ee,hours:Pe}):m("review_bonus_remaining_hours",{hours:Pe,minutes:nt})})})()]})},Ct=g=>e.jsx("button",{onClick:Q=>{Q.stopPropagation(),Le(g)},title:m("order_print_title"),className:"inline-flex items-center justify-center w-8 h-8 rounded-lg bg-blue-600 text-white hover:bg-blue-700 shadow-sm shadow-blue-200 transition-colors",children:e.jsx(Ya,{size:15})}),Gt=async()=>{if(it){Y(!0);try{if(await Fr(it.id)){alert(m("order_details_cannot_edit_reserved")),Ge(null);return}const{error:g}=await ds("orders",{id:it.id});if(g)throw new Error(g);const{data:Q}=await Re("orders",{id:it.id},{select:"id"});if(Q&&Q.length>0)throw new Error(m("orders_delete_failed_history"));R(N.filter(ne=>ne.id!==it.id)),Ge(null)}catch(g){alert(m("orders_delete_error_prefix")+g.message)}finally{Y(!1)}}},Nt=async()=>{if(!Ue)return;const g=Ue.id;$e(null),R(ne=>ne.map(De=>De.id===g?{...De,status:"PAID"}:De));const Q=N.find(ne=>ne.id===g);Q&&(V&&V.id===g&&ye(ne=>ne&&ne.id===g?{...ne,...Q,status:"PAID"}:ne),setTimeout(()=>We(Q),300)),G()},Wt=async()=>{const g=J?.id;if(We(null),await G(),g&&V?.id===g){const{data:Q}=await Re("orders",{id:g},{select:"client_preferences",single:!0});Q&&ye(ne=>ne&&{...ne,client_preferences:Q.client_preferences})}},os=N.filter(g=>E.includes(g.status)),As=g=>{ke(Q=>{const ne=new Set(Q);return ne.has(g)?ne.delete(g):ne.add(g),ne})},cs=async()=>{if(!(T.size<2)){Ae(!0);try{const g=crypto.randomUUID(),Q=Array.from(T),{error:ne}=await Je("orders",{id:`in.(${Q.join(",")})`},{shipment_group_id:g});if(ne){alert(m("orders_group_error"));return}const De=N.filter(It=>Q.includes(It.id)),Ee=De.map(It=>It.display_id||It.id).join(" и "),Pe=new Date().toISOString(),nt=yt(),ft=De.find(It=>It.client_preferences?.deliveryData?.recipientName);if(ft){const It=ft.client_preferences.deliveryData;for(const Vt of De){if(Vt.id===ft.id||Vt.client_preferences?.deliveryData?.recipientName)continue;const fs=Vt.client_preferences||{};await Je("orders",{id:Vt.id},{client_preferences:{...fs,deliveryData:It}}).catch(f=>{})}}
57await st("notifications",{user_id:null,type:"SYSTEM",title:"ð¦ ÐÐ»Ð¸ÐµÐ½Ñ Ð¾Ð±Ñединил заказÑ",text:`ÐÐ»Ð¸ÐµÐ½Ñ Ñ
оÑÐµÑ Ð¾ÑпÑавиÑÑ Ð²Ð¼ÐµÑÑе: ${Ee}`,date:Pe,is_read:!1}),nt&&await st("notifications",{user_id:nt,type:"SYSTEM",title:"ð ÐÐ°ÐºÐ°Ð·Ñ Ð¾Ð±ÑединенÑ",text:`ÐÑ Ð¾Ð±Ñединили Ð·Ð°ÐºÐ°Ð·Ñ ${Ee} â они бÑдÑÑ Ð¾ÑпÑÐ°Ð²Ð»ÐµÐ½Ñ Ð²Ð¼ÐµÑÑе`,date:Pe,is_read:!1}),ve(!1),ke(new Set),await G()}catch{}finally{Ae(!1)}}},Xt=async g=>{Ae(!0);try{const ne=N.filter(Pe=>Pe.shipment_group_id===g).map(Pe=>Pe.display_id||Pe.id).join(" и "),{error:De}=await Je("orders",{shipment_group_id:g},{shipment_group_id:null});if(De){alert(m("orders_ungroup_error"));return}const Ee=yt();Ee&&await st("notifications",{user_id:Ee,type:"SYSTEM",title:"ð ÐÐ°ÐºÐ°Ð·Ñ ÑазделенÑ",text:`ÐÑ Ñазделили Ð·Ð°ÐºÐ°Ð·Ñ ${ne} â они бÑдÑÑ Ð¾ÑпÑÐ°Ð²Ð»ÐµÐ½Ñ Ð¿Ð¾ оÑделÑноÑÑи`,date:new Date().toISOString(),is_read:!1}),await G()}catch{}finally{Ae(!1)}},Mt=g=>Kn(g,m),Ls=g=>{const Q=g.status,ne=!!g.delivery_invoice,De=!!g.delivery_paid;if(ne&&!De)return e.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs font-bold border whitespace-nowrap bg-orange-100 text-orange-700 border-orange-200",children:m("orders_badge_delivery_payment")});if(Q==="RECEIVED")return e.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs font-bold border whitespace-nowrap bg-green-100 text-green-700 border-green-200",children:m("orders_status_received")});if(De)return e.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs font-bold border whitespace-nowrap bg-emerald-50 text-emerald-700 border-emerald-200",children:m("orders_badge_delivery_paid")});const Ee=Q==="NEW"?m("orders_badge_new_topay"):Mt(Q);let Pe="bg-slate-100 text-slate-600";switch(Q){case"NEW":Pe="bg-blue-50 text-blue-700 border-blue-100";break;case"PAID":$.has(g.id)?Pe="bg-green-50 text-green-700 border-green-100":Pe="bg-orange-50 text-orange-700 border-orange-100";break;case"PURCHASED":Pe="bg-purple-50 text-purple-700 border-purple-100";break;case"COLLECTING":Pe="bg-amber-50 text-amber-700 border-amber-100";break;case"ASSEMBLED":Pe="bg-orange-50 text-orange-700 border-orange-100";break;case"SHIPPED":Pe="bg-green-50 text-green-700 border-green-100";break}return e.jsx("span",{className:`px-2 py-0.5 rounded-full text-xs font-bold border whitespace-nowrap ${Pe}`,children:Ee})},Ft=a.useMemo(()=>{const g=N.filter(Ee=>{if(L==="CANCELED")return Ee.status==="CANCELED";if(Ee.status==="CANCELED")return!1;if(L==="COLLECTING_GROUP")return["PURCHASED","COLLECTING","ASSEMBLED"].includes(Ee.status);if(L==="DELIVERY_PAYMENT")return!!Ee.delivery_invoice&&!Ee.delivery_paid;if(L==="DELIVERY_PAID")return!!Ee.delivery_paid&&Ee.status!=="RECEIVED";if(L==="SHIPPED")return Ee.status==="SHIPPED"&&!Ee.delivery_invoice;if(L!=="ALL"&&Ee.status!==L)return!1;const Pe=(Ee.created_at||"").slice(0,10);return!(u&&Pe<u||P&&Pe>P)}).sort((Ee,Pe)=>{if(!M||!ge)return 0;const nt=ge==="asc"?1:-1;switch(M){case"date":return(Ee.created_at||"").localeCompare(Pe.created_at||"")*nt;case"status":{const ft=pe[Ee.status]??99,It=pe[Pe.status]??99;return(ft-It)*nt}case"items":return((Ee.items_count||0)-(Pe.items_count||0))*nt;
57case"finance":{const ft=(Ee.total_cny+(Ee.commission_cny||0))*ze(Ee),It=(Pe.total_cny+(Pe.commission_cny||0))*ze(Pe);return(ft-It)*nt}case"shipped":{const ft=Ee.logistics_dates?.shipped||"",It=Pe.logistics_dates?.shipped||"";return ft.localeCompare(It)*nt}default:return 0}}),Q=[],ne=new Set;for(const Ee of g){if(ne.has(Ee.id))continue;const Pe=Ee.shipment_group_id;Pe?g.filter(nt=>nt.shipment_group_id===Pe).forEach(nt=>{ne.add(nt.id),Q.push(nt)}):(ne.add(Ee.id),Q.push(Ee))}if(!se)return Q;const De=se.toLowerCase();return Q.filter(Ee=>(Ee.display_id||"").toLowerCase().includes(De))},[N,L,u,P,M,ge,Z,se]),{groupColorMap:Es,groupPosMap:Zt}=a.useMemo(()=>{const g=new Map,Q=new Map;let ne=0;const De=new Map;return Ft.forEach(Ee=>{const Pe=Ee.shipment_group_id;Pe&&(g.has(Pe)||g.set(Pe,ne++%ai.length),De.has(Pe)||De.set(Pe,[]),De.get(Pe).push(Ee.id))}),Ft.forEach(Ee=>{const Pe=Ee.shipment_group_id;if(Pe){const nt=De.get(Pe),ft=nt.indexOf(Ee.id);Q.set(Ee.id,{isFirst:ft===0,isLast:ft===nt.length-1,groupNum:(g.get(Pe)??0)+1})}}),{groupColorMap:g,groupPosMap:Q}},[Ft]),Ht=N.filter(g=>!!g.delivery_invoice&&!g.delivery_paid),kr=Ht.length,pr=N.filter(g=>g.status==="CANCELED").length,Rr=N.filter(g=>g.status==="NEW").length,xs=Ht.reduce((g,Q)=>{const ne=Q.delivery_invoice;return ne?g+(Math.round((ne.totalUSD||0)*mt)||ne.totalRUB||0):g},0),fr=g=>{Ht.length>1&&xs>=2e4?de(g):le(g)};if(V)return e.jsxs(e.Fragment,{children:[e.jsx(Xx,{order:V,onClose:()=>{ye(null),Pt(!1),G()},cnyRate:Z,usdRate:c??90,commissionSettings:r,canEditOrders:F,userBalance:o,initialShowPackingInfo:St,onUngroup:Xt,onPaymentSuccess:()=>{const g={...V,status:"PAID"};ye(g),R(Q=>Q.map(ne=>ne.id===g.id?g:ne)),setTimeout(()=>We(g),300)},onPayDelivery:()=>V&&fr(V),onEditDelivery:()=>V&&We(V),onContactManager:()=>{ye(null),Pt(!1),window.dispatchEvent(new CustomEvent("tradehub:navigate",{detail:"MESSAGES"}))},onLabelSaved:(g,Q)=>{R(ne=>ne.map(De=>De.id===g?{...De,client_label:Q}:De))}}),J&&e.jsx(Ua,{orderId:J.id,onClose:()=>We(null),onSave:Wt}),H&&e.jsx(Zl,{order:H,currentUsdRate:mt,onClose:()=>le(null),onSuccess:async()=>{le(null),G();const{data:g}=await Re("orders",{id:H.id},{select:"*",single:!0});g&&ye(Q=>Q&&{...Q,...g})}}),xe&&e.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-slate-900/60 backdrop-blur-sm p-4",children:e.jsxs("div",{className:"bg-white rounded-2xl w-full max-w-sm shadow-2xl p-6 text-center space-y-4",children:[e.jsx("div",{className:"w-14 h-14 bg-orange-50 text-orange-600 rounded-full flex items-center justify-center mx-auto",children:e.jsx(Lt,{size:26})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-bold text-slate-900 mb-1",children:m("orders_delivery_pay_choice_title")}),e.jsx("p",{className:"text-sm text-slate-500",children:m("orders_delivery_pay_choice_text",{count:Ht.length,amount:xs.toLocaleString("ru-RU")})})]}),e.jsxs("div",{className:"flex flex-col gap-2 pt-1",children:[e.jsx("button",{onClick:()=>{de(null),k(!0)},className:"w-full py-3 bg-orange-500 text-white rounded-xl font-bold hover:bg-orange-600 transition-colors",children:m("orders_delivery_pay_choice_all",{count:Ht.length})}),e.jsx("button",{onClick:()=>{const g=xe;de(null),le(g)},className:"w-full py-3 bg-slate-100 text-slate-700 rounded-xl font-bold hover:bg-slate-200 transition-colors",children:m("orders_delivery_pay_choice_one")})]})]})}),Qe&&e.jsx(si,{orders:Ht.map(g=>{const Q=g.delivery_invoice,ne=g.delivery_prepaid_amount??0,De=Q?Math.max((Math.round((Q.totalUSD||0)*mt)||Q.totalRUB||0)-ne,0):0;return{id:g.id,displayId:g.display_id||g.id,amount:De}}).filter(g=>g.amount>0),onClose:()=>k(!1),onSuccess:()=>{k(!1),G()}})]});const Cs=[{id:"ALL",label:m("orders_tab_all")},{id:"NEW",label:m("orders_tab_new")},{id:"PAID",label:m("orders_tab_paid")},{id:"PURCHASED",label:m("orders_status_purchased")},{id:"COLLECTING",label:m("orders_status_collecting")},{id:"SHIPPED",label:m("orders_status_shipped")},{id:"DELIVERY_PAYMENT",label:m("orders_badge_delivery_payment")},{id:"DELIVERY_PAID",label:m("orders_tab_delivery_paid")},{id:"RECEIVED",label:m("orders_status_received")},{id:"CANCELED",label:m("orders_tab_archive")}],hr=N.reduce((g,Q)=>
57{const ne=Q.total_cny+(Q.commission_cny||0);return g+Math.round(ne*ze(Q))},0),Tr=["ASSEMBLED","SHIPPED","RECEIVED"],qs=N.some(g=>!Tr.includes(g.status)),Ms=N.reduce((g,Q)=>g+(Q.weight_kg||0),0),zs=N.filter(g=>g.status==="RECEIVED").length,ps=N.reduce((g,Q)=>{const ne=Q.delivery_invoice;return ne?g+(Math.round((ne.totalUSD||0)*mt)||ne.totalRUB||0):g},0),Ws=N.filter(g=>!["NEW","CANCELED"].includes(g.status)),br=Ws.length>0?Math.round(Ws.reduce((g,Q)=>g+Math.round((Q.total_cny+(Q.commission_cny||0))*ze(Q)),0)/Ws.length):0,ks=g=>{if(!g)return null;if(/^\d{2}\.\d{2}\.\d{4}$/.test(g)){const[ne,De,Ee]=g.split(".").map(Number);return new Date(Ee,De-1,ne).getTime()}const Q=new Date(g).getTime();return isNaN(Q)?null:Q},nr=N.filter(g=>{const Q=g.logistics_dates||{};return g.status==="RECEIVED"&&Q.shipped&&Q.arrivalActual}),gr=nr.length>0?Math.round(nr.reduce((g,Q)=>{const ne=Q.logistics_dates||{},De=ks(ne.shipped),Ee=ks(ne.arrivalActual);return!De||!Ee?g:g+(Ee-De)/(1e3*60*60*24)},0)/nr.length):null,_r=async()=>{const g=(await uc(async()=>{const{default:It}=await import("./exceljs.min-DP_NmrKk.js").then(Vt=>Vt.e);return{default:It}},__vite__mapDeps([0,1,2]))).default,Q=new g.Workbook,ne=Q.addWorksheet(m("orders_excel_sheet_name"));ne.columns=[{header:m("orders_excel_col_id"),key:"id",width:18},{header:m("orders_excel_col_date"),key:"date",width:14},{header:m("orders_excel_col_status"),key:"status",width:20},{header:m("orders_excel_col_items"),key:"items",width:13},{header:m("orders_excel_col_weight"),key:"weight",width:10},{header:m("orders_excel_col_cny"),key:"cny",width:13},{header:m("orders_excel_col_rub"),key:"rub",width:14},{header:m("orders_excel_col_shipped"),key:"shipped",width:15},{header:m("orders_excel_col_arrival"),key:"arrival",width:18}],ne.getRow(1).font={bold:!0},ne.getRow(1).fill={type:"pattern",pattern:"solid",fgColor:{argb:"FFE8F0FE"}},Ft.forEach(It=>{const Vt=It.logistics_dates||{}
57,fs=It.total_cny+(It.commission_cny||0);ne.addRow({id:It.display_id||It.id,date:(It.created_at||"").slice(0,10),status:It.status==="NEW"?m("orders_tab_new"):Kn(It.status,m),items:It.items_count||0,weight:It.weight_kg||0,cny:+fs.toFixed(2),rub:Math.round(fs*ze(It)),shipped:Vt.shipped||"",arrival:Vt.arrivalExpected||""})});const De=Ft.length+2;ne.getCell(`F${De}`).value={formula:`SUM(F2:F${De-1})`},ne.getCell(`G${De}`).value={formula:`SUM(G2:G${De-1})`},ne.getCell(`F${De}`).font={bold:!0},ne.getCell(`G${De}`).font={bold:!0};const Ee=await Q.xlsx.writeBuffer(),Pe=new Blob([Ee],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}),nt=URL.createObjectURL(Pe),ft=document.createElement("a");ft.href=nt,ft.download=`мои_заказÑ_${new Date().toISOString().slice(0,10)}.xlsx`,ft.click(),URL.revokeObjectURL(nt)};if(S)return e.jsxs("div",{className:"flex flex-col items-center justify-center min-h-[400px]",children:[e.jsx(rt,{className:"w-10 h-10 text-blue-600 animate-spin mb-4"}),e.jsx("p",{className:"text-slate-500",children:m("orders_loading")})]});const ar={моÑква:0,"моÑковÑÐºÐ°Ñ Ð¾Ð±Ð»Ð°ÑÑÑ":0,кемеÑово:0,"ÑанкÑ-пеÑеÑбÑÑг":2,Ñпб:2,пиÑеÑ:2,екаÑеÑинбÑÑг:4,"нижний новгоÑод":2,казанÑ:2,ÑамаÑа:3,ÑÑа:3,пеÑмÑ:3,ÑелÑбинÑк:4,омÑк:5,новоÑибиÑÑк:5,баÑнаÑл:5,ÑомÑк:6,кÑаÑноÑÑÑк:7,иÑкÑÑÑк:8,"Ñлан-ÑдÑ":9,ÑиÑа:9,Ñ
абаÑовÑк:11,владивоÑÑок:11,ÑкÑÑÑк:12,магадан:14,"ÑоÑÑов-на-донÑ":3,кÑаÑнодаÑ:3,воÑонеж:2,волгогÑад:3,ÑаÑаÑов:3,оÑенбÑÑг:4,ÑÑменÑ:4,ÑÑÑгÑÑ:6,"Ñ
анÑÑ-манÑийÑк":6,мÑÑманÑк:4,аÑÑ
ангелÑÑк:3,калинингÑад:4,аÑÑÑаÑ
анÑ:4,маÑ
аÑкала:5},Dr=7,lr=N.filter(g=>{if(!g.delivery_paid||g.status==="RECEIVED"||g.status==="CANCELED")return!1;const Q=g.delivery_transferred_at;if(!Q)return!1;const ne=(g.client_preferences?.deliveryData?.city||"").toLowerCase().trim(),De=ar[ne]??Dr,Ee=new Date(Q).getTime()+De*24*60*60*1e3;return Date.now()>=Ee});return e.jsxs("div",{className:"w-full max-w-full px-4 md:px-6 xl:px-2 mx-auto space-y-8 pb-20",children:[lr.map(g=>e.jsxs("div",{className:"w-full bg-gradient-to-r from-orange-500 to-amber-500 rounded-2xl p-5 shadow-lg flex flex-col sm:flex-row items-start sm:items-center gap-4",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(Lt,{size:20,className:"text-white shrink-0"}),e.jsx("span",{className:"font-black text-white text-base",children:m("orders_cargo_in_moscow")})]}),e.jsxs("p",{className:"text-orange-100 text-sm font-medium",children:[m("orders_confirm_receipt_prefix")," ",e.jsx("strong",{className:"text-white",children:g.display_id||g.id})," â ",m("orders_confirm_receipt_suffix")]})]}),e.jsxs("div",{className:"flex gap-2 w-full sm:w-auto shrink-0",children:[e.jsxs("button",{onClick:async()=>{const Q=new Date().toISOString(),{error:ne}=await Je("orders",{id:g.id},{status:"RECEIVED",received_at:Q});if(ne){alert(m("orders_status_update_error_prefix")+ne);return}await st("notifications",{user_id:null,type:"ORDER",title:`ÐÐ»Ð¸ÐµÐ½Ñ Ð¿Ð¾Ð´ÑвеÑдил полÑÑение â ${g.display_id||g.id}`,text:"ÐÐ»Ð¸ÐµÐ½Ñ Ð¿Ð¾Ð´ÑвеÑдил полÑÑение заказа.",date:new Date().toISOString(),is_read:!1,link:g.id}),R(De=>De.map(Ee=>Ee.id===g.id?{...Ee,status:"RECEIVED",received_at:Q}:Ee)),Oe({...g,status:"RECEIVED",received_at:Q})},className:"flex-1 sm:flex-none flex items-center justify-center gap-1.5 bg-white text-green-700 font-black px-4 py-2.5 rounded-xl text-sm hover:bg-green-50 transition-colors shadow-sm",children:[e.jsx(as,{size:16})," ",m("orders_received_button")]}),e.jsxs("button",{onClick:d,className:"flex-1 sm:flex-none flex items-center justify-center gap-1.5 bg-white/20 hover:bg-white/30 text-white font-black px-4 py-2.5 rounded-xl text-sm transition-colors border border-white/40",children:[e.jsx(Fs,{size:16})," ",m("orders_has_problem_button")]})]})]},g.id)),e.jsxs("button",{onClick:()=>re(g=>!g),className:"md:hidden w-full flex items-center justify-between bg-white rounded-2xl px-4 py-3 border border-slate-200 shadow-sm",children:[e.jsx("span",{className:"font-bold text-slate-700 text-sm",children:m("orders_stats_toggle")}),W?e.jsx(qr,{size:20,className:"text-slate-400"}):e.jsx(er,{size:20,className:"text-slate-400"})]}),e.jsxs("div",{className:`${W?"grid":"hidden"} md:grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-3 sm:gap-4`,"data-tour":"order-stats",children:[e.jsxs("div",{className:"bg-white rounded-2xl p-4 sm:p-5 border border-slate-200 shadow-sm flex items-center gap-3 sm:gap-4",children:[e.jsx("div",{className:"w-10 h-10 sm:w-11 sm:h-11 rounded-xl bg-blue-50 flex items-center justify-center text-blue-600 shrink-0",children:e.jsx(Po,{size:20})}),e.jsxs("div",{children:[e.jsxs("div",{className:"text-lg sm:text-xl font-bold text-slate-900",children:[hr.toLocaleStr
57ing("ru-RU")," â½"]}),e.jsx("div",{className:"text-xs text-slate-500 font-bold uppercase tracking-wide",children:m(qs?"orders_stats_excl_refunds":"orders_stats_incl_refunds")})]})]}),e.jsxs("div",{className:"bg-white rounded-2xl p-4 sm:p-5 border border-slate-200 shadow-sm flex items-center gap-3 sm:gap-4",children:[e.jsx("div",{className:"w-10 h-10 sm:w-11 sm:h-11 rounded-xl bg-purple-50 flex items-center justify-center text-purple-600 shrink-0",children:e.jsx(Fn,{size:20})}),e.jsxs("div",{children:[e.jsxs("div",{className:"text-lg sm:text-xl font-bold text-slate-900",children:[Ms.toFixed(2)," ",m("orders_unit_kg")]}),e.jsx("div",{className:"text-xs text-slate-500 font-bold uppercase tracking-wide",children:m("orders_stats_total_weight")})]})]}),e.jsxs("div",{className:"bg-white rounded-2xl p-4 sm:p-5 border border-slate-200 shadow-sm flex items-center gap-3 sm:gap-4",children:[e.jsx("div",{className:"w-10 h-10 sm:w-11 sm:h-11 rounded-xl bg-green-50 flex items-center justify-center text-green-600 shrink-0",children:e.jsx(as,{size:20})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-lg sm:text-xl font-bold text-slate-900",children:zs}),e.jsx("div",{className:"text-xs text-slate-500 font-bold uppercase tracking-wide",children:m("orders_stats_received_count")})]})]}),e.jsxs("div",{className:"bg-white rounded-2xl p-4 sm:p-5 border border-slate-200 shadow-sm flex items-center gap-3 sm:gap-4",children:[e.jsx("div",{className:"w-10 h-10 sm:w-11 sm:h-11 rounded-xl bg-orange-50 flex items-center justify-center text-orange-600 shrink-0",children:e.jsx(Lt,{size:20})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-lg sm:text-xl font-bold text-slate-900",children:ps>0?ps.toLocaleString("ru-RU")+" â½":"â"}),e.jsx("div",{className:"text-xs text-slate-500 font-bold uppercase tracking-wide",children:m("orders_stats_delivery_paid")})]})]}),e.jsxs("div",{className:"bg-white rounded-2xl p-4 sm:p-5 border border-slate-200 shadow-sm flex items-center gap-3 sm:gap-4",children:[e.jsx("div",{className:"w-10 h-10 sm:w-11 sm:h-11 rounded-xl bg-indigo-50 flex items-center justify-center text-indigo-600 shrink-0",children:e.jsx(Xs,{size:20})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-lg sm:text-xl font-bold text-slate-900",children:br>0?br.toLocaleString("ru-RU")+" â½":"â"}),e.jsx("div",{className:"text-xs text-slate-500 font-bold uppercase tracking-wide",children:m("orders_stats_avg_check")})]})]}),e.jsxs("div",{className:"bg-white rounded-2xl p-4 sm:p-5 border border-slate-200 shadow-sm flex items-center gap-3 sm:gap-4",children:[e.jsx("div",{className:"w-10 h-10 sm:w-11 sm:h-11 rounded-xl bg-sky-50 flex items-center justify-center text-sky-600 shrink-0",children:e.jsx(Un,{size:20})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-lg sm:text-xl font-bold text-slate-900",children:gr!==null?m("orders_days_short",{count:gr}):"â"}),e.jsx("div",{className:"text-xs text-slate-500 font-bold uppercase tracking-wide",children:m("orders_stats_avg_delivery_time")})]})]})]}),e.jsxs("div",{className:"space-y-6 min-w-0",children:[e.jsx("div",{className:"flex justify-between items-center",children:e.jsx("h1",{className:"text-2xl font-bold text-slate-900",children:m("orders_history_title")})}),e.jsx("div",{className:"flex gap-2 overflow-x-auto pb-2 scrollbar-hide","data-tour":"order-tabs",children:Cs.map(g=>{const Q=g.id==="DELIVERY_PAYMENT",ne=g.id==="CANCELED",De=g.id==="NEW",Ee=Q&&kr>0||ne&&pr>0||De&&Rr>0,Pe=Q?kr:ne?pr:De?Rr:0,nt=L===g.id;let ft="";return nt?ft=Ee?"bg-orange-500 text-white shadow-lg shadow-orange-200":"bg-slate-900 text-white shadow-lg shadow-slate-200":ft=Ee?"bg-orange-50 text-orange-600 border border-orange-300 hover:bg-orange-100":"bg-white text-slate-500 hover:bg-slate-50 hover:text-slate-900 border border-slate-200",e.jsxs("button",{onClick:()=>U(g.id),className:`px-3 py-1.5 rounded-xl font-bold text-xs whitespace-nowrap transition-all ${ft}`,children:[g.label,Ee&&e.jsx("span",{className:`ml-2 text-xs font-bold px-1.5 py-0.5 rounded-full ${nt?"bg-white/20 text-white":"bg-orange-500 text-white"}`,children:Pe})]},g.id)})}),L==="DELIVERY_PAYMENT"&&Ht.length>0&&e.jsxs("div",{className:"bg-orange-50 border border-orange-200 rounded-xl px-4 py-3 flex items-center gap-3 flex-wrap",children:[e.jsx(Lt,{size:16,className:"text-orange-600 shrink-0"}),e.jsxs("span",{className:"text-sm font-bold text-orange-700 flex-1",children:[m("orders_total_delivery_debt",{amount:xs.toLocaleStr
57ing("ru-RU")})," (",m("orders_count_label",{count:Ht.length}),")"]}),e.jsxs("button",{onClick:()=>k(!0),disabled:xs<2e4,className:"flex items-center gap-1.5 bg-orange-500 text-white px-4 py-1.5 rounded-lg text-sm font-bold disabled:opacity-40 disabled:cursor-not-allowed hover:bg-orange-600 transition-colors",children:[e.jsx(Lt,{size:14})," ",m("orders_pay_multiple_button")]})]}),Se&&e.jsxs("div",{className:"bg-orange-50 border border-orange-200 rounded-xl px-4 py-3 flex items-center gap-3 flex-wrap",children:[e.jsx(jn,{size:16,className:"text-orange-600 shrink-0"}),e.jsx("span",{className:"text-sm font-bold text-orange-700 flex-1",children:m("orders_select_2plus",{count:T.size})}),e.jsxs("button",{onClick:cs,disabled:T.size<2||be,className:"flex items-center gap-1.5 bg-orange-500 text-white px-4 py-1.5 rounded-lg text-sm font-bold disabled:opacity-40 hover:bg-orange-600 transition-colors",children:[be?e.jsx(rt,{size:14,className:"animate-spin"}):e.jsx(jn,{size:14}),m("orders_confirm_button")]}),e.jsx("button",{onClick:()=>{ve(!1),ke(new Set)},className:"text-sm font-bold text-slate-500 hover:text-slate-700",children:m("orders_cancel_button")})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-stretch sm:items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 bg-white border border-slate-200 rounded-xl px-3 py-2 text-sm flex-1 sm:max-w-[200px]",children:[e.jsx(Qn,{size:14,className:"text-slate-400 shrink-0"}),e.jsx("input",{type:"text",value:se,onChange:g=>ee(g.target.value),placeholder:m("orders_search_placeholder"),className:"outline-none bg-transparent text-slate-700 w-full"}),se&&e.jsx("button",{onClick:()=>ee(""),className:"text-slate-400 hover:text-slate-600 transition-colors shrink-0",children:e.jsx(bt,{size:13})})]}),e.jsxs("div",{className:"flex items-center gap-2 bg-white border border-slate-200 rounded-xl px-3 py-2 text-sm flex-1 sm:flex-none",children:[e.jsx(Un,{size:15,className:"text-slate-400 shrink-0"}),e.jsx("input",{type:"date",value:u,onChange:g=>_(g.target.value),className:"text-sm text-slate-700 outline-none bg-transparent cursor-pointer",title:m("orders_period_start_title")}),e.jsx("span",{className:"text-slate-300 shrink-0",children:"â"}),e.jsx("input",{type:"date",value:P,onChange:g=>A(g.target.value),className:"text-sm text-slate-700 outline-none bg-transparent cursor-pointer",title:m("orders_period_end_title")}),(u||P)&&e.jsx("button",{onClick:()=>{_(""),A("")},className:"text-slate-400 hover:text-slate-600 transition-colors shrink-0",children:e.jsx(bt,{size:14})})]}),e.jsxs("button",{onClick:_r,className:"flex items-center gap-2 bg-emerald-50 hover:bg-emerald-100 text-emerald-700 border border-emerald-200 px-4 py-2 rounded-xl text-sm font-bold transition-colors whitespace-nowrap",title:m("orders_download_excel_title",{count:Ft.length}),children:[e.jsx(Sa,{size:15}),m("orders_download_excel_button",{count:Ft.length})]}),os.length>=2&&!Se&&e.jsxs("button",{onClick:()=>ve(!0),className:"flex items-center gap-2 bg-orange-50 hover:bg-orange-100 text-orange-700 border border-orange-200 px-4 py-2 rounded-xl text-sm font-bold transition-colors whitespace-nowrap",children:[e.jsx(jn,{size:15})," ",m("orders_merge_orders_button")]})]}),e.jsx("div",{className:"md:hidden space-y-3",children:Ft.length===0?e.jsxs("div",{className:"bg-white rounded-2xl p-10 text-center border border-slate-200",children:[e.jsx(js,{size:40,className:"mx-auto mb-3 text-slate-200"}),e.jsx("p",{className:"text-slate-400 font-medium",children:m("orders_empty_category")})]}):Ft.map(g=>
57{const Q=g.total_cny+(g.commission_cny||0),ne=Math.round(Q*ze(g)),De=g.photo_report_sent&&!g.client_confirmed;return e.jsxs("div",{onClick:()=>xt(g),className:"bg-white rounded-2xl border border-slate-200 p-4 shadow-sm cursor-pointer active:bg-slate-50",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2 mb-2",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"text-sm font-bold text-blue-600",children:g.display_id||g.id}),e.jsx("button",{onClick:Ee=>{Ee.stopPropagation(),jt(g)},title:m("order_timeline_view_tooltip"),className:"p-1 text-slate-400 hover:text-blue-600 hover:bg-blue-50 rounded-lg transition-colors",children:e.jsx(ul,{size:14})})]}),g.client_label&&e.jsx("div",{className:"text-xs font-semibold text-blue-700 bg-blue-50 px-2 py-0.5 rounded mt-1 w-fit max-w-[200px] line-clamp-2 break-words",children:g.client_label})]}),e.jsx("div",{className:"shrink-0",children:Ls(g)})]}),De&&e.jsxs("div",{className:"text-[10px] font-bold text-orange-600 bg-orange-50 border border-orange-200 px-2 py-0.5 rounded-full w-fit mb-2 animate-pulse",children:["â ",m("orders_waiting_reply")]}),e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsxs("div",{children:[e.jsxs("span",{className:"font-bold text-slate-900",children:[ne.toLocaleString()," â½"]}),e.jsxs("span",{className:"text-xs text-slate-400 ml-1",children:["Â¥",Q.toFixed(0)," · ",g.items_count," ",m("orders_unit_pcs")]})]}),e.jsx("span",{className:"text-xs text-slate-400",children:Ta(g.created_at)})]}),g.status==="RECEIVED"&&e.jsxs("div",{className:"mt-3 pt-3 border-t border-slate-100 flex items-center justify-center gap-2",onClick:Ee=>Ee.stopPropagation(),children:[Xe(g),Ct(g)]}),L==="CANCELED"&&e.jsx("div",{className:"mt-2 pt-2 border-t border-slate-100",onClick:Ee=>Ee.stopPropagation(),children:e.jsxs("button",{onClick:()=>Ge(g),className:"flex items-center gap-1 text-xs font-medium text-red-400 hover:text-red-600 transition-colors",children:[e.jsx(is,{size:12})," ",m("orders_delete_from_archive")]})})]},g.id)})}),e.jsx("div",{className:"hidden md:block bg-white rounded-2xl shadow-sm border border-slate-200 overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-left border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-slate-50/50 border-b border-slate-200 text-xs text-slate-500 font-bold uppercase tracking-wider",children:[e.jsx("th",{className:"px-4 py-3 pl-6",children:m("orders_col_id")}),e.jsx(nn,{field:"date",label:m("orders_col_date"),sortField:M,sortDir:ge,onSort:fe,className:"px-4 py-3"}),e.jsx(nn,{field:"status",label:m("orders_col_status"),sortField:M,sortDir:ge,onSort:fe,className:"px-4 py-3"}),e.jsx(nn,{field:"items",label:m("orders_col_items"),sortField:M,sortDir:ge,onSort:fe,className:"px-4 py-3 text-center"}),e.jsx(nn,{field:"finance",label:m("orders_col_finance"),sortField:M,sortDir:ge,onSort:fe,className:"px-4 py-3"}),e.jsx("th",{className:"px-4 py-3",children:m("layout_label_delivery")}),e.jsx(nn,{field:"shipped",label:m("orders_col_shipped"),sortField:M,sortDir:ge,onSort:fe,className:"px-4 py-3"}),e.jsxs("th",{className:"px-4 py-3",children:[m("orders_col_arrival"),e.jsx("div",{className:"font-normal normal-case text-[10px] text-slate-400 tracking-normal mt-0.5",children:m("orders_col_arrival_approx")})]}),e.jsx("th",{className:"px-4 py-3 text-center pr-6",children:m("orders_col_action")})]})}),e.jsx("tbody",{className:"divide-y divide-slate-100 text-sm",children:Ft.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"px-6 py-16 text-center",children:e.jsxs("div",{className:"flex flex-col items-center justify-center text-slate-400",children:[e.jsx(js,{size:48,className:"mb-4 text-slate-200"}),e.jsx("p",{className:"font-medium",children:m("orders_empty_category")})]})})}):Ft.map(g=>
57{const Q=g.total_cny+(g.commission_cny||0),ne=Math.round(Q*ze(g)),De=!!g.client_preferences?.deliveryData,Ee=!!g.shipment_group_id,Pe=E.includes(g.status),nt=T.has(g.id),ft=(g.items||[]).some(ue=>["ON_WAY","PROCESSING","PURCHASED"].includes(ue.status)),It=(g.items||[]).some(ue=>ue.status==="RECEIVED"),Vt=ft&&It&&!g.partial_ship_requested&&!["ASSEMBLED","SHIPPED","RECEIVED","CANCELED"].includes(g.status),fs=g.shipment_group_id?Es.get(g.shipment_group_id)??0:0,f=ai[fs],ae=g.shipment_group_id?Zt.get(g.id):null;return e.jsxs("tr",{onClick:()=>{if(Se&&Pe){As(g.id);return}Se||xt(g)},className:`group transition-colors cursor-pointer ${nt?"bg-orange-100":Ee?`${f.rowBg} border-l-4 ${f.borderL} ${ae?.isFirst?`border-t-2 ${f.borderT}`:""} ${ae?.isLast?`border-b-2 ${f.borderB}`:""}`:"hover:bg-slate-50"} ${Se&&!Pe?"opacity-40 cursor-not-allowed":""}`,children:[e.jsx("td",{className:"px-4 py-3 pl-6",children:e.jsxs("div",{className:"flex items-start gap-2",children:[Se&&Pe&&e.jsx("div",{className:`mt-0.5 w-4 h-4 rounded border-2 flex-shrink-0 flex items-center justify-center transition-colors ${nt?"bg-orange-500 border-orange-500":"border-slate-300"}`,children:nt&&e.jsx(ss,{size:10,className:"text-white"})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"font-bold text-blue-600 hover:underline whitespace-nowrap",children:g.display_id||g.id}),e.jsx("button",{onClick:ue=>{ue.stopPropagation(),jt(g)},title:m("order_timeline_view_tooltip"),className:"p-1 text-slate-400 hover:text-blue-600 hover:bg-blue-50 rounded-lg transition-colors",children:e.jsx(ul,{size:14})})]}),g.client_label&&e.jsx("div",{className:"mt-1 text-xs font-semibold text-blue-700 bg-blue-50 border border-blue-200 px-2 py-0.5 rounded-md w-fit max-w-[280px] truncate",children:g.client_label}),Ee&&!Se&&e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5 w-fit",children:[e.jsxs("div",{className:`flex items-center gap-1 text-xs font-bold px-2.5 py-1 rounded-lg border ${f.badgeCls}`,children:[e.jsx(jn,{size:13})," ",m("orders_group_label",{num:ae?.groupNum})]}),e.jsxs("button",{onClick:ue=>{ue.stopPropagation(),Xt(g.shipment_group_id)},className:"flex items-center gap-1 text-xs font-bold text-red-500 bg-red-50 hover:bg-red-100 border border-red-200 px-2.5 py-1 rounded-lg transition-colors",title:m("orders_split_orders_title"),children:[e.jsx(Ao,{size:13})," ",m("orders_split_button")]})]}),g.parent_order_id&&e.jsxs("div",{className:"mt-1 flex items-center gap-1 text-[10px] font-bold text-blue-600 bg-blue-50 border border-blue-200 px-2 py-0.5 rounded-full w-fit",children:["â³ ",m("orders_continuation")]}),g.photo_report_sent&&!g.client_confirmed&&e.jsxs("div",{className:"mt-1 flex items-center gap-1 text-[10px] font-bold text-orange-600 bg-orange-50 border border-orange-200 px-2 py-0.5 rounded-full w-fit animate-pulse",children:["â ",m("orders_waiting_reply")]}),Vt&&e.jsxs("div",{className:"mt-1 flex items-center gap-1 text-[10px] font-bold text-blue-700 bg-blue-50 border border-blue-200 px-2 py-0.5 rounded-full w-fit",children:[e.jsx(Lt,{size:10})," ",m("orders_can_ship_received")]})]})]})}),e.jsx("td",{className:"px-4 py-3 font-medium text-slate-600",children:Ta(g.created_at)}),e.jsx("td",{className:"px-4 py-3",children:Ls(g)}),e.jsxs("td",{className:"px-4 py-3 text-center font-bold text-slate-700",children:[g.items_count," ",m("orders_unit_pcs")]}),e.jsxs("td",{className:"px-4 py-3",children:[e.jsxs("div",{className:"font-bold text-slate-900",children:[ne.toLocaleString()," â½"]}),e.jsxs("div",{className:"text-xs text-slate-400",children:["Â¥ ",Q.toFixed(2)]}),(()=>{const ue=g.delivery_invoice;if(!ue||!ne)return null;const Me=Math.round((ue.totalUSD||0)*mt)||ue.totalRUB||0;if(!Me)return null;const Fe=Math.round(Me/ne*100),ot=g.items||[],at=ot.reduce((kt,pt)=>kt+(pt.quantity||1),0),vt=new Set(ot.map(kt=>(kt.link||kt.url||"").trim()).filter(Boolean)),wt=ot.length>0&&(ot.length===1||vt.size===1)&&at>0&&["SHIPPED","RECEIVED"].includes(g.status),et=wt?Math.round((ne+Me)/at):0;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-xs text-orange-500 font-medium mt
57-0.5",children:m("orders_delivery_pct_of_goods",{pct:Fe})}),Fe>=50&&e.jsxs("details",{className:"mt-0.5",children:[e.jsxs("summary",{className:"list-none cursor-pointer select-none inline-flex items-center gap-0.5 text-[10px] text-slate-400 hover:text-slate-600",children:[e.jsx(On,{size:10})," ",m("orders_delivery_pct_why")]}),e.jsx("div",{className:"mt-1 max-w-[220px] text-[10px] text-slate-500 leading-snug",children:m("orders_delivery_pct_explanation")})]}),wt&&e.jsxs("div",{className:"text-xs text-emerald-600 font-bold mt-0.5",children:["~",et.toLocaleString("ru-RU")," ",m("orders_rub_per_unit")]})]})})()]}),e.jsx("td",{className:"px-4 py-3",onClick:ue=>ue.stopPropagation(),children:De?["PAID","PURCHASED","COLLECTING","ASSEMBLED"].includes(g.status)?e.jsxs("div",{className:"flex items-start gap-2 cursor-pointer rounded-lg px-2 py-1.5 -mx-2 hover:bg-blue-50 hover:ring-1 hover:ring-blue-200 transition-all",onClick:()=>We(g),children:[e.jsx("div",{className:"bg-green-50 p-1.5 rounded text-green-600 flex-shrink-0",children:e.jsx(Lt,{size:14})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-bold text-slate-700",children:g.client_preferences?.deliveryData?.city}),e.jsxs("div",{className:"text-[10px] text-slate-500",children:[g.client_preferences?.packaging==="BAG"?m("orders_packaging_bag"):m("orders_packaging_box")," ⢠",g.client_preferences?.strategy==="AUTO_SHIP"?m("orders_strategy_auto"):m("orders_strategy_wait")]})]})]}):e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("div",{className:"bg-green-50 p-1.5 rounded text-green-600 flex-shrink-0",children:e.jsx(Lt,{size:14})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-bold text-slate-700",children:g.client_preferences?.deliveryData?.city}),e.jsxs("div",{className:"text-[10px] text-slate-500",children:[g.client_preferences?.packaging==="BAG"?m("orders_packaging_bag"):m("orders_packaging_box")," ⢠",g.client_preferences?.strategy==="AUTO_SHIP"?m("orders_strategy_auto"):m("orders_strategy_wait")]})]})]}):["PAID","PURCHASED","COLLECTING","ASSEMBLED"].includes(g.status)?e.jsxs("button",{onClick:()=>We(g),className:"flex items-center gap-1.5 text-xs font-bold text-amber-600 bg-amber-50 hover:bg-amber-100 px-3 py-1.5 rounded-lg transition-colors border border-amber-100",children:[e.jsx(Fs,{size:14})," ",m("orders_configure_button")]}):e.jsx("span",{className:"text-xs text-slate-400 font-medium",children:"-"})}),(()=>{const ue=g.logistics_dates||{},Me=ue.shipped,Fe=ue.arrivalExpected,ot=wt=>{if(/^\d{2}\.\d{2}\.\d{4}$/.test(wt))return wt;const et=new Date(wt);return isNaN(et.getTime())?wt:et.toLocaleDateString("ru-RU",{day:"2-digit",month:"2-digit",year:"2-digit"})},at=(wt,et)=>{let kt;if(/^\d{2}\.\d{2}\.\d{4}$/.test(wt)){const[pt,$t,Bt]=wt.split(".").map(Number);kt=new Date(Bt,$t-1,pt)}else kt=new Date(wt);return isNaN(kt.getTime())?null:(kt.setDate(kt.getDate()+et),kt.toLocaleDateString("ru-RU",{day:"2-digit",month:"2-digit",year:"2-digit"}))},vt=Me?at(Me,18):null,es=Me?at(Me,35):null;return e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"px-4 py-3",children:Me?e.jsx("span",{className:"text-sm font-bold text-slate-700",children:ot(Me)}):e.jsx("span",{className:"text-xs text-slate-300",children:"â"})}),e.jsx("td",{className:"px-4 py-3",children:Fe?e.jsx("span",{className:"text-sm font-bold text-green-700",children:ot(Fe)}):vt&&es?e.jsxs("div",{children:[e.jsx("span",{className:"text-sm font-bold text-blue-700",children:vt}),e.jsx("span",{className:"text-xs text-slate-400 mx-1",children:"â"}),e.jsx("span",{className:"text-sm font-bold text-blue-700",children:es})]}):e.jsx("span",{className:"text-xs text-slate-300",children:"â"})})]})})(),e.jsx("td",{className:"px-4 py-3 pr-6 text-center",onClick:ue=>ue.stopPropagation(),children:(()=>{const ue=me.has(g.id),Me=!!g.delivery_invoice,Fe=!!g.delivery_paid;if(g.status==="RECEIVED")return e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[Xe(g),Ct(g)]});if(g.status==="NEW")return e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsxs("button",{onClick:()=>$e(g),className:"inline-flex items-center gap-1 bg-blue-600 text-white px-4 py-2 rounded-lg text-xs font-bold hover:bg-blue-700 transition-colors shadow-sm shadow-blue-200",children:[e.jsx(Xs,{size:14})," ",m("home_pay_button")]}),F&&e.jsxs("button",{onClick:()=>xt(g),className:"inline-flex items-center gap-1 bg-slate-100 text-slate-600 px-3 py-2 rounded-lg text-xs font-bold hover:bg-slate-200 transition-colors",children:[e.jsx(dr,{size:13})," ",m("orders_edit_button")]}),!B.has(g.id)&&e.jsx("button",{onClick:()=>Ge(g),className:"p-2 text-slate-400 hover:text-red-500 hover:bg-red-50 rounded-lg transition-colors",children:e.jsx(is,{size:18})})]});if(Me&&!Fe){const ot=te.has(g.id),at=g.delivery_invoice,vt=g.delivery_prepaid_amount??0;return(at?Math.max((Math.round((at.totalUSD||0)*mt)||at.totalRUB||0)-vt,0):0)<2e4?null:e.jsxs("button",{disabled:ot,onClick:()=>!ot&&fr(g),className:`inline-flex items-center gap-1 px-4 py-2 rounded-lg text-xs font-bold transition-colors ${ot?"bg-slate-100 text-slate-400 cursor-not-allowed":"bg-orange-500 text-white hover:bg-orange-600 shadow-sm shadow-orange-200"}`,children:[e.jsx(Lt,{size:14})," ",m(ot?"orders_delivery_pending_short":"orders_pay_delivery_button")]})}return ue?e.jsx("span",{className:"inline-flex items-center gap-1 text-xs font-bold text-amber-600 bg-amber-50 border border-amber-100 px-3 py-1.5 rounded-lg",children:m("orders_under_review")}):Fe?e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs font-bold text-emerald-600 bg-emerald-50 border border-emerald-100 px-3 py-1.5 rounded-lg",children:[e.jsx(ss,{size:13})," ",m("orders_paid_label")]}):g.status==="CANCELED"?e.jsx("button",{onClick:()=>Ge(g),className:"p-2 text-slate-400 hover:text-red-500 hover:bg-red-50 rounded-lg transition-colors",title:m("orders_delete_from_archive"),children:e.jsx(is,{size:16})}):p?e.jsxs("button",{onClick:()=>{window.confirm("ÐÑÐ´ÐµÑ Ð¾ÑкÑÑÑа ÑÑÑаниÑа импоÑÑа Ñ Ñеми же ÑоваÑами и колиÑеÑÑвом, как в ÑÑом заказе. ÐÑовеÑÑÑе акÑÑалÑноÑÑÑ Ñен и налиÑие ÑоваÑов Ñ Ð¿ÑодавÑа пеÑед оÑоÑмлением â ÑÑÑлки могли ÑÑÑаÑеÑÑ.")&&p(g)},className:"inline-flex items-center gap-1 bg-slate-100 text-slate-600 px-3 py-2 rounded-lg text-xs font-bold hover:bg-blue-50 hover:text-blue-700 transition-colors",title:"ÐовÑоÑиÑÑ Ð·Ð°ÐºÐ°Ð·",children:[e.jsx(Lo,{size:13})," ÐовÑоÑиÑÑ"]}):e.jsx("span",{className:"text-slate-300",children:"-"})})()})]},g.id)})})]})})})]}),Ie&&e.jsx(nm,{orderId:Ie.id,orderLabel:Ie.display_id||Ie.id,weightKg:Ie.weightKg,receivedAt:Ie.received_at,onClose:()=>{Oe(null),_e()}}),we&&e.jsx(lo,{order:we,onClose:()=>Le(null)}),_t&&e.jsx(lm,{order:_t,onClose:()=>jt(null)}),Ue&&e.jsx(nl,{onClose:()=>$e(null),onPaymentSuccess:Nt,initialAmount:Math.round((Ue.total_cny+(Ue.commission_cny||
570))*Z),totalCNY:Ue.total_cny+(Ue.commission_cny||0),orderUUID:Ue.id,displayId:Ue.display_id||Ue.id}),it&&e.jsx(Zx,{orderDisplayId:it.display_id||it.id,onCancel:()=>Ge(null),onConfirm:Gt,isLoading:oe}),J&&e.jsx(Ua,{orderId:J.id,onClose:()=>We(null),onSave:Wt}),H&&e.jsx(Zl,{order:H,currentUsdRate:mt,onClose:()=>le(null),onSuccess:()=>{le(null),G()}}),xe&&e.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-slate-900/60 backdrop-blur-sm p-4",children:e.jsxs("div",{className:"bg-white rounded-2xl w-full max-w-sm shadow-2xl p-6 text-center space-y-4",children:[e.jsx("div",{className:"w-14 h-14 bg-orange-50 text-orange-600 rounded-full flex items-center justify-center mx-auto",children:e.jsx(Lt,{size:26})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-bold text-slate-900 mb-1",children:m("orders_delivery_pay_choice_title")}),e.jsx("p",{className:"text-sm text-slate-500",children:m("orders_delivery_pay_choice_text",{count:Ht.length,amount:xs.toLocaleString("ru-RU")})})]}),e.jsxs("div",{className:"flex flex-col gap-2 pt-1",children:[e.jsx("button",{onClick:()=>{de(null),k(!0)},className:"w-full py-3 bg-orange-500 text-white rounded-xl font-bold hover:bg-orange-600 transition-colors",children:m("orders_delivery_pay_choice_all",{count:Ht.length})}),e.jsx("button",{onClick:()=>{const g=xe;de(null),le(g)},className:"w-full py-3 bg-slate-100 text-slate-700 rounded-xl font-bold hover:bg-slate-200 transition-colors",children:m("orders_delivery_pay_choice_one")})]})]})}),Qe&&e.jsx(si,{orders:Ht.map(g=>{const Q=g.delivery_invoice,ne=g.delivery_prepaid_amount??0,De=Q?Math.max((Math.round((Q.totalUSD||0)*mt)||Q.totalRUB||0)-ne,0):0;return{id:g.id,displayId:g.display_id||g.id,amount:De}}).filter(g=>g.amount>0),onClose:()=>k(!1),onSuccess:()=>{k(!1),G()}})]})}function nn({field:t,label:s,sortField:n,sortDir:r,onSort:l,className:c=""}){const o=n===t;return e.jsx("th",{className:`${c} cursor-pointer select-none group`,onClick:()=>l(t),children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[s,e.jsx("span",{className:`transition-colors ${o?"text-blue-600":"text-slate-300 group-hover:text-slate-400"}`,children:o&&r==="asc"?e.jsx(qr,{size:13}):o&&r==="desc"?e.jsx(er,{size:13}):e.jsx(Mo,{size:13})})]})})}function li(t){return t?t.includes("1688.com")?"1688":t.includes("tmall.com")?"tmall":t.includes("taobao.com")?"taobao":"other":"other"}const ii={1688:0,taobao:1,tmall:2,other:3},jr="import_cart_draft";function dm({initialCart:t,isAuthenticated:s=!1,userProfile:n,onRequireAuth:r,onSuccess:l,commissionSettings:c}){const{t:o}
57=qt(),[d,p]=a.useState(()=>{if(!t)try{const k=localStorage.getItem(jr);if(k){const xe=JSON.parse(k);if(Array.isArray(xe)&&xe.length>0)return xe}}catch{}return[]}),[y,j]=a.useState(!1),[b,h]=a.useState(!1),v=()=>{navigator.clipboard.writeText("goodschina.ru/cabinet"),h(!0),setTimeout(()=>h(!1),2e3)},[i,x]=a.useState(!t&&!localStorage.getItem(jr)),[m,N]=a.useState(()=>{try{const k=localStorage.getItem("tradehub_currencies");if(k){const xe=JSON.parse(k);return Array.isArray(xe)&&xe.length>0}}catch{}return!1}),[R,S]=a.useState(!1),[C,L]=a.useState(()=>{try{const k=localStorage.getItem("tradehub_currencies");if(k){const de=JSON.parse(k)?.find(V=>V.code==="CNY");if(de)return Number(de.rate)||13.5}}catch{}return 13.5}),[U,W]=a.useState(null),[re,Z]=a.useState(null),[O,F]=a.useState(!1),[D,$]=a.useState(()=>localStorage.getItem("hideCommissionPanel")!=="true");a.useEffect(()=>{(async()=>{const xe=de=>Number(de.rate)||0;try{const{data:de}=await Re("app_settings",{},{select:"currencies",single:!0}),V=de?.currencies;if(Array.isArray(V)&&V.length>0){const ye=V.find(Ie=>Ie.code==="CNY");ye&&L(xe(ye));try{localStorage.setItem("tradehub_currencies",JSON.stringify(V))}catch{}N(!0);return}}catch{}try{const de=localStorage.getItem("tradehub_currencies");if(de){const ye=JSON.parse(de).find(Ie=>Ie.code==="CNY");ye&&L(xe(ye))}}catch{}N(!0)})()},[]),a.useEffect(()=>{const k=setTimeout(()=>S(!0),5e3);return()=>clearTimeout(k)},[]),a.useEffect(()=>{if(t&&Array.isArray(t)){const k=t.map(xe=>({...xe,itemComment:""}));p(k),localStorage.setItem(jr,JSON.stringify(k)),x(!1)}},[t]),a.useEffect(()=>{d.length>0&&localStorage.setItem(jr,JSON.stringify(d))},[d]),a.useEffect(()=>{if(!t&&!localStorage.getItem(jr)){const k=setTimeout(()=>x(!1),2500);return()=>clearTimeout(k)}},[]);const z=k=>{const xe=[...d];xe.splice(k,1),p(xe)},me=()=>{confirm(o("import_confirm_clear"))&&(p([]),localStorage.removeItem("orderease-cart"),localStorage.removeItem("orderease_pending_cart"),localStorage.removeItem(jr))},K=()=>{re&&(p(k=>k.filter(xe=>{const de=li(xe.url),V=xe.shopName?.trim()||o("import_other_shop");return!(de===re.source&&V===re.shopName)})),Z(null))},te=(k,xe)=>{const de=[...d];de[k].itemComment=xe,p(de)},I=(k,xe)=>{const de=[...d];de[k]={...de[k],itemWeight:xe>0?xe:void 0},p(de)},B=(k,xe)=>{p(de=>{const V=[...de],ye=V[k];if(!ye)return de;const Ie=Math.max(1,Math.round((ye.quantity||1)+xe));return V[k]={...ye,quantity:Ie},V})},[Ne,Ue]=a.useState({}),$e=k=>{const xe=Ne[k];if(xe===void 0)return;Ue(V=>{const ye={...V};return delete ye[k],ye});const de=parseInt(xe,10);Number.isFinite(de)&&de>=1&&p(V=>{const ye=[...V];return ye[k]?(ye[k]={...ye[k],quantity:de},ye):V})},H=a.useMemo(()=>{const k={};return d.forEach((xe,de)=>{const V=xe.shopName?.trim()||o("import_other_shop"),ye=li(xe.url),Ie=`${ye}|${V}`,Oe=Number(xe.chinaDelivery)||0;k[Ie]||(k[Ie]={shopName:V,source:ye,totalDeliveryPrice:0,items:[]}),k[Ie].items.push({originalIndex:de,item:xe}),k[Ie].totalDeliveryPrice+=Oe}),Object.values(k).sort((xe,de)=>{const V=ii[xe.source]-ii[de.source];return V!==0?V:xe.shopName.localeCompare(de.shopName)})},[d]),le=a.useMemo(()=>{const k=d.reduce((dt,gt)=>dt+gt.price*gt.quantity,0),xe=d.reduce((dt,gt)=>dt+(Number(gt.chinaDelivery)||0),0),de=d.map(dt=>dt.url).filter(dt=>!!dt),V=new Set(de).size,ye=d.length>0&&V<=1,Ie=d.length>50;let Oe=0,we=5,Le=!1;if(ye){const dt=d.reduce((gt,ht)=>gt+(ht.itemWeight??0),0);dt>0?(we=sc(dt),Oe=k*(we/100)):(we=5,Oe=k*.05,Le=k>0)}else if(Ie)we=5,Oe=k*.05;else if(c&&c.isEnabled){const dt=c.rules.map(it=>({...it,minAmount:parseFloat(it.minAmount),maxAmount:it.maxAmount?parseFloat(it.maxAmount):null,rate:parseFloat(it.rate)})).sort((it,Ge)=>it.minAmount-Ge.minAmount);let gt=dt[0];for(const it of dt){let Ge=k;it.currency==="RUB"?Ge=k*C:it.currency==="USD"&&(Ge=k*C/92),Ge>=it.minAmount&&(it.maxAmount===null||Ge<=it.maxAmount)&&(gt=it)}gt?(we=gt.rate,Oe=k*(gt.rate/100)):Oe=k*.05;let ht=0;const qe=parseFloat(c.minCommission);qe>0&&(c.minCommissionCurrency==="USD"?ht=qe*7.2:c.minCommissionCurrency==="RUB"?ht=qe/C:ht=qe),Oe<ht&&k>0&&(Oe=ht)}else Oe=k*.05;const _t=k+xe+Oe,jt=Math.round(_t*C);return{goodsCNY:k,deliveryCNY:xe,commissionCNY:Oe,totalCNY:_t,totalRUB:jt,appliedPercent:we,isSingleLink:ye,isOver50Links:Ie,needsWeightRecalculation:Le}},[d,C,c]),Qe=async()=>
57{if(d.length!==0){if(!s){r&&r(d);return}j(!0);try{const k=yt();if(!k)throw new Error("User not auth");const{data:xe}=await Re("users",{id:k},{select:"friendly_id",single:!0}),de=xe?.friendly_id||n?.friendly_id;if(!de)throw new Error(o("import_profile_not_loaded"));const V=await qa(k,de),ye=[];H.forEach(we=>{we.items.forEach((Le,_t)=>{const jt=_t===0,dt=Le.item;ye.push({...dt,priceCNY:dt.price,chinaDelivery:jt?we.totalDeliveryPrice:0,originalChinaDelivery:jt?we.totalDeliveryPrice:0,estimatedWeightPerUnit:dt.itemWeight||null,needsWeightRecalculation:le.needsWeightRecalculation})})}),await Promise.all(ye.map(async we=>{if(!we.itemComment?.trim())return;const Le=await ki(we.itemComment,"zh");Le&&(we.itemCommentZh=Le)}));const Ie=le.goodsCNY+le.deliveryCNY,{error:Oe}=await st("orders",{user_id:k,display_id:V,status:"NEW",total_cny:Ie,commission_cny:le.commissionCNY,commission_rate_pct:le.appliedPercent,is_single_link:le.isSingleLink,comment:"",items:ye,items_count:d.reduce((we,Le)=>we+Le.quantity,0),created_at:new Date().toISOString()});if(Oe)throw new Error(Oe);p([]),localStorage.removeItem("orderease-cart"),localStorage.removeItem("orderease_pending_cart"),localStorage.removeItem("cart_backup"),localStorage.removeItem(jr),l&&l()}catch(k){alert(o("import_create_order_error_prefix")+k.message)}finally{j(!1)}}};return d.length===0&&i?e.jsxs("div",{className:"flex flex-col items-center justify-center py-24 bg-white rounded-3xl border border-slate-200 text-center",children:[e.jsx(rt,{size:40,className:"text-blue-500 animate-spin mb-4"}),e.jsx("p",{className:"text-slate-400 text-sm font-medium",children:o("import_loading_from_extension")})]}):d.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-24 bg-white rounded-3xl border border-slate-200 border-dashed text-center",children:[e.jsx("div",{className:"w-20 h-20 bg-slate-50 rounded-full flex items-center justify-center mb-6 text-slate-300",children:e.jsx(zo,{size:40})}),e.jsx("h2",{className:"text-2xl font-bold text-slate-900 mb-3",children:o("import_list_empty")}),e.jsx("p",{className:"text-slate-500 max-w-md mb-8 leading-relaxed",children:o("import_empty_instructions")}),e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-3 mb-8","data-tour":"nav-marketplaces",children:[e.jsxs("a",{href:"https://www.1688.com",target:"_blank",rel:"noreferrer",className:"flex items-center gap-2 px-5 py-2.5 rounded-xl border-2 font-bold text-sm transition-all hover:opacity-80",style:{borderColor:"rgb(249 115 22)",color:"rgb(249 115 22)"},children:[o("import_go_to_1688"),e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}),e.jsx("polyline",{points:"15 3 21 3 21 9"}),e.jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]})]}),e.jsxs("a",{href:"https://www.taobao.com",target:"_blank",rel:"noreferrer",className:"flex items-center gap-2 px-5 py-2.5 rounded-xl border-2 font-bold text-sm transition-all hover:opacity-80",style:{borderColor:"rgb(239 68 68)",color:"rgb(239 68 68)"},children:[o("import_go_to_taobao"),e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}),e.jsx("polyline",{points:"15 3 21 3 21 9"}),e.jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]})]})]}),e.jsxs("a",{href:"https://chromewebstore.google.com/detail/goods-china/jcfocpdliaabckbcfenhgphnejljmobi?hl=ru&utm_source=ext_sidebar",target:"_blank",rel:"noreferrer",className:"hidden md:inline-block text-blue-600 font-medium hover:underline text-sm","data-tour":"nav-extension-link",children:[o("import_install_extension")," â"]}),e.jsxs("div",{className:"md:hidden flex flex-col items-center gap-3 max-w-xs",children:[e.jsx("p",{className:"text-slate-400 text-xs leading-relaxed",children:o("import_desktop_only_notice")}),e.jsxs("button",{onClick:v,className:"flex items-center gap-2 px-4 py-2 rounded-xl border border-slate-200 bg-slate-50 hover:bg-slate-100 transition-colors",children:[e.jsx("span",{className:"font-mono font-bold text-slate-700 text-sm",children:"goodschina.ru/cabinet"}),b?e.jsx(Kt,{size:15,className:"text-green-500"}):e.jsx(Us,{size:15,className:"text-slate-400"})]})]})]}):e.jsxs("div",{className:"max-w-6xl xl:max-w-7xl mx-auto pb-20",children:[O&&e.jsx("div",{className:"fixed inset-0 z-[120] flex items-center justify-center bg-black/60 backdrop-blur-sm p-4",onClick:()=>F(!1),children:e.jsxs("div",{className:"bg-white w-full max-w-lg rounded-2xl shadow-2xl overflow-hidden flex flex-col max-h-[85vh]",onClick:k=>k.stopPropagation(),children:[e.jsxs("div",{className:"bg-orange-500 text-white px-5 py-4 flex justify-between items-center shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(aa,{size:20}),e.jsx("h3",{className:"font-bold text-base",children:o("import_one_position_title")})]}),e.jsx("button",{onClick:()=>F(!1),className:"text-white/80 hover:text-white",children:e.jsx(bt,{size:20})})]}),e.jsxs("div",{className:"overflow-y-auto p-5 space-y-4 text-sm text-slate-700",children:[e.jsx("p",{children:o("import_one_position_p1")}),e.jsxs("div",{className:"bg-slate-50 border border-slate-200 rounded-xl p-3",children:[e.jsx("p",{className:"font-bold text-slate-800 mb-2",children:o("import_example_label")}),e.jsxs("p",{children:[o("import_one_position_example_prefix")," ",e.jsx("strong",{className:"text-slate-900",children:"3%"}),o("import_one_position_example_suffix")]})]})]}),e.jsx("div",{className:"p-4 border-t border-slate-200 bg-white shrink-0",children:e.jsx("button",{onClick:()=>F(!1),className:"w-full px-6 py-2.5 rounded-xl font-bold bg-orange-500 text-white hover:bg-orange-600 transition-colors",children:o("topup_understood")})})]})}),re&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm",children:e.jsxs("div",{className:"bg-white rounded-2xl shadow-2xl p-6 w-full max-w-sm mx-4",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-red-100 flex items-center justify-center",children:e.jsx(is,{size:18,className:"text-red-600"})}),e.jsx("h3",{className:"font-bold text-slate-800",children:o("import_delete_shop_question")})]}),e.jsxs("p",{className:"text-sm text-slate-500 mb-5",children:[o("import_delete_shop_body_prefix")," ",e.jsxs("span",{className:"font-bold text-slate-700",children:["«",re.shopName,"»"]})," ",o("import_delete_shop_body_suffix")]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{onClick:()=>Z(null),className:"flex-1 py-2.5 rounded-xl border border-slate-200 text-sm font-bold text-slate-600 hover:bg-slate-50 transition-colors",children:o("orders_cancel_button")}),e.jsx("button",{onClick:K,className:"flex-1 py-2.5 rounded-xl bg-red-500 text-white text-sm font-bold hover:bg-red-600 transition-colors",children:o("import_delete_button")})]})]})}),e.jsxs("div",{className:"flex items-center justify-between mb-8",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-3xl font-bold text-slate-900 flex items-center gap-3",children:[o("import_title"),!s&&e.jsx("span",{className:"bg-amber-100 text-amber-700 text-xs px-2.5 py-1 rounded-full font-bold uppercase tracking-wide border border-amber-200",children:o("import_guest_mode")})]}),e.jsx("p",{className:"text-slate-500 mt-1",children:o("import_check_list_subtitle")})]}),e.jsxs("button",{onClick:me,className:"flex items-center gap-2 text-red-500 hover:text-red-700 font-medium transition-colors px-4 py-2 hover:bg-red-50 rounded-lg",children:[e.jsx(is,{size:16}),o("import_clear_list")]})]}),e.jsxs("div",{className:"flex flex-col lg:flex-row gap-8 items-start",children:[e.jsx("div",{className:"flex-1 w-full space-y-6",children:H.map((k,xe)=>{const de=xe===0||H[xe-1].source!==k.source,V=k.source==="1688"?"#f97316":k.source==="tmall"?"#ff0036":"#ef4444",ye=k.source==="1688"?"https://www.1688.com/favicon.ico":k.source==="tmall"?"https://www.tmall.com/favicon.ico":"https://www.taobao.c
57om/favicon.ico",Ie=k.source==="1688"?"1688":k.source==="tmall"?"Tmall":"Taobao",Oe=de&&k.source!=="other"?e.jsxs("div",{className:"flex items-center gap-3 px-4 py-2 rounded-xl font-bold text-sm text-white",style:{backgroundColor:V},children:[e.jsx("img",{src:ye,alt:k.source,className:"w-4 h-4 rounded",onError:we=>{we.target.style.display="none"}}),o("import_items_from")," ",Ie]}):null;return e.jsxs(ct.Fragment,{children:[Oe,e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-200 shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"px-5 py-3 bg-slate-50 border-b border-slate-200 flex flex-wrap justify-between items-center gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 bg-white border border-slate-200 rounded-lg flex items-center justify-center text-blue-600",children:e.jsx(Uo,{size:16})}),e.jsx("span",{className:"font-bold text-slate-800 text-sm",children:k.shopName}),e.jsx("span",{className:"text-[10px] font-bold bg-slate-200 text-slate-500 px-1.5 py-0.5 rounded border border-slate-300",children:o("order_details_positions_short",{count:k.items.length})}),e.jsx("button",{onClick:()=>Z({source:k.source,shopName:k.shopName}),className:"p-1.5 text-slate-300 hover:text-red-500 hover:bg-red-50 rounded-lg transition-colors",title:o("import_delete_shop_title"),children:e.jsx(is,{size:14})})]}),e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 bg-white border border-red-200 rounded-lg shadow-sm",children:[e.jsx(Lt,{size:14,className:"text-red-500"}),e.jsxs("span",{className:"text-xs font-bold text-slate-500 uppercase",children:[o("import_total_delivery_label"),":"]}),e.jsxs("div",{className:"flex flex-col items-end gap-0",children:[e.jsxs("span",{className:"text-sm font-bold text-red-600",children:[Math.round(k.totalDeliveryPrice*C).toLocaleString("ru-RU")," â½"]}),e.jsxs("span",{className:"text-xs text-slate-400",children:["Â¥ ",k.totalDeliveryPrice.toFixed(2)]})]})]})]}),e.jsx("div",{className:"divide-y divide-slate-100",children:k.items.map(({item:we,originalIndex:Le})=>e.jsxs("div",{className:"p-5 grid grid-cols-1 md:grid-cols-12 gap-3 items-stretch hover:bg-slate-50/50 transition-colors",children:[e.jsxs("div",{className:"col-span-12 md:col-span-7 flex gap-4",children:[e.jsx("div",{className:"w-20 h-20 shrink-0 bg-slate-100 rounded-lg overflow-hidden border border-slate-200 relative",children:we.image?e.jsx("img",{src:we.image,alt:we.name,className:"w-full h-full object-cover",referrerPolicy:"no-referrer"}):e.jsx("div",{className:"w-full h-full flex items-center justify-center text-slate-300",children:e.jsx(js,{size:24})})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"text-sm font-bold text-slate-900 leading-snug mb-1 line-clamp-2 hover:text-blue-600 transition-colors",children:we.url?e.jsx("a",{href:we.url,target:"_blank",rel:"noreferrer",children:we.name||o("import_no_name_item")}):we.name||o("import_no_name_item")}),e.jsx("div",{className:"flex flex-wrap gap-2 mb-2",children:we.specs&&e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-slate-100 text-slate-600 border border-slate-200",children:we.specs})}),e.jsx("div",{className:"mb-2",children:U===Le?e.jsxs("div",{className:"flex flex-col gap-1 animate-fade-in",children:[e.jsxs("div",{className:"flex gap-2 items-start",children:[e.jsx("textarea",{autoFocus:!0,rows:2,maxLength:500,placeholder:o("import_comment_placeholder"),className:"flex-1 text-xs px-3 py-2 border-2 border-blue-300 rounded-lg bg-white outline-none focus:border-blue-400 focus:ring-2 focus:ring-blue-100 resize-none transition-all",value:we.itemComment||"",onChange:_t=>te(Le,_t.target.value),onBlur:()=>W(null)}),e.jsx("button",{onClick:()=>{te(Le,""),W(null)},className:"text-slate-400 hover:text-slate-600 mt-1",title:o("import_clear_button"),children:e.jsx(bt,{size:16})})]}),e.jsxs("span",{className:"text-[10px] text-slate-400 text-right pr-7",children:[(we.itemComment||"").length,"/500"]})]}):e.jsxs("button",{type:"button",onClick:()=>W(Le),className:`flex items-center gap-1.5 w-full text-left text-xs px-3 py-1.5 rounded-lg border-2 transition-colors ${we.itemComment?"bg-blue-50 text-blue-700 border-blue-200":"bg-blue-50/30 text-slate-400 border-blue-200 hover:border-blue-300 hover:text-blue-600"}`,children:[we.itemComment?e.jsx(dr,{size:12,className:"shrink-0 text-blue-500"}):e.jsx(zr,{size:13,className:"shrink-0 text-blue-400"}),e.jsx("span",{className:"flex-1 truncate",children:we.itemComment||o("import_add_comment")}),!we.itemComment&&e.jsx($s,{size:12,className:"shrink-0 text-blue-400"})]})}),le.isSingleLink&&e.jsxs("div",{className:"flex flex-col gap-0.5 shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"text-xs text-slate-400",children:"â"}),e.jsx("input",{type:"number",min:"0",step:"0.1",placeholder:"0",title:o("import_weight_per_unit_title"),className:"w-16 text-xs px-2 py-1 border border-slate-200 rounded-lg text-center focus:border-blue-300 focus:ring-1 focus:ring-blue-100 outline-none transition-all",value:we.itemWeight||"",onChange:_t=>I(Le,parseFloat(_t.target.value)||0)}),e.jsx("span",{className:"text-xs text-slate-400",children:o("orders_unit_kg")})]}),!we.itemWeight&&e.jsx("p",{className:"text-[10px] text-amber-600 leading-tight max-w-[140px]",children:o("import_weight_hint")})]})]})]}),e.jsxs("div",{className:"col-span-4 md:col-span-2 flex md:flex-col items-center md:justify-center justify-between text-sm",children:[e.jsxs("span",{className:"md:hidden text-slate-500 font-medium",children:[o("import_price_label"),":"]}),e.jsxs("div",{className:"flex flex-col items-end md:items-center gap-0.5",children:[e.jsxs("span",{className:"font-bold text-green-700",children:[Math.round(we.price*C).toLocaleStr
57ing("ru-RU")," â½"]}),e.jsxs("span",{className:"text-xs text-slate-400",children:["Â¥ ",we.price.toFixed(2)]})]})]}),e.jsxs("div",{className:"col-span-4 md:col-span-1 flex md:flex-col items-center md:justify-center justify-between",children:[e.jsxs("span",{className:"md:hidden text-slate-500 font-medium",children:[o("import_qty_label"),":"]}),e.jsxs("div",{className:"flex items-center gap-1.5 bg-blue-50 border border-blue-100 rounded-lg px-1.5 py-1",children:[e.jsx("button",{type:"button",onClick:()=>B(Le,-1),disabled:we.quantity<=1,className:"w-5 h-5 flex items-center justify-center rounded-md bg-white border border-blue-200 text-blue-600 disabled:opacity-30 hover:bg-blue-100 transition-colors",children:e.jsx(ka,{size:11})}),e.jsx("input",{type:"number",inputMode:"numeric",min:1,value:Ne[Le]??we.quantity,onChange:_t=>Ue(jt=>({...jt,[Le]:_t.target.value})),onBlur:()=>$e(Le),onKeyDown:_t=>{_t.key==="Enter"&&_t.target.blur()},className:"w-9 text-center bg-transparent border-0 outline-none text-sm font-bold text-blue-700 [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"}),e.jsx("button",{type:"button",onClick:()=>B(Le,1),className:"w-5 h-5 flex items-center justify-center rounded-md bg-white border border-blue-200 text-blue-600 hover:bg-blue-100 transition-colors",children:e.jsx($s,{size:11})})]})]}),e.jsxs("div",{className:"col-span-4 md:col-span-2 flex md:flex-col items-center md:items-end justify-between relative",children:[e.jsxs("span",{className:"md:hidden text-slate-500 font-medium",children:[o("import_sum_label"),":"]}),e.jsxs("div",{className:"flex flex-col items-end gap-0.5",children:[e.jsxs("span",{className:"text-lg font-bold text-green-700",children:[Math.round(we.price*we.quantity*C).toLocaleString("ru-RU")," â½"]}),e.jsxs("span",{className:"text-xs text-slate-400",children:["Â¥ ",(we.price*we.quantity).toFixed(2)]})]}),e.jsxs("button",{onClick:()=>z(Le),className:"flex items-center gap-1 text-xs text-slate-400 hover:text-red-500 transition-colors px-1 py-1 rounded hover:bg-red-50",title:o("import_delete_item_title"),children:[e.jsx(is,{size:13})," ",o("import_delete_button")]})]})]},Le))})]})]},`${k.source}|${k.shopName}`)})}),e.jsxs("div",{className:"w-full lg:w-[360px] xl:w-[420px] shrink-0 space-y-4",children:[D?e.jsxs("div",{className:"bg-gradient-to-br from-indigo-50 via-blue-50 to-slate-50 rounded-2xl border border-blue-200 shadow-sm p-5 relative",children:[e.jsx("button",{onClick:()=>{$(!1),localStorage.setItem("hideCommissionPanel","true")},className:"absolute top-3 right-3 w-7 h-7 flex items-center justify-center rounded-lg text-slate-400 hover:bg-white hover:text-slate-600 transition-colors",children:e.jsx(bt,{size:15})}),e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("div",{className:"w-7 h-7 bg-blue-600 rounded-lg flex items-center justify-center text-white shrink-0",children:e.jsx(aa,{size:13})}),e.jsx("h3",{className:"font-extrabold text-slate-800 text-sm uppercase tracking-wide",children:o("import_commission_discounts")})]}),e.jsx("p",{className:"text-[10px] font-bold text-slate-400 uppercase tracking-widest mb-2",children:o("import_by_order_amount")}),e.jsx("div",{className:"space-y-1 mb-4",children:[{range:o("import_range_up_to_250k"),rate:"5%",best:!1},{range:o("import_range_250k_500k"),rate:"3%",best:!1},{range:o("import_range_500k_900k"),rate:"2.5%",best:!1},{range:o("import_range_from_900k"),rate:"1%",best:!0}].map(k=>e.jsxs("div",{className:`flex justify-between items-center text-xs px-3 py-1.5 rounded-lg ${k.best?"bg-green-50 border border-green-200":"bg-white/80 border border-slate-100"}`,children:[e.jsx("span",{className:"text-slate-600",children:k.range}),e.jsx("span",{className:`font-bold tabular-nums ${k.best?"text-green-700":"text-blue-700"}`,children:k.rate})]},k.range))}),e.jsxs("div",{className:"flex items-start gap-2 mb-4 p-2.5 bg-amber-50 border border-amber-200 rounded-lg text-xs text-amber-800 leading-relaxed",children:[e.jsx("span",{className:"shrink-0 text-sm",children:"â¡"}),e.jsxs("span",{children:[o("import_over_50_links_prefix")," ",e.jsxs("strong",{children:["50 ",o("import_links_word")]})," ",o("import_over_50_links_suffix")," ",e.jsx("strong",{children:"5%"})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[e.jsxs("p",{className:"text-[10px] font-bold text-slate-400 uppercase tracking-widest",children:[o("import_commission_per_item"),":"]}),e.jsx("button",{type:"button",onClick:()=>F(!0),title:o("import_one_position_title"),className:"w-5 h-5 rounded-full bg-orange-500 hover:bg-orange-600 text-white flex items-center justify-center text-[11px] font-bold leading-none transition-colors shadow-sm",children:"!"})]}),e.jsx("div",{className:"space-y-1",children:[{range:o("import_weight_up_to_30"),rate:"5%",best:!1},{range:o("import_weight_30_100"),rate:"3%",best:!1},{range:o("import_weight_100_200"),rate:"2.5%",best:!1},{range:o("import_weight_200_350"),rate:"2%",best:!1},{range:o("import_weight_from_350"),rate:"1%",best:!0}].map(k=>e.jsxs("div",{className:`flex justify-between items-center text-xs px-3 py-1.5 rounded-lg ${k.best?"bg-green-50 border border-green-200":"bg-white/80 border border-slate-100"}`,children:[e.jsx("span",{className:"text-slate-600",children:k.range}),e.jsx("span",{className:`font-bold tabular-nums ${k.best?"text-green-700":"text-blue-700"}`,children:k.rate})]},k.range))})]}):e.jsxs("button",{onClick:()=>{$(!0),localStorage.removeItem("hideCommissionPanel")},className:"w-full flex items-center justify-center gap-2 py-2.5 bg-blue-50 hover:bg-blue-100 border border-blue-200 rounded-xl text-xs font-semibold text-blue-700 transition-colors",children:[e.jsx("div",{className:"w-5 h-5 bg-blue-600 rounded flex items-center justify-center text-white",children:e.jsx(aa,{size:11})}),o("import_commission_rates")]}),e.jsxs("div",{className:"bg-white p-6 rounded-2xl border border-slate-200 shadow-sm sticky top-24",children:[e.jsx("h3",{className:"font-bold text-slate-900 text-lg mb-6 flex items-center gap-2",children:o("import_order_summary")}
57),!m||c===null&&!R?e.jsxs("div",{className:"space-y-4 mb-6 animate-pulse",children:[[...Array(3)].map((k,xe)=>e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("div",{className:"h-3 bg-slate-200 rounded w-2/5"}),e.jsx("div",{className:"h-4 bg-slate-200 rounded w-1/3"})]},xe)),e.jsx("div",{className:"pt-4 border-t border-slate-100",children:e.jsxs("div",{className:"flex justify-between items-end",children:[e.jsx("div",{className:"h-4 bg-slate-200 rounded w-1/4"}),e.jsx("div",{className:"h-8 bg-slate-200 rounded w-2/5"})]})})]}):e.jsxs("div",{className:"space-y-4 mb-6",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsxs("span",{className:"text-slate-500",children:[o("order_details_goods")," (",d.length,")"]}),e.jsxs("div",{className:"flex flex-col items-end gap-0.5",children:[e.jsxs("span",{className:"font-bold text-green-700",children:[Math.round(le.goodsCNY*C).toLocaleString("ru-RU")," â½"]}),e.jsxs("span",{className:"text-xs text-slate-400",children:["Â¥ ",le.goodsCNY.toFixed(2)]})]})]}),le.deliveryCNY>0&&e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-slate-500",children:o("import_china_delivery_total")}),e.jsxs("div",{className:"flex flex-col items-end gap-0.5",children:[e.jsxs("span",{className:"font-bold text-amber-600",children:["+ ",Math.round(le.deliveryCNY*C).toLocaleString("ru-RU")," â½"]}),e.jsxs("span",{className:"text-xs text-slate-400",children:["Â¥ ",le.deliveryCNY.toFixed(2)]})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsxs("span",{className:"text-slate-500",children:[o("import_service_commission")," (",le.appliedPercent,"%)",le.isSingleLink&&e.jsx("span",{className:"ml-1 text-[10px] font-semibold text-blue-500 uppercase tracking-wide",children:o("order_details_by_weight")})]}),e.jsxs("div",{className:"flex flex-col items-end gap-0.5",children:[e.jsxs("span",{className:"font-bold text-slate-700",children:[Math.round(le.commissionCNY*C).toLocaleString("ru-RU")," â½"]}),e.jsxs("span",{className:"text-xs text-slate-400",children:["Â¥ ",le.commissionCNY.toFixed(2)]})]})]}),le.needsWeightRecalculation&&e.jsxs("p",{className:"text-[11px] text-amber-600 mt-1 leading-snug",children:["â ",o("import_weight_recalc_hint")]}),le.isSingleLink&&!le.needsWeightRecalculation&&e.jsxs("p",{className:"text-[11px] text-green-600 mt-1 leading-snug",children:["â ",o("order_details_commission_by_weight_note")]}),le.isOver50Links&&e.jsx("p",{className:"text-[11px] text-amber-600 mt-1 leading-snug",children:o("import_over_50_no_discount")})]}),e.jsxs("div",{className:"pt-4 border-t border-slate-100",children:[e.jsxs("div",{className:"flex justify-between items-end mb-1",children:[e.jsx("span",{className:"font-bold text-slate-900 text-lg",children:o("import_total_label")}),e.jsx("div",{className:"text-right",children:e.jsxs("span",{className:"text-3xl font-bold text-orange-600 tracking-tight",children:[le.totalRUB.toLocaleString("ru-RU")," â½"]})})]}),e.jsx("div",{className:"text-right",children:e.jsxs("span",{className:"text-xs text-slate-400 font-medium",children:["Â¥ ",le.totalCNY.toFixed(2)]})})]})]}),e.jsx("button",{onClick:Qe,disabled:y,className:`w-full py-4 rounded-xl font-bold text-lg shadow-lg transition-all active:scale-[0.98] flex items-center justify-center gap-2 ${s?"bg-blue-600 hover:bg-blue-700 text-white shadow-blue-200":"bg-amber-400 hover:bg-amber-500 text-slate-900 shadow-amber-200"}`,children:y?e.jsx(rt,{className:"animate-spin"}):s?e.jsxs(e.Fragment,{children:[o("import_create_order")," ",e.jsx(Ga,{size:20})]}):e.jsxs(e.Fragment,{children:[o("import_login_and_order")," ",e.jsx($o,{size:20})]})}),!s&&e.jsxs("div",{className:"mt-4 p-3 bg-amber-50 rounded-lg border border-amber-100 text-xs text-amber-800 text-center leading-relaxed",children:[e.jsx("span",{className:"font-bold",children:o("topup_attention")})," ",o("import_guest_warning")]}),e.jsx("div",{className:"mt-6 pt-6 border-t border-slate-100 text-center",children:e.jsx("p",{className:"text-xs text-slate-400",children:o("import_terms_agreement")})})]})]})]})]})}const um=(t,s)=>{const n=new Date(t),r=new Date,l=new Date(r);l.setDate(r.getDate()-1);const c=(o,d)=>o.getDate()===d.getDate()&&o.getMonth()===d.getMonth()&&o.getFullYear()===d.getFullYear();
57return c(n,r)?s("messages_today"):c(n,l)?s("messages_yesterday"):n.toLocaleDateString("ru-RU",{day:"numeric",month:"long"})},oi=t=>new Date(t).toDateString(),Dn=t=>({...t,senderRole:t.sender_role,managerName:t.manager_name,isRead:t.is_read,deleted:t.deleted??!1,fileUrl:t.file_url,fileName:t.file_name,fileType:t.file_type,timestamp:t.created_at?new Date(t.created_at).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):""});function xm({currentUser:t,incomingMessage:s,onReadMessages:n,onReadNotifications:r,onOrderClick:l}){const{t:c}=qt(),[o,d]=a.useState(""),[p,y]=a.useState([]),[j,b]=a.useState([]),[h,v]=a.useState(!1),[i,x]=a.useState(!0),[m,N]=a.useState(!1),[R,S]=a.useState([]),C=5,[L,U]=a.useState(!1),W=a.useRef(0),[re,Z]=a.useState(!1),O=a.useRef(null),[F,D]=a.useState(!1),$=a.useRef(null),z=a.useRef(null),me=a.useRef(null),[K,te]=a.useState(!1),[I,B]=a.useState(null),[Ne,Ue]=a.useState(null),[$e,H]=a.useState(null),[le,Qe]=a.useState("messages");a.useEffect(()=>{if(!I)return;const u=_=>{_.key==="Escape"&&B(null)};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[I]);const k=a.useRef(!0),xe=50,[de,V]=a.useState(!1),[ye,Ie]=a.useState(0),[Oe,we]=a.useState(!1),Le=a.useRef(null),_t=a.useRef(null),jt=a.useRef(null),dt=a.useRef(!1),gt=a.useRef(Date.now()),ht=a.useRef(null),qe=fc(),[it,Ge]=a.useState(null);a.useLayoutEffect(()=>{Ge(hc(ht.current,qe))},[qe.inset,qe.visibleBottom]),a.useEffect(()=>{if(!it)return;const u=Le.current;u&&k.current&&(u.scrollTop=u.scrollHeight)},[it]),a.useEffect(()=>{const u=At.channel("admin-presence").on("broadcast",{event:"heartbeat"},()=>{Z(!0),O.current&&clearTimeout(O.current),O.current=setTimeout(()=>Z(!1),18e4)}).subscribe(_=>{_==="SUBSCRIBED"&&u.send({type:"broadcast",event:"ping_request",payload:{}})});return()=>{At.removeChannel(u),O.current&&clearTimeout(O.current)}},[]),a.useEffect(()=>{const u=jt.current;if(!u)return;const _=ht.current?.clientHeight||0,P=_?Math.max(88,Math.min(320,Math.round(_*.4))):320;u.style.maxHeight=`${P}px`,u.style.height="auto",u.style.height=`${Math.min(u.scrollHeight,P)}px`,u.selectionStart===u.value.length&&(u.scrollTop=u.scrollHeight)},[o,it]),a.useEffect(()=>{if(t?.id)try{const u=localStorage.getItem(`client_chat_draft_${t.id}`);u&&d(u)}catch{}},[t?.id]),a.useEffect(()=>{if(t?.id)try{const u=`client_chat_draft_${t.id}`;o?localStorage.setItem(u,o):localStorage.removeItem(u)}catch{}},[o,t?.id]),a.useEffect(()=>{if(!t?.id)return;const u=At.channel(`typing-${t.id}`).on("broadcast",{event:"typing"},()=>{D(!0),$.current&&clearTimeout($.current),$.current=setTimeout(()=>D(!1),3e3)}).subscribe();return z.current=At.channel(`typing-client-${t.id}`).subscribe(),()=>{At.removeChannel(u),z.current&&At.removeChannel(z.current),$.current&&clearTimeout($.current)}},[t?.id]);const St=()=>{z.current&&(me.current||(z.current.send({type:"broadcast",event:"typing",payload:{}}),me.current=setTimeout(()=>{me.current=null},2e3)))};a.useEffect(()=>{if(!t?.id)return;Pt();const u=At.channel("user-messages-page").on("postgres_changes",{event:"UPDATE",schema:"public",table:"messages",filter:`user_id=eq.${t.id}`},_=>{const P=_.new;P.is_read&&y(A=>A.map(M=>M.id===P.id?{...M,isRead:!0}:M))}).on("postgres_changes",{event:"INSERT",schema:"public",table:"notifications",filter:`user_id=eq.${t.id}`},_=>{b(P=>[_.new,...P])}).subscribe();return()=>{At.removeChannel(u)}},[t?.id]),a.useEffect(()=>{if(!s)return;const u=Dn(s);y(_=>_.some(P=>P.id===u.id)?_:(dt.current=!0,[..._,u])),u.sender==="ADMIN"&&new Date(s.created_at).getTime()>=gt.current&&(Je("messages",{id:u.id},{is_read:!0}),n&&n())},[s]),a.useEffect(()=>{if(!i&&!Oe){k.current=!0;const u=()=>{const P=Le.current;P&&(P.scrollTop=P.scrollHeight)};requestAnimationFrame(()=>requestAnimationFrame(u));const _=setTimeout(u,300);return()=>clearTimeout(_)}},[i]),a.useEffect(()=>{if(!(i||Oe||!dt.current))if(dt.current=!1,k.current){const u=Le.current;u&&(u.scrollTop=u.scrollHeight),te(!1)}else te(!0)},[p]);const Pt=async()=>{x(!0),Ie(0);try{const[u,_]=await Promise.all([Re("messages",{user_id:t.id},{order:"created_at.desc",limit:xe}),Re("notifications",{user_id:t.id},{order:"date.desc"})]);if(u.data){const P=u.data.filter(M=>!M.deleted).map(Dn).reverse();V(u.data.length===xe),P.some(M=>M.sender==="ADMIN"&&!M.isRead)?(y(P.map(M=>M.sender==="ADMIN"?{...M,isRead:!0}:M)),Je("messages",{user_id:t.id,sender:"ADMIN",is_read:!1},{is_read:!0})):y(P),n&&n()}_.data&&b(_.data)}catch{}finally{x(!1)}},Ut=async()=>
57{if(!t?.id||Oe||!de)return;we(!0);const u=Le.current,_=u?.scrollHeight??0,P=ye+xe,{data:A}=await Re("messages",{user_id:t.id},{order:"created_at.desc",limit:xe,offset:P}),M=(A||[]).filter(ie=>!ie.deleted).map(Dn).reverse();V((A||[]).length===xe),Ie(P),y(ie=>[...M,...ie]),requestAnimationFrame(()=>{u&&(u.scrollTop=u.scrollHeight-_)}),we(!1)},xt=async()=>{const u=j.filter(_=>!_.is_read).map(_=>_.id);u.length!==0&&(b(_=>_.map(P=>({...P,is_read:!0}))),r?.(u.length),await Je("notifications",{id:`in.(${u.join(",")})`},{is_read:!0}))},zt=async u=>{j.find(_=>_.id===u&&!_.is_read)&&(b(_=>_.map(P=>P.id===u?{...P,is_read:!0}:P)),r?.(1),await Je("notifications",{id:u},{is_read:!0}))},J=u=>{if(!u.length)return;const _=C-R.length;if(_<=0){alert(`Ðожно пÑиложиÑÑ Ð½Ðµ более ${C} Ñайлов за Ñаз`);return}const P=50*1024*1024;u.some(ie=>ie.size>P)&&alert(c("messages_file_too_large"));const M=u.filter(ie=>ie.size<=P).slice(0,_);S(ie=>[...ie,...M.map(ge=>({file:ge,previewUrl:ge.type.startsWith("image/")?URL.createObjectURL(ge):null}))])},We=u=>{J(Array.from(u.target.files||[])),u.target.value=""},oe=u=>{u.dataTransfer.types.includes("Files")&&(u.preventDefault(),W.current++,U(!0))},Y=u=>{u.dataTransfer.types.includes("Files")&&u.preventDefault()},Se=u=>{u.preventDefault(),W.current=Math.max(0,W.current-1),W.current===0&&U(!1)},ve=u=>{u.preventDefault(),W.current=0,U(!1),J(Array.from(u.dataTransfer.files||[]))},T=u=>{S(_=>{const P=_[u];return P?.previewUrl&&URL.revokeObjectURL(P.previewUrl),_.filter((A,M)=>M!==u)})},ke=u=>{const _=Array.from(u.clipboardData.items).find(P=>P.type.startsWith("image/"))?.getAsFile();_&&(R.length>=C||(u.preventDefault(),S(P=>[...P,{file:_,previewUrl:URL.createObjectURL(_)}])))},be=u=>u.sender!=="USER"?!1:!u.isRead,Ae=async u=>{Ue(null),y(P=>P.filter(A=>A.id!==u));const{error:_}=await Je("messages",{id:u},{deleted:!0})},E=async()=>{if(!o.trim()&&R.length===0||h||!t?.id)return;v(!0);const u=o.trim(),_=R;dt.current=!0,d(""),S([]),H(null);let P=$e?{id:$e.id,text:$e.text,sender:$e.sender,manager_name:$e.manager_name}:null;{const M=t?.name?`${t.name}${t?.friendly_id?` (#${t.friendly_id})`:""}`:t?.friendly_id?`#${t.friendly_id}`:"клиенÑ",ie=[];u&&ie.push(u),_.length>0&&ie.push(`ð ${_.length} Ñайл(ов)`),At.functions.invoke("send-telegram",{body:{to_admin:!0,message:`ð¬ <b>Ðовое ÑообÑение Ð¾Ñ ÐºÐ»Ð¸ÐµÐ½Ñа</b> 58 59ð¤ ${M} 60ð ${ie.join(` 61`)||"(пÑÑÑо)"}`}}).catch(()=>{})}const A=async M=>{const ie=crypto.randomUUID(),ge={id:ie,user_id:t.id,sender:"USER",text:"",is_read:!1,created_at:new Date().toISOString(),reply_to:P,...M};P=null,y(fe=>[...fe,Dn(ge)]);const{error:w}=await st("messages",ge);w&&y(fe=>fe.filter(pe=>pe.id!==ie))};try{u&&await A({text:u});for(const{file:M,previewUrl:ie}of _){N(!0);try{const ge=M.type.startsWith("image/")?await Er(M,1600,.88):M,w=ge.name.split(".").pop();let fe="",pe=null;for(let mt=1;mt<=2;mt++){const Tt=`messages/${Date.now()}_${Math.random().toString(36).slice(2)}.${w}`,{publicUrl:G,error:q}=await Ln("chat-files",Tt,ge,mt);if(!q){fe=Tt,pe=null;break}pe=q,mt<2&&await new Promise(he=>setTimeout(he,1500))}if(pe)throw new Error(pe);ie&&URL.revokeObjectURL(ie);const je=fo("chat-files",fe),ze=M.type.startsWith("image/")?"image":M.type.includes("zip")?"zip":"pdf";await A({file_url:je,file_name:M.name,file_type:ze})}catch{alert("Ðе ÑдалоÑÑ Ð·Ð°Ð³ÑÑзиÑÑ Ñайл: "+M.name)}finally{N(!1)}}}catch{}finally{v(!1),N(!1)}};if(i)return e.jsx("div",{className:"flex justify-center items-center h-[500px]",children:e.jsx(rt,{className:"w-8 h-8 text-blue-600 animate-spin"})});const se=p.filter(u=>u.sender==="ADMIN"&&!u.isRead).length,ee=j.filter(u=>!u.is_read).length;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"md:hidden flex gap-1 mb-3 bg-slate-100 rounded-xl p-1 shrink-0",children:[e.jsxs("button",{onClick:()=>Qe("messages"),className:`flex-1 flex items-center justify-center gap-1.5 py-2 rounded-lg text-sm font-bold transition-colors ${le==="messages"?"bg-white text-blue-600 shadow-sm":"text-slate-500"}`,children:[e.jsx(Ur,{size:16}),c("messages_tab_messages"),se>0&&e.jsx("span",{className:"w-4 h-4 bg-red-500 text-white text-[10px] rounded-full flex items-center justify-center leading-none",children:se>9?"9+":se})]}),e.jsxs("button",{onClick:()=>{Qe("notifications"),ee>0&&xt()},className:`flex-1 flex items-center justify-center gap-1.5 py-2 rounded-lg text-sm font-bold transition-colors ${le==="notifications"?"bg-white text-red-500 shadow-sm":"text-slate-500"}`,children:[e.jsx(_s,{size:16}),c("messages_tab_notifications"),ee>0&&e.jsx("span",{className:"w-4 h-4 bg-red-500 text-white text-[10px] rounded-full flex items-center justify-center leading-none",children:ee>9?"9+":ee})]})]}),e.jsxs("div",{ref:ht,style:it?{height:`${it}px`}:void 0,className:"flex flex-col md:flex-row gap-4 h-[calc(100dvh-232px)] md:h-[calc(100dvh-140px)] min-h-0",children:[e.jsxs("div",{className:`${le==="messages"?"flex":"hidden"} md:flex flex-col flex-[3] min-h-0 bg-white rounded-2xl shadow-sm border border-slate-200 overflow-hidden`,children:[(()=>{const _=[...p].reverse().find(P=>P.sender==="ADMIN"&&P.senderRole==="MANAGER"&&P.managerName)?.managerName||null;return e.jsxs("div",{className:"flex items-center gap-3 px-5 py-4 border-b border-slate-100 shrink-0",children:[e.jsxs("div",{className:"relative",children:[(()=>{const P=_?rc(_):null;return P?.avatar?e.jsx("img",{src:P.avatar,alt:P.name,className:"w-9 h-9 rounded-xl object-cover"}):e.jsx("div",{className:"w-9 h-9 bg-blue-100 rounded-xl flex items-center justify-center font-bold text-blue-700 text-sm",children:_?_.charAt(0):e.jsx(Ur,{size:18,className:"text-blue-600"})})})(),e.jsx("span",{className:`absolute bottom-0 right-0 w-2.5 h-2.5 rounded-full border-2 border-white ${re?"bg-green-500":"bg-slate-300"}`})]}),e.jsxs("div",{children:[e.jsx("div",{className:"font-bold text-slate-800 text-sm",children:_?c("messages_chat_manager_title",{name:_}):c("messages_chat_default_title")}),e.jsx("div",{className:`text-xs font-medium ${re?"text-green-600":"text-slate-400"}`,children:c(re?"messages_online":"messages_offline")})]})]})})(),e.jsxs("div",{className:"flex-1 min-h-0 relative",children:[e.jsxs("div",{ref:Le,className:"ym-hide-content h-full overflow-y-auto p-4 md:p-5 space-y-4",onScroll:()=>{const u=Le.current;if(!u)return;u.scrollTop<80&&de&&!Oe&&Ut();const _=u.scrollHeight-u.scrollTop-u.clientHeight<80;k.current=_,_&&te(!1)},children:[Oe&&e.jsx("div",{className:"flex justify-center py-2",children:e.jsx(rt,{className:"w-4 h-4 text-slate-400 animate-spin"})}),!de&&p.length>0&&e.jsx("div",{className:"text-center text-[10px] text-slate-400 py-1",children:c("messages_history_start")}),p.length===0&&e.jsxs("div",{className:"text-center py-10 text-slate-400",children:[e.jsx(Ur,{size:40,className:"mx-auto mb-3 opacity-20"}),e.jsx("p",{className:"text-sm",children:c("messages_start_dialog")})]}),p.map((u,_)=>{const P=p[_-1],A=!P||oi(u.created_at)!==oi(P.created_at),M=u.sender==="ADMIN",ie=u.senderRole,ge=u.managerName,w=M?ie==="DIRECTOR"?c("messages_role_director"):ie==="ADMIN"?c("messages_role_admin"):ge||c("messages_role_manager_default"):null,fe=!u.text&&!u.reply_to&&u.fileType==="image",pe=fe?M?"rounded-bl-none":"rounded-br-none":M?ie==="DIRECTOR"?"bg-gradient-to-br from-amber-50 to-orange-50 border border-amber-200 text-slate-800 rounded-bl-none":ie==="ADMIN"?"bg-gradient-to-br from-indigo-50 to-indigo-100 border border-indigo-200 text-slate-800 rounded-bl-none":"bg-white border border-slate-200 text-slate-800 rounded-bl-none":"bg-blue-400/80 text-white rounded-br-none";return e.jsxs(ct.Fragment,{children:[A&&e.jsxs("div",{className:"flex items-center gap-3 my-2",children:[e.jsx("div",{className:"flex-1 h-px bg-slate-200"}),e.jsx("span",{className:"text-[11px] text-slate-400 font-medium shrink-0",children:um(u.created_at,c)}),e.jsx("div",{className:"flex-1 h-px bg-slate-200"})]}),e.jsxs("div",{id:`msg-${u.id}`,className:`w-full flex flex-col group/msg ${u.sender==="USER"?"items-end":"items-start"}`,children:[w&&e.jsx("span",{className:`text-[10px] font-bold mb-1 px-1 ${ie==="DIRECTOR"?"text-amber-600":ie==="ADMIN"?"text-indigo-600":"text-slate-500"}`,children:w}),e.jsxs("div",{className:`w-full flex items-end gap-1.5 ${u.sender==="USER"?"justify-end":"justify-start"}`,children:[u.sender==="USER"&&e.jsxs("div",{className:"flex items-center gap-0.5 flex-shrink-0 mb-1",children:[e.jsx("button",{onClick:()=>H({id:u.id,text:u.text||"",sender:u.sender}),className:"p-1 text-slate-300 hover:text-blue-400 transition-colors opacity-0 group-hover/msg:opacity-100",children:e.jsx($r,{size:13})}),be(u)&&(Ne===u.id?e.jsxs("div",{className:"flex items-center gap-1 bg-white border border-red-200 rounded-xl px-2 py-1 shadow-sm",children:[e.jsx("span",{className:"text-[10px] text-slate-500",children:c("messages_delete_confirm")}),e.jsx("button",{onClick:()=>Ae(u.id),className:"text-[10px] font-bold text-red-500 hover:text-red-700 px-1",children:c("messages_yes")}),e.jsx("button",{onClick:()=>Ue(null),className:"text-[10px] text-slate-400 hover:text-slate-600 px-1",children:c("messages_no")})]}):e.jsx("button",{onClick:()=>Ue(u.id),className:"p-1 text-slate-300 hover:text-red-400 transition-colors opacity-0 group-hover/msg:opacity-100",children:e.jsx(is,{size:13})}))]}),e.jsxs("div",{className:`max-w-[94%] md:max-w-[80%] rounded-2xl text-sm shadow-sm ${pe} ${fe?"p-0 overflow-hidden":"px-4 py-3"}`,children:[u.reply_to&&e.jsxs("div",{className:"mb-2 px-2.5 py-1.5 rounded-lg border-l-[3px] border-current bg-black/10 cursor-pointer",onClick:()=>{const je=document.getElementById(`msg-${u.reply_to.id}`);je&&je.scrollIntoView({behavior:"smooth",block:"center"})},children:[e.jsx("p",{className:"text-[10px] font-bold opacity-80 truncate",children:u.reply_to.sender==="ADMIN"?u.reply_to.manager_name||c("messages_role_manager_default"):c("messages_you")}),e.jsx("p",{className:"text-xs opacity-70 line-clamp-2",children:u.reply_to.text||c("messages_attachment")})]}),u.text&&e.jsx("p",{className:"leading-relaxed whitespace-pre-wrap break-words",children:u.text}),u.fileUrl&&u.fileType==="image"&&e.jsxs("div",{className:`relative group inline-block ${u.text?"mt-2":""}`,children:[e.jsx("img",{src:u.fileUrl,alt:u.fileName,className:"rounded-2xl object-cover cursor-pointer block hover:brightness-95 transition-all",style:{maxWidth:"220px",maxHeight:"280px",width:"auto",height:"auto"},onClick:()=>B({url:u.fileUrl,name:u.fileName||"image"})}),fe&&e.jsxs("div",{className:"absolute bottom-1.5 right-2 flex items-center gap-1 bg-black/40 rounded-md px-1.5 py-0.5",children:[e.jsx("span",{className:"text-[10px] text-white/90 font-medium",children:u.timestamp}),u.isRead?e.jsx(xl,{size:11,className:"text-white/90"}):e.jsx(Kt,{size:11,className:"text-white/90"})]})]}),u.fileUrl&&(u.fileType==="pdf"||u.fileType==="zip")&&e.jsxs("a",{href:u.fileUrl,target:"_blank",rel:"noreferrer",className:`flex items-center gap-2 mt-1 text-xs underline ${u.sender==="USER"?"text-blue-100":"text-blue-600"}`,children:[u.fileType==="zip"?"ðï¸":"ð"," ",u.fileName]}),!fe&&e.jsxs("div",{className:"text-[10px] mt-1.5 text-right font-medium opacity-70 flex items-center justify-end gap-1",children:[u.timestamp,u.sender==="USER"&&(u.isRead?e.jsx(xl,{size:12}):e.jsx(Kt,{size:12}))]})]}),u.sender==="ADMIN"&&e.jsx("button",{onClick:()=>H({id:u.id,text:u.text||"",sender:u.sender,manager_name:u.managerName}),className:"flex-shrink-0 mb-1 p-1 text-slate-300 hover:text-blue-400 transition-colors opacity-0 group-hover/msg:opacity-100",children:e.jsx($r,{size:13})})]})]})]},_)}),F&&e.jsxs("div",{className:"flex items-start gap-2 mt-2",children:[e.jsx("style",{children:"@keyframes typingDot{0%,80%,100%{transform:translateY(0);opacity:.35}40%{transform:translateY(-5px);opacity:1}}"}),e.jsxs("div",{className:"bg-white border border-slate-200 rounded-2xl rounded-bl-none px-4 py-2.5 shadow-sm flex items-center gap-2",children:[e.jsx("span",{className:"text-slate-400 text-xs font-medium",children:c("messages_typing")}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"w-1.5 h-1.5 bg-slate-400 rounded-full",style:{animation:"typingDot 1.2s ease-in-out infinite",animationDelay:"0ms"}}),e.jsx("span",{className:"w-1.5 h-1.5 bg-slate-400 rounded-full",style:{animation:"typingDot 1.2s ease-in-out infinite",animationDelay:"200ms"}}),e.jsx("span",{className:"w-1.5 h-1.5 bg-slate-400 rounded-full",style:{animation:"typingDot 1.2s ease-in-out infinite",animationDelay:"400ms"}})]})]})]})]}),K&&e.jsx("button",{onClick:()=>{const u=Le.current;u&&(u.scrollTop=u.scrollHeight),te(!1)},className:"absolute bottom-4 right-4 bg-blue-600 text-white rounded-full px-3 py-2 text-xs font-bold shadow-lg flex items-center gap-1.5 hover:bg-blue-700 transition-colors z-10",children:c("messages_new_message_scroll")})]}),e.jsxs("div",{className:`relative bg-white border-t border-slate-200 p-4 shrink-0 ${L?"bg-blue-50":""}`,onDragEnter:oe,onDragOver:Y,onDragLeave:Se,onDrop:ve,children:[L&&e.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-blue-50/90 border-2 border-dashed border-blue-400 rounded-t-xl pointer-events-none",children:e.jsxs("div",{className:"flex items-center gap-2 text-blue-600 font-bold text-sm",children:[e.jsx(Bn,{size:18})," ",c("messages_drop_to_attach")]})}),e.jsx("input",{ref:_t,type:"file",accept:"image/png,image/jpeg,image/jpg,application/pdf,application/zip,.zip",multiple:!0,className:"hidden",onChange:We}),$e&&e.jsxs("div",{className:"flex items-center gap-2 mb-2 px-3 py-2 bg-blue-50 border border-blue-200 rounded-xl border-l-4 border-l-blue-400",children:[e.jsx($r,{size:13,className:"text-blue-500 flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-[10px] font-bold text-blue-600 mb-0.5",children:$e.sender==="ADMIN"?$e.manager_name||c("messages_role_manager_default"):c("messages_you")}),e.jsx("p",{className:"text-xs text-slate-600 truncate",children:$e.text||c("messages_attachment")})]}),e.jsx("button",{onClick:()=>H(null),className:"p-1 text-slate-400 hover:text-slate-600 flex-shrink-0",children:e.jsx(bt,{size:14})})]}),R.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 mb-2",children:R.map((u,_)=>e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 bg-slate-50 rounded-xl border border-slate-200",children:[u.previewUrl?e.jsx("img",{src:u.previewUrl,className:"w-10 h-10 object-cover rounded-lg flex-shrink-0"}):e.jsx("div",{className:"w-10 h-10 bg-slate-100 rounded-lg flex items-center justify-center text-xl flex-shrink-0",children:u.file.type.includes("zip")?"ðï¸":"ð"}),e.jsxs("div",{className:"min-w-0 max-w-[140px]",children:[e.jsx("p",{className:"text-xs text-slate-700 font-medium truncate",children:u.file.name}),e.jsxs("p",{className:"text-[10px] text-slate-400",children:[(u.file.size/1024/1024).toFixed(1)," ",c("messages_mb_unit")]})]}),e.jsx("button",{onClick:()=>T(_),className:"p-1 text-slate-400 hover:text-red-500 transition-colors flex-shrink-0",children:e.jsx(bt,{size:15})})]},_))}),e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx("textarea",{ref:jt,rows:1,className:"w-full bg-slate-50 border border-transparent focus:bg-white focus:border-blue-300 pl-4 pr-20 py-3 rounded-xl text-sm outline-none transition-all placeholder:text-slate-400 resize-none min-h-[64px] overflow-y-auto",placeholder:c("messages_input_placeholder"),value:o,onChange:u=>
61{d(u.target.value),St()},onKeyDown:u=>{u.key==="Enter"&&!u.shiftKey&&(u.preventDefault(),E())},onPaste:ke}),e.jsxs("div",{className:"absolute right-1.5 bottom-1.5 flex items-center gap-0.5",children:[e.jsx(pc,{onSelect:u=>d(_=>_+u)}),e.jsx("button",{onClick:()=>_t.current?.click(),disabled:m||R.length>=C,title:R.length>0?`${R.length}/${C}`:void 0,className:"p-2 text-slate-400 hover:text-slate-600 hover:bg-slate-200/60 rounded-lg transition-colors disabled:opacity-50",children:m?e.jsx(rt,{size:17,className:"animate-spin"}):e.jsx(Bn,{size:17})})]})]}),e.jsx("button",{onClick:E,disabled:!o.trim()&&R.length===0||h,className:"p-2.5 bg-blue-600 text-white rounded-xl hover:bg-blue-700 disabled:opacity-50 transition-all shadow-md shadow-blue-200 shrink-0",children:h?e.jsx(rt,{className:"animate-spin",size:18}):e.jsx(Ss,{size:18})})]})]})]}),e.jsxs("div",{className:`${le==="notifications"?"flex":"hidden"} md:flex flex-col flex-[1] min-h-0 bg-white rounded-2xl shadow-sm border border-slate-200 overflow-hidden`,"data-tour":"notifications-panel",children:[e.jsxs("div",{className:"flex items-center gap-3 px-5 py-4 border-b border-slate-100 shrink-0",children:[e.jsx("div",{className:"w-9 h-9 bg-red-50 rounded-xl flex items-center justify-center shrink-0",children:e.jsx(_s,{size:18,className:"text-red-500"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"font-bold text-slate-800 text-sm",children:c("messages_tab_notifications")}),ee>0&&e.jsx("div",{className:"text-xs text-red-500 font-medium",children:c("messages_new_count",{count:ee})})]}),ee>0&&e.jsx("button",{onClick:xt,className:"text-xs text-slate-400 hover:text-slate-600 underline transition-colors shrink-0",children:c("messages_mark_all_read")})]}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto p-4 space-y-3",children:[j.length===0&&e.jsxs("div",{className:"text-center py-10 text-slate-400",children:[e.jsx(_s,{size:40,className:"mx-auto mb-3 opacity-20"}),e.jsx("p",{className:"text-sm",children:c("messages_no_notifications")})]}),j.map(u=>{const _=u.title&&(u.title.includes("ð¦")||u.title.includes("Ñпакован")||u.title.includes("коÑÑекÑиÑовк")),P=u.type==="DELIVERY_INVOICE",A=u.type==="ANNOUNCEMENT",M=_||P,ie=!!(u.link&&l);return e.jsxs("div",{onClick:!ie&&!u.is_read?()=>zt(u.id):void 0,className:`p-4 rounded-xl border shadow-sm flex gap-3 ${M?"bg-orange-50 border-orange-200":A?"bg-amber-50 border-amber-200":"bg-white border-slate-200"} ${u.is_read?"":"border-l-4 "+(M?"border-l-orange-500":A?"border-l-amber-500":"border-l-blue-500")} ${!ie&&!u.is_read?"cursor-pointer hover:bg-slate-50 transition-colors":""}`,children:[e.jsx("div",{className:`mt-0.5 p-2 rounded-lg flex-shrink-0 ${M?"bg-orange-100 text-orange-600":A?"bg-amber-100 text-amber-600":u.type==="ORDER"?"bg-blue-50 text-blue-600":u.type==="PAYMENT"?"bg-green-50 text-green-600":u.type==="SYSTEM"?"bg-red-50 text-red-500":"bg-purple-50 text-purple-600"}`,children:P?e.jsx(Lt,{size:16}):_?e.jsx(js,{size:16}):A?e.jsx(Fo,{size:16}):u.type==="ORDER"?e.jsx(Bo,{size:16}):u.type==="PAYMENT"?e.jsx(Kt,{size:16}):u.type==="SYSTEM"?e.jsx(_s,{size:16}):e.jsx(gs,{size:16})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex justify-between items-start gap-2",children:[e.jsx("h3",{className:"font-bold text-slate-900 text-sm leading-snug",children:u.title}),e.jsx("span",{className:"text-[10px] text-slate-400 font-medium shrink-0",children:new Date(u.date||u.created_at).toLocaleDateString()})]}),e.jsx("p",{className:"text-xs text-slate-600 mt-1 leading-relaxed",children:u.text}),ie&&e.jsxs("button",{onClick:()=>{zt(u.id),l(u.link,M)},className:`mt-2 inline-flex items-center gap-1 text-xs font-bold px-2.5 py-1 rounded-lg transition-colors ${P?"text-orange-700 bg-orange-100 hover:bg-orange-200 border border-orange-200":"text-blue-600 bg-blue-50 hover:bg-blue-100"}`,children:[P?e.jsx(Lt,{size:12}):e.jsx(js,{size:12}),c(P?"orders_pay_delivery_button":"messages_to_order")," ",e.jsx(Ga,{size:10})]})]})]},u.id)})]})]})]}),I&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/85 backdrop-blur-sm",onClick:()=>B(null),children:e.jsxs("div",{className:"relative max-w-[90vw] max-h-[90vh]",onClick:u=>u.stopPropagation(),children:[e.jsx("img",{src:I.url,alt:I.name,className:"max-w-[90vw] max-h-[90vh] rounded-xl object-contain shadow-2xl"}),e.jsxs("div",{className:"absolute top-3 right-3 flex gap-2",children:[e.jsx("a",{href:I.url,download:I.name,target:"_blank",rel:"noreferrer",onClick:u=>u.stopPropagation(),className:"p-2 bg-black/50 hover:bg-black/70 text-white rounded-xl transition-colors",title:c("messages_download_title"),children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:e.jsx("path",{d:"M12 15V3m0 12-4-4m4 4 4-4M2 17l.621 2.485A2 2 0 0 0 4.561 21h14.878a2 2 0 0 0 1.94-1.515L22 17"})})}),e.jsx("button",{onClick:()=>B(null),className:"p-2 bg-black/50 hover:bg-black/70 text-white rounded-xl transition-colors",children:e.jsx(bt,{size:16})})]})]})})]})}const mm="Goods_China_bot",pm=!1,Ks=[{key:"RU",code:"+7",labelKey:"profile_country_russia",length:10},{key:"KZ",code:"+7",labelKey:"profile_country_kazakhstan",length:10},{key:"BY",code:"+375",labelKey:"profile_country_belarus",length:9},{key:"KG",code:"+996",labelKey:"profile_country_kyrgyzstan",length:9}],fm=[{value:"",labelKey:"profile_transport_not_selected",label:""},{value:"CDEK",label:"СÐÐÐ"},{value:"PEK",label:"ÐÐÐ"},{value:"DL",label:"ÐеловÑе Ðинии"},{value:"KIT",label:"ÐÐТ (GTD)"},{value:"BAIKAL",label:"Ðайкал СеÑвиÑ"},{value:"ENERGIA",label:"ÐнеÑгиÑ"},{value:"MAGIC_TRANS",label:"Magic Trans"}
61,{value:"ZHELDOR",label:"ÐелÐоÑÐкÑпедиÑиÑ"},{value:"MEGATRANS",label:"Ðега ÑÑанÑ"},{value:"VICTORIA",label:"ÐикÑоÑиÑ"},{value:"VOZOVOZ",label:"Ðозовоз"},{value:"GLAVTRASA",label:"ÐлавÑÑаÑа"},{value:"PICKUP",labelKey:"delivery_pickup_option",label:""}],hm=["ÐоÑква","СанкÑ-ÐеÑеÑбÑÑг","ÐовоÑибиÑÑк","ÐкаÑеÑинбÑÑг","ÐазанÑ","Ðижний ÐовгоÑод","ÐоÑ","ÐладивоÑÑок","ÐемеÑово","ÐÑаÑнодаÑ","ÐмÑк"];function ci(t={}){return{id:crypto.randomUUID(),label:"",isDefault:!1,surname:"",name:"",patronymic:"",phoneCode:"+7",phoneCountryKey:"RU",phone:"",city:"",passportSeries:"",passportNumber:"",transportCompany:"",market:"",gender:"",birthDate:"",...t}}const bm=({initialData:t,onProfileUpdate:s,hasPendingUpdate:n,updateMessage:r})=>{const{t:l}=qt(),[c,o]=a.useState(!1),[d,p]=a.useState(null),[y,j]=a.useState(()=>localStorage.getItem("pd_consent_given")==="1"),b=localStorage.getItem("pd_consent_given")==="1",[h,v]=a.useState(!0),[i,x]=a.useState([]),[m,N]=a.useState(!0),[R,S]=a.useState(new Set),C=E=>{S(se=>{const ee=new Set(se);return ee.has(E)?ee.delete(E):ee.add(E),ee})},[L,U]=a.useState(null),[W,re]=a.useState(""),[Z,O]=a.useState(null),[F,D]=a.useState(""),[$,z]=a.useState("idle"),[me,K]=a.useState(null),te=ho(),[I,B]=a.useState(null),[Ne,Ue]=a.useState(!1),[$e,H]=a.useState(!0),[le,Qe]=a.useState(!1),[k,xe]=a.useState(!1),[de,V]=a.useState(!1),[ye,Ie]=a.useState(!1),Oe=a.useRef(!1),[we,Le]=a.useState(null),[_t,jt]=a.useState(!1),[dt,gt]=a.useState(!1),[ht,qe]=a.useState(!1),[it,Ge]=a.useState(!1);a.useEffect(()=>{if(!t||Oe.current)return;Oe.current=!0,re(t.email||""),v(t.bonus_consent!==!1),B(t.telegram_chat_id||null),H(t.notification_prefs?.telegram!==!1),Qe(t.notification_prefs?.email===!0);const E=typeof Notification<"u"?Notification.permission:"denied";xe(t.notification_prefs?.browser===!0&&E==="granted"),V(t.notification_prefs?.push===!0&&E==="granted"),t.id&&Re("support_tickets",{user_id:t.id},{select:"id,messages,status"}).then(({data:P})=>{P?.some(M=>M.status!=="CLOSED"&&M.messages?.some(ie=>ie.text?.includes("ÐапÑÐ¾Ñ Ð½Ð° Ñдаление аккаÑнÑа")))&&Ge(!0)});const se=async P=>{const[A,M]=await Promise.all([Ar(P.passportSeries)?cn(t.id,P.passportSeries):Promise.resolve(P.passportSeries),Ar(P.passportNumber)?cn(t.id,P.passportNumber):Promise.resolve(P.passportNumber)]);return{...P,passportSeries:A??P.passportSeries,passportNumber:M??P.passportNumber}};if(Array.isArray(t.delivery_recipients)&&t.delivery_recipients.length>0){Promise.all(t.delivery_recipients.map(se)).then(P=>{x(P),N(!1)});return}let ee=t.surname||"",u=t.first_name||"";if(!ee&&!u&&t.name){const P=t.name.split(" ");ee=P[0]||"",u=P[1]||""}const _=ci({label:l("profile_me"),isDefault:!0,surname:ee,name:u,patronymic:t.patronymic||"",phoneCode:t.phone_code||"+7",phone:t.phone||"",city:t.city||"",passportSeries:t.passport_series||"",passportNumber:t.passport_number||"",transportCompany:t.transport_company||"",gender:t.gender||"",birthDate:t.birth_date||""});se(_).then(P=>{x([P]),N(!1)})},[t]);const St=(E,se,ee)=>{x(u=>u.map(_=>_.id===E?{..._,[se]:ee}:_))},Pt=E=>{x(se=>se.map(ee=>({...ee,isDefault:ee.id===E})))},Ut=()=>{x(E=>[...E,ci({label:""})])},xt=async()=>{if(!L)return;const E=L;U(null);const se=i.filter(ee=>ee.id!==E);!se.some(ee=>ee.isDefault)&&se.length>0&&(se[0].isDefault=!0),x(se);try{const ee=yt();if(!ee)return;await Je("users",{id:ee},{delivery_recipients:se})}catch(ee){p({type:"error",text:l("common_delete_error_prefix")+ee.message})}},zt=(E,se,ee,u=30)=>{const _=ee.replace(/[^а-ÑÐ-ЯÑÐ\s-]/g,"").slice(0,u);St(E,se,_)},J=(E,se,ee)=>{const u=Ks.find(P=>P.key===ee)||Ks[0],_=se.replace(/\D/g,"").slice(0,u.length);St(E,"phone",_)},We=(E,se,ee,u)=>{const _=ee.replace(/\D/g,"").slice(0,u);St(E,se,_)},oe=(E,se)=>{const ee=Ks.find(u=>u.key===se)||Ks[0];x(u=>u.map(_=>_.id===E?{..._,phoneCountryKey:se,phoneCode:ee.code,phone:""}:_))},Y=(E,se)=>{if(!se){St(E,"birthDate","");return}const ee=se.split("-")[0];ee&&ee.length>4||St(E,"birthDate",se)},Se=async E=>{if(E.preventDefault(),!b&&!y){p({type:"error",text:l("profile_pd_consent_required")});return}y&&!b&&localStorage.setItem("pd_consent_given","1");const se=W.trim();if(se&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(se)){O(l("profile_invalid_email"));return}O(null),o(!0),p(null);try{const ee=yt();if(!ee)throw new Error("No user found");for(const ie of i){const ge=Ks.find(w=>w.key===ie.phoneCountryKey)||Ks[0];if(ie.phone.length>0&&ie.phone.length<ge.length){const w=ie.label||(ie===i[0]?l("profile_me"):l("profile_recipient_default"));p({type:"error",text:l("profile_incomplete_phone",{label:w,country:l(ge.labelKey),needed:ge.length,entered:ie.phone.length})}),o(!1);return}}const u=await Promise.all(i.map(async ie=>{const[ge,w]=await Promise.all([ie.passportSeries?Da(ee,ie.passportSeries):Promise.resolve(""),ie.passportNumber?Da(ee,
61ie.passportNumber):Promise.resolve("")]);if(ie.passportSeries&&ge===null||ie.passportNumber&&w===null)throw new Error(l("profile_passport_encrypt_error"));return{...ie,passportSeries:ge??"",passportNumber:w??""}})),_=u.find(ie=>ie.isDefault)||u[0],P=`${_.surname} ${_.name} ${_.patronymic}`.trim(),A={email:se||null,delivery_recipients:u,name:P,surname:_.surname,first_name:_.name,patronymic:_.patronymic,phone:_.phone,city:_.city,passport_series:_.passportSeries,passport_number:_.passportNumber,transport_company:_.transportCompany,gender:_.gender,birth_date:_.birthDate||null,bonus_consent:h,notification_prefs:{telegram:$e,email:le,browser:k,push:de}},{error:M}=await Je("users",{id:ee},A);if(M)throw new Error(M);Re("users",{id:ee},{select:"email",single:!0}).then(({data:ie})=>{const ge=new AbortController,w=setTimeout(()=>ge.abort(),8e3);fetch("/pd/profile",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:ee,email:ie?.email||null,name:_.name,surname:_.surname,patronymic:_.patronymic,phone:_.phone,delivery_recipients:u}),signal:ge.signal}).then(()=>{}).catch(fe=>{}).finally(()=>clearTimeout(w))}),p({type:"success",text:l("profile_update_success")}),s(),setTimeout(()=>p(null),3e3)}catch(ee){p({type:"error",text:l("common_error_prefix")+ee.message}),setTimeout(()=>p(null),4e3)}finally{o(!1)}},ve=async()=>{const E=F.trim();if(!E||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(E)){z("error"),K(l("profile_invalid_email"));return}z("saving"),K(null);const{error:se}=await bo(E);if(se){z("error"),K(se==="timeout"?l("auth_error_timeout"):se);return}z("sent"),D("")},T=async()=>{Ue(!0);try{const E=yt();if(!E)return;const se=crypto.randomUUID().replace(/-/g,"").slice(0,16);await Je("users",{id:E},{telegram_link_token:se}),window.open(`https://t.me/${mm}?start=${se}`,"_blank"),setTimeout(async()=>{const{data:ee}=await Re("users",{id:E},{select:"telegram_chat_id",single:!0});ee?.telegram_chat_id&&B(ee.telegram_chat_id),Ue(!1)},1e4)}catch{Ue(!1)}},ke=async()=>{const E=yt();E&&(await Je("users",{id:E},{telegram_chat_id:null,notification_prefs:{telegram:!1,email:le,browser:k,push:de}}),B(null))},be=async()=>{gt(!0);try{const E=yt();if(!E)return;const se=i.find(M=>M.isDefault)||i[0],ee=se?`${se.surname} ${se.name}`.trim():"Ðе Ñказано",u={user_id:E,status:"OPEN",messages:[{id:crypto.randomUUID(),sender:"CLIENT",text:`â ï¸ ÐапÑÐ¾Ñ Ð½Ð° Ñдаление аккаÑнÑа 62 63ÐмÑ: ${ee} 64ID: ${E}`,created_at:new Date().toISOString()}],client_unread:!1,created_at:new Date().toISOString(),updated_at:new Date().toISOString()},{error:_}=await st("support_tickets",u);if(_)throw new Error(_);Ge(!0);const{data:P,error:A}=await At.functions.invoke("send-telegram",{body:{to_admin:!0,message:`ð <b>ÐапÑÐ¾Ñ Ð½Ð° Ñдаление аккаÑнÑа</b> 65 66ð¤ ${ee} 67ð ${E} 68 69ÐбÑабоÑайÑе запÑÐ¾Ñ Ð² ÑеÑение 30 дней ÑоглаÑно 152-ФÐ.`}});qe(!0)}catch{}gt(!1)},Ae=new Date().toISOString().split("T")[0];return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"max-w-4xl xl:max-w-5xl mx-auto font-sans pb-10",children:[e.jsx("div",{className:"mb-8",children:e.jsx("h1",{className:"text-2xl font-bold text-slate-900",children:l("profile_title")})}),d&&e.jsxs("div",{className:`fixed bottom-6 left-1/2 -translate-x-1/2 z-50 flex items-center gap-3 px-5 py-3.5 rounded-2xl shadow-xl text-sm font-semibold transition-all ${d.type==="success"?"bg-green-600 text-white":"bg-red-600 text-white"}`,children:[d.type==="success"&&e.jsx(as,{size:18}),e.jsx("span",{children:d.text})]}),e.jsxs("form",{onSubmit:Se,className:"space-y-4 relative",children:[c&&e.jsx("div",{className:"fixed inset-0 bg-white/50 backdrop-blur-sm z-50 flex items-center justify-center",children:e.jsx(rt,{className:"w-8 h-8 text-blue-600 animate-spin"})}),m&&e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx(rt,{className:"w-6 h-6 text-blue-600 animate-spin"})}),!m&&i.map((E,se)=>{const ee=Ks.find(_=>_.key===E.phoneCountryKey)||Ks[0],u=se===0;return e.jsxs("div",{className:`ym-hide-content bg-white rounded-2xl shadow-sm border p-6 space-y-6 transition-all ${E.isDefault?"border-blue-400 ring-2 ring-blue-100":"border-slate-200"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 pb-2 border-b border-slate-100",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[e.jsx("div",{className:`w-9 h-9 rounded-xl flex items-center justify-center shrink-0 ${E.isDefault?"bg-blue-600 text-white":"bg-slate-100 text-slate-400"}`,children:e.jsx(gs,{size:17})}),e.jsx("input",{type:"text",placeholder:l(u?"profile_me":"profile_name_placeholder"),maxLength:30,value:E.label,onChange:_=>St(E.id,"label",_.target.value),className:"flex-1 min-w-0 text-sm font-bold text-slate-800 placeholder-slate-300 border-none outline-none bg-transparent"})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsxs("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[e.jsx("div",{onClick:()=>Pt(E.id),className:`w-5 h-5 rounded-full border-2 flex items-center justify-center transition-all cursor-pointer ${E.isDefault?"border-blue-600 bg-blue-600":"border-slate-300 hover:border-blue-400"}`,children:E.isDefault&&e.jsx("div",{className:"w-2 h-2 bg-white rounded-full"})}),e.jsx("span",{className:`hidden sm:inline text-xs font-semibold ${E.isDefault?"text-blue-600":"text-slate-400"}`,children:l("profile_default")})]}),i.length>1&&e.jsx("button",{type:"button",onClick:()=>U(E.id),className:"w-8 h-8 flex items-center justify-center rounded-lg text-slate-300 hover:text-red-500 hover:bg-red-50 transition-colors",title:l("profile_delete_recipient_title"),children:e.jsx(is,{size:15})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-5",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-bold text-slate-500 uppercase mb-2",children:[l("profile_surname")," ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",required:E.isDefault,value:E.surname,onChange:_=>zt(E.id,"surname",_.target.value),className:"w-full px-4 py-3 bg-white border border-slate-200 rounded-xl focus:border-blue-500 focus:ring-4 focus:ring-blue-50 transition-all outline-none text-sm font-medium",placeholder:"Ðванов"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-bold text-slate-500 uppercase mb-2",children:[l("profile_first_name")," ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",required:E.isDefault,value:E.name,onChange:_=>zt(E.id,"name",_.target.value),className:"w-full px-4 py-3 bg-white border border-slate-200 rounded-xl focus:border-blue-500 focus:ring-4 focus:ring-blue-50 transition-all outline-none text-sm font-medium",placeholder:"Ðван"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-slate-500 uppercase mb-2",children:l("profile_patronymic")}),e.jsx("input",{type:"text",value:E.patronymic,onChange:_=>zt(E.id,"patronymic",_.target.value),className:"w-full px-4 py-3 bg-white border border-slate-200 rounded-xl focus:border-blue-500 focus:ring-4 focus:ring-blue-50 transition-all outline-none text-sm font-medium",placeholder:"ÐвановиÑ"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-5",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-bold text-slate-500 uppercase mb-2",children:[l("profile_phone")," ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx("select",{value:E.phoneCountryKey,onChange:_=>oe(E.id,_.target.value),className:"px-3 py-3 bg-white border border-slate-200 rounded-xl focus:border-blue-500 outline-none text-sm font-bold text-slate-700 appearance-none pr-8 w-20 sm:w-[140px]",children:Ks.map(_=>e.jsxs("option",{value:_.key,children:[_.code," ",l(_.labelKey)]},_.key))}),e.jsx(er,{className:"absolute right-2 top-1/2 -translate-y-1/2 text-slate-400 pointer-events-none",size:14})]}),e.jsx("input",{type:"tel",required:E.isDefault,value:E.phone,onChange:_=>J(E.id,_.target.value,E.phoneCountryKey),className:"flex-1 px-4 py-3 bg-white border border-slate-200 rounded-xl focus:border-blue-500 focus:ring-4 focus:ring-blue-50 transition-all outline-none text-sm font-medium tracking-wide",placeholder:"9991234567"})]}),E.phone.length>0&&E.phone.length<ee.length?e.jsx("div",{className:"text-[10px] text-red-500 font-medium mt
69-1 ml-1",children:l("profile_digits_remaining",{remaining:ee.length-E.phone.length,entered:E.phone.length,total:ee.length})}):e.jsx("div",{className:"text-[10px] text-slate-400 mt-1 ml-1",children:l("profile_digits_count",{entered:E.phone.length,total:ee.length})})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsxs("label",{className:"block text-xs font-bold text-slate-500 uppercase",children:[l("profile_city")," ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("button",{type:"button",onClick:()=>Le(l("profile_city_tooltip")),className:"w-5 h-5 rounded-full bg-orange-500 hover:bg-orange-600 text-white flex items-center justify-center text-[11px] font-bold leading-none transition-colors shadow-sm",children:"!"})]}),e.jsx("input",{list:`cities-${E.id}`,required:E.isDefault,value:E.city,onChange:_=>zt(E.id,"city",_.target.value),className:"w-full px-4 py-3 bg-white border border-slate-200 rounded-xl focus:border-blue-500 focus:ring-4 focus:ring-blue-50 transition-all outline-none text-sm font-medium",placeholder:l("profile_start_typing")}),e.jsx("datalist",{id:`cities-${E.id}`,children:hm.map(_=>e.jsx("option",{value:_},_))})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-5",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("label",{className:"block text-xs font-bold text-slate-500 uppercase",children:l("profile_passport")}),e.jsx("button",{type:"button",onClick:()=>Le(l("profile_passport_tooltip")),className:"w-5 h-5 rounded-full bg-orange-500 hover:bg-orange-600 text-white flex items-center justify-center text-[11px] font-bold leading-none transition-colors shadow-sm",children:"!"})]}),e.jsxs("div",{className:"flex gap-2 sm:gap-4",children:[e.jsx("input",{type:R.has(E.id)?"text":"password",maxLength:4,value:E.passportSeries,onChange:_=>We(E.id,"passportSeries",_.target.value,4),className:"w-20 sm:w-24 px-3 sm:px-4 py-3 bg-white border border-slate-200 rounded-xl focus:border-blue-500 focus:ring-4 focus:ring-blue-50 transition-all outline-none text-sm font-medium text-center",placeholder:"0000"}),e.jsx("input",{type:R.has(E.id)?"text":"password",maxLength:6,value:E.passportNumber,onChange:_=>We(E.id,"passportNumber",_.target.value,6),className:"flex-1 px-3 sm:px-4 py-3 bg-white border border-slate-200 rounded-xl focus:border-blue-500 focus:ring-4 focus:ring-blue-50 transition-all outline-none text-sm font-medium",placeholder:"123456"}),e.jsx("button",{type:"button",onClick:()=>C(E.id),title:R.has(E.id)?l("profile_passport_hide"):l("profile_passport_show"),className:"shrink-0 w-11 flex items-center justify-center border border-slate-200 rounded-xl text-slate-400 hover:text-slate-600 hover:bg-slate-50 transition-colors",children:R.has(E.id)?e.jsx(Fa,{size:16}):e.jsx(Xn,{size:16})})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-slate-500 uppercase mb-2",children:l("profile_transport_company")}),e.jsxs("div",{className:"relative",children:[e.jsx(er,{className:"absolute right-4 top-1/2 -translate-y-1/2 text-slate-400 pointer-events-none",size:16}),e.jsx("select",{value:E.transportCompany,onChange:_=>{const P=_.target.value;St(E.id,"transportCompany",P),P==="CDEK"&&E.market==="SOUTH_GATE"&&St(E.id,"market","LYUBLINO")},className:"w-full px-4 py-3 bg-white border border-slate-200 rounded-xl focus:border-blue-500 focus:ring-4 focus:ring-blue-50 transition-all outline-none text-sm font-medium appearance-none text-slate-700",children:fm.map(_=>e.jsx("option",{value:_.value,children:_.labelKey?l(_.labelKey):_.label},_.value))})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-slate-500 uppercase mb-2",children:l("profile_dispatch_warehouse")}),e.jsxs("div",{className:"relative",children:[e.jsx(er,{className:"absolute right-4 top-1/2 -translate-y-1/2 text-slate-400 pointer-events-none",size:16}),e.jsxs("select",{value:E.market||"",onChange:_=>{const P=_.target.value;P==="SOUTH_GATE"&&E.transportCompany==="CDEK"||St(E.id,"market",P)},className:"w-full px-4 py-3 bg-white border border-slate-200 rounded-xl focus:border-blue-500 focus:ring-4 focus:ring-blue-50 transition-all outline-none text-sm font-medium appearance-none text-slate-700",children:[e.jsx("option",{value:"",children:l("profile_market_manager_choice")}),e.jsx("option",{value:"SOUTH_GATE",disabled:E.transportCompany==="CDEK",children:l("delivery_market_south_gate")}),e.jsx("option",{value:"LYUBLINO",children:l("delivery_market_lyublino")})]})]}),E.transportCompany==="CDEK"&&e.jsx("p",{className:"mt-1.5 text-xs text-orange-600 font-medium",children:l("profile_cdek_market_note")})]})]}),u&&e.jsxs("div",{children:[e.jsxs("label",{className:"flex items-center gap-2 text-xs font-bold text-slate-500 uppercase mb-2",children:[e.jsx(Ca,{size:14,className:"text-slate-400"}),"Email"]}),e.jsx("input",{type:"email",value:W,onChange:_=>{re(_.target.value),O(null)},className:`w-full px-4 py-3 bg-white border rounded-xl focus:ring-4 transition-all outline-none text-sm font-medium ${Z?"border-red-400 focus:border-red-500 focus:ring-red-50":"border-slate-200 focus:border-blue-500 focus:ring-blue-50"}`,placeholder:"[email protected]"}),Z&&e.jsx("p",{className:"text-xs font-semibold text-red-500 mt-1.5",children:Z})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-slate-500 uppercase mb-2",children:l("profile_birth_date")}),e.jsx("input",{type:"date",max:Ae,value:E.birthDate,onChange:_=>Y(E.id,_.target.value),className:"w-full px-4 py-3 border border-slate-200 rounded-xl text-sm font-medium text-slate-700 transition-all outline-none bg-white focus:border-blue-500 focus:ring-4 focus:ring-blue-50"}),u&&pm]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-slate-500 uppercase mb-3",children:l("profile_gender")}),e.jsx("div",{className:"flex gap-4 sm:gap-6",children:[["MALE",l("profile_gender_male")],["FEMALE",l("profile_gender_female")]].map(([_,P])=>e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer group",children:[e.jsx("div",{onClick:()=>St(E.id,"gender",E.gender===_?"":_),className:`w-5 h-5 rounded-full border flex items-center justify-center transition-colors cursor-pointer ${E.gender===_?"border-blue-600":"border-slate-300 group-hover:border-blue-400"}`,children:E.gender===_&&e.jsx("div",{className:"w-2.5 h-2.5 bg-blue-600 rounded-full"})}),e.jsx("span",{className:`text-sm font-medium ${E.gender===_?"text-blue-700":"text-slate-600"}`,children:P})]},_))})]})]})]},E.id)}),e.jsxs("button",{type:"button",onClick:Ut,className:"w-full py-3.5 rounded-2xl bg-blue-600 hover:bg-blue-700 active:bg-blue-800 text-white font-bold text-sm flex items-center justify-center gap-2 transition-colors shadow-lg shadow-blue-200",children:[e.jsx("span",{className:"w-6 h-6 rounded-full bg-white/20 flex items-center justify-center shrink-0",children:e.jsx($s,{size:16})}),l("profile_add_recipient")]}),e.jsx("div",{className:"bg-white rounded-2xl shadow-sm border border-slate-200 p-6",children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-9 h-9 rounded-xl flex items-center justify-center shrink-0 ${n?"bg-blue-50":"bg-slate-100"}`,children:e.jsx(vr,{size:17,className:n?"text-blue-600":"text-slate-400"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-bold text-slate-800",children:l(n?"profile_update_available":"profile_site_version")}),e.jsx("p",{className:"text-xs text-slate-400",children:n?r||l("profile_update_hint"):l("profile_latest_version")})]})]}),n&&e.jsx("button",{type:"button",onClick:()=>window.location.reload(),className:"px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white text-sm font-bold rounded-lg transition-colors shrink-0",children:l("profile_update_button")})]})}),e.jsxs("div",{className:"bg-white rounded-2xl shadow-sm border border-slate-200 p-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-5 pb-4 border-b border-slate-100",children:[e.jsx("div",{className:"w-9 h-9 rounded-xl bg-blue-50 flex items-center justify-center shrink-0",children:e.jsx(_s,{size:17,className:"text-blue-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-bold text-slate-800",children:l("messages_tab_notifications")}),e.jsx("p",{className:"text-xs text-slate-400",children:l("profile_notifications_hint")})]})]}),e.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-slate-50",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-slate-100 flex items-center justify-center text-slate-500 text-sm font-bold",children:"W"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-slate-700",children:l("profile_on_site")}),e.jsx("p",{className:"text-xs text-slate-400",children:l("profile_always_on")})]})]}),e.jsx("div",{className:"w-10 h-5 rounded-full bg-emerald-500 relative shrink-0",children:e.jsx("span",{className:"absolute top-0.5 right-0.5 w-4 h-4 bg-white rounded-full shadow"})})]}),e.jsxs("div",{className:"py-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-blue-100 flex items-center justify-center",children:e.jsx(Ss,{size:14,className:"text-blue-500"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-slate-700",children:"Telegram"}),I?e.jsx("p",{className:"text-xs text-emerald-600 font-medium",children:l("profile_connected")}):e.jsx("p",{className:"text-xs text-slate-400",children:l("profile_click_to_connect")})]})]}),I?e.jsx("button",{type:"button",onClick:ke,className:"text-xs text-red-400 hover:text-red-600 font-medium transition-colors",children:l("profile_disconnect")}):e.jsxs("button",{type:"button",onClick:T,disabled:Ne,className:"flex items-center gap-1.5 px-3 py-1.5 bg-blue-500 hover:bg-blue-600 text-white text-xs font-semibold rounded-lg transition-colors disabled:opacity-60",children:[Ne?e.jsx(rt,{size:12,className:"animate-spin"}):e.jsx(Ss,{size:12}),l(Ne?"profile_waiting":"profile_connect")]})]}),I&&e.jsxs("div",{className:"mt-2 ml-11 flex items-center justify-between",children:[e.jsx("p",{className:"text-xs text-slate-500",children:l("profile_duplicate_telegram")}),e.jsx("button",{type:"button",onClick:async()=>{const E=!$e;H(E);const se=yt();se&&await Je("users",{id:se},{notification_prefs:{telegram:E,email:le,browser:k,push:de}})},className:`relative shrink-0 w-10 h-5 rounded-full transition-colors duration-200 ${$e?"bg-emerald-500":"bg-slate-200"}`,children:e.jsx("span",{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full shadow transition-transform duration-200 ${$e?"translate-x-5":"translate-x-0"}`})})]})]}),e.jsx("div",{className:"py-3 border-t border-slate-50",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-amber-50 flex items-center justify-center",children:e.jsx(Ca,{size:14,className:"text-amber-500"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-slate-700",children:"Email"}),e.jsx("p",{className:"text-xs text-slate-400",children:l("profile_duplicate_email")})]})]}),e.jsx("button",{type:"button",onClick:async()=>{const E=!le;Qe(E);const se=yt();se&&await Je("users",{id:se},{notification_prefs:{telegram:$e,email:E,browser:k,push:de}})},className:`relative shrink-0 w-10 h-5 rounded-full transition-colors duration-200 ${le?"bg-emerald-500":"bg-slate-200"}`,children:e.jsx("span",{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full shadow transition-transform duration-200 ${le?"translate-x-5":"translate-x-0"}`})})]})}),e.jsxs("div",{className:"py-3 border-t border-slate-50",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-violet-50 flex items-center justify-center",children:e.jsx(_s,{size:14,className:"text-violet-500"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-slate-700",children:l("profile_browser_notifications")}),e.jsx("p",{className:"text-xs text-slate-400",children:l("profile_browser_notifications_hint")})]})]}),e.jsx("button",{type:"button",onClick:async()=>
69{if(!k){if(typeof Notification>"u"){alert(l("profile_browser_notifications_unsupported"));return}if(await Notification.requestPermission()!=="granted"){alert(l("profile_allow_notifications"));return}}const E=!k;xe(E);const se=yt();se&&await Je("users",{id:se},{notification_prefs:{telegram:$e,email:le,browser:E,push:de}})},className:`relative shrink-0 w-10 h-5 rounded-full transition-colors duration-200 ${k?"bg-emerald-500":"bg-slate-200"}`,children:e.jsx("span",{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full shadow transition-transform duration-200 ${k?"translate-x-5":"translate-x-0"}`})})]}),typeof Notification<"u"&&Notification.permission==="denied"&&e.jsx("p",{className:"mt-1 ml-11 text-xs text-red-400",children:l("profile_notifications_blocked")})]}),nc()&&e.jsxs("div",{className:"py-3 border-t border-slate-50",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-indigo-50 flex items-center justify-center",children:e.jsx(_s,{size:14,className:"text-indigo-500"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-slate-700",children:l("profile_push_notifications")}),e.jsx("p",{className:"text-xs text-slate-400",children:l(ye?"profile_connecting":"profile_push_hint")})]})]}),ye?e.jsx(rt,{size:18,className:"shrink-0 animate-spin text-indigo-400"}):e.jsx("button",{type:"button",onClick:async()=>{Ie(!0);try{if(de)await lc();else{if(typeof Notification<"u"&&Notification.permission!=="granted"&&await Notification.requestPermission()!=="granted"){alert(l("profile_allow_notifications"));return}const{error:ee}=await ac();if(ee){alert(l("profile_push_connect_failed")+ee);return}}const E=!de;V(E);const se=yt();se&&await Je("users",{id:se},{notification_prefs:{telegram:$e,email:le,browser:k,push:E}})}finally{Ie(!1)}},className:`relative shrink-0 w-10 h-5 rounded-full transition-colors duration-200 ${de?"bg-emerald-500":"bg-slate-200"}`,children:e.jsx("span",{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full shadow transition-transform duration-200 ${de?"translate-x-5":"translate-x-0"}`})})]}),/iPhone|iPad|iPod/.test(navigator.userAgent)&&!window.navigator.standalone&&e.jsx("p",{className:"mt-1 ml-11 text-xs text-amber-500",children:l("profile_iphone_hint")})]})]}),e.jsxs("div",{className:"ym-hide-content bg-white rounded-2xl shadow-sm border border-slate-200 p-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-5 pb-4 border-b border-slate-100",children:[e.jsx("div",{className:"w-9 h-9 rounded-xl bg-amber-50 flex items-center justify-center shrink-0",children:e.jsx(ln,{size:17,className:"text-amber-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-bold text-slate-800",children:l("profile_login_email_title")}),e.jsx("p",{className:"text-xs text-slate-400",children:l("profile_login_email_hint")})]})]}),e.jsxs("p",{className:"text-xs text-slate-500 mb-3",children:[l("profile_login_email_current_prefix")," ",e.jsx("span",{className:"font-semibold text-slate-700",children:te||"â"})]}),$==="sent"?e.jsxs("div",{className:"p-3 bg-emerald-50 border border-emerald-100 rounded-lg flex items-start gap-2 text-sm text-emerald-700",children:[e.jsx(as,{size:16,className:"shrink-0 mt-0.5"}),e.jsx("span",{children:l("profile_login_email_sent")})]}):e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsx("input",{type:"email",value:F,onChange:E=>{D(E.target.value),$==="error"&&z("idle")},placeholder:l("profile_login_email_placeholder"),className:"flex-1 px-4 py-3 bg-white border border-slate-200 rounded-xl focus:border-blue-500 focus:ring-4 focus:ring-blue-50 transition-all outline-none text-sm font-medium"}),e.jsx("button",{type:"button",onClick:ve,disabled:$==="saving"||!F.trim(),className:"px-5 py-3 bg-slate-900 hover:bg-slate-800 disabled:opacity-50 disabled:cursor-not-allowed text-white text-sm font-bold rounded-xl transition-colors flex items-center justify-center gap-2 shrink-0",children:$==="saving"?e.jsx(rt,{size:16,className:"animate-spin"}):l("profile_login_email_submit")})]}),$==="error"&&me&&e.jsx("p",{className:"text-xs font-semibold text-red-500 mt-2",children:me})]}),!b&&e.jsxs("label",{className:"flex items-start gap-3 cursor-pointer select-none p-3 bg-slate-50 border border-slate-200 rounded-xl",children:[e.jsx("input",{type:"checkbox",checked:y,onChange:E=>j(E.target.checked),className:"mt-0.5 w-4 h-4 accent-blue-600 shrink-0 cursor-pointer"}),e.jsxs("span",{className:"text-xs text-slate-700 leading-relaxed",children:[l("profile_pd_consent_text")," ",e.jsx("a",{href:wr("/privacy"),target:"_blank",rel:"noreferrer",className:"font-semibold underline hover:text-blue-600 transition-colors",children:l("auth_link_privacy")}),"."]})]}),e.jsx("div",{className:"flex justify-end pt-2",children:e.jsxs("button",{type:"submit",disabled:c||!b&&!y,className:"px-8 py-3 bg-yellow-400 hover:bg-yellow-500 disabled:bg-slate-200 disabled:cursor-not-allowed text-slate-900 font-bold rounded-xl shadow-lg shadow-yellow-100 transition-all active:scale-95 flex items-center gap-2",children:[c&&e.jsx(rt,{className:"animate-spin w-4 h-4"}),l("profile_save_button")]})}),e.jsx("div",{className:"pt-4 border-t border-slate-100 flex justify-start",children:it?e.jsx("p",{className:"text-xs text-slate-400",children:l("profile_delete_request_pending")}):e.jsx("button",{type:"button",onClick:()=>jt(!0),className:"text-xs text-slate-400 hover:text-red-500 transition-colors underline underline-offset-2",children:l("profile_delete_account")}
69)})]}),L&&(()=>{const E=i.find(ee=>ee.id===L),se=E?`${E.surname} ${E.name}`.trim()||E.label||l("profile_this_recipient"):l("profile_recipient_default");return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm p-4",children:e.jsxs("div",{className:"bg-white rounded-2xl shadow-2xl w-full max-w-sm p-6 animate-in fade-in zoom-in-95",children:[e.jsx("div",{className:"w-12 h-12 bg-red-100 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(is,{size:22,className:"text-red-500"})}),e.jsx("h3",{className:"text-base font-black text-slate-900 text-center mb-1",children:l("profile_delete_recipient_question")}),e.jsxs("p",{className:"text-sm text-slate-500 text-center mb-6",children:[l("profile_delete_recipient_body_prefix")," ",e.jsxs("span",{className:"font-semibold text-slate-700",children:["«",se,"»"]})," ",l("profile_delete_recipient_body_suffix")]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{onClick:()=>U(null),className:"flex-1 px-4 py-2.5 rounded-xl border border-slate-200 text-sm font-bold text-slate-600 hover:bg-slate-50 transition-colors",children:l("orders_cancel_button")}),e.jsx("button",{onClick:xt,className:"flex-1 px-4 py-2.5 rounded-xl bg-red-500 hover:bg-red-600 text-white text-sm font-bold transition-colors",children:l("import_delete_button")})]})]})})})(),_t&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm p-4",children:e.jsx("div",{className:"bg-white rounded-2xl shadow-2xl w-full max-w-sm p-6",children:ht?e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-12 h-12 bg-green-100 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(as,{size:22,className:"text-green-500"})}),e.jsx("h3",{className:"text-base font-black text-slate-900 mb-2",children:l("profile_delete_request_sent")}),e.jsx("p",{className:"text-sm text-slate-500 mb-6",children:l("profile_delete_request_sent_body")}),e.jsx("button",{onClick:()=>{jt(!1),qe(!1)},className:"w-full px-4 py-2.5 rounded-xl bg-slate-900 text-white text-sm font-bold hover:bg-slate-700 transition-colors",children:l("profile_close_button")})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-12 h-12 bg-red-100 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(is,{size:22,className:"text-red-500"})}),e.jsx("h3",{className:"text-base font-black text-slate-900 text-center mb-2",children:l("profile_delete_account_question")}),e.jsx("p",{className:"text-sm text-slate-500 text-center mb-2",children:l("profile_delete_account_body")}),e.jsx("p",{className:"text-xs text-slate-400 text-center mb-6",children:l("profile_delete_account_history_note")}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{onClick:()=>jt(!1),className:"flex-1 px-4 py-2.5 rounded-xl border border-slate-200 text-sm font-bold text-slate-600 hover:bg-slate-50 transition-colors",children:l("orders_cancel_button")}),e.jsxs("button",{onClick:be,disabled:dt,className:"flex-1 px-4 py-2.5 rounded-xl bg-red-500 hover:bg-red-600 text-white text-sm font-bold transition-colors disabled:opacity-50 flex items-center justify-center gap-2",children:[dt&&e.jsx(rt,{size:14,className:"animate-spin"}),l("profile_send_request")]})]})]})})})]}),we&&e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",onClick:()=>Le(null),children:[e.jsx("div",{className:"absolute inset-0 bg-black/40"}),e.jsxs("div",{className:"relative bg-white rounded-2xl shadow-2xl max-w-sm w-full p-5",onClick:E=>E.stopPropagation(),children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Fs,{size:20,className:"text-orange-500 shrink-0 mt-0.5"}),e.jsx("p",{className:"text-sm text-slate-700 leading-relaxed",children:we})]}),e.jsx("button",{onClick:()=>Le(null),className:"mt-4 w-full py-2.5 bg-slate-100 hover:bg-slate-200 text-slate-700 rounded-xl text-sm font-semibold transition-colors",children:l("topup_understood")})]})]})]})};function gm({onOrderClick:t}){const{t:s}=qt(),[n,r]=a.useState([]),[l,c]=a.useState(!0);a.useEffect(()=>{const i=yt();if(!i)return;let x,m=null;return(async()=>{await o(i),x=At.channel("user-transactions-update").on("postgres_changes",{event:"INSERT",schema:"public",table:"transactions",filter:`user_id=eq.${i}`},()=>o(i)).on("postgres_changes",{event:"UPDATE",schema:"public",table:"transactions",filter:`user_id=eq.${i}`},()=>o(i)).subscribe(),m=In({intervalMs:3e5,run:()=>o(i),immediate:!1})})(),()=>{x&&At.removeChannel(x),m&&m()}},[]);const o=async i=>{try{const{data:x,error:m}=await Re("transactions",{user_id:i},{select:"*,orders(id,display_id)",order:"created_at.desc"});if(m)throw new Error(m);x&&r(x)}catch{}finally{c(!1)}},d=i=>{if(i.type==="DELIVERY_INVOICE")return null;switch(i.status){case"COMPLETED":return e.jsxs("span",{className:"flex items-center gap-1 text-xs font-bold text-green-700 bg-green-100 px-2 py-1 rounded-full",children:[e.jsx(as,{size:12})," ",s("payments_status_success")]});case"PENDING":return e.jsxs("span",{className:"flex items-center gap-1 text-xs font-bold text-amber-700 bg-amber-100 px-2 py-1 rounded-full",children:[e.jsx(rs,{size:12})," ",s("payments_status_pending")]});
69case"REJECTED":case"CANCELED":return e.jsxs("span",{className:"flex items-center gap-1 text-xs font-bold text-red-700 bg-red-100 px-2 py-1 rounded-full",children:[e.jsx(Gr,{size:12})," ",s("payments_status_rejected")]});default:return null}},p=i=>i.type==="BALANCE_ADJUSTMENT"?i.amount>=0?{icon:e.jsx("div",{className:"w-10 h-10 rounded-full bg-green-50 text-green-600 flex items-center justify-center",children:e.jsx(vn,{size:20})}),amountStr:`+${i.amount.toLocaleString()} â½`,color:"text-green-600"}:{icon:e.jsx("div",{className:"w-10 h-10 rounded-full bg-red-50 text-red-600 flex items-center justify-center",children:e.jsx(vn,{size:20})}),amountStr:`â${Math.abs(i.amount).toLocaleString()} â½`,color:"text-red-600"}:i.type==="DELIVERY_INVOICE"?{icon:e.jsx("div",{className:"w-10 h-10 rounded-full bg-orange-50 text-orange-500 flex items-center justify-center",children:e.jsx(Lt,{size:20})}),amountStr:`â${Math.abs(i.amount).toLocaleString()} â½`,color:"text-red-600"}:i.type==="DELIVERY_PAYMENT"?{icon:e.jsx("div",{className:"w-10 h-10 rounded-full bg-green-50 text-green-600 flex items-center justify-center",children:e.jsx(Lt,{size:20})}),amountStr:`+${Math.abs(i.amount).toLocaleString()} â½`,color:"text-green-600"}:i.amount<0||i.type==="WITHDRAWAL"?{icon:e.jsx("div",{className:"w-10 h-10 rounded-full bg-red-50 text-red-600 flex items-center justify-center",children:e.jsx(vn,{size:20})}),amountStr:`â${Math.abs(i.amount).toLocaleString()} â½`,color:"text-red-600"}:{icon:e.jsx("div",{className:"w-10 h-10 rounded-full bg-green-50 text-green-600 flex items-center justify-center",children:e.jsx(vn,{size:20})}),amountStr:`+${i.amount.toLocaleString()} â½`,color:"text-green-600"},y=new Map;n.forEach(i=>{i.type==="BONUS_PAYMENT"&&i.order_id&&i.amount<0&&y.set(i.order_id,Math.abs(i.amount))});const j=new Set;n.forEach(i=>{i.type==="ORDER_PAYMENT"&&i.order_id&&i.amount>0&&n.some(m=>m.type==="BALANCE_ADJUSTMENT"&&m.order_id===i.order_id&&Math.round(Math.abs(m.amount))===Math.round(i.amount))&&j.add(i.order_id)});const b=new Set;n.forEach(i=>{i.type==="PAYMENT"&&i.amount<0&&i.order_id&&n.some(m=>m.type==="BALANCE_ADJUSTMENT"&&m.amount>0&&m.order_id===i.order_id&&m.description?.includes("пеÑеплаÑ"))&&b.add(i.order_id)});const h=new Set;n.forEach(i=>{i.type==="BALANCE_ADJUSTMENT"&&i.amount<0&&i.order_id&&i.description?.includes("оплаÑа в ÐоÑкве")&&n.some(m=>m.type==="DELIVERY_PAYMENT"&&m.order_id===i.order_id&&Math.round(Math.abs(m.amount))===Math.round(Math.abs(i.amount)))&&h.add(i.order_id)});const v=n.filter(i=>!(i.type==="BONUS_PAYMENT"||i.type==="ORDER_PAYMENT"&&i.order_id&&j.has(i.order_id)||i.type==="BALANCE_ADJUSTMENT"&&i.amount<0&&i.order_id&&b.has(i.order_id)&&i.description?.includes("заказ")||i.type==="DELIVERY_PAYMENT"&&i.order_id&&h.has(i.order_id)));return l?e.jsx("div",{className:"flex items-center justify-center min-h-[300px]",children:e.jsx(rt,{className:"w-8 h-8 text-blue-600 animate-spin"})}):e.jsxs("div",{className:"max-w-4xl xl:max-w-5xl mx-auto pb-10 animate-in fade-in slide-in-from-bottom-4 duration-300",children:[e.jsx("div",{className:"flex items-center justify-between mb-8",children:e.jsx("h1",{className:"text-2xl font-bold text-slate-900",children:s("payments_title")})}),n.length===0?e.jsxs("div",{className:"bg-white rounded-2xl shadow-sm border border-slate-200 p-10 text-center text-slate-400",children:[e.jsx("div",{className:"w-16 h-16 bg-slate-50 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx($n,{size:32})}),e.jsx("p",{children:s("payments_empty")})]}):e.jsx("div",{className:"space-y-3","data-tour":"payment-history-list",children:v.map(i=>{const x=p(i),m=i.order_id?y.get(i.order_id):void 0,N=m&&m>0&&i.type==="ORDER_PAYMENT";return e.jsx("div",{className:"bg-white rounded-2xl border border-slate-200 shadow-sm p-4 md:p-5 hover:bg-slate-50 transition-colors",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex items-start gap-4 flex-1 min-w-0",children:[x.icon,e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-bold text-slate-900 text-sm leading-snug",children:i.description||s("payments_operation_fallback")}),e.jsx("div",{className:"text-xs text-slate-400 mt-1",children:ic(i.created_at)}),(d(i)||N||i.orders&&t)&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mt-2",children:[d(i),i.orders&&t&&e.jsxs("button",{onClick:()=>t(i.orders.id),className:"inline-flex items-center gap-1 text-xs font-bold text-blue-600 bg-blue-50 px-2 py-1 rounded-lg hover:bg-blue-100 transition-colors",children:[e.jsx(js,{size:12}),s("payments_order_prefix")," ",i.orders.display_id]}),N&&e.jsxs("div",{className:"flex items-center gap-1 text-xs text-amber-700 bg-amber-50 border border-amber-200 px-2 py-0.5 rounded-full",children:[e.jsx($a,{size:11}
69),"+",m.toLocaleString()," â½ ",s("payments_with_bonuses")]})]})]})]}),e.jsxs("div",{className:"text-right shrink-0",children:[e.jsx("div",{className:`font-bold text-lg ${x.color}`,children:x.amountStr}),i.currency==="USDT"&&i.amount_usdt&&e.jsxs("div",{className:"flex items-center justify-end gap-1 text-xs font-bold text-emerald-700 bg-emerald-50 border border-emerald-200 px-2 py-0.5 rounded-full mt-1 ml-auto",children:[e.jsx(Ds,{size:10})," ",i.amount_usdt," USDT"]}),N&&e.jsx("div",{className:"text-xs text-slate-400 mt-0.5",children:s("payments_in_cash")})]})]})},i.id)})})]})}const _m=["ð","ð","ð","ð","ð
","ð","ð","ð","ð","ð","ð¤","ð","ð","ð","ð¢","ð","ð¡","ð³","ð´","ð¤","ð","ð","ð","ð","ð","ðª","ð¥","â
","â","â ï¸","â¤ï¸","ð","ð¦","ð","ð°","â°"];function ym({onSelect:t}){const[s,n]=a.useState(!1),r=a.useRef(null);return a.useEffect(()=>{if(!s)return;const l=c=>{r.current&&!r.current.contains(c.target)&&n(!1)};return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[s]),e.jsxs("div",{className:"relative shrink-0",ref:r,children:[e.jsx("button",{type:"button",onClick:()=>n(l=>!l),className:"px-2 py-2.5 text-slate-400 hover:text-slate-600 transition-colors",children:e.jsx(Yo,{size:16})}),s&&e.jsx("div",{className:"absolute bottom-full left-0 mb-2 w-64 bg-white border border-slate-200 rounded-xl shadow-lg z-50 p-2 grid grid-cols-7 gap-1",children:_m.map(l=>e.jsx("button",{type:"button",onClick:()=>{t(l),n(!1)},className:"text-xl hover:bg-slate-100 rounded-lg p-1 transition-colors",children:l},l))})]})}const jm="https://vk.me/goodschina1",vm="https://t.me/GOODSCHINAMR",dn="ð¡ ÐÑедложение по ÑайÑÑ",Nm=[dn,"Ðе Ð¼Ð¾Ð³Ñ Ð²Ð¾Ð¹Ñи на ÑайÑ","ÐÑоблема Ñ Ð·Ð°ÐºÐ°Ð·Ð¾Ð¼","ÐÑоблема Ñ Ð¾Ð¿Ð»Ð°Ñой","Ðе пÑиÑ
одÑÑ ÑведомлениÑ","Ðе Ð¼Ð¾Ð³Ñ Ð½Ð°Ð¿Ð¸ÑаÑÑ ÑообÑение","Ðе Ð¼Ð¾Ð³Ñ Ð·Ð°Ð³ÑÑзиÑÑ Ñайл","ÐопÑÐ¾Ñ Ð¿Ð¾ доÑÑавке","ÐÑибка на ÑÑÑаниÑе","ÐÑÑгое"],di={"Ðе Ð¼Ð¾Ð³Ñ Ð²Ð¾Ð¹Ñи на ÑайÑ":"support_quick_answer_login","ÐÑоблема Ñ Ð¾Ð¿Ð»Ð°Ñой":"support_quick_answer_payment","ÐопÑÐ¾Ñ Ð¿Ð¾ доÑÑавке":"support_quick_answer_delivery"},wm={[dn]:"support_topic_idea","Ðе Ð¼Ð¾Ð³Ñ Ð²Ð¾Ð¹Ñи на ÑайÑ":"support_topic_login","ÐÑоблема Ñ Ð·Ð°ÐºÐ°Ð·Ð¾Ð¼":"support_topic_order","ÐÑоблема Ñ Ð¾Ð¿Ð»Ð°Ñой":"support_topic_payment","Ðе пÑиÑ
одÑÑ ÑведомлениÑ":"support_topic_notifications","Ðе Ð¼Ð¾Ð³Ñ Ð½Ð°Ð¿Ð¸ÑаÑÑ ÑообÑение":"support_topic_message","Ðе Ð¼Ð¾Ð³Ñ Ð·Ð°Ð³ÑÑзиÑÑ Ñайл":"support_topic_upload","ÐопÑÐ¾Ñ Ð¿Ð¾ доÑÑавке":"support_topic_delivery","ÐÑибка на ÑÑÑаниÑе":"support_topic_error",ÐÑÑгое:"support_topic_other"},ja={OPEN:{labelKey:"support_status_open",color:"bg-amber-100 text-amber-700 border-amber-200",icon:rs},IN_PROGRESS:{labelKey:"support_status_in_progress",color:"bg-blue-100 text-blue-700 border-blue-200",icon:Fs},CLOSED:{labelKey:"support_status_closed",color:"bg-green-100 text-green-700 border-green-200",icon:as}};function Sm({resetKey:t}){const{t:s}=qt(),[n,r]=a.useState([]),[l,c]=a.useState("ALL"),[o,d]=a.useState(null),[p,y]=a.useState(!0),[j,b]=a.useState(""),[h,v]=a.useState(null),[i,x]=a.useState(!1),[m,N]=a.useState(!1),[R,S]=a.useState(""),[C,L]=a.useState(null),[U,W]=a.useState(""),[re,Z]=a.useState([]),[O,F]=a.useState([]),[D,$]=a.useState(!1),[z,me]=a.useState(!1),[K,te]=a.useState(null),[I,B]=a.useState(!1),[Ne,Ue]=a.useState(!1),[$e,H]=a.useState(!1),[le,Qe]=a.useState(""),[k,xe]=a.useState(""),[de,V]=a.useState(!1),[ye,Ie]=a.useState(!1),[Oe,we]=a.useState(null),Le=a.useRef(null),_t=a.useRef(null),jt=a.useRef(null),dt=a.useRef(null),gt=a.useRef(null);a.useEffect(()=>{qe()},[]),a.useEffect(()=>{const J=dt.current;J&&(J.style.height="auto",J.style.height=`${Math.min(J.scrollHeight,320)}px`)},[j]),a.useEffect(()=>{t!==void 0&&t>0&&d(null)},[t]),a.useEffect(()=>{gt.current=o},[o]),a.useEffect(()=>{const J=yt();if(!J)return;const We=At.channel("support-client-rt").on("postgres_changes",{event:"UPDATE",schema:"public",table:"support_tickets",filter:`user_id=eq.${J}`},oe=>{const Y=oe.new;r(Se=>Se.map(ve=>ve.id===Y.id?{...ve,...Y}:ve)),gt.current?.id===Y.id&&(d(Se=>Se?{...Se,messages:Y.messages,status:Y.status,client_unread:Y.client_unread}:null),setTimeout(()=>Le.current?.scrollIntoView({behavior:"smooth"}),50)),Y.client_unread&&Pr("default")}).subscribe();return()=>{At.removeChannel(We)}},[]),a.useEffect(()=>{o&&setTimeout(()=>Le.current?.scrollIntoView({behavior:"smooth"}),50)},[o?.messages.length]);const ht=async()=>
69{if(!(!le.trim()||!k.trim())){V(!0),we(null);try{const{error:J}=await go("send-support-email",{fromEmail:le.trim(),message:k.trim()});if(J)throw new Error(J);Ie(!0),Qe(""),xe("")}catch{we(s("support_email_send_failed"))}finally{V(!1)}}},qe=async()=>{y(!0);const J=yt();if(!J){y(!1);return}const{data:We}=await Re("support_tickets",{user_id:J},{select:"*",order:"updated_at.desc"});r(We||[]),y(!1)},it=async J=>{d(J),J.client_unread&&(await Je("support_tickets",{id:J.id},{client_unread:!1}),r(We=>We.map(oe=>oe.id===J.id?{...oe,client_unread:!1}:oe)))},Ge=async()=>{const J=C==="ÐÑÑгое"?U.trim():C;if(!J){me(!0);return}if(!R.trim())return;$(!0),te(null);const We=yt();if(!We){$(!1);return}const Y=[{id:crypto.randomUUID(),sender:"USER",text:R.trim(),created_at:new Date().toISOString()}];for(const{file:T}of re){const ke=await Er(T),be=ke.name.split(".").pop(),Ae=`support/${Date.now()}_${Math.random().toString(36).slice(2)}.${be}`,E=await tr("chat-files",Ae,ke);E?.publicUrl&&Y.push({id:crypto.randomUUID(),sender:"USER",text:"",created_at:new Date().toISOString(),fileUrl:E.publicUrl,fileName:T.name,fileType:T.type.startsWith("image/")?"image":"pdf"})}const Se=crypto.randomUUID(),{error:ve}=await st("support_tickets",{id:Se,user_id:We,subject:J,status:"OPEN",messages:Y,client_unread:!1,admin_unread:!0});if(ve)te(`${s("common_error_prefix")}${ve}`);else{const{error:T}=await st("notifications",{user_id:null,type:"SUPPORT_TICKET",title:"Ðовое обÑаÑение в поддеÑжкÑ",text:`${J}: ${R.trim()}`,date:new Date().toISOString(),is_read:!1,link:Se});await qe(),N(!1),S(""),L(null),W(""),re.forEach(ke=>ke.previewUrl&&URL.revokeObjectURL(ke.previewUrl)),Z([])}$(!1)},St=J=>{const We=Array.from(J.target.files||[]);if(!We.length)return;const oe=5-O.length;if(oe<=0){alert(s("support_max_3_files")),J.target.value="";return}We.some(ve=>ve.size>10*1024*1024)&&alert(s("support_file_too_large"));const Se=We.filter(ve=>ve.size<=10*1024*1024).slice(0,oe);F(ve=>[...ve,...Se.map(T=>({file:T,previewUrl:T.type.startsWith("image/")?URL.createObjectURL(T):null}))]),J.target.value=""},Pt=J=>{F(We=>{const oe=We[J];return oe?.previewUrl&&URL.revokeObjectURL(oe.previewUrl),We.filter((Y,Se)=>Se!==J)})},Ut=async()=>{if(!j.trim()&&O.length===0||!o)return;x(!0);const J=[];j.trim()&&J.push({id:crypto.randomUUID(),sender:"USER",text:j.trim(),created_at:new Date().toISOString()}),B(!0);for(const{file:Se}of O){const ve=await Er(Se),T=ve.name.split(".").pop(),ke=`support/${Date.now()}_${Math.random().toString(36).slice(2)}.${T}`;try{const{publicUrl:be}=await tr("chat-files",ke,ve);J.push({id:crypto.randomUUID(),sender:"USER",text:"",created_at:new Date().toISOString(),fileUrl:be,fileName:Se.name,fileType:Se.type.startsWith("image/")?"image":"pdf"})}catch(be){alert(be.message||s("support_upload_error"))}}if(B(!1),J.length===0){x(!1);return}
69h&&(J[0].reply_to=h);const{data:We}=await Re("support_tickets",{id:o.id},{select:"messages",single:!0}),oe=_o(We?.messages,[...o.messages,...J]),{error:Y}=await Je("support_tickets",{id:o.id},{messages:oe,updated_at:new Date().toISOString(),client_unread:!1,admin_unread:!0});if(Y)te(`${s("support_send_error_prefix")}${Y}`);else{const Se={...o,messages:oe};d(Se),r(ve=>ve.map(T=>T.id===Se.id?Se:T)),b(""),O.forEach(ve=>ve.previewUrl&&URL.revokeObjectURL(ve.previewUrl)),F([]),v(null)}x(!1)};if(o){const J=ja[o.status],We=J.icon;return e.jsxs("div",{className:"max-w-2xl lg:max-w-3xl xl:max-w-4xl mx-auto",children:[e.jsxs("button",{onClick:()=>d(null),className:"flex items-center gap-1.5 px-3 py-2 bg-white border border-slate-200 rounded-xl text-slate-600 font-bold hover:bg-slate-50 transition-colors shadow-sm text-sm mb-4",children:[e.jsx(Mn,{size:16})," ",s("support_all_tickets")]}),e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-200 shadow-sm overflow-hidden flex flex-col",style:{height:"calc(100vh - 220px)",minHeight:"400px"},children:[e.jsxs("div",{className:"px-5 py-4 border-b border-slate-100 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-bold text-slate-900 text-sm",children:o.subject||s("support_ticket_fallback",{id:o.id.slice(-6).toUpperCase()})}),e.jsxs("div",{className:"text-xs text-slate-400 mt-0.5",children:[s("support_id_label")," ",e.jsx("span",{className:"font-mono font-bold text-slate-500 select-all",children:o.id.slice(-8).toUpperCase()})," · ",new Date(o.created_at).toLocaleDateString("ru-RU")]})]}),e.jsxs("span",{className:`flex items-center gap-1.5 px-3 py-1.5 rounded-full text-xs font-bold border ${J.color}`,children:[e.jsx(We,{size:12})," ",s(J.labelKey)]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-5 space-y-3",children:[o.messages.map(oe=>{const Y=!oe.text&&oe.fileUrl&&oe.fileType==="image",Se=oe.sender==="USER";return e.jsxs("div",{id:`support-msg-user-${oe.id}`,className:`flex items-end gap-1.5 group/msg ${Se?"justify-end":"justify-start"}`,children:[!Se&&e.jsx("button",{onClick:()=>v({id:oe.id,sender:oe.sender,text:oe.text||"",...oe.fileUrl?{fileUrl:oe.fileUrl,fileType:oe.fileType}:{}}),className:"shrink-0 mb-1 p-1 text-slate-300 hover:text-blue-500 transition-colors opacity-0 group-hover/msg:opacity-100",title:s("support_reply_title"),children:e.jsx($r,{size:13})}),e.jsxs("div",{className:`max-w-[75%] text-sm ${Y?"":`px-4 py-2.5 rounded-2xl ${Se?"bg-blue-600 text-white rounded-br-sm":"bg-slate-100 text-slate-800 rounded-bl-sm"}`}`,children:[oe.sender==="ADMIN"&&!Y&&e.jsx("div",{className:"text-[10px] font-bold text-slate-400 mb-1",children:s("support_admin_label")}),oe.reply_to&&e.jsxs("div",{className:`mb-2 px-2.5 py-1.5 rounded-lg border-l-[3px] cursor-pointer flex items-center gap-2 ${Se?"border-white/60 bg-black/10":"border-blue-400 bg-slate-200/60"}`,onClick:()=>
69{const ve=document.getElementById(`support-msg-user-${oe.reply_to.id}`);ve&&ve.scrollIntoView({behavior:"smooth",block:"center"})},children:[oe.reply_to.fileUrl&&oe.reply_to.fileType==="image"&&e.jsx("img",{src:oe.reply_to.fileUrl,className:"w-8 h-8 object-cover rounded flex-shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[10px] font-bold opacity-80",children:oe.reply_to.sender==="USER"?s("support_you_label"):s("support_admin_label")}),e.jsx("p",{className:"text-xs opacity-70 truncate",children:oe.reply_to.text||"ð"})]})]}),oe.text&&e.jsx("p",{children:oe.text}),oe.fileUrl&&oe.fileType==="image"&&e.jsxs("div",{className:`relative group inline-block ${oe.text?"mt-1":""}`,children:[e.jsx("img",{src:oe.fileUrl,alt:oe.fileName,className:"rounded-lg object-cover cursor-pointer",style:{maxWidth:"220px",maxHeight:"160px",width:"auto",height:"auto"},onDoubleClick:()=>window.open(oe.fileUrl,"_blank")}),e.jsx("a",{href:oe.fileUrl,download:oe.fileName,target:"_blank",rel:"noreferrer",className:"absolute top-1.5 right-1.5 bg-black/50 hover:bg-black/70 text-white rounded-lg p-1 opacity-0 group-hover:opacity-100 transition-opacity",title:s("messages_download_title"),children:e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:e.jsx("path",{d:"M12 15V3m0 12-4-4m4 4 4-4M2 17l.621 2.485A2 2 0 0 0 4.561 21h14.878a2 2 0 0 0 1.94-1.515L22 17"})})})]}),oe.fileUrl&&oe.fileType==="pdf"&&e.jsxs("a",{href:oe.fileUrl,target:"_blank",rel:"noreferrer",className:`flex items-center gap-2 mt-1 text-xs underline ${oe.sender==="USER"?"text-blue-100":"text-blue-600"}`,children:["ð ",oe.fileName]}),e.jsx("div",{className:`text-[10px] mt-1 ${Y?"text-slate-400":oe.sender==="USER"?"text-blue-200":"text-slate-400"}`,children:new Date(oe.created_at).toLocaleTimeString("ru-RU",{hour:"2-digit",minute:"2-digit"})})]}),Se&&e.jsx("button",{onClick:()=>v({id:oe.id,sender:oe.sender,text:oe.text||"",...oe.fileUrl?{fileUrl:oe.fileUrl,fileType:oe.fileType}:{}}),className:"shrink-0 mb-1 p-1 text-slate-300 hover:text-blue-500 transition-colors opacity-0 group-hover/msg:opacity-100",title:s("support_reply_title"),children:e.jsx($r,{size:13})})]},oe.id)}),e.jsx("div",{ref:Le})]}),o.status!=="CLOSED"?e.jsxs("div",{className:"p-4 border-t border-slate-100 space-y-2",children:[e.jsx("input",{ref:_t,type:"file",accept:"image/png,image/jpeg,image/jpg,application/pdf",multiple:!0,className:"hidden",onChange:St}),h&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-blue-50 border border-blue-200 rounded-xl border-l-4 border-l-blue-400",children:[e.jsx($r,{size:13,className:"text-blue-500 flex-shrink-0"}),h.fileUrl&&h.fileType==="image"&&e.jsx("img",{src:h.fileUrl,className:"w-8 h-8 object-cover rounded-lg flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-[10px] font-bold text-blue-600 mb-0.5",children:h.sender==="USER"?s("support_you_label"):s("support_admin_label")}),e.jsx("p",{className:"text-xs text-slate-600 truncate",children:h.text||"ð"})]}),e.jsx("button",{onClick:()=>v(null),className:"p-1 text-slate-400 hover:text-slate-600 flex-shrink-0",children:e.jsx(bt,{size:14})})]}),O.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2",children:O.map((oe,Y)=>e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 bg-white rounded-xl border border-slate-200 max-w-full",children:[oe.previewUrl?e.jsx("img",{src:oe.previewUrl,draggable:!1,className:"w-8 h-8 object-cover rounded-lg flex-shrink-0 outline-none border-0 select-none"}):e.jsx("div",{className:"w-8 h-8 bg-slate-100 rounded-lg flex items-center justify-center text-base flex-shrink-0",children:"ð"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs text-slate-700 font-medium truncate max-w-[140px]",children:oe.file.name}),e.jsxs("p",{className:"text-[10px] text-slate-400",children:[(oe.file.size/1024/1024).toFixed(1)," ",s("messages_mb_unit")]})]}),e.jsx("button",{onClick:()=>Pt(Y),className:"p-1 text-slate-400 hover:text-red-500 transition-colors flex-shrink-0",children:e.jsx(bt,{size:14})})]},Y))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>_t.current?.click(),disabled:O.length>=5,className:"px-2 py-2.5 text-slate-400 hover:text-slate-600 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:e.jsx(Bn,{size:16})}),e.jsx(ym,{onSelect:oe=>b(Y=>Y+oe)}
69),e.jsx("textarea",{ref:dt,rows:1,value:j,onChange:oe=>b(oe.target.value),onKeyDown:oe=>{oe.key==="Enter"&&!oe.shiftKey&&(oe.preventDefault(),Ut())},placeholder:s("support_chat_input_placeholder"),className:"flex-1 px-4 py-2.5 border border-slate-200 rounded-xl text-sm outline-none focus:border-blue-400 focus:ring-2 focus:ring-blue-50 resize-y overflow-y-auto",style:{minHeight:"44px",maxHeight:"320px"}}),e.jsx("button",{onClick:Ut,disabled:i||I||!j.trim()&&O.length===0,className:"px-4 py-2.5 bg-blue-600 hover:bg-blue-700 disabled:opacity-50 text-white rounded-xl transition-colors",children:i||I?e.jsx(rt,{size:16,className:"animate-spin"}):e.jsx(Ss,{size:16})})]})]}):e.jsxs("div",{className:"p-4 border-t border-slate-100 text-center text-sm text-slate-400",children:[s("support_ticket_closed_note")," ",e.jsx("button",{onClick:()=>{d(null),N(!0)},className:"text-blue-600 hover:underline",children:s("support_create_new")})]})]})]})}const xt=n.filter(J=>J.status==="OPEN").length,zt=l==="ALL"?n:n.filter(J=>J.status===l);return e.jsxs("div",{className:"max-w-2xl lg:max-w-3xl xl:max-w-4xl mx-auto space-y-4",children:[e.jsxs("div",{className:"p-4 bg-[#F0F6FF] border border-blue-200 rounded-2xl space-y-3",children:[e.jsx("div",{className:"text-sm font-bold text-slate-800",children:s("support_banner_title")}),e.jsx("div",{className:"text-xs text-slate-500",children:s("support_banner_body")}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsxs("a",{href:jm,target:"_blank",rel:"noreferrer",className:"flex items-center gap-2 px-4 py-2.5 bg-[#0077FF] hover:bg-[#0066DD] text-white rounded-xl text-sm font-bold transition-colors flex-1 justify-center",children:[e.jsx("div",{className:"font-black text-base leading-none",children:"ÐÐ"}),"ÐÐонÑакÑе"]}),e.jsxs("a",{href:vm,target:"_blank",rel:"noreferrer",className:"flex items-center gap-2 px-4 py-2.5 bg-[#29A8E9] hover:bg-[#1d96d4] text-white rounded-xl text-sm font-bold transition-colors flex-1 justify-center",children:[e.jsx(Ss,{size:15}),"Telegram"]}),e.jsxs("button",{onClick:()=>H(J=>!J),className:"flex items-center gap-2 px-4 py-2.5 bg-slate-700 hover:bg-slate-800 text-white rounded-xl text-sm font-bold transition-colors flex-1 justify-center",children:[e.jsx(Ur,{size:15}),s("support_write_email")]})]}),$e&&e.jsx("div",{className:"pt-2 space-y-2",children:ye?e.jsxs("div",{className:"flex items-center gap-2 bg-green-50 border border-green-200 text-green-700 rounded-xl px-4 py-3 text-sm font-medium",children:[e.jsx(as,{size:16}),s("support_email_sent")]}):e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"email",placeholder:s("support_email_placeholder"),value:le,onChange:J=>Qe(J.target.value),className:"w-full px-4 py-2.5 rounded-xl border border-slate-200 text-sm outline-none focus:border-blue-400 focus:ring-2 focus:ring-blue-100 bg-white"}),e.jsx("textarea",{placeholder:s("support_describe_problem_placeholder"),value:k,onChange:J=>xe(J.target.value),rows:3,className:"w-full px-4 py-2.5 rounded-xl border border-slate-200 text-sm outline-none focus:border-blue-400 focus:ring-2 focus:ring-blue-100 bg-white resize-y"}),Oe&&e.jsx("div",{className:"text-red-500 text-xs",children:Oe}),e.jsxs("button",{onClick:ht,disabled:de||!le.trim()||!k.trim(),className:"flex items-center gap-2 px-5 py-2.5 bg-blue-600 hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed text-white rounded-xl text-sm font-bold transition-colors",children:[de?e.jsx(rt,{size:15,className:"animate-spin"}):e.jsx(Ss,{size:15}),s("support_send_button")]})]})})]}),e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-200 shadow-sm",children:[e.jsxs("div",{className:"px-6 py-5 border-b border-slate-100 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-black text-slate-900",children:s("support_my_tickets")}),e.jsx("p",{className:"text-xs text-slate-500 mt-0.5",children:s("support_tickets_subtitle")})]}),e.jsxs("button",{onClick:()=>N(J=>!J),className:"flex items-center gap-2 px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-xl text-sm font-bold transition-colors",children:[e.jsx($s,{size:15})," ",s("support_new_ticket")]})]}),m&&e.jsxs("div",{className:"p-5 border-b border-slate-100 bg-slate-50 space-y-4",children:[K&&e.jsx("div",{className:"px-3 py-2 bg-red-50 border border-red-200 rounded-lg text-xs text-red-600",children:K}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-bold text-slate-700 mb-2",children:s("support_topic_label")}),e.jsxs("select",{value:C||"",onChange:J=>{L(J.target.value||null),W(""),me(!1)},className:`w-full px-4 py-2.5 border rounded-xl text-sm outline-none bg-white appearance-none cursor-pointer transition-colors ${z?"border-red-400 ring-2 ring-red-50 focus:border-red-400 focus:ring-red-50":C===dn?"border-green-400 ring-2 ring-green-50 focus:border-green-400 focus:ring-green-50 text-green-700":"border-slate-200 focus:border-blue-400 focus:ring-2 focus:ring-blue-50"} ${C?C===dn?"text-green-700":"text-slate-700":"text-slate-400"}`,children:[e.jsx("option",{value:"",disabled:!0,children:s("support_select_topic")}),Nm.map(J=>e.jsx("option",{value:J,children:s(wm[J])},J))]}),C===dn&&e.jsx("p",{className:"mt-1.5 text-xs text-green-600 font-medium",children:s("support_idea_note")}),z&&e.jsx("p",{className:"mt-1.5 text-xs text-red-500 font-medium",children:s("support_select_topic")}),C&&di[C]&&e.jsxs("div",{className:"mt-2 p-3 bg-blue-50 border border-blue-200 rounded-xl",children:[e.jsx("p",{className:"text-xs font-bold text-blue-700 mb-1",children:s("support_quick_answer_title")}),e.jsx("p",{className:"text-xs text-blue-700/90 leading-relaxed",children:s(di[C])}),e.jsx("p",{className:"text-xs text-blue-500 mt-1.5",children:s("support_quick_answer_still_stuck")})]}),C==="ÐÑÑгое"&&e.jsx("input",{type:"text",placeholder:s("support_custom_topic_placeholder"),value:U,onChange:J=>W(J.target.value),className:"mt-2 w-full px-4 py-2.5 border border-slate-200 rounded-xl text-sm outline-none focus:border-blue-400 focus:ring-2 focus:ring-blue-50 bg-white"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-bold text-slate-700 mb-2",children:s("support_describe_detail_label")}),e.jsx("textarea",{value:R,onChange:J=>S(J.target.value),placeholder:s("support_describe_detail_placeholder"),rows:3,className:"w-full px-4 py-2.5 border border-slate-200 rounded-xl text-sm outline-none focus:border-blue-400 focus:ring-2 focus:ring-blue-50 resize-y bg-white"})]}),e.jsx("input",{ref:jt,type:"file",accept:"image/png,image/jpeg,image/jpg,application/pdf",multiple:!0,className:"hidden",onChange:J=>{const We=Array.from(J.target.files||[]);if(!We.length)return;const oe=5-re.length;if(oe<=0){alert(s("support_max_3_files")),J.target.value="";return}We.some(ve=>ve.size>10*1024*1024)&&alert(s("support_file_too_large"));const Se=We.filter(ve=>ve.size<=10*1024*1024).slice(0,oe);Z(ve=>[...ve,...Se.map(T=>
69({file:T,previewUrl:T.type.startsWith("image/")?URL.createObjectURL(T):null}))]),J.target.value=""}}),re.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2",children:re.map((J,We)=>e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 bg-white rounded-xl border border-slate-200 max-w-full",children:[J.previewUrl?e.jsx("img",{src:J.previewUrl,className:"w-8 h-8 object-cover rounded-lg flex-shrink-0"}):e.jsx("div",{className:"w-8 h-8 bg-slate-100 rounded-lg flex items-center justify-center text-base flex-shrink-0",children:"ð"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs text-slate-700 font-medium truncate max-w-[140px]",children:J.file.name}),e.jsxs("p",{className:"text-[10px] text-slate-400",children:[(J.file.size/1024/1024).toFixed(1)," ",s("messages_mb_unit")]})]}),e.jsx("button",{onClick:()=>{J.previewUrl&&URL.revokeObjectURL(J.previewUrl),Z(oe=>oe.filter((Y,Se)=>Se!==We))},className:"p-1 text-slate-400 hover:text-red-500 transition-colors flex-shrink-0",children:e.jsx(bt,{size:14})})]},We))}),e.jsxs("div",{className:"flex flex-wrap gap-2 justify-between items-center",children:[e.jsxs("button",{onClick:()=>jt.current?.click(),disabled:re.length>=5,className:"flex items-center gap-1.5 text-xs text-slate-500 hover:text-slate-700 font-medium px-2 py-1 rounded-lg hover:bg-slate-100 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:[e.jsx(Bn,{size:14})," ",s("support_attach_file")," ",re.length>0&&`(${re.length}/5)`]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>{N(!1),S(""),L(null),W(""),me(!1)},className:"px-4 py-2 text-sm text-slate-500 hover:text-slate-700 font-medium",children:s("support_cancel")}),e.jsxs("button",{onClick:Ge,disabled:D||!R.trim()||!C||C==="ÐÑÑгое"&&!U.trim(),className:"flex items-center gap-2 px-4 py-2 bg-blue-600 hover:bg-blue-700 disabled:opacity-50 text-white rounded-xl text-sm font-bold transition-colors",children:[D&&e.jsx(rt,{size:14,className:"animate-spin"}),s("support_send_button")]})]})]})]}),e.jsx("div",{className:"px-3 md:px-6 py-2.5 flex gap-1.5 border-b border-slate-100 overflow-x-auto scrollbar-none",style:{scrollbarWidth:"none"},children:["ALL","OPEN","IN_PROGRESS","CLOSED"].map(J=>e.jsxs("button",{onClick:()=>c(J),className:`px-3 py-1.5 rounded-lg text-xs font-bold transition-all whitespace-nowrap shrink-0 ${l===J?"bg-blue-600 text-white":"bg-slate-100 text-slate-500 hover:bg-slate-200"}`,children:[s(J==="ALL"?"orders_tab_all":ja[J].labelKey),J==="OPEN"&&xt>0&&e.jsx("span",{className:"ml-1.5 bg-amber-500 text-white text-[9px] px-1.5 py-0.5 rounded-full",children:xt})]},J))}),p?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(rt,{className:"animate-spin text-slate-400"})}):zt.length===0?e.jsxs("div",{className:"flex flex-col items-center py-12 text-slate-400 gap-2",children:[e.jsx(Ur,{size:32}),e.jsx("p",{className:"text-sm",children:s("support_no_tickets")})]}):e.jsx("div",{children:zt.map(J=>{const We=ja[J.status],oe=We.icon,Y=J.messages[J.messages.length-1];return e.jsxs("button",{onClick:()=>it(J),className:"w-full flex items-center gap-4 px-5 py-4 border-b border-slate-100 last:border-0 hover:bg-slate-50 transition-colors text-left",children:[e.jsx("div",{className:`w-10 h-10 rounded-full flex items-center justify-center shrink-0 border ${We.color}`,children:e.jsx(oe,{size:16})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-bold text-slate-800 text-sm",children:J.subject||`#${J.id.slice(-6).toUpperCase()}`}),e.jsx("span",{className:`text-[10px] font-bold px-2 py-0.5 rounded-full border ${We.color}`,children:s(We.labelKey)}),J.client_unread&&e.jsx("span",{className:"w-2 h-2 rounded-full bg-red-500 shrink-0"})]}),Y&&e.jsxs("div",{className:"text-xs text-slate-500 truncate mt-0.5",children:[Y.sender==="ADMIN"?"â ":"",Y.text]})]}),e.jsx("div",{className:"text-xs text-slate-400 shrink-0",children:new Date(J.updated_at).toLocaleDateString("ru-RU")})]},J.id)})})]})]})}const Em=[{id:"none",label:"ÐеÑ",icon:e.jsx(bt,{size:18})}
69,{id:"bag",label:"ÐеÑок",icon:e.jsx(zn,{size:18})},{id:"box",label:"ÐоÑобка",icon:e.jsx(js,{size:18})},{id:"box_corner",label:"Уголки",icon:e.jsx(xn,{size:18})},{id:"crate",label:"ÐбÑеÑеÑка",icon:e.jsx(qo,{size:18})},{id:"pallet",label:"ÐаллеÑ",icon:e.jsx(Wo,{size:18})},{id:"wooden_box",label:"ÐеÑ. ÑÑик",icon:e.jsx(vi,{size:18})}],ui=t=>{const s=new Map;for(const n of t){const r=!!n.priority;for(const l of n.routes??[]){if(l.hidden)continue;const c=l.name||"";s.has(c)?r&&!s.get(c).hasPriority&&s.set(c,{route:l,hasPriority:!0}):s.set(c,{route:l,hasPriority:r})}}return Array.from(s.values()).map(n=>n.route)},Cm=async()=>{try{const t=await oc();if(t){const s=t.carriers;if(s?.length&&s[0]?.routes!==void 0)return ui(s);if(t.routes?.length)return t.routes.filter(n=>!n.hidden)}}catch{}try{const t=localStorage.getItem("admin_tariffs_fallback");if(t){const s=JSON.parse(t);if(s?.carriers?.[0]?.routes!==void 0)return ui(s.carriers);const n=Array.isArray(s)?s:s.routes||[];if(n.length)return n.filter(r=>!r.hidden)}}catch{}return[]},km=async()=>{try{const{data:t,error:s}=await Re("admin_services",{id:"default"},{select:"data",single:!0});if(!s&&t?.data)return t.data}catch{}try{const t=localStorage.getItem("admin_services_fallback");if(t)return JSON.parse(t)}catch{}return null},Rm={bag_small:"ÐеÑок малÑй",bag_medium:"ÐеÑок ÑÑедний",bag_large:"ÐеÑок болÑÑой",box_small:"ÐоÑобка малаÑ",box_medium:"ÐоÑобка ÑÑеднÑÑ",box_large:"ÐоÑобка болÑÑаÑ",box_corner_small:"Уголки малÑе",box_corner_medium:"Уголки ÑÑедние",box_corner_large:"Уголки болÑÑие",crate_small:"ÐбÑеÑеÑка малаÑ",crate_medium:"ÐбÑеÑеÑка ÑÑеднÑÑ",crate_large:"ÐбÑеÑеÑка болÑÑаÑ",wooden_box_small:"ÐеÑ. ÑÑик малÑй",wooden_box_medium:"ÐеÑ. ÑÑик ÑÑедний",wooden_box_large:"ÐеÑ. ÑÑик болÑÑой",pallet:"ÐаллеÑ"},Tm=async()=>{try{const{data:t,error:s}=await Re("app_settings",{},{select:"commission_settings",single:!0});if(!s&&t?.commission_settings)return t.commission_settings}catch{}return null},Dm={large:.8*.48*.6,medium:.68*.48*.5,small:.6*.38*.6},Om={large:.25,medium:.18,small:.1},Im={bag_small:"до 0.10 м³",bag_medium:"до 0.18 м³",bag_large:"до 0.25 м³",box_small:"60Ã38Ã60 Ñм · 0.137 м³",box_medium:"68Ã48Ã50 Ñм · 0.163 м³",box_large:"80Ã48Ã60 Ñм · 0.230 м³",box_corner_small:"60Ã38Ã60 Ñм · 0.137 м³",box_corner_medium:"68Ã48Ã50 Ñм · 0.163 м³",box_corner_large:"80Ã48Ã60 Ñм · 0.230 м³",crate_small:"60Ã38Ã60 Ñм · 0.137 м³",crate_medium:"68Ã48Ã50 Ñм · 0.163 м³",crate_large:"80Ã48Ã60 Ñм · 0.230 м³",wooden_box_small:"60Ã38Ã60 Ñм · 0.137 м³",wooden_box_medium:"68Ã48Ã50 Ñм · 0.163 м³",wooden_box_large:"80Ã48Ã60 Ñм · 0.230 м³"},va=t=>t==="USD"?"$":t==="CNY"?"Â¥":"â½";function Pm(){const[t,s]=a.useState([]),[n,r]=a.useState(null),[l,c]=a.useState(null),[o,d]=a.useState(!0),[p,y]=a.useState(0),[j,b]=a.useState(0),[h,v]=a.useState(0),[i,x]=a.useState(""),[m,N]=a.useState("1"),[R,S]=a.useState("simple"),[C,L]=a.useState(""),[U,W]=a.useState({l:"",w:"",h:""}),[re,Z]=a.useState("none"),[O,F]=a.useState(""),[D,$]=a.useState("CNY"),[z,me]=a.useState(!0),[K,te]=a.useState(null),[I,B]=a.useState(""),[Ne,Ue]=a.useState(!1),[$e,H]=a.useState(92),[le,Qe]=a.useState(13.5);a.useEffect(()=>{Promise.all([Cm(),km(),Tm()]).then(([Se,ve,T])=>{s(Se),r(ve),T&&c(T),d(!1)}),(async()=>{const Se=ve=>Number(ve.rate)||0;try{const{data:ve}=await Re("app_settings",{},{select:"currencies",single:!0}),T=ve?.currencies;if(Array.isArray(T)&&T.length>0){H(Se(T.find(ke=>ke.code==="USD")||{rate:92})),Qe(Se(T.find(ke=>ke.code==="CNY")||{rate:13.5}));return}}catch{}try{const ve=localStorage.getItem("tradehub_currencies");if(ve){const T=JSON.parse(ve);H(Se(T.find(ke=>ke.code==="USD")||{rate:92})),Qe(Se(T.find(ke=>ke.code==="CNY")||{rate:13.5}))}}catch{}})()},[]);const k=t[p]??null,xe=k?.deliveryTypes??[],de=xe[j]??null,V=de?.categories??[],ye=V[h]??null,Ie=Y=>{y(Y),b(0),v(0),te(null)},Oe=Y=>{b(Y),v(0),te(null)},we=(parseFloat(i)||0)*(parseFloat(m)||1),Le=(R==="simple"?parseFloat(C)||0:(()=>{const Se=parseFloat(U.l)||0,ve=parseFloat(U.w)||0,T=parseFloat(U.h)||0;return Se&&ve&&T?Se*ve*T/1e6:0})())*(parseFloat(m)||1),_t=Le>0?we/Le:0,jt=k?.name.split("â")[0].trim()??"",dt=Y=>{if(Y==="none"||!n)return{cost:0,currency:"USD",details:[],weightAddition:0};const Se=Y==="box_corner"?"box_corner":Y,ve=u=>{const _=n.packaging.filter(P=>P.type===u&&P.location===jt);return _.length?_[0]:n.packaging.find(P=>P.type===u)??null};if(Y==="pallet"){const u=ve("pallet");if(!u)return{cost:0,currency:"USD",details:[],weightAddition:0};const _=u.unit==="m3"?u.price*Le:u.price,P=u.loadingPrice?u.unit==="m3"?u.loadingPrice*Le:u.loadingPrice:0;return{cost:_+P,currency:u.currency,details:[{count:1,name:"ÐаллеÑ",typeKey:"pallet",unitPrice:u.price,total:_,loadingUnitPrice:u.loadingPrice??0,loadingTotal:P,currency:u.currency}],weightAddition:u.weightAddition??0}}const T=Y==="bag"?Om:Dm,ke=["large","medium","small"];let be=Le;const Ae=[];for(const u of ke){if(be<=.001)break;const _=ve(`${Se}_${u}`);if(!_)continue;const P=T[u],A=Math.floor(be/P);A>0&&(Ae.push({opt:_,count:A}),be-=A*P)}if(be>.001){let u=null;for(const _ of["small","medium","large"])if(u=ve(`${Se}_${_}`),u)break;
69if(u){const _=Ae.find(P=>P.opt.id===u.id);_?_.count+=1:Ae.push({opt:u,count:1})}}if(!Ae.length)return{cost:0,currency:"USD",details:[],weightAddition:0};const E=Ae.map(({opt:u,count:_})=>({count:_,name:Rm[u.type]??u.type,typeKey:u.type,unitPrice:u.price,total:u.price*_,loadingUnitPrice:u.loadingPrice??0,loadingTotal:(u.loadingPrice??0)*_,currency:u.currency})),se=E.reduce((u,_)=>u+_.total+_.loadingTotal,0),ee=Ae.reduce((u,{opt:_,count:P})=>u+(_.weightAddition??0)*P,0);return{cost:se,currency:Ae[0].opt.currency,details:E,weightAddition:ee}},gt=(Y,Se)=>{if(!n?.insurance?.isEnabled||Y<=0||we<=0)return 0;let ve=0;if(Se==="USD")ve=Y;else if(Se==="RUB")ve=Y/$e;else try{const be=localStorage.getItem("tradehub_currencies");if(be){const E=JSON.parse(be).find(ee=>ee.code==="CNY"),se=E&&Number(E.rate)||13.5;ve=Y*se/$e}}catch{ve=Y/7}const T=ve/we,ke=n.insurance.rules.find(be=>T>=be.minPrice&&(be.maxPrice===null||T<=be.maxPrice));return ke?ve*ke.rate/100:0},ht=(Y,Se)=>{if(!l?.isEnabled||Y<=0)return{cost:0,rate:0};let ve=0;Se==="CNY"?ve=Y:Se==="USD"?ve=Y*7:ve=Y/$e*7;const T=$e/7,ke=l.rules.map(ee=>({...ee,minAmount:Number(ee.minAmount),maxAmount:ee.maxAmount!=null?Number(ee.maxAmount):null,rate:Number(ee.rate)})).sort((ee,u)=>ee.minAmount-u.minAmount);let be=ke[0];for(const ee of ke){let u=ve;ee.currency==="RUB"?u=ve*T:ee.currency==="USD"&&(u=ve*T/$e),u>=ee.minAmount&&(ee.maxAmount===null||u<=ee.maxAmount)&&(be=ee)}const Ae=be?.rate??5;let E=ve*(Ae/100);const se=Number(l.minCommission)||0;if(se>0){let ee=se;l.minCommissionCurrency==="RUB"?ee=se/T:l.minCommissionCurrency==="USD"&&(ee=se*7),E=Math.max(E,ee)}return{cost:E/7,rate:Ae}},qe=()=>{if(B(""),!ye||!ye.prices.length){B("ТаÑиÑÑ Ð´Ð»Ñ Ð²ÑбÑанной каÑегоÑии не наÑÑÑоенÑ");return}if(we<=0||Le<=0){B("ÐведиÑе Ð²ÐµÑ Ð¸ обÑÑм гÑÑза");return}const Y=ye.prices.find(E=>_t>=E.minDensity&&(E.maxDensity===0||_t<=E.maxDensity))??ye.prices[ye.prices.length-1],Se=Y.unit==="kg"?Y.price*we:Y.price*Le,ve=dt(re),T=gt(parseFloat(O)||0,D),{cost:ke,rate:be}=ht(parseFloat(O)||0,D),Ae=we+ve.weightAddition;Ue(!0),setTimeout(()=>{te({deliveryCost:Se,deliveryRate:Y.price,deliveryUnit:Y.unit,packagingCost:ve.cost,packagingCurrency:ve.currency,packagingDetails:ve.details,packagingWeight:ve.weightAddition,insuranceCost:T,commissionCost:ke,commissionRate:be,routeName:k.name,deliveryTypeName:de.name,categoryName:ye.name,totalWeight:we,grossWeight:Ae,totalVolume:Le,density:_t}),Ue(!1)},350)};if(o)return e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx(rt,{size:32,className:"animate-spin text-blue-500"})});if(!t.length)return e.jsxs("div",{className:"flex flex-col items-center justify-center h-64 gap-3 text-slate-500",children:[e.jsx(hs,{size:36,className:"text-amber-400"}),e.jsx("p",{className:"font-semibold text-slate-700",children:"ТаÑиÑÑ ÐµÑÑ Ð½Ðµ наÑÑÑоенÑ"}),e.jsx("p",{className:"text-sm text-slate-400 text-center max-w-xs",children:"ÐалÑкÑлÑÑÐ¾Ñ Ð±ÑÐ´ÐµÑ Ð´Ð¾ÑÑÑпен поÑле Ñого, как админиÑÑÑаÑÐ¾Ñ Ð´Ð¾Ð±Ð°Ð²Ð¸Ñ ÑаÑиÑÑ."})]});const it=K!==null&&K.packagingCost>0,Ge=K!==null&&K.insuranceCost>0,St=K!==null&&K.commissionCost>0,Pt=K&&z?K.insuranceCost:0,Ut=K?K.deliveryCost+K.packagingCost+Pt+K.commissionCost:0,xt=Math.round(Ut*$e),zt=parseFloat(O)||0,J=zt>
690?Math.round(D==="RUB"?zt:D==="USD"?zt*$e:zt*le):0,We=D==="CNY"?`${le.toFixed(2)} â½/Â¥`:D==="USD"?`${$e.toFixed(2)} â½/$`:null,oe=xt+J;return e.jsxs("div",{className:"max-w-2xl lg:max-w-3xl xl:max-w-4xl mx-auto space-y-5",children:[e.jsxs("div",{className:"bg-white p-6 rounded-2xl shadow-sm border border-slate-200",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsx("div",{className:"w-12 h-12 bg-blue-600 rounded-xl flex items-center justify-center text-white shadow-lg shadow-blue-200",children:e.jsx(un,{size:22})}),e.jsxs("div",{children:[e.jsx("h2",{className:"font-bold text-lg text-slate-900",children:"УмнÑй ÑаÑÑеÑ"}),e.jsx("p",{className:"text-xs text-slate-400",children:"ТоÑнÑй калÑкÑлÑÑÐ¾Ñ ÑÑоимоÑÑи доÑÑавки"})]})]}),e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"bg-slate-50 p-4 rounded-xl border border-slate-100 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] font-bold text-slate-500 uppercase mb-1.5",children:"ÐаÑÑÑÑÑ"}),e.jsx("select",{className:"w-full border border-slate-200 rounded-lg px-3 py-2 text-sm outline-none focus:border-blue-400 bg-white",value:p,onChange:Y=>Ie(Number(Y.target.value)),children:t.map((Y,Se)=>e.jsx("option",{value:Se,children:Y.name},Y.id))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] font-bold text-slate-500 uppercase mb-1.5",children:"Тип доÑÑавки"}),e.jsx("select",{className:"w-full border border-slate-200 rounded-lg px-3 py-2 text-sm outline-none focus:border-blue-400 bg-white",value:j,onChange:Y=>Oe(Number(Y.target.value)),disabled:!xe.length,children:xe.map((Y,Se)=>e.jsx("option",{value:Se,children:Y.name},Y.id))})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] font-bold text-slate-500 uppercase mb-1.5",children:"ÐаÑегоÑÐ¸Ñ Ð³ÑÑза"}),e.jsx("select",{className:"w-full border border-slate-200 rounded-lg px-3 py-2 text-sm font-semibold outline-none focus:border-blue-400 bg-white",value:h,onChange:Y=>{v(Number(Y.target.value)),te(null)},disabled:!V.length,children:V.map((Y,Se)=>e.jsx("option",{value:Se,children:Y.name},Y.id))})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] font-bold text-slate-400 uppercase mb-2",children:"ÐаÑамеÑÑÑ Ð³ÑÑза"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-12 gap-2 items-end",children:[e.jsxs("div",{className:"col-span-3",children:[e.jsx("label",{className:"block text-[10px] font-bold text-slate-500 mb-1 text-center",children:"ÐÐС 1 ÐÐСТÐ"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:"number",placeholder:"0",min:"0",step:"0.1",value:i,onChange:Y=>{x(Y.target.value),te(null)},className:"w-full p-2.5 text-center border rounded-lg outline-none focus:border-blue-400 text-sm pr-7"}),e.jsx("span",{className:"absolute right-2 top-1/2 -translate-y-1/2 text-[10px] font-bold text-slate-400",children:"кг"})]})]}),e.jsxs("div",{className:"col-span-6",children:[e.jsxs("div",{className:"flex justify-between mb-1 px-1",children:[e.jsx("label",{className:"block text-[10px] font-bold text-slate-500",children:"ÐÐЪÐÐ / ÐÐÐÐÐ ÐТЫ"}),e.jsx("button",{onClick:()=>{S(Y=>Y==="simple"?"dims":"simple"),te(null)},className:"text-blue-500 text-[10px] font-bold hover:underline",children:R==="simple"?"Ðо габаÑиÑам":"РкÑбаÑ
"})]}),R==="simple"?e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:"number",placeholder:"0",min:"0",step:"0.001",value:C,onChange:Y=>{L(Y.target.value),te(null)},className:"w-full p-2.5 text-center border rounded-lg outline-none focus:border-blue-400 text-sm pr-9"}),e.jsx("span",{className:"absolute right-2 top-1/2 -translate-y-1/2 text-[10px] font-bold text-slate-400",children:"м³"})]}):e.jsxs("div",{className:"flex gap-1 items-end",children:[["l","w","h"].map((Y,Se)=>e.jsx("input",{type:"number",placeholder:["Ð","Ш","Ð"][Se],value:U[Y],onChange:ve=>{W(T=>({...T,[Y]:ve.target.value})),te(null)},className:"w-full p-2.5 text-center border rounded-lg text-xs outline-none focus:border-blue-400",min:"0"},Y)),e.jsx("span",{className:"text-[10px] text-slate-400 pb-2 whitespace-nowrap",children:"Ñм"})]})]}),e.jsxs("div",{className:"col-span-3",children:[e.jsx("label",{className:"block text-[10px] font-bold text-blue-500 mb-1 text-center",children:"ÐÐÐ-ÐÐ ÐÐСТ"}),e.jsx("input",{type:"number",placeholder:"1",min:"1",value:m,onChange:Y=>{N(Y.target.value),te(null)},className:"w-full p-2.5 text-center border border-blue-200 bg-blue-50 text-blue-700 rounded-lg font-bold outline-none focus:border-blue-400 text-sm"})]})]}),e.jsxs("div",{className:"flex justify-end gap-4 text-xs font-bold text-slate-500 bg-slate-50 p-2 rounded-lg border border-slate-100 mt-2",children:[e.jsxs("span",{children:["ÐеÑ: ",we.toFixed(1)," кг"]}),e.jsxs("span",{children:["ÐбÑем: ",Le.toFixed(3)," м³"]}),Le>0&&e.jsxs("span",{children:["ÐлоÑноÑÑÑ: ",_t.toFixed(0)," кг/м³"]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] font-bold text-slate-400 uppercase mb-2",children:"СÑоимоÑÑÑ ÑоваÑа (Ð´Ð»Ñ ÑÑÑаÑ
овки)"}),e.jsxs("div",{className:"flex",children:[e.jsx("input",{type:"number",placeholder:"0",min:"0",value:O,onChange:Y=>{F(Y.target.value),te(null)},className:"w-full p-2.5 border rounded-l-lg outline-none focus:border-blue-400 text-sm"}),e.jsxs("select",{value:D,onChange:Y=>{$(Y.target.value),te(null)},className:"bg-slate-50 border border-l-0 rounded-r-lg px-3 text-sm font-bold outline-none focus:border-blue-400 cursor-pointer text-slate-700",children:[e.jsx("option",{value:"CNY",children:"Â¥ CNY"}),e.jsx("option",{value:"USD",children:"$ USD"}),e.jsx("option",{value:"RUB",children:"â½ RUB"})]})]}),D!=="USD"&&parseFloat(O)>0&&e.jsx("p",{className:"text-[10px] text-slate-400 mt-1 px-1",children:"ÐÑÐ´ÐµÑ ÐºÐ¾Ð½Ð²ÐµÑÑиÑовано в USD Ð´Ð»Ñ ÑаÑÑÑÑа ÑÑÑаÑ
овки"})]}),n&&n.packaging.length>0&&e.jsxs("div",{className:"bg-orange-50 p-4 rounded-xl border border-orange-100",children:[e.jsx("label",{className:"block text-[10px] font-bold text-orange-400 uppercase mb-3",children:"Упаковка"}),e.jsx("div",{className:"grid grid-cols-4 gap-2 sm:grid-cols-7",children:Em.map(Y=>e.jsxs("button",{onClick:()=>{Z(Y.id),te(null)},className:`flex flex-col items-center justify-center p-2 rounded-lg transition-all ${re===Y.id?"bg-white border-2 border-orange-500 shadow-sm text-orange-600 scale-105":"bg-white/50 border-2 border-transparent text-slate-500 hover:bg-white hover:border-orange-200"}`,children:[Y.icon,e.jsx("span",{className:"text-[9px] font-bold text-center leading-tight mt-1",children:Y.label})]},Y.id))})]}),I&&e.jsxs("div",{className:"flex items-center gap-2 bg-red-50 border border-red-200 text-red-700 rounded-lg px-4 py-3 text-sm font-medium",children:[e.jsx(hs,{size:16}),I]}),e.jsx("button",{onClick:qe,disabled:Ne,className:"w-full bg-blue-600 text-white font-bold py-3.5 rounded-xl hover:bg-blue-700 transition-all shadow-lg shadow-blue-200 active:scale-95 flex items-center justify-center gap-2 disabled:opacity-60",children:Ne?e.jsx(rt,{size:20,className:"animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(un,{size:20})," РаÑÑÑиÑаÑÑ ÑÑоимоÑÑÑ Ð´Ð¾ÑÑавки"]})})]})]}),K&&e.jsx("div",{className:"bg-white rounded-2xl shadow-sm border border-slate-200 overflow-hidden animate-in fade-in slide-in-from-bottom-2 duration-300",children:e.jsxs("div",{className:"p-6 space-y-5",children:[e.jsxs("div",{className:"flex justify-between items-center text-xs font-bold text-slate-500 bg-slate-50 p-3 rounded-xl border border-slate-100",children:[e.jsxs("span",{children:["ÐÐµÑ Ð±ÑÑÑÑо: ",e.jsxs("span",{className:"text-orange-600",children:[K.grossWeight.toFixed(1)," кг"]})]}),K.packagingWeight>0&&e.jsxs("span",{className:"text-slate-400 font-normal",children:["(",K.totalWeight.toFixed(1)," неÑÑо + ",K.packagingWeight.toFixed(1)," Ñпак.)"]})]}),e.jsx("div",{className:"grid grid-cols-3 gap-3",children:[{label:"ÐÐµÑ Ð½ÐµÑÑо",value:K.totalWeight.toFixed(1),unit:"кг"},{label:"ÐбÑем",value:K.totalVolume.toFixed(3),unit:"м³"},{label:"ÐлоÑноÑÑÑ",value:K.density.toFixed(0),unit:"кг/м³"}].map(Y=>e.jsxs("div",{className:"bg-slate-50 rounded-xl p-3 text-center border border-slate-100",children:[e.jsx("div",{className:"text-[10px] font-bold text-slate-400 uppercase mb-1",children:Y.label}),e.jsx("div",{className:"text-lg font-black text-slate-800",children:Y.value}),e.jsx("div",{className:"text-[10px] text-slate-500",children:Y.unit})]},Y.label))}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-bold text-slate-400 uppercase mb-2",children:"ÐеÑализаÑиÑ"}),e.jsxs("div",{className:"divide-y divide-slate-100",children:[e.jsx(Na,{label:"ÐаÑегоÑиÑ",value:K.categoryName}),e.jsx(Na,{label:`ТаÑÐ¸Ñ Ð´Ð¾ÑÑавки (${K.deliveryUnit==="kg"?"$/кг":"$/м³"})`,value:`$${K.deliveryRate.toFixed(2)}`}),e.jsx(Na,{label:"СÑоимоÑÑÑ Ð´Ð¾ÑÑавки",value:`$${K.deliveryCost.toFixed(2)}`,bold:!0}),it&&K.packagingDetails.map((Y,Se)=>{const ve=`Ñпак. ${va(Y.currency)}${Y.unitPrice.toFixed(0)}`,T=Y.loadingUnitPrice>0?` + погÑÑзка ${va(Y.currency)}${Y.loadingUnitPrice.toFixed(0)}`:"",ke=Im[Y.typeKey]??"",be=Y.count>1?` à ${Y.count} ÑÑ.`:"",Ae=Y.total+Y.loadingTotal;return e.jsxs("div",{className:"flex justify-between items-center py-2.5",children:[e.jsxs("div",{children:[e.jsxs("span",{className:"text-sm text-slate-700 font-bold",children:[Y.name,be,e.jsxs("span",{className:"font-normal text-slate-400 ml-1.5",children:["(",ve,T,")"]})]}),ke&&e.jsx("div",{className:"text-[10px] text-slate-400 mt-0.5",children:ke})]}),e.jsxs("span",{className:"text-sm font-bold text-slate-800",children:[va(Y.currency),Ae.toFixed(2)]})]},Se)}),St&&e.jsxs("div",{className:"flex justify-between items-center py-2.5",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-sm text-slate-700 font-bold",children:"ÐомиÑÑÐ¸Ñ Ð·Ð° вÑкÑп"}),e.jsxs("div",{className:"text-[10px] text-slate-400 mt-0.5",children:[K.commissionRate,"% Ð¾Ñ ÑÑоимоÑÑи ÑоваÑа"]})]}),e.jsxs("span",{className:"text-sm font-bold text-slate-800",children:["$",K.commissionCost.toFixed(2)]})]}),Ge&&e.jsxs("div",{className:"flex justify-between items-center py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[e.jsx("input",{type:"checkbox",checked:z,onChange:Y=>me(Y.target.checked),className:"w-4 h-4 rounded accent-blue-600 cursor-pointer"}),e.jsx("span",{className:"text-sm text-slate-700 font-bold",children:"СÑÑаÑ
овка"})]}),e.jsx("span",{className:"text-[10px] font-bold text-green-600 bg-green-50 px-1.5 py-0.5 rounded-full",children:"по желаниÑ"})]}),e.jsxs("span",{className:`text-sm font-bold ${z?"text-slate-800":"text-slate-300 line-through"}`,children:["$",K.insuranceCost.toFixed(2)]})]})]})]}),e.jsxs("div",{className:"-mx-6 -mb-6 rounded-b-2xl overflow-hidden bg-blue-600",children:[e.jsxs("div",{className:"px-5 pt-4 pb-3 flex items-center justify-between border-b border-blue-500",children:[e.jsx("span",{className:"text-sm font-bold text-white",children:K.routeName}),e.jsx("span",{className:"text-xs font-semibold text-blue-100 bg-blue-500 px-2.5 py-1 rounded-full",children:K.deliveryTypeName})]}),e.jsxs("div",{className:"flex justify-between items-center px-5 py-3 border-b border-blue-500",children:[e.jsx("span",{className:"text-sm font-medium text-blue-100",children:"ÐоÑÑавка и ÑÑлÑги"}),e.jsxs("span",{className:"text-sm font-bold text-white",children:[xt.toLocaleStr
69ing("ru-RU")," â½"]})]}),J>0&&e.jsxs("div",{className:"flex justify-between items-center px-5 py-3 border-b border-blue-500",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-sm font-medium text-blue-100",children:"СÑоимоÑÑÑ ÑоваÑа"}),We&&e.jsxs("div",{className:"text-[10px] text-blue-300 font-mono",children:["ÐÑÑÑ: ",We]})]}),e.jsxs("span",{className:"text-sm font-bold text-white",children:[J.toLocaleString("ru-RU")," â½"]})]}),e.jsxs("div",{className:"flex justify-between items-center px-5 py-4",children:[e.jsx("span",{className:"text-xs font-bold text-blue-200 uppercase tracking-widest",children:"ÐÑого"}),e.jsxs("div",{className:"text-right",children:[e.jsxs("div",{className:"text-2xl font-extrabold text-white",children:[(J>0?oe:xt).toLocaleString("ru-RU")," â½"]}),J===0&&e.jsxs("div",{className:"text-[10px] text-blue-300 font-mono",children:["ÐÑÑÑ: ",$e.toFixed(2)," â½/$"]})]})]})]}),e.jsxs("button",{onClick:()=>te(null),className:"w-full flex items-center justify-center gap-2 text-sm text-slate-400 hover:text-slate-600 py-2 hover:bg-slate-50 rounded-lg transition-colors",children:[e.jsx(Go,{size:14})," ÐовÑй ÑаÑÑеÑ"]})]})}),e.jsx(Am,{})]})}function Am(){const[t,s]=a.useState(""),[n,r]=a.useState(""),[l,c]=a.useState(""),[o,d]=a.useState(""),[p,y]=a.useState([]),[j,b]=a.useState(!1),[h,v]=a.useState(!1),i=async m=>{const N=Array.from(m.target.files||[]),R=3-p.length;y(S=>[...S,...N.slice(0,R)]),m.target.value=""},x=async()=>{if(!t||!n){alert("УкажиÑе Ð²ÐµÑ Ð¸ обÑÑм");return}const m=yt();if(!m){alert("ÐойдиÑе в аккаÑнÑ");return}b(!0);try{const N=[];for(const C of p){const L=await Er(C),U=`price_req_${m}_${Date.now()}_${N.length}.jpg`,{publicUrl:W}=await tr("support-attachments",U,L);W&&N.push(W)}const R=crypto.randomUUID(),{error:S}=await st("price_requests",{id:R,user_id:m,product_url:l.trim()||null,images:N,weight_kg:parseFloat(t),volume_m3:parseFloat(n),client_comment:o.trim()||null,status:"PENDING",created_at:new Date().toISOString()});if(S)throw new Error(S);await st("notifications",{type:"PRICE_REQUEST",title:"ÐапÑÐ¾Ñ ÑенÑ",text:`ÐеÑ: ${t} кг, ÐбÑÑм: ${n} м³${l?". ÐÑÑÑ ÑÑÑлка.":""}`,date:new Date().toISOString(),is_read:!1,link:R}),v(!0)}catch(N){alert("ÐÑибка: "+N.message)}finally{b(!1)}};return h?e.jsxs("div",{className:"mt-8 bg-green-50 border border-green-200 rounded-2xl p-6 text-center",children:[e.jsx("div",{className:"text-3xl mb-2",children:"â
"}),e.jsx("p",{className:"font-bold text-green-800",children:"ÐапÑÐ¾Ñ Ð¾ÑпÑавлен!"}),e.jsx("p",{className:"text-sm text-green-700 mt-1",children:"ÐÐµÐ½ÐµÐ´Ð¶ÐµÑ ÑаÑÑÑиÑÐ°ÐµÑ ÑÐµÐ½Ñ Ð¸ пÑиÑлÑÑ Ð¾ÑÐ²ÐµÑ Ð² ÑообÑениÑ."})]}):e.jsxs("div",{className:"mt-8 bg-white border border-slate-200 rounded-2xl p-5 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(un,{size:18,className:"text-blue-600"}),e.jsx("h3",{className:"font-bold text-slate-800",children:"Ðе наÑли ÑÐ²Ð¾Ñ ÐºÐ°ÑегоÑиÑ?"})]}),e.jsx("p",{className:"text-sm text-slate-500 mb-4",children:"УкажиÑе паÑамеÑÑÑ ÑоваÑа â Ð¼ÐµÐ½ÐµÐ´Ð¶ÐµÑ ÑаÑÑÑиÑÐ°ÐµÑ ÑÐµÐ½Ñ Ð¸Ð½Ð´Ð¸Ð²Ð¸Ð´ÑалÑно."}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"text-xs font-bold text-slate-500 mb-1 block",children:["ÐÐµÑ (кг) ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"number",value:t,onChange:m=>s(m.target.value),placeholder:"напÑимеÑ: 10",className:"w-full border border-slate-200 rounded-xl px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-400"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"text-xs font-bold text-slate-500 mb-1 block",children:["ÐбÑÑм (м³) ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"number",value:n,onChange:m=>r(m.target.value),placeholder:"напÑимеÑ: 0.05",className:"w-full border border-slate-200 rounded-xl px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-400"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-bold text-slate-500 mb-1 block",children:"СÑÑлка на ÑÐ¾Ð²Ð°Ñ (необÑзаÑелÑно)"}
69),e.jsx("input",{type:"url",value:l,onChange:m=>c(m.target.value),placeholder:"https://1688.com/...",className:"w-full border border-slate-200 rounded-xl px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-400"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-bold text-slate-500 mb-1 block",children:"ÐомменÑаÑий (необÑзаÑелÑно)"}),e.jsx("textarea",{value:o,onChange:m=>d(m.target.value),placeholder:"ÐпиÑиÑе ÑоваÑ, маÑеÑиал, оÑобенноÑÑи...",rows:2,className:"w-full border border-slate-200 rounded-xl px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-400 resize-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-bold text-slate-500 mb-1 block",children:"ФоÑо ÑоваÑа (до 3 ÑÑ, необÑзаÑелÑно)"}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[p.map((m,N)=>e.jsxs("div",{className:"relative w-16 h-16",children:[e.jsx("img",{src:URL.createObjectURL(m),alt:"",className:"w-full h-full object-cover rounded-lg border"}),e.jsx("button",{onClick:()=>y(R=>R.filter((S,C)=>C!==N)),className:"absolute -top-1 -right-1 w-4 h-4 bg-red-500 text-white rounded-full flex items-center justify-center",children:e.jsx(bt,{size:10})})]},N)),p.length<3&&e.jsxs("label",{className:"w-16 h-16 border-2 border-dashed border-slate-300 rounded-lg flex items-center justify-center cursor-pointer hover:border-blue-400 transition-colors",children:[e.jsx(Ei,{size:18,className:"text-slate-400"}),e.jsx("input",{type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:i})]})]})]}),e.jsxs("button",{onClick:x,disabled:j||!t||!n,className:"w-full flex items-center justify-center gap-2 py-3 bg-blue-600 hover:bg-blue-700 disabled:bg-slate-200 disabled:cursor-not-allowed text-white font-bold rounded-xl transition-colors text-sm",children:[j?e.jsx(rt,{size:16,className:"animate-spin"}):e.jsx(Ss,{size:16}),j?"ÐÑпÑавка...":"ÐапÑоÑиÑÑ ÑаÑÑÑÑ"]})]})]})}function Na({label:t,value:s,bold:n,sub:r}){return e.jsxs("div",{className:"flex justify-between items-center py-2.5",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-sm text-slate-500",children:t}),r&&e.jsx("div",{className:"text-[10px] text-slate-400",children:r})]}),e.jsx("span",{className:`text-sm ${n?"font-bold text-slate-800":"text-slate-700"}`,children:s})]})}function Lm({userId:t,friendlyId:s,items:n,batches:r,initialKey:l,onClose:c,onCreated:o}
69){const[d,p]=a.useState(()=>new Set([l])),[y,j]=a.useState(!1),b=a.useMemo(()=>new Set(r.map(S=>S.id)),[r]),h=S=>S.batch_id&&b.has(S.batch_id)?S.batch_id:fl,v=a.useMemo(()=>Ri(n,r).filter(S=>S.counts.arrived>0),[n,r]),x=v.filter(S=>d.has(S.key)).reduce((S,C)=>S+C.counts.arrived,0),m=v.filter(S=>!d.has(S.key)),N=S=>{p(C=>{const L=new Set(C);return L.has(S)?L.delete(S):L.add(S),L})},R=async()=>{if(d.size===0){alert("ÐÑмеÑÑÑе Ñ
оÑÑ Ð±Ñ Ð¾Ð´Ð½Ñ Ð¿Ð»Ð°ÑкÑ");return}j(!0);try{const{data:S,error:C}=await Re("self_buyout_items",{user_id:t,status:"ARRIVED"},{select:"*",order:"created_at.asc"});if(C){alert("Ðе ÑдалоÑÑ Ð¿Ð¾Ð»ÑÑиÑÑ Ð°ÐºÑÑалÑнÑй ÑпиÑок поÑÑлок. ÐопÑобÑйÑе еÑÑ Ñаз.");return}const U=(S||[]).filter(B=>d.has(h(B)));if(U.length===0){alert("РвÑбÑаннÑÑ
плаÑкаÑ
болÑÑе Ð½ÐµÑ Ð¿Ð¾ÑÑлок на Ñкладе â обновиÑе ÑÑÑаниÑÑ."),c();return}const W=new Set(U.map(h)),re=new Map(v.map(B=>[B.key,B.label])),Z=v.filter(B=>W.has(B.key)).map(B=>B.label),O=cc(Z),F=W.size>1,D=new Date().toISOString(),z=v.find(B=>B.key===l)?.batch?.display_id||(s?await qa(t,s):`SB-${Date.now().toString(36).toUpperCase()}`),me=crypto.randomUUID(),{error:K}=await st("orders",{id:me,user_id:t,display_id:z,status:"PURCHASED",total_cny:0,commission_cny:0,delivery_cost_usd:0,delivery_payment_status:"UNPAID",items_count:U.length,items:U.map(B=>{const Ne=h(B),Ue=re.get(Ne)||Lr,$e=Ne!==fl?Ue:B.recipient_name||(F?Lr:"");return{id:B.id,name:B.item_description||`ТÑек: ${B.track_number}`,priceCNY:0,quantity:1,trackingNumber:B.track_number,status:"RECEIVED",params:$e?`ÐлÑ: ${$e}`:"",photos:[],refundStatus:"NONE"}}),client_label:O||null,is_self_buyout:!0,created_at:D,paid_at:D,purchased_at:D});if(K){alert("ÐÑибка ÑÐ¾Ð·Ð´Ð°Ð½Ð¸Ñ Ð·Ð°Ñвки. ÐопÑобÑйÑе еÑÑ Ñаз.");return}for(const B of U)await Je("self_buyout_items",{id:B.id},{status:"SHIPPED",order_id:me});const{data:te}=await Re("self_buyout_items",{user_id:t},{select:"id,batch_id,status",inFilters:{status:["PENDING","ARRIVED"]}}),I=new Set((te||[]).map(B=>B.batch_id).filter(B=>!!B));for(const B of v)!B.batch||!W.has(B.key)||!I.has(B.batch.id)&&B.batch.status!=="SHIPPED"&&await Je("self_buyout_batches",{id:B.batch.id},{status:"SHIPPED"});o(me,z,U.length,O)}finally{j(!1)}};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-end sm:items-center justify-center bg-black/40 backdrop-blur-sm p-4",children:e.jsxs("div",{className:"ym-hide-content bg-white rounded-2xl w-full max-w-lg max-h-[90vh] overflow-y-auto shadow-2xl",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-slate-100 sticky top-0 bg-white z-10",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"font-bold text-slate-900",children:"ÐÑоÑмиÑÑ Ð´Ð¾ÑÑавкÑ"}),e.jsx("p",{className:"text-xs text-slate-500 mt-0.5",children:"ЧÑо оÑпÑавлÑем одной поÑÑлкой"})]}),e.jsx("button",{onClick:c,className:"p-2 rounded-full hover:bg-slate-100 text-slate-400",children:e.jsx(bt,{size:20})})]}),e.jsxs("div",{className:"px-5 py-4 space-y-4",children:[e.jsxs("div",{className:"text-sm text-slate-600",children:["ÐÑмеÑÑÑе плаÑки, коÑоÑÑе едÑÑ ",e.jsx("b",{children:"вмеÑÑе одной оÑпÑавкой на один адÑеÑ"}),". ЧÑо не оÑмеÑиÑе â оÑÑанеÑÑÑ Ð½Ð° Ñкладе и ждÑÑ Ñвоей оÑпÑавки."]}),e.jsx("div",{className:"space-y-2",children:v.map(S=>{const C=d.has(S.key);return e.jsxs("button",{onClick:()=>N(S.key),className:`w-full flex items-center gap-3 px-3.5 py-3 rounded-xl border text-left transition-all ${C?"border-green-500 bg-green-50":"border-slate-200 hover:border-slate-300"}`,children:[C?e.jsx(Ho,{size:18,className:"text-green-600 shrink-0"}):e.jsx(Vo,{size:18,className:"text-slate-300 shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-semibold text-slate-800 text-sm truncate",children:S.label}),e.jsxs("div",{className:"text-xs text-slate-500",children:[S.counts.arrived," ÑÑек. на Ñкладе",S.counts.pending>0&&` · ${S.counts.pending} еÑÑ Ð¶Ð´Ñм`]})]})]},S.key)})}),e.jsxs("div",{className:"rounded-xl border border-amber-200 bg-amber-50 p-3.5 text-sm text-amber-800 space-y-1.5",children:[e.jsxs("div",{className:"font-semibold flex items-center gap-2",children:[e.jsx(Fn,{size:15}),"ÐинимÑм 10 кг на Ð¾Ð´Ð½Ñ Ð¾ÑпÑавкÑ"]}),m.length>0?e.jsxs("div",{children:["СейÑÐ°Ñ ÐµÐ´ÐµÑ ",x," из ",x+m.reduce((S,C)=>S+C.counts.arrived,0)," поÑÑлок, гоÑовÑÑ
к оÑпÑавке. ÐÑли ÑазбиÑÑ Ð¸Ñ
на неÑколÑко оÑпÑавок, ÐºÐ°Ð¶Ð´Ð°Ñ Ð´Ð¾Ð»Ð¶Ð½Ð° набÑаÑÑ 10 кг оÑделÑно â ÑаÑÑо вÑгоднее оÑмеÑиÑÑ ÐµÑÑ Ð¿Ð»Ð°Ñки и оÑпÑавиÑÑ Ð²ÑÑ Ð²Ð¼ÐµÑÑе."]}):e.jsx("div",{children:"ÐÑпÑавка легÑе 10 кг вÑÑ Ñавно ÑÑиÑаеÑÑÑ ÐºÐ°Ðº 10 кг. ÐÑли веÑа не Ñ
ваÑÐ°ÐµÑ â подождиÑе оÑÑалÑнÑе поÑÑлки."})]}),e.jsxs("button",{onClick:R,disabled:d.size===0||y,className:"w-full flex items-center justify-center gap-2 py-3.5 bg-green-600 hover:bg-green-700 disabled:opacity-50 text-white font-bold rounded-xl transition-colors",children:[y?e.jsx(rt,{size:18,className:"animate-spin"}):e.jsx(Lt,{size:18}),y?"СоздаÑм заказ...":"Ðалее â кÑда и как оÑпÑавиÑÑ"]})]})]})})}
69const Mm={PENDING:{label:"ÐжидаеÑÑÑ",color:"bg-amber-100 text-amber-700 border-amber-200",icon:rs,dot:"bg-amber-400"},ARRIVED:{label:"Ðа Ñкладе",color:"bg-green-100 text-green-700 border-green-200",icon:ss,dot:"bg-green-500"},SHIPPED:{label:"ÐÑпÑавлен",color:"bg-blue-100 text-blue-700 border-blue-200",icon:Lt,dot:"bg-blue-500"}},xi=[{icon:Qn,title:"1. ÐайдиÑе ÑÑек-номеÑ",text:"ÐÑÐ¾Ð´Ð°Ð²ÐµÑ Ð¿ÑиÑÑÐ»Ð°ÐµÑ ÐµÐ³Ð¾ в ÑаÑе заказа (или он еÑÑÑ Ð² пÑиложении кÑÑÑеÑа: å¿«éåå· / Waybill No.). ÐбÑÑно ÑÑо 10â15 ÑиÑÑ Ð¸ бÑкв."},{icon:rs,title:"2. ÐождиÑеÑÑ Ð¿ÑибÑÑÐ¸Ñ Ð½Ð° Ñклад",text:"СледиÑе за поÑÑлкой Ñами â по ÑÐ²Ð¾ÐµÐ¼Ñ ÑÑÐµÐºÐ¸Ð½Ð³Ñ Ð¸Ð»Ð¸ в пÑиложении кÑÑÑеÑа. Ðе добавлÑйÑе Ð½Ð¾Ð¼ÐµÑ ÑÑÐ°Ð·Ñ Ð¿Ð¾Ñле покÑпки, подождиÑе, пока Ñами ÑвидиÑе, ÑÑо она доеÑ
ала до наÑего Ñклада в ÐиÑае."},{icon:Ci,title:"3. ТолÑко Ñогда добавÑÑе Ð½Ð¾Ð¼ÐµÑ ÑÑда",text:"Ðак ÑолÑко ÑвидиÑе по ÑÐ²Ð¾ÐµÐ¼Ñ ÑÑекингÑ, ÑÑо поÑÑлка на Ñкладе â ÑÑÐ°Ð·Ñ Ð½Ð°Ð¶Ð¼Ð¸Ñе «+ ТÑек» на нÑжной плаÑке и вÑÑавÑÑе номеÑ. ÐÑ ÑвеÑим и подÑвеÑдим пÑиÑмкÑ."}];function mi({step:t}){const s=t.icon;return e.jsxs("div",{className:"flex-1 min-w-[200px] bg-white rounded-xl border border-slate-200 p-3.5",children:[t.imageUrl?e.jsx("img",{src:t.imageUrl,alt:t.title,className:"w-full h-28 object-cover rounded-lg mb-2.5"}):e.jsx("div",{className:"w-full h-20 rounded-lg mb-2.5 bg-slate-50 border border-slate-100 flex items-center justify-center",children:e.jsx(s,{size:28,className:"text-blue-400"})}),e.jsx("div",{className:"font-semibold text-slate-800 text-sm",children:t.title}),e.jsx("div",{className:"text-xs text-slate-500 mt-1 leading-relaxed",children:t.text})]})}const wa=[{icon:gs,title:"ÐÑоÑмлÑÑ Ð´Ð»Ñ ÑебÑ",text:"ÐÑе ÑÑеки в одной поÑÑлке, Ð¿Ð¾ÐµÐ´ÐµÑ Ð½Ð° Ð²Ð°Ñ Ð°Ð´ÑеÑ."},{icon:Ra,title:"ÐÑоÑмлÑÑ Ð´Ð»Ñ ÑазнÑÑ
лÑдей",text:"ÐÑделÑÐ½Ð°Ñ Ð¿Ð»Ð°Ñка на каждого Ñеловека. ÐаждÑÑ Ð¿Ð»Ð°ÑÐºÑ Ð¼Ð¾Ð¶Ð½Ð¾ оÑпÑавиÑÑ Ð¾ÑделÑно на Ñвой адÑеÑ. ÐинимÑм 10 кг на каждÑÑ Ð¾ÑпÑавкÑ."}];function zm({onNavigateToOrder:t}){const s=yt(),[n,r]=a.useState(""),[l,c]=a.useState([]),[o,d]=a.useState([]),[p,y]=a.useState(null),[j,b]=a.useState(!0),[h,v]=a.useState(null),[i,x]=a.useState(!1),[m,N]=a.useState(!1),[R,S]=a.useState(!1),[C,L]=a.useState(!1),[U,W]=a.useState(null),[re,Z]=a.useState(""),[O,F]=a.useState(""),D=5,[$,z]=a.useState([]),[me,K]=a.useState([]),[te,I]=a.useState([]),[B,Ne]=a.useState(!1),[Ue,$e]=a.useState(!1),[H,le]=a.useState(""),[Qe,k]=a.useState(!1),[xe,de]=a.useState(""),[V,ye]=a.useState(!1),[Ie,Oe]=a.useState(null),[we,Le]=a.useState(null),[_t,jt]=a.useState(null),[dt,gt]=a.useState(null),ht=a.useCallback(async()=>{if(!s)return;b(!0);const[w,fe,pe]=await Promise.all([Re("self_buyout_batches",{user_id:s},{select:"*",order:"created_at.asc"}),Re("self_buyout_items",{user_id:s},{select:"*",order:"created_at.desc"}),Re("users",{id:s},{select:"friendly_id",single:!0})]);w.error||fe.error?v("ÐÑибка загÑÑзки даннÑÑ
"):v(null),d(w.data||[]),c(fe.data||[]),y(pe.data?.friendly_id??null),b(!1)},[s]);a.useEffect(()=>{ht()},[ht]);const qe=a.useMemo(()=>Ri(l,o),[l,o]),it=a.useMemo(()=>{const w=n.trim().toLowerCase();return w?qe.filter(fe=>fe.label.toLowerCase().includes(w)||fe.batch?.display_id?.toLowerCase().includes(w)||fe.items.some(pe=>pe.track_number.toLowerCase().includes(w))):qe},[qe,n]),Ge=it.filter(w=>w.status!=="SHIPPED"),St=it.filter(w=>w.status==="SHIPPED"),Pt=o.some(w=>!wn(w.label)),Ut=a.useMemo(()=>hl(o,Lr),[o]),xt=U?la(o,U.item?U.item.batch_id:U.batchKey):null,zt=l.filter(w=>w.status==="PENDING").length,J=l.filter(w=>w.status==="ARRIVED").length,We=l.filter(w=>w.status==="SHIPPED").length,oe=(w,fe=null)=>{W({batchKey:w,item:fe}),Z(fe?.track_number||""),F(fe?.item_description||""),z([]),K([]),I(fe?.arrival_photo_urls||[]),le("")},Y=()=>{me.forEach(w=>URL.revokeObjectURL(w)),W(null),z([]),K([]),I([]),le("")},Se=te.length+$.length,ve=w=>{const fe=Array.from(w.target.files||[]);if(w.target.value="",!fe.length)return;const pe=D-Se;if(pe<=0)return;const je=fe.slice(0,pe);z(ze=>[...ze,...je]),K(ze=>[...ze,...je.map(mt=>URL.createObjectURL(mt))])},T=w=>{I(fe=>fe.filter(pe=>pe!==w))},ke=w=>{URL.revokeObjectURL(me[w]),z(fe=>fe.filter((pe,je)=>je!==w)),K(fe=>fe.filter((pe,je)=>je!==w))},be=async w=>{if(!s)return null;const fe={id:crypto.randomUUID(),user_id:s,label:w,status:"OPEN",display_id:p?await qa(s,p):null,delivery_data:null,note:null,created_at:new Date().toISOString()},{error:pe}=await st("self_buyout_batches",fe);return pe?null:fe},Ae=async w=>{const fe=la(o,w);if(fe.action==="USE")return{batch:fe.batch,created:!1};const pe=await be(fe.label);return pe?{batch:pe,created:!0}:null},E=async()=>
69{if(!U||!s)return;const w=dc(re);if(!w){le("ÐведиÑе ÑÑек-номеÑ");return}Ne(!0),le("");try{let fe=te;if($.length>0){$e(!0);try{const pe=await Promise.all($.map(async je=>{const ze=(je.name.split(".").pop()||"jpg").toLowerCase(),mt=`selfbuyout/${s}/${Date.now()}_${Math.random().toString(36).slice(2)}.${ze}`,{publicUrl:Tt}=await tr("client-attachments",mt,je);return Tt}));fe=[...te,...pe]}catch(pe){le(`Ðе ÑдалоÑÑ Ð·Ð°Ð³ÑÑзиÑÑ ÑоÑо: ${pe?.message||"оÑибка ÑеÑи"}`);return}finally{$e(!1)}}if(U.item){const{error:pe}=await Je("self_buyout_items",{id:U.item.id},{track_number:w,item_description:O.trim()||null,arrival_photo_urls:fe});if(pe){le(pi(pe));return}}else{const pe=await Ae(U.batchKey);if(!pe){le("Ðе ÑдалоÑÑ ÑоздаÑÑ Ð¿Ð»Ð°ÑÐºÑ Ð´Ð»Ñ ÑÑека");return}const{error:je}=await st("self_buyout_items",{user_id:s,batch_id:pe.batch.id,track_number:w,item_description:O.trim()||null,arrival_photo_urls:fe,status:"PENDING",created_at:new Date().toISOString()});if(je){le(pi(je));return}(dt||pe.created)&>(pe.batch.id)}Y(),ht()}finally{Ne(!1)}},se=async w=>{confirm(`УдалиÑÑ ÑÑек ${w.track_number}?`)&&(await ds("self_buyout_items",{id:w.id}),c(fe=>fe.filter(pe=>pe.id!==w.id)))},ee=async(w,fe)=>{Oe(null);const pe=await Ae(fe);if(!pe){alert("Ðе ÑдалоÑÑ Ð¿ÐµÑенеÑÑи ÑÑек");return}const{error:je}=await Je("self_buyout_items",{id:w.id},{batch_id:pe.batch.id});if(je){alert("Ðе ÑдалоÑÑ Ð¿ÐµÑенеÑÑи ÑÑек");return}ht()},u=a.useMemo(()=>{const w=qe.filter(fe=>!fe.isLegacy).map(fe=>({key:fe.key,label:fe.label,total:fe.counts.total}));return Ut||w.push({key:null,label:Lr,total:0}),w},[qe,Ut]),_=hl(o,xe),P=async()=>{if(!s)return;const w=xe.trim();if(w){ye(!0);try{const fe=await be(w);if(!fe){alert("Ðе ÑдалоÑÑ ÑоздаÑÑ Ð¿Ð»Ð°ÑкÑ");return}k(!1),de(""),await ht(),gt(fe.id),oe(fe.id)}finally{ye(!1)}}},A=async w=>{if(!(!w.batch||!confirm(`УдалиÑÑ Ð¿Ð»Ð°ÑÐºÑ Â«${w.label}»? 70 71ТÑек-номеÑа ÐÐ ÑдалÑÑÑÑ â они пеÑеедÑÑ Ð² «${Lr}».`))){if(w.counts.total>0){const pe=la(o.filter(mt=>mt.id!==w.batch.id),null),je=pe.action==="USE"?pe.batch:await be(pe.label);if(!je){alert("Ðе ÑдалоÑÑ Ð¿ÐµÑенеÑÑи ÑÑеки â плаÑка не Ñдалена");return}const{error:ze}=await Je("self_buyout_items",{batch_id:w.batch.id},{batch_id:je.id});if(ze){alert("Ðе ÑдалоÑÑ Ð¿ÐµÑенеÑÑи ÑÑеки â плаÑка не Ñдалена");return}}await ds("self_buyout_batches",{id:w.batch.id}),dt===w.batch.id&>(null),ht()}};if(j)return e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(rt,{className:"w-8 h-8 text-blue-500 animate-spin"})});if(!i&&o.length===0&&l.length===0)return e.jsxs("div",{className:"max-w-2xl mx-auto px-4 py-8 space-y-6",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-14 h-14 rounded-2xl bg-blue-50 flex items-center justify-center mx-auto mb-3",children:e.jsx(an,{size:26,className:"text-blue-500"})}),e.jsx("h1",{className:"text-xl font-bold text-slate-900",children:"СамовÑкÑп"}),e.jsx("p",{className:"text-sm text-slate-500 mt-1",children:"ÐÑ Ð²ÑкÑпаеÑе ÑÐ¾Ð²Ð°Ñ Ñами и оÑпÑавлÑеÑе его на Ð½Ð°Ñ Ñклад в ÐиÑае. ÐÑ Ð¿Ñинимаем поÑÑлки по ÑÑек-номеÑÑ Ð¸ оÑпÑавлÑем Ð¸Ñ Ð² РоÑÑиÑ."})]}),e.jsxs("div",{className:"grid sm:grid-cols-2 gap-3",children:[e.jsxs("button",{onClick:()=>{x(!0),oe(null)},className:"text-left p-5 rounded-2xl border-2 border-blue-500 bg-blue-50/40 hover:bg-blue-50/70 transition-all",children:[e.jsx(gs,{size:26,className:"text-blue-500 mb-3"}),e.jsx("div",{className:"font-bold text-slate-800",children:"ÐÑоÑмлÑÑ Ð´Ð»Ñ ÑебÑ"}),e.jsx("div",{className:"text-sm text-slate-500 mt-1",children:wa[0].text})]}),e.jsxs("button",{onClick:()=>{x(!0),k(!0)},className:"text-left p-5 rounded-2xl border-2 border-blue-500 bg-blue-50/40 hover:bg-blue-50/70 transition-all",children:[e.jsx(Ra,{size:26,className:"text-blue-500 mb-3"}),e.jsx("div",{className:"font-bold text-slate-800",children:"ÐÑоÑмлÑÑ Ð´Ð»Ñ ÑазнÑÑ Ð»Ñдей"}),e.jsx("div",{className:"text-sm text-slate-500 mt-1",children:wa[1].text})]})]}),e.jsx("div",{className:"flex flex-wrap gap-3",children:xi.map(w=>e.jsx(mi,{step:w},w.title))})]});const M=(w,fe)=>{const pe=Mm[w.status];return e.jsxs("div",{className:"px-3.5 py-3 flex items-start gap-3",children:[e.jsx("div",{className:`mt-0.5 shrink-0 px-2 py-0.5 rounded-full text-[10px] font-bold border ${pe.color}`,children:pe.label}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-mono font-bold text-slate-800 text-sm break-all",children:w.track_number}),w.item_description&&e.jsx("div",{className:"text-xs text-slate-500 mt-0.5",children:w.item_description}),w.recipient_name&&fe.isLegacy&&e.jsxs("div",{className:"text-xs text-slate-400 mt-0.5 flex items-center gap-1",children:[e.jsx(gs,{size:10}),"ÐлÑ: ",w.recipient_name]}),w.staff_note&&e.jsxs("div",{className:"text-xs text-amber-600 mt-1 bg-amber-50 rounded px-2 py-1",children:["ÐамеÑка Ñклада: ",w.staff_note]}),w.arrived_at&&e.jsxs("div",{className:"text-[10px] text-slate-400 mt-1",children:["ÐолÑÑено: ",new Date(w.arrived_at).toLocaleDateString("ru-RU")]})]}),w.arrival_photo_urls?.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1 shrink-0 max-w-[92px]",children:w.arrival_photo_urls.map((je,ze)=>e.jsx("a",{href:je,target:"_blank",rel:"noreferrer",className:"w-10 h-10 rounded-lg overflow-hidden border border-slate-200",title:`ФоÑо оÑпÑÐ°Ð²Ð»ÐµÐ½Ð¸Ñ ${ze+1} из ${w.arrival_photo_urls.length}`,children:e.jsx("img",{src:je,alt:"",className:"w-full h-full object-cover"})},je))}),w.status!=="SHIPPED"&&e.jsxs("div",{className:"flex gap-1 shrink-0",children:[e.jsx("button",{onClick:()=>oe(fe.key,w),className:"p-1.5 text-slate-400 hover:text-blue-600 hover:bg-blue-50 rounded-lg transition-colors",title:"РедакÑиÑоваÑÑ",children:e.jsx(dr,{size:14})}),e.jsx("button",{onClick:()=>Oe(w),className:"p-1.5 text-slate-400 hover:text-blue-600 hover:bg-blue-50 rounded-lg transition-colors",title:"ÐеÑемеÑÑиÑÑ ÑÑек в дÑÑгÑÑ Ð¿Ð»Ð°ÑкÑ",children:e.jsx(Jo,{size:14})}),w.status==="PENDING"&&e.jsx("button",{onClick:()=>se(w),className:"p-1.5 text-slate-400 hover:text-red-600 hover:bg-red-50 rounded-lg transition-colors",title:"УдалиÑÑ",children:e.jsx(is,{size:14})})]})]},w.id)},ie=w=>e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-200 shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"px-4 py-3 border-b border-slate-100 flex items-start justify-between gap-3 bg-slate-50/60",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[w.isLegacy||wn(w.label)?e.jsx(an,{size:15,className:"text-slate-400 shrink-0"}):e.jsx(gs,{size:15,className:"text-slate-400 shrink-0"}),e.jsx("span",{className:"font-bold text-slate-800 truncate",children:w.label}),w.batch?.display_id&&e.jsx("span",{className:"shrink-0 text-[11px] font-mono font-semibold text-blue-600 bg-blue-50 border border-blue-100 px-1.5 py-0.5 rounded",children:w.batch.display_id})]}),e.jsxs("div",{className:"text-xs text-slate-500 mt-0.5",children:["ÐжидаеÑÑÑ ",w.counts.pending," · Ðа Ñкладе ",w.counts.arrived," · ÐÑпÑавлено ",w.counts.shipped]})]}),!w.isLegacy&&w.counts.shipped===0&&e.jsx("button",{onClick:()=>A(w),className:"p-1.5 text-slate-300 hover:text-red-600 hover:bg-red-50 rounded-lg transition-colors shrink-0",title:"УдалиÑÑ Ð¿Ð»Ð°ÑÐºÑ (ÑÑеки оÑÑанÑÑÑÑ)",children:e.jsx(is,{size:14})})]}),w.items.length===0?e.jsx("div",{className:"px-4 py-6 text-center text-sm text-slate-400",children:"Ðока пÑÑÑо â добавÑÑе пеÑвÑй ÑÑек-номеÑ"}):e.jsx("div",{className:"divide-y divide-slate-50",children:w.items.map(fe=>M(fe,w))}),e.jsxs("div",{className:"px-3.5 py-3 border-t border-slate-100 flex flex-wrap gap-2",children:[e.jsxs("button",{onClick:()=>oe(w.key),className:"flex items-center gap-1.5 px-3 py-2 bg-blue-600 hover:bg-blue-700 text-white text-sm font-semibold rounded-lg transition-colors",children:[e.jsx($s,{size:14}),"ТÑек"]}),w.counts.arrived>0&&e.jsxs("button",{onClick:()=>Le(w.key),className:"flex items-center gap-1.5 px-3 py-2 bg-green-600 hover:bg-green-700 text-white text-sm font-bold rounded-lg transition-colors",children:[e.jsx(Lt,{size:14}),"ÐÑоÑмиÑÑ Ð´Ð¾ÑÑавкÑ"]})]})]},w.key),ge=w=>e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-200 shadow-sm overflow-hidden",children:[e.jsxs("button",{onClick:()=>gt(w.key),className:"w-full flex items-center gap-3 px-4 py-3.5 hover:bg-slate-50 transition-colors text-left",children:[w.isLegacy||wn(w.label)?e.jsx(an,{size:16,className:"text-slate-400 shrink-0"}):e.jsx(gs,{size:16,className:"text-slate-400 shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:"font-bold text-slate-800 text-sm truncate min-w-0",children:w.label}),w.batch?.display_id&&e.jsx("span",{className:"text-[11px] font-mono font-semibold text-blue-600 bg-blue-50 border border-blue-100 px-1.5 py-0.5 rounded shrink-0",children:w.batch.display_id})]}),e.jsxs("div",{className:"flex items-center gap-1.5 mt-1 flex-wrap",children:[w.counts.pending>0&&e.jsxs("span",{className:"px-1.5 py-0.5 bg-amber-100 text-amber-700 text-[10px] font-bold rounded-full",children:["ÐжидаеÑÑÑ ",w.counts.pending]}),w.counts.arrived>0&&e.jsxs("span",{className:"px-1.5 py-0.5 bg-green-100 text-green-700 text-[10px] font-bold rounded-full",children:["Ðа Ñкладе ",w.counts.arrived]}),w.counts.shipped>0&&e.jsxs("span",{className:"px-1.5 py-0.5 bg-blue-100 text-blue-700 text-[10px] font-bold rounded-full",children:["ÐÑпÑавлено ",w.counts.shipped]}),w.counts.total===0&&e.jsx("span",{className:"text-xs text-slate-400",children:"Ðока пÑÑÑо"})]})]}),e.jsx(Sr,{size:16,className:"text-slate-300 shrink-0"})]}),e.jsxs("div",{className:"px-4 pb-3.5 -mt-0.5 flex flex-wrap gap-2",children:[e.jsxs("button",{onClick:()=>oe(w.key),className:"flex items-center gap-1 px-2.5 py-1.5 bg-blue-50 hover:bg-blue-100 text-blue-700 text-xs font-bold rounded-lg transition-colors",children:[e.jsx($s,{size:12}),"ТÑек"]}),w.counts.arrived>0&&e.jsxs("button",{onClick:()=>Le(w.key),className:"flex items-center gap-1 px-2.5 py-1.5 bg-green-50 hover:bg-green-100 text-green-700 text-xs font-bold rounded-lg transition-colors",children:[e.jsx(Lt,{size:12}),"ÐоÑÑавка"]})]})]},w.key);return e.jsxs("div",{className:"max-w-2xl mx-auto px-4 py-6 space-y-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-xl font-bold text-slate-900 flex items-center gap-2",children:["СамовÑкÑп",e.jsx("button",{onClick:()=>S(!0),title:"Ðак ÑÑо ÑÑÑÑоено",className:"w-6 h-6 rounded-full bg-orange-500 hover:bg-orange-600 text-white flex items-center justify-center text-[13px] font-bold leading-none transition-colors shadow-sm",children:"?"})]}),e.jsx("p",{className:"text-sm text-slate-500 mt-0.5",children:"Ðак ÑолÑко ÑвидиÑе по ÑÐ²Ð¾ÐµÐ¼Ñ ÑÑекингÑ, ÑÑо поÑÑлка на Ñкладе â добавÑÑе Ð½Ð¾Ð¼ÐµÑ ÑÑда"}),e.jsxs("p",{className:"text-xs text-slate-400 mt-1 flex items-center gap-1",children:[e.jsx(Fn,{size:12,className:"shrink-0"}),"ÐинимÑм 10 кг на оÑпÑÐ°Ð²ÐºÑ â еÑли менÑÑе, вÑгоднее обÑединиÑÑ Ñ Ð´ÑÑгой поÑÑлкой"]})]}),e.jsxs("button",{onClick:ht,className:"shrink-0 flex items-center gap-1.5 px-3 py-2 text-slate-500 hover:text-slate-700 text-sm transition-colors",title:"ÐбновиÑÑ ÑÑаÑÑÑÑ",children:[e.jsx(vr,{size:14}),"ÐбновиÑÑ"]})]}),h&&e.jsxs("div",{className:"flex items-center gap-2 text-red-600 text-sm bg-red-50 border border-red-200 rounded-xl px-3 py-2",children:[e.jsx(Fs,{size:14}),h]}),e.jsxs("div",{className:"bg-blue-50/60 border border-blue-100 rounded-2xl overflow-hidden",children:[e.jsxs("button",{onClick:()=>N(w=>!w),className:"w-full flex items-center justify-between px-4 py-3 text-left",children:[e.jsxs("span",{className:"font-semibold text-slate-800 text-sm flex items-center gap-2",children:[e.jsx(Ci,{size:16,className:"text-blue-500"}),"Ðак ÑÑо ÑабоÑÐ°ÐµÑ â 3 Ñага"]}),m?e.jsx(qr,{size:16,className:"text-slate-400"}):e.jsx(er,{size:16,className:"text-slate-400"})]}),m&&e.jsx("div",{className:"px-4 pb-4 flex flex-wrap gap-3",children:xi.map(w=>e.jsx(mi,{step:w},w.title))})]}),dt&&qe.find(w=>w.key===dt)?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("button",{onClick:()=>gt(null),className:"flex items-center gap-1.5 text-sm font-semibold text-slate-500 hover:text-slate-700 transition-colors",children:[e.jsx(Ba,{size:15}),"Ðо вÑем плаÑкам"]}),ie(qe.find(w=>w.key===dt))]}):e.jsxs(e.Fragment,{children:[l.length>0&&e.jsx("div",{className:"grid grid-cols-3 gap-3",children:[{label:"ÐжидаеÑÑÑ",count:zt,color:"bg-
71amber-50 border-amber-200 text-amber-700"},{label:"Ðа Ñкладе",count:J,color:"bg-green-50 border-green-200 text-green-700"},{label:"ÐÑпÑавлено",count:We,color:"bg-blue-50 border-blue-200 text-blue-700"}].map(w=>e.jsxs("div",{className:`rounded-xl border px-3 py-3 text-center ${w.color}`,children:[e.jsx("div",{className:"text-2xl font-bold",children:w.count}),e.jsx("div",{className:"text-xs font-medium mt-0.5",children:w.label})]},w.label))}),(o.length>1||l.length>3)&&e.jsxs("div",{className:"relative",children:[e.jsx(Qn,{size:15,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-400"}),e.jsx("input",{value:n,onChange:w=>r(w.target.value),placeholder:"ÐоиÑк по ÑÑÐµÐºÑ Ð¸Ð»Ð¸ имени полÑÑаÑелÑ...",className:"w-full pl-9 pr-3 py-2.5 border border-slate-200 rounded-xl text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),n.trim()&&it.length===0&&e.jsx("div",{className:"text-center text-sm text-slate-400 py-6",children:"ÐиÑего не наÑлоÑÑ"}),e.jsx("div",{className:"space-y-2.5",children:Ge.map(w=>ge(w))}),!Ut&&e.jsxs("button",{onClick:()=>oe(null),className:"w-full flex items-center justify-center gap-2 py-3 border-2 border-dashed border-blue-400 hover:border-blue-500 hover:bg-blue-50/40 text-blue-600 text-sm font-semibold rounded-xl transition-colors",children:[e.jsx($s,{size:15}),"ТÑек Ð´Ð»Ñ ÑебÑ"]}),e.jsxs("button",{onClick:()=>{de(""),k(!0)},className:"w-full flex items-center justify-center gap-2 py-3 border-2 border-dashed border-blue-400 hover:border-blue-500 hover:bg-blue-50/40 text-blue-600 text-sm font-semibold rounded-xl transition-colors",children:[e.jsx(Ra,{size:15}),"+ ÐлаÑка на дÑÑгого Ñеловека"]}),!Pt&&e.jsx("div",{className:"text-xs text-slate-400 text-center -mt-2",children:"ÐаказÑваеÑе Ð´Ð»Ñ Ð½ÐµÑколÑкиÑ
лÑдей? ÐаведиÑе оÑделÑнÑÑ Ð¿Ð»Ð°ÑÐºÑ Ð½Ð° каждого â иÑ
можно оÑпÑавлÑÑÑ Ð¿Ð¾ ÑазнÑм адÑеÑам."}),St.length>0&&e.jsxs("div",{className:"pt-2",children:[e.jsxs("button",{onClick:()=>L(w=>!w),className:"w-full flex items-center justify-between px-1 py-2 text-sm font-semibold text-slate-500",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Ko,{size:15}),"ÐÑпÑавленнÑе (",St.length,")"]}),C?e.jsx(qr,{size:16}):e.jsx(er,{size:16})]}),(C||!!n.trim()&&Ge.length===0)&&e.jsx("div",{className:"space-y-2.5 mt-2 opacity-80",children:St.map(w=>ge(w))})]})]}),U&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-end sm:items-center justify-center bg-black/40 backdrop-blur-sm p-4",children:e.jsxs("div",{className:"bg-white rounded-2xl w-full max-w-md max-h-[90vh] overflow-y-auto shadow-2xl",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-slate-100",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-bold text-slate-900",children:U.item?"РедакÑиÑоваÑÑ ÑÑек":"ÐовÑй ÑÑек-номеÑ"}),e.jsxs("p",{className:"text-xs text-slate-500 mt-0.5",children:["ÐлаÑка: ",xt?.action==="USE"?xt.batch.label:xt?.label||Lr,xt?.action==="USE"&&xt.batch.display_id&&` · ${xt.batch.display_id}`]})]}),e.jsx("button",{onClick:Y,className:"p-2 rounded-full hover:bg-slate-100 text-slate-400",children:e.jsx(bt,{size:18})})]}),e.jsxs("div",{className:"px-5 py-4 space-y-3",children:[!U.item&&xt?.action==="CREATE"&&e.jsx("div",{className:"rounded-xl border border-blue-100 bg-blue-50/70 px-3 py-2.5 text-xs text-slate-600",children:xt.after?e.jsxs(e.Fragment,{children:["ÐлаÑка «",xt.after.label,"» ",xt.after.display_id||""," Ñже оÑпÑавлена â допиÑаÑÑ Ð² Ð½ÐµÑ Ð½ÐµÐ»ÑзÑ. ÐÑÐ¾Ñ ÑÑек наÑнÑÑ Ð½Ð¾Ð²ÑÑ Ð¿Ð»Ð°ÑÐºÑ Â«",xt.label,"» Ñо ÑледÑÑÑим номеÑом."]}):e.jsxs(e.Fragment,{children:["ÐаведÑм плаÑÐºÑ Â«",xt.label,"» â она ÑÑÐ°Ð·Ñ Ð¿Ð¾Ð»ÑÑÐ¸Ñ Ñвой Ð½Ð¾Ð¼ÐµÑ Ð·Ð°ÐºÐ°Ð·Ð°."]})}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-slate-600 mb-1",children:"ТÑек-Ð½Ð¾Ð¼ÐµÑ *"}),e.jsx("input",{value:re,onChange:w=>Z(w.target.value.toUpperCase()),placeholder:"ÐапÑимеÑ: LP123456789CN",autoFocus:!0,className:"w-full px-3 py-2.5 border border-slate-200 rounded-lg text-sm font-mono focus:outline-none focus:ring-2 focus:ring-blue-500 uppercase"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-medium text-slate-600 mb-1",children:["ÐпиÑание ",e.jsx("span",{className:"text-slate-400 font-normal",children:"(необÑзаÑелÑно)"})]}),e.jsx("input",{value:O,onChange:w=>F(w.target.value),placeholder:"ЧÑо заказали: кÑоÑÑовки, плаÑÑе...",className:"w-full px-3 py-2.5 border border-slate-200 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-medium text-slate-600 mb-1",children:["ФоÑо ",e.jsxs("span",{className:"text-slate-400 font-normal",children:["(необÑзаÑелÑно, до ",D,")"]})]}),(te.length>0||me.length>0)&&e.jsxs("div",{className:"flex flex-wrap gap-2 mb-2",children:[te.map(w=>e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:w,alt:"",className:"w-16 h-16 rounded-lg object-cover border border-slate-200"}),e.jsx("button",{onClick:()=>T(w),className:"absolute -top-1.5 -right-1.5 w-5 h-5 rounded-full bg-slate-700 text-white flex items-center justify-center hover:bg-red-600 transition-colors",title:"УбÑаÑÑ ÑоÑо",children:e.jsx(bt,{size:12})})]},w)),me.map((w,fe)=>e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:w,alt:"",className:"w-16 h-16 rounded-lg object-cover border border-slate-200"}),e.jsx("button",{onClick:()=>
71ke(fe),className:"absolute -top-1.5 -right-1.5 w-5 h-5 rounded-full bg-slate-700 text-white flex items-center justify-center hover:bg-red-600 transition-colors",title:"УбÑаÑÑ ÑоÑо",children:e.jsx(bt,{size:12})})]},w))]}),Se<D&&e.jsxs("label",{className:"flex items-center gap-2 px-3 py-2.5 border border-dashed border-slate-300 rounded-lg text-sm text-slate-500 cursor-pointer hover:border-blue-400 hover:text-blue-600 transition-colors",children:[e.jsx(Ei,{size:16}),"ÐÑиложиÑÑ ÑоÑо",e.jsx("input",{type:"file",accept:"image/*",multiple:!0,onChange:ve,className:"hidden"})]}),e.jsxs("div",{className:"text-[11px] text-slate-400 mt-1 flex items-start gap-1",children:[e.jsx(Yr,{size:11,className:"mt-0.5 shrink-0"}),"СкÑинÑÐ¾Ñ Ð¸Ð· ÑÑекинга, ÑÑо поÑÑлка доеÑ
ала до наÑего Ñклада â ÑÐºÐ»Ð°Ð´Ñ Ð¿ÑоÑе ÐµÑ Ð½Ð°Ð¹Ñи. ÐÑÐ¾Ð´Ð°Ð²ÐµÑ Ð¼Ð¾Ð³ оÑпÑавиÑÑ Ð½ÐµÑколÑко ÑоваÑов одним ÑÑек-номеÑом â можно пÑиложиÑÑ ÑоÑо на каждÑй. СÑаÑÑÑ ÑÑека ÑÑо не менÑеÑ: пÑиÑÐ¼ÐºÑ Ð²ÑÑ Ñавно подÑвеÑÐ¶Ð´Ð°ÐµÑ Ñклад."]})]}),H&&e.jsxs("div",{className:"flex items-start gap-2 text-red-600 text-sm",children:[e.jsx(Fs,{size:14,className:"mt-0.5 shrink-0"}),H]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsxs("button",{onClick:E,disabled:B,className:"flex items-center gap-2 px-4 py-2.5 bg-blue-600 hover:bg-blue-700 disabled:opacity-60 text-white text-sm font-semibold rounded-lg transition-colors",children:[B?e.jsx(rt,{size:14,className:"animate-spin"}):e.jsx(wi,{size:14}),Ue?"ÐагÑÑжаем ÑоÑо...":U.item?"СоÑ
ÑаниÑÑ":"ÐобавиÑÑ"]}),e.jsx("button",{onClick:Y,className:"px-4 py-2.5 text-slate-600 hover:text-slate-800 text-sm font-medium",children:"ÐÑмена"})]})]})]})}),Qe&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-end sm:items-center justify-center bg-black/40 backdrop-blur-sm p-4",children:e.jsxs("div",{className:"bg-white rounded-2xl w-full max-w-md
71shadow-2xl",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-slate-100",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-bold text-slate-900",children:"ÐÐ¾Ð²Ð°Ñ Ð¿Ð»Ð°Ñка"}),e.jsx("p",{className:"text-xs text-slate-500 mt-0.5",children:"ÐÑделÑÐ½Ð°Ñ Ð¿Ð¾ÑÑлка на Ñвоего полÑÑаÑелÑ"})]}),e.jsx("button",{onClick:()=>{k(!1),de("")},className:"p-2 rounded-full hover:bg-slate-100 text-slate-400",children:e.jsx(bt,{size:18})})]}),e.jsxs("div",{className:"px-5 py-4 space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-slate-600 mb-1",children:"Ðазвание *"}),e.jsx("input",{value:xe,onChange:w=>de(w.target.value),placeholder:"ÐапÑимеÑ: ÐолÑ",autoFocus:!0,className:"w-full px-3 py-2.5 border border-slate-200 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),_&&e.jsxs("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-3 py-2.5 text-sm text-amber-800",children:[e.jsxs("div",{children:["У Ð²Ð°Ñ Ñже еÑÑÑ Ð¿Ð»Ð°Ñка «",_.label,"»",_.display_id?` ${_.display_id}`:""," â добавиÑÑ ÑÑда?"]}),e.jsxs("button",{onClick:()=>{k(!1),de(""),gt(_.id),oe(_.id)},className:"mt-2 px-3 py-1.5 bg-amber-500 hover:bg-amber-600 text-white text-xs font-bold rounded-lg transition-colors",children:["ÐÑкÑÑÑÑ Â«",_.label,"»"]})]}),e.jsxs("div",{className:"flex items-start gap-2 text-xs text-slate-500 bg-slate-50 rounded-xl px-3 py-2.5",children:[e.jsx(Fn,{size:13,className:"mt-0.5 shrink-0"}),"ÐаждÑÑ Ð¿Ð»Ð°ÑÐºÑ Ð¼Ð¾Ð¶Ð½Ð¾ оÑпÑавиÑÑ Ð¾ÑделÑно на Ñвой адÑеÑ. ÐинимÑм 10 кг на каждÑÑ Ð¾ÑпÑÐ°Ð²ÐºÑ â еÑли веÑа не Ñ
ваÑаеÑ, вÑгоднее оÑпÑавиÑÑ Ð½ÐµÑколÑко плаÑек вмеÑÑе."]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsxs("button",{onClick:P,disabled:V||!xe.trim(),className:"flex items-center gap-2 px-4 py-2.5 bg-blue-600 hover:bg-blue-700 disabled:opacity-60 text-white text-sm font-semibold rounded-lg transition-colors",children:[V?e.jsx(rt,{size:14,className:"animate-spin"}):e.jsx($s,{size:14}),_?"ÐÑÑ Ñавно ÑоздаÑÑ Ð½Ð¾Ð²ÑÑ":"СоздаÑÑ Ð¿Ð»Ð°ÑкÑ"]}),e.jsx("button",{onClick:()=>{k(!1),de("")},className:"px-4 py-2.5 text-slate-600 hover:text-slate-800 text-sm font-medium",children:"ÐÑмена"})]})]})]})}),Ie&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-end sm:items-center justify-center bg-black/40 backdrop-blur-sm p-4",children:e.jsxs("div",{className:"bg-white rounded-2xl w-full max-w-sm shadow-2xl overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-slate-100",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"font-bold text-slate-900",children:"ÐеÑемеÑÑиÑÑ ÑÑек"}),e.jsx("p",{className:"text-xs text-slate-500 mt-0.5 font-mono break-all",children:Ie.track_number})]}),e.jsx("button",{onClick:()=>Oe(null),className:"p-2 rounded-full hover:bg-slate-100 text-slate-400",children:e.jsx(bt,{size:18})})]}),e.jsx("div",{className:"p-3 space-y-1.5 max-h-[50vh] overflow-y-auto",children:u.filter(w=>w.key===null||w.key!==Ie.batch_id).map(w=>e.jsxs("button",{onClick:()=>ee(Ie,w.key),className:"w-full flex items-center gap-2 px-3 py-2.5 rounded-xl border border-slate-200 hover:border-blue-400 hover:bg-blue-50/50 text-left transition-all",children:[wn(w.label)?e.jsx(an,{size:14,className:"text-slate-400"}):e.jsx(gs,{size:14,className:"text-slate-400"}),e.jsx("span",{className:"font-medium text-slate-700 text-sm truncate",children:w.label}),e.jsxs("span",{className:"ml-auto text-xs text-slate-400",children:[w.total," ÑÑек."]})]},w.key||"__new_default__"))})]})}),R&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-end sm:items-center justify-center bg-black/40 backdrop-blur-sm p-4",children:e.jsxs("div",{className:"bg-white rounded-2xl w-full max-w-md
71shadow-2xl overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-slate-100",children:[e.jsx("h3",{className:"font-bold text-slate-900",children:"Ðак ÑÑо ÑÑÑÑоено"}),e.jsx("button",{onClick:()=>S(!1),className:"p-2 rounded-full hover:bg-slate-100 text-slate-400",children:e.jsx(bt,{size:18})})]}),e.jsxs("div",{className:"px-5 py-4 space-y-4",children:[wa.map(w=>{const fe=w.icon;return e.jsxs("div",{className:"flex gap-3",children:[e.jsx(fe,{size:20,className:"text-blue-500 shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-slate-800 text-sm",children:w.title}),e.jsx("div",{className:"text-sm text-slate-500 mt-0.5",children:w.text})]})]},w.title)}),e.jsx("div",{className:"text-xs text-slate-400 border-t border-slate-100 pt-3",children:"ÐлаÑÐºÑ Ð½Ð° дÑÑгого Ñеловека можно завеÑÑи в лÑбой Ð¼Ð¾Ð¼ÐµÐ½Ñ â ÑÑо не наÑÑÑойка, а пÑоÑÑо ÑпоÑоб ÑазложиÑÑ ÑÑеки по полÑÑаÑелÑм."})]})]})}),we&&s&&e.jsx(Lm,{userId:s,friendlyId:p,items:l,batches:o,initialKey:we,onClose:()=>Le(null),onCreated:(w,fe,pe,je)=>{Le(null),jt({id:w,displayId:fe,itemCount:pe,clientLabel:je}),ht()}}),_t&&e.jsx(Ua,{orderId:_t.id,onClose:()=>jt(null),onSave:async()=>{const{id:w,displayId:fe,itemCount:pe,clientLabel:je}=_t;jt(null),await st("notifications",{user_id:null,type:"ORDER",title:`СамовÑкÑп â ${fe}`,text:`ÐÐ»Ð¸ÐµÐ½Ñ Ð¾ÑоÑмил доÑÑÐ°Ð²ÐºÑ ÑамовÑкÑпа (${pe} ÑÑек-ном.${je?`, ${je}`:""})`,is_read:!1,link:w,created_at:new Date().toISOString()}),alert(`ÐаÑвка на доÑÑÐ°Ð²ÐºÑ ${fe} Ñоздана! ÐдминиÑÑÑаÑÐ¾Ñ ÑвÑжеÑÑÑ Ñ Ð²Ð°Ð¼Ð¸.`),t?.(w)}})]})}function pi(t){return t.includes("23505")||t.toLowerCase().includes("duplicate key")?"Такой ÑÑек-Ð½Ð¾Ð¼ÐµÑ Ñ Ð²Ð°Ñ Ñже еÑÑÑ â он еÑÑ Ð½Ðµ оÑпÑавлен.":"ÐÑибка ÑоÑ
ÑанениÑ"}const fi={PENDING:{label:"Ðа модеÑаÑии",className:"bg-amber-50 text-amber-700 border-amber-200"},APPROVED:{label:"ÐпÑбликовано",className:"bg-green-50 text-green-700 border-green-200"},REJECTED:{label:"ÐÑклонено",className:"bg-red-50 text-red-600 border-red-200"}},Um=t=>`/voprosy/${t}`;function $m(){const[t,s]=a.useState([]),[n,r]=a.useState([]),[l,c]=a.useState([]),[o,d]=a.useState({}),[p,y]=a.useState(!0);a.useEffect(()=>{(async()=>{const h=yt();if(!h){y(!1);return}const[v,i,x]=await Promise.all([Re("qa_topics",{user_id:h},{select:"id,slug,title,status,rejection_reason,answers_count,created_at",order:"created_at.desc"}),Re("qa_answers",{user_id:h},{select:"id,topic_id,body,status,rejection_reason,created_at",order:"created_at.desc"}),Re("notifications",{user_id:h},{select:"id,type,title,text,link,is_read,date",order:"date.desc",limit:20})]);s(v.data||[]),r(i.data||[]);const m=(x.data||[]).filter(S=>S.type?.startsWith("QA_"));c(m);const N=i.data||[],R=Array.from(new Set(N.map(S=>S.topic_id)));if(R.length>0){const{data:S}=await Re("qa_topics",{},{select:"id,title,slug",inFilters:{id:R}}),C={};(S||[]).forEach(L=>{C[L.id]=L.title}),d(C)}y(!1)})()},[]);const j=async b=>{b.is_read||(c(h=>h.map(v=>v.id===b.id?{...v,is_read:!0}:v)),await Je("notifications",{id:b.id},{is_read:!0}))};return p?e.jsx("div",{className:"flex justify-center py-16",children:e.jsx(rt,{className:"animate-spin text-slate-400",size:24})}):e.jsxs("div",{className:"space-y-6 pb-8",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-lg font-black text-slate-900 flex items-center gap-2",children:[e.jsx(Ea,{size:20})," Ðои вопÑоÑÑ"]}),e.jsxs("p",{className:"text-sm text-slate-500 mt-1",children:["ÐадаÑÑ Ð½Ð¾Ð²Ñй вопÑÐ¾Ñ Ð¸Ð»Ð¸ оÑвеÑиÑÑ Ð¼Ð¾Ð¶Ð½Ð¾ на"," ",e.jsxs("a",{href:"/voprosy",className:"text-blue-600 hover:underline inline-flex items-center gap-1",children:["goodschina.ru/voprosy ",e.jsx(Zn,{size:12})]})]})]}),l.length>0&&e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-200 shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"px-4 py-3 border-b border-slate-100 flex items-center gap-2 font-bold text-sm text-slate-700",children:[e.jsx(_s,{size:15})," УведомлениÑ"]}),e.jsx("div",{className:"divide-y divide-slate-100",children:l.map(b=>e.jsxs("div",{onClick:()=>j(b),className:`px-4 py-3 text-sm cursor-pointer hover:bg-slate-50 transition-colors ${b.is_read?"":"bg-blue-50/50"}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[!b.is_read&&e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-blue-500 shrink-0"}),e.jsx("span",{className:"font-bold text-slate-800",children:b.title})]}),e.jsx("p",{className:"text-slate-500 mt-0.5",children:b.text}),e.jsx("p",{className:"text-[11px] text-slate-400 mt-1",children:new Date(b.date).toLocaleStr
71ing("ru-RU")})]},b.id))})]}),e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-200 shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"px-4 py-3 border-b border-slate-100 flex items-center gap-2 font-bold text-sm text-slate-700",children:[e.jsx(Ea,{size:15})," Ðои ÑемÑ"]}),t.length===0?e.jsx("div",{className:"px-4 py-8 text-center text-sm text-slate-400",children:"ÐÑ ÐµÑÑ Ð½Ðµ задавали вопÑоÑов"}):e.jsx("div",{className:"divide-y divide-slate-100",children:t.map(b=>{const h=fi[b.status];return e.jsxs("div",{className:"px-4 py-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[b.status==="APPROVED"?e.jsx("a",{href:Um(b.slug),className:"font-bold text-slate-800 hover:text-blue-600 hover:underline",children:b.title}):e.jsx("span",{className:"font-bold text-slate-800",children:b.title}),e.jsx("span",{className:`text-[10px] font-bold px-2 py-0.5 rounded-full border shrink-0 ${h.className}`,children:h.label})]}),b.status==="REJECTED"&&b.rejection_reason&&e.jsxs("p",{className:"text-xs text-red-500 mt-1",children:["ÐÑиÑина: ",b.rejection_reason]}),b.status==="APPROVED"&&e.jsxs("p",{className:"text-xs text-slate-400 mt-1",children:[b.answers_count," оÑвеÑов"]})]},b.id)})})]}),e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-200 shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"px-4 py-3 border-b border-slate-100 flex items-center gap-2 font-bold text-sm text-slate-700",children:[e.jsx(Ur,{size:15})," Ðои оÑвеÑÑ"]}),n.length===0?e.jsx("div",{className:"px-4 py-8 text-center text-sm text-slate-400",children:"ÐÑ ÐµÑÑ Ð½Ðµ оÑвеÑали на вопÑоÑÑ"}):e.jsx("div",{className:"divide-y divide-slate-100",children:n.map(b=>{const h=fi[b.status];return e.jsxs("div",{className:"px-4 py-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("span",{className:"text-xs text-slate-400",children:["Ð Ñеме: ",o[b.topic_id]||"..."]}),e.jsx("span",{className:`text-[10px] font-bold px-2 py-0.5 rounded-full border shrink-0 ${h.className}`,children:h.label})]}),e.jsx("p",{className:"text-sm text-slate-700 mt-1 line-clamp-2",children:b.body}),b.status==="REJECTED"&&b.rejection_reason&&e.jsxs("p",{className:"text-xs text-red-500 mt-1",children:["ÐÑиÑина: ",b.rejection_reason]})]},b.id)})})]})]})}function Jm(){const{t}=qt(),[s,n]=a.useState(!1),[r,l]=a.useState(!0),[c,o]=a.useState(()=>{const G=["HOME","ORDERS","IMPORT","CALCULATOR","MESSAGES","PROFILE","PAYMENTS","SUPPORT","SELF_BUYOUT","MY_QUESTIONS"],q={home:"HOME",orders:"ORDERS",import:"IMPORT",calculator:"CALCULATOR",messages:"MESSAGES",profile:"PROFILE",payments:"PAYMENTS",support:"SUPPORT",self_buyout:"SELF_BUYOUT","my-questions":"MY_QUESTIONS"},he=yo[il(window.location.pathname)];if(he)return he;const _e=new URLSearchParams(window.location.search).get("tab");if(_e&&q[_e.toLowerCase()])return q[_e.toLowerCase()];const Xe=localStorage.getItem("tradehub_user_view");return Xe&&G.includes(Xe)?Xe:"HOME"}
71),[d,p]=a.useState(!1),[y]=a.useState(()=>il(window.location.pathname)==="/import"||new URLSearchParams(window.location.search).get("tab")==="import"),[j]=a.useState(()=>new URLSearchParams(window.location.search).get("data")),[b,h]=a.useState(null),[v,i]=a.useState(!1),[x,m]=a.useState(null),[N,R]=a.useState(!1),[S,C]=a.useState(0),[L,U]=a.useState(0),[W,re]=a.useState(null),[Z,O]=a.useState(null),F=a.useRef(null),[D,$]=a.useState(null),[z,me]=a.useState({collecting:0,shipping:0,received:0,total:0,photoWaiting:0}),[K,te]=a.useState(null),[I,B]=a.useState(()=>localStorage.getItem("cookie_consent")===null),Ne=a.useRef(new Date().toISOString()),[Ue,$e]=a.useState(null),[H,le]=a.useState(""),[Qe,k]=a.useState(!1),xe=!!Ue&&Ue>Ne.current,[de,V]=a.useState(()=>{try{const G=localStorage.getItem("tradehub_currencies");if(G){const he=JSON.parse(G).find(_e=>_e.code==="CNY");if(he)return Number(he.rate)||13.5}}catch{}return 13.5}),[ye,Ie]=a.useState(()=>{try{const G=localStorage.getItem("tradehub_currencies");if(G){const he=JSON.parse(G).find(_e=>_e.code==="USD");if(he)return Number(he.rate)||92}}catch{}return 92}),Oe=a.useRef(!1),we=a.useRef(!1),[Le,_t]=a.useState(!1),[jt,dt]=a.useState(()=>ol()),gt=a.useRef(null);a.useEffect(()=>jo(()=>{dt(ol())}),[]),a.useEffect(()=>{Le&>.current&&(gt.current.scrollTop=0)},[jt,Le]),a.useEffect(()=>{F.current=Z},[Z]);const ht=a.useRef(null),qe=a.useRef(null),it=a.useRef(null),Ge=a.useRef(-1),St=a.useRef(-1);a.useEffect(()=>{localStorage.setItem("tradehub_user_view",c),en(`ð Ðкладка: ${c}`,"info");const G=wr(No[c]||"/"),q=new URLSearchParams(window.location.search);q.delete("tab");const he=q.toString(),_e=G+(he?`?${he}`:"");window.location.pathname+window.location.search!==_e&&window.history.replaceState({},"",_e)},[c]),a.useEffect(()=>{const G=q=>o(q.detail);return window.addEventListener("tradehub:navigate",G),()=>window.removeEventListener("tradehub:navigate",G)},[]);const Pt=a.useRef(!1);a.useEffect(()=>{const G=Object.keys(localStorage).find(_e=>_e.startsWith("sb-")&&_e.endsWith("-auth-token"));if(!G)return;let q,he;return Z||(q=setTimeout(()=>{if(Z)return;const Xe=JSON.parse(localStorage.getItem(G)||"{}").user?.id;Xe&&M(Xe)},5e3)),()=>{clearTimeout(q),clearTimeout(he)}},[Z]);const[Ut,xt]=a.useState(0),zt=a.useRef("GOODS CHINA"),[J,We]=a.useState(0),[oe,Y]=a.useState(0);a.useEffect(()=>{const G=Ut+J;if(document.title=G>0?`(${G}) ${zt.current}`:zt.current,"setAppBadge"in navigator)try{G>0?navigator.setAppBadge(G):navigator.clearAppBadge()}catch{}},[Ut,J]);const[Se,ve]=a.useState(null),T=G=>G.map(q=>{const he=q.specs||q.sku_name||q.sku||"";return{id:q.id||Math.random().toString(36).substr(2,9),price:Number(q.priceCNY||q.price||0),quantity:Number(q.quantity||1),name:q.title||q.name||q.desc||"Ð¢Ð¾Ð²Ð°Ñ Ð±ÐµÐ· названиÑ",image:q.image||q.img||"https://via.placeholder.com/200",specs:he,params:he,url:q.shopUrl||q.url||q.link||q.detailUrl||q.itemUrl||"",chinaDelivery:Number(q.deliveryFee||q.delivery||q.express||q.freight||0),shopName:q.shopName||q.shop||q.seller||q.nick||q.shop_name||""}}),ke=G=>{const q=(G.items||[]).map(({id:_e,...Xe})=>Xe),he=T(q);localStorage.setItem("import_cart_draft",JSON.stringify(he)),o("IMPORT")},be=()=>y||!!j,Ae=()=>{const G=localStorage.getItem("orderease_pending_cart");if(G)try{const q=JSON.parse(G);if(Array.isArray(q)&&q.length>0){const he=T(q);return localStorage.setItem("import_cart_draft",JSON.stringify(he)),localStorage.removeItem("orderease_pending_cart"),o("IMPORT"),!0}}catch{}if(j)try{const q=decodeURIComponent(escape(atob(j))),he=JSON.parse(q);if(Array.isArray(he)&&he.length>0){const _e=T(he);return localStorage.setItem("import_cart_draft",JSON.stringify(_e)),o("IMPORT"),!0}}catch{}return!1};a.useEffect(()=>{if(!be())return;let G=!1;const q=()=>{G||Ae()&&(G=!0,clearInterval(he),clearTimeout(_e))};window.addEventListener("orderease_cart_ready",q);const he=setInterval(q,150),_e=setTimeout(()=>{clearInterval(he)},8e3);return q(),()=>{window.removeEventListener("orderease_cart_ready",q),clearInterval(he),clearTimeout(_e)}},[]),a.useEffect(()=>{Ts("UserEntry: ÐºÐ¾Ð¼Ð¿Ð¾Ð½ÐµÐ½Ñ ÑмонÑиÑован"),ge();const G=At.channel("app_settings_rates_global").on("postgres_changes",{event:"UPDATE",schema:"public",table:"app_settings"},_e=>{en("ð± ÐÑÑÑ Ð²Ð°Ð»ÑÑ Ð¾Ð±Ð½Ð¾Ð²Ð»Ñн админиÑÑÑаÑоÑом","info"),Array.isArray(_e.new?.currencies)&&se(_e.new.currencies),_e.new?.commission_settings&&te(_e.new.commission_settings),_e.new?.update_announced_at&&($e(_e.new.update_announced_at),le(_e.new.update_message||""))}).subscribe(_e=>{en(`ð± Realtime кÑÑÑÑ: ${_e}`,"info")}),q=_e=>
71{if(_e.origin!==window.location.origin)return;const Xe=_e.data?.items||_e.data?.payload||_e.data?.data;if(Array.isArray(Xe)&&Xe.length>0){const Ct=T(Xe);localStorage.setItem("import_cart_draft",JSON.stringify(Ct)),Pt.current||o("IMPORT")}};window.addEventListener("message",q),Pt.current=!0,setTimeout(()=>{window.postMessage({type:"ORDEREASE_REQUEST_DATA"},"*"),setTimeout(()=>{Pt.current=!1},3e3)},500);const{data:{subscription:he}}=At.auth.onAuthStateChange((_e,Xe)=>{if(en(`ð Auth: ${_e}`,_e==="SIGNED_OUT"?"warn":"info"),_e==="INITIAL_SESSION"||_e==="TOKEN_REFRESHED")return;const Ct=!!Xe;if(n(Ct),Ct){p(!1);const Gt=it.current===Xe.user.id;if(it.current=Xe.user.id,Gt)return;M(Xe.user.id),ie(Xe.user.id),Notification.permission==="default"&&Notification.requestPermission();const Nt=new Date().toISOString().split("T")[0];vo("visits",{user_id:Xe.user.id,date:Nt,visited_at:new Date().toISOString()},{onConflict:"user_id,date",ignoreDuplicates:!0})}else it.current=null,O(null)});return()=>{he.unsubscribe(),window.removeEventListener("message",q),At.removeChannel(G),ht.current&&(At.removeChannel(ht.current),ht.current=null),qe.current&&(At.removeChannel(qe.current),qe.current=null)}},[]),a.useEffect(()=>{if(!s||!Z?.id)return;const G=Z.id,q=300*1e3;let he=0,_e=!1;const Xe=()=>{_e||document.visibilityState==="visible"&&(he=Date.now(),Je("users",{id:G},{last_seen_at:new Date().toISOString()}).then(({error:Nt})=>{hi(Nt)&&(_e=!0,clearInterval(Ct))}).catch(()=>{}))};Xe();const Ct=setInterval(Xe,q),Gt=()=>{document.visibilityState==="visible"&&(Date.now()-he<q||Xe())};return document.addEventListener("visibilitychange",Gt),()=>{clearInterval(Ct),document.removeEventListener("visibilitychange",Gt)}},[s,Z?.id]),a.useEffect(()=>{if(!s||!Z?.id)return;const G=Z.id;return In({intervalMs:3e5,run:async()=>{const _e=(await Re("messages",{user_id:G,sender:"ADMIN",is_read:!1},{countOnly:!0})).count??0,Xe=Ge.current;if(Xe===-1){Ge.current=_e;return}_e>Xe&&(xt(_e),Pr("message")),Ge.current=_e}})},[s,Z?.id]),a.useEffect(()=>{if(!s||!Z?.id)return;const G=Z.id;return In({intervalMs:3e5,run:async()=>{const _e=(await Re("notifications",{user_id:G,is_read:!1},{countOnly:!0})).count??0,Xe=St.current;if(Xe===-1){St.current=_e;return}_e>Xe&&(We(_e),Pr("default")),St.current=_e}})},[s,Z?.id]),a.useEffect(()=>In({intervalMs:3e5,run:ee}),[]);const E=G=>Number(G.rate)||0,se=G=>{const q=G.find(_e=>_e.code==="CNY"),he=G.find(_e=>_e.code==="USD");q&&V(E(q)),he&&Ie(E(he))},ee=async()=>{try{const{data:G}=await At.from("app_settings").select("commission_settings, currencies, update_announced_at, update_message").limit(1).single();G?.commission_settings&&te(G.commission_settings),Array.isArray(G?.currencies)&&G.currencies.length>0&&se(G.currencies),G?.update_announced_at&&$e(G.update_announced_at),G?.update_message&&le(G.update_message)}catch{}},u=async(G,q)=>{},_=300,P=30,A=async(G,q)=>{const he=Number(q?.welcome_bonus_remaining)||0,_e=q?.welcome_bonus_expires_at||null;if(!_e){if(we.current)return;we.current=!0;const Xe=new Date(Date.now()+P*864e5).toISOString(),Ct=(q?.bonus_balance||0)+_,{error:Gt}=await Je("users",{id:G},{bonus_balance:Ct,welcome_bonus_remaining:_,welcome_bonus_expires_at:Xe});if(Gt)return;const Nt=crypto.randomUUID();await st("transactions",{id:Nt,user_id:G,amount:_,type:"BONUS_PAYMENT",status:"COMPLETED",description:`ÐÑивеÑÑÑвеннÑй бонÑÑ Ð·Ð° ÑегиÑÑÑаÑÐ¸Ñ â ${_} â½ (дейÑÑвÑÐµÑ ${P} дней)`,created_at:new Date().toISOString()}).catch(()=>{}),Qt("ledger_shadow_welcome_bonus_event",{p_tx_id:Nt}).then(({error:Wt})=>{}).catch(Wt=>{}),await st("notifications",{user_id:G,type:"SYSTEM",title:`Ðам наÑиÑлено ${_} бонÑÑов`,text:`ÐаÑим ${_} ⽠бонÑÑами за ÑегиÑÑÑаÑÐ¸Ñ â ими можно оплаÑиÑÑ Ð·Ð°ÐºÐ°Ð· или доÑÑавкÑ. УÑпейÑе поÑÑаÑиÑÑ Ð² ÑеÑение ${P} дней.`,date:new Date().toISOString(),is_read:!1}).catch(()=>{}),O(Wt=>({...Wt,bonus_balance:Ct,welcome_bonus_remaining:_,welcome_bonus_expires_at:Xe}));return}if(he>0&&new Date(_e).getTime()<=Date.now()){const Xe=Math.max(0,(q?.bonus_balance||0)-he),{error:Ct}=await Je("users",{id:G},{bonus_balance:Xe,welcome_bonus_remaining:0});if(Ct)return;const Gt=crypto.randomUUID();await st("transactions",{id:Gt,user_id:G,amount:-he,type:"BONUS_PAYMENT",status:"COMPLETED",description:`СгоÑели неиÑполÑзованнÑе пÑивеÑÑÑвеннÑе бонÑÑÑ â ${he} â½`,created_at:new Date().toISOString()}).catch(()=>{}
71),Qt("ledger_shadow_welcome_bonus_event",{p_tx_id:Gt}).then(({error:Nt})=>{}).catch(Nt=>{}),O(Nt=>({...Nt,bonus_balance:Xe,welcome_bonus_remaining:0}))}},M=async G=>{if(!Oe.current){Oe.current=!0;try{Ts("UserEntry: fetchUserData запÑÑен");const q=performance.now(),[he,_e,Xe,Ct,Gt]=await Promise.all([Re("users",{id:G},{single:!0}),Re("notifications",{user_id:G,is_read:!1},{countOnly:!0}),Re("support_tickets",{user_id:G,client_unread:!0},{countOnly:!0}),Re("messages",{user_id:G,sender:"ADMIN",is_read:!1},{countOnly:!0}),Re("orders",{user_id:G},{select:"status,photo_report_sent,client_confirmed"})]),Nt=he.data,Wt=he.error,os=_e.count,As=Xe.count,cs=Ct.count,Xt=Gt.data||[];if(me({collecting:Xt.filter(Mt=>["PURCHASED","COLLECTING","ASSEMBLED"].includes(Mt.status)).length,shipping:Xt.filter(Mt=>Mt.status==="SHIPPED").length,received:Xt.filter(Mt=>Mt.status==="RECEIVED").length,total:Xt.length,photoWaiting:Xt.filter(Mt=>Mt.photo_report_sent&&!Mt.client_confirmed).length}),Ts(`UserEntry: fetchUserData завеÑÑÑн за ${Math.round(performance.now()-q)}мÑ`),Wt&&Ts(`users error: ${Wt}`,!1),Nt){O(Nt),u(G,Nt),A(G,Nt),Ts("UserEntry: пÑоÑÐ¸Ð»Ñ ÑÑÑановлен â"),Je("users",{id:G},{last_user_agent:navigator.userAgent}).catch(()=>{});const Mt=Jl();Ux(Nt.first_touch_attribution,Mt)?Je("users",{id:G},{first_touch_attribution:Mt}).catch(()=>{}):$x(Nt.first_touch_attribution,Mt)&&Je("users",{id:G},{first_touch_attribution:Mt}).catch(()=>{})}else{Ts("UserEntry: пÑоÑÐ¸Ð»Ñ Ð½Ðµ найден â ÑоздаÑм авÑомаÑиÑеÑки",!1);try{const Mt=Object.keys(localStorage).find(Ht=>Ht.startsWith("sb-")&&Ht.endsWith("-auth-token")),Ls=Mt?JSON.parse(localStorage.getItem(Mt)||"{}"):{},Ft=Ls.user?.email||"",Es=Ls.user?.user_metadata?.name||Ft.split("@")[0]||"ÐлиенÑ",{error:Zt}=await st("users",{id:G,email:Ft,name:Es,balance:0,messages:[],first_touch_attribution:Jl()});if(Zt)Ts(`UserEntry: оÑибка ÑÐ¾Ð·Ð´Ð°Ð½Ð¸Ñ Ð¿ÑоÑилÑ: ${Zt}`,!1);else{const Ht=await Re("users",{id:G},{single:!0});Ht.data&&(O(Ht.data),Ts("UserEntry: пÑоÑÐ¸Ð»Ñ Ñоздан и ÑÑÑановлен â"))}}catch(Mt){Ts(`UserEntry: иÑклÑÑение пÑи Ñоздании пÑоÑилÑ: ${Mt}`,!1)}}os!==null&&We(os),As!==null&&Y(As),cs!==null&&xt(cs)}catch(q){const he=q?.message==="timeout";Ts(`UserEntry: ${he?"TIMEOUT 8Ñек â Ð½ÐµÑ Ð¾ÑвеÑа Ð¾Ñ Supabase":"оÑибка: "+q}`,!1)}finally{Oe.current=!1}}},ie=G=>{en(`ð¡ setupRealtime userId=${G.slice(0,8)}...`,"info"),ht.current&&(At.removeChannel(ht.current),ht.current=null);const q=At.channel("user-realtime").on("postgres_changes",{event:"UPDATE",schema:"public",table:"users",filter:`id=eq.${G}`},he=>{he.new&&O(_e=>({..._e,balance:he.new.balance??_e?.balance,bonus_balance:he.new.bonus_balance??_e?.bonus_balance}))}).on("postgres_changes",{event:"INSERT",schema:"public",table:"notifications",filter:`user_id=eq.${G}`},he=>{const _e=he.new;if(St.current+=1,We(Xe=>Xe+1),Pr("default"),Notification.permission==="granted"&&F.current?.notification_prefs?.browser===!0){const Xe=new Notification(_e?.title||t("user_entry_new_notification"),{body:_e?.text||"",icon:"/favicon-32x32.png"});Xe.onclick=()=>{window.focus(),Xe.close()}}}).on("postgres_changes",{event:"INSERT",schema:"public",table:"messages",filter:`user_id=eq.${G}`},he=>{const _e=he.new;if(ve(_e),_e?.sender==="ADMIN"&&(Ge.current+=1,xt(Xe=>Xe+1),Pr("message"),document.visibilityState==="hidden"&&Notification.permission==="granted")){const Xe=new Notification(t("user_entry_new_message"),{body:_e.text||t("messages_attachment"),icon:"/favicon.ico"});Xe.onclick=()=>{window.focus(),Xe.close()}}}).subscribe();ht.current=q},ge=async()=>{const G=be(),q=Object.keys(localStorage).find(Ct=>Ct.startsWith("sb-")&&Ct.endsWith("-auth-token"));let he=null,_e=null,Xe=null;if(q)try{const Ct=JSON.parse(localStorage.getItem(q)||"{}");Ct.expires_at&&Ct.expires_at*1e3-6e4<Date.now()?localStorage.removeItem(q):(he=Ct.user?.id??null,_e=Ct.access_token??null,Xe=Ct.refresh_token??null)}catch{localStorage.removeItem(q)}if(n(!!he),l(!1),!!he&&(Ts("UserEntry: иниÑиализаÑÐ¸Ñ JWT..."),it.current=he,M(he),ie(he),qe.current&&At.removeChannel(qe.current),qe.current=At.channel("user-support-rt").on("postgres_changes",{event:"UPDATE",schema:"public",table:"support_tickets",filter:`user_id=eq.${he}`},Ct=>{const Gt=Ct.old?.client_unread,Nt=Ct.new?.client_unread;!Gt&&Nt?(Y(Wt=>Wt+1),Pr("default")):Gt&&!Nt&&Y(Wt=>Math.max(0,Wt-1))}).subscribe(),!G)){const Ct=new URLSearchParams(window.location.search),Gt=Ct.get("orderId");if(Gt){o("ORDERS"),h(Gt),window.history.replaceState({},"",window.location.pathname);return}const Nt=Ct.get("tab");if(Nt){const Wt={home:"HOME",orders:"ORDERS",import:"IMPORT",calculator:"CALCULATOR",messages:"MESSAGES",profile:"PROFILE",payments:"PAYMENTS"};Wt[Nt.toLowerCase()]&&o(Wt[Nt.toLowerCase()])}}},w=async()=>{Z?.id&&await M(Z.id)},fe=G=>{Array.isArray(G)&&G.length>0&&localStorage.setItem("import_cart_draft",JSON.stringify(G)),p(!0)},pe=()=>{$(null);const G=window.location.protocol+"//"+window.location.host+window.location.pathname;window.history.replaceState({path:G},"",G)},je=()=>{m("DELIVERY_PAYMENT"),R(!0),o("ORDERS")},ze=G=>{re(G),o("ORDERS")},mt=(G,q)=>{if(G==="COMBINED_DELIVERY_PAYMENT"){je();return}h(G),i(!!q),o("ORDERS")};if(r)return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-slate-50",children:e.jsx(rt,{className:"w-8 h-8 text-blue-600 animate-spin"})});if(d)return e.jsx(Kl,{onLogin:()=>{n(!0),p(!1)}});if(!s&&c!=="IMPORT")return e.jsx(Kl,{onLogin:()=>{n(!0)}});const Tt=()=>{switch(c){case"HOME":return e.jsx(Ql,{orderCounts:z,userProfile:Z,usdRate:ye,onNavigate:o,onPayDelivery:je,onNavigateToOrders:G=>{m(G),o("ORDERS")}});case"ORDERS":return e.jsx(cm,{initialOrderId:b,initialOpenPacking:v,onInitialOrderOpened:()=>{h(null),i(!1)},initialTab:x,onInitialTabApplied:()=>m(null),autoOpenCombinedPayment:N,onAutoOpenCombinedPaymentHandled:()=>R(!1),initialSearchQuery:W,onInitialSearchApplied:()=>re(null),commissionSettings:K,cnyRate:de,usdRate:ye,userBalance:Z?.balance??0,onContactManager:()=>o("MESSAGES"),onReorderOrder:ke,resetKey:S});case"IMPORT":return e.jsx(dm,{initialCart:D,isAuthenticated:s,userProfile:Z,onRequireAuth:fe,onSuccess:()=>{pe(),o("ORDERS")},commissionSettings:K});case"CALCULATOR":return e.jsx(Pm,{});case"MESSAGES":return e.jsx(xm,{currentUser:Z,incomingMessage:Se,onReadMessages:()=>xt(0),onReadNotifications:(G=1)=>We(q=>Math.max(0,q-G)),onOrderClick:mt});case"PROFILE":return e.jsx(bm,{initialData:Z,onProfileUpdate:w,hasPendingUpdate:xe,updateMessage:H});case"PAYMENTS":return e.jsx(gm,{onOrderClick:mt});case"SUPPORT":return e.jsx(Sm,{resetKey:L});case"SELF_BUYOUT":return e.jsx(zm,{onNavigateToOrder:mt});case"MY_QUESTIONS":return e.jsx($m,{});default:return e.jsx(Ql,{orderCounts:z})}};return e.jsxs(e.Fragment,{children:[e.jsx(Ax,{currentView:c,onChangeView:G=>{G==="ORDERS"&&c==="ORDERS"?C(q=>q+1):G==="SUPPORT"&&c==="SUPPORT"?U(q=>q+1):o(G)},userProfile:Z,unreadMessages:Ut,unreadNotifications:J,unreadSupport:oe,cnyRate:de,usdRate:ye,isAuthenticated:s,onPayDelivery:je,onSearchOrder:ze,children:Tt()}),I&&e.jsx("div",{className:"fixed bottom-0 left-0 right-0 z-[9998] bg-slate-900 text-white px-4 py-4 shadow-2xl",children:e.jsxs("div",{className:"max-w-3xl mx-auto flex flex-col sm:flex-row items-start sm:items-center gap-3",children:[e.jsxs("p",{className:"text-sm text-slate-200 flex-1 leading-relaxed",children:[t("user_entry_cookie_banner")," ",e.jsx("a",{href:wr("/privacy"),target:"_blank",rel:"noreferrer",className:"underline hover:text-white font-medium",children:t("auth_link_privacy")}),"."]}),e.jsxs("div",{className:"flex gap-2 shrink-0",children:[e.jsx("button",{onClick:()=>{localStorage.setItem("cookie_consent","1"),B(!1)},className:"px-4 py-2 bg-yellow-400 hover:bg-yellow-500 text-slate-900 text-sm font-bold rounded-lg transition-colors",children:t("user_entry_cookie_accept")}),e.jsx("button",{onClick:()=>{localStorage.setItem("cookie_consent","0"),B(!1)},className:"px-4 py-2 bg-slate-700 hover:bg-slate-600 text-white text-sm font-semibold rounded-lg transition-colors",children:t("user_entry_cookie_decline")})]})]})}),xe&&!Qe&&e.jsx("div",{className:"fixed top-0 left-0 right-0 z-[9998] bg-blue-600 text-white px-4 py-3 shadow-2xl",children:e.jsxs("div",{className:"max-w-3xl mx-auto flex items-center gap-3",children:[e.jsxs("p",{className:"text-sm flex-1 leading-relaxed",children:[t("user_entry_update_banner"),H?`: ${H}`:"."," ",t("user_entry_update_banner_suffix")]}),e.jsxs("div",{className:"flex gap-2 shrink-0",children:[e.jsx("button",{onClick:()=>window.location.reload(),className:"px-4 py-2 bg-white hover:bg-blue-50 text-blue-700 text-sm font-bold rounded-lg transition-colors",children:t("profile_update_button")}),e.jsx("button",{onClick:()=>k(!0),"aria-label":t("profile_close_button"),className:"px-3 py-2 text-white/80 hover:text-white text-sm font-semibold rounded-lg transition-colors",children:"Ã"})]})]})})]})}export{Jm as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.