1import{u as e,bX as tt,bY as st,bZ as rt,b_ as at,r as c,ad as nt,am as V,b$ as Oe,af as ot,a$ as pe,a_ as it,L as lt,b2 as ct,c0 as dt,c1 as ut,ay as mt}from"./vendor-DzWMmZj2.js";import{a as C,ae as Ae,af as xt,ag as ae,x as pt,B as q,ah as ft,ai as ht,v as gt,u as bt,k as Ne,U as me,b as re,d as yt,aa as vt,ab as Nt,ac as jt,ad as je,aj as we,ak as ke,al as wt,am as kt,an as St,a1 as Tt,o as Ct,F as _e,a9 as Me}from"./index-B-ZZKIlh.js";import{d as zt,e as Ot}from"./vendor-tanstack-D-s8FawA.js";import{g as At}from"./order-CWMXdt5a.js";import{D as _t}from"./date-picker-Ci6ABAHb.js";import{u as W}from"./vendor-i18n-C7hD56hb.js";import{T as Mt,a as It}from"./TableInfo-BAN1HXmd.js";import{T as Rt}from"./TablePagination-H7cog67h.js";import{h as Ft,l as Pt,P as Se,t as K,b as Dt,a as Et,O as $t,i as Te,e as Lt}from"./ordersFilterShared-DK6b_T6I.js";import{g as Ie,D as Re,a as Fe}from"./orderStatusConfig-DIVgw1vs.js";import{I as Kt,c as Ce}from"./reportsFakeData-CKBuvQOX.js";import"./vendor-socket-CdJ84v18.js";import"./vendor-phone-CDRp5aFf.js";import"./useTable-CFZmHKgO.js";function qt({className:t,...o}){return e.jsx(tt,{"data-slot":"radio-group",className:C("grid gap-2",t),...o})}function Vt({className:t,...o}){return e.jsx(st,{"data-slot":"radio-group-item",className:C("border-primary text-primary focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 aria-invalid:border-destructive aspect-square size-4 shrink-0 rounded-full border shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",t),...o,children:e.jsx(rt,{className:"flex items-center justify-center",children:e.jsx(at,{className:"size-2.5 fill-current text-current"})})})}const Gt=({item:t,onDelete:o,render:i,tabIndex:l=-1})=>{var x;return e.jsxs("button",{"data-chip":!0,tabIndex:l,className:C("inline-flex items-center gap-0.5 rounded-md px-2 py-1 text-xs font-medium",t.notAvailable?"bg-error text-error-foreground hover:bg-error-hover":"bg-white text-primary-black hover:bg-[color-mix(in_srgb,var(--color-primary)_12%,white)] focus-visible:bg-[color-mix(in_srgb,var(--color-primary)_18%,white)]"),onClick:p=>{p.stopPropagation(),o(t)},onKeyDown:p=>{(p.key===" "||p.key==="Delete"||p.key==="Backspace")&&(p.preventDefault(),o(t))},children:[e.jsx("span",{className:"max-w-28 truncate",children:(x=i==null?void 0:i({item:t}))!=null?x:t.name}),e.jsx(V,{className:"ml-0.5 size-3 shrink-0","aria-hidden":!0})]})},Ut=({title:t,selectedCount:o,selectedOptions:i,onOpen:l,onDeleteItem:x,onClickItem:p,clearAll:b,renderItem:S})=>{const{t:n}=W();return e.jsxs("div",{className:"px-6 pointer-events-none fixed inset-0 z-50 flex items-end justify-center overflow-hidden",children:[e.jsxs("div",{className:"relative items-center justify-center bottom-6 rounded-xl overflow-hidden size-12 bg-filter text-background flex tablet:hidden gap-2 pointer-events-auto cursor-pointer",onClick:l,children:[e.jsx(pe,{className:"size-6"}),!!o&&e.jsx("div",{className:"text-conte-body-m absolute top-1.5 right-1.5 size-4 rounded-full flex items-center justify-center bg-primary text-background",children:o})]}),e.jsx("div",{className:"relative max-w-240 h-12 bottom-6 items-center overflow-hidden w-full flex-1 p-0 hidden tablet:flex flex-col",children:e.jsxs("div",{className:"max-w-full relative bg-filter overflow-hidden h-12 py-2 px-2 rounded-xl hidden tablet:flex gap-2 items-center justify-end pointer-events-auto cursor-pointer",onClick:l,children:[o?e.jsx(ae,{withScrollbar:!1,orientation:"horizontal",className:"relative h-8 flex-1",arrows:e.jsxs(e.Fragment,{children:[e.jsx(ft,{className:"bg-background text-background"}),e.jsx(ht,{className:"bg-filter text-background"})]}),children:e.jsx("div",{className:"flex items-center gap-2 overflow-x-auto flex-1 flex-nowrap",children:i.map(f=>{var N;return e.jsxs("div",{className:C("inline-flex items-center gap-0.5 rounded-md px-2 py-1 text-xs font-medium whitespace-nowrap cursor-pointer",f.notAvailable?"bg-error text-error-foreground":"bg-white text-[#151516]"),onClick:v=>{v.stopPropagation(),p(f)},children:[e.jsx("span",{children:(N=S==null?void 0:S({item:f}))!=null?N:f.name}),e.jsx("button",{onClick:v=>{v.stopPropagation(),x(f)},className:"h-4 w-4 p-0.5 rounded-full hover:bg-black/10 transition",children:e.jsx(V,{className:"size-3"})})]},"".concat(f.group,"_").concat(f.id))})})}):e.jsx("div",{className:"text-conte-button-s text-white text-sm w-fit px-2",children:t}),!!o&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:b,className:"flex-0 text-conte-button-xs text-gray flex items-center gap-1 px-2 py-1 rounded transition hover:opacity-90 cursor-pointer",children:[e.jsx(it,{className:"size-4"}),n("common.clear")]}),e.jsx(gt,{orientation:"vertical",className:"min-h-7"})]}),e.jsx("button",{className:"flex-0 min-w-12 text-background text-xs rounded-[30px] flex justify-center items-center gap-2 shadow pr-1.5",children:e.jsx(pe,{className:"size-6"})})]})})]})};function Bt({title:t,groups:o=[],value:i,onChange:l,renderItem:x,open:p,onOpenChange:b,singleSelect:S=!1,onApply:n}){var J,te;
1const{t:f}=W();t=t||f("common.filter.title");const[N,v]=c.useTransition(),[u,G]=c.useState(!1),_=p!==void 0?p:u,U=r=>{G(r),b==null||b(r)},[k,P]=c.useState(null),[B,M]=c.useState(""),T=c.useMemo(()=>{const r=new Map;return{groups:o.map(g=>({...g,items:g.items.map(j=>{var w;const y={...j,_lcName:(w=j._lcName)!=null?w:j.name.toLowerCase(),group:g.key};return r.set("".concat(g.key,"_").concat(j.id),y),y})})),map:r}},[o]),I=c.useMemo(()=>Object.entries(i||{}).flatMap(([r,d])=>d==null?void 0:d.map(g=>T.map.get("".concat(r,"_").concat(g)))).filter(r=>!!r),[i,T.map]),X=c.useMemo(()=>{const r={};for(const d of I)r[d.group]||(r[d.group]=[]),r[d.group].push(d);return r},[I]),z=c.useMemo(()=>T.groups.find(r=>r.key===k),[T.groups,k]),R=c.useMemo(()=>{var r;return((r=(i||{})[k!=null?k:""])!=null?r:[]).map(String)},[i,k]),D=c.useMemo(()=>{if(!z)return[];const r=z.items.filter(g=>!g.notAvailable||R.includes(String(g.id)));if(!B.trim())return r;const d=B.toLowerCase();return r.filter(g=>g._lcName.includes(d))},[z,B,R]),Q=()=>{U(!1),P(null),M("")};Ae("keydown",r=>{_&&r.key==="Escape"&&Q()});const F=r=>{v(()=>{P(d=>d===r?null:r),M("")})},ne=()=>{v(()=>{P(null),M("")})},E=(r,d)=>{var y;const g=i||{},j=(y=g[r])!=null?y:[];l==null||l({...g,[r]:j.includes(d)?j.filter(w=>w!==d):[...j,d]})},ee=r=>{r.stopPropagation(),l==null||l({})},Y=k?e.jsxs("div",{className:C("flex h-full w-full flex-col bg-card tablet:w-80 tablet:border-l tablet:border-border",N&&"opacity-50"),children:[e.jsxs("div",{className:"h-13 shrink-0 border-b border-border px-3 flex items-center gap-2",children:[e.jsx("button",{onClick:ne,className:"tablet:hidden rounded-md p-1 hover:bg-muted transition",children:e.jsx(nt,{className:"size-5"})}),e.jsx(xt,{size:"md",value:B,onChange:M,placeholder:"ÐоиÑк по ".concat((J=z==null?void 0:z.title.toLowerCase())!=null?J:"знаÑениÑ"),className:"w-full"})]}),e.jsx(ae,{className:"flex-1",withScrollbar:!1,children:e.jsx("div",{className:"px-4 py-3",children:D.length===0?e.jsx("p",{className:"py-8 text-center text-sm text-muted-foreground",children:f("common.not_found")}):S?e.jsxs(e.Fragment,{children:[R.length>0&&e.jsx("button",{onClick:()=>l==null?void 0:l({...i||{},[k]:[]}),className:"mb-2 w-full text-left px-2 py-1.5 text-xs text-muted-foreground hover:text-foreground hover:bg-muted/60 rounded-md transition",children:f("common.filter.reset",{defaultValue:"СбÑоÑиÑÑ"})}),e.jsx(qt,{value:(te=R[0])!=null?te:"",onValueChange:r=>l==null?void 0:l({...i||{},[k]:r?[r]:[]}),className:"flex flex-col gap-0",children:D.map(r=>{var d;return e.jsxs("label",{className:"flex cursor-pointer items-center gap-3 rounded-md px-2 py-2 hover:bg-muted/60 transition",children:[e.jsx(Vt,{value:String(r.id),id:"rg-".concat(k,"-").concat(r.id)}),e.jsx("span",{className:"flex-1 text-sm",children:(d=x==null?void 0:x({item:r}))!=null?d:r.name})]},r.id)})})]}):e.jsx("div",{className:"flex flex-col gap-0.5",onKeyDown:r=>{var w;if(!["ArrowUp","ArrowDown"].includes(r.key))return;const d=Array.from(r.currentTarget.querySelectorAll("button[role='checkbox']")),g=d.indexOf(document.activeElement);if(g===-1)return;r.preventDefault();const j=r.key==="ArrowDown"?1:-1,y=(g+j+d.length)%d.length;d.forEach(O=>O.tabIndex=-1),d[y].tabIndex=0,(w=d[y])==null||w.focus()},children:D.map((r,d)=>{var j;const g=R.includes(String(r.id));return e.jsxs("label",{className:C("flex cursor-pointer items-center gap-3 rounded-md px-2 py-2 transition",r.notAvailable?"hover:bg-error-hover":"hover:bg-muted/60"),children:[e.jsx(pt,{checked:g,onCheckedChange:()=>E(k,r.id),tabIndex:d===0?0:-1}),e.jsx("span",{className:C("flex-1 text-sm",r.notAvailable&&"text-error font-medium"),children:(j=x==null?void 0:x({item:r}))!=null?j:r.name})]},r.id)})})})})]}):null,oe=e.jsxs("div",{className:C("flex h-full w-full flex-col bg-card tablet:w-72",k&&"hidden tablet:flex"),children:[e.jsxs("div",{className:"flex h-13 shrink-0 items-center gap-2 border-b border-border px-4",children:[e.jsx("button",{onClick:Q,className:"rounded-md p-1 hover:bg-muted transition","aria-label":f("common.filter.close"),children:e.jsx(V,{className:"size-5"})}),e.jsx("span",{className:"flex-1 text-sm font-semibold",children:t}),!!I.length&&e.jsx("button",{onClick:ee,className:"rounded-md p-1 hover:bg-muted transition text-muted-foreground","aria-label":f("common.filter.reset_all"),children:e.jsx(Oe,{className:"size-5"})})]}),e.jsx(ae,{className:"flex-1",withScrollbar:!1,children:T.groups.map(r=>{var j;const d=(j=X[r.key])!=null?j:[],g=k===r.key;return e.jsxs("div",{className:"border-b border-border/40 last:border-0",children:[e.jsxs("button",{onClick:()=>F(r.key),className:C("flex w-full items-center gap-2 px-4 py-3 text-left transition hover:bg-muted/60",g&&"bg-muted/50"),children:[e.jsx("span",{className:"flex-1 text-sm font-medium",children:r.title}),!!d.length&&e.jsx("span",{className:"flex h-5 min-w-5 items-center justify-center rounded-full bg-primary px-1 text-[11px] font-semibold text-primary-foreground",children:d.length}),e.jsx(ot,{className:C("size-4 shrink-0 text-muted-foreground transition-transform duration-200",g&&"rotate-90")})]}),!!d.length&&e.jsx("div",{className:"flex flex-wrap gap-1.5 px-4 pt-2 pb-3",onKeyDown:y=>{if(!["ArrowLeft","ArrowRight"].includes(y.key))return;const w=Array.from(y.currentTarget.querySelectorAll("button[data-chip]")),O=w.indexOf(document.activeElement);if(O===-1)return;y.preventDefault();const H=(O+(y.key==="ArrowRight"?1:-1)+w.length)%w.length;
1w.forEach(se=>se.tabIndex=-1),w[H].tabIndex=0,w[H].focus()},children:d.map((y,w)=>e.jsx(Gt,{item:y,onDelete:({id:O,group:H})=>E(H,O),render:x,tabIndex:w===0?0:-1},"chip_".concat(y.group,"_").concat(y.id)))})]},r.key)})}),n&&e.jsx("div",{className:"shrink-0 border-t border-border px-3 py-3",children:e.jsx(q,{className:"w-full",size:"md",onClick:()=>{n(),Q()},children:f("common.filter.apply",{defaultValue:"ÐÑимениÑÑ"})})})]});return e.jsxs(e.Fragment,{children:[!_&&p===void 0&&e.jsx(Ut,{title:t,selectedCount:I.length,selectedOptions:I,onOpen:()=>U(!0),onDeleteItem:({id:r,group:d})=>E(d,r),onClickItem:({group:r})=>{F(r),U(!0)},clearAll:ee,renderItem:x}),_&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-119 bg-foreground/20",onClick:Q}),e.jsxs("div",{className:"fixed left-0 top-0 z-120 flex h-full shadow-2xl",children:[oe,Y]})]})]})}const Qt={queued:{labelKey:"orders.reports.card.status.queued",className:"bg-muted text-muted-foreground"},processing:{labelKey:"orders.reports.card.status.processing",className:"bg-amber-100 text-amber-700"},ready:{labelKey:"orders.reports.card.status.ready",className:"bg-green-100 text-green-700"},error:{labelKey:"orders.reports.card.status.error",className:"bg-destructive/10 text-destructive"},cancelled:{labelKey:"orders.reports.card.status.cancelled",className:"bg-muted text-muted-foreground"}};function Jt(t,o){const i=Math.floor((Date.now()-t.getTime())/6e4),l=Math.floor(i/1440),x=t.toLocaleTimeString("ru-RU",{hour:"2-digit",minute:"2-digit"});return i<1?o("orders.reports.card.time.just_now"):l===0?o("orders.reports.card.time.today",{time:x}):l===1?o("orders.reports.card.time.yesterday",{time:x}):o("orders.reports.card.time.days_ago",{count:l})}function Ht({job:t,onCancel:o,onRelaunch:i}){var N,v;const{t:l}=W("orders"),[x,p]=c.useState(!1),b=Qt[t.status],S=t.status==="queued"||t.status==="processing",n=t.status==="ready"&&t.downloadUrl,f=t.status==="ready"||t.status==="error"||t.status==="cancelled";return e.jsxs("div",{className:"rounded-lg border border-border bg-card overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-2 border-b border-border/60",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:Jt(t.createdAt,l)}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("span",{className:C("rounded-full px-2 py-0.5 text-[10px] font-medium leading-none",b.className),children:l(b.labelKey)}),S&&!x&&e.jsx("button",{onClick:()=>p(!0),className:"rounded-full p-0.5 text-muted-foreground hover:text-foreground hover:bg-muted transition-colors",children:e.jsx(V,{className:"size-3"})})]})]}),e.jsxs("div",{className:"px-3 py-2 flex flex-col gap-2",children:[e.jsx("div",{className:"flex flex-wrap gap-1",children:t.params.map((u,G)=>e.jsxs("span",{className:"inline-flex items-center gap-1 rounded bg-muted px-1.5 py-0.5 text-[11px]",children:[e.jsxs("span",{className:"text-muted-foreground",children:[u.label,":"]}),e.jsx("span",{className:"font-medium text-foreground",children:u.value})]},G))}),(t.status==="queued"||t.status==="processing")&&e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("div",{className:"flex items-center justify-between text-[11px] text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(lt,{className:"size-3 animate-spin"}),e.jsx("span",{children:t.status==="queued"?l("orders.reports.card.status.queued"):"".concat((N=t.progress)!=null?N:0,"%")})]}),t.estimatedSeconds!=null&&t.status==="processing"&&e.jsx("span",{children:l("orders.reports.card.minutes",{count:Math.ceil(t.estimatedSeconds/60)})})]}),e.jsx("div",{className:"h-1 w-full rounded-full bg-muted overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-primary transition-all duration-500",style:{width:"".concat(t.status==="queued"?0:(v=t.progress)!=null?v:0,"%")}})})]}),t.status==="error"&&t.error&&e.jsxs("div",{className:"flex items-center gap-1 text-[11px] text-destructive",children:[e.jsx(ct,{className:"size-3 shrink-0"}),t.error]}),t.status==="ready"&&(t.fileSize||t.expiresAt)&&e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] text-muted-foreground",children:[t.fileSize&&e.jsx("span",{children:t.fileSize}),t.fileSize&&t.expiresAt&&e.jsx("span",{children:"·"}),t.expiresAt&&e.jsx("span",{children:l("orders.reports.card.expires",{date:t.expiresAt.toLocaleDateString("ru-RU",{day:"numeric",month:"long"})})})]})]}),x&&e.jsxs("div",{className:"flex items-center justify-between border-t border-border/60 px-3 py-1.5 text-xs bg-muted/40",children:[e.jsx("span",{className:"text-muted-foreground",children:l("orders.reports.card.cancel_confirm")}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(q,{variant:"text",color:"gray",size:"xs",onClick:()=>p(!1),children:l("common:common.no")}),e.jsx(q,{variant:"default",color:"black",size:"xs",onClick:()=>{p(!1),o(t.id)},children:l("common:common.yes")})]})]}),(n||f)&&!x&&e.jsxs("div",{className:"flex items-center gap-2 border-t border-border/60 px-3 py-1.5",children:[n&&e.jsx(q,{variant:"default",size:"xs",asChild:!0,children:e.jsxs("a",{href:t.downloadUrl,download:!0,children:[e.jsx(dt,{className:"size-3"}),l("orders.reports.card.download")]})}),f&&e.jsxs(q,{variant:"outline",size:"xs",className:"bg-muted border-transparent text-foreground hover:bg-muted/70",onClick:()=>i(t.params),children:[e.jsx(ut,{className:"size-3"}),l("orders.reports.card.relaunch")]})]})]})}function Xt({open:t,onClose:o,jobs:i,onCancel:l,onRelaunch:x}){const{t:p}=W("orders"),[b,S]=c.useState("all");Ae("keydown",u=>{t&&u.key==="Escape"&&o()});const n=[{key:"all",labelKey:"orders.reports.sheet.tabs.all"},{key:"active",labelKey:"orders.reports.sheet.tabs.active"},{key:"ready",labelKey:"orders.reports.sheet.tabs.ready"},{key:"error",labelKey:"orders.reports.sheet.tabs.error"}],f=c.useMemo(()=>b==="all"?i:b==="active"?i.filter(u=>u.status==="queued"||u.status==="processing"):b==="ready"?i.filter(u=>u.status==="ready"):b==="error"?i.filter(u=>u.status==="error"):i,[i,b]),N=c.useMemo(()=>({all:i.length,active:i.filter(u=>u.status==="queued"||u.status==="processing").length,ready:i.filter(u=>u.status==="ready").length,error:i.filter(u=>u.status==="error").length}),[i]),v=u=>{x(u),S("active")};return t?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-119 bg-foreground
1/20",onClick:o}),e.jsxs("div",{className:"fixed right-0 top-0 z-120 flex h-full w-full max-w-[520px] flex-col bg-card shadow-2xl",children:[e.jsxs("div",{className:"flex h-14 shrink-0 items-center justify-between border-b border-border px-5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-semibold",children:p("orders.reports.sheet.title")}),i.length>0&&e.jsx("span",{className:"flex h-5 min-w-5 items-center justify-center rounded-full bg-muted px-1 text-[11px] font-medium text-muted-foreground",children:i.length})]}),e.jsx("button",{onClick:o,className:"rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground transition-colors",children:e.jsx(V,{className:"size-5"})})]}),e.jsx("div",{className:"flex shrink-0 gap-1 border-b border-border px-4 py-2",children:n.map(u=>e.jsxs("button",{onClick:()=>S(u.key),className:"flex items-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-medium transition-colors ".concat(b===u.key?"bg-primary/10 text-primary":"text-muted-foreground hover:bg-muted hover:text-foreground"),children:[p(u.labelKey),N[u.key]>0&&e.jsx("span",{className:"flex h-4 min-w-4 items-center justify-center rounded-full px-1 text-[10px] font-semibold ".concat(b===u.key?"bg-primary text-primary-foreground":"bg-muted-foreground/20 text-muted-foreground"),children:N[u.key]})]},u.key))}),e.jsx(ae,{className:"flex-1",withScrollbar:!1,children:e.jsx("div",{className:"flex flex-col gap-3 p-4",children:f.length===0?e.jsx("p",{className:"py-12 text-center text-sm text-muted-foreground",children:p("orders.reports.sheet.empty")}):f.map(u=>e.jsx(Ht,{job:u,onCancel:l,onRelaunch:v},u.id))})})]})]}):null}const{orderList:Yt,orderGetAvailableFilters:Zt}=At(),{settingsCountries:Wt,settingOrderTypes:es}=yt(),ts=[10,25,50,100],Z=t=>t.map(o=>({id:o.value,name:o.label,_lcName:o.label.toLowerCase()})),ze=t=>{var o,i,l,x,p,b,S,n,f,N,v;return{distributor:((o=t.distributor)==null?void 0:o[0])||void 0,store:((i=t.store)==null?void 0:i[0])||void 0,manager:((l=t.manager)==null?void 0:l[0])||void 0,clientManager:((x=t.clientManager)==null?void 0:x[0])||void 0,whoseOrder:((p=t.whoseOrder)==null?void 0:p[0])||void 0,deviceType:((b=t.deviceType)==null?void 0:b[0])||void 0,client:((S=t.client)==null?void 0:S[0])||void 0,status:((n=t.status)==null?void 0:n[0])||void 0,orderType:((f=t.orderType)==null?void 0:f[0])||void 0,country:((N=t.country)==null?void 0:N[0])||void 0,hasQuantityMismatch:(v=t.hasQuantityMismatch)!=null&&v.length?"1":void 0}},xe=t=>{const o={};return t.distributor&&(o.distributor=[t.distributor]),t.store&&(o.store=[t.store]),t.manager&&(o.manager=[t.manager]),t.clientManager&&(o.clientManager=[t.clientManager]),t.whoseOrder&&(o.whoseOrder=[t.whoseOrder]),t.deviceType&&(o.deviceType=[t.deviceType]),t.client&&(o.client=[t.client]),t.status&&(o.status=[t.status]),t.orderType&&(o.orderType=[t.orderType]),t.country&&(o.country=[t.country]),t.hasQuantityMismatch==="1"&&(o.hasQuantityMismatch=["1"]),o},ss=({type:t,valueLabel:o,meta:i})=>{var l,x;return t==="status"?e.jsxs("div",{className:"flex items-center gap-1 min-w-0",children:[e.jsx("div",{className:"size-2 rounded-full shrink-0",style:{background:i==null?void 0:i.color}}),e.jsx("span",{className:"truncate",children:o})]}):t==="orderType"?e.jsxs("div",{className:"flex items-center gap-1 min-w-0",children:[e.jsx(Me,{className:"size-3 shrink-0",style:{color:(l=i==null?void 0:i.color)!=null?l:"#adb5bd"}}),e.jsx("span",{className:"truncate",children:o})]}):t==="country"?e.jsxs("div",{className:"flex items-center gap-1 min-w-0",children:[e.jsx(_e,{code:i==null?void 0:i.code,size:12,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:o})]}):t==="deviceType"?e.jsxs("div",{className:"flex items-center gap-1 min-w-0",children:[e.jsx("span",{className:"flex items-center gap-0.5 shrink-0",children:((x=i==null?void 0:i.icons)!=null?x:[]).map(p=>{const b=Fe[p];return b?e.jsx(b,{size:10,className:"flex"},p):null})}),o&&e.jsx("span",{className:"truncate",children:o})]}):e.jsx("span",{className:"truncate",children:o})},rs=({chip:t,onDelete:o})=>e.jsxs("div",{className:"bg-muted rounded-md px-2 py-1 inline-flex items-center gap-1.5 text-xs font-medium text-primary-black whitespace-nowrap min-w-0",children:[e.jsxs("div",{className:"flex flex-col gap-0.5 min-w-0",children:[e.jsx("span",{className:"text-[10px] leading-none text-muted-foreground",children:t.fieldLabel}),e.jsx(ss,{type:t.type,valueLabel:t.valueLabel,meta:t.meta})]}),e.jsx("button",{onClick:i=>{i.stopPropagation(),o()},className:"h-3.5 w-3.5 p-0.5 shrink-0 rounded-full hover:bg-border transition",children:e.jsx(V,{className:"size-full"})})]}),as=({item:t})=>{var o,i;return t.group==="status"?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"size-2 roun
1ded-full shrink-0",style:{background:Ie(String(t.id))}}),e.jsx("span",{children:t.name})]}):t.group==="country"?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(_e,{code:t.code,size:14,className:"shrink-0"}),e.jsx("span",{children:t.name})]}):t.group==="orderType"?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Me,{className:"size-3.5 shrink-0",style:{color:(o=t.color)!=null?o:"#adb5bd"}}),e.jsx("span",{children:t.name})]}):t.group==="deviceType"?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"flex items-center gap-0.5 shrink-0",children:((i=Re[String(t.id)])!=null?i:[]).map(l=>{const x=Fe[l];return x?e.jsx(x,{size:12,className:"flex"},l):null})}),e.jsx("span",{children:t.name})]}):e.jsx("span",{children:t.name})};function ns(){var be,ye,ve;const{t}=W("orders"),{currentRole:o,userRole:i}=bt("appStore"),l=zt(),x=Ne(i,[me.ADMIN]),p=Ne(o,[me.ADMIN,me.DISTRIBUTOR]),b=Ot({strict:!1}),n=Ft(b)?b:Pt(),f=Number((be=n.page)!=null?be:"1")||1,N=Number((ye=n.perPage)!=null?ye:String(Se))||Se,v=JSON.stringify(n),[u,G]=c.useState(!1),[_,U]=c.useState(()=>xe(n)),[k,P]=c.useState(!1),[B,M]=c.useState(Kt),[T,I]=c.useState(()=>xe(n)),[X,z]=c.useState((ve=n.id)!=null?ve:""),R=c.useRef(v);c.useEffect(()=>{var s;R.current!==v&&(R.current=v,I(xe(n)),z((s=n.id)!=null?s:""))},[v]),c.useEffect(()=>{u&&U(T)},[u]);const[D,Q]=c.useState([]),[F,ne]=c.useState(0),[E,ee]=c.useState([]),[Y,oe]=c.useState([]),[J,te]=c.useState([]),[r,d]=c.useState([]),[g,j]=c.useState([]),[y,w]=c.useState([]),[O,H]=c.useState([]),[se,Pe]=c.useState({}),[fe,De]=c.useState({}),{mutateAsync:Ee}=re({mutationKey:["settings-countries-for-flags"],mutationFn:()=>Wt({}),successFn:s=>{var m;const a={};
1((m=s==null?void 0:s.result)!=null?m:[]).forEach(h=>{h.id!=null&&h.code&&(a[String(h.id)]=h.code)}),Pe(a)}}),{mutateAsync:$e}=re({mutationKey:["settings-order-types-for-colors"],mutationFn:()=>es({}),successFn:s=>{var m;const a={};for(const h of(m=s==null?void 0:s.result)!=null?m:[])h.code&&h.color&&(a[h.code]=h.color);De(a)}});c.useEffect(()=>{Ee(),$e()},[]);const{mutateAsync:Le}=re({mutationKey:["order-available-filters"],abortable:!0,cached:!1,mutationFn:(s,{signal:a})=>Zt(s,{signal:a}),successFn:s=>{var m;const a=(m=s==null?void 0:s.result)==null?void 0:m.values;a&&(te(K(a.distributor)),d(K(a.store)),ee(K(a.status)),oe(K(a.orderType)),j(K(a.country)),w(K(a.whoseOrder)),H(K(a.deviceType)))}}),Ke=JSON.stringify(_);c.useEffect(()=>{const s={...n,...ze(_)};Le(Dt(s))},[Ke]);const{isPending:ie,mutateAsync:qe}=re({mutationKey:["orders-list"],abortable:!0,cached:!1,mutationFn:(s,{signal:a})=>Yt(s,{signal:a}),successFn:s=>{var a,m,h,A;Q((m=(a=s==null?void 0:s.result)==null?void 0:a.items)!=null?m:[]),ne((A=(h=s==null?void 0:s.result)==null?void 0:h.count)!=null?A:0)}});c.useEffect(()=>{qe(Et(n,f,N))},[v]);const le=c.useMemo(()=>{const s=[];return x&&J.length>0&&s.push({key:"distributor",title:t("orders.filter.distributor"),items:Z(J)}),p&&r.length>0&&s.push({key:"store",title:t("orders.filter.store"),items:Z(r)}),p&&y.length>0&&s.push({key:"whoseOrder",title:t("orders.filter.order_by"),items:Z(y)}),O.length>0&&s.push({key:"deviceType",title:t("orders.filter.device"),items:Z(O)}),E.length>0&&s.push({key:"status",title:t("orders.filter.status"),items:Z(E)}),Y.length>0&&s.push({key:"orderType",title:t("orders.filter.type"),items:Y.map(a=>({id:a.value,name:a.label,_lcName:a.label.toLowerCase(),color:fe[a.value]}))}),g.length>0&&s.push({key:"country",title:t("orders.filter.country"),items:g.map(a=>({id:a.value,name:a.label,_lcName:a.label.toLowerCase(),code:se[a.value]}))}),s},[x,p,J,r,y,O,E,Y,g,se,fe,t]),ce=c.useMemo(()=>Object.values(T).reduce((s,a)=>{var m;return s+((m=a==null?void 0:a.length)!=null?m:0)},0),[T]),Ve=c.useMemo(()=>Object.entries(T).flatMap(([s,a])=>{const m=le.find(h=>h.key===s);return m?(a!=null?a:[]).map(h=>{const A=m.items.find(ue=>String(ue.id)===String(h));if(!A)return null;const L={key:"".concat(s,"_").concat(h),groupKey:s,fieldLabel:m.title,valueLabel:A.name,rawValue:String(h)};return s==="status"?{...L,type:"status",meta:{color:Ie(String(h))}}:s==="country"?{...L,type:"country",meta:{code:A.code}}:s==="deviceType"?{...L,type:"deviceType",meta:{icons:Re[String(h)]}}:s==="orderType"?{...L,type:"orderType",meta:{color:A.color}}:{...L,type:"text"}}).filter(h=>!!h):[]}),[T,le]),Ge=c.useMemo(()=>{const{from:s,to:a}=n;if(!s&&!a)return;const m=h=>{if(!h)return;const[A,L,ue]=h.split(".");return new Date(Number(ue),Number(L)-1,Number(A))};return{from:m(s),to:m(a)}},[n]),$=s=>{Lt(s),l({to:"/order/list",search:s,replace:!0})},de=s=>{I(s);const a={};n.b2m&&(a.b2m=n.b2m),n.excludeStatuses&&(a.excludeStatuses=n.excludeStatuses),n.from_distributor&&(a.from_distributor=n.from_distributor),n.perPage&&(a.perPage=n.perPage),n.from&&(a.from=n.from),n.to&&(a.to=n.to),n.id&&(a.id=n.id),$({...ze(s),...a})},Ue=s=>{const a=s!=null&&s.from?Te(s.from):void 0,m=s!=null&&s.to?Te(s.to):void 0;$({...n,from:a,to:m,page:void 0})},he=()=>{var a;const s=X.trim();s!==((a=n.id)!=null?a:"")&&$({...n,id:s||void 0,page:void 0})},Be=()=>{var a,m;const s=[];return(n.from||n.to)&&s.push({label:"ÐеÑиод",value:"".concat((a=n.from)!=null?a:"â¦","â").concat((m=n.to)!=null?m:"â¦")}),n.status&&s.push({label:"СÑаÑÑÑ",value:n.status}),n.store&&s.push({label:"Склад",value:n.store}),n.distributor&&s.push({label:"ÐиÑÑÑибÑÑÑоÑ",value:n.distributor}),n.orderType&&s.push({label:"Тип",value:n.orderType}),n.country&&s.push({label:"СÑÑана",value:n.country}),s.length||s.push({label:"ÐеÑиод",value:"ÐÑе заказÑ"}),s},ge=()=>{const s=Ce(Be());M(a=>[s,...a]),P(!0)},Qe=s=>M(a=>a.map(m=>m.id===s?{...m,status:"cancelled"}:m)),Je=s=>{const a=Ce(s);M(m=>[a,...m])},He=n.hasQuantityMismatch==="1",Xe=s=>$({...n,hasQuantityMismatch:s?"1":void 0,page:void 0}),Ye=Math.min((f-1)*N+1,F),Ze=Math.min(f*N,F),We=s=>$({...n,page:s>1?String(s):void 0}),et=s=>$({...n,perPage:String(s),page:void 0});return e.jsxs("div",{className:"flex flex-col gap-4 px-8 py-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("h1",{className:"text-conte-heading2 text-primary-black shrink-0",children:t("orders.title")}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx(q,{variant:"default",color:"black",size:"md",onClick:()=>P(!0),children:t("orders.ready_reports",{defaultValue:"ÐоÑовÑе оÑÑÑÑÑ"})}),e.jsxs(vt,{children:[e.jsx(Nt,{asChild:!0,children:e.jsxs(q,{variant:"default",color:"black",size:"md",children:[t("orders.download_report",{defaultValue:"СкаÑаÑÑ Ð¾ÑÑÑÑ"}),e.jsx(mt,{className:"size-4"})]})}),e.jsxs(jt,{align:"end",children:[e.jsx(je,{onSelect:ge,children:t("orders.report_standard",{defaultValue:"СÑандаÑÑнÑй"})}),e.jsx(je,{onSelect:ge,children:t("orders.report_extended",{defaultValue:"РаÑÑиÑеннÑй"})})]})]})]})]}),e.jsxs("div",{className:"bg-white rounded-xl flex flex-col",children:[e.jsxs("div",{className:"flex items-end gap-3 px-4 py-3",children:[e.jsxs("div",{className:"relative self-end shrink-0 pb-[9px]",children:[e.jsx("button",{onClick:()=>G(!0),className:"flex items-center justify-center text-muted-foreground hover:text-foreground transition-colors",children:e.jsx(pe,{className:"size-4"})}),ce>0&&e.jsx("span",{className:"pointer-events-none absolute -top-1 -right-1.5 size-4 rounded-full flex items-center justify-center bg-primary text-background text-[10px] font-medium",children:ce})]}),e.jsxs(we,{className:"flex-1 min-w-0",children:[e.jsx(ke,{children:t("orders.filter.period",{defaultValue:"ÐеÑиод"})}),e.jsx(_t,{size:"md",value:Ge,onChange:Ue})]}),e.jsxs(we,{className:"flex-1 min-w-0",children:[e.jsx(ke,{children:t("orders.filter.order_number")}),e.jsxs(wt,{size:"md",children:[e.jsx(kt,{placeholder:"â",value:X,onChange:s=>
1z(s.target.value),onBlur:he,onKeyDown:s=>{s.key==="Enter"&&he()}}),X&&e.jsx(St,{align:"inline-end",children:e.jsx("button",{onClick:()=>{z(""),$({...n,id:void 0,page:void 0})},className:"text-muted-foreground hover:text-foreground transition-colors",children:e.jsx(V,{className:"size-3.5"})})})]})]}),e.jsxs("div",{className:"flex flex-col items-end gap-1 self-end shrink-0 ml-auto",children:[e.jsx("label",{htmlFor:"qty-mismatch",className:"text-xs font-medium text-muted-foreground leading-none cursor-pointer",children:t("orders.filter.quantity_changed",{defaultValue:"Ðзменено колиÑеÑÑво"})}),e.jsx("div",{className:"h-9 flex items-center",children:e.jsx(Tt,{id:"qty-mismatch",size:"md",color:"success",withText:!0,checked:He,onCheckedChange:Xe})})]})]}),ce>0&&e.jsxs("div",{className:"flex items-center gap-2 flex-wrap px-4 py-2 border-t border-border/60",children:[Ve.map(s=>e.jsx(rs,{chip:s,onDelete:()=>{var m;const a={...T,[s.groupKey]:((m=T[s.groupKey])!=null?m:[]).filter(h=>String(h)!==s.rawValue)};de(a)}},s.key)),e.jsx("button",{className:"ml-auto flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors",onClick:()=>de({}),children:e.jsx(Oe,{className:"size-3.5"})})]})]}),e.jsx(Ct,{id:"orders-list-header",top:"#header-sticky",zIndex:40,className:"bg-(--background-page)",children:e.jsx(Mt,{pagination:e.jsx(Rt,{isLoading:ie&&!D.length,page:f,perPage:N,totalCount:F,onChangePage:We}),info:e.jsx(It,{isLoading:ie&&!D.length,startItem:Ye,endItem:Ze,totalFilteredItems:F,totalItems:F,perPage:N,pageSizeOptions:ts,onPageSizeChange:et,formatText:()=>""})})}),e.jsx("div",{className:"bg-white rounded-xl overflow-clip",children:e.jsx($t,{items:D,isLoading:ie,stickyHeaderProps:{id:"orders-table-header",top:"#orders-list-header",zIndex:30}})}),e.jsx(Xt,{open:k,onClose:()=>P(!1),jobs:B,onCancel:Qe,onRelaunch:Je}),e.jsx(Bt,{title:t("orders.filter.title",{defaultValue:"ФилÑÑÑÑ"}),groups:le,value:_,onChange:U,renderItem:as,open:u,onOpenChange:G,singleSelect:!0,onApply:()=>de(_)})]})}const vs=ns;export{vs as component};
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.