import{r as l,P as b,c as g,U as j,k as w,h as v}from"./utils-B1oDxhJx.js";import{j as t}from"./chains-By83jz87.js";import{a as N,u as y}from"./use-panel-chain-ZDlIX6Z4.js";function z(e){return e.direction==="sell"}function S(e){return e.toLocaleString("en-US",{maximumSignificantDigits:3,maximumFractionDigits:3,roundingPriority:"lessPrecision"})}function $(e){return e>=1e9?`$${+(e/1e9).toPrecision(3)}B`:e>=1e6?`$${+(e/1e6).toPrecision(3)}M`:e>=1e3?`$${+(e/1e3).toPrecision(3)}K`:`$${e.toFixed(0)}`}function L(e){const s=parseFloat(e.target);return e.label==="Dev Sell"?s===0?"Any Amount":"Whole Amount":e.label==="Timed"?new Date(s*1e3).toLocaleString("en-US",{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}):e.label==="Trailing Stop Loss"?`${s}% trail`:e.label==="Claim"?"Fee Claim":`${$(s)} MC`}function C(){const[e,s]=l.useState([]),[r,o]=l.useState({});l.useEffect(()=>{const n=a=>{a.data?.type==="bloom-orders-data"&&(s(a.data.orders??[]),a.data.walletLabels&&o(a.data.walletLabels))};return window.addEventListener("message",n),()=>window.removeEventListener("message",n)},[]);const c=()=>{window.parent.postMessage({type:"bloom-orders-sidebar-close"},"*")};return t.jsxs("div",{className:"flex h-full w-full flex-col bg-black text-white",children:[t.jsxs("div",{className:"flex h-11 shrink-0 items-center justify-between border-b border-zinc-800/80 bg-zinc-900/50 px-3",children:[t.jsx("span",{className:"text-sm font-medium",children:"Active Orders"}),t.jsx("button",{type:"button",onClick:c,className:"rounded-md p-0.5 text-zinc-400 hover:bg-zinc-800 hover:text-white",children:t.jsx(b,{className:"size-4"})})]}),t.jsx("div",{className:"scrollbar-none flex-1 overflow-y-auto p-2",children:e.length===0?t.jsx("div",{className:"py-6 text-center text-[12px] text-zinc-600",children:"No active orders"}):t.jsx("div",{className:"space-y-1",children:e.map(n=>t.jsx(D,{order:n,walletLabels:r},n.id))})})]})}function D({order:e,walletLabels:s}){const{executeDeleteOrder:r,showToast:o}=N(),{chain:c}=y(),n=c.tokenIcon,[a,d]=l.useState(!1),m=z(e),u=e.amount,f=L(e),x=s[e.wallet_address]??null,h=e.label==="Dev Sell"||e.label==="Claim"?`${e.direction==="buy"?"Buy":"Sell"} on ${e.label}`:e.label,p=async()=>{if(!a){d(!0);try{const i=await r({order_id:e.id});i.success||o({message:i.error||"Failed to delete order",variant:"error"})}catch(i){o({message:i instanceof Error?i.message:"Failed to delete order",variant:"error"})}finally{d(!1)}}};return t.jsxs("div",{className:g("group flex w-full items-center justify-between gap-2 rounded-lg border-l-2 bg-zinc-900/50 px-3 py-2.5",m?"border-red-500/70":"border-emerald-500/70"),children:[t.jsxs("div",{className:"flex min-w-0 flex-col gap-0.5",children:[t.jsx("span",{className:"truncate text-xs font-medium text-zinc-200",children:h}),t.jsxs("span",{className:"text-[10px] text-zinc-500",children:[f,x&&` · ${x}`]})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[m?t.jsxs("span",{className:"text-[11px] font-medium whitespace-nowrap text-zinc-400 tabular-nums",children:[u,"%"]}):t.jsxs("div",{className:"flex items-center gap-1 text-[11px] font-medium text-zinc-400",children:[t.jsx(n,{className:"size-3"}),S(u)]}),t.jsx("button",{type:"button",onClick:p,disabled:a,title:"Delete order",className:"rounded-md p-0.5 text-zinc-500 hover:bg-zinc-800 hover:text-red-400 disabled:opacity-50",children:a?t.jsx(j,{className:"size-3.5 animate-spin"}):t.jsx(w,{className:"size-3.5"})})]})]})}v.createRoot(document.getElementById("root")).render(t.jsx(l.StrictMode,{children:t.jsx(C,{})}));
