1import{r as l,j as e}from"./vendor-react-DiJp4Ids.js";import{B as we,aL as ke}from"./vendor-firestore-ClmovigS.js";import{L as q}from"./vendor-router-BQ9A5i6-.js";import{u as T,e as pe,T as F,B as E,t as j,c0 as Se,w as Y,bX as H,L as M,z as O,E as z,F as $,G as K,H as R,I as Ce,M as Ae,ae as De,af as Ee,ag as Pe,ah as Te,ai as Ie,aj as Be,ak as Le,al as Ue,au as Me,aJ as He,aK as Fe,aL as G,aM as X,o as Oe,f as ze}from"./index-DV0CPbmh.js";import{c as $e,d as Ke,u as Re,i as Ve,e as qe,P as xe,f as We,g as ee,M as Q,h as Ge,D as J,j as se,k as Xe,m as Qe,n as Je,o as ue,l as Ze,p as Ye}from"./helpersService-CjfG5mHh.js";import{A as he}from"./AgentAvatar-vNw3m4UG.js";import{m as es}from"./vendor-motion-WsbK-hjl.js";import{c as _e,H as ss}from"./HelperChat-C0tBe25X.js";import{t as as,A as ts,x as rs}from"./vendor-firebase-TSmD8Bmi.js";import{u as ae,L as P,f as te,d9 as ls,w as L,F as is,cs as ns,C as os,a4 as fe,da as ge,a7 as cs,bX as je,bq as V,c0 as ds,aM as be,ad as ms,ai as ps,m as xs,a6 as us,T as hs,bT as _s,aV as ce,ca as fs,Z as gs,S as Ne,db as js,aQ as bs,cK as Ns,B as vs}from"./vendor-icons-Dp3csqOa.js";import{S as U}from"./switch-DIJynihj.js";import{A as I}from"./AyudaDeControl-HTbUmWGE.js";import"./vendor-firebase-core-4rc3q345.js";import"./vendor-capacitor-Brsuti7y.js";import"./i18n-translations-TdFnI7jD.js";import"./vendor-tanstack-Bh8mR0Am.js";import"./vendor-ui-CKX6mHe-.js";import"./vendor-radix-DA_kJhMJ.js";import"./vendor-datefns-Bq6ooyM0.js";import"./vendor-shared-SwkB51P9.js";import"./useNotaDeVozWeb-Djc1BC1Z.js";import"./musicService-DDPSIPkd.js";function ys(a){if(!a)return!1;if(typeof a=="object"){const c=a.value;return typeof c=="string"&&c.trim().length>0}return!1}function ws({helperId:a}){const{language:c,t:o}=T(),[s,t]=l.useState([]),[b,p]=l.useState(""),[f,x]=l.useState(null),[g,r]=l.useState(""),u=async()=>{if(!f)return;const i=g.trim();if(!i){x(null);return}try{await Re(a,f,i)}catch{j.error(o("helpers_memoria_editar_error"))}x(null)},{user:w}=pe(),n=l.useRef(null),[d,C]=l.useState(!1),S=async i=>{if(!(w!=null&&w.id)||d)return;if(!/\.(pdf|txt|md)$/i.test(i.name)){j.error(o("helpers_memoria_solo_pdf_txt_md"));return}if(i.size>10*1024*1024){j.error(o("helpers_chat_max_10mb"));return}C(!0);try{const y=`media/${w.id}/helpers/${a}/docs/${Date.now()}-${i.name.replace(/[^\w.-]+/g,"_").slice(0,60)}`,k=as(Se,y);await ts(k,i);const B=await rs(k),h=await Ve({helperId:a,fileUrl:B,fileName:i.name});j.success(_e(o("helpers_memoria_documento_leido"),{n:h.memorias})+(h.truncado?o("helpers_memoria_texto_recortado"):""))}catch(y){j.error(y instanceof Error?y.message:o("helpers_memoria_documento_error"))}finally{C(!1),n.current&&(n.current.value="")}},[A,N]=l.useState(!1);l.useEffect(()=>$e(a,t),[a]);const _=async()=>{const i=b.trim();if(i){N(!0);try{await qe(a,i),p("")}catch{j.error(o("helpers_memoria_guardar_error"))}finally{N(!1)}}};return e.jsxs("div",{className:"flex h-full flex-col gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold",children:[e.jsx(ae,{className:"h-4 w-4 text-primary"}),o("helpers_memoria_titulo"),e.jsx("span",{className:"ml-auto text-xs font-normal text-muted-foreground",children:s.length})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(F,{value:b,onChange:i=>p(i.target.value),placeholder:o("helpers_memoria_ensenale"),className:"min-h-[64px] resize-none rounded-xl text-sm"}),e.jsxs(E,{size:"sm",className:"w-full gap-1.5",onClick:_,disabled:A||!b.trim(),children:[A?e.jsx(P,{className:"h-4 w-4 animate-spin"}):e.jsx(te,{className:"h-4 w-4"}),o("helpers_memoria_anadir")]}),e.jsx("input",{ref:n,type:"file",accept:".pdf,.txt,.md",className:"hidden",onChange:i=>{var y;const v=(y=i.target.files)==null?void 0:y[0];v&&S(v)}}),e.jsxs(E,{size:"sm",variant:"outline",className:"w-full gap-1.5",onClick:()=>{var i;return(i=n.current)==null?void 0:i.click()},disabled:d,children:[d?e.jsx(P,{className:"h-4 w-4 animate-spin"}):e.jsx(ls,{className:"h-4 w-4"}),o("helpers_memoria_subir_documento")]})]}),e.jsxs("div",{className:"min-h-0 flex-1 space-y-2 overflow-y-auto",children:[s.length===0&&e.jsx("p",{className:"rounded-xl border border-dashed p-3 text-center text-xs text-muted-foreground",children:o("helpers_memoria_vacia")}
1),s.map(i=>e.jsxs("div",{className:"group flex items-start gap-2 rounded-2xl border bg-card p-2.5 shadow-sm",children:[e.jsx("span",{className:`mt-0.5 inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-full ${i.source==="agent"?"chip-violet":i.source==="document"?"chip-amber":"chip-blue"}`,children:i.source==="agent"?e.jsx(L,{className:"h-3 w-3"}):i.source==="document"?e.jsx(is,{className:"h-3 w-3"}):e.jsx(ns,{className:"h-3 w-3"})}),f===i.id?e.jsxs("div",{className:"flex min-w-0 flex-1 items-start gap-1.5",children:[e.jsx(F,{value:g,onChange:v=>r(v.target.value),onKeyDown:v=>{v.key==="Enter"&&!v.shiftKey&&(v.preventDefault(),u()),v.key==="Escape"&&x(null)},className:"min-h-[48px] flex-1 resize-none rounded-lg text-xs",autoFocus:!0}),e.jsx("button",{onClick:()=>void u(),className:"mt-1 shrink-0 text-emerald-600","aria-label":o("helpers_memoria_guardar"),children:e.jsx(os,{className:"h-3.5 w-3.5"})})]}):e.jsx("button",{type:"button",onClick:()=>{x(i.id),r(i.content)},className:"min-w-0 flex-1 cursor-text text-left text-xs leading-relaxed",title:o("helpers_memoria_clic_editar"),children:i.content}),e.jsx("button",{onClick:()=>Ke(a,i.id).catch(()=>j.error(o("helpers_memoria_borrar_error"))),className:"shrink-0 text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover:opacity-100","aria-label":o("helpers_memoria_borrar"),children:e.jsx(fe,{className:"h-3.5 w-3.5"})})]},i.id))]})]})}function ks(){const{t:a}=T(),{activeCompany:c}=Y(),o=c,[s,t]=l.useState((o==null?void 0:o.helperUbicaciones)||[]),b=async p=>{t(p),c&&await H(c.id,{helperUbicaciones:p})};return e.jsxs("section",{className:"space-y-3","aria-labelledby":"helper-ubicaciones-titulo",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("h3",{id:"helper-ubicaciones-titulo",className:"flex items-center gap-1.5 text-sm font-medium",children:[e.jsx(ge,{className:"h-4 w-4 text-muted-foreground","aria-hidden":"true"}),a("helpers_ubicaciones_titulo")]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("helpers_ubicaciones_para_que")}),e.jsxs("p",{className:"flex gap-1.5 rounded-md bg-muted/60 p-2 text-xs text-muted-foreground",children:[e.jsx(cs,{className:"mt-0.5 h-3.5 w-3.5 shrink-0","aria-hidden":"true"}),e.jsx("span",{children:a("helpers_ubicaciones_ejemplo")})]})]}),s.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:a("helpers_ubicaciones_vacio")}):e.jsx("ul",{className:"space-y-1.5",children:s.map((p,f)=>e.jsxs("li",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-xs",title:p.nombre,children:p.nombre}),e.jsxs("select",{value:p.tipo,"aria-label":`${p.nombre} â ${a("helpers_ubicaciones_titulo")}`,onChange:x=>void b(s.map((g,r)=>r===f?{...g,tipo:x.target.value}:g)),className:"h-8 rounded border bg-background px-1.5 text-xs",children:[e.jsx("option",{value:"tienda",children:a("helpers_ubicaciones_tipo_tienda")}),e.jsx("option",{value:"almacen",children:a("helpers_ubicaciones_tipo_almacen")})]}),e.jsxs("select",{value:p.agrupaCon||"","aria-label":a("helpers_ubicaciones_cuenta_con"),title:a("helpers_ubicaciones_cuenta_con"),onChange:x=>void b(s.map((g,r)=>r===f?{...g,agrupaCon:x.target.value||void 0}:g)),className:"h-8 w-36 rounded border bg-background px-1.5 text-xs",children:[e.jsx("option",{value:"",children:a("helpers_ubicaciones_cuenta_sola")}),s.filter(x=>x.tipo==="tienda"&&x.nombre!==p.nombre).map(x=>e.jsx("option",{value:x.nombre,children:x.nombre},x.nombre))]})]},p.nombre))}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:a("helpers_ubicaciones_sin_agrupar")})]})}function Ss({helper:a,availableProviders:c}){const{language:o,t:s}=T(),[t,b]=l.useState(a.provider),[p,f]=l.useState(a.model),[x,g]=l.useState(a.systemPromptExtra||""),[r,u]=l.useState(!1);l.useEffect(()=>{b(a.provider),f(a.model),g(a.systemPromptExtra||"")},[a.id]);const w=h=>{const D=h;b(D),Q[D].includes(p)||f(J[D])},n=t!==a.provider||p!==a.model||x!==(a.systemPromptExtra||""),d=async()=>{u(!0);try{await se(a.id,{provider:t,model:p,systemPromptExtra:x}),j.success(s("helpers_tools_guardados"))}catch{j.error(s("helpers_ajustes_guardar_error"))}finally{u(!1)}},C=xe.filter(h=>c.includes(h)||h===a.provider),[S,A]=l.useState([]),[N,_]=l.useState(""),[i,v]=l.useState(""),[y,k]=l.useState(!1);l.useEffect(()=>We(a.id,A),[a.id]);const B=async()=>
1{if(!(!N.trim()||!i.trim()||y)){k(!0);try{await Xe(a.id,N,i),_(""),v(""),j.success(s("helpers_tools_skill_creada"))}catch{j.error(s("helpers_tools_skill_error"))}finally{k(!1)}}};return e.jsxs("div",{className:"flex h-full flex-col gap-4 overflow-y-auto",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold",children:[e.jsx(je,{className:"h-4 w-4 text-primary"}),s("helpers_tools_titulo")]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(M,{className:"text-xs",children:s("helpers_tools_proveedor")}),e.jsxs(O,{value:t,onValueChange:w,children:[e.jsx(z,{className:"rounded-xl",children:e.jsx($,{})}),e.jsx(K,{children:C.map(h=>e.jsxs(R,{value:h,disabled:!c.includes(h),children:[ee[h],c.includes(h)?"":s("helpers_tools_sin_key")]},h))})]}),!c.includes(t)&&e.jsxs(q,{to:"/settings?tab=apikeys",className:"inline-flex items-center gap-1 text-[11px] text-primary hover:underline",children:[e.jsx(V,{className:"h-3 w-3"}),s("helpers_tools_configura_key")]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(M,{className:"text-xs",children:s("helpers_tools_modelo")}),e.jsxs(O,{value:p,onValueChange:f,children:[e.jsx(z,{className:"rounded-xl",children:e.jsx($,{})}),e.jsx(K,{children:Q[t].map(h=>e.jsx(R,{value:h,children:h},h))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(M,{className:"text-xs",children:s("helpers_tools_instrucciones_extra")}),e.jsx(F,{value:x,onChange:h=>g(h.target.value),placeholder:s("helpers_tools_instrucciones_ejemplo"),className:"min-h-[96px] resize-none rounded-xl text-sm"})]}),e.jsxs(E,{size:"sm",className:"gap-1.5",onClick:d,disabled:r||!n,children:[r?e.jsx(P,{className:"h-4 w-4 animate-spin"}):e.jsx(ds,{className:"h-4 w-4"}),s("helpers_tools_guardar_ajustes")]}),e.jsxs("div",{className:"space-y-2 border-t pt-3",children:[e.jsx("p",{className:"section-label",children:s("helpers_tools_herramientas")}),[["remember",s("helpers_tools_t_memoria")],["draft_post",s("helpers_tools_t_borrador_post")],["draft_blog_idea",s("helpers_tools_t_idea_blog")],["create_task",s("helpers_tools_t_crear_tareas")],["comment_task",s("helpers_tools_t_comentar_tareas")],["list_tasks",s("helpers_tools_t_leer_tareas")],["list_posts",s("helpers_tools_t_leer_publicado")],["list_blogs",s("helpers_tools_t_leer_blogs")],["list_approvals",s("helpers_tools_t_aprobaciones")],["list_connections",s("helpers_tools_t_cuentas")],["list_products",s("helpers_tools_t_catalogo")],["get_brand_kit",s("helpers_tools_t_brand_kit")],["update_brand_kit",s("helpers_tools_t_cambios_marca")],["seo_summary",s("helpers_tools_t_seo_blogs")],["list_emails",s("helpers_tools_t_bandeja_equipo")],["search_emails",s("helpers_tools_t_buscar_correo")],["shopify_sales",s("helpers_tools_t_ventas_shopify")],["shopify_stock",s("helpers_tools_t_stock_real")],["stock_forecast",s("helpers_tools_t_reposicion")],["list_ideas",s("helpers_tools_t_cola_ideas")],["search_posts",s("helpers_tools_t_buscar_posts")],["get_company_summary",s("helpers_tools_t_foto_empresa")],["list_branches",s("helpers_tools_t_sucursales")],["post_performance",s("helpers_tools_t_mejores_posts")],["social_stats",s("helpers_tools_t_rendimiento_red")],["calendar_overview",s("helpers_tools_t_agenda_14")],["content_gaps",s("helpers_tools_t_dias_sin_publicar")],["cost_summary",s("helpers_tools_t_gasto_ia")],["web_stats",s("helpers_tools_t_trafico_web")],["search_performance",s("helpers_tools_t_seo_keywords")],["list_reviews",s("helpers_tools_t_resenas_gbp")],["gbp_performance",s("helpers_tools_t_rendimiento_ficha")],["meta_ads",s("helpers_tools_t_meta_ads")],["list_comments",s("helpers_tools_t_comentarios_redes")],["draft_comment_reply",s("helpers_tools_t_responder_comentarios")],["shopify_insights",s("helpers_tools_t_shopify_extra")],["bc_sales",s("helpers_tools_t_business_central")],["google_ads",s("helpers_tools_t_google_ads")],["gbp_profile",s("helpers_tools_t_ficha_google")],["list_questions",s("helpers_tools_t_qa_ficha")],["draft_review_reply",s("helpers_tools_t_responder_resenas")],["network_overview",s("helpers_tools_t_vista_red")],["best_posting_times",s("helpers_tools_t_mejores_horas")],["network_compare",s("helpers_tools_t_mes_vs_anterior")]].map(([h,D])=>e.jsxs("div",{className:"flex items-center gap-2 rounded-2xl border bg-card p-2.5",children:[e.jsx("span",{className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full chip-violet",children:e.jsx(ae,{className:"h-3.5 w-3.5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-medium",children:h}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:D})]})]},h))]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold",children:[e.jsx(L,{className:"h-4 w-4 text-primary"}),s("helpers_tools_skills_casa"),e.jsxs("span",{className:"ml-auto text-xs font-normal text-muted-foreground",children:[S.length,"/20"]})]}),e.jsx("p",{className:"-mt-2 text-[11px] text-muted-foreground",children:s("helpers_tools_skills_explicacion")}),e.jsxs("div",{className:"flex flex-col gap-2",children:[S.map(h=>e.jsxs("div",{className:"group flex items-start gap-2 rounded-2xl border bg-card p-2.5",children:[e.jsx("span",{className:"mt-0.5 inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-full chip-amber",children:e.jsx(L,{className:"h-3 w-3"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-xs font-medium",children:h.name}),e.jsx("p",{className:"line-clamp-3 text-[11px] text-muted-foreground",children:h.instructions})]}),e.jsx("button",{onClick:()=>Ge(a.id,h.id).catch(()=>j.error(s("helpers_memoria_borrar_error"))),className:"shrink-0 text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover:opacity-100","aria-label":s("helpers_tools_borrar_skill"),children:e.jsx(fe,{className:"h-3.5 w-3.5"})})]}
1,h.id)),S.length<20&&e.jsxs("div",{className:"flex flex-col gap-2 rounded-2xl border border-dashed p-2.5",children:[e.jsx(Ce,{value:N,onChange:h=>_(h.target.value),placeholder:s("helpers_tools_skill_nombre"),className:"h-8 text-xs"}),e.jsx(F,{value:i,onChange:h=>v(h.target.value),placeholder:s("helpers_tools_skill_instrucciones"),rows:3,className:"text-xs"}),e.jsxs(E,{size:"sm",className:"gap-1.5 self-end",onClick:()=>void B(),disabled:!N.trim()||!i.trim()||y,children:[y?e.jsx(P,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(te,{className:"h-3.5 w-3.5"}),s("helpers_tools_crear_skill")]})]})]}),e.jsx("div",{className:"border-t pt-4",children:e.jsx(ks,{})})]})}const de={pending:{Icon:ms,clase:"text-amber-500"},approved:{Icon:ps,clase:"text-blue-500"},executed:{Icon:xs,clase:"text-emerald-500"},denied:{Icon:us,clase:"text-muted-foreground"},failed:{Icon:hs,clase:"text-destructive"}};function Cs({helper:a}){const{language:c,t:o}=T(),[s,t]=l.useState([]),[b,p]=l.useState([]);l.useEffect(()=>Qe(a.companyId,t),[a.companyId]),l.useEffect(()=>Je(a.companyId,p),[a.companyId]);const f={pending:o("helpers_actividad_pendiente"),approved:o("helpers_actividad_aprobada"),executed:o("helpers_actividad_ejecutada"),denied:o("helpers_actividad_denegada"),failed:o("helpers_actividad_fallo")},x=s.filter(r=>r.helperId===a.id),g=b.filter(r=>r.helperId===a.id);return e.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-y-auto rounded-2xl border bg-card p-3 shadow-sm",children:[x.length===0?e.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-2 py-8 text-center",children:[e.jsx(be,{className:"h-8 w-8 text-muted-foreground/50"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:o("helpers_actividad_vacio")})]}):e.jsx("ul",{className:"flex flex-col gap-1.5",children:x.map(r=>{var d,C,S,A;const{Icon:u,clase:w}=de[r.status]??de.pending,n=((C=(d=r.decidedAt)==null?void 0:d.toDate)==null?void 0:C.call(d))||((A=(S=r.requestedAt)==null?void 0:S.toDate)==null?void 0:A.call(S))||null;return e.jsxs("li",{className:"flex items-start gap-2 rounded-xl border bg-background/50 px-2.5 py-2",children:[e.jsx(u,{className:`mt-0.5 h-4 w-4 shrink-0 ${w}`}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-xs font-medium",children:r.type==="draft_post"?o("helpers_actividad_borrador_post"):r.type==="update_brand_kit"?o("helpers_actividad_cambio_brand_kit"):r.type==="review_reply"?o("helpers_actividad_respuesta_resena"):r.type}),r.preview&&e.jsx("p",{className:"mt-0.5 line-clamp-2 text-[11px] text-muted-foreground",children:r.preview}),r.error&&e.jsx("p",{className:"mt-0.5 line-clamp-2 text-[11px] text-destructive",children:r.error}),e.jsxs("p",{className:"mt-0.5 text-[10px] text-muted-foreground",children:[f[r.status]??r.status,n?` · ${n.toLocaleString(c==="es"?"es":"en",{day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"})}`:""]})]})]},r.id)})}),g.length>0&&e.jsxs("div",{className:"mt-4",children:[e.jsx("p",{className:"mb-1.5 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:o("helpers_actividad_preguntas_fallidas")}),e.jsx("ul",{className:"flex flex-col gap-1.5",children:g.map(r=>{var u,w;return e.jsxs("li",{className:"rounded-xl border border-amber-500/30 bg-amber-500/5 px-2.5 py-2",children:[e.jsx("p",{className:"line-clamp-2 text-[11px]",children:r.pregunta}),e.jsxs("p",{className:"mt-0.5 text-[10px] text-muted-foreground",children:[r.motivo==="tool_error"?`${o("helpers_actividad_fallo_herramienta")}: ${(r.herramientas||[]).join(", ")}`:o("helpers_actividad_sin_forma_de_responder"),(w=(u=r.createdAt)==null?void 0:u.toDate)!=null&&w.call(u)?` · ${r.createdAt.toDate().toLocaleDateString(c==="es"?"es":"en",{day:"numeric",month:"short"})}`:""]})]},r.id)})})]})]})}const Z=a=>{const c=Number(a);return Number.isFinite(c)&&c>=1?Math.floor(c):null};function me({etiqueta:a,ayuda:c,frase:o,valor:s,porDefecto:t,maximo:b,onCambio:p}){const{t:f}=T(),x=l.useId(),g=s!==null,[r,u]=l.useState(String(s??""));l.useEffect(()=>{u(String(s??""))},[s]);const[w,n]=f(o).split("{n}");return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("label",{className:"flex items-center justify-between gap-2",htmlFor:x,children:[e.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-muted-foreground",children:[a,e.jsx(I,{texto:c})]}),e.jsx(U,{id:x,"aria-label":a,checked:g,onCheckedChange:d=>p(d?t:null)})]}),g&&e.jsxs("p",{className:"flex flex-wrap items-baseline gap-1 pl-0.5 text-[10px] leading-relaxed text-muted-foreground",children:[w,e.jsx("input",{type:"number",min:1,max:b,value:r,"aria-label":a,title:f("helpers_umbral_minimo"),onChange:d=>u(d.target.value),onBlur:()=>{const d=Math.min(Z(r)??t,b);u(String(d)),p(d)},className:"w-12 rounded-md border bg-background px-1 py-0.5 text-right text-[10px] tabular-nums"}),n]})]})}
1function As({helper:a,hasKey:c,onIrAUbicaciones:o}){var le,ie,ne,oe;const{language:s,t}=T(),[b,p]=l.useState(!1),[f,x]=l.useState(!1),[g,r]=l.useState(!1),u=async m=>{p(!0);try{await se(a.id,{bypassApprovals:m})}catch{j.error(t("helpers_ajustes_actualizar_error"))}finally{p(!1)}},w=m=>{if(m&&!a.bypassApprovals){r(!0);return}u(m)},{activeCompany:n}=Y(),d=String((n==null?void 0:n.mascotUrl)||"").trim(),[C,S]=l.useState(String((n==null?void 0:n.helperBudgetUsd)||"")),[A,N]=l.useState(!1),_=n,[i,v]=l.useState(!!(_!=null&&_.helperWeeklySummary)),y=(_==null?void 0:_.helperUbicaciones)||[],[k,B]=l.useState({cuentasCaducadas:!!((le=_==null?void 0:_.helperAlerts)!=null&&le.cuentasCaducadas),postsFallidos:!!((ie=_==null?void 0:_.helperAlerts)!=null&&ie.postsFallidos),ventasCaidaPct:Z((ne=_==null?void 0:_.helperAlerts)==null?void 0:ne.ventasCaidaPct),pedidosSinPagarDias:Z((oe=_==null?void 0:_.helperAlerts)==null?void 0:oe.pedidosSinPagarDias)}),h=async m=>{if(n!=null&&n.id){v(m);try{await H(n.id,{helperWeeklySummary:m})}catch{j.error(t("helpers_ajustes_guardar_error")),v(!m)}}},D=async m=>{if(n!=null&&n.id){B(m);try{await H(n.id,{helperAlerts:{cuentasCaducadas:m.cuentasCaducadas,postsFallidos:m.postsFallidos,ventasCaidaPct:m.ventasCaidaPct??0,pedidosSinPagarDias:m.pedidosSinPagarDias??0}})}catch{j.error(t("helpers_ajustes_guardar_error"))}}},ve=async()=>{if(!(n!=null&&n.id)||A)return;const m=Math.max(0,Number(C)||0);N(!0);try{await H(n.id,{helperBudgetUsd:m}),j.success(m>0?_e(t("helpers_ajustes_tope_puesto"),{n:m}):t("helpers_ajustes_sin_tope"))}catch{j.error(t("helpers_ajustes_tope_error"))}finally{N(!1)}},[W,re]=l.useState(!1),ye=async()=>{if(!(!(n!=null&&n.id)||W)){re(!0);try{await ue(n.id),j.success(t("helpers_ajustes_mascota_creada"))}catch(m){j.error(m instanceof Error?m.message:t("helpers_ajustes_crear_error"))}finally{re(!1)}}};return e.jsxs("div",{className:"rounded-2xl border bg-card p-4 shadow-sm",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[d?e.jsx("img",{src:d,alt:"",className:"h-12 w-12 shrink-0 rounded-2xl object-cover ring-1 ring-border"}):e.jsx(he,{id:a.id,emoji:"ð¤",size:"lg"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"truncate font-heading text-lg font-bold tracking-tight",children:a.name}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1.5",children:[e.jsxs(Ae,{variant:"secondary",className:"max-w-[220px] text-[10px]",children:[e.jsx(_s,{className:"mr-1 h-3 w-3 shrink-0"}),e.jsxs("span",{className:"truncate",children:[ee[a.provider]," · ",a.model]})]}),c?e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full chip-green px-2 py-0.5 text-[10px] font-medium",children:[e.jsx(ce,{className:"h-3 w-3"}),t("helpers_ajustes_api_key_lista")]}):e.jsxs(q,{to:"/settings?tab=apikeys",className:"inline-flex items-center gap-1 rounded-full chip-red px-2 py-0.5 text-[10px] font-medium hover:opacity-80",children:[e.jsx(V,{className:"h-3 w-3"}),t("helpers_ajustes_api_key_falta")]})]})]})]}),e.jsxs("button",{type:"button",onClick:()=>x(m=>!m),"aria-expanded":f,title:t("helpers_ajustes_pista"),className:"ml-auto inline-flex items-center gap-1.5 rounded-xl border px-3 py-1.5 text-xs text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground",children:[e.jsx(fs,{className:"h-3.5 w-3.5","aria-hidden":"true"}),t(f?"helpers_ajustes_cerrar":"helpers_ajustes_abrir"),e.jsx(gs,{className:`h-3.5 w-3.5 transition-transform ${f?"rotate-180":""}`,"aria-hidden":"true"})]})]}),f&&e.jsxs("div",{className:"mt-3 grid gap-2 border-t pt-3 sm:grid-cols-2 xl:grid-cols-3",children:[e.jsxs("label",{className:"flex items-center gap-3 rounded-xl border bg-muted/30 px-3 py-2",children:[a.bypassApprovals?e.jsx(Ne,{className:"h-4 w-4 shrink-0 text-primary"}):e.jsx(ce,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"flex items-center gap-1 text-xs font-medium leading-tight",children:[t("helpers_ajustes_sin_aprobacion"),e.jsx(I,{texto:t("helpers_ayuda_sin_aprobacion")})]}),e.jsx("p",{className:"text-[10px] leading-tight text-muted-foreground",children:a.bypassApprovals?t("helpers_ajustes_al_instante"):t("helpers_ajustes_pide_ok")})]}),b?e.jsx(P,{className:"h-4 w-4 animate-spin text-muted-foreground"}):e.jsx(U,{"aria-label":t("helpers_ajustes_pide_ok"),checked:a.bypassApprovals,onCheckedChange:w})]}),e.jsxs("label",{className:"flex items-center gap-3 rounded-xl border bg-muted/30 px-3 py-2",children:[e.jsx(js,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"flex items-center gap-1 text-xs font-medium leading-tight",children:[t("helpers_ajustes_tope_gasto"),e.jsx(I,{texto:t("helpers_ayuda_tope_gasto")})]}),e.jsx("p",{className:"text-[10px] leading-tight text-muted-foreground",children:t("helpers_ajustes_tope_gasto_pista")})]}),e.jsx("input",{type:"number",min:0,value:C,onChange:m=>S(m.target.value),onBlur:()=>void ve(),className:"w-20 rounded-lg border bg-background px-2 py-1 text-right text-xs",placeholder:"â"})]}),e.jsxs("label",{className:"flex items-center gap-3 rounded-xl border bg-muted/30 px-3 py-2",children:[e.jsx(bs,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"flex items-center gap-1 text-xs font-medium leading-tight",children:[t("helpers_ajustes_resumen_semanal"),e.jsx(I,{texto:t("helpers_ayuda_resumen_semanal")})]}),e.jsx("p",{className:"text-[10px] leading-tight text-muted-foreground",children:t("helpers_ajustes_resumen_semanal_pista")})]}),e.jsx(U,{"aria-label":t("helpers_ajustes_resumen_semanal"),checked:i,onCheckedChange:m=>void h(m)})]}),e.jsxs("div",{className:"flex flex-col gap-2 rounded-xl border bg-muted/30 px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ns,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsxs("p",{className:"flex items-center gap-1 text-xs font-medium leading-tight",children:[t("helpers_ajustes_alertas_diarias"),e.jsx(I,{texto:t("helpers_ayuda_alertas")})]})]}),e.jsxs("label",{className:"flex items-center justify-between gap-2",children:[e.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-muted-foreground",children:[t("helpers_ajustes_conexiones_caducadas"),e.jsx(I,{texto:t("helpers_ayuda_conexiones")})]}),e.jsx(U,{"aria-label":t("helpers_ajustes_conexiones_caducadas"),checked:k.cuentasCaducadas,onCheckedChange:m=>void D({...k,cuentasCaducadas:m})})]}),e.jsxs("label",{className:"flex items-center justify-between gap-2",children:[e.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-muted-foreground",children:[t("helpers_ajustes_posts_fallidos"),e.jsx(I,{texto:t("helpers_ayuda_posts_fallidos")})]}),e.jsx(U,{"aria-label":t("helpers_ajustes_posts_fallidos"),checked:k.postsFallidos,onCheckedChange:m=>void D({...k,postsFallidos:m})})]}),e.jsx(me,{etiqueta:t("helpers_ajustes_caida_ventas"),ayuda:t("helpers_ayuda_caida_ventas"),frase:"helpers_umbral_caida_frase",valor:k.ventasCaidaPct,porDefecto:20,maximo:95,onCambio:m=>void D({...k,ventasCaidaPct:m})}),e.jsx(me,{etiqueta:t("helpers_ajustes_pedidos_sin_cobrar"),ayuda:t("helpers_ayuda_pedidos_sin_cobrar"),frase:"helpers_umbral_pedidos_frase",valor:k.pedidosSinPagarDias,porDefecto:7,maximo:365,onCambio:m=>void D({...k,pedidosSinPagarDias:m})})]}),y.length>0&&e.jsx("div",{className:"border-t pt-2",children:e.jsxs("button",{type:"button",onClick:o,title:t("helpers_ubicaciones_enlace_pista"),className:"flex items-center gap-1.5 text-[11px] text-muted-foreground underline-offset-2 hover:text-foreground hover:underline",children:[e.jsx(ge,{className:"h-3.5 w-3.5","aria-hidden":"true"}),t("helpers_ubicaciones_enlace"),e.jsxs("span",{className:"text-muted-foreground
1/70",children:["(",y.length,")"]})]})}),e.jsxs(E,{type:"button",variant:"outline",size:"sm",onClick:()=>void ye(),disabled:W||!(n!=null&&n.id),title:t("helpers_ajustes_mascota_pista"),children:[W?e.jsx(P,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):e.jsx(L,{className:"mr-1.5 h-3.5 w-3.5"}),t(d?"helpers_ajustes_rehacer_mascota":"helpers_ajustes_generar_mascota")]})]}),e.jsx(De,{open:g,onOpenChange:r,children:e.jsxs(Ee,{children:[e.jsxs(Pe,{children:[e.jsx(Te,{children:t("helpers_ajustes_confirmar_titulo")}),e.jsx(Ie,{children:t("helpers_ajustes_confirmar_cuerpo")})]}),e.jsxs(Be,{children:[e.jsx(Le,{children:t("helpers_accion_cancelar")}),e.jsx(Ue,{onClick:()=>void u(!0),children:t("helpers_ajustes_confirmar_si")})]})]})})]})}function Zs(){const{user:a}=pe(),{activeCompany:c,hasPermission:o}=Y(),{t:s}=T(),t=o("helpers"),[b,p]=l.useState([]),[f,x]=l.useState("memory"),[g,r]=l.useState(!0),[u,w]=l.useState(null),[n,d]=l.useState([]),[C,S]=l.useState(!1);l.useEffect(()=>{!a||!t||Me(a.id,a.email||"").then(w)},[a,t]);const A=!!(u&&(a!=null&&a.id)&&u===a.id);l.useEffect(()=>{if(u){if(!A){d([]),S(!0);return}S(!1),we(ke(ze,"workspace_settings",u)).then(i=>{var y;const v=((y=i.data())==null?void 0:y.apiKeys)||{};d(xe.filter(k=>ys(v[k])))}).catch(()=>d([])).finally(()=>S(!0))}},[u,A]),l.useEffect(()=>{if(!c||!t||!u){p([]),r(!1);return}return r(!0),Ze(c.id,u,i=>{p(i),r(!1)})},[c==null?void 0:c.id,t,u]);const N=b[0]||null,_=N?A?n.includes(N.provider):!0:!1;return t?c?g||!C?e.jsx("div",{className:"flex min-h-[60vh] items-center justify-center",children:e.jsx(P,{className:"h-8 w-8 animate-spin text-primary"})}):!N&&!A?e.jsx("div",{className:"flex min-h-[60vh] items-center justify-center p-6",children:e.jsxs("div",{className:"max-w-sm rounded-2xl border bg-card p-8 text-center shadow-sm",children:[e.jsx(L,{className:"mx-auto mb-3 h-10 w-10 text-muted-foreground"}),e.jsx("h2",{className:"font-heading text-lg font-bold",children:s("helpers_none_yet_title")}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:s("helpers_none_yet_body").replace("{company}",c.name)})]})}):N?e.jsxs("div",{className:"flex h-[calc(100vh-4rem)] flex-col gap-4 p-4 md:p-6",children:[e.jsx(As,{helper:N,hasKey:_,onIrAUbicaciones:()=>{x("settings"),setTimeout(()=>{var i;(i=document.getElementById("helper-ubicaciones-titulo"))==null||i.scrollIntoView({behavior:"smooth",block:"center"})},120)}}),e.jsxs("div",{className:"grid min-h-0 flex-1 gap-4 lg:grid-cols-[1fr_340px]",children:[e.jsx("div",{className:"min-h-0",children:e.jsx(ss,{helper:N,hasKey:_})}),e.jsx("aside",{className:"min-h-0 rounded-2xl border bg-card p-3 shadow-sm",children:e.jsxs(He,{value:f,onValueChange:x,className:"flex h-full min-h-0 flex-col",children:[e.jsxs(Fe,{className:"grid w-full grid-cols-3",children:[e.jsxs(G,{value:"memory",className:"gap-1.5",children:[e.jsx(ae,{className:"h-3.5 w-3.5"}),s("helpers_tab_memory")]}),e.jsxs(G,{value:"activity",className:"gap-1.5",children:[e.jsx(be,{className:"h-3.5 w-3.5"}),s("helpers_tab_activity")]}),e.jsxs(G,{value:"settings",className:"gap-1.5",children:[e.jsx(je,{className:"h-3.5 w-3.5"}),s("helpers_tab_settings")]})]}),e.jsx(X,{value:"memory",className:"mt-3 min-h-0 flex-1 data-[state=inactive]:hidden",children:e.jsx(ws,{helperId:N.id})}),e.jsx(X,{value:"activity",className:"mt-3 min-h-0 flex-1 data-[state=inactive]:hidden",children:e.jsx(Cs,{helper:N})}),e.jsx(X,{value:"settings",className:"mt-3 min-h-0 flex-1 data-[state=inactive]:hidden",children:e.jsx(Ss,{helper:N,availableProviders:n})})]})})]})]}):e.jsx(Ds,{companyName:c.name,availableProviders:n,onCreate:async(i,v)=>{if(u)try{const y=await Ye({companyId:c.id,ownerUserId:u,name:s("helpers_default_name").replace("{company}",c.name),provider:i,model:v});let k=String(c.mascotPersonality||"").trim();if(!!!String(c.mascotUrl||"").trim())try{j.info("Creando la mascotaâ¦"),await ue(c.id)}catch{}y&&k&&await se(y,{systemPromptExtra:k}),j.success(s("helpers_created"))}catch{j.error(s("helpers_create_failed"))}}}):e.jsx("div",{className:"flex min-h-[60vh] items-center justify-center p-6",children:e.jsxs("div",{className:"max-w-sm rounded-2xl border bg-card p-8 text-center shadow-sm",children:[e.jsx(vs,{className:"mx-auto mb-3 h-10 w-10 text-muted-foreground"}),e.jsx("h2",{className:"font-heading text-lg font-bold",children:s("helpers_pick_company_title")}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:s("helpers_pick_company_body")}),e.jsx(E,{asChild:!0,variant:"outline",className:"mt-4",children:e.jsx(q,{to:"/companies",children:s("helpers_go_companies")})})]})}):e.jsx("div",{className:"flex min-h-[60vh] items-center justify-center p-6",children:e.jsxs("div",{className:"max-w-sm rounded-2xl border bg-card p-8 text-center shadow-sm",children:[e.jsx(Ne,{className:"mx-auto mb-3 h-10 w-10 text-muted-foreground"}),e.jsx("h2",{className:"font-heading text-lg font-bold",children:s("helpers_restricted_title")}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:s("helpers_restricted_body")})]})})}function Ds({companyName:a,availableProviders:c,onCreate:o}){const{t:s}=T(),t=c.length===0,b=c[0]||"claude",[p,f]=l.useState(b),[x,g]=l.useState(J[b]),[r,u]=l.useState(!1),w=d=>{const C=d;f(C),g(J[C])},n=async()=>{u(!0),await o(p,x),u(!1)};return e.jsx("div",{className:"flex min-h-[70vh] items-center justify-center p-4 md:p-6",children:e.jsxs(es.div,{variants:Oe,initial:"hidden",animate:"visible",className:"w-full max-w-md rounded-2xl border bg-card p-8 text-center shadow-sm",children:[e.jsx("div",{className:"mx-auto mb-4 flex h-16 w-16 items-center justify-center",children:e.jsx(he,{id:a,emoji:"ð¤",size:"xl"})}),e.jsxs("h2",{className:"font-heading text-xl font-bold tracking-tight",children:[s("helpers_create_for"),e.jsx("span",{className:"text-primary",children:a})]}),e.jsx("p",{className:"mx-auto mt-1.5 max-w-sm text-sm text-muted-foreground",children:s("helpers_create_intro")}),t?e.jsxs("div",{className:"mt-6 rounded-2xl border border-dashed p-5",children:[e.jsx(V,{className:"mx-auto mb-2 h-8 w-8 text-muted-foreground"}),e.jsx("p",{className:"text-sm font-medium",children:s("helpers_no_key_title")}),e.jsx("p",{className:"mx-auto mt-1 max-w-xs text-xs text-muted-foreground",children:s("helpers_no_key_body")}),e.jsx(E,{asChild:!0,className:"mt-3 gap-1.5",children:e.jsxs(q,{to:"/settings?tab=apikeys",children:[e.jsx(V,{className:"h-4 w-4"}),s("helpers_go_api_keys")]})})]}):e.jsxs("div",{className:"mt-6 space-y-3 text-left",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(M,{className:"text-xs",children:s("helpers_provider")}),e.jsxs(O,{value:p,onValueChange:w,children:[e.jsx(z,{className:"rounded-xl",children:e.jsx($,{})}),e.jsx(K,{children:c.map(d=>e.jsx(R,{value:d,children:ee[d]},d))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(M,{className:"text-xs",children:s("helpers_model")}),e.jsxs(O,{value:x,onValueChange:g,children:[e.jsx(z,{className:"rounded-xl",children:e.jsx($,{})}),e.jsx(K,{children:Q[p].map(d=>e.jsx(R,{value:d,children:d},d))})]})]}),e.jsxs(E,{onClick:n,disabled:r,className:"w-full gap-1.5",children:[r?e.jsx(P,{className:"h-4 w-4 animate-spin"}):e.jsx(te,{className:"h-4 w-4"}),s("helpers_create_button")]}),e.jsxs("p",{className:"flex items-center justify-center gap-1 text-center text-[11px] text-muted-foreground",children:[e.jsx(L,{className:"h-3 w-3"}),s("helpers_will_be_named"),e.jsx("span",{className:"font-medium",children:s("helpers_default_name").replace("{company}",a)})]})]})]})})}export{Zs 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.