PageSourceSearch

https://floraflor.lovable.app/assets/SalesOrders-jMiapWFf.js

js floraflor.lovable.app collected 2026-10-03 03:31:39 UTC 23,393 bytes, 11 lines download raw bytes

1import{n as fe,r as l,j as e,B as x,J as m,s as j,f as ze,b as I,h as U,q as Te,P as me,t as Oe,w as Ie}from"./index-RxDZGo8S.js";import{I as M}from"./input-CS9s6izM.js";import{C as Z}from"./checkbox-BpNYG9vW.js";import{D as xe,a as ge,b as ye,c as be,d as We,f as He}from"./dialog-Kd5QqSd7.js";import{L as G}from"./label-Fqe9mk9Y.js";import{M as Be}from"./message-circle-BHbxpExN.js";import{u as _e}from"./useProductCosts-BGDetP5F.js";import{T as Ke}from"./triangle-alert-tJx7Lrdn.js";import{R as ue}from"./refresh-cw-DBr1zaJK.js";import{S as Re}from"./search-Dss-hsDb.js";import{C as Ue}from"./calendar-DWLwoYri.js";import{P as Ge}from"./printer-ot7QQNne.js";import{T as Qe}from"./trash-2-DXjGIb-t.js";import{C as Ze}from"./chevron-up-DbNI7lUd.js";import{f as he}from"./format-DuJJlbci.js";import{e as pe}from"./es-DhgJzuV8.js";import"./index-Da3vg3Bj.js";import"./check-dsJNWiFz.js";import"./index-BnR4gmtC.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 Je=fe("ClipboardPaste",[["path",{d:"M15 2H9a1 1 0 0 0-1 1v2c0 .6.4 1 1 1h6c.6 0 1-.4 1-1V3c0-.6-.4-1-1-1Z",key:"1pp7kr"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2M16 4h2a2 2 0 0 1 2 2v2M11 14h10",key:"2ik1ml"}],["path",{d:"m17 10 4 4-4 4",key:"vp2hj1"}]]);/**
7 * @license lucide-react v0.462.0 - ISC
8 *
9 * This source code is licensed under the ISC license.
10 * See the LICENSE file in the root directory of this source tree.
11 */const Ve=fe("SlidersHorizontal",[["line",{x1:"21",x2:"14",y1:"4",y2:"4",key:"obuewd"}],["line",{x1:"10",x2:"3",y1:"4",y2:"4",key:"1q6298"}],["line",{x1:"21",x2:"12",y1:"12",y2:"12",key:"1iu8h1"}],["line",{x1:"8",x2:"3",y1:"12",y2:"12",key:"ntss68"}],["line",{x1:"21",x2:"16",y1:"20",y2:"20",key:"14d8ph"}],["line",{x1:"12",x2:"3",y1:"20",y2:"20",key:"m0wm8r"}],["line",{x1:"14",x2:"14",y1:"2",y2:"6",key:"14e1ph"}],["line",{x1:"8",x2:"8",y1:"10",y2:"14",key:"1i6ji0"}],["line",{x1:"16",x2:"16",y1:"18",y2:"22",key:"1lctlv"}]]);function Xe({open:P,onOpenChange:p,onSuccess:f}){const[g,A]=l.useState(""),[S,F]=l.useState(""),[u,y]=l.useState(""),[C,c]=l.useState(""),[N,b]=l.useState(!1),v=async()=>{try{const E=(await navigator.clipboard.readText()).replace(/[^\d+]/g,"");y(E),m.success("Teléfono pegado")}catch{m.error("No se pudo acceder al portapapeles")}},W=async h=>{if(h.preventDefault(),!g.trim()){m.error("Ingresa el nombre del cliente");return}if(!S.trim()){m.error("Ingresa el ítem");return}if(!C||parseFloat(C)<=0){m.error("Ingresa un precio válido");return}b(!0);try{const H=(u.replace(/\D/g,"")||Date.now().toString()).slice(-10),{error:B}=await j.from("sales_orders").insert({sale_number:H,source:"otros",status:"esperando_pago_envio",customer_data:{name:g.trim(),phone:u.trim(),source_type:"whatsapp"},products:[{name:S.trim(),price:parseFloat(C),quantity:1}]});if(B)throw B;m.success("Pedido WhatsApp creado"),A(""),F(""),y(""),c(""),p(!1),f()}catch(E){console.error("Error creating WhatsApp order:",E),m.error("Error al crear el pedido")}finally{b(!1)}};return e.jsx(xe,{open:P,onOpenChange:p,children:e.jsxs(ge,{className:"sm:max-w-md",children:[e.jsx(ye,{children:e.jsxs(be,{className:"flex items-center gap-2",children:[e.jsx(Be,{className:"h-5 w-5 text-green-500"}),"Nuevo Pedido WhatsApp"]})}),e.jsxs("form",{onSubmit:W,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(G,{htmlFor:"customerName",children:"Nombre del cliente *"}),e.jsx(M,{id:"customerName",value:g,onChange:h=>A(h.target.value),placeholder:"Nombre completo",autoFocus:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(G,{htmlFor:"itemName",children:"Ítem *"}),e.jsx(M,{id:"itemName",value:S,onChange:h=>F(h.target.value),placeholder:"Ej: Orquídea Phalaenopsis"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(G,{htmlFor:"customerPhone",children:"Celular cliente"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(M,{id:"customerPhone",value:u,onChange:h=>y(h.target.value),placeholder:"+56 9 1234 5678",type:"tel",className:"flex-1"}),e.jsx(x,{type:"button",variant:"outline",size:"icon",onClick:v,title:"Pegar teléfono",children:e.jsx(Je,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(G,{htmlFor:"price",children:"Precio *"}),e.jsx(M,{id:"price",value:C,onChange:h=>c(h.target.value),placeholder:"0",type:"number",min:"0",step:"1"})]}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx(x,{type:"button",variant:"outline",className:"flex-1",onClick:()=>p(!1),children:"Cancelar"}),e.jsx(x,{type:"submit",className:"flex-1 bg-green-600 hover:bg-green-700",disabled:N,children:N?"Creando...":"Crear Pedido"})]})]})]})})}const Ye=({open:P,onOpenChange:p,missingProducts:f,onComplete:g})=>{const{saveCost:A}=_e(),[S,F]=l.useState({}),[u,y]=l.useState(!1);l.useEffect(()=>{if(P&&f.length>0){const c={};f.forEach(N=>{c[N]=""}),F(c)}},[P,f]);const C=async()=>{const c=Object.entries(S);if(c.filter(([b,v])=>!v||isNaN(parseInt(v))||parseInt(v)<0).length>0){m.error("Completa todos los costos con valores válidos");return}y(!0);try{await Promise.all(c.map(([b,v])=>A(b,parseInt(v)))),m.success(`${c.length} costo${c.length>
111?"s":""} guardado${c.length>1?"s":""}`),g(),p(!1)}catch{m.error("Error al guardar costos")}finally{y(!1)}};return f.length===0?null:e.jsx(xe,{open:P,onOpenChange:p,children:e.jsxs(ge,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[e.jsxs(ye,{children:[e.jsxs(be,{className:"flex items-center gap-2",children:[e.jsx(Ke,{className:"h-5 w-5 text-amber-500"}),"Costos faltantes"]}),e.jsx(We,{children:"Los siguientes productos no tienen costo registrado. Completa el costo para calcular ganancias."})]}),e.jsx("div",{className:"space-y-4",children:f.map(c=>e.jsxs("div",{className:"flex items-center gap-3 p-3 border rounded-lg bg-muted/30",children:[e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx("p",{className:"text-sm font-medium truncate",children:c})}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"$"}),e.jsx(M,{type:"number",min:"0",placeholder:"0",value:S[c]||"",onChange:N=>F(b=>({...b,[c]:N.target.value})),className:"w-28 h-9"})]})]},c))}),e.jsxs(He,{className:"gap-2",children:[e.jsx(x,{variant:"outline",onClick:()=>p(!1),children:"Omitir"}),e.jsx(x,{onClick:C,disabled:u,children:u?"Guardando...":"Guardar costos"})]})]})})},bs=()=>{const P=ze(),[p,f]=l.useState(!1),[g,A]=l.useState(""),[S,F]=l.useState(new Set),[u,y]=l.useState(new Set),[C,c]=l.useState(!1),[N,b]=l.useState(!1),[v,W]=l.useState([]),{getMissingCosts:h,isLoading:E}=_e(),{data:H=[],refetch:B}=I({queryKey:["order-statuses"],queryFn:async()=>{const{data:t,error:s}=await j.from("order_statuses").select("order_id, platform, status");if(s)throw s;return t||[]},staleTime:1e3*60,gcTime:1e3*60*5}),K=(t,s,a)=>{if(a)return"entregado";const r=H.find(n=>n.order_id===t&&n.platform===s);return(r==null?void 0:r.status)||"pendiente"},{data:J=[],refetch:je,isLoading:Ne}=I({queryKey:["shopify-orders-unified"],queryFn:async()=>{const{data:t,error:s}=await j.from("shopify_orders").select("id, shopify_order_id, order_number, customer_name, customer_email, customer_phone, line_items, total_price, created_at_shopify, shipping_address, billing_address, fulfillment_status, financial_status, raw_order").order("created_at_shopify",{ascending:!1}).limit(20);if(s)throw s;return t||[]},staleTime:1e3*60,gcTime:1e3*60*5}),{data:V=[],refetch:ve,isLoading:we}=I({queryKey:["meli-orders-unified"],queryFn:async()=>{const{data:t,error:s}=await j.from("meli_orders").select("id, meli_order_id, buyer_name, buyer_email, buyer_phone, items, total_amount, purchase_date, order_status, shipping_status, shipping_address, billing_info, raw_order").order("purchase_date",{ascending:!1}).limit(20);if(s)throw s;return t||[]},staleTime:1e3*60,gcTime:1e3*60*5}),{data:X=[],refetch:Q,isLoading:Se}=I({queryKey:["sales-orders-unified"],queryFn:async()=>{const{data:t,error:s}=await j.from("sales_orders").select("id, sale_number, customer_data, products, status, source, created_at, shipping_cost").order("created_at",{ascending:!1}).limit(20);if(s)throw s;return t||[]},staleTime:1e3*60,gcTime:1e3*60*5}),{data:Y=[],refetch:Ce,isLoading:ke}=I({queryKey:["falabella-orders-unified"],queryFn:async()=>{const{data:t,error:s}=await j.from("falabella_orders").select("*").order("created_at_falabella",{ascending:!1}).limit(20);if(s)throw s;return t||[]}}),ee=U({mutationFn:async()=>{const{error:t}=await j.functions.invoke("shopify-api",{body:{action:"fetch",endpoint:"orders",method:"GET"}});if(t)throw t},onSuccess:()=>je(),onError:t=>m.error(`Error Shopify: ${t.message}`)}),se=U({mutationFn:async()=>{const{error:t}=await j.functions.invoke("meli-api",{body:{action:"sync-orders"}});if(t)throw t},onSuccess:()=>ve(),onError:t=>m.error(`Error MercadoLibre: ${t.message}`)}),te=U({mutationFn:async()=>{const{error:t}=await j.functions.invoke("falabella-api",{body:{action:"sync-orders"}});if(t)throw t},onSuccess:()=>Ce(),onError:t=>m.error(`Error Falabella: ${t.message}`)}),Pe=U({mutationFn:async({orderId:t,platform:s,status:a})=>{const{error:r}=await j.from("order_statuses").upsert({order_id:t,platform:s,status:a},{onConflict:"order_id,platform"});if(r)throw r},onSuccess:()=>{B(),m.success("Estado actualizado")}});l.useEffect(()=>{(async()=>{f(!0);try{await Promise.allSettled([ee.mutateAsync(),se.mutateAsync(),te.mutateAsync(),Q()])}catch(s){console.error("Sync error:",s)}finally{f(!1)}})()},[]);const D=l.useMemo(()=>{const t=[];return J.forEach(s=>{var q,L,$,z,T;const a=s.raw_order||{}
11,r=s.shipping_address||a.shipping_address||null,n=s.billing_address||a.billing_address||null,i=s.customer_email||((q=a.customer)==null?void 0:q.email)||a.email||a.contact_email||null,o=s.customer_phone||((L=a.customer)==null?void 0:L.phone)||(r==null?void 0:r.phone)||(n==null?void 0:n.phone)||null;let d=s.customer_name;(!d||d==="Sin nombre")&&(($=a.customer)!=null&&$.first_name&&((z=a.customer)!=null&&z.last_name)?d=`${a.customer.first_name} ${a.customer.last_name}`.trim():(T=a.customer)!=null&&T.first_name?d=a.customer.first_name:r!=null&&r.name?d=r.name:r!=null&&r.first_name?d=`${r.first_name||""} ${r.last_name||""}`.trim():n!=null&&n.name?d=n.name:n!=null&&n.first_name?d=`${n.first_name||""} ${n.last_name||""}`.trim():i?d=i.split("@")[0]:d="Sin nombre");const R=(Array.isArray(s.line_items)?s.line_items:Array.isArray(a.line_items)?a.line_items:[]).map(w=>{var O;return{name:w.title||w.name||"Producto",price:parseFloat(w.price)||0,quantity:w.quantity||1,sku:w.sku,thumbnail:((O=w.image)==null?void 0:O.src)||null}});t.push({id:s.shopify_order_id||s.id,platform:"shopify",orderNumber:s.order_number||s.shopify_order_id||"",customerName:d,customerEmail:i,customerPhone:o,products:R,total:parseFloat(s.total_price)||0,status:K(s.shopify_order_id||s.id,"shopify",!1),platformStatus:s.fulfillment_status,date:new Date(s.created_at_shopify||s.created_at),shippingAddress:r,billingAddress:n,currency:s.currency,rawData:a,isDeliveredFromPlatform:!1})}),V.forEach(s=>{var q,L,$,z,T,w,O,oe;const a=s.raw_order||{},n=(Array.isArray(s.items)?s.items:Array.isArray(a.order_items)?a.order_items:[]).map(k=>{var le,ce,de;return{name:k.title||((le=k.item)==null?void 0:le.title)||"Producto MercadoLibre",price:parseFloat(k.unit_price||0),quantity:k.quantity||1,sku:k.seller_sku||((ce=k.item)==null?void 0:ce.seller_sku),thumbnail:k.thumbnail||((de=k.item)==null?void 0:de.thumbnail)||null}});let i=(s.buyer_name||"").trim()||"Comprador";const o=((q=s.shipping_address)==null?void 0:q.receiver_name)||(($=(L=s.shipping_details)==null?void 0:L.receiver_address)==null?void 0:$.receiver_name);o&&(i==="Comprador"||/^[A-Z0-9]{6,}$/.test(i))&&(i=o),/^[A-Z0-9]{6,}$/.test(i)&&(i="Comprador");const d=s.buyer_email||((z=a.buyer)==null?void 0:z.email)||null,ie=s.buyer_phone||((T=s.shipping_address)==null?void 0:T.receiver_phone)||((O=(w=s.shipping_details)==null?void 0:w.receiver_address)==null?void 0:O.receiver_phone)||null,R=s.shipping_status==="delivered"||s.order_status==="delivered";t.push({id:s.meli_order_id||s.id,platform:"mercadolibre",orderNumber:s.meli_order_id||"",customerName:i,customerNickname:(oe=a.buyer)==null?void 0:oe.nickname,customerEmail:d,customerPhone:ie,products:n,total:parseFloat(s.total_amount)||0,status:K(s.meli_order_id||s.id,"mercadolibre",R),platformStatus:s.shipping_status||s.order_status,date:new Date(s.purchase_date),shippingAddress:s.shipping_address,currency:s.currency,rawData:a,isDeliveredFromPlatform:R})}),X.forEach(s=>{const a=Array.isArray(s.products)?s.products:[],r=s.customer_data||{},n=r.source_type==="whatsapp";t.push({id:s.id,platform:n?"whatsapp":"otros",orderNumber:s.sale_number||"",customerName:r.name||"Sin nombre",customerEmail:r.email,customerPhone:r.phone,products:a.map(i=>({name:i.name||i.producto||"Producto",price:i.price||i.precio||0,quantity:i.quantity||i.cantidad||1})),total:a.reduce((i,o)=>i+(o.price||o.precio||0)*(o.quantity||o.cantidad||1),0)+(s.shipping_cost||0),status:K(s.id,n?"whatsapp":"otros",!1),date:new Date(s.created_at),rawData:s,isDeliveredFromPlatform:!1})}),Y.forEach(s=>{const r=(Array.isArray(s.items)?s.items:[]).map(n=>({name:n.name||"Producto Falabella",price:parseFloat(n.price||n.paid_price||0),quantity:n.quantity||1,sku:n.sku}));t.push({id:s.falabella_order_id||s.id,platform:"falabella",orderNumber:s.order_number||s.falabella_order_id||"",customerName:s.customer_name||"Cliente Falabella",customerEmail:s.customer_email,customerPhone:s.customer_phone,products:r,total:parseFloat(s.total_amount)||0,status:K(s.falabella_order_id||s.id,"falabella",s.shipping_status==="delivered"),platformStatus:s.shipping_status,date:new Date(s.created_at_falabella||s.created_at),shippingAddress:s.shipping_address,billingAddress:s.billing_address,currency:s.currency,rawData:s,isDeliveredFromPlatform:s.shipping_status==="delivered"})}),t.sort((s,a)=>a.date.getTime()-s.date.getTime()).slice(0,20)},[J,V,X,Y,H]),_=l.useMemo(()=>
11{if(!g.trim())return D;const t=g.toLowerCase();return D.filter(s=>s.orderNumber.toLowerCase().includes(t)||s.customerName.toLowerCase().includes(t)||s.products.some(a=>a.name.toLowerCase().includes(t)))},[D,g]),ae=l.useRef(!1);l.useEffect(()=>{if(E||p||D.length===0||ae.current)return;const t={};D.forEach(r=>r.products.forEach(n=>{if(n.name){const i=n.name.trim();t[i]=(t[i]||0)+1}}));const s=Object.entries(t).filter(([r,n])=>n>1).map(([r])=>r),a=h(s);console.log("[CostCheck] Repeated products:",s.length,"Missing costs:",a.length,a),a.length>0&&(ae.current=!0,W(a),b(!0))},[D,E,p,h]);const Fe=(t,s)=>{if(t.platform==="mercadolibre"&&t.isDeliveredFromPlatform){m.error("Este pedido ya fue marcado como entregado por MercadoLibre");return}Pe.mutate({orderId:t.id,platform:t.platform,status:s})},Ee=t=>{F(s=>{const a=new Set(s);return a.has(t)?a.delete(t):a.add(t),a})},Ae=t=>{y(s=>{const a=new Set(s);return a.has(t)?a.delete(t):a.add(t),a})},re=()=>{u.size===_.length?y(new Set):y(new Set(_.map(t=>t.id)))},ne=(t,s)=>{const a=(s==null?void 0:s.toUpperCase())==="USD"?"USD":"CLP";return new Intl.NumberFormat("es-CL",{style:"currency",currency:a,maximumFractionDigits:0}).format(t)},De=t=>{switch(t){case"pendiente":return"Por entregar";case"enviado":return"En tránsito";case"entregado":return"Entregado";default:return"Pendiente"}},Me=t=>{switch(t){case"pendiente":return"text-warning";case"enviado":return"text-info";case"entregado":return"text-success";default:return"text-muted-foreground"}},qe=Ne||we||Se||ke,Le=({platform:t})=>t==="mercadolibre"?e.jsx("div",{className:"w-8 h-8 rounded-full bg-brand-ml flex items-center justify-center text-xs font-bold text-brand-ml-foreground shrink-0",children:"ML"}):t==="shopify"?e.jsx("div",{className:"w-8 h-8 rounded-full bg-brand-shopify flex items-center justify-center text-xs font-bold text-brand-shopify-foreground shrink-0",children:"S"}):t==="falabella"?e.jsx("div",{className:"w-8 h-8 rounded-full bg-brand-falabella flex items-center justify-center text-xs font-bold text-brand-falabella-foreground shrink-0",children:"F"}):t==="whatsapp"?e.jsx("div",{className:"w-8 h-8 rounded-full bg-green-500 flex items-center justify-center text-xs font-bold text-white shrink-0",children:"WA"}):e.jsx("div",{className:"w-8 h-8 rounded-full bg-muted flex items-center justify-center text-xs font-bold text-muted-foreground shrink-0",children:"O"}),$e=({order:t})=>{const s=S.has(t.id),a=u.has(t.id),r=he(t.date,"d MMM HH:mm 'hs'",{locale:pe}),n=!(t.platform==="mercadolibre"&&t.isDeliveredFromPlatform),i=t.platform==="mercadolibre"&&t.orderNumber.length>10?`${t.orderNumber.slice(-8)}`:t.orderNumber;return e.jsxs("div",{className:"bg-card border border-border rounded-lg overflow-hidden mb-3",children:[e.jsxs("div",{className:"flex items-center gap-3 px-3 py-3 border-b border-border cursor-pointer hover:bg-muted/50 transition-colors",onClick:()=>P(`/pedidos/${t.orderNumber}`),children:[e.jsx(Z,{checked:a,onCheckedChange:()=>Ae(t.id),onClick:o=>o.stopPropagation(),className:"shrink-0"}),e.jsx(Le,{platform:t.platform}),e.jsxs("div",{className:"flex-1 min-w-0 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsxs("span",{className:"font-semibold text-foreground text-sm",children:["#",i]}),e.jsx("span",{className:"text-muted-foreground hidden sm:inline",children:"|"}),e.jsx("span",{className:"text-muted-foreground text-xs sm:text-sm whitespace-nowrap",children:r})]}),e.jsx("span",{className:"text-sm text-foreground truncate max-w-[120px] sm:max-w-[150px]",children:t.customerName})]})]}),e.jsx("div",{className:"p-3 sm:p-4",children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:justify-between gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"mb-3",children:[e.jsx("p",{className:`font-semibold text-sm ${Me(t.status)}`,children:De(t.status)}),t.platform==="mercadolibre"&&t.isDeliveredFromPlatform&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Llegó el ",he(t.date,"d 'de' MMMM",{locale:pe})," (ML)"]}),t.status==="pendiente"&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Por acordar con el comprador"})]}),e.jsxs("div",{className:"space-y-2",children:[t.products.slice(0,s?void 0:2).map((o,d)=>e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3 bg-muted/30 rounded-lg p-2",children:[e.jsx("div",{className:"w-10 h-10 sm:w-12 sm:h-12 bg-muted rounded-md flex items-center justify-center overflow-hidden shrink-0",children:o.thumbnail?e.jsx("img",{src:o.thumbnail,alt:o.name,className:"w-full h-full object-cover"}):e.jsx(me,{className:"w-5 h-5 sm:w-6 sm:h-6 text-muted-foreground"})}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx("p",{className:"text-xs sm:text-sm text-foreground line-clamp-2",children:o.name})}),e.jsxs("div",{className:"text-right shrink-0",children:[e.jsx("p",{className:"text-xs sm:text-sm font-medium text-foreground",children:ne(o.price,t.currency)}),e.jsxs("p",{className:"text-[10px] sm:text-xs text-muted-foreground",children:[o.quantity," u."]})]})]},d)),t.products.length>2&&e.jsxs("button",{onClick:()=>Ee(t.id),className:"text-xs text-info hover:underline flex items-center gap-1",children:[s?e.jsx(Ze,{className:"h-3 w-3"}):e.jsx(Ie,{className:"h-3 w-3"}),s?"Mostrar menos":`+${t.products.length-2} más`]})]})]}),e.jsxs("div",{className:"flex items-center justify-between sm:flex-col sm:items-end gap-2 mt-3 sm:mt-0 sm:ml-4 pt-3 sm:pt-0 border-t sm:border-t-0 border-border",children:[e.jsx("p",{className:"text-base sm:text-lg font-bold text-foreground",children:ne(t.total,t.currency)}),n?e.jsxs("select",{value:t.status,onChange:o=>Fe(t,o.target.value),className:"text-xs border border-border rounded px-2 py-1 bg-background text-foreground",onClick:o=>o.stopPropagation(),children:[e.jsx("option",{value:"pendiente",children:"Pendiente"}),e.jsx("option",{value:"enviado",children:"Enviado"}),e.jsx("option",{value:"entregado",children:"Entregado"})]}):e.jsx("span",{className:"text-xs text-success bg-success/10 px-2 py-1 rounded",children:"Entregado (ML)"})]})]})})]})};return e.jsxs("div",{className:"min-h-screen bg-background pb-24",children:[e.jsx("div",{className:"bg-card border-b border-border sticky top-0 z-10",children:e.jsxs("div",{className:"w-full px-4 py-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h1",{className:"text-xl font-bold text-foreground",children:"Pedidos"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(x,{size:"icon",className:"bg-green-500 hover:bg-green-600 text-white h-8 w-8",onClick:()=>c(!0),children:e.jsx(Te,{className:"h-5 w-5"})}),e.jsxs(x,{variant:"outline",size:"sm",onClick:()=>{f(!0),Promise.allSettled([ee.mutateAsync(),se.mutateAsync(),te.mutateAsync(),Q()]).finally(()=>f(!1))},disabled:p,children:[e.jsx(ue,{className:`h-4 w-4 mr-2 ${p?"animate-spin":""}`}),p?"Sincronizando...":"Sincronizar"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(Re,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(M,{placeholder:"Buscar pedido, cliente o producto...",value:g,onChange:t=>A(t.target.value),className:"pl-10"})]}),e.jsx(x,{variant:"outline",size:"icon",className:"shrink-0",children:e.jsx(Ue,{className:"h-4 w-4"})}),e.jsxs(x,{variant:"outline",size:"sm",className:"shrink-0 gap-1",children:[e.jsx(Ve,{className:"h-4 w-4"}),"Filtrar"]})]}),u.size>0&&e.jsxs("div",{className:"flex items-center gap-2 mt-3 p-2 bg-muted rounded-lg",children:[e.jsx(Z,{checked:u.size===_.length,onCheckedChange:re}),e.jsxs("span",{className:"text-sm text-foreground flex-1",children:[u.size," seleccionado",u.size>1?"s":""]}),e.jsxs(x,{variant:"outline",size:"sm",className:"gap-1",children:[e.jsx(Ge,{className:"h-4 w-4"}),"Imprimir"]}),e.jsxs(x,{variant:"outline",size:"sm",className:"gap-1 text-destructive hover:text-destructive",children:[e.jsx(Qe,{className:"h-4 w-4"}),"Eliminar"]})]}),e.jsxs("div",{className:"flex items-center justify-between mt-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Z,{checked:u.size===_.length&&_.length>0,onCheckedChange:re}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Seleccionar todos"})]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[_.length," pedido",_.length!==1?"s":""]})]})]})}),e.jsx("div",{className:"w-full px-4 py-4",children:qe&&_.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12",children:[e.jsx(ue,{className:"h-8 w-8 animate-spin text-muted-foreground mb-2"}),e.jsx("p",{className:"text-muted-foreground",children:"Cargando pedidos..."})]}):_.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12",children:[e.jsx(me,{className:"h-12 w-12 text-muted-foreground mb-4"}),e.jsx("p",{className:"text-muted-foreground",children:"No hay pedidos"})]}):e.jsx("div",{children:_.map(t=>e.jsx($e,{order:t},`${t.platform}-${t.id}`))})}),e.jsx(Xe,{open:C,onOpenChange:c,onSuccess:()=>Q()}),e.jsx(Ye,{open:N,onOpenChange:b,missingProducts:v,onComplete:()=>W([])}),e.jsx(Oe,{})]})};export{bs 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.