PageSourceSearch

https://wedraw.kr/assets/ShippingFeeTrackingPage.DfVy4E8M.js

js wedraw.kr collected 2026-10-04 07:44:01 UTC 143,871 bytes, 21 lines download raw bytes

1import{j as t}from"./vendor-ui.BwPBmVwt.js";import{r as C,R as M}from"./vendor-react.kR8tqwKZ.js";import{c as Xs,s as re,bp as it,P as en,B as V,bd as Ne,be as je,bf as ve,X as Gt,bq as nt,br as tn,au as sn,ao as ke,O as nn}from"./index.86ltQqcV.js";import{u as an}from"./useTabParam.0zzDdGkW.js";import{T as rn,a as on,b as Ze,c as Ve}from"./tabs.B_vF9hjw.js";import{c as L}from"./utils.DalesSUU.js";import{u as Ht}from"./useQuery.CKEnFAuE.js";import{d as ln,e as cn,a as dn}from"./packagingFeeCalculator.Ds_FKGKV.js";import{s as Be,f as z,n as lt,o as Ut,q as ge,r as hn,u as mn,v as un,w as xn,x as zt,y as Kt,z as fn,A as gn,B as pn,C as yn,D as bn,E as Nn,F as Zt,G as jn,H as vn,I as Vt,J as wn,K as Mn,L as kn,M as Cn,N as Dn,O as _n,P as Sn,Q as On,R as Wn,S as Fn,U as Tn,V as Ln,W as In,X as En,d as pe}from"./vendor-utils.D2q0l15H.js";import{k as he}from"./ko.CSP0_8Uo.js";import{I as de}from"./input.Bn8hRSEL.js";import{C as We}from"./calendar.o8eP9MLv.js";import{S as An}from"./search.CoLV_vkF.js";import{P as we}from"./package.sYWGe6pn.js";import{u as Pn,A as Bn}from"./AdminWriteGuard.xT1R3h4-.js";import{R as Fe}from"./refresh-cw.BJ6elI4y.js";import{S as $n}from"./save.DyDnqxYS.js";import{I as Yn}from"./info.oSrbbhNg.js";import{T as Te}from"./truck.Cz6XYkxF.js";import{S as xe}from"./settings.Eoz354Vz.js";import{L as qn}from"./lock-open.DyYde3-e.js";import{L as Le}from"./lock.DKQK9Mbl.js";import{T as Ce}from"./triangle-alert.DiFS_pz6.js";import{T as Jt}from"./trash-2.DYInpbaD.js";import{P as Qt}from"./plus.VSSFQhJP.js";import{C as Xt}from"./circle-check.C2VxFn-u.js";import{C as at}from"./circle-x.CdkrLera.js";import{T as Ie}from"./trending-up.DrO9OvSf.js";import{T as Me}from"./trending-down.HWXfzOr_.js";import{A as rt}from"./arrow-right.BJDjibZk.js";import{L as es}from"./lightbulb.D5sQEORT.js";import{G as Rn}from"./grid-3x3.MTklan2N.js";import{C as Gn}from"./chevron-down.8Oyg22r0.js";import{C as Hn}from"./chevron-right.BO4QQ722.js";import{C as Ee}from"./chart-column.wBcVfGnD.js";import{M as jt}from"./minus.-470SVQC.js";import"./vendor-three.C5-HLXBy.js";const Un=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M16 8h-6a2 2 0 1 0 0 4h4a2 2 0 1 1 0 4H8",key:"1h4pet"}],["path",{d:"M12 18V6",key:"zqpxq5"}]],zn=Xs("circle-dollar-sign",Un),fe=500,Kn={cj:"CJ",chunil:"천일",kyungdong:"경동"},ts={cj:"CJ대한통운",chunil:"천일택배",kyungdong:"경동택배"},Zn={CJ대한통운:"cj",천일택배:"chunil",경동택배:"kyungdong"},Vn=[{label:"최근 7일",days:7},{label:"최근 14일",days:14},{label:"최근 30일",days:30},{label:"최근 60일",days:60}],Je=1e3;async function Jn(e,s){const a=[];let n=0;for(;;){const{data:r,error:o}=await re.from("tp_order").select("id, order_code, order_date, shipping_company, item_invoices, user_name, phone_number, shipping_fee").gte("order_date",e).lte("order_date",s).range(n,n+Je-1);if(o)throw o;if(!r||r.length===0||(a.push(...r),r.length<Je))break;n+=Je}return a}async function Qn(e){const s=[];for(let a=0;a<e.length;a+=fe){const n=e.slice(a,a+fe),{data:r,error:o}=await re.from("tp_order_mapping").select(`
2        internal_order_id,
3        request_order_id,
4        ln_order_requests!inner (
5          is_matched,
6          customer_name,
7          customer_phone,
8          wood_subtotal,
9          accessory_subtotal,
10          packaging_fee,
11          total_amount,
12          request_data
13        )
14      `).in("internal_order_id",n);if(o)throw o;r&&s.push(...r)}return s}async function Xn(e){const s=[];for(let a=0;a<e.length;a+=fe){const n=e.slice(a,a+fe),{data:r,error:o}=await re.from("tp_order_items").select("order_id, customer_width, customer_depth, quantity, manufacturing_specs, product_id").in("order_id",n);!o&&r&&s.push(...r)}return s}async function ea(e){const s=[],a=[...new Set(e)];for(let n=0;n<a.length;n+=fe){const r=a.slice(n,n+fe),{data:o,error:i}=await re.from("ln_shipping_invoice").select("*").in("order_code",r).order("invoice_seq",{ascending:!0});!i&&o&&s.push(...o)}return s}const ta=["admin","shippingFeeTracking"];function sa(){const[e,s]=C.useState(""),[a,n]=C.useState(!1),[r,o]=C.useState("all"),[i,l]=C.useState({from:Be(new Date,14),to:new Date}),{data:c=[],isLoading:h}=Ht({queryKey:[...ta,i.from?.toISOString(),i.to?.toISOString()],queryFn:async()=>
14{if(!i.from||!i.to)return[];const m=z(lt(i.from),"yyyy-MM-dd"),u=z(Ut(i.to),"yyyy-MM-dd"),g=await Jn(m,u);if(g.length===0)return[];const N=g.map(v=>v.id),y=new Map(g.map(v=>[v.id,v])),w=await Qn(N),f=w.map(v=>y.get(v.internal_order_id)?.order_code).filter(Boolean),p=new Map;for(const v of g){const F=v.item_invoices||[];if(F.length>0){const O=F.filter(E=>E.shipping_company).map((E,Y)=>({invoice_seq:Y+1,carrier:Zn[E.shipping_company]||"cj",recipient_name:"",recipient_phone:"",actual_fee:E.actual_fee!=null&&E.actual_fee>0?E.actual_fee:null}));O.length>0&&p.set(v.order_code,O)}}const k=f.filter(v=>!p.has(v));k.length>0&&(await ea(k)).forEach(F=>{const O=p.get(F.order_code)||[];O.push({invoice_seq:F.invoice_seq,carrier:F.carrier,recipient_name:F.recipient_name,recipient_phone:F.recipient_phone,actual_fee:F.actual_fee}),p.set(F.order_code,O)});const j=new Map,b=new Map,_=new Set;w.forEach(v=>{const F=y.get(v.internal_order_id),O=F?.order_code||"";if(!O)return;const E=p.get(O)||[],Y=E.reduce((B,K)=>B+(K.actual_fee??0),0),R=!_.has(v.request_order_id);if(v.request_order_id&&_.add(v.request_order_id),R){const K=v.ln_order_requests.request_data?.wood_items||[];if(K.length>0){const Z=b.get(O)||[];Z.push(...K.map(G=>({width:G.width||0,length:G.length||0,thickness:G.thickness||18,density:G.density??null,quantity:G.quantity||1}))),b.set(O,Z)}}const H=j.get(O);H?(H.mappingCount+=1,R&&(H.wood_subtotal+=v.ln_order_requests.wood_subtotal||0,H.accessory_subtotal+=v.ln_order_requests.accessory_subtotal||0,H.packaging_fee+=v.ln_order_requests.packaging_fee||0,H.total_amount+=v.ln_order_requests.total_amount||0)):j.set(O,{order_code:O,order_date:F?.order_date||"",internal_order_id:v.internal_order_id,request_order_id:v.request_order_id,is_matched:v.ln_order_requests.is_matched,customer_name:v.ln_order_requests.customer_name,customer_phone:v.ln_order_requests.customer_phone,mappingCount:1,wood_subtotal:v.ln_order_requests.wood_subtotal||0,accessory_subtotal:v.ln_order_requests.accessory_subtotal||0,packaging_fee:v.ln_order_requests.packaging_fee||0,shipping_company:F?.shipping_company||"",total_amount:v.ln_order_requests.total_amount||0,invoices:E,actualFeeTotal:Y,currentLogicFee:null,currentLogicBreakdown:null})});const T=[];for(const v of g){const F=v.order_code;if(j.has(F))continue;T.push(v.id);const O=p.get(F)||[],E=O.reduce((Y,R)=>Y+(R.actual_fee??0),0);j.set(F,{order_code:F,order_date:v.order_date||"",internal_order_id:v.id,request_order_id:0,is_matched:!1,customer_name:v.user_name||"",customer_phone:v.phone_number||"",mappingCount:0,wood_subtotal:0,accessory_subtotal:0,packaging_fee:v.shipping_fee||0,shipping_company:v.shipping_company||"",total_amount:0,invoices:O,actualFeeTotal:E,currentLogicFee:null,currentLogicBreakdown:null})}if(T.length>0){const v=await Xn(T),F=new Map(g.map(O=>[O.id,O.order_code]));for(const O of v){if(O.product_id==="prod_cut_accessory")continue;const E=F.get(O.order_id);if(!E)continue;const Y=O.customer_width||O.manufacturing_specs?.width||0,R=O.customer_depth||O.manufacturing_specs?.length||0;if(!Y||!R)continue;const H=O.manufacturing_specs?.thickness||O.manufacturing_specs?.options?.thickness||18,B={width:Y,length:R,thickness:H,density:O.manufacturing_specs?.density??null,quantity:O.quantity||1},K=b.get(E)||[];K.push(B),b.set(E,K)}}await it();for(const[v,F]of j){const O=b.get(v);if(O&&O.length>0){const E=ln(O);E&&(F.currentLogicFee=E.fee,F.currentLogicBreakdown=E)}}const $=Array.from(j.values());return $.sort((v,F)=>v.order_date?F.order_date?new Date(F.order_date).getTime()-new Date(v.order_date).getTime():-1:1),$}}),d=C.useMemo(()=>{let m=c;if(e){const u=e.toLowerCase();m=m.filter(g=>g.order_code.toLowerCase().includes(u)||g.customer_name.toLowerCase().includes(u)||g.customer_phone.includes(u))}return a&&(m=m.filter(u=>u.actualFeeTotal>0)),r!=="all"&&(m=m.filter(u=>u.invoices.some(g=>g.carrier===r))),m},[c,e,a,r]),x=C.useMemo(()=>{const m=d.filter(_=>_.actualFeeTotal>0),u=d.filter(_=>_.invoices.length>1).length,g=m.reduce((_,T)=>_+(T.packaging_fee||0),0),N=m.reduce((_,T)=>_+T.actualFeeTotal,0),y=g-N,w=g>0?y/g*100:0,f=m.filter(_=>_.currentLogicFee!=null),p=f.reduce((_,T)=>_+(T.currentLogicFee??0),0),k=f.reduce((_,T)=>_+T.actualFeeTotal,0),j=p-k,b=p>0?j/p*100:0;return{totalOrders:d.length,matchedWithExcel:m.length,unmatchedWithExcel:d.length-m.length,multipleShipments:u,expectedFeeTotal:g,actualFeeTotal:N,feeDifference:y,differencePercent:w,currentLogicFeeTotal:p,currentLogicDifference:j,currentLogicDiffPercent:b,currentLogicMatchedCount:f.length}},[d]);return{orders:c,filteredOrders:d,loading:h,searchTerm:e,setSearchTerm:s,showOnlyMatched:a,setShowOnlyMatched:n,carrierFilter:r,setCarrierFilter:o,dateRange:i,setDateRange:l,stats:x}}function na(e,s,a="long"){return new Intl.DateTimeFormat("en-US",{hour:"numeric",timeZone:e,timeZoneName:a}).format(s).split(/\s/g).slice(2).join(" ")}const aa={},be={};function me(e,s){try{const n=(aa[e]||=new Intl.DateTimeFormat("en-US",{timeZone:e,timeZoneName:"longOffset"}).format)(s).split("GMT")[1];return n in be?be[n]:vt(n,n.split(":"))}catch{if(e in be)return be[e];const a=e?.match(ra);return a?vt(e,a.slice(1)):NaN}}const ra=/([+-]\d\d):?(\d\d)?/;function vt(e,s){const a=+(s[0]||0),n=+(s[1]||0),r=+(s[2]||0)/60;return be[e]=a*60+n>0?a*60+n+r:a*60-n-r}class ae extends Date{constructor(...s){super(),s.length>1&&typeof s[s.length-1]=="string"&&(this.timeZone=s.pop()),this.internal=new Date,isNaN(me(this.timeZone,this))?this.setTime(NaN):s.length?typeof s[0]=="number"&&(s.length===1||s.length===2&&typeof s[1]!="number")?this.setTime(s[0]):typeof s[0]=="string"?this.setTime(+new Date(s[0])):s[0]instanceof Date?this.setTime(+s[0]):(this.setTime(+new Date(...s)),ss(this),ot(this)):this.setTime(Date.now())}static tz(s,...a){return a.length?new ae(...a,s):new ae(Date.now(),s)}withTimeZone(s){return new ae(+this,s)}getTimezoneOffset(){const s=-me(this.timeZone,this);return s>0?Math.floor(s):Math.ceil(s)}setTime(s){return Date.prototype.setTime.apply(this,arguments),ot(this),+this}[Symbol.for("constructDateFrom")](s){return new ae(+new Date(s),this.timeZone)}}const wt=/^(get|set)(?!UTC)/;
vendor: 4,813 bytes, line 14
14Object.getOwnPropertyNames(Date.prototype).forEach(e=>{if(!wt.test(e))return;const s=e.replace(wt,"$1UTC");ae.prototype[s]&&(e.startsWith("get")?ae.prototype[e]=function(){return this.internal[s]()}:(ae.prototype[e]=function(){return Date.prototype[s].apply(this.internal,arguments),oa(this),+this},ae.prototype[s]=function(){return Date.prototype[s].apply(this,arguments),ot(this),+this}))});function ot(e){e.internal.setTime(+e),e.internal.setUTCSeconds(e.internal.getUTCSeconds()-Math.round(-me(e.timeZone,e)*60))}function oa(e){Date.prototype.setFullYear.call(e,e.internal.getUTCFullYear(),e.internal.getUTCMonth(),e.internal.getUTCDate()),Date.prototype.setHours.call(e,e.internal.getUTCHours(),e.internal.getUTCMinutes(),e.internal.getUTCSeconds(),e.internal.getUTCMilliseconds()),ss(e)}function ss(e){const s=me(e.timeZone,e),a=s>0?Math.floor(s):Math.ceil(s),n=new Date(+e);n.setUTCHours(n.getUTCHours()-1);const r=-new Date(+e).getTimezoneOffset(),o=-new Date(+n).getTimezoneOffset(),i=r-o,l=Date.prototype.getHours.apply(e)!==e.internal.getUTCHours();i&&l&&e.internal.setUTCMinutes(e.internal.getUTCMinutes()+i);const c=r-a;c&&Date.prototype.setUTCMinutes.call(e,Date.prototype.getUTCMinutes.call(e)+c);const h=new Date(+e);h.setUTCSeconds(0);const d=r>0?h.getSeconds():(h.getSeconds()-60)%60,x=Math.round(-(me(e.timeZone,e)*60))%60;(x||d)&&(e.internal.setUTCSeconds(e.internal.getUTCSeconds()+x),Date.prototype.setUTCSeconds.call(e,Date.prototype.getUTCSeconds.call(e)+x+d));const m=me(e.timeZone,e),u=m>0?Math.floor(m):Math.ceil(m),N=-new Date(+e).getTimezoneOffset()-u,y=u!==a,w=N-c;if(y&&w){Date.prototype.setUTCMinutes.call(e,Date.prototype.getUTCMinutes.call(e)+w);const f=me(e.timeZone,e),p=f>0?Math.floor(f):Math.ceil(f),k=u-p;k&&(e.internal.setUTCMinutes(e.internal.getUTCMinutes()+k),Date.prototype.setUTCMinutes.call(e,Date.prototype.getUTCMinutes.call(e)+k))}}class U extends ae{static tz(s,...a){return a.length?new U(...a,s):new U(Date.now(),s)}toISOString(){const[s,a,n]=this.tzComponents(),r=`${s}${a}:${n}`;return this.internal.toISOString().slice(0,-1)+r}toString(){return`${this.toDateString()} ${this.toTimeString()}`}toDateString(){const[s,a,n,r]=this.internal.toUTCString().split(" ");return`${s?.slice(0,-1)} ${n} ${a} ${r}`}toTimeString(){const s=this.internal.toUTCString().split(" ")[4],[a,n,r]=this.tzComponents();return`${s} GMT${a}${n}${r} (${na(this.timeZone,this)})`}toLocaleString(s,a){return Date.prototype.toLocaleString.call(this,s,{...a,timeZone:a?.timeZone||this.timeZone})}toLocaleDateString(s,a){return Date.prototype.toLocaleDateString.call(this,s,{...a,timeZone:a?.timeZone||this.timeZone})}toLocaleTimeString(s,a){return Date.prototype.toLocaleTimeString.call(this,s,{...a,timeZone:a?.timeZone||this.timeZone})}tzComponents(){const s=this.getTimezoneOffset(),a=s>0?"-":"+",n=String(Math.floor(Math.abs(s)/60)).padStart(2,"0"),r=String(Math.abs(s)%60).padStart(2,"0");return[a,n,r]}withTimeZone(s){return new U(+this,s)}[Symbol.for("constructDateFrom")](s){return new U(+new Date(s),this.timeZone)}}const Mt=5,ia=4;function la(e,s){const a=s.startOfMonth(e),n=a.getDay()>0?a.getDay():7,r=s.addDays(e,-n+1),o=s.addDays(r,Mt*7-1);return s.getMonth(e)===s.getMonth(o)?Mt:ia}function ns(e,s){const a=s.startOfMonth(e),n=a.getDay();return n===1?a:n===0?s.addDays(a,-6):s.addDays(a,-1*(n-1))}function ca(e,s){const a=ns(e,s),n=la(e,s);return s.addDays(a,n*7-1)}const as={...ge,labels:{labelDayButton:(e,s,a,n)=>{let r;n&&typeof n.format=="function"?r=n.format.bind(n):r=(i,l)=>z(i,l,{locale:ge,...a});let o=r(e,"PPPP");return s.today&&(o=`Today, ${o}`),s.selected&&(o=`${o}, selected`),o},labelMonthDropdown:"Choose the Month",labelNext:"Go to the Next Month",labelPrevious:"Go to the Previous Month",labelWeekNumber:e=>`Week ${e}`,labelYearDropdown:"Choose the Year",labelGrid:(e,s,a)=>{let n;return a&&typeof a.format=="function"?n=a.format.bind(a):n=(r,o)=>z(r,o,{locale:ge,...s}),n(e,"LLLL yyyy")},labelGridcell:(e,s,a,n)=>{let r;n&&typeof n.format=="function"?r=n.format.bind(n):r=(i,l)=>z(i,l,{locale:ge,...a});let o=r(e,"PPPP");return s?.today&&(o=`Today, ${o}`),o},labelNav:"Navigation bar",labelWeekNumberHeader:"Week Number",labelWeekday:(e,s,a)=>{let n;return a&&typeof a.format=="function"?n=a.format.bind(a):n=(r,o)=>z(r,o,{locale:ge,...s}),n(e,"cccc")}}};class X{constructor(s,a){this.Date=Date,this.today=()=>this.overrides?.today?this.overrides.today():this.options.timeZone?U.tz(this.options.timeZone):new this.Date,this.newDate=(n,r,o)=>this.overrides?.newDate?this.overrides.newDate(n,r,o):this.options.timeZone?new U(n,r,o,this.options.timeZone):new Date(n,r,o),this.addDays=(n,r)=>this.overrides?.addDays?this.overrides.addDays(n,r):hn(n,r),this.addMonths=(n,r)=>this.overrides?.addMonths?this.overrides.addMonths(n,r):mn(n,r),this.addWeeks=(n,r)=>
14this.overrides?.addWeeks?this.overrides.addWeeks(n,r):un(n,r),this.addYears=(n,r)=>this.overrides?.addYears?this.overrides.addYears(n,r):xn(n,r),this.differenceInCalendarDays=(n,r)=>this.overrides?.differenceInCalendarDays?this.overrides.differenceInCalendarDays(n,r):zt(n,r),this.differenceInCalendarMonths=(n,r)=>this.overrides?.differenceInCalendarMonths?this.overrides.differenceInCalendarMonths(n,r):Kt(n,r),this.eachMonthOfInterval=n=>this.overrides?.eachMonthOfInterval?this.overrides.eachMonthOfInterval(n):fn(n),this.eachYearOfInterval=n=>{const r=this.overrides?.eachYearOfInterval?this.overrides.eachYearOfInterval(n):gn(n),o=new Set(r.map(l=>this.getYear(l)));if(o.size===r.length)return r;const i=[];return o.forEach(l=>{i.push(new Date(l,0,1))}),i},this.endOfBroadcastWeek=n=>this.overrides?.endOfBroadcastWeek?this.overrides.endOfBroadcastWeek(n):ca(n,this),this.endOfISOWeek=n=>this.overrides?.endOfISOWeek?this.overrides.endOfISOWeek(n):pn(n),this.endOfMonth=n=>this.overrides?.endOfMonth?this.overrides.endOfMonth(n):yn(n),this.endOfWeek=(n,r)=>this.overrides?.endOfWeek?this.overrides.endOfWeek(n,r):bn(n,this.options),this.endOfYear=n=>this.overrides?.endOfYear?this.overrides.endOfYear(n):Nn(n),this.format=(n,r,o)=>{const i=this.overrides?.format?this.overrides.format(n,r,this.options):z(n,r,this.options);return this.options.numerals&&this.options.numerals!=="latn"?this.replaceDigits(i):i},this.getISOWeek=n=>this.overrides?.getISOWeek?this.overrides.getISOWeek(n):Zt(n),this.getMonth=(n,r)=>this.overrides?.getMonth?this.overrides.getMonth(n,this.options):jn(n,this.options),this.getYear=(n,r)=>this.overrides?.getYear?this.overrides.getYear(n,this.options):vn(n,this.options),this.getWeek=(n,r)=>this.overrides?.getWeek?this.overrides.getWeek(n,this.options):Vt(n,this.options),this.isAfter=(n,r)=>this.overrides?.isAfter?this.overrides.isAfter(n,r):wn(n,r),this.isBefore=(n,r)=>this.overrides?.isBefore?this.overrides.isBefore(n,r):Mn(n,r),this.isDate=n=>this.overrides?.isDate?this.overrides.isDate(n):kn(n),this.isSameDay=(n,r)=>this.overrides?.isSameDay?this.overrides.isSameDay(n,r):Cn(n,r),this.isSameMonth=(n,r)=>this.overrides?.isSameMonth?this.overrides.isSameMonth(n,r):Dn(n,r),this.isSameYear=(n,r)=>this.overrides?.isSameYear?this.overrides.isSameYear(n,r):_n(n,r),this.max=n=>this.overrides?.max?this.overrides.max(n):Sn(n),this.min=n=>this.overrides?.min?this.overrides.min(n):On(n),this.setMonth=(n,r)=>this.overrides?.setMonth?this.overrides.setMonth(n,r):Wn(n,r),this.setYear=(n,r)=>this.overrides?.setYear?this.overrides.setYear(n,r):Fn(n,r),this.startOfBroadcastWeek=(n,r)=>this.overrides?.startOfBroadcastWeek?this.overrides.startOfBroadcastWeek(n,this):ns(n,this),this.startOfDay=n=>this.overrides?.startOfDay?this.overrides.startOfDay(n):lt(n),this.startOfISOWeek=n=>this.overrides?.startOfISOWeek?this.overrides.startOfISOWeek(n):Tn(n),this.startOfMonth=n=>this.overrides?.startOfMonth?this.overrides.startOfMonth(n):Ln(n),this.startOfWeek=(n,r)=>this.overrides?.startOfWeek?this.overrides.startOfWeek(n,this.options):In(n,this.options),this.startOfYear=n=>this.overrides?.startOfYear?this.overrides.startOfYear(n):En(n),this.options={locale:as,...s},this.overrides=a}getDigitMap(){const{numerals:s="latn"}=this.options,a=new Intl.NumberFormat("en-US",{numberingSystem:s}),n={};for(let r=0;r<10;r++)n[r.toString()]=a.format(r);return n}replaceDigits(s){const a=this.getDigitMap();return s.replace(/\d/g,n=>a[n]||n)}formatNumber(s){return this.replaceDigits(s.toString())}getMonthYearOrder(){const s=this.options.locale?.code;return s&&X.yearFirstLocales.has(s)?"year-first":"month-first"}formatMonthYear(s){const{locale:a,timeZone:n,numerals:r}=this.options,o=a?.code;if(o&&X.yearFirstLocales.has(o))try{return new Intl.DateTimeFormat(o,{month:"long",year:"numeric",timeZone:n,numberingSystem:r}).format(s)}catch{}const i=this.getMonthYearOrder()==="year-first"?"y LLLL":"LLLL y";return this.format(s,i)}}X.yearFirstLocales=new Set(["eu","hu","ja","ja-Hira","ja-JP","ko","ko-KR","lt","lt-LT","lv","lv-LV","mn","mn-MN","zh","zh-CN","zh-HK","zh-TW"]);const oe=new X;class rs{constructor(s,a,n=oe){this.date=s,this.displayMonth=a,this.outside=!!(a&&!n.isSameMonth(s,a)),this.dateLib=n,this.isoDate=n.format(s,"yyyy-MM-dd"),this.displayMonthId=n.format(a,"yyyy-MM"),this.dateMonthId=n.format(s,"yyyy-MM")}isEqualTo(s){return this.dateLib.isSameDay(s.date,this.date)&&this.dateLib.isSameMonth(s.displayMonth,this.displayMonth)}}class da{constructor(s,a){this.date=s,this.weeks=a}}class ha{constructor(s,a){this.days=a,this.weekNumber=s}}function ma(e){return M.createElement("button",{...e})}function ua(e){return M.createElement("span",{...e})}function xa(e){const{size:s=24,orientation:a="left",className:n}=e;return M.createElement("svg",{className:n,width:s,height:s,viewBox:"0 0 24 24"},a==="up"&&M.createElement("polygon",{points:"6.77 17 12.5 11.43 18.24 17 20 15.28 12.5 8 5 15.28"}),a==="down"&&M.createElement("polygon",{points:"6.77 8 12.5 13.57 18.24 8 20 9.72 12.5 17 5 9.72"}),a==="left"&&M.createElement("polygon",{points:"16 18.112 9.81111111 12 16 5.87733333 14.0888889 4 6 12 14.0888889 20"}),a==="right"&&M.createElement("polygon",{points:"8 18.112 14.18888889 12 8 5.87733333 9.91111111 4 18 12 9.91111111 20"}))}function fa(e){const{day:s,modifiers:a,...n}=e;return M.createElement("td",{...n})}function ga(e){const{day:s,modifiers:a,...n}=e,r=M.useRef(null);return M.useEffect(()=>{a.focused&&r.current?.focus()},[a.focused]),M.createElement("button",{ref:r,...n})}var D;(function(e){e.Root="root",e.Chevron="chevron",e.Day="day",e.DayButton="day_button",e.CaptionLabel="caption_label",e.Dropdowns="dropdowns",e.Dropdown="dropdown",e.DropdownRoot="dropdown_root",e.Footer="footer",e.MonthGrid="month_grid",e.MonthCaption="month_caption",e.MonthsDropdown="months_dropdown",e.Month="month",e.Months="months",e.Nav="nav",e.NextMonthButton="button_next",e.PreviousMonthButton="button_previous",e.Week="week",e.Weeks="weeks",e.Weekday="weekday",e.Weekdays="weekdays",e.WeekNumber="week_number",e.WeekNumberHeader="week_number_header",e.YearsDropdown="years_dropdown"})(D||(D={}));var q;(function(e){e.disabled="disabled",e.hidden="hidden",e.outside="outside",e.focused="focused",e.today="today"})(q||(q={}));var se;(function(e){e.range_end="range_end",e.range_middle="range_middle",e.range_start="range_start",e.selected="selected"})(se||(se={}));var Q;(function(e){e.weeks_before_enter="weeks_before_enter",e.weeks_before_exit="weeks_before_exit",e.weeks_after_enter="weeks_after_enter",e.weeks_after_exit="weeks_after_exit",e.caption_after_enter="caption_after_enter",e.caption_after_exit="caption_after_exit",e.caption_before_enter="caption_before_enter",e.caption_before_exit="caption_before_exit"})(Q||(Q={}));function pa(e){const{options:s,className:a,components:n,classNames:r,...o}=e,i=[r[D.Dropdown],a].join(" "),l=s?.find(({value:c})=>c===o.value);return M.createElement("span",{"data-disabled":o.disabled,className:r[D.DropdownRoot]},M.createElement(n.Select,{className:i,...o},s?.map(({value:c,label:h,disabled:d})=>M.createElement(n.Option,{key:c,value:c,disabled:d},h))),M.createElement("span",{className:r[D.CaptionLabel],"aria-hidden":!0},l?.label,M.createElement(n.Chevron,{orientation:"down",size:18,className:r[D.Chevron]}
vendor: 4,287 bytes, line 14
14)))}function ya(e){return M.createElement("div",{...e})}function ba(e){return M.createElement("div",{...e})}function Na(e){const{calendarMonth:s,displayIndex:a,...n}=e;return M.createElement("div",{...n},e.children)}function ja(e){const{calendarMonth:s,displayIndex:a,...n}=e;return M.createElement("div",{...n})}function va(e){return M.createElement("table",{...e})}function wa(e){return M.createElement("div",{...e})}const os=C.createContext(void 0);function De(){const e=C.useContext(os);if(e===void 0)throw new Error("useDayPicker() must be used within a custom component.");return e}function Ma(e){const{components:s}=De();return M.createElement(s.Dropdown,{...e})}function ka(e){const{onPreviousClick:s,onNextClick:a,previousMonth:n,nextMonth:r,...o}=e,{components:i,classNames:l,labels:{labelPrevious:c,labelNext:h}}=De(),d=C.useCallback(m=>{r&&a?.(m)},[r,a]),x=C.useCallback(m=>{n&&s?.(m)},[n,s]);return M.createElement("nav",{...o},M.createElement(i.PreviousMonthButton,{type:"button",className:l[D.PreviousMonthButton],tabIndex:n?void 0:-1,"aria-disabled":n?void 0:!0,"aria-label":c(n),onClick:x},M.createElement(i.Chevron,{disabled:n?void 0:!0,className:l[D.Chevron],orientation:"left"})),M.createElement(i.NextMonthButton,{type:"button",className:l[D.NextMonthButton],tabIndex:r?void 0:-1,"aria-disabled":r?void 0:!0,"aria-label":h(r),onClick:d},M.createElement(i.Chevron,{disabled:r?void 0:!0,orientation:"right",className:l[D.Chevron]})))}function Ca(e){const{components:s}=De();return M.createElement(s.Button,{...e})}function Da(e){return M.createElement("option",{...e})}function _a(e){const{components:s}=De();return M.createElement(s.Button,{...e})}function Sa(e){const{rootRef:s,...a}=e;return M.createElement("div",{...a,ref:s})}function Oa(e){return M.createElement("select",{...e})}function Wa(e){const{week:s,...a}=e;return M.createElement("tr",{...a})}function Fa(e){return M.createElement("th",{...e})}function Ta(e){return M.createElement("thead",{"aria-hidden":!0},M.createElement("tr",{...e}))}function La(e){const{week:s,...a}=e;return M.createElement("th",{...a})}function Ia(e){return M.createElement("th",{...e})}function Ea(e){return M.createElement("tbody",{...e})}function Aa(e){const{components:s}=De();return M.createElement(s.Dropdown,{...e})}const Pa=Object.freeze(Object.defineProperty({__proto__:null,Button:ma,CaptionLabel:ua,Chevron:xa,Day:fa,DayButton:ga,Dropdown:pa,DropdownNav:ya,Footer:ba,Month:Na,MonthCaption:ja,MonthGrid:va,Months:wa,MonthsDropdown:Ma,Nav:ka,NextMonthButton:Ca,Option:Da,PreviousMonthButton:_a,Root:Sa,Select:Oa,Week:Wa,WeekNumber:La,WeekNumberHeader:Ia,Weekday:Fa,Weekdays:Ta,Weeks:Ea,YearsDropdown:Aa},Symbol.toStringTag,{value:"Module"}));function le(e,s,a=!1,n=oe){let{from:r,to:o}=e;const{differenceInCalendarDays:i,isSameDay:l}=n;return r&&o?(i(o,r)<0&&([r,o]=[o,r]),i(s,r)>=(a?1:0)&&i(o,s)>=(a?1:0)):!a&&o?l(o,s):!a&&r?l(r,s):!1}function ct(e){return!!(e&&typeof e=="object"&&"before"in e&&"after"in e)}function $e(e){return!!(e&&typeof e=="object"&&"from"in e)}function dt(e){return!!(e&&typeof e=="object"&&"after"in e)}function ht(e){return!!(e&&typeof e=="object"&&"before"in e)}function is(e){return!!(e&&typeof e=="object"&&"dayOfWeek"in e)}function ls(e,s){return Array.isArray(e)&&e.every(s.isDate)}function ce(e,s,a=oe){const n=Array.isArray(s)?s:[s],{isSameDay:r,differenceInCalendarDays:o,isAfter:i}=a;return n.some(l=>{if(typeof l=="boolean")return l;if(a.isDate(l))return r(e,l);if(ls(l,a))return l.some(c=>r(e,c));if($e(l))return le(l,e,!1,a);if(is(l))return Array.isArray(l.dayOfWeek)?l.dayOfWeek.includes(e.getDay()):l.dayOfWeek===e.getDay();if(ct(l)){const c=o(l.before,e),h=o(l.after,e),d=c>0,x=h<0;return i(l.before,l.after)?x&&d:d||x}return dt(l)?o(e,l.after)>0:ht(l)?o(l.before,e)>0:typeof l=="function"?l(e):!1})}function Ba(e,s,a,n,r){const{disabled:o,hidden:i,modifiers:l,showOutsideDays:c,broadcastCalendar:h,today:d=r.today()}=s,{isSameDay:x,isSameMonth:m,startOfMonth:u,isBefore:g,endOfMonth:N,isAfter:y}=r,w=a&&u(a),f=n&&N(n),p={[q.focused]:[],[q.outside]:[],[q.disabled]:[],[q.hidden]:[],[q.today]:[]},k={};for(const j of e){const{date:b,displayMonth:_}=j,T=!!(_&&!m(b,_)),$=!!(w&&g(b,w)),v=!!(f&&y(b,f)),F=!!(o&&ce(b,o,r)),O=!!(i&&ce(b,i,r))||$||v||!h&&!c&&T||h&&c===!1&&T,E=x(b,d);
14T&&p.outside.push(j),F&&p.disabled.push(j),O&&p.hidden.push(j),E&&p.today.push(j),l&&Object.keys(l).forEach(Y=>{const R=l?.[Y];R&&ce(b,R,r)&&(k[Y]?k[Y].push(j):k[Y]=[j])})}return j=>{const b={[q.focused]:!1,[q.disabled]:!1,[q.hidden]:!1,[q.outside]:!1,[q.today]:!1},_={};for(const T in p){const $=p[T];b[T]=$.some(v=>v===j)}for(const T in k)_[T]=k[T].some($=>$===j);return{...b,..._}}}function $a(e,s,a={}){return Object.entries(e).filter(([,r])=>r===!0).reduce((r,[o])=>(a[o]?r.push(a[o]):s[q[o]]?r.push(s[q[o]]):s[se[o]]&&r.push(s[se[o]]),r),[s[D.Day]])}function Ya(e){return{...Pa,...e}}function qa(e){const s={"data-mode":e.mode??void 0,"data-required":"required"in e?e.required:void 0,"data-multiple-months":e.numberOfMonths&&e.numberOfMonths>1||void 0,"data-week-numbers":e.showWeekNumber||void 0,"data-broadcast-calendar":e.broadcastCalendar||void 0,"data-nav-layout":e.navLayout||void 0};return Object.entries(e).forEach(([a,n])=>{a.startsWith("data-")&&(s[a]=n)}),s}function Ra(){const e={};for(const s in D)e[D[s]]=`rdp-${D[s]}`;for(const s in q)e[q[s]]=`rdp-${q[s]}`;for(const s in se)e[se[s]]=`rdp-${se[s]}`;for(const s in Q)e[Q[s]]=`rdp-${Q[s]}`;return e}function cs(e,s,a){return(a??new X(s)).formatMonthYear(e)}const Ga=cs;function Ha(e,s,a){return(a??new X(s)).format(e,"d")}function Ua(e,s=oe){return s.format(e,"LLLL")}function za(e,s,a){return(a??new X(s)).format(e,"cccccc")}function Ka(e,s=oe){return e<10?s.formatNumber(`0${e.toLocaleString()}`):s.formatNumber(`${e.toLocaleString()}`)}function Za(){return""}function ds(e,s=oe){return s.format(e,"yyyy")}const Va=ds,Ja=Object.freeze(Object.defineProperty({__proto__:null,formatCaption:cs,formatDay:Ha,formatMonthCaption:Ga,formatMonthDropdown:Ua,formatWeekNumber:Ka,formatWeekNumberHeader:Za,formatWeekdayName:za,formatYearCaption:Va,formatYearDropdown:ds},Symbol.toStringTag,{value:"Module"}));function Qa(e){return e?.formatMonthCaption&&!e.formatCaption&&(e.formatCaption=e.formatMonthCaption),e?.formatYearCaption&&!e.formatYearDropdown&&(e.formatYearDropdown=e.formatYearCaption),{...Ja,...e}}function mt(e,s,a,n){let r=(n??new X(a)).format(e,"PPPP");return s.today&&(r=`Today, ${r}`),s.selected&&(r=`${r}, selected`),r}const Xa=mt;function ut(e,s,a){return(a??new X(s)).formatMonthYear(e)}const er=ut;function hs(e,s,a,n){let r=(n??new X(a)).format(e,"PPPP");return s?.today&&(r=`Today, ${r}`),r}function ms(e){return"Choose the Month"}function us(){return""}const tr="Go to the Next Month";function xs(e,s){return tr}function fs(e){return"Go to the Previous Month"}function gs(e,s,a){return(a??new X(s)).format(e,"cccc")}function ps(e,s){return`Week ${e}`}function ys(e){return"Week Number"}function bs(e){return"Choose the Year"}const sr=Object.freeze(Object.defineProperty({__proto__:null,labelCaption:er,labelDay:Xa,labelDayButton:mt,labelGrid:ut,labelGridcell:hs,labelMonthDropdown:ms,labelNav:us,labelNext:xs,labelPrevious:fs,labelWeekNumber:ps,labelWeekNumberHeader:ys,labelWeekday:gs,labelYearDropdown:bs},Symbol.toStringTag,{value:"Module"})),te=(e,s,a)=>s||(a?typeof a=="function"?a:(...n)=>a:e);function nr(e,s){const a=s.locale?.labels??{};return{...sr,...e??{},labelDayButton:te(mt,e?.labelDayButton,a.labelDayButton),labelMonthDropdown:te(ms,e?.labelMonthDropdown,a.labelMonthDropdown),labelNext:te(xs,e?.labelNext,a.labelNext),labelPrevious:te(fs,e?.labelPrevious,a.labelPrevious),labelWeekNumber:te(ps,e?.labelWeekNumber,a.labelWeekNumber),labelYearDropdown:te(bs,e?.labelYearDropdown,a.labelYearDropdown),labelGrid:te(ut,e?.labelGrid,a.labelGrid),labelGridcell:te(hs,e?.labelGridcell,a.labelGridcell),labelNav:te(us,e?.labelNav,a.labelNav),labelWeekNumberHeader:te(ys,e?.labelWeekNumberHeader,a.labelWeekNumberHeader),labelWeekday:te(gs,e?.labelWeekday,a.labelWeekday)}}function ar(e,s,a,n,r){const{startOfMonth:o,startOfYear:i,endOfYear:l,eachMonthOfInterval:c,getMonth:h}=r;return c({start:i(e),end:l(e)}).map(m=>{const u=n.formatMonthDropdown(m,r),g=h(m),N=s&&m<o(s)||a&&m>o(a)||!1;return{value:g,label:u,disabled:N}})}function rr(e,s={},a={}){let n={...s?.[D.Day]};return Object.entries(e).filter(([,r])=>
vendor: 9,224 bytes, line 14
14r===!0).forEach(([r])=>{n={...n,...a?.[r]}}),n}function or(e,s,a,n){const r=n??e.today(),o=a?e.startOfBroadcastWeek(r,e):s?e.startOfISOWeek(r):e.startOfWeek(r),i=[];for(let l=0;l<7;l++){const c=e.addDays(o,l);i.push(c)}return i}function ir(e,s,a,n,r=!1){if(!e||!s)return;const{startOfYear:o,endOfYear:i,eachYearOfInterval:l,getYear:c}=n,h=o(e),d=i(s),x=l({start:h,end:d});return r&&x.reverse(),x.map(m=>{const u=a.formatYearDropdown(m,n);return{value:c(m),label:u,disabled:!1}})}function lr(e,s={}){const{weekStartsOn:a,locale:n}=s,r=a??n?.options?.weekStartsOn??0,o=l=>{const c=typeof l=="number"||typeof l=="string"?new Date(l):l;return new U(c.getFullYear(),c.getMonth(),c.getDate(),12,0,0,e)},i=l=>{const c=o(l);return new Date(c.getFullYear(),c.getMonth(),c.getDate(),0,0,0,0)};return{today:()=>o(U.tz(e)),newDate:(l,c,h)=>new U(l,c,h,12,0,0,e),startOfDay:l=>o(l),startOfWeek:(l,c)=>{const h=o(l),d=c?.weekStartsOn??r,x=(h.getDay()-d+7)%7;return h.setDate(h.getDate()-x),h},startOfISOWeek:l=>{const c=o(l),h=(c.getDay()-1+7)%7;return c.setDate(c.getDate()-h),c},startOfMonth:l=>{const c=o(l);return c.setDate(1),c},startOfYear:l=>{const c=o(l);return c.setMonth(0,1),c},endOfWeek:(l,c)=>{const h=o(l),m=(((c?.weekStartsOn??r)+6)%7-h.getDay()+7)%7;return h.setDate(h.getDate()+m),h},endOfISOWeek:l=>{const c=o(l),h=(7-c.getDay())%7;return c.setDate(c.getDate()+h),c},endOfMonth:l=>{const c=o(l);return c.setMonth(c.getMonth()+1,0),c},endOfYear:l=>{const c=o(l);return c.setMonth(11,31),c},eachMonthOfInterval:l=>{const c=o(l.start),h=o(l.end),d=[],x=new U(c.getFullYear(),c.getMonth(),1,12,0,0,e),m=h.getFullYear()*12+h.getMonth();for(;x.getFullYear()*12+x.getMonth()<=m;)d.push(new U(x,e)),x.setMonth(x.getMonth()+1,1);return d},addDays:(l,c)=>{const h=o(l);return h.setDate(h.getDate()+c),h},addWeeks:(l,c)=>{const h=o(l);return h.setDate(h.getDate()+c*7),h},addMonths:(l,c)=>{const h=o(l);return h.setMonth(h.getMonth()+c),h},addYears:(l,c)=>{const h=o(l);return h.setFullYear(h.getFullYear()+c),h},eachYearOfInterval:l=>{const c=o(l.start),h=o(l.end),d=[],x=new U(c.getFullYear(),0,1,12,0,0,e);for(;x.getFullYear()<=h.getFullYear();)d.push(new U(x,e)),x.setFullYear(x.getFullYear()+1,0,1);return d},getWeek:(l,c)=>{const h=i(l);return Vt(h,{weekStartsOn:c?.weekStartsOn??r,firstWeekContainsDate:c?.firstWeekContainsDate??n?.options?.firstWeekContainsDate??1})},getISOWeek:l=>{const c=i(l);return Zt(c)},differenceInCalendarDays:(l,c)=>{const h=i(l),d=i(c);return zt(h,d)},differenceInCalendarMonths:(l,c)=>{const h=i(l),d=i(c);return Kt(h,d)}}}const _e=e=>e instanceof HTMLElement?e:null,Qe=e=>[...e.querySelectorAll("[data-animated-month]")??[]],cr=e=>_e(e.querySelector("[data-animated-month]")),Xe=e=>_e(e.querySelector("[data-animated-caption]")),et=e=>_e(e.querySelector("[data-animated-weeks]")),dr=e=>_e(e.querySelector("[data-animated-nav]")),hr=e=>_e(e.querySelector("[data-animated-weekdays]"));function mr(e,s,{classNames:a,months:n,focused:r,dateLib:o}){const i=C.useRef(null),l=C.useRef(n),c=C.useRef(!1);C.useLayoutEffect(()=>{const h=l.current;if(l.current=n,!s||!e.current||!(e.current instanceof HTMLElement)||n.length===0||h.length===0||n.length!==h.length)return;const d=o.isSameMonth(n[0].date,h[0].date),x=o.isAfter(n[0].date,h[0].date),m=x?a[Q.caption_after_enter]:a[Q.caption_before_enter],u=x?a[Q.weeks_after_enter]:a[Q.weeks_before_enter],g=i.current,N=e.current.cloneNode(!0);if(N instanceof HTMLElement?(Qe(N).forEach(p=>{if(!(p instanceof HTMLElement))return;const k=cr(p);k&&p.contains(k)&&p.removeChild(k);const j=Xe(p);j&&j.classList.remove(m);const b=et(p);b&&b.classList.remove(u)}),i.current=N):i.current=null,c.current||d||r)return;const y=g instanceof HTMLElement?Qe(g):[],w=Qe(e.current);if(w?.every(f=>f instanceof HTMLElement)&&y&&y.every(f=>f instanceof HTMLElement)){c.current=!0,e.current.style.isolation="isolate";const f=dr(e.current);f&&(f.style.zIndex="1"),w.forEach((p,k)=>{const j=y[k];if(!j)return;p.style.position="relative",p.style.overflow="hidden";const b=Xe(p);b&&b.classList.add(m);const _=et(p);_&&_.classList.add(u);const T=()=>{c.current=!1,e.current&&(e.current.style.isolation=""),f&&(f.style.zIndex=""),b&&b.classList.remove(m),_&&_.classList.remove(u),p.style.position="",p.style.overflow="",p.contains(j)&&p.removeChild(j)};j.style.pointerEvents="none",j.style.position="absolute",j.style.overflow="hidden",j.setAttribute("aria-hidden","true");const $=hr(j);$&&($.style.opacity="0");const v=Xe(j);v&&(v.classList.add(x?a[Q.caption_before_exit]:a[Q.caption_after_exit]),v.addEventListener("animationend",T));const F=et(j);F&&F.classList.add(x?a[Q.weeks_before_exit]:a[Q.weeks_after_exit]),p.insertBefore(j,p.firstChild)})}})}function ur(e,s,a,n){const r=e[0],o=e[e.length-1],{ISOWeek:i,fixedWeeks:l,broadcastCalendar:c}=a??{},{addDays:h,differenceInCalendarDays:d,differenceInCalendarMonths:x,endOfBroadcastWeek:m,endOfISOWeek:u,endOfMonth:g,endOfWeek:N,isAfter:y,startOfBroadcastWeek:w,startOfISOWeek:f,startOfWeek:p}=n,k=c?w(r,n):i?f(r):p(r),j=c?m(o):i?u(g(o)):N(g(o)),b=s&&(c?m(s):i?u(s):N(s)),_=b&&y(j,b)?b:j,T=d(_,k),$=x(o,r)+1,v=[];for(let E=0;E<=T;E++){const Y=h(k,E);v.push(Y)}const O=(c?35:42)*$;if(l&&v.length<O){const E=O-v.length;for(let Y=0;Y<E;Y++){const R=h(v[v.length-1],1);v.push(R)}}return v}function xr(e){const s=[];return e.reduce((a,n)=>{const r=n.weeks.reduce((o,i)=>o.concat(i.days.slice()),s.slice());return a.concat(r.slice())},s.slice())}function fr(e,s,a,n){const{numberOfMonths:r=1}=a,o=[];for(let i=0;i<r;i++){const l=n.addMonths(e,i);if(s&&l>s)break;o.push(l)}return o}function kt(e,s,a,n){const{month:r,defaultMonth:o,today:i=n.today(),numberOfMonths:l=1}=e;let c=r||o||i;const{differenceInCalendarMonths:h,addMonths:d,startOfMonth:x}=n;if(a&&h(a,c)<l-1){const m=-1*(l-1);c=d(a,m)}return s&&h(c,s)<0&&(c=s),x(c)}function gr(e,s,a,n){const{addDays:r,endOfBroadcastWeek:o,endOfISOWeek:i,endOfMonth:l,endOfWeek:c,getISOWeek:h,getWeek:d,startOfBroadcastWeek:x,startOfISOWeek:m,startOfWeek:u}=n,g=e.reduce((N,y)=>{const w=a.broadcastCalendar?x(y,n):a.ISOWeek?m(y):u(y),f=a.broadcastCalendar?o(y):a.ISOWeek?i(l(y)):c(l(y)),p=s.filter(_=>_>=w&&_<=f),k=a.broadcastCalendar?35:42;if(a.fixedWeeks&&p.length<k){const _=s.filter(T=>{const $=k-p.length;return T>f&&T<=r(f,$)});p.push(..._)}const j=p.reduce((_,T)=>{const $=a.ISOWeek?h(T):d(T),v=_.find(O=>O.weekNumber===$),F=new rs(T,y,n);return v?v.days.push(F):_.push(new ha($,[F])),_},[]),b=new da(y,j);return N.push(b),N},[]);return a.reverseMonths?g.reverse():g}function pr(e,s){let{startMonth:a,endMonth:n}=e;const{startOfYear:r,startOfDay:o,startOfMonth:i,endOfMonth:l,addYears:c,endOfYear:h,newDate:d,today:x}=s,{fromYear:m,toYear:u,fromMonth:g,toMonth:N}=e;!a&&g&&(a=g),!a&&m&&(a=s.newDate(m,0,1)),!n&&N&&(n=N),!n&&u&&(n=d(u,11,31));const y=e.captionLayout==="dropdown"||e.captionLayout==="dropdown-years";return a?a=i(a):m?a=d(m,0,1):!a&&y&&(a=r(c(e.today??x(),-100))),n?n=l(n):u?n=d(u,11,31):!n&&y&&(n=h(e.today??x())),[a&&o(a),n&&o(n)]}function yr(e,s,a,n){if(a.disableNavigation)return;const{pagedNavigation:r,numberOfMonths:o=1}=a,{startOfMonth:i,addMonths:l,differenceInCalendarMonths:c}=n,h=r?o:1,d=i(e);if(!s)return l(d,h);if(!(c(s,e)<o))return l(d,h)}function br(e,s,a,n){if(a.disableNavigation)return;const{pagedNavigation:r,numberOfMonths:o}=a,{startOfMonth:i,addMonths:l,differenceInCalendarMonths:c}=n,h=r?o??1:1,d=i(e);if(!s)return l(d,-h);if(!(c(d,s)<=0))return l(d,-h)}function Nr(e){const s=[];return e.reduce((a,n)=>a.concat(n.weeks.slice()),s.slice())}function Ye(e,s){const[a,n]=C.useState(e);return[s===void 0?a:s,n]}function jr(e,s){const[a,n]=pr(e,s),{startOfMonth:r,endOfMonth:o}=s,i=kt(e,a,n,s),[l,c]=Ye(i,e.month?i:void 0);C.useEffect(()=>{const k=kt(e,a,n,s);c(k)},[e.timeZone]);const{months:h,weeks:d,days:x,previousMonth:m,nextMonth:u}=C.useMemo(()=>{const k=fr(l,n,{numberOfMonths:e.numberOfMonths},s),j=ur(k,e.endMonth?o(e.endMonth):void 0,{ISOWeek:e.ISOWeek,fixedWeeks:e.fixedWeeks,broadcastCalendar:e.broadcastCalendar},s),b=gr(k,j,{broadcastCalendar:e.broadcastCalendar,fixedWeeks:e.fixedWeeks,ISOWeek:e.ISOWeek,reverseMonths:e.reverseMonths},s),_=Nr(b),T=xr(b),$=br(l,a,e,s),v=yr(l,n,e,s);return{months:b,weeks:_,days:T,previousMonth:$,nextMonth:v}},[s,l.getTime(),n?.getTime(),a?.getTime(),e.disableNavigation,e.broadcastCalendar,e.endMonth?.getTime(),e.fixedWeeks,e.ISOWeek,e.numberOfMonths,e.pagedNavigation,e.reverseMonths]),{disableNavigation:g,onMonthChange:N}=e,y=k=>d.some(j=>j.days.some(b=>b.isEqualTo(k))),w=k=>{if(g)return;let j=r(k);a&&j<r(a)&&(j=r(a)),n&&j>r(n)&&(j=r(n)),c(j),N?.(j)};return{months:h,weeks:d,days:x,navStart:a,navEnd:n,previousMonth:m,nextMonth:u,goToMonth:w,goToDay:k=>{y(k)||w(k.date)}}}var ne;(function(e){e[e.Today=0]="Today",e[e.Selected=1]="Selected",e[e.LastFocused=2]="LastFocused",e[e.FocusedModifier=3]="FocusedModifier"})(ne||(ne={}));function Ct(e){return!e[q.disabled]&&!e[q.hidden]&&!e[q.outside]}function vr(e,s,a,n){let r,o=-1;for(const i of e){const l=s(i);Ct(l)&&(l[q.focused]&&o<ne.FocusedModifier?(r=i,o=ne.FocusedModifier):n?.isEqualTo(i)&&o<ne.LastFocused?(r=i,o=ne.LastFocused):a(i.date)&&o<ne.Selected?(r=i,o=ne.Selected):l[q.today]&&o<ne.Today&&(r=i,o=ne.Today))}return r||(r=e.find(i=>
14Ct(s(i)))),r}function wr(e,s,a,n,r,o,i){const{ISOWeek:l,broadcastCalendar:c}=o,{addDays:h,addMonths:d,addWeeks:x,addYears:m,endOfBroadcastWeek:u,endOfISOWeek:g,endOfWeek:N,max:y,min:w,startOfBroadcastWeek:f,startOfISOWeek:p,startOfWeek:k}=i;let b={day:h,week:x,month:d,year:m,startOfWeek:_=>c?f(_,i):l?p(_):k(_),endOfWeek:_=>c?u(_):l?g(_):N(_)}[e](a,s==="after"?1:-1);return s==="before"&&n?b=y([n,b]):s==="after"&&r&&(b=w([r,b])),b}function Ns(e,s,a,n,r,o,i,l=0){if(l>365)return;const c=wr(e,s,a.date,n,r,o,i),h=!!(o.disabled&&ce(c,o.disabled,i)),d=!!(o.hidden&&ce(c,o.hidden,i)),x=c,m=new rs(c,x,i);return!h&&!d?m:Ns(e,s,m,n,r,o,i,l+1)}function Mr(e,s,a,n,r){const{autoFocus:o}=e,[i,l]=C.useState(),c=vr(s.days,a,n||(()=>!1),i),[h,d]=C.useState(o?c:void 0);return{isFocusTarget:N=>!!c?.isEqualTo(N),setFocused:d,focused:h,blur:()=>{l(h),d(void 0)},moveFocus:(N,y)=>{if(!h)return;const w=Ns(N,y,h,s.navStart,s.navEnd,e,r);w&&(e.disableNavigation&&!s.days.some(p=>p.isEqualTo(w))||(s.goToDay(w),d(w)))}}}function kr(e,s){const{selected:a,required:n,onSelect:r}=e,[o,i]=Ye(a,r?a:void 0),l=r?a:o,{isSameDay:c}=s,h=u=>l?.some(g=>c(g,u))??!1,{min:d,max:x}=e;return{selected:l,select:(u,g,N)=>{let y=[...l??[]];if(h(u)){if(l?.length===d||n&&l?.length===1)return;y=l?.filter(w=>!c(w,u))}else l?.length===x?y=[u]:y=[...y,u];return r||i(y),r?.(y,u,g,N),y},isSelected:h}}function Cr(e,s,a=0,n=0,r=!1,o=oe){const{from:i,to:l}=s||{},{isSameDay:c,isAfter:h,isBefore:d}=o;let x;if(!i&&!l)x={from:e,to:a>0?void 0:e};else if(i&&!l)c(i,e)?a===0?x={from:i,to:e}:r?x={from:i,to:void 0}:x=void 0:d(e,i)?x={from:e,to:i}:x={from:i,to:e};else if(i&&l)if(c(i,e)&&c(l,e))r?x={from:i,to:l}:x=void 0;else if(c(i,e))x={from:i,to:a>0?void 0:e};else if(c(l,e))x={from:e,to:a>0?void 0:e};else if(d(e,i))x={from:e,to:l};else if(h(e,i))x={from:i,to:e};else if(h(e,l))x={from:i,to:e};else throw new Error("Invalid range");if(x?.from&&x?.to){const m=o.differenceInCalendarDays(x.to,x.from);n>0&&m>n?x={from:e,to:void 0}:a>1&&m<a&&(x={from:e,to:void 0})}return x}function Dr(e,s,a=oe){const n=Array.isArray(s)?s:[s];let r=e.from;const o=a.differenceInCalendarDays(e.to,e.from),i=Math.min(o,6);for(let l=0;l<=i;l++){if(n.includes(r.getDay()))return!0;r=a.addDays(r,1)}return!1}function Dt(e,s,a=oe){return le(e,s.from,!1,a)||le(e,s.to,!1,a)||le(s,e.from,!1,a)||le(s,e.to,!1,a)}function _r(e,s,a=oe){const n=Array.isArray(s)?s:[s];if(n.filter(l=>typeof l!="function").some(l=>typeof l=="boolean"?l:a.isDate(l)?le(e,l,!1,a):ls(l,a)?l.some(c=>le(e,c,!1,a)):$e(l)?l.from&&l.to?Dt(e,{from:l.from,to:l.to},a):!1:is(l)?Dr(e,l.dayOfWeek,a):ct(l)?a.isAfter(l.before,l.after)?Dt(e,{from:a.addDays(l.after,1),to:a.addDays(l.before,-1)},a):ce(e.from,l,a)||ce(e.to,l,a):dt(l)||ht(l)?ce(e.from,l,a)||ce(e.to,l,a):!1))return!0;const i=n.filter(l=>typeof l=="function");if(i.length){let l=e.from;const c=a.differenceInCalendarDays(e.to,e.from);for(let h=0;h<=c;h++){if(i.some(d=>d(l)))return!0;l=a.addDays(l,1)}}return!1}function Sr(e,s){const{disabled:a,excludeDisabled:n,resetOnSelect:r,selected:o,required:i,onSelect:l}=e,[c,h]=Ye(o,l?o:void 0),d=l?o:c;return{selected:d,select:(u,g,N)=>{const{min:y,max:w}=e;let f;if(u){const p=d?.from,k=d?.to,j=!!p&&!!k,b=!!p&&!!k&&s.isSameDay(p,k)&&s.isSameDay(u,p);r&&(j||!d?.from)?!i&&b?f=void 0:f={from:u,to:void 0}:f=Cr(u,d,y,w,i,s)}return n&&a&&f?.from&&f.to&&_r({from:f.from,to:f.to},a,s)&&(f.from=u,f.to=void 0),l||h(f),l?.(f,u,g,N),f},isSelected:u=>d&&le(d,u,!1,s)}}function Or(e,s){const{selected:a,required:n,onSelect:r}=e,[o,i]=Ye(a,r?a:void 0),l=r?a:o,{isSameDay:c}=s;return{selected:l,select:(x,m,u)=>{let g=x;return!n&&l&&l&&c(x,l)&&(g=void 0),r||i(g),r?.(g,x,m,u),g},isSelected:x=>l?c(l,x):!1}}function Wr(e,s){const a=Or(e,s),n=kr(e,s),r=Sr(e,s);switch(e.mode){case"single":return a;case"multiple":return n;case"range":return r;default:return}}function ee(e,s){return e instanceof U&&e.timeZone===s?e:new U(e,s)}function ue(e,s,a){return ee(e,s)}function _t(e,s,a){return typeof e=="boolean"||typeof e=="function"?e:e instanceof Date?ue(e,s):Array.isArray(e)?e.map(n=>n instanceof Date?ue(n,s):n):$e(e)?{...e,from:e.from?ee(e.from,s):e.from,to:e.to?ee(e.to,s):e.to}:ct(e)?{before:ue(e.before,s),after:ue(e.after,s)}:dt(e)?{after:ue(e.after,s)}:ht(e)?{before:ue(e.before,s)}:e}function tt(e,s,a){return e&&(Array.isArray(e)?e.map(n=>_t(n,s)):_t(e,s))}function Fr(e){let s=e;const a=s.timeZone;if(a&&(s={...e,timeZone:a},s.today&&(s.today=ee(s.today,a)),s.month&&(s.month=ee(s.month,a)),s.defaultMonth&&(s.defaultMonth=ee(s.defaultMonth,a)),s.startMonth&&(s.startMonth=ee(s.startMonth,a)),s.endMonth&&(s.endMonth=ee(s.endMonth,a)),s.mode==="single"&&s.selected?s.selected=ee(s.selected,a):s.mode==="multiple"&&s.selected?s.selected=s.selected?.map(W=>ee(W,a)):s.mode==="range"&&s.selected&&(s.selected={from:s.selected.from?ee(s.selected.from,a):s.selected.from,to:s.selected.to?ee(s.selected.to,a):s.selected.to}),s.disabled!==void 0&&(s.disabled=tt(s.disabled,a)),s.hidden!==void 0&&(s.hidden=tt(s.hidden,a)),s.modifiers)){const W={};
14Object.keys(s.modifiers).forEach(P=>{W[P]=tt(s.modifiers?.[P],a)}),s.modifiers=W}const{components:n,formatters:r,labels:o,dateLib:i,locale:l,classNames:c}=C.useMemo(()=>{const W={...as,...s.locale},P=s.broadcastCalendar?1:s.weekStartsOn,S=s.noonSafe&&s.timeZone?lr(s.timeZone,{weekStartsOn:P,locale:W}):void 0,A=s.dateLib&&S?{...S,...s.dateLib}:s.dateLib??S,J=new X({locale:W,weekStartsOn:P,firstWeekContainsDate:s.firstWeekContainsDate,useAdditionalWeekYearTokens:s.useAdditionalWeekYearTokens,useAdditionalDayOfYearTokens:s.useAdditionalDayOfYearTokens,timeZone:s.timeZone,numerals:s.numerals},A);return{dateLib:J,components:Ya(s.components),formatters:Qa(s.formatters),labels:nr(s.labels,J.options),locale:W,classNames:{...Ra(),...s.classNames}}},[s.locale,s.broadcastCalendar,s.weekStartsOn,s.firstWeekContainsDate,s.useAdditionalWeekYearTokens,s.useAdditionalDayOfYearTokens,s.timeZone,s.numerals,s.dateLib,s.noonSafe,s.components,s.formatters,s.labels,s.classNames]);s.today||(s={...s,today:i.today()});const{captionLayout:h,mode:d,navLayout:x,numberOfMonths:m=1,onDayBlur:u,onDayClick:g,onDayFocus:N,onDayKeyDown:y,onDayMouseEnter:w,onDayMouseLeave:f,onNextClick:p,onPrevClick:k,showWeekNumber:j,styles:b}=s,{formatCaption:_,formatDay:T,formatMonthDropdown:$,formatWeekNumber:v,formatWeekNumberHeader:F,formatWeekdayName:O,formatYearDropdown:E}=r,Y=jr(s,i),{days:R,months:H,navStart:B,navEnd:K,previousMonth:Z,nextMonth:G,goToMonth:ie}=Y,qe=Ba(R,s,B,K,i),{isSelected:Re,select:Ge,selected:Se}=Wr(s,i)??{},{blur:ft,focused:gt,isFocusTarget:Cs,moveFocus:pt,setFocused:Oe}=Mr(s,Y,qe,Re??(()=>!1),i),{labelDayButton:Ds,labelGridcell:_s,labelGrid:Ss,labelMonthDropdown:Os,labelNav:yt,labelPrevious:Ws,labelNext:Fs,labelWeekday:Ts,labelWeekNumber:Ls,labelWeekNumberHeader:Is,labelYearDropdown:Es}=o,As=C.useMemo(()=>or(i,s.ISOWeek,s.broadcastCalendar,s.today),[i,s.ISOWeek,s.broadcastCalendar,s.today]),bt=d!==void 0||g!==void 0,He=C.useCallback(()=>{Z&&(ie(Z),k?.(Z))},[Z,ie,k]),Ue=C.useCallback(()=>{G&&(ie(G),p?.(G))},[ie,G,p]),Ps=C.useCallback((W,P)=>S=>{S.preventDefault(),S.stopPropagation(),Oe(W),!P.disabled&&(Ge?.(W.date,P,S),g?.(W.date,P,S))},[Ge,g,Oe]),Bs=C.useCallback((W,P)=>S=>{Oe(W),N?.(W.date,P,S)},[N,Oe]),$s=C.useCallback((W,P)=>S=>{ft(),u?.(W.date,P,S)},[ft,u]),Ys=C.useCallback((W,P)=>S=>{const A={ArrowLeft:[S.shiftKey?"month":"day",s.dir==="rtl"?"after":"before"],ArrowRight:[S.shiftKey?"month":"day",s.dir==="rtl"?"before":"after"],ArrowDown:[S.shiftKey?"year":"week","after"],ArrowUp:[S.shiftKey?"year":"week","before"],PageUp:[S.shiftKey?"year":"month","before"],PageDown:[S.shiftKey?"year":"month","after"],Home:["startOfWeek","before"],End:["endOfWeek","after"]};if(A[S.key]){S.preventDefault(),S.stopPropagation();const[J,I]=A[S.key];pt(J,I)}y?.(W.date,P,S)},[pt,y,s.dir]),qs=C.useCallback((W,P)=>S=>{w?.(W.date,P,S)},[w]),Rs=C.useCallback((W,P)=>S=>{f?.(W.date,P,S)},[f]),Gs=C.useCallback(W=>P=>{const S=Number(P.target.value),A=i.setMonth(i.startOfMonth(W),S);ie(A)},[i,ie]),Hs=C.useCallback(W=>P=>{const S=Number(P.target.value),A=i.setYear(i.startOfMonth(W),S);ie(A)},[i,ie]),{className:Us,style:zs}=C.useMemo(()=>({className:[c[D.Root],s.className].filter(Boolean).join(" "),style:{...b?.[D.Root],...s.style}}),[c,s.className,s.style,b]),Ks=qa(s),Nt=C.useRef(null);mr(Nt,!!s.animate,{classNames:c,months:H,focused:gt,dateLib:i});const Zs={dayPickerProps:s,selected:Se,select:Ge,isSelected:Re,months:H,nextMonth:G,previousMonth:Z,goToMonth:ie,getModifiers:qe,components:n,classNames:c,styles:b,labels:o,formatters:r};return M.createElement(os.Provider,{value:Zs},M.createElement(n.Root,{rootRef:s.animate?Nt:void 0,className:Us,style:zs,dir:s.dir,id:s.id,lang:s.lang??l.code,nonce:s.nonce,title:s.title,role:s.role,"aria-label":s["aria-label"],"aria-labelledby":s["aria-labelledby"],...Ks},M.createElement(n.Months,{className:c[D.Months],style:b?.[D.Months]},!s.hideNavigation&&!x&&M.createElement(n.Nav,{"data-animated-nav":s.animate?"true":void 0,className:c[D.Nav],style:b?.[D.Nav],"aria-label":yt(),onPreviousClick:He,onNextClick:Ue,previousMonth:Z,nextMonth:G}),H.map((W,P)=>M.createElement(n.Month,{"data-animated-month":s.animate?"true":void 0,className:c[D.Month],style:b?.[D.Month],key:P,displayIndex:P,calendarMonth:W},x==="around"&&!s.hideNavigation&&P===0&&M.createElement(n.PreviousMonthButton,{type:"button",className:c[D.PreviousMonthButton],tabIndex:Z?void 0:-1,"aria-disabled":Z?void 0:!0,"aria-label":Ws(Z),onClick:He,"data-animated-button":s.animate?"true":void 0},M.createElement(n.Chevron,{disabled:Z?void 0:!0,className:c[D.Chevron],orientation:s.dir==="rtl"?"right":"left"})),M.createElement(n.MonthCaption,{"data-animated-caption":s.animate?"true":void 0,className:c[D.MonthCaption],style:b?.[D.MonthCaption],calendarMonth:W,displayIndex:P},h?.startsWith("dropdown")?M.createElement(n.DropdownNav,{className:c[D.Dropdowns],style:b?.[D.Dropdowns]},(()=>{const S=h==="dropdown"||h==="dropdown-months"?M.createElement(n.MonthsDropdown,{key:"month",className:c[D.MonthsDropdown],"aria-label":Os(),classNames:c,components:n,disabled:!!s.disableNavigation,onChange:Gs(W.date),options:ar(W.date,B,K,r,i),style:b?.[D.Dropdown],value:i.getMonth(W.date)}):M.createElement("span",{key:"month"},$(W.date,i)),A=h==="dropdown"||h==="dropdown-years"?M.createElement(n.Years
14Dropdown,{key:"year",className:c[D.YearsDropdown],"aria-label":Es(i.options),classNames:c,components:n,disabled:!!s.disableNavigation,onChange:Hs(W.date),options:ir(B,K,r,i,!!s.reverseYears),style:b?.[D.Dropdown],value:i.getYear(W.date)}):M.createElement("span",{key:"year"},E(W.date,i));return i.getMonthYearOrder()==="year-first"?[A,S]:[S,A]})(),M.createElement("span",{role:"status","aria-live":"polite",style:{border:0,clip:"rect(0 0 0 0)",height:"1px",margin:"-1px",overflow:"hidden",padding:0,position:"absolute",width:"1px",whiteSpace:"nowrap",wordWrap:"normal"}},_(W.date,i.options,i))):M.createElement(n.CaptionLabel,{className:c[D.CaptionLabel],role:"status","aria-live":"polite"},_(W.date,i.options,i))),x==="around"&&!s.hideNavigation&&P===m-1&&M.createElement(n.NextMonthButton,{type:"button",className:c[D.NextMonthButton],tabIndex:G?void 0:-1,"aria-disabled":G?void 0:!0,"aria-label":Fs(G),onClick:Ue,"data-animated-button":s.animate?"true":void 0},M.createElement(n.Chevron,{disabled:G?void 0:!0,className:c[D.Chevron],orientation:s.dir==="rtl"?"left":"right"})),P===m-1&&x==="after"&&!s.hideNavigation&&M.createElement(n.Nav,{"data-animated-nav":s.animate?"true":void 0,className:c[D.Nav],style:b?.[D.Nav],"aria-label":yt(),onPreviousClick:He,onNextClick:Ue,previousMonth:Z,nextMonth:G}),M.createElement(n.MonthGrid,{role:"grid","aria-multiselectable":d==="multiple"||d==="range","aria-label":Ss(W.date,i.options,i)||void 0,className:c[D.MonthGrid],style:b?.[D.MonthGrid]},!s.hideWeekdays&&M.createElement(n.Weekdays,{"data-animated-weekdays":s.animate?"true":void 0,className:c[D.Weekdays],style:b?.[D.Weekdays]},j&&M.createElement(n.WeekNumberHeader,{"aria-label":Is(i.options),className:c[D.WeekNumberHeader],style:b?.[D.WeekNumberHeader],scope:"col"},F()),As.map(S=>M.createElement(n.Weekday,{"aria-label":Ts(S,i.options,i),className:c[D.Weekday],key:String(S),style:b?.[D.Weekday],scope:"col"},O(S,i.options,i)))),M.createElement(n.Weeks,{"data-animated-weeks":s.animate?"true":void 0,className:c[D.Weeks],style:b?.[D.Weeks]},W.weeks.map(S=>M.createElement(n.Week,{className:c[D.Week],key:S.weekNumber,style:b?.[D.Week],week:S},j&&M.createElement(n.WeekNumber,{week:S,style:b?.[D.WeekNumber],"aria-label":Ls(S.weekNumber,{locale:l}),className:c[D.WeekNumber],scope:"row",role:"rowheader"},v(S.weekNumber,i)),S.days.map(A=>{const{date:J}=A,I=qe(A);if(I[q.focused]=!I.hidden&&!!gt?.isEqualTo(A),I[se.selected]=Re?.(J)||I.selected,$e(Se)){const{from:ze,to:Ke}=Se;I[se.range_start]=!!(ze&&Ke&&i.isSameDay(J,ze)),I[se.range_end]=!!(ze&&Ke&&i.isSameDay(J,Ke)),I[se.range_middle]=le(Se,J,!0,i)}const Vs=rr(I,b,s.modifiersStyles),Js=$a(I,c,s.modifiersClassNames),Qs=!bt&&!I.hidden?_s(J,I,i.options,i):void 0;return M.createElement(n.Day,{key:`${A.isoDate}_${A.displayMonthId}`,day:A,modifiers:I,className:Js.join(" "),style:Vs,role:"gridcell","aria-selected":I.selected||void 0,"aria-label":Qs,"data-day":A.isoDate,"data-month":A.outside?A.dateMonthId:void 0,"data-selected":I.selected||void 0,"data-disabled":I.disabled||void 0,"data-hidden":I.hidden||void 0,"data-outside":A.outside||void 0,"data-focused":I.focused||void 0,"data-today":I.today||void 0},!I.hidden&&bt?M.createElement(n.DayButton,{className:c[D.DayButton],style:b?.[D.DayButton],type:"button",day:A,modifiers:I,disabled:!I.focused&&I.disabled||void 0,"aria-disabled":I.focused&&I.disabled||void 0,tabIndex:Cs(A)?0:-1,"aria-label":Ds(J,I,i.options,i),onClick:Ps(A,I),onBlur:$s(A,I),onFocus:Bs(A,I),onKeyDown:Ys(A,I),onMouseEnter:qs(A,I),onMouseLeave:Rs(A,I)},T(J,i.options,i)):!I.hidden&&T(A.date,i.options,i))})))))))),s.footer&&M.createElement(n.Footer,{className:c[D.Footer],style:b?.[D.Footer],role:"status","aria-live":"polite"},s.footer)))}function Ae({className:e,classNames:s,showOutsideDays:a=!0,locale:n=he,...r}){return t.jsx(Fr,{showOutsideDays:a,locale:n,className:en("p-3",e),classNames:{...s},...r})}function Tr({dateRange:e,setDateRange:s,searchTerm:a,setSearchTerm:n,showOnlyMatched:r,setShowOnlyMatched:o,carrierFilter:i,setCarrierFilter:l}){return t.jsxs("div",{className:"bg-white rounded-xl border border-gray-200 p-4 space-y-4",children:[t.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.jsx("span",{className:"text-sm text-gray-500 flex items-center mr-2",children:"빠른 선택:"}),Vn.map(({label:c,days:h})=>t.jsx(V,{variant:"outline",size:"sm",className:L("h-8",e.from&&e.to&&Math.round((e.to.getTime()-e.from.getTime())/(1e3*60*60*24))===h&&z(e.to,"yyyy-MM-dd")===z(new Date,"yyyy-MM-dd")?"bg-blue-50 border-blue-300 text-blue-700":""),onClick:()=>s({from:Be(new Date,h),to:new Date}),children:c},c))]}),t.jsxs("div",{className:"flex flex-wrap gap-4 items-center",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-sm text-gray-600 whitespace-nowrap",children:"시작일"}),t.jsxs(Ne,{children:[t.jsx(je,{asChild:!0,children:t.jsxs(V,{variant:"outline",className:"w-[180px] justify-start text-left font-normal",children:[t.jsx(We,{className:"mr-2 h-4 w-4"}),e.from?z(e.from,"yyyy-MM-dd"):"선택"]})}),t.jsx(ve,{className:"w-auto p-0 bg-white",align:"start",children:t.jsx(Ae,{mode:"single",selected:e.from,onSelect:c=>c&&s(h=>({...h,from:c})),locale:he,initialFocus:!0})})]})]}),t.jsx("span",{className:"text-gray-400",children:"~"}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-sm text-gray-600 whitespace-nowrap",children:"종료일"}),t.jsxs(Ne,{children:[t.jsx(je,{asChild:!0,children:t.jsxs(V,{variant:"outline",className:"w-[180px] justify-start text-left font-normal",children:[t.jsx(We,{className:"mr-2 h-4 w-4"}),e.to?z(e.to,"yyyy-MM-dd"):"선택"]})}),t.jsx(ve,{className:"w-auto p-0 bg-white",align:"start",children:t.jsx(Ae,{mode:"single",selected:e.to,onSelect:c=>c&&s(h=>({...h,to:c})),locale:he,initialFocus:!0,disabled:c=>e.from?c<e.from:!1})})]})]}),t.jsxs("div",{className:"relative flex-1 min-w-[200px]",children:[t.jsx(An,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400"}),t.jsx(de,{placeholder:"주문번호/이름/연락처 검색",value:a,onChange:c=>n(c.target.value),className:"pl-9 pr-8"}),a&&t.jsx("button",{type:"button",onClick:()=>n(""),className:"absolute right-2 top-1/2 -translate-y-1/2 p-0.5 rounded hover:bg-gray-100 text-gray-400 hover:text-gray-600",title:"검색어 지우기",children:t.jsx(Gt,{className:"h-4 w-4"})})]}),t.jsxs(V,{variant:r?"default":"outline",onClick:()=>o(!r),className:"gap-2",children:[t.jsx(zn,{className:"w-4 h-4"}),"운임 매칭만 보기"]}),t.jsx("div",{className:"flex items-center gap-1 border rounded-lg p-1",children:[{value:"all",label:"전체"},{value:"cj",label:"CJ",color:"yellow"},{value:"chunil",label:"천일",color:"green"},{value:"kyungdong",label:"경동",color:"blue"}].map(({value:c,label:h,color:d})=>t.jsx(V,{variant:i===c?"default":"ghost",size:"sm",onClick:()=>l(c),className:L("h-7 px-3",i===c&&c!=="all"&&{yellow:"bg-yellow-500 hover:bg-yellow-600",green:"bg-green-500 hover:bg-green-600",blue:"bg-blue-500 hover:bg-blue-600"}[d]),children:h},c))})]})]})}const Lr={CJ대한통운:"CJ",천일택배:"천일",경동택배:"경동"};function Ir(e){return Lr[e]||e}function St(e,s){const a=e-s;return a===0?t.jsx("span",{className:"text-gray-500",children:"0원"}):a>0?t.jsxs("span",{className:"text-blue-600 font-medium",children:["+",a.toLocaleStr
14ing(),"원"]}):t.jsxs("span",{className:"text-red-600 font-medium",children:[a.toLocaleString(),"원"]})}function Er(e){return e.invoices.length===0?"-":[...new Set(e.invoices.map(a=>Kn[a.carrier]||a.carrier))].join(", ")}function Ar({breakdown:e,onClose:s}){return t.jsxs("div",{className:"w-[280px]",children:[t.jsxs("div",{className:"flex items-center justify-between mb-3",children:[t.jsx("h4",{className:"font-bold text-sm text-gray-900",children:"로직 내역"}),t.jsx("button",{onClick:s,className:"text-gray-400 hover:text-gray-600",children:t.jsx(Gt,{className:"w-4 h-4"})})]}),t.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[t.jsx("span",{className:L("px-2 py-0.5 rounded-full text-xs font-medium",e.type==="화물택배"?"bg-orange-100 text-orange-700":"bg-indigo-100 text-indigo-700"),children:e.type}),t.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs font-medium bg-gray-100 text-gray-700",children:e.gradeName})]}),t.jsxs("div",{className:"bg-gray-50 rounded-lg p-3 space-y-2 text-sm",children:[t.jsxs("div",{className:"flex justify-between",children:[t.jsx("span",{className:"text-gray-500",children:"기준 요금"}),t.jsxs("span",{className:"font-medium",children:[e.baseFee.toLocaleString(),"원"]})]}),t.jsxs("div",{className:"flex justify-between",children:[t.jsx("span",{className:"text-gray-500",children:"총 무게"}),t.jsxs("span",{className:"font-medium",children:[e.totalWeightKg.toFixed(1),"kg"]})]}),t.jsxs("div",{className:"flex justify-between",children:[t.jsx("span",{className:"text-gray-500",children:"건수"}),t.jsxs("span",{className:"font-medium",children:[e.unitCount,"건",t.jsxs("span",{className:"text-xs text-gray-400 ml-1",children:["(",e.weightPerUnit,"kg/건)"]})]})]})]}),t.jsxs("div",{className:"mt-3 px-1 text-xs text-gray-500 space-y-0.5",children:[t.jsxs("div",{children:[e.baseFee.toLocaleString(),"원 x ",e.unitCount,"건 = ",e.rawAmount.toLocaleString(),"원"]}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx("span",{children:"천원 올림 →"}),t.jsxs("span",{className:"text-sm font-bold text-gray-900",children:[e.fee.toLocaleString(),"원"]})]})]}),e.items.length>1&&t.jsxs("div",{className:"mt-3 pt-3 border-t",children:[t.jsx("div",{className:"text-xs font-medium text-gray-500 mb-1.5",children:"아이템별 등급"}),t.jsx("div",{className:"space-y-1",children:e.items.map((a,n)=>t.jsxs("div",{className:"flex justify-between text-xs",children:[t.jsxs("span",{className:"text-gray-600",children:[a.w," x ",a.l,"mm (",a.qty,"개)"]}),t.jsx("span",{className:"font-medium text-gray-700",children:a.grade})]},n))})]})]})}function Pr({filteredOrders:e,loading:s}){const[a,n]=C.useState(null);return t.jsx("div",{className:"bg-white rounded-xl border border-gray-200 overflow-hidden",children:t.jsxs("table",{className:"w-full text-sm table-fixed",children:[t.jsxs("colgroup",{children:[t.jsx("col",{className:"w-[5%]"}),t.jsx("col",{className:"w-[13%]"}),t.jsx("col",{className:"w-[5%]"}),t.jsx("col",{className:"w-[9%]"}),t.jsx("col",{className:"w-[4%]"}),t.jsx("col",{className:"w-[8%]"}),t.jsx("col",{className:"w-[7%]"}),t.jsx("col",{className:"w-[9%]"}),t.jsx("col",{className:"w-[9%]"}),t.jsx("col",{className:"w-[11%]"}),t.jsx("col",{className:"w-[9%]"})]}),t.jsx("thead",{className:"bg-gray-50 border-b border-gray-200",children:t.jsxs("tr",{children:[t.jsx("th",{className:"px-2 py-3 text-center text-sm font-medium text-gray-600 whitespace-nowrap",children:"주문일"}),t.jsx("th",{className:"px-2 py-3 text-left text-sm font-medium text-gray-600 whitespace-nowrap",children:"주문번호"}),t.jsx("th",{className:"px-2 py-3 text-center text-sm font-medium text-gray-600 whitespace-nowrap",children:"이름"}),t.jsx("th",{className:"px-2 py-3 text-center text-sm font-medium text-gray-600 whitespace-nowrap",children:"연락처"}),t.jsx("th",{className:"px-2 py-3 text-center text-sm font-medium text-gray-600 whitespace-nowrap",children:"택배사"}),t.jsx("th",{className:"px-2 py-3 text-right text-sm font-medium text-gray-600 whitespace-nowrap",children:"배송비"}),t.jsx("th",{className:"px-2 py-3 text-center text-sm font-medium text-gray-600 bg-blue-50 whitespace-nowrap",children:"실제 택배사"}),t.jsx("th",{className:"px-2 py-3 text-right text-sm font-medium text-gray-600 bg-blue-50 whitespace-nowrap",children:"실제 배송비"}),t.jsx("th",{className:"px-2 py-3 text-right text-sm font-medium text-gray-600 bg-blue-50 whitespace-nowrap",children:"차액"}),t.jsx("th",{className:"px-2 py-3 text-right text-sm font-medium text-gray-600 bg-emerald-50 whitespace-nowrap",children:"현재로직"}),t.jsx("th",{className:"px-2 py-3 text-right text-sm font-medium text-gray-600 bg-emerald-50 whitespace-nowrap",children:"로직차액"})]})}),t.jsx("tbody",{className:"divide-y divide-gray-100",children:s?t.jsx("tr",{children:t.jsx("td",{colSpan:11,className:"px-4 py-8 text-center text-gray-500",children:"로딩 중..."})}):e.length===0?t.jsx("tr",{children:t.jsx("td",{colSpan:11,className:"px-4 py-8 text-center text-gray-500",children:"조회된 주문이 없습니다."})}):e.map(r=>{const o=r.invoices.filter(i=>i.actual_fee!=null).length;return t.jsxs("tr",{className:L("hover:bg-gray-50 align-middle",o>1&&"bg-orange-50/50"),children:[t.jsx("td",{className:"px-2 py-3 text-center text-sm text-gray-600 whitespace-nowrap",children:r.order_date?z(new Date(r.order_date),"MM-dd"):"-"}),t.jsx("td",{className:"px-2 py-3 text-left",children:t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx("a",{href:`/admin/orders/${r.order_code}`,target:"_blank",rel:"noopener noreferrer",className:"font-mono text-sm font-bold text-blue-600 hover:text-blue-800 hover:underline",children:r.order_code}),o>1&&t.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1 py-0.5 rounded bg-orange-100 text-orange-700 text-xs font-medium cursor-help flex-shrink-0",title:`다건 출고: 이 주문은 ${o}건의 개별 배송으로 발송되었습니다`,children:[t.jsx(we,{className:"w-3 h-3"}),o]})]})}),t.jsx("td",{className:"px-2 py-3 text-center text-sm truncate",title:r.customer_name,children:r.customer_name}),t.jsx("td",{className:"px-2 py-3 text-center text-sm text-gray-600 whitespace-nowrap truncate",children:r.customer_phone||"-"}),t.jsx("td",{className:"px-2 py-3 text-center text-sm whitespace-nowrap",children:Ir(r.shipping_company)||"-"}),t.jsxs("td",{className:"px-2 py-3 text-right text-sm font-medium whitespace-nowrap",children:[r.packaging_fee.toLocaleStr
14ing(),"원"]}),t.jsx("td",{className:"px-2 py-3 text-center text-sm bg-blue-50/50 whitespace-nowrap",children:Er(r)}),t.jsx("td",{className:"px-2 py-3 text-right bg-blue-50/50 whitespace-nowrap",children:r.actualFeeTotal>0?t.jsxs("div",{children:[t.jsxs("span",{className:"font-bold text-sm text-blue-700",children:[r.actualFeeTotal.toLocaleString(),"원"]}),o>1&&t.jsxs("div",{className:"text-xs text-gray-500",children:["(",o,"건)"]})]}):t.jsx("span",{className:"text-gray-400",children:"-"})}),t.jsx("td",{className:"px-2 py-3 text-right bg-blue-50/50 whitespace-nowrap",children:r.actualFeeTotal>0?St(r.packaging_fee,r.actualFeeTotal):t.jsx("span",{className:"text-gray-400",children:"-"})}),t.jsx("td",{className:"px-2 py-3 text-right bg-emerald-50/50 whitespace-nowrap",children:r.currentLogicFee!=null?r.currentLogicBreakdown?t.jsxs(Ne,{open:a===r.order_code,onOpenChange:i=>n(i?r.order_code:null),children:[t.jsx(je,{asChild:!0,children:t.jsxs("button",{className:L("inline-flex items-center gap-0.5 font-medium text-sm cursor-pointer hover:underline decoration-dotted underline-offset-2",r.currentLogicFee!==r.packaging_fee?"text-emerald-700":"text-gray-600"),children:[r.currentLogicFee.toLocaleString(),"원",t.jsx("span",{className:"text-gray-400 text-xs",children:"?"})]})}),t.jsx(ve,{className:"w-auto p-4 bg-white border border-gray-200 shadow-lg",side:"left",align:"start",children:t.jsx(Ar,{breakdown:r.currentLogicBreakdown,onClose:()=>n(null)})})]}):t.jsxs("span",{className:L("font-medium text-sm",r.currentLogicFee!==r.packaging_fee?"text-emerald-700":"text-gray-600"),children:[r.currentLogicFee.toLocaleString(),"원"]}):t.jsx("span",{className:"text-gray-400",children:"-"})}),t.jsx("td",{className:"px-2 py-3 text-right bg-emerald-50/50 whitespace-nowrap",children:r.currentLogicFee!=null&&r.actualFeeTotal>0?St(r.currentLogicFee,r.actualFeeTotal):t.jsx("span",{className:"text-gray-400",children:"-"})})]},r.order_code)})})]})})}async function Br(){const{data:e,error:s}=await re.from("ln_packaging_fee_config").select("*").eq("config_type","packaging_fee_v2").eq("is_active",!0).maybeSingle();if(s)throw console.error("[PackagingFeeSettingsService] 조회 실패:",s),s;return e?e.config_data:nt}async function $r(e){await re.from("ln_packaging_fee_config").update({is_active:!1}).eq("config_type","packaging_fee_v2").eq("is_active",!0);const{error:s}=await re.from("ln_packaging_fee_config").insert({config_type:"packaging_fee_v2",config_data:e,description:"안전포장비 V2 설정",is_active:!0,updated_at:new Date().toISOString()});if(s)throw console.error("[PackagingFeeSettingsService] 저장 실패:",s),s;tn(),await it()}function Yr(){const[e,s]=C.useState(nt),[a,n]=C.useState(nt),[r,o]=C.useState(!0),[i,l]=C.useState(!1),[c,h]=C.useState(!1),d=C.useCallback(async()=>{o(!0);try{const f=await Br();s(f),n(f),h(!1)}catch(f){console.error("설정 로드 실패:",f),pe.error("설정을 불러오는데 실패했습니다")}finally{o(!1)}},[]);C.useEffect(()=>{d()},[d]),C.useEffect(()=>{const f=JSON.stringify(e)!==JSON.stringify(a);h(f)},[e,a]);const x=C.useCallback(f=>{s(p=>({...p,parcelTiers:f}))},[]),m=C.useCallback(f=>{s(p=>({...p,freightTiers:f}))},[]),u=C.useCallback((f,p)=>{s(k=>({...k,[f]:p}))},[]),g=C.useCallback(f=>{s(p=>({...p,parcelGapDecisions:f}))},[]),N=C.useCallback(f=>{s(p=>({...p,freightGapDecisions:f}))},[]),y=C.useCallback(async f=>{if(!c){pe.info("변경된 내용이 없습니다");return}l(!0);try{await $r(e),n(e),h(!1),pe.success("설정이 저장되었습니다"),f?.()}catch(p){console.error("설정 저장 실패:",p),pe.error("설정 저장에 실패했습니다")}finally{l(!1)}},[e,c]),w=C.useCallback(()=>{s(a),pe.info("변경 사항이 취소되었습니다")},[a]);return{settings:e,loading:r,saving:i,hasChanges:c,loadSettings:d,handleSave:y,handleReset:w,updateParcelTiers:x,updateFreightTiers:m,updateConstant:u,updateParcelGapDecisions:g,updateFreightGapDecisions:N}}const Pe={small:{label:"소형",description:"폭 200mm×길이 1200mm 이하 등"},medium:{label:"중형",description:"폭 400mm×길이 1000mm 이하 등"},large:{label:"대형",description:"폭 600mm×길이 900mm 이하 등"}};function qr({onSaved:e}={}){const s=Pn(),{settings:a,loading:n,saving:r,hasChanges:o,loadSettings:i,handleSave:l,handleReset:c,updateParcelTiers:h,updateFreightTiers:d,updateConstant:x,updateParcelGapDecisions:m,updateFreightGapDecisions:u}=Yr(),[g,N]=C.useState(!1),[y,w]=C.useState(!1);return n?t.jsxs("div",{className:"flex items-center justify-center py-20",children:[t.jsx(Fe,{className:"w-6 h-6 animate-spin text-gray-400"}),t.jsx("span",{className:"ml-2 text-gray-500",children:"설정을 불러오는 중..."})]}):t.jsxs("div",{className:"space-y-6",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(we,{className:"w-5 h-5 text-blue-600"}),t.jsx("h2",{className:"text-lg font-semibold",children:"안전포장비 설정"}),o&&t.jsx("span",{className:"px-2 py-0.5 text-xs bg-orange-100 text-orange-700 rounded-full",children:"변경됨"})]}),t.jsxs("div",{className:"flex gap-2",children:[t.jsxs(V,{variant:"outline",size:"sm",onClick:i,disabled:r,children:[t.jsx(Fe,{className:"w-4 h-4 mr-1"}),"새로고침"]}),t.jsxs(Bn,{children:[o&&t.jsx(V,{variant:"outline",size:"sm",onClick:c,disabled:r,children:"취소"}),t.jsxs(V,{size:"sm",onClick:()=>l(e),disabled:!o||r,children:[t.jsx($n,{className:"w-4 h-4 mr-1"}),r?"저장 중...":"저장"]})]})]})]}),t.jsxs("div",{className:"bg-gradient-to-r from-blue-50 to-indigo-50 border border-blue-200 rounded-xl p-5",children:[t.jsxs("div",{className:"flex items-start gap-3 mb-3",children:[t.jsx(Yn,{className:"w-5 h-5 text-blue-600 mt-0.5 flex-shrink-0"}),t.jsxs("div",{children:[t.jsx("h3",{className:"font-semibold text-gray-900",children:"현재로직 방식"}),t.jsxs("p",{className:"text-sm text-gray-600 mt-1",children:["주문 내 모든 아이템 중 ",t.jsx("strong",{children:"가장 큰 아이템"}),"으로 등급을 판정합니다. 일반택배 테이블에 매칭되지 않는 아이템이 ",t.jsx("strong",{children:"하나라도"})," 있으면 전체 주문이 화물택배로 전환됩니다."]})]})]}),t.jsxs("div",{className:"grid grid-cols-3 gap-4 text-sm",children:[t.jsxs("div",{className:"bg-white rounded-lg p-3 border border-blue-100",children:[t.jsx("p",{className:"font-medium text-gray-800 mb
14-1",children:"1. 등급 판정"}),t.jsxs("p",{className:"text-gray-600",children:["일반택배: 폭×길이 순차 매칭",t.jsx("br",{}),"화물택배: #순서대로 매칭"]})]}),t.jsxs("div",{className:"bg-white rounded-lg p-3 border border-blue-100",children:[t.jsx("p",{className:"font-medium text-gray-800 mb-1",children:"2. 건수 산출"}),t.jsxs("p",{className:"text-gray-600",children:["총 무게 ÷ ",a.weightPerUnit,"kg = 건수 (올림, 최소 1)"]})]}),t.jsxs("div",{className:"bg-white rounded-lg p-3 border border-blue-100",children:[t.jsx("p",{className:"font-medium text-gray-800 mb-1",children:"3. 최종 요금"}),t.jsxs("p",{className:"text-gray-600",children:["등급 요금 × 건수 → 천원 단위 올림",t.jsx("br",{}),"최대 ",a.maxFee.toLocaleString(),"원까지"]})]})]})]}),t.jsx(st,{icon:t.jsx(we,{className:"w-4 h-4"}),title:"일반택배 요금표",description:"폭(짧은쪽) × 길이(긴쪽) 순서대로 매칭합니다. 첫 번째 매칭된 등급이 적용됩니다.",editingSize:g,onToggleEditSize:s?void 0:()=>N(!g),children:t.jsx(Hr,{tiers:a.parcelTiers,onUpdate:h,editingSize:g,gapDecisions:a.parcelGapDecisions??{},onGapDecisionsChange:m,readOnly:s})}),t.jsx(st,{icon:t.jsx(Te,{className:"w-4 h-4"}),title:"화물택배 요금표",description:"일반택배에 매칭되지 않는 아이템은 화물택배로 전환됩니다. #순서대로 매칭합니다.",editingSize:y,onToggleEditSize:s?void 0:()=>
14w(!y),children:t.jsx(Xr,{tiers:a.freightTiers,onUpdate:d,editingSize:y,gapDecisions:a.freightGapDecisions??{},onGapDecisionsChange:u,readOnly:s})}),t.jsx(st,{icon:t.jsx(xe,{className:"w-4 h-4"}),title:"기타 설정",description:"건수 산출 및 무게 계산에 사용되는 상수입니다.",children:t.jsxs("div",{className:"grid grid-cols-3 gap-6",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsx("label",{className:"text-sm font-medium text-gray-700",children:"무게 단위 (건수 기준)"}),t.jsx("p",{className:"text-xs text-gray-500",children:"이 무게(kg)당 1건으로 계산합니다"}),t.jsxs("div",{className:"relative",children:[t.jsx(de,{type:"text",inputMode:"numeric",value:a.weightPerUnit,onChange:f=>x("weightPerUnit",parseInt(f.target.value)||20),className:"pr-8",disabled:s}),t.jsx("span",{className:"absolute right-3 top-1/2 -translate-y-1/2 text-sm text-gray-400",children:"kg"})]})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx("label",{className:"text-sm font-medium text-gray-700",children:"기본 밀도"}),t.jsx("p",{className:"text-xs text-gray-500",children:"목재 기본 밀도 (kg/mm³). 무게 자동 계산에 사용"}),t.jsx(de,{type:"text",inputMode:"decimal",value:a.defaultDensity,onChange:f=>x("defaultDensity",parseFloat(f.target.value)||65e-8),disabled:s})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx("label",{className:"text-sm font-medium text-gray-700",children:"안전포장비 상한"}),t.jsx("p",{className:"text-xs text-gray-500",children:"1회 계산당 최대 금액. 용달 실비 상한 기준"}),t.jsxs("div",{className:"relative",children:[t.jsx(de,{type:"text",inputMode:"numeric",value:a.maxFee,onChange:f=>x("maxFee",parseInt(f.target.value)||sn),className:"pr-8",disabled:s}),t.jsx("span",{className:"absolute right-3 top-1/2 -translate-y-1/2 text-sm text-gray-400",children:"원"})]})]})]})})]})}function Rr(e){const s=new Map,a=(o,i)=>{if(o<=0||i<=0)return;const l=`${o}×${i}`;s.has(l)||s.set(l,{width:o,length:i})},n=Math.max(...e.map(o=>o.maxWidth),0),r=Math.max(...e.map(o=>o.maxLength),0);for(const o of e)a(o.maxWidth,o.maxLength),a(Math.max(1,o.maxWidth-50),o.maxLength),a(o.maxWidth,Math.max(1,o.maxLength-50)),a(o.maxWidth+50,o.maxLength),a(o.maxWidth,o.maxLength+50);return a(n+100,r),a(n,r+100),Array.from(s.entries()).map(([o,i])=>({...i,label:o})).sort((o,i)=>o.width-i.width||o.length-i.length)}function Gr(e){const a=Rr(e).map(r=>{const o=e.findIndex(l=>r.width<=l.maxWidth&&r.length<=l.maxLength),i=o>=0?e[o]:null;return{width:r.width,length:r.length,label:r.label,matchedIdx:o>=0?o:null,matchedGrade:i?Pe[i.grade]?.label??i.grade:null,isGap:o<0}}),n=[];for(let r=1;r<e.length;r++)for(let o=0;o<r;o++)if(e[o].maxWidth>=e[r].maxWidth&&e[o].maxLength>=e[r].maxLength){n.push({tierIdx:r,shadowedByIdx:o});break}return{tests:a,shadowed:n,gapCount:a.filter(r=>r.isGap).length}}function Hr({tiers:e,onUpdate:s,editingSize:a,gapDecisions:n,onGapDecisionsChange:r,readOnly:o}){const i=n,l=(x,m,u)=>{const g=[...e];g[x]={...g[x],[m]:u},s(g)},c=()=>{s([...e,{maxWidth:0,maxLength:0,grade:"small",fee:0}])},h=x=>{s(e.filter((m,u)=>u!==x))},d=C.useMemo(()=>a?Gr(e):null,[e,a]);return t.jsxs("div",{className:"space-y-3",children:[t.jsx("div",{className:"border border-gray-200 rounded overflow-hidden",children:t.jsxs("table",{className:"w-full text-sm",children:[t.jsx("thead",{className:"bg-gray-50",children:t.jsxs("tr",{children:[t.jsx("th",{className:"px-3 py-2 text-left font-medium text-gray-600 w-[80px]",children:"등급"}),t.jsx("th",{className:"px-3 py-2 text-center font-medium text-gray-600 w-12",children:"#"}),t.jsxs("th",{className:"px-3 py-2 text-left font-medium text-gray-600",children:["최대 폭 (mm) ",!a&&t.jsx(Le,{className:"w-3 h-3 inline ml-1 text-gray-400"})]}),t.jsxs("th",{className:"px-3 py-2 text-left font-medium text-gray-600",children:["최대 길이 (mm) ",!a&&t.jsx(Le,{className:"w-3 h-3 inline ml-1 text-gray-400"})]}),t.jsx("th",{className:"px-3 py-2 text-left font-medium text-gray-600 w-[140px]",children:"요금 (원)"}),a&&t.jsx("th",{className:"px-3 py-2 w-12"})]})}),t.jsx("tbody",{children:e.map((x,m)=>{const u=d?.shadowed.some(g=>g.tierIdx===m);return t.jsxs("tr",{className:L("border-t border-gray-100 hover:bg-gray-50",u&&"bg-red-50/50"),children:[t.jsx("td",{className:"px-3 py-1.5 text-sm text-gray-700 font-medium",children:Pe[x.grade]?.label??x.grade}),t.jsxs("td",{className:"px-3 py-1.5 text-gray-400 text-center",children:[m+1,u&&t.jsx(Ce,{className:"w-3 h-3 text-red-500 
14inline ml-1"})]}),t.jsx("td",{className:"px-3 py-1.5",children:t.jsx(de,{type:"text",inputMode:"numeric",value:x.maxWidth,onChange:g=>l(m,"maxWidth",parseInt(g.target.value)||0),className:L("h-8",!a&&"bg-gray-50 text-gray-600"),disabled:!a})}),t.jsx("td",{className:"px-3 py-1.5",children:t.jsx(de,{type:"text",inputMode:"numeric",value:x.maxLength,onChange:g=>l(m,"maxLength",parseInt(g.target.value)||0),className:L("h-8",!a&&"bg-gray-50 text-gray-600"),disabled:!a})}),t.jsx("td",{className:"px-3 py-1.5",children:t.jsx(de,{type:"text",inputMode:"numeric",value:x.fee,onChange:g=>l(m,"fee",parseInt(g.target.value)||0),className:"h-8",disabled:o})}),a&&!o&&t.jsx("td",{className:"px-3 py-1.5",children:t.jsx("button",{onClick:()=>h(m),className:"text-red-400 hover:text-red-600 p-1",title:"삭제",children:t.jsx(Jt,{className:"w-4 h-4"})})})]},m)})})]})}),a&&!o&&t.jsxs(V,{variant:"outline",size:"sm",onClick:c,children:[t.jsx(Qt,{className:"w-4 h-4 mr-1"}),"행 추가"]}),t.jsx("p",{className:"text-xs text-gray-400",children:"순서대로 매칭: 폭 ≤ 최대폭 AND 길이 ≤ 최대길이인 첫 번째 행이 적용됩니다. 어떤 행에도 매칭되지 않으면 화물택배로 전환됩니다."}),a&&d&&t.jsx(Kr,{validation:d,tiers:e,confirmed:i,onConfirm:(x,m)=>r({...i,[x]:m}),onUndo:x=>{const{[x]:m,...u}=i;r(u)}})]})}function Ur(e,s,a,n){const r=n.filter(l=>l.grade===a);if(r.some(l=>e<=l.maxWidth&&s<=l.maxLength))return null;if(r.length===0)return"해당 등급의 행이 없습니다";const o=[],i=r.reduce((l,c)=>{const h=Math.max(0,e-l.maxWidth)+Math.max(0,s-l.maxLength),d=Math.max(0,e-c.maxWidth)+Math.max(0,s-c.maxLength);return h<=d?l:c});return e>i.maxWidth&&o.push(`폭 ${i.maxWidth}→${e}`),s>i.maxLength&&o.push(`길이 ${i.maxLength}→${s}`),o.length>0?`조건 조정 필요: ${o.join(", ")}`:null}function zr(e,s,a,n){const r=n.find(h=>h.name===a);if(!r)return"해당 등급을 찾을 수 없습니다";const o=Math.min(e,s),i=Math.max(e,s),l=o+i,c=[];return r.exactWidth!==void 0&&o!==r.exactWidth&&c.push(`폭=${r.exactWidth} (현재 ${o})`),r.exactLength!==void 0&&i!==r.exactLength&&c.push(`길이=${r.exactLength} (현재 ${i})`),r.minWidth!==void 0&&o<r.minWidth&&c.push(`폭≥${r.minWidth}→${o}`),r.maxWidth!==void 0&&o>r.maxWidth&&c.push(`폭≤${r.maxWidth}→${o}`),r.minLength!==void 0&&i<r.minLength&&c.push(`길이≥${r.minLength}→${i}`),r.maxLength!==void 0&&i>r.maxLength&&c.push(`길이≤${r.maxLength}→${i}`),r.minSum!==void 0&&l<r.minSum&&c.push(`합≥${r.minSum}→${l}`),r.maxSum!==void 0&&l>r.maxSum&&c.push(`합≤${r.maxSum}→${l}`),c.length>0?`조건 조정 필요: ${c.join(", ")}`:null}function Kr({validation:e,tiers:s,confirmed:a,onConfirm:n,onUndo:r}){const{tests:o,shadowed:i,gapCount:l}=e,c=o.filter(m=>m.isGap&&a[m.label]).length,h=l-c,d=h>0||i.length>0,x=[...new Set(s.map(m=>m.grade))];return t.jsxs("div",{className:L("rounded-lg border p-3 mt-2",d?"bg-amber-50 border-amber-200":"bg-green-50 border-green-200"),children:[t.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[d?t.jsx(Ce,{className:"w-4 h-4 text-amber-600"}):t.jsx(Xt,{className:"w-4 h-4 text-green-600"}),t.jsx("span",{className:L("text-sm font-medium",d?"text-amber-800":"text-green-800"),children:d?`등급 지정 필요 ${h>0?`(미지정 ${h}건`:"("}${i.length>0?`${h>0?", ":""}겹침 ${i.length}건`:""})`:"커버리지 정상 — 모든 사이즈 등급 지정 완료"})]}),i.length>0&&t.jsx("div",{className:"mb-2 space-y-1",children:i.map(m=>t.jsxs("div",{className:"flex items-start gap-1.5 text-xs text-red-700",children:[t.jsx(at,{className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0"}),t.jsxs("span",{children:[t.jsxs("strong",{children:[m.tierIdx+1,"번 행"]}),"이 ",t.jsxs("strong",{children:[m.shadowedByIdx+1,"번 행"]}),"에 완전히 포함되어 도달 불가능합니다."]})]},m.tierIdx))}),t.jsx("div",{className:"overflow-hidden rounded border border-gray-200/50",children:t.jsxs("table",{className:"w-full text-xs",children:[t.jsx("thead",{className:"bg-white/60",children:t.jsxs("tr",{children:[t.jsx("th",{className:"px-2 py-1.5 text-left font-medium text-gray-600",children:"테스트 사이즈"}),t.jsx("th",{className:"px-2 py-1.5 text-center font-medium text-gray-600",children:"현재 매칭"}),t.jsx("th",{className:"px-2 py-1.5 text-center font-medium text-gray-600",children:"등급 지정"})]})}),t.jsx("tbody",{children:o.map(m=>{const u=a[m.label],g=!!u;return t.jsxs("tr",{className:L("border-t border-gray-100",m.isGap&&!g&&"bg-red-50",m.isGap&&g&&"bg-green-50/50"),children:[t.jsx("td",{className:"px-2 py-1.5 font-mono text-gray-700",children:m.label}),t.jsx("td",{className:"px-2 py-1.5 text-center",children:m.matchedGrade?t.jsxs("span",{className:"text-gray-700",children:[m.matchedGrade," (#",(m.matchedIdx??0)+1,")"]}):t.jsx("span",{className:L("font-medium",g?"text-gray-500":"text-orange-600"),children:"미매칭"})}),t.jsx("td",{className:"px-2 py-1.5 text-center",children:m.isGap?g?t.jsxs("div",{className:"space-y-0.5",children:[t.jsxs("div",{className:"flex items-center justify-center gap-1",children:[t.jsx("span",{className:L("px-1.5 py-0.5 rounded text-xs font-medium",u==="freight"?"bg-green-100 text-green-700":"bg-blue-100 text-blue-700"),
14children:u==="freight"?"화물 전환":Pe[u]?.label??u}),t.jsx("button",{onClick:()=>r(m.label),className:"text-gray-400 hover:text-gray-600",title:"재선택",children:t.jsx(at,{className:"w-3 h-3"})})]}),u!=="freight"&&(()=>{const N=Ur(m.width,m.length,u,s);return N?t.jsx("span",{className:"block text-[10px] text-amber-600 leading-tight",children:N}):null})()]}):t.jsxs("select",{className:"h-6 px-1 text-xs border border-red-300 rounded bg-white text-red-700 focus:outline-none focus:ring-1 focus:ring-red-400",value:"",onChange:N=>n(m.label,N.target.value),children:[t.jsx("option",{value:"",disabled:!0,children:"선택..."}),t.jsx("option",{value:"freight",children:"화물 전환"}),x.map(N=>t.jsx("option",{value:N,children:Pe[N]?.label??N},N))]}):t.jsx("span",{className:"text-green-600",children:"정상"})})]},m.label)})})]})}),t.jsx("p",{className:"text-xs text-gray-500 mt-1.5",children:"* 미매칭 사이즈에 대해 의도한 등급 분류를 확인합니다. 사이즈 조건은 변경되지 않습니다."})]})}const Zr={exactWidth:"정확히 폭",minWidth:"폭 ≥",maxWidth:"폭 ≤",exactLength:"정확히 길이",minLength:"길이 ≥",maxLength:"길이 ≤",minSum:"폭+길이 ≥",maxSum:"폭+길이 ≤"},Vr=[{label:"폭",keys:["exactWidth","minWidth","maxWidth"]},{label:"길이",keys:["exactLength","minLength","maxLength"]},{label:"합계",keys:["minSum","maxSum"]}];function Jr(e){const s=new Map,a=(o,i)=>{if(o<=0||i<=0)return;const l=`${o}×${i}`;s.has(l)||s.set(l,{width:o,length:i})},n=new Set,r=new Set;for(const o of e){if(o.exactWidth!==void 0&&n.add(o.exactWidth),o.minWidth!==void 0&&(n.add(o.minWidth),n.add(o.minWidth-50)),o.maxWidth!==void 0&&(n.add(o.maxWidth),n.add(o.maxWidth+50)),o.exactLength!==void 0&&r.add(o.exactLength),o.minLength!==void 0&&(r.add(o.minLength),r.add(o.minLength-50)),o.maxLength!==void 0&&(r.add(o.maxLength),r.add(o.maxLength+50)),o.minSum!==void 0){const i=Math.round(o.minSum/2);a(i,o.minSum-i),a(i,o.minSum-i-50)}if(o.maxSum!==void 0){const i=Math.round(o.maxSum/2);a(i,o.maxSum-i),a(i,o.maxSum-i+50)}}n.size===0&&[600,800,1e3,1200].forEach(o=>n.add(o)),r.size===0&&[1e3,1500,2e3,2400].forEach(o=>r.add(o));for(const o of n)for(const i of r)a(Math.min(o,i),Math.max(o,i));return Array.from(s.entries()).map(([o,i])=>({...i,label:o})).sort((o,i)=>o.width-i.width||o.length-i.length)}function Qr(e){const s=[...e].sort((n,r)=>n.priority-r.priority);return Jr(e).map(n=>{const r=Math.min(n.width,n.length),o=Math.max(n.width,n.length),i=r+o,l=s.find(c=>!(c.exactWidth!==void 0&&r!==c.exactWidth||c.exactLength!==void 0&&o!==c.exactLength||c.minWidth!==void 0&&r<c.minWidth||c.maxWidth!==void 0&&r>c.maxWidth||c.minLength!==void 0&&o<c.minLength||c.maxLength!==void 0&&o>c.maxLength||c.minSum!==void 0&&i<c.minSum||c.maxSum!==void 0&&i>c.maxSum));return{label:n.label,width:r,length:o,matchedTier:l?.name??null,isGap:!l}})}function Xr({tiers:e,onUpdate:s,editingSize:a,gapDecisions:n,onGapDecisionsChange:r,readOnly:o}){const i=n,l=(u,g,N)=>{const y=[...e];y[u]={...y[u],[g]:N},s(y)},c=(u,g,N)=>{const y=[...e],w={...y[u]},f=parseInt(N);N===""||isNaN(f)?delete w[g]:w[g]=f,y[u]=w,s(y)},h=()=>{const u=e.reduce((g,N)=>Math.max(g,N.priority),0);s([...e,{name:"신규",fee:0,priority:u+1}])},d=u=>{s(e.filter((g,N)=>N!==u))},x=[...e].map((u,g)=>({...u,_origIdx:g})).sort((u,g)=>u.priority-g.priority),m=C.useMemo(()=>a?Qr(e):null,[e,a]);return t.jsxs("div",{className:"space-y-3",children:[t.jsx("div",{className:"border border-gray-200 rounded overflow-hidden",children:t.jsxs("table",{className:"w-full text-sm",children:[t.jsx("thead",{className:"bg-gray-50",children:t.jsxs("tr",{children:[t.jsx("th",{className:"px-3 py-2 text-left font-medium text-gray-600 w-[80px]",children:"등급"}),t.jsx("th",{className:"px-3 py-2 text-center font-medium text-gray-600 w-12",children:"#"}),t.jsxs("th",{className:"px-3 py-2 text-left font-medium text-gray-600",children:["사이즈 조건 ",!a&&t.jsx(Le,{className:"w-3 h-3 inline ml-1 text-gray-400"})]}),t.jsx("th",{className:"px-3 py-2 text-left font-medium text-gray-600 w-[140px]",children:"요금 (원)"}),a&&t.jsx("th",{className:"px-3 py-2 w-12"})]})}),t.jsx("tbody",{children:x.map(u=>{const g=u._origIdx;return t.jsxs("tr",{className:"border-t border-gray-100 hover:bg-gray-50",children:[t.jsx("td",{className:"px-3 py-1.5 text-sm text-gray-700 font-medium whitespace-nowrap",children:u.name}),t.jsx("td",{className:"px-3 py-1.5 text-gray-400 text-center",children:u.priority}),t.jsx("td",{className:"px-3 py-2",children:a?t.jsx("div",{className:"space-y-1.5",children:Vr.map(N=>t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-[10px] text-gray-400 w-6 flex-shrink-0 text-right",children:N.label}),t.jsx("div",{className:"flex gap-2 flex-1",children:N.keys.map(y=>{const w=u[y];return t.jsxs("div",{className:"flex-1",children:[t.jsx("label",{className:"block text-[11px] text-gray-400 mb-0.5 whitespace-nowrap",children:Zr[y]}),t.jsx(de,{type:"text",inputMode:"numeric",value:w??"",onChange:f=>c(g,y,f.target.value),className:"h-7 text-xs",placeholder:"-"})]},y)})})]},N.label))}):t.jsx("span",{className:"text-xs text-gray-500",children:eo(u)})}),t.jsx("td",{className:"px-3 py-1.5",children:t.jsx(de,{type:"text",inputMode:"numeric",value:u.fee,onChange:N=>l(g,"fee",parseInt(N.target.value)||0),className:"h-8",disabled:o})}),a&&!o&&t.jsx("td",{className:"px-3 py-1.5",children:t.jsx("button",{onClick:()=>d(g),className:"text-red-400 hover:text-red-600 p-1",title:"삭제",children:t.jsx(Jt,{className:"w-4 h-4"})})})]},g)})})]})}),a&&!o&&t.jsxs(V,{variant:"outline",size:"sm",onClick:h,children:[t.jsx(Qt,{className:"w-4 h-4 mr-1"}),"등급 추가"]}),t.jsx("p",{className:"text-xs text-gray-400",children:"#순서대로 매칭 (1 → 2 → 3 ...). 설정된 조건은 모두 AND로 결합됩니다. 빈 필드는 무시됩니다. 가장 마지막 항목을 catch-all로 사용하세요."}),a&&m&&t.jsx(to,{results:m,tiers:e,confirmed:i,onConfirm:(u,g)=>r({...i,[u]:g}),onUndo:u=>{const{[u]:g,...N}=i;r(N)}})]})}function eo(e){const s=[];return e.exactWidth!==void 0&&s.push(`폭=${e.exactWidth}`),e.exactLength!==void 0&&s.push(`길이=${e.exactLength}`),e.minWidth!==void 0&&s.push(`폭≥${e.minWidth}`),e.maxWidth!==void 0&&s.push(`폭≤${e.maxWidth}`),e.minLength!==void 0&&s.push(`길이≥${e.minLength}`),e.maxLength!==void 0&&s.push(`길이≤${e.maxLength}`),e.minSum!==void 0&&s.push(`합≥${e.minSum}`),e.maxSum!==void 0&&s.push(`합≤${e.maxSum}`),s.length>0?s.join(", "):"조건 없음 (catch-all)"}function to({results:e,tiers:s,confirmed:a,onConfirm:n,onUndo:r}){const o=e.filter(d=>d.isGap).length,i=e.filter(d=>d.isGap&&a[d.label]).length,l=o-i,c=l>0,h=[...new Set(s.map(d=>d.name))].sort();
14return t.jsxs("div",{className:L("rounded-lg border p-3 mt-2",c?"bg-amber-50 border-amber-200":"bg-green-50 border-green-200"),children:[t.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[c?t.jsx(Ce,{className:"w-4 h-4 text-amber-600"}):t.jsx(Xt,{className:"w-4 h-4 text-green-600"}),t.jsx("span",{className:L("text-sm font-medium",c?"text-amber-800":"text-green-800"),children:c?`등급 지정 필요 — ${l}건의 테스트 사이즈 미지정`:"화물 커버리지 정상 — 모든 테스트 사이즈 등급 지정 완료"})]}),t.jsx("div",{className:"grid grid-cols-4 gap-2",children:e.map(d=>{const x=a[d.label],m=!!x;return t.jsxs("div",{className:L("rounded px-2 py-1.5 text-xs border",d.isGap&&!m?"bg-red-50 border-red-200":d.isGap&&m?"bg-green-50/50 border-green-200":"bg-white border-gray-200"),children:[t.jsx("span",{className:"font-mono text-gray-700",children:d.label}),d.isGap?m?t.jsxs("div",{className:"space-y-0.5",children:[t.jsxs("div",{className:"flex items-center gap-1 mt-0.5",children:[t.jsx("span",{className:"px-1.5 py-0.5 rounded text-xs font-medium bg-blue-100 text-blue-700",children:x}),t.jsx("button",{onClick:()=>r(d.label),className:"text-gray-400 hover:text-gray-600",title:"재선택",children:t.jsx(at,{className:"w-3 h-3"})})]}),(()=>{const u=zr(d.width,d.length,x,s);return u?t.jsx("span",{className:"block text-[10px] text-amber-600 leading-tight",children:u}):null})()]}):t.jsxs("select",{className:"block w-full mt-0.5 h-5 px-0.5 text-xs border border-red-300 rounded bg-white text-red-700 focus:outline-none focus:ring-1 focus:ring-red-400",value:"",onChange:u=>n(d.label,u.target.value),children:[t.jsx("option",{value:"",disabled:!0,children:"등급 선택..."}),h.map(u=>t.jsx("option",{value:u,children:u},u))]}):t.jsx("span",{className:"block text-gray-500",children:d.matchedTier})]},d.label)})}),t.jsx("p",{className:"text-xs text-gray-500 mt-1.5",children:"* 미매칭 사이즈에 대해 의도한 등급 분류를 확인합니다. 사이즈 조건은 변경되지 않습니다."})]})}function st({icon:e,title:s,description:a,children:n,editingSize:r,onToggleEditSize:o}){return t.jsxs("div",{className:"bg-white border border-gray-200 rounded-lg p-4",children:[t.jsxs("div",{className:"flex items-start gap-2 mb-4",children:[t.jsx("div",{className:"p-1.5 bg-gray-100 rounded text-gray-600",children:e}),t.jsxs("div",{className:"flex-1",children:[t.jsx("h3",{className:"font-medium text-gray-900",children:s}),t.jsx("p",{className:"text-sm text-gray-500",children:a})]}),o&&t.jsxs(V,{variant:r?"default":"outline",size:"sm",onClick:o,className:r?"bg-amber-600 hover:bg-amber-700":"",children:[r?t.jsx(qn,{className:"w-4 h-4 mr-1"}):t.jsx(Le,{className:"w-4 h-4 mr-1"}),r?"사이즈 편집 중":"사이즈 수정"]})]}),n]})}const Ot=500,Wt=80;async function so(e,s){const{data:a,error:n}=await re.from("tp_order").select("id, order_code, order_date, shipping_company").gte("order_date",e).lte("order_date",s);if(n)throw n;if(!a||a.length===0)return{invoiceMap:new Map,orders:[],mappings:[]};const r=a.map(c=>c.id),o=[];for(let c=0;c<r.length;c+=Ot){const h=r.slice(c,c+Ot),{data:d,error:x}=await re.from("tp_order_mapping").select(`
15        internal_order_id,
16        request_order_id,
17        ln_order_requests!inner (
18          packaging_fee,
19          request_data
20        )
21      `).in("internal_order_id",h);if(x)throw console.error("[ShippingAnalysis] 매핑 조회 실패:",x),x;d&&o.push(...d)}const i=a.map(c=>
21c.order_code).filter(Boolean),l=new Map;for(let c=0;c<i.length;c+=Wt){const h=i.slice(c,c+Wt),{data:d,error:x}=await re.from("ln_shipping_invoice").select("order_code, carrier, invoice_seq, actual_fee").in("order_code",h).order("invoice_seq",{ascending:!0});if(x&&console.error("[ShippingAnalysis] 인보이스 조회 실패:",x),d)for(const m of d){const u=l.get(m.order_code)||[];u.push({carrier:m.carrier,invoice_seq:m.invoice_seq,actual_fee:m.actual_fee}),l.set(m.order_code,u)}}return{invoiceMap:l,orders:a,mappings:o}}const js=[{label:"~200 × ~600",widthMin:0,widthMax:200,lengthMin:0,lengthMax:600},{label:"~200 × ~1200",widthMin:0,widthMax:200,lengthMin:601,lengthMax:1200},{label:"~200 × 1200+",widthMin:0,widthMax:200,lengthMin:1201,lengthMax:99999},{label:"~400 × ~600",widthMin:201,widthMax:400,lengthMin:0,lengthMax:600},{label:"~400 × ~1000",widthMin:201,widthMax:400,lengthMin:601,lengthMax:1e3},{label:"~400 × 1000+",widthMin:201,widthMax:400,lengthMin:1001,lengthMax:99999},{label:"~600 × ~900",widthMin:401,widthMax:600,lengthMin:0,lengthMax:900},{label:"~600 × 900+",widthMin:401,widthMax:600,lengthMin:901,lengthMax:99999},{label:"~700 × any",widthMin:601,widthMax:700,lengthMin:0,lengthMax:99999},{label:"700+ × any",widthMin:701,widthMax:99999,lengthMin:0,lengthMax:99999}],no=[{label:"~400",min:0,max:400},{label:"401~600",min:401,max:600},{label:"601~800",min:601,max:800},{label:"801~1000",min:801,max:1e3},{label:"1001~1200",min:1001,max:1200},{label:"1200+",min:1201,max:99999}],ao=[{label:"~1200",min:0,max:1200},{label:"1201~1600",min:1201,max:1600},{label:"1601~2000",min:1601,max:2e3},{label:"2001~2400",min:2001,max:2400},{label:"2400+",min:2401,max:99999}],Ft=no.flatMap(e=>ao.map(s=>({widthLabel:e.label,lengthLabel:s.label,widthMin:e.min,widthMax:e.max,lengthMin:s.min,lengthMax:s.max}))),vs={small:"소형",medium:"중형",large:"대형",freight:"화물"},ro=["admin","shippingCostAnalysis"];function oo(){const[e,s]=C.useState({from:Be(new Date,60),to:new Date}),{data:a=[],isLoading:n,error:r}=Ht({queryKey:[...ro,e.from?.toISOString(),e.to?.toISOString()],queryFn:async()=>{if(!e.from||!e.to)return[];const i=z(lt(e.from),"yyyy-MM-dd"),l=z(Ut(e.to),"yyyy-MM-dd"),{invoiceMap:c,orders:h,mappings:d}=await so(i,l);if(h.length===0)return[];await it();const x=ke(),m=new Map(h.map(y=>[y.id,y])),u=new Map,g=new Set;for(const y of d){const w=m.get(y.internal_order_id);if(!w)continue;const f=w.order_code;if(!c.has(f))continue;const p=!g.has(y.request_order_id);y.request_order_id&&g.add(y.request_order_id);const k=u.get(f);if(k){if(p){k.expectedFee+=y.ln_order_requests?.packaging_fee||0;const j=Tt(y.ln_order_requests?.request_data);k.woodItems.push(...j)}}else{const j=Tt(y.ln_order_requests?.request_data);u.set(f,{orderCode:f,orderDate:w.order_date,shippingCompany:w.shipping_company||"",expectedFee:y.ln_order_requests?.packaging_fee||0,woodItems:j})}}const N=[];for(const[y,w]of u){const f=c.get(y);if(!f||f.length===0)continue;const p=f.reduce((B,K)=>B+(K.actual_fee??0),0),k=f[0].carrier,j=w.woodItems.reduce((B,K)=>B+K.quantity,0),b=w.woodItems.length>0?Math.max(...w.woodItems.map(B=>Math.min(B.width,B.length))):0,_=w.woodItems.length>0?Math.max(...w.woodItems.map(B=>Math.max(B.width,B.length))):0,{totalVolumeCm3:T,totalWeightKg:$,isFreightShipping:v}=io(w.woodItems),F=v?"freight":cn(b,_),O=dn(w.woodItems.map(B=>({width:B.width,length:B.length,thickness:B.thickness,quantity:B.quantity}))),E=Math.max(1,Math.ceil($/x.weightPerUnit));let Y,R,H=!1;if(v){const B=co(w.woodItems);Y=B.tierName,H=B.isCatchAll}else R=lo(b,_,x.parcelTiers);N.push({orderCode:y,orderDate:w.orderDate,carrier:k,actualFee:p,expectedFee:w.expectedFee,recalculatedFee:O,shippingCompany:w.shippingCompany,woodItems:w.woodItems,totalQuantity:j,maxWidth:b,maxLength:_,invoiceCount:f.length,totalVolumeCm3:T,totalWeightKg:$,isFreight:v,grade:F,matchedTierName:Y,matchedParcelTierIdx:R,isCatchAll:H,unitCount:E})}return N}}),o=C.useMemo(()=>a.length===0?null:uo(a),[a]);return{dateRange:e,setDateRange:s,loading:n,error:r,matchedOrders:a,analysis:o}}function io(e){const s=ke(),{defaultDensity:a}=s;let n=0,r=0;for(const l of e){const c=parseFloat(l.thickness)||18,h=l.width||0,d=l.length||0,x=l.quantity||1;n+=h*d*c*x,r+=h*d*c*a*x}
21const o=n/1e3,i=e.length>0&&e.some(l=>{const c=Math.min(l.width,l.length),h=Math.max(l.width,l.length);return!s.parcelTiers.some(d=>c<=d.maxWidth&&h<=d.maxLength)});return{totalVolumeCm3:o,totalWeightKg:r,isFreightShipping:i}}function lo(e,s,a){const n=Math.min(e,s),r=Math.max(e,s),o=a.findIndex(i=>n<=i.maxWidth&&r<=i.maxLength);return o>=0?o:void 0}function co(e){const s=ke(),a=[...s.freightTiers].sort((c,h)=>c.priority-h.priority),n=Math.max(...s.freightTiers.map(c=>c.priority)),r=s.freightTiers.find(c=>c.priority===n);let o="미분류",i=-1,l=!1;for(const c of e){const h=Math.min(c.width,c.length),d=Math.max(c.width,c.length),x=h+d;let m=!1;for(const u of a)if(ho(h,d,x,u)){u.fee>i&&(i=u.fee,o=u.name),m=!0;break}m||(l=!0,r&&r.fee>i&&(i=r.fee,o=r.name))}return{tierName:o,isCatchAll:l}}function ho(e,s,a,n){return!(n.exactWidth!==void 0&&e!==n.exactWidth||n.exactLength!==void 0&&s!==n.exactLength||n.minWidth!==void 0&&e<n.minWidth||n.maxWidth!==void 0&&e>n.maxWidth||n.minLength!==void 0&&s<n.minLength||n.maxLength!==void 0&&s>n.maxLength||n.minSum!==void 0&&a<n.minSum||n.maxSum!==void 0&&a>n.maxSum)}function Tt(e){if(!e)return[];try{const a=(typeof e=="string"?JSON.parse(e):e)?.wood_items;return Array.isArray(a)?a.map(n=>({woodType:n.woodType||n.wood_type||"기타",thickness:String(n.thickness||"18"),width:Number(n.width)||0,length:Number(n.length)||0,quantity:Number(n.quantity)||1})):[]}catch{return[]}}function Lt(){return{count:0,avgActualFee:0,avgExpectedFee:0,totalActualFee:0,totalExpectedFee:0,avgDiff:0}}function It(e,s,a){e.count+=1,e.totalActualFee+=s,e.totalExpectedFee+=a}function Et(e){e.count>0&&(e.avgActualFee=Math.round(e.totalActualFee/e.count),e.avgExpectedFee=Math.round(e.totalExpectedFee/e.count),e.avgDiff=e.avgExpectedFee-e.avgActualFee)}function mo(e,s){return js.find(a=>e>=a.widthMin&&e<=a.widthMax&&s>=a.lengthMin&&s<=a.lengthMax)??null}function ws(e,s){return s<=0?e:Math.ceil(e*s/1e3)*1e3}function Ms(e){return e<=0?0:Math.ceil(e/1e3)*1e3}function xt(e,s){return s<=0||e<=0?0:Math.ceil(e/s/1e3)*1e3}function uo(e){const s=ke(),a=e.reduce((f,p)=>f+p.actualFee,0),n=e.reduce((f,p)=>f+p.recalculatedFee,0),r=[...new Set(e.map(f=>f.carrier))].sort(),o=new Map;for(const f of js){const p={};for(const k of r)p[k]=Lt();o.set(f.label,{bucket:f,byCarrier:p,total:Lt()})}for(const f of e){const p=mo(f.maxWidth,f.maxLength);if(!p)continue;const k=o.get(p.label);k&&(It(k.total,f.actualFee,f.recalculatedFee),k.byCarrier[f.carrier]&&It(k.byCarrier[f.carrier],f.actualFee,f.recalculatedFee))}const i=[];for(const f of o.values()){Et(f.total);for(const p of r)Et(f.byCarrier[p]);f.total.count>0&&i.push(f)}const l=new Map,c=["small","medium","large","freight"];for(const f of c)l.set(f,{count:0,totalActual:0,totalExpected:0});for(const f of e){const p=l.get(f.grade);p&&(p.count+=1,p.totalActual+=f.actualFee,p.totalExpected+=f.recalculatedFee)}const h=c.map(f=>{const p=l.get(f);return{grade:f,gradeLabel:vs[f],orderCount:p.count,totalActualFee:p.totalActual,totalExpectedFee:p.totalExpected,avgActualFee:p.count>0?Math.round(p.totalActual/p.count):0,avgExpectedFee:p.count>0?Math.round(p.totalExpected/p.count):0}}).filter(f=>f.orderCount>0),d=e.filter(f=>!f.isFreight),x=xo(d,s.parcelTiers),m=e.filter(f=>f.isFreight),u=fo(m,s.freightTiers),g=n-a,{sizeDistribution:N,coverageGaps:y,tierRecommendations:w}=go(m);return{totalMatchedOrders:e.length,totalActualFee:a,totalExpectedFee:n,avgActualFee:Math.round(a/e.length),avgExpectedFee:Math.round(n/e.length),overallDiff:g,overallDiffPercent:n>0?g/n*100:0,pivotTable:i,gradeAnalysis:h,parcelTierAnalysis:x,freightTierAnalysis:u,carriers:r,sizeDistribution:N,coverageGaps:y,tierRecommendations:w}}function xo(e,s){if(e.length===0||s.length===0)return[];const a=new Map;for(let n=0;n<s.length;n++)a.set(n,[]);for(const n of e)n.matchedParcelTierIdx!==void 0&&a.get(n.matchedParcelTierIdx)?.push(n);return[...a.entries()].filter(([,n])=>n.length>0).map(([n,r])=>{const o=s[n],i=Math.round(r.reduce((d,x)=>d+x.actualFee,0)/r.length),l=Math.round(r.reduce((d,x)=>d+x.recalculatedFee,0)/r.length),c=r.reduce((d,x)=>d+x.unitCount,0)/r.length,h=Math.round(c*10)/10;return{tierIdx:n,tierLabel:`~${o.maxWidth}×${o.maxLength}`,tierFee:o.fee,gradeLabel:vs[o.grade],orderCount:r.length,avgActualFee:i,avgRecalcFee:l,avgUnitCount:h,currentCharge:ws(o.fee,c),recommendedCharge:Ms(i),recommendedBaseFee:xt(i,c)}})}function fo(e,s){if(e.length===0||s.length===0)return[];const a=new Map;
21for(const n of s)a.set(n.name,{tierName:n.name,conditionLabel:yo(n),tierFee:n.fee,priority:n.priority,orders:[]});for(const n of e){const r=n.matchedTierName||"미분류",o=a.get(r);o&&o.orders.push(n)}return[...a.values()].filter(n=>n.orders.length>0).sort((n,r)=>n.priority-r.priority).map(n=>{const r=Math.round(n.orders.reduce((c,h)=>c+h.actualFee,0)/n.orders.length),o=Math.round(n.orders.reduce((c,h)=>c+h.recalculatedFee,0)/n.orders.length),i=n.orders.reduce((c,h)=>c+h.unitCount,0)/n.orders.length,l=Math.round(i*10)/10;return{tierName:n.tierName,conditionLabel:n.conditionLabel,tierFee:n.tierFee,priority:n.priority,orderCount:n.orders.length,totalActualFee:n.orders.reduce((c,h)=>c+h.actualFee,0),avgActualFee:r,avgRecalcFee:o,avgUnitCount:l,currentCharge:ws(n.tierFee,i),recommendedCharge:Ms(r),recommendedBaseFee:xt(r,i)}})}function go(e){const s=ke(),a=Math.max(...s.freightTiers.map(m=>m.priority)),n=s.freightTiers.find(m=>m.priority===a)?.fee??0,r=new Map;for(const m of Ft){const u=`${m.widthLabel}×${m.lengthLabel}`;r.set(u,{range:m,orders:[],tierNames:new Map})}for(const m of e){const u=Ft.find(w=>m.maxWidth>=w.widthMin&&m.maxWidth<=w.widthMax&&m.maxLength>=w.lengthMin&&m.maxLength<=w.lengthMax);if(!u)continue;const g=`${u.widthLabel}×${u.lengthLabel}`,N=r.get(g);if(!N)continue;N.orders.push(m);const y=m.matchedTierName||"미분류";N.tierNames.set(y,(N.tierNames.get(y)||0)+1)}const o=[],i=[];let l=0,c=0,h=0;for(const m of r.values()){if(m.orders.length===0)continue;const u=m.orders,g=u.map(j=>j.actualFee),N=u.filter(j=>j.isCatchAll).length,y=u.reduce((j,b)=>j+b.unitCount,0)/u.length;let w=null,f=0;for(const[j,b]of m.tierNames)b>f&&(w=j,f=b);const p=N>u.length/2,k={range:m.range,orderCount:u.length,avgActualFee:Math.round(g.reduce((j,b)=>j+b,0)/g.length),minActualFee:Math.min(...g),maxActualFee:Math.max(...g),avgUnitCount:Math.round(y*10)/10,matchedTierName:w,catchAllCount:N,isGap:p,catchAllFee:n};o.push(k),p&&(i.push(k),l+=u.length,c+=u.reduce((j,b)=>j+b.recalculatedFee,0),h+=u.reduce((j,b)=>j+b.actualFee,0))}o.sort((m,u)=>m.range.widthMin-u.range.widthMin||m.range.lengthMin-u.range.lengthMin);const d={totalGapOrders:l,totalCatchAllCost:c,totalActualCost:h,costDifference:c-h,gaps:i},x=i.filter(m=>m.orderCount>=2).map((m,u)=>{const g=xt(m.avgActualFee,m.avgUnitCount);return{range:m.range,suggestedName:`신규구간${u+1}`,suggestedConditions:po(m.range),suggestedFee:g,orderCount:m.orderCount,avgActualFee:m.avgActualFee,avgUnitCount:m.avgUnitCount,currentCatchAllFee:n,potentialSaving:Math.round((n-g)*m.avgUnitCount*m.orderCount)}});return{sizeDistribution:o,coverageGaps:d,tierRecommendations:x}}function po(e){const s={};return e.widthMin>0&&(s.minWidth=e.widthMin),e.widthMax<99999&&(s.maxWidth=e.widthMax),e.lengthMin>0&&(s.minLength=e.lengthMin),e.lengthMax<99999&&(s.maxLength=e.lengthMax),s}function yo(e){const s=[];return e.exactWidth!==void 0&&s.push(`폭=${e.exactWidth}`),e.exactLength!==void 0&&s.push(`길이=${e.exactLength}`),e.minWidth!==void 0&&s.push(`폭≥${e.minWidth}`),e.maxWidth!==void 0&&s.push(`폭≤${e.maxWidth}`),e.minLength!==void 0&&s.push(`길이≥${e.minLength}`),e.maxLength!==void 0&&s.push(`길이≤${e.maxLength}`),e.minSum!==void 0&&s.push(`합≥${e.minSum}`),e.maxSum!==void 0&&s.push(`합≤${e.maxSum}`),s.length>0?s.join(", "):"조건 없음 (catch-all)"}function At({value:e}){if(e===0)return t.jsx("span",{className:"text-gray-400",children:"0"});const s=e>0;return t.jsxs("span",{className:L("inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-xs font-medium",s?"bg-blue-50 text-blue-700":"bg-red-50 text-red-700"),children:[s?t.jsx(Ie,{className:"w-3 h-3"}):t.jsx(Me,{className:"w-3 h-3"}),s?"+":"",e.toLocaleString()]})}function Pt(e,s){return s<=0?e:Math.round(e/s)}function bo({parcelTierAnalysis:e,freightTierAnalysis:s,onGoToSettings:a}){return e.length>0||s.length>0?t.jsxs("div",{className:"space-y-4",children:[t.jsx(jo,{parcelTierAnalysis:e,freightTierAnalysis:s}),e.length>0&&t.jsxs("div",{className:"bg-white border border-gray-200 rounded-lg overflow-hidden",children:[t.jsx("div",{className:"p-4 border-b border-gray-100",children:t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx("div",{className:"p-1.5 bg-indigo-50 rounded text-indigo-600",children:t.jsx(we,{className:"w-4 h-4"})}),t.jsxs("div",{className:"flex-1",children:[t.jsx("h3",{className:"font-semibold text-gray-900",children:"일반택배 등급별 분석"}),t.jsx("p",{className:"text-sm text-gray-500",children:"사이즈 구간별 실제운임 기반 기본요금 추천"})]}),a&&t.jsxs("button",{onClick:a,className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-indigo-600 bg-indigo-50 hover:bg-indigo-100 rounded-md transition-colors",children:[t.jsx(xe,{className:"w-3.5 h-3.5"}),"설정에서 요금 수정"]})]})}),t.jsx("div",{className:"overflow-x-auto",children:t.jsxs("table",{className:"w-full text-sm table-fixed",children:[t.jsx(Bt,{}),t.jsx("thead",{className:"bg-gray-50",children:t.jsx($t,{})}),t.jsx("tbody",{children:e.map(r=>
21t.jsxs("tr",{className:"border-t border-gray-100 hover:bg-gray-50",children:[t.jsx("td",{className:"px-3 py-2.5 font-medium text-gray-800 text-xs",children:r.tierLabel}),t.jsx("td",{className:"px-3 py-2.5 text-center",children:t.jsx(No,{label:r.gradeLabel})}),t.jsxs("td",{className:"px-3 py-2.5 text-center text-xs text-gray-600",children:[r.orderCount,"건"]}),t.jsxs("td",{className:"px-3 py-2.5 text-right text-xs text-gray-500",children:[r.tierFee.toLocaleString(),"원"]}),t.jsxs("td",{className:"px-3 py-2.5 text-right text-xs font-medium text-gray-700",children:[Pt(r.avgActualFee,r.avgUnitCount).toLocaleString(),"원"]}),t.jsx("td",{className:"px-3 py-2.5 text-center",children:t.jsx(rt,{className:"w-3.5 h-3.5 text-gray-300 mx-auto"})}),t.jsx("td",{className:"px-3 py-2.5 text-right",children:t.jsx(qt,{current:r.tierFee,recommended:r.recommendedBaseFee})}),t.jsx("td",{className:"px-3 py-2.5 text-right",children:t.jsx(Rt,{value:r.recommendedBaseFee-r.tierFee})})]},r.tierIdx))})]})}),t.jsx(Yt,{})]}),s.length>0&&t.jsxs("div",{className:"bg-white border border-gray-200 rounded-lg overflow-hidden",children:[t.jsx("div",{className:"p-4 border-b border-gray-100",children:t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx("div",{className:"p-1.5 bg-orange-50 rounded text-orange-600",children:t.jsx(Te,{className:"w-4 h-4"})}),t.jsxs("div",{className:"flex-1",children:[t.jsx("h3",{className:"font-semibold text-gray-900",children:"화물택배 등급별 분석"}),t.jsx("p",{className:"text-sm text-gray-500",children:"화물택배 등급별 실제운임 기반 기본요금 추천"})]}),a&&t.jsxs("button",{onClick:a,className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-orange-600 bg-orange-50 hover:bg-orange-100 rounded-md transition-colors",children:[t.jsx(xe,{className:"w-3.5 h-3.5"}),"설정에서 요금 수정"]})]})}),t.jsx("div",{className:"overflow-x-auto",children:t.jsxs("table",{className:"w-full text-sm table-fixed",children:[t.jsx(Bt,{}),t.jsx("thead",{className:"bg-gray-50",children:t.jsx($t,{})}),t.jsx("tbody",{children:s.map(r=>t.jsxs("tr",{className:"border-t border-gray-100 hover:bg-gray-50",children:[t.jsx("td",{className:"px-3 py-2.5 font-medium text-gray-800 text-xs",children:r.conditionLabel}),t.jsx("td",{className:"px-3 py-2.5 text-center text-xs text-gray-700",children:r.tierName}),t.jsxs("td",{className:"px-3 py-2.5 text-center text-xs text-gray-600",children:[r.orderCount,"건"]}),t.jsxs("td",{className:"px-3 py-2.5 text-right text-xs text-gray-500",children:[r.tierFee.toLocaleString(),"원"]}),t.jsxs("td",{className:"px-3 py-2.5 text-right text-xs font-medium text-gray-700",children:[Pt(r.avgActualFee,r.avgUnitCount).toLocaleString(),"원"]}),t.jsx("td",{className:"px-3 py-2.5 text-center",children:t.jsx(rt,{className:"w-3.5 h-3.5 text-gray-300 mx-auto"})}),t.jsx("td",{className:"px-3 py-2.5 text-right",children:t.jsx(qt,{current:r.tierFee,recommended:r.recommendedBaseFee})}),t.jsx("td",{className:"px-3 py-2.5 text-right",children:t.jsx(Rt,{value:r.recommendedBaseFee-r.tierFee})})]},r.tierName))})]})}),t.jsx(Yt,{})]})]}):null}function Bt(){return t.jsxs("colgroup",{children:[t.jsx("col",{style:{width:"22%"}}),"   ",t.jsx("col",{style:{width:"10%"}}),"   ",t.jsx("col",{style:{width:"8%"}}),"    ",t.jsx("col",{style:{width:"13%"}}),"   ",t.jsx("col",{style:{width:"15%"}}),"   ",t.jsx("col",{style:{width:"4%"}}),"    ",t.jsx("col",{style:{width:"14%"}}),"   ",t.jsx("col",{style:{width:"14%"}}),"   "]})}function $t(){return t.jsxs("tr",{children:[t.jsx("th",{className:"px-3 py-2.5 text-left font-medium text-gray-600 text-xs",children:"사이즈 조건"}),t.jsx("th",{className:"px-3 py-2.5 text-center font-medium text-gray-600 text-xs",children:"등급"}),t.jsx("th",{className:"px-3 py-2.5 text-center font-medium text-gray-600 text-xs",children:"건수"}),t.jsx("th",{className:"px-3 py-2.5 text-right font-medium text-gray-600 text-xs",children:"현재 설정"}),t.jsx("th",{className:"px-3 py-2.5 text-right font-medium text-gray-600 text-xs",children:"건당 실제운임"}),t.jsx("th",{className:"px-3 py-2.5 text-center font-medium text-gray-600 text-xs"}),t.jsx("th",{className:"px-3 py-2.5 text-right font-medium text-gray-600 text-xs",children:"추천 요금"}),t.jsx("th",{className:"px-3 py-2.5 text-right font-medium text-gray-600 text-xs",children:"차이"})]})}function Yt(){return t.jsx("div",{className:"p-3 bg-gray-50 border-t border-gray-100 text-xs text-gray-500",children:"* 현재 설정 = 설정 탭의 기본요금. 건당 실제운임 = 평균실제운임 / 평균건수. 추천 요금 = ceil(건당실제운임 / 1,000) × 1,000."})}function No({label:e}){return t.jsx("span",{className:"text-xs font-medium text-gray-700",children:e})}function qt({current:e,recommended:s}){if(s===0)return t.jsx("span",{className:"text-xs text-gray-400",children:"-"});const a=e===s,n=s>e;return t.jsxs("span",{className:L("text-xs font-bold",a?"text-gray-500":n?"text-red-600":"text-blue-600"),children:[s.toLocaleStr
21ing(),"원"]})}function Rt({value:e}){if(e===0)return t.jsx("span",{className:"text-xs text-gray-400",children:"동일"});const s=e>0;return t.jsxs("span",{className:L("text-xs font-medium",s?"text-red-600":"text-blue-600"),children:[s?"▲":"▼",Math.abs(e).toLocaleString()]})}function jo({parcelTierAnalysis:e,freightTierAnalysis:s}){const a=[...e.map(o=>({name:`일반 ${o.tierLabel}`,diff:o.recommendedBaseFee-o.tierFee,count:o.orderCount})),...s.map(o=>({name:o.tierName,diff:o.recommendedBaseFee-o.tierFee,count:o.orderCount}))].filter(o=>o.diff!==0&&o.count>=3);if(a.length===0)return null;const n=a.filter(o=>o.diff>0),r=a.filter(o=>o.diff<0);return t.jsxs("div",{className:"bg-gradient-to-r from-amber-50 to-yellow-50 border border-amber-200 rounded-lg p-4",children:[t.jsxs("div",{className:"flex items-start gap-2 mb-3",children:[t.jsx(es,{className:"w-4 h-4 text-amber-600 mt-0.5"}),t.jsx("h4",{className:"font-semibold text-gray-900 text-sm",children:"요금 조정 인사이트"})]}),t.jsxs("div",{className:"space-y-2 text-sm",children:[n.length>0&&t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx("span",{className:"text-red-500 font-bold text-xs mt-0.5",children:"인상 권장"}),t.jsxs("span",{className:"text-gray-700",children:[n.map(o=>`${o.name} (+${o.diff.toLocaleString()}원)`).join(", "),"— 현재 기본요금이 실제운임 대비 낮아 손실이 발생하고 있습니다."]})]}),r.length>0&&t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx("span",{className:"text-blue-500 font-bold text-xs mt-0.5",children:"인하 가능"}),t.jsxs("span",{className:"text-gray-700",children:[r.map(o=>`${o.name} (${o.diff.toLocaleString()}원)`).join(", "),"— 현재 기본요금이 실제운임보다 높아 마진이 있습니다."]})]})]})]})}function vo({sizeDistribution:e,coverageGaps:s,tierRecommendations:a,freightTierAnalysis:n,onGoToSettings:r}){if(e.length===0&&n.length===0)return null;const o=n.filter(l=>l.orderCount>=3&&l.recommendedBaseFee!==l.tierFee&&l.recommendedBaseFee>0),i=a.length>0||o.length>0;return t.jsxs("div",{className:"space-y-4",children:[s.totalGapOrders>0&&t.jsx(wo,{coverageGaps:s}),e.length>0&&t.jsx(Mo,{cells:e}),i&&t.jsx(ko,{modificationSuggestions:o,newRecommendations:a,onGoToSettings:r})]})}function wo({coverageGaps:e}){return t.jsxs("div",{className:"bg-gradient-to-r from-red-50 to-orange-50 border border-red-200 rounded-lg p-4",children:[t.jsxs("div",{className:"flex items-start gap-2 mb-3",children:[t.jsx(Ce,{className:"w-4 h-4 text-red-500 mt-0.5 flex-shrink-0"}),t.jsxs("div",{children:[t.jsx("h4",{className:"font-semibold text-gray-900 text-sm",children:"커버리지 갭 감지 (화물택배)"}),t.jsxs("p",{className:"text-sm text-gray-600 mt-0.5",children:["현재 화물 등급 설정에서 매칭되지 않는 주문이 ",t.jsxs("strong",{className:"text-red-600",children:[e.totalGapOrders,"건"]})," 발견되었습니다. 이 주문들은 catch-all(최고 요금 등급)이 자동 적용되고 있습니다."]}),t.jsx("p",{className:"text-xs text-gray-400 mt-1",children:"* 일반택배는 미매칭 시 자동으로 화물로 전환되어 갭이 발생하지 않습니다"})]})]}),t.jsxs("div",{className:"grid grid-cols-3 gap-3 mt-3",children:[t.jsxs("div",{className:"bg-white/70 rounded-lg p-3",children:[t.jsx("p",{className:"text-xs text-gray-500",children:"catch-all 부과 총액"}),t.jsxs("p",{className:"text-lg font-bold text-red-600",children:[e.totalCatchAllCost.toLocaleString(),"원"]})]}),t.jsxs("div",{className:"bg-white/70 rounded-lg p-3",children:[t.jsx("p",{className:"text-xs text-gray-500",children:"실제운임 총액"}),t.jsxs("p",{className:"text-lg font-bold text-gray-800",children:[e.totalActualCost.toLocaleString(),"원"]})]}),t.jsxs("div",{className:"bg-white/70 rounded-lg p-3",children:[t.jsx("p",{className:"text-xs text-gray-500",children:"차이 (과다 징수)"}),t.jsxs("p",{className:L("text-lg font-bold",e.costDifference>0?"text-blue-600":"text-red-600"),children:[e.costDifference>0?"+":"",e.costDifference.toLocaleString(),"원"]})]})]}),t.jsx("div",{className:"mt-3 space-y-1",children:e.gaps.map(s=>t.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[t.jsx("span",{className:"text-red-400",children:"●"}),t.jsxs("span",{className:"text-gray-700",children:["폭 ",s.range.widthLabel," × 길이 ",s.range.lengthLabel]}),t.jsx("span",{className:"text-gray-400",children:"—"}),t.jsxs("span",{className:"text-gray-600",children:[s.orderCount,"건"]}),t.jsx("span",{className:"text-gray-400",children:"|"}),t.jsxs("span",{className:"text-gray-600",children:["평균 실제운임 ",s.avgActualFee.toLocaleStr
21ing(),"원"]}),t.jsx("span",{className:"text-gray-400",children:"|"}),t.jsxs("span",{className:"text-red-500 text-xs",children:["catch-all ",s.catchAllFee.toLocaleString(),"원 적용 중"]})]},`${s.range.widthLabel}×${s.range.lengthLabel}`))})]})}function Mo({cells:e}){const[s,a]=C.useState(!1),n=e.filter(r=>r.isGap).length;return t.jsxs("div",{className:"bg-white border border-gray-200 rounded-lg overflow-hidden",children:[t.jsxs("button",{type:"button",onClick:()=>a(r=>!r),className:"w-full p-4 flex items-center gap-2 text-left hover:bg-gray-50 transition-colors",children:[t.jsx("div",{className:"p-1.5 bg-violet-50 rounded text-violet-600",children:t.jsx(Rn,{className:"w-4 h-4"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("h3",{className:"font-semibold text-gray-900",children:"화물 사이즈별 실제운임 분포"}),t.jsxs("p",{className:"text-sm text-gray-500",children:["화물택배 주문의 폭×길이 구간별 실제운임 통계와 현재 매칭 등급을 보여줍니다",t.jsxs("span",{className:"ml-2 text-gray-400",children:["(",e.length,"개 구간",n>0?`, 갭 ${n}건`:"",")"]})]})]}),s?t.jsx(Gn,{className:"w-5 h-5 text-gray-400 flex-shrink-0"}):t.jsx(Hn,{className:"w-5 h-5 text-gray-400 flex-shrink-0"})]}),s&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"overflow-x-auto border-t border-gray-100",children:t.jsxs("table",{className:"w-full text-sm",children:[t.jsx("thead",{className:"bg-gray-50",children:t.jsxs("tr",{children:[t.jsx("th",{className:"px-3 py-2.5 text-left font-medium text-gray-600 text-xs",children:"폭 구간"}),t.jsx("th",{className:"px-3 py-2.5 text-left font-medium text-gray-600 text-xs",children:"길이 구간"}),t.jsx("th",{className:"px-3 py-2.5 text-center font-medium text-gray-600 text-xs",children:"건수"}),t.jsx("th",{className:"px-3 py-2.5 text-right font-medium text-gray-600 text-xs",children:"평균 실제운임"}),t.jsx("th",{className:"px-3 py-2.5 text-right font-medium text-gray-600 text-xs",children:"최소"}),t.jsx("th",{className:"px-3 py-2.5 text-right font-medium text-gray-600 text-xs",children:"최대"}),t.jsx("th",{className:"px-3 py-2.5 text-center font-medium text-gray-600 text-xs",children:"평균 건수"}),t.jsx("th",{className:"px-3 py-2.5 text-left font-medium text-gray-600 text-xs",children:"매칭 등급"}),t.jsx("th",{className:"px-3 py-2.5 text-center font-medium text-gray-600 text-xs",children:"상태"})]})}),t.jsx("tbody",{children:e.map(r=>{const o=`${r.range.widthLabel}×${r.range.lengthLabel}`;return t.jsxs("tr",{className:L("border-t border-gray-100 hover:bg-gray-50",r.isGap&&"bg-red-50/50"),children:[t.jsx("td",{className:"px-3 py-2.5 text-xs font-medium text-gray-800",children:r.range.widthLabel}),t.jsx("td",{className:"px-3 py-2.5 text-xs font-medium text-gray-800",children:r.range.lengthLabel}),t.jsx("td",{className:"px-3 py-2.5 text-center text-xs text-gray-600",children:r.orderCount}),t.jsxs("td",{className:"px-3 py-2.5 text-right text-xs font-medium text-gray-700",children:[r.avgActualFee.toLocaleString(),"원"]}),t.jsx("td",{className:"px-3 py-2.5 text-right text-xs text-gray-500",children:r.minActualFee.toLocaleString()}),t.jsx("td",{className:"px-3 py-2.5 text-right text-xs text-gray-500",children:r.maxActualFee.toLocaleString()}),t.jsx("td",{className:"px-3 py-2.5 text-center text-xs text-gray-600",children:r.avgUnitCount}),t.jsxs("td",{className:"px-3 py-2.5 text-xs",children:[r.matchedTierName?t.jsx("span",{className:"text-gray-700",children:r.matchedTierName}):t.jsx("span",{className:"text-gray-400",children:"-"}),r.catchAllCount>0&&t.jsxs("span",{className:"ml-1 text-red-500 text-[10px]",children:["(catch-all ",r.catchAllCount,"건)"]})]}),t.jsx("td",{className:"px-3 py-2.5 text-center",children:r.isGap?t.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[10px] font-medium text-red-600 bg-red-100 px-1.5 py-0.5 rounded",children:[t.jsx(Ce,{className:"w-3 h-3"}),"갭"]}):t.jsx("span",{className:"text-[10px] font-medium text-green-600 bg-green-100 px-1.5 py-0.5 rounded",children:"정상"})})]},o)})})]})}),t.jsx("div",{className:"p-3 bg-gray-50 border-t border-gray-100 text-xs text-gray-500",children:"* 폭 = min(가로,세로), 길이 = max(가로,세로). 갭 = 주문 과반이 catch-all 적용. 평균 건수 = ceil(총무게/15kg)."})]})]})}function ko({modificationSuggestions:e,newRecommendations:s,onGoToSettings:a}){return t.jsxs("div",{className:"bg-gradient-to-r from-emerald-50 to-teal-50 border border-emerald-200 rounded-lg overflow-hidden",children:[t.jsx("div",{className:"p-4 border-b border-emerald-100",children:t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx(es,{className:"w-4 h-4 text-emerald-600 mt-0.5"}),t.jsxs("div",{children:[t.jsx("h4",{className:"font-semibold text-gray-900 text-sm",children:"등급 추천"}),t.jsx("p",{className:"text-sm text-gray-600",children:"실제운임 데이터를 기반으로 기존 등급 요금 수정과 신규 등급 추가를 추천합니다."})]})]})}),t.jsxs("div",{className:"p-4 space-y-4",children:[e.length>0&&t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("h5",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wider",children:"기존 등급 요금 수정 권장"}),a&&t.jsxs("button",{onClick:a,className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-amber-700 bg-amber-100 hover:bg-amber-200 rounded-lg transition-colors",children:[t.jsx(xe,{className:"w-3.5 h-3.5"}),"설정에서 요금 수정하기"]})]}),e.map(n=>t.jsx(Co,{tier:n},n.tierName))]}),s.length>0&&t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("h5",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wider",children:"신규 등급 추가 권장"}),a&&t.jsxs("button",{onClick:a,className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-emerald-700 bg-emerald-100 hover:bg-emerald-200 rounded-lg transition-colors",children:[t.jsx(xe,{className:"w-3.5 h-3.5"}),"설정에서 등급 추가하기"]})]}),s.map((n,r)=>t.jsx(Do,{rec:n},r))]})]})]})}function Co({tier:e}){const s=e.recommendedBaseFee-e.tierFee,a=s>0;return t.jsx("div",{className:"bg-white rounded-lg border border-gray-200 p-4",children:t.jsx("div",{className:"flex items-center justify-between",children:t.jsxs("div",{className:"space-y-1.5",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-sm font-semibold text-gray-800",children:e.tierName}),t.jsx("span",{className:"text-xs text-gray-400",children:"|"}),t.jsxs("span",{className:"text-xs text-gray-500",children:[e.orderCount,"건 분석"]}),t.jsx("span",{className:"text-xs text-gray-400",children:"|"}),t.jsx("span",{className:"text-xs text-gray-500",children:e.conditionLabel})]}),t.jsxs("div",{className:"flex items-center gap-3 text-xs",children:[t.jsx("span",{className:"text-gray-500",children:"현재 요금"}),t.jsxs("span",{className:"font-medium text-gray-700",children:[e.tierFee.toLocaleStr
21ing(),"원"]}),t.jsx(rt,{className:"w-3 h-3 text-gray-300"}),t.jsx("span",{className:"text-gray-500",children:"추천 요금"}),t.jsxs("span",{className:L("font-bold",a?"text-red-600":"text-blue-600"),children:[e.recommendedBaseFee.toLocaleString(),"원"]}),t.jsxs("span",{className:L("text-xs font-medium",a?"text-red-500":"text-blue-500"),children:["(",a?"▲":"▼",Math.abs(s).toLocaleString(),"원)"]})]}),t.jsxs("div",{className:"flex items-center gap-1 text-xs text-gray-500",children:[a?t.jsx(Ie,{className:"w-3 h-3 text-red-400"}):t.jsx(Me,{className:"w-3 h-3 text-blue-400"}),t.jsxs("span",{children:["건당 실제운임 평균 ",Math.round(e.avgActualFee/e.avgUnitCount).toLocaleString(),"원",a?" — 현재 요금이 실제운임보다 낮아 손실 발생":" — 현재 요금이 실제운임보다 높아 마진 여유"]})]})]})})})}function Do({rec:e}){const s=[];return e.suggestedConditions.minWidth&&s.push(`폭 ≥ ${e.suggestedConditions.minWidth}`),e.suggestedConditions.maxWidth&&s.push(`폭 ≤ ${e.suggestedConditions.maxWidth}`),e.suggestedConditions.minLength&&s.push(`길이 ≥ ${e.suggestedConditions.minLength}`),e.suggestedConditions.maxLength&&s.push(`길이 ≤ ${e.suggestedConditions.maxLength}`),t.jsx("div",{className:"bg-white rounded-lg border border-gray-200 p-4",children:t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("span",{className:"text-sm font-semibold text-gray-800",children:["폭 ",e.range.widthLabel," × 길이 ",e.range.lengthLabel]}),t.jsx("span",{className:"text-xs text-gray-400",children:"|"}),t.jsxs("span",{className:"text-xs text-gray-500",children:[e.orderCount,"건 분석"]}),t.jsx("span",{className:"inline-flex items-center text-[10px] font-medium text-orange-600 bg-orange-100 px-1.5 py-0.5 rounded",children:"미등록 구간"})]}),t.jsxs("div",{className:"grid grid-cols-2 gap-x-6 gap-y-1 text-xs",children:[t.jsxs("div",{children:[t.jsx("span",{className:"text-gray-500",children:"추천 조건: "}),t.jsx("span",{className:"text-gray-700",children:s.join(", ")})]}),t.jsxs("div",{children:[t.jsx("span",{className:"text-gray-500",children:"평균 실제운임: "}),t.jsxs("span",{className:"text-gray-700",children:[e.avgActualFee.toLocaleString(),"원"]})]}),t.jsxs("div",{children:[t.jsx("span",{className:"text-gray-500",children:"추천 기본요금: "}),t.jsxs("span",{className:"font-bold text-emerald-700",children:[e.suggestedFee.toLocaleString(),"원"]})]}),t.jsxs("div",{children:[t.jsx("span",{className:"text-gray-500",children:"현재 catch-all: "}),t.jsxs("span",{className:"text-red-600",children:[e.currentCatchAllFee.toLocaleString(),"원"]})]})]}),e.potentialSaving>0&&t.jsxs("div",{className:"flex items-center gap-1 text-xs",children:[t.jsx(Me,{className:"w-3 h-3 text-blue-500"}),t.jsxs("span",{className:"text-blue-600 font-medium",children:["등급 추가 시 약 ",e.potentialSaving.toLocaleString(),"원 과다징수 절감 예상"]})]})]})})}const ks={cj:"text-blue-700",chunil:"text-green-700",kyungdong:"text-orange-700"},_o=[{label:"30일",days:30},{label:"60일",days:60},{label:"90일",days:90}];function So({orders:e}){const[s,a]=C.useState(!1);return e.length===0?null:t.jsxs("div",{className:"bg-white border border-gray-200 rounded-lg overflow-hidden",children:[t.jsxs("button",{className:"w-full p-4 flex items-center justify-between hover:bg-gray-50 transition-colors",onClick:()=>a(!s),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Ee,{className:"w-4 h-4 text-gray-600"}),t.jsx("span",{className:"font-medium text-gray-900",children:"상세 주문 데이터"}),t.jsxs("span",{className:"text-sm text-gray-400",children:["(",e.length,"건)"]})]}),t.jsx("span",{className:"text-sm text-gray-400",children:s?"접기":"펼치기"})]}),s&&t.jsxs("div",{className:"overflow-x-auto max-h-[500px]",children:[t.jsxs("table",{className:"w-full text-xs",children:[t.jsx("thead",{className:"bg-gray-50 sticky top-0",children:t.jsxs("tr",{children:[t.jsx("th",{className:"px-3 py-2 text-left font-medium text-gray-600",children:"주문번호"}),t.jsx("th",{className:"px-3 py-2 text-left font-medium text-gray-600",children:"주문일"}),t.jsx("th",{className:"px-3 py-2 text-center font-medium text-gray-600",children:"택배사"}),t.jsx("th",{className:"px-3 py-2 text-center font-medium text-gray-600",children:"수량"}),t.jsx("th",{className:"px-3 py-2 text-center font-medium text-gray-600",children:"최대 폭×길이"}),t.jsx("th",{className:"px-3 py-2 text-center font-medium text-gray-600",children:"목재"}),t.jsx("th",{className:"px-3 py-2 text-center font-medium text-gray-600",children:"두께"}),t.jsx("th",{className:"px-3 py-2 text-right font-medium text-gray-600",children:"현재 로직"}),t.jsx("th",{className:"px-3 py-2 text-right font-medium text-gray-600",children:"실제운임"}),t.jsx("th",{className:"px-3 py-2 text-right font-medium text-gray-600",children:"차액"})]})}),t.jsx("tbody",{children:e.slice(0,200).map(n=>{const r=n.recalculatedFee-n.actualFee,o=[...new Set(n.woodItems.map(l
21=>l.woodType))],i=[...new Set(n.woodItems.map(l=>l.thickness))];return t.jsxs("tr",{className:"border-t border-gray-100 hover:bg-gray-50",children:[t.jsx("td",{className:"px-3 py-1.5 font-mono text-gray-700",children:n.orderCode}),t.jsx("td",{className:"px-3 py-1.5 text-gray-500",children:n.orderDate?.slice(5,10)}),t.jsx("td",{className:L("px-3 py-1.5 text-center",ks[n.carrier]||"text-gray-600"),children:ts[n.carrier]||n.carrier}),t.jsxs("td",{className:"px-3 py-1.5 text-center",children:[n.totalQuantity,"장"]}),t.jsxs("td",{className:"px-3 py-1.5 text-center text-gray-600",children:[n.maxWidth,"×",n.maxLength]}),t.jsx("td",{className:"px-3 py-1.5 text-center text-gray-600 max-w-[120px] truncate",children:o.join(", ")}),t.jsxs("td",{className:"px-3 py-1.5 text-center",children:[i.join("/"),"T"]}),t.jsx("td",{className:"px-3 py-1.5 text-right",children:n.recalculatedFee.toLocaleString()}),t.jsx("td",{className:"px-3 py-1.5 text-right",children:n.actualFee.toLocaleString()}),t.jsxs("td",{className:L("px-3 py-1.5 text-right font-medium",r>0?"text-blue-600":r<0?"text-red-600":"text-gray-400"),children:[r>0?"+":"",r.toLocaleString()]})]},n.orderCode)})})]}),e.length>200&&t.jsxs("div",{className:"p-3 text-center text-xs text-gray-400",children:["상위 200건만 표시됩니다 (전체 ",e.length,"건)"]})]})]})}function Oo({onGoToSettings:e}){const{dateRange:s,setDateRange:a,loading:n,error:r,matchedOrders:o,analysis:i}=oo();return t.jsxs("div",{className:"space-y-6",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Ee,{className:"w-5 h-5 text-indigo-600"}),t.jsx("h2",{className:"text-lg font-semibold",children:"실제운임 분석"})]}),t.jsxs("div",{className:"bg-white border border-gray-200 rounded-lg p-4 flex items-center gap-3 flex-wrap",children:[t.jsx("span",{className:"text-sm text-gray-500",children:"기간:"}),_o.map(l=>t.jsxs(V,{variant:"outline",size:"sm",className:"h-8 text-xs",onClick:()=>a({from:Be(new Date,l.days),to:new Date}),children:["최근 ",l.label]},l.days)),t.jsxs(Ne,{children:[t.jsx(je,{asChild:!0,children:t.jsxs(V,{variant:"outline",size:"sm",className:"h-8 text-xs gap-1",children:[t.jsx(We,{className:"w-3.5 h-3.5"}),s.from?z(s.from,"yy.MM.dd",{locale:he}):"시작일"]})}),t.jsx(ve,{className:"w-auto p-0 bg-white",align:"start",children:t.jsx(Ae,{mode:"single",selected:s.from,onSelect:l=>l&&a(c=>({...c,from:l})),locale:he,initialFocus:!0})})]}),t.jsx("span",{className:"text-gray-400 text-xs",children:"~"}),t.jsxs(Ne,{children:[t.jsx(je,{asChild:!0,children:t.jsxs(V,{variant:"outline",size:"sm",className:"h-8 text-xs gap-1",children:[t.jsx(We,{className:"w-3.5 h-3.5"}),s.to?z(s.to,"yy.MM.dd",{locale:he}):"종료일"]})}),t.jsx(ve,{className:"w-auto p-0 bg-white",align:"start",children:t.jsx(Ae,{mode:"single",selected:s.to,onSelect:l=>l&&a(c=>({...c,to:l})),locale:he,initialFocus:!0,disabled:l=>s.from?l<s.from:!1})})]}),n&&t.jsx(Fe,{className:"w-4 h-4 animate-spin text-gray-400"}),t.jsxs("span",{className:"ml-auto text-sm text-gray-500",children:["매칭 주문: ",t.jsxs("strong",{className:"text-indigo-600",children:[o.length,"건"]})]})]}),n&&t.jsxs("div",{className:"flex items-center justify-center py-16 text-gray-400",children:[t.jsx(Fe,{className:"w-5 h-5 mr-2 animate-spin"}),t.jsx("span",{children:"분석 데이터 로딩 중..."})]}),!n&&r&&t.jsxs("div",{className:"text-center py-16",children:[t.jsx("div",{className:"text-red-500 mb-2",children:"데이터 조회 중 오류가 발생했습니다"}),t.jsx("pre",{className:"text-xs text-gray-500 bg-gray-50 rounded p-3 inline-block max-w-lg text-left",children:r instanceof Error?r.message:JSON.stringify(r,null,2)})]}),!n&&!r&&!i&&t.jsxs("div",{className:"text-center py-16 text-gray-400",children:[t.jsx(Ee,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),t.jsx("p",{children:"매칭된 주문이 없습니다. 배송비 추적 탭에서 엑셀을 먼저 업로드하세요."})]}),!n&&i&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"grid grid-cols-5 gap-4",children:[t.jsx(ye,{label:"매칭 주문",value:`${i.totalMatchedOrders}건`}),t.jsx(ye,{label:"현재로직 평균",value:`${i.avgExpectedFee.toLocaleStr
21ing()}원`}),t.jsx(ye,{label:"평균 실제운임",value:`${i.avgActualFee.toLocaleString()}원`}),t.jsx(ye,{label:"평균 차액",value:`${i.overallDiff>0?"+":""}${Math.round(i.overallDiff/i.totalMatchedOrders).toLocaleString()}원`,variant:i.overallDiff>0?"positive":i.overallDiff<0?"negative":"neutral"}),t.jsx(ye,{label:"차액률",value:`${i.overallDiffPercent>0?"+":""}${i.overallDiffPercent.toFixed(1)}%`,variant:i.overallDiff>0?"positive":i.overallDiff<0?"negative":"neutral"})]}),t.jsx(vo,{sizeDistribution:i.sizeDistribution,coverageGaps:i.coverageGaps,tierRecommendations:i.tierRecommendations,freightTierAnalysis:i.freightTierAnalysis,onGoToSettings:e}),t.jsx(bo,{parcelTierAnalysis:i.parcelTierAnalysis,freightTierAnalysis:i.freightTierAnalysis,onGoToSettings:e}),t.jsx(Wo,{title:"사이즈 구간 × 택배사별 실제운임",description:"목재의 최대 폭(좁은쪽) × 최대 길이 구간별로 택배사 실제 평균 운임을 비교합니다",icon:t.jsx(we,{className:"w-4 h-4"}),pivotTable:i.pivotTable,carriers:i.carriers}),t.jsx(So,{orders:o})]})]})}function ye({label:e,value:s,variant:a="neutral"}){return t.jsxs("div",{className:L("rounded-xl border p-4",a==="positive"&&"border-blue-200 bg-blue-50",a==="negative"&&"border-red-200 bg-red-50",a==="neutral"&&"border-gray-200 bg-white"),children:[t.jsx("p",{className:"text-sm text-gray-500",children:e}),t.jsx("p",{className:L("text-xl font-bold mt-1",a==="positive"&&"text-blue-600",a==="negative"&&"text-red-600",a==="neutral"&&"text-gray-900"),children:s})]})}function Wo({title:e,description:s,icon:a,pivotTable:n,carriers:r}){return t.jsxs("div",{className:"bg-white border border-gray-200 rounded-lg overflow-hidden",children:[t.jsx("div",{className:"p-4 border-b border-gray-100",children:t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx("div",{className:"p-1.5 bg-indigo-50 rounded text-indigo-600",children:a}),t.jsxs("div",{children:[t.jsx("h3",{className:"font-semibold text-gray-900",children:e}),t.jsx("p",{className:"text-sm text-gray-500",children:s})]})]})}),t.jsx("div",{className:"overflow-x-auto",children:t.jsxs("table",{className:"w-full text-sm",children:[t.jsxs("thead",{className:"bg-gray-50",children:[t.jsxs("tr",{children:[t.jsx("th",{className:"px-4 py-3 text-left font-medium text-gray-600 whitespace-nowrap",rowSpan:2,children:"사이즈 구간 (폭×길이 mm)"}),t.jsx("th",{className:"px-3 py-3 text-center font-medium text-gray-600 whitespace-nowrap",rowSpan:2,children:"건수"}),r.map(o=>t.jsx("th",{className:"text-center border-l border-gray-200",colSpan:2,children:t.jsx("div",{className:L("px-3 py-2 font-medium whitespace-nowrap",ks[o]||"text-gray-600"),children:ts[o]||o})},o)),t.jsx("th",{className:"text-center border-l border-gray-200",colSpan:2,children:t.jsx("div",{className:"px-3 py-2 font-medium text-gray-700",children:"전체 평균"})})]}),t.jsxs("tr",{className:"bg-gray-50/50",children:[r.map(o=>t.jsxs(M.Fragment,{children:[t.jsx("th",{className:"px-2 py-1 text-center text-xs text-gray-500 font-normal border-l border-gray-200",children:"실제운임"}),t.jsx("th",{className:"px-2 py-1 text-center text-xs text-gray-500 font-normal",children:"차액"})]},o)),t.jsx("th",{className:"px-2 py-1 text-center text-xs text-gray-500 font-normal border-l border-gray-200",children:"실제운임"}),t.jsx("th",{className:"px-2 py-1 text-center text-xs text-gray-500 font-normal",children:"차액"})]})]}),t.jsx("tbody",{children:n.map(o=>t.jsxs("tr",{className:"border-t border-gray-100 hover:bg-gray-50",children:[t.jsx("td",{className:"px-4 py-2.5 font-medium text-gray-800 whitespace-nowrap",children:o.bucket.label}),t.jsx("td",{className:"px-3 py-2.5 text-center text-gray-600",children:o.total.count}),r.map(i=>{const l=o.byCarrier[i];return!l||l.count===0?t.jsxs(M.Fragment,{children:[t.jsx("td",{className:"px-2 py-2.5 text-center text-gray-300 border-l border-gray-100",children:"-"}),t.jsx("td",{className:"px-2 py-2.5 text-center text-gray-300",children:"-"})]},i):t.jsxs(M.Fragment,{children:[t.jsxs("td",{className:"px-2 py-2.5 text-center whitespace-nowrap border-l border-gray-100",children:[t.jsx("span",{className:"text-gray-800",children:l.avgActualFee.toLocaleStr
21ing()}),t.jsxs("span",{className:"text-gray-400 text-xs ml-1",children:["(",l.count,")"]})]}),t.jsx("td",{className:"px-2 py-2.5 text-center",children:t.jsx(At,{value:l.avgDiff})})]},i)}),t.jsx("td",{className:"px-2 py-2.5 text-center font-medium text-gray-800 whitespace-nowrap border-l border-gray-200",children:o.total.avgActualFee.toLocaleString()}),t.jsx("td",{className:"px-2 py-2.5 text-center",children:t.jsx(At,{value:o.total.avgDiff})})]},o.bucket.label))})]})}),t.jsx("div",{className:"p-3 bg-gray-50 border-t border-gray-100 text-xs text-gray-500",children:"* 차액 = 현재로직 - 실제운임. 양수(파란색) = 이익, 음수(빨간색) = 손실. 괄호 안 숫자 = 해당 택배사 건수"})]})}function gi(){const[e,s]=an("tracking"),a=nn(),n=C.useCallback(()=>{a.invalidateQueries({queryKey:["admin","shippingFeeTracking"]}),a.invalidateQueries({queryKey:["admin","shippingCostAnalysis"]})},[a]);return t.jsxs("div",{className:"p-6",children:[t.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[t.jsx(Te,{className:"w-8 h-8 text-blue-600"}),t.jsxs("div",{children:[t.jsx("h1",{className:"text-[22px] font-bold text-gray-900",children:"배송비 관리"}),t.jsx("p",{className:"text-sm text-gray-500",children:"배송비 추적 및 안전포장비 설정을 관리합니다"})]})]}),t.jsxs(rn,{value:e,onValueChange:s,children:[t.jsxs(on,{className:"mb-6",children:[t.jsxs(Ze,{value:"tracking",className:"gap-2",children:[t.jsx(Te,{className:"w-4 h-4"}),"배송비 추적"]}),t.jsxs(Ze,{value:"analysis",className:"gap-2",children:[t.jsx(Ee,{className:"w-4 h-4"}),"실제운임 분석"]}),t.jsxs(Ze,{value:"settings",className:"gap-2",children:[t.jsx(xe,{className:"w-4 h-4"}),"안전포장비 설정"]})]}),t.jsx(Ve,{value:"tracking",children:t.jsx(Fo,{})}),t.jsx(Ve,{value:"analysis",children:t.jsx(Oo,{onGoToSettings:()=>s("settings")})}),t.jsx(Ve,{value:"settings",children:t.jsx(qr,{onSaved:n})})]})]})}function Fo(){const{filteredOrders:e,loading:s,searchTerm:a,setSearchTerm:n,showOnlyMatched:r,setShowOnlyMatched:o,carrierFilter:i,setCarrierFilter:l,dateRange:c,setDateRange:h,stats:d}=sa();return t.jsxs("div",{className:"space-y-6",children:[t.jsx(Tr,{dateRange:c,setDateRange:h,searchTerm:a,setSearchTerm:n,showOnlyMatched:r,setShowOnlyMatched:o,carrierFilter:i,setCarrierFilter:l}),t.jsxs("div",{className:"flex gap-4",children:[t.jsxs("div",{className:"w-[145px] flex-shrink-0 bg-white rounded-xl border border-gray-200 p-4",children:[t.jsx("p",{className:"text-sm text-gray-500",children:"총 주문"}),t.jsxs("p",{className:"text-[22px] font-bold text-gray-900",children:[d.totalOrders,"건"]})]}),t.jsxs("div",{className:"w-[145px] flex-shrink-0 bg-white rounded-xl border border-gray-200 p-4",children:[t.jsx("p",{className:"text-sm text-gray-500",children:"운임 매칭"}),t.jsxs("p",{className:"text-[22px] font-bold text-green-600",children:[d.matchedWithExcel,"건"]})]}),t.jsxs("div",{className:"w-[145px] flex-shrink-0 bg-white rounded-xl border border-gray-200 p-4",children:[t.jsx("p",{className:"text-sm text-gray-500",children:"미매칭"}),t.jsxs("p",{className:"text-[22px] font-bold text-gray-400",children:[d.unmatchedWithExcel,"건"]})]}),t.jsxs("div",{className:"w-[145px] flex-shrink-0 rounded-xl border border-orange-200 bg-orange-50 p-4",children:[t.jsx("p",{className:"text-sm text-gray-500",children:"다건 출고"}),t.jsxs("p",{className:"text-[22px] font-bold text-orange-600",children:[d.multipleShipments,"건"]})]}),t.jsxs("div",{className:"flex-1 bg-white rounded-xl border border-gray-200 p-4",children:[t.jsx("p",{className:"text-sm text-gray-500",children:"고객 청구 배송비"}),t.jsxs("p",{className:"text-[22px] font-bold text-gray-900",children:[d.expectedFeeTotal.toLocaleString(),"원"]})]}),t.jsxs("div",{className:"flex-1 bg-white rounded-xl border border-gray-200 p-4",children:[t.jsx("p",{className:"text-sm text-gray-500",children:"택배사 운임비"}),t.jsxs("p",{className:"text-[22px] font-bold text-gray-900",children:[d.actualFeeTotal.toLocaleString(),"원"]})]}),t.jsxs("div",{className:L("flex-1 rounded-xl border p-4",d.feeDifference>0?"border-blue-200 bg-blue-50":d.feeDifference<0?"border-red-200 bg-red-50":"bg-white border-gray-200"),children:[t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx("p",{className:"text-sm text-gray-500",children:"차액 합계"}),d.feeDifference>0?t.jsx(Ie,{className:"w-4 h-4 text-blue-600"}):d.feeDifference<0?t.jsx(Me,{className:"w-4 h-4 text-red-600"}):t.jsx(jt,{className:"w-4 h-4 text-gray-400"})]}),t.jsxs("p",{className:L("text-[22px] font-bold",d.feeDifference>0?"text-blue-600":d.feeDifference<0?"text-red-600":"text-gray-900"),children:[d.feeDifference>
210?"+":"",d.feeDifference.toLocaleString(),"원"]})]}),t.jsxs("div",{className:L("flex-1 rounded-xl border p-4",d.differencePercent>0?"border-blue-200 bg-blue-50":d.differencePercent<0?"border-red-200 bg-red-50":"bg-white border-gray-200"),children:[t.jsx("p",{className:"text-sm text-gray-500",children:"차액률"}),t.jsxs("p",{className:L("text-[22px] font-bold",d.differencePercent>0?"text-blue-600":d.differencePercent<0?"text-red-600":"text-gray-900"),children:[d.differencePercent>0?"+":"",d.differencePercent.toFixed(1),"%"]})]})]}),d.currentLogicMatchedCount>0&&t.jsxs("div",{className:"flex gap-4",children:[t.jsxs("div",{className:"w-[145px] flex-shrink-0 bg-emerald-50 rounded-xl border border-emerald-200 p-4",children:[t.jsx("p",{className:"text-sm text-gray-500",children:"로직 적용"}),t.jsxs("p",{className:"text-[22px] font-bold text-emerald-700",children:[d.currentLogicMatchedCount,"건"]})]}),t.jsxs("div",{className:"flex-1 bg-emerald-50 rounded-xl border border-emerald-200 p-4",children:[t.jsx("p",{className:"text-sm text-gray-500",children:"현재 로직 배송비"}),t.jsxs("p",{className:"text-[22px] font-bold text-emerald-700",children:[d.currentLogicFeeTotal.toLocaleString(),"원"]})]}),t.jsxs("div",{className:L("flex-1 rounded-xl border p-4",d.currentLogicDifference>0?"border-blue-200 bg-blue-50":d.currentLogicDifference<0?"border-red-200 bg-red-50":"bg-emerald-50 border-emerald-200"),children:[t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx("p",{className:"text-sm text-gray-500",children:"로직 차액"}),d.currentLogicDifference>0?t.jsx(Ie,{className:"w-4 h-4 text-blue-600"}):d.currentLogicDifference<0?t.jsx(Me,{className:"w-4 h-4 text-red-600"}):t.jsx(jt,{className:"w-4 h-4 text-gray-400"})]}),t.jsxs("p",{className:L("text-[22px] font-bold",d.currentLogicDifference>0?"text-blue-600":d.currentLogicDifference<0?"text-red-600":"text-gray-900"),children:[d.currentLogicDifference>0?"+":"",d.currentLogicDifference.toLocaleString(),"원"]})]}),t.jsxs("div",{className:L("flex-1 rounded-xl border p-4",d.currentLogicDiffPercent>0?"border-blue-200 bg-blue-50":d.currentLogicDiffPercent<0?"border-red-200 bg-red-50":"bg-emerald-50 border-emerald-200"),children:[t.jsx("p",{className:"text-sm text-gray-500",children:"로직 차액률"}),t.jsxs("p",{className:L("text-[22px] font-bold",d.currentLogicDiffPercent>0?"text-blue-600":d.currentLogicDiffPercent<0?"text-red-600":"text-gray-900"),children:[d.currentLogicDiffPercent>0?"+":"",d.currentLogicDiffPercent.toFixed(1),"%"]})]})]}),t.jsx(Pr,{filteredOrders:e,loading:s})]})}export{gi 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.