import{j as e}from"./ui-vendor-DUfjpZ4p.js";import{r as t,L as _}from"./react-vendor-DlVMRrtE.js";import{am as u,B as b,b4 as C,e as j,ba as S,C as y,k as B,m as L,d as k,at as c,I as o,b6 as I,s as v,t as l}from"./index-BKwmLAPt.js";import"./charts-vendor-wgDUSDZK.js";import"./supabase-vendor-Bd7R0Yn5.js";const z=()=>{const[f,m]=t.useState(!0),[x,h]=t.useState(!1),[r,g]=t.useState([]),p=async()=>{m(!0);const{data:s,error:a}=await v.from("importer_badge_weights").select("*").order("sort_order",{ascending:!0});a&&l({title:"Load failed",description:a.message,variant:"destructive"}),g(s||[]),m(!1)};t.useEffect(()=>{p()},[]);const i=(s,a)=>g(w=>w.map(n=>n.id===s?{...n,...a}:n)),N=async()=>{h(!0);try{for(const s of r){const{error:a}=await v.from("importer_badge_weights").update({score:Number(s.score)||0,badge_name:s.badge_name,sort_order:Number(s.sort_order)||0}).eq("id",s.id);if(a)throw a}l({title:"Saved",description:"Importer badge weights updated."}),await p()}catch(s){l({title:"Save failed",description:s.message,variant:"destructive"})}finally{h(!1)}},d=r.reduce((s,a)=>s+(Number(a.score)||0),0);return f?e.jsxs("div",{className:"flex items-center gap-2 p-6",children:[e.jsx(u,{className:"h-4 w-4 animate-spin"})," Loading…"]}):e.jsxs("div",{className:"space-y-6 max-w-4xl mx-auto",children:[e.jsx(b,{asChild:!0,variant:"ghost",size:"sm",children:e.jsxs(_,{to:"/portal/importer-network/admin/dashboard",children:[e.jsx(C,{className:"h-4 w-4 mr-1"})," Back to dashboard"]})}),e.jsxs("div",{className:"relative overflow-hidden rounded-2xl bg-navy-gradient text-white p-6 shadow-xl",children:[e.jsx("div",{className:"absolute inset-0 opacity-10 bg-[radial-gradient(circle_at_70%_30%,white,transparent_45%)]"}),e.jsxs("div",{className:"relative flex flex-wrap items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs(j,{className:"bg-white/15 text-white border-white/20 mb-2 gap-1",children:[e.jsx(S,{className:"h-3 w-3"})," Trust Score Engine"]}),e.jsx("h1",{className:"font-heading text-2xl md:text-3xl font-bold",children:"Importer Badge Weights"}),e.jsx("p",{className:"text-white/70 text-sm mt-1 max-w-xl",children:"Tune the points awarded for each verification badge. The sum is the maximum trust score an importer can earn from verification badges (recommended: 100)."})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:"text-xs uppercase text-white/60 tracking-wider",children:"Current Maximum"}),e.jsx("div",{className:"font-heading text-4xl font-bold text-accent",children:d}),e.jsx("div",{className:"text-xs text-white/60",children:"/ 100 recommended"})]})]})]}),e.jsxs(y,{children:[e.jsx(B,{children:e.jsx(L,{children:"Badge Scoring"})}),e.jsxs(k,{className:"space-y-3",children:[r.map(s=>e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-12 gap-3 items-end border border-border rounded-lg p-3",children:[e.jsxs("div",{className:"md:col-span-5",children:[e.jsx(c,{className:"text-xs",children:"Badge name"}),e.jsx(o,{value:s.badge_name,onChange:a=>i(s.id,{badge_name:a.target.value})}),e.jsx("div",{className:"text-[10px] text-muted-foreground mt-1 font-mono",children:s.badge_code})]}),e.jsxs("div",{className:"md:col-span-3",children:[e.jsx(c,{className:"text-xs",children:"Score"}),e.jsx(o,{type:"number",min:0,max:100,value:s.score,onChange:a=>i(s.id,{score:Number(a.target.value)})})]}),e.jsxs("div",{className:"md:col-span-2",children:[e.jsx(c,{className:"text-xs",children:"Sort order"}),e.jsx(o,{type:"number",value:s.sort_order,onChange:a=>i(s.id,{sort_order:Number(a.target.value)})})]}),e.jsx("div",{className:"md:col-span-2 text-right",children:e.jsxs(j,{className:"bg-accent/20 text-accent border-accent/30",children:[s.score," pts"]})})]},s.id)),e.jsxs("div",{className:"flex items-center justify-between pt-3 border-t border-border",children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:["Max attainable score: ",e.jsx("span",{className:"font-bold text-foreground",children:d}),d!==100&&e.jsx("span",{className:"ml-2 text-amber-600",children:"(Tip: keep close to 100 so scores read as a familiar /100.)"})]}),e.jsxs(b,{onClick:N,disabled:x,children:[x?e.jsx(u,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(I,{className:"h-4 w-4 mr-2"}),"Save Weights"]})]})]})]})]})};export{z as default};
