1import{n as Ft,k as Ce,u as Qe,r as x,h as Ee,j as e,B as k,s as B,J as L,y as xe,P as Se,b as $e,C as ye,a as we,c as st,d as at,w as It,Z as vt,X as $t,q as jt,t as zt}from"./index-RxDZGo8S.js";import{I as $}from"./input-CS9s6izM.js";import{B as ee}from"./badge-Kwp9j7fd.js";import{S as le,a as ce,b as de,c as ue,d as A}from"./select-B3f6lReZ.js";import{D as qe,a as He,b as Ue,c as Ve}from"./dialog-Kd5QqSd7.js";import{L as w}from"./label-Fqe9mk9Y.js";import{T as ht}from"./textarea-ZYM4NL9m.js";import{u as Nt}from"./useActivityLog-fCH0wk49.js";import{L as ze}from"./loader-circle-CaA3DVt2.js";import{p as bt}from"./index-Cj1iWM2O.js";import{P as Qt}from"./printer-ot7QQNne.js";import{f as oe}from"./format-DuJJlbci.js";import{e as _e}from"./es-DhgJzuV8.js";import{L as qt}from"./link-Hx3NKTdf.js";import{F as tt}from"./file-text-jf7w95e0.js";import{P as Ht}from"./phone-BqXZyssE.js";import{M as Ut}from"./map-pin-SZp2PROJ.js";import{C as Vt}from"./calendar-DWLwoYri.js";import{C as yt}from"./clock-B-vpET2t.js";import{C as wt}from"./circle-check-big-ubcqJ6vK.js";import{C as _t}from"./circle-x-BzR8rTt0.js";import{S as Kt}from"./shopping-bag-ldsaMMws.js";import{C as Gt}from"./chevron-up-DbNI7lUd.js";import{E as Xt}from"./external-link-B1cu3f2-.js";import{C as Jt}from"./checkbox-BpNYG9vW.js";import{x as ge}from"./xlsx.min-BwoBGzjS.js";import{S as Wt}from"./save-O8uKCrCu.js";import{T as Yt}from"./trash-2-DXjGIb-t.js";import{D as Zt}from"./download-C_n9HF-k.js";import{S as es}from"./search-Dss-hsDb.js";import{E as ts}from"./eye-CB4j9jLn.js";import{Q as ss}from"./qr-code-hDwLaaY8.js";import{L as as}from"./link-2-D_WB_7TQ.js";import"./index-BnR4gmtC.js";import"./index-Da3vg3Bj.js";import"./check-dsJNWiFz.js";import"./_commonjs-dynamic-modules-TDtrdbi3.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const rs=Ft("FileSpreadsheet",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M8 13h2",key:"yr2amv"}],["path",{d:"M14 13h2",key:"un5t4a"}],["path",{d:"M8 17h2",key:"2yhykz"}],["path",{d:"M14 17h2",key:"10kma7"}]]);function ns({open:t,onOpenChange:a}){const{user:s}=Ce(),r=Qe(),{logActivity:n}=Nt(),[i,c]=x.useState(""),[o,m]=x.useState(""),[p,h]=x.useState(""),[b,_]=x.useState(""),[E,S]=x.useState(""),f=Ee({mutationFn:async()=>{const{data:N,error:te}=await B.rpc("generate_shipment_tracking_code");if(te)throw te;const D=N,{data:W,error:K}=await B.from("shipments").insert({tracking_code:D,customer_name:i.trim(),customer_phone:o.trim(),destination_address:p.trim(),delivery_date:b||null,notes:E.trim()||null,created_by:s==null?void 0:s.id,status:"pending"}).select().single();if(K)throw K;return W},onSuccess:N=>{r.invalidateQueries({queryKey:["shipments"]}),n("create_shipment",`creó envÃo ${N.tracking_code} para ${i.trim()}`,{tracking_code:N.tracking_code,customer_name:i.trim(),destination:p.trim()}),y(),a(!1)},onError:N=>{L.error("Error al crear el envÃo"),console.error(N)}}),y=()=>{c(""),m(""),h(""),_(""),S("")},P=N=>{if(N.preventDefault(),!i.trim()){L.error("El nombre del cliente es requerido");return}if(!o.trim()){L.error("El teléfono del cliente es requerido");return}if(!p.trim()){L.error("La dirección de destino es requerida");return}f.mutate()};return e.jsx(qe,{open:t,onOpenChange:a,children:e.jsxs(He,{className:"max-w-md max-h-[90vh] overflow-y-auto",children:[e.jsx(Ue,{children:e.jsx(Ve,{children:"Nuevo EnvÃo"})}),e.jsxs("form",{onSubmit:P,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{htmlFor:"customerName",children:"Nombre del Cliente *"}),e.jsx($,{id:"customerName",value:i,onChange:N=>c(N.target.value),placeholder:"Juan Pérez",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{htmlFor:"customerPhone",children:"Teléfono *"}),e.jsx($,{id:"customerPhone",value:o,onChange:N=>m(N.target.value),placeholder:"+56 9 1234 5678",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{htmlFor:"destinationAddress",children:"Dirección de Destino *"}),e.jsx(ht,{id:"destinationAddress",value:p,onChange:N=>h(N.target.value),placeholder:"Av. Principal 123, Santiago",required:!0,rows:2})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{htmlFor:"deliveryDate",children:"Fecha de Entrega (opcional)"}),e.jsx($,{id:"deliveryDate",type:"date",value:b,onChange:N=>_(N.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{htmlFor:"notes",children:"Notas Especiales (opcional)"}),e.jsx(ht,{id:"notes",value:E,onChange:N=>S(N.target.value),placeholder:"Instrucciones especiales de entrega...",rows:3})]}),e.jsxs("div",{className:"flex gap-2 pt-4",children:[e.jsx(k,{type:"button",variant:"outline",onClick:()=>a(!1),className:"flex-1",children:"Cancelar"}),e.jsxs(k,{type:"submit",disabled:f.isPending,className:"flex-1",children:[f.isPending&&e.jsx(ze,{className:"h-4 w-4 mr-2 animate-spin"}),"Crear EnvÃo"]})]})]})]})})}var Ke={},Ct={L:1,M:0,Q:3,H:2},Et={MODE_NUMBER:1,MODE_ALPHA_NUM:2,MODE_8BIT_BYTE:4,MODE_KANJI:8},is=Et;function St(t){this.mode=is.MODE_8BIT_BYTE,this.data=t}St.prototype={getLength:function(t){return this.data.length},write:function(t){for(var a=0;a<this.data.length;a++)t.put(this.data.charCodeAt(a),8)}};var os=St,Re=Ct;function X(t,a){this.totalCount=t,this.dataCount=a}X.RS_BLOCK_TABLE=[[1,26,19],[1,26,16],[1,26,13],[1,26,9],[1,44,34],[1,44,28],[1,44,22],[1,44,16],[1,70,55],[1,70,44],[2,35,17],[2,35,13],[1,100,80],[2,50,32],[2,50,24],[4,25,9],[1,134,108],[2,67,43],[2,33,15,2,34,16],[2,33,11,2,34,12],[2,86,68],[4,43,27],[4,43,19],[4,43,15],[2,98,78],[4,49,31],[2,32,14,4,33,15],[4,39,13,1,40,14],[2,121,97],[2,60,38,2,61,39],[4,40,18,2,41,19],[4,40,14,2,41,15],[2,146,116],[3,58,36,2,59,37
vendor: 4,432 bytes, line 6
6],[4,36,16,4,37,17],[4,36,12,4,37,13],[2,86,68,2,87,69],[4,69,43,1,70,44],[6,43,19,2,44,20],[6,43,15,2,44,16],[4,101,81],[1,80,50,4,81,51],[4,50,22,4,51,23],[3,36,12,8,37,13],[2,116,92,2,117,93],[6,58,36,2,59,37],[4,46,20,6,47,21],[7,42,14,4,43,15],[4,133,107],[8,59,37,1,60,38],[8,44,20,4,45,21],[12,33,11,4,34,12],[3,145,115,1,146,116],[4,64,40,5,65,41],[11,36,16,5,37,17],[11,36,12,5,37,13],[5,109,87,1,110,88],[5,65,41,5,66,42],[5,54,24,7,55,25],[11,36,12],[5,122,98,1,123,99],[7,73,45,3,74,46],[15,43,19,2,44,20],[3,45,15,13,46,16],[1,135,107,5,136,108],[10,74,46,1,75,47],[1,50,22,15,51,23],[2,42,14,17,43,15],[5,150,120,1,151,121],[9,69,43,4,70,44],[17,50,22,1,51,23],[2,42,14,19,43,15],[3,141,113,4,142,114],[3,70,44,11,71,45],[17,47,21,4,48,22],[9,39,13,16,40,14],[3,135,107,5,136,108],[3,67,41,13,68,42],[15,54,24,5,55,25],[15,43,15,10,44,16],[4,144,116,4,145,117],[17,68,42],[17,50,22,6,51,23],[19,46,16,6,47,17],[2,139,111,7,140,112],[17,74,46],[7,54,24,16,55,25],[34,37,13],[4,151,121,5,152,122],[4,75,47,14,76,48],[11,54,24,14,55,25],[16,45,15,14,46,16],[6,147,117,4,148,118],[6,73,45,14,74,46],[11,54,24,16,55,25],[30,46,16,2,47,17],[8,132,106,4,133,107],[8,75,47,13,76,48],[7,54,24,22,55,25],[22,45,15,13,46,16],[10,142,114,2,143,115],[19,74,46,4,75,47],[28,50,22,6,51,23],[33,46,16,4,47,17],[8,152,122,4,153,123],[22,73,45,3,74,46],[8,53,23,26,54,24],[12,45,15,28,46,16],[3,147,117,10,148,118],[3,73,45,23,74,46],[4,54,24,31,55,25],[11,45,15,31,46,16],[7,146,116,7,147,117],[21,73,45,7,74,46],[1,53,23,37,54,24],[19,45,15,26,46,16],[5,145,115,10,146,116],[19,75,47,10,76,48],[15,54,24,25,55,25],[23,45,15,25,46,16],[13,145,115,3,146,116],[2,74,46,29,75,47],[42,54,24,1,55,25],[23,45,15,28,46,16],[17,145,115],[10,74,46,23,75,47],[10,54,24,35,55,25],[19,45,15,35,46,16],[17,145,115,1,146,116],[14,74,46,21,75,47],[29,54,24,19,55,25],[11,45,15,46,46,16],[13,145,115,6,146,116],[14,74,46,23,75,47],[44,54,24,7,55,25],[59,46,16,1,47,17],[12,151,121,7,152,122],[12,75,47,26,76,48],[39,54,24,14,55,25],[22,45,15,41,46,16],[6,151,121,14,152,122],[6,75,47,34,76,48],[46,54,24,10,55,25],[2,45,15,64,46,16],[17,152,122,4,153,123],[29,74,46,14,75,47],[49,54,24,10,55,25],[24,45,15,46,46,16],[4,152,122,18,153,123],[13,74,46,32,75,47],[48,54,24,14,55,25],[42,45,15,32,46,16],[20,147,117,4,148,118],[40,75,47,7,76,48],[43,54,24,22,55,25],[10,45,15,67,46,16],[19,148,118,6,149,119],[18,75,47,31,76,48],[34,54,24,34,55,25],[20,45,15,61,46,16]];X.getRSBlocks=function(t,a){var s=X.getRsBlockTable(t,a);if(s==null)throw new Error("bad rs block @ typeNumber:"+t+"/errorCorrectLevel:"+a);for(var r=s.length/3,n=new Array,i=0;i<r;i++)for(var c=s[i*3+0],o=s[i*3+1],m=s[i*3+2],p=0;p<c;p++)n.push(new X(o,m));return n};X.getRsBlockTable=function(t,a){switch(a){case Re.L:return X.RS_BLOCK_TABLE[(t-1)*4+0];case Re.M:return X.RS_BLOCK_TABLE[(t-1)*4+1];case Re.Q:return X.RS_BLOCK_TABLE[(t-1)*4+2];case Re.H:return X.RS_BLOCK_TABLE[(t-1)*4+3];default:return}};var ls=X;function kt(){this.buffer=new Array,this.length=0}kt.prototype={get:function(t){var a=Math.floor(t/8);return(this.buffer[a]>>>7-t%8&1)==1},put:function(t,a){for(var s=0;s<a;s++)this.putBit((t>>>a-s-1&1)==1)},getLengthInBits:function(){return this.length},putBit:function(t){var a=Math.floor(this.length/8);this.buffer.length<=a&&this.buffer.push(0),t&&(this.buffer[a]|=128>>>this.length%8),this.length++}};var cs=kt,V={glog:function(t){if(t<1)throw new Error("glog("+t+")");return V.LOG_TABLE[t]},gexp:function(t){for(;t<0;)t+=255;for(;t>=256;)t-=255;return V.EXP_TABLE[t]},EXP_TABLE:new Array(256),LOG_TABLE:new Array(256)};for(var O=0;O<8;O++)V.EXP_TABLE[O]=1<<O;for(var O=8;O<256;O++)V.EXP_TABLE[O]=V.EXP_TABLE[O-4]^V.EXP_TABLE[O-5]^V.EXP_TABLE[O-6]^V.EXP_TABLE[O-8];for(var O=0;O<255;O++)V.LOG_TABLE[V.EXP_TABLE[O]]=O;var Dt=V,ie=Dt;function Ie(t,a){if(t.length==null)throw new Error(t.length+"/"+a);for(var s=0;s<t.length&&t[s]==0;)s++;this.num=new Array(t.length-s+a);for(var r=0;r<t.length-s;r++)this.num[r]=t[r+s]}Ie.prototype={get:function(t){return this.num[t]},getLength:function(){return this.num.length},multiply:function(t){for(var a=new Array(this.getLength()+t.getLength()-1),s=0;s<this.getLength();s++)for(var r=0;r<t.getLength();r++)a[s+r]^=ie.gexp(ie.glog(this.get(s))+ie.glog(t.get(r)));return new Ie(a,0)},mod:function(t){if(this.getLength()-t.getLength()<0)return this;for(var a=ie.glog(this.get(0))-ie.glog(t.get(0)),s=new Array(this.getLength()),r
6=0;r<this.getLength();r++)s[r]=this.get(r);for(var r=0;r<t.getLength();r++)s[r]^=ie.gexp(ie.glog(t.get(r))+a);return new Ie(s,0).mod(t)}};var Tt=Ie,H=Et,gt=Tt,ds=Dt,se={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7},R={PATTERN_POSITION_TABLE:[[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50],[6,30,54],[6,32,58],[6,34,62],[6,26,46,66],[6,26,48,70],[6,26,50,74],[6,30,54,78],[6,30,56,82],[6,30,58,86],[6,34,62,90],[6,28,50,72,94],[6,26,50,74,98],[6,30,54,78,102],[6,28,54,80,106],[6,32,58,84,110],[6,30,58,86,114],[6,34,62,90,118],[6,26,50,74,98,122],[6,30,54,78,102,126],[6,26,52,78,104,130],[6,30,56,82,108,134],[6,34,60,86,112,138],[6,30,58,86,114,142],[6,34,62,90,118,146],[6,30,54,78,102,126,150],[6,24,50,76,102,128,154],[6,28,54,80,106,132,158],[6,32,58,84,110,136,162],[6,26,54,82,110,138,166],[6,30,58,86,114,142,170]],G15:1335,G18:7973,G15_MASK:21522,getBCHTypeInfo:function(t){for(var a=t<<10;R.getBCHDigit(a)-R.getBCHDigit(R.G15
vendor: 7,416 bytes, line 6
6)>=0;)a^=R.G15<<R.getBCHDigit(a)-R.getBCHDigit(R.G15);return(t<<10|a)^R.G15_MASK},getBCHTypeNumber:function(t){for(var a=t<<12;R.getBCHDigit(a)-R.getBCHDigit(R.G18)>=0;)a^=R.G18<<R.getBCHDigit(a)-R.getBCHDigit(R.G18);return t<<12|a},getBCHDigit:function(t){for(var a=0;t!=0;)a++,t>>>=1;return a},getPatternPosition:function(t){return R.PATTERN_POSITION_TABLE[t-1]},getMask:function(t,a,s){switch(t){case se.PATTERN000:return(a+s)%2==0;case se.PATTERN001:return a%2==0;case se.PATTERN010:return s%3==0;case se.PATTERN011:return(a+s)%3==0;case se.PATTERN100:return(Math.floor(a/2)+Math.floor(s/3))%2==0;case se.PATTERN101:return a*s%2+a*s%3==0;case se.PATTERN110:return(a*s%2+a*s%3)%2==0;case se.PATTERN111:return(a*s%3+(a+s)%2)%2==0;default:throw new Error("bad maskPattern:"+t)}},getErrorCorrectPolynomial:function(t){for(var a=new gt([1],0),s=0;s<t;s++)a=a.multiply(new gt([1,ds.gexp(s)],0));return a},getLengthInBits:function(t,a){if(1<=a&&a<10)switch(t){case H.MODE_NUMBER:return 10;case H.MODE_ALPHA_NUM:return 9;case H.MODE_8BIT_BYTE:return 8;case H.MODE_KANJI:return 8;default:throw new Error("mode:"+t)}else if(a<27)switch(t){case H.MODE_NUMBER:return 12;case H.MODE_ALPHA_NUM:return 11;case H.MODE_8BIT_BYTE:return 16;case H.MODE_KANJI:return 10;default:throw new Error("mode:"+t)}else if(a<41)switch(t){case H.MODE_NUMBER:return 14;case H.MODE_ALPHA_NUM:return 13;case H.MODE_8BIT_BYTE:return 16;case H.MODE_KANJI:return 12;default:throw new Error("mode:"+t)}else throw new Error("type:"+a)},getLostPoint:function(t){for(var a=t.getModuleCount(),s=0,r=0;r<a;r++)for(var n=0;n<a;n++){for(var i=0,c=t.isDark(r,n),o=-1;o<=1;o++)if(!(r+o<0||a<=r+o))for(var m=-1;m<=1;m++)n+m<0||a<=n+m||o==0&&m==0||c==t.isDark(r+o,n+m)&&i++;i>5&&(s+=3+i-5)}for(var r=0;r<a-1;r++)for(var n=0;n<a-1;n++){var p=0;t.isDark(r,n)&&p++,t.isDark(r+1,n)&&p++,t.isDark(r,n+1)&&p++,t.isDark(r+1,n+1)&&p++,(p==0||p==4)&&(s+=3)}for(var r=0;r<a;r++)for(var n=0;n<a-6;n++)t.isDark(r,n)&&!t.isDark(r,n+1)&&t.isDark(r,n+2)&&t.isDark(r,n+3)&&t.isDark(r,n+4)&&!t.isDark(r,n+5)&&t.isDark(r,n+6)&&(s+=40);for(var n=0;n<a;n++)for(var r=0;r<a-6;r++)t.isDark(r,n)&&!t.isDark(r+1,n)&&t.isDark(r+2,n)&&t.isDark(r+3,n)&&t.isDark(r+4,n)&&!t.isDark(r+5,n)&&t.isDark(r+6,n)&&(s+=40);for(var h=0,n=0;n<a;n++)for(var r=0;r<a;r++)t.isDark(r,n)&&h++;var b=Math.abs(100*h/a/a-50)/5;return s+=b*10,s}},us=R,ms=os,Bt=ls,At=cs,ae=us,hs=Tt;function J(t,a){this.typeNumber=t,this.errorCorrectLevel=a,this.modules=null,this.moduleCount=0,this.dataCache=null,this.dataList=[]}var q=J.prototype;q.addData=function(t){var a=new ms(t);this.dataList.push(a),this.dataCache=null};q.isDark=function(t,a){if(t<0||this.moduleCount<=t||a<0||this.moduleCount<=a)throw new Error(t+","+a);return this.modules[t][a]};q.getModuleCount=function(){return this.moduleCount};q.make=function(){if(this.typeNumber<1){var t=1;for(t=1;t<40;t++){for(var a=Bt.getRSBlocks(t,this.errorCorrectLevel),s=new At,r=0,n=0;n<a.length;n++)r+=a[n].dataCount;for(var n=0;n<this.dataList.length;n++){var i=this.dataList[n];s.put(i.mode,4),s.put(i.getLength(),ae.getLengthInBits(i.mode,t)),i.write(s)}if(s.getLengthInBits()<=r*8)break}this.typeNumber=t}this.makeImpl(!1,this.getBestMaskPattern())};q.makeImpl=function(t,a){this.moduleCount=this.typeNumber*4+17,this.modules=new Array(this.moduleCount);for(var s=0;s<this.moduleCount;s++){this.modules[s]=new Array(this.moduleCount);for(var r=0;r<this.moduleCount;r++)this.modules[s][r]=null}this.setupPositionProbePattern(0,0),this.setupPositionProbePattern(this.moduleCount-7,0),this.setupPositionProbePattern(0,this.moduleCount-7),this.setupPositionAdjustPattern(),this.setupTimingPattern(),this.setupTypeInfo(t,a),this.typeNumber>=7&&this.setupTypeNumber(t),this.dataCache==null&&(this.dataCache=J.createData(this.typeNumber,this.errorCorrectLevel,this.dataList)),this.mapData(this.dataCache,a)};q.setupPositionProbePattern=function(t,a){for(var s=-1;s<=7;s++)if(!(t+s<=-1||this.moduleCount<=t+s))for(var r=-1;r<=7;r++)a+r<=-1||this.moduleCount<=a+r||(0<=s&&s<=6&&(r==0||r==6)||0<=r&&r<=6&&(s==0||s==6)||2<=s&&s<=4&&2<=r&&r<=4?this.modules[t+s][a+r]=!0:this.modules[t+s][a+r]=!1)};q.getBestMaskPattern=function(){for(var t=0,a=0,s=0;s<8;s++){this.makeImpl(!0,s);var r=ae.getLostPoint(this);(s==0||t>r)&&(t=r,a=s)}return a};q.createMovieClip=function(t,a,s){var r=t.createEmptyMovieClip(a,s),n=1;this.make();for(var i=0;i<this.modules.length;i++)for(var c=i*n,o=0;o<this.modules[i].length;o++){var m=o*n,p=this.modules[i][o];p&&(r.beginFill(0,100),r.moveTo(m,c),r.lineTo(m+n,c),r.lineTo(m+n,c+n),r.lineTo(m,c+n),r.endFill())}return r};q.setupTimingPattern=function(){for(var t=8;t<this.moduleCount-8;t++)this.modules[t][6]==null&&(this.modules[t][6]=t%2==0);for(var a=8;a<this.moduleCount-8;a++)this.modules[6][a]==null&&(this.modules[6][a]=a%2==0)};q.setupPositionAdjustPattern=function(){for(var t=ae.getPatternPosition(this.typeNumber),a=0;a<t.length;a++)for(var s=0;s<t.length;s++){var r=t[a],n=t[s];if(this.modules[r][n]==null)for(var i=-2;i<=2;i++)for(var c=-2;c<=2;c++)i==-2||i==2||c==-2||c==2||i==0&&c==0?this.modules[r+i][n+c]=!0:this.modules[r+i][n+c]=!1}};q.setupTypeNumber=function(t){for(var a=ae.getBCHTypeNumber(this.typeNumber),s=0;s<18;s++){var r=!t&&(a>>s&1)==1;this.modules[Math.floor(s/3)][s%3+this.moduleCount-8-3]=r}for(var s=0;s<18;s++){var r=!t&&(a>>s&1)==1;this.modules[s%3+this.moduleCount-8-3][Math.floor(s/3)]=r}};q.setupTypeInfo=function(t,a){for(var s=this.errorCorrectLevel<<3|a,r=ae.getBCHTypeInfo(s),n=0;n<15;n++){var i=!t&&(r>>n&1)==1;n<6?this.modules[n][8]=i:n<8?this.modules[n+1][8]=i:this.modules[this.moduleCount-15+n][8]=i}for(var n=0;n<15;n++){var i=!t&&(r>>n&1)==1;n<8?this.modules[8][this.moduleCount-n-1]=i:n<9?this.modules[8][15-n-1+1]=i:this.modules[8][15-n-1]=i}this.modules[this.moduleCount-8][8]=!t};q.mapData=function(t,a){for(var s=-1,r=this.moduleCount-1,n=7,i=0,c=this.moduleCount-1;c>0;c-=2)for(c==6&&c--;;){for(var o=0;o<2;o++)if(this.modules[r][c-o]==null){var m=!1;i<t.length&&(m=(t[i]>>>n&1)==1);var p=ae.getMask(a,r,c-o);p&&(m=!m),this.modules[r][c-o]=m,n--,n==-1&&(i++,n=7)}if(r+=s,r<0||this.moduleCount<=r){r-=s,s=-s;break}}};J.PAD0=236;J.PAD1=17;J.createData=function(t,a,s){for(var r=Bt.getRSBlocks(t,a),n=new At,i=0;i<s.length;i++){var c=s[i];n.put(c.mode,4),n.put(c.getLength(),ae.getLengthInBits(c.mode,t)),c.write(n)}for(var o=0,i=0;i<r.length;i++)o+=r[i].dataCount;if(n.getLengthInBits()>o*8)throw new Error("code length overflow. ("+n.getLengthInBits()+">"+o*8+")");for(n.getLengthInBits()+4<=o*8&&n.put(0,4);n.getLengthInBits()%8!=0;)n.putBit(!1);for(;!(n.getLengthInBits()>=o*8||(n.put(J.PAD0,8),n.getLengthInBits()>=o*8));)n.put(J.PAD1,8);return J.createBytes(n,r)};J.createBytes=function(t,a){for(var s=0,r=0,n=0,i=new Array(a.length),c=new Array(a.length),o=0;o<a.length;o++){var m=a[o].dataCount,p=a[o].totalCount-m;r=Math.max(r,m),n=Math.max(n,p),i[o]=new Array(m);for(var h=0;h<i[o].length;h++)i[o][h]=255&t.buffer[h+s];s+=m;var b=ae.getErrorCorrectPolynomial(p),_=new hs(i[o],b.getLength()-1),E=_.mod(b);c[o]=new Array(b.getLength()-1);for(var h=0;h<c[o].length;h++){var S=h+E.getLength()-c[o].length;c[o][h]=S>=0?E.get(S):0}}for(var f=0,h=0;h<a.length;h++)f+=a[h].totalCount;for(var y=new Array(f),P=0,h=0;h<r;h++)for(var o=0;o<a.length;o++)h<i[o].length&&(y[P++]=i[o][h]);for(var h=0;h<n;h++)for(var o=0;o<a.length;o++)h<c[o].length&&(y[P++]=c[o][h]);return y};var gs=J,rt={};
6Object.defineProperty(rt,"__esModule",{value:!0});var fs=Object.assign||function(t){for(var a=1;a<arguments.length;a++){var s=arguments[a];for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(t[r]=s[r])}return t},xs=bt,U=Pt(xs),Lt=x,Oe=Pt(Lt);function Pt(t){return t&&t.__esModule?t:{default:t}}function ps(t,a){var s={};for(var r in t)a.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(t,r)&&(s[r]=t[r]);return s}var vs={bgColor:U.default.oneOfType([U.default.object,U.default.string]).isRequired,bgD:U.default.string.isRequired,fgColor:U.default.oneOfType([U.default.object,U.default.string]).isRequired,fgD:U.default.string.isRequired,size:U.default.number.isRequired,title:U.default.string,viewBoxSize:U.default.number.isRequired,xmlns:U.default.string},nt=(0,Lt.forwardRef)(function(t,a){var s=t.bgColor,r=t.bgD,n=t.fgD,i=t.fgColor,c=t.size,o=t.title,m=t.viewBoxSize,p=t.xmlns,h=p===void 0?"http://www.w3.org/2000/svg":p,b=ps(t,["bgColor","bgD","fgD","fgColor","size","title","viewBoxSize","xmlns"]);return Oe.default.createElement("svg",fs({},b,{height:c,ref:a,viewBox:"0 0 "+m+" "+m,width:c,xmlns:h}),o?Oe.default.createElement("title",null,o):null,Oe.default.createElement("path",{d:r,fill:s}),Oe.default.createElement("path",{d:n,fill:i}))});nt.displayName="QRCodeSvg";nt.propTypes=vs;rt.default=nt;Object.defineProperty(Ke,"__esModule",{value:!0});Ke.QRCode=void 0;var js=Object.assign||function(t){for(var a=1;a<arguments.length;a++){var s=arguments[a];for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(t[r]=s[r])}return t},Ns=bt,Z=ke(Ns),bs=Ct,ys=ke(bs),ws=gs,_s=ke(ws),Mt=x,Cs=ke(Mt),Es=rt,Ss=ke(Es);function ke(t){return t&&t.__esModule?t:{default:t}}function ks(t,a){var s={};for(var r in t)a.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(t,r)&&(s[r]=t[r]);return s}var Ds={bgColor:Z.default.oneOfType([Z.default.object,Z.default.string]),fgColor:Z.default.oneOfType([Z.default.object,Z.default.string]),level:Z.default.string,size:Z.default.number,value:Z.default.string.isRequired},Ge=(0,Mt.forwardRef)(function(t,a){var s=t.bgColor,r=s===void 0?"#FFFFFF":s,n=t.fgColor,i=n===void 0?"#000000":n,c=t.level,o=c===void 0?"L":c,m=t.size,p=m===void 0?256:m,h=t.value,b=ks(t,["bgColor","fgColor","level","size","value"]),_=new _s.default(-1,ys.default[o]);_.addData(h),_.make();var E=_.modules;return Cs.default.createElement(Ss.default,js({},b,{bgColor:r,bgD:E.map(function(S,f){return S.map(function(y,P){return y?"":"M "+P+" "+f+" l 1 0 0 1 -1 0 Z"}).join(" ")}).join(" "),fgColor:i,fgD:E.map(function(S,f){return S.map(function(y,P){return y?"M "+P+" "+f+" l 1 0 0 1 -1 0 Z":""}).join(" ")}).join(" "),ref:a,size:p,viewBoxSize:E.length}))});Ke.QRCode=Ge;Ge.displayName="QRCode";Ge.propTypes=Ds;var Ts=Ke.default=Ge;function Bs({open:t,onOpenChange:a,shipment:s}){const r=x.useRef(null);`${s.tracking_code}`;const n=()=>{const i=r.current;if(!i)return;const c=window.open("","","width=400,height=600");c&&(c.document.write(` 7 <html> 8 <head> 9 <title>Etiqueta ${s.tracking_code}</title> 10 <style> 11 body { 12 font-family: Arial, sans-serif; 13 margin: 0; 14 padding: 20px; 15 } 16 .label { 17 border: 2px solid #000; 18 padding: 20px; 19 max-width: 350px; 20 margin: 0 auto; 21 } 22 .header { 23 text-align: center; 24 border-bottom: 2px solid #000; 25 padding-bottom: 10px; 26 margin-bottom: 15px; 27 } 28 .tracking-code { 29 font-size: 24px; 30 font-weight: bold; 31 font-family: monospace; 32 } 33 .qr-container { 34 text-align: center; 35 margin: 15px 0; 36 } 37 .info-section { 38 margin: 10px 0; 39 } 40 .info-label { 41 font-size: 12px; 42 color: #666; 43 text-transform: uppercase; 44 } 45 .info-value { 46 font-size: 14px; 47 font-weight: 500; 48 margin-top: 2px; 49 } 50 .notes { 51 background: #f5f5f5; 52 padding: 10px; 53 border-radius: 4px; 54 font-size: 12px; 55 margin-top: 10px; 56 } 57 </style> 58 </head> 59 <body> 60 ${i.innerHTML} 61 </body> 62 </html> 63 `),c.document.close(),c.focus(),setTimeout(()=>{c.print(),c.close()},250))};return e.jsx(qe,{open:t,onOpenChange:a,children:e.jsxs(He,{className:"max-w-md max-h-[90vh] overflow-y-auto",children:[e.jsx(Ue,{children:e.jsx(Ve,{children:"Etiqueta de EnvÃo"})}),e.jsxs("div",{ref:r,className:"label border-2 border-foreground p-5 rounded-lg",children:[e.jsxs("div",{className:"header text-center border-b-2 border-foreground pb-3 mb-4",children:[e.jsx("div",{className:"text-xs text-muted-foreground uppercase tracking-wider mb-1",children:"Código de Seguimiento"}),e.jsx("div",{className:"tracking-code text-2xl font-bold font-mono text-primary",children:s.tracking_code})]}),e.jsx("div",{className:"qr-container flex justify-center my-4",children:e.jsx(Ts,{value:s.tracking_code,size:150})}),e.jsx("div",{className:"text-center text-xs text-muted-foreground mb-4",children:"Escanea para actualizar el estado (chofer)"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"info-section",children:[e.jsx("div",{className:"info-label text-xs text-muted-foreground uppercase",children:"Destinatario"}),e.jsx("div",{className:"info-value font-medium",children:s.customer_name})]}),e.jsxs("div",{className:"info-section",children:[e.jsx("div",{className:"info-label text-xs text-muted-foreground uppercase",children:"Teléfono"}),e.jsx("div",{className:"info-value font-medium",children:s.customer_phone})]}),e.jsxs("div",{className:"info-section",children:[e.jsx("div",{className:"info-label text-xs text-muted-foreground uppercase",children:"Dirección"}),e.jsx("div",{className:"info-value font-medium",children:s.destination_address})]}),s.delivery_date&&e.jsxs("div",{className:"info-section",children:[e.jsx("div",{className:"info-label text-xs text-muted-foreground uppercase",children:"Fecha de Entrega"}),e.jsx("div",{className:"info-value font-medium",children:oe(new Date(s.delivery_date),"dd MMMM yyyy",{locale:_e})})]}),s.notes&&e.jsxs("div",{className:"notes bg-muted p-3 rounded text-sm",children:[e.jsx("div",{className:"font-medium mb-1",children:"Notas:"}),s.notes]})]})]}),e.jsx("div",{className:"flex gap-2 mt-4",children:e.jsxs(k,{variant:"outline",onClick:n,className:"flex-1",children:[e.jsx(Qt,{className:"h-4 w-4 mr-2"}),"Imprimir"]})})]})})}const fe={uflash:{label:"UFlash",color:"bg-orange-500",trackingBase:"https://uflash.cl/tracking/"},bluexpress:{label:"Blue Express",color:"bg-blue-500",trackingBase:"https://www.bluex.cl/seguimiento?codigo="},driver:{label:"Chofer Propio",color:"bg-green-500",trackingBase:null}},Fe={pending:{label:"Pendiente",variant:"secondary",icon:yt},assigned:{label:"Asignado",variant:"outline",icon:Se},in_transit:{label:"En Tránsito",variant:"default",icon:xe},delivered:{label:"Entregado",variant:"default",icon:wt},cancelled:{label:"Cancelado",variant:"destructive",icon:_t}},As=["pending","assigned","in_transit","delivered","cancelled"];function Ls({open:t,onOpenChange:a,shipment:s,drivers:r,onUpdate:n}){var S;const{isAdmin:i}=Ce(),[c,o]=x.useState(s.status),[m,p]=x.useState(s.driver_id||"unassigned"),h=Ee({mutationFn:async()=>{const f={status:c,driver_id:m==="unassigned"?null:m},{error:y}=await B.from("shipments").update(f).eq("id",s.id);if(y)throw y},onSuccess:()=>{n(),a(!1)},onError:f=>{L.error("Error al actualizar el envÃo"),console.error(f)}}),b=Fe[s.status].icon,_=()=>{const f=s.customer_phone.replace(/\D/g,"");window.open(`https://wa.me/${f}`,"_blank")},E=()=>{const f=`https://floraflor.vercel.app/tracking/${s.tracking_code}`;navigator.clipboard.writeText(f),L.info("Link copiado al portapapeles")};return e.jsx(qe,{open:t,onOpenChange:a,children:e.jsxs(He,{className:"max-w-md max-h-[90vh] overflow-y-auto",children:[e.jsx(Ue,{children:e.jsxs(Ve,{className:"flex items-center justify-between",children:[e.jsx("span",{className:"font-mono text-primary",children:s.tracking_code}),e.jsxs(k,{variant:"outline",size:"sm",onClick:E,className:"gap-2",children:[e.jsx(qt,{className:"h-4 w-4"}),"Copiar Link"]})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs(ee,{variant:Fe[s.status].variant,className:"gap-1",children:[e.jsx(b,{className:"h-3 w-3"}),Fe[s.status].label]}),s.carrier&&fe[s.carrier]&&e.jsxs(ee,{variant:"outline",className:"gap-1",children:[e.jsx("div",{className:`w-2 h-2 rounded-full ${fe[s.carrier].color}`}),fe[s.carrier].label]}),s.shopify_order_number&&e.jsxs(ee,{variant:"outline",className:"bg-green-50 text-green-700 border-green-200",children:["#",s.shopify_order_number]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["Creado ",oe(new Date(s.created_at),"dd MMM yyyy HH:mm",{locale:_e})]})]}),s.carrier&&s.external_tracking_number&&((S=fe[s.carrier])==null?void 0:S.trackingBase)&&e.jsxs("a",{href:`${fe[s.carrier].trackingBase}${s.external_tracking_number}`,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2 text-primary hover:underline text-sm border rounded-lg p-3 bg-primary/5",children:[e.jsx(xe,{className:"h-4 w-4"}),"Ver tracking en ",fe[s.carrier].label,": ",s.external_tracking_number]}),s.packing_slip_url&&e.jsxs("a",{href:s.packing_slip_url,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2 text-primary hover:underline text-sm border rounded-lg p-3 bg-muted/50",children:[e.jsx(tt,{className:"h-4 w-4"}),"Ver Packing Slip"]}),e.jsxs("div",{className:"space-y-3 border rounded-lg p-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Se,{className:"h-5 w-5 text-muted-foreground mt-0.5"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:s.customer_name}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Cliente"})]})]}),e.jsxs("div",{className:"flex items-start gap-3 cursor-pointer hover:bg-accent/50 -mx-2 px-2 py-1 rounded",onClick:_,children:[e.jsx(Ht,{className:"h-5 w-5 text-green-500 mt-0.5"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-green-600",children:s.customer_phone}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Abrir WhatsApp"})]})]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Ut,{className:"h-5 w-5 text-muted-foreground mt-0.5"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:s.destination_address}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Dirección de entrega"})]})]}),s.delivery_date&&e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Vt,{className:"h-5 w-5 text-muted-foreground mt-0.5"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:oe(new Date(s.delivery_date),"dd MMMM yyyy",{locale:_e})}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Fecha de entrega"})]})]}),s.notes&&e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(tt,{className:"h-5 w-5 text-muted-foreground mt-0.5"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:s.notes}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Notas"})]})]})]}),i&&e.jsxs("div",{className:"space-y-4 border rounded-lg p-4",children:[e.jsx("h3",{className:"font-medium",children:"Actualizar EnvÃo"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:"Estado"}),e.jsxs(le,{value:c,onValueChange:f=>o(f),children:[e.jsx(ce,{children:e.jsx(de,{})}),e.jsx(ue,{children:As.map(f=>e.jsx(A,{value:f,children:Fe[f].label},f))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:"Chofer Asignado"}),e.jsxs(le,{value:m,onValueChange:p,children:[e.jsx(ce,{children:e.jsx(de,{placeholder:"Sin asignar"})}),e.jsxs(ue,{children:[e.jsx(A,{value:"unassigned",children:"Sin asignar"}),r.map(f=>e.jsxs(A,{value:f.id,children:[f.first_name||f.email," ",f.last_name||""]},f.id))]})]})]}),e.jsxs(k,{onClick:()=>h.mutate(),disabled:h.isPending,className:"w-full",children:[h.isPending&&e.jsx(ze,{className:"h-4 w-4 mr-2 animate-spin"}),"Guardar Cambios"]})]})]})]})})}const Ps={uflash:{label:"UFlash",color:"bg-orange-500",trackingBase:"https://uflash.cl/tracking/"},bluexpress:{label:"Blue Express",color:"bg-blue-500",trackingBase:"https://www.bluex.cl/seguimiento?codigo="},driver:{label:"Chofer Propio",color:"bg-green-500",trackingBase:null}};function Ms(){const{user:t}
63=Ce(),a=Qe(),[s,r]=x.useState(!0),[n,i]=x.useState(null),[c,o]=x.useState(!1),[m,p]=x.useState(""),[h,b]=x.useState(""),[_,E]=x.useState(""),[S,f]=x.useState(!1),[y,P]=x.useState(null),{data:N,isLoading:te}=$e({queryKey:["shopify-orders-for-shipment"],queryFn:async()=>{const{data:d}=await B.from("shipments").select("shopify_order_id").not("shopify_order_id","is",null),g=(d==null?void 0:d.map(C=>C.shopify_order_id))||[];let v=B.from("shopify_orders").select("*").order("created_at_shopify",{ascending:!1}).limit(50);const{data:M,error:Q}=await v;if(Q)throw Q;return(M||[]).filter(C=>!g.includes(C.shopify_order_id))}}),{data:D}=$e({queryKey:["drivers"],queryFn:async()=>{const{data:d}=await B.from("user_roles").select("user_id").eq("role","chofer");if(!d||d.length===0)return[];const{data:g}=await B.from("profiles").select("id, first_name, last_name, email").in("id",d.map(v=>v.user_id));return g||[]}}),W=Ee({mutationFn:async()=>{if(!n)throw new Error("No order selected");const{data:d,error:g}=await B.rpc("generate_shipment_tracking_code");if(g)throw g;const v=n.shipping_address,M=[v==null?void 0:v.address1,v==null?void 0:v.address2,v==null?void 0:v.city,v==null?void 0:v.province].filter(Boolean);let Q=null;if(y){f(!0);const me=`${n.order_number}_${Date.now()}.${y.name.split(".").pop()}`,{data:l,error:j}=await B.storage.from("packing-slips").upload(me,y);if(j)throw j;const{data:T}=B.storage.from("packing-slips").getPublicUrl(me);Q=T.publicUrl,f(!1)}const{error:C}=await B.from("shipments").insert({tracking_code:d,customer_name:n.customer_name||"Cliente Shopify",customer_phone:n.customer_phone||"",destination_address:M.join(", ")||"Sin dirección",status:"pending",carrier:m,driver_id:m==="driver"&&h?h:null,external_tracking_number:_||null,shopify_order_id:n.shopify_order_id,shopify_order_number:n.order_number,packing_slip_url:Q,created_by:t==null?void 0:t.id});if(C)throw C},onSuccess:()=>{a.invalidateQueries({queryKey:["shopify-orders-for-shipment"]}),a.invalidateQueries({queryKey:["shipments"]}),L.success(`EnvÃo creado para pedido ${n==null?void 0:n.order_number}`),K()},onError:d=>{console.error(d),L.error("Error al crear el envÃo"),f(!1)}}),K=()=>{i(null),o(!1),p(""),b(""),E(""),P(null)},pe=d=>{i(d),o(!0)},ve=d=>{var v;const g=(v=d.target.files)==null?void 0:v[0];g&&P(g)},u=()=>{if(!m||m==="driver"||!_)return null;const d=Ps[m];return d!=null&&d.trackingBase?`${d.trackingBase}${_}`:null};return te?e.jsx(ye,{children:e.jsx(we,{className:"p-6",children:e.jsx("div",{className:"flex items-center justify-center",children:e.jsx(ze,{className:"h-6 w-6 animate-spin text-muted-foreground"})})})}):!N||N.length===0?null:e.jsxs(e.Fragment,{children:[e.jsxs(ye,{children:[e.jsx(st,{className:"cursor-pointer hover:bg-accent/50 transition-colors",onClick:()=>r(!s),children:e.jsxs(at,{className:"flex items-center justify-between text-lg",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Kt,{className:"h-5 w-5 text-green-600"}),"Pedidos Shopify sin Asignar",e.jsx(ee,{variant:"secondary",children:N.length})]}),s?e.jsx(Gt,{className:"h-4 w-4"}):e.jsx(It,{className:"h-4 w-4"})]})}),s&&e.jsx(we,{className:"p-0",children:e.jsx("div",{className:"divide-y",children:N.map(d=>{const g=d.shipping_address,v=[g==null?void 0:g.address1,g==null?void 0:g.city].filter(Boolean).join(", ");return e.jsx("div",{className:"p-4 hover:bg-accent/50 transition-colors",children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-3",children:[e.jsxs("div",{className:"space-y-1 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs(ee,{variant:"outline",className:"bg-green-50 text-green-700 border-green-200",children:["#",d.order_number]}),e.jsx("span",{className:"text-sm text-muted-foreground",children:oe(new Date(d.created_at_shopify),"dd MMM yyyy",{locale:_e})})]}),e.jsx("p",{className:"font-medium",children:d.customer_name||"Sin nombre"}),v&&e.jsx("p",{className:"text-sm text-muted-foreground",children:v}),e.jsx("p",{className:"text-sm text-muted-foreground",children:Array.isArray(d.line_items)?d.line_items.map(M=>`${M.quantity||1}x ${M.title||"Producto"}`).join(", "):"Sin productos"})]}),e.jsxs(k,{onClick:()=>pe(d),className:"gap-2",children:[e.jsx(xe,{className:"h-4 w-4"}),"Asignar EnvÃo"]})]})},d.id)})})})]}),e.jsx(qe,{open:c,onOpenChange:o,children:e.jsxs(He,{className:"max-w-md max-h-[90vh] overflow-y-auto",children:[e.jsx(Ue,{children:e.jsxs(Ve,{className:"flex items-center gap-2",children:[e.jsx(Se,{className:"h-5 w-5"}),"Asignar EnvÃo - #",n==null?void 0:n.order_number]})}),n&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"border rounded-lg p-3 bg-muted/50",children:[e.jsx("p",{className:"font-medium",children:n.customer_name}),n.shipping_address&&e.jsx("p",{className:"text-sm text-muted-foreground",children:[n.shipping_address.address1,n.shipping_address.address2,n.shipping_address.city].filter(
63Boolean).join(", ")}),n.customer_phone&&e.jsx("p",{className:"text-sm text-muted-foreground",children:n.customer_phone})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{children:"Transportista *"}),e.jsxs(le,{value:m,onValueChange:p,children:[e.jsx(ce,{children:e.jsx(de,{placeholder:"Seleccionar transportista"})}),e.jsxs(ue,{children:[e.jsx(A,{value:"uflash",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-3 h-3 rounded-full bg-orange-500"}),"UFlash"]})}),e.jsx(A,{value:"bluexpress",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-3 h-3 rounded-full bg-blue-500"}),"Blue Express"]})}),e.jsx(A,{value:"driver",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-3 h-3 rounded-full bg-green-500"}),"Chofer Propio"]})})]})]})]}),m==="driver"&&D&&D.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{children:"Chofer"}),e.jsxs(le,{value:h,onValueChange:b,children:[e.jsx(ce,{children:e.jsx(de,{placeholder:"Seleccionar chofer"})}),e.jsx(ue,{children:D.map(d=>e.jsxs(A,{value:d.id,children:[d.first_name||d.email," ",d.last_name||""]},d.id))})]})]}),(m==="uflash"||m==="bluexpress")&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{children:"Número de Tracking (opcional)"}),e.jsx($,{value:_,onChange:d=>E(d.target.value),placeholder:"Ej: 123456789"}),u()&&e.jsxs("a",{href:u(),target:"_blank",rel:"noopener noreferrer",className:"text-sm text-primary hover:underline flex items-center gap-1",children:[e.jsx(Xt,{className:"h-3 w-3"}),"Ver tracking"]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{children:"Subir Packing Slip / Screenshot (opcional)"}),e.jsxs("div",{className:"border-2 border-dashed rounded-lg p-4 text-center",children:[e.jsx("input",{type:"file",accept:".pdf,.png,.jpg,.jpeg",onChange:ve,className:"hidden",id:"packing-slip-upload"}),e.jsx("label",{htmlFor:"packing-slip-upload",className:"cursor-pointer flex flex-col items-center gap-2",children:y?e.jsxs(e.Fragment,{children:[e.jsx(tt,{className:"h-8 w-8 text-primary"}),e.jsx("span",{className:"text-sm text-primary",children:y.name})]}):e.jsxs(e.Fragment,{children:[e.jsx(vt,{className:"h-8 w-8 text-muted-foreground"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Haz clic para subir PDF o imagen"})]})})]})]}),e.jsxs("div",{className:"flex gap-2 pt-4",children:[e.jsx(k,{variant:"outline",onClick:K,className:"flex-1",children:"Cancelar"}),e.jsxs(k,{onClick:()=>W.mutate(),disabled:!m||W.isPending||S,className:"flex-1",children:[(W.isPending||S)&&e.jsx(ze,{className:"h-4 w-4 mr-2 animate-spin"}),"Crear EnvÃo"]})]})]})]})})]})}const Rt="blue-express-boxes",ft="blue-express-descripcion";function Rs(){try{return JSON.parse(localStorage.getItem(Rt)||"[]")}catch{return[]}}function xt(t){localStorage.setItem(Rt,JSON.stringify(t))}const pt={RM:"Metropolitana","Región Metropolitana":"Metropolitana",Santiago:"Metropolitana",ValparaÃso:"ValparaÃso",BiobÃo:"BiobÃo",Maule:"Maule","O'Higgins":"O'Higgins",AraucanÃa:"AraucanÃa","Los Lagos":"Los Lagos",Coquimbo:"Coquimbo",Atacama:"Atacama",Antofagasta:"Antofagasta",Tarapacá:"Tarapacá","Arica y Parinacota":"Arica y Parinacota","Los RÃos":"Los RÃos",Aysén:"Aysén",Magallanes:"Magallanes",Ãuble:"Ãuble"};function Os(t){const a=t.match(/^(.+?)\s+(\d+\S*)$/);return a?{calle:a[1],numero:a[2]}:{calle:t,numero:"S/N"}}function Fs(t){const a=t.replace(/\D/g,"");return a.startsWith("56")?a:(a.startsWith("9")&&a.length===9,"56"+a)}function Is(){const{user:t}=Ce(),a=Qe(),[s,r]=x.useState([]),[n,i]=x.useState(Rs),[c,o]=x.useState(""),[m,p]=x.useState(""),[h,b]=x.useState(""),[_,E]=x.useState(""),[S,f]=x.useState(""),[y,P]=x.useState(!1),[N,te]=x.useState("2"),[D,W]=x.useState(()=>localStorage.getItem(ft)||"OrquÃdeas"),[K,pe]=x.useState("STD");x.useEffect(()=>{localStorage.setItem(ft,D)},[D]),x.useEffect(()=>{const l=n.find(j=>j.id===c);l&&(p(String(l.alto)),b(String(l.ancho)),E(String(l.largo)))},[c,n]);const ve=()=>{if(!S.trim()||!m||!h||!_){L.error("Completa nombre y dimensiones");return}const l={id:crypto.randomUUID(),label:S.trim(),alto:Number(m),ancho:Number(h),largo:Number(_)},j=[...n,l];i(j),xt(j),o(l.id),f(""),P(!1),L.success("Caja guardada")},u=l=>{const j=n.filter(T=>T.id!==l);i(j),xt(j),c===l&&o("")},d=x.useCallback(l=>{var G;const j=(G=l.target.files)==null?void 0:G[0];if(!j)return;const T=new FileReader;T.onload=Xe=>{var je,De,Te,Y,Be,Ae,Ne,F,he,re,Le,it,ot,lt,ct;try{const Je=((je=Xe.target)==null?void 0:je.result).split(` 64`),Ot=Je[0].split(",").map(ne=>ne.trim().replace(/"/g,"")),z=ne=>Ot.indexOf(ne),We=new Map;for(let ne=1;ne<Je.length;ne++){const I=$s(Je[ne]);if(I.length<5)continue;const Pe=(De=I[z("Name")])==null?void 0:De.replace(/"/g,"").trim();if(!Pe)continue;const ut=We.get(Pe),Me=((Te=I[z("Lineitem name")])==null?void 0:Te.replace(/"/g,"").trim())||"";if(ut){Me&&ut.items.push(Me);continue}const Ze=parseFloat(((Y=I[z("Subtotal")])==null?void 0:Y.replace(/"/g,""))||"0"),mt=parseFloat(((Be=I[z("Total")])==null?void 0:Be.replace(/"/g,""))||"0");We.set(Pe,{orderNumber:Pe,name:((Ae=I[z("Shipping Name")])==null?void 0:Ae.replace(/"/g,"").trim())||((Ne=I[z("Billing Name")])==null?void 0:Ne.replace(/"/g,"").trim())||"",email:((F=I[z("Email")])==null?void 0:F.replace(/"/g,"").trim())||"",phone:((he=I[z("Shipping Phone")])==null?void 0:he.replace(/"/g,"").trim())||((re=I[z("Billing Phone")])==null?void 0:re.replace(/"/g,"").trim())||"",address1:((Le=I[z("Shipping Address1")])==null?void 0:Le.replace(/"/g,"").trim())||"",address2:((it=I[z("Shipping Address2")])==null?void 0:it.replace(/"/g,"").trim())||"",city:((ot=I[z("Shipping City")])==null?void 0:ot.replace(/"/g,"").trim())||"",province:((lt=I[z("Shipping Province")])==null?void 0:lt.replace(/"/g,"").trim())||"",provinceName:((ct=I[z("Shipping Province Name")])==null?void 0:ct.replace(/"/g,"").trim())||"",subtotal:Ze,total:mt||Ze,items:Me?[Me]:[],selected:!0,valorC
64ontenido:String(mt||Ze||0)})}const Ye=Array.from(We.values());if(Ye.length===0){L.error("No se encontraron pedidos en el archivo");return}r(Ye),L.success(`${Ye.length} pedido(s) importados`)}catch(dt){console.error(dt),L.error("Error al leer el archivo CSV")}},T.readAsText(j),l.target.value=""},[]),g=x.useMemo(()=>s.filter(l=>l.selected),[s]),v=l=>{r(j=>j.map(T=>T.orderNumber===l?{...T,selected:!T.selected}:T))},M=()=>{const l=s.every(j=>j.selected);r(j=>j.map(T=>({...T,selected:!l})))},Q=(l,j)=>{r(T=>T.map(G=>G.orderNumber===l?{...G,valorContenido:j}:G))},C=Ee({mutationFn:async l=>{for(const j of l){const{data:T}=await B.rpc("generate_shipment_tracking_code"),G=T;await B.from("shipments").insert({tracking_code:G,customer_name:j.name,customer_phone:j.phone,destination_address:`${j.address1} ${j.address2}, ${j.city}`.trim(),carrier:"bluexpress",shopify_order_number:j.orderNumber,status:"pending",created_by:t==null?void 0:t.id,notes:`Items: ${j.items.join(", ")}`})}},onSuccess:()=>{a.invalidateQueries({queryKey:["shipments"]})}}),me=async()=>{if(g.length===0){L.error("Selecciona al menos un pedido");return}const l={alto:Number(m)||30,ancho:Number(h)||30,largo:Number(_)||30},j=ge.utils.book_new(),T=["Debes ingresar los datos del destinatario: MÃXIMO 999 ENVÃOS CON DESTINO DOMICILIO","","","","","","","","","","","","","","","","","","","","","","","",""],G=["Versión","1.3","","","","","","","","","","","","","","","","","","","","","","",""],Xe=["","Datos destinatario","","","Datos Entrega EnvÃo","","","","","","¿Qué estás enviando?","","","","","","","Servicios Complementarios","","","","","","",""],je=["Nº Referencia*","Nombre Completo*","Teléfono*","Correo*","Región*","Comuna*","Nombre calle*","N° Domicilio *","N° Dpto / N ° Oficina","Ayuda para llegar (Ej: Tienda)","Alto(cms)*","Ancho(cms)*","Largo(cms)*","Peso(kg)*","Descripción contenido*","Valor Contenido*","Servicio*","GarantÃa*","Nº boleta/factura","Servicio DD","Tipo documento","Número documento","Servicio COD","Método de pago","Monto"],De=g.map(F=>{const{calle:he,numero:re}=Os(F.address1),Le=pt[F.provinceName]||pt[F.province]||F.provinceName||F.province||"Metropolitana";return[F.orderNumber,F.name,Fs(F.phone),F.email,Le,F.city||"Santiago",he,re,F.address2||"","",l.alto,l.ancho,l.largo,Number(N),D,Number(F.valorContenido),K,"","","","","","","",""]}),Te=[T,G,Xe,je,...De],Y=ge.utils.aoa_to_sheet(Te),Be={font:{bold:!0,color:{rgb:"FFFFFF"}},fill:{fgColor:{rgb:"003399"}}},Ae={font:{bold:!0,sz:10},fill:{fgColor:{rgb:"D9E2F3"}},border:{bottom:{style:"thin",color:{rgb:"000000"}}}};je.forEach((F,he)=>{const re=ge.utils.encode_cell({r:3,c:he});Y[re]&&(Y[re].s=Ae)});const Ne=ge.utils.encode_cell({r:0,c:0});Y[Ne]&&(Y[Ne].s=Be),Y["!cols"]=[{wch:15},{wch:25},{wch:14},{wch:25},{wch:18},{wch:18},{wch:25},{wch:14},{wch:18},{wch:25},{wch:10},{wch:10},{wch:10},{wch:10},{wch:22},{wch:15},{wch:12},{wch:12},{wch:16},{wch:12},{wch:15},{wch:16},{wch:12},{wch:14},{wch:10}],ge.utils.book_append_sheet(j,Y,"Carga Masiva"),ge.writeFile(j,`blue_express_carga_${new Date().toISOString().slice(0,10)}.xlsx`),await C.mutateAsync(g),L.success(`Archivo generado y ${g.length} envÃo(s) creados`)};return e.jsxs(ye,{className:"border-blue-200 bg-blue-50/30 dark:bg-blue-950/10 dark:border-blue-800",children:[e.jsxs(st,{children:[e.jsxs(at,{className:"flex items-center gap-2 text-lg",children:[e.jsx("div",{className:"p-1.5 bg-blue-500 rounded-lg",children:e.jsx(Se,{className:"h-4 w-4 text-white"})}),"Blue Express â Carga desde Shopify"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Sube el CSV de pedidos de Shopify y genera el archivo de carga masiva para Blue Express"})]}),e.jsxs(we,{className:"space-y-5",children:[e.jsxs("div",{children:[e.jsx(w,{className:"text-sm font-medium mb-2 block",children:"1. Subir CSV de Shopify"}),e.jsxs("label",{className:"flex items-center justify-center gap-2 border-2 border-dashed border-blue-300 rounded-lg p-4 cursor-pointer hover:bg-blue-50 dark:hover:bg-blue-950/20 transition-colors",children:[e.jsx(vt,{className:"h-5 w-5 text-blue-500"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Arrastra o haz clic para subir orders_exp
64ort.csv"}),e.jsx("input",{type:"file",accept:".csv",onChange:d,className:"hidden"})]})]}),s.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"col-span-2 sm:col-span-4",children:e.jsx(w,{className:"text-sm font-medium mb-2 block",children:"2. Configurar envÃo"})}),e.jsxs("div",{children:[e.jsx(w,{className:"text-xs mb-1 block",children:"Tamaño caja"}),n.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 mb-2",children:n.map(l=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs(k,{variant:c===l.id?"default":"outline",size:"sm",onClick:()=>o(l.id),className:"text-xs",children:[l.label," (",l.alto,"Ã",l.ancho,"Ã",l.largo,")"]}),e.jsx(k,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>u(l.id),children:e.jsx($t,{className:"h-3 w-3"})})]},l.id))}),y?e.jsxs("div",{className:"flex items-end gap-2 flex-wrap border rounded-lg p-3 bg-muted/30",children:[e.jsxs("div",{children:[e.jsx(w,{className:"text-xs",children:"Nombre"}),e.jsx($,{value:S,onChange:l=>f(l.target.value),placeholder:"Ej: Mediana",className:"mt-1 h-8 w-28 text-xs"})]}),e.jsxs("div",{children:[e.jsx(w,{className:"text-xs",children:"Alto (cm)"}),e.jsx($,{value:m,onChange:l=>p(l.target.value),type:"number",className:"mt-1 h-8 w-20 text-xs"})]}),e.jsxs("div",{children:[e.jsx(w,{className:"text-xs",children:"Ancho (cm)"}),e.jsx($,{value:h,onChange:l=>b(l.target.value),type:"number",className:"mt-1 h-8 w-20 text-xs"})]}),e.jsxs("div",{children:[e.jsx(w,{className:"text-xs",children:"Largo (cm)"}),e.jsx($,{value:_,onChange:l=>E(l.target.value),type:"number",className:"mt-1 h-8 w-20 text-xs"})]}),e.jsxs(k,{size:"sm",onClick:ve,className:"gap-1 h-8 text-xs",children:[e.jsx(Wt,{className:"h-3 w-3"})," Guardar"]}),e.jsx(k,{variant:"ghost",size:"sm",onClick:()=>P(!1),className:"h-8 text-xs",children:"Cancelar"})]}):e.jsxs(k,{variant:"outline",size:"sm",onClick:()=>P(!0),className:"gap-1 text-xs",children:[e.jsx(jt,{className:"h-3 w-3"})," Nueva caja"]})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-5 gap-3",children:[e.jsxs("div",{children:[e.jsx(w,{className:"text-xs",children:"Alto (cm)"}),e.jsx($,{value:m,onChange:l=>p(l.target.value),type:"number",className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(w,{className:"text-xs",children:"Ancho (cm)"}),e.jsx($,{value:h,onChange:l=>b(l.target.value),type:"number",className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(w,{className:"text-xs",children:"Largo (cm)"}),e.jsx($,{value:_,onChange:l=>E(l.target.value),type:"number",className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(w,{className:"text-xs",children:"Peso (kg)"}),e.jsx($,{value:N,onChange:l=>te(l.target.value),type:"number",className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(w,{className:"text-xs",children:"Descripción"}),e.jsx($,{value:D,onChange:l=>W(l.target.value),className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(w,{className:"text-xs",children:"Servicio"}),e.jsxs(le,{value:K,onValueChange:pe,children:[e.jsx(ce,{className:"mt-1",children:e.jsx(de,{})}),e.jsxs(ue,{children:[e.jsx(A,{value:"STD",children:"Estándar"}),e.jsx(A,{value:"PRI",children:"Prioritario"}),e.jsx(A,{value:"EXP",children:"Express"})]})]})]})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs(w,{className:"text-sm font-medium",children:["3. Pedidos (",g.length,"/",s.length," seleccionados)"]}),e.jsx(k,{variant:"ghost",size:"sm",onClick:M,children:s.every(l=>l.selected)?"Deseleccionar todos":"Seleccionar todos"})]}),e.jsx("div",{className:"border rounded-lg overflow-hidden divide-y max-h-80 overflow-y-auto",children:s.map(l=>e.jsxs("div",{className:`p-3 flex items-center gap-3 text-sm transition-colors ${l.selected?"bg-background":"bg-muted/50 opacity-60"}`,children:[e.jsx(Jt,{checked:l.selected,onCheckedChange:()=>v(l.orderNumber)}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(ee,{variant:"outline",className:"font-mono text-xs",children:l.orderNumber}),e.jsx("span",{className:"font-medium truncate",children:l.name})]}),e.jsxs("p",{className:"text-xs text-muted-foreground truncate mt-0.5",children:[l.address1,", ",l.city," ⢠",l.items.length," item(s)"]})]}),e.jsxs("div",{className:"w-24 shrink-0",children:[e.jsx(w,{className:"text-xs",children:"Valor $"}),e.jsx($,{value:l.valorContenido,onChange:j=>Q(l.orderNumber,j.target.value),type:"number",className:"h-7 text-xs mt-0.5"})]})]},l.orderNumber))})]}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsxs(k,{variant:"outline",onClick:()=>r([]),className:"gap-2",children:[e.jsx(Yt,{className:"h-4 w-4"}),"Limpiar"]}),e.jsxs(k,{onClick:me,disabled:g.length===0||C.isPending,className:"gap-2 bg-blue-600 hover:bg-blue-700 flex-1",children:[e.jsx(rs,{className:"h-4 w-4"}
64),"Generar archivo Blue Express (",g.length,")"]})]})]})]})]})}function $s(t){const a=[];let s="",r=!1;for(let n=0;n<t.length;n++){const i=t[n];i==='"'?r&&t[n+1]==='"'?(s+='"',n++):r=!r:i===","&&!r?(a.push(s),s=""):s+=i}return a.push(s),a}const be={pending:{label:"Pendiente",variant:"secondary",icon:yt},assigned:{label:"Asignado",variant:"outline",icon:Se},in_transit:{label:"En Tránsito",variant:"default",icon:xe},delivered:{label:"Entregado",variant:"default",icon:wt},cancelled:{label:"Cancelado",variant:"destructive",icon:_t}},et={uflash:{label:"UFlash",color:"bg-orange-500"},bluexpress:{label:"Blue Express",color:"bg-blue-500"},driver:{label:"Chofer",color:"bg-green-500"}};function _a(){const{user:t,isAdmin:a}=Ce(),s=Qe(),{logActivity:r}=Nt(),[n,i]=x.useState(""),[c,o]=x.useState("all"),[m,p]=x.useState(!1),[h,b]=x.useState(null),[_,E]=x.useState(!1),[S,f]=x.useState(!1),{data:y,isLoading:P}=$e({queryKey:["shipments"],queryFn:async()=>{try{await B.rpc("cleanup_old_pending_shipments")}catch{}const{data:u,error:d}=await B.from("shipments").select(` 65 *, 66 driver:profiles!shipments_driver_id_fkey(first_name, last_name, email) 67 `).order("created_at",{ascending:!1});if(d)throw d;return u}}),{data:N}=$e({queryKey:["drivers"],queryFn:async()=>{const{data:u,error:d}=await B.from("user_roles").select("user_id").eq("role","chofer");if(d)throw d;if(!u||u.length===0)return[];const g=u.map(Q=>Q.user_id),{data:v,error:M}=await B.from("profiles").select("id, first_name, last_name, email").in("id",g);if(M)throw M;return v||[]}}),te=Ee({mutationFn:async({id:u,status:d,driver_id:g})=>{const v={};d&&(v.status=d),g!==void 0&&(v.driver_id=g);const{error:M}=await B.from("shipments").update(v).eq("id",u);if(M)throw M},onSuccess:(u,d)=>{var g;if(s.invalidateQueries({queryKey:["shipments"]}),d.status){const v=((g=be[d.status])==null?void 0:g.label)||d.status;r("update_shipment_status",`actualizó estado de envÃo a "${v}"`,{shipment_id:d.id,new_status:d.status})}},onError:u=>{L.error("Error al actualizar el envÃo"),console.error(u)}}),D=x.useMemo(()=>y?y.filter(u=>{const d=u.customer_name.toLowerCase().includes(n.toLowerCase())||u.tracking_code.toLowerCase().includes(n.toLowerCase())||u.destination_address.toLowerCase().includes(n.toLowerCase())||u.customer_phone.includes(n),g=c==="all"||u.status===c;return d&&g}):[],[y,n,c]),W=u=>{const d=`https://floraflor.vercel.app/tracking/${u}`;navigator.clipboard.writeText(d),L.info("Link copiado al portapapeles")},K=()=>{if(!D||D.length===0){L.error("No hay envÃos para descargar");return}const u=["Código","Cliente","Teléfono","Dirección","Fecha Entrega","Estado","Chofer","Notas"],d=D.map(C=>[C.tracking_code,C.customer_name,C.customer_phone,C.destination_address,C.delivery_date?oe(new Date(C.delivery_date),"dd/MM/yyyy"):"",be[C.status].label,C.driver?`${C.driver.first_name||""} ${C.driver.last_name||""}`.trim():"",C.notes||""]),g=[u,...d].map(C=>C.map(me=>`"${String(me).replace(/"/g,'""')}"`).join(",")).join(` 68`),v=new Blob(["\uFEFF"+g],{type:"text/csv;charset=utf-8;"}),M=URL.createObjectURL(v),Q=document.createElement("a");Q.href=M,Q.download=`envios_${oe(new Date,"yyyy-MM-dd")}.csv`,Q.click(),URL.revokeObjectURL(M)},pe=u=>{b(u),E(!0)},ve=u=>{b(u),f(!0)};return e.jsxs("div",{className:"min-h-screen bg-gradient-to-br from-secondary/30 via-background to-accent/20 pb-20",children:[e.jsxs("div",{className:"w-full py-6 px-4 space-y-6 max-w-6xl mx-auto",children:[e.jsx("div",{className:"space-y-2",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2.5 bg-primary/10 rounded-xl",children:e.jsx(xe,{className:"w-6 h-6 text-primary"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"EnvÃos"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Gestiona los envÃos y seguimiento"})]})]})}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:[(D==null?void 0:D.length)||0," envÃo(s) encontrado(s)"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(k,{variant:"outline",onClick:K,size:"sm",className:"gap-2",children:[e.jsx(Zt,{className:"h-4 w-4"}),"CSV"]}),a&&e.jsxs(k,{onClick:()=>p(!0),size:"sm",className:"gap-2",children:[e.jsx(jt,{className:"h-4 w-4"}),"Nuevo EnvÃo"]})]})]}),e.jsx(Is,{}),e.jsx(Ms,{}),e.jsxs(ye,{className:"border-border/40 bg-card/80 backdrop-blur-sm",children:[e.jsx(st,{children:e.jsx(at,{className:"text-lg",children:"Filtros de Búsqueda"})}),e.jsx(we,{children:e.jsxs("div",{className:"flex flex-col sm:flex-row gap-4",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(es,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx($,{placeholder:"Buscar por nombre, código, dirección o teléfono...",value:n,onChange:u=>i(u.target.value),className:"pl-10"})]}),e.jsxs(le,{value:c,onValueChange:o,children:[e.jsx(ce,{className:"w-full sm:w-48",children:e.jsx(de,{placeholder:"Estado"})}),e.jsxs(ue,{children:[e.jsx(A,{value:"all",children:"Todos los estados"}),e.jsx(A,{value:"pending",children:"Pendiente"}),e.jsx(A,{value:"assigned",children:"Asignado"}),e.jsx(A,{value:"in_transit",children:"En Tránsito"}),e.jsx(A,{value:"delivered",children:"Entregado"}),e.jsx(A,{value:"cancelled",children:"Cancelado"})]})]})]})})]}),e.jsx(ye,{className:"border-border/40 bg-card/90 backdrop-blur-sm",children:e.jsx(we,{className:"p-0",children:P?e.jsx("div",{className:"flex justify-center p-8",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary"})}):D.length===0?e.jsxs("div",{className:"text-center p-8",children:[e.jsx("div",{className:"p-4 bg-muted/50 rounded-full w-fit mx-auto mb-4",children:e.jsx(xe,{className:"w-12 h-12 text-muted-foreground"})}),e.jsx("h3",{className:"text-xl font-semibold mb-2",children:"No hay envÃos que mostrar"}),e.jsx("p",{className:"text-muted-foreground",children:n||c!=="all"?"Intenta ajustar los filtros de búsqueda":"Agrega tu primer envÃo para comenzar"})]}):e.jsx("div",{className:"divide-y",children:D.map(u=>{const d=be[u.status].icon;return e.jsx("div",{className:"p-4 hover:bg-accent/50 transition-colors",children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-mono text-sm font-medium text-primary",children:u.tracking_code}),e.jsxs(ee,{variant:be[u.status].variant,className:"gap-1",children:[e.jsx(d,{className:"h-3 w-3"}),be[u.status].label]}),u.carrier&&et[u.carrier]&&e.jsxs(ee,{variant:"outline",className:"gap-1",children:[e.jsx("div",{className:`w-2 h-2 rounded-full ${et[u.carrier].color}`}),et[u.carrier].label]}),u.shopify_order_number&&e.jsxs(ee,{variant:"outline",className:"bg-green-50 text-green-700 border-green-200",children:["#",u.shopify_order_number]})]}),e.jsx("p",{className:"font-medium",children:u.customer_name}),e.jsx("p",{className:"text-sm text-muted-foreground",children:u.destination_address}),e.jsx("p",{className:"text-sm text-muted-foreground",children:u.customer_phone}),u.delivery_date&&e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Entrega: ",oe(new Date(u.delivery_date),"dd MMM yyyy",{locale:_e})]}),u.driver&&e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Chofer: ",u.driver.first_name," ",u.driver.last_name]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[a&&N&&N.length>0&&e.jsxs(le,{value:u.driver_id||"unassigned",onValueChange:g=>{te.mutate({id:u.id,driver_id:g==="unassigned"?null:g,status:g!=="unassigned"&&u.status==="pending"?"assigned":void 0})},children:[e.jsx(ce,{className:"w-36",children:e.jsx(de,{placeholder:"Asignar chofer"})}),e.jsxs(ue,{children:[e.jsx(A,{value:"unassigned",children:"Sin asignar"}),N.map(g=>e.jsx(A,{value:g.id,children:g.first_name||g.email},g.id))]})]}),e.jsx(k,{variant:"outline",size:"sm",onClick:()=>ve(u),children:e.jsx(ts,{className:"h-4 w-4"})}),e.jsx(k,{variant:"outline",size:"sm",onClick:()=>pe(u),children:e.jsx(ss,{className:"h-4 w-4"})}),e.jsx(k,{variant:"outline",size:"sm",onClick:()=>W(u.tracking_code),children:e.jsx(as,{className:"h-4 w-4"})})]})]})},u.id)})})})}),e.jsx(ns,{open:m,onOpenChange:p}),h&&e.jsxs(e.Fragment,{children:[e.jsx(Bs,{open:_,onOpenChange:E,shipment:h}),e.jsx(Ls,{open:S,onOpenChange:f,shipment:h,drivers:N||[],onUpdate:()=>s.invalidateQueries({queryKey:["shipments"]})})]})]}),e.jsx(zt,{})]})}
68export{_a 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.