import{f as b,b as f,r as i,j as e}from"./main-yCyLqVcf.js";import{S as o}from"./StatusPill-BaxYX9Mg.js";import{m as w}from"./proxy-DDs1xMqj.js";import"./index-qgskiNTF.js";async function k(t="",n=""){const r=new URLSearchParams;t&&r.set("search",t),n&&r.set("tag",n);const d=r.toString();return b(`/marketplace/plugins${d?`?${d}`:""}`)}async function S(t,n=!1){return f(`/marketplace/plugins/${t}/install`,{enable:n})}async function P(t){return f(`/marketplace/plugins/${t}/uninstall`,{})}async function C(t){return b(`/marketplace/plugins/${t}/scan`)}function U(){const[t,n]=i.useState([]),[r,d]=i.useState(""),[x,m]=i.useState(!1),[p,u]=i.useState(null),[j,g]=i.useState({}),h=async(s="")=>{m(!0),u(null);try{const a=await k(s);n(a.plugins)}catch(a){u((a==null?void 0:a.message)||"Erreur chargement marketplace")}finally{m(!1)}};i.useEffect(()=>{h()},[]);const y=async s=>{const a=await S(s,!0);n(l=>l.map(c=>c.id===s?a:c))},N=async s=>{const a=await P(s);n(l=>l.map(c=>c.id===s?{...c,...a}:c))},v=async s=>{const a=await C(s);g(l=>({...l,[s]:a}))};return e.jsxs(w.section,{className:"hud-panel scanline relative rounded-2xl p-4",initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.6},children:[e.jsx("div",{className:"absolute inset-0 bg-grid bg-[size:32px_32px] opacity-10"}),e.jsxs("div",{className:"relative space-y-5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"font-display text-base text-neon-cyan",children:"Plugin Marketplace"}),e.jsx("div",{className:"text-xs uppercase tracking-[0.3em] text-neon-cyan/60",children:"Secure Catalog"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("input",{className:"w-full rounded-xl border border-neon-cyan/20 bg-bg-800/80 px-3 py-2 text-xs text-white placeholder:text-white/40 focus:outline-none md:w-56",placeholder:"Search plugins",value:r,onChange:s=>d(s.target.value)}),e.jsx("button",{className:"rounded-full border border-neon-cyan/40 px-3 py-2 text-xs uppercase tracking-[0.3em] text-neon-cyan",onClick:()=>h(r),children:x?"Loading...":"Search"}),p&&e.jsx("span",{className:"text-xs text-red-300",children:p})]}),e.jsxs("div",{className:"grid gap-3",children:[t.length===0&&!x&&e.jsx("div",{className:"rounded-xl border border-neon-cyan/10 bg-bg-800/70 p-3 text-xs text-white/60",children:"No plugins found."}),t.slice(0,2).map(s=>{const a=j[s.id];return e.jsxs("div",{className:"rounded-xl border border-neon-cyan/10 bg-bg-800/70 p-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-white",children:s.name}),e.jsxs("span",{className:"text-xs text-white/60",children:["v",s.version]})]}),e.jsx("p",{className:"mt-1 text-xs text-white/60",children:s.description}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-2 text-[10px] text-white/60",children:[e.jsxs("span",{children:["Sandbox: ",s.sandbox]}),e.jsxs("span",{children:["Perm: ",s.permissions.join(", ")||"none"]})]})]}),e.jsxs("div",{className:"flex flex-col items-end gap-2",children:[e.jsx(o,{label:s.installed?"installed":"available",status:s.installed?"active":"idle"}),e.jsx(o,{label:s.enabled?"enabled":"disabled",status:s.enabled?"running":"offline"}),e.jsxs("div",{className:"flex gap-2",children:[s.installed?e.jsx("button",{className:"rounded-full border border-red-400/70 px-3 py-2 text-[10px] font-semibold uppercase tracking-[0.2em] text-red-300",onClick:()=>N(s.id),children:"Uninstall"}):e.jsx("button",{className:"rounded-full bg-neon-cyan px-3 py-2 text-[10px] font-semibold uppercase tracking-[0.2em] text-bg-900",onClick:()=>y(s.id),children:"Install"}),e.jsx("button",{className:"rounded-full border border-neon-cyan/40 px-3 py-2 text-[10px] uppercase tracking-[0.2em] text-neon-cyan",onClick:()=>v(s.id),children:"Scan"})]})]})]}),a&&e.jsxs("div",{className:"mt-3 rounded-xl border border-neon-cyan/10 bg-bg-900/60 p-3 text-xs text-white/70",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(o,{label:a.status,status:a.status==="ok"?"active":"idle"}),e.jsx("span",{children:"Scan results"})]}),a.warnings.length>0?e.jsx("ul",{className:"mt-2 space-y-1",children:a.warnings.map(l=>e.jsxs("li",{children:["• ",l]},l))}):e.jsx("p",{className:"mt-2",children:"No warnings detected."})]})]},s.id)})]})]})]})}export{U as MarketplacePanel};
