PageSourceSearch

https://peyu-command-flow.base44.app/assets/AdminProducts-BKqePIA1.js

js peyu-command-flow.base44.app collected 2026-10-03 03:08:50 UTC 122,162 bytes, 149 lines download raw bytes

1import{c as ce,r as o,bk as ee,j as e,N as I,L as R,S as q,bl as ss,ak as Ae,ah as U,ag as ue,e as L,af as Te,al as G,X as Q,aM as oe,a7 as Ne,a9 as ae,ar as ne,t as K,Q as ve,W as Ve,ae as We,R as Xe,D as as,i as J,w as pe,aN as ts,bm as Le,C as Re,bb as rs,ao as Qe,bn as is,P as Pe,au as ze,a8 as ls,z as ns,l as os,F as cs}from"./index-DjUjCSoi.js";import{T as ds}from"./target-jjL8a3nE.js";import{S as xs}from"./save-CLWMgMec.js";import{I as ms}from"./instagram-DhNR3dGD.js";import{L as hs}from"./linkedin-D6fbxKBt.js";import{P as be}from"./play-CWZLB0eu.js";import{P as De}from"./pause-DqGGQXZt.js";import{F as Oe}from"./folder-DcOn1CfD.js";import{A as Be}from"./archive-MO1vtFJL.js";import{S as ps}from"./square-CrNwRDxR.js";import{D as gs}from"./dollar-sign-C3-HhJal.js";/**
2 * @license lucide-react v0.475.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 us=[["path",{d:"M12 13v8",key:"1l5pq0"}],["path",{d:"M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242",key:"1pljnt"}],["path",{d:"m8 17 4-4 4 4",key:"1quai1"}]],bs=ce("CloudUpload",us);/**
7 * @license lucide-react v0.475.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 fs=[["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:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]],js=ce("FileWarning",fs);/**
12 * @license lucide-react v0.475.0 - ISC
13 *
14 * This source code is licensed under the ISC license.
15 * See the LICENSE file in the root directory of this source tree.
16 */const ws=[["circle",{cx:"18",cy:"18",r:"3",key:"1xkwt0"}],["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M6 21V9a9 9 0 0 0 9 9",key:"7kw0sc"}]],ge=ce("GitMerge",ws);/**
17 * @license lucide-react v0.475.0 - ISC
18 *
19 * This source code is licensed under the ISC license.
20 * See the LICENSE file in the root directory of this source tree.
21 */const Ns=[["line",{x1:"2",x2:"22",y1:"2",y2:"22",key:"a6p6uj"}],["path",{d:"M10.41 10.41a2 2 0 1 1-2.83-2.83",key:"1bzlo9"}],["line",{x1:"13.5",x2:"6",y1:"13.5",y2:"21",key:"1q0aeu"}],["line",{x1:"18",x2:"21",y1:"12",y2:"15",key:"5mozeu"}],["path",{d:"M3.59 3.59A1.99 1.99 0 0 0 3 5v14a2 2 0 0 0 2 2h14c.55 0 1.052-.22 1.41-.59",key:"mmje98"}],["path",{d:"M21 15V5a2 2 0 0 0-2-2H9",key:"43el77"}]],fe=ce("ImageOff",Ns);/**
22 * @license lucide-react v0.475.0 - ISC
23 *
24 * This source code is licensed under the ISC license.
25 * See the LICENSE file in the root directory of this source tree.
26 */const vs=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m14.5 9.5-5 5",key:"17q4r4"}],["path",{d:"m9.5 9.5 5 5",key:"18nt4w"}]],ys=ce("ShieldX",vs);function ks({producto:s,onSaved:a}){const[i,c]=o.useState(!1),[t,b]=o.useState(""),[g,j]=o.useState(!1),[y,C]=o.useState(!1),w=o.useMemo(()=>{const d=(s.descripcion||"").trim().length;if(d===0)return{min:500,max:1200,source:"merchant_default"};const u=Math.max(300,Math.round(d*.85)),f=Math.max(u+150,Math.round(d*1.15));return{min:u,max:f,source:"current"}},[s.descripcion]),N=o.useMemo(()=>{const d=(s.categoria||"").toLowerCase(),u=(s.canal||"").toLowerCase();let f=ee.coreB2B;return d.includes("corporativo")||u.includes("b2b")?f=ee.coreB2B:d.includes("escritorio")?f=ee.rrhh:d.includes("hogar")?f=ee.coreB2B:d.includes("entretenimiento")?f=ee.eventos:d.includes("carcasa")&&(f=ee.tecnica),[...f.slice(0,4),...ee.tecnica.slice(0,2)]},[s.categoria,s.canal]),_=async()=>{var d;c(!0),b("");try{const f=(s.material||"").toLowerCase().includes("trigo")?"fibra de trigo compostable (origen agrícola, biodegradable)":"plástico 100% reciclado post-consumo (origen Chile, economía circular)",h=`Eres copywriter senior SEO de PEYU Chile (peyuchile.cl), marca chilena de productos sostenibles. Vas a redactar la descripción comercial de un producto que será publicada en la ficha pública del sitio Y enviada al feed de Google Merchant Center, por lo que debe cumplir las políticas de Google Shopping.
27
28═══════════════════════════════════
29PRODUCTO
30═══════════════════════════════════
31- Nombre: ${s.nombre}
32- SKU: ${s.sku}
33- Categoría: ${s.categoria}
34- Material: ${f}
35- Canal de venta: ${s.canal}
36- Garantía: ${s.garantia_anios||10} años
37- Personalización láser UV gratis desde ${s.personalizacion_gratis_desde||10} unidades
38${s.area_laser_mm?`- Área de grabado láser: ${s.area_laser_mm} mm`:""}
39${s.precio_b2c?`- Precio referencial B2C: $${s.precio_b2c.toLocaleStr
39ing("es-CL")} CLP`:""}
40
41═══════════════════════════════════
42DESCRIPCIÓN ACTUAL (${(s.descripcion||"").trim().length} chars) — ÚSALA COMO BASE Y MEJÓRALA
43═══════════════════════════════════
44${((d=s.descripcion)==null?void 0:d.trim())||"(El producto no tiene descripción previa. Crea una desde cero respetando los requisitos.)"}
45
46═══════════════════════════════════
47LONGITUD OBJETIVO (CRÍTICO)
48═══════════════════════════════════
49La nueva descripción debe tener entre ${w.min} y ${w.max} caracteres ${w.source==="current"?"(mantenemos ±15% del largo actual para preservar el ritmo editorial del catálogo).":"(rango óptimo Google Merchant Center para fichas de producto)."} Cuenta los caracteres antes de devolver el texto.
50
51═══════════════════════════════════
52KEYWORDS PEYU A INTEGRAR (SEO)
53═══════════════════════════════════
54Integra naturalmente, sin keyword stuffing, AL MENOS 4 de las siguientes frases (puedes flexionarlas/conjugarlas):
55${N.map(m=>`• ${m}`).join(`
56`)}
57
58═══════════════════════════════════
59POLÍTICAS GOOGLE MERCHANT CENTER (OBLIGATORIO CUMPLIR)
60═══════════════════════════════════
61✓ DEBE: Describir SOLO el producto (qué es, de qué está hecho, cómo se usa, qué incluye, dimensiones si aplican).
62✓ DEBE: Tono profesional, oraciones completas, ortografía perfecta en español de Chile.
63✓ DEBE: Mencionar atributos verificables del producto (material, garantía, personalización).
64
65✗ NO incluyas: precios, ofertas, descuentos, "envío gratis", códigos de cupón.
66✗ NO incluyas: URLs, dominios, teléfonos, emails, redes sociales, CTAs ("compra ahora", "haz clic").
67✗ NO incluyas: emojis, símbolos decorativos, listas con bullets, markdown (**, #, -, *).
68✗ NO incluyas: claims absolutos prohibidos ("el mejor", "el único", "100% garantizado", "milagroso", "exclusivo").
69✗ NO incluyas: comparaciones con competidores ni menciones de otras marcas.
70✗ NO incluyas: MAYÚSCULAS sostenidas, signos repetidos (!!!, ???), capitalización ALL CAPS.
71✗ NO incluyas: información de stock, disponibilidad, plazos de entrega, métodos de pago.
72
73═══════════════════════════════════
74ESTRUCTURA RECOMENDADA
75═══════════════════════════════════
76Párrafo 1 — Qué es y de qué material: nombre del producto, función principal, material reciclado/compostable, fabricación en Chile.
77Párrafo 2 — Atributos y experiencia de uso: durabilidad, garantía, contexto de uso (escritorio/hogar/oficina), personalización láser UV disponible para empresas.
78Párrafo 3 — Propuesta sostenible y casos de uso B2B: economía circular, idoneidad para regalos corporativos, kits de bienvenida, gifting empresarial.
79
80Separa los párrafos con UNA línea en blanco. Texto plano. Sin títulos. Sin firma.
81
82═══════════════════════════════════
83DEVUELVE
84═══════════════════════════════════
85SOLO el texto plano de la descripción, listo para copiar-pegar en el feed de Merchant Center y en la ficha de peyuchile.cl. Nada más.`,x=await L.integrations.Core.InvokeLLM({prompt:h}),l=(typeof x=="string"?x:String(x)).trim();b(l)}catch{b("Error al generar contenido. Intenta nuevamente.")}finally{c(!1)}},$=async()=>{if(t){j(!0);try{await L.entities.Producto.update(s.id,{descripcion:t}),a==null||a(t)}finally{j(!1)}}},k=async()=>{await navigator.clipboard.writeText(t),C(!0),setTimeout(()=>C(!1),1500)},v=o.useMemo(()=>
85{if(!t)return null;const d=t.length,u=d>=w.min&&d<=w.max,f=/[\u{1F300}-\u{1FAFF}\u{2600}-\u{27BF}]/u.test(t),h=/(https?:\/\/|www\.)/i.test(t),x=/\+?56\s?9?\s?\d{4}\s?\d{4}/.test(t),l=/\$\s?\d|CLP|clp/.test(t),m=/\b[A-ZÁÉÍÓÚÑ]{6,}\b/.test(t),n=/(!{2,}|\?{2,})/.test(t),p=N.filter(A=>t.toLowerCase().includes(A.toLowerCase().split(" ").slice(0,2).join(" "))).length;return{chars:d,inRange:u,hasEmoji:f,hasUrl:h,hasPhone:x,hasPrice:l,hasAllCaps:m,hasBangs:n,kwHits:p,compliant:!f&&!h&&!x&&!l&&!m&&!n}},[t,w,N]);return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-poppins font-semibold text-white text-sm",children:"Descripción del producto"}),e.jsx("p",{className:"text-xs text-white/50 mt-0.5",children:"IA · Alineada al largo actual · Keywords PEYU · Google Merchant compliant"})]}),e.jsxs(I,{onClick:_,disabled:i,size:"sm",className:"gap-2 bg-gradient-to-r from-violet-500 to-fuchsia-600 hover:from-violet-600 hover:to-fuchsia-700 text-white",children:[i?e.jsx(R,{className:"w-4 h-4 animate-spin"}):e.jsx(q,{className:"w-4 h-4"}),s.descripcion?"Mejorar con IA":"Generar con IA"]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsx(ye,{icon:ss,label:"Largo objetivo",value:`${w.min}–${w.max} chars`,hint:w.source==="current"?`±15% del actual (${(s.descripcion||"").length})`:"Rango óptimo Merchant"}),e.jsx(ye,{icon:ds,label:"Keywords PEYU",value:`${N.length} frases`,hint:"Categoría + técnicas"}),e.jsx(ye,{icon:Ae,label:"Compliance",value:"Merchant",hint:"Sin claims, sin precios"})]}),s.descripcion&&!t&&e.jsxs("div",{className:"bg-white/5 border border-white/10 rounded-lg p-3",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("p",{className:"text-xs uppercase tracking-wider text-white/40",children:"Descripción actual"}),e.jsxs("span",{className:"text-[10px] font-mono text-white/40",children:[s.descripcion.length," chars"]})]}),e.jsx("p",{className:"text-sm text-white/80 whitespace-pre-wrap leading-relaxed",children:s.descripcion})]}),t&&e.jsxs("div",{className:"bg-violet-500/10 border border-violet-400/30 rounded-lg p-3 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-xs uppercase tracking-wider text-violet-300 font-bold",children:"Borrador IA"}),e.jsxs("button",{onClick:k,className:"text-xs text-white/60 hover:text-white flex items-center gap-1",children:[y?e.jsx(U,{className:"w-3 h-3"}):e.jsx(ue,{className:"w-3 h-3"}),y?"Copiado":"Copiar"]})]}),e.jsx("textarea",{value:t,onChange:d=>b(d.target.value),className:"w-full h-48 bg-black/30 border border-white/10 rounded-lg p-3 text-sm text-white/90 leading-relaxed resize-none"}),v&&e.jsxs("div",{className:"flex flex-wrap gap-1.5 text-[10px]",children:[e.jsx(X,{ok:v.inRange,label:`${v.chars} chars · objetivo ${w.min}–${w.max}`}),e.jsx(X,{ok:v.kwHits>=4,label:`${v.kwHits}/${N.length} keywords PEYU`}),e.jsx(X,{ok:!v.hasEmoji,label:"Sin emojis"}),e.jsx(X,{ok:!v.hasUrl,label:"Sin URLs"}),e.jsx(X,{ok:!v.hasPhone,label:"Sin teléfonos"}),e.jsx(X,{ok:!v.hasPrice,label:"Sin precios"}),e.jsx(X,{ok:!v.hasAllCaps,label:"Sin ALL CAPS"}),e.jsx(X,{ok:!v.hasBangs,label:"Sin signos repetidos"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(I,{onClick:$,disabled:g,size:"sm",className:"flex-1 bg-emerald-600 hover:bg-emerald-700 text-white gap-2",children:[g?e.jsx(R,{className:"w-4 h-4 animate-spin"}):e.jsx(U,{className:"w-4 h-4"}),"Guardar en producto"]}),e.jsx(I,{onClick:()=>b(""),variant:"outline",size:"sm",className:"bg-white/5 border-white/20 text-white hover:bg-white/10",children:"Descartar"})]})]})]})}function ye({icon:s,label:a,value:i,hint:c}){return e.jsxs("div",{className:"bg-white/5 border border-white/10 rounded-lg p-2.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] uppercase tracking-wider text-white/50 mb-1",children:[e.jsx(s,{className:"w-3 h-3"}),a]}),e.jsx("div",{className:"text-sm font-poppins font-bold text-white truncate",children:i}),e.jsx("div",{className:"text-[10px] text-white/40 truncate",children:c})]})}function X({ok:s,label:a}){return e.jsxs("span",{className:`px-2 py-0.5 rounded-full font-medium ${s?"bg-emerald-500/15 text-emerald-300 border border-emerald-400/30":"bg-rose-500/15 text-rose-300 border border-rose-400/30"}`,children:[s?"✓":"✗"," ",a]})}function Cs({producto:s,onSaved:a}){const[i,c]=o.useState(!1),[t,b]=o.useState({done:0,total:0}),[g,j]=o.useState("galeria"),[y,C]=o.useState(null),[w,N]=o.useState(!1),_=o.useRef(null),$=Array.isArray(s.galeria_urls)?s.galeria_urls:[],k=async d=>{const u=Array.from(d||[]).filter(x=>{var l;return(l=x.type)==null?void 0:l.startsWith("image/")});if(u.length===0){C("Selecciona al menos una imagen válida (JPG, PNG, WebP)");return}c(!0),C(null),b({done:0,total:u.length});const f=[];for(let x=0;x<u.length;x++)try{const l=await L.integrations.Core.UploadFile({file:u[x]});l!=null&&l.file_url&&f.push(l.file_url),b({done:x+1,total:u.length})}catch(l){console.error("Error subiendo",u[x].name,l)}if(f.length===0){C("No se pudo subir ninguna imagen"),c(!1);return}let h={};if(g==="principal"){const[x,...l]=f,m=[...l,...s.imagen_url?[s.imagen_url]:[],...$];h={imagen_url:x,galeria_urls:[...new Set(m)]}}else h={galeria_urls:[...new Set([...$,...f])]};await L.entities.Producto.update(s.id,h),a==null||a(h),c(!1),b({done:0,total:0}),_.current&&(_.current.value="")},v=d=>{d.preventDefault(),N(!1),k(d.dataTransfer.files)};return e.jsxs("div",{className:"bg-cyan-500/5 border border-cyan-400/20 rounded-lg p-3 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[e.jsxs("p",{className:"text-xs uppercase tracking-wider text-cyan-300 font-bold flex items-center gap-1.5",children:[e.jsx(Te,{className:"w-3.5 h-3.5"}),"Subir desde tu equipo"]}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx("button",{onClick:()=>j("galeria"),className:`px-2.5 py-1 rounded text-[11px] font-medium transition-all ${g==="galeria"?"bg-cyan-500 text-white":"bg-white/5 text-white/60 hover:bg-white/10"}`,children:"A galería"}),e.jsx("button",{onClick:()=>j("principal"),className:`px-2.5 py-1 rounded text-[11px] font-medium transition-all ${g==="principal"?"bg-yellow-500 text-white":"bg-white/5 text-white/60 hover:bg-white/10"}`,children:"Como principal"})]})]}),e.jsxs("label",{onDragOver:d=>{d.preventDefault(),N(!0)},onDragLeave:()=>N(!1),onDrop:v,className:`block border-2 border-dashed rounded-lg p-4 text-center cursor-pointer transition-all ${w?"border-cyan-400 bg-cyan-500/10":"border-white/15 bg-white/5 hover:bg-white/10 hover:border-white/25"}`,children:[e.jsx("input",{ref:_,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:d=>k(d.target.files),disabled:i}),i?e.jsxs("div",{className:"flex items-center justify-center gap-2 text-sm text-cyan-200",children:[e.jsx(R,{className:"w-4 h-4 animate-spin"}),"Subiendo ",t.done,"/",t.total,"…"]}):e.jsxs("div",{className:"space-y-1",children:[e.jsx(Te,{className:"w-6 h-6 mx-auto text-white/40"}),e.jsxs("p",{className:"text-xs text-white/70",children:[e.jsx("span",{className:"text-cyan-300 font-medium",children:"Click para elegir"})," o arrastra imágenes aquí"]}),e.jsx("p",{className:"text-[10px] text-white/40",children:"JPG, PNG, WebP · selección múltiple"})]})]}),y&&e.jsxs("div",{className:"flex items-start gap-2 text-xs text-rose-300 bg-rose-500/10 border border-rose-400/30 rounded px-2 py-1.5",children:[e.jsx(G,{className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0"}),e.jsx("span",{className:"flex-1",children:y}),e.jsx("button",{onClick:()=>C(null),children:e.jsx(Q,{className:"w-3 h-3"})})]}),!i&&t.total>0&&t.done===t.total&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-emerald-300",children:[e.jsx(U,{className:"w-3.5 h-3.5"}),t.total," ",t.total===1?"imagen subida":"imágenes subidas"," correctamente"]})]})}const se=[{id:"lifestyle",label:"Lifestyle",prompt:"in a lifestyle scene, soft natural daylight, scandinavian wooden desk surface, plants softly blurred in the background, shallow depth of field"},{id:"studio",label:"Estudio limpio",prompt:"on a seamless white studio background, soft single-source studio lighting, subtle drop shadow, professional product catalog photography"},{id:"corporate",label:"Corporativo",prompt:"in a corporate office environment, modern minimalist desk, neutral business setting, warm professional lighting"}
85,{id:"eco",label:"Eco / Natural",prompt:"on a natural eco surface (wood, linen, recycled paper), surrounded by leaves and natural fibers, earthy tones, sustainability mood"}];function _s(s=""){const a=s.toLowerCase();return a.includes("reciclado")?"made of 100% recycled plastic with a subtle marbled/speckled texture (visible color flecks from recycled HDPE/PP plastic), matte finish, slightly irregular natural surface that proves it is reclaimed material — NOT shiny mass-produced plastic":a.includes("trigo")||a.includes("compostable")?"made of compostable wheat fiber bioplastic, soft beige/cream color with a natural fibrous texture, matte organic finish, slight grain visible — looks earthy and biodegradable":`made of ${s}`}function Ss(s="",a=280){if(!s)return"";const i=s.replace(/<[^>]+>/g," ").replace(/\s+/g," ").trim();return i.length<=a?i:i.slice(0,a).replace(/\s\S*$/,"")+"…"}function Je(s=""){const a=s.match(/(?:pack|set|kit|combo|promo(?:ci[oó]n)?|caja|grupo)\s*(?:de\s+)?(\d{1,2})/i)||s.match(/\b(\d{1,2})\s*(?:unidades?|u\.?|pcs|piezas?)\b/i)||s.match(/\b(\d{1,2})\s*x\s+/i);if(!a)return null;const i=parseInt(a[1],10);return i>=2&&i<=20?i:null}function Ze(s=""){const a=s.toLowerCase(),i=["cachos","cacho","posavasos","posacachos","maceteros","macetero","sujetadores","sujetador","paletas","paleta","pocillos","pocillo","llaveros","llavero","soportes","soporte"];for(const c of i)if(a.includes(c))return c;return"unidades"}function Ie(s,a,i,c=""){const t=Je(s.nombre),b=Ze(s.nombre),g=t?`
86
87CRITICAL — EXACT QUANTITY REQUIRED:
88- This product is a "${s.nombre}". You MUST show EXACTLY ${t} ${b} in the image. Not fewer, not more.
89- Count them visually before finishing. The image MUST contain ${t} individual ${b} clearly visible.
90- Arrange them neatly so all ${t} are clearly countable.`:"",j=c&&c.trim()?`
91
92ADDITIONAL ADMIN INSTRUCTION:
93${c.trim()}`:"",y=Ss(s.descripcion),C=_s(s.material),w=`
94PRODUCT BRIEF (use this to understand what to show):
95- Name: ${s.nombre}
96- Category: ${s.categoria}
97- Material: ${C}
98- Channel: ${s.canal||"B2C + B2B"}${y?`
99- Real product description (from catalog): "${y}"`:""}`,N=`
100
101ABSOLUTE PROHIBITIONS (Google Shopping policy — STRICTLY ENFORCED):
102- ❌ NO brand names, NO company names, NO text of any kind anywhere in the image.
103- ❌ NO logos: not on the product, not in the background, not on packaging, not on props.
104- ❌ NO watermarks, NO captions, NO labels with readable text.
105- ❌ NO third-party trademarks (Apple, Nike, Coca-Cola, IKEA, Starbucks, etc.) visible on any object, screen, book cover, mug, sign, or surface.
106- ❌ NO competitor products or branded competitor packaging.
107- ❌ NO PEYU logo either — this image must be 100% brand-neutral.
108- ✅ The product itself must appear completely UNBRANDED — plain surface, no engraved/printed brand marks.
109- ✅ If props appear (laptop, phone, mug, notebook), they must be GENERIC and brandless.
110- ✅ All text-like surfaces (book spines, packaging, screens, signs) must be blank or blurred.`;return i?`Take the EXACT product shown in the reference image(s) and place it in a new scene.${w}
111
112CRITICAL — DO NOT CHANGE THE PRODUCT:
113- The product must look IDENTICAL to the reference: same shape, exact same color, same material texture, same proportions, same details and finishings.
114- Do not redesign, restyle, recolor, or alter the product in any way.
115- IMPORTANT: If the reference shows any logo or brand mark on the product, REMOVE it cleanly in the output. The output product must be unbranded.
116- Keep the product as the clear hero of the composition, centered and in sharp focus.${g}
117
118ONLY CHANGE THE BACKGROUND, SETTING AND LIGHTING:
119${a.prompt}.${j}${N}
120
121Photography style: premium e-commerce product photography, high resolution, sharp focus on the product, natural realistic shadows. Looks like a real DSLR product photo, not 3D render.`:`Create a realistic, premium product photograph for an e-commerce listing of a sustainable Chilean product.${w}
122
123CRITICAL — DESIGN THE PRODUCT FROM THE BRIEF:
124- Render the product as accurately as possible based on the name, category and description above.
125- Make sure the MATERIAL is visually unmistakable: ${C}. This is the most important visual detail — the viewer must instantly recognize the product is made of this material.
126- If the description mentions specific features (size, color, finish, parts), include them faithfully.
127- Single hero product, well composed, sharp focus, realistic proportions.${g}
128
129SCENE / BACKGROUND:
130${a.prompt}.${j}${N}
131
132Photography style: sustainability-forward, natural, warm and premium. High resolution, realistic shadows. Looks like a real DSLR product photo, not 3D render.`}function Es({producto:s,onSaved:a}){const[i,c]=o.useState("lifestyle"),[t,b]=o.useState(!1),[g,j]=o.useState(""),[y,C]=o.useState(!1),[w,N]=o.useState(!1),[_,$]=o.useState(!1),[k,v]=o.useState(!1),[d,u]=o.useState(""),[f,h]=o.use
132State(!1),[x,l]=o.useState({done:0,total:0}),[m,n]=o.useState([]),[p,A]=o.useState(!1),r=Array.isArray(s.galeria_urls)?s.galeria_urls:[],E=Je(s.nombre),T=Ze(s.nombre),V=async()=>{var S;b(!0),j("");try{const P=se.find(we=>we.id===i),O=[s.imagen_url,...r].filter(Boolean).slice(0,4),B=O.length>0,ie={prompt:Ie(s,P,B,d)};B&&(ie.existing_image_urls=O);const Y=await L.integrations.Core.GenerateImage(ie),F=(Y==null?void 0:Y.url)||((S=Y==null?void 0:Y.data)==null?void 0:S.url);F&&j(F)}catch(P){console.error("Error generando imagen",P)}finally{b(!1)}},H=async()=>{h(!0),n([]),l({done:0,total:se.length});const S=[s.imagen_url,...r].filter(Boolean).slice(0,4),P=S.length>0,O=async te=>{var ie;try{const Y={prompt:Ie(s,te,P,d)};P&&(Y.existing_image_urls=S);const F=await L.integrations.Core.GenerateImage(Y),we=(F==null?void 0:F.url)||((ie=F==null?void 0:F.data)==null?void 0:ie.url);return l(Me=>({...Me,done:Me.done+1})),{id:te.id,label:te.label,url:we}}catch(Y){return l(F=>({...F,done:F.done+1})),{id:te.id,label:te.label,error:Y.message}}},B=await Promise.all(se.map(O));n(B),h(!1)},W=async()=>{const S=m.filter(P=>P.url).map(P=>P.url);if(S.length!==0){A(!0);try{const P=[...r,...S];await L.entities.Producto.update(s.id,{galeria_urls:P}),a==null||a({galeria_urls:P}),n([])}finally{A(!1)}}},z=async S=>{if(!S)return;const P=[...r,S];await L.entities.Producto.update(s.id,{galeria_urls:P}),a==null||a({galeria_urls:P}),n(O=>O.filter(B=>B.url!==S))},D=async S=>{if(S){A(!0);try{const P=m.filter(B=>B.url&&B.url!==S).map(B=>B.url),O=[...s.imagen_url?[s.imagen_url]:[],...r,...P];await L.entities.Producto.update(s.id,{imagen_url:S,galeria_urls:O}),a==null||a({imagen_url:S,galeria_urls:O}),n([])}finally{A(!1)}}},M=async()=>{if(g){C(!0);try{const S=[...r,g];await L.entities.Producto.update(s.id,{galeria_urls:S}),a==null||a({galeria_urls:S}),j("")}finally{C(!1)}}},Z=async S=>{N(!0);try{const P=r.filter(B=>B!==S),O=s.imagen_url?[s.imagen_url,...P]:P;await L.entities.Producto.update(s.id,{imagen_url:S,galeria_urls:O}),a==null||a({imagen_url:S,galeria_urls:O})}finally{N(!1)}},de=async()=>{$(!0);try{await L.entities.Producto.update(s.id,{imagen_url:""}),a==null||a({imagen_url:""}),v(!1)}finally{$(!1)}},je=async S=>{const P=r.filter(O=>O!==S);await L.entities.Producto.update(s.id,{galeria_urls:P}),a==null||a({galeria_urls:P})};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-poppins font-semibold text-white text-sm",children:"Imágenes del producto"}),e.jsx("p",{className:"text-xs text-white/50 mt-0.5",children:"La IA preserva el producto exacto y solo cambia el entorno · Las nuevas imágenes se guardan en galería sin reemplazar la principal"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"bg-white/5 border border-white/10 rounded-lg p-2",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2 px-1",children:[e.jsxs("p",{className:"text-xs uppercase tracking-wider text-white/50 flex items-center gap-1",children:[e.jsx(oe,{className:"w-3 h-3 fill-yellow-400 text-yellow-400"}),"Principal"]}),s.imagen_url&&e.jsxs("button",{onClick:()=>v(!0),className:"text-[10px] text-rose-300 hover:text-rose-200 flex items-center gap-1",title:"Eliminar imagen principal",children:[e.jsx(Ne,{className:"w-3 h-3"})," Eliminar"]})]}),s.imagen_url?e.jsx("img",{src:s.imagen_url,alt:s.nombre,className:"w-full aspect-square object-cover rounded-md"}):e.jsxs("div",{className:"w-full aspect-square rounded-md bg-white/5 flex flex-col items-center justify-center gap-1 text-white/30",children:[e.jsx(ae,{className:"w-8 h-8"}),e.jsx("p",{className:"text-[10px]",children:"Sin imagen principal"})]})]}),e.jsxs("div",{className:"bg-violet-500/10 border border-violet-400/30 rounded-lg p-2",children:[e.jsx("p",{className:"text-xs uppercase tracking-wider text-violet-300 mb-2 px-1 font-bold",children:"Vista previa IA"}),t?e.jsxs("div",{className:"w-full aspect-square rounded-md bg-black/30 flex flex-col items-center justify-center gap-2",children:[e.jsx(R,{className:"w-6 h-6 text-violet-300 animate-spin"}),e.jsx("p",{className:"text-xs text-white/60",children:"Generando…"})]}):g?e.jsx("img",{src:g,alt:"generada",className:"w-full aspect-square object-cover rounded-md"}):e.jsxs("div",{className:"w-full aspect-square rounded-md bg-white/5 flex flex-col items-center justify-center gap-1 text-violet-300/40",children:[e.jsx(ne,{className:"w-8 h-8"}),e.jsx("p",{className:"text-[10px]",children:"Aún no generada"})]})]})]}),k&&e.jsxs("div",{className:"bg-rose-500/10 border border-rose-400/40 rounded-lg p-3 flex items-start gap-3",children:[e.jsx(K,{className:"w-5 h-5 text-rose-300 flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm text-rose-200 font-semibold",children:"¿Eliminar la imagen principal?"}),e.jsx("p",{className:"text-xs text-white/60 mt-0.5",children:"El producto quedará sin imagen principal hasta que promuevas una de la galería o 
132subas otra."}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsxs(I,{onClick:de,disabled:_,size:"sm",className:"bg-rose-600 hover:bg-rose-700 text-white gap-2",children:[_?e.jsx(R,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(Ne,{className:"w-3.5 h-3.5"}),"Sí, eliminar"]}),e.jsx(I,{onClick:()=>v(!1),size:"sm",variant:"outline",className:"bg-white/5 border-white/20 text-white hover:bg-white/10",children:"Cancelar"})]})]})]}),e.jsx(Cs,{producto:s,onSaved:a}),e.jsxs("div",{className:"bg-violet-500/5 border border-violet-400/20 rounded-lg p-3 space-y-1.5",children:[e.jsxs("p",{className:"text-xs font-semibold text-violet-200 flex items-center gap-1.5",children:[e.jsx(ne,{className:"w-3.5 h-3.5"}),s.imagen_url||r.length>0?"Modo Restyle · preserva el producto real y cambia el entorno":"Modo Creativo · sin imagen base, genera desde el título y descripción"]}),e.jsxs("ul",{className:"text-[11px] text-white/60 space-y-0.5 pl-5 list-disc",children:[e.jsxs("li",{children:["Título: ",e.jsx("span",{className:"text-white/80",children:s.nombre})]}),e.jsxs("li",{children:["Material: ",e.jsx("span",{className:"text-white/80",children:s.material})," · Categoría: ",e.jsx("span",{className:"text-white/80",children:s.categoria})]}),e.jsxs("li",{children:["Descripción del catálogo:"," ",s.descripcion?e.jsx("span",{className:"text-emerald-300",children:"✓ se usará para guiar la imagen"}):e.jsx("span",{className:"text-amber-300",children:'⚠ vacía — generá una en la pestaña "Descripción IA" para mejores resultados'})]})]})]}),E&&e.jsxs("div",{className:"bg-emerald-500/10 border border-emerald-400/30 rounded-lg p-3 flex items-start gap-2.5",children:[e.jsx(q,{className:"w-4 h-4 text-emerald-300 flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"flex-1 text-xs",children:[e.jsxs("p",{className:"text-emerald-200 font-semibold",children:['Detectamos "',e.jsxs("strong",{children:["Pack ",E," ",T]}),'" en el título.']}),e.jsxs("p",{className:"text-emerald-300/80 mt-0.5",children:["La IA va a generar la imagen con ",e.jsxs("strong",{children:[E," ",T]})," visibles, no menos."]})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"text-xs uppercase tracking-wider text-white/40 mb-1.5 block",children:["Instrucción extra para la IA ",e.jsx("span",{className:"text-white/30 normal-case",children:"(opcional)"})]}),e.jsx("textarea",{value:d,onChange:S=>u(S.target.value),placeholder:'Ej: "mostrar los 6 cachos en círculo con una mano sosteniendo uno", "tomas cenitales", "incluir empaque"…',className:"w-full bg-white/5 border border-white/15 rounded-lg px-3 py-2 text-xs text-white placeholder:text-white/30 focus:border-violet-400/50 focus:outline-none resize-none",rows:2})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs uppercase tracking-wider text-white/40 mb-2",children:"Estilo del entorno (IA)"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:se.map(S=>e.jsx("button",{onClick:()=>c(S.id),className:`px-3 py-1.5 rounded-lg text-xs font-medium transition-all ${i===S.id?"bg-violet-500 text-white border border-violet-400":"bg-white/5 text-white/70 border border-white/10 hover:bg-white/10"}`,children:S.label},S.id))})]}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsxs(I,{onClick:V,disabled:t||f,size:"sm",className:"flex-1 min-w-[160px] gap-2 bg-gradient-to-r from-violet-500 to-fuchsia-600 hover:from-violet-600 hover:to-fuchsia-700 text-white",children:[t?e.jsx(R,{className:"w-4 h-4 animate-spin"}):e.jsx(q,{className:"w-4 h-4"}),g?"Regenerar estilo actual":"Generar 1 imagen"]}),e.jsx(I,{onClick:H,disabled:t||f,size:"sm",className:"flex-1 min-w-[160px] gap-2 bg-gradient-to-r from-cyan-500 to-emerald-600 hover:from-cyan-600 hover:to-emerald-700 text-white",children:f?e.jsxs(e.Fragment,{children:[e.jsx(R,{className:"w-4 h-4 animate-spin"})," ",x.done,"/",x.total,"…"]}):e.jsxs(e.Fragment,{children:[e.jsx(ne,{className:"w-4 h-4"})," Generar 4 estilos"]})}),g&&e.jsxs(e.Fragment,{children:[e.jsxs(I,{onClick:M,disabled:y,size:"sm",className:"bg-emerald-600 hover:bg-emerald-700 text-white gap-2",children:[y?e.jsx(R,{className:"w-4 h-4 animate-spin"}):e.jsx(ve,{className:"w-4 h-4"}),"Añadir a galería"]}),e.jsxs(I,{onClick:()=>j(""),size:"sm",variant:"outline",className:"bg-white/5 border-white/20 text-white hover:bg-white/10 gap-2",children:[e.jsx(Q,{className:"w-4 h-4"})," Descartar"]})]})]}),(f||m.length>0)&&e.jsxs("div",{className:"bg-cyan-500/5 border border-cyan-400/20 rounded-xl p-3 space-y-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 flex-wrap",children:[e.jsxs("p",{className:"text-xs font-semibold text-cyan-200 flex items-center gap-1.5",children:[e.jsx(ne,{className:"w-3.5 h-3.5"}),"Los 4 estilos (sin marcas — apto Google Shopping)"]}),m.filter(S=>S.url).length>0&&!f&&e.jsxs(I,{onClick:W,disabled:p,size:"sm",className:"bg-emerald-600 hover:bg-emerald-700 text-white gap-1.5 h-7 text-xs",children:[p?e.jsx(R,{className:"w-3 h-3 animate-spin"}):e.jsx(ve,{className:"w-3 h-3"}),"Guardar todas en galería (",m.filter(S=>S.url).length,")"]})]}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-2",children:se.map(S=>{const P=m.find(B=>B.id===S.id),O=f&&!P;return e.jsxs("div",{className:"bg-black/20 border border-white/10 rounded-lg overflow-hidden",children:[e.jsxs("div",{className:"aspect-square relative bg-white/5 flex items-center justify-center",children:[O&&e.jsx(R,{className:"w-5 h-5 text-cyan-300 animate-spin"}),(P==null?void 0:P.url)&&e.jsxs(e.Fragment,{children:[e.jsx("img",{src:P.url,alt:S.label,className:"w-full h-full object-cover"}),e.jsxs("div",{className:"absolute inset-x-1.5 bottom-1.5 flex gap-1",children:[e.jsxs("button",{onClick:()=>D(P.url),disabled:p,className:"flex-1 bg-yellow-500 hover:bg-yellow-400 text-slate-900 text-[10px] px-2 py-1 rounded-md font-bold flex items-center justify-center gap-1 shadow-lg",title:"Elegir como principal · las otras 3 van a galería",children:[e.jsx(oe,{className:"w-3 h-3 fill-current"})," Elegir"]}),e.jsx("button",{onClick:()=>z(P.url),disabled:p,className:"bg-emerald-600 hover:bg-emerald-500 text-white text-[10px] px-2 py-1 rounded-md font-medium flex items-center gap-1",title:"Solo añadir a galería",children:e.jsx(ve,{className:"w-3 h-3"})})]})]}),(P==null?void 0:P.error)&&e.jsxs("div",{className:"text-[10px] text-rose-300 px-2 text-center",children:[e.jsx(K,{className:"w-4 h-4 mx-auto mb-1"}),"Falló"]})]}),e.jsx("div",{className:"px-2 py-1.5 text-[11px] text-white/70 font-medium text-center border-t border-white/5",children:S.label})]},S.id)})})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("p",{className:"text-xs uppercase tracking-wider text-white/50 font-semibold",children:["Galería · ",r.length," ",r.length===1?"imagen":"imágenes"]}),r.length>0&&e.jsx("p",{className:"text-[10px] text-white/40",children:"Click en ⭐ para promover · 🗑 para eliminar"})]}),r.length===0?e.jsx("div",{className:"bg-white/5 border border-dashed border-white/10 rounded-lg p-4 text-center text-xs text-white/40",children:"Aún no hay imágenes alternativas. Genera una con IA y guárdala en la galería."}):e.jsx("div",{className:"grid grid-cols-3 sm:grid-cols-4 gap-2",children:r.map((S,P)=>e.jsxs("div",{className:"relative group bg-white/5 border border-white/10 rounded-lg overflow-hidden",children:[e.jsx("img",{src:S,alt:"",className:"w-full aspect-square object-cover"}),e.jsxs("div",{className:"absolute inset-0 bg-black/0 group-hover:bg-black/60 transition-all flex items-center justify-center gap-1.5 opacity-0 group-hover:opacity-100",children:[e.jsx("button",{onClick:()=>Z(S),disabled:w,title:"Promover a principal",className:"w-7 h-7 rounded-md bg-yellow-500 hover:bg-yellow-400 text-white flex items-center justify-center",children:w?e.jsx(R,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(oe,{className:"w-3.5 h-3.5 fill-current"})}),e.jsx("button",{onClick:()=>je(S),title:"Eliminar de galería",className:"w-7 h-7 rounded-md bg-rose-600 hover:bg-rose-500 text-white flex items-center justify-center",children:e.jsx(Ne,{className:"w-3.5 h-3.5"})})]})]},`${S}-${P}`))})]})]})}const ke=[{key:"precio_b2c",label:"Precio B2C (CLP)",type:"number"},{key:"precio_base_b2b",label:"Precio base B2B (CLP)",type:"number"},{key:"precio_50_199",label:"50-199 u",type:"number"},{key:"precio_200_499",label:"200-499 u",type:"number"},{key:"precio_500_mas",label:"500+ u",type:"number"},{key:"stock_actual",label:"Stock actual (u)",type:"number"},{key:"lead_time_sin_personal",label:"Lead sin pers. (días)",type:"number"},{key:"lead_time_con_personal",label:"Lead con pers. (días)",type:"number"},{key:"garantia_anios",label:"Garantía (años)",type:"number"},{key:"area_laser_mm",label:"Área láser (mm)",type:"text"}];function $s({producto:s,onSaved:a}){const[i,c]=o.useState(s),[t,b]=o.useState(!1),[g,j]=o.useState(!1);o.useEffect(()=>{c(s)},[s.id]);const y=ke.some(w=>(i[w.key]??"")!==(s[w.key]??""))||!!i._activoChanged,C=async()=>{b(!0);try{const w={};ke.forEach(N=>{const _=i[N.key];w[N.key]=N.type==="number"?_===""||_==null?0:Number(_):_??""}),w.activo=i.activo!==!1,await L.entities.Producto.update(s.id,w),a==null||a(w),j(!0),setTimeout(()=>j(!1),1500)}finally{b(!1)}};return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-poppins font-semibold text-white text-sm",children:"Datos del producto"}),e.jsx("p",{className:"text-xs text-white/50 mt-0.5",children:"Edición rápida de precios, stock y producción"})]}),e.jsxs("label",{className:"flex items-center gap-2 text-xs text-white/70 cursor-pointer select-none",children:[e.jsx("input",{type:"checkbox",checked:i.activo!==!1,onChange:w=>c({...i,activo:w.target.checked,_activoChanged:!0}),className:"rounded accent-emerald-500"}),"Activo en catálogo"]})]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:ke.map(w=>e.jsxs("div",{className:"min-w-0",children:[e.jsx("label",{className:"block text-[11px] text-white/50 mb-1 truncate",title:w.label,children:w.label}),e.jsx(Ve,{type:w.type,value:i[w.key]??"",onChange:N=>c({...i,[w.key]:(w.type==="number",N.target.value)}),className:"h-8 bg-white/5 border-white/10 text-white text-sm"})]},w.key))}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(I,{onClick:C,disabled:!y||t,size:"sm",className:`gap-2 ${g?"bg-emerald-600":"bg-violet-600 hover:bg-violet-700"} text-white disabled:opacity-40`,children:[t?e.jsx(R,{className:"w-4 h-4 animate-spin"}):g?e.jsx(U,{className:"w-4 h-4"}):e.jsx(xs,{className:"w-4 h-4"}),g?"Guardado":"Guardar cambios"]})})]})}function Ps({producto:s,onSaved:a}){const[i,c]=o.useState(!1),[t,b]=o.useState(""),[g,j]=o.useState(!1),y=s.imagen_promo_url,C=s.imagen_promo_generada_at,w=async()=>{c(!0),b("");try{const $=await L.functions.invoke("generateProductPromoImage",{producto_id:s.id}),k=$==null?void 0:$.data;if(!(k!=null&&k.success)||!k.imagen_promo_url)throw new Error((k==null?void 0:k.error)||"No se pudo generar la 
132imagen");a==null||a({imagen_promo_url:k.imagen_promo_url,imagen_promo_generada_at:new Date().toISOString()})}catch($){b($.message)}finally{c(!1)}},N=async()=>{y&&(await navigator.clipboard.writeText(y),j(!0),setTimeout(()=>j(!1),2e3))},_=Is(s);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"font-poppins font-semibold text-white text-sm flex items-center gap-1.5",children:[e.jsx(We,{className:"w-4 h-4 text-pink-400"}),"Imagen Promo · Redes sociales"]}),e.jsx("p",{className:"text-xs text-white/50 mt-0.5",children:"Cuadrada (1:1) con paleta PEYU y espacio para tu copy. Lista para Instagram, LinkedIn y feed."})]}),!s.imagen_url&&e.jsxs("div",{className:"bg-amber-500/10 border border-amber-400/30 rounded-lg p-3 flex items-start gap-2",children:[e.jsx(K,{className:"w-4 h-4 text-amber-300 flex-shrink-0 mt-0.5"}),e.jsx("p",{className:"text-xs text-amber-200",children:'Carga primero una imagen principal del producto en la pestaña "Imagen IA". La promo usa esa imagen como referencia visual.'})]}),e.jsxs("div",{className:"bg-gradient-to-br from-pink-500/10 to-violet-500/10 border border-pink-400/20 rounded-xl p-3",children:[e.jsx("div",{className:"aspect-square rounded-lg overflow-hidden bg-black/30 flex items-center justify-center",children:i?e.jsxs("div",{className:"flex flex-col items-center gap-2 text-white/60",children:[e.jsx(R,{className:"w-8 h-8 animate-spin text-pink-400"}),e.jsx("p",{className:"text-xs",children:"Generando imagen promocional…"}),e.jsx("p",{className:"text-[10px] text-white/40",children:"Esto toma 5-10 segundos"})]}):y?e.jsx("img",{src:y,alt:`Promo ${s.nombre}`,className:"w-full h-full object-cover"}):e.jsxs("div",{className:"flex flex-col items-center gap-2 text-white/30",children:[e.jsx(ae,{className:"w-10 h-10"}),e.jsx("p",{className:"text-xs",children:"Aún no se ha generado"})]})}),C&&!i&&e.jsxs("p",{className:"text-[10px] text-white/40 text-center mt-2",children:["Generada ",new Date(C).toLocaleString("es-CL")]})]}),t&&e.jsx("div",{className:"bg-rose-500/10 border border-rose-400/30 rounded-lg p-2.5 text-xs text-rose-200",children:t}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsxs(I,{onClick:w,disabled:i||!s.imagen_url,className:"flex-1 min-w-[180px] gap-2 bg-gradient-to-r from-pink-500 to-violet-600 hover:from-pink-600 hover:to-violet-700 text-white",children:[i?e.jsx(R,{className:"w-4 h-4 animate-spin"}):y?e.jsx(Xe,{className:"w-4 h-4"}):e.jsx(q,{className:"w-4 h-4"}),y?"Regenerar imagen":"Generar imagen promo"]}),y&&e.jsxs(e.Fragment,{children:[e.jsxs(I,{onClick:N,variant:"outline",className:"bg-white/5 border-white/20 text-white hover:bg-white/10 gap-2",children:[g?e.jsx(U,{className:"w-4 h-4 text-emerald-400"}):e.jsx(ue,{className:"w-4 h-4"}),g?"Copiado":"Copiar URL"]}),e.jsxs("a",{href:y,download:`peyu-promo-${s.sku||s.id}.png`,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 px-3 py-2 rounded-md text-sm font-medium bg-white/5 border border-white/20 text-white hover:bg-white/10 transition-colors",children:[e.jsx(as,{className:"w-4 h-4"})," Descargar"]})]})]}),y&&e.jsxs("div",{className:"bg-white/5 border border-white/10 rounded-xl p-3 space-y-2",children:[e.jsxs("p",{className:"text-xs uppercase tracking-wider text-white/50 font-semibold flex items-center gap-1.5",children:[e.jsx(ms,{className:"w-3 h-3"}),e.jsx(hs,{className:"w-3 h-3"}),"Copy sugerido para redes"]}),_.map(($,k)=>e.jsx(As,{...$},k))]})]})}function Is(s){var i,c,t;const a=(i=s.material)!=null&&i.includes("Trigo")?"fibra de trigo compostable":"plástico 100% reciclado";return[{red:"Instagram",texto:`🌱 Te presentamos ${s.nombre}
133
134Hecho en Chile con ${a} ♻️
135${((c=s.descripcion)==null?void 0:c.slice(0,100))||"Diseño consciente, gifting con propósito."}
136
137👉 peyuchile.cl
138
139#PeyuChile #RegalosCorporativos #EconomíaCircular #HechoEnChile`},{red:"LinkedIn",texto:`Nuevo en el catálogo PEYU: ${s.nombre} 🇨🇱
140
141Fabricado con ${a}, ${((t=s.descripcion)==null?void 0:t.slice(0,140))||"una pieza que combina diseño chileno con compromiso ambiental."}
142
143Gifting corporativo con impacto medible. Personalización láser des
143de 10 unidades.`}]}function As({red:s,texto:a}){const[i,c]=o.useState(!1),t=async()=>{await navigator.clipboard.writeText(a),c(!0),setTimeout(()=>c(!1),2e3)};return e.jsxs("div",{className:"bg-black/20 rounded-lg p-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-[10px] font-bold text-white/70 uppercase tracking-wider",children:s}),e.jsx("button",{onClick:t,className:"text-[10px] text-white/50 hover:text-white flex items-center gap-1",children:i?e.jsxs(e.Fragment,{children:[e.jsx(U,{className:"w-3 h-3 text-emerald-400"})," Copiado"]}):e.jsxs(e.Fragment,{children:[e.jsx(ue,{className:"w-3 h-3"})," Copiar"]})})]}),e.jsx("p",{className:"text-xs text-white/80 whitespace-pre-line leading-relaxed",children:a})]})}function Ls({onComplete:s}){const[a,i]=o.useState(null),[c,t]=o.useState(!1),[b,g]=o.useState(!1),[j,y]=o.useState({migrated:0,errors:0,total:0}),[C,w]=o.useState([]);o.useEffect(()=>{(async()=>{var u;const d=await L.functions.invoke("migrateProductImagesToBase44",{dryRun:!0});(u=d.data)!=null&&u.ok&&(i(d.data),y(f=>({...f,total:d.data.totalPendientes})))})()},[]);const N=(d,u="info")=>{w(f=>[{msg:d,type:u,at:new Date},...f].slice(0,20))},_=async()=>{var m,n;const d=await L.functions.invoke("migrateProductImagesToBase44",{batchSize:5});if(!((m=d.data)!=null&&m.ok))return N(`Error en lote: ${((n=d.data)==null?void 0:n.error)||"desconocido"}`,"error"),{done:!0,error:!0};const{migrated:u,errors:f,remaining:h,done:x,details:l}=d.data;return y(p=>({migrated:p.migrated+u,errors:p.errors+((f==null?void 0:f.length)||0),total:p.total})),l!=null&&l.length&&l.forEach(p=>N(`✓ ${p.sku} · ${p.nombre.slice(0,40)}`,"success")),f!=null&&f.length&&f.forEach(p=>N(`✗ ${p.sku}: ${p.error}`,"error")),{done:x,remaining:h}},$=async()=>{t(!0),g(!1),N("Iniciando migración por lotes…","info");let d=0;for(;d<50&&!b;){if((await _()).done){N("🎉 Migración completa","success"),s&&s();break}d+=1,await new Promise(f=>setTimeout(f,800))}t(!1)},k=()=>{g(!0),t(!1),N("⏸ Pausado por el usuario","info")};if(!a)return e.jsxs("div",{className:"bg-white/5 border border-white/10 rounded-xl p-3 flex items-center gap-2 text-xs text-white/60",children:[e.jsx(R,{className:"w-3.5 h-3.5 animate-spin"}),"Calculando productos pendientes…"]});if(a.totalPendientes===0)return e.jsxs("div",{className:"bg-emerald-500/10 border border-emerald-400/30 rounded-xl p-3 flex items-center gap-2 text-xs text-emerald-300",children:[e.jsx(J,{className:"w-4 h-4"}),"Todas las imágenes ya están en Base44 CDN ✨"]});const v=j.total>0?Math.round(j.migrated/j.total*100):0;return e.jsxs("div",{className:"bg-gradient-to-br from-amber-500/10 to-orange-500/10 border border-amber-400/30 rounded-xl p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 flex-wrap",children:[e.jsxs("div",{className:"flex items-start gap-2 min-w-0",children:[e.jsx(bs,{className:"w-5 h-5 text-amber-300 flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"text-sm font-semibold text-white",children:"Migrar imágenes WordPress → Base44 CDN"}),e.jsxs("p",{className:"text-xs text-white/60 mt-0.5",children:[e.jsx("strong",{className:"text-amber-300",children:j.total-j.migrated})," productos"," ","aún dependen de ",e.jsx("code",{className:"px-1 bg-white/10 rounded",children:"i0.wp.com"}),". Migrar las desconecta totalmente de WordPress."]})]})]}),c?e.jsxs(I,{onClick:k,size:"sm",variant:"outline",className:"gap-1.5 flex-shrink-0",children:[e.jsx(De,{className:"w-3.5 h-3.5"}),"Pausar"]}):e.jsxs(I,{onClick:$,size:"sm",className:"bg-amber-600 hover:bg-amber-700 text-white gap-1.5 flex-shrink-0",children:[e.jsx(be,{className:"w-3.5 h-3.5"}),j.migrated>0?"Reanudar":"Iniciar migración"]})]}),(c||j.migrated>0)&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex justify-between text-[11px] text-white/60",children:[e.jsxs("span",{children:[j.migrated," / ",j.total," migradas · ",v,"%"]}),j.errors>0&&e.jsxs("span",{className:"text-rose-300",children:[j.errors," errores"]})]}),e.jsx("div",{className:"h-1.5 bg-white/10 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-gradient-to-r from-amber-400 to-emerald-400 transition-all duration-300",style:{width:`${v}%`}})})]}),C.length>0&&e.jsx("div",{className:"bg-black/30 rounded-lg p-2 max-h-32 overflow-y-auto peyu-scrollbar-light text-[10px] font-mono space-y-0.5",children:C.map((d,u)=>e.jsx("div",{className:d.type==="success"?"text-emerald-300":d.type==="error"?"text-rose-300":"text-white/60",children:d.msg},u))}),e.jsxs("p",{className:"text-[10px] text-white/40 leading-relaxed",children:["El proceso descarga cada imagen, la sube a Base44, y actualiza el producto. La URL antigua queda preservada en ",e.jsx("code",{children:"galeria_urls"})," como respaldo. Procesa 5 por lote · ~3 segundos por producto."]})]})}function Rs({onComplete:s}){const[a,i]=o.useState("idle"),[c,t]=o.useState(null),[b,g]=o.useState(null),[j,y]=o.useState([]),[C,w]=o.useState(new Set),[N,_]=o.useState({processed:0,total:0,results:[]}
143),[$,k]=o.useState(!1),[v,d]=o.useState(null),[u,f]=o.useState(!0),h=async()=>{i("previewing"),d(null);try{const n=(await L.functions.invoke("drivePreviewMapping",{folderId:"1qXw3mA_KcimLqC5pH5sZr1Ib7gm9mBDR"})).data;if(!(n!=null&&n.ok))throw new Error((n==null?void 0:n.error)||"Error en preview");t(n.preview),g(n.stats),y(n.raw_mapping),i("reviewing")}catch(m){d(m.message),i("idle")}},x=m=>{const n=new Set(C);n.has(m)?n.delete(m):n.add(m),w(n)},l=async()=>{const m=j.filter(r=>!r.skip&&!C.has(r.carpeta)).map(r=>({...r}));if(m.length===0){d("No hay carpetas seleccionadas para migrar");return}i("migrating"),k(!1),d(null);let n=0,p=0;const A=[];for(;;){if($){await new Promise(r=>setTimeout(r,1e3));continue}try{const E=(await L.functions.invoke("driveMigrateProductImages",{mapping:m,cursor:n,batchSize:5,replacePrincipal:u})).data;if(!(E!=null&&E.ok))throw new Error((E==null?void 0:E.error)||"Error en migración");if(p=E.total,n=E.processed,E.resultados&&A.push(...E.resultados),_({processed:n,total:p,results:A}),E.done)break;await new Promise(T=>setTimeout(T,600))}catch(r){d(r.message);break}}i("done"),s&&s()};if(a==="idle")return e.jsxs("div",{className:"bg-gradient-to-br from-violet-500/10 to-fuchsia-500/10 border border-violet-400/30 rounded-2xl p-4 lg:p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 flex-wrap",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(q,{className:"w-5 h-5 text-violet-300"}),e.jsx("h3",{className:"text-base lg:text-lg font-poppins font-bold text-white",children:"Restaurar imágenes desde Google Drive"})]}),e.jsx("p",{className:"text-white/70 text-xs lg:text-sm leading-relaxed",children:"Recupera las 121 imágenes perdidas desde tu Drive. Hago match inteligente carpeta↔producto, descargo y subo todo al CDN de Base44 con un click."})]}),e.jsxs(I,{onClick:h,className:"gap-2 bg-violet-600 hover:bg-violet-700 text-white",children:[e.jsx(Oe,{className:"w-4 h-4"}),"Analizar carpetas"]})]}),v&&e.jsxs("div",{className:"mt-3 px-3 py-2 rounded-lg bg-rose-500/10 border border-rose-400/30 text-rose-300 text-xs flex items-start gap-2",children:[e.jsx(G,{className:"w-4 h-4 mt-0.5 flex-shrink-0"}),v]})]});if(a==="previewing")return e.jsxs("div",{className:"bg-violet-500/10 border border-violet-400/30 rounded-2xl p-5 flex items-center gap-3",children:[e.jsx(R,{className:"w-5 h-5 text-violet-300 animate-spin"}),e.jsx("span",{className:"text-white/80 text-sm",children:"Analizando estructura del Drive y haciendo match con tu catálogo…"})]});if(a==="reviewing"){const m=c.filter(r=>!r.skip),n=c.filter(r=>r.skip),p=m.filter(r=>!C.has(r.carpeta)),A=p.reduce((r,E)=>r+E.cantidad_imagenes,0);return e.jsxs("div",{className:"bg-white/5 border border-white/10 rounded-2xl overflow-hidden",children:[e.jsx("div",{className:"p-4 border-b border-white/10 bg-white/[0.02]",children:e.jsxs("div",{className:"flex items-start justify-between gap-3 flex-wrap",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-base lg:text-lg font-poppins font-bold text-white flex items-center gap-2",children:[e.jsx(q,{className:"w-5 h-5 text-violet-300"}),"Revisa el matching propuesto"]}),e.jsxs("p",{className:"text-white/60 text-xs mt-1",children:[m.length," carpetas matcheadas → ",p.reduce((r,E)=>r+E.productos.length,0)," productos · ",A," imágenes"]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("label",{className:"flex items-center gap-2 text-xs text-white/70 px-3 py-1.5 bg-white/5 rounded-lg border border-white/10 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:u,onChange:r=>f(r.target.checked)}),"Reemplazar imagen principal"]}),e.jsx(I,{onClick:()=>i("idle"),variant:"outline",size:"sm",className:"bg-white/5 border-white/10 text-white hover:bg-white/10",children:"Cancelar"}),e.jsxs(I,{onClick:l,disabled:p.length===0,className:"gap-2 bg-emerald-600 hover:bg-emerald-700 text-white",children:[e.jsx(pe,{className:"w-4 h-4"}),"Migrar ",A," imágenes"]})]})]})}),e.jsxs("div",{className:"max-h-[480px] overflow-y-auto peyu-scrollbar-light",children:[m.map(r=>{const E=C.has(r.carpeta);return e.jsx("div",{className:`px-4 py-3 border-b border-white/5 ${E?"opacity-40":""}`,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("button",{onClick:()=>
143x(r.carpeta),className:"mt-1 flex-shrink-0",children:E?e.jsx("div",{className:"w-5 h-5 rounded-md border-2 border-white/30"}):e.jsx("div",{className:"w-5 h-5 rounded-md bg-emerald-500 flex items-center justify-center",children:e.jsx(U,{className:"w-3.5 h-3.5 text-white"})})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(Oe,{className:"w-4 h-4 text-violet-300 flex-shrink-0"}),e.jsx("span",{className:"font-mono text-sm text-white truncate",children:r.carpeta}),e.jsxs("span",{className:"text-[11px] px-2 py-0.5 rounded-full bg-violet-500/20 text-violet-200 flex items-center gap-1",children:[e.jsx(ae,{className:"w-3 h-3"}),r.cantidad_imagenes]})]}),e.jsx("div",{className:"mt-2 space-y-1 pl-6",children:r.productos.map(T=>e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx(pe,{className:"w-3 h-3 text-white/30 flex-shrink-0"}),e.jsx("span",{className:"text-white/80 truncate flex-1",children:T.nombre}),e.jsx("span",{className:"font-mono text-white/40 text-[10px]",children:T.sku}),e.jsxs("span",{className:`text-[10px] px-1.5 py-0.5 rounded ${T.confianza>=.8?"bg-emerald-500/20 text-emerald-300":T.confianza>=.5?"bg-amber-500/20 text-amber-300":"bg-rose-500/20 text-rose-300"}`,children:[Math.round(T.confianza*100),"%"]})]},T.producto_id))})]})]})},r.carpeta)}),n.length>0&&e.jsxs("div",{className:"px-4 py-2.5 bg-white/[0.02] border-t border-white/5",children:[e.jsxs("p",{className:"text-[11px] text-white/40 uppercase tracking-wide mb-1.5",children:["Saltadas (",n.length,") · ",n.reduce((r,E)=>r+E.cantidad_imagenes,0)," imágenes"]}),e.jsx("div",{className:"space-y-0.5",children:n.map(r=>e.jsxs("div",{className:"flex items-center gap-2 text-xs text-white/40",children:[e.jsx(Q,{className:"w-3 h-3"}),e.jsx("span",{className:"font-mono truncate",children:r.carpeta}),e.jsx("span",{children:"·"}),e.jsxs("span",{children:[r.cantidad_imagenes," imgs"]}),e.jsx("span",{children:"·"}),e.jsx("span",{className:"italic",children:r.razon_skip})]},r.carpeta))})]})]})]})}if(a==="migrating"||a==="done"){const m=N.total>0?Math.round(N.processed/N.total*100):0,n=N.results.filter(r=>r.ok).length,p=N.results.filter(r=>!r.ok).length,A=N.results.filter(r=>r.ok).reduce((r,E)=>r+(E.imagenes_migradas||0),0);return e.jsxs("div",{className:"bg-white/5 border border-white/10 rounded-2xl p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-4 flex-wrap",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-base lg:text-lg font-poppins font-bold text-white flex items-center gap-2",children:[a==="done"?e.jsx(U,{className:"w-5 h-5 text-emerald-400"}):e.jsx(R,{className:"w-5 h-5 text-violet-300 animate-spin"}),a==="done"?"Migración completada":"Migrando imágenes…"]}),e.jsxs("p",{className:"text-white/60 text-xs mt-1",children:[N.processed," / ",N.total," productos · ",A," imágenes subidas al CDN"]})]}),a==="migrating"&&e.jsx(I,{onClick:()=>k(r=>!r),variant:"outline",size:"sm",className:"gap-1.5 bg-white/5 border-white/10 text-white hover:bg-white/10",children:$?e.jsxs(e.Fragment,{children:[e.jsx(be,{className:"w-3.5 h-3.5"}),"Reanudar"]}):e.jsxs(e.Fragment,{children:[e.jsx(De,{className:"w-3.5 h-3.5"}),"Pausar"]})}),a==="done"&&e.jsx(I,{onClick:()=>{i("idle"),t(null),_({processed:0,total:0,results:[]})},className:"bg-white/10 hover:bg-white/15 text-white",children:"Cerrar"})]}),e.jsx("div",{className:"h-2 bg-white/10 rounded-full overflow-hidden mb-3",children:e.jsx("div",{className:`h-full transition-all duration-500 ${a==="done"?"bg-emerald-500":"bg-violet-500"}`,style:{width:`${m}%`}})}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 mb-3",children:[e.jsx(Ce,{label:"Éxitos",value:n,color:"text-emerald-300"}),e.jsx(Ce,{label:"Errores",value:p,color:"text-rose-300"}),e.jsx(Ce,{label:"Imágenes",value:A,color:"text-cyan-300"})]}),e.jsxs("div",{className:"bg-black/30 border border-white/10 rounded-lg max-h-48 overflow-y-auto peyu-scrollbar-light p-2 space-y-0.5 font-mono text-[11px]",children:[N.results.slice(-15).reverse().map((r,E)=>{var T;return e.jsxs("div",{className:`flex items-center gap-2 ${r.ok?"text-emerald-300":"text-rose-300"}`,children:[r.ok?e.jsx(U,{className:"w-3 h-3"}):e.jsx(Q,{className:"w-3 h-3"}),e.jsxs("span",{className:"truncate flex-1",children:[r.carpeta||((T=r.producto_id)==null?void 0:T.slice(-8))," ",r.ok&&`· ${r.imagenes_migradas} imgs`,!r.ok&&` · ${r.error}`]})]},E)}),N.results.length===0&&e.jsx("div",{className:"text-white/40 text-center py-4",children:"Esperando primer lote…"})]}),v&&e.jsxs("div",{className:"mt-3 px-3 py-2 rounded-lg bg-rose-500/10 border border-rose-400/30 text-rose-300 text-xs flex items-start gap-2",children:[e.jsx(G,{className:"w-4 h-4 mt-0.5 flex-shrink-0"}),v]})]})}return null}function Ce({label:s,value:a,color:i}){return e.jsxs("div",{className:"bg-white/5 border border-white/10 rounded-lg px-3 py-2",children:[e.jsx("div",{className:"text-[10px] text-white/50 uppercase tracking-wide",children:s}),e.jsx("div",{className:`text-lg font-poppins font-bold ${i}`,children:a})]})}function Ds({onComplete:s}){const[a,i]=o.useState("idle"),[c,t]=o.useState({processed:0,total:0,results:[]}),[b,g]=o.useState(!1),[j,y]=o.useState(null),[C,w]=o.useState(!0),[N,_]=o.useState(!1),$=async(h=!1)=>{i(h?"preview":"migrating"),g(!1),y(null),t({processed:0,total:0,results:[]});let x=0,l=0;const m=[];for(;;){if(b){await new Promise(n=>setTimeout(n,1e3));continue}try{const p=(await L.functions.invoke("waybackImportProductImages",{cursor:x,batchSize:h?20:3,replacePrincipal:C,onlyMissing:N,previewOnly:h})).data;if(!(p!=null&&p.ok))throw new Error((p==null?void 0:p.error)||"Error");
143if(l=p.total,x=p.processed,p.resultados&&m.push(...p.resultados),t({processed:x,total:l,results:m}),p.done)break;await new Promise(A=>setTimeout(A,h?200:800))}catch(n){y(n.message);break}}i("done"),!h&&s&&s()};if(a==="idle")return e.jsxs("div",{className:"bg-gradient-to-br from-amber-500/10 to-orange-500/10 border border-amber-400/30 rounded-2xl p-4 lg:p-5",children:[e.jsx("div",{className:"flex items-start justify-between gap-3 flex-wrap",children:e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(Be,{className:"w-5 h-5 text-amber-300"}),e.jsx("h3",{className:"text-base lg:text-lg font-poppins font-bold text-white",children:"Recuperar imágenes desde Wayback Machine"})]}),e.jsx("p",{className:"text-white/70 text-xs lg:text-sm leading-relaxed",children:"Busca cada producto en archive.org (snapshots de la web WordPress original) y migra todas las imágenes archivadas al CDN. Ideal para recuperar las galerías secundarias que se perdieron."})]})}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2 items-center",children:[e.jsxs("label",{className:"flex items-center gap-2 text-xs text-white/70 px-3 py-1.5 bg-white/5 rounded-lg border border-white/10 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:N,onChange:h=>_(h.target.checked)}),"Solo productos con < 2 imágenes"]}),e.jsxs("label",{className:"flex items-center gap-2 text-xs text-white/70 px-3 py-1.5 bg-white/5 rounded-lg border border-white/10 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:C,onChange:h=>w(h.target.checked)}),"Reemplazar imagen principal"]}),e.jsxs(I,{onClick:()=>$(!0),variant:"outline",className:"gap-2 bg-white/5 border-white/10 text-white hover:bg-white/10",children:[e.jsx(ts,{className:"w-4 h-4"}),"Solo previsualizar matches"]}),e.jsxs(I,{onClick:()=>$(!1),className:"gap-2 bg-amber-600 hover:bg-amber-700 text-white",children:[e.jsx(Be,{className:"w-4 h-4"}),"Recuperar imágenes"]})]}),j&&e.jsxs("div",{className:"mt-3 px-3 py-2 rounded-lg bg-rose-500/10 border border-rose-400/30 text-rose-300 text-xs flex items-start gap-2",children:[e.jsx(G,{className:"w-4 h-4 mt-0.5 flex-shrink-0"}),j]})]});const k=c.total>0?Math.round(c.processed/c.total*100):0,v=c.results.filter(h=>h.ok).length,d=c.results.filter(h=>!h.ok).length,u=c.results.filter(h=>h.ok&&!h.preview).reduce((h,x)=>h+(x.subidas||0),0),f=c.results.some(h=>h.preview);return e.jsxs("div",{className:"bg-white/5 border border-white/10 rounded-2xl p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-4 flex-wrap",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-base lg:text-lg font-poppins font-bold text-white flex items-center gap-2",children:[a==="done"?e.jsx(U,{className:"w-5 h-5 text-emerald-400"}):e.jsx(R,{className:"w-5 h-5 text-amber-300 animate-spin"}),f?a==="done"?"Preview completado":"Buscando matches en Wayback…":a==="done"?"Recuperación completada":"Recuperando imágenes…"]}),e.jsxs("p",{className:"text-white/60 text-xs mt-1",children:[c.processed," / ",c.total," productos",!f&&` · ${u} imágenes subidas al CDN`]})]}),a==="migrating"&&e.jsx(I,{onClick:()=>g(h=>!h),variant:"outline",size:"sm",className:"gap-1.5 bg-white/5 border-white/10 text-white hover:bg-white/10",children:b?e.jsxs(e.Fragment,{children:[e.jsx(be,{className:"w-3.5 h-3.5"}),"Reanudar"]}):e.jsxs(e.Fragment,{children:[e.jsx(De,{className:"w-3.5 h-3.5"}),"Pausar"]})}),a==="done"&&e.jsx(I,{onClick:()=>{i("idle"),t({processed:0,total:0,results:[]})},className:"bg-white/10 hover:bg-white/15 text-white",children:"Cerrar"})]}),e.jsx("div",{className:"h-2 bg-white/10 rounded-full overflow-hidden mb-3",children:e.jsx("div",{className:`h-full transition-all duration-500 ${a==="done"?"bg-emerald-500":"bg-amber-500"}`,style:{width:`${k}%`}})}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 mb-3",children:[e.jsx(_e,{label:"Con match",value:v,color:"text-emerald-300"}),e.jsx(_e,{label:"Sin match",value:d,color:"text-rose-300"}),e.jsx(_e,{label:f?"Productos":"Imágenes",value:f?v:u,color:"text-cyan-300"})]}),e.jsxs("div",{className:"bg-black/30 border border-white/10 rounded-lg max-h-72 overflow-y-auto peyu-scrollbar-light p-2 space-y-0.5 font-mono text-[11px]",children:[c.results.slice(-30).reverse().map((h,x)=>e.jsxs("div",{className:`flex items-center gap-2 ${h.ok?"text-emerald-300":"text-rose-300"}`,children:[h.ok?e.jsx(U,{className:"w-3 h-3 flex-shrink-0"}):e.jsx(Q,{className:"w-3 h-3 flex-shrink-0"}),e.jsxs("span",{className:"truncate flex-1",children:[e.jsxs("span",{className:"text-white/40",children:["[",h.sku,"]"]})," ",h.nombre,h.ok&&h.slug_match&&e.jsxs("span",{className:"text-amber-300/70",children:[" → /",h.slug_match]}),h.ok&&!h.preview&&h.subidas>0&&e.jsxs("span",{className:"text-cyan-300",children:[" · ",h.subidas," imgs"]}),!h.ok&&e.jsxs("span",{className:"text-rose-300/70",children:[" · ",h.error]})]}),h.ok&&typeof h.score=="number"&&e.jsxs("span",{className:"text-[10px] px-1 py-0.5 rounded bg-white/5 text-white/60",children:[Math.round(h.score*100),"%"]})]},x)),c.results.length===0&&e.jsx("div",{className:"text-white/40 text-center py-4",children:"Esperando primer lote…"})]}),j&&e.jsxs("div",{className:"mt-3 px-3 py-2 rounded-lg bg-rose-500/10 border border-rose-400/30 text-rose-300 text-xs flex items-start gap-2",children:[e.jsx(G,{className:"w-4 h-4 mt-0.5 flex-shrink-0"}),j]})]})}function _e({label:s,value:a,color:i}){return e.jsxs("div",{className:"bg-white/5 border border-white/10 rounded-lg px-3 py-2",children:[e.jsx("div",{className:"text-[10px] text-white/50 uppercase tracking-wide",children:s}),e.jsx("div",{className:`text-lg font-poppins font-bold ${i}`,children:a})]})}const Ge={blocked:{label:"Bloqueado",icon:ys,ring:"ring-rose-500/40",text:"text-rose-200",bg:"bg-rose-500/15",border:"border-rose-500/40"},warning:{label:"Revisar",icon:rs,ring:"ring-amber-500/40",text:"text-amber-200",bg:"bg-amber-500/15",border:"border-amber-500/40"},compliant:{label:"Aprobado",icon:Ae,ring:"ring-emerald-500/40",text:"text-emerald-200",bg:"bg-emerald-500/15",border:"border-emerald-500/40"}
143,error:{label:"Error",icon:K,ring:"ring-white/20",text:"text-white/60",bg:"bg-white/5",border:"border-white/15"}};function es(s){return s==null?"text-white/40":s>=90?"text-emerald-300":s>=70?"text-amber-300":"text-rose-300"}function Ms({onProductClick:s}){const[a,i]=o.useState(!1),[c,t]=o.useState(!1),[b,g]=o.useState(null),[j,y]=o.useState("all"),[C,w]=o.useState(50),[N,_]=o.useState(null),$=async()=>{t(!0),_(null);try{const u=await L.functions.invoke("auditGoogleShoppingCompliance",{limit:C});g((u==null?void 0:u.data)||null),a||i(!0)}catch(u){_(u.message)}t(!1)},k=(b==null?void 0:b.results)||[],v=b==null?void 0:b.stats,d=j==="all"?k:k.filter(u=>u.veredicto===j);return e.jsxs("div",{className:"bg-gradient-to-br from-indigo-500/10 via-violet-500/5 to-fuchsia-500/10 border border-indigo-400/20 rounded-2xl overflow-hidden",children:[e.jsxs("div",{className:"px-4 py-3 flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-indigo-500/20 border border-indigo-400/30 flex items-center justify-center flex-shrink-0",children:e.jsx(Ae,{className:"w-4.5 h-4.5 text-indigo-300"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-sm font-semibold text-white flex items-center gap-1.5",children:["Auditoría Google Shopping (IA)",(v==null?void 0:v.blocked)>0&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded-full bg-rose-500/20 text-rose-200 border border-rose-500/40",children:[e.jsx(K,{className:"w-3 h-3"})," ",v.blocked," urgentes"]})]}),e.jsx("p",{className:"text-[11px] text-white/55 truncate",children:"IA escanea cada imagen y detecta marcas, texto, descentrado → score 0-100 + veredicto Merchant Center."})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("label",{className:"text-[11px] text-white/60 flex items-center gap-1.5",children:["Cuántos",e.jsx("input",{type:"number",min:5,max:200,value:C,onChange:u=>w(Number(u.target.value)||50),className:"w-16 h-7 rounded bg-white/10 border border-white/15 px-2 text-white text-xs"})]}),e.jsxs(I,{onClick:$,disabled:c,size:"sm",className:"gap-1.5 bg-indigo-600 hover:bg-indigo-700 text-white h-8",children:[c?e.jsx(R,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(q,{className:"w-3.5 h-3.5"}),b?"Re-auditar":"Auditar ahora"]}),b&&e.jsx(I,{size:"sm",variant:"outline",onClick:()=>i(u=>!u),className:"bg-white/5 border-white/15 text-white hover:bg-white/10 h-8 px-2",children:a?e.jsx(Le,{className:"w-3.5 h-3.5"}):e.jsx(Re,{className:"w-3.5 h-3.5"})})]})]}),N&&e.jsx("div",{className:"mx-4 mb-3 px-3 py-2 rounded-lg bg-rose-500/10 border border-rose-400/30 text-rose-200 text-xs",children:N}),b&&a&&e.jsxs("div",{className:"border-t border-white/10 px-4 py-3 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-5 gap-2",children:[e.jsx(le,{label:"Score promedio",value:`${v.avg_score}/100`,accent:es(v.avg_score)}),e.jsx(le,{label:"Bloqueados",value:v.blocked,accent:"text-rose-300"}),e.jsx(le,{label:"A revisar",value:v.warning,accent:"text-amber-300"}),e.jsx(le,{label:"Aprobados",value:v.compliant,accent:"text-emerald-300"}),e.jsx(le,{label:"Con marca/logo",value:v.con_marca,accent:"text-fuchsia-300"})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:["all","blocked","warning","compliant"].map(u=>e.jsx("button",{onClick:()=>y(u),className:`text-[11px] px-2.5 py-1 rounded-full border transition ${j===u?"bg-indigo-500/25 border-indigo-400/60 text-indigo-50":"bg-white/5 border-white/10 text-white/65 hover:bg-white/10"}`,children:u==="all"?`Todos · ${k.length}`:u==="blocked"?`Bloqueados · ${v.blocked}`:u==="warning"?`Revisar · ${v.warning}`:`Aprobados · ${v.compliant}`},u))}),e.jsx("div",{className:"space-y-1.5 max-h-[420px] overflow-y-auto peyu-scrollbar-light pr-1",children:d.length===0?e.jsx("div",{className:"text-center py-8 text-white/45 text-xs",children:"Sin resultados en este filtro."}):d.map(u=>e.jsx(Ts,{row:u,onClick:()=>s==null?void 0:s(u.producto_id)},u.producto_id))})]})]})}function le({label:s,value:a,accent:i="text-white"}){return e.jsxs("div",{className:"bg-white/5 border border-white/10 rounded-lg px-2.5 py-1.5",children:[e.jsx("p",{className:"text-[10px] text-white/50",children:s}),e.jsx("p",{className:`text-base font-poppins font-bold ${i}`,children:a})]})}function Ts({row:s,onClick:a}){var b;const i=Ge[s.veredicto]||Ge.error,c=i.icon,t=s.veredicto==="blocked";return e.jsxs("div",{className:`rounded-lg border ${i.border} ${i.bg} px-2.5 py-2 flex items-start gap-2.5`,children:[e.jsx("div",{className:`w-12 h-12 rounded-md bg-black/30 border ${t?"ring-2 ring-rose-500/60":""} overflow-hidden flex-shrink-0 flex items-center justify-center`,children:s.imagen_url?e.jsx("img",{src:s.imagen_url,alt:s.nombre,className:"w-full h-full object-cover",onError:g=>{g.currentTarget.style.display="none"}}):e.jsx(ae,{className:"w-4 h-4 text-white/30"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsxs("span",{className:`inline-flex items-center gap-1 text-[10px] uppercase font-bold px-1.5 py-0.5 rounded border ${i.border} ${i.text} ${i.bg}`,children:[t&&e.jsx(K,{className:"w-2.5 h-2.5"}),e.jsx(c,{className:"w-2.5 h-2.5"})," ",i.label]}),s.score!=null&&e.jsxs("span",{className:`text-[11px] font-mono font-bold ${es(s.score)}`,children:[s.score,"/100"]}),e.jsx("span",{className:"text-[10px] text-white/40 font-mono",children:s.sku})]}),e.jsx("p",{className:"text-xs font-medium text-white mt-0.5 truncate",children:s.nombre}),((b=s.problemas)==null?void 0:b.length)>0&&e.jsx("ul",{className:"mt-1 space-y-0.5",children:s.problemas.slice(0,3).map((g,j)=>e.jsxs("li",{className:"text-[10.5px] text-white/65 leading-snug",children:[e.jsx("span",{className:i.text,children:"›"})," ",g]},j))}),s.recomendacion&&e.jsxs("p",{className:"text-[10.5px] text-indigo-200/80 mt-1 italic leading-snug",children:["💡 ",s.recomendacion]})]}),e.jsxs("button",{onClick:a,className:"flex-shrink-0 text-[11px] px-2 py-1 rounded-md bg-white/10 hover:bg-white/15 text-white border border-white/15 flex items-center gap-1 self-center",children:[e.jsx(Qe,{className:"w-3 h-3"})," Abrir"]})]})}const Fe=[{id:"sin_imagen",label:"Sin imagen",desc:"Productos activos que no tienen imagen principal",filter:s=>s.activo!==!1&&!s.imagen_url},{id:"activos",label:"Solo activos",desc:"Todos los productos publicados",filter:s=>s.activo!==!1},{id:"todos",label:"Todo el catálogo",desc:"Activos + inactivos (¡usá con cuidado!)",filter:()=>!0}],zs=[{id:"galeria",label:"Solo galería",icon:is,desc:"Añade la imagen a galería sin tocar la principal (seguro)"},{id:"principal",label:"Reemplazar principal",icon:oe,desc:"Si el producto no tiene principal, la nueva pasa a principal; si tenía, la antigua va a galería"}],Ue=3;function Os({productos:s=[],onComplete:a}){const[i,c]=o.useState(!1),[t,b]=o.useState("sin_imagen"),[g,j]=o.useState("galeria"),[y,C]=o.useState("lifestyle"),[w,N]=o.useState(20),[_,$]=o.useState(!1),[k,v]=o.useState([]),[d,u]=o.useState({ok:0,fail:0,done:0,total:0}),f=o.useRef(!1),h=o.useRef(null),x=o.useMemo(()=>{const r=Fe.find(T=>T.id===t);return s.filter(r.filter).slice(0,Math.max(1,w))},[s,t,w]),l=o.useMemo(()=>{const r=new Set(x.map(E=>
143E.categoria).filter(Boolean));return Array.from(r)},[x]);o.useEffect(()=>{h.current&&(h.current.scrollTop=h.current.scrollHeight)},[k.length]);const m=async r=>{var de;const E=se.find(je=>je.id===y),T=Array.isArray(r.galeria_urls)?r.galeria_urls:[],V=[r.imagen_url,...T].filter(Boolean).slice(0,4),H=V.length>0,z={prompt:Ie(r,E,H,"")};H&&(z.existing_image_urls=V);const D=await L.integrations.Core.GenerateImage(z),M=(D==null?void 0:D.url)||((de=D==null?void 0:D.data)==null?void 0:de.url);if(!M)throw new Error("Sin URL devuelta por la IA");const Z={};return g==="principal"&&!r.imagen_url?Z.imagen_url=M:g==="principal"&&r.imagen_url?(Z.imagen_url=M,Z.galeria_urls=[r.imagen_url,...T]):Z.galeria_urls=[...T,M],await L.entities.Producto.update(r.id,Z),M},n=async()=>{f.current=!1,$(!0),v([]),u({ok:0,fail:0,done:0,total:x.length});let r=0;const E=async()=>{for(;;){if(f.current)return;const V=r++;if(V>=x.length)return;const H=x[V];v(W=>[...W,{sku:H.sku,nombre:H.nombre,status:"running"}]);try{const W=await m(H);v(z=>z.map((D,M)=>(M===z.length-(x.length-V),D))),v(z=>{const D=[...z];for(let M=D.length-1;M>=0;M--)if(D[M].sku===H.sku&&D[M].status==="running"){D[M]={...D[M],status:"done",url:W};break}return D}),u(z=>({...z,ok:z.ok+1,done:z.done+1}))}catch(W){v(z=>{const D=[...z];for(let M=D.length-1;M>=0;M--)if(D[M].sku===H.sku&&D[M].status==="running"){D[M]={...D[M],status:"fail",error:W.message};break}return D}),u(z=>({...z,fail:z.fail+1,done:z.done+1}))}}},T=Array.from({length:Ue},()=>E());await Promise.all(T),$(!1),a&&a()},p=()=>{f.current=!0},A=s.filter(r=>r.activo!==!1&&!r.imagen_url).length;return e.jsxs("div",{className:"bg-gradient-to-br from-fuchsia-500/10 via-violet-500/10 to-cyan-500/10 border border-fuchsia-400/30 rounded-2xl overflow-hidden",children:[e.jsxs("button",{onClick:()=>c(r=>!r),className:"w-full px-4 py-3 flex items-center justify-between gap-3 hover:bg-white/5 transition",children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-fuchsia-500/20 border border-fuchsia-400/30 flex items-center justify-center flex-shrink-0",children:e.jsx(ne,{className:"w-4 h-4 text-fuchsia-300"})}),e.jsxs("div",{className:"text-left min-w-0",children:[e.jsxs("p",{className:"text-sm font-semibold text-white flex items-center gap-1.5",children:["Generación masiva de imágenes IA",A>0&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded-full bg-amber-500/20 text-amber-200 border border-amber-500/40",children:[e.jsx(fe,{className:"w-3 h-3"})," ",A," sin imagen"]})]}),e.jsx("p",{className:"text-[11px] text-white/55 truncate",children:"Procesa muchos productos a la vez · Razona título, cantidad, material y descripción · Sin marcas (Google Shopping)"})]})]}),i?e.jsx(Le,{className:"w-4 h-4 text-white/50"}):e.jsx(Re,{className:"w-4 h-4 text-white/50"})]}),i&&e.jsxs("div",{className:"border-t border-white/10 px-4 py-4 space-y-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] uppercase tracking-wider text-white/50 mb-2",children:"1 · Qué productos"}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-2",children:Fe.map(r=>{const E=s.filter(r.filter).length;return e.jsxs("button",{onClick:()=>b(r.id),disabled:_,className:`text-left p-2.5 rounded-lg border transition ${t===r.id?"bg-fuchsia-500/15 border-fuchsia-400/50":"bg-white/5 border-white/10 hover:bg-white/10"}`,children:[e.jsxs("p",{className:"text-xs font-semibold text-white flex items-center gap-1.5",children:[r.label,e.jsx("span",{className:"text-[10px] font-mono text-white/50",children:E})]}),e.jsx("p",{className:"text-[10.5px] text-white/55 mt-0.5 leading-snug",children:r.desc})]},r.id)})})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] uppercase tracking-wider text-white/50 mb-2",children:"2 · Dónde guardar"}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:zs.map(r=>{const E=r.icon;return e.jsxs("button",{onClick:()=>j(r.id),disabled:_,className:`text-left p-2.5 rounded-lg border transition ${g===r.id?"bg-violet-500/15 border-violet-400/50":"bg-white/5 border-white/10 hover:bg-white/10"}`,children:[e.jsxs("p",{className:"text-xs font-semibold text-white flex items-center gap-1.5",children:[e.jsx(E,{className:"w-3.5 h-3.5"})," ",r.label]}),e.jsx("p",{className:"text-[10.5px] text-white/55 mt-0.5 leading-snug",children:r.desc})]},r.id)})})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] uppercase tracking-wider text-white/50 mb-2",children:"3 · Estilo"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:se.map(r=>e.jsx("button",{onClick:()=>C(r.id),disabled:_,className:`text-[11px] px-2.5 py-1 rounded-full border transition ${y===r.id?"bg-cyan-500/20 border-cyan-400/60 text-cyan-50":"bg-white/5 border-white/10 text-white/65 hover:bg-white/10"}`,children:r.label},r.id))})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] uppercase tracking-wider text-white/50 mb-2",children:"4 · Cuántos máx."}),e.jsx("input",{type:"number",min:1,max:200,disabled:_,value:w,onChange:r=>N(Number(r.target.value)||20),className:"w-full h-9 rounded-lg bg-white/10 border border-white/15 px-3 text-white text-sm focus:border-fuchsia-400/50 outline-none"}),e.jsxs("p",{className:"text-[10px] text-white/45 mt-1",children:["Se procesan en lotes de ",Ue," en paralelo"]})]})]}),e.jsxs("div",{className:"bg-black/30 border border-white/10 rounded-lg p-3 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[e.jsxs("p",{className:"text-xs font-semibold text-white flex items-center gap-1.5",children:[e.jsx(Pe,{className:"w-3.5 h-3.5 text-fuchsia-300"}),"Lote a procesar: ",e.jsx("span",{className:"font-mono text-fuchsia-200",children:x.length})," productos"]}),e.jsxs("p",{className:"text-[10.5px] text-white/55",children:["Costo aprox: ~",x.length," imágenes IA"]})]}),l.length>0&&e.jsxs("p",{className:"text-[10.5px] text-white/55",children:["Categorías: ",l.join(" · ")]}),g==="principal"&&e.jsxs("p",{className:"text-[10.5px] text-amber-200 flex items-start gap-1.5",children:[e.jsx(K,{className:"w-3 h-3 mt-0.5 flex-shrink-0"}),'Modo "Reemplazar principal": las imágenes anteriores se moverán a galería, no se borrarán.']})]}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:_?e.jsxs(I,{onClick:p,className:"flex-1 min-w-[200px] gap-2 bg-rose-600 hover:bg-rose-700 text-white",children:[e.jsx(ps,{className:"w-4 h-4"})," Cancelar (termina lo en vuelo)"]}):e.jsxs(I,{onClick:n,disabled:x.length===0,className:"flex-1 min-w-[200px] gap-2 bg-gradient-to-r from-fuchsia-500 to-violet-600 hover:from-fuchsia-600 hover:to-violet-700 text-white",children:[e.jsx(be,{className:"w-4 h-4"}),"Generar ",x.length," ",x.length===1?"imagen":"imágenes"," ahora"]})}),(_||d.done>0)&&e.jsxs("div",{className:"bg-white/5 border border-white/10 rounded-xl p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsxs("span",{className:"text-white/70 flex items-center gap-1.5",children:[_&&e.jsx(R,{className:"w-3.5 h-3.5 animate-spin text-fuchsia-300"}),"Progreso: ",e.jsxs("span",{className:"font-mono text-white",children:[d.done,"/",d.total]})]}),e.jsxs("span",{className:"flex items-center gap-3 text-[11px]",children:[e.jsxs("span",{className:"text-emerald-300 flex items-center gap-1",children:[e.jsx(J,{className:"w-3 h-3"})," ",d.ok]}),e.jsxs("span",{className:"text-rose-300 flex items-center gap-1",children:[e.jsx(K,{className:"w-3 h-3"})," ",d.fail]})]})]}),e.jsx("div",{className:"h-1.5 rounded-full bg-white/10 overflow-hidden",children:e.jsx("div",{className:"h-full bg-gradient-to-r from-fuchsia-500 to-violet-500 transition-all",style:{width:`${d.total?d.done/d.total*100:0}%`}})}),e.jsx("div",{ref:h,className:"max-h-56 overflow-y-auto peyu-scrollbar-light bg-black/20 rounded-lg p-1.5 space-y-0.5 mt-2",children:k.map((r,E)=>e.jsxs("div",{className:"flex items-center gap-2 text-[11px] px-1.5 py-1 rounded",children:[r.status==="running"&&e.jsx(R,{className:"w-3 h-3 animate-spin text-fuchsia-300 flex-shrink-0"}),r.status==="done"&&e.jsx(J,{className:"w-3 h-3 text-emerald-300 flex-shrink-0"}),r.status==="fail"&&e.jsx(K,{className:"w-3 h-3 text-rose-300 flex-shrink-0"}),e.jsx("span",{className:"font-mono text-white/50 text-[10px] w-20 truncate flex-shrink-0",children:r.sku}),e.jsx("span",{className:"text-white/80 truncate flex-1",children:r.nombre}),r.url&&e.jsx("img",{src:r.url,alt:"",className:"w-6 h-6 rounded object-cover flex-shrink-0"}),r.error&&e.jsx("span",{className:"text-rose-300 text-[10px] truncate max-w-[140px]",title:r.error,children:r.error})]},E))})]}),e.jsxs("div",{className:"text-[10.5px] text-white/45 flex items-start gap-1.5",children:[e.jsx(q,{className:"w-3 h-3 mt-0.5 flex-shrink-0 text-fuchsia-300"}),e.jsxs("span",{children:["Cada imagen razona ",e.jsx("strong",{className:"text-white/70",children:"título + cantidad detectada + material + descripción"}),". Sin marcas, logos ni texto — apto Google Shopping."]})]})]})]})}function Bs({onProductClick:s,onAction:a}){var h;const[i,c]=o.useState(!1),[t,b]=o.useState(null),[g,j]=o.useState(""),[y,C]=o.useState(!1),[w,N]=o.useState(new Set),[_,$]=o.useState(!0),k=async()=>{var x;c(!0),j("");try{const l=await L.functions.invoke("auditCatalogForLaunch",{mode:"scan"});if((x=l==null?void 0:l.data)!=null&&x.error)throw new Error(l.data.error);b(l.data)}catch(l){j(l.message||"Error escaneando el catálogo")}finally{c(!1)}},v=async(x,l)=>{var m;if(confirm(`¿Desactivar ${x.length} producto${x.length>
1431?"s":""}?
144
145${l}
146
147Se pueden reactivar luego.`)){C(!0);try{const n=await L.functions.invoke("auditCatalogForLaunch",{mode:"apply",deactivateIds:x});if((m=n==null?void 0:n.data)!=null&&m.error)throw new Error(n.data.error);N(p=>{const A=new Set(p);return x.forEach(r=>A.add(r)),A}),a==null||a()}catch(n){alert("Error: "+(n.message||"desconocido"))}finally{C(!1)}}},d=async()=>{var l;if(!((l=t==null?void 0:t.duplicates)!=null&&l.length))return;const x=t.duplicates.flatMap(m=>m.remove.map(n=>n.id)).filter(m=>!w.has(m));x.length!==0&&await v(x,`Desactivar ${x.length} duplicados (conservando el mejor de cada grupo).`)},u=t?t.summary.duplicate_removable+t.summary.precio_issues+t.summary.descripcion_issues+t.summary.image_issues:0,f=((h=t==null?void 0:t.duplicates)==null?void 0:h.filter(x=>x.remove.some(l=>!w.has(l.id))))||[];return e.jsxs("div",{className:"bg-gradient-to-br from-indigo-500/10 via-violet-500/5 to-fuchsia-500/10 border border-violet-400/30 rounded-2xl p-4 lg:p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 flex-wrap",children:[e.jsxs("div",{className:"flex items-start gap-3 min-w-0",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-gradient-to-br from-violet-500 to-fuchsia-500 flex items-center justify-center flex-shrink-0",children:e.jsx(ze,{className:"w-5 h-5 text-white"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h3",{className:"font-poppins font-bold text-white text-base flex items-center gap-2",children:["Pre-Launch Audit",t&&u===0&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] font-bold text-emerald-300 bg-emerald-500/15 px-2 py-0.5 rounded-full",children:[e.jsx(J,{className:"w-3 h-3"})," Tienda lista"]})]}),e.jsx("p",{className:"text-xs text-white/65 mt-0.5 leading-relaxed",children:"Escanea duplicados, precios faltantes, descripciones malas e imágenes rotas antes del lanzamiento."})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[t&&e.jsx("button",{onClick:()=>$(!_),className:"text-white/50 hover:text-white text-xs px-2 py-1 rounded-md hover:bg-white/5",children:_?"Colapsar":"Expandir"}),e.jsxs(I,{onClick:k,disabled:i,size:"sm",className:"bg-violet-600 hover:bg-violet-700 text-white gap-2",children:[i?e.jsx(R,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(ze,{className:"w-3.5 h-3.5"}),i?"Escaneando...":t?"Re-escanear":"Iniciar scan"]})]})]}),g&&e.jsxs("div",{className:"mt-3 p-3 bg-rose-500/10 border border-rose-400/30 rounded-lg text-xs text-rose-300 flex items-start gap-2",children:[e.jsx(G,{className:"w-4 h-4 flex-shrink-0 mt-0.5"}),e.jsx("span",{children:g})]}),t&&_&&e.jsxs("div",{className:"mt-4 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-2",children:[e.jsx(xe,{icon:ue,color:"amber",label:"Duplicados",value:f.length,subtitle:`${f.reduce((x,l)=>x+l.remove.filter(m=>!w.has(m.id)).length,0)} a desactivar`}),e.jsx(xe,{icon:gs,color:"rose",label:"Precio $0",value:t.precio_issues.length}),e.jsx(xe,{icon:js,color:"orange",label:"Sin descripción",value:t.descripcion_issues.length}),e.jsx(xe,{icon:fe,color:"fuchsia",label:"Imagen rota",value:t.image_issues.length,subtitle:`de ${t.summary.images_checked} verificadas`})]}),f.length>0&&e.jsx(me,{title:`Duplicados obvios (${f.length} grupos)`,hint:"Match por nombre o SKU idéntico. Se conserva el de mejor calidad (más imágenes, precios B2B, descripción completa).",action:e.jsx(I,{size:"sm",onClick:d,disabled:y,className:"bg-amber-600 hover:bg-amber-700 text-white text-xs h-7",children:y?e.jsx(R,{className:"w-3 h-3 animate-spin"}):"Desactivar todos"}),children:f.map((x,l)=>{const m=x.remove.filter(n=>!w.has(n.id));return m.length===0?null:e.jsx(Gs,{group:x,removeActive:m,onDeactivate:n=>v(n,`Match: "${x.key}"`),onProductClick:s,applying:y},l)})}),t.precio_issues.length>0&&e.jsx(me,{title:`Productos con precio en $0 (${t.precio_issues.length})`,hint:"Estos productos NO se pueden vender. Edítalos o desactívalos.",children:e.jsx(Se,{items:t.precio_issues,onProductClick:s,field:"precio_b2c",formatValue:x=>x?`$${x.toLocaleString("es-CL")}`:"Sin precio"})}),t.descripcion_issues.length>0&&e.jsx(me,{title:`Sin descripción usable (${t.descripcion_issues.length})`,hint:"Productos sin descripción o con texto < 15 caracteres reales. Mal para SEO y conversión.",children:e.jsx(Se,{items:t.descripcion_issues,onProductClick:s,field:"descripcion_length",formatValue:x=>`${x||0} chars`})}),t.image_issues.length>0&&e.jsx(me,{title:`Imágenes rotas o faltantes (${t.image_issues.length})`,hint:"URL no responde, devuelve 404 o no es imagen.",children:e.jsx(Se,{items:t.image_issues,onProductClick:s,field:"reason"})}),u===0&&e.jsxs("div",{className:"p-4 bg-emerald-500/10 border border-emerald-400/30 rounded-xl text-center",children:[e.jsx(J,{className:"w-8 h-8 text-emerald-300 mx-auto mb-2"}),e.jsx("p",{className:"font-bold text-emerald-200 text-sm",children:"¡Catálogo limpio!"}),e.jsxs("p",{className:"text-xs text-emerald-200/70 mt-1",children:[t.total_productos," productos escaneados · sin problemas críticos detectados"]})]})]})]})}function xe({icon:s,color:a,label:i,value:c,subtitle:t}){const b={amber:"text-amber-300 border-amber-400/30 bg-amber-500/10",rose:"text-rose-300 border-rose-400/30 bg-rose-500/10",orange:"text-orange-300 border-orange-400/30 bg-
147orange-500/10",fuchsia:"text-fuchsia-300 border-fuchsia-400/30 bg-fuchsia-500/10"},g=c===0;return e.jsxs("div",{className:`px-3 py-2 rounded-xl border ${g?"border-white/10 bg-white/5":b[a]}`,children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] font-bold uppercase tracking-wider opacity-80",children:[e.jsx(s,{className:"w-3 h-3"}),i]}),e.jsx("div",{className:`text-xl font-poppins font-bold mt-0.5 ${g?"text-white/40":""}`,children:c}),t&&e.jsx("div",{className:"text-[10px] opacity-60 mt-0.5",children:t})]})}function me({title:s,hint:a,action:i,children:c}){return e.jsxs("div",{className:"bg-white/[0.03] border border-white/10 rounded-xl p-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-bold text-white text-sm",children:s}),a&&e.jsx("p",{className:"text-[11px] text-white/50 mt-0.5",children:a})]}),i]}),e.jsx("div",{className:"space-y-2 mt-2",children:c})]})}function Gs({group:s,removeActive:a,onDeactivate:i,onProductClick:c,applying:t}){return e.jsxs("div",{className:"bg-black/20 border border-white/10 rounded-lg p-2.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-white/50 mb-2",children:[e.jsx("span",{className:"px-1.5 py-0.5 rounded bg-violet-500/20 text-violet-300 font-mono",children:s.type==="sku"?"SKU":"NAME"}),e.jsxs("span",{className:"font-mono truncate",children:['"',s.key,'"']})]}),e.jsx(qe,{producto:s.keep,badge:"MANTENER",badgeColor:"emerald",onProductClick:c}),a.map(b=>e.jsx(qe,{producto:b,badge:"DUPLICADO",badgeColor:"rose",onProductClick:c,actionLabel:"Desactivar",onAction:()=>i([b.id]),actionDisabled:t},b.id))]})}function qe({producto:s,badge:a,badgeColor:i,onProductClick:c,actionLabel:t,onAction:b,actionDisabled:g}){const j={emerald:"bg-emerald-500/20 text-emerald-300",rose:"bg-rose-500/20 text-rose-300"};return e.jsxs("div",{className:"flex items-center gap-2 py-1.5 px-1.5 rounded-md hover:bg-white/5",children:[s.imagen_url?e.jsx("img",{src:s.imagen_url,alt:"",className:"w-9 h-9 rounded-md object-cover flex-shrink-0 bg-white/5"}):e.jsx("div",{className:"w-9 h-9 rounded-md bg-white/5 flex items-center justify-center flex-shrink-0",children:e.jsx(fe,{className:"w-3.5 h-3.5 text-white/30"})}),e.jsxs("button",{onClick:()=>c==null?void 0:c(s.id),className:"flex-1 min-w-0 text-left",children:[e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:`text-[9px] font-bold px-1.5 py-0.5 rounded ${j[i]}`,children:a}),e.jsx("span",{className:"text-xs text-white font-medium truncate",children:s.nombre})]}),e.jsxs("div",{className:"text-[10px] text-white/40 font-mono mt-0.5 flex items-center gap-2",children:[e.jsx("span",{children:s.sku}),s.precio_b2c!==void 0&&e.jsxs("span",{children:["$",(s.precio_b2c||0).toLocaleString("es-CL")]})]})]}),t&&e.jsx(I,{size:"sm",onClick:b,disabled:g,className:"bg-rose-600/80 hover:bg-rose-600 text-white text-[10px] h-7 px-2.5",children:g?e.jsx(R,{className:"w-3 h-3 animate-spin"}):t})]})}function Se({items:s,onProductClick:a,field:i,formatValue:c}){const t=s.slice(0,20);return e.jsxs(e.Fragment,{children:[t.map(b=>e.jsxs("div",{className:"flex items-center gap-2 py-1.5 px-1.5 rounded-md hover:bg-white/5 cursor-pointer",onClick:()=>a==null?void 0:a(b.id),children:[b.imagen_url?e.jsx("img",{src:b.imagen_url,alt:"",className:"w-9 h-9 rounded-md object-cover flex-shrink-0 bg-white/5"}):e.jsx("div",{className:"w-9 h-9 rounded-md bg-white/5 flex items-center justify-center flex-shrink-0",children:e.jsx(fe,{className:"w-3.5 h-3.5 text-white/30"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-xs text-white font-medium truncate",children:b.nombre}),e.jsxs("div",{className:"text-[10px] text-white/40 font-mono mt-0.5 flex items-center gap-2",children:[e.jsx("span",{children:b.sku}),e.jsx("span",{className:"text-amber-300",children:c?c(b[i]):b[i]})]})]}),e.jsx(ls,{className:"w-3.5 h-3.5 text-white/30 flex-shrink-0"})]},b.id)),s.length>t.length&&e.jsxs("p",{className:"text-[11px] text-white/40 text-center pt-1",children:["+ ",s.length-t.length," más..."]})]})}const Ye={very_high:{label:"Muy alta",color:"bg-emerald-500/20 text-emerald-300 border-emerald-400/40"},high:{label:"Alta",color:"bg-cyan-500/20 text-cyan-300 border-cyan-400/40"}
147,medium:{label:"Media",color:"bg-amber-500/20 text-amber-300 border-amber-400/40"},low:{label:"Baja",color:"bg-rose-500/20 text-rose-300 border-rose-400/40"}},Fs={sku_exact:"SKU idéntico",sku_root:"SKU raíz",name_exact:"Nombre exacto",name_near_exact:"Nombre casi exacto",name_fuzzy:"Nombre similar",name_loose:"Nombre vagamente similar"};function Us({group:s,onMerge:a}){const i=Ye[s.best_match_confidence]||Ye.low,c=Fs[s.best_match_type]||s.best_match_type;return e.jsxs("div",{className:"bg-black/30 border border-white/10 rounded-xl p-3 hover:border-cyan-400/30 transition-all",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-2 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:`text-[10px] font-bold px-2 py-0.5 rounded-full border ${i.color}`,children:i.label}),e.jsx("span",{className:"text-[10px] text-white/50 font-mono",children:c}),e.jsxs("span",{className:"text-[10px] text-white/40",children:[s.duplicates.length," duplicado",s.duplicates.length>1?"s":""]})]}),e.jsxs(I,{size:"sm",onClick:a,className:"bg-cyan-600 hover:bg-cyan-700 text-white text-[11px] h-7 px-3 gap-1.5",children:[e.jsx(ge,{className:"w-3 h-3"})," Fusionar"]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-[1fr_auto_1fr] gap-2 items-stretch",children:[e.jsxs("div",{className:"bg-emerald-500/5 border border-emerald-400/20 rounded-lg p-2",children:[e.jsxs("div",{className:"flex items-center gap-1 mb-1.5",children:[e.jsx(oe,{className:"w-3 h-3 text-emerald-300 fill-emerald-300"}),e.jsx("span",{className:"text-[10px] font-bold text-emerald-300 uppercase tracking-wider",children:"A conservar"}),e.jsxs("span",{className:"text-[10px] text-white/40 ml-auto",children:["score ",s.primary.quality_score]})]}),e.jsx(He,{producto:s.primary})]}),e.jsx("div",{className:"hidden md:flex items-center justify-center px-1",children:e.jsx(pe,{className:"w-4 h-4 text-cyan-400/60"})}),e.jsxs("div",{className:"bg-rose-500/5 border border-rose-400/20 rounded-lg p-2 space-y-1.5",children:[e.jsx("div",{className:"flex items-center gap-1 mb-0.5",children:e.jsx("span",{className:"text-[10px] font-bold text-rose-300 uppercase tracking-wider",children:"A fusionar y desactivar"})}),s.duplicates.map(t=>e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(He,{producto:t,compact:!0}),e.jsxs("span",{className:"text-[9px] font-mono text-white/40 flex-shrink-0 mt-1",children:[(t.similarity*100).toFixed(0),"%"]})]},t.id))]})]})]})}function He({producto:s,compact:a}){return e.jsxs("div",{className:"flex items-start gap-2 min-w-0",children:[s.imagen_url?e.jsx("img",{src:s.imagen_url,alt:"",className:`${a?"w-8 h-8":"w-10 h-10"} rounded-md object-cover flex-shrink-0 bg-white/5`,onError:i=>{i.target.style.display="none"}}):e.jsx("div",{className:`${a?"w-8 h-8":"w-10 h-10"} rounded-md bg-white/5 flex items-center justify-center flex-shrink-0`,children:e.jsx(ae,{className:"w-3 h-3 text-white/30"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:`${a?"text-[11px]":"text-xs"} text-white font-medium truncate leading-tight`,children:s.nombre}),e.jsxs("div",{className:"text-[9px] text-white/40 font-mono mt-0.5 flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{children:s.sku}),s.precio_b2c>0&&e.jsxs("span",{children:["$",s.precio_b2c.toLocaleString("es-CL")]}),s.galeria_count>0&&e.jsxs("span",{children:[s.galeria_count,"🖼️"]}),s.descripcion_length>0&&e.jsxs("span",{children:[s.descripcion_length,"c"]}),!s.activo&&e.jsx("span",{className:"text-rose-300/70",children:"inactivo"})]})]})]})}const qs={descripcion:"Descripción",imagen_url:"Imagen principal",galeria_urls:"Galería de imágenes",imagen_promo_url:"Imagen promo social",area_laser_mm:"Área grabado láser",garantia_anios:"Garantía (años)",peso_kg:"Peso (kg)",largo_cm:"Largo (cm)",ancho_cm:"Ancho (cm)",alto_cm:"Alto (cm)",precio_base_b2b:"Precio base B2B",precio_50_199:"Precio 50–199 u.",precio_200_499:"Precio 200–499 u.",precio_500_mas:"Precio 500+ u.",seo_meta_title:"SEO · Meta Title",seo_meta_description:"SEO · Meta Description",seo_focus_keyword:"SEO · Focus Keyword",stock_actual:"Stock (suma total)"};function Ke(s){return s==null||s===""?e.jsx("span",{className:"text-white/30 italic",children:"vacío"}):Array.isArray(s)?e.jsxs("span",{children:[s.length," URL",s.length!==1?"s":""]}):typeof s=="string"&&s.length>80?e.jsxs("span",{title:s,children:[s.slice(0,80),"…"]}
147):typeof s=="number"?s.toLocaleString("es-CL"):String(s)}function Ys({context:s,onClose:a,onApplied:i}){var l;const{primaryId:c,duplicateIds:t,group:b}=s,[g,j]=o.useState(!0),[y,C]=o.useState(null),[w,N]=o.useState(""),[_,$]=o.useState({}),[k,v]=o.useState(!1),[d,u]=o.useState(null);o.useEffect(()=>{let m=!1;return(async()=>{var n;j(!0),N("");try{const p=await L.functions.invoke("scanDuplicateProducts",{mode:"preview_merge",primaryId:c,duplicateIds:t});if(m)return;if((n=p==null?void 0:p.data)!=null&&n.error)throw new Error(p.data.error);C(p.data.preview);const A={};for(const[r,E]of Object.entries(p.data.preview||{}))A[r]=E.changed;$(A)}catch(p){m||N(p.message)}finally{m||j(!1)}})(),()=>{m=!0}},[c,t.join(",")]);const f=m=>{$(n=>({...n,[m]:!n[m]}))},h=async()=>{var n;if(!y)return;const m={};for(const[p,A]of Object.entries(y))_[p]&&A.proposed!==void 0&&A.proposed!==null&&A.proposed!==""&&(m[p]=A.proposed);if(confirm(`Se aplicarán ${Object.keys(m).length} cambios al primario y se desactivarán ${t.length} duplicados.
148
149¿Continuar?`)){v(!0);try{const p=await L.functions.invoke("scanDuplicateProducts",{mode:"apply_merge",primaryId:c,duplicateIds:t,fieldsToApply:m});if((n=p==null?void 0:p.data)!=null&&n.error)throw new Error(p.data.error);u(p.data),setTimeout(()=>{i()},1200)}catch(p){N(p.message)}finally{v(!1)}}},x=y?Object.entries(y).filter(([m,n])=>n.changed):[];return e.jsx("div",{className:"fixed inset-0 z-[200] bg-black/80 backdrop-blur-sm flex items-center justify-center p-3 overflow-y-auto",children:e.jsxs("div",{className:"bg-slate-900 border border-cyan-400/30 rounded-2xl w-full max-w-3xl my-4 shadow-2xl flex flex-col max-h-[92vh]",children:[e.jsxs("div",{className:"p-4 border-b border-white/10 flex items-start justify-between gap-3 flex-shrink-0",children:[e.jsxs("div",{className:"flex items-start gap-3 min-w-0",children:[e.jsx("div",{className:"w-9 h-9 rounded-xl bg-gradient-to-br from-cyan-500 to-indigo-500 flex items-center justify-center flex-shrink-0",children:e.jsx(ge,{className:"w-4 h-4 text-white"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"font-poppins font-bold text-white text-base",children:"Preview de fusión"}),e.jsxs("p",{className:"text-xs text-white/60 mt-0.5 truncate",children:[e.jsx("strong",{className:"text-emerald-300",children:b.primary.nombre})," ← ",t.length," duplicado",t.length>1?"s":""]})]})]}),e.jsx("button",{onClick:a,className:"p-1.5 rounded-md hover:bg-white/10 text-white/60 hover:text-white flex-shrink-0",children:e.jsx(Q,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 peyu-scrollbar-light",children:[g&&e.jsxs("div",{className:"text-center py-10 text-white/50 text-sm",children:[e.jsx(R,{className:"w-6 h-6 animate-spin mx-auto mb-2"}),"Calculando preview de fusión…"]}),w&&e.jsxs("div",{className:"p-3 bg-rose-500/10 border border-rose-400/30 rounded-lg text-xs text-rose-300 flex items-start gap-2",children:[e.jsx(G,{className:"w-4 h-4 flex-shrink-0 mt-0.5"}),e.jsx("span",{children:w})]}),d&&e.jsxs("div",{className:"p-4 bg-emerald-500/10 border border-emerald-400/30 rounded-xl text-center",children:[e.jsx(J,{className:"w-8 h-8 text-emerald-300 mx-auto mb-2"}),e.jsx("p",{className:"font-bold text-emerald-200 text-sm",children:"¡Fusión completada!"}),e.jsxs("p",{className:"text-xs text-emerald-200/70 mt-1",children:[((l=d.fields_applied)==null?void 0:l.length)||0," campos fusionados · ",d.deactivated_count," duplicados desactivados"]})]}),!g&&!w&&!d&&y&&e.jsxs(e.Fragment,{children:[x.length===0?e.jsxs("div",{className:"p-6 bg-amber-500/10 border border-amber-400/30 rounded-xl text-center",children:[e.jsx(G,{className:"w-8 h-8 text-amber-300 mx-auto mb-2"}),e.jsx("p",{className:"font-bold text-amber-200 text-sm",children:"El primario ya tiene los mejores datos"}),e.jsx("p",{className:"text-xs text-amber-200/70 mt-1",children:"No hay metadatos extra que aportar desde los duplicados. Solo se desactivarán los duplicados."})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between flex-wrap gap-2",children:[e.jsxs("p",{className:"text-xs text-white/60",children:[x.length," campo",x.length!==1?"s":""," se actualizará",x.length!==1?"n":""," en el primario. Desmarca los que no quieras."]}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{onClick:()=>{const m={};x.forEach(([n])=>{m[n]=!0}),$(n=>({...n,...m}))},className:"text-[10px] text-cyan-300 hover:text-cyan-200 underline",children:"marcar todos"}),e.jsx("button",{onClick:()=>{const m={};x.forEach(([n])=>{m[n]=!1}),$(n=>({...n,...m}))},className:"text-[10px] text-white/50 hover:text-white underline",children:"ninguno"})]})]}),e.jsx("div",{className:"space-y-1.5",children:x.map(([m,n])=>e.jsx(Hs,{fieldKey:m,info:n,enabled:_[m],onToggle:()=>f(m)},m))})]}),e.jsxs("div",{className:"mt-4 p-3 bg-white/5 border border-white/10 rounded-lg text-[11px] text-white/60 flex items-start gap-2",children:[e.jsx(q,{className:"w-3.5 h-3.5 text-cyan-300 flex-shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("strong",{className:"text-white/80",children:"Qué pasa al confirmar:"}),e.jsxs("ul",{className:"mt-1 space-y-0.5 list-disc list-inside",children:[e.jsx("li",{children:"El producto primario recibe los campos marcados arriba."}),e.jsxs("li",{children:["Los ",t.length," duplicados se marcan ",e.jsx("code",{className:"text-cyan-300",children:"activo=false"})," (NO se borran)."]}),e.jsx("li",{children:"Se agrega nota interna en la descripción del duplicado para trazabilidad."})]})]})]})]})]}),!d&&e.jsxs("div",{className:"p-4 border-t border-white/10 flex items-center justify-end gap-2 flex-shrink-0",children:[e.jsx(I,{variant:"ghost",onClick:a,disabled:k,className:"text-white/70 hover:text-white text-xs h-9",children:"Cancelar"}),e.jsxs(I,{onClick:h,disabled:g||k||!y,className:"bg-cyan-600 hover:bg-cyan-700 text-white text-xs h-9 gap-2",children:[k?e.jsx(R,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(ge,{className:"w-3.5 h-3.5"}),k?"Fusionando…":`Aplicar fusión (${Object.values(_).filter(
149Boolean).length} campos)`]})]})]})})}function Hs({fieldKey:s,info:a,enabled:i,onToggle:c}){const t=qs[s]||s;return e.jsxs("label",{className:`flex items-start gap-2 p-2 rounded-lg border cursor-pointer transition-all ${i?"bg-cyan-500/5 border-cyan-400/30 hover:bg-cyan-500/10":"bg-white/[0.02] border-white/5 opacity-60"}`,children:[e.jsx("input",{type:"checkbox",checked:i,onChange:c,className:"mt-0.5 accent-cyan-500 flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-xs font-bold text-white",children:t}),e.jsxs("div",{className:"grid grid-cols-[1fr_auto_1fr] items-center gap-2 mt-1 text-[11px]",children:[e.jsx("div",{className:"text-white/50 line-through truncate",children:Ke(a.current)}),e.jsx(pe,{className:"w-3 h-3 text-cyan-400 flex-shrink-0"}),e.jsx("div",{className:"text-cyan-200 font-medium truncate",children:Ke(a.proposed)})]})]})]})}function Ks({onActionComplete:s}){const[a,i]=o.useState(!1),[c,t]=o.useState(null),[b,g]=o.useState(""),[j,y]=o.useState(.88),[C,w]=o.useState(!1),[N,_]=o.useState(!0),[$,k]=o.useState("all"),[v,d]=o.useState(null),[u,f]=o.useState(new Set),h=async()=>{var n;i(!0),g(""),f(new Set);try{const p=await L.functions.invoke("scanDuplicateProducts",{mode:"scan",threshold:j,includeInactive:C});if((n=p==null?void 0:p.data)!=null&&n.error)throw new Error(p.data.error);t(p.data)}catch(p){g(p.message||"Error escaneando duplicados")}finally{i(!1)}},x=n=>{d({primaryId:n.primary.id,duplicateIds:n.duplicates.map(p=>p.id),group:n})},l=n=>{f(p=>new Set(p).add(n)),d(null),s==null||s()},m=(c==null?void 0:c.groups.filter(n=>u.has(n.primary.id)?!1:$==="all"?!0:n.best_match_confidence===$))||[];return e.jsxs("div",{className:"bg-gradient-to-br from-cyan-500/10 via-sky-500/5 to-indigo-500/10 border border-cyan-400/30 rounded-2xl p-4 lg:p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 flex-wrap",children:[e.jsxs("div",{className:"flex items-start gap-3 min-w-0",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-gradient-to-br from-cyan-500 to-indigo-500 flex items-center justify-center flex-shrink-0",children:e.jsx(ge,{className:"w-5 h-5 text-white"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h3",{className:"font-poppins font-bold text-white text-base flex items-center gap-2 flex-wrap",children:["Fusión inteligente de duplicados",c&&e.jsxs("span",{className:"text-[10px] font-bold text-cyan-300 bg-cyan-500/15 px-2 py-0.5 rounded-full",children:[m.length," grupos · ",m.reduce((n,p)=>n+p.duplicates.length,0)," duplicados"]})]}),e.jsxs("p",{className:"text-xs text-white/65 mt-0.5 leading-relaxed",children:["Match exacto + fuzzy + SKU root. Conserva el mejor metadato (descripción más larga, todas las imágenes, precios B2B, SEO) y desactiva los redundantes. ",e.jsx("strong",{className:"text-white/80",children:"Nada se borra."})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[c&&e.jsxs("button",{onClick:()=>_(!N),className:"text-white/50 hover:text-white text-xs px-2 py-1 rounded-md hover:bg-white/5 flex items-center gap-1",children:[N?e.jsx(Le,{className:"w-3 h-3"}):e.jsx(Re,{className:"w-3 h-3"}),N?"Colapsar":"Expandir"]}),e.jsxs(I,{onClick:h,disabled:a,size:"sm",className:"bg-cyan-600 hover:bg-cyan-700 text-white gap-2",children:[a?e.jsx(R,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(q,{className:"w-3.5 h-3.5"}),a?"Escaneando...":c?"Re-escanear":"Detectar duplicados"]})]})]}),N&&e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-3 text-xs",children:[e.jsxs("label",{className:"flex items-center gap-2 text-white/70",children:[e.jsx("span",{children:"Umbral similitud:"}),e.jsx("input",{type:"range",min:"0.75",max:"0.99",step:"0.01",value:j,onChange:n=>y(parseFloat(n.target.value)),className:"w-32 accent-cyan-500"}),e.jsxs("span",{className:"font-mono text-cyan-300 w-12",children:[(j*100).toFixed(0),"%"]})]}),e.jsxs("label",{className:"flex items-center gap-1.5 text-white/70 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:C,onChange:n=>w(n.target.checked),className:"accent-cyan-500"}),e.jsx("span",{children:"Incluir inactivos en scan"})]})]}),b&&e.jsxs("div",{className:"mt-3 p-3 bg-rose-500/10 border border-rose-400/30 rounded-lg text-xs text-rose-300 flex items-start gap-2",children:[e.jsx(G,{className:"w-4 h-4 flex-shrink-0 mt-0.5"}),e.jsx("span",{children:b})]}),c&&N&&e.jsxs("div",{className:"mt-4 space-y-3",children:[e.jsx("div",{className:"flex flex-wrap gap-1.5",children:[{id:"all",label:`Todos · ${c.total_groups}`,color:"white"},{id:"very_high",label:`Muy alta · ${c.by_confidence.very_high}`,color:"emerald"},{id:"high",label:`Alta · ${c.by_confidence.high}`,color:"cyan"},{id:"medium",label:`Media · ${c.by_confidence.medium}`,color:"amber"},{id:"low",label:`Baja · ${c.by_confidence.low}`,color:"rose"}].map(n=>e.jsx("button",{onClick:()=>k(n.id),className:`px-2.5 py-1 rounded-md text-[11px] font-medium transition-all ${$===n.id?"bg-cyan-500 text-white shadow-sm":"bg-white/5 text-white/60 hover:bg-white/10"}`,children:n.label},n.id))}),m.length===0?e.jsxs("div",{className:"p-6 bg-emerald-500/10 border border-emerald-400/30 rounded-xl text-center",children:[e.jsx(J,{className:"w-8 h-8 text-emerald-300 mx-auto mb-2"}),e.jsx("p",{className:"font-bold text-emerald-200 text-sm",children:"Sin duplicados en este filtro"}),e.jsx("p",{className:"text-xs text-emerald-200/70 mt-1",children:u.size>0?`${u.size} grupos ya fusionados en esta sesión`:"Catálogo limpio para este nivel de confianza."})]}):e.jsx("div",{className:"space-y-2 max-h-[700px] overflow-y-auto peyu-scrollbar-light pr-1",children:m.map(n=>e.jsx(Us,{group:n,onMerge:()=>x(n)},n.primary.id))})]}),v&&e.jsx(Ys,{context:v,onClose:()=>d(null),onApplied:()=>l(v.primaryId)})]})}function Vs(){var j;
149const[s,a]=o.useState(!1),[i,c]=o.useState(null),[t,b]=o.useState(null),g=async()=>{a(!0),b(null),c(null);try{const y=await L.functions.invoke("syncToMerchantCenter",{});c(y.data||y)}catch(y){b((y==null?void 0:y.message)||"Error desconocido")}finally{a(!1)}};return e.jsxs("div",{className:"bg-white border border-slate-200 rounded-3xl p-6 shadow-sm",children:[e.jsxs("div",{className:"flex items-start gap-4 mb-5",children:[e.jsx("div",{className:"w-12 h-12 rounded-2xl bg-gradient-to-br from-emerald-500 to-teal-600 flex items-center justify-center flex-shrink-0 shadow-lg shadow-emerald-500/30",children:e.jsx(ns,{className:"w-6 h-6 text-white"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"font-poppins font-bold text-slate-900 text-lg",children:"Google Merchant Center · Sync"}),e.jsx("p",{className:"text-sm text-slate-600 mt-1 leading-relaxed",children:"Empuja todo el catálogo activo a Google Shopping, Bing, Yandex y otros motores en un solo click. Útil tras subir productos nuevos o actualizar precios."})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 mb-4",children:[e.jsx(I,{onClick:g,disabled:s,className:"bg-gradient-to-r from-emerald-600 to-teal-600 hover:from-emerald-700 hover:to-teal-700 text-white gap-2 h-11 px-5",children:s?e.jsxs(e.Fragment,{children:[e.jsx(R,{className:"w-4 h-4 animate-spin"}
149),"Empujando catálogo…"]}):e.jsxs(e.Fragment,{children:[e.jsx(q,{className:"w-4 h-4"}),"Sincronizar todos los productos"]})}),e.jsxs("a",{href:"https://peyuchile.cl/googleMerchantFeed",target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1.5 px-4 h-11 rounded-md border border-slate-200 hover:border-slate-300 hover:bg-slate-50 text-sm font-semibold text-slate-700",children:["Ver Feed XML ",e.jsx(Qe,{className:"w-3.5 h-3.5"})]})]}),t&&e.jsxs("div",{className:"bg-red-50 border border-red-200 rounded-xl p-3 text-sm text-red-900 flex items-start gap-2",children:[e.jsx(G,{className:"w-4 h-4 mt-0.5 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-bold",children:"No se pudo sincronizar"}),e.jsx("p",{className:"text-xs mt-0.5",children:t})]})]}),i&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsx(Ee,{label:"Productos enviados",value:i.eligible,tone:"emerald"}),e.jsx(Ee,{label:"Catálogo total",value:i.total_products,tone:"slate"}),e.jsx(Ee,{label:"Excluidos",value:i.skipped,tone:"amber",hint:"Inactivos / sin imagen / B2B exclusivo / sin precio"})]}),e.jsxs("div",{className:"space-y-1.5 pt-1",children:[e.jsx($e,{name:"Google · ping sitemap",status:i.google_ping}),e.jsx($e,{name:"Search Console · re-submit",status:i.gsc_sitemap}),e.jsx($e,{name:"IndexNow · Bing/Yandex/Seznam",status:i.indexnow,extra:(j=i.indexnow)!=null&&j.urls_sent?`${i.indexnow.urls_sent} URLs`:null})]}),e.jsx("p",{className:"text-[11px] text-slate-500 pt-1",children:"Google y Bing tardan entre 1h y 48h en re-indexar. Revisa el estado en Google Merchant Center → Productos → Diagnóstico."})]})]})}function Ee({label:s,value:a,tone:i,hint:c}){const t={emerald:"bg-emerald-50 border-emerald-200 text-emerald-900",slate:"bg-slate-50 border-slate-200 text-slate-900",amber:"bg-amber-50 border-amber-200 text-amber-900"};return e.jsxs("div",{className:`border rounded-xl p-3 ${t[i]}`,title:c,children:[e.jsx("p",{className:"text-[10px] uppercase tracking-wider font-bold opacity-70",children:s}),e.jsx("p",{className:"text-2xl font-poppins font-extrabold tabular-nums mt-0.5",children:a??"—"})]})}function $e({name:s,status:a,extra:i}){const c=a==null?void 0:a.ok;return e.jsxs("div",{className:"flex items-center justify-between gap-3 px-3 py-2 rounded-lg bg-slate-50 border border-slate-100 text-sm",children:[e.jsx("span",{className:"font-medium text-slate-700",children:s}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[i&&e.jsx("span",{className:"text-[11px] text-slate-500 font-mono",children:i}),c?e.jsxs("span",{className:"inline-flex items-center gap-1 text-emerald-700 font-bold text-xs",children:[e.jsx(J,{className:"w-3.5 h-3.5"})," OK ",a!=null&&a.status?`· ${a.status}`:""]}):e.jsxs("span",{className:"inline-flex items-center gap-1 text-red-700 font-bold text-xs",children:[e.jsx(G,{className:"w-3.5 h-3.5"})," ",(a==null?void 0:a.error)||`Error ${(a==null?void 0:a.status)||""}`]})]})]})}function la(){const[s,a]=o.useState([]),[i,c]=o.useState(!0),[t,b]=o.useState(""),[g,j]=o.useState("publicados"),[y,C]=o.useState(null),[w,N]=o.useState("datos"),[_,$]=o.useState(!1),[k,v]=o.useState(null),d=async()=>{c(!0);const l=await L.entities.Producto.list("nombre",200);a(l),c(!1)};o.useEffect(()=>{d()},[]);const u=o.useMemo(()=>s.filter(l=>{var n,p;if(g==="publicados"&&l.activo===!1||g==="inactivos"&&l.activo!==!1||g==="sin_descripcion"&&l.descripcion||g==="sin_imagen"&&l.imagen_url)return!1;const m=t.toLowerCase();return!m||((n=l.nombre)==null?void 0:n.toLowerCase().includes(m))||((
149p=l.sku)==null?void 0:p.toLowerCase().includes(m))}),[s,t,g]),f=o.useMemo(()=>({total:s.length,publicados:s.filter(l=>l.activo!==!1).length,inactivos:s.filter(l=>l.activo===!1).length,sinDescripcion:s.filter(l=>!l.descripcion).length,sinImagen:s.filter(l=>!l.imagen_url).length,completos:s.filter(l=>l.descripcion&&l.imagen_url).length}),[s]),h=s.find(l=>l.id===y);o.useEffect(()=>{!h&&u.length>0&&C(u[0].id)},[u,h]);const x=l=>{a(m=>m.map(n=>n.id===y?{...n,...l}:n))};return e.jsxs("div",{className:"min-h-screen flex flex-col p-4 lg:p-6 gap-4 bg-gray-50",children:[e.jsxs("div",{className:"flex items-start justify-between flex-wrap gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h1",{className:"text-xl lg:text-2xl font-poppins font-bold text-gray-900 flex items-center gap-2",children:[e.jsx(q,{className:"w-5 h-5 lg:w-6 lg:h-6 text-violet-600 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:"Administración de Productos"})]}),e.jsx("p",{className:"text-gray-500 text-xs lg:text-sm mt-1",children:"Edita precios, stock e imágenes · Genera descripciones SEO con IA · Sincroniza con peyuchile.cl"})]}),e.jsxs(I,{onClick:async()=>{$(!0),v(null);try{const l=await L.functions.invoke("syncWooCatalogo",{fullSync:!0});v(l.data),await d()}catch(l){v({error:l.message})}finally{$(!1)}},disabled:_,className:"gap-2 bg-emerald-600 hover:bg-emerald-700 text-white",children:[_?e.jsx(R,{className:"w-4 h-4 animate-spin"}):e.jsx(Xe,{className:"w-4 h-4"}),_?"Sincronizando…":"Sync con peyuchile.cl"]})]}),k&&e.jsxs("div",{className:`px-4 py-2.5 rounded-xl border flex items-start gap-2 text-xs ${k.error?"bg-red-50 border-red-200 text-red-800":"bg-emerald-50 border-emerald-200 text-emerald-800"}`,children:[k.error?e.jsx(G,{className:"w-4 h-4 mt-0.5 flex-shrink-0"}):e.jsx(U,{className:"w-4 h-4 mt-0.5 flex-shrink-0"}),e.jsx("div",{className:"flex-1",children:k.error?e.jsxs("span",{children:["Error: ",k.error]}):e.jsxs("span",{children:["✓ Sincronizados ",e.jsx("strong",{children:k.total_woo})," productos ·"," ",e.jsx("strong",{children:k.creados})," nuevos ·"," ",e.jsx("strong",{children:k.actualizados})," actualizados",k.desactivados>0&&e.jsxs(e.Fragment,{children:[" · ",e.jsx("strong",{className:"text-red-700",children:k.desactivados})," desactivados"]}),k.errores>0&&e.jsxs(e.Fragment,{children:[" · ",e.jsx("strong",{className:"text-amber-700",children:k.errores})," errores"]})]})}),e.jsx("button",{onClick:()=>v(null),className:"text-gray-400 hover:text-gray-700",children:e.jsx(Q,{className:"w-3 h-3"})})]}),e.jsx(Vs,{}),e.jsx(Bs,{onProductClick:l=>{C(l),N("datos")},onAction:d}),e.jsx(Ks,{onActionComplete:d}),e.jsx(Rs,{onComplete:d}),e.jsx(Ds,{onComplete:d}),e.jsx(Ls,{onComplete:d}),e.jsx(Ms,{onProductClick:l=>{C(l),N("imagen")}}),e.jsx(Os,{productos:s,onComplete:d}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-6 gap-2",children:[e.jsx(re,{label:"Publicados",value:f.publicados,color:"text-emerald-700",bgActive:"bg-emerald-50 border-emerald-400",active:g==="publicados",onClick:()=>j("publicados")}),e.jsx(re,{label:"Inactivos",value:f.inactivos,color:"text-gray-600",bgActive:"bg-gray-100 border-gray-400",active:g==="inactivos",onClick:()=>j("inactivos")}),e.jsx(re,{label:"Todos",value:f.total,color:"text-gray-900",bgActive:"bg-violet-50 border-violet-400",active:g==="todos",onClick:()=>j("todos")}),e.jsx(re,{label:"Sin descripción",value:f.sinDescripcion,color:"text-amber-700",bgActive:"bg-amber-50 border-amber-400",highlight:!0,active:g==="sin_descripcion",onClick:()=>j("sin_descripcion")}),e.jsx(re,{label:"Sin imagen",value:f.sinImagen,color:"text-red-700",bgActive:"bg-red-50 border-red-400",highlight:!0,active:g==="sin_imagen",onClick:()=>j("sin_imagen")}),e.jsx(re,{label:"Completos",value:f.completos,color:"text-cyan-700",bgActive:"bg-cyan-50 border-cyan-400",active:!1})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[340px_minmax(0,1fr)] gap-3 h-[720px] max-h-[calc(100vh-120px)]",children:[e.jsxs("div",{className:"bg-white border border-gray-200 rounded-2xl flex flex-col min-h-0 overflow-hidden shadow-sm h-[720px] max-h-[calc(100vh-120px)] lg:h-auto",children:[e.jsxs("div",{className:"p-3 space-y-2 border-b border-gray-100 flex-shrink-0",children:[e.jsxs("div",{className:"relative",children:[e.jsx(os,{className:"w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-gray-400"}),e.jsx(Ve,{value:t,onChange:l=>b(l.target.value),placeholder:"Buscar SKU o nombre…",className:"pl-9 h-9 bg-gray-50 border-gray-200 text-gray-900 placeholder:text-gray-400"})]}),e.jsx("div",{className:"flex gap-1 flex-wrap",children:[{id:"publicados",label:`Publicados · ${f.publicados}`,color:"emerald"},{id:"inactivos",label:`Inactivos · ${f.inactivos}`,color:"slate"},{id:"todos",label:`Todos · ${f.total}`,color:"violet"},{id:"sin_descripcion",label:`Sin desc · ${f.sinDescripcion}`,color:"amber"},{id:"sin_imagen",label:`Sin img · ${f.sinImagen}`,color:"rose"}].map(l=>e.jsx("button",{onClick:()=>j(l.id),className:`px-2 py-1 rounded-md text-[11px] font-medium transition-all ${g===l.id?"bg-violet-600 text-white shadow-sm":"bg-gray-100 text-gray-600 hover:bg-gray-200"}`,children:l.label},l.id))})]}),e.jsx("div",{className:"flex-1 overflow-y-auto peyu-scrollbar p-2 min-h-0",children:i?e.jsxs("div",{className:"text-center py-8 text-gray-400 text-sm",children:[e.jsx(R,{className:"w-5 h-5 animate-spin mx-auto mb-2"})," Cargando productos…"]}):u.length===0?e.jsxs("div",{className:"text-center py-8 text-gray-400 text-sm",children:[e.jsx(Pe,{className:"w-8 h-8 mx-auto mb-2 opacity-30"})," Sin productos"]}):e.jsx("div",{className:"space-y-1",children:u.map(l=>e.jsxs("button",{onClick:()=>C(l.id),className:`w-full text-left p-2 rounded-lg transition-all flex items-center gap-2.5 border ${y===l.id?"bg-violet-50 border-violet-300":"bg-white border-gray-100 hover:bg-gray-50 hover:border-gray-200"} ${l.activo===!1?"opacity-60":""}`,children:[l.imagen_url?e.jsx("img",{src:l.imagen_url,alt:"",className:"w-10 h-10 rounded-md object-cover flex-shrink-0 border border-gray-100"}):e.jsx("div",{className:"w-10 h-10 rounded-md bg-gray-100 flex items-center justify-center flex-shrink-0",children:e.jsx(ae,{className:"w-4 h-4 text-gray-400"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:`text-sm font-medium truncate ${y===l.id?"text-violet-900":"text-gray-900"}`,children:l.nombre}),e.jsxs("div",{className:"flex items-center gap-1 mt-0.5 flex-wrap",children:[e.jsx("span",{className:"text-[10px] font-mono text-gray-400 truncate",children:l.sku}),!l.descripcion&&e.jsx("span",{className:"text-[10px] px-1 py-0.5 rounded bg-amber-100 text-amber-700",children:"desc"}),!l.imagen_url&&e.jsx("span",{className:"text-[10px] px-1 py-0.5 rounded bg-red-100 text-red-700",children:"img"}),l.activo===!1&&e.jsx("span",{className:"text-[10px] px-1 py-0.5 rounded bg-gray-100 text-gray-500",children:"off"})]})]})]},l.id))})})]}),e.jsx("div",{className:"bg-white border border-gray-200 rounded-2xl flex flex-col min-h-0 overflow-hidden shadow-sm h-[720px] max-h-[calc(100vh-120px)] lg:h-auto",children:h?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"px-5 pt-4 pb-3 border-b border-gray-100 flex-shrink-0",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-xs font-mono text-gray-400",children:h.sku}),e.jsx("h2",{className:"text-lg lg:text-xl font-poppins font-bold text-gray-900 mt-0.5 truncate",children:h.nombre}),e.jsxs("div",{className:"flex flex-wrap gap-1.5 mt-2",children:[e.jsx(he,{children:h.categoria}),e.jsx(he,{children:h.material}),e.jsx(he,{children:h.canal}),h.activo===!1&&e.jsx(he,{className:"bg-red-100 text-red-700",children:"Inactivo"})]})]}),e.jsx("button",{onClick:()=>C(null),className:"p-1.5 rounded-md hover:bg-gray-100 text-gray-400 lg:hidden flex-shrink-0",children:e.jsx(Q,{className:"w-4 h-4"})})]}),e.jsx("div",{className:"flex gap-1 mt-3 border-b border-gray-100 -mb-3",children:[{id:"datos",label:"Datos",icon:Pe},{id:"imagen",label:"Imagen IA",icon:ae},{id:"descripcion",label:"Descripción IA",icon:cs},{id:"promo",label:"Promo Social",icon:We}].map(l=>e.jsxs("button",{onClick:()=>N(l.id),className:`flex items-center gap-1.5 px-3 py-2 text-xs font-medium border-b-2 transition-all ${w===l.id?"border-violet-600 text-violet-700":"border-transparent text-gray-500 hover:text-gray-800"}`,children:[e.jsx(l.icon,{className:"w-3.5 h-3.5"})," ",l.label]},l.id))})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto peyu-scrollbar p-5 min-h-0",children:[w==="datos"&&e.jsx($s,{producto:h,onSaved:x}
149,h.id),w==="imagen"&&e.jsx(Es,{producto:h,onSaved:x}),w==="descripcion"&&e.jsx(ks,{producto:h,onSaved:l=>x({descripcion:l})}),w==="promo"&&e.jsx(Ps,{producto:h,onSaved:x})]})]}):e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center text-gray-400",children:[e.jsx(G,{className:"w-10 h-10 mb-3 opacity-30"}),e.jsx("p",{className:"text-sm",children:"Selecciona un producto de la lista"})]})})]})]})}function re({label:s,value:a,color:i,highlight:c,active:t,bgActive:b,onClick:g}){const j=g?"button":"div";return e.jsxs(j,{onClick:g,className:`text-left border rounded-xl px-3 py-2 transition-all shadow-sm ${t?`${b} ring-1`:"bg-white border-gray-200"} ${g?"hover:shadow-md cursor-pointer":""}`,children:[e.jsx("div",{className:"text-[11px] text-gray-500 font-medium mb-0.5 truncate",children:s}),e.jsx("div",{className:`text-xl font-poppins font-bold ${i}`,children:a})]})}function he({children:s,className:a=""}){return e.jsx("span",{className:`text-[11px] px-2 py-0.5 rounded-full bg-gray-100 text-gray-600 font-medium ${a}`,children:s})}export{la 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.