import{r as n,j as t,P as b,c as h,S as g,f as j,h as w,d as y}from"./solana-DqgBswAh.js";import{u as N}from"./use-panel-bridge-BiZ65WTV.js";function S(e){return e.direction==="sell"}function v(e){return e.toLocaleString("en-US",{maximumSignificantDigits:3,maximumFractionDigits:3,roundingPriority:"lessPrecision"})}function z(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 $(e,i){const a=parseFloat(e.target);if(e.label==="Dev Sell")return a===0?"Any Amount":"Whole Amount";if(e.label==="Timed")return new Date(a*1e3).toLocaleString("en-US",{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"});if(e.label==="Trailing Stop Loss")return`${a}% trail`;if(e.label==="Claim")return"Fee Claim";const r=a*i;return`${z(r)} MC`}function L(){const[e,i]=n.useState([]),[a,r]=n.useState(0),[o,c]=n.useState({});n.useEffect(()=>{const l=s=>{s.data?.type==="bloom-orders-data"&&(i(s.data.orders??[]),s.data.supply!=null&&r(s.data.supply),s.data.walletLabels&&c(s.data.walletLabels))};return window.addEventListener("message",l),()=>window.removeEventListener("message",l)},[]);const m=()=>{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:m,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(l=>t.jsx(D,{order:l,supply:a,walletLabels:o},l.id))})})]})}function D({order:e,supply:i,walletLabels:a}){const{executeDeleteOrder:r,showToast:o}=N(),[c,m]=n.useState(!1),l=S(e),s=parseFloat(e.amount),x=$(e,i),u=a[e.wallet_address]??null,f=e.label==="Dev Sell"||e.label==="Claim"?`${e.direction==="buy"?"Buy":"Sell"} on ${e.label}`:e.label,p=async()=>{if(!c){m(!0);try{const d=await r({order_id:e.id});d.success||o({message:d.error||"Failed to delete order",variant:"error"})}catch(d){o({message:d instanceof Error?d.message:"Failed to delete order",variant:"error"})}finally{m(!1)}}};return t.jsxs("div",{className:h("group flex w-full items-center justify-between gap-2 rounded-lg border-l-2 bg-zinc-900/50 px-3 py-2.5",l?"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:f}),t.jsxs("span",{className:"text-[10px] text-zinc-500",children:[x,u&&` · ${u}`]})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[l?t.jsxs("span",{className:"text-[11px] font-medium whitespace-nowrap text-zinc-400 tabular-nums",children:[s,"%"]}):t.jsxs("div",{className:"flex items-center gap-1 text-[11px] font-medium text-zinc-400",children:[t.jsx(g,{className:"size-3"}),v(s)]}),t.jsx("button",{type:"button",onClick:p,disabled:c,title:"Delete order",className:"rounded-md p-0.5 text-zinc-500 hover:bg-zinc-800 hover:text-red-400 disabled:opacity-50",children:c?t.jsx(j,{className:"size-3.5 animate-spin"}):t.jsx(w,{className:"size-3.5"})})]})]})}y.createRoot(document.getElementById("root")).render(t.jsx(n.StrictMode,{children:t.jsx(L,{})}));
