改用高德地图附近 POI 查询发货地,移除闲鱼定位接口调用。发货地改为可选项,虚拟商品可直接发布;修正闲鱼网页版要求的纬度、经度 GPS 顺序,并补充前端映射与发布测试。
20 lines
334 KiB
JavaScript
20 lines
334 KiB
JavaScript
import{j as e,r,b as Me,c as xa,d as Fa}from"./react-vendor-C_od1ZSF.js";import{L as Ba,U as ma,M as rs,C as ns,B as pa,S as ua,Z as is,a as jt,b as bs,c as fs,d as ys,e as za,f as at,A as Ls,D as Ua,g as Os,P as ha,h as Tt,E as ga,T as Wa,i as Ja,j as Ee,X as Te,k as Va,l as Qa,m as js,n as ba,o as Ge,Q as Zt,p as xt,q as Qe,r as yt,s as Et,t as Is,R as Be,u as fa,v as Ga,w as Je,K as Ka,x as dt,y as st,z as Ye,F as As,G as Nt,H as _t,I as $t,J as ya,N as Ha,O as Rs,V as Ps,W as Za,Y as Ya,_ as Xa,$ as el,a0 as Yt,a1 as qt,a2 as os,a3 as tl,a4 as sl,a5 as cs,a6 as $s,a7 as al,a8 as ll,a9 as Dt,aa as Es,ab as Vt,ac as ja,ad as rl,ae as nl,af as Kt,ag as _a,ah as il,ai as ol,aj as cl,ak as dl,al as xl,am as ml,an as Ds}from"./icons-vendor-DF3hof7q.js";import{R as Ft,B as pl,X as Ts,Y as Ms,T as Bt,a as ul,C as Xt,A as hl,b as gl,c as bl,P as qs,d as Fs,L as fl}from"./charts-vendor-BxxJOyEX.js";import"./vendor-D-Edl3pr.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const x of document.querySelectorAll('link[rel="modulepreload"]'))o(x);new MutationObserver(x=>{for(const v of x)if(v.type==="childList")for(const k of v.addedNodes)k.tagName==="LINK"&&k.rel==="modulepreload"&&o(k)}).observe(document,{childList:!0,subtree:!0});function l(x){const v={};return x.integrity&&(v.integrity=x.integrity),x.referrerPolicy&&(v.referrerPolicy=x.referrerPolicy),x.crossOrigin==="use-credentials"?v.credentials="include":x.crossOrigin==="anonymous"?v.credentials="omit":v.credentials="same-origin",v}function o(x){if(x.ep)return;x.ep=!0;const v=l(x);fetch(x.href,v)}})();const yl=({className:t="w-full h-full text-white"})=>e.jsx("svg",{className:t,viewBox:"0 0 256 256","aria-hidden":"true",children:e.jsx("g",{stroke:"none",fill:"none",fillRule:"evenodd",children:e.jsx("path",{d:"M121.73,57.0003 C138.901,57.0003 154.897,65.5053 164.52,79.7493 C166.029,81.9823 165.441,85.0143 163.209,86.5233 C160.976,88.0323 157.944,87.4433 156.436,85.2113 C148.629,73.6553 135.655,66.7563 121.73,66.7563 C104.076789,66.7563 88.6201962,77.6596007 82.5581814,93.8184545 C83.9120803,93.7133631 85.2800264,93.66 86.6602,93.66 C111.537727,93.66 132.442611,110.997575 137.926382,134.224255 L162.5425,92.109 L162.615557,91.9879406 L162.756884,91.77367 L162.911804,91.5639102 L162.98657,91.4716759 C163.351845,91.025169 163.786059,90.6571744 164.264191,90.3738733 L164.550153,90.2178351 L164.729252,90.1315693 L164.989203,90.021723 L165.230265,89.9354653 L165.542393,89.8445739 C165.666021,89.8126706 165.790834,89.7857324 165.916565,89.7637431 L166.116517,89.7342499 C166.29505,89.7098142 166.475001,89.6957386 166.655596,89.6918808 L166.7539,89.693 C196.8909,89.693 221.4079,114.21 221.4079,144.347 C221.4079,174.482 196.8909,199 166.7539,199 L125.0869,199 C122.3919,199 120.2079,196.815 120.2079,194.122 C120.2079,191.429 122.3919,189.244 125.0869,189.244 L166.7539,189.244 C191.5109,189.244 211.6519,169.104 211.6519,144.347 C211.6519,120.513406 192.985349,100.957891 169.504046,99.5322548 L112.7745,196.584 C111.8995,198.08 110.2965,199 108.5635,199 L86.6602,199 C57.6182,199 33.9902,175.373 33.9902,146.33 C33.9902,122.475163 49.9316132,102.273061 71.7206298,95.817503 L71.9446339,94.967678 C78.0600632,72.5405324 98.33054,57.0003 121.73,57.0003 Z M86.6602,103.417 C62.9972,103.417 43.7462,122.667 43.7462,146.33 C43.7462,169.992 62.9972,189.244 86.6602,189.244 L105.7645,189.244 L129.869462,148.004782 C129.678439,147.482425 129.5742,146.918336 129.5742,146.33 C129.5742,122.667 110.3232,103.417 86.6602,103.417 Z",fill:"currentColor"})})}),ds=({sizeClass:t="w-12 h-12",logoClassName:s="w-full h-full text-white"})=>e.jsxs("div",{className:"relative z-10 flex items-center justify-center",children:[e.jsx("div",{className:"absolute -inset-1 bg-blue-500/20 rounded-xl blur opacity-25"}),e.jsxs("div",{className:`relative ${t} rounded-xl flex items-center justify-center group-hover:scale-105 transition-transform duration-300`,children:[e.jsxs("svg",{className:"absolute inset-0 w-full h-full",viewBox:"0 0 120 120","aria-hidden":"true",children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"login-squircle-gradient",x1:"0",y1:"0",x2:"1",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"rgb(var(--color-brand))"}),e.jsx("stop",{offset:"100%",stopColor:"rgb(var(--color-brand-light))"})]})}),e.jsx("path",{d:"M 114.00 60.00 L 113.83 71.48 L 113.31 78.16 L 112.44 83.67 L 111.22 88.46 L 109.66 92.71 L 107.75 96.49 L 105.48 99.87 L 102.86 102.86 L 99.87 105.48 L 96.49 107.75 L 92.71 109.66 L 88.46 111.22 L 83.67 112.44 L 78.16 113.31 L 71.48 113.83 L 60.00 114.00 L 48.52 113.83 L 41.84 113.31 L 36.33 112.44 L 31.54 111.22 L 27.29 109.66 L 23.51 107.75 L 20.13 105.48 L 17.14 102.86 L 14.52 99.87 L 12.25 96.49 L 10.34 92.71 L 8.78 88.46 L 7.56 83.67 L 6.69 78.16 L 6.17 71.48 L 6.00 60.00 L 6.17 48.52 L 6.69 41.84 L 7.56 36.33 L 8.78 31.54 L 10.34 27.29 L 12.25 23.51 L 14.52 20.13 L 17.14 17.14 L 20.13 14.52 L 23.51 12.25 L 27.29 10.34 L 31.54 8.78 L 36.33 7.56 L 41.84 6.69 L 48.52 6.17 L 60.00 6.00 L 71.48 6.17 L 78.16 6.69 L 83.67 7.56 L 88.46 8.78 L 92.71 10.34 L 96.49 12.25 L 99.87 14.52 L 102.86 17.14 L 105.48 20.13 L 107.75 23.51 L 109.66 27.29 L 111.22 31.54 L 112.44 36.33 L 113.31 41.84 L 113.83 48.52 Z",fill:"url(#login-squircle-gradient)"})]}),e.jsx("div",{className:"relative z-10 flex items-center justify-center w-full h-full",children:e.jsx(yl,{className:s})})]})]}),jl=({activeTab:t,isAdmin:s=!1,collapsed:l,onToggleCollapsed:o,onNavigate:x,onLogout:v})=>{const k=[{id:"dashboard",icon:Ba,label:"仪表盘"},{id:"accounts",icon:ma,label:"账号管理"},{id:"chat",icon:rs,label:"在线聊天"},{id:"cards",icon:ns,label:"卡密库存"},{id:"items",icon:pa,label:"商品列表"},{id:"orders",icon:ua,label:"订单管理"},{id:"rules",icon:is,label:"自动化规则"},{id:"notifications",icon:jt,label:"通知设置"},...s?[{id:"settings",icon:bs,label:"系统与AI"}]:[]];return e.jsxs("aside",{className:`fixed inset-y-0 left-0 z-20 flex flex-col border-r border-slate-200/80 bg-white/95 shadow-sidebar backdrop-blur-xl transition-[width] duration-300 ${l?"w-16":"w-64"}`,children:[e.jsxs("div",{className:`flex h-20 items-center border-b border-slate-100 ${l?"justify-center px-2":"gap-3 px-5"}`,children:[e.jsx(ds,{sizeClass:"h-10 w-10"}),!l&&e.jsxs("div",{className:"min-w-0 leading-tight",children:[e.jsx("div",{className:"truncate text-base font-black tracking-tight text-slate-950",children:"Ydisks 闲鱼助手"}),e.jsx("div",{className:"mt-1 text-[10px] font-extrabold uppercase tracking-[0.22em] text-sky-600",children:"Operations"})]})]}),e.jsx("nav",{className:`flex-1 space-y-1.5 overflow-y-auto py-5 ${l?"px-2":"px-3"}`,"aria-label":"主导航",children:k.map(A=>{const b=A.icon,O=t===A.id;return e.jsxs("button",{type:"button",title:l?A.label:void 0,"aria-label":A.label,"aria-current":O?"page":void 0,onClick:()=>x(A.id),className:`group relative flex h-11 w-full items-center rounded-xl transition-colors ${l?"justify-center":"gap-3 px-3.5"} ${O?"bg-brand text-white shadow-brand-active":"text-slate-500 hover:bg-slate-100 hover:text-slate-900"}`,children:[e.jsx(b,{className:`h-[19px] w-[19px] shrink-0 ${O?"text-white":"text-slate-400 group-hover:text-slate-700"}`}),!l&&e.jsx("span",{className:"truncate text-sm font-bold",children:A.label}),O&&!l&&e.jsx("span",{className:"ml-auto h-1.5 w-1.5 rounded-full bg-white/90"})]},A.id)})}),e.jsxs("div",{className:`space-y-2 border-t border-slate-100 p-2 ${l?"":"p-3"}`,children:[e.jsxs("button",{type:"button",onClick:o,title:l?"展开侧边栏":"收起侧边栏","aria-label":l?"展开侧边栏":"收起侧边栏",className:`flex h-10 w-full items-center rounded-xl text-slate-500 transition-colors hover:bg-slate-100 hover:text-slate-900 ${l?"justify-center":"gap-3 px-3"}`,children:[l?e.jsx(fs,{className:"h-5 w-5"}):e.jsx(ys,{className:"h-5 w-5"}),!l&&e.jsx("span",{className:"text-sm font-bold",children:"收起侧边栏"})]}),e.jsxs("button",{type:"button",onClick:v,title:l?"退出登录":void 0,"aria-label":"退出登录",className:`flex h-10 w-full items-center rounded-xl text-slate-500 transition-colors hover:bg-red-50 hover:text-red-600 ${l?"justify-center":"gap-3 px-3"}`,children:[e.jsx(za,{className:"h-5 w-5"}),!l&&e.jsx("span",{className:"text-sm font-bold",children:"退出登录"})]})]})]})},_l=3e4,Nl=10*6e4;let es=!1;const Na=()=>{es||typeof window>"u"||(es=!0,window.dispatchEvent(new Event("auth:logout")),queueMicrotask(()=>{es=!1}))},vl=t=>{if(!t)return"";const s=new URLSearchParams;for(const[o,x]of Object.entries(t))x!=null&&s.set(o,String(x));const l=s.toString();return l?`?${l}`:""},Ht=async(t,s,l={})=>{var O;const o=vl(l.params),x=`${s}${o}`,v=va(l.signal,l.timeoutMs??_l);let k;try{k=await fetch(x,{method:t,credentials:"include",signal:v.signal,headers:{...l.body===void 0?{}:{"Content-Type":"application/json"}},body:l.body===void 0?void 0:JSON.stringify(l.body)})}catch(j){throw v.signal.aborted?new Error((O=l.signal)!=null&&O.aborted?"请求已取消":"请求超时,请稍后重试"):j}finally{v.cleanup()}const b=(k.headers.get("content-type")||"").includes("application/json");if(!k.ok){k.status===401&&!l.skipAuthLogout&&Na();const j=b?await k.json().catch(()=>{}):await k.text().catch(()=>{}),V=typeof j=="string"?j:(j==null?void 0:j.detail)||(j==null?void 0:j.message)||(j==null?void 0:j.msg);throw new Error(V||`请求失败: ${k.status}`)}return b?await k.json():await k.text()},Ie=async(t,s,l)=>Ht("GET",t,{params:s,...l}),Oe=async(t,s,l)=>Ht("POST",t,{body:s,...l}),Fe=async(t,s,l)=>Ht("PUT",t,{body:s,...l}),Ke=async(t,s,l)=>Ht("DELETE",t,{params:s,...l}),wt=async(t,s,l={})=>{var b;const o=va(l.signal,l.timeoutMs??Nl);let x;try{x=await fetch(t,{method:"POST",credentials:"include",signal:o.signal,body:s})}catch(O){throw o.signal.aborted?new Error((b=l.signal)!=null&&b.aborted?"请求已取消":"上传超时,请稍后重试"):O}finally{o.cleanup()}const A=(x.headers.get("content-type")||"").includes("application/json")?await x.json().catch(()=>{}):await x.text().catch(()=>{});if(!x.ok){x.status===401&&Na();const O=typeof A=="string"?A:(A==null?void 0:A.detail)||(A==null?void 0:A.message)||(A==null?void 0:A.msg),j=new Error(O||"请求失败: "+x.status);throw j.payload=A,j}return A},va=(t,s)=>{const l=new AbortController,o=()=>l.abort(t==null?void 0:t.reason);t!=null&&t.aborted?o():t==null||t.addEventListener("abort",o,{once:!0});const x=globalThis.setTimeout(()=>l.abort(new DOMException("timeout","TimeoutError")),Math.max(1,s));return{signal:l.signal,cleanup:()=>{globalThis.clearTimeout(x),t==null||t.removeEventListener("abort",o)}}},Qt=t=>{const s=t.getFullYear(),l=String(t.getMonth()+1).padStart(2,"0"),o=String(t.getDate()).padStart(2,"0");return`${s}-${l}-${o}`},_s=(t,s)=>{const l=new Date(t);return l.setHours(12,0,0,0),l.setDate(l.getDate()+s),l},xs=(t,s)=>({startDate:Qt(_s(t,-(s-1))),endDate:Qt(t)}),Bs=(t,s=new Date,l="",o="")=>{if(t==="custom"&&l&&o){if(l>o)throw new Error("开始日期不能晚于结束日期");return{startDate:l,endDate:o}}return t==="yesterday"?xs(_s(s,-1),1):xs(s,t==="3days"?3:t==="30days"?30:t==="today"?1:7)},wl=t=>{const s=new Date(`${t.startDate}T12:00:00`),l=new Date(`${t.endDate}T12:00:00`),o=Math.round((l.getTime()-s.getTime())/864e5)+1,x=_s(s,-1);return xs(x,o)},kl=t=>{const s={...t};if("renewal_log_retention_days"in s){const l=Number(s.renewal_log_retention_days);s.renewal_log_retention_days=Number.isFinite(l)?l:10}return s},Cl=async t=>Oe("/login",t,{skipAuthLogout:!0}),Sl=async t=>Oe("/initialize",{password:t},{skipAuthLogout:!0}),wa=async()=>Ie("/verify"),Ll=async()=>Oe("/logout",{}),Ol=async t=>Fe("/account/credentials",t),Il=(t,s)=>{const l=t.avatar_url||"";if(!l)return"";try{const o=new URL(l,window.location.origin);return o.hostname.endsWith("alicdn.com")&&o.searchParams.set("_v",s),o.toString()}catch{return l}},Mt=async t=>{const s=await Ie("/cookies/details",void 0,t),l=Date.now().toString();return s.map(o=>({id:o.id,value:"",cookie:"",enabled:o.enabled,auto_confirm:o.auto_confirm,remark:o.remark,note:o.remark,pause_duration:o.pause_duration,paused_until:Number(o.paused_until||0),paused:o.paused===!0,username:o.username||"",login_password:"",show_browser:o.show_browser===!0||o.show_browser===1||o.show_browser==="1"||o.show_browser==="true",nickname:o.nickname||o.remark||`账号 ${o.id.substring(0,6)}`,avatar_url:Il(o,l),profile_error:o.profile_error||"",ai_enabled:!1,auto_rate_enabled:o.auto_rate_enabled===!0||o.auto_rate_enabled===1,rate_content:o.rate_content||"不错的买家,交易愉快",auto_polish_enabled:o.auto_polish_enabled===!0||o.auto_polish_enabled===1,polish_time:o.polish_time||"03:00",last_rate_scan_at:Number(o.last_rate_scan_at||0),last_polish_date:o.last_polish_date||"",last_polish_at:Number(o.last_polish_at||0)}))},Al=async t=>Ie(`/api/account-tasks/${t}`),zs=async(t,s)=>Fe(`/api/account-tasks/${t}`,s),Rl=async(t,s)=>Oe(`/api/account-tasks/${t}/run`,{task_type:s},{timeoutMs:12e4}),ts=async(t,s,l,o=!1)=>{const x=await Ie("/api/chat/sessions",{account_id:t,cursor:s,refresh:o?1:void 0},o?{timeoutMs:6e4,...l}:l);return{sessions:x.sessions||[],has_more:x.has_more===!0,next_cursor:x.next_cursor}},ms=async(t,s,l,o,x)=>{const v=await Ie("/api/chat/messages",{account_id:t,chat_id:s,cursor:l,before_id:o},x);return{messages:v.messages||[],has_more:v.has_more===!0,next_cursor:v.next_cursor,session:v.session}},Pl=async(t,s,l,o)=>(await ms(t,s,void 0,l,o)).messages,$l=async t=>Oe("/api/chat/messages",t),El=async t=>{const s=new FormData;return Object.entries(t).forEach(([l,o])=>s.append(l,o)),wt("/api/chat/images",s,{timeoutMs:12e4})},Us=async(t,s)=>Oe("/api/chat/read",{account_id:t,chat_id:s}),ps=async t=>Ie("/cookies/runtime-status",void 0,t),Dl=async t=>Oe("/qr-login/generate",void 0,t),Tl=async(t,s)=>Ie(`/qr-login/check/${t}`,void 0,{signal:s,timeoutMs:1e4}),Ml=async(t,s)=>Oe(`/qr-login/complete-verification/${t}`,{target_account_id:s||""}),ql=async(t,s)=>Fe(`/cookies/${t}/status`,{enabled:s}),Fl=async t=>Ke(`/cookies/${t}`),Bl=async(t,s)=>Fe(`/cookies/${t}/pause-duration`,{pause_duration:s}),zl=async(t,s)=>Fe(`/cookies/${t}/settings`,s),Ul=async t=>Ie(`/cookies/${t}/long-login`),Wl=async(t,s)=>Fe(`/cookies/${t}/long-login`,{enabled:s}),Jl=async t=>Oe("/password-login",t),Vl=async(t,s)=>Ie(`/password-login/check/${t}`,void 0,{signal:s,timeoutMs:1e4}),Ql=async t=>Ke(`/password-login/cancel/${t}`),Gl=async t=>Oe(`/cookies/${t}/refresh-profile`,{}),Kl=async t=>Ie("/ai-reply-settings",void 0,t),ka=t=>{const s=String(t||"");return s==="paid"?"pending_ship":["processing","pending_ship","shipped","completed","cancelled","refunding"].includes(s)?s:"unknown"},Hl=async(t,s,l=1,o=20,x)=>{const v={page:l,page_size:o};t&&(v.cookie_id=t),s&&s!=="all"&&(v.status=s),x!=null&&x.trim()&&(v.search=x.trim());const k=await Ie("/api/orders",v),b=(k.orders||k.data||[]).map(O=>({...O,id:O.id||O.order_id,status:ka(O.status||O.order_status),quantity:Number(O.quantity||1)}));return{success:!0,data:b,total:k.total||b.length,page:k.page||l,page_size:k.page_size||o,total_pages:k.total_pages||1}},Zl=async(t,s)=>Fe(`/api/orders/${t}`,s),Yl=async t=>Ke(`/api/orders/${t}`),Xl=async(t,s)=>{const l=new FormData;return t&&l.append("cookie_id",t),s&&l.append("status",s),wt("/api/orders/refresh",l)},er=async t=>Oe(`/api/orders/${t}/refresh`),tr=async(t,s)=>Oe("/api/orders/manual-ship",{order_ids:t,ship_mode:s}),sr=async t=>t instanceof FormData?wt("/api/orders/import",t):Oe("/api/orders/import",t),ar=async()=>Ie("/dashboard/stats"),Ws=async(t=7)=>{let s;if(typeof t=="number"){const l=new Date,o=new Date;o.setDate(o.getDate()-t),s={start_date:Qt(o),end_date:Qt(l)}}else s=t;return Ie("/analytics/orders",{...s,timezone_offset_minutes:-new Date().getTimezoneOffset()})},lr=async t=>{const s=await Ie("/analytics/orders/valid",{start_date:t.start_date,end_date:t.end_date,timezone_offset_minutes:-new Date().getTimezoneOffset()}),o=(Array.isArray(s)?s:s.orders||[]).map(x=>({...x,id:x.id||x.order_id,status:ka(x.status||x.order_status),quantity:Number(x.quantity||1)}));return{orders:o,total:Array.isArray(s)?o.length:Number(s.total??o.length),truncated:Array.isArray(s)?!1:s.truncated===!0}},rr=t=>{let s=t.api_config;if(typeof s=="string"&&s.trim())try{s=JSON.parse(s)}catch{s=void 0}return{...t,api_config:s||void 0}},Ca=t=>({...t,api_config:t.api_config?JSON.stringify(t.api_config):""}),Ze=async()=>{const t=await Ie("/cards");return(Array.isArray(t)?t:t.cards||[]).map(rr)},nr=async t=>Oe("/cards",Ca(t)),Js=async(t,s)=>Fe(`/cards/${t}`,Ca(s)),ir=async t=>Ke(`/cards/${t}`),or=async t=>{const s=new FormData;return s.append("file",t),wt("/cards/batch",s)},cr=async(t,s)=>Oe(`/cards/${t}/append-data`,{content:s}),ss=t=>t===!0||t===1||t==="1",vt=async t=>{const s=await Ie("/items",void 0);return(Array.isArray(s)?s:s.items||[]).map(o=>({...o,id:o.id||`${o.cookie_id}-${o.item_id}`,is_multi_spec:ss(o.is_multi_spec),is_multi_qty_ship:ss(o.is_multi_qty_ship??o.multi_quantity_delivery),multi_quantity_delivery:ss(o.multi_quantity_delivery??o.is_multi_qty_ship)}))},dr=async t=>Oe("/items/get-all-from-account",{cookie_id:t}),xr=async(t,s)=>Ke(`/items/${t}/${s}`),mr=async(t,s)=>Oe(`/items/${t}`,s),pr=async t=>{const s=new FormData;s.set("cookie_id",t.cookie_id),s.set("title",t.title),s.set("description",t.description),s.set("price",t.price),s.set("original_price",t.original_price||""),s.set("quantity",String(t.quantity)),s.set("postage_mode",t.postage_mode),s.set("postage",t.postage||""),t.location&&s.set("location",JSON.stringify(t.location));for(const l of t.images)s.append("images",l);return wt("/items/publish",s)},ur=async(t,s)=>Oe("/items/publish-categories/recommend",{cookie_id:t,keyword:s}),hr=async t=>{const s=new FormData;return s.set("file",t.file),t.imagesZip&&s.set("images_zip",t.imagesZip),t.defaultCookieId&&s.set("default_cookie_id",t.defaultCookieId),s.set("fallback_category_id",t.fallbackCategory.catId),s.set("fallback_category_name",t.fallbackCategory.catName),s.set("fallback_channel_category_id",t.fallbackCategory.channelCatId||""),s.set("fallback_tb_category_id",t.fallbackCategory.tbCatId||""),t.location&&s.set("location",JSON.stringify(t.location)),wt("/items/publish-batches/preview",s)},gr=async t=>Oe("/items/publish-batches",{preview_id:t}),bt=async t=>Ie(`/items/publish-batches/${t}`),Vs=async(t=20)=>{const s=await Ie("/items/publish-batches",{limit:t});return Array.isArray(s)?s:s.batches||[]},br=async t=>Ke(`/items/publish-batches/${t}`),fr=async t=>Oe(`/items/publish-batches/${t}/cancel`,{}),yr=async t=>Oe(`/items/publish-batches/${t}/retry-failed`,{}),jr=async(t,s,l)=>Fe(`/items/${t}/${s}`,l),Sa=t=>t.map(s=>{var l,o;return{id:String(s.id),name:s.name||"",trigger_type:s.trigger_type||"order_paid",item_keyword:s.item_title||s.item_id||"",cookie_id:s.cookie_id||"",item_id:s.item_id||"",item_title:s.item_title||"",card_group_id:Number(((l=(s.actions||[]).find(x=>x.action_type==="send_card"))==null?void 0:l.card_id)||0),card_group_name:((o=(s.actions||[]).find(x=>x.action_type==="send_card"))==null?void 0:o.card_name)||"",priority:s.priority||100,enabled:s.enabled||!1,config_json:s.config_json||"{}",actions:(s.actions||[]).map(x=>({id:x.id?String(x.id):void 0,action_type:x.action_type,card_id:Number(x.card_id||0),card_name:x.card_name||"",delivery_count:Number(x.delivery_count||1),message_template:x.message_template||"",delay_seconds:Number(x.delay_seconds||0),config_json:x.config_json||"{}",enabled:x.enabled!==!1,sort_order:Number(x.sort_order||0)})),variants:(s.actions||[]).filter(x=>x.action_type==="send_card").map(x=>{let v={};try{v=JSON.parse(x.config_json||"{}")}catch{}return{id:x.id?String(x.id):void 0,spec_name:v.spec_name||"",spec_value:v.spec_value||"",card_id:Number(x.card_id||0),card_name:x.card_name||"",delivery_count:Number(x.delivery_count||1),enabled:x.enabled!==!1,delay_override:v.delay_override===!0,delay_seconds:Number(x.delay_seconds||0),config_json:x.config_json||"{}"}})}}),us=async()=>{const t=await Ie("/automation-rules"),s=Array.isArray(t)?t:t.data||t.rules||[];return Sa(s)},_r=async({cookieId:t,triggerType:s,enabled:l,search:o,page:x=1,pageSize:v=10}={})=>{const k=await Ie("/automation-rules",{page:x,page_size:v,cookie_id:t||void 0,trigger_type:s||void 0,enabled:l,search:(o==null?void 0:o.trim())||void 0}),A=Sa(Array.isArray(k)?k:k.data||k.rules||[]);return{success:!0,data:A,total:Number(k.total??A.length),page:Number(k.page??x),page_size:Number(k.page_size??v),total_pages:Number(k.total_pages??(A.length?1:0)),trigger_counts:Object.fromEntries(Object.entries(k.trigger_counts||{}).map(([b,O])=>[b,Number(O)]))}},Nr=(t,s)=>{if(t!=="order_paid")return s.map((x,v)=>({...x,sort_order:x.sort_order||v+1}));const l=s.filter(x=>x.action_type==="send_card").map((x,v)=>({...x,sort_order:v+1})),o=s.filter(x=>x.action_type!=="send_card"&&x.action_type!=="confirm_shipment");return[...l,...o.map((x,v)=>({...x,sort_order:l.length+v+1})),{action_type:"confirm_shipment",enabled:!0,sort_order:l.length+o.length+1}]},Qs=async t=>{const s=t.trigger_type||"order_paid",o=[{order_paid:"付款后自动发货",buyer_reviewed:"评价后发送赠品",review_missing_timeout:"超时未评价求评价"}[s]||"自动化规则",t.item_title||t.item_id||t.cookie_id||""].filter(Boolean).join(" - "),x=(t.actions||[]).filter(b=>b.action_type!=="send_card"&&b.action_type!=="confirm_shipment"),v=t.variants&&t.variants.length>0?[...t.variants.map((b,O)=>({action_type:"send_card",card_id:b.card_id,delivery_count:b.delivery_count||1,enabled:b.enabled!==!1,sort_order:O+1,delay_seconds:b.delay_seconds||0,config_json:JSON.stringify({spec_name:b.spec_name||"",spec_value:b.spec_value||"",delay_override:b.delay_override===!0})})),...x]:t.actions&&t.actions.length>0?t.actions:[{action_type:"send_card",card_id:t.card_group_id||0,delivery_count:1,enabled:!0,sort_order:1}],k=Nr(s,v),A={cookie_id:t.cookie_id||"",item_id:t.item_id||"",name:(t.name||"").trim()||o||"自动化规则",trigger_type:s,enabled:t.enabled??!0,priority:t.priority||100,config_json:t.config_json||"{}",actions:k.map((b,O)=>({action_type:b.action_type,card_id:b.card_id||0,delivery_count:b.delivery_count||1,message_template:b.message_template||"",delay_seconds:b.delay_seconds||0,config_json:b.config_json||"{}",enabled:b.enabled!==!1,sort_order:b.sort_order||O+1}))};return t.id?Fe(`/automation-rules/${t.id}`,A):Oe("/automation-rules",A)},vr=async t=>Ke(`/automation-rules/${t}`),wr=async()=>{const t=await Ie("/automation-issues");return{runs:Array.isArray(t==null?void 0:t.runs)?t.runs:[],pending_tasks:Array.isArray(t==null?void 0:t.pending_tasks)?t.pending_tasks:[]}},kr=async(t,s)=>Oe(`/automation-runs/${t}/resolve`,{resolution:s}),Cr=async(t,s)=>Oe(`/automation-pending-tasks/${t}/resolve`,{resolution:s}),Sr=t=>({id:String((t==null?void 0:t.id)||""),keyword:(t==null?void 0:t.keyword)||"",reply:(t==null?void 0:t.reply)||"",item_id:(t==null?void 0:t.item_id)||"",type:(t==null?void 0:t.type)==="image"?"image":"text",image_url:(t==null?void 0:t.image_url)||""}),Lr=async t=>{const s=await Ie(`/keywords-with-type/${t}`);return Array.isArray(s)?s.map(Sr):[]},Or=async t=>t?(await Lr(t)).map(l=>({id:l.id,keyword:l.keyword||"",reply_content:l.reply||"",match_type:"fuzzy",enabled:!0,item_id:l.item_id||"",type:l.type==="image"?"image":"text",image_url:l.image_url||""})):[],Ir=async(t,s)=>{const l=t.type||"text",o={keyword:t.keyword||"",reply:l==="text"&&t.reply_content||"",item_id:t.item_id||"",type:l,image_url:l==="image"&&t.image_url||""};return t.id?Fe(`/keywords-with-type/${s}/${t.id}`,o):Oe(`/keywords-with-item-id/${s}`,o)},Ar=async(t,s)=>Ke(`/keywords-with-type/${s}/${t}`),La=async()=>{const t=await Ie("/system-settings");return kl(t.data||t)},Oa=async t=>{const s=Object.fromEntries(Object.entries(t).filter(([,l])=>l!=null));return Fe("/system-settings",s)},Rr=async(t,s)=>Ie(`/ai-reply-settings/${t}`,void 0,s),Pr=async(t,s)=>{const l={ai_enabled:s.ai_enabled??!1,max_discount_percent:s.max_discount_percent??10,max_discount_amount:s.max_discount_amount??100,max_bargain_rounds:s.max_bargain_rounds??3,custom_prompts:s.custom_prompts??""};return Fe(`/ai-reply-settings/${t}`,l)},$r=async(t,s="")=>(await Oe("/ai-models",{base_url:t,api_key:s})).models||[],Er=t=>{if(Array.isArray(t))return t.filter(Boolean);if(typeof t!="string"||!t.trim())return[];try{const s=JSON.parse(t);if(Array.isArray(s))return s.filter(Boolean)}catch{}return t.split(/[,\s;]+/).map(s=>s.trim()).filter(Boolean)},Ia=t=>{const s=Array.from(new Set((t||[]).filter(Boolean)));return s.length>0?JSON.stringify(s):""},Aa=async t=>({success:!0,data:(await Ie("/notification-channels",void 0,t)||[]).map(o=>{let x;try{x=typeof o.config=="string"?JSON.parse(o.config):o.config}catch{x={}}return{id:String(o.id),name:o.name,type:o.type==="ding_talk"?"dingtalk":o.type==="lark"?"feishu":o.type,config:x,event_types:Er(o.event_types),enabled:o.enabled,created_at:o.created_at,updated_at:o.updated_at}})}),Dr=async t=>Oe("/notification-channels",{...t,config:JSON.stringify(t.config),event_types:Ia(t.event_types)}),Gs=async(t,s)=>{const l={...s};return"config"in s&&(l.config=JSON.stringify(s.config)),"event_types"in s&&(l.event_types=Ia(s.event_types)),Fe(`/notification-channels/${t}`,l)},Tr=async t=>Ke(`/notification-channels/${t}`),Mr=async(t,s)=>{const l=await Ie(`/message-notifications/${t}`,void 0,s);return(l==null?void 0:l.channel_ids)||[]},qr=async t=>Oe(`/notification-channels/${t}/test`,{}),Ks=async()=>Ie("/api/default-replies"),Fr=async t=>{const s=await Ie(`/api/default-reply/${t}`);return{cookie_id:t,enabled:s.enabled||!1,reply_content:s.reply_content||"",reply_once:s.reply_once||!1,reply_image_url:s.reply_image_url||""}},Br=async(t,s)=>Fe(`/api/default-reply/${t}`,{enabled:s.enabled??!1,reply_content:s.reply_content||"",reply_once:s.reply_once??!1,reply_image_url:s.reply_image_url||""}),zr=async t=>Ke(`/api/default-reply/${t}`),Ur=async t=>Oe(`/api/default-reply/${t}/clear-records`,{}),Ot=t=>String(t).padStart(2,"0"),hs=t=>{if(t==null||t==="")return"-";const s=t instanceof Date?t:new Date(t);return Number.isNaN(s.getTime())?"-":[s.getFullYear(),Ot(s.getMonth()+1),Ot(s.getDate())].join("-")+" "+[Ot(s.getHours()),Ot(s.getMinutes()),Ot(s.getSeconds())].join(":")},_e=(t,s)=>s===void 0?`rgb(var(--color-${t}))`:`rgb(var(--color-${t}) / ${s})`,Wr=({status:t})=>{const s={processing:"bg-blue-100 text-blue-800",pending_ship:"bg-brand text-white",shipped:"bg-blue-100 text-blue-700",completed:"bg-green-100 text-green-700",cancelled:"bg-gray-100 text-gray-500",refunding:"bg-red-100 text-red-600",unknown:"bg-gray-100 text-gray-500"},l={processing:"处理中",pending_ship:"待发货",shipped:"已发货",completed:"已完成",cancelled:"已取消",refunding:"退款中",unknown:"未知"};return e.jsx("span",{className:`inline-flex items-center justify-center whitespace-nowrap px-3 py-1.5 rounded-lg text-xs leading-none font-bold ${s[t]||s.cancelled}`,children:l[t]||t})},zt=({title:t,value:s,icon:l,colorClass:o,trend:x})=>e.jsxs("div",{className:"ios-card p-6 rounded-xl flex flex-col justify-between hover:translate-y-[-4px] transition-all duration-300 h-full relative overflow-hidden group border-0",children:[e.jsx("div",{className:`absolute -right-6 -top-6 w-32 h-32 ${o} opacity-10 rounded-full group-hover:scale-125 transition-transform duration-500 blur-2xl`}),e.jsxs("div",{className:"flex justify-between items-start mb-6",children:[e.jsx("div",{className:`p-4 rounded-2xl ${o} bg-opacity-10 backdrop-blur-sm`,children:e.jsx(l,{className:`w-6 h-6 ${o.replace("bg-","text-")}`})}),x&&e.jsxs("span",{className:"text-xs font-bold text-white bg-brand px-3 py-1.5 rounded-full flex items-center gap-1 shadow-sm",children:[e.jsx(Wa,{className:"w-3 h-3"})," ",x]})]}),e.jsxs("div",{className:"relative z-10",children:[e.jsx("h3",{className:"text-3xl font-extrabold text-gray-900 tracking-tight font-feature-settings-tnum",children:s}),e.jsx("p",{className:"text-gray-500 text-sm font-medium mt-1",children:t})]})]}),as=()=>{var S,Q;const[t,s]=r.useState(null),[l,o]=r.useState(null),[x,v]=r.useState(""),[k,A]=r.useState("7days"),[b,O]=r.useState(""),[j,V]=r.useState(""),[Y,pe]=r.useState(null),[ce,w]=r.useState(""),[M,de]=r.useState([]),[G,X]=r.useState(0),[U,fe]=r.useState(!1),[ge,L]=r.useState(!1),[K,ae]=r.useState([]),[Z,me]=r.useState({}),R=r.useRef(0),E=[_e("brand"),_e("brand-highlight"),_e("success-500"),_e("warning-500"),_e("accent-500")],ee=u=>`¥${Number(u||0).toLocaleString("zh-CN",{maximumFractionDigits:2})}`,T=async u=>{let d;try{d=Bs(u,new Date,b,j)}catch(Re){v(Re instanceof Error?Re.message:"日期范围无效");return}const{startDate:F,endDate:I}=d,H={start_date:F,end_date:I},P=wl(d),Ce=++R.current;L(!0),v("");try{const[Re,xe,Pe]=await Promise.all([Ws(H),Ws({start_date:P.startDate,end_date:P.endDate}),lr(H)]);if(Ce!==R.current)return;o(Re),pe(xe),de(Pe.orders),X(Pe.total),fe(Pe.truncated)}catch(Re){Ce===R.current&&v(Re instanceof Error?Re.message:"经营数据加载失败")}finally{Ce===R.current&&L(!1)}},se=()=>{if(!l||!Y)return null;const u=l.revenue_stats.total_amount,d=Y.revenue_stats.total_amount;if(d===0)return u>0?"+100%":"0%";const F=(u-d)/d*100;return`${F>=0?"+":""}${F.toFixed(1)}%`};if(r.useEffect(()=>{let u=!1;return Promise.all([ar(),vt()]).then(([d,F])=>{if(u)return;s(d),ae(F);const I={};F.forEach(H=>{I[H.item_id]=H.item_title||H.item_id}),me(I)}).catch(d=>{u||v(d instanceof Error?d.message:"概览加载失败")}),()=>{u=!0}},[]),r.useEffect(()=>{k!=="custom"&&T(k)},[k]),x&&(!t||!l))return e.jsxs("div",{className:"p-8 flex flex-col items-center gap-3 text-red-600",children:[e.jsx(at,{className:"w-8 h-8"}),e.jsx("span",{children:x}),e.jsx("button",{type:"button",className:"ios-btn-primary px-4 py-2 rounded-xl",onClick:()=>window.location.reload(),children:"重新加载"})]});if(!t||!l)return e.jsx("div",{className:"p-8 flex justify-center text-gray-400",children:e.jsx(Ls,{className:"w-8 h-8 animate-spin text-brand"})});const ke=((S=l.daily_stats)==null?void 0:S.map(u=>({name:u.date.slice(5),amount:u.amount,orders:u.order_count,avgAmount:u.order_count>0?(u.amount/u.order_count).toFixed(2):0})))||[],ye=l.item_stats||[],z=l.revenue_stats.total_orders||0,m=l.revenue_stats.total_amount||0,f=ye.length>0?ye.map(u=>({name:(Z[u.item_id]||u.item_id).length>12?(Z[u.item_id]||u.item_id).substring(0,12)+"...":Z[u.item_id]||u.item_id,sales:u.order_count})).sort((u,d)=>d.sales-u.sales).slice(0,10):[],W=Math.max(...f.map(u=>u.sales),1),q=ye.length>0?ye.map(u=>({name:(Z[u.item_id]||u.item_id).length>10?(Z[u.item_id]||u.item_id).substring(0,10)+"...":Z[u.item_id]||u.item_id,value:u.order_count,percent:z>0?u.order_count/z*100:0})).sort((u,d)=>d.value-u.value).slice(0,6).map((u,d)=>({...u,color:E[d%E.length]})):[],ne=ye.length>0?ye.map(u=>({name:(Z[u.item_id]||u.item_id).length>12?(Z[u.item_id]||u.item_id).substring(0,12)+"...":Z[u.item_id]||u.item_id,value:u.total_amount,orderCount:u.order_count,percentage:m>0?u.total_amount/m*100:0})).sort((u,d)=>d.value-u.value).slice(0,5).map((u,d)=>({...u,color:E[d%E.length],percentage:u.percentage.toFixed(1)})):[],be=[{key:"today",label:"今天"},{key:"yesterday",label:"昨天"},{key:"3days",label:"三天内"},{key:"7days",label:"7天内"},{key:"30days",label:"一个月内"},{key:"custom",label:"自定义"}],ve=((Q=be.find(u=>u.key===k))==null?void 0:Q.label)||"所选范围";let De;try{De=Bs(k,new Date,b,j)}catch{De={startDate:b,endDate:j}}const Ne=ce.trim().toLowerCase(),c=M.filter(u=>{var d,F,I,H;return((d=u.order_id)==null?void 0:d.toLowerCase().includes(Ne))||((F=u.item_id)==null?void 0:F.toLowerCase().includes(Ne))||((I=u.item_title)==null?void 0:I.toLowerCase().includes(Ne))||((H=u.buyer_id)==null?void 0:H.toLowerCase().includes(Ne))});return e.jsxs("div",{className:"space-y-8 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col md:flex-row justify-between md:items-end gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-4xl font-extrabold text-gray-900 tracking-tight",children:"运营概览"}),e.jsx("p",{className:"text-gray-500 mt-2 text-base",children:"欢迎回来,以下是闲鱼店铺的实时经营数据。"})]}),e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("div",{className:"text-sm font-bold text-gray-700 bg-white px-5 py-2.5 rounded-full shadow-sm border border-gray-100 flex items-center gap-2",children:[e.jsx("span",{className:"w-2.5 h-2.5 bg-green-500 rounded-full animate-pulse"}),"系统正常运行"]})})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 p-2 bg-gray-100/50 rounded-2xl",children:[be.map(u=>e.jsx("button",{onClick:()=>A(u.key),className:`px-5 py-2.5 rounded-xl text-sm font-bold transition-all ${k===u.key?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:text-black hover:bg-gray-50"}`,children:u.label},u.key)),k==="custom"&&e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"date",value:b,onChange:u=>O(u.target.value),className:"px-3 py-2 rounded-xl text-sm border border-gray-200 focus:outline-none focus:ring-2 focus:ring-brand"}),e.jsx("span",{className:"self-center text-gray-400",children:"-"}),e.jsx("input",{type:"date",value:j,onChange:u=>V(u.target.value),className:"px-3 py-2 rounded-xl text-sm border border-gray-200 focus:outline-none focus:ring-2 focus:ring-brand"}),e.jsx("button",{onClick:()=>{try{v(""),T("custom")}catch(u){v(u instanceof Error?u.message:"日期范围无效")}},className:"px-4 py-2 rounded-xl text-sm font-bold bg-black text-white hover:bg-gray-800 transition-colors",children:"应用"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6",children:[e.jsx(zt,{title:"累计营收 (CNY)",value:`¥${l.revenue_stats.total_amount.toLocaleString("zh-CN",{minimumFractionDigits:2})}`,icon:Ua,colorClass:"bg-blue-400",trend:se()||void 0}),e.jsx(zt,{title:"活跃账号 / 总数",value:`${t.active_cookies} / ${t.total_cookies}`,icon:ma,colorClass:"bg-blue-500"}),e.jsx(zt,{title:"订单数",value:l.revenue_stats.total_orders.toLocaleString(),icon:Os,colorClass:"bg-blue-500"}),e.jsx(zt,{title:"库存卡密余量",value:t.available_card_stock,icon:ha,colorClass:"bg-purple-500"})]}),e.jsxs("div",{className:"ios-card p-8 rounded-xl",children:[e.jsxs("div",{className:"mb-10",children:[e.jsx("h3",{className:"text-xl font-bold text-gray-900",children:"营收趋势分析"}),e.jsxs("p",{className:"text-sm text-gray-400 mt-1",children:[ve,"的销售额走势"]})]}),e.jsx("div",{className:"dashboard-revenue-chart h-[350px] w-full",children:ke.length===0||l.revenue_stats.total_amount===0?e.jsxs("div",{className:"h-full flex flex-col items-center justify-center text-gray-400",children:[e.jsx(Os,{className:"w-16 h-16 mb-4 opacity-20"}),e.jsx("p",{className:"text-lg font-medium",children:"暂无营收数据"}),e.jsx("p",{className:"text-sm mt-2",children:"所选时间范围内暂无订单记录"})]}):ke.length<=2?e.jsx(Ft,{width:"100%",height:"100%",children:e.jsxs(pl,{data:ke,margin:{top:30,right:20,left:0,bottom:30},barCategoryGap:"45%",children:[e.jsx(Ts,{dataKey:"name",axisLine:!1,tickLine:!1,tick:{fill:_e("neutral-700"),fontSize:14,fontWeight:600},dy:10}),e.jsx(Ms,{axisLine:!1,tickLine:!1,tick:{fill:_e("neutral-400"),fontSize:13,fontWeight:500},tickFormatter:u=>`¥${u}`}),e.jsx(Bt,{contentStyle:{backgroundColor:_e("white"),borderRadius:"8px",border:`1px solid ${_e("neutral-200")}`,boxShadow:"var(--shadow-xl)",padding:"12px 16px"},labelStyle:{color:_e("neutral-500"),fontWeight:500},itemStyle:{color:_e("brand"),fontWeight:600},cursor:{fill:_e("brand",.08)},formatter:u=>[`¥${Number(u).toFixed(2)}`,"营收"]}),e.jsx(ul,{dataKey:"amount",fill:_e("brand"),maxBarSize:72,radius:[12,12,0,0],activeBar:!1,stroke:"none",strokeWidth:0,children:ke.map((u,d)=>e.jsx(Xt,{fill:_e("brand"),stroke:"none",strokeWidth:0},`cell-${d}`))})]})}):e.jsx(Ft,{width:"100%",height:"100%",children:e.jsxs(hl,{data:ke,margin:{top:10,right:10,left:-20,bottom:0},children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"colorAmount",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:_e("brand"),stopOpacity:.5}),e.jsx("stop",{offset:"95%",stopColor:_e("brand"),stopOpacity:0})]})}),e.jsx(Ts,{dataKey:"name",axisLine:!1,tickLine:!1,tick:{fill:_e("neutral-400"),fontSize:13,fontWeight:500},dy:15}),e.jsx(Ms,{axisLine:!1,tickLine:!1,tick:{fill:_e("neutral-400"),fontSize:13,fontWeight:500}}),e.jsx(gl,{vertical:!1,stroke:_e("neutral-100"),strokeDasharray:"3 3"}),e.jsx(Bt,{contentStyle:{backgroundColor:_e("white"),borderRadius:"8px",border:`1px solid ${_e("neutral-200")}`,boxShadow:"var(--shadow-xl)",padding:"12px 16px"},labelStyle:{color:_e("neutral-500"),fontWeight:500},itemStyle:{color:_e("brand"),fontWeight:600},cursor:{stroke:_e("brand"),strokeWidth:2,strokeDasharray:"4 4"}}),e.jsx(bl,{type:"monotone",dataKey:"amount",stroke:_e("brand"),strokeWidth:4,fillOpacity:1,fill:"url(#colorAmount)",activeDot:{r:8,fill:_e("white"),stroke:_e("brand"),strokeWidth:2}})]})})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8",children:[e.jsxs("div",{className:"ios-card p-6 rounded-xl",children:[e.jsx("h3",{className:"font-bold text-lg text-gray-900 mb-6",children:"商品销量排行"}),e.jsx("div",{className:"h-[280px]",children:f.length===0?e.jsx("div",{className:"flex items-center justify-center h-full text-gray-400",children:"暂无数据"}):e.jsx("div",{className:"h-full space-y-4 overflow-y-auto pr-2",children:f.map((u,d)=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("span",{className:`w-7 h-7 rounded-xl flex items-center justify-center text-xs font-extrabold ${d<3?"bg-blue-600 text-white":"bg-gray-100 text-gray-500"}`,children:d+1}),e.jsx("span",{className:"font-bold text-gray-800 text-sm truncate",children:u.name})]}),e.jsxs("span",{className:"font-mono text-sm font-extrabold text-gray-900",children:[u.sales," 单"]})]}),e.jsx("div",{className:"h-3 rounded-full bg-gray-100 overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-brand",style:{width:`${Math.max(8,u.sales/W*100)}%`}})})]},`${u.name}-${d}`))})})]}),e.jsxs("div",{className:"ios-card p-6 rounded-xl",children:[e.jsx("h3",{className:"font-bold text-lg text-gray-900 mb-6",children:"商品下单占比"}),e.jsx("div",{className:"dashboard-pie-chart h-[280px] relative",role:"img","aria-label":`商品下单占比,共 ${z} 单`,children:q.length===0?e.jsx("div",{className:"flex items-center justify-center h-full text-gray-400",children:"暂无数据"}):e.jsxs(e.Fragment,{children:[e.jsx(Ft,{width:"100%",height:"100%",children:e.jsxs(qs,{accessibilityLayer:!1,children:[e.jsx(Fs,{data:q,cx:"50%",cy:"45%",innerRadius:60,outerRadius:90,paddingAngle:2,dataKey:"value",activeShape:{outerRadius:96,stroke:"none",strokeWidth:0},rootTabIndex:-1,label:!1,labelLine:!1,children:q.map((u,d)=>e.jsx(Xt,{fill:u.color},`cell-${d}`))}),e.jsx(Bt,{formatter:u=>`${Number(u||0)} 单`,wrapperStyle:{zIndex:30,outline:"none"},contentStyle:{backgroundColor:_e("white"),border:`1px solid ${_e("neutral-200")}`,borderRadius:"10px",boxShadow:"var(--shadow-md)"}}),e.jsx(fl,{verticalAlign:"bottom",height:36,iconType:"circle",formatter:u=>e.jsx("span",{style:{color:_e("neutral-500"),fontWeight:500},children:u})})]})}),e.jsxs("div",{className:"pointer-events-none absolute inset-0 z-10 flex flex-col items-center justify-center pb-9",children:[e.jsx("span",{className:"text-2xl font-extrabold text-gray-900 tabular-nums",children:z}),e.jsx("span",{className:"text-xs font-medium text-gray-400 mt-0.5",children:"总订单"})]})]})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-8",children:[e.jsxs("div",{className:"lg:col-span-2 ios-card p-0 rounded-xl border-0 bg-white overflow-hidden flex flex-col",children:[e.jsxs("div",{className:"p-6 border-b border-gray-50 flex justify-between items-center bg-surface-muted",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-bold text-lg text-gray-900",children:"参与统计的订单"}),U&&e.jsxs("p",{className:"text-xs text-amber-700 mt-1",children:["当前显示最近 ",M.length," / ",G," 条,搜索仅覆盖已加载明细。"]})]}),e.jsx("div",{className:"relative",children:e.jsx("input",{placeholder:"搜索订单号/商品/买家...",value:ce,onChange:u=>w(u.target.value),className:"pl-4 pr-4 py-2 rounded-xl bg-white border border-gray-100 text-sm focus:border-blue-400 outline-none w-48",type:"text"})})]}),e.jsx("div",{className:"overflow-x-auto flex-1 max-h-[400px]",children:ge?e.jsxs("div",{className:"flex items-center justify-center py-20 text-gray-400",children:[e.jsx(Ls,{className:"w-6 h-6 animate-spin mr-2"}),"加载中..."]}):c.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 px-8 text-center",children:[e.jsx("div",{className:"w-14 h-14 rounded-2xl bg-gray-100 flex items-center justify-center mb-4",children:e.jsx(Tt,{className:"w-7 h-7 text-gray-300"})}),Ne?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-sm font-extrabold text-gray-900",children:"没有匹配的订单"}),e.jsxs("div",{className:"text-xs text-gray-400 mt-2 max-w-md",children:["当前共有 ",M.length," 单参与统计,但没有订单号、商品、买家匹配“",ce,"”。"]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-sm font-extrabold text-gray-900",children:"当前范围内没有参与统计的订单"}),e.jsxs("div",{className:"text-xs text-gray-400 mt-2 max-w-lg leading-6",children:["日期范围:",De.startDate," 至 ",De.endDate,"; 统计口径:待发货、已发货、已完成,且订单金额不为空。 当前统计卡片订单数:",l.revenue_stats.total_orders," 单。"]})]})]}):e.jsxs("table",{className:"w-full min-w-[760px] text-left border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-white text-gray-400 text-xs font-bold uppercase tracking-wider border-b border-gray-50",children:[e.jsx("th",{className:"px-6 py-4",children:"订单信息"}),e.jsx("th",{className:"px-6 py-4",children:"买家信息"}),e.jsx("th",{className:"px-6 py-4",children:"金额"}),e.jsx("th",{className:"px-6 py-4 whitespace-nowrap",children:"状态"}),e.jsx("th",{className:"px-6 py-4 text-right",children:"操作"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50",children:c.map(u=>e.jsxs("tr",{className:"hover:bg-warning-50/50 transition-colors group",children:[e.jsx("td",{className:"px-6 py-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-gray-100 overflow-hidden shadow-sm border border-gray-100 flex-shrink-0",children:e.jsx(Tt,{className:"w-full h-full text-gray-300 p-2"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-bold text-gray-900 text-sm line-clamp-1",children:u.item_title||u.item_id||"未知商品"}),e.jsx("div",{className:"text-xs text-gray-500 mt-1 font-mono",children:u.order_id}),e.jsxs("div",{className:"text-xs text-gray-400 mt-0.5",children:["数量: ",u.quantity||1]})]})]})}),e.jsxs("td",{className:"px-6 py-4",children:[e.jsx("div",{className:"text-sm font-bold text-gray-800",children:u.buyer_id}),u.created_at&&e.jsx("div",{className:"text-xs text-gray-400 mt-1",children:hs(u.created_at)})]}),e.jsxs("td",{className:"px-6 py-4 text-base font-extrabold text-gray-900 font-feature-settings-tnum",children:["¥",u.amount||"0.00"]}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap",children:e.jsx(Wr,{status:u.status||u.order_status||"unknown"})}),e.jsx("td",{className:"px-6 py-4 text-right",children:e.jsx("a",{href:`https://www.goofish.com/order-detail?orderId=${u.order_id}&role=seller`,target:"_blank",rel:"noopener noreferrer",className:"inline-flex text-gray-400 hover:text-blue-600 p-2 rounded-xl hover:bg-blue-50 transition-colors",title:"查看闲鱼详情",children:e.jsx(ga,{className:"w-4 h-4"})})})]},u.order_id))})]})})]}),e.jsxs("div",{className:"ios-card p-6 rounded-xl bg-white",children:[e.jsx("h3",{className:"font-bold text-lg text-gray-900 mb-6",children:"商品金额分析 (TOP5)"}),ne.length===0?e.jsx("div",{className:"flex items-center justify-center h-[300px] text-gray-400",children:"暂无数据"}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"dashboard-pie-chart h-[280px] relative",role:"img","aria-label":`商品金额分析,总金额 ${ee(m)}`,children:[e.jsx(Ft,{width:"100%",height:"100%",children:e.jsxs(qs,{accessibilityLayer:!1,children:[e.jsx(Fs,{data:ne,cx:"50%",cy:"50%",innerRadius:60,outerRadius:92,paddingAngle:2,dataKey:"value",activeShape:{outerRadius:98,stroke:"none",strokeWidth:0},rootTabIndex:-1,label:!1,labelLine:!1,children:ne.map((u,d)=>e.jsx(Xt,{fill:u.color||E[d%E.length]},`cell-${d}`))}),e.jsx(Bt,{wrapperStyle:{zIndex:30,outline:"none"},contentStyle:{backgroundColor:_e("white"),border:`1px solid ${_e("neutral-200")}`,borderRadius:"6px",boxShadow:"var(--shadow-md)"},formatter:u=>`¥${Number(u||0).toLocaleString()}`})]})}),e.jsxs("div",{className:"pointer-events-none absolute inset-0 z-10 flex flex-col items-center justify-center",children:[e.jsx("span",{className:"text-lg font-extrabold text-gray-900 tabular-nums",children:ee(m)}),e.jsx("span",{className:"text-xs font-medium text-gray-400 mt-0.5",children:"总金额"})]})]}),e.jsx("div",{className:"space-y-3 mt-4",children:ne.map(u=>e.jsxs("div",{className:"flex justify-between items-center gap-3 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.jsx("div",{className:"w-3 h-3 rounded-full shrink-0",style:{backgroundColor:u.color||E[ne.indexOf(u)%E.length]}}),e.jsx("span",{className:"text-gray-600 font-medium truncate",title:u.name,children:u.name})]}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0 whitespace-nowrap",children:[e.jsxs("span",{className:"font-bold text-gray-900",children:["¥",u.value.toLocaleString()]}),e.jsxs("span",{className:"text-xs text-gray-500 bg-gray-100 px-2 py-0.5 rounded",children:[u.percentage,"%"]})]})]},u.name))})]})]})]})]})},Jr=(t,s)=>{const l=s.pause_duration||0;return t!==l},Vr=(t,s)=>{const l=s.username!==(t.username||""),o=s.show_browser!==(t.show_browser||!1),x=s.login_password!=="",v=s.clear_password===!0;if(!l&&!o&&!x&&!v)return null;const k={username:s.username,show_browser:s.show_browser};return v?k.clear_password=!0:x&&(k.login_password=s.login_password),k},Qr=(t,s)=>t&&s,Gr=(t,s)=>{if(!t||!s)return!1;const l=Date.parse(t),o=Date.parse(s);return Number.isFinite(l)&&Number.isFinite(o)&&o<l},Kr=(t,s)=>t.map(l=>{const o=s[l.id];return!o||Gr(l.runtime_updated_at,o.updated_at)?l:{...l,runtime_state:o.state,runtime_message:o.message||"",runtime_connected:o.connected,runtime_updated_at:o.updated_at}}),Hr=new Set(["expired","cancelled","error","not_found"]),Ut=()=>{let t=0;return{next:()=>(t+=1,t),cancel:()=>{t+=1},isCurrent:s=>s===t}},Zr=(t={setInterval:globalThis.setInterval.bind(globalThis),clearInterval:globalThis.clearInterval.bind(globalThis)})=>{let s=null,l=null,o=-1,x=0;const v=()=>{x+=1,l==null||l.abort(),l=null,s!==null&&(t.clearInterval(s),s=null)};return{start:(A,b,O,j=2e3)=>{v();const V=x;l=new AbortController;const Y=l.signal;s=t.setInterval(()=>{o===V||V!==x||(o=V,(async()=>{var pe,ce;try{const w=await b(A,Y);if(w.status==="success"){v(),await O.onSuccess(w);return}if(w.status==="scanned"){(pe=O.onScanned)==null||pe.call(O,w);return}if(w.status==="verification_required"){(ce=O.onVerificationRequired)==null||ce.call(O,w);return}w.status&&Hr.has(w.status)&&(v(),O.onTerminalError(w))}catch(w){if(Y.aborted||V!==x)return;v(),O.onPollError(w)}finally{o===V&&(o=-1)}})())},j)},stop:v,isActive:()=>s!==null}},Yr=({faceQrUrl:t,verificationScreenshot:s})=>e.jsxs("div",{className:"w-full min-w-0 max-h-[min(64vh,28rem)] overflow-y-auto overscroll-contain px-1 py-2 text-center",children:[e.jsx("div",{className:"mx-auto mb-2 flex h-10 w-10 items-center justify-center rounded-full bg-amber-100 text-amber-700",children:e.jsx(Ja,{className:"h-5 w-5","aria-hidden":"true"})}),e.jsx("h4",{className:"break-words text-base font-extrabold leading-6 text-amber-900",children:"需要完成安全风控验证"}),e.jsx("p",{className:"mx-auto mt-1 max-w-[15rem] break-words text-xs leading-5 text-amber-800",children:"当前账号触发了闲鱼平台风控。请使用手机闲鱼 App 扫描下方二维码,并按 App 提示完成人脸识别。"}),e.jsx("div",{className:"mx-auto mt-3 flex min-h-36 w-full max-w-[12rem] items-center justify-center overflow-hidden rounded-xl border border-amber-200 bg-white p-2 shadow-sm",children:t?e.jsx("img",{src:t,alt:"闲鱼安全风控验证二维码",className:"block max-h-44 w-full object-contain"}):s?e.jsx("img",{src:s,alt:"闲鱼风控验证页面",className:"block max-h-44 w-full object-contain"}):e.jsxs("div",{className:"flex flex-col items-center gap-2 text-amber-700",children:[e.jsx(Ee,{className:"h-6 w-6 animate-spin","aria-hidden":"true"}),e.jsx("span",{className:"text-xs font-bold",children:"正在准备风控二维码…"})]})}),e.jsx("p",{className:"mx-auto mt-2 max-w-[15rem] break-words text-[11px] leading-4 text-gray-500",children:"请勿在浏览器中打开验证链接。完成验证后系统会自动检测并刷新登录状态,无需手动确认。"})]}),Hs=({src:t,alt:s,className:l=""})=>e.jsx("img",{src:t,alt:s,className:`block aspect-square h-auto w-full object-contain ${l}`.trim()}),Zs=({checked:t,onChange:s,label:l})=>e.jsx("button",{type:"button","aria-label":l,"aria-pressed":t,onClick:s,className:`relative h-8 w-14 shrink-0 rounded-full transition-colors ${t?"bg-sky-500":"bg-slate-300"}`,children:e.jsx("span",{className:`absolute left-1 top-1 h-6 w-6 rounded-full bg-white shadow-sm transition-transform ${t?"translate-x-6":""}`})}),Xr=({account:t,onClose:s,onSaved:l})=>{const[o,x]=r.useState({account_id:t.id,auto_rate_enabled:t.auto_rate_enabled===!0,rate_content:t.rate_content||"不错的买家,交易愉快",auto_polish_enabled:t.auto_polish_enabled===!0,polish_time:t.polish_time||"03:00",last_rate_scan_at:t.last_rate_scan_at,last_polish_date:t.last_polish_date,last_polish_at:t.last_polish_at}),[v,k]=r.useState(!1),[A,b]=r.useState(""),[O,j]=r.useState(""),[V,Y]=r.useState(null),pe=async()=>{k(!0),j("");try{const w=await zs(t.id,o);x(w),l(w)}catch(w){j(w instanceof Error?w.message:"保存失败")}finally{k(!1)}},ce=async w=>{b(w),j(""),Y(null);try{await zs(t.id,o);const M=await Rl(t.id,w),de=await Al(t.id);Y(M.summary),x(de),l(de)}catch(M){j(M instanceof Error?M.message:"任务执行失败")}finally{b("")}};return e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"640px"},role:"dialog","aria-modal":"true","aria-labelledby":"account-task-title",children:[e.jsxs("div",{className:"modal-header",children:[e.jsxs("div",{children:[e.jsx("h3",{id:"account-task-title",className:"text-2xl font-extrabold text-slate-950",children:"账号自动任务"}),e.jsx("p",{className:"mt-1 text-sm text-slate-500",children:t.nickname||t.remark||t.id})]}),e.jsx("button",{type:"button",onClick:s,className:"rounded-xl p-2 text-slate-400 hover:bg-slate-100 hover:text-slate-700","aria-label":"关闭",children:e.jsx(Te,{className:"h-5 w-5"})})]}),e.jsxs("div",{className:"modal-body space-y-5",children:[e.jsx("section",{className:"rounded-2xl border border-slate-200 bg-white p-5",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-xl bg-emerald-50 text-emerald-600",children:e.jsx(Va,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-black text-slate-900",children:"自动评价"}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-slate-500",children:"持续扫描待评价订单,按订单执行;不是每日任务。"})]}),e.jsx(Zs,{checked:o.auto_rate_enabled,onChange:()=>x(w=>({...w,auto_rate_enabled:!w.auto_rate_enabled})),label:"自动评价"})]}),e.jsx("label",{className:"mt-4 block text-xs font-extrabold text-slate-600",children:"统一好评文案"}),e.jsx("textarea",{"aria-label":"统一好评文案",value:o.rate_content,maxLength:500,onChange:w=>x(M=>({...M,rate_content:w.target.value})),className:"mt-2 h-24 w-full resize-none rounded-xl border border-slate-200 bg-slate-50 px-3 py-2.5 text-sm leading-6 text-slate-800 placeholder:text-slate-400 outline-none focus:border-sky-400 focus:ring-2 focus:ring-sky-100"}),e.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3",children:[e.jsxs("span",{className:"text-xs text-slate-400",children:["最近扫描:",o.last_rate_scan_at?new Date(o.last_rate_scan_at*1e3).toLocaleString("zh-CN"):"尚未执行"]}),e.jsxs("button",{type:"button",disabled:A!==""||!t.enabled,onClick:()=>void ce("auto_rate"),className:"flex items-center gap-2 rounded-xl bg-emerald-50 px-3 py-2 text-xs font-extrabold text-emerald-700 hover:bg-emerald-100 disabled:opacity-50",children:[A==="auto_rate"?e.jsx(Ee,{className:"h-4 w-4 animate-spin"}):e.jsx(Qa,{className:"h-4 w-4"}),"立即评价"]})]})]})]})}),e.jsx("section",{className:"rounded-2xl border border-slate-200 bg-white p-5",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-xl bg-amber-50 text-amber-600",children:e.jsx(js,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-black text-slate-900",children:"每日自动擦亮"}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-slate-500",children:"每个账号每天最多执行一次,按北京时间判断。"})]}),e.jsx(Zs,{checked:o.auto_polish_enabled,onChange:()=>x(w=>({...w,auto_polish_enabled:!w.auto_polish_enabled})),label:"每日自动擦亮"})]}),e.jsxs("div",{className:"mt-4 flex items-end justify-between gap-4",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-extrabold text-slate-600",children:"每日执行时间"}),e.jsx("input",{type:"time",value:o.polish_time,onChange:w=>x(M=>({...M,polish_time:w.target.value})),className:"mt-2 block rounded-xl border border-slate-200 bg-slate-50 px-3 py-2 text-sm font-bold text-slate-800 outline-none focus:border-sky-400"})]}),e.jsxs("button",{type:"button",disabled:A!==""||!t.enabled,onClick:()=>void ce("auto_polish"),className:"flex items-center gap-2 rounded-xl bg-amber-50 px-3 py-2 text-xs font-extrabold text-amber-700 hover:bg-amber-100 disabled:opacity-50",children:[A==="auto_polish"?e.jsx(Ee,{className:"h-4 w-4 animate-spin"}):e.jsx(ba,{className:"h-4 w-4"}),"立即擦亮"]})]}),e.jsxs("div",{className:"mt-3 text-xs text-slate-400",children:["上次完成:",o.last_polish_at?new Date(o.last_polish_at*1e3).toLocaleString("zh-CN"):"尚未执行"]})]})]})}),V&&e.jsxs("div",{className:"rounded-xl border border-sky-100 bg-sky-50 px-4 py-3 text-sm text-sky-900",children:["本次发现 ",V.found," 项,成功 ",V.success,",失败 ",V.failed,",跳过 ",V.skipped,"。",V.message||""]}),O&&e.jsx("div",{className:"rounded-xl border border-red-100 bg-red-50 px-4 py-3 text-sm font-medium text-red-700",children:O})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex w-full gap-3",children:[e.jsx("button",{type:"button",onClick:s,disabled:v||A!=="",className:"flex-1 rounded-xl bg-gray-100 px-6 py-3 font-bold text-gray-700 transition-colors hover:bg-gray-200 disabled:opacity-50",children:"关闭"}),e.jsxs("button",{type:"button",onClick:()=>void pe(),disabled:v||A!==""||o.auto_rate_enabled&&!o.rate_content.trim(),className:"ios-btn-primary flex flex-1 items-center justify-center gap-2 rounded-xl px-6 py-3 font-bold disabled:opacity-50",children:[v?e.jsx(Ee,{className:"h-4 w-4 animate-spin"}):e.jsx(Ge,{className:"h-4 w-4"}),"保存"]})]})})]})})},en=()=>{const[t,s]=r.useState([]),[l,o]=r.useState(!0),[x,v]=r.useState(""),[k,A]=r.useState(""),[b,O]=r.useState(""),[j,V]=r.useState(null),[Y,pe]=r.useState(""),[ce,w]=r.useState(!1),[M,de]=r.useState(""),[G,X]=r.useState("pending"),[U,fe]=r.useState(""),[ge,L]=r.useState(""),[K,ae]=r.useState(null),[Z,me]=r.useState(null),[R,E]=r.useState(null),[ee,T]=r.useState(null),[se,ke]=r.useState({loading:!1,saving:!1,canOpen:!1,enabled:!1,error:""}),[ye,z]=r.useState([]),[m,f]=r.useState([]),[W,q]=r.useState(!1),[ne,be]=r.useState(!1),[ve,De]=r.useState(!1),[Ne,c]=r.useState(""),[S,Q]=r.useState({remark:"",cookie:"",auto_confirm:!1,pause_duration:0,username:"",login_password:"",show_browser:!1,showLoginPassword:!1,clear_password:!1}),[u,d]=r.useState({ai_enabled:!1,max_discount_percent:10,max_discount_amount:100,max_bargain_rounds:3,custom_prompts:""}),[F,I]=r.useState(!1),[H,P]=r.useState({sessionId:"",status:"idle",message:"",qrCodeUrl:""}),Ce=r.useRef(null),Re=r.useRef(null),xe=r.useRef(null),Pe=r.useRef(null),le=r.useRef(null),g=r.useRef(null),y=r.useRef(null),D=r.useRef(null),J=r.useRef(null),Se=r.useRef(null),$e=r.useRef(null),Le=r.useRef(null),Ae=r.useRef(0);Ce.current===null&&(Ce.current=Zr()),Re.current===null&&(Re.current=Ut()),xe.current===null&&(xe.current=Ut()),Pe.current===null&&(Pe.current=Ut()),le.current===null&&(le.current=Ut());const te=()=>{$e.current!==null&&(window.clearTimeout($e.current),$e.current=null)},je=()=>{Le.current!==null&&(window.clearTimeout(Le.current),Le.current=null)},p=()=>{var i;(i=Ce.current)==null||i.stop()},$=()=>{var i,N;(i=J.current)==null||i.abort(),(N=Re.current)==null||N.cancel(),p(),te(),w(!1)},ie=()=>{te(),$e.current=window.setTimeout(()=>{$e.current=null,w(!1),re()},1e3)},re=async()=>{var a,h,_,B,oe;const i=xe.current.next();(a=g.current)==null||a.abort();const N=new AbortController;g.current=N,o(!0);try{const ue={signal:N.signal},[he,qe]=await Promise.allSettled([Mt(ue),Kl(ue)]);if(!((h=xe.current)!=null&&h.isCurrent(i)))return;if(he.status==="rejected")throw he.reason;const we=he.value,ot=qe.status==="fulfilled"?qe.value:{};qe.status==="rejected"&&console.error("Failed to load AI settings:",qe.reason);const qa=we.map(gt=>{var vs,ws,ks,Cs,Ss;return{...gt,ai_enabled:((vs=ot[gt.id])==null?void 0:vs.ai_enabled)??!1,max_discount_percent:((ws=ot[gt.id])==null?void 0:ws.max_discount_percent)??10,max_discount_amount:((ks=ot[gt.id])==null?void 0:ks.max_discount_amount)??100,max_bargain_rounds:((Cs=ot[gt.id])==null?void 0:Cs.max_bargain_rounds)??3,custom_prompts:((Ss=ot[gt.id])==null?void 0:Ss.custom_prompts)??""}});(_=xe.current)!=null&&_.isCurrent(i)&&s(qa)}catch(ue){(B=xe.current)!=null&&B.isCurrent(i)&&!N.signal.aborted&&console.error("Failed to load accounts:",ue)}finally{(oe=xe.current)!=null&&oe.isCurrent(i)&&o(!1)}};r.useEffect(()=>{let i=!1,N=null;const a=new AbortController,h=async()=>{try{const _=await ps({signal:a.signal,timeoutMs:1e4});i||s(B=>Kr(B,_))}catch(_){i||console.error("Failed to load account runtime statuses:",_)}finally{i||(N=window.setTimeout(()=>void h(),2e3))}};return re().finally(()=>{i||h()}),()=>{i=!0,a.abort(),N!==null&&window.clearTimeout(N)}},[]),r.useEffect(()=>()=>{var i,N,a,h,_,B,oe,ue,he;p(),(i=Re.current)==null||i.cancel(),(N=xe.current)==null||N.cancel(),(a=Pe.current)==null||a.cancel(),(h=le.current)==null||h.cancel(),(_=g.current)==null||_.abort(),(B=y.current)==null||B.abort(),(oe=D.current)==null||oe.abort(),(ue=J.current)==null||ue.abort(),(he=Se.current)==null||he.abort(),te(),Ae.current+=1,je()},[]);const ze=i=>{if(!i.enabled||i.runtime_state==="disabled")return{label:"已停用",badge:"bg-gray-100 text-gray-500",dot:"bg-gray-300"};switch(i.runtime_state){case"online":return{label:"在线",badge:"bg-green-100 text-green-700",dot:"bg-green-500"};case"starting":case"connecting":return{label:"连接中",badge:"bg-blue-100 text-blue-700",dot:"bg-blue-500"};case"reconnecting":return{label:"重连中",badge:"bg-amber-100 text-amber-700",dot:"bg-amber-500"};case"auth_expired":return{label:"登录已失效",badge:"bg-red-100 text-red-700",dot:"bg-red-500"};case"verification_required":return{label:"需要验证",badge:"bg-orange-100 text-orange-700",dot:"bg-orange-500"};case"error":case"stopped":return{label:"运行异常",badge:"bg-red-100 text-red-700",dot:"bg-red-500"};default:return{label:"状态检测中",badge:"bg-gray-100 text-gray-600",dot:"bg-gray-400"}}},He=async(i,N)=>{await ql(i,!N),re()},Xe=i=>{b||(pe(""),V(i))},mt=()=>{b||(pe(""),V(null))},Ue=async()=>{const i=j;if(!(!i||b)){O(i.id),pe("");try{await Fl(i.id),s(N=>N.filter(a=>a.id!==i.id)),V(null)}catch(N){console.error("删除账号失败:",N),pe((N==null?void 0:N.message)||"删除账号失败,请稍后重试")}finally{O("")}}},We=async i=>{A(i.id);try{const N=await Gl(i.id);N!=null&&N.profile_error&&alert("资料刷新失败:"+N.profile_error),await re()}catch(N){console.error("刷新账号资料失败:",N),alert((N==null?void 0:N.message)||"刷新账号资料失败,请先重新授权该账号")}finally{A("")}},pt=async i=>{var B,oe;const N=Pe.current.next();(B=y.current)==null||B.abort();const a=new AbortController;y.current=a,be(!0),q(!1),De(!1),c("");const[h,_]=await Promise.allSettled([Aa({signal:a.signal}),Mr(i,{signal:a.signal})]);(oe=Pe.current)!=null&&oe.isCurrent(N)&&(h.status==="fulfilled"?z(h.value.data||[]):(z([]),c("通知渠道列表加载失败,请重试")),_.status==="fulfilled"?(f(_.value||[]),q(!0)):(f([]),c("通知绑定加载失败;本次保存不会修改现有绑定")),be(!1))},kt=async i=>{var a;Ae.current+=1,(a=Se.current)==null||a.abort(),je(),P({sessionId:"",status:"idle",message:"",qrCodeUrl:""}),E(i),Q({remark:i.remark||i.note||"",cookie:i.cookie||i.value||"",auto_confirm:i.auto_confirm||!1,pause_duration:i.pause_duration||0,username:i.username||"",login_password:i.login_password||"",show_browser:i.show_browser||!1,showLoginPassword:!1,clear_password:!1}),me("edit"),ke({loading:!0,saving:!1,canOpen:!1,enabled:!1,error:""});const[,N]=await Promise.allSettled([pt(i.id),Ul(i.id)]);N.status==="fulfilled"?ke({loading:!1,saving:!1,canOpen:N.value.can_open_long_login,enabled:N.value.enabled,error:""}):ke({loading:!1,saving:!1,canOpen:!1,enabled:!1,error:"无法读取闲鱼保存登录信息状态"})},Ct=async()=>{if(!R||se.loading||se.saving||!se.canOpen)return;const i=!se.enabled;ke(N=>({...N,saving:!0,error:""}));try{const N=await Wl(R.id,i);ke({loading:!1,saving:!1,canOpen:N.can_open_long_login,enabled:N.enabled,error:""})}catch(N){ke(a=>({...a,saving:!1,error:N instanceof Error?N.message:"保存登录信息设置失败"}))}},St=async i=>{var h,_,B,oe;const N=le.current.next();(h=D.current)==null||h.abort();const a=new AbortController;D.current=a,E(i),me("ai-settings"),I(!0);try{const ue=await Rr(i.id,{signal:a.signal});if(!((_=le.current)!=null&&_.isCurrent(N)))return;d({ai_enabled:ue.ai_enabled??!1,max_discount_percent:ue.max_discount_percent??10,max_discount_amount:ue.max_discount_amount??100,max_bargain_rounds:ue.max_bargain_rounds??3,custom_prompts:ue.custom_prompts??""})}catch(ue){(B=le.current)!=null&&B.isCurrent(N)&&console.error("Failed to load AI settings:",ue)}finally{(oe=le.current)!=null&&oe.isCurrent(N)&&I(!1)}},lt=async()=>{if(R){I(!0);try{const i={};S.remark!==(R.remark||R.note||"")&&(i.remark=S.remark),S.cookie&&S.cookie!==(R.cookie||R.value||"")&&(i.cookie=S.cookie),S.auto_confirm!==R.auto_confirm&&(i.auto_confirm=S.auto_confirm),Jr(S.pause_duration,R)&&(i.pause_duration=S.pause_duration);const N=Vr(R,S);N&&Object.assign(i,N),Qr(W,ve)&&(i.channel_ids=m),Object.keys(i).length>0&&await zl(R.id,i),me(null),re()}catch(i){console.error("更新账号失败:",i),alert("更新失败,请重试")}finally{I(!1)}}},rt=async()=>{if(!(!R||S.pause_duration<=0)){I(!0);try{const i=await Bl(R.id,S.pause_duration);E({...R,pause_duration:S.pause_duration,paused:(i==null?void 0:i.paused)===!0,paused_until:Number((i==null?void 0:i.paused_until)||0)}),await re()}catch(i){alert(i instanceof Error?i.message:"重新暂停失败")}finally{I(!1)}}},Lt=async()=>{if(R){I(!0);try{await Pr(R.id,u),me(null),re()}catch(i){console.error("更新AI设置失败:",i),alert("更新失败,请重试")}finally{I(!1)}}},nt=async(i,N)=>{var h;(h=Se.current)==null||h.abort();const a=new AbortController;Se.current=a;try{const _=await Vl(i,a.signal);if(N!==Ae.current)return;if(_.status==="success"){je(),P({sessionId:i,status:"success",message:_.message||"账号密码登录成功,授权信息已更新",qrCodeUrl:""}),Q(B=>({...B,login_password:"",showLoginPassword:!1})),await re();return}if(_.status==="processing"||_.status==="verification_required"){P({sessionId:i,status:_.status,message:_.message||(_.status==="verification_required"?"账号触发风控,需要完成人脸识别":"登录处理中"),qrCodeUrl:_.qr_code_url||""}),je(),Le.current=window.setTimeout(()=>void nt(i,N),1500);return}je(),P({sessionId:i,status:"failed",message:_.error||_.message||"密码登录失败,请检查账号信息后重试",qrCodeUrl:""})}catch(_){if(N!==Ae.current)return;je(),P({sessionId:i,status:"failed",message:_ instanceof Error?_.message:"查询密码登录状态失败",qrCodeUrl:""})}},ut=async()=>{var a;if(!R)return;const i=S.username.trim();if(!i||!S.login_password){alert("请先填写登录账号和本次登录密码");return}je(),(a=Se.current)==null||a.abort();const N=++Ae.current;P({sessionId:"",status:"processing",message:"正在启动密码登录…",qrCodeUrl:""});try{const h=await Jl({account_id:R.id,account:i,password:S.login_password,show_browser:S.show_browser});if(N!==Ae.current)return;if(!h.success||!h.session_id)throw new Error(h.message||"无法启动密码登录");P({sessionId:h.session_id,status:"processing",message:h.message||"登录处理中",qrCodeUrl:""}),await nt(h.session_id,N)}catch(h){if(N!==Ae.current)return;P({sessionId:"",status:"failed",message:h instanceof Error?h.message:"启动密码登录失败",qrCodeUrl:""})}},et=async()=>{var N;const i=H.sessionId;if(Ae.current+=1,(N=Se.current)==null||N.abort(),je(),i)try{await Ql(i)}catch(a){console.error("取消密码登录失败",a)}P({sessionId:"",status:"idle",message:"",qrCodeUrl:""})},it=async()=>{var i,N;(i=Pe.current)==null||i.cancel(),(N=y.current)==null||N.abort(),(H.status==="processing"||H.status==="verification_required")&&await et(),me(null)},Ve=()=>{var i,N;(i=le.current)==null||i.cancel(),(N=D.current)==null||N.abort(),me(null)},ht=async(i,N)=>{const a=await Ml(i,N==null?void 0:N.id);if(!a.success||!a.account_id)throw new Error(a.message||"保存扫码授权失败");return a.account_id},n=async i=>{var _,B,oe,ue;p(),(_=J.current)==null||_.abort();const N=new AbortController;J.current=N;const a=Re.current.next();te();const h=i||null;ae(h),w(!0),X("loading"),de(""),fe(""),L("");try{const he=await Dl({signal:N.signal});if(!((B=Re.current)!=null&&B.isCurrent(a)))return;if(he.success&&he.qr_code_url&&he.session_id){const qe=he.session_id;de(he.qr_code_url),X("waiting"),(oe=Ce.current)==null||oe.start(qe,Tl,{onSuccess:async()=>{try{if(!await ht(qe,h)){X("error");return}}catch(we){console.error("保存扫码授权失败",we),X("error");return}X("success"),ie()},onScanned:()=>{X("waiting")},onTerminalError:()=>{X("error")},onPollError:we=>{console.error("轮询扫码状态失败",we),X("error")},onVerificationRequired:we=>{X("verification"),we.face_qr_url&&L(we.face_qr_url),we.verification_screenshot&&fe(we.verification_screenshot)}})}}catch{if(!((ue=Re.current)!=null&&ue.isCurrent(a)))return;X("error")}};if(l)return e.jsx("div",{className:"p-20 flex justify-center",children:e.jsx(Ee,{className:"w-8 h-8 text-brand animate-spin"})});const C=t.filter(i=>{const N=x.trim().toLowerCase();return N?[i.id,i.nickname,i.remark,i.note,i.username,i.runtime_message].some(a=>(a||"").toLowerCase().includes(N)):!0});return e.jsxs("div",{className:"space-y-8 animate-fade-in relative",children:[e.jsxs("div",{className:"flex flex-col xl:flex-row xl:justify-between xl:items-end gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-4xl font-extrabold text-gray-900 tracking-tight",children:"账号管理"}),e.jsx("p",{className:"text-gray-500 mt-2 font-medium",children:"管理您的闲鱼授权账号及设置。建议给账号填写备注,便于多账号区分。"})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[e.jsx("input",{value:x,onChange:i=>v(i.target.value),placeholder:"搜索昵称 / 备注 / 账号ID",className:"ios-input px-4 py-3 rounded-2xl text-sm w-full sm:w-72"}),e.jsxs("button",{onClick:()=>n(),className:"ios-btn-primary flex items-center gap-2 px-6 py-3 rounded-2xl font-bold shadow-lg shadow-blue-200 transition-transform hover:scale-105 active:scale-95",children:[e.jsx(Zt,{className:"w-5 h-5"}),"扫码添加新账号"]})]})]}),e.jsxs("div",{className:"rounded-2xl border border-blue-100 bg-blue-50 px-5 py-4 text-sm text-blue-900 flex flex-col md:flex-row md:items-center md:justify-between gap-2",children:[e.jsxs("div",{className:"font-bold",children:["当前显示 ",C.length," / ",t.length," 个账号"]}),e.jsx("div",{className:"text-blue-700",children:"如果某个账号只显示 ID,点该账号右侧“刷新资料”;若刷新失败,先点二维码重新授权。"})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-6",children:[C.map(i=>{const N=ze(i),a=i.runtime_state==="auth_expired"||i.runtime_state==="verification_required";return e.jsx("div",{className:"ios-card rounded-xl p-6 group transition-all duration-300 hover:border-brand",children:e.jsxs("div",{className:"flex min-w-0 items-start gap-5 sm:gap-8",children:[e.jsxs("div",{className:"relative",children:[i.avatar_url?e.jsx("img",{src:i.avatar_url,alt:i.nickname||"账号头像",className:"w-20 h-20 rounded-full object-cover shadow-md ring-4 ring-white bg-gray-100"}):e.jsx("div",{className:"w-20 h-20 rounded-full bg-gray-100 text-gray-400 shadow-md ring-4 ring-white flex items-center justify-center",children:e.jsx(xt,{className:"w-9 h-9"})}),e.jsx("div",{className:`absolute -bottom-1 -right-1 w-6 h-6 rounded-full border-4 border-white flex items-center justify-center ${N.dot}`,children:i.runtime_state==="online"&&e.jsx(Qe,{className:"w-3 h-3 text-white"})})]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2.5 mb-1",children:[e.jsx("h3",{className:"text-xl font-extrabold text-gray-900 break-words",children:i.nickname||i.remark||`账号 ${i.id.substring(0,6)}...`}),e.jsx("span",{className:`px-2.5 py-0.5 rounded-lg text-xs font-bold ${N.badge}`,children:N.label}),i.ai_enabled&&e.jsxs("span",{className:"px-2.5 py-0.5 rounded-lg bg-purple-100 text-purple-700 text-xs font-bold flex items-center gap-1",children:[e.jsx(yt,{className:"w-3 h-3"})," AI"]}),i.auto_rate_enabled&&e.jsxs("span",{className:"flex items-center gap-1 rounded-lg bg-emerald-100 px-2.5 py-0.5 text-xs font-bold text-emerald-700",children:[e.jsx(Et,{className:"h-3 w-3"})," 自动评价"]}),i.auto_polish_enabled&&e.jsxs("span",{className:"flex items-center gap-1 rounded-lg bg-amber-100 px-2.5 py-0.5 text-xs font-bold text-amber-700",children:[e.jsx(js,{className:"h-3 w-3"})," 每日擦亮"]}),i.auto_confirm&&e.jsxs("span",{className:"flex items-center gap-1 rounded-lg bg-blue-50 px-2.5 py-0.5 text-xs font-bold text-blue-700",children:[e.jsx(Qe,{className:"h-3 w-3"})," 自动确认发货"]}),i.profile_error&&e.jsxs("span",{className:"px-2.5 py-0.5 rounded-lg bg-amber-100 text-amber-700 text-xs font-bold flex items-center gap-1",title:i.profile_error,children:[e.jsx(at,{className:"w-3 h-3"})," 资料未同步"]})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-between gap-4",children:[e.jsxs("div",{className:"text-sm font-medium text-gray-500",children:[e.jsx("p",{children:i.remark||i.note||"暂无备注"}),e.jsxs("p",{className:"font-mono text-xs text-gray-400",children:["ID: ",i.id]})]}),i.runtime_message&&i.runtime_state!=="online"&&i.runtime_state!=="disabled"&&e.jsxs("div",{className:`mb-3 flex flex-wrap items-center gap-2 text-sm font-medium ${a?"text-red-700":"text-amber-700"}`,children:[e.jsx(at,{className:"w-4 h-4 flex-shrink-0"}),e.jsx("span",{children:i.runtime_message}),a&&e.jsxs("button",{type:"button",onClick:()=>n(i),className:"inline-flex items-center gap-1.5 rounded-lg bg-red-50 px-2.5 py-1 text-xs font-bold text-red-700 hover:bg-red-100",children:[e.jsx(Zt,{className:"w-3.5 h-3.5"})," 重新授权"]})]}),i.paused&&e.jsxs("span",{className:"flex items-center gap-1.5 rounded-lg bg-blue-50 px-3 py-1.5 text-xs font-bold text-blue-700",children:[e.jsx(Is,{className:"h-3 w-3"})," 暂停处理中"]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-end gap-2",children:[e.jsx("button",{onClick:()=>We(i),disabled:k===i.id,className:"p-3 rounded-xl transition-colors text-gray-600 hover:bg-gray-100 disabled:opacity-50",title:"刷新昵称和头像",children:e.jsx(Be,{className:`w-5 h-5 ${k===i.id?"animate-spin":""}`})}),e.jsx("button",{onClick:()=>n(i),className:`p-3 rounded-xl transition-colors ${a?"text-red-600 bg-red-50 hover:bg-red-100":"text-blue-600 hover:bg-blue-50"}`,title:"重新扫码授权当前账号",children:e.jsx(Zt,{className:"w-5 h-5"})}),e.jsx("button",{onClick:()=>kt(i),className:"p-3 rounded-xl hover:bg-gray-100 transition-colors text-gray-600",title:"编辑账号",children:e.jsx(fa,{className:"w-5 h-5"})}),e.jsx("button",{onClick:()=>St(i),className:"p-3 rounded-xl hover:bg-purple-100 transition-colors text-purple-600",title:"AI设置",children:e.jsx(yt,{className:"w-5 h-5"})}),e.jsx("button",{onClick:()=>T(i),className:"p-3 rounded-xl hover:bg-amber-100 transition-colors text-amber-600",title:"自动评价与每日擦亮",children:e.jsx(ba,{className:"w-5 h-5"})}),e.jsx("button",{onClick:()=>He(i.id,i.enabled),className:`p-3 rounded-xl transition-colors ${i.enabled?"text-green-600 hover:bg-green-50":"text-gray-400 hover:bg-gray-100"}`,title:i.enabled?"停用账号":"启用账号",children:e.jsx(Ga,{className:"w-5 h-5"})}),e.jsx("button",{onClick:()=>Xe(i),disabled:b!=="",className:"p-3 rounded-xl hover:bg-red-100 transition-colors text-red-500 disabled:cursor-not-allowed disabled:opacity-40",title:b===i.id?"删除中…":`删除账号 ${i.nickname||i.remark||i.id}`,children:b===i.id?e.jsx(Ee,{className:"w-5 h-5 animate-spin"}):e.jsx(Je,{className:"w-5 h-5"})})]})]})]})]})},i.id)}),t.length===0&&e.jsxs("div",{className:"ios-card p-12 text-center",children:[e.jsx("div",{className:"w-20 h-20 bg-gray-100 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(xt,{className:"w-10 h-10 text-gray-400"})}),e.jsx("h3",{className:"text-lg font-bold text-gray-900",children:"暂无账号"}),e.jsx("p",{className:"text-gray-500 mt-1",children:"请点击右上角扫码添加您的闲鱼账号"})]}),t.length>0&&C.length===0&&e.jsxs("div",{className:"ios-card p-12 text-center",children:[e.jsx("h3",{className:"text-lg font-bold text-gray-900",children:"没有匹配的账号"}),e.jsx("p",{className:"text-gray-500 mt-1",children:"换一个关键词搜索昵称、备注或账号ID。"})]})]}),ee&&Me.createPortal(e.jsx(Xr,{account:ee,onClose:()=>T(null),onSaved:i=>{s(N=>N.map(a=>a.id===ee.id?{...a,auto_rate_enabled:i.auto_rate_enabled,rate_content:i.rate_content,auto_polish_enabled:i.auto_polish_enabled,polish_time:i.polish_time,last_rate_scan_at:i.last_rate_scan_at,last_polish_date:i.last_polish_date,last_polish_at:i.last_polish_at}:a))}}),document.body),j&&Me.createPortal(e.jsx("div",{className:"modal-overlay-centered",role:"presentation",children:e.jsxs("div",{className:"h-fit w-full max-w-[400px] self-center overflow-hidden rounded-2xl border border-white/80 bg-white shadow-modal",role:"dialog","aria-modal":"true","aria-labelledby":"delete-account-title","aria-describedby":"delete-account-description",children:[e.jsxs("div",{className:"relative overflow-hidden border-b border-red-100 bg-gradient-to-br from-red-50 via-white to-orange-50 px-5 py-5",children:[e.jsx("div",{className:"absolute -right-12 -top-16 h-36 w-36 rounded-full bg-red-200/35 blur-2xl"}),e.jsxs("div",{className:"relative flex items-start gap-4",children:[e.jsx("div",{className:"flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-xl bg-red-600 text-white shadow-md shadow-red-200",children:e.jsx(Je,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h3",{id:"delete-account-title",className:"text-lg font-extrabold tracking-tight text-gray-950",children:"删除这个账号?"}),e.jsx("p",{id:"delete-account-description",className:"mt-1 text-xs leading-5 text-gray-600",children:"删除后,该账号的关联配置也会一并清理,此操作无法撤销。"})]}),e.jsx("button",{type:"button",onClick:mt,disabled:b!=="",className:"flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-full text-gray-400 transition-colors hover:bg-white hover:text-gray-700 disabled:cursor-not-allowed disabled:opacity-40","aria-label":"关闭删除确认",children:e.jsx(Te,{className:"h-5 w-5"})})]})]}),e.jsxs("div",{className:"px-5 py-4",children:[e.jsxs("div",{className:"rounded-xl border border-gray-100 bg-gray-50/80 px-4 py-3",children:[e.jsx("div",{className:"text-sm font-extrabold text-gray-900",children:j.nickname||j.remark||"未命名账号"}),j.remark&&j.nickname&&e.jsxs("div",{className:"mt-1 text-sm text-gray-500",children:["备注:",j.remark]}),e.jsxs("div",{className:"mt-1.5 break-all font-mono text-[11px] text-gray-400",children:["ID: ",j.id]})]}),b===j.id&&e.jsxs("div",{className:"mt-4 flex items-center gap-3 rounded-xl border border-blue-100 bg-blue-50 px-4 py-3",role:"progressbar","aria-label":"正在删除账号",children:[e.jsx(Ee,{className:"h-5 w-5 flex-shrink-0 animate-spin text-brand"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-extrabold text-blue-950",children:"正在删除账号"}),e.jsx("div",{className:"mt-0.5 text-xs text-blue-700",children:"正在清理关联数据,请保持页面打开…"})]})]}),Y&&e.jsxs("div",{className:"mt-4 flex items-start gap-3 rounded-xl border border-red-100 bg-red-50 px-4 py-3",role:"alert",children:[e.jsx(at,{className:"mt-0.5 h-5 w-5 flex-shrink-0 text-red-600"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-extrabold text-red-800",children:"删除失败"}),e.jsx("div",{className:"mt-1 text-xs leading-5 text-red-700",children:Y})]})]})]}),e.jsxs("div",{className:"flex gap-3 border-t border-gray-100 bg-gray-50/70 px-5 py-4",children:[e.jsx("button",{type:"button",onClick:mt,disabled:b!=="",className:"flex-1 rounded-xl bg-white px-5 py-3 text-sm font-extrabold text-gray-700 ring-1 ring-gray-200 transition-colors hover:bg-gray-100 disabled:cursor-not-allowed disabled:opacity-50",children:"取消"}),e.jsx("button",{type:"button",onClick:()=>void Ue(),disabled:b!=="",className:"flex flex-1 items-center justify-center gap-2 rounded-xl bg-red-600 px-5 py-3 text-sm font-extrabold text-white shadow-lg shadow-red-200 transition-colors hover:bg-red-700 disabled:cursor-not-allowed disabled:bg-red-400",children:b===j.id?e.jsxs(e.Fragment,{children:[e.jsx(Ee,{className:"h-4 w-4 animate-spin"}),"处理中"]}):e.jsxs(e.Fragment,{children:[e.jsx(Je,{className:"h-4 w-4"}),"确认删除"]})})]})]})}),document.body),ce&&Me.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container relative",style:{maxWidth:"26rem"},children:[e.jsx("button",{onClick:$,className:"absolute top-4 right-4 z-10 w-9 h-9 flex items-center justify-center bg-gray-100 hover:bg-gray-200 rounded-full transition-colors",children:e.jsx(Te,{className:"w-5 h-5 text-gray-600"})}),e.jsx("div",{className:"modal-body",children:e.jsxs("div",{className:"text-center",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900 mb-2",children:K?"重新授权账号":"扫码添加账号"}),e.jsx("p",{className:"text-gray-500 mb-8 font-medium",children:K?`请用闲鱼APP扫码,为「${K.nickname||K.remark||K.id}」刷新授权`:"请打开闲鱼APP扫描下方二维码"}),e.jsxs("div",{className:`w-full bg-surface-subtle rounded-xl mx-auto flex items-center justify-center overflow-hidden border-4 border-white shadow-inner mb-6 relative ${G==="verification"?"max-w-72 min-h-64 h-auto p-2":"max-w-64 aspect-square"}`,children:[G==="loading"&&e.jsx(Ee,{className:"w-10 h-10 text-brand animate-spin"}),G==="waiting"&&e.jsx(Hs,{src:M,alt:"闲鱼登录二维码",className:"p-2"}),G==="success"&&e.jsxs("div",{className:"absolute inset-0 bg-white/95 flex flex-col items-center justify-center text-green-600 animate-fade-in",children:[e.jsx("div",{className:"w-16 h-16 bg-green-100 rounded-full flex items-center justify-center mb-4",children:e.jsx(Qe,{className:"w-8 h-8"})}),e.jsx("span",{className:"font-bold text-lg",children:"登录成功"})]}),G==="error"&&e.jsxs("div",{className:"px-5 text-center",children:[e.jsx("span",{className:"block text-red-600 font-bold",children:"二维码获取失败"}),e.jsx("span",{className:"mt-2 block text-xs leading-5 text-gray-500",children:"请关闭窗口后重新发起扫码登录。"})]}),G==="verification"&&e.jsx(Yr,{faceQrUrl:ge,verificationScreenshot:U})]}),G!=="verification"&&e.jsx("p",{className:"text-xs text-gray-400 font-medium bg-gray-50 py-2 rounded-xl",children:"二维码有效期为5分钟,请尽快扫码。"})]})})]})}),document.body),Z==="edit"&&R&&Me.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"600px"},children:[e.jsxs("div",{className:"modal-header",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"编辑账号"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:R.nickname||R.remark||R.id})]}),e.jsx("button",{onClick:()=>void it(),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors flex-shrink-0",children:e.jsx(Te,{className:"w-5 h-5 text-gray-500"})})]}),e.jsxs("div",{className:"modal-body space-y-6",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"账号ID"}),e.jsx("input",{type:"text",value:R.id,disabled:!0,className:"w-full ios-input px-4 py-3 rounded-xl bg-gray-50 text-gray-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"备注"}),e.jsx("input",{type:"text",value:S.remark,onChange:i=>Q({...S,remark:i.target.value}),placeholder:"为账号添加备注",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"Cookie"}),e.jsx("textarea",{value:S.cookie,onChange:i=>Q({...S,cookie:i.target.value}),placeholder:"更新账号Cookie",className:"w-full ios-input px-4 py-3 rounded-xl h-32 resize-none font-mono text-xs"}),e.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:["当前Cookie长度: ",S.cookie.length," 字符"]})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-gray-50 rounded-xl",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"font-bold text-gray-900 flex items-center gap-2",children:[e.jsx(Qe,{className:"w-4 h-4 text-green-500"}),"自动确认发货"]}),e.jsx("div",{className:"text-xs text-gray-500",children:"自动将闲鱼订单标记为已发货"})]}),e.jsx("button",{type:"button",onClick:()=>Q({...S,auto_confirm:!S.auto_confirm}),className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${S.auto_confirm?"bg-brand":"bg-gray-300"}`,children:e.jsx("span",{className:`absolute left-1 top-1 w-6 h-6 bg-white rounded-full shadow-md transition-transform duration-300 ${S.auto_confirm?"translate-x-6":"translate-x-0"}`})})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-700 mb-2 flex items-center gap-2",children:[e.jsx(Is,{className:"w-4 h-4 text-blue-500"}),"暂停处理时长(分钟)"]}),e.jsx("input",{type:"number",value:S.pause_duration,onChange:i=>Q({...S,pause_duration:parseInt(i.target.value)||0}),placeholder:"0",min:"0",max:"1440",className:"w-full ios-input px-4 py-3 rounded-xl"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"设置后会暂停处理该账号的订单,到时间后自动恢复"}),S.pause_duration>0&&!R.paused&&S.pause_duration===(R.pause_duration||0)&&e.jsx("button",{type:"button",disabled:F,onClick:()=>void rt(),className:"mt-3 px-4 py-2 rounded-xl bg-amber-50 text-amber-700 hover:bg-amber-100 text-sm font-bold disabled:opacity-50",children:"立即按当前时长重新暂停"})]}),e.jsxs("div",{className:"border-t border-gray-200 pt-6",children:[e.jsxs("h3",{className:"text-lg font-bold text-gray-900 mb-4 flex items-center gap-2",children:[e.jsx(Ka,{className:"w-5 h-5 text-blue-500"}),"登录信息"]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 rounded-xl bg-blue-50 p-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-bold text-gray-900",children:"保存登录信息"}),e.jsx("div",{className:"mt-1 text-xs text-gray-500",children:"状态直接读取并修改闲鱼官方长登录设置"}),se.error&&e.jsx("div",{className:"mt-1 text-xs text-red-600",children:se.error})]}),e.jsx("button",{type:"button","aria-label":"保存登录信息",disabled:se.loading||se.saving||!se.canOpen,onClick:()=>void Ct(),className:`relative h-8 w-14 flex-shrink-0 rounded-full transition-colors ${se.enabled?"bg-brand":"bg-gray-300"} disabled:cursor-not-allowed disabled:opacity-50`,children:e.jsx("span",{className:`absolute left-1 top-1 h-6 w-6 rounded-full bg-white shadow-md transition-transform ${se.enabled?"translate-x-6":"translate-x-0"}`})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"用户名"}),e.jsx("input",{type:"text",value:S.username,onChange:i=>Q({...S,username:i.target.value}),placeholder:"闲鱼账号/手机号",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"登录密码"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:S.showLoginPassword?"text":"password",value:S.login_password,onChange:i=>Q({...S,login_password:i.target.value,clear_password:!1}),placeholder:"用于自动登录",className:"w-full ios-input px-4 py-3 rounded-xl pr-12"}),e.jsx("button",{type:"button",onClick:()=>Q({...S,showLoginPassword:!S.showLoginPassword}),className:"absolute right-3 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600",children:S.showLoginPassword?e.jsx(dt,{className:"w-5 h-5"}):e.jsx(st,{className:"w-5 h-5"})})]}),e.jsxs("label",{className:"mt-3 flex items-center gap-3 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:S.clear_password,onChange:i=>Q({...S,clear_password:i.target.checked,login_password:i.target.checked?"":S.login_password}),className:"w-4 h-4 accent-brand"}),e.jsx("span",{className:"text-sm font-bold text-gray-700",children:"清空已保存密码"})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-bold text-gray-900",children:"登录时显示浏览器"}),e.jsx("div",{className:"text-xs text-gray-500",children:"调试时可开启查看登录过程"})]}),e.jsx("button",{type:"button",onClick:()=>Q({...S,show_browser:!S.show_browser}),className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${S.show_browser?"bg-brand":"bg-gray-300"}`,children:e.jsx("span",{className:`absolute left-1 top-1 w-6 h-6 bg-white rounded-full shadow-md transition-transform duration-300 ${S.show_browser?"translate-x-6":"translate-x-0"}`})})]}),e.jsxs("div",{className:"rounded-xl border border-blue-100 bg-blue-50 p-4 space-y-3",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-bold text-blue-950",children:"立即执行账号密码登录"}),e.jsx("div",{className:"text-xs text-blue-700 mt-1",children:"需要在上方重新输入本次登录密码;成功后后端会更新 Cookie 和保存的登录信息。"})]}),H.status==="processing"||H.status==="verification_required"?e.jsx("button",{type:"button",onClick:et,className:"px-4 py-2 rounded-xl bg-white text-red-600 font-bold text-sm border border-red-100",children:"取消登录"}):e.jsx("button",{type:"button",onClick:ut,className:"px-4 py-2 rounded-xl bg-blue-600 text-white font-bold text-sm whitespace-nowrap",children:"密码登录刷新授权"})]}),H.message&&e.jsx("div",{className:`text-sm font-medium ${H.status==="failed"?"text-red-700":H.status==="success"?"text-green-700":"text-blue-800"}`,children:H.message}),H.status==="verification_required"&&e.jsxs("div",{className:"rounded-xl border border-amber-200 bg-amber-50 p-3 text-amber-900",children:[e.jsx("div",{className:"font-extrabold",children:"账号已触发平台风控,需要完成人脸识别"}),e.jsx("div",{className:"text-xs mt-1 leading-5",children:"请在闲鱼 App 或已打开的登录浏览器中按提示完成验证。本页面不会提供可直接打开的风控链接。"}),H.qrCodeUrl&&e.jsx("div",{className:"mt-3 aspect-square w-48 overflow-hidden rounded-xl border bg-white",children:e.jsx(Hs,{src:H.qrCodeUrl,alt:"密码登录风控二维码",className:"p-2"})})]})]})]})]}),(ye.length>0||ne||Ne)&&e.jsxs("div",{className:"border-t border-gray-200 pt-6",children:[e.jsxs("h3",{className:"text-lg font-bold text-gray-900 mb-1 flex items-center gap-2",children:[e.jsx(jt,{className:"w-5 h-5 text-blue-500"}),"通知渠道绑定"]}),e.jsx("p",{className:"text-xs text-gray-500 mb-4",children:"勾选后,该账号的 token 失效、自动恢复失败、风控验证等事件会推送到这些渠道"}),ne&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-500",children:[e.jsx(Ee,{className:"w-4 h-4 animate-spin"}),"正在加载通知绑定"]}),Ne&&!ne&&e.jsxs("div",{className:"mb-3 rounded-xl bg-amber-50 p-3 text-sm text-amber-800 flex items-center justify-between gap-3",children:[e.jsx("span",{children:Ne}),e.jsx("button",{type:"button",className:"font-bold whitespace-nowrap",onClick:()=>pt(R.id),children:"重试"})]}),e.jsx("div",{className:"space-y-2",children:ye.map(i=>{const N=m.includes(Number(i.id));return e.jsxs("label",{className:"flex items-center gap-3 p-3 rounded-xl border border-gray-200 hover:bg-gray-50 cursor-pointer transition-colors",children:[e.jsx("button",{type:"button",onClick:()=>{W&&(f(a=>N?a.filter(h=>h!==Number(i.id)):[...a,Number(i.id)]),De(!0))},disabled:!W,className:`w-5 h-5 rounded-md border-2 flex items-center justify-center transition-colors flex-shrink-0 ${N?"bg-brand border-brand":"bg-white border-gray-300"}`,children:N&&e.jsx(Qe,{className:"w-3.5 h-3.5 text-white"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-bold text-gray-900 text-sm",children:i.name}),e.jsxs("div",{className:"text-xs text-gray-500",children:[i.type,i.enabled?"":" · 已停用"]})]})]},i.id)})})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:()=>void it(),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",disabled:F,children:"取消"}),e.jsxs("button",{onClick:lt,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",disabled:F,children:[F?e.jsx(Ee,{className:"w-4 h-4 animate-spin"}):e.jsx(Ge,{className:"w-4 h-4"}),F?"保存中...":"保存"]})]})})]})}),document.body),Z==="ai-settings"&&R&&Me.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"600px"},children:[e.jsxs("div",{className:"modal-header",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-2xl font-extrabold text-gray-900 flex items-center gap-2",children:[e.jsx(yt,{className:"w-6 h-6 text-purple-500"}),"AI助手设置"]}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:R.nickname||R.remark||R.id})]}),e.jsx("button",{onClick:Ve,className:"p-2 rounded-xl hover:bg-gray-100 transition-colors flex-shrink-0",children:e.jsx(Te,{className:"w-5 h-5 text-gray-500"})})]}),e.jsxs("div",{className:"modal-body space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 bg-purple-50 rounded-xl",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"font-bold text-gray-900 flex items-center gap-2",children:[e.jsx(yt,{className:"w-4 h-4 text-purple-500"}),"启用AI自动回复"]}),e.jsx("div",{className:"text-xs text-gray-500",children:"AI将自动处理买家的砍价消息"})]}),e.jsx("button",{type:"button",onClick:()=>d({...u,ai_enabled:!u.ai_enabled}),className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${u.ai_enabled?"bg-brand":"bg-gray-300"}`,children:e.jsx("span",{className:`absolute left-1 top-1 w-6 h-6 bg-white rounded-full shadow-md transition-transform duration-300 ${u.ai_enabled?"translate-x-6":"translate-x-0"}`})})]}),e.jsxs("div",{className:"border-t border-gray-200 pt-6",children:[e.jsx("h3",{className:"text-lg font-bold text-gray-900 mb-4",children:"砍价策略"}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"最大折扣比例 (%)"}),e.jsx("input",{type:"number",value:u.max_discount_percent,onChange:i=>d({...u,max_discount_percent:parseInt(i.target.value)||0}),className:"w-full ios-input px-4 py-3 rounded-xl",min:"0",max:"100"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"例如:10 表示最多降价 10%;设为 0 表示不允许降价"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"最大折扣金额 (元)"}),e.jsx("input",{type:"number",value:u.max_discount_amount,onChange:i=>d({...u,max_discount_amount:parseInt(i.target.value)||0}),className:"w-full ios-input px-4 py-3 rounded-xl",min:"0"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"例如:100 表示最多降价 100 元;设为 0 表示不允许降价"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"最大砍价轮次"}),e.jsx("input",{type:"number",value:u.max_bargain_rounds,onChange:i=>d({...u,max_bargain_rounds:parseInt(i.target.value)||1}),className:"w-full ios-input px-4 py-3 rounded-xl",min:"1",max:"10"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"买家最多可以砍价的次数"})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"自定义提示词(可选)"}),e.jsx("textarea",{value:u.custom_prompts,onChange:i=>d({...u,custom_prompts:i.target.value}),placeholder:`输入自定义的AI回复规则或风格指引...
|
||
|
||
例如:回复时保持礼貌专业、使用简洁的语言、强调产品质量等`,className:"w-full ios-input px-4 py-3 rounded-xl h-40 resize-none"})]}),e.jsxs("div",{className:"bg-blue-50 border border-blue-200 rounded-xl p-4",children:[e.jsxs("h4",{className:"font-bold text-blue-900 mb-2 flex items-center gap-2",children:[e.jsx(bs,{className:"w-4 h-4"}),"AI如何工作"]}),e.jsxs("ul",{className:"text-xs text-blue-800 space-y-1",children:[e.jsx("li",{children:"• 自动识别买家的砍价请求"}),e.jsx("li",{children:"• 根据设定的策略智能回复"}),e.jsx("li",{children:"• 在合理范围内同意降价或礼貌拒绝"}),e.jsx("li",{children:"• 保持专业友好的沟通风格"})]})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:Ve,className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",disabled:F,children:"取消"}),e.jsxs("button",{onClick:Lt,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",disabled:F,children:[F?e.jsx(Ee,{className:"w-4 h-4 animate-spin"}):e.jsx(Ge,{className:"w-4 h-4"}),F?"保存中...":"保存"]})]})})]})}),document.body)]})},tn=t=>({total:Number((t==null?void 0:t.total)||0),success_count:Number((t==null?void 0:t.success_count)||0),failed_count:Number((t==null?void 0:t.failed_count)||0),results:Array.isArray(t==null?void 0:t.results)?t.results.map(s=>({order_id:String((s==null?void 0:s.order_id)||"unknown"),success:(s==null?void 0:s.success)===!0,message:String((s==null?void 0:s.message)||"")})):[]}),sn=t=>(t==null?void 0:t.results.filter(s=>!s.success))||[],Ys=({status:t})=>{const s={processing:"bg-blue-100 text-blue-800",pending_ship:"bg-brand text-white",shipped:"bg-blue-100 text-blue-700",completed:"bg-green-100 text-green-700",cancelled:"bg-gray-100 text-gray-500",refunding:"bg-red-100 text-red-600",unknown:"bg-gray-100 text-gray-500"},l={processing:"处理中",pending_ship:"待发货",shipped:"已发货",completed:"已完成",cancelled:"已取消",refunding:"退款中",unknown:"未知"};return e.jsx("span",{className:`px-3 py-1.5 rounded-lg text-xs font-bold ${s[t]||s.cancelled}`,children:l[t]||t})},an=()=>{const[t,s]=r.useState([]),[l,o]=r.useState([]),[x,v]=r.useState([]),[k,A]=r.useState({}),[b,O]=r.useState("all"),[j,V]=r.useState(""),[Y,pe]=r.useState(""),[ce,w]=r.useState(""),M=r.useRef(0),[de,G]=r.useState(1),[X,U]=r.useState(1),[fe,ge]=r.useState(!1),[L,K]=r.useState(!1),[ae,Z]=r.useState(!1),[me,R]=r.useState(!1),[E,ee]=r.useState(null),[T,se]=r.useState(null),[ke,ye]=r.useState({}),[z,m]=r.useState(!1),[f,W]=r.useState(""),[q,ne]=r.useState(!1),[be,ve]=r.useState(null),[De,Ne]=r.useState(null),[c,S]=r.useState(null),[Q,u]=r.useState(!1),[d,F]=r.useState(null),[I,H]=r.useState(null),P=async()=>{const p=++M.current;ge(!0);try{const $=await Hl(j||void 0,b,de,20,ce);if(p!==M.current)return;s($.data),U($.total_pages)}catch($){console.error("加载订单失败:",$)}finally{p===M.current&&ge(!1)}},Ce=(p,$,ie)=>{if(ie&&ie.trim())return ie;if(k[`${p}:${$}`])return k[`${p}:${$}`];const re=l.find(ze=>{if(ie&&ze.item_title){const He=ie.toLowerCase(),Xe=ze.item_title.toLowerCase();return Xe.includes(He)||He.includes(Xe)}return!1});return re!=null&&re.item_title?re.item_title:"未知商品"},Re=p=>{const $={};p.forEach(ie=>{ie.item_id&&($[`${ie.cookie_id}:${ie.item_id}`]=ie.item_title||ie.item_id)}),A($)};r.useEffect(()=>{const p=window.setTimeout(()=>{G(1),w(Y.trim())},300);return()=>window.clearTimeout(p)},[Y]),r.useEffect(()=>{P()},[j,b,de,ce]),r.useEffect(()=>{Promise.all([Mt(),vt()]).then(([p,$])=>{v(p),o($),Re($)}).catch(p=>{console.error("加载商品列表失败:",p)})},[]);const xe=r.useMemo(()=>new Map(x.map(p=>[p.id,p])),[x]),Pe=p=>{const $=xe.get(p),ie=($==null?void 0:$.remark)||($==null?void 0:$.nickname);return ie?`${ie} · ${p.slice(0,6)}`:`账号 ${p.slice(0,8)}`},le=p=>{const $=xe.get(p);return($==null?void 0:$.remark)||($==null?void 0:$.nickname)||"未命名账号"},g=async()=>{ge(!0);try{const p=await Xl(j||void 0,b);await P(),p!=null&&p.message&&alert(p.message)}catch(p){console.error("同步订单失败:",p),alert((p==null?void 0:p.message)||"同步失败,请重试")}finally{ge(!1)}},y=p=>{W(p),ve(null),m(!0)},D=async p=>{var $;ne(!0),ve(null);try{const ie=await tr([f],p),re=($=ie==null?void 0:ie.results)==null?void 0:$[0];re!=null&&re.success?(ve({success:!0,message:re.message}),P()):ve({success:!1,message:(re==null?void 0:re.message)||"发货失败"})}catch(ie){ve({success:!1,message:(ie==null?void 0:ie.message)||"请求失败"})}finally{ne(!1)}},J=p=>{ee(p),K(!0)},Se=p=>{se({...p}),Z(!0)},$e=async()=>{if(!(!T||!T.order_id))try{const p={};T.status!==void 0&&(p.order_status=T.status),T.buyer_id!==void 0&&(p.buyer_id=T.buyer_id),T.amount!==void 0&&(p.amount=T.amount),T.receiver_name!==void 0&&(p.receiver_name=T.receiver_name),T.receiver_phone!==void 0&&(p.receiver_phone=T.receiver_phone),T.receiver_address!==void 0&&(p.receiver_address=T.receiver_address),T.item_id!==void 0&&(p.item_id=T.item_id),T.quantity!==void 0&&(p.quantity=T.quantity),T.item_title!==void 0&&(p.item_title=T.item_title),await Zl(T.order_id,p),Z(!1),se(null),P()}catch(p){console.error("更新订单失败:",p),alert("更新失败,请重试")}},Le=async()=>{if(De){u(!0);try{const p=new FormData;p.append("file",De);const $=tn(await sr(p));S($),Ne(null),await P(),$.failed_count===0&&(R(!1),S(null),alert(`订单导入成功,共 ${$.success_count} 条`))}catch(p){alert((p==null?void 0:p.message)||"导入失败,请检查文件格式")}finally{u(!1)}}},Ae=()=>{Q||(R(!1),Ne(null),S(null))},te=async p=>{F(p);try{const $=await er(p);$.success?await P():alert($.message||"同步失败")}catch($){console.error("同步订单失败:",$),alert(($==null?void 0:$.message)||"同步失败,请重试")}finally{F(null)}},je=async p=>{if(confirm("确认删除该订单吗?删除后无法恢复。")){H(p);try{await Yl(p),t.length===1&&de>1?G($=>$-1):await P()}catch($){console.error("删除订单失败:",$),alert(($==null?void 0:$.message)||"删除失败,请重试"),await P()}finally{H(null)}}};return e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col md:flex-row justify-between md:items-end gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-4xl font-extrabold text-gray-900 tracking-tight",children:"订单中心"}),e.jsx("p",{className:"text-gray-500 mt-2 font-medium",children:"查看所有闲鱼交易记录与状态。"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:P,className:"p-3 rounded-2xl bg-white border border-gray-100 text-gray-600 hover:bg-gray-50 hover:text-black transition-colors shadow-sm",children:e.jsx(Be,{className:`w-5 h-5 ${fe?"animate-spin":""}`})}),e.jsxs("button",{onClick:()=>{S(null),R(!0)},className:"px-5 py-3 rounded-2xl font-bold bg-gray-900 text-white hover:bg-gray-800 transition-colors text-sm flex items-center gap-2 shadow-lg",children:[e.jsx(Ye,{className:"w-4 h-4"}),"插入订单"]}),e.jsxs("button",{onClick:g,className:"ios-btn-primary px-6 py-3 rounded-2xl font-bold shadow-lg shadow-blue-200 text-sm flex items-center gap-2",children:[e.jsx(As,{className:"w-5 h-5"}),"一键同步订单"]})]})]}),e.jsxs("div",{className:"ios-card rounded-xl overflow-hidden shadow-lg border-0 bg-white",children:[e.jsxs("div",{className:"p-4 border-b border-gray-50 flex flex-col md:flex-row gap-4 justify-between items-center bg-surface-muted",children:[e.jsx("div",{className:"flex gap-1 p-1 bg-gray-200/50 rounded-xl overflow-x-auto max-w-full",children:[{k:"all",v:"全部"},{k:"processing",v:"处理中"},{k:"shipped",v:"已发货"},{k:"pending_ship",v:"待发货"},{k:"completed",v:"已完成"},{k:"cancelled",v:"已取消"},{k:"refunding",v:"退款中"}].map(p=>e.jsx("button",{onClick:()=>{O(p.k),G(1),pe("")},className:`px-5 py-2 rounded-lg text-sm font-bold transition-all whitespace-nowrap ${b===p.k?"bg-white text-black shadow-sm":"text-gray-500 hover:text-gray-700"}`,children:p.v},p.k))}),e.jsxs("div",{className:"flex w-full md:w-auto flex-col sm:flex-row gap-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(xt,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{"aria-label":"按账号筛选订单",value:j,onChange:p=>{V(p.target.value),G(1)},className:"ios-input pl-10 pr-9 py-2.5 rounded-xl w-full sm:w-56 bg-white border-none shadow-sm",children:[e.jsx("option",{value:"",children:"全部账号"}),x.map(p=>e.jsx("option",{value:p.id,children:Pe(p.id)},p.id))]})]}),e.jsxs("div",{className:"relative group",children:[e.jsx(Nt,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 group-focus-within:text-brand transition-colors"}),e.jsx("input",{type:"text",placeholder:"搜索订单号/商品/买家...",value:Y,onChange:p=>{pe(p.target.value),G(1)},className:"ios-input pl-10 pr-4 py-2.5 rounded-xl w-64 bg-white border-none shadow-sm focus:ring-0"})]})]})]}),e.jsx("div",{className:"overflow-x-auto min-h-[400px]",children:e.jsxs("table",{className:"w-full text-left border-collapse table-fixed",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-white text-gray-400 text-xs font-bold uppercase tracking-wider border-b border-gray-50",children:[e.jsx("th",{className:"px-6 py-5",style:{width:"28%"},children:"订单信息"}),e.jsx("th",{className:"px-6 py-5",style:{width:"26%"},children:"买家信息"}),e.jsx("th",{className:"px-6 py-5",style:{width:"11%"},children:"实付金额"}),e.jsx("th",{className:"px-6 py-5",style:{width:"13%"},children:"当前状态"}),e.jsx("th",{className:"px-6 py-5 text-right",style:{width:"22%"},children:"操作"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50",children:t.map(p=>e.jsxs("tr",{className:"hover:bg-warning-50/50 transition-colors group",children:[e.jsx("td",{className:"px-6 py-5",children:e.jsxs("div",{className:"flex items-center gap-5",children:[e.jsx("div",{className:"w-14 h-14 rounded-xl bg-gray-100 overflow-hidden shadow-sm border border-gray-100 flex-shrink-0",children:p.item_image?e.jsx("img",{src:p.item_image,alt:"",className:"w-full h-full object-cover"}):e.jsx("div",{className:"w-full h-full flex items-center justify-center text-gray-300",children:e.jsx(Tt,{})})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-bold text-gray-900 line-clamp-1 text-sm",children:Ce(p.cookie_id,p.item_id,p.item_title)}),e.jsxs("div",{className:"mt-1 flex w-fit min-w-0 max-w-full items-center gap-1 rounded-md bg-blue-50 px-2 py-1 text-[10px] font-extrabold text-blue-700",title:le(p.cookie_id),children:[e.jsx(xt,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{className:"min-w-0 truncate whitespace-nowrap",children:le(p.cookie_id)})]}),e.jsxs("div",{className:"text-xs text-gray-500 mt-1 font-medium",children:["订单ID: ",p.order_id]}),e.jsxs("div",{className:"text-xs text-gray-400 mt-0.5",children:["数量: ",p.quantity," • ",hs(p.created_at)]})]})]})}),e.jsx("td",{className:"px-6 py-5",children:e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("div",{className:"text-xs text-gray-500",children:"买家ID"}),e.jsx("div",{className:"text-sm font-bold text-gray-800",children:p.buyer_id}),p.receiver_name&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-xs text-gray-500",children:"收货人"}),e.jsx("div",{className:"text-xs text-gray-600",children:p.receiver_name})]}),p.receiver_phone&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-xs text-gray-500",children:"联系电话"}),e.jsx("div",{className:"text-xs text-gray-600 font-mono",children:p.receiver_phone})]}),p.receiver_address&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-xs text-gray-500",children:"收货地址"}),e.jsx("div",{className:"text-xs text-gray-600 line-clamp-1",children:p.receiver_address})]})]})}),e.jsx("td",{className:"px-6 py-5 text-base font-extrabold text-gray-900 font-feature-settings-tnum",children:p.amount?`¥${p.amount}`:e.jsx("span",{className:"text-xs text-amber-600 font-bold",children:"待获取"})}),e.jsx("td",{className:"px-6 py-5",children:e.jsx(Ys,{status:p.status})}),e.jsxs("td",{className:"px-6 py-5 text-right",children:[p.status==="pending_ship"&&e.jsx("button",{onClick:()=>y(p.order_id),className:"mr-2 text-white bg-black hover:bg-gray-800 shadow-lg shadow-gray-200 text-xs font-bold px-3 py-2 rounded-xl transition-all active:scale-95",children:"立即发货"}),e.jsx("a",{href:`https://www.goofish.com/order-detail?orderId=${p.order_id}&role=seller`,target:"_blank",rel:"noopener noreferrer",className:"mr-2 inline-flex text-gray-400 hover:text-blue-600 p-2 rounded-xl hover:bg-blue-50 transition-colors",title:"查看闲鱼详情",children:e.jsx(ga,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>J(p),className:"mr-2 text-gray-400 hover:text-blue-600 p-2 rounded-xl hover:bg-blue-50 transition-colors",title:"查看详情",children:e.jsx(st,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>Se(p),className:"mr-2 text-gray-400 hover:text-black p-2 rounded-xl hover:bg-gray-100 transition-colors",title:"编辑订单",children:e.jsx(_t,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>te(p.order_id),disabled:d===p.order_id,className:"mr-2 text-gray-400 hover:text-green-600 p-2 rounded-xl hover:bg-green-50 transition-colors disabled:opacity-50",title:"同步订单",children:e.jsx(Be,{className:`w-4 h-4 ${d===p.order_id?"animate-spin":""}`})}),e.jsx("button",{onClick:()=>je(p.order_id),disabled:I===p.order_id,className:"text-gray-400 hover:text-red-500 p-2 rounded-xl hover:bg-red-50 transition-colors disabled:opacity-50",title:"删除订单",children:e.jsx(Je,{className:"w-4 h-4"})})]})]},p.id))})]})}),e.jsxs("div",{className:"p-4 border-t border-gray-50 flex items-center justify-between bg-white",children:[e.jsxs("div",{className:"text-sm text-gray-500 font-medium pl-2",children:["第 ",de," 页 / 共 ",X," 页"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{disabled:de<=1,onClick:()=>G(p=>p-1),className:"p-2.5 rounded-xl bg-gray-50 hover:bg-gray-100 disabled:opacity-50 disabled:cursor-not-allowed text-gray-600 transition-colors",children:e.jsx(ys,{className:"w-5 h-5"})}),e.jsx("button",{disabled:de>=X,onClick:()=>G(p=>p+1),className:"p-2.5 rounded-xl bg-gray-50 hover:bg-gray-100 disabled:opacity-50 disabled:cursor-not-allowed text-gray-600 transition-colors",children:e.jsx(fs,{className:"w-5 h-5"})})]})]})]}),L&&E&&Me.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",children:[e.jsx("div",{className:"modal-header",children:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"订单详情"}),e.jsx("button",{onClick:()=>K(!1),className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",children:e.jsx(Te,{className:"w-5 h-5 text-gray-600"})})]})}),e.jsxs("div",{className:"modal-body space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"text-lg font-bold text-gray-800",children:"订单信息"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4 p-4 bg-gray-50 rounded-xl",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"订单号"}),e.jsx("div",{className:"font-mono text-sm font-bold text-gray-900",children:E.order_id})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"所属账号"}),e.jsx("div",{className:"truncate whitespace-nowrap text-sm font-bold text-blue-700",title:le(E.cookie_id),children:le(E.cookie_id)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"状态"}),e.jsx(Ys,{status:E.status})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"实付金额"}),e.jsx("div",{className:"text-lg font-extrabold text-gray-900",children:E.amount?`¥${E.amount}`:"待获取"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"数量"}),e.jsx("div",{className:"font-bold text-gray-900",children:E.quantity})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"创建时间"}),e.jsx("div",{className:"text-sm font-medium text-gray-700",children:hs(E.created_at)})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"text-lg font-bold text-gray-800",children:"商品信息"}),e.jsxs("div",{className:"p-4 bg-gray-50 rounded-xl flex items-center gap-4",children:[E.item_image&&e.jsx("img",{src:E.item_image,alt:"",className:"w-20 h-20 rounded-xl object-cover border border-gray-200"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"font-bold text-gray-900 mb-1",children:Ce(E.cookie_id,E.item_id,E.item_title)}),e.jsxs("div",{className:"text-sm text-gray-500",children:["商品ID: ",E.item_id]}),E.item_price&&e.jsxs("div",{className:"text-sm text-gray-500 mt-1",children:["标价: ¥",E.item_price]})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"text-lg font-bold text-gray-800",children:"买家信息"}),e.jsxs("div",{className:"p-4 bg-gray-50 rounded-xl space-y-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"买家ID"}),e.jsx("div",{className:"font-bold text-gray-900",children:E.buyer_id})]}),E.receiver_name&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"收货人"}),e.jsx("div",{className:"font-medium text-gray-700",children:E.receiver_name})]}),E.receiver_phone&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"联系电话"}),e.jsx("div",{className:"font-mono text-sm text-gray-700",children:E.receiver_phone})]}),E.receiver_address&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"收货地址"}),e.jsx("div",{className:"text-sm text-gray-700",children:E.receiver_address})]})]})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:()=>K(!1),className:"flex-1 px-6 py-3 rounded-xl bg-gray-100 hover:bg-gray-200 text-gray-800 font-bold transition-colors",children:"关闭"}),E.status==="pending_ship"&&e.jsx("button",{onClick:()=>{K(!1),y(E.order_id)},className:"flex-1 px-6 py-3 rounded-xl ios-btn-primary font-bold shadow-lg shadow-blue-200",children:"立即发货"})]})})]})}),document.body),me&&Me.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",children:[e.jsx("div",{className:"modal-header",children:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"插入订单"}),e.jsx("button",{onClick:Ae,className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",children:e.jsx(Te,{className:"w-5 h-5 text-gray-600"})})]})}),e.jsxs("div",{className:"modal-body space-y-5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"选择Excel文件"}),e.jsx("input",{type:"file",accept:".xlsx,.csv,.tsv,.json",onChange:p=>{var $;return Ne((($=p.target.files)==null?void 0:$[0])||null)},className:"w-full ios-input px-4 py-3 rounded-xl text-sm"}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"支持 .xlsx、.csv、.tsv、.json 格式"})]}),De&&e.jsx("div",{className:"p-3 bg-blue-50 rounded-xl",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($t,{className:"w-4 h-4 text-blue-600"}),e.jsx("span",{className:"text-sm font-medium text-blue-900",children:De.name})]})}),c&&c.failed_count>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"rounded-xl bg-amber-50 border border-amber-100 p-3 text-sm font-bold text-amber-800",children:["导入完成:成功 ",c.success_count," 条,失败 ",c.failed_count," 条"]}),e.jsx("div",{className:"max-h-64 overflow-y-auto rounded-xl border border-gray-100",children:e.jsxs("table",{className:"w-full text-left text-xs",children:[e.jsx("thead",{className:"sticky top-0 bg-gray-50 text-gray-500",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2",children:"订单ID"}),e.jsx("th",{className:"px-3 py-2",children:"失败原因"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-100",children:sn(c).map((p,$)=>e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 font-mono",children:p.order_id}),e.jsx("td",{className:"px-3 py-2 text-red-600",children:p.message||"导入失败"})]},`${p.order_id}-${$}`))})]})})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:Ae,disabled:Q,className:"flex-1 px-6 py-3 rounded-xl bg-gray-100 hover:bg-gray-200 text-gray-800 font-bold transition-colors",children:"取消"}),e.jsx("button",{onClick:Le,disabled:!De||Q,className:"flex-1 px-6 py-3 rounded-xl ios-btn-primary font-bold shadow-lg shadow-blue-200 disabled:opacity-50",children:Q?"正在导入…":"导入订单"})]})})]})}),document.body),z&&Me.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"480px"},children:[e.jsx("div",{className:"modal-header",children:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"立即发货"}),e.jsx("button",{onClick:()=>{m(!1),ve(null)},className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",children:e.jsx(Te,{className:"w-5 h-5 text-gray-600"})})]})}),e.jsxs("div",{className:"modal-body space-y-4",children:[e.jsx("p",{className:"text-sm text-gray-600",children:"请选择发货方式:"}),e.jsx("button",{onClick:()=>D("status_only"),disabled:q,className:"w-full text-left p-4 rounded-xl border-2 border-gray-200 hover:border-gray-400 hover:bg-gray-50 transition-all disabled:opacity-50 disabled:cursor-not-allowed",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-blue-100 flex items-center justify-center flex-shrink-0 mt-0.5",children:e.jsx(As,{className:"w-5 h-5 text-blue-600"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-bold text-gray-900 text-sm",children:"仅修改闲鱼发货状态"}),e.jsx("div",{className:"text-xs text-gray-500 mt-1 leading-relaxed",children:'不实际扣除或发送卡券,仅在闲鱼平台将订单标记为"已发货"。 适用于已经给客户发过货、只是忘记在闲鱼修改状态的情况。'})]})]})}),e.jsx("button",{onClick:()=>D("full_delivery"),disabled:q,className:"w-full text-left p-4 rounded-xl border-2 border-gray-200 hover:border-brand hover:bg-blue-50 transition-all disabled:opacity-50 disabled:cursor-not-allowed",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-blue-100 flex items-center justify-center flex-shrink-0 mt-0.5",children:e.jsx(Tt,{className:"w-5 h-5 text-blue-700"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-bold text-gray-900 text-sm",children:"完整发货(匹配卡券并发送)"}),e.jsx("div",{className:"text-xs text-gray-500 mt-1 leading-relaxed",children:"自动匹配发货规则、获取卡券、发送卡券信息给买家,并修改发货状态。 适用于订单既没有发送卡券给买家、也没有修改发货状态的情况。"})]})]})}),q&&e.jsxs("div",{className:"flex items-center justify-center gap-2 py-3",children:[e.jsx(Be,{className:"w-4 h-4 animate-spin text-gray-500"}),e.jsx("span",{className:"text-sm text-gray-500",children:"正在处理中..."})]}),be&&e.jsxs("div",{className:`p-3 rounded-xl text-sm ${be.success?"bg-green-50 text-green-800":"bg-red-50 text-red-800"}`,children:[be.success?"✓ ":"✗ ",be.message]})]}),e.jsx("div",{className:"modal-footer",children:e.jsx("button",{onClick:()=>{m(!1),ve(null)},className:"w-full px-6 py-3 rounded-xl bg-gray-100 hover:bg-gray-200 text-gray-800 font-bold transition-colors",children:be!=null&&be.success?"完成":"取消"})})]})}),document.body),ae&&T&&Me.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",children:[e.jsx("div",{className:"modal-header",children:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"编辑订单"}),e.jsx("button",{onClick:()=>Z(!1),className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",children:e.jsx(Te,{className:"w-5 h-5 text-gray-600"})})]})}),e.jsxs("div",{className:"modal-body space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"订单号"}),e.jsx("input",{type:"text",value:T.order_id,disabled:!0,className:"w-full ios-input px-4 py-3 rounded-xl bg-gray-50 text-gray-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"订单状态"}),e.jsxs("select",{value:T.status,onChange:p=>se({...T,status:p.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"processing",children:"处理中"}),e.jsx("option",{value:"pending_ship",children:"待发货"}),e.jsx("option",{value:"shipped",children:"已发货"}),e.jsx("option",{value:"completed",children:"已完成"}),e.jsx("option",{value:"cancelled",children:"已取消"}),e.jsx("option",{value:"refunding",children:"退款中"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"买家ID"}),e.jsx("input",{type:"text",value:T.buyer_id,onChange:p=>se({...T,buyer_id:p.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"实付金额"}),e.jsx("input",{type:"number",value:T.amount,onChange:p=>se({...T,amount:p.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"收货人"}),e.jsx("input",{type:"text",value:T.receiver_name||"",onChange:p=>se({...T,receiver_name:p.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"联系电话"}),e.jsx("input",{type:"text",value:T.receiver_phone||"",onChange:p=>se({...T,receiver_phone:p.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"收货地址"}),e.jsx("textarea",{value:T.receiver_address||"",onChange:p=>se({...T,receiver_address:p.target.value}),rows:2,className:"w-full ios-input px-4 py-3 rounded-xl resize-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"商品标题"}),e.jsx("input",{type:"text",value:T.item_title||"",onChange:p=>se({...T,item_title:p.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl"})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:()=>Z(!1),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:$e,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Ge,{className:"w-4 h-4"}),"保存更改"]})]})})]})}),document.body)]})},ln=(t,s,l)=>{const o=l.trim().toLocaleLowerCase();return t.filter(x=>(!s||x.type===s)&&(!o||x.name.toLocaleLowerCase().includes(o)))},Xs=()=>({name:"",type:"data",content:"",description:"",enabled:!0,delay_seconds:0,api_method:"GET",api_timeout:10,api_headers:"",api_params:""}),rn=()=>{const[t,s]=r.useState([]),[l,o]=r.useState(!1),[x,v]=r.useState(!1),[k,A]=r.useState(null),[b,O]=r.useState({}),[j,V]=r.useState(Xs),[Y,pe]=r.useState(!1),[ce,w]=r.useState("create"),[M,de]=r.useState(null),[G,X]=r.useState(null),[U,fe]=r.useState(!1),[ge,L]=r.useState(""),[K,ae]=r.useState(""),[Z,me]=r.useState(null),[R,E]=r.useState(""),[ee,T]=r.useState("");r.useEffect(()=>{Ze().then(s)},[]);const se=({type:c})=>{switch(c){case"text":return e.jsx(Rs,{className:"w-5 h-5 text-blue-500"});case"image":return e.jsx(Ps,{className:"w-5 h-5 text-purple-500"});case"api":return e.jsx(Xa,{className:"w-5 h-5 text-blue-500"});default:return e.jsx(ns,{className:"w-5 h-5 text-gray-500"})}},ke=c=>{var S,Q,u,d,F;A(c),O({id:c.id,name:c.name||"",type:c.type||"text",api_url:((S=c.api_config)==null?void 0:S.url)||"",api_method:((Q=c.api_config)==null?void 0:Q.method)||"GET",api_timeout:((u=c.api_config)==null?void 0:u.timeout)||10,api_headers:((d=c.api_config)==null?void 0:d.headers)||"",api_params:((F=c.api_config)==null?void 0:F.params)||"",text_content:c.text_content||"",data_content:c.data_content||"",image_url:c.image_url||"",delay_seconds:c.delay_seconds||0,description:c.description||"",enabled:c.enabled}),o(!0)},ye=async()=>{var c,S,Q,u,d,F,I,H;if(k){if(!((c=b.name)!=null&&c.trim())){alert("请输入卡密名称");return}if(!b.type){alert("请选择卡密类型");return}try{const P={name:b.name.trim(),type:b.type,description:(S=b.description)==null?void 0:S.trim(),delay_seconds:b.delay_seconds||0,enabled:b.enabled??!0};b.type==="api"?P.api_config={url:((Q=b.api_url)==null?void 0:Q.trim())||"",method:b.api_method,timeout:b.api_timeout||10,headers:((u=b.api_headers)==null?void 0:u.trim())||void 0,params:((d=b.api_params)==null?void 0:d.trim())||void 0}:b.type==="text"?P.text_content=((F=b.text_content)==null?void 0:F.trim())||"":b.type==="data"?P.data_content=((I=b.data_content)==null?void 0:I.trim())||"":b.type==="image"&&(P.image_url=((H=b.image_url)==null?void 0:H.trim())||""),await Js(k.id,P),o(!1),Ze().then(s)}catch(P){console.error("更新卡密失败:",P),alert("更新失败,请重试")}}},z=async c=>{if(confirm("确认删除该卡密吗?"))try{await ir(c),Ze().then(s)}catch(S){console.error("删除卡密失败:",S),alert("删除失败,请重试")}},m=async()=>{if(!j.name.trim()){alert("请输入卡密名称");return}if(!j.content.trim()){alert(j.type==="api"?"请输入 API 地址":"请输入卡密内容");return}try{const c={name:j.name.trim(),type:j.type,description:j.description.trim(),enabled:j.enabled,delay_seconds:j.delay_seconds};j.type==="text"&&(c.text_content=j.content.trim()),j.type==="data"&&(c.data_content=j.content.trim()),j.type==="image"&&(c.image_url=j.content.trim()),j.type==="api"&&(c.api_config={url:j.content.trim(),method:j.api_method,timeout:j.api_timeout,headers:j.api_headers.trim()||void 0,params:j.api_params.trim()||void 0}),await nr(c),v(!1),V(Xs()),Ze().then(s)}catch(c){console.error("添加卡密失败:",c),alert("添加失败,请重试")}},f=async c=>{try{await Js(c.id,{...c,enabled:!c.enabled}),Ze().then(s)}catch(S){console.error("切换状态失败:",S)}},W=async c=>{try{await navigator.clipboard.writeText(String(c)),alert(`已复制卡密组ID:${c}`)}catch{prompt("复制卡密组ID",String(c))}},q=t.filter(c=>c.type==="data"),ne=r.useMemo(()=>ln(t,R,ee),[t,ee,R]),be=()=>{const Q=[["名称","类型","内容","描述","启用","延迟秒","多规格","规格名","规格值"],...[["VIP月卡","data",`VIP-MONTH-001
|
||
VIP-MONTH-002
|
||
VIP-MONTH-003`,"按行消费的卡密队列","是","0","否","",""],["感谢文案","text","感谢购买,如有问题联系客服~","固定文本","是","0","否","",""],["教程图","image","https://cdn.example.com/tutorial.jpg","图片URL","是","0","否","",""]]].map(I=>I.map(H=>`"${String(H).replace(/"/g,'""')}"`).join(",")).join(`
|
||
`),u=new Blob(["\uFEFF"+Q],{type:"text/csv;charset=utf-8"}),d=URL.createObjectURL(u),F=document.createElement("a");F.href=d,F.download="卡密组批量导入模板.csv",document.body.appendChild(F),F.click(),F.remove(),URL.revokeObjectURL(d)},ve=async()=>{if(M){fe(!0),X(null);try{const c=await or(M);if(X(c),c.created>0){const S=await Ze();s(S)}}catch(c){X({error:(c==null?void 0:c.message)||"上传失败"})}finally{fe(!1)}}},De=async()=>{if(!(!ge||!K.trim())){fe(!0),me(null);try{const c=await cr(ge,K);me({added:c.added}),ae("");const S=await Ze();s(S)}catch(c){alert("追加失败:"+((c==null?void 0:c.message)||"未知错误"))}finally{fe(!1)}}},Ne=()=>{var c;w("create"),de(null),X(null),L((c=q[0])!=null&&c.id?String(q[0].id):""),ae(""),me(null),pe(!0)};return e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col md:flex-row justify-between md:items-end gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-4xl font-extrabold text-gray-900 tracking-tight",children:"卡密库存"}),e.jsx("p",{className:"text-gray-500 mt-2 font-medium",children:"管理自动发货的卡密、链接或图片资源。"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:Ne,className:"px-4 py-3 bg-gray-100 hover:bg-gray-200 rounded-2xl font-bold text-gray-700 flex items-center gap-2 transition-colors",children:[e.jsx($t,{className:"w-5 h-5"}),"批量导入"]}),e.jsxs("button",{onClick:()=>v(!0),className:"ios-btn-primary flex items-center gap-2 px-6 py-3 rounded-2xl font-bold shadow-lg shadow-blue-200 transition-transform hover:scale-105 active:scale-95",children:[e.jsx(Ye,{className:"w-5 h-5"}),"添加新卡密"]})]})]}),e.jsxs("div",{className:"ios-card rounded-xl overflow-hidden shadow-lg border-0 bg-white",children:[e.jsxs("div",{className:"flex flex-col gap-3 border-b border-gray-50 bg-surface-muted p-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex flex-1 flex-col gap-3 sm:flex-row",children:[e.jsxs("div",{className:"relative sm:w-48",children:[e.jsx(ya,{className:"pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsxs("select",{"aria-label":"按卡密类型筛选",value:R,onChange:c=>E(c.target.value),className:"ios-input w-full rounded-xl border-none bg-white py-2.5 pl-10 pr-9 text-sm shadow-sm",children:[e.jsx("option",{value:"",children:"全部类型"}),e.jsx("option",{value:"data",children:"批量卡密"}),e.jsx("option",{value:"text",children:"文本"}),e.jsx("option",{value:"api",children:"API"}),e.jsx("option",{value:"image",children:"图片"})]})]}),e.jsxs("div",{className:"relative w-full sm:max-w-sm",children:[e.jsx(Nt,{className:"pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsx("input",{type:"search","aria-label":"按卡密名称搜索",placeholder:"搜索卡密名称...",value:ee,onChange:c=>T(c.target.value),className:"ios-input w-full rounded-xl border-none bg-white py-2.5 pl-10 pr-4 text-sm shadow-sm"})]})]}),e.jsxs("div",{className:"whitespace-nowrap px-1 text-xs font-bold text-gray-400",children:["显示 ",ne.length," / ",t.length," 组"]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full table-fixed text-left border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-white text-gray-400 text-xs font-bold uppercase tracking-wider border-b border-gray-50",children:[e.jsx("th",{className:"w-[23%] px-5 py-5",children:"卡密名称"}),e.jsx("th",{className:"w-[8%] px-3 py-5",children:"卡密组ID"}),e.jsx("th",{className:"w-[7%] px-2 py-5",children:"类型"}),e.jsx("th",{className:"w-[27%] px-5 py-5",children:"内容/库存"}),e.jsx("th",{className:"w-[19%] px-5 py-5",children:"描述"}),e.jsx("th",{className:"w-[7%] px-2 py-5",children:"状态"}),e.jsx("th",{className:"w-[9%] px-3 py-5 text-right",children:"操作"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50",children:ne.map(c=>{let S="";return c.type==="data"&&c.data_content?S=`库存: ${c.data_content.split(`
|
||
`).filter(u=>u.trim()).length} 条`:c.type==="text"&&c.text_content?S=c.text_content:c.type==="api"&&c.api_config?S=c.api_config.url:c.type==="image"&&c.image_url&&(S="图片链接"),e.jsxs("tr",{className:"hover:bg-warning-50/50 transition-colors group",children:[e.jsx("td",{className:"px-5 py-5 align-middle",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"shrink-0 rounded-xl bg-gray-50 p-2 transition-colors group-hover:bg-white",children:e.jsx(se,{type:c.type})}),e.jsx("span",{className:"line-clamp-3 min-w-0 text-[13px] font-bold leading-5 text-gray-900",title:c.name,children:c.name})]})}),e.jsx("td",{className:"px-3 py-5",children:e.jsxs("button",{onClick:()=>W(c.id),className:"inline-flex max-w-full items-center gap-1 rounded-lg bg-gray-100 px-2 py-1.5 font-mono text-[11px] font-extrabold text-gray-700 transition-colors hover:bg-gray-200",title:"复制卡密组ID,用于批量铺货表格",children:[e.jsx("span",{className:"truncate",children:c.id}),e.jsx(Ha,{className:"h-3 w-3 shrink-0"})]})}),e.jsx("td",{className:"px-2 py-5",children:e.jsx("span",{className:`inline-flex rounded-md px-2 py-1 text-[11px] font-bold ${c.type==="text"?"bg-blue-50 text-blue-600":c.type==="data"?"bg-purple-50 text-purple-600":c.type==="api"?"bg-blue-50 text-blue-600":"bg-pink-50 text-pink-600"}`,children:c.type==="text"?"文本":c.type==="data"?"批量":c.type==="api"?"API":"图片"})}),e.jsx("td",{className:"px-5 py-5",children:e.jsx("span",{className:"line-clamp-3 break-all font-mono text-sm leading-5 text-gray-600",title:S,children:S})}),e.jsx("td",{className:"px-5 py-5",children:e.jsx("span",{className:"block truncate text-sm text-gray-500",title:c.description||"-",children:c.description||"-"})}),e.jsx("td",{className:"px-2 py-5",children:e.jsx("button",{onClick:()=>f(c),className:`w-12 h-8 rounded-full relative transition-colors ${c.enabled?"bg-green-500":"bg-gray-300"}`,children:e.jsx("div",{className:`absolute top-1 w-6 h-6 bg-white rounded-full shadow-sm transition-transform ${c.enabled?"left-5":"left-1"}`})})}),e.jsx("td",{className:"px-3 py-5",children:e.jsxs("div",{className:"flex items-center justify-end gap-0.5",children:[e.jsx("button",{onClick:()=>ke(c),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-gray-100 hover:text-black",title:"编辑",children:e.jsx(_t,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>z(c.id),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-red-50 hover:text-red-500",children:e.jsx(Je,{className:"h-4 w-4"})})]})})]},c.id)})})]})}),ne.length===0&&e.jsxs("div",{className:"py-20 text-center text-gray-400",children:[e.jsx(ha,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),e.jsx("p",{children:t.length===0?"暂无卡密配置,请点击右上角添加。":"没有符合当前筛选条件的卡密组。"})]})]}),l&&k&&Me.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"编辑卡密"}),e.jsx("button",{onClick:()=>o(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",children:e.jsx(Te,{className:"w-5 h-5 text-gray-500"})})]}),e.jsx("div",{className:"modal-body",children:e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:["卡密名称 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",value:b.name||"",onChange:c=>O({...b,name:c.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"例如:游戏点卡、会员卡等"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"卡券类型"}),e.jsxs("select",{value:b.type||"text",onChange:c=>O({...b,type:c.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"请选择类型"}),e.jsx("option",{value:"text",children:"固定文字"}),e.jsx("option",{value:"data",children:"批量数据"}),(k==null?void 0:k.type)==="api"&&e.jsx("option",{value:"api",children:"API接口(仅保留现有配置)"}),e.jsx("option",{value:"image",children:"图片"})]})]})]}),b.type==="api"&&e.jsxs("div",{className:"border border-gray-200 rounded-xl p-4 space-y-4 bg-gray-50",children:[e.jsx("h3",{className:"font-bold text-gray-900",children:"API 配置"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"API 地址"}),e.jsx("input",{type:"url",value:b.api_url||"",onChange:c=>O({...b,api_url:c.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl font-mono text-sm",placeholder:"https://api.example.com/get-card"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"请求方法"}),e.jsxs("select",{value:b.api_method||"GET",onChange:c=>O({...b,api_method:c.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"GET",children:"GET"}),e.jsx("option",{value:"POST",children:"POST"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"超时时间(秒)"}),e.jsx("input",{type:"number",value:b.api_timeout||10,onChange:c=>O({...b,api_timeout:parseInt(c.target.value)||10}),className:"w-full ios-input px-4 py-3 rounded-xl",min:"1",max:"60"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"请求头(JSON 格式)"}),e.jsx("textarea",{value:b.api_headers||"",onChange:c=>O({...b,api_headers:c.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-20 resize-none font-mono text-sm",placeholder:'{"Authorization": "Bearer token"}'})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"请求参数(JSON 格式)"}),e.jsx("textarea",{value:b.api_params||"",onChange:c=>O({...b,api_params:c.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-20 resize-none font-mono text-sm",placeholder:'{"type": "card", "count": 1}'})]})]}),b.type==="text"&&e.jsxs("div",{className:"border border-gray-200 rounded-xl p-4 bg-gray-50",children:[e.jsx("h3",{className:"font-bold text-gray-900 mb-3",children:"固定文字配置"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"文字内容"}),e.jsx("textarea",{value:b.text_content||"",onChange:c=>O({...b,text_content:c.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-32 resize-none",placeholder:"请输入要发送的固定文字内容..."})]})]}),b.type==="data"&&e.jsxs("div",{className:"border border-gray-200 rounded-xl p-4 bg-gray-50",children:[e.jsx("h3",{className:"font-bold text-gray-900 mb-3",children:"批量数据配置"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"数据内容(一行一个)"}),e.jsx("textarea",{value:b.data_content||"",onChange:c=>O({...b,data_content:c.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-80 resize-none font-mono text-sm",placeholder:`请输入数据,每行一个:
|
||
卡号1:密码1
|
||
卡号2:密码2
|
||
或者
|
||
兑换码1
|
||
兑换码2`}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"支持格式:卡号:密码 或 单独的兑换码"}),e.jsxs("p",{className:"text-xs text-gray-500",children:["当前库存:",e.jsx("span",{className:"font-bold text-blue-600",children:b.data_content?b.data_content.split(`
|
||
`).filter(c=>c.trim()).length:0})," 条"]})]})]}),b.type==="image"&&e.jsxs("div",{className:"border border-gray-200 rounded-xl p-4 bg-gray-50",children:[e.jsx("h3",{className:"font-bold text-gray-900 mb-3",children:"图片配置"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"图片 URL"}),e.jsx("input",{type:"url",value:b.image_url||"",onChange:c=>O({...b,image_url:c.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl font-mono text-sm",placeholder:"https://example.com/image.png"}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"输入图片卡密的 URL 地址"})]}),b.image_url&&e.jsxs("div",{className:"mt-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"图片预览"}),e.jsx("img",{src:b.image_url,alt:"预览",className:"max-w-full max-h-48 rounded-xl border border-gray-200",onError:c=>{c.currentTarget.src="https://via.placeholder.com/400x200?text=图片加载失败"}})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"延时发货时间(秒)"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"number",value:b.delay_seconds||0,onChange:c=>O({...b,delay_seconds:parseInt(c.target.value)||0}),className:"flex-1 ios-input px-4 py-3 rounded-xl",min:"0",max:"3600",placeholder:"0"}),e.jsx("span",{className:"text-sm text-gray-500 whitespace-nowrap",children:"秒"})]}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"0表示立即发货,最大3600秒(1小时)"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"备注信息"}),e.jsx("textarea",{value:b.description||"",onChange:c=>O({...b,description:c.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-40 resize-none",placeholder:"可选的备注信息"})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-gray-50 rounded-xl",children:[e.jsx("span",{className:"font-bold text-gray-900",children:"启用状态"}),e.jsx("button",{type:"button",onClick:()=>O({...b,enabled:!b.enabled}),className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${b.enabled?"bg-brand":"bg-gray-300"}`,children:e.jsx("span",{className:`absolute top-1 w-6 h-6 bg-white rounded-full shadow-md transition-transform duration-300 block ${b.enabled?"translate-x-7":"translate-x-1"}`})})]})]})}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:()=>o(!1),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:ye,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Ge,{className:"w-4 h-4"}),"保存更改"]})]})})]})}),document.body),x&&Me.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"780px"},children:[e.jsxs("div",{className:"modal-header flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"添加新卡密"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"选择交付方式并录入自动发货内容"})]}),e.jsx("button",{onClick:()=>v(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors flex-shrink-0",title:"关闭",children:e.jsx(Te,{className:"w-5 h-5 text-gray-500"})})]}),e.jsx("div",{className:"modal-body",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"卡密名称"}),e.jsx("input",{type:"text",value:j.name,onChange:c=>V({...j,name:c.target.value}),placeholder:"例如:VIP会员卡密",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"类型"}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>V({...j,type:"data",content:""}),className:`p-3 rounded-xl font-bold transition-all ${j.type==="data"?"bg-brand text-white":"bg-gray-100 text-gray-600 hover:bg-gray-200"}`,children:[e.jsx(ns,{className:"w-5 h-5 mx-auto mb-1"}),"批量库存"]}),e.jsxs("button",{type:"button",onClick:()=>V({...j,type:"text",content:""}),className:`p-3 rounded-xl font-bold transition-all ${j.type==="text"?"bg-brand text-white":"bg-gray-100 text-gray-600"}`,children:[e.jsx(Rs,{className:"w-5 h-5 mx-auto mb-1"}),"文本"]}),e.jsxs("button",{type:"button",onClick:()=>V({...j,type:"image",content:""}),className:`p-3 rounded-xl font-bold transition-all ${j.type==="image"?"bg-brand text-white":"bg-gray-100 text-gray-600"}`,children:[e.jsx(Ps,{className:"w-5 h-5 mx-auto mb-1"}),"图片"]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:j.type==="data"?"库存内容(一行一个)":j.type==="text"?"固定回复内容":j.type==="image"?"图片 URL":"API 地址"}),j.type==="api"?e.jsx("input",{type:"url",value:j.content,onChange:c=>V({...j,content:c.target.value}),placeholder:"https://api.example.com/get-code",className:"w-full ios-input px-4 py-3 rounded-xl"}):j.type==="image"?e.jsx("input",{type:"url",value:j.content,onChange:c=>V({...j,content:c.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"https://example.com/card.png"}):e.jsx("textarea",{value:j.content,onChange:c=>V({...j,content:c.target.value}),className:`w-full ios-input px-4 py-3 rounded-xl resize-none text-sm ${j.type==="data"?"h-48 font-mono":"h-32"}`,placeholder:j.type==="data"?`CODE-123456
|
||
CODE-789012
|
||
...`:"请输入每次发货时发送的固定文字"}),j.type==="data"&&e.jsxs("p",{className:"text-xs text-gray-500",children:["当前库存:",e.jsx("span",{className:"font-bold text-brand",children:j.content.split(`
|
||
`).filter(c=>c.trim()).length})," 条"]})]}),j.type==="api"&&e.jsxs("div",{className:"border-t border-gray-100 pt-5 space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求方法"}),e.jsxs("select",{value:j.api_method,onChange:c=>V({...j,api_method:c.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"GET",children:"GET"}),e.jsx("option",{value:"POST",children:"POST"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"超时时间(秒)"}),e.jsx("input",{type:"number",min:"1",max:"60",value:j.api_timeout,onChange:c=>V({...j,api_timeout:parseInt(c.target.value)||10}),className:"w-full ios-input px-4 py-3 rounded-xl"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求头(JSON)"}),e.jsx("textarea",{value:j.api_headers,onChange:c=>V({...j,api_headers:c.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-24 resize-none font-mono text-xs",placeholder:'{"Authorization":"Bearer token"}'})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求参数(JSON)"}),e.jsx("textarea",{value:j.api_params,onChange:c=>V({...j,api_params:c.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-24 resize-none font-mono text-xs",placeholder:'{"order_id":"{order_id}"}'})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-[1fr_180px] gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"描述"}),e.jsx("input",{value:j.description,onChange:c=>V({...j,description:c.target.value}),placeholder:"卡密用途描述(可选)",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"延时发货(秒)"}),e.jsx("input",{type:"number",value:j.delay_seconds,onChange:c=>V({...j,delay_seconds:parseInt(c.target.value)||0}),className:"w-full ios-input px-4 py-3 rounded-xl",min:"0",max:"3600"})]})]})]})}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:()=>v(!1),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:m,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Ye,{className:"w-4 h-4"}),"添加卡密"]})]})})]})}),document.body),Y&&Me.createPortal(e.jsx("div",{className:"modal-overlay",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"40rem"},children:[e.jsxs("div",{className:"px-6 py-5 border-b border-gray-100 flex items-center justify-between",children:[e.jsx("h3",{className:"text-xl font-extrabold text-gray-900",children:"批量导入卡密"}),e.jsx("button",{onClick:()=>pe(!1),className:"w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center",children:e.jsx(Te,{className:"w-5 h-5 text-gray-600"})})]}),e.jsxs("div",{className:"px-6 py-5 space-y-5",children:[e.jsxs("div",{className:"flex flex-wrap gap-2 p-2 bg-gray-100/50 rounded-2xl",children:[e.jsxs("button",{onClick:()=>w("create"),className:`flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl text-sm font-bold transition-all ${ce==="create"?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(Za,{className:"w-4 h-4"}),"批量创建卡密组"]}),e.jsxs("button",{onClick:()=>w("append"),className:`flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl text-sm font-bold transition-all ${ce==="append"?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx($t,{className:"w-4 h-4"}),"往单个组充卡密"]})]}),ce==="create"?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-xl bg-blue-50 border border-blue-100 p-4 text-xs text-blue-900 leading-5",children:["上传表格,每行一个卡密组。表头:",e.jsx("code",{className:"bg-blue-100/70 px-1.5 py-0.5 rounded",children:"名称,类型,内容,描述,启用,延迟秒,多规格,规格名,规格值"}),'。 类型填 text/data/image;data 类型的"内容"按行存卡密(CSV 单元格内换行需用引号包裹)。']}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:be,className:"px-4 py-2.5 bg-gray-100 hover:bg-gray-200 rounded-xl font-bold text-gray-700 flex items-center gap-2 text-sm transition-colors",children:[e.jsx(Ya,{className:"w-4 h-4"}),"下载模板"]}),e.jsxs("label",{className:"flex-1 px-4 py-2.5 bg-gray-100 hover:bg-gray-200 rounded-xl font-bold text-gray-700 flex items-center gap-2 text-sm cursor-pointer transition-colors",children:[e.jsx($t,{className:"w-4 h-4"}),M?M.name:"选择 .xlsx / .csv / .tsv",e.jsx("input",{type:"file",accept:".xlsx,.csv,.tsv",className:"hidden",onChange:c=>{var S;return de(((S=c.target.files)==null?void 0:S[0])||null)}})]})]}),G&&!G.error&&e.jsxs("div",{className:"rounded-xl border border-gray-200 p-4 space-y-2",children:[e.jsxs("div",{className:"text-sm font-bold text-gray-900",children:["共 ",G.total," 行 · 成功 ",G.created," · 失败 ",G.failed]}),G.failed>0&&e.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1",children:G.rows.filter(c=>!c.success).map(c=>e.jsxs("div",{className:"text-xs text-red-600",children:["第 ",c.row_no," 行「",c.name,"」:",c.error]},c.row_no))})]})]}):e.jsx("div",{className:"space-y-4",children:q.length===0?e.jsx("div",{className:"rounded-xl bg-amber-50 border border-amber-200 p-4 text-sm text-amber-800",children:"暂无 data(批量卡密)类型的卡密组,请先创建一个再充卡密。"}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"选择卡密组"}),e.jsx("select",{value:ge,onChange:c=>L(c.target.value),className:"w-full ios-input px-4 py-3 rounded-xl text-sm",children:q.map(c=>e.jsxs("option",{value:String(c.id),children:[c.name,"(ID: ",c.id,")"]},c.id))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"卡密号(每行一个)"}),e.jsx("textarea",{value:K,onChange:c=>ae(c.target.value),placeholder:`VIP-001
|
||
VIP-002
|
||
VIP-003`,className:"w-full ios-input px-4 py-3 rounded-xl text-sm font-mono h-40 resize-y"}),e.jsx("p",{className:"text-xs text-gray-500",children:"一行一个卡密号,空行自动忽略。会追加到该组现有库存末尾。"})]}),Z&&e.jsxs("div",{className:"rounded-xl bg-green-50 border border-green-200 p-3 text-sm text-green-700 font-bold",children:["已追加 ",Z.added," 个卡密"]})]})})]}),e.jsxs("div",{className:"px-6 py-4 border-t border-gray-100 flex items-center justify-end gap-3",children:[e.jsx("button",{onClick:()=>pe(!1),className:"px-5 py-2.5 rounded-xl bg-gray-100 hover:bg-gray-200 font-bold text-gray-700 transition-colors",children:"关闭"}),ce==="create"?e.jsxs("button",{onClick:ve,disabled:!M||U,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[U?e.jsx(Ee,{className:"w-4 h-4 animate-spin"}):e.jsx($t,{className:"w-4 h-4"}),U?"处理中...":"上传创建"]}):e.jsxs("button",{onClick:De,disabled:!ge||!K.trim()||U||q.length===0,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[U?e.jsx(Ee,{className:"w-4 h-4 animate-spin"}):e.jsx(Ye,{className:"w-4 h-4"}),U?"处理中...":"追加卡密"]})]})]})}),document.body)]})},nn=t=>t.find(s=>s.status==="running"||s.status==="canceling"),ea="ydisks-amap-js-api",on="c9b68d4ce9a2a97f22a4a439404488ca";let It=null;const cn=()=>on,dn=()=>window.AMap?Promise.resolve(window.AMap):It||(It=new Promise((t,s)=>{const l=document.getElementById(ea),o=l||document.createElement("script"),x=()=>{window.__ydisksAmapLoaded=void 0,window.clearTimeout(k)},v=()=>{window.AMap?(x(),t(window.AMap)):(x(),s(new Error("高德地图 API 加载完成但未找到 AMap 对象")))},k=window.setTimeout(()=>{x(),s(new Error("高德地图 API 加载超时,请检查网络或 VITE_AMAP_JS_KEY 配置"))},15e3);window.__ydisksAmapLoaded=v,o.id=ea,o.async=!0,o.src=`https://webapi.amap.com/maps?v=2.0&key=${encodeURIComponent(cn())}&plugin=AMap.PlaceSearch&callback=__ydisksAmapLoaded`,o.onerror=()=>{x(),s(new Error("高德地图 API 加载失败,请检查网络或 VITE_AMAP_JS_KEY 配置"))},l||document.head.appendChild(o)}).catch(t=>{throw It=null,t}),It),Gt=t=>Number.isFinite(t)&&t!==0,xn=t=>{var x,v;const s=Number((x=t.location)==null?void 0:x.lng),l=Number((v=t.location)==null?void 0:v.lat),o={area:String(t.adname||"").trim(),city:String(t.cityname||"").trim(),division_id:String(t.adcode||"").trim(),longitude:s,latitude:l,poi_id:String(t.id||"").trim(),poi_name:String(t.name||"").trim(),province:String(t.pname||"").trim()};return!o.division_id||!o.province||!o.city||!o.poi_id||!o.poi_name||!Gt(s)||!Gt(l)||s<-180||s>180||l<-90||l>90?null:o},mn=async(t,s)=>{if(!Gt(t)||!Gt(s)||t<-180||t>180||s<-90||s>90)throw new Error("经纬度无效");const l=await dn();return new Promise((o,x)=>{new l.PlaceSearch({extensions:"all",pageSize:10}).searchNearBy("",[t,s],1e3,(k,A)=>{var O;if(k!=="complete"){if(k==="no_data"){o([]);return}x(new Error("高德地图附近地址查询失败,请稍后重试"));return}const b=(((O=A==null?void 0:A.poiList)==null?void 0:O.pois)||[]).map(xn).filter(j=>j!==null);o(b)})})},pn=t=>{const s=String(t||"").trim();return s?/^[¥¥]/.test(s)?s:`¥${s}`:"-"},un=({onConfigureDelivery:t})=>{const[s,l]=r.useState([]),[o,x]=r.useState([]),[v,k]=r.useState([]),[A,b]=r.useState(""),[O,j]=r.useState(""),[V,Y]=r.useState(!1),[pe,ce]=r.useState(!1),[w,M]=r.useState(!1),[de,G]=r.useState(!1),[X,U]=r.useState(!1),[fe,ge]=r.useState(!1),[L,K]=r.useState(!1),[ae,Z]=r.useState("upload"),[me,R]=r.useState(null),[E,ee]=r.useState(null),[T,se]=r.useState(""),[ke,ye]=r.useState(!1),[z,m]=r.useState(!1),[f,W]=r.useState([]),[q,ne]=r.useState(null),[be,ve]=r.useState([]),[De,Ne]=r.useState(null),[c,S]=r.useState({catId:"",catName:"",channelCatId:"",tbCatId:""}),[Q,u]=r.useState(null),[d,F]=r.useState(null),[I,H]=r.useState(null),P=r.useRef(!1),[Ce,Re]=r.useState(null),[xe,Pe]=r.useState({}),[le,g]=r.useState({cookie_id:"",item_id:"",item_title:"",item_price:"",item_image:""}),[y,D]=r.useState({cookie_id:"",title:"",description:"",price:"",original_price:"",quantity:"1",postage_mode:"free",postage:"",images:[]}),[J,Se]=r.useState([]);r.useEffect(()=>{if(!fe||y.images.length===0){Se([]);return}const n=y.images.map((C,i)=>({key:C.name+i,url:URL.createObjectURL(C)}));return Se(n),()=>{n.forEach(C=>URL.revokeObjectURL(C.url))}},[fe,y.images]);const $e=async()=>{const n=await vt();l(n)},Le=async()=>{x(await us())};r.useEffect(()=>{Promise.all([Mt(),vt(),us(),Vs(20)]).then(([n,C,i,N])=>{k(n),l(C),x(i);const a=N.find(h=>["running","canceling"].includes(h.status))||N.find(h=>h.status!=="preview");H(a||null)}).catch(n=>console.error("加载商品配置失败:",n))},[]),r.useEffect(()=>{if(!L||!(d!=null&&d.id)||!["running","canceling"].includes(d.status))return;const n=window.setInterval(async()=>{if(!P.current){P.current=!0;try{const C=await bt(d.id);F(C),H(C),["running","canceling"].includes(C.status)||(Z("done"),await $e(),await Le())}catch(C){console.error("刷新批量铺货进度失败:",C)}finally{P.current=!1}}},3e3);return()=>{window.clearInterval(n)}},[L,d==null?void 0:d.id,d==null?void 0:d.status]);const Ae=async()=>{if(!A)return alert("请先选择账号");Y(!0);try{const n=await dr(A);await $e(),alert((n==null?void 0:n.message)||"商品同步完成")}catch(n){console.error("同步商品失败:",n),alert((n==null?void 0:n.message)||"同步失败,请重试")}finally{Y(!1)}},te=n=>{Re(n),Pe({...n}),G(!0)},je=async()=>{if(Ce)try{await jr(Ce.cookie_id,Ce.item_id,{item_title:xe.item_title||"",item_description:xe.item_description||"",item_category:xe.item_category||"",item_price:xe.item_price||"",item_detail:xe.item_detail||Ce.item_detail||""}),await $e(),await Le(),G(!1),Re(null)}catch(n){console.error("更新商品失败:",n),alert("更新失败,请重试")}},p=async n=>{if(confirm(`确认删除商品"${n.item_title}"吗?`))try{await xr(n.cookie_id,n.item_id),l(C=>C.filter(i=>!(i.cookie_id===n.cookie_id&&i.item_id===n.item_id)))}catch(C){console.error("删除商品失败:",C),alert("删除失败,请重试")}},$=async()=>{try{if(!le.cookie_id||!le.item_id){alert("请选择账号并填写商品ID");return}await mr(le.cookie_id,{item_id:le.item_id,item_title:le.item_title,item_price:le.item_price,item_detail:le.item_image?JSON.stringify({item_image:le.item_image}):""}),await $e(),U(!1),g({cookie_id:"",item_id:"",item_title:"",item_price:"",item_image:""})}catch(n){console.error("添加商品失败:",n),alert("添加失败,请重试")}},ie=async()=>{if(!y.cookie_id)return alert("请选择发布账号");if(!y.title.trim())return alert("请填写商品标题");if(!y.price.trim())return alert("请填写商品价格");if(!y.quantity||Number(y.quantity)<=0)return alert("库存数量必须大于 0");if(y.images.length===0)return alert("至少上传 1 张商品图片");if(y.postage_mode==="fixed"&&!y.postage.trim())return alert("请填写一口价邮费");ce(!0);try{const n=await pr({...y,location:q||void 0});if(await $e(),ge(!1),D({cookie_id:A||"",title:"",description:"",price:"",original_price:"",quantity:"1",postage_mode:"free",postage:"",images:[]}),W([]),ne(null),n!=null&&n.item_id){const C={id:n.item_id,cookie_id:y.cookie_id,item_id:n.item_id,item_title:n.item_title||y.title,item_price:n.item_price||y.price,item_image:n.item_image};t(C),alert("商品发布成功,ID: "+n.item_id+",已为你打开发货规则配置")}else alert("商品发布成功")}catch(n){console.error("发布商品失败:",n);const C=n==null?void 0:n.payload;if((C==null?void 0:C.code)==="stock_permission_missing"){alert("发布失败:该账号没有库存发布权限,无法按库存数量发布商品。请换账号或先在闲鱼确认库存能力。");return}alert((n==null?void 0:n.message)||"发布失败,请重试")}finally{ce(!1)}},re=async()=>{Z("upload"),u(null),F(null),R(null),ee(null),se(""),S({catId:"",catName:"",channelCatId:"",tbCatId:""}),ve([]),Ne(null),K(!0),M(!0);try{const n=await Vs(20),C=nn(n);if(C!=null&&C.id){const i=await bt(C.id);H(i),F(i),Z(["running","canceling"].includes(i.status)?"running":"done")}}catch(n){console.error("恢复最近批量铺货任务失败:",n)}finally{M(!1)}},ze=async()=>{const n=T.trim();if(!A)return alert("请先选择默认发布账号");if(!n)return alert("请输入类目关键词");ye(!0);try{const i=(await ur(A,n)).category;S({catId:i.cat_id,catName:i.cat_name,channelCatId:i.channel_cat_id,tbCatId:i.tb_cat_id||""})}catch(C){console.error("获取推荐类目失败:",C),alert((C==null?void 0:C.message)||"没有匹配到类目,请换一个更具体的关键词")}finally{ye(!1)}},He=async()=>{if(I!=null&&I.id){M(!0),K(!0);try{const n=await bt(I.id);F(n),Z(["running","canceling"].includes(n.status)?"running":"done")}catch(n){console.error("加载最近批量铺货结果失败:",n)}finally{M(!1)}}},Xe=async()=>{if(!me)return alert("请先上传商品表格");if(!A)return alert("请先选择默认发布账号");M(!0);try{const n=await hr({file:me,imagesZip:E,defaultCookieId:A,fallbackCategory:c,location:De||void 0});u(n),F(null),Z("preview")}catch(n){console.error("批量铺货预检失败:",n),alert((n==null?void 0:n.message)||"预检失败,请检查表格和图片 zip")}finally{M(!1)}},mt=async()=>{if(Q!=null&&Q.preview_id){if(Q.valid<=0)return alert("没有可发布的商品行");M(!0);try{const n=await gr(Q.preview_id),C=await bt(n.batch_id||Q.preview_id);F(C),H(C),Z(C.status==="running"?"running":"done")}catch(n){console.error("启动批量铺货失败:",n),alert((n==null?void 0:n.message)||"启动发布任务失败")}finally{M(!1)}}},Ue=async()=>{if(d!=null&&d.id&&confirm("确认取消当前批量铺货任务吗?正在发布的单个商品可能会继续完成。")){M(!0);try{const n=await fr(d.id),C=await bt(d.id);F(C),Z((n==null?void 0:n.status)==="canceling"||C.status==="canceling"?"running":"done")}catch(n){alert((n==null?void 0:n.message)||"取消失败")}finally{M(!1)}}},We=async()=>{const n=Q==null?void 0:Q.preview_id;if(n&&ae==="preview")try{await br(n)}catch(C){console.error("清理批量铺货预检失败:",C)}u(null),Z("upload")},pt=async()=>{await We(),K(!1)},kt=async()=>{if(d!=null&&d.id){M(!0);try{await yr(d.id),F(await bt(d.id)),Z("running")}catch(n){alert((n==null?void 0:n.message)||"重试失败")}finally{M(!1)}}},Ct=()=>{const i=[["账号ID","标题","描述","价格","原价","库存","邮费模式","邮费","图片","类目ID","类目名称","频道类目ID","淘宝类目ID","付款发货启用","付款发货内容","评价赠品启用","评价赠品内容","求评价启用","求评价等待小时","求评价文案","求评价最多次数"],...[["","会员组合包自动发货","下单后发送主卡和附赠卡。","19.90","29.90","10","free","","images/bundle-1.jpg;images/bundle-2.jpg","","","","","是","101:1;102:1","是","201:1;202:2","是","72","亲,满意的话麻烦给个评价,谢谢~","1"],["","普通商品","仅发布商品,不创建自动化规则。","49.90","","10","fixed","8.00","https://example.com/product.jpg","","","","","否","","否","","否","","",""]]].map(_=>_.map(B=>`"${String(B).replace(/"/g,'""')}"`).join(",")).join(`
|
||
`),N=new Blob(["\uFEFF"+i],{type:"text/csv;charset=utf-8"}),a=URL.createObjectURL(N),h=document.createElement("a");h.href=a,h.download="批量铺货模板.csv",document.body.appendChild(h),h.click(),h.remove(),URL.revokeObjectURL(a)},St=()=>{g(n=>({...n,cookie_id:A||n.cookie_id})),U(!0)},lt=()=>{D(n=>({...n,cookie_id:A||n.cookie_id})),ge(!0)},rt=async n=>{if(!(n?A:y.cookie_id))return alert("请先选择发布账号");if(!navigator.geolocation)return alert("当前浏览器不支持定位");m(!0),navigator.geolocation.getCurrentPosition(async i=>{try{const N=await mn(i.coords.longitude,i.coords.latitude);if(!N.length)throw new Error("当前位置附近没有可用的高德发货地,请稍后重试");n?(ve(N),Ne(N[0])):(W(N),ne(N[0]))}catch(N){alert((N==null?void 0:N.message)||"获取发货地失败")}finally{m(!1)}},i=>{m(!1),alert(i.code===i.PERMISSION_DENIED?"定位权限被拒绝,请在浏览器设置中允许定位":"无法获取当前位置,请稍后重试")},{enableHighAccuracy:!0,timeout:15e3,maximumAge:6e4})},Lt=n=>o.filter(C=>C.cookie_id===n.cookie_id&&C.item_id===n.item_id).length>0?o.filter(C=>C.cookie_id===n.cookie_id&&C.item_id===n.item_id):o.filter(C=>C.cookie_id===n.cookie_id&&!C.item_id),nt=n=>{switch(n){case"preview":return"待确认";case"pending":return"等待中";case"running":return"发布中";case"canceling":return"正在安全取消";case"success":return"成功";case"failed":return"失败";case"completed":return"已完成";case"partially_failed":return"部分失败";case"canceled":return"已取消";default:return n||"-"}},ut=n=>{switch(n){case"success":case"completed":return"bg-emerald-50 text-emerald-700 border-emerald-100";case"partially_failed":case"failed":return"bg-red-50 text-red-700 border-red-100";case"running":return"bg-blue-50 text-blue-700 border-blue-100";case"canceled":return"bg-gray-100 text-gray-600 border-gray-200";default:return"bg-amber-50 text-amber-700 border-amber-100"}},et=r.useMemo(()=>new Map(v.map(n=>[n.id,n])),[v]),it=r.useMemo(()=>O?s.filter(n=>n.cookie_id===O):s,[O,s]),Ve=n=>{const C=et.get(n),i=(C==null?void 0:C.remark)||(C==null?void 0:C.nickname);return i?`${i} · ${n.slice(0,6)}`:`账号 ${n.slice(0,8)}`},ht=n=>{const C=et.get(n);return(C==null?void 0:C.remark)||(C==null?void 0:C.nickname)||"未命名账号"};return e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col xl:flex-row xl:justify-between xl:items-center gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-3xl font-bold text-gray-900",children:"商品管理"}),e.jsx("p",{className:"text-gray-500 mt-2 text-sm",children:"监控并管理所有账号下的闲鱼商品。"})]}),e.jsxs("div",{className:"flex flex-wrap items-end gap-3",children:[e.jsxs("div",{className:"flex min-w-[200px] flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"item-account-filter",className:"px-1 text-[11px] font-extrabold tracking-wide text-gray-500",children:"商品列表筛选"}),e.jsxs("div",{className:"relative",children:[e.jsx(el,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{id:"item-account-filter","aria-label":"按账号筛选商品列表",className:"ios-input w-full pl-10 pr-9 py-3 rounded-xl text-sm",value:O,onChange:n=>j(n.target.value),children:[e.jsx("option",{value:"",children:"全部账号"}),v.map(n=>e.jsx("option",{value:n.id,children:Ve(n.id)},n.id))]})]})]}),e.jsxs("div",{className:"flex min-w-[200px] flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"item-sync-account",className:"px-1 text-[11px] font-extrabold tracking-wide text-gray-500",children:"同步商品账号"}),e.jsxs("div",{className:"relative",children:[e.jsx(xt,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{id:"item-sync-account","aria-label":"选择要同步商品的账号",className:"ios-input w-full pl-10 pr-9 py-3 rounded-xl text-sm",value:A,onChange:n=>b(n.target.value),children:[e.jsx("option",{value:"",children:"请选择账号"}),v.map(n=>e.jsx("option",{value:n.id,children:Ve(n.id)},n.id))]})]})]}),e.jsxs("button",{onClick:Ae,disabled:V||!A,className:"ios-btn-primary flex items-center gap-2 px-6 py-3 rounded-2xl font-bold shadow-lg shadow-blue-200 disabled:opacity-50",children:[e.jsx(Be,{className:`w-4 h-4 ${V?"animate-spin":""}`}),"同步商品"]}),e.jsxs("button",{onClick:St,className:"px-5 py-3 rounded-2xl font-bold bg-gray-900 text-white hover:bg-gray-800 transition-colors flex items-center gap-2 shadow-lg",children:[e.jsx(Ye,{className:"w-4 h-4"}),"添加商品"]}),e.jsxs("button",{onClick:lt,className:"px-5 py-3 rounded-2xl font-bold bg-emerald-500 text-white hover:bg-emerald-600 transition-colors flex items-center gap-2 shadow-lg shadow-emerald-100",children:[e.jsx(Yt,{className:"w-4 h-4"}),"发布商品"]}),e.jsxs("button",{onClick:()=>void re(),className:"px-5 py-3 rounded-2xl font-bold bg-brand text-white hover:bg-brand-highlight transition-colors flex items-center gap-2 shadow-lg shadow-blue-100",children:[e.jsx(qt,{className:"w-4 h-4"}),I&&["running","canceling"].includes(I.status)?"继续批量任务":"批量铺货"]}),I&&!["running","canceling"].includes(I.status)&&e.jsx("button",{onClick:()=>void He(),className:"px-4 py-3 rounded-2xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"最近批次结果"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-4",children:[it.map(n=>{const C=Lt(n),i=C.length>0;return e.jsxs("div",{className:"ios-card p-3 rounded-2xl hover:shadow-lg transition-all group relative flex flex-col",children:[e.jsxs("div",{className:"absolute top-2 right-2 flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity z-10",children:[e.jsx("button",{onClick:()=>te(n),className:"p-1.5 bg-white/90 backdrop-blur rounded-lg shadow-md text-gray-600 hover:bg-brand hover:text-white transition-colors",title:"编辑",children:e.jsx(_t,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:()=>p(n),className:"p-1.5 bg-white/90 backdrop-blur rounded-lg shadow-md hover:bg-red-100 text-red-500 transition-colors",title:"删除",children:e.jsx(Je,{className:"w-3.5 h-3.5"})})]}),e.jsxs("div",{className:"aspect-square bg-gray-100 rounded-xl mb-2.5 overflow-hidden relative",children:[n.item_image?e.jsx("img",{src:n.item_image,alt:"",className:"w-full h-full object-cover group-hover:scale-105 transition-transform duration-500"}):e.jsx("div",{className:"w-full h-full flex items-center justify-center text-gray-300",children:e.jsx(pa,{className:"w-8 h-8"})}),e.jsx("div",{className:"absolute top-1.5 left-1.5 bg-black/50 backdrop-blur-md text-white text-[10px] font-bold px-1.5 py-0.5 rounded-md",children:pn(n.item_price)})]}),e.jsx("h3",{className:"font-bold text-gray-900 line-clamp-2 text-xs mb-1.5 h-8 leading-4",children:n.item_title}),e.jsxs("div",{className:"mb-2 inline-flex min-w-0 max-w-full items-center gap-1 self-start rounded-md bg-blue-50 px-2 py-1 text-[10px] font-extrabold text-blue-700",title:ht(n.cookie_id),children:[e.jsx(xt,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{className:"min-w-0 truncate whitespace-nowrap",children:ht(n.cookie_id)})]}),e.jsxs("div",{className:"flex justify-between items-center text-[10px] text-gray-500 mb-2",children:[e.jsxs("span",{className:"bg-gray-100 px-1.5 py-0.5 rounded truncate max-w-[80px]",children:["ID: ",n.item_id]}),e.jsxs("span",{className:`inline-flex items-center gap-1 font-bold ${i?"text-emerald-600":"text-amber-600"}`,children:[i?e.jsx(os,{className:"w-3 h-3"}):e.jsx(tl,{className:"w-3 h-3"}),i?`${C.length} 规则`:"未配置"]})]}),e.jsx("div",{className:"space-y-2 mt-auto",children:e.jsxs("button",{onClick:()=>t(n),className:`w-full flex items-center justify-between gap-1 px-2.5 py-2 rounded-lg text-[11px] font-extrabold transition-all ${i?"bg-gray-900 text-white hover:bg-black":"bg-brand text-white hover:bg-brand-highlight shadow-md shadow-blue-100"}`,children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(sl,{className:"w-3.5 h-3.5"}),i?"查看发货规则":"关联发货规则"]}),e.jsx(cs,{className:"w-3.5 h-3.5"})]})})]},`${n.cookie_id}-${n.item_id}`)}),it.length===0&&e.jsxs("div",{className:"col-span-full py-20 text-center text-gray-400",children:[e.jsx(ua,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),O?"该账号暂无商品数据":"暂无商品数据,请选择账号进行同步"]})]}),de&&Ce&&Me.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"560px"},children:[e.jsxs("div",{className:"modal-header flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-extrabold text-gray-900",children:"编辑商品"}),e.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:["ID: ",Ce.item_id]})]}),e.jsx("button",{onClick:()=>G(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",children:e.jsx(Te,{className:"w-5 h-5 text-gray-500"})})]}),e.jsxs("div",{className:"modal-body space-y-4",children:[e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"商品标题",value:xe.item_title||"",onChange:n=>Pe({...xe,item_title:n.target.value})}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"价格",value:xe.item_price||"",onChange:n=>Pe({...xe,item_price:n.target.value})}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"分类",value:xe.item_category||"",onChange:n=>Pe({...xe,item_category:n.target.value})}),e.jsx("textarea",{className:"w-full ios-input px-4 py-3 rounded-xl h-28 resize-none",placeholder:"描述",value:xe.item_description||"",onChange:n=>Pe({...xe,item_description:n.target.value})})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("button",{onClick:je,className:"w-full ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Ge,{className:"w-4 h-4"}),"保存"]})})]})}),document.body),X&&Me.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"720px"},children:[e.jsxs("div",{className:"modal-header flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-extrabold text-gray-900",children:"添加商品"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"手动建立商品与自动发货规则的关联"})]}),e.jsx("button",{onClick:()=>U(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",title:"关闭",children:e.jsx(Te,{className:"w-5 h-5 text-gray-500"})})]}),e.jsxs("div",{className:"modal-body space-y-5",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"所属账号"}),e.jsxs("select",{className:"w-full ios-input px-4 py-3 rounded-xl",value:le.cookie_id,onChange:n=>g({...le,cookie_id:n.target.value}),children:[e.jsx("option",{value:"",children:"选择账号"}),v.map(n=>e.jsx("option",{value:n.id,children:Ve(n.id)},n.id))]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"商品 ID"}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"输入闲鱼商品 ID",value:le.item_id,onChange:n=>g({...le,item_id:n.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"商品价格"}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"例如 99.00",value:le.item_price,onChange:n=>g({...le,item_price:n.target.value})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"商品标题"}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"输入商品标题",value:le.item_title,onChange:n=>g({...le,item_title:n.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"图片 URL"}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"https://...",value:le.item_image,onChange:n=>g({...le,item_image:n.target.value})})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("button",{onClick:$,className:"w-full ios-btn-primary px-6 py-3.5 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Ye,{className:"w-4 h-4"}),"添加商品"]})})]})}),document.body),fe&&Me.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"820px"},children:[e.jsxs("div",{className:"modal-header flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-extrabold text-gray-900",children:"发布商品到闲鱼"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"普通单规格发布;库存数量会写入闲鱼发布参数,用于判断账号库存能力。"})]}),e.jsx("button",{onClick:()=>ge(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",title:"关闭",children:e.jsx(Te,{className:"w-5 h-5 text-gray-500"})})]}),e.jsxs("div",{className:"modal-body space-y-5",children:[e.jsx("div",{className:"rounded-2xl border border-amber-200 bg-amber-50 p-4 text-sm text-amber-800 leading-6",children:"发布时必须填写库存。若账号没有库存发布能力,后端会返回明确的“库存权限不足”错误,不会误报为普通发布失败。"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"发布账号"}),e.jsxs("select",{className:"w-full ios-input px-4 py-3 rounded-xl",value:y.cookie_id,onChange:n=>{D({...y,cookie_id:n.target.value}),W([]),ne(null)},children:[e.jsx("option",{value:"",children:"选择账号"}),v.map(n=>e.jsx("option",{value:n.id,children:Ve(n.id)},n.id))]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"商品标题"}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"例如:会员月卡自动发货",value:y.title,onChange:n=>D({...y,title:n.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"库存数量"}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",type:"number",min:"1",placeholder:"必须大于 0",value:y.quantity,onChange:n=>D({...y,quantity:n.target.value})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"商品描述"}),e.jsx("textarea",{className:"w-full ios-input px-4 py-3 rounded-xl h-28 resize-none",placeholder:"描述会用于自动识别类目;留空时使用标题",value:y.description,onChange:n=>D({...y,description:n.target.value})})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"售价"}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"99.00",value:y.price,onChange:n=>D({...y,price:n.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"原价(可选)"}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"129.00",value:y.original_price,onChange:n=>D({...y,original_price:n.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"运费方式"}),e.jsxs("select",{className:"w-full ios-input px-4 py-3 rounded-xl",value:y.postage_mode,onChange:n=>D({...y,postage_mode:n.target.value}),children:[e.jsx("option",{value:"free",children:"包邮"}),e.jsx("option",{value:"distance",children:"按距离计费"}),e.jsx("option",{value:"fixed",children:"一口价邮费"}),e.jsx("option",{value:"none",children:"无需邮寄"})]})]})]}),y.postage_mode==="fixed"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"一口价邮费"}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"例如 8.00",value:y.postage,onChange:n=>D({...y,postage:n.target.value})})]}),e.jsxs("div",{className:"rounded-2xl border border-sky-200 bg-sky-50 p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-extrabold text-gray-900",children:"发货地(可选)"}),e.jsx("p",{className:"mt-1 text-xs text-sky-800",children:"虚拟商品无需发货地;发布失败时可再定位并作为补充信息提交。"})]}),e.jsxs("button",{type:"button",disabled:z||!y.cookie_id,onClick:()=>void rt(!1),className:"ios-btn-primary flex items-center gap-2 rounded-xl px-4 py-2 text-sm font-bold disabled:opacity-50",children:[e.jsx($s,{className:"h-4 w-4"}),z?"定位中...":"获取当前位置"]})]}),f.length>0&&e.jsx("select",{className:"w-full ios-input rounded-xl bg-white px-4 py-3",value:String(Math.max(0,f.indexOf(q))),onChange:n=>ne(f[Number(n.target.value)]||null),children:f.map((n,C)=>e.jsx("option",{value:String(C),children:[n.province,n.city,n.area,n.poi_name].filter(Boolean).join(" ")},`${n.division_id}-${n.poi_id}-${C}`))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"商品图片(1-9 张)"}),e.jsxs("label",{className:"flex min-h-[120px] cursor-pointer flex-col items-center justify-center rounded-2xl border-2 border-dashed border-gray-200 bg-gray-50 px-4 py-6 text-center hover:border-emerald-300 hover:bg-emerald-50/50 transition-colors",children:[e.jsx(qt,{className:"w-8 h-8 text-emerald-600 mb-2"}),e.jsx("span",{className:"text-sm font-bold text-gray-800",children:"选择图片"}),e.jsx("span",{className:"text-xs text-gray-500 mt-1",children:y.images.length?"已选择 "+y.images.length+" 张":"支持 JPG / PNG / GIF"}),e.jsx("input",{className:"hidden",type:"file",accept:"image/*",multiple:!0,onChange:n=>D({...y,images:Array.from(n.target.files||[]).slice(0,9)})})]}),J.length>0&&e.jsx("div",{className:"grid grid-cols-4 sm:grid-cols-6 gap-3",children:J.map(n=>e.jsx("div",{className:"aspect-square rounded-xl bg-gray-100 overflow-hidden border border-gray-100",children:e.jsx("img",{src:n.url,alt:"",className:"w-full h-full object-cover"})},n.key))})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("button",{disabled:pe,onClick:ie,className:"w-full bg-emerald-500 hover:bg-emerald-600 disabled:opacity-60 text-white px-6 py-3.5 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Yt,{className:"w-4 h-4"}),pe?"正在发布...":"发布到闲鱼"]})})]})}),document.body),L&&Me.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"980px"},children:[e.jsxs("div",{className:"modal-header flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-extrabold text-gray-900",children:"批量铺货"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"上传商品表格和图片 zip,先预检,再逐条发布到闲鱼。"})]}),e.jsx("button",{onClick:()=>void pt(),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",title:"关闭",children:e.jsx(Te,{className:"w-5 h-5 text-gray-500"})})]}),e.jsxs("div",{className:"modal-body space-y-5",children:[e.jsx("div",{className:"grid grid-cols-4 gap-2",children:[["upload","1 上传"],["preview","2 预检"],["running","3 发布"],["done","4 结果"]].map(([n,C])=>e.jsx("div",{className:`rounded-xl px-3 py-2 text-center text-xs font-extrabold border ${ae===n?"bg-blue-600 text-white border-blue-600":"bg-gray-50 text-gray-500 border-gray-100"}`,children:C},n))}),ae==="upload"&&e.jsxs("div",{className:"space-y-5",children:[e.jsx("div",{className:"rounded-2xl border border-blue-100 bg-blue-50 p-4 text-sm text-blue-900 leading-6",children:e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center md:justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-extrabold",children:"先下载模板,再按字段填写。"}),e.jsxs("div",{children:["图片字段写 zip 内相对路径,多个图片用英文分号分隔,例如 ",e.jsx("span",{className:"font-mono font-bold",children:"images/a.jpg;images/b.jpg"}),"。也支持直接填写图片 URL。"]})]}),e.jsx("button",{type:"button",onClick:Ct,className:"shrink-0 rounded-xl bg-blue-600 px-4 py-2 text-sm font-extrabold text-white hover:bg-blue-700",children:"下载CSV模板"})]})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"默认发布账号"}),e.jsxs("select",{className:"w-full ios-input px-4 py-3 rounded-xl",value:A,onChange:n=>{b(n.target.value),ve([]),Ne(null)},children:[e.jsx("option",{value:"",children:"选择账号"}),v.map(n=>e.jsx("option",{value:n.id,children:Ve(n.id)},n.id))]}),e.jsx("p",{className:"text-xs text-gray-500",children:"表格中“账号ID”为空时,会使用这里选择的账号。"})]}),e.jsxs("div",{className:"rounded-xl border border-amber-200 bg-amber-50/70 p-4 space-y-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"text-sm font-extrabold text-gray-900",children:["默认类目 ",e.jsx("span",{className:"font-medium text-gray-500",children:"(可为空)"})]}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-amber-800",children:"填写后优先使用该类目;留空时由闲鱼根据每件商品自动识别。仍无法识别时,系统最终使用“电子资料”兜底。"})]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsxs("label",{className:"relative flex-1",children:[e.jsx("span",{className:"sr-only",children:"类目关键词"}),e.jsx(Nt,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsx("input",{className:"w-full ios-input rounded-xl bg-white py-2.5 pl-10 pr-3",placeholder:"输入关键词,例如:课程资料、设计素材",value:T,onChange:n=>se(n.target.value),onKeyDown:n=>{n.key==="Enter"&&(n.preventDefault(),ze())}})]}),e.jsxs("button",{type:"button",disabled:!A||!T.trim()||ke,onClick:()=>void ze(),className:"ios-btn-primary flex min-h-[42px] items-center justify-center gap-2 rounded-xl px-4 text-sm font-bold disabled:opacity-50",children:[e.jsx(Nt,{className:"h-4 w-4"}),ke?"匹配中...":"获取类目"]})]}),c.catId?e.jsxs("div",{className:"flex min-h-[46px] items-center justify-between gap-3 border-t border-amber-200 pt-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-bold text-gray-900",children:[e.jsx(os,{className:"h-4 w-4 shrink-0 text-emerald-600"}),e.jsx("span",{className:"truncate",children:c.catName})]}),e.jsxs("div",{className:"mt-1 font-mono text-xs text-gray-500",children:["类目 ",c.catId," · 频道 ",c.channelCatId]})]}),e.jsx("button",{type:"button",title:"清除默认类目",onClick:()=>S({catId:"",catName:"",channelCatId:"",tbCatId:""}),className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-lg text-gray-500 hover:bg-white hover:text-gray-900",children:e.jsx(Te,{className:"h-4 w-4"})})]}):null]}),e.jsxs("div",{className:"rounded-xl border border-sky-200 bg-sky-50 p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-extrabold text-gray-900",children:"批次发货地(可选)"}),e.jsx("p",{className:"mt-1 text-xs text-sky-800",children:"虚拟商品可留空;填写后整个批次使用同一个发货地,并随任务保存用于恢复和重试。"})]}),e.jsxs("button",{type:"button",disabled:z||!A,onClick:()=>void rt(!0),className:"ios-btn-primary flex items-center gap-2 rounded-xl px-4 py-2 text-sm font-bold disabled:opacity-50",children:[e.jsx($s,{className:"h-4 w-4"}),z?"定位中...":"获取当前位置"]})]}),be.length>0&&e.jsx("select",{className:"w-full ios-input rounded-xl bg-white px-4 py-3",value:String(Math.max(0,be.indexOf(De))),onChange:n=>Ne(be[Number(n.target.value)]||null),children:be.map((n,C)=>e.jsx("option",{value:String(C),children:[n.province,n.city,n.area,n.poi_name].filter(Boolean).join(" ")},`${n.division_id}-${n.poi_id}-${C}`))})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("label",{className:"flex min-h-[150px] cursor-pointer flex-col items-center justify-center rounded-2xl border-2 border-dashed border-gray-200 bg-gray-50 px-4 py-6 text-center hover:border-blue-300 hover:bg-blue-50 transition-colors",children:[e.jsx(qt,{className:"w-9 h-9 text-blue-600 mb-3"}),e.jsx("span",{className:"text-sm font-extrabold text-gray-900",children:"上传商品表格"}),e.jsx("span",{className:"text-xs text-gray-500 mt-1",children:me?me.name:"支持 .xlsx / .csv / .tsv"}),e.jsx("input",{className:"hidden",type:"file",accept:".xlsx,.csv,.tsv",onChange:n=>{var C;return R(((C=n.target.files)==null?void 0:C[0])||null)}})]}),e.jsxs("label",{className:"flex min-h-[150px] cursor-pointer flex-col items-center justify-center rounded-2xl border-2 border-dashed border-gray-200 bg-gray-50 px-4 py-6 text-center hover:border-emerald-300 hover:bg-emerald-50 transition-colors",children:[e.jsx(qt,{className:"w-9 h-9 text-emerald-600 mb-3"}),e.jsx("span",{className:"text-sm font-extrabold text-gray-900",children:"上传图片 zip(可选)"}),e.jsx("span",{className:"text-xs text-gray-500 mt-1",children:E?E.name:"表格图片字段使用 zip 内相对路径"}),e.jsx("input",{className:"hidden",type:"file",accept:".zip",onChange:n=>{var C;return ee(((C=n.target.files)==null?void 0:C[0])||null)}})]})]}),e.jsxs("div",{className:"rounded-2xl bg-gray-50 border border-gray-100 p-4 space-y-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-extrabold text-gray-900",children:"字段说明"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"照着下面的“什么时候填写”处理即可。预检发现问题时,会指出具体哪一行需要修改。"})]}),e.jsxs("div",{className:"rounded-xl border border-blue-100 bg-blue-50 p-4 text-xs text-blue-950",children:[e.jsx("div",{className:"text-sm font-extrabold",children:"“付款后发送的卡密”怎么填"}),e.jsxs("div",{className:"mt-3 grid grid-cols-1 gap-3 lg:grid-cols-3",children:[e.jsxs("div",{className:"rounded-lg bg-white/80 p-3",children:[e.jsx("code",{className:"font-bold text-blue-700",children:"101"}),e.jsx("p",{className:"mt-1 leading-5",children:"从卡密组 101 立即发送 1 份。卡密组 ID 可以在“卡密库存”页面查看。"})]}),e.jsxs("div",{className:"rounded-lg bg-white/80 p-3",children:[e.jsx("code",{className:"font-bold text-blue-700",children:"101:2"}),e.jsx("p",{className:"mt-1 leading-5",children:"每购买 1 件,就从卡密组 101 发送 2 份。买家购买 3 件时会发送 6 份。"})]}),e.jsxs("div",{className:"rounded-lg bg-white/80 p-3",children:[e.jsx("code",{className:"font-bold text-blue-700",children:"101:1:0;102:2:3"}),e.jsx("p",{className:"mt-1 leading-5",children:"先立即发送卡密组 101 的 1 份,再等待 3 秒发送卡密组 102 的 2 份。"})]})]}),e.jsxs("p",{className:"mt-3 leading-5 text-blue-800",children:["每一组依次写“卡密组 ID : 每件发送几份 : 等待几秒”。份数不写时按 1 份处理,等待时间不写时立即发送。需要发送多种卡密时,用英文分号 ",e.jsx("code",{className:"font-bold",children:";"})," 隔开。"]})]}),e.jsx("div",{className:"overflow-x-auto rounded-xl border border-gray-100 bg-white",children:e.jsxs("table",{className:"w-full text-left text-xs",children:[e.jsx("thead",{className:"bg-gray-50 text-gray-500",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2",children:"字段"}),e.jsx("th",{className:"px-3 py-2",children:"什么时候填写"}),e.jsx("th",{className:"px-3 py-2",children:"填写方法"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50 text-gray-700",children:[["账号ID","需要覆盖默认账号时填写","上方默认发布账号为必选;本列留空时使用默认账号,填写后仅覆盖当前行"],["标题","每个商品都要填","填写买家能看到的商品标题"],["描述","可以留空","留空时会使用商品标题作为描述"],["价格","每个商品都要填","只填数字,例如 19.90"],["原价","可以留空","需要展示划线原价时填写,例如 29.90"],["库存","可以留空","留空按 1 件处理;填写时必须大于 0"],["邮费模式","可以留空","留空表示包邮;包邮填 free,固定邮费填 fixed"],["邮费","邮费模式填 fixed 时填写","只填数字,例如 8.00"],["图片","每个商品都要填","填写 zip 内图片路径或图片网址;多张图片用英文分号隔开"],["类目ID","需要指定当前行默认类目时填写","必须和“类目名称、频道类目ID”同时填写;优先于自动识别"],["类目名称","填写了“类目ID”时必填","填写该 ID 对应的准确类目名称"],["频道类目ID","覆盖类目时必填","必须填写闲鱼返回的准确频道类目 ID"],["淘宝类目ID","按闲鱼返回填写","“电子资料”无淘宝类目 ID,保持为空"],["付款发货启用","需要付款后自动发货时填写","填“是”表示开启;不需要时填“否”或留空"],["付款发货内容","“付款发货启用”填“是”时填写","从“卡密库存”页面取得卡密组 ID,按上方示例填写"],["评价赠品启用","需要评价赠品时填写","填“是”表示开启;不需要时填“否”或留空"],["评价赠品内容","“评价赠品启用”填“是”时填写","格式和付款发货内容相同,也可以同时发送多个卡密组"],["求评价启用","需要自动求评价时填写","填“是”表示开启;不需要时填“否”或留空"],["求评价等待小时","“求评价启用”填“是”时填写","填写等待小时数;留空按 72 小时处理"],["求评价文案","“求评价启用”填“是”时填写","填写要发送给买家的求评价消息"],["求评价最多次数","可以留空","留空只提醒 1 次"]].map(([n,C,i])=>e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 font-bold text-gray-900 whitespace-nowrap",children:n}),e.jsx("td",{className:`px-3 py-2 min-w-[210px] font-bold ${C==="每个商品都要填"?"text-red-600":C==="可以留空"?"text-gray-500":"text-amber-700"}`,children:C}),e.jsx("td",{className:"px-3 py-2 min-w-[260px]",children:i})]},n))})]})})]})]}),ae==="preview"&&Q&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{className:"rounded-2xl bg-gray-50 p-4 border border-gray-100",children:[e.jsx("div",{className:"text-xs font-bold text-gray-500",children:"总行数"}),e.jsx("div",{className:"text-2xl font-extrabold text-gray-900 mt-1",children:Q.total})]}),e.jsxs("div",{className:"rounded-2xl bg-emerald-50 p-4 border border-emerald-100",children:[e.jsx("div",{className:"text-xs font-bold text-emerald-700",children:"可发布"}),e.jsx("div",{className:"text-2xl font-extrabold text-emerald-700 mt-1",children:Q.valid})]}),e.jsxs("div",{className:"rounded-2xl bg-red-50 p-4 border border-red-100",children:[e.jsx("div",{className:"text-xs font-bold text-red-700",children:"有问题"}),e.jsx("div",{className:"text-2xl font-extrabold text-red-700 mt-1",children:Q.invalid})]})]}),e.jsx("div",{className:"max-h-[380px] overflow-y-auto rounded-2xl border border-gray-100",children:e.jsxs("table",{className:"w-full text-left text-sm",children:[e.jsx("thead",{className:"sticky top-0 bg-white text-xs text-gray-400 border-b border-gray-100",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3",children:"行号"}),e.jsx("th",{className:"px-4 py-3",children:"状态"}),e.jsx("th",{className:"px-4 py-3",children:"标题"}),e.jsx("th",{className:"px-4 py-3",children:"价格/库存"}),e.jsx("th",{className:"px-4 py-3",children:"类目策略"}),e.jsx("th",{className:"px-4 py-3",children:"图片"}),e.jsx("th",{className:"px-4 py-3",children:"问题"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50",children:Q.rows.map(n=>{var C,i,N,a;return e.jsxs("tr",{className:"hover:bg-gray-50",children:[e.jsx("td",{className:"px-4 py-3 font-mono text-xs",children:n.row_no}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("span",{className:`inline-flex px-2 py-1 rounded-lg border text-xs font-extrabold ${n.valid?"bg-emerald-50 text-emerald-700 border-emerald-100":"bg-red-50 text-red-700 border-red-100"}`,children:n.valid?"可发布":"需修正"})}),e.jsx("td",{className:"px-4 py-3 font-bold text-gray-900 max-w-[240px] truncate",children:n.title||"-"}),e.jsxs("td",{className:"px-4 py-3 text-gray-600",children:["¥",n.price||"-"," / ",n.quantity||1]}),e.jsxs("td",{className:"px-4 py-3 text-xs text-gray-600 min-w-[150px]",children:[e.jsx("div",{className:"font-bold text-gray-800",children:((C=n.category)==null?void 0:C.cat_name)||"自动识别"}),e.jsx("div",{className:"font-mono text-gray-400",children:((i=n.category)==null?void 0:i.cat_id)||"失败后使用电子资料"})]}),e.jsxs("td",{className:"px-4 py-3 text-gray-600",children:[((N=n.images)==null?void 0:N.length)||0," 张"]}),e.jsx("td",{className:"px-4 py-3 text-red-600 text-xs max-w-[280px]",children:((a=n.errors)==null?void 0:a.join(";"))||"-"})]},n.row_no)})})]})})]}),(ae==="running"||ae==="done")&&d&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-3",children:[e.jsxs("div",{className:`rounded-2xl p-4 border ${ut(d.status)}`,children:[e.jsx("div",{className:"text-xs font-bold opacity-70",children:"任务状态"}),e.jsx("div",{className:"text-xl font-extrabold mt-1",children:nt(d.status)})]}),e.jsxs("div",{className:"rounded-2xl bg-gray-50 p-4 border border-gray-100",children:[e.jsx("div",{className:"text-xs font-bold text-gray-500",children:"总数"}),e.jsx("div",{className:"text-xl font-extrabold text-gray-900 mt-1",children:d.total})]}),e.jsxs("div",{className:"rounded-2xl bg-emerald-50 p-4 border border-emerald-100",children:[e.jsx("div",{className:"text-xs font-bold text-emerald-700",children:"成功"}),e.jsx("div",{className:"text-xl font-extrabold text-emerald-700 mt-1",children:d.success})]}),e.jsxs("div",{className:"rounded-2xl bg-red-50 p-4 border border-red-100",children:[e.jsx("div",{className:"text-xs font-bold text-red-700",children:"失败"}),e.jsx("div",{className:"text-xl font-extrabold text-red-700 mt-1",children:d.failed})]}),e.jsxs("div",{className:"rounded-2xl bg-blue-50 p-4 border border-blue-100",children:[e.jsx("div",{className:"text-xs font-bold text-blue-700",children:"等待"}),e.jsx("div",{className:"text-xl font-extrabold text-blue-700 mt-1",children:d.pending})]})]}),e.jsx("div",{className:"max-h-[420px] overflow-y-auto rounded-2xl border border-gray-100",children:e.jsxs("table",{className:"w-full text-left text-sm",children:[e.jsx("thead",{className:"sticky top-0 bg-white text-xs text-gray-400 border-b border-gray-100",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3",children:"行号"}),e.jsx("th",{className:"px-4 py-3",children:"状态"}),e.jsx("th",{className:"px-4 py-3",children:"标题"}),e.jsx("th",{className:"px-4 py-3",children:"类目策略"}),e.jsx("th",{className:"px-4 py-3",children:"商品ID"}),e.jsx("th",{className:"px-4 py-3",children:"错误原因"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50",children:d.rows.map(n=>{var C,i;return e.jsxs("tr",{className:"hover:bg-gray-50",children:[e.jsx("td",{className:"px-4 py-3 font-mono text-xs",children:n.row_no}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("span",{className:`inline-flex px-2 py-1 rounded-lg border text-xs font-extrabold ${ut(n.status)}`,children:nt(n.status)})}),e.jsx("td",{className:"px-4 py-3 font-bold text-gray-900 max-w-[260px] truncate",children:n.title}),e.jsxs("td",{className:"px-4 py-3 text-xs text-gray-600 min-w-[150px]",children:[e.jsx("div",{className:"font-bold text-gray-800",children:((C=n.category)==null?void 0:C.cat_name)||"自动识别"}),e.jsx("div",{className:"font-mono text-gray-400",children:((i=n.category)==null?void 0:i.cat_id)||"失败后使用电子资料"})]}),e.jsx("td",{className:"px-4 py-3 text-xs font-mono",children:n.item_url?e.jsx("a",{href:n.item_url,target:"_blank",rel:"noreferrer",className:"text-blue-600 hover:underline",children:n.item_id}):n.item_id||"-"}),e.jsx("td",{className:"px-4 py-3 text-red-600 text-xs max-w-[340px]",children:n.error_message||"-"})]},n.id)})})]})})]})]}),e.jsxs("div",{className:"modal-footer",children:[ae==="upload"&&e.jsxs("button",{disabled:w||!me||!A,onClick:Xe,className:"w-full ios-btn-primary px-6 py-3.5 rounded-xl font-bold flex items-center justify-center gap-2 disabled:opacity-50",children:[e.jsx(Be,{className:`w-4 h-4 ${w?"animate-spin":""}`}),w?"正在预检...":"开始预检"]}),ae==="preview"&&Q&&e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{disabled:w,onClick:()=>void We(),className:"flex-1 px-6 py-3.5 rounded-xl bg-gray-100 hover:bg-gray-200 text-gray-800 font-bold",children:"返回修改"}),e.jsxs("button",{disabled:w||Q.valid<=0,onClick:mt,className:"flex-1 ios-btn-primary px-6 py-3.5 rounded-xl font-bold flex items-center justify-center gap-2 disabled:opacity-50",children:[e.jsx(Yt,{className:"w-4 h-4"}),w?"启动中...":`确认发布 ${Q.valid} 个商品`]})]}),(ae==="running"||ae==="done")&&d&&e.jsxs("div",{className:"flex gap-3 w-full",children:[d.status==="running"?e.jsx("button",{disabled:w,onClick:Ue,className:"flex-1 px-6 py-3.5 rounded-xl bg-gray-900 text-white hover:bg-black font-bold",children:"取消任务"}):d.status==="canceling"?e.jsx("button",{disabled:!0,className:"flex-1 px-6 py-3.5 rounded-xl bg-amber-100 text-amber-800 font-bold",children:"正在保存远端结果并安全取消…"}):e.jsx("button",{onClick:()=>window.open(`/items/publish-batches/${d.id}/result.csv`,"_blank"),className:"flex-1 px-6 py-3.5 rounded-xl bg-gray-900 text-white hover:bg-black font-bold",children:"下载结果"}),d.retryable>0&&!["running","canceling"].includes(d.status)&&e.jsxs("button",{disabled:w,onClick:kt,className:"flex-1 ios-btn-primary px-6 py-3.5 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Be,{className:`w-4 h-4 ${w?"animate-spin":""}`}),"重试失败项"]}),!["running","canceling"].includes(d.status)&&e.jsx("button",{onClick:()=>{K(!1),$e(),Le()},className:"flex-1 px-6 py-3.5 rounded-xl bg-gray-100 hover:bg-gray-200 text-gray-800 font-bold",children:"完成"})]})]})]})}),document.body)]})},ta="https://dashscope.aliyuncs.com/compatible-mode/v1",hn=[{value:"debug",label:"Debug"},{value:"info",label:"Info"},{value:"warn",label:"Warn"},{value:"error",label:"Error"}],gn=new Set(["smtp_server","smtp_port","smtp_user","smtp_password","smtp_from","smtp_from_name","smtp_from_address","registration_enabled","show_default_login_info","login_captcha_enabled","item_sync_enabled","item_sync_interval","item_sync_max_pages","default_reply"]),bn=()=>{const[t,s]=r.useState(null),[l,o]=r.useState(!1),[x,v]=r.useState(""),[k,A]=r.useState(!1),[b,O]=r.useState([]),[j,V]=r.useState(!1),[Y,pe]=r.useState(""),[ce,w]=r.useState(!1),M=r.useRef(null),[de,G]=r.useState(!1),[X,U]=r.useState(!1),[fe,ge]=r.useState(!1),[L,K]=r.useState(!1),[ae,Z]=r.useState(!1),[me,R]=r.useState(null),[E,ee]=r.useState({new_username:"",current_password:"",new_password:"",confirm_password:""});r.useEffect(()=>{se(),wa().then(f=>{f.username&&ee(W=>({...W,new_username:f.username||""}))}).catch(()=>{})},[]),r.useEffect(()=>{const f=W=>{var q;(q=M.current)!=null&&q.contains(W.target)||w(!1)};return document.addEventListener("mousedown",f),()=>document.removeEventListener("mousedown",f)},[]);const T=async(f,W=!1)=>{const q=f||t,ne=(q==null?void 0:q.ai_api_url)||(q==null?void 0:q.ai_base_url)||ta;V(!0),pe("");try{const be=await $r(ne,(q==null?void 0:q.ai_api_key)||"");O(be),w(W&&be.length>0),!(q!=null&&q.ai_model)&&be.length>0&&s(ve=>ve&&{...ve,ai_model:be[0]})}catch(be){O([]),w(!1),pe(be.message||"读取模型失败")}finally{V(!1)}},se=()=>{o(!0),v(""),La().then(f=>{s(f),T(f)}).catch(f=>{s(null),v(f.message||"加载配置失败")}).finally(()=>o(!1))},ke=async()=>{if(t){A(!0);try{const f=Object.fromEntries(Object.entries(t).filter(([W,q])=>!gn.has(W)&&q!==void 0&&q!==null));await Oa(f),alert("系统配置已保存")}catch(f){alert("保存失败:"+f.message)}finally{A(!1)}}},ye=async f=>{f.preventDefault(),R(null);const W=E.new_username.trim();if(W.length<3){R({type:"error",text:"用户名至少需要 3 个字符"});return}if(!E.current_password){R({type:"error",text:"请输入当前密码确认身份"});return}if(E.new_password&&E.new_password.length<8){R({type:"error",text:"新密码至少需要 8 个字符"});return}if(E.new_password!==E.confirm_password){R({type:"error",text:"两次输入的新密码不一致"});return}Z(!0);try{const q=await Ol({current_password:E.current_password,new_username:W,new_password:E.new_password||void 0});if(!q.success){R({type:"error",text:q.message||"登录凭据更新失败"});return}R({type:"success",text:q.message||"登录凭据已更新"}),window.setTimeout(()=>window.location.reload(),1400)}catch(q){R({type:"error",text:q.message||"登录凭据更新失败"})}finally{Z(!1)}};if(!t)return e.jsx("div",{className:"p-8 text-center text-gray-400",children:x||(l?"加载配置中...":"暂无配置")});const z=t.ai_model||"",m=b;return e.jsxs("div",{className:"max-w-6xl mx-auto space-y-8 animate-fade-in pb-24",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-12 h-12 bg-gray-100 rounded-2xl flex items-center justify-center",children:e.jsx(bs,{className:"w-6 h-6 text-gray-600"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-3xl font-extrabold text-gray-900",children:"系统设置"}),e.jsx("p",{className:"text-gray-500 mt-1 text-sm font-medium",children:"配置全局自动化规则与系统参数"})]})]}),e.jsxs("button",{onClick:se,className:"px-4 py-2 bg-gray-100 hover:bg-gray-200 rounded-xl font-bold text-gray-700 flex items-center gap-2 transition-colors",children:[e.jsx(Be,{className:"w-4 h-4"}),"刷新"]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8",children:[e.jsxs("div",{className:"space-y-8",children:[e.jsxs("section",{className:"space-y-4",children:[e.jsxs("h3",{className:"text-lg font-extrabold text-gray-800 flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-gray-100 text-gray-600",children:e.jsx(al,{className:"w-4 h-4"})}),"基础设置"]}),e.jsxs("div",{className:"ios-card rounded-xl p-6 bg-white space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"日志输出等级"}),e.jsx("select",{value:t.log_level||"info",onChange:f=>s({...t,log_level:f.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:hn.map(f=>e.jsx("option",{value:f.value,children:f.label},f.value))}),e.jsx("p",{className:"text-xs text-gray-500",children:"等级越低输出越详细,Debug 适合排查问题"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"日志输出格式"}),e.jsxs("select",{value:t.log_format||"text",onChange:f=>s({...t,log_format:f.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"text",children:"Text"}),e.jsx("option",{value:"json",children:"JSON"})]}),e.jsx("p",{className:"text-xs text-gray-500",children:"JSON 适合接入集中式日志系统,保存后需重启服务生效"})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"续期日志保留天数"}),e.jsx("input",{type:"number",value:t.renewal_log_retention_days??10,onChange:f=>s({...t,renewal_log_retention_days:parseInt(f.target.value)||0}),className:"w-full ios-input px-4 py-3 rounded-xl",min:"0",max:"365"}),e.jsx("p",{className:"text-xs text-gray-500",children:"0 表示不自动清理续期日志"})]})]})]}),e.jsxs("section",{className:"space-y-4",children:[e.jsxs("h3",{className:"text-lg font-extrabold text-gray-800 flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-brand text-white",children:e.jsx(js,{className:"w-4 h-4"})}),"AI 智能回复配置"]}),e.jsxs("div",{className:"ios-card rounded-xl p-6 bg-white space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"API 地址"}),e.jsx("input",{type:"text",value:t.ai_api_url||ta,onChange:f=>s({...t,ai_api_url:f.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl text-sm",placeholder:"https://api.openai.com/v1"}),e.jsx("p",{className:"text-xs text-gray-500",children:"无需补全 /chat/completions"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"API Key"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:de?"text":"password",value:t.ai_api_key||"",onChange:f=>s({...t,ai_api_key:f.target.value}),className:"w-full ios-input px-4 py-3 pr-12 rounded-xl font-mono text-sm",placeholder:"sk-..."}),e.jsx("button",{type:"button",onClick:()=>G(!de),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600 transition-colors",children:de?e.jsx(dt,{className:"w-4 h-4"}):e.jsx(st,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"模型"}),e.jsxs("div",{ref:M,className:"relative flex flex-col sm:flex-row gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx("input",{value:z,onFocus:()=>b.length>0&&w(!0),onChange:f=>{s({...t,ai_model:f.target.value}),b.length>0&&w(!0)},onKeyDown:f=>{f.key==="Escape"&&w(!1),f.key==="ArrowDown"&&b.length>0&&w(!0)},className:"w-full ios-input px-4 py-3 pr-10 rounded-xl",placeholder:"从接口读取或手动输入模型名"}),e.jsx("button",{type:"button",onClick:()=>b.length>0&&w(f=>!f),disabled:b.length===0,className:"absolute right-2 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600 disabled:opacity-30","aria-label":"展开模型列表",children:e.jsx(ll,{className:`w-4 h-4 transition-transform ${ce?"rotate-180":""}`})}),ce&&e.jsx("div",{className:"absolute left-0 right-0 top-[calc(100%+6px)] z-40 max-h-64 overflow-y-auto rounded-xl border border-gray-200 bg-white shadow-xl shadow-gray-200/70 py-1",children:m.length>0?m.map(f=>e.jsxs("button",{type:"button",onClick:()=>{s({...t,ai_model:f}),w(!1)},className:"w-full px-4 py-2.5 text-left text-sm text-gray-700 hover:bg-blue-50 hover:text-brand flex items-center justify-between gap-3",children:[e.jsx("span",{className:"truncate",children:f}),f===z&&e.jsx(Qe,{className:"w-4 h-4 shrink-0 text-brand"})]},f)):e.jsx("div",{className:"px-4 py-3 text-sm text-gray-400",children:"没有匹配的模型"})})]}),e.jsxs("button",{type:"button",onClick:()=>T(void 0,!0),disabled:j,className:"px-4 py-3 rounded-xl bg-gray-100 text-gray-700 hover:bg-gray-200 disabled:opacity-60 font-bold flex items-center justify-center gap-2 whitespace-nowrap",children:[e.jsx(Be,{className:`w-4 h-4 ${j?"animate-spin":""}`}),"读取模型"]})]}),Y?e.jsx("p",{className:"text-xs text-red-500",children:Y}):e.jsx("p",{className:"text-xs text-gray-500",children:b.length>0?`已从当前 API 地址读取到 ${b.length} 个模型`:"模型列表从当前 API 地址读取,也可以手动输入模型名"})]}),e.jsxs("div",{className:"p-3 bg-blue-50 rounded-xl text-xs text-blue-700",children:[e.jsx("strong",{children:"常见 AI 服务:"}),e.jsxs("ul",{className:"list-disc list-inside mt-1 space-y-0.5",children:[e.jsx("li",{children:"阿里云通义千问: https://dashscope.aliyuncs.com/compatible-mode/v1"}),e.jsx("li",{children:"OpenAI: https://api.openai.com/v1"})]})]})]})]})]}),e.jsxs("div",{className:"space-y-8",children:[e.jsxs("section",{className:"space-y-4",children:[e.jsxs("h3",{className:"text-lg font-extrabold text-gray-800 flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-amber-500 text-white",children:e.jsx(Dt,{className:"w-4 h-4"})}),"远程过滑块配置"]}),e.jsxs("div",{className:"ios-card rounded-xl p-6 bg-white space-y-5",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"服务地址"}),e.jsx("input",{type:"url",value:t["captcha.remote_service_url"]||"",onChange:f=>s({...t,"captcha.remote_service_url":f.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl text-sm",placeholder:"https://example.com/internal/captcha/solve"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"服务秘钥"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:X?"text":"password",value:t["captcha.remote_secret_key"]||"",onChange:f=>s({...t,"captcha.remote_secret_key":f.target.value}),className:"w-full ios-input px-4 py-3 pr-12 rounded-xl font-mono text-sm",autoComplete:"off"}),e.jsx("button",{type:"button",onClick:()=>U(!X),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",title:X?"隐藏秘钥":"显示秘钥",children:X?e.jsx(dt,{className:"w-4 h-4"}):e.jsx(st,{className:"w-4 h-4"})})]})]}),e.jsxs("label",{className:"flex items-start gap-3 rounded-xl bg-amber-50 p-4 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:String(t["captcha.remote_pass_cookies"]||"").toLowerCase()==="true",onChange:f=>s({...t,"captcha.remote_pass_cookies":f.target.checked}),className:"mt-0.5 w-4 h-4 rounded border-gray-300"}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-sm font-bold text-amber-900",children:"允许向远程服务传递账号 Cookie"}),e.jsx("span",{className:"block mt-1 text-xs text-amber-700",children:"默认关闭。仅在信任远程服务且需要由其自动重取过期验证链接时开启。"})]})]}),e.jsx("p",{className:"text-xs text-gray-500",children:"配置地址和秘钥后优先调用远程服务;只有网络不可用或超时才回退本机引擎,远程明确返回失败时不会重复触发本机验证。"})]})]}),e.jsxs("section",{className:"space-y-4",children:[e.jsxs("h3",{className:"text-lg font-extrabold text-gray-800 flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-gray-900 text-white",children:e.jsx(Es,{className:"w-4 h-4"})}),"登录凭据"]}),e.jsxs("form",{onSubmit:ye,className:"ios-card rounded-xl p-6 bg-white space-y-5",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"登录用户名"}),e.jsxs("div",{className:"relative",children:[e.jsx(Vt,{className:"absolute left-4 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400"}),e.jsx("input",{type:"text",value:E.new_username,onChange:f=>ee({...E,new_username:f.target.value}),className:"w-full ios-input pl-11 pr-4 py-3 rounded-xl text-sm",autoComplete:"username"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"当前密码"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:fe?"text":"password",value:E.current_password,onChange:f=>ee({...E,current_password:f.target.value}),className:"w-full ios-input px-4 py-3 pr-12 rounded-xl text-sm",placeholder:"用于确认当前身份",autoComplete:"current-password"}),e.jsx("button",{type:"button",onClick:()=>ge(!fe),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",title:fe?"隐藏密码":"显示密码",children:fe?e.jsx(dt,{className:"w-4 h-4"}):e.jsx(st,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"新密码"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:L?"text":"password",value:E.new_password,onChange:f=>ee({...E,new_password:f.target.value}),className:"w-full ios-input px-4 py-3 pr-11 rounded-xl text-sm",placeholder:"不修改则留空",autoComplete:"new-password"}),e.jsx("button",{type:"button",onClick:()=>K(!L),className:"absolute right-2 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",title:L?"隐藏密码":"显示密码",children:L?e.jsx(dt,{className:"w-4 h-4"}):e.jsx(st,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"确认新密码"}),e.jsx("input",{type:L?"text":"password",value:E.confirm_password,onChange:f=>ee({...E,confirm_password:f.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl text-sm",placeholder:"再次输入新密码",autoComplete:"new-password"})]})]}),me&&e.jsxs("div",{className:`flex items-start gap-2 rounded-xl px-3 py-2.5 text-sm font-medium ${me.type==="success"?"bg-green-50 text-green-700":"bg-red-50 text-red-700"}`,children:[e.jsx(Dt,{className:"w-4 h-4 mt-0.5 flex-shrink-0"}),e.jsx("span",{children:me.text})]}),e.jsxs("button",{type:"submit",disabled:ae||!E.new_username||!E.current_password,className:"w-full bg-gray-900 hover:bg-black text-white px-5 py-3 rounded-xl font-bold text-sm flex items-center justify-center gap-2 transition-colors disabled:opacity-40",children:[e.jsx(Es,{className:"w-4 h-4"}),ae?"正在更新...":"更新登录凭据"]})]})]})]})]}),e.jsx("div",{className:"fixed bottom-10 right-10 z-30",children:e.jsxs("button",{onClick:ke,disabled:k,className:"ios-btn-primary px-10 py-5 rounded-xl text-lg shadow-2xl shadow-blue-200 flex items-center gap-3 transform hover:scale-105 active:scale-95 transition-all disabled:opacity-70",children:[e.jsx(Ge,{className:"w-6 h-6"}),k?"保存中...":"保存所有配置"]})})]})},ls=(t,s)=>t.allowed_resolutions.includes(s),fn=(t,s)=>({runs:t.runs.filter(l=>!s||l.cookie_id===s),pending_tasks:t.pending_tasks.filter(l=>!s||l.cookie_id===s)}),yn=t=>({external_result_unknown:"外部动作结果未知",invalid_snapshot:"历史数据无法恢复",rule_unavailable:"规则不可用",partial_failure:"部分动作失败",execution_failed:"动作执行失败"})[t]||"自动化异常",jn=(t,s,l,o,x,v)=>t!==s||l!==o?!1:(v(x),!0),tt={order_paid:{label:"付款后自动发货",shortLabel:"自动发货",description:"闲鱼付款系统卡片进入自动化中心后,先发送卡密,成功后再确认发货。",flow:["付款系统卡片","匹配商品/规格","发送卡密","确认发货"],accent:"blue",icon:Tt},buyer_reviewed:{label:"评价后发送赠品",shortLabel:"评价赠品",description:"闲鱼评价系统卡片进入自动化中心后,给买家发送赠品卡密。",flow:["评价系统卡片","匹配商品/规格","发送赠品"],accent:"emerald",icon:rl},review_missing_timeout:{label:"超时未评价求评价",shortLabel:"求评价",description:"计划任务扫描已发货未评价订单,到期后发送求评价文案。",flow:["计划任务扫描","已发货未评价","达到等待时间","发送提醒"],accent:"amber",icon:ja}},Wt=["order_paid","buyer_reviewed","review_missing_timeout"],_n="亲,商品使用满意的话,麻烦给个评价,谢谢~",At=()=>({spec_name:"",spec_value:"",card_id:0,delivery_count:1,enabled:!0,delay_override:!1,delay_seconds:0}),Ra=t=>{if(!t)return{};try{const s=JSON.parse(t);return s&&typeof s=="object"&&!Array.isArray(s)?s:{}}catch{return{}}},ct=(t,s={})=>{const l=Ra(t);return JSON.stringify({after_shipped_hours:Number(l.after_shipped_hours||72),repeat_interval_hours:Number(l.repeat_interval_hours||24),max_attempts:Number(l.max_attempts||1),...s})},Rt=(t,s)=>{var o;const l=((o=tt[t])==null?void 0:o.label)||"自动化规则";return s?`${l} - ${s}`:l},sa=t=>{const s=(t||"").trim();return s?Object.values(tt).some(l=>s===l.label||s.startsWith(`${l.label} -`)):!0},Pt=(t,s=0)=>{if(t==="review_missing_timeout")return[{action_type:"send_text",message_template:_n,enabled:!0,sort_order:1}];const l={action_type:"send_card",card_id:s,delivery_count:1,enabled:!0,sort_order:1};return t==="order_paid"?[l,{action_type:"confirm_shipment",enabled:!0,sort_order:2}]:[l]},Nn=t=>{var l,o;if(t.trigger_type==="review_missing_timeout")return((o=(l=t.actions)==null?void 0:l.find(x=>x.action_type==="send_text"))==null?void 0:o.message_template)||"发送求评价文案";const s=(t.actions||[]).filter(x=>x.action_type==="send_card");return s.length?s.map(x=>x.card_name||`卡密 ${x.card_id}`).join(" / "):"未配置卡密库存"},aa=(t,s=!1)=>{const l={blue:s?"border-blue-500 bg-blue-50 text-blue-700":"border-blue-100 bg-blue-50/60 text-blue-700 hover:border-blue-300",emerald:s?"border-emerald-500 bg-emerald-50 text-emerald-700":"border-emerald-100 bg-emerald-50/60 text-emerald-700 hover:border-emerald-300",amber:s?"border-amber-500 bg-amber-50 text-amber-700":"border-amber-100 bg-amber-50/60 text-amber-700 hover:border-amber-300"};return l[t]||l.blue},vn=t=>t?"bg-emerald-100 text-emerald-700":"bg-gray-200 text-gray-500",Jt=t=>(t==null?void 0:t.nickname)||(t==null?void 0:t.remark)||(t==null?void 0:t.id)||"未知账号",wn=t=>t===!0||t===1||t==="1",kn=({initialDeliveryTarget:t,onDeliveryTargetHandled:s})=>{var C,i,N;const[l,o]=r.useState("automation"),[x,v]=r.useState([]),[k,A]=r.useState({runs:[],pending_tasks:[]}),[b,O]=r.useState([]),[j,V]=r.useState({}),[Y,pe]=r.useState([]),[ce,w]=r.useState([]),[M,de]=r.useState([]),[G,X]=r.useState(!1),[U,fe]=r.useState(""),[ge,L]=r.useState(""),[K,ae]=r.useState(""),[Z,me]=r.useState(""),[R,E]=r.useState("all"),[ee,T]=r.useState(1),[se,ke]=r.useState(10),[ye,z]=r.useState(0),[m,f]=r.useState(0),[W,q]=r.useState({}),ne=r.useRef(0),be=r.useRef(0),ve=r.useRef("");ve.current=U;const[De,Ne]=r.useState(!1),[c,S]=r.useState(!1),[Q,u]=r.useState(!1),[d,F]=r.useState(null),[I,H]=r.useState(null),[P,Ce]=r.useState({cookie_id:"",enabled:!1,reply_content:"",reply_once:!1,reply_image_url:""});Y.find(a=>a.id===U);const Re=r.useCallback(async()=>{const[a,h,_,B]=await Promise.all([Mt(),Ze(),vt(),Ks()]);pe(a),w(h),de(_),V(B),fe(oe=>{var ue;return oe||((ue=a[0])==null?void 0:ue.id)||""})},[]),xe=r.useCallback(async()=>{const a=++ne.current,h=wr().catch(oe=>(console.warn("加载自动化异常列表失败,不阻断规则展示",oe),null)),_=await _r({cookieId:U||void 0,triggerType:Z,enabled:R==="all"?void 0:R==="enabled",search:K,page:ee,pageSize:se});if(a!==ne.current)return;v(_.data),z(_.total),f(_.total_pages),q(_.trigger_counts||{}),_.page!==ee&&T(_.page);const B=await h;a===ne.current&&B&&A(B)},[ee,se,R,Z,K,U]),Pe=r.useCallback(async()=>{const a=U;if(a!==ve.current)return;const h=++be.current;if(O([]),!a)return;const _=await Or(a);jn(h,be.current,a,ve.current,_,O)},[U]),le=r.useCallback(async()=>{V(await Ks())},[]),g=r.useCallback(async()=>{X(!0);try{l==="automation"?await xe():l==="reply"?await Pe():await le()}finally{X(!1)}},[l,xe,le,Pe]);r.useEffect(()=>{const a=window.setTimeout(()=>{T(1),ae(ge.trim())},300);return()=>window.clearTimeout(a)},[ge]),r.useEffect(()=>{Re().catch(a=>console.error("加载规则参考数据失败",a))},[Re]),r.useEffect(()=>{g().catch(a=>console.error("刷新规则页面失败",a))},[g]);const y=r.useMemo(()=>x.filter(a=>!U||a.cookie_id===U),[x,U]),D=r.useMemo(()=>fn(k,U),[k,U]),J=r.useMemo(()=>Y.filter(a=>!U||a.id===U),[Y,U]),Se=r.useMemo(()=>{if(m<=1)return[];const a=Math.max(1,Math.min(ee-2,m-4)),h=Math.min(m,a+4);return Array.from({length:h-a+1},(_,B)=>a+B)},[ee,m]),$e=!!(ge.trim()||Z||R!=="all"),Le=()=>{L(""),ae(""),me(""),E("all"),T(1)},Ae=r.useMemo(()=>{const a=(d==null?void 0:d.cookie_id)||U;return M.filter(h=>h.cookie_id===a)},[d==null?void 0:d.cookie_id,M,U]),te=r.useMemo(()=>{if(!(!(d!=null&&d.cookie_id)||!(d!=null&&d.item_id)))return M.find(a=>a.cookie_id===d.cookie_id&&a.item_id===d.item_id)},[d==null?void 0:d.cookie_id,d==null?void 0:d.item_id,M]),je=wn(te==null?void 0:te.is_multi_spec),p=(d==null?void 0:d.trigger_type)||"order_paid",$=tt[p],ie=Ra(d==null?void 0:d.config_json),re=r.useCallback((a="order_paid",h=U,_="")=>{const B=M.find(ue=>ue.cookie_id===h&&ue.item_id===_),oe=(B==null?void 0:B.item_title)||_;return{name:Rt(a,oe),trigger_type:a,cookie_id:h,item_id:_,item_title:(B==null?void 0:B.item_title)||"",item_keyword:oe,card_group_id:0,priority:100,enabled:!0,config_json:a==="review_missing_timeout"?ct():"{}",actions:Pt(a),variants:a==="review_missing_timeout"?[]:[At()]}},[M,U]),ze=r.useCallback(a=>{var _,B;const h=a.trigger_type||"order_paid";F({...a,trigger_type:h,config_json:h==="review_missing_timeout"?ct(a.config_json):a.config_json||"{}",actions:(_=a.actions)!=null&&_.length?a.actions.map(oe=>({...oe})):Pt(h,a.card_group_id),variants:(B=a.variants)!=null&&B.length?a.variants.map(oe=>({...oe})):h==="review_missing_timeout"?[]:[At()]}),Ne(!0)},[]);r.useEffect(()=>{if(!t)return;let a=!1;return(async()=>{o("automation"),fe(t.cookieId),X(!0);try{const[_,B,oe]=await Promise.all([us(),vt(),Ze().catch(he=>(console.warn("加载卡密库存失败,不阻断打开自动化规则",he),[]))]);if(a)return;v(_),de(B),w(oe);const ue=_.find(he=>he.cookie_id===t.cookieId&&he.item_id===t.itemId&&he.trigger_type==="order_paid");if(ue)ze(ue);else{const he=B.find(qe=>qe.cookie_id===t.cookieId&&qe.item_id===t.itemId);F({...re("order_paid",t.cookieId,t.itemId),item_title:(he==null?void 0:he.item_title)||"",item_keyword:(he==null?void 0:he.item_title)||t.itemId,name:Rt("order_paid",(he==null?void 0:he.item_title)||t.itemId)}),Ne(!0)}}catch(_){console.error("打开商品自动化规则失败",_),alert("无法加载该商品的自动化规则")}finally{a||(X(!1),s==null||s())}})(),()=>{a=!0}},[re,t,s,ze]);const He=(a="order_paid")=>{if(!U){alert("请先选择账号");return}F(re(a)),Ne(!0)},Xe=a=>{var B,oe,ue,he,qe;if(!d)return;const h=((oe=(B=d.variants)==null?void 0:B.find(we=>we.card_id))==null?void 0:oe.card_id)||((he=(ue=d.actions)==null?void 0:ue.find(we=>we.action_type==="send_card"))==null?void 0:he.card_id)||d.card_group_id||0,_=(te==null?void 0:te.item_title)||d.item_title||d.item_id||"";F({...d,trigger_type:a,name:sa(d.name)?Rt(a,_):d.name,card_group_id:h,config_json:a==="review_missing_timeout"?ct(d.config_json):"{}",actions:Pt(a,h),variants:a==="review_missing_timeout"?[]:(qe=d.variants)!=null&&qe.length?d.variants:[{...At(),card_id:h}]})},mt=a=>{if(!d)return;const h=M.find(B=>B.cookie_id===(d.cookie_id||U)&&B.item_id===a),_=(h==null?void 0:h.item_title)||a;F({...d,item_id:a,item_title:(h==null?void 0:h.item_title)||"",item_keyword:_,name:sa(d.name)?Rt(p,_):d.name})},Ue=(C=d==null?void 0:d.variants)!=null&&C.length?d.variants:[At()],We=(a,h)=>{var B;if(!d)return;const _=Ue.map((oe,ue)=>ue===a?{...oe,...h}:oe);F({...d,variants:_,card_group_id:((B=_[0])==null?void 0:B.card_id)||0})},pt=()=>{if(!d)return;const a=Ue[Ue.length-1];F({...d,variants:[...Ue,{...At(),spec_name:je&&(a==null?void 0:a.spec_name)||"",spec_value:je&&(a==null?void 0:a.spec_value)||""}]})},kt=async()=>{var B,oe,ue,he,qe;if(!d)return;const a=d.trigger_type||"order_paid";if(!d.cookie_id){alert("请选择账号");return}const h=(B=d.variants)!=null&&B.length?d.variants:[];if(a!=="review_missing_timeout"){if(!h.length||h.some(we=>!we.card_id)){alert(a==="buyer_reviewed"?"请选择评价赠品卡密库存":"请选择发货卡密库存");return}if(je&&h.some(we=>!we.spec_name.trim()||!we.spec_value.trim())){alert("多规格商品必须填写每一行的规格名称和规格值");return}}if(a==="review_missing_timeout"&&!(((ue=(oe=d.actions)==null?void 0:oe.find(ot=>ot.action_type==="send_text"))==null?void 0:ue.message_template)||"").trim()){alert("请填写求评价文案");return}const _=a==="review_missing_timeout"?[]:h.map(we=>({...we,spec_name:je?we.spec_name.trim():"",spec_value:je?we.spec_value.trim():"",delivery_count:Math.max(1,Number(we.delivery_count)||1),enabled:we.enabled!==!1}));try{await Qs({...d,trigger_type:a,name:(d.name||"").trim()||Rt(a,(te==null?void 0:te.item_title)||d.item_id||""),config_json:a==="review_missing_timeout"?ct(d.config_json):d.config_json||"{}",actions:(he=d.actions)!=null&&he.length?d.actions:Pt(a,((qe=_[0])==null?void 0:qe.card_id)||d.card_group_id||0),variants:_}),Ne(!1),await Promise.all([xe(),Re()]),alert("保存成功")}catch(we){console.error("保存自动化规则失败:",we),alert("保存失败:"+we.message)}},Ct=async a=>{if(confirm("确定删除该自动化规则吗?"))try{await vr(a),await xe(),alert("删除成功")}catch(h){alert("删除失败:"+h.message)}},St=async a=>{try{await Qs({...a,enabled:!a.enabled}),await xe()}catch(h){alert("操作失败:"+h.message)}},lt=async(a,h)=>{if(confirm(h==="continue"?"确认外部动作已经执行成功,并跳到下一步吗?":h==="retry"?"确认外部动作没有执行,可以安全重试吗?错误判断可能造成重复发送。":"确认终止该自动化运行吗?"))try{await kr(a,h),await xe()}catch(B){alert("处理失败:"+B.message)}},rt=async(a,h)=>{if(confirm(h==="retry"?"确认重新执行该任务吗?":"确认忽略并删除该异常任务吗?"))try{await Cr(a,h),await xe()}catch(_){alert("处理失败:"+_.message)}},Lt=()=>{if(!U){alert("请先选择账号");return}H({keyword:"",reply_content:"",image_url:"",item_id:"",type:"text",match_type:"fuzzy",enabled:!0}),S(!0)},nt=async()=>{var h,_,B;if(!I||!U)return;const a=I.type==="image"?!!((h=I.image_url)!=null&&h.trim()):!!((_=I.reply_content)!=null&&_.trim());if(!((B=I.keyword)!=null&&B.trim())||!a){alert("请填写关键词和回复内容");return}try{await Ir({...I,match_type:"fuzzy",enabled:!0},U),S(!1),await Pe(),alert("保存成功")}catch(oe){alert("保存失败:"+oe.message)}},ut=async a=>{if(!(!U||!confirm("确定删除该回复规则吗?")))try{await Ar(a,U),await Pe(),alert("删除成功")}catch(h){alert("删除失败:"+h.message)}},et=async(a=U)=>{if(!a){alert("请先选择账号");return}try{const h=await Fr(a);Ce({cookie_id:a,enabled:h.enabled,reply_content:h.reply_content,reply_once:h.reply_once,reply_image_url:h.reply_image_url||""})}catch{Ce({cookie_id:a,enabled:!1,reply_content:"",reply_once:!1,reply_image_url:""})}u(!0)},it=async()=>{if(!P.cookie_id){alert("请先选择账号");return}if(P.enabled&&!P.reply_content.trim()&&!P.reply_image_url.trim()){alert("启用默认回复时,请填写回复内容或图片 URL");return}try{await Br(P.cookie_id,{enabled:P.enabled,reply_content:P.reply_content,reply_once:P.reply_once,reply_image_url:P.reply_image_url}),u(!1),await le(),alert("保存成功")}catch(a){alert("保存失败:"+a.message)}},Ve=async a=>{if(confirm("确定删除该账号默认回复吗?"))try{await zr(a),await le(),alert("删除成功")}catch(h){alert("删除失败:"+h.message)}},ht=async a=>{if(confirm("确定清空该账号的默认回复记录吗?清空后可重新对所有会话使用“只回复一次”。"))try{await Ur(a),alert("清空成功")}catch(h){alert("清空失败:"+h.message)}},n=l==="automation"?"新建自动化":l==="reply"?"新增关键词":"编辑默认回复";return e.jsxs("div",{className:"min-w-0 space-y-8 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col xl:flex-row justify-between xl:items-end gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-4xl font-extrabold text-gray-900 tracking-tight",children:"自动化规则"}),e.jsx("p",{className:"text-gray-500 mt-2 font-medium",children:"系统通知卡片只进入自动化判断;买家消息进入关键词、默认或 AI 回复。"})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:flex-wrap gap-3",children:[e.jsxs("select",{value:U,onChange:a=>{fe(a.target.value),T(1)},className:"ios-input w-full px-4 py-3 rounded-2xl text-sm sm:w-64",children:[e.jsx("option",{value:"",children:"全部账号"}),Y.map(a=>e.jsx("option",{value:a.id,children:Jt(a)},a.id))]}),e.jsxs("button",{onClick:g,className:"px-4 py-3 rounded-2xl font-bold bg-gray-100 hover:bg-gray-200 text-gray-700 flex items-center justify-center gap-2 whitespace-nowrap transition-colors",children:[e.jsx(Be,{className:`w-4 h-4 ${G?"animate-spin":""}`}),"刷新"]}),e.jsxs("button",{onClick:l==="automation"?()=>He("order_paid"):l==="reply"?Lt:()=>void et(),disabled:!U,className:"ios-btn-primary px-5 py-3 rounded-2xl text-sm font-extrabold flex items-center justify-center gap-2 whitespace-nowrap disabled:opacity-50",children:[e.jsx(Ye,{className:"w-4 h-4"}),n]})]})]}),e.jsx("div",{className:"flex flex-wrap gap-2 p-2 bg-gray-100/50 rounded-2xl",children:[{id:"automation",label:"交易自动化",icon:is},{id:"reply",label:"关键词回复",icon:Et},{id:"default",label:"账号默认回复",icon:yt}].map(a=>{const h=a.icon;return e.jsxs("button",{onClick:()=>o(a.id),className:`inline-flex items-center gap-2 px-5 py-2.5 rounded-xl text-sm font-bold transition-all ${l===a.id?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:text-black hover:bg-gray-50"}`,children:[e.jsx(h,{className:"w-4 h-4"}),a.label]},a.id)})}),l==="automation"&&(D.runs.length>0||D.pending_tasks.length>0)&&e.jsxs("section",{className:"rounded-2xl border border-red-200 bg-red-50 p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(at,{className:"w-5 h-5 text-red-600 mt-0.5"}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-black text-red-900",children:"需要人工处理的自动化任务"}),e.jsx("p",{className:"text-sm text-red-700 mt-1",children:"请先在闲鱼聊天、订单或商品列表中核对真实结果,再选择继续或重试。"})]})]}),e.jsxs("div",{className:"space-y-3",children:[D.runs.map(a=>e.jsxs("div",{className:"rounded-xl border border-red-100 bg-white p-4 flex flex-col lg:flex-row lg:items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"font-bold text-gray-900",children:["账号 ",a.cookie_id," · 订单 ",a.order_id||"-"," · 已记录发送 ",a.sent_count," 条"]}),e.jsx("div",{className:"text-xs font-bold text-red-800 mt-1",children:yn(a.issue_kind)}),e.jsx("div",{className:"text-xs text-red-700 mt-1 break-words",children:a.error_message})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 shrink-0",children:[ls(a,"continue")&&e.jsx("button",{onClick:()=>void lt(a.id,"continue"),className:"px-3 py-2 rounded-lg bg-emerald-100 text-emerald-800 text-xs font-bold",children:"已执行,继续下一步"}),ls(a,"retry")&&e.jsx("button",{onClick:()=>void lt(a.id,"retry"),className:"px-3 py-2 rounded-lg bg-amber-100 text-amber-800 text-xs font-bold",children:"未执行,安全重试"}),ls(a,"cancel")&&e.jsx("button",{onClick:()=>void lt(a.id,"cancel"),className:"px-3 py-2 rounded-lg bg-gray-100 text-gray-700 text-xs font-bold",children:"终止"})]})]},`run-${a.id}`)),D.pending_tasks.map(a=>e.jsxs("div",{className:"rounded-xl border border-red-100 bg-white p-4 flex flex-col lg:flex-row lg:items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"font-bold text-gray-900",children:["账号 ",a.cookie_id," · 延迟任务重试已达 ",a.attempt_count," 次"]}),e.jsx("div",{className:"text-xs text-red-700 mt-1 break-words",children:a.error_message})]}),e.jsxs("div",{className:"flex gap-2 shrink-0",children:[e.jsx("button",{onClick:()=>void rt(a.id,"retry"),className:"px-3 py-2 rounded-lg bg-amber-100 text-amber-800 text-xs font-bold",children:"重新入队"}),e.jsx("button",{onClick:()=>void rt(a.id,"dismiss"),className:"px-3 py-2 rounded-lg bg-gray-100 text-gray-700 text-xs font-bold",children:"忽略"})]})]},`task-${a.id}`))]})]}),l==="automation"&&e.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-6 xl:grid-cols-[minmax(270px,0.72fr)_minmax(0,1.28fr)]",children:[e.jsxs("aside",{className:"min-w-0 space-y-4",children:[e.jsxs("div",{className:"bg-white rounded-xl p-5 border border-gray-100 shadow-sm",children:[e.jsx("h3",{className:"font-black text-gray-900 mb-1",children:"新建规则"}),e.jsx("p",{className:"text-sm text-gray-500 mb-4",children:"先选自动化类型,再配置对应动作。"}),e.jsx("div",{className:"space-y-3",children:Wt.map(a=>{const h=tt[a],_=h.icon;return e.jsx("button",{type:"button",onClick:()=>He(a),className:`w-full text-left rounded-2xl border p-4 transition-colors ${aa(h.accent)}`,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-white/80 flex items-center justify-center shrink-0",children:e.jsx(_,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-extrabold",children:h.label}),e.jsx("div",{className:"text-xs opacity-75 mt-1 leading-5",children:h.description})]})]})},a)})})]}),e.jsxs("div",{className:"bg-white rounded-xl p-5 border border-gray-100 shadow-sm",children:[e.jsxs("div",{className:"mb-4 flex items-center justify-between gap-3",children:[e.jsx("h3",{className:"font-black text-gray-900",children:"筛选结果构成"}),e.jsxs("span",{className:"text-xs font-bold text-gray-400",children:["共 ",ye," 条"]})]}),e.jsx("div",{className:"space-y-3",children:Wt.map(a=>{const h=tt[a],_=h.icon;return e.jsxs("div",{className:"flex items-center justify-between rounded-2xl bg-gray-50 p-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(_,{className:"w-4 h-4 text-gray-500"}),e.jsx("span",{className:"text-sm font-bold text-gray-700",children:h.shortLabel})]}),e.jsx("span",{className:"text-sm font-black text-gray-900",children:W[a]||0})]},a)})})]})]}),e.jsxs("section",{className:"min-w-0 space-y-4",children:[e.jsxs("div",{className:"rounded-xl border border-gray-100 bg-surface-muted p-4 shadow-sm",children:[e.jsxs("div",{className:"flex flex-col gap-3 xl:flex-row xl:items-center",children:[e.jsxs("div",{className:"relative min-w-0 flex-1",children:[e.jsx(Nt,{className:"pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsx("input",{type:"search","aria-label":"搜索自动化规则",placeholder:"搜索规则名、商品名或商品 ID...",value:ge,onChange:a=>{L(a.target.value),T(1)},className:"ios-input w-full rounded-xl border-none bg-white py-2.5 pl-10 pr-4 text-sm shadow-sm"})]}),e.jsxs("div",{className:"relative xl:w-52",children:[e.jsx(ya,{className:"pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsxs("select",{"aria-label":"按自动化类型筛选",value:Z,onChange:a=>{me(a.target.value),T(1)},className:"ios-input w-full rounded-xl border-none bg-white py-2.5 pl-10 pr-9 text-sm shadow-sm",children:[e.jsx("option",{value:"",children:"全部自动化类型"}),Wt.map(a=>e.jsx("option",{value:a,children:tt[a].shortLabel},a))]})]}),e.jsxs("select",{"aria-label":"按启用状态筛选",value:R,onChange:a=>{E(a.target.value),T(1)},className:"ios-input rounded-xl border-none bg-white px-4 py-2.5 text-sm shadow-sm xl:w-36",children:[e.jsx("option",{value:"all",children:"全部状态"}),e.jsx("option",{value:"enabled",children:"已启用"}),e.jsx("option",{value:"disabled",children:"已禁用"})]}),$e&&e.jsx("button",{type:"button",onClick:Le,className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-xl bg-white text-gray-500 shadow-sm transition-colors hover:bg-gray-100 hover:text-gray-900",title:"清除筛选","aria-label":"清除筛选",children:e.jsx(Te,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"mt-3 flex items-center justify-between text-xs font-bold text-gray-400",children:[e.jsxs("span",{children:["找到 ",ye," 条规则"]}),G&&e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Be,{className:"h-3.5 w-3.5 animate-spin"}),"正在更新"]})]})]}),G&&y.length===0?e.jsxs("div",{className:"flex min-h-56 items-center justify-center rounded-xl border border-gray-100 bg-white text-sm font-bold text-gray-400",children:[e.jsx(Be,{className:"mr-2 h-4 w-4 animate-spin"}),"正在加载规则"]}):y.length===0?e.jsxs("div",{className:"bg-white rounded-xl border border-dashed border-gray-200 p-16 text-center",children:[e.jsx(is,{className:"w-12 h-12 text-gray-300 mx-auto mb-4"}),e.jsx("h3",{className:"text-xl font-black text-gray-900",children:$e?"没有匹配的自动化规则":"还没有自动化规则"}),e.jsx("p",{className:"text-gray-500 mt-2",children:$e?"调整或清除筛选条件后再试。":"从左侧选择一个模板开始配置。"})]}):y.map(a=>{const h=tt[a.trigger_type],_=h.icon;return e.jsx("article",{className:"bg-white rounded-xl border border-gray-100 p-5 shadow-sm hover:shadow-lg transition-all",children:e.jsxs("div",{className:"flex flex-col lg:flex-row lg:items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-start gap-4 min-w-0",children:[e.jsx("div",{className:`w-12 h-12 rounded-2xl flex items-center justify-center shrink-0 ${aa(h.accent,!0)}`,children:e.jsx(_,{className:"w-5 h-5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-2",children:[e.jsx("h3",{className:"text-lg font-black text-gray-900 truncate",children:a.name}),e.jsx("span",{className:`px-2.5 py-1 rounded-full text-xs font-bold ${vn(a.enabled)}`,children:a.enabled?"已启用":"已禁用"})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 text-xs font-bold",children:[e.jsx("span",{className:"px-2.5 py-1 rounded-lg bg-gray-100 text-gray-600",children:h.label}),e.jsx("span",{className:"px-2.5 py-1 rounded-lg bg-gray-100 text-gray-600",children:a.item_title||a.item_id||"账号级规则"}),e.jsx("span",{className:"px-2.5 py-1 rounded-lg bg-blue-50 text-blue-700",children:Nn(a)})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsxs("button",{onClick:()=>ze(a),className:"px-4 py-2 rounded-xl bg-gray-100 hover:bg-gray-200 text-gray-700 text-sm font-bold flex items-center gap-2",children:[e.jsx(_t,{className:"w-4 h-4"}),"编辑"]}),e.jsx("button",{onClick:()=>St(a),className:`px-4 py-2 rounded-xl text-sm font-bold ${a.enabled?"bg-amber-50 text-amber-700 hover:bg-amber-100":"bg-emerald-50 text-emerald-700 hover:bg-emerald-100"}`,children:a.enabled?"禁用":"启用"}),e.jsx("button",{onClick:()=>Ct(a.id),className:"p-2.5 rounded-xl text-red-500 hover:bg-red-50",title:"删除",children:e.jsx(Je,{className:"w-4 h-4"})})]})]})},a.id)}),ye>0&&e.jsxs("div",{className:"flex flex-col gap-3 rounded-xl border border-gray-100 bg-white px-4 py-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3 text-sm font-medium text-gray-500",children:[e.jsxs("span",{children:["第 ",ee," / ",Math.max(m,1)," 页"]}),e.jsx("span",{className:"h-4 w-px bg-gray-200"}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"sr-only",children:"每页显示数量"}),e.jsx("select",{value:se,onChange:a=>{ke(Number(a.target.value)),T(1)},className:"ios-input rounded-lg border-none bg-gray-50 px-2.5 py-2 text-sm",children:[10,20,50].map(a=>e.jsxs("option",{value:a,children:[a," 条/页"]},a))})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{type:"button",disabled:ee<=1||G,onClick:()=>T(a=>Math.max(1,a-1)),className:"flex h-9 w-9 items-center justify-center rounded-lg bg-gray-50 text-gray-600 transition-colors hover:bg-gray-100 disabled:cursor-not-allowed disabled:opacity-40","aria-label":"上一页",title:"上一页",children:e.jsx(ys,{className:"h-4 w-4"})}),Se.map(a=>e.jsx("button",{type:"button",disabled:G,onClick:()=>T(a),className:`h-9 min-w-9 rounded-lg px-2 text-sm font-bold transition-colors ${a===ee?"bg-brand text-white":"bg-gray-50 text-gray-600 hover:bg-gray-100"} disabled:cursor-not-allowed disabled:opacity-60`,"aria-label":`第 ${a} 页`,"aria-current":a===ee?"page":void 0,children:a},a)),e.jsx("button",{type:"button",disabled:ee>=m||G,onClick:()=>T(a=>Math.min(m,a+1)),className:"flex h-9 w-9 items-center justify-center rounded-lg bg-gray-50 text-gray-600 transition-colors hover:bg-gray-100 disabled:cursor-not-allowed disabled:opacity-40","aria-label":"下一页",title:"下一页",children:e.jsx(fs,{className:"h-4 w-4"})})]})]})]})]}),l==="reply"&&e.jsxs("section",{className:"bg-white rounded-xl border border-gray-100 p-6 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-blue-700 bg-blue-50 px-4 py-2 rounded-xl mb-5 w-fit",children:[e.jsx(at,{className:"w-4 h-4"}),"这里只处理买家用户消息;系统通知不会进入关键词或 AI 回复。"]}),e.jsxs("div",{className:"space-y-3",children:[b.map(a=>e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between p-5 rounded-2xl border border-gray-100 bg-surface-subtle hover:bg-white hover:shadow-lg transition-all gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("span",{className:"px-3 py-1 bg-black text-white rounded-lg text-xs font-bold",children:"包含匹配"}),e.jsxs("h3",{className:"font-bold text-gray-900",children:["“",a.keyword,"”"]})]}),e.jsx("div",{className:"bg-white p-3 rounded-xl border border-gray-100 text-sm text-gray-600 leading-relaxed",children:a.type==="image"&&a.image_url?a.image_url:a.reply_content})]}),e.jsxs("div",{className:"flex items-center gap-3 border-t md:border-t-0 md:border-l border-gray-200 pt-4 md:pt-0 md:pl-6",children:[e.jsx("button",{onClick:()=>{H({...a}),S(!0)},className:"p-2 text-gray-400 hover:text-black hover:bg-gray-100 rounded-xl transition-colors",title:"编辑",children:e.jsx(_t,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>ut(a.id),className:"p-2 text-gray-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors",title:"删除",children:e.jsx(Je,{className:"w-5 h-5"})})]})]},a.id)),b.length===0&&e.jsx("div",{className:"text-center py-20 text-gray-400",children:"暂无关键词回复规则"})]})]}),l==="default"&&e.jsxs("section",{className:"bg-white rounded-xl border border-gray-100 p-6 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-blue-700 bg-blue-50 px-4 py-2 rounded-xl mb-5 w-fit",children:[e.jsx(at,{className:"w-4 h-4"}),"默认回复只处理买家用户消息;关键词未命中且 AI 未接管时才会使用。"]}),e.jsxs("div",{className:"space-y-3",children:[J.map(a=>{const h=j[a.id],_=!!(h!=null&&h.enabled);return e.jsxs("div",{className:`flex flex-col md:flex-row md:items-center justify-between p-5 rounded-2xl border transition-all gap-4 ${_?"border-purple-100 bg-purple-50/50 hover:bg-white hover:shadow-lg":"border-gray-100 bg-surface-subtle hover:bg-white hover:shadow-lg"}`,children:[e.jsxs("div",{className:"flex items-center gap-4 min-w-0",children:[e.jsx("div",{className:`w-12 h-12 rounded-2xl flex items-center justify-center ${_?"bg-purple-600 text-white":"bg-gray-200 text-gray-400"}`,children:e.jsx(yt,{className:"w-5 h-5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("h3",{className:"font-bold text-gray-900 text-lg truncate",children:Jt(a)}),e.jsx("span",{className:`px-2 py-0.5 rounded-lg text-xs font-bold ${_?"bg-green-100 text-green-700":"bg-gray-200 text-gray-500"}`,children:_?"已启用":"未启用"}),(h==null?void 0:h.reply_once)&&e.jsx("span",{className:"px-2 py-0.5 rounded-lg text-xs font-bold bg-purple-100 text-purple-700",children:"只回复一次"})]}),e.jsx("div",{className:"text-sm text-gray-600 line-clamp-2",children:_?h.reply_content||h.reply_image_url||"已配置默认回复":"未配置默认回复"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 border-t md:border-t-0 md:border-l border-gray-200 pt-4 md:pt-0 md:pl-6",children:[e.jsx("button",{onClick:()=>void et(a.id),className:"p-2 text-gray-400 hover:text-black hover:bg-gray-100 rounded-xl transition-colors",title:"编辑",children:e.jsx(_t,{className:"w-4 h-4"})}),_&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>void ht(a.id),className:"px-3 py-2 text-xs font-bold text-blue-600 hover:bg-blue-50 rounded-xl transition-colors",children:"清空记录"}),e.jsx("button",{onClick:()=>void Ve(a.id),className:"p-2 text-gray-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors",title:"删除",children:e.jsx(Je,{className:"w-5 h-5"})})]})]})]},a.id)}),J.length===0&&e.jsx("div",{className:"text-center py-20 text-gray-400",children:"暂无账号"})]})]}),De&&d&&Me.createPortal(e.jsx("div",{className:"modal-overlay",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"72rem",maxHeight:"92vh"},children:[e.jsxs("div",{className:"px-6 py-5 border-b border-gray-100 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-2xl font-black text-gray-900",children:d.id?"编辑自动化规则":"新建自动化规则"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:$.description})]}),e.jsx("button",{onClick:()=>Ne(!1),className:"w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center",title:"关闭",children:e.jsx(Te,{className:"w-5 h-5 text-gray-600"})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[320px_1fr] min-h-0",children:[e.jsxs("aside",{className:"bg-slate-900 text-white p-5 overflow-y-auto",children:[e.jsx("div",{className:"text-xs font-bold text-slate-400 mb-3",children:"选择自动化类型"}),e.jsx("div",{className:"space-y-3",children:Wt.map(a=>{const h=tt[a],_=h.icon,B=p===a;return e.jsx("button",{type:"button",onClick:()=>Xe(a),className:`w-full rounded-2xl p-4 text-left border transition-all ${B?"bg-white text-slate-950 border-white":"bg-white/5 text-white border-white/10 hover:bg-white/10"}`,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(_,{className:`w-5 h-5 mt-0.5 ${B?"text-brand":"text-white"}`}),e.jsxs("div",{children:[e.jsx("div",{className:"font-black",children:h.label}),e.jsx("div",{className:`text-xs mt-1 leading-5 ${B?"text-gray-500":"text-gray-400"}`,children:h.description})]})]})},a)})}),e.jsxs("div",{className:"mt-6 rounded-2xl bg-white/5 border border-white/10 p-4",children:[e.jsx("div",{className:"text-xs font-bold text-slate-400 mb-3",children:"执行流程"}),e.jsx("div",{className:"space-y-3",children:$.flow.map((a,h)=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-6 h-6 rounded-full bg-white text-slate-950 text-xs font-black flex items-center justify-center",children:h+1}),e.jsx("span",{className:"text-sm font-bold text-gray-100",children:a})]},a))})]})]}),e.jsx("div",{className:"p-6 overflow-y-auto bg-surface-subtle",children:e.jsxs("div",{className:"space-y-5",children:[e.jsxs("section",{className:"bg-white rounded-3xl border border-gray-100 p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(os,{className:"w-5 h-5 text-brand"}),e.jsx("h4",{className:"font-black text-gray-900",children:"生效范围"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"md:col-span-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"规则名称"}),e.jsx("input",{type:"text",value:d.name||"",onChange:a=>F({...d,name:a.target.value}),placeholder:"不填时按类型和商品自动生成",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"闲鱼账号"}),e.jsxs("select",{value:d.cookie_id||"",onChange:a=>F({...d,cookie_id:a.target.value,item_id:"",item_title:"",item_keyword:""}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"选择账号"}),Y.map(a=>e.jsx("option",{value:a.id,children:Jt(a)},a.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"关联商品"}),e.jsxs("select",{value:d.item_id||"",onChange:a=>mt(a.target.value),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"账号级规则(不限定商品)"}),Ae.map(a=>e.jsx("option",{value:a.item_id,children:a.item_title||a.item_id},`${a.cookie_id}-${a.item_id}`))]})]})]}),te&&p!=="review_missing_timeout"&&e.jsxs("div",{className:"mt-4 rounded-2xl bg-gray-50 border border-gray-100 p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-2",children:[e.jsx("span",{className:"px-3 py-1.5 rounded-lg bg-gray-100 text-gray-700 text-xs font-bold",children:te.item_title||te.item_id}),e.jsx("span",{className:`px-3 py-1.5 rounded-lg text-xs font-bold ${je?"bg-blue-50 text-blue-700":"bg-gray-100 text-gray-500"}`,children:je?"多规格商品":"普通商品"}),e.jsx("span",{className:"px-3 py-1.5 rounded-lg text-xs font-bold bg-emerald-50 text-emerald-700",children:"按订单购买数量自动发货"})]}),e.jsx("p",{className:"text-xs leading-5 text-gray-500",children:"多规格状态来自闲鱼商品本身,发布后不能在这里修改;系统会在买家付款后读取订单详情,按实际购买规格和数量匹配下面的发货规则。"})]})]}),p!=="review_missing_timeout"?e.jsxs("section",{className:"bg-white rounded-3xl border border-gray-100 p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 mb-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(nl,{className:"w-5 h-5 text-brand"}),e.jsx("h4",{className:"font-black text-gray-900",children:p==="buyer_reviewed"?"赠品库存":"发货库存"})]}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:je?"每条发货内容绑定一个订单规格;同一规格可添加多条内容并全部发送。":"可添加多条发货内容,买家付款后会按顺序全部发送。"})]}),e.jsxs("button",{type:"button",onClick:pt,className:"px-3 py-2 rounded-xl bg-gray-900 text-white text-xs font-bold hover:bg-black flex items-center gap-1.5",children:[e.jsx(Ye,{className:"w-3.5 h-3.5"}),"添加发货内容"]})]}),e.jsx("div",{className:"space-y-3",children:Ue.map((a,h)=>e.jsxs("div",{className:`grid grid-cols-1 gap-3 items-end rounded-2xl border border-gray-200 p-4 ${je?"md:grid-cols-[1fr_1fr_1.4fr_110px_40px]":"md:grid-cols-[1.4fr_110px_40px]"}`,children:[je&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-gray-600 mb-2",children:"规格名称"}),e.jsx("input",{value:a.spec_name,onChange:_=>We(h,{spec_name:_.target.value}),className:"w-full ios-input px-3 py-2.5 rounded-lg",placeholder:"例如:套餐"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-gray-600 mb-2",children:"规格值"}),e.jsx("input",{value:a.spec_value,onChange:_=>We(h,{spec_value:_.target.value}),className:"w-full ios-input px-3 py-2.5 rounded-lg",placeholder:"例如:30天"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-gray-600 mb-2",children:"卡密库存"}),e.jsxs("select",{value:a.card_id||"",onChange:_=>We(h,{card_id:Number(_.target.value)}),className:"w-full ios-input px-3 py-2.5 rounded-lg",children:[e.jsx("option",{value:"",children:"请选择卡密库存"}),ce.filter(_=>_.enabled&&_.type!=="api").map(_=>e.jsx("option",{value:_.id,children:_.name},_.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-gray-600 mb-2",children:"每件份数"}),e.jsx("input",{type:"number",min:"1",max:"100",value:a.delivery_count,onChange:_=>We(h,{delivery_count:Math.max(1,Number(_.target.value)||1)}),className:"w-full ios-input px-3 py-2.5 rounded-lg"})]}),e.jsxs("div",{className:"md:col-span-full flex flex-wrap items-center gap-3 rounded-xl bg-gray-50 px-3 py-2",children:[e.jsxs("label",{className:"flex items-center gap-2 text-xs font-bold text-gray-600 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:a.delay_override===!0,onChange:_=>We(h,{delay_override:_.target.checked}),className:"accent-brand"}),"覆盖卡密默认延时"]}),a.delay_override&&e.jsx("input",{type:"number",min:"0",max:"3600",value:a.delay_seconds||0,onChange:_=>We(h,{delay_seconds:Math.max(0,Number(_.target.value)||0)}),className:"w-28 ios-input px-2 py-1.5 rounded-lg text-xs","aria-label":"动作延时秒数"}),e.jsx("span",{className:"text-xs text-gray-500",children:a.delay_override?`本动作延时 ${a.delay_seconds||0} 秒`:"使用卡密默认延时"})]}),e.jsx("button",{type:"button",disabled:Ue.length===1,onClick:()=>F({...d,variants:Ue.filter((_,B)=>B!==h)}),className:"w-10 h-10 flex items-center justify-center rounded-lg text-red-500 hover:bg-red-50 disabled:opacity-25",title:"删除发货内容",children:e.jsx(Je,{className:"w-4 h-4"})})]},a.id||h))})]}):e.jsxs("section",{className:"bg-white rounded-3xl border border-gray-100 p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(ja,{className:"w-5 h-5 text-amber-600"}),e.jsx("h4",{className:"font-black text-gray-900",children:"求评价计划"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"发货后等待小时"}),e.jsx("input",{type:"number",min:"1",value:Number(ie.after_shipped_hours||72),onChange:a=>F({...d,config_json:ct(d.config_json,{after_shipped_hours:Math.max(1,Number(a.target.value)||72)})}),className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"再次求评间隔小时"}),e.jsx("input",{type:"number",min:"1",value:Number(ie.repeat_interval_hours||24),onChange:a=>F({...d,config_json:ct(d.config_json,{repeat_interval_hours:Math.max(1,Number(a.target.value)||24)})}),className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"最多求评次数"}),e.jsx("input",{type:"number",min:"1",value:Number(ie.max_attempts||1),onChange:a=>F({...d,config_json:ct(d.config_json,{max_attempts:Math.max(1,Number(a.target.value)||1)})}),className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{className:"md:col-span-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"求评价文案"}),e.jsx("textarea",{value:((N=(i=d.actions)==null?void 0:i.find(a=>a.action_type==="send_text"))==null?void 0:N.message_template)||"",onChange:a=>{var h;return F({...d,actions:((h=d.actions)!=null&&h.length?d.actions:Pt("review_missing_timeout")).map(_=>_.action_type==="send_text"?{..._,message_template:a.target.value}:_)})},className:"w-full ios-input px-4 py-3 rounded-xl h-28 resize-none"})]})]})]}),e.jsx("section",{className:"bg-white rounded-3xl border border-gray-100 p-5",children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-[180px_1fr] gap-4 items-end",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"优先级"}),e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:"数字越小优先级越高;同一账号、商品和触发条件只执行优先级最高的一条规则。"}),e.jsx("input",{type:"number",value:d.priority||100,onChange:a=>F({...d,priority:Number(a.target.value)||100}),min:"1",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("label",{className:"h-[48px] flex items-center gap-3 px-4 bg-gray-50 rounded-xl text-sm font-bold text-gray-800",children:[e.jsx("input",{type:"checkbox",checked:d.enabled!==!1,onChange:a=>F({...d,enabled:a.target.checked}),className:"w-4 h-4 rounded"}),"启用规则"]})]})})]})})]}),e.jsxs("div",{className:"px-6 py-4 border-t border-gray-100 bg-white flex gap-3",children:[e.jsx("button",{onClick:()=>Ne(!1),className:"flex-1 px-6 py-3 rounded-2xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200",children:"取消"}),e.jsxs("button",{onClick:kt,className:"flex-1 ios-btn-primary px-6 py-3 rounded-2xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Ge,{className:"w-4 h-4"}),"保存自动化规则"]})]})]})}),document.body),c&&I&&Me.createPortal(e.jsx("div",{className:"modal-overlay",children:e.jsxs("div",{className:"modal-container",children:[e.jsx("div",{className:"modal-header",children:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:I.id?"编辑回复规则":"新增回复规则"}),e.jsx("button",{onClick:()=>S(!1),className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",children:e.jsx(Te,{className:"w-5 h-5 text-gray-600"})})]})}),e.jsxs("div",{className:"modal-body space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"关联商品"}),e.jsxs("select",{value:I.item_id||"",onChange:a=>H({...I,item_id:a.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"账号级回复"}),M.filter(a=>!U||a.cookie_id===U).map(a=>e.jsx("option",{value:a.item_id,children:a.item_title||a.item_id},`${a.cookie_id}-${a.item_id}`))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"回复类型"}),e.jsxs("select",{value:I.type||"text",onChange:a=>{const h=a.target.value;H({...I,type:h,reply_content:h==="text"?I.reply_content:"",image_url:h==="image"?I.image_url:""})},className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"text",children:"文字"}),e.jsx("option",{value:"image",children:"图片"})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"关键词"}),e.jsx("input",{type:"text",value:I.keyword||"",onChange:a=>H({...I,keyword:a.target.value}),placeholder:"买家发送的关键词",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),I.type==="image"?e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"图片 URL"}),e.jsx("input",{value:I.image_url||"",onChange:a=>H({...I,image_url:a.target.value}),placeholder:"https://...",className:"w-full ios-input px-4 py-3 rounded-xl"})]}):e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"回复内容"}),e.jsx("textarea",{value:I.reply_content||"",onChange:a=>H({...I,reply_content:a.target.value}),placeholder:"自动回复的内容",className:"w-full ios-input px-4 py-3 rounded-xl h-32 resize-none"})]}),e.jsxs("div",{className:"flex gap-3 pt-4",children:[e.jsx("button",{onClick:()=>S(!1),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:nt,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Kt,{className:"w-4 h-4"}),"保存规则"]})]})]})]})}),document.body),Q&&Me.createPortal(e.jsx("div",{className:"modal-overlay",children:e.jsxs("div",{className:"modal-container",children:[e.jsx("div",{className:"modal-header",children:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"账号默认回复"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"关键词和 AI 都未处理时,才会使用默认回复。"})]}),e.jsx("button",{onClick:()=>u(!1),className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",title:"关闭",children:e.jsx(Te,{className:"w-5 h-5 text-gray-600"})})]})}),e.jsxs("div",{className:"modal-body space-y-5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"闲鱼账号"}),e.jsxs("select",{value:P.cookie_id,onChange:a=>Ce({...P,cookie_id:a.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"选择账号"}),Y.map(a=>e.jsx("option",{value:a.id,children:Jt(a)},a.id))]})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-gray-50 rounded-xl",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-bold text-gray-900",children:"启用默认回复"}),e.jsx("div",{className:"text-xs text-gray-500 mt-1",children:"启用后,未命中关键词时自动发送"})]}),e.jsx("button",{type:"button",onClick:()=>Ce({...P,enabled:!P.enabled}),className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${P.enabled?"bg-brand":"bg-gray-300"}`,children:e.jsx("span",{className:`absolute top-1 w-6 h-6 bg-white rounded-full shadow-md transition-transform duration-300 block ${P.enabled?"translate-x-7":"translate-x-1"}`})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"回复内容"}),e.jsx("textarea",{value:P.reply_content,onChange:a=>Ce({...P,reply_content:a.target.value}),placeholder:"输入默认回复内容",className:"w-full ios-input px-4 py-3 rounded-xl h-32 resize-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"回复图片 URL(可选)"}),e.jsx("input",{type:"text",value:P.reply_image_url,onChange:a=>Ce({...P,reply_image_url:a.target.value}),placeholder:"https://example.com/image.jpg",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("label",{className:"flex items-center justify-between p-4 bg-gray-50 rounded-xl text-sm font-bold text-gray-800",children:[e.jsxs("span",{children:["只回复一次",e.jsx("span",{className:"block text-xs text-gray-500 font-medium mt-1",children:"同一会话只发送一次默认回复"})]}),e.jsx("input",{type:"checkbox",checked:P.reply_once,onChange:a=>Ce({...P,reply_once:a.target.checked}),className:"w-4 h-4 rounded"})]}),e.jsxs("div",{className:"flex gap-3 pt-4",children:[e.jsx("button",{onClick:()=>u(!1),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:it,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Ge,{className:"w-4 h-4"}),"保存默认回复"]})]})]})]})}),document.body)]})},Cn=t=>{const s=String(t.smtp_from||"").trim(),l=/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(s);return{...t,smtp_from_name:t.smtp_from_name||(l?"":s),smtp_from_address:t.smtp_from_address||(l?s:t.smtp_user||""),smtp_use_tls:la(t.smtp_use_tls,!0),smtp_use_ssl:la(t.smtp_use_ssl,!1)}},la=(t,s)=>{if(typeof t=="boolean")return t;if(typeof t=="string"){if(["true","1","yes","on"].includes(t.toLowerCase()))return!0;if(["false","0","no","off"].includes(t.toLowerCase()))return!1}return s},Ns=["smtp_server","smtp_port","smtp_user","smtp_password","smtp_from_name","smtp_from_address","smtp_use_tls","smtp_use_ssl"],gs=(t,s)=>{if(typeof t=="boolean")return t;if(typeof t=="string"){if(["true","1","yes","on"].includes(t.toLowerCase()))return!0;if(["false","0","no","off"].includes(t.toLowerCase()))return!1}return s},Pa=t=>{const s=Object.prototype.hasOwnProperty.call(t,"use_custom_smtp"),l=Ns.some(o=>String(t[o]??"").trim()!=="");return{...t,use_custom_smtp:s?gs(t.use_custom_smtp,!1):l}},ra=(t,s)=>{const l={...t,use_custom_smtp:!0};for(const o of Ns)String(l[o]??"").trim()===""&&s[o]!==void 0&&(l[o]=s[o]);return l.smtp_port||(l.smtp_port=587),l.smtp_from_address||(l.smtp_from_address=l.smtp_user||""),l.smtp_use_tls=gs(l.smtp_use_tls,!0),l.smtp_use_ssl=gs(l.smtp_use_ssl,!1),l},Sn=t=>{const s=Pa(t),l={to_email:String(s.to_email??"").trim(),use_custom_smtp:s.use_custom_smtp===!0};if(l.use_custom_smtp)for(const o of Ns)l[o]=s[o];return l},ft={bark:{label:"Bark",icon:jt,fields:[{key:"server_url",label:"Bark 服务器",placeholder:"https://api.day.app",required:!0},{key:"device_key",label:"Device Key",placeholder:"你的 Bark 设备 Key",required:!0},{key:"title",label:"标题(可选)",placeholder:"Ydisks闲鱼助手"},{key:"sound",label:"铃声(可选)",placeholder:"default"},{key:"group",label:"分组(可选)",placeholder:"xianyu"}],guide:{steps:["App Store 搜索并安装 Bark(免费)","打开 Bark App,首页会显示一条测试 URL,形如 https://api.day.app/<key>/这是测试推送内容","URL 路径里 <key> 那一段就是 Device Key,复制填入","服务器地址默认 https://api.day.app,自建服务端则填自建域名"],urlFormat:"https://api.day.app/<你的key>/测试内容",note:"不需要 secret,Device Key 本身就是唯一凭证。"}},dingtalk:{label:"钉钉机器人",icon:Et,fields:[{key:"webhook_url",label:"Webhook URL",placeholder:"https://oapi.dingtalk.com/robot/send?access_token=...",required:!0},{key:"secret",label:"加签密钥",placeholder:"SEC...",help:"安全设置勾选「加签」后生成,SEC 开头"}],guide:{steps:["钉钉进入一个群(可建单人群)→ 右上角 群设置","机器人 → 添加机器人 → 选择「自定义机器人」","安全设置勾选「加签」","完成页同时展示 Webhook 地址和 SEC 开头的 Secret,两个都复制","Webhook URL 填上面,Secret 填加签密钥"],urlFormat:"https://oapi.dingtalk.com/robot/send?access_token=XXX",note:"加签密钥可选,但强烈建议启用,否则机器人可能被滥用。"}},feishu:{label:"飞书机器人",icon:Et,fields:[{key:"webhook_url",label:"Webhook URL",placeholder:"https://open.feishu.cn/open-apis/bot/v2/hook/...",required:!0},{key:"secret",label:"签名校验密钥",placeholder:"sec-...",help:"安全设置选「签名校验」后生成"}],guide:{steps:["飞书进入目标群 → 右上角 更多 → 设置","群机器人 → 添加机器人 → 自定义机器人","安全设置选择「签名校验」,复制生成的秘钥","完成会给 Webhook 地址,复制","Webhook URL 填上面,秘钥填签名校验密钥"],urlFormat:"https://open.feishu.cn/open-apis/bot/v2/hook/xxx",note:"签名密钥可选,建议启用。频率限制:单机器人 100 次/分钟。"}},wechat:{label:"企业微信机器人",icon:Et,fields:[{key:"webhook_url",label:"Webhook URL",placeholder:"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=...",required:!0}],guide:{steps:["企业微信进入一个内部群 → 右上角 … → 群设置","找到「群机器人」(新版可能叫「消息推送」)","添加 → 选择自定义机器人","完成给 Webhook 地址(含 ?key=),复制填入"],urlFormat:"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=XXX",note:"不需要 secret,URL 里的 key 就是唯一凭证,注意不要泄露。频率限制 20 条/分钟。"}},webhook:{label:"自定义 Webhook",icon:il,fields:[{key:"webhook_url",label:"Webhook URL",placeholder:"https://your-server/notify",required:!0}],guide:{steps:["仅适用于自己有服务器的用户:在你自己的机器上起一个 HTTP 接口收 JSON","系统会 POST 这个 URL,Content-Type: application/json","请求体固定为右侧 JSON 格式,按需解析 message 字段"],urlFormat:'{"message":"告警正文","timestamp":"2026-07-05 12:00:00","source":"xianyu-auto-reply"}',note:"若用 Server酱 / PushPlus 等第三方推送服务,格式不兼容,需写中间脚本转发,或改用对应专用渠道。"}},telegram:{label:"Telegram",icon:Kt,fields:[{key:"bot_token",label:"Bot Token",placeholder:"123456:ABC-DEF...",required:!0},{key:"chat_id",label:"Chat ID",placeholder:"-1001234567890 或你的用户 ID",required:!0}],guide:{steps:["在 Telegram 搜索 @BotFather,发送 /newbot,按提示创建机器人,拿到 Bot Token","把你的 Bot 拉进一个群,或私聊它发一条消息","浏览器访问 https://api.telegram.org/bot<你的Token>/getUpdates",'从返回 JSON 里找 "chat":{"id":xxx},xxx 就是 Chat ID(群是负数,私聊是正数)'],urlFormat:"Bot Token: 123456:ABC-DEF... Chat ID: -1001234567890",note:"群聊需先把 Bot 设为管理员才能发消息。"}},email:{label:"邮件",icon:_a,fields:[{key:"to_email",label:"收件邮箱",placeholder:"receiver@example.com",required:!0}],guide:{steps:["通常先保存页面中的系统 SMTP 配置","邮件渠道只需填写收件邮箱,即可完整继承系统 SMTP","只有确实需要另一套发件服务时,才开启“使用独立 SMTP”并填写整套配置"],note:"继承和独立 SMTP 是互斥模式,不会再混用两套配置中的部分字段。"}}},$a=[{value:"account_offline",label:"掉线通知",description:"账号过期、断线或登录态失效"},{value:"account_recovered",label:"恢复通知",description:"自动恢复成功并重新在线"},{value:"account_disabled",label:"禁用通知",description:"连续失败、账密错误等导致账号停用"},{value:"security_verification",label:"风控验证",description:"滑块、人脸、扫码验证等安全校验"},{value:"delivery_result",label:"交易通知",description:"订单发货、卡密发送等交易结果"},{value:"token_renewal",label:"续期通知",description:"Cookie/token 续期和自动恢复过程"},{value:"system_error",label:"系统错误",description:"后台任务或系统级异常"}],Ln=t=>!t||t.length===0?"全部事件":t.map(l=>{var o;return((o=$a.find(x=>x.value===l))==null?void 0:o.label)||l}).join("、"),On=({isAdmin:t=!1})=>{const[s,l]=r.useState([]),[o,x]=r.useState(!0),[v,k]=r.useState(!1),[A,b]=r.useState(null),[O,j]=r.useState(!1),[V,Y]=r.useState(""),[pe,ce]=r.useState(null),[w,M]=r.useState({}),[de,G]=r.useState(!1),[X,U]=r.useState(!1),[fe,ge]=r.useState(!1),[L,K]=r.useState({name:"",type:"bark",enabled:!0,config:{},event_types:[]}),ae=async()=>{x(!0);try{const m=await Aa();l(m.data||[])}catch(m){console.error("加载通知渠道失败",m)}finally{x(!1)}},Z=async()=>{try{const m=await La();M(Cn(m||{}))}catch(m){console.error("加载 SMTP 配置失败",m)}},me=async()=>{G(!0);try{await Oa({smtp_server:w.smtp_server||"",smtp_port:w.smtp_port||587,smtp_user:w.smtp_user||"",smtp_password:w.smtp_password||"",smtp_from_name:w.smtp_from_name||"",smtp_from_address:w.smtp_from_address||w.smtp_user||"",smtp_use_tls:w.smtp_use_tls!==!1,smtp_use_ssl:w.smtp_use_ssl===!0}),R("success","SMTP 配置已保存")}catch(m){R("error",(m==null?void 0:m.message)||"保存失败")}finally{G(!1)}};r.useEffect(()=>{ae(),t?Z():M({})},[t]);const R=(m,f)=>{ce({type:m,text:f}),window.setTimeout(()=>ce(null),3e3)},E=()=>{b(null),K({name:"",type:"bark",enabled:!0,config:{},event_types:[]}),ge(!1),k(!0)},ee=m=>{b(m);const f=m.type==="email"?Pa({...m.config||{}}):null,W=f?f.use_custom_smtp===!0?ra(f,w):f:{...m.config||{}};K({name:m.name,type:m.type,enabled:m.enabled,config:W,event_types:m.event_types||[]}),ge(!1),k(!0)},T=async()=>{const m=ft[L.type];for(const W of m.fields)if(W.required&&!String(L.config[W.key]||"").trim()){R("error",`请填写 ${W.label}`);return}if(!L.name.trim()){R("error","请填写渠道名称");return}let f=L.config;if(L.type==="email"&&(f=Sn(L.config),f.use_custom_smtp)){const q=[["smtp_server","独立 SMTP 服务器"],["smtp_port","独立 SMTP 端口"],["smtp_user","独立 SMTP 登录邮箱"],["smtp_password","独立 SMTP 密码 / 授权码"],["smtp_from_address","独立 SMTP 发件地址"]].find(([ne])=>!String(f[ne]||"").trim());if(q){R("error",`请填写 ${q[1]}`);return}}j(!0);try{const W={name:L.name.trim(),type:L.type,config:f,event_types:L.event_types,enabled:L.enabled};A?await Gs(A.id,W):await Dr(W),k(!1),await ae(),R("success",A?"已更新":"已创建")}catch(W){console.error("保存失败",W),R("error",(W==null?void 0:W.message)||"保存失败")}finally{j(!1)}},se=async m=>{if(confirm(`确认删除渠道「${m.name}」吗?已绑定该渠道的账号会自动解绑。`))try{await Tr(m.id),await ae(),R("success","已删除")}catch(f){R("error",(f==null?void 0:f.message)||"删除失败")}},ke=async m=>{try{await Gs(m.id,{enabled:!m.enabled}),l(f=>f.map(W=>W.id===m.id?{...W,enabled:!W.enabled}:W))}catch(f){R("error",(f==null?void 0:f.message)||"切换失败")}},ye=async m=>{Y(m.id);try{await qr(m.id),R("success","测试通知已发送,请检查对应渠道")}catch(f){R("error",(f==null?void 0:f.message)||"发送失败")}finally{Y("")}},z=ft[L.type];return e.jsxs("div",{className:"space-y-8 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col md:flex-row justify-between md:items-end gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-4xl font-extrabold text-gray-900 tracking-tight",children:"通知设置"}),e.jsx("p",{className:"text-gray-500 mt-2 font-medium",children:"配置通知渠道,账号异常时主动推送告警"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:ae,className:"px-4 py-2 bg-gray-100 hover:bg-gray-200 rounded-xl font-bold text-gray-700 flex items-center gap-2 transition-colors",children:[e.jsx(Be,{className:"w-4 h-4"}),"刷新"]}),e.jsxs("button",{onClick:E,className:"ios-btn-primary px-5 py-2.5 rounded-xl font-bold flex items-center gap-2",children:[e.jsx(Ye,{className:"w-4 h-4"}),"新建渠道"]})]})]}),e.jsx("div",{className:"ios-card rounded-xl p-5 bg-blue-50/50 border border-blue-100",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(jt,{className:"w-5 h-5 text-brand mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"text-sm text-gray-700 leading-6",children:["配置通知渠道并在「账号管理 → 编辑」里绑定后,以下事件会主动推送到该账号绑定的渠道:",e.jsxs("ul",{className:"mt-2 space-y-1 text-gray-600",children:[e.jsxs("li",{children:["• ",e.jsx("strong",{children:"账号 session 失效"}),":系统正在尝试自动恢复(警告)"]}),e.jsxs("li",{children:["• ",e.jsx("strong",{children:"自动恢复失败"}),":账号已停止,需人工处理(严重)"]}),e.jsxs("li",{children:["• ",e.jsx("strong",{children:"触发风控验证"}),":可能需要扫码完成验证(警告)"]})]})]})]})}),o?e.jsx("div",{className:"flex justify-center py-20",children:e.jsx(Ee,{className:"w-8 h-8 text-brand animate-spin"})}):s.length===0?e.jsxs("div",{className:"ios-card rounded-xl p-12 bg-white text-center",children:[e.jsx(jt,{className:"w-12 h-12 text-gray-300 mx-auto mb-4"}),e.jsx("p",{className:"text-gray-500 font-medium",children:"还没有配置任何通知渠道"}),e.jsx("p",{className:"text-gray-400 text-sm mt-1",children:"点击右上角「新建渠道」开始配置"})]}):e.jsx("div",{className:"space-y-3",children:s.map(m=>{const f=ft[m.type]||ft.webhook,W=f.icon;return e.jsxs("div",{className:"ios-card rounded-xl p-5 bg-white flex items-center gap-4",children:[e.jsx("div",{className:"w-11 h-11 rounded-xl bg-gray-100 flex items-center justify-center flex-shrink-0",children:e.jsx(W,{className:"w-5 h-5 text-gray-600"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-bold text-gray-900 truncate",children:m.name}),e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-gray-100 text-gray-600 font-medium",children:f.label}),!m.enabled&&e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-gray-100 text-gray-400 font-medium",children:"已停用"})]}),e.jsx("div",{className:"text-xs text-gray-500 mt-1 truncate",children:f.fields.map(q=>{var ne;return(ne=m.config)==null?void 0:ne[q.key]}).filter(Boolean).map((q,ne)=>e.jsx("span",{className:"mr-3",children:String(q).length>40?String(q).slice(0,40)+"…":String(q)},ne))}),e.jsxs("div",{className:"text-xs text-gray-400 mt-1 truncate",children:["订阅:",Ln(m.event_types)]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx("button",{onClick:()=>ke(m),className:`px-3 py-1.5 rounded-lg text-xs font-bold transition-colors ${m.enabled?"bg-green-50 text-green-700 hover:bg-green-100":"bg-gray-100 text-gray-500 hover:bg-gray-200"}`,children:m.enabled?"启用中":"已停用"}),e.jsxs("button",{onClick:()=>ye(m),disabled:V===m.id,className:"px-3 py-1.5 rounded-lg text-xs font-bold bg-blue-50 text-brand hover:bg-blue-100 transition-colors flex items-center gap-1 disabled:opacity-50",children:[V===m.id?e.jsx(Ee,{className:"w-3 h-3 animate-spin"}):e.jsx(Kt,{className:"w-3 h-3"}),"测试"]}),e.jsx("button",{onClick:()=>ee(m),className:"w-8 h-8 rounded-lg bg-gray-100 hover:bg-gray-200 flex items-center justify-center text-gray-600 transition-colors",title:"编辑",children:e.jsx(fa,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>se(m),className:"w-8 h-8 rounded-lg bg-red-50 hover:bg-red-100 flex items-center justify-center text-red-500 transition-colors",title:"删除",children:e.jsx(Je,{className:"w-4 h-4"})})]})]},m.id)})}),t&&e.jsxs("section",{className:"ios-card rounded-xl p-6 bg-white space-y-5",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-extrabold text-gray-800",children:"SMTP 邮件配置"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"系统级邮件发送服务,供邮件通知渠道复用"})]}),e.jsx("div",{className:"p-2 rounded-xl bg-blue-50 text-blue-600",children:e.jsx(_a,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"SMTP 服务器"}),e.jsx("input",{type:"text",value:w.smtp_server||"",onChange:m=>M({...w,smtp_server:m.target.value}),placeholder:"smtp.qq.com",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"SMTP 端口"}),e.jsx("input",{type:"number",value:w.smtp_port||587,onChange:m=>M({...w,smtp_port:parseInt(m.target.value)||587}),placeholder:"587",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"发件邮箱"}),e.jsx("input",{type:"email",value:w.smtp_user||"",onChange:m=>M({...w,smtp_user:m.target.value}),placeholder:"your-email@qq.com",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"邮箱密码 / 授权码"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:X?"text":"password",value:w.smtp_password||"",onChange:m=>M({...w,smtp_password:m.target.value}),placeholder:"输入密码或授权码",className:"w-full ios-input px-4 py-3 pr-12 rounded-xl text-sm"}),e.jsx("button",{type:"button",onClick:()=>U(!X),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600 transition-colors",children:X?e.jsx(dt,{className:"w-4 h-4"}):e.jsx(st,{className:"w-4 h-4"})})]}),e.jsx("p",{className:"text-xs text-gray-500",children:"QQ 邮箱需使用授权码(QQ 邮箱设置 → 账号 → 开启 SMTP → 生成授权码)"})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"发件人显示名(可选)"}),e.jsx("input",{type:"text",value:w.smtp_from_name||"",onChange:m=>M({...w,smtp_from_name:m.target.value}),placeholder:"闲鱼自动回复系统",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"发件邮箱地址"}),e.jsx("input",{type:"email",value:w.smtp_from_address||w.smtp_user||"",onChange:m=>M({...w,smtp_from_address:m.target.value}),placeholder:"your-email@qq.com",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("label",{className:"flex items-center gap-3 rounded-xl border border-gray-200 p-4 text-sm font-semibold text-gray-700",children:[e.jsx("input",{type:"checkbox",checked:w.smtp_use_tls!==!1,onChange:m=>M({...w,smtp_use_tls:m.target.checked,smtp_use_ssl:m.target.checked?!1:w.smtp_use_ssl})}),"STARTTLS(常用于 587 端口)"]}),e.jsxs("label",{className:"flex items-center gap-3 rounded-xl border border-gray-200 p-4 text-sm font-semibold text-gray-700",children:[e.jsx("input",{type:"checkbox",checked:w.smtp_use_ssl===!0,onChange:m=>M({...w,smtp_use_ssl:m.target.checked,smtp_use_tls:m.target.checked?!1:w.smtp_use_tls})}),"SSL/TLS 直连(常用于 465 端口)"]})]}),e.jsxs("button",{onClick:me,disabled:de,className:"ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[de?e.jsx(Ee,{className:"w-4 h-4 animate-spin"}):e.jsx(Ge,{className:"w-4 h-4"}),de?"保存中...":"保存 SMTP 配置"]})]}),v&&Me.createPortal(e.jsx("div",{className:"modal-overlay",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"36rem"},children:[e.jsxs("div",{className:"px-6 py-5 border-b border-gray-100 flex items-center justify-between",children:[e.jsx("h3",{className:"text-xl font-extrabold text-gray-900",children:A?"编辑通知渠道":"新建通知渠道"}),e.jsx("button",{onClick:()=>k(!1),className:"w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center",children:e.jsx(Te,{className:"w-5 h-5 text-gray-600"})})]}),e.jsxs("div",{className:"px-6 py-5 space-y-5 overflow-y-auto flex-1 min-h-0",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"渠道名称"}),e.jsx("input",{type:"text",value:L.name,onChange:m=>K({...L,name:m.target.value}),placeholder:"例如:我的 Bark",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"渠道类型"}),e.jsx("div",{className:"grid grid-cols-3 sm:grid-cols-4 gap-2",children:Object.keys(ft).map(m=>{const f=ft[m],W=f.icon,q=L.type===m;return e.jsxs("button",{type:"button",onClick:()=>K({...L,type:m,config:{}}),className:`p-3 rounded-xl border-2 flex flex-col items-center gap-1.5 transition-all ${q?"border-brand bg-blue-50":"border-gray-100 hover:border-gray-300"}`,children:[e.jsx(W,{className:`w-5 h-5 ${q?"text-brand":"text-gray-500"}`}),e.jsx("span",{className:`text-xs font-bold ${q?"text-brand":"text-gray-600"}`,children:f.label})]},m)})})]}),e.jsxs("div",{className:"rounded-xl bg-amber-50 border border-amber-200 p-4 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(jt,{className:"w-4 h-4 text-amber-600"}),e.jsxs("span",{className:"text-sm font-bold text-amber-800",children:["如何获取 ",z.label," 配置?"]})]}),e.jsx("ol",{className:"space-y-1.5 text-xs text-amber-900/90 leading-5 list-decimal pl-5",children:z.guide.steps.map((m,f)=>e.jsx("li",{children:m},f))}),z.guide.urlFormat&&e.jsxs("div",{className:"text-xs text-amber-900/90",children:[e.jsx("span",{className:"font-bold",children:"格式示例:"}),e.jsx("code",{className:"mt-1 block bg-amber-100/70 px-2.5 py-1.5 rounded-lg break-all font-mono text-[11px]",children:z.guide.urlFormat})]}),z.guide.note&&e.jsxs("p",{className:"text-xs text-amber-800/80 leading-5 pt-1",children:["💡 ",z.guide.note]})]}),e.jsx("div",{className:"space-y-3",children:z.fields.map(m=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-800",children:[m.label,m.required&&e.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),e.jsx("input",{type:m.type==="password"?"password":m.type==="number"?"number":"text",value:String(L.config[m.key]||""),onChange:f=>K({...L,config:{...L.config,[m.key]:f.target.value}}),placeholder:m.placeholder,className:"w-full ios-input px-4 py-3 rounded-xl text-sm"}),m.help&&e.jsx("p",{className:"text-xs text-gray-500",children:m.help})]},m.key))}),L.type==="email"&&e.jsxs("div",{className:"overflow-hidden rounded-2xl border border-blue-100 bg-blue-50/40",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 p-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-extrabold text-gray-900",children:"SMTP 来源"}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-gray-500",children:L.config.use_custom_smtp===!0?"当前渠道使用一套完整、独立的发件配置。":"当前渠道完整继承系统 SMTP,只单独设置收件邮箱。"})]}),e.jsx("button",{type:"button",onClick:()=>{const m=L.config.use_custom_smtp===!0;K({...L,config:m?{...L.config,use_custom_smtp:!1}:ra(L.config,w)})},className:`relative h-7 w-12 shrink-0 rounded-full transition-colors ${L.config.use_custom_smtp===!0?"bg-brand":"bg-gray-300"}`,"aria-label":"使用独立 SMTP",children:e.jsx("span",{className:`absolute left-1 top-1 h-5 w-5 rounded-full bg-white shadow-sm transition-transform ${L.config.use_custom_smtp===!0?"translate-x-5":""}`})})]}),L.config.use_custom_smtp===!0&&e.jsxs("div",{className:"space-y-4 border-t border-blue-100 bg-white/80 p-4",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-800",children:["SMTP 服务器 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",value:String(L.config.smtp_server||""),onChange:m=>K({...L,config:{...L.config,smtp_server:m.target.value}}),placeholder:"smtp.qq.com",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-800",children:["SMTP 端口 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"number",value:String(L.config.smtp_port||587),onChange:m=>K({...L,config:{...L.config,smtp_port:m.target.value}}),placeholder:"587",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-800",children:["登录邮箱 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"email",value:String(L.config.smtp_user||""),onChange:m=>K({...L,config:{...L.config,smtp_user:m.target.value}}),placeholder:"your-email@qq.com",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-800",children:["密码 / 授权码 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:fe?"text":"password",value:String(L.config.smtp_password||""),onChange:m=>K({...L,config:{...L.config,smtp_password:m.target.value}}),placeholder:"输入密码或授权码",className:"w-full ios-input px-4 py-3 pr-12 rounded-xl text-sm"}),e.jsx("button",{type:"button",onClick:()=>ge(m=>!m),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",children:fe?e.jsx(dt,{className:"w-4 h-4"}):e.jsx(st,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"发件人显示名(可选)"}),e.jsx("input",{type:"text",value:String(L.config.smtp_from_name||""),onChange:m=>K({...L,config:{...L.config,smtp_from_name:m.target.value}}),placeholder:"闲鱼自动回复系统",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-800",children:["发件邮箱地址 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"email",value:String(L.config.smtp_from_address||""),onChange:m=>K({...L,config:{...L.config,smtp_from_address:m.target.value}}),placeholder:"your-email@qq.com",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[e.jsxs("label",{className:"flex items-center gap-3 rounded-xl border border-gray-200 p-3 text-xs font-bold text-gray-700",children:[e.jsx("input",{type:"checkbox",checked:L.config.smtp_use_tls!==!1,onChange:m=>K({...L,config:{...L.config,smtp_use_tls:m.target.checked,smtp_use_ssl:m.target.checked?!1:L.config.smtp_use_ssl}})}),"STARTTLS(常用于 587)"]}),e.jsxs("label",{className:"flex items-center gap-3 rounded-xl border border-gray-200 p-3 text-xs font-bold text-gray-700",children:[e.jsx("input",{type:"checkbox",checked:L.config.smtp_use_ssl===!0,onChange:m=>K({...L,config:{...L.config,smtp_use_ssl:m.target.checked,smtp_use_tls:m.target.checked?!1:L.config.smtp_use_tls}})}),"SSL/TLS 直连(常用于 465)"]})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-800",children:"通知内容"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"不选择表示接收全部通知;选择后仅接收勾选类型。"})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:$a.map(m=>{const f=L.event_types.includes(m.value);return e.jsxs("button",{type:"button",onClick:()=>{const W=f?L.event_types.filter(q=>q!==m.value):[...L.event_types,m.value];K({...L,event_types:W})},className:`text-left rounded-xl border px-3 py-2.5 transition-colors ${f?"border-brand bg-blue-50":"border-gray-100 hover:border-gray-300"}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`w-4 h-4 rounded border flex items-center justify-center ${f?"bg-brand border-brand":"border-gray-300"}`,children:f&&e.jsx(Qe,{className:"w-3 h-3 text-white"})}),e.jsx("span",{className:`text-sm font-bold ${f?"text-brand":"text-gray-800"}`,children:m.label})]}),e.jsx("p",{className:"text-xs text-gray-500 mt-1 pl-6 leading-5",children:m.description})]},m.value)})})]}),e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[e.jsx("button",{type:"button",onClick:()=>K({...L,enabled:!L.enabled}),className:`relative w-11 h-6 rounded-full transition-colors ${L.enabled?"bg-brand":"bg-gray-300"}`,children:e.jsx("span",{className:`absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform ${L.enabled?"translate-x-5":""}`})}),e.jsx("span",{className:"text-sm font-bold text-gray-800",children:"启用此渠道"})]})]}),e.jsxs("div",{className:"px-6 py-4 border-t border-gray-100 flex items-center justify-end gap-3",children:[e.jsx("button",{onClick:()=>k(!1),className:"px-5 py-2.5 rounded-xl bg-gray-100 hover:bg-gray-200 font-bold text-gray-700 transition-colors",children:"取消"}),e.jsxs("button",{onClick:T,disabled:O,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[O?e.jsx(Ee,{className:"w-4 h-4 animate-spin"}):e.jsx(Qe,{className:"w-4 h-4"}),O?"保存中...":"保存"]})]})]})}),document.body),pe&&e.jsxs("div",{className:`fixed bottom-8 left-1/2 -translate-x-1/2 z-[10000] px-5 py-3 rounded-xl shadow-lg font-bold text-sm flex items-center gap-2 animate-fade-in text-white ${pe.type==="success"?"bg-success-500":"bg-danger-500"}`,children:[pe.type==="success"?e.jsx(Qe,{className:"w-4 h-4"}):e.jsx(Te,{className:"w-4 h-4"}),pe.text]})]})},Ea=[["尊嘟假嘟","https://img.alicdn.com/imgextra/i2/O1CN01hWzOgD1KcmFEIaGwE_!!6000000001185-2-tps-64-64.png_110x10000.jpg_.webp"],["鸡哔你","https://img.alicdn.com/imgextra/i1/O1CN01P9TVJl1JCqCZcQIdW_!!6000000000993-2-tps-64-64.png_110x10000.jpg_.webp"],["谁懂啊","https://img.alicdn.com/imgextra/i1/O1CN01r9qUnx1g3tcrtSmcs_!!6000000004087-2-tps-64-64.png_110x10000.jpg_.webp"],["吗喽","https://img.alicdn.com/imgextra/i4/O1CN01dTynZh1LnbIYTHI1D_!!6000000001344-2-tps-64-64.png_110x10000.jpg_.webp"],["功德+1","https://img.alicdn.com/imgextra/i1/O1CN01l1G5pS1IVn37pfQJi_!!6000000000899-2-tps-64-64.png_110x10000.jpg_.webp"],["city不city啊","https://img.alicdn.com/imgextra/i2/O1CN01zRjPTR29lWHqabmDA_!!6000000008108-2-tps-64-64.png_110x10000.jpg_.webp"],["激推","https://img.alicdn.com/imgextra/i3/O1CN01ADTJ6u1khypfxbfnQ_!!6000000004716-2-tps-64-64.png_110x10000.jpg_.webp"],["微笑","https://img.alicdn.com/imgextra/i1/O1CN017b61R51wRk2lVV7vx_!!6000000006305-2-tps-980-980.png_110x10000.jpg_.webp"],["龇牙","https://img.alicdn.com/imgextra/i2/O1CN01nmOh4S22Yxz8IdEVf_!!6000000007133-2-tps-980-980.png_110x10000.jpg_.webp"],["流泪","https://img.alicdn.com/imgextra/i2/O1CN01Ec1EaL1zqQETcM2dX_!!6000000006765-2-tps-980-980.png_110x10000.jpg_.webp"],["尴尬","https://img.alicdn.com/imgextra/i2/O1CN01UrWH7a1ZVBrgRYXlc_!!6000000003199-2-tps-980-980.png_110x10000.jpg_.webp"],["撇嘴","https://img.alicdn.com/imgextra/i2/O1CN01Sr7o2b1lUWg5KfOD8_!!6000000004822-2-tps-980-980.png_110x10000.jpg_.webp"],["破涕为笑","https://img.alicdn.com/imgextra/i4/O1CN01pPetah1gkwndfn7Fs_!!6000000004181-2-tps-980-980.png_110x10000.jpg_.webp"],["捂脸哭","https://img.alicdn.com/imgextra/i2/O1CN0170KgpE1dE1TuQgd66_!!6000000003703-2-tps-980-980.png_110x10000.jpg_.webp"],["害羞","https://img.alicdn.com/imgextra/i3/O1CN01ZoB0Lb1ps7XpqP8PQ_!!6000000005415-2-tps-980-980.png_110x10000.jpg_.webp"],["感动","https://img.alicdn.com/imgextra/i2/O1CN01wqD4ly29yndR3Qp3A_!!6000000008137-2-tps-980-980.png_110x10000.jpg_.webp"],["滴泪","https://img.alicdn.com/imgextra/i1/O1CN01MpkJ3L1oUTTqfryOn_!!6000000005228-2-tps-980-980.png_110x10000.jpg_.webp"],["暗中观察","https://img.alicdn.com/imgextra/i1/O1CN010LO9yj272W07GlLls_!!6000000007739-2-tps-980-980.png_110x10000.jpg_.webp"],["偷笑","https://img.alicdn.com/imgextra/i4/O1CN01vJtO031g818IuYO7x_!!6000000004096-2-tps-980-980.png_110x10000.jpg_.webp"],["ok","https://img.alicdn.com/imgextra/i3/O1CN01QRkqDF25tz0WcANje_!!6000000007585-2-tps-980-980.png_110x10000.jpg_.webp"],["送花","https://img.alicdn.com/imgextra/i2/O1CN01PpzBNX1JNpeJBWnvr_!!6000000001017-2-tps-980-980.png_110x10000.jpg_.webp"],["大哭","https://img.alicdn.com/imgextra/i4/O1CN014TiaNb1ViEgNvRrTB_!!6000000002686-2-tps-980-980.png_110x10000.jpg_.webp"],["色","https://img.alicdn.com/imgextra/i2/O1CN01840t1B1JaCLGvHnBK_!!6000000001044-2-tps-980-980.png_110x10000.jpg_.webp"],["惊慌","https://img.alicdn.com/imgextra/i1/O1CN01mnqO7G1LAfUnfAN2U_!!6000000001259-2-tps-980-980.png_110x10000.jpg_.webp"],["惊讶","https://img.alicdn.com/imgextra/i3/O1CN0127IeyS1Kw0p0P4jzI_!!6000000001227-2-tps-980-980.png_110x10000.jpg_.webp"],["得意","https://img.alicdn.com/imgextra/i4/O1CN018QUnFv1WpOUES9POZ_!!6000000002837-2-tps-980-980.png_110x10000.jpg_.webp"],["睡","https://img.alicdn.com/imgextra/i2/O1CN01RprGZl1lqVgnEJLCx_!!6000000004870-2-tps-980-980.png_110x10000.jpg_.webp"],["不好意思","https://img.alicdn.com/imgextra/i3/O1CN01rMJJgn1SUXzuVpUhO_!!6000000002250-2-tps-980-980.png_110x10000.jpg_.webp"],["托腮","https://img.alicdn.com/imgextra/i1/O1CN01w3reBU1d3wlgOBtyZ_!!6000000003681-2-tps-980-980.png_110x10000.jpg_.webp"],["发怒","https://img.alicdn.com/imgextra/i2/O1CN013Wzy8d2A8PxGJZPpT_!!6000000008158-2-tps-980-980.png_110x10000.jpg_.webp"],["难过","https://img.alicdn.com/imgextra/i2/O1CN01zcwaSh1G9gZCFuFal_!!6000000000580-2-tps-980-980.png_110x10000.jpg_.webp"],["调皮","https://img.alicdn.com/imgextra/i3/O1CN01Zd1YHi1TI0lwpBe8c_!!6000000002358-2-tps-980-980.png_110x10000.jpg_.webp"],["愉快","https://img.alicdn.com/imgextra/i2/O1CN0145wDk21SWpyjTvsvA_!!6000000002255-2-tps-980-980.png_110x10000.jpg_.webp"],["白眼","https://img.alicdn.com/imgextra/i4/O1CN01nexGth1hwEAT1SHO2_!!6000000004341-2-tps-980-980.png_110x10000.jpg_.webp"],["拒绝","https://img.alicdn.com/imgextra/i2/O1CN01nqusqS1uHXzoUcpXr_!!6000000006012-2-tps-980-980.png_110x10000.jpg_.webp"],["期待","https://img.alicdn.com/imgextra/i3/O1CN01M44QY11Oh8Q5PdMIx_!!6000000001736-2-tps-980-980.png_110x10000.jpg_.webp"],["困","https://img.alicdn.com/imgextra/i4/O1CN01J4hFFz1Y9pmNdBq76_!!6000000003017-2-tps-980-980.png_110x10000.jpg_.webp"],["流汗","https://img.alicdn.com/imgextra/i4/O1CN01BU3NZ21gdcSjkqnST_!!6000000004165-2-tps-980-980.png_110x10000.jpg_.webp"],["憨笑","https://img.alicdn.com/imgextra/i2/O1CN01Pee9Ql1SJ661eH9By_!!6000000002225-2-tps-980-980.png_110x10000.jpg_.webp"],["耶","https://img.alicdn.com/imgextra/i2/O1CN01pFicsL1ipBhIqzcgs_!!6000000004461-2-tps-980-980.png_110x10000.jpg_.webp"],["奋斗","https://img.alicdn.com/imgextra/i3/O1CN01ZhQ4AV25xBmTK3CnF_!!6000000007592-2-tps-980-980.png_110x10000.jpg_.webp"],["咒骂","https://img.alicdn.com/imgextra/i3/O1CN01r1Zh9927QKb4pnf7k_!!6000000007791-2-tps-980-980.png_110x10000.jpg_.webp"],["疑问","https://img.alicdn.com/imgextra/i4/O1CN01UZqbzt29MmlNctCQS_!!6000000008054-2-tps-980-980.png_110x10000.jpg_.webp"],["嘘","https://img.alicdn.com/imgextra/i1/O1CN01qBlYkM1ojaYF75On5_!!6000000005261-2-tps-980-980.png_110x10000.jpg_.webp"],["晕","https://img.alicdn.com/imgextra/i2/O1CN014zhM2h1wPuSUFoMwV_!!6000000006301-2-tps-980-980.png_110x10000.jpg_.webp"],["开心到模糊","https://img.alicdn.com/imgextra/i1/O1CN01T1Dy271j6akZWo7Vr_!!6000000004499-2-tps-980-980.png_110x10000.jpg_.webp"],["衰","https://img.alicdn.com/imgextra/i1/O1CN01aOXsNr1LmgMvtyzOO_!!6000000001342-2-tps-980-980.png_110x10000.jpg_.webp"],["委屈","https://img.alicdn.com/imgextra/i2/O1CN013J0bMk1QNYih3UFTk_!!6000000001964-2-tps-980-980.png_110x10000.jpg_.webp"],["再见","https://img.alicdn.com/imgextra/i2/O1CN01IHKsQx1UdpFgeTHcA_!!6000000002541-2-tps-980-980.png_110x10000.jpg_.webp"],["鼓掌","https://img.alicdn.com/imgextra/i4/O1CN01DHxB5s1G1RRBxekIu_!!6000000000562-2-tps-980-980.png_110x10000.jpg_.webp"],["吐","https://img.alicdn.com/imgextra/i1/O1CN01xyVxH21LNUaMgW4hh_!!6000000001287-2-tps-980-980.png_110x10000.jpg_.webp"],["坏笑","https://img.alicdn.com/imgextra/i1/O1CN01zV7opv1bIU6iI8OhM_!!6000000003442-2-tps-980-980.png_110x10000.jpg_.webp"],["抠鼻","https://img.alicdn.com/imgextra/i1/O1CN01QOanju1sNqCrtYstu_!!6000000005755-2-tps-980-980.png_110x10000.jpg_.webp"],["叹气","https://img.alicdn.com/imgextra/i3/O1CN01RElx7R1QD1c8ZN07f_!!6000000001941-2-tps-980-980.png_110x10000.jpg_.webp"],["无聊","https://img.alicdn.com/imgextra/i2/O1CN01d91LnZ1UJDQjKCouC_!!6000000002496-2-tps-980-980.png_110x10000.jpg_.webp"],["思考","https://img.alicdn.com/imgextra/i2/O1CN01wQjg2f1tO84ZWitn9_!!6000000005891-2-tps-980-980.png_110x10000.jpg_.webp"],["呆","https://img.alicdn.com/imgextra/i1/O1CN01GLqBWC1DGbhqmpD2L_!!6000000000189-2-tps-980-980.png_110x10000.jpg_.webp"],["哇哦","https://img.alicdn.com/imgextra/i2/O1CN01MtLpS21qRO2bnAA5k_!!6000000005492-2-tps-980-980.png_110x10000.jpg_.webp"],["飞吻","https://img.alicdn.com/imgextra/i4/O1CN01q1WpFE25ljsNKjvHX_!!6000000007567-2-tps-980-980.png_110x10000.jpg_.webp"],["好喜欢","https://img.alicdn.com/imgextra/i2/O1CN01mD4iQM1O57XyQ5SHD_!!6000000001653-2-tps-980-980.png_110x10000.jpg_.webp"],["拜托","https://img.alicdn.com/imgextra/i4/O1CN01SQgrTH1dzCH3pIyRN_!!6000000003806-2-tps-980-980.png_110x10000.jpg_.webp"],["真棒","https://img.alicdn.com/imgextra/i2/O1CN017fcAmd1SCgYCj9Upk_!!6000000002211-2-tps-980-980.png_110x10000.jpg_.webp"],["流鼻血","https://img.alicdn.com/imgextra/i3/O1CN0139JscY1rC6RS9GR4j_!!6000000005594-2-tps-980-980.png_110x10000.jpg_.webp"],["费解","https://img.alicdn.com/imgextra/i1/O1CN01FqAVvR1tyJMPj13ie_!!6000000005970-2-tps-980-980.png_110x10000.jpg_.webp"],["秃头","https://img.alicdn.com/imgextra/i4/O1CN01ZF4bV11thMhqm2Z1h_!!6000000005933-2-tps-980-980.png_110x10000.jpg_.webp"],["嘿哈","https://img.alicdn.com/imgextra/i4/O1CN01ObcOw61FOVlvQg7Mw_!!6000000000477-2-tps-980-980.png_110x10000.jpg_.webp"],["吃土","https://img.alicdn.com/imgextra/i3/O1CN01Z6nJ1b1ZYr22YseHN_!!6000000003207-2-tps-980-980.png_110x10000.jpg_.webp"],["机智","https://img.alicdn.com/imgextra/i1/O1CN01rfKY351zDUZJlBiir_!!6000000006680-2-tps-980-980.png_110x10000.jpg_.webp"],["举杯","https://img.alicdn.com/imgextra/i4/O1CN01R2tn4F1mn8NuEIE8J_!!6000000004998-2-tps-980-980.png_110x10000.jpg_.webp"],["握手","https://img.alicdn.com/imgextra/i4/O1CN01NDcA251JDkvuFhSDb_!!6000000000995-2-tps-980-980.png_110x10000.jpg_.webp"],["挥手","https://img.alicdn.com/imgextra/i4/O1CN01iVN0ht1TmEuSwauGt_!!6000000002424-2-tps-980-980.png_110x10000.jpg_.webp"],["yeah","https://img.alicdn.com/imgextra/i3/O1CN01opt7hh27Wk8omjR4t_!!6000000007805-2-tps-980-980.png_110x10000.jpg_.webp"],["666","https://img.alicdn.com/imgextra/i3/O1CN01YRWDPF1OjQOpXeuTC_!!6000000001741-2-tps-980-980.png_110x10000.jpg_.webp"],["棒","https://img.alicdn.com/imgextra/i3/O1CN01agprvs1HU7rPRxOnB_!!6000000000760-2-tps-980-980.png_110x10000.jpg_.webp"],["爱你","https://img.alicdn.com/imgextra/i1/O1CN01SzxgcH1GSSo6Lwmwk_!!6000000000621-2-tps-980-980.png_110x10000.jpg_.webp"],["比心","https://img.alicdn.com/imgextra/i1/O1CN01YHZ39t1DeQIeb0TWQ_!!6000000000241-2-tps-980-980.png_110x10000.jpg_.webp"],["感谢","https://img.alicdn.com/imgextra/i3/O1CN01ywacF81baLYNeyK1n_!!6000000003481-2-tps-980-980.png_110x10000.jpg_.webp"],["拍手","https://img.alicdn.com/imgextra/i4/O1CN01wbj4wv1K7ArD9AU44_!!6000000001116-2-tps-980-980.png_110x10000.jpg_.webp"],["拉钩","https://img.alicdn.com/imgextra/i1/O1CN01dePkKH1HOd6ivAcu8_!!6000000000748-2-tps-980-980.png_110x10000.jpg_.webp"],["没钱","https://img.alicdn.com/imgextra/i3/O1CN01qhxGjp1zD2AfqmWx5_!!6000000006679-2-tps-980-980.png_110x10000.jpg_.webp"],["小刀","https://img.alicdn.com/imgextra/i3/O1CN01tFVx5Y1T2thPjhR6b_!!6000000002325-2-tps-980-980.png_110x10000.jpg_.webp"],["不刀","https://img.alicdn.com/imgextra/i4/O1CN01zTxff61clcvOcTS3n_!!6000000003641-2-tps-980-980.png_110x10000.jpg_.webp"],["同出","https://img.alicdn.com/imgextra/i3/O1CN01URKas6249R8ozS98O_!!6000000007348-2-tps-980-980.png_110x10000.jpg_.webp"],["递钱","https://img.alicdn.com/imgextra/i4/O1CN01PzhgV51FLlOaZHZ6n_!!6000000000471-2-tps-980-980.png_110x10000.jpg_.webp"],["数钱","https://img.alicdn.com/imgextra/i3/O1CN01CzXXvp23khkljToQH_!!6000000007294-2-tps-980-980.png_110x10000.jpg_.webp"],["打call","https://img.alicdn.com/imgextra/i1/O1CN01X7VUVm1il48IYv8Qw_!!6000000004452-2-tps-980-980.png_110x10000.jpg_.webp"],["号外","https://img.alicdn.com/imgextra/i2/O1CN01vg6xSM1Vxo9EKyfjR_!!6000000002720-2-tps-980-980.png_110x10000.jpg_.webp"],["包邮","https://img.alicdn.com/imgextra/i3/O1CN01yVS7ys24jA22oVZ2T_!!6000000007426-2-tps-980-980.png_110x10000.jpg_.webp"],["求赞","https://img.alicdn.com/imgextra/i1/O1CN01Xwqi5A1giCQMRcX6N_!!6000000004175-2-tps-980-980.png_110x10000.jpg_.webp"],["非主流","https://img.alicdn.com/imgextra/i1/O1CN013wyI1j1hlEfDUoATI_!!6000000004317-2-tps-980-980.png_110x10000.jpg_.webp"],["吃瓜","https://img.alicdn.com/imgextra/i1/O1CN01LLOFsh1UUCw0deZba_!!6000000002520-2-tps-980-980.png_110x10000.jpg_.webp"],["种草","https://img.alicdn.com/imgextra/i2/O1CN01ooeRC81hA8a4x9S3q_!!6000000004236-2-tps-980-980.png_110x10000.jpg_.webp"],["佛系","https://img.alicdn.com/imgextra/i4/O1CN01BYXEe321GMHMZ9w66_!!6000000006957-2-tps-980-980.png_110x10000.jpg_.webp"],["超便宜","https://img.alicdn.com/imgextra/i4/O1CN01mqgSZi1Er4rOIDiP7_!!6000000000404-2-tps-980-980.png_110x10000.jpg_.webp"],["拥抱","https://img.alicdn.com/imgextra/i1/O1CN01yuGD9c1hJkttfKHAm_!!6000000004257-2-tps-980-980.png_110x10000.jpg_.webp"],["摊手","https://img.alicdn.com/imgextra/i2/O1CN014AiIqE1o9repE6STR_!!6000000005183-2-tps-980-980.png_110x10000.jpg_.webp"],["举手","https://img.alicdn.com/imgextra/i1/O1CN01xizuHZ1WPkJCogbuj_!!6000000002781-2-tps-980-980.png_110x10000.jpg_.webp"],["蹲","https://img.alicdn.com/imgextra/i3/O1CN01Midjjn1FrMj2CWer6_!!6000000000540-2-tps-980-980.png_110x10000.jpg_.webp"],["跪了","https://img.alicdn.com/imgextra/i3/O1CN01F2y52j24E16L6RIjF_!!6000000007358-2-tps-980-980.png_110x10000.jpg_.webp"],["拜","https://img.alicdn.com/imgextra/i4/O1CN01Jldd1G1oXDrEHH2qr_!!6000000005234-2-tps-980-980.png_110x10000.jpg_.webp"],["排","https://img.alicdn.com/imgextra/i3/O1CN01uSUmYD1jD0IJf0UVU_!!6000000004513-2-tps-980-980.png_110x10000.jpg_.webp"],["旺财","https://img.alicdn.com/imgextra/i3/O1CN01A25Mv01DKjGseAmuP_!!6000000000198-2-tps-980-980.png_110x10000.jpg_.webp"],["招财猫","https://img.alicdn.com/imgextra/i3/O1CN01WmJ7Sr20EhDyp86Bd_!!6000000006818-2-tps-980-980.png_110x10000.jpg_.webp"],["酸了","https://img.alicdn.com/imgextra/i3/O1CN01UFgjn61JJi5Iqxdk7_!!6000000001008-2-tps-980-980.png_110x10000.jpg_.webp"],["鸭鸭","https://img.alicdn.com/imgextra/i3/O1CN01pHSCSQ1deaS8WDiqG_!!6000000003761-2-tps-980-980.png_110x10000.jpg_.webp"],["方了","https://img.alicdn.com/imgextra/i3/O1CN01br7g711whlu8xOPUt_!!6000000006340-2-tps-980-980.png_110x10000.jpg_.webp"],["白菜","https://img.alicdn.com/imgextra/i1/O1CN01KABFLt24WKwXjVp08_!!6000000007398-2-tps-980-980.png_110x10000.jpg_.webp"],["桃子","https://img.alicdn.com/imgextra/i1/O1CN01CQhhPH1vJfRjDGBv5_!!6000000006152-2-tps-980-980.png_110x10000.jpg_.webp"],["打包","https://img.alicdn.com/imgextra/i3/O1CN01oYOkUI1VT7c0ivZHV_!!6000000002653-2-tps-980-980.png_110x10000.jpg_.webp"],["沙发","https://img.alicdn.com/imgextra/i4/O1CN018qUFaE1DGbhqpMIit_!!6000000000189-2-tps-980-980.png_110x10000.jpg_.webp"],["南","https://img.alicdn.com/imgextra/i1/O1CN01ZSA6wg1PEZKf4h99R_!!6000000001809-2-tps-980-980.png_110x10000.jpg_.webp"],["盯","https://img.alicdn.com/imgextra/i4/O1CN01OWB1Gx1s01bzBhHN6_!!6000000005703-2-tps-980-980.png_110x10000.jpg_.webp"],["hot","https://img.alicdn.com/imgextra/i4/O1CN01DDD9uA22cAl7VDH7d_!!6000000007140-2-tps-980-980.png_110x10000.jpg_.webp"],["new","https://img.alicdn.com/imgextra/i3/O1CN01rRJXJo1qwzN4YnOHX_!!6000000005561-2-tps-980-980.png_110x10000.jpg_.webp"],["cool","https://img.alicdn.com/imgextra/i4/O1CN013bUubF2855qb2Qt5l_!!6000000007880-2-tps-980-980.png_110x10000.jpg_.webp"],["1","https://img.alicdn.com/imgextra/i1/O1CN01U8XG5y1Ie22frQHCQ_!!6000000000917-2-tps-980-980.png_110x10000.jpg_.webp"],["可","https://img.alicdn.com/imgextra/i2/O1CN01SMjtPG1iJaN17p94N_!!6000000004392-2-tps-980-980.png_110x10000.jpg_.webp"],["搬砖","https://img.alicdn.com/imgextra/i1/O1CN01GbqW6G1LOrm0Gllcb_!!6000000001290-2-tps-980-980.png_110x10000.jpg_.webp"],["菜狗","https://img.alicdn.com/imgextra/i2/O1CN01VtN0t91USNLmvfmol_!!6000000002516-2-tps-980-980.png_110x10000.jpg_.webp"],["开心面具","https://img.alicdn.com/imgextra/i3/O1CN017elkpk22EoYlBPKd3_!!6000000007089-2-tps-980-980.png_110x10000.jpg_.webp"],["快递","https://img.alicdn.com/imgextra/i2/O1CN01AmUZXk1d3wle5O8IJ_!!6000000003681-2-tps-980-980.png_110x10000.jpg_.webp"],["裂开","https://img.alicdn.com/imgextra/i1/O1CN01BihwvO1a5N9bFt0LU_!!6000000003278-2-tps-980-980.png_110x10000.jpg_.webp"],["啤酒","https://img.alicdn.com/imgextra/i4/O1CN01jDkgEj1WvLdXUVBDx_!!6000000002850-2-tps-980-980.png_110x10000.jpg_.webp"],["瑞思拜","https://img.alicdn.com/imgextra/i4/O1CN011gR0Um1K3VgpYjPOi_!!6000000001108-2-tps-980-980.png_110x10000.jpg_.webp"],["小丑","https://img.alicdn.com/imgextra/i3/O1CN01jMikhO1NJUM15XKTf_!!6000000001549-2-tps-980-980.png_110x10000.jpg_.webp"],["爱心","https://img.alicdn.com/imgextra/i1/O1CN015RVSWf23s25eETJqO_!!6000000007310-2-tps-980-980.png_110x10000.jpg_.webp"]],In=t=>t,An=new Map(Ea.map(([t,s])=>[t,s])),na=t=>t.split(/(\[[^\]]+\])/g).map((s,l)=>{const o=s.startsWith("[")?An.get(s.slice(1,-1)):void 0;return o?e.jsx("img",{src:o,alt:s,title:s,className:"mx-0.5 inline-block h-7 w-7 align-middle"},l):e.jsx(xa.Fragment,{children:s},l)}),ia="ydisks.chat.account.v1",Rn=t=>{if(!t)return"";const s=new Date(t<1e10?t*1e3:t),l=new Date;return s.toDateString()===l.toDateString()?s.toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit",hour12:!1}):s.toLocaleDateString("zh-CN",{month:"2-digit",day:"2-digit"})},oa=t=>new Date(t<1e10?t*1e3:t).toLocaleString("zh-CN",{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hour12:!1}),Pn=()=>{const[t,s]=r.useState([]),[l,o]=r.useState(""),[x,v]=r.useState({}),[k,A]=r.useState(""),[b,O]=r.useState([]),[j,V]=r.useState(""),[Y,pe]=r.useState(!1),[ce,w]=r.useState(""),[M,de]=r.useState(!0),[G,X]=r.useState(!1),[U,fe]=r.useState(!1),[ge,L]=r.useState(!1),[K,ae]=r.useState(),[Z,me]=r.useState({}),[R,E]=r.useState({}),[ee,T]=r.useState(!1),[se,ke]=r.useState(!1),[ye,z]=r.useState(!1),[m,f]=r.useState(""),[W,q]=r.useState("connecting"),ne=r.useRef(""),be=r.useRef(""),ve=r.useRef(null),De=r.useRef({accountID:"",chatID:""}),Ne=r.useRef(!0),c=r.useRef(!1),S=r.useRef(null),Q=r.useRef(new Set);r.useEffect(()=>{ne.current=l},[l]),r.useEffect(()=>{be.current=k},[k]);const u=async g=>{const y=await ts(g,void 0,void 0,!0);return v(D=>({...D,[g]:y.sessions})),me(D=>({...D,[g]:y.next_cursor})),E(D=>({...D,[g]:y.has_more})),y.sessions};r.useEffect(()=>{let g=!1;return(async()=>{var D;de(!0);try{const[J,Se]=await Promise.all([Mt(),ps()]),Le=J.map(p=>{var $,ie;return{...p,runtime_state:(($=Se[p.id])==null?void 0:$.state)||(p.enabled?"connecting":"disabled"),runtime_connected:((ie=Se[p.id])==null?void 0:ie.connected)===!0}}).filter(p=>p.enabled),Ae=await Promise.all(Le.map(async p=>[p.id,await ts(p.id)]));if(g)return;s(Le),v(Object.fromEntries(Ae.map(([p,$])=>[p,$.sessions]))),me(Object.fromEntries(Ae.map(([p,$])=>[p,$.next_cursor]))),E(Object.fromEntries(Ae.map(([p,$])=>[p,$.has_more])));const te=window.localStorage.getItem(ia)||"",je=Le.some(p=>p.id===te)?te:((D=Le[0])==null?void 0:D.id)||"";o(je)}catch(J){g||f(J instanceof Error?J.message:"加载聊天数据失败")}finally{g||de(!1)}})(),()=>{g=!0}},[]),r.useEffect(()=>{let g=!1,y=0,D=null;const J=async()=>{D=new AbortController;try{const Se=await ps({signal:D.signal,timeoutMs:1e4});g||s($e=>$e.map(Le=>{var Ae,te;return{...Le,runtime_state:((Ae=Se[Le.id])==null?void 0:Ae.state)||Le.runtime_state,runtime_connected:((te=Se[Le.id])==null?void 0:te.connected)??Le.runtime_connected}}))}catch{}finally{g||(y=window.setTimeout(J,3e3))}};return y=window.setTimeout(J,3e3),()=>{g=!0,window.clearTimeout(y),D==null||D.abort()}},[]),r.useEffect(()=>{if(!l)return;window.localStorage.setItem(ia,l);const g=x[l]||[];A(y=>{var D;return g.some(J=>J.chat_id===y)?y:((D=g[0])==null?void 0:D.chat_id)||""})},[l,x]),r.useEffect(()=>{!l||Q.current.has(l)||(Q.current.add(l),u(l).catch(g=>{f(g instanceof Error?g.message:"同步会话失败")}))},[l]),r.useEffect(()=>{if(!l||!k){O([]);return}const g=new AbortController;return X(!0),Promise.all([ms(l,k,void 0,void 0,{signal:g.signal}),Us(l,k)]).then(([y])=>{O(y.messages),L(y.has_more),ae(y.next_cursor),y.session&&v(D=>({...D,[l]:(D[l]||[]).map(J=>{var Se;return J.chat_id===((Se=y.session)==null?void 0:Se.chat_id)?y.session:J})})),v(D=>({...D,[l]:(D[l]||[]).map(J=>J.chat_id===k?{...J,unread_count:0}:J)}))}).catch(y=>{g.signal.aborted||f(y instanceof Error?y.message:"加载消息失败")}).finally(()=>{g.signal.aborted||X(!1)}),()=>g.abort()},[l,k]);const d=async()=>{var D;if(!l||!k||U||!ge)return;const g=ve.current,y=(g==null?void 0:g.scrollHeight)||0;c.current=!0,fe(!0),f("");try{const J=(D=b[0])==null?void 0:D.id,Se=await ms(l,k,K,J);O($e=>{const Le=new Set($e.map(Ae=>Ae.message_key));return[...Se.messages.filter(Ae=>!Le.has(Ae.message_key)),...$e]}),L(Se.has_more),ae(Se.next_cursor),requestAnimationFrame(()=>{g&&(g.scrollTop+=g.scrollHeight-y)})}catch(J){c.current=!1,f(J instanceof Error?J.message:"加载历史消息失败")}finally{fe(!1)}};r.useEffect(()=>{let g=!1,y=0,D=0,J=null;const Se=()=>{if(g)return;q("connecting");const $e=window.location.protocol==="https:"?"wss:":"ws:";J=new WebSocket(`${$e}//${window.location.host}/api/chat/ws`),J.onopen=()=>{D=0,q("online")},J.onmessage=Le=>{try{const te=JSON.parse(Le.data).message;if(!te)return;const je=te.account_id;v(p=>{const $=p[je]||[];return $.some(re=>re.chat_id===te.chat_id)?{...p,[je]:$.map(re=>re.chat_id===te.chat_id?{...re,last_message:te.content,last_message_at:te.sent_at,unread_count:te.direction==="incoming"&&(ne.current!==je||be.current!==te.chat_id)?re.unread_count+1:re.unread_count}:re).sort((re,ze)=>ze.last_message_at-re.last_message_at)}:(u(je),p)}),ne.current===je&&be.current===te.chat_id&&(O(p=>{const $=p.findIndex(ie=>ie.message_key===te.message_key);return $>=0?p.map((ie,re)=>re===$?te:ie):[...p,te]}),te.direction==="incoming"&&Us(je,te.chat_id))}catch{}},J.onclose=()=>{if(g)return;q("offline");const Le=Math.min(15e3,1e3*2**Math.min(D++,4));y=window.setTimeout(Se,Le)},J.onerror=()=>J==null?void 0:J.close()};return Se(),()=>{g=!0,window.clearTimeout(y),J==null||J.close()}},[]);const F=()=>{const g=ve.current;if(!g)return;const y=g.scrollHeight-g.scrollTop-g.clientHeight;Ne.current=y<=48};r.useLayoutEffect(()=>{const g=De.current.accountID!==l||De.current.chatID!==k;De.current={accountID:l,chatID:k},g&&(Ne.current=!0);const y=ve.current;if(y){if(c.current){c.current=!1;return}(G||Ne.current)&&(y.scrollTop=y.scrollHeight)}},[l,k,b,G]);const I=t.find(g=>g.id===l),H=x[l]||[],P=H.find(g=>g.chat_id===k),Ce=r.useMemo(()=>{const g=j.trim().toLowerCase();return H.filter(y=>Y&&y.unread_count<=0?!1:g?[y.buyer_name,y.buyer_id,y.item_title,y.last_message].some(D=>(D||"").toLowerCase().includes(g)):!0)},[H,j,Y]),Re=g=>(x[g]||[]).reduce((y,D)=>y+D.unread_count,0),xe=async()=>{if(!(!l||ee||!R[l])){T(!0),f("");try{const g=await ts(l,Z[l],void 0,!0);v(y=>({...y,[l]:g.sessions})),me(y=>({...y,[l]:g.next_cursor})),E(y=>({...y,[l]:g.has_more}))}catch(g){f(g instanceof Error?g.message:"加载历史联系人失败")}finally{T(!1)}}},Pe=async()=>{const g=ce.trim();if(!(!g||!P||!l||ye)){z(!0),f("");try{const y=await $l({account_id:l,chat_id:P.chat_id,buyer_id:P.buyer_id,buyer_name:P.buyer_name,item_id:P.item_id,item_title:P.item_title,text:g});w(""),O(D=>D.some(J=>J.message_key===y.message.message_key)?D.map(J=>J.message_key===y.message.message_key?y.message:J):[...D,y.message])}catch(y){f(y instanceof Error?y.message:"消息发送失败"),Pl(l,P.chat_id).then(O)}finally{z(!1)}}},le=async g=>{if(!(!g||!P||!l||ye)){z(!0),f("");try{const y=await El({account_id:l,chat_id:P.chat_id,buyer_id:P.buyer_id,buyer_name:P.buyer_name,buyer_avatar_url:P.buyer_avatar_url,item_id:P.item_id,item_title:P.item_title,image:g});O(D=>D.some(J=>J.message_key===y.message.message_key)?D.map(J=>J.message_key===y.message.message_key?y.message:J):[...D,y.message])}catch(y){f(y instanceof Error?y.message:"图片发送失败")}finally{z(!1),S.current&&(S.current.value="")}}};return M?e.jsx("div",{className:"flex h-[calc(100vh-4rem)] items-center justify-center",children:e.jsx(Ee,{className:"h-8 w-8 animate-spin text-sky-500"})}):e.jsxs("section",{className:"flex h-[calc(100vh-4rem)] min-h-[560px] flex-col overflow-hidden rounded-2xl border border-slate-200 bg-white shadow-chat",children:[e.jsxs("header",{className:"border-b border-slate-200 bg-slate-50/70 px-5 pt-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-black tracking-tight text-slate-950",children:"在线聊天"}),e.jsx("p",{className:"mt-0.5 text-xs font-medium text-slate-500",children:"复用账号实时连接,消息按账号完全隔离"})]}),e.jsxs("div",{className:`flex items-center gap-2 rounded-full px-3 py-1.5 text-xs font-bold ${W==="online"?"bg-emerald-50 text-emerald-700":W==="connecting"?"bg-amber-50 text-amber-700":"bg-red-50 text-red-700"}`,children:[W==="online"?e.jsx(ol,{className:"h-3.5 w-3.5"}):e.jsx(cl,{className:"h-3.5 w-3.5"}),W==="online"?"实时同步中":W==="connecting"?"正在连接":"连接已断开"]})]}),e.jsx("div",{className:"flex gap-1 overflow-x-auto pb-0",role:"tablist","aria-label":"聊天账号",children:t.map(g=>{const y=g.id===l,D=Re(g.id),J=g.runtime_state==="online";return e.jsxs("button",{type:"button",role:"tab","aria-selected":y,onClick:()=>o(g.id),className:`relative flex h-11 shrink-0 items-center gap-2 border-b-2 px-3 text-sm font-extrabold transition-colors ${y?"border-sky-500 text-sky-700":"border-transparent text-slate-500 hover:text-slate-900"}`,children:[e.jsx("span",{className:`h-2 w-2 rounded-full ${J?"bg-emerald-500":"bg-slate-300"}`}),e.jsx("span",{className:"max-w-36 truncate",children:g.nickname||g.remark||g.id}),D>0&&e.jsx("span",{className:"min-w-5 rounded-full bg-red-500 px-1.5 py-0.5 text-[10px] text-white",children:D>99?"99+":D})]},g.id)})})]}),t.length===0?e.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center text-center",children:[e.jsx(rs,{className:"h-12 w-12 text-slate-300"}),e.jsx("h3",{className:"mt-4 font-black text-slate-800",children:"暂无启用账号"}),e.jsx("p",{className:"mt-1 text-sm text-slate-500",children:"先在账号管理中启用账号,聊天会话会自动出现。"})]}):e.jsxs("div",{className:"grid min-h-0 flex-1 overflow-hidden grid-cols-[320px_minmax(0,1fr)]",children:[e.jsxs("aside",{className:"flex min-h-0 flex-col border-r border-slate-200 bg-slate-50/40",children:[e.jsxs("div",{className:"space-y-3 border-b border-slate-200 p-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(Nt,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-slate-400"}),e.jsx("input",{value:j,onChange:g=>V(g.target.value),placeholder:"搜索用户、商品或消息",className:"h-10 w-full rounded-xl border border-slate-200 bg-white pl-9 pr-3 text-sm outline-none transition focus:border-sky-400 focus:ring-2 focus:ring-sky-100"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("button",{type:"button",onClick:()=>pe(g=>!g),className:`rounded-lg px-2.5 py-1.5 text-xs font-bold ${Y?"bg-sky-100 text-sky-700":"text-slate-500 hover:bg-slate-100"}`,children:Y?"只看未读":"全部会话"}),e.jsx("button",{type:"button",title:"刷新会话",onClick:()=>void u(l),className:"rounded-lg p-2 text-slate-400 hover:bg-slate-100 hover:text-slate-700",children:e.jsx(Be,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto",children:[Ce.map(g=>e.jsxs("button",{type:"button",onClick:()=>A(g.chat_id),className:`flex w-full gap-3 border-b border-slate-100 p-4 text-left transition-colors ${g.chat_id===k?"bg-white shadow-chat-active":"hover:bg-white/80"}`,children:[e.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center overflow-hidden rounded-full bg-slate-200 text-slate-500",children:g.buyer_avatar_url?e.jsx("img",{src:g.buyer_avatar_url,alt:"",className:"h-full w-full object-cover"}):e.jsx(Vt,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate text-sm font-extrabold text-slate-900",children:g.buyer_name||`用户 ${g.buyer_id}`}),e.jsx("span",{className:"ml-auto shrink-0 text-[10px] font-medium text-slate-400",children:Rn(g.last_message_at)})]}),e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[e.jsx("span",{className:"truncate text-xs text-slate-500",children:g.last_message||"暂无消息"}),g.unread_count>0&&e.jsx("span",{className:"ml-auto min-w-5 shrink-0 rounded-full bg-red-500 px-1.5 py-0.5 text-center text-[10px] font-bold text-white",children:g.unread_count})]}),g.item_title&&e.jsxs("div",{className:"mt-1.5 truncate text-[10px] font-medium text-sky-700",children:["商品 · ",g.item_title]})]})]},g.chat_id)),Ce.length===0&&e.jsx("div",{className:"px-6 py-16 text-center text-sm text-slate-400",children:"当前账号暂无匹配会话"}),R[l]&&!j&&!Y&&e.jsx("div",{className:"flex justify-center p-4",children:e.jsxs("button",{type:"button",onClick:()=>void xe(),disabled:ee,className:"flex items-center gap-2 rounded-full border border-slate-200 bg-white px-4 py-2 text-xs font-bold text-slate-500 shadow-sm hover:border-sky-200 hover:text-sky-600 disabled:opacity-50",children:[ee&&e.jsx(Ee,{className:"h-3.5 w-3.5 animate-spin"}),ee?"正在加载":"加载更多历史联系人"]})})]})]}),e.jsx("main",{className:"flex min-h-0 min-w-0 flex-col overflow-hidden bg-surface-subtle",children:P?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex h-16 shrink-0 items-center border-b border-slate-200 bg-white px-5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-black text-slate-950",children:P.buyer_name||P.buyer_id}),e.jsxs("div",{className:"mt-0.5 truncate text-xs text-slate-500",children:["用户 ID:",P.buyer_id]})]}),e.jsx("span",{className:`ml-auto rounded-full px-2.5 py-1 text-[10px] font-bold ${(I==null?void 0:I.runtime_state)==="online"?"bg-emerald-50 text-emerald-700":"bg-slate-100 text-slate-500"}`,children:(I==null?void 0:I.runtime_state)==="online"?"账号在线":"账号离线"})]}),e.jsx("div",{ref:ve,onScroll:F,className:"min-h-0 flex-1 space-y-5 overflow-y-auto px-6 py-5",children:G?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(Ee,{className:"h-6 w-6 animate-spin text-sky-500"})}):e.jsxs(e.Fragment,{children:[ge&&e.jsx("div",{className:"flex justify-center pb-1",children:e.jsxs("button",{type:"button",onClick:()=>void d(),disabled:U,className:"flex items-center gap-2 rounded-full border border-slate-200 bg-white px-4 py-1.5 text-xs font-bold text-slate-500 shadow-sm transition hover:border-sky-200 hover:text-sky-600 disabled:opacity-50",children:[U&&e.jsx(Ee,{className:"h-3.5 w-3.5 animate-spin"}),U?"正在加载":"加载更早消息"]})}),b.map(g=>{const y=g.direction==="outgoing";return g.message_type==="system"?e.jsx("div",{className:"flex justify-center py-1",children:e.jsxs("div",{className:"max-w-[82%] rounded-xl border border-slate-200 bg-slate-100 px-4 py-2 text-center text-xs leading-5 text-slate-500",children:[na(g.content),e.jsx("div",{className:"mt-1 text-[10px] text-slate-400",children:oa(g.sent_at)})]})},g.message_key):e.jsxs("div",{className:`flex items-end gap-2.5 ${y?"justify-end":"justify-start"}`,children:[!y&&e.jsx("div",{className:"h-9 w-9 shrink-0 overflow-hidden rounded-full bg-slate-200 ring-2 ring-white",children:P.buyer_avatar_url?e.jsx("img",{src:P.buyer_avatar_url,alt:P.buyer_name||"用户",className:"h-full w-full object-cover"}):e.jsx(Vt,{className:"m-2 h-5 w-5 text-slate-500"})}),e.jsxs("div",{className:`max-w-[72%] ${y?"items-end":"items-start"} flex flex-col`,children:[e.jsx("div",{className:"mb-1 px-1 text-[10px] font-semibold text-slate-400",children:y?(I==null?void 0:I.nickname)||(I==null?void 0:I.remark)||"我":P.buyer_name||g.sender_name||P.buyer_id}),g.message_type==="image"?e.jsx("a",{href:g.content,target:"_blank",rel:"noreferrer",className:`block overflow-hidden rounded-2xl border bg-white p-1 shadow-sm ${y?"rounded-br-md border-sky-200":"rounded-bl-md border-slate-200"}`,children:e.jsx("img",{src:g.content,alt:"聊天图片",className:"max-h-80 max-w-full rounded-xl object-contain"})}):g.message_type==="video"?e.jsx("video",{src:g.content,controls:!0,preload:"metadata",className:"max-h-80 max-w-full rounded-2xl bg-black"}):e.jsx("div",{className:`rounded-2xl px-4 py-2.5 text-sm leading-6 shadow-sm ${y?"rounded-br-md bg-sky-500 text-white":"rounded-bl-md border border-slate-200 bg-white text-slate-800"}`,children:na(g.content)}),e.jsxs("div",{className:"mt-1 flex items-center gap-1 text-[10px] text-slate-400",children:[oa(g.sent_at),y&&(g.status==="failed"?e.jsx(at,{className:"h-3 w-3 text-red-500"}):g.status==="sent"?e.jsx(dl,{className:"h-3 w-3 text-sky-500"}):e.jsx(Qe,{className:"h-3 w-3"}))]})]}),y&&e.jsx("div",{className:"h-9 w-9 shrink-0 overflow-hidden rounded-full bg-sky-100 ring-2 ring-white",children:I!=null&&I.avatar_url?e.jsx("img",{src:I.avatar_url,alt:"我",className:"h-full w-full object-cover"}):e.jsx(Vt,{className:"m-2 h-5 w-5 text-sky-600"})})]},g.message_key)})]})}),m&&e.jsx("div",{className:"border-t border-red-100 bg-red-50 px-5 py-2 text-xs font-medium text-red-700",children:m}),e.jsxs("div",{className:"relative z-10 shrink-0 border-t border-slate-200 bg-white p-4 shadow-chat-input",children:[e.jsxs("div",{className:"mb-2 flex items-center gap-1",children:[e.jsxs("div",{className:"relative",children:[e.jsx("button",{type:"button",onClick:()=>ke(g=>!g),disabled:ye||(I==null?void 0:I.runtime_state)!=="online",className:"rounded-lg p-2 text-slate-500 hover:bg-sky-50 hover:text-sky-600 disabled:opacity-40",title:"闲鱼表情",children:e.jsx(xl,{className:"h-5 w-5"})}),se&&e.jsxs("div",{className:"absolute bottom-11 left-0 z-30 w-[360px] rounded-2xl border border-slate-200 bg-white p-3 shadow-2xl",children:[e.jsx("div",{className:"mb-2 text-xs font-bold text-slate-500",children:"全部表情"}),e.jsx("div",{className:"grid max-h-72 grid-cols-8 gap-1 overflow-y-auto",children:Ea.map(([g,y])=>e.jsx("button",{type:"button",title:`[${g}]`,onClick:()=>{w(D=>D+`[${g}]`),ke(!1)},className:"flex h-10 w-10 items-center justify-center rounded-lg hover:bg-slate-100",children:e.jsx("img",{src:In(y),alt:`[${g}]`,className:"h-8 w-8 object-contain"})},g))})]})]}),e.jsx("input",{ref:S,type:"file",accept:"image/*",className:"hidden",onChange:g=>{var y;return void le((y=g.target.files)==null?void 0:y[0])}}),e.jsx("button",{type:"button",onClick:()=>{var g;return(g=S.current)==null?void 0:g.click()},disabled:ye||(I==null?void 0:I.runtime_state)!=="online",className:"rounded-lg p-2 text-slate-500 transition hover:bg-sky-50 hover:text-sky-600 disabled:opacity-40",title:"发送图片(最大 10MB)",children:e.jsx(ml,{className:"h-5 w-5"})})]}),e.jsxs("div",{className:"flex items-end gap-3 rounded-2xl border border-slate-200 bg-slate-50 p-2 transition focus-within:border-sky-400 focus-within:ring-2 focus-within:ring-sky-100",children:[e.jsx("textarea",{value:ce,onChange:g=>w(g.target.value),rows:2,maxLength:2e3,onKeyDown:g=>{g.key==="Enter"&&!g.shiftKey&&(g.preventDefault(),Pe())},disabled:(I==null?void 0:I.runtime_state)!=="online",placeholder:(I==null?void 0:I.runtime_state)==="online"?"输入消息,Enter 发送,Shift + Enter 换行":"账号离线,暂时无法发送",className:"max-h-32 min-h-12 flex-1 resize-none bg-transparent px-2 py-2 text-sm leading-6 outline-none disabled:cursor-not-allowed"}),e.jsx("button",{type:"button",onClick:()=>void Pe(),disabled:!ce.trim()||ye||(I==null?void 0:I.runtime_state)!=="online",className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-xl bg-sky-500 text-white shadow-md shadow-sky-100 transition hover:bg-sky-600 disabled:cursor-not-allowed disabled:bg-slate-300 disabled:shadow-none","aria-label":"发送消息",children:ye?e.jsx(Ee,{className:"h-4 w-4 animate-spin"}):e.jsx(Kt,{className:"h-4 w-4"})})]})]})]}):e.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center text-center",children:[e.jsx(rs,{className:"h-12 w-12 text-slate-300"}),e.jsx("h3",{className:"mt-4 font-black text-slate-700",children:"选择一个用户开始聊天"}),e.jsx("p",{className:"mt-1 text-sm text-slate-400",children:"该账号的新消息会实时出现在左侧列表。"})]})})]})]})},Da="ydisks.sidebar.v1",$n=()=>{try{return window.localStorage.getItem(Da)==="collapsed"}catch{return!1}},En=t=>{try{window.localStorage.setItem(Da,t?"collapsed":"expanded")}catch{}},Ta={"/app/dashboard":"dashboard","/app/accounts":"accounts","/app/chat":"chat","/app/orders":"orders","/app/cards":"cards","/app/items":"items","/app/rules":"rules","/app/notifications":"notifications","/app/settings":"settings"},ca=Object.fromEntries(Object.entries(Ta).map(([t,s])=>[s,t])),da=()=>Ta[window.location.pathname]||"dashboard",Dn=()=>{const[t,s]=r.useState(!1),[l,o]=r.useState(!1),[x,v]=r.useState(da),[k,A]=r.useState(!0),[b,O]=r.useState(!1),[j,V]=r.useState(""),[Y,pe]=r.useState(""),[ce,w]=r.useState(!1),[M,de]=r.useState(""),[G,X]=r.useState(""),[U,fe]=r.useState(""),[ge,L]=r.useState(!1),[K,ae]=r.useState(""),[Z,me]=r.useState(),[R,E]=r.useState($n),ee=z=>{const m=z==="settings"&&!l?"dashboard":z,f=ca[m];f&&f!==window.location.pathname&&window.history.pushState({},"",f),v(m)};r.useEffect(()=>{const z=()=>v(da());return window.addEventListener("popstate",z),()=>window.removeEventListener("popstate",z)},[]),r.useEffect(()=>{wa().then(m=>{if((m==null?void 0:m.initialized)===!1){O(!0),s(!1),o(!1);return}O(!1),m!=null&&m.authenticated?(s(!0),o(m.is_admin===!0)):o(!1)}).catch(()=>{s(!1),o(!1)}).finally(()=>A(!1));const z=()=>{s(!1),o(!1)};return window.addEventListener("auth:logout",z),()=>window.removeEventListener("auth:logout",z)},[]),r.useEffect(()=>{!k&&t&&!l&&x==="settings"&&(window.history.replaceState({},"",ca.dashboard),v("dashboard"))},[k,t,l,x]);const T=async z=>{z.preventDefault(),w(!0),de("");try{const m=await Cl({username:j,password:Y});m.success?(s(!0),o(m.is_admin===!0)):de(m.message||"登录失败")}catch(m){const f=m instanceof Error?m.message:String(m);de(f||"登录失败")}finally{w(!1)}},se=async z=>{if(z.preventDefault(),ae(""),G.length<8){ae("密码至少需要 8 个字符");return}if(G!==U){ae("两次输入的密码不一致");return}L(!0);try{const m=await Sl(G);if(!m.success){ae(m.message||"初始化失败,请重试");return}O(!1),s(!0),o(m.is_admin===!0),X(""),fe("")}catch(m){const f=m instanceof Error?m.message:String(m);ae(f||"初始化失败,请重试")}finally{L(!1)}},ke=async()=>{try{await Ll()}catch(z){console.error("退出登录失败",z)}finally{s(!1),o(!1)}};if(k)return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-surface",children:e.jsx(Ee,{className:"w-8 h-8 text-brand animate-spin"})});if(b)return e.jsxs("div",{className:"min-h-screen flex items-center justify-center bg-canvas p-4 relative overflow-hidden font-sans",children:[e.jsx("div",{className:"absolute top-[-10%] left-[-10%] w-[60%] h-[60%] bg-blue-200/40 rounded-full blur-[120px] animate-pulse"}),e.jsx("div",{className:"absolute bottom-[-10%] right-[-10%] w-[60%] h-[60%] bg-blue-200/30 rounded-full blur-[120px] animate-pulse",style:{animationDelay:"2s"}}),e.jsxs("div",{className:"bg-white/80 backdrop-blur-3xl p-8 md:p-12 rounded-xl shadow-panel w-full max-w-xl border border-white relative z-10 animate-fade-in",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("div",{className:"mx-auto mb-6 flex justify-center",children:e.jsx(ds,{sizeClass:"w-24 h-24"})}),e.jsx("h2",{className:"text-3xl font-extrabold text-gray-900 mb-2 tracking-tight",children:"首次设置管理员密码"}),e.jsx("p",{className:"text-gray-600 font-medium",children:"设置完成后会自动进入系统,管理员账号为 admin。"})]}),e.jsxs("form",{onSubmit:se,className:"space-y-5",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"relative group",children:[e.jsx(Ds,{className:"absolute left-5 top-1/2 -translate-y-1/2 w-5 h-5 text-gray-400 group-focus-within:text-black transition-colors"}),e.jsx("input",{type:"password",placeholder:"设置管理员密码(至少 8 个字符)",value:G,onChange:z=>X(z.target.value),autoFocus:!0,className:"w-full ios-input pl-14 pr-6 py-4.5 rounded-2xl text-base h-14"})]}),e.jsxs("div",{className:"relative group",children:[e.jsx(Dt,{className:"absolute left-5 top-1/2 -translate-y-1/2 w-5 h-5 text-gray-400 group-focus-within:text-black transition-colors"}),e.jsx("input",{type:"password",placeholder:"再次输入密码",value:U,onChange:z=>fe(z.target.value),className:"w-full ios-input pl-14 pr-6 py-4.5 rounded-2xl text-base h-14"})]})]}),K&&e.jsxs("div",{className:"p-3 rounded-xl bg-red-50 text-red-500 text-sm text-center font-bold flex items-center justify-center gap-2",children:[e.jsx(Dt,{className:"w-4 h-4"})," ",K]}),e.jsx("button",{type:"submit",disabled:ge,className:"w-full ios-btn-primary h-14 rounded-2xl text-lg shadow-xl shadow-blue-200 mt-2 flex items-center justify-center gap-2 group disabled:opacity-70",children:ge?e.jsx(Ee,{className:"w-5 h-5 animate-spin"}):e.jsxs(e.Fragment,{children:["设置密码并进入系统 ",e.jsx(cs,{className:"w-5 h-5 group-hover:translate-x-1 transition-transform"})]})})]}),e.jsx("div",{className:"mt-8 pt-6 border-t border-gray-100 text-center",children:e.jsx("span",{className:"text-xs text-gray-400 font-medium tracking-widest uppercase",children:"Secure Bootstrap"})})]})]});if(!t)return e.jsxs("div",{className:"min-h-screen flex items-center justify-center bg-canvas p-4 relative overflow-hidden font-sans",children:[e.jsx("div",{className:"absolute top-[-10%] left-[-10%] w-[60%] h-[60%] bg-blue-200/40 rounded-full blur-[120px] animate-pulse"}),e.jsx("div",{className:"absolute bottom-[-10%] right-[-10%] w-[60%] h-[60%] bg-blue-200/30 rounded-full blur-[120px] animate-pulse",style:{animationDelay:"2s"}}),e.jsxs("div",{className:"bg-white/80 backdrop-blur-3xl p-8 md:p-12 rounded-xl shadow-panel w-full max-w-lg border border-white relative z-10 animate-fade-in",children:[e.jsxs("div",{className:"text-center mb-10",children:[e.jsx("div",{className:"group mx-auto mb-6 flex cursor-pointer justify-center",children:e.jsx(ds,{sizeClass:"w-24 h-24",logoClassName:"w-full h-full text-white group-hover:scale-110 transition-transform"})}),e.jsx("h2",{className:"text-3xl font-extrabold text-gray-900 mb-2 tracking-tight",children:"欢迎回来"}),e.jsx("p",{className:"text-gray-500 font-medium",children:"Ydisks闲鱼助手 · 自动发货与管家系统"})]}),e.jsxs("form",{onSubmit:T,className:"space-y-5",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"relative group",children:[e.jsx(xt,{className:"absolute left-5 top-1/2 -translate-y-1/2 w-5 h-5 text-gray-400 group-focus-within:text-black transition-colors"}),e.jsx("input",{type:"text",placeholder:"管理员账号",value:j,onChange:z=>V(z.target.value),className:"w-full ios-input pl-14 pr-6 py-4.5 rounded-2xl text-base h-14"})]}),e.jsxs("div",{className:"relative group",children:[e.jsx(Ds,{className:"absolute left-5 top-1/2 -translate-y-1/2 w-5 h-5 text-gray-400 group-focus-within:text-black transition-colors"}),e.jsx("input",{type:"password",placeholder:"密码",value:Y,onChange:z=>pe(z.target.value),className:"w-full ios-input pl-14 pr-6 py-4.5 rounded-2xl text-base h-14"})]})]}),M&&e.jsxs("div",{className:"p-3 rounded-xl bg-red-50 text-red-500 text-sm text-center font-bold flex items-center justify-center gap-2",children:[e.jsx(Dt,{className:"w-4 h-4"})," ",M]}),e.jsx("button",{type:"submit",disabled:ce,className:"w-full ios-btn-primary h-14 rounded-2xl text-lg shadow-xl shadow-blue-200 mt-2 flex items-center justify-center gap-2 group disabled:opacity-70",children:ce?e.jsx(Ee,{className:"w-5 h-5 animate-spin"}):e.jsxs(e.Fragment,{children:["立即登录 ",e.jsx(cs,{className:"w-5 h-5 group-hover:translate-x-1 transition-transform"})]})})]}),e.jsx("div",{className:"mt-8 pt-6 border-t border-gray-100",children:e.jsx("div",{className:"mt-6 text-center",children:e.jsx("span",{className:"text-xs text-gray-400 font-medium tracking-widest uppercase",children:"Ydisks闲鱼助手 v1.0"})})})]})]});const ye=()=>{switch(x){case"dashboard":return e.jsx(as,{});case"accounts":return e.jsx(en,{});case"chat":return e.jsx(Pn,{});case"orders":return e.jsx(an,{});case"cards":return e.jsx(rn,{});case"items":return e.jsx(un,{onConfigureDelivery:z=>{me({cookieId:z.cookie_id,itemId:z.item_id,requestId:Date.now()}),ee("rules")}});case"rules":return e.jsx(kn,{initialDeliveryTarget:Z,onDeliveryTargetHandled:()=>me(void 0)});case"notifications":return e.jsx(On,{isAdmin:l});case"settings":return l?e.jsx(bn,{}):e.jsx(as,{});default:return e.jsx(as,{})}};return e.jsxs("div",{className:"flex min-h-screen bg-canvas text-ink",children:[e.jsx(jl,{activeTab:x,isAdmin:l,collapsed:R,onToggleCollapsed:()=>E(z=>{const m=!z;return En(m),m}),onNavigate:ee,onLogout:ke}),e.jsxs("main",{className:`h-screen min-w-0 flex-1 overflow-x-hidden overflow-y-auto scroll-smooth transition-[margin] duration-300 ${R?"ml-16":"ml-64"} ${x==="chat"?"p-4 md:p-6":"p-8 md:p-12"}`,children:[e.jsx("div",{className:"fixed top-0 right-0 w-[800px] h-[800px] bg-gradient-to-bl from-blue-50 to-transparent rounded-full blur-[120px] pointer-events-none -z-10 opacity-60"}),e.jsx("div",{className:`${x==="chat"?"mx-auto max-w-[1680px]":"mx-auto max-w-[1400px] pb-10"}`,children:ye()})]})]})},Ma=document.getElementById("root");if(!Ma)throw new Error("Could not find root element to mount to");const Tn=Fa.createRoot(Ma);Tn.render(e.jsx(xa.StrictMode,{children:e.jsx(Dn,{})}));
|