import{f as b,b as f,r as i,j as e}from"./index-CnhUkfW3.js";import{S as o}from"./StatusPill-BHFBsi9V.js";import{m as k}from"./proxy-DCqCEQlg.js";async function S(t="",l=""){const c=new URLSearchParams;t&&c.set("search",t),l&&c.set("tag",l);const d=c.toString();return b(`/marketplace/plugins${d?`?${d}`:""}`)}async function P(t,l=!1){return f(`/marketplace/plugins/${t}/install`,{enable:l})}async function C(t){return f(`/marketplace/plugins/${t}/uninstall`,{})}async function $(t){return b(`/marketplace/plugins/${t}/scan`)}function U({className:t=""}){const[l,c]=i.useState([]),[d,j]=i.useState(""),[x,m]=i.useState(!1),[p,u]=i.useState(null),[g,y]=i.useState({}),h=async(s="")=>{m(!0),u(null);try{const a=await S(s);c(a.plugins)}catch(a){u((a==null?void 0:a.message)||"Erreur chargement marketplace")}finally{m(!1)}};i.useEffect(()=>{h()},[]);const N=async s=>{const a=await P(s,!0);c(n=>n.map(r=>r.id===s?a:r))},v=async s=>{const a=await C(s);c(n=>n.map(r=>r.id===s?{...r,...a}:r))},w=async s=>{const a=await $(s);y(n=>({...n,[s]:a}))};return e.jsxs(k.section,{className:`hud-panel scanline relative rounded-2xl p-4 ${t}`,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:d,onChange:s=>j(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(d),children:x?"Loading...":"Search"}),p&&e.jsx("span",{className:"text-xs text-red-300",children:p})]}),e.jsxs("div",{className:"grid gap-3",children:[l.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."}),l.slice(0,2).map(s=>{const a=g[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:()=>v(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:()=>N(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:()=>w(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(n=>e.jsxs("li",{children:["• ",n]},n))}):e.jsx("p",{className:"mt-2",children:"No warnings detected."})]})]},s.id)})]})]})]})}export{U as MarketplacePanel};
