1import{b as k,c4 as E,r as x,aI as f,s as o,c5 as N,j as e,L as u,i as y,G as z,F as q,H as C,J as F,K as L,Q as W,E as D,a2 as I,I as K,Z as Q,f as c}from"./index-CiJ62xMb.js";import{S as A,a as H,b as P,c as B,d as G}from"./select-z-1Oe9m2.js";import{T as R,a as U,b as v,c as h,d as V,e as b}from"./table-C9oTap3O.js";const J=["Landing","Website","Ecommerce"],Z=()=>{const{t:r}=k(),p=E(),[a,g]=x.useState(null),[i,j]=x.useState(""),[n,w]=x.useState(""),{data:d,isLoading:_}=f({queryKey:["admin_companies"],queryFn:async()=>{const{data:s,error:t}=await o.from("companies").select("id, name, branding_color, logo_url").order("name");if(t)throw t;return s}}),{data:l,isLoading:S}=f({queryKey:["admin_websites",a==null?void 0:a.id],queryFn:async()=>{if(!a)return[];const{data:s,error:t}=await o.from("company_websites").select("*").eq("company_id",a.id).order("created_at");if(t)throw t;return s},enabled:!!a}),m=N({mutationFn:async()=>{if(!a||!i||!n)return;const{error:s}=await o.from("company_websites").insert({company_id:a.id,url:i,site_type:n});if(s)throw s},onSuccess:()=>{p.invalidateQueries({queryKey:["admin_websites",a==null?void 0:a.id]}),j(""),w(""),c.success(r("admin.websiteAdded"))},onError:()=>c.error(r("admin.websiteError"))}),T=N({mutationFn:async s=>{const{error:t}=await o.from("company_websites").delete().eq("id",s);if(t)throw t},onSuccess:()=>{p.invalidateQueries({queryKey:["admin_websites",a==null?void 0:a.id]}),c.success(r("admin.websiteDeleted"))},onError:()=>c.error(r("admin.websiteError"))});return e.jsxs("div",{className:"max-w-5xl mx-auto",children:[e.jsx("h1",{className:"text-2xl font-semibold text-foreground tracking-wide mb-1",children:"Empresas"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-8",children:"Gestiona las empresas registradas en la plataforma."}),_?e.jsx("div",{className:"flex justify-center py-16",children:e.jsx(u,{className:"w-6 h-6 animate-spin text-muted-foreground"})}):d!=null&&d.length?e.jsx("div",{className:"border border-white/[0.06] rounded-lg overflow-hidden",children:e.jsxs(R,{children:[e.jsx(U,{children:e.jsxs(v,{className:"border-white/[0.06] hover:bg-transparent",children:[e.jsx(h,{className:"text-zinc-400 text-xs uppercase tracking-wider",children:r("admin.companyName")}),e.jsx(h,{className:"text-zinc-400 text-xs uppercase tracking-wider",children:r("admin.color")}),e.jsx(h,{className:"text-zinc-400 text-xs uppercase tracking-wider text-right",children:r("admin.actions")})]})}),e.jsx(V,{children:d.map(s=>e.jsxs(v,{className:"border-white/[0.06]",children:[e.jsx(b,{className:"text-foreground font-medium",children:s.name}),e.jsx(b,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-4 h-4 rounded-full border border-white/10",style:{backgroundColor:s.branding_color||"#00A3FF"}}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s.branding_color||"#00A3FF"})]})}),e.jsx(b,{className:"text-right",children:e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>g(s),className:"border-primary/30 text-primary hover:bg-primary/10 hover:text-primary",children:[e.jsx(z,{size:14,className:"mr-1.5"}),r("admin.manageSites")]})})]},s.id))})]})}):e.jsx("p",{className:"text-muted-foreground text-center py-16",children:r("admin.noCompanies")}),e.jsx(q,{open:!!a,onOpenChange:s=>!s&&g(null),children:e.jsxs(C,{className:"sm:max-w-lg bg-background border-white/[0.08]",children:[e.jsx(F,{children:e.jsxs(L,{className:"text-foreground",children:[a==null?void 0:a.name," â ",r("admin.sites")]})}),e.jsx("div",{className:"space-y-2 max-h-60 overflow-y-auto",children:S?e.jsx("div",{className:"flex justify-center py-4",children:e.jsx(u,{className:"w-5 h-5 animate-spin text-muted-foreground"})}):l!=null&&l.length?l.map(s=>e.jsxs("div",{className:"flex items-center justify-between gap-3 px-3 py-2.5 rounded-lg bg-white/[0.03] border border-white/[0.06]",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.jsx(W,{variant:"outline",className:"text-[10px] shrink-0 border-white/10",children:s.site_type||"â"}),e.jsx("a",{href:s.url.startsWith("http")?s.url:`https://${s.url}`,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-primary hover:underline truncate",children:s.url}),e.jsx(D,{size:12,className:"text-muted-foreground shrink-0"})]}),e.jsx("button",{onClick:()=>T.mutate(s.id),className:"text-zinc-500 hover:text-red-400 transition-colors p-1",children:e.jsx(I,{size:14})})]},s.id)):e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:r("admin.noWebsites")})}),e.jsxs("div",{className:"border-t border-white/[0.06] pt-4 mt-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:r("admin.addWebsite")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(K,{value:i,onChange:s=>j(s.target.value),placeholder:"https://example.com",className:"flex-1 bg-white/[0.03] border-white/[0.08]"}),e.jsxs(A,{value:n,onValueChange:w,children:[e.jsx(H,{className:"w-32 bg-white/[0.03] border-white/[0.08]",children:e.jsx(P,{placeholder:r("admin.type")})}),e.jsx(B,{children:J.map(s=>e.jsx(G,{value:s,children:s},s))})]})]}),e.jsxs(y,{onClick:()=>m.mutate(),disabled:!i||!n||m.isPending,className:"mt-3 w-full",children:[m.isPending?e.jsx(u,{size:14,className:"animate-spin mr-2"}):e.jsx(Q,{size:14,className:"mr-2"}),r("admin.addSite")]})]})]})})]})};export{Z 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.