1import{r as l,j as e}from"./react-DmmmXvkf.js";import{u as O,a as N}from"./query-BEXY55w7.js";import{$ as Y,f as m,g as u,ae as J,B as h,A as M,S as Q,a as G,b as W,c as X,d as Z}from"./index-C1oWTp1R.js";import{T as ee,a as re,b as I,c as i,d as se,e as t}from"./table-J6rnOMWM.js";import{I as p}from"./input-CTSe_ZQa.js";import{L as o}from"./label-y6hAHYHS.js";import{T as te}from"./textarea-JBoVG7_K.js";import{B as R}from"./badge-Ax88e8v2.js";import{S as ae}from"./skeleton-B3U8IGPm.js";import{C as w}from"./CoinAmount-NqEC5dRb.js";import{u as ne}from"./i18n-DQg7CiDt.js";import{S as le}from"./send-BCr-ODVC.js";import{E as ie}from"./external-link-CU7laT39.js";import{R as oe}from"./refresh-cw-BrhrdZjd.js";import{T as de}from"./trash-2-W1ofATpH.js";import"./motion-BB-_2whf.js";import"./index-DYnXUCYV.js";const P=-1;async function x(s,j){return(await s.json().catch(()=>null))?.error||j}function Ce(){const{t:s,i18n:j}=ne(),{toast:a}=Y(),[d,S]=l.useState("free"),[g,C]=l.useState(""),[k,T]=l.useState(String(P)),[v,E]=l.useState(""),[b,L]=l.useState(""),[y,F]=l.useState(""),[B,D]=l.useState(""),c=O({queryKey:["trader-invests"],queryFn:async()=>{const r=await m(u("/api/trader/invests"));if(!r.ok)throw new Error(await x(r,s("traderInvests.loadError")));return r.json()}}),$=O({queryKey:["trader-chemistry-styles"],queryFn:async()=>{const r=await m(u("/api/trader/chemistry-styles"));if(!r.ok)throw new Error(await x(r,"styles_fetch_failed"));return(await r.json()).styles},staleTime:1/0}),A=c.data?.invests??[],z=()=>{C(""),T(String(P)),E(""),L(""),F(""),D("")},f=N({mutationFn:async()=>{const r=await m(u("/api/trader/invests"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({link:g.trim(),tier:d,chemistryId:Number(k),buyPrice:Number(v),sellPricePc:b?Number(b):void 0,sellPriceConsole:y?Number(y):void 0,comment:B.trim()||void 0})});if(!r.ok)throw new Error(await x(r,s("traderInvests.saveError")));return r.json()},onSuccess:()=>{a({title:s("traderInvests.published")}),z(),c.refetch()},onError:r=>a({title:r.message,variant:"destructive"})}),_=N({mutationFn:async r=>{const n=await m(u(`/api/trader/invests/${r}/repost`),{method:"POST"});if(!n.ok)throw new Error(await x(n,s("traderInvests.saveError")));return n.json()},onSuccess:()=>{a({title:s("traderInvests.reposted")}),c.refetch()},onError:r=>a({title:r.message,variant:"destructive"})}),q=N({mutationFn:async r=>{const n=await m(u(`/api/trader/invests/${r}`),{method:"DELETE"});if(!n.ok)throw new Error(await x(n,s("traderInvests.deleteError")));return n.json()},onSuccess:()=>{a({title:s("traderInvests.deleted")}),c.refetch()},onError:r=>a({title:r.message,variant:"destructive"})}),K=r=>{confirm(s("traderInvests.deleteConfirm",{player:r.playerName}))&&q.mutate(r.id)},H=Number(v),U=g.trim().length>10&&Number.isFinite(H)&&H>=1&&!f.isPending,V=r=>r?new Date(r).toLocaleDateString(j.language,{day:"2-digit",month:"short",hour:"2-digit",minute:"2-digit"}):null;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-3xl font-bold tracking-tight flex items-center gap-2",children:[e.jsx(J,{className:"w-6 h-6 text-primary"})," ",s("traderInvests.title")]}),e.jsx("p",{className:"text-muted-foreground",children:s("traderInvests.subtitle")})]}),e.jsxs("div",{className:"rounded-xl border border-white/5 bg-card/40 p-5 space-y-4",children:[e.jsx("h2",{className:"font-semibold",children:s("traderInvests.formTitle")}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:s("traderInvests.tierLabel")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(h,{type:"button",variant:d==="free"?"default":"outline",onClick:()=>S("free"),className:d==="free"?"bg-emerald-500 hover:bg-emerald-500/90 text-black":"",children:s("traderInvests.tierFree")}),e.jsx(h,{type:"button",variant:d==="premium"?"default":"outline",onClick:()=>S("premium"),className:d==="premium"?"bg-primary hover:bg-primary/90 text-primary-foreground":"",children:s("traderInvests.tierPremium")})]}),e.jsxs("p",{className:"text-xs text-muted-foreground flex items-center gap-1.5",children:[e.jsx(M,{className:"w-3.5 h-3.5 shrink-0"})," ",s("traderInvests.discordDelay")]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"trader-link",children:s("traderInvests.linkLabel")}),e.jsx(p,{id:"trader-link",value:g,onChange:r=>C(r.target.value),placeholder:"https://www.futbin.com/27/player/1078/fikayo-tomori",className:"bg-background/50"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("traderInvests.linkHint")})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"trader-buy",children:s("traderInvests.buyPriceLabel")}),e.jsx(p,{id:"trader-buy",type:"number",min:1,step:100,value:v,onCh
1ange:r=>E(r.target.value),className:"bg-background/50"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"trader-sell-pc",children:s("traderInvests.sellPcLabel")}),e.jsx(p,{id:"trader-sell-pc",type:"number",min:1,step:100,value:b,onChange:r=>L(r.target.value),className:"bg-background/50"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"trader-sell-console",children:s("traderInvests.sellConsoleLabel")}),e.jsx(p,{id:"trader-sell-console",type:"number",min:1,step:100,value:y,onChange:r=>F(r.target.value),className:"bg-background/50"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground -mt-2",children:s("traderInvests.sellHint")}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:s("traderInvests.chemistryLabel")}),e.jsxs(Q,{value:k,onValueChange:T,children:[e.jsx(G,{className:"bg-background/50",children:e.jsx(W,{placeholder:s("traderInvests.chemistryLabel")})}),e.jsx(X,{children:($.data??[]).map(r=>e.jsx(Z,{value:String(r.id),children:r.id===P?s("traderInvests.anyStyle"):r.name},r.id))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"trader-comment",children:s("traderInvests.commentLabel")}),e.jsx(te,{id:"trader-comment",value:B,onChange:r=>D(r.target.value),placeholder:s("traderInvests.commentPlaceholder"),rows:3,maxLength:1e3,className:"bg-background/50"})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(h,{onClick:()=>f.mutate(),disabled:!U,className:"bg-primary text-primary-foreground",children:[e.jsx(le,{className:"w-4 h-4 mr-2"}),f.isPending?s("traderInvests.publishing"):s("traderInvests.publish")]})})]}),c.isLoading?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(r=>e.jsx(ae,{className:"h-16 w-full bg-card rounded-md"},r))}):e.jsx("div",{className:"rounded-xl border border-white/5 bg-card/40 overflow-hidden",children:e.jsxs(ee,{children:[e.jsx(re,{className:"bg-secondary/30",children:e.jsxs(I,{className:"border-white/5",children:[e.jsx(i,{children:s("traderInvests.colPlayer")}),e.jsx(i,{children:s("traderInvests.colTier")}),e.jsx(i,{children:s("traderInvests.colBuy")}),e.jsx(i,{children:s("traderInvests.colSell")}),e.jsx(i,{children:s("traderInvests.colChemistry")}),e.jsx(i,{children:s("traderInvests.colPosted")}),e.jsx(i,{className:"text-right",children:s("traderInvests.colActions")})]})}),e.jsxs(se,{children:[A.map(r=>e.jsxs(I,{className:"border-white/5 hover:bg-white/5 align-top",children:[e.jsxs(t,{children:[e.jsx("div",{className:"font-medium",children:r.playerName}),e.jsxs("a",{href:r.link,target:"_blank",rel:"noreferrer",className:"text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1",children:[s("traderInvests.openOnFutbin")," ",e.jsx(ie,{className:"w-3 h-3"})]}),r.comment&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1 max-w-xs",children:r.comment})]}),e.jsx(t,{children:r.tier==="premium"?e.jsx(R,{variant:"outline",className:"text-primary border-primary/30 bg-primary/10",children:s("traderInvests.tierPremium")}):e.jsx(R,{variant:"outline",className:"text-emerald-400 border-emerald-400/30 bg-emerald-400/10",children:s("traderInvests.tierFree")})}),e.jsx(t,{children:e.jsx(w,{value:r.buyPrice})}),e.jsxs(t,{className:"text-sm",children:[r.sellPricePc!=null&&e.jsxs("div",{children:["PC ",e.jsx(w,{value:r.sellPricePc})]}),r.sellPriceConsole!=null&&e.jsxs("div",{children:["Console ",e.jsx(w,{value:r.sellPriceConsole})]}),r.sellPricePc==null&&r.sellPriceConsole==null&&e.jsx("span",{className:"text-muted-foreground",children:"â"})]}),e.jsx(t,{children:r.chemistryName||s("traderInvests.anyStyle")}),e.jsxs(t,{className:"text-sm",children:[V(r.postedAt)??e.jsx("span",{className:"text-muted-foreground",children:s("traderInvests.neverPosted")}),r.postCount>1&&e.jsx("div",{className:"text-xs text-muted-foreground",children:s("traderInvests.postCount",{count:r.postCount})})]}),e.jsx(t,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(h,{variant:"ghost",size:"icon",title:s("traderInvests.repost"),onClick:()=>_.mutate(r.id),disabled:_.isPending,children:e.jsx(oe,{className:"w-4 h-4 text-muted-foreground hover:text-foreground"})}),e.jsx(h,{variant:"ghost",size:"icon",title:s("traderInvests.deleteAction"),onClick:()=>K(r),disabled:q.isPending,children:e.jsx(de,{className:"w-4 h-4 text-destructive opacity-70 hover:opacity-100"})})]})})]},r.id)),A.length===0&&e.jsx(I,{children:e.jsx(t,{colSpan:7,className:"text-center py-8 text-muted-foreground",children:s("traderInvests.emptyState")})})]})]})})]})}export{Ce as DashboardTrader};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.