20 lines
228 KiB
JavaScript
20 lines
228 KiB
JavaScript
import{j as e,r as d,b as he,c as bt,d as yt}from"./react-vendor-DZnRGM0-.js";import{L as ft,U as Ks,S as Gs,C as us,B as Xs,Z as hs,a as Be,b as ys,c as Zs,d as jt,A as ws,D as Nt,e as _s,P as Hs,f as Xe,E as et,T as vt,g as ke,Q as is,h as gs,i as Ae,j as qe,k as ls,l as ks,R as Se,m as st,n as wt,o as De,X as pe,K as _t,p as Ge,q as ze,r as Le,s as Pe,t as Ss,u as kt,v as Ue,w as St,x as Ct,y as Ke,z as $t,F as Cs,I as $s,G as Is,H as It,J as At,M as os,N as Ze,O as tt,V as Dt,W as Pt,Y as bs,_ as Lt,$ as Ft,a0 as As,a1 as Et,a2 as at,a3 as as,a4 as lt,a5 as Rt,a6 as Ot,a7 as fs,a8 as rt,a9 as Tt,aa as Mt}from"./icons-vendor-BmeuAUrP.js";import{R as He,B as qt,X as Ds,Y as Ps,T as ds,a as Bt,C as cs,A as zt,b as Ut,c as Wt,P as Ls,d as Fs,L as Jt}from"./charts-vendor-B_BfwiL0.js";import"./vendor-w5t2K9ux.js";(function(){const a=document.createElement("link").relList;if(a&&a.supports&&a.supports("modulepreload"))return;for(const g of document.querySelectorAll('link[rel="modulepreload"]'))h(g);new MutationObserver(g=>{for(const p of g)if(p.type==="childList")for(const k of p.addedNodes)k.tagName==="LINK"&&k.rel==="modulepreload"&&h(k)}).observe(document,{childList:!0,subtree:!0});function l(g){const p={};return g.integrity&&(p.integrity=g.integrity),g.referrerPolicy&&(p.referrerPolicy=g.referrerPolicy),g.crossOrigin==="use-credentials"?p.credentials="include":g.crossOrigin==="anonymous"?p.credentials="omit":p.credentials="same-origin",p}function h(g){if(g.ep)return;g.ep=!0;const p=l(g);fetch(g.href,p)}})();const Vt=({activeTab:s,isAdmin:a=!1,onNavigate:l,onLogout:h})=>{const g=[{id:"dashboard",icon:ft,label:"仪表盘"},{id:"accounts",icon:Ks,label:"账号管理"},{id:"orders",icon:Gs,label:"订单管理"},{id:"cards",icon:us,label:"卡密库存"},{id:"items",icon:Xs,label:"商品列表"},{id:"rules",icon:hs,label:"自动化规则"},{id:"notifications",icon:Be,label:"通知设置"},...a?[{id:"settings",icon:ys,label:"系统与AI"}]:[]];return e.jsxs("div",{className:"w-64 h-screen fixed left-0 top-0 bg-white border-r border-gray-100 flex flex-col justify-between z-20 shadow-[4px_0_24px_rgba(0,0,0,0.02)]",children:[e.jsxs("div",{className:"p-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-12 px-2",children:[e.jsx("div",{className:"w-10 h-10 bg-[#0094f7] squircle flex items-center justify-center shrink-0 p-1.5",style:{filter:"drop-shadow(0 4px 12px rgba(0,148,247,0.25))"},children:e.jsx("img",{src:"/static/ydisks-logo.svg",alt:"Ydisks",className:"w-full h-full"})}),e.jsxs("h1",{className:"text-xl font-extrabold tracking-tight text-gray-900",children:["Ydisks闲鱼助手 ",e.jsx("span",{className:"text-xs bg-[#0094f7] text-white px-1.5 py-0.5 rounded ml-1",children:"PRO"})]})]}),e.jsx("nav",{className:"space-y-2",children:g.map(p=>{const k=p.icon,_=s===p.id;return e.jsxs("button",{onClick:()=>l(p.id),className:`w-full flex items-center gap-3 px-4 py-3.5 rounded-2xl transition-all duration-300 group relative overflow-hidden ${_?"bg-[#0094f7] text-white font-bold shadow-lg shadow-blue-100 transform scale-[1.02]":"text-gray-500 hover:bg-gray-50 hover:text-gray-900"}`,children:[e.jsx(k,{className:`w-5 h-5 transition-colors ${_?"text-white":"text-gray-400 group-hover:text-gray-600"}`}),e.jsx("span",{className:"text-sm tracking-wide",children:p.label}),_&&e.jsx(Zs,{className:"w-4 h-4 absolute right-3 text-white/30 animate-pulse"})]},p.id)})})]}),e.jsx("div",{className:"p-6 border-t border-gray-50",children:e.jsxs("button",{onClick:h,className:"w-full flex items-center gap-3 px-4 py-3 text-gray-500 hover:text-red-500 hover:bg-red-50 rounded-2xl transition-all duration-200 font-medium",children:[e.jsx(jt,{className:"w-5 h-5"}),e.jsx("span",{className:"text-sm",children:"退出登录"})]})})]})},Qt=s=>{if(!s)return"";const a=new URLSearchParams;for(const[h,g]of Object.entries(s))g!=null&&a.set(h,String(g));const l=a.toString();return l?`?${l}`:""},ns=async(s,a,l={})=>{const h=Qt(l.params),g=`${a}${h}`,p=await fetch(g,{method:s,credentials:"include",headers:{...l.body===void 0?{}:{"Content-Type":"application/json"}},body:l.body===void 0?void 0:JSON.stringify(l.body)}),_=(p.headers.get("content-type")||"").includes("application/json");if(!p.ok){const u=_?await p.json().catch(()=>{}):await p.text().catch(()=>{}),q=typeof u=="string"?u:(u==null?void 0:u.detail)||(u==null?void 0:u.message)||(u==null?void 0:u.msg);throw new Error(q||`请求失败: ${p.status}`)}return _?await p.json():await p.text()},me=async(s,a)=>ns("GET",s,{params:a}),de=async(s,a)=>ns("POST",s,{body:a}),Ne=async(s,a)=>ns("PUT",s,{body:a}),Oe=async(s,a)=>ns("DELETE",s,{params:a}),js=async(s,a)=>{const l=await fetch(s,{method:"POST",credentials:"include",body:a}),p=(l.headers.get("content-type")||"").includes("application/json")?await l.json().catch(()=>{}):await l.text().catch(()=>{});if(!l.ok){const k=typeof p=="string"?p:(p==null?void 0:p.detail)||(p==null?void 0:p.message)||(p==null?void 0:p.msg),_=new Error(k||"请求失败: "+l.status);throw _.payload=p,_}return p},Yt=s=>{const a={...s};if("renewal_log_retention_days"in a){const l=Number(a.renewal_log_retention_days);a.renewal_log_retention_days=Number.isFinite(l)?l:10}return a},Kt=async s=>de("/login",s),nt=async()=>me("/verify"),Gt=async()=>de("/logout",{}),Xt=async s=>Ne("/account/credentials",s),Zt=async(s,a,l)=>de("/cookies",{id:s,value:a,login_method:l}),Ht=(s,a)=>{const l=s.avatar_url||"";if(!l)return"";try{const h=new URL(l,window.location.origin);return h.hostname.endsWith("alicdn.com")&&h.searchParams.set("_v",a),h.toString()}catch{return l}},Ns=async()=>{const s=await me("/cookies/details"),a=Date.now().toString();return s.map(l=>({id:l.id,value:"",cookie:"",enabled:l.enabled,auto_confirm:l.auto_confirm,remark:l.remark,note:l.remark,pause_duration:l.pause_duration,username:l.username||"",login_password:"",show_browser:l.show_browser===!0||l.show_browser===1||l.show_browser==="1"||l.show_browser==="true",nickname:l.nickname||l.remark||`账号 ${l.id.substring(0,6)}`,avatar_url:Ht(l,a),profile_error:l.profile_error||"",ai_enabled:!1}))},ea=async()=>me("/cookies/runtime-status"),sa=async()=>de("/qr-login/generate"),ta=async s=>me(`/qr-login/check/${s}`),aa=async(s,a)=>Ne(`/cookies/${s}/status`,{enabled:a}),la=async s=>Oe(`/cookies/${s}`),ra=async(s,a)=>Ne(`/cookies/${s}/remark`,{remark:a}),na=async(s,a)=>Ne(`/cookies/${s}/auto-confirm`,{auto_confirm:a}),ia=async(s,a)=>Ne(`/cookies/${s}/pause-duration`,{pause_duration:a}),Es=async(s,a,l)=>Ne(`/cookies/${s}`,{id:s,value:a,login_method:l}),oa=async s=>de(`/cookies/${s}/refresh-profile`,{}),da=async(s,a)=>Ne(`/cookies/${s}/login-info`,a),ca=async()=>me("/ai-reply-settings"),Rs=async(s,a,l=1,h=20)=>{const g={page:l,page_size:h};a&&a!=="all"&&(g.status=a);const p=await me("/api/orders",g),_=(p.orders||p.data||[]).map(u=>({...u,id:u.id||u.order_id,status:u.status||u.order_status||"processing",quantity:Number(u.quantity||1)}));return{success:!0,data:_,total:p.total||_.length,page:p.page||l,page_size:p.page_size||h,total_pages:p.total_pages||1}},xa=async(s,a)=>Ne(`/api/orders/${s}`,a),ma=async s=>Oe(`/api/orders/${s}`),pa=async(s,a)=>{const l=new FormData,h=await fetch("/api/orders/refresh",{method:"POST",credentials:"include",body:l}),g=await h.json().catch(()=>({}));if(!h.ok||g.success===!1)throw new Error(g.detail||g.message||`订单同步失败: ${h.status}`);return g},ua=async s=>de(`/api/orders/${s}/refresh`),ha=async(s,a,l)=>de("/api/orders/manual-ship",{order_ids:s,ship_mode:a,custom_content:l}),ga=async s=>{const a=s instanceof FormData,l=await fetch("/api/orders/import",{method:"POST",credentials:"include",headers:{...a?{}:{"Content-Type":"application/json"}},body:a?s:JSON.stringify(s)}),h=await l.json().catch(()=>({}));if(!l.ok||h.success===!1)throw new Error(h.detail||h.message||`订单导入失败: ${l.status}`);return h},ba=async()=>me("/admin/stats"),Os=async(s=7)=>{let a;if(typeof s=="number"){const l=new Date,h=new Date;h.setDate(h.getDate()-s),a={start_date:h.toISOString().split("T")[0],end_date:l.toISOString().split("T")[0]}}else a=s;return me("/analytics/orders",a)},ya=async s=>{const a=await me("/analytics/orders/valid",{start_date:s.start_date,end_date:s.end_date});return(Array.isArray(a)?a:a.orders||[]).map(h=>({...h,id:h.id||h.order_id,status:h.status||h.order_status||"processing",quantity:Number(h.quantity||1)}))},fa=s=>{let a=s.api_config;if(typeof a=="string"&&a.trim())try{a=JSON.parse(a)}catch{a=void 0}return{...s,api_config:a||void 0}},it=s=>({...s,api_config:s.api_config?JSON.stringify(s.api_config):""}),Ie=async()=>{const s=await me("/cards");return(Array.isArray(s)?s:s.cards||[]).map(fa)},ja=async s=>de("/cards",it(s)),Ts=async(s,a)=>Ne(`/cards/${s}`,it(a)),Na=async s=>Oe(`/cards/${s}`),va=async s=>{const a=new FormData;return a.append("file",s),js("/cards/batch",a)},wa=async(s,a)=>de(`/cards/${s}/append-data`,{content:a}),xs=s=>s===!0||s===1||s==="1",We=async()=>{const s=await me("/items");return(Array.isArray(s)?s:s.items||[]).map(l=>({...l,id:l.id||`${l.cookie_id}-${l.item_id}`,is_multi_spec:xs(l.is_multi_spec),is_multi_qty_ship:xs(l.is_multi_qty_ship??l.multi_quantity_delivery),multi_quantity_delivery:xs(l.multi_quantity_delivery??l.is_multi_qty_ship)}))},_a=async s=>de("/items/get-all-from-account",{cookie_id:s}),ka=async(s,a)=>Oe(`/items/${s}/${a}`),Sa=async(s,a)=>de(`/items/${s}`,a),Ca=async s=>{const a=new FormData;a.set("cookie_id",s.cookie_id),a.set("title",s.title),a.set("description",s.description),a.set("price",s.price),a.set("original_price",s.original_price||""),a.set("quantity",String(s.quantity)),a.set("postage_mode",s.postage_mode),a.set("postage",s.postage||"");for(const l of s.images)a.append("images",l);return js("/items/publish",a)},$a=async s=>{const a=new FormData;return a.set("file",s.file),s.imagesZip&&a.set("images_zip",s.imagesZip),s.defaultCookieId&&a.set("default_cookie_id",s.defaultCookieId),js("/items/publish-batches/preview",a)},Ia=async s=>de("/items/publish-batches",{preview_id:s}),es=async s=>me(`/items/publish-batches/${s}`),Aa=async s=>de(`/items/publish-batches/${s}/cancel`,{}),Da=async s=>de(`/items/publish-batches/${s}/retry-failed`,{}),Pa=async(s,a,l)=>Ne(`/items/${s}/${a}`,l),rs=async()=>{const s=await me("/automation-rules");return(Array.isArray(s)?s:s.data||s.rules||[]).map(l=>{var h,g;return{id:String(l.id),name:l.name||"",trigger_type:l.trigger_type||"order_paid",item_keyword:l.item_title||l.item_id||"",cookie_id:l.cookie_id||"",item_id:l.item_id||"",item_title:l.item_title||"",card_group_id:Number(((h=(l.actions||[]).find(p=>p.action_type==="send_card"))==null?void 0:h.card_id)||0),card_group_name:((g=(l.actions||[]).find(p=>p.action_type==="send_card"))==null?void 0:g.card_name)||"",priority:l.priority||100,enabled:l.enabled||!1,config_json:l.config_json||"{}",actions:(l.actions||[]).map(p=>({id:p.id?String(p.id):void 0,action_type:p.action_type,card_id:Number(p.card_id||0),card_name:p.card_name||"",delivery_count:Number(p.delivery_count||1),message_template:p.message_template||"",delay_seconds:Number(p.delay_seconds||0),config_json:p.config_json||"{}",enabled:p.enabled!==!1,sort_order:Number(p.sort_order||0)})),variants:(l.actions||[]).filter(p=>p.action_type==="send_card").map(p=>{let k={};try{k=JSON.parse(p.config_json||"{}")}catch{}return{id:p.id?String(p.id):void 0,spec_name:k.spec_name||"",spec_value:k.spec_value||"",card_id:Number(p.card_id||0),card_name:p.card_name||"",delivery_count:Number(p.delivery_count||1),enabled:p.enabled!==!1,config_json:p.config_json||"{}"}})}})},La=(s,a)=>{if(s!=="order_paid")return a.map((g,p)=>({...g,sort_order:g.sort_order||p+1}));const l=a.filter(g=>g.action_type==="send_card").map((g,p)=>({...g,sort_order:p+1})),h=a.filter(g=>g.action_type!=="send_card"&&g.action_type!=="confirm_shipment");return[...l,...h.map((g,p)=>({...g,sort_order:l.length+p+1})),{action_type:"confirm_shipment",enabled:!0,sort_order:l.length+h.length+1}]},Ms=async s=>{const a=s.trigger_type||"order_paid",h=[{order_paid:"付款后自动发货",buyer_reviewed:"评价后发送赠品",review_missing_timeout:"超时未评价求评价"}[a]||"自动化规则",s.item_title||s.item_id||s.cookie_id||""].filter(Boolean).join(" - "),g=s.variants&&s.variants.length>0?s.variants.map((_,u)=>({action_type:"send_card",card_id:_.card_id,delivery_count:_.delivery_count||1,enabled:_.enabled!==!1,sort_order:u+1,config_json:JSON.stringify({spec_name:_.spec_name||"",spec_value:_.spec_value||""})})):s.actions&&s.actions.length>0?s.actions:[{action_type:"send_card",card_id:s.card_group_id||0,delivery_count:1,enabled:!0,sort_order:1}],p=La(a,g),k={cookie_id:s.cookie_id||"",item_id:s.item_id||"",name:(s.name||"").trim()||h||"自动化规则",trigger_type:a,enabled:s.enabled??!0,priority:s.priority||100,config_json:s.config_json||"{}",actions:p.map((_,u)=>({action_type:_.action_type,card_id:_.card_id||0,delivery_count:_.delivery_count||1,message_template:_.message_template||"",delay_seconds:_.delay_seconds||0,config_json:_.config_json||"{}",enabled:_.enabled!==!1,sort_order:_.sort_order||u+1}))};return s.id?Ne(`/automation-rules/${s.id}`,k):de("/automation-rules",k)},Fa=async s=>Oe(`/automation-rules/${s}`),Ea=s=>({keyword:(s==null?void 0:s.keyword)||"",reply:(s==null?void 0:s.reply)||"",item_id:(s==null?void 0:s.item_id)||"",type:(s==null?void 0:s.type)==="image"?"image":"text",image_url:(s==null?void 0:s.image_url)||""}),vs=async s=>{const a=await me(`/keywords-with-type/${s}`);return Array.isArray(a)?a.map(Ea):[]},Ra=async s=>s?(await vs(s)).map((l,h)=>({id:String(h),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||""})):[],Oa=async(s,a)=>{const l=await vs(a);if(s.id){const h=parseInt(s.id);if(h>=0&&h<l.length){const g=l[h];l[h]={...g,keyword:s.keyword??g.keyword,reply:s.reply_content??g.reply,item_id:s.item_id??g.item_id,type:s.type??g.type,image_url:s.image_url??g.image_url}}}else l.push({keyword:s.keyword||"",reply:s.reply_content||"",item_id:s.item_id||"",type:s.type||"text",image_url:s.image_url||""});return de(`/keywords-with-item-id/${a}`,{keywords:l})},Ta=async(s,a)=>{const l=await vs(a),h=parseInt(s);return h>=0&&h<l.length&&l.splice(h,1),de(`/keywords-with-item-id/${a}`,{keywords:l})},ot=async()=>{const s=await me("/system-settings");return Yt(s.data||s)},dt=async s=>{const a=Object.entries(s).filter(([,l])=>l!=null).map(([l,h])=>Ne(`/system-settings/${l}`,{value:String(h)}));return await Promise.all(a),{success:!0,message:"Settings saved"}},Ma=async s=>me(`/ai-reply-settings/${s}`),qa=async(s,a)=>{const l={ai_enabled:a.ai_enabled??!1,max_discount_percent:a.max_discount_percent??10,max_discount_amount:a.max_discount_amount??100,max_bargain_rounds:a.max_bargain_rounds??3,custom_prompts:a.custom_prompts??""};return Ne(`/ai-reply-settings/${s}`,l)},Ba=async(s,a="")=>(await de("/ai-models",{base_url:s,api_key:a})).models||[],za=s=>{if(Array.isArray(s))return s.filter(Boolean);if(typeof s!="string"||!s.trim())return[];try{const a=JSON.parse(s);if(Array.isArray(a))return a.filter(Boolean)}catch{}return s.split(/[,\s;]+/).map(a=>a.trim()).filter(Boolean)},ct=s=>{const a=Array.from(new Set((s||[]).filter(Boolean)));return a.length>0?JSON.stringify(a):""},xt=async()=>({success:!0,data:(await me("/notification-channels")||[]).map(l=>{let h;try{h=typeof l.config=="string"?JSON.parse(l.config):l.config}catch{h=void 0}return{id:String(l.id),name:l.name,type:l.type==="ding_talk"?"dingtalk":l.type,config:h,event_types:za(l.event_types),enabled:l.enabled,created_at:l.created_at,updated_at:l.updated_at}})}),Ua=async s=>de("/notification-channels",{...s,config:JSON.stringify(s.config),event_types:ct(s.event_types)}),qs=async(s,a)=>{const l={...a};return"config"in a&&(l.config=JSON.stringify(a.config)),"event_types"in a&&(l.event_types=ct(a.event_types)),Ne(`/notification-channels/${s}`,l)},Wa=async s=>Oe(`/notification-channels/${s}`),Ja=async s=>{const a=await me(`/message-notifications/${s}`);return(a==null?void 0:a.channel_ids)||[]},Va=async(s,a)=>de(`/message-notifications/${s}`,{channel_ids:a}),Qa=async s=>de(`/notification-channels/${s}/test`,{}),Bs=async()=>me("/api/default-replies"),Ya=async s=>{const a=await me(`/api/default-reply/${s}`);return{cookie_id:s,enabled:a.enabled||!1,reply_content:a.reply_content||"",reply_once:a.reply_once||!1,reply_image_url:a.reply_image_url||""}},Ka=async(s,a)=>Ne(`/api/default-reply/${s}`,{enabled:a.enabled??!1,reply_content:a.reply_content||"",reply_once:a.reply_once??!1,reply_image_url:a.reply_image_url||""}),Ga=async s=>Oe(`/api/default-reply/${s}`),Xa=async s=>de(`/api/default-reply/${s}/clear-records`,{}),Za=({status:s})=>{const a={processing:"bg-blue-100 text-blue-800",pending_ship:"bg-[#0094f7] 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"},l={processing:"处理中",pending_ship:"待发货",shipped:"已发货",completed:"已完成",cancelled:"已取消",refunding:"退款中"};return e.jsx("span",{className:`px-3 py-1.5 rounded-lg text-xs font-bold ${a[s]||a.cancelled}`,children:l[s]||s})},ss=({title:s,value:a,icon:l,colorClass:h,trend:g})=>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 ${h} 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 ${h} bg-opacity-10 backdrop-blur-sm`,children:e.jsx(l,{className:`w-6 h-6 ${h.replace("bg-","text-")}`})}),g&&e.jsxs("span",{className:"text-xs font-bold text-white bg-[#0094f7] px-3 py-1.5 rounded-full flex items-center gap-1 shadow-sm",children:[e.jsx(vt,{className:"w-3 h-3"})," ",g]})]}),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:a}),e.jsx("p",{className:"text-gray-500 text-sm font-medium mt-1",children:s})]})]}),ms=()=>{var ne,ae;const[s,a]=d.useState(null),[l,h]=d.useState(null),[g,p]=d.useState("7days"),[k,_]=d.useState(""),[u,q]=d.useState(""),[b,Y]=d.useState(null),[te,B]=d.useState(""),[Q,T]=d.useState([]),[Z,H]=d.useState(!1),[E,X]=d.useState([]),[ee,I]=d.useState({}),J=["#0094f7","#3B82F6","#10B981","#F59E0B","#8B5CF6"],U=c=>{const f=c.getFullYear(),V=String(c.getMonth()+1).padStart(2,"0"),le=String(c.getDate()).padStart(2,"0");return`${f}-${V}-${le}`},v=c=>{const f=new Date,V=U(f);let le=V;if(c==="yesterday"){const M=new Date(f);M.setDate(M.getDate()-1);const ge=U(M);return{startDate:ge,endDate:ge}}if(c==="3days"){const M=new Date(f);M.setDate(M.getDate()-3),le=U(M)}else if(c==="7days"){const M=new Date(f);M.setDate(M.getDate()-7),le=U(M)}else if(c==="30days"){const M=new Date(f);M.setDate(M.getDate()-30),le=U(M)}else{if(c==="custom"&&k&&u)return{startDate:k,endDate:u};if(c==="custom"){const M=new Date(f);M.setDate(M.getDate()-7),le=U(M)}}return{startDate:le,endDate:V}},F=c=>{const{startDate:f,endDate:V}=v(c);H(!0),ya({start_date:f,end_date:V}).then(T).catch(console.error).finally(()=>H(!1))},o=c=>{const f=new Date,{startDate:V,endDate:le}=v(c),M={start_date:V,end_date:le},ge=C(c,f);ge&&Os(ge).then(Y).catch(console.error),Os(M).then(h).catch(console.error)},C=(c,f)=>{switch(f.getFullYear(),String(f.getMonth()+1).padStart(2,"0"),String(f.getDate()).padStart(2,"0"),c){case"today":const V=new Date(f);V.setDate(V.getDate()-1);const le=V.getFullYear(),M=String(V.getMonth()+1).padStart(2,"0"),ge=String(V.getDate()).padStart(2,"0");return{start_date:`${le}-${M}-${ge}`,end_date:`${le}-${M}-${ge}`};case"yesterday":const ve=new Date(f);ve.setDate(ve.getDate()-2);const be=ve.getFullYear(),_e=String(ve.getMonth()+1).padStart(2,"0"),Ce=String(ve.getDate()).padStart(2,"0");return{start_date:`${be}-${_e}-${Ce}`,end_date:`${be}-${_e}-${Ce}`};case"7days":const we=new Date(f);we.setDate(we.getDate()-7);const ye=new Date(we);return ye.setDate(ye.getDate()-7),{start_date:`${ye.getFullYear()}-${String(ye.getMonth()+1).padStart(2,"0")}-${String(ye.getDate()).padStart(2,"0")}`,end_date:`${we.getFullYear()}-${String(we.getMonth()+1).padStart(2,"0")}-${String(we.getDate()).padStart(2,"0")}`};case"30days":const fe=new Date(f);fe.setDate(fe.getDate()-30);const t=new Date(fe);return t.setDate(t.getDate()-30),{start_date:`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")}`,end_date:`${fe.getFullYear()}-${String(fe.getMonth()+1).padStart(2,"0")}-${String(fe.getDate()).padStart(2,"0")}`};default:return null}},re=()=>{if(!l||!b)return null;const c=l.revenue_stats.total_amount,f=b.revenue_stats.total_amount;if(f===0)return c>0?"+100%":"0%";const V=(c-f)/f*100;return`${V>=0?"+":""}${V.toFixed(1)}%`};if(d.useEffect(()=>{ba().then(a).catch(console.error),o(g),We().then(c=>{X(c);const f={};c.forEach(V=>{f[V.item_id]=V.item_title||V.item_id}),I(f)}).catch(console.error)},[g]),d.useEffect(()=>{F(g)},[g]),!s||!l)return e.jsx("div",{className:"p-8 flex justify-center text-gray-400",children:e.jsx(ws,{className:"w-8 h-8 animate-spin text-[#0094f7]"})});const K=((ne=l.daily_stats)==null?void 0:ne.map(c=>({name:c.date.slice(5),amount:c.amount,orders:c.order_count,avgAmount:c.order_count>0?(c.amount/c.order_count).toFixed(2):0})))||[],z=l.item_stats||[],S=l.revenue_stats.total_orders||0,A=l.revenue_stats.total_amount||0,W=z.length>0?z.map(c=>({name:(ee[c.item_id]||c.item_id).length>12?(ee[c.item_id]||c.item_id).substring(0,12)+"...":ee[c.item_id]||c.item_id,sales:c.order_count})).sort((c,f)=>f.sales-c.sales).slice(0,10):[],m=Math.max(...W.map(c=>c.sales),1),x=z.length>0?z.map(c=>({name:(ee[c.item_id]||c.item_id).length>10?(ee[c.item_id]||c.item_id).substring(0,10)+"...":ee[c.item_id]||c.item_id,value:c.order_count,percent:S>0?c.order_count/S*100:0})).sort((c,f)=>f.value-c.value).slice(0,6).map((c,f)=>({...c,color:J[f%J.length]})):[],P=z.length>0?z.map(c=>({name:(ee[c.item_id]||c.item_id).length>12?(ee[c.item_id]||c.item_id).substring(0,12)+"...":ee[c.item_id]||c.item_id,value:c.total_amount,orderCount:c.order_count,percentage:A>0?c.total_amount/A*100:0})).sort((c,f)=>f.value-c.value).slice(0,5).map((c,f)=>({...c,color:J[f%J.length],percentage:c.percentage.toFixed(1)})):[],N=[{key:"today",label:"今天"},{key:"yesterday",label:"昨天"},{key:"3days",label:"三天内"},{key:"7days",label:"7天内"},{key:"30days",label:"一个月内"},{key:"custom",label:"自定义"}],se=((ae=N.find(c=>c.key===g))==null?void 0:ae.label)||"所选范围",D=v(g),i=te.trim().toLowerCase(),R=Q.filter(c=>{var f,V,le,M;return((f=c.order_id)==null?void 0:f.toLowerCase().includes(i))||((V=c.item_id)==null?void 0:V.toLowerCase().includes(i))||((le=c.item_title)==null?void 0:le.toLowerCase().includes(i))||((M=c.buyer_id)==null?void 0:M.toLowerCase().includes(i))});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:[N.map(c=>e.jsx("button",{onClick:()=>p(c.key),className:`px-5 py-2.5 rounded-xl text-sm font-bold transition-all ${g===c.key?"bg-[#0094f7] text-white shadow-md":"bg-white text-gray-600 hover:text-black hover:bg-gray-50"}`,children:c.label},c.key)),g==="custom"&&e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"date",value:k,onChange:c=>_(c.target.value),className:"px-3 py-2 rounded-xl text-sm border border-gray-200 focus:outline-none focus:ring-2 focus:ring-[#0094f7]"}),e.jsx("span",{className:"self-center text-gray-400",children:"-"}),e.jsx("input",{type:"date",value:u,onChange:c=>q(c.target.value),className:"px-3 py-2 rounded-xl text-sm border border-gray-200 focus:outline-none focus:ring-2 focus:ring-[#0094f7]"}),e.jsx("button",{onClick:()=>{o("custom"),F("custom")},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(ss,{title:"累计营收 (CNY)",value:`¥${l.revenue_stats.total_amount.toLocaleString("zh-CN",{minimumFractionDigits:2})}`,icon:Nt,colorClass:"bg-blue-400",trend:re()||void 0}),e.jsx(ss,{title:"活跃账号 / 总数",value:`${s.active_cookies} / ${s.total_cookies}`,icon:Ks,colorClass:"bg-blue-500"}),e.jsx(ss,{title:"订单数",value:l.revenue_stats.total_orders.toLocaleString(),icon:_s,colorClass:"bg-blue-500"}),e.jsx(ss,{title:"库存卡密余量",value:s.total_cards,icon:Hs,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:[se,"的销售额走势"]})]}),e.jsx("div",{className:"h-[350px] w-full",children:K.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(_s,{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:"所选时间范围内暂无订单记录"})]}):K.length<=2?e.jsx(He,{width:"100%",height:"100%",children:e.jsxs(qt,{data:K,margin:{top:30,right:20,left:0,bottom:30},barCategoryGap:"45%",children:[e.jsx(Ds,{dataKey:"name",axisLine:!1,tickLine:!1,tick:{fill:"#374151",fontSize:14,fontWeight:600},dy:10}),e.jsx(Ps,{axisLine:!1,tickLine:!1,tick:{fill:"#9CA3AF",fontSize:13,fontWeight:500},tickFormatter:c=>`¥${c}`}),e.jsx(ds,{contentStyle:{backgroundColor:"#fff",borderRadius:"8px",border:"1px solid #e5e7eb",boxShadow:"0 10px 25px -5px rgba(0, 0, 0, 0.1)",padding:"12px 16px"},labelStyle:{color:"#6b7280",fontWeight:500},itemStyle:{color:"#0094f7",fontWeight:600},cursor:{fill:"rgba(0, 148, 247, 0.08)"},formatter:c=>[`¥${Number(c).toFixed(2)}`,"营收"]}),e.jsx(Bt,{dataKey:"amount",fill:"#0094f7",maxBarSize:72,radius:[12,12,0,0],stroke:"#000000",strokeWidth:0,children:K.map((c,f)=>e.jsx(cs,{fill:["#0094f7","#FCD34D","#0071e3"][f%3]},`cell-${f}`))})]})}):e.jsx(He,{width:"100%",height:"100%",children:e.jsxs(zt,{data:K,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:"#0094f7",stopOpacity:.5}),e.jsx("stop",{offset:"95%",stopColor:"#0094f7",stopOpacity:0})]})}),e.jsx(Ds,{dataKey:"name",axisLine:!1,tickLine:!1,tick:{fill:"#9CA3AF",fontSize:13,fontWeight:500},dy:15}),e.jsx(Ps,{axisLine:!1,tickLine:!1,tick:{fill:"#9CA3AF",fontSize:13,fontWeight:500}}),e.jsx(Ut,{vertical:!1,stroke:"#F3F4F6",strokeDasharray:"3 3"}),e.jsx(ds,{contentStyle:{backgroundColor:"#fff",borderRadius:"8px",border:"1px solid #e5e7eb",boxShadow:"0 10px 25px -5px rgba(0, 0, 0, 0.1)",padding:"12px 16px"},labelStyle:{color:"#6b7280",fontWeight:500},itemStyle:{color:"#0094f7",fontWeight:600},cursor:{stroke:"#0094f7",strokeWidth:2,strokeDasharray:"4 4"}}),e.jsx(Wt,{type:"monotone",dataKey:"amount",stroke:"#0094f7",strokeWidth:4,fillOpacity:1,fill:"url(#colorAmount)",activeDot:{r:8,fill:"#fff",stroke:"#0094f7",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:W.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:W.map((c,f)=>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 ${f<3?"bg-blue-600 text-white":"bg-gray-100 text-gray-500"}`,children:f+1}),e.jsx("span",{className:"font-bold text-gray-800 text-sm truncate",children:c.name})]}),e.jsxs("span",{className:"font-mono text-sm font-extrabold text-gray-900",children:[c.sales," 单"]})]}),e.jsx("div",{className:"h-3 rounded-full bg-gray-100 overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-[#0094f7]",style:{width:`${Math.max(8,c.sales/m*100)}%`}})})]},`${c.name}-${f}`))})})]}),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:x.length===0?e.jsx("div",{className:"flex items-center justify-center h-full text-gray-400",children:"暂无数据"}):e.jsx(He,{width:"100%",height:"100%",children:e.jsxs(Ls,{children:[e.jsx(Fs,{data:x,cx:"50%",cy:"50%",innerRadius:60,outerRadius:90,paddingAngle:2,dataKey:"value",label:({name:c,payload:f})=>`${c} ${Number((f==null?void 0:f.percent)||0).toFixed(1)}%`,labelLine:!1,children:x.map((c,f)=>e.jsx(cs,{fill:c.color},`cell-${f}`))}),e.jsx(Jt,{verticalAlign:"bottom",height:36,iconType:"circle",formatter:c=>e.jsx("span",{style:{color:"#6B7280",fontWeight:500},children:c})})]})})})]})]}),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-[#FAFAFA]",children:[e.jsx("h3",{className:"font-bold text-lg text-gray-900",children:"参与统计的订单"}),e.jsx("div",{className:"relative",children:e.jsx("input",{placeholder:"搜索订单号/商品/买家...",value:te,onChange:c=>B(c.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:Z?e.jsxs("div",{className:"flex items-center justify-center py-20 text-gray-400",children:[e.jsx(ws,{className:"w-6 h-6 animate-spin mr-2"}),"加载中..."]}):R.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(Xe,{className:"w-7 h-7 text-gray-300"})}),i?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:["当前共有 ",Q.length," 单参与统计,但没有订单号、商品、买家匹配“",te,"”。"]})]}):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:["日期范围:",D.startDate," 至 ",D.endDate,"; 统计口径:待发货、已发货、已完成,且订单金额不为空。 当前统计卡片订单数:",l.revenue_stats.total_orders," 单。"]})]})]}):e.jsxs("table",{className:"w-full 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",children:"状态"}),e.jsx("th",{className:"px-6 py-4 text-right",children:"操作"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50",children:R.map(c=>e.jsxs("tr",{className:"hover:bg-[#FFFDE7]/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(Xe,{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:c.item_title||c.item_id||"未知商品"}),e.jsx("div",{className:"text-xs text-gray-500 mt-1 font-mono",children:c.order_id}),e.jsxs("div",{className:"text-xs text-gray-400 mt-0.5",children:["数量: ",c.quantity||1]})]})]})}),e.jsxs("td",{className:"px-6 py-4",children:[e.jsx("div",{className:"text-sm font-bold text-gray-800",children:c.buyer_id}),c.created_at&&e.jsx("div",{className:"text-xs text-gray-400 mt-1",children:c.created_at})]}),e.jsxs("td",{className:"px-6 py-4 text-base font-extrabold text-gray-900 font-feature-settings-tnum",children:["¥",c.amount||"0.00"]}),e.jsx("td",{className:"px-6 py-4",children:e.jsx(Za,{status:c.status||c.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=${c.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(et,{className:"w-4 h-4"})})})]},c.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)"}),P.length===0?e.jsx("div",{className:"flex items-center justify-center h-[300px] text-gray-400",children:"暂无数据"}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-[300px] relative",children:e.jsx(He,{width:"100%",height:"100%",children:e.jsxs(Ls,{children:[e.jsx(Fs,{data:P,cx:"50%",cy:"50%",innerRadius:60,outerRadius:100,paddingAngle:2,dataKey:"value",label:({name:c,payload:f})=>`${c} ${(f==null?void 0:f.percentage)||"0.0"}%`,children:P.map((c,f)=>e.jsx(cs,{fill:c.color||J[f%J.length]},`cell-${f}`))}),e.jsx(ds,{contentStyle:{backgroundColor:"#fff",border:"1px solid #e5e7eb",borderRadius:"6px",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.1)"},formatter:c=>`¥${c.toLocaleString()}`})]})})}),e.jsx("div",{className:"space-y-3 mt-4",children:P.map(c=>e.jsxs("div",{className:"flex justify-between items-center text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:c.color||J[P.indexOf(c)%J.length]}}),e.jsx("span",{className:"text-gray-600 font-medium",children:c.name})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"font-bold text-gray-900",children:["¥",c.value.toLocaleString()]}),e.jsxs("span",{className:"text-xs text-gray-500 bg-gray-100 px-2 py-0.5 rounded",children:[c.percentage,"%"]})]})]},c.name))})]})]})]})]})},Ha=(s,a)=>{const l=a.username!==(s.username||""),h=a.show_browser!==(s.show_browser||!1),g=a.login_password!=="",p=a.clear_password===!0;if(!l&&!h&&!g&&!p)return null;const k={username:a.username,show_browser:a.show_browser};return p?k.clear_password=!0:g&&(k.login_password=a.login_password),k},el=new Set(["expired","cancelled","error","not_found"]),sl=(s={setInterval:globalThis.setInterval.bind(globalThis),clearInterval:globalThis.clearInterval.bind(globalThis)})=>{let a=null;const l=()=>{a!==null&&(s.clearInterval(a),a=null)};return{start:(g,p,k,_=2e3)=>{l(),a=s.setInterval(()=>{(async()=>{var u,q;try{const b=await p(g);if(b.status==="success"){l(),await k.onSuccess(b);return}if(b.status==="scanned"){(u=k.onScanned)==null||u.call(k,b);return}if(b.status==="verification_required"){(q=k.onVerificationRequired)==null||q.call(k,b);return}b.status&&el.has(b.status)&&(l(),k.onTerminalError(b))}catch(b){l(),k.onPollError(b)}})()},_)},stop:l,isActive:()=>a!==null}},tl=()=>{const[s,a]=d.useState([]),[l,h]=d.useState(!0),[g,p]=d.useState(""),[k,_]=d.useState(""),[u,q]=d.useState(!1),[b,Y]=d.useState(""),[te,B]=d.useState("pending"),[Q,T]=d.useState(""),[Z,H]=d.useState(""),[E,X]=d.useState(""),[ee,I]=d.useState(""),[J,U]=d.useState(null),[v,F]=d.useState(null),[o,C]=d.useState(null),[re,K]=d.useState([]),[z,S]=d.useState([]),[A,W]=d.useState({remark:"",cookie:"",auto_confirm:!1,pause_duration:0,username:"",login_password:"",show_browser:!1,showLoginPassword:!1,clear_password:!1}),[m,x]=d.useState({ai_enabled:!1,max_discount_percent:10,max_discount_amount:100,max_bargain_rounds:3,custom_prompts:""}),[P,N]=d.useState(!1),se=d.useRef(null),D=d.useRef(null);se.current===null&&(se.current=sl());const i=()=>{D.current!==null&&(window.clearTimeout(D.current),D.current=null)},R=()=>{var t;(t=se.current)==null||t.stop()},ne=()=>{R(),i(),q(!1)},ae=()=>{i(),D.current=window.setTimeout(()=>{D.current=null,q(!1),f()},1e3)},c=async()=>{try{const t=await ea();a(y=>y.map($=>{const O=t[$.id];return O?{...$,runtime_state:O.state,runtime_message:O.message||"",runtime_connected:O.connected,runtime_updated_at:O.updated_at}:$}))}catch(t){console.error("Failed to load account runtime statuses:",t)}},f=async()=>{h(!0);try{const t=await Ns();let y={};try{y=await ca()}catch(O){console.error("Failed to load AI settings:",O)}const $=t.map(O=>{var oe,r,L,ie,$e;return{...O,ai_enabled:((oe=y[O.id])==null?void 0:oe.ai_enabled)??!1,max_discount_percent:((r=y[O.id])==null?void 0:r.max_discount_percent)??10,max_discount_amount:((L=y[O.id])==null?void 0:L.max_discount_amount)??100,max_bargain_rounds:((ie=y[O.id])==null?void 0:ie.max_bargain_rounds)??3,custom_prompts:(($e=y[O.id])==null?void 0:$e.custom_prompts)??""}});a($),window.setTimeout(c,0)}catch(t){console.error("Failed to load accounts:",t)}finally{h(!1)}};d.useEffect(()=>{f();const t=window.setInterval(c,1e4);return()=>window.clearInterval(t)},[]),d.useEffect(()=>()=>{R(),i()},[]);const V=t=>{if(!t.enabled||t.runtime_state==="disabled")return{label:"已停用",badge:"bg-gray-100 text-gray-500",dot:"bg-gray-300"};switch(t.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"}}},le=async(t,y)=>{await aa(t,!y),f()},M=async t=>{confirm("确认删除该账号吗?")&&(await la(t),f())},ge=async t=>{_(t.id);try{const y=await oa(t.id);y!=null&&y.profile_error&&alert("资料刷新失败:"+y.profile_error),await f()}catch(y){console.error("刷新账号资料失败:",y),alert((y==null?void 0:y.message)||"刷新账号资料失败,请先重新授权该账号")}finally{_("")}},ve=async t=>{C(t),W({remark:t.remark||t.note||"",cookie:t.cookie||t.value||"",auto_confirm:t.auto_confirm||!1,pause_duration:t.pause_duration||0,username:t.username||"",login_password:t.login_password||"",show_browser:t.show_browser||!1,showLoginPassword:!1,clear_password:!1}),F("edit");try{const[y,$]=await Promise.all([xt(),Ja(t.id).catch(()=>[])]);K(y.data||[]),S($||[])}catch(y){console.error("加载通知渠道绑定失败",y),K([]),S([])}},be=async t=>{C(t),N(!0);try{const y=await Ma(t.id);x({ai_enabled:y.ai_enabled??!1,max_discount_percent:y.max_discount_percent??10,max_discount_amount:y.max_discount_amount??100,max_bargain_rounds:y.max_bargain_rounds??3,custom_prompts:y.custom_prompts??""})}catch(y){console.error("Failed to load AI settings:",y)}finally{N(!1)}F("ai-settings")},_e=async()=>{if(o){N(!0);try{const t=[];A.remark!==(o.remark||o.note||"")&&t.push(ra(o.id,A.remark)),A.cookie&&A.cookie!==(o.cookie||o.value||"")&&t.push(Es(o.id,A.cookie)),A.auto_confirm!==o.auto_confirm&&t.push(na(o.id,A.auto_confirm)),A.pause_duration!==(o.pause_duration||0)&&t.push(ia(o.id,A.pause_duration));const y=Ha(o,A);y&&t.push(da(o.id,y)),t.push(Va(o.id,z)),await Promise.all(t),F(null),f()}catch(t){console.error("更新账号失败:",t),alert("更新失败,请重试")}finally{N(!1)}}},Ce=async()=>{if(o){N(!0);try{await qa(o.id,m),F(null),f()}catch(t){console.error("更新AI设置失败:",t),alert("更新失败,请重试")}finally{N(!1)}}},we=async(t,y,$)=>{if($){if(y&&y!==$.id&&!confirm(`扫码返回的账号ID是 ${y},当前要重新授权的是 ${$.id}。确认用本次扫码结果覆盖当前账号授权吗?`))throw new Error("已取消覆盖当前账号授权");return await Es($.id,t,"qr_scan"),$.id}if(!y)throw new Error("扫码结果缺少账号ID,无法添加账号");return await Zt(y,t,"qr_scan"),y},ye=async t=>{var $;R(),i();const y=t||null;U(y),q(!0),B("loading"),Y(""),I(""),T(""),H(""),X("");try{const O=await sa();O.success&&O.qr_code_url&&O.session_id&&(Y(O.qr_code_url),I(O.session_id),B("waiting"),($=se.current)==null||$.start(O.session_id,ta,{onSuccess:async oe=>{if(B("success"),oe.cookies&&oe.unb)try{await we(oe.cookies,oe.unb,y)}catch(r){console.error("保存扫码授权失败",r),B("error");return}ae()},onScanned:()=>{B("waiting")},onTerminalError:()=>{B("error")},onPollError:oe=>{console.error("轮询扫码状态失败",oe),B("error")},onVerificationRequired:oe=>{B("verification"),T(oe.verification_url||""),oe.face_qr_url&&X(oe.face_qr_url),oe.verification_screenshot&&H(oe.verification_screenshot)}}))}catch{B("error")}};if(l)return e.jsx("div",{className:"p-20 flex justify-center",children:e.jsx(ke,{className:"w-8 h-8 text-[#0094f7] animate-spin"})});const fe=s.filter(t=>{const y=g.trim().toLowerCase();return y?[t.id,t.nickname,t.remark,t.note,t.username,t.runtime_message].some($=>($||"").toLowerCase().includes(y)):!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:g,onChange:t=>p(t.target.value),placeholder:"搜索昵称 / 备注 / 账号ID",className:"ios-input px-4 py-3 rounded-2xl text-sm w-full sm:w-72"}),e.jsxs("button",{onClick:()=>ye(),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(is,{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:["当前显示 ",fe.length," / ",s.length," 个账号"]}),e.jsx("div",{className:"text-blue-700",children:"如果某个账号只显示 ID,点该账号右侧“刷新资料”;若刷新失败,先点二维码重新授权。"})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-6",children:[fe.map(t=>{const y=V(t),$=t.runtime_state==="auth_expired"||t.runtime_state==="verification_required";return e.jsxs("div",{className:"ios-card p-6 rounded-xl flex flex-col lg:flex-row lg:items-center justify-between gap-5 group hover:border-[#0094f7] transition-all duration-300",children:[e.jsxs("div",{className:"flex items-center gap-5 sm:gap-8 min-w-0",children:[e.jsxs("div",{className:"relative",children:[t.avatar_url?e.jsx("img",{src:t.avatar_url,alt:t.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(gs,{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 ${y.dot}`,children:t.runtime_state==="online"&&e.jsx(Ae,{className:"w-3 h-3 text-white"})})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3 mb-1",children:[e.jsx("h3",{className:"text-xl font-extrabold text-gray-900 break-words",children:t.nickname||t.remark||`账号 ${t.id.substring(0,6)}...`}),e.jsx("span",{className:`px-2.5 py-0.5 rounded-lg text-xs font-bold ${y.badge}`,children:y.label}),t.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(qe,{className:"w-3 h-3"})," AI"]}),t.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:t.profile_error,children:[e.jsx(ls,{className:"w-3 h-3"})," 资料未同步"]})]}),e.jsxs("div",{className:"text-sm text-gray-500 font-medium mb-3 space-y-1",children:[e.jsx("p",{children:t.remark||t.note||"暂无备注"}),e.jsxs("p",{className:"font-mono text-xs text-gray-400",children:["ID: ",t.id]})]}),t.runtime_message&&t.runtime_state!=="online"&&t.runtime_state!=="disabled"&&e.jsxs("div",{className:`mb-3 flex flex-wrap items-center gap-2 text-sm font-medium ${$?"text-red-700":"text-amber-700"}`,children:[e.jsx(ls,{className:"w-4 h-4 flex-shrink-0"}),e.jsx("span",{children:t.runtime_message}),$&&e.jsxs("button",{type:"button",onClick:()=>ye(t),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(is,{className:"w-3.5 h-3.5"})," 重新授权"]})]}),e.jsxs("div",{className:"flex gap-2",children:[t.auto_confirm&&e.jsxs("span",{className:"text-xs bg-blue-50 text-blue-700 px-3 py-1.5 rounded-lg font-bold flex items-center gap-1.5",children:[e.jsx(Ae,{className:"w-3 h-3"})," 自动确认发货"]}),t.pause_duration>0&&e.jsxs("span",{className:"text-xs bg-blue-50 text-blue-700 px-3 py-1.5 rounded-lg font-bold flex items-center gap-1.5",children:[e.jsx(ks,{className:"w-3 h-3"})," 暂停",t.pause_duration,"分钟"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-3 self-end lg:self-auto flex-shrink-0",children:[e.jsx("button",{onClick:()=>ge(t),disabled:k===t.id,className:"p-3 rounded-xl transition-colors text-gray-600 hover:bg-gray-100 disabled:opacity-50",title:"刷新昵称和头像",children:e.jsx(Se,{className:`w-5 h-5 ${k===t.id?"animate-spin":""}`})}),e.jsx("button",{onClick:()=>ye(t),className:`p-3 rounded-xl transition-colors ${$?"text-red-600 bg-red-50 hover:bg-red-100":"text-blue-600 hover:bg-blue-50"}`,title:"重新扫码授权当前账号",children:e.jsx(is,{className:"w-5 h-5"})}),e.jsx("button",{onClick:()=>ve(t),className:"p-3 rounded-xl hover:bg-gray-100 transition-colors text-gray-600",title:"编辑账号",children:e.jsx(st,{className:"w-5 h-5"})}),e.jsx("button",{onClick:()=>be(t),className:"p-3 rounded-xl hover:bg-purple-100 transition-colors text-purple-600",title:"AI设置",children:e.jsx(qe,{className:"w-5 h-5"})}),e.jsx("button",{onClick:()=>le(t.id,t.enabled),className:`p-3 rounded-xl transition-colors ${t.enabled?"text-green-600 hover:bg-green-50":"text-gray-400 hover:bg-gray-100"}`,title:t.enabled?"停用账号":"启用账号",children:e.jsx(wt,{className:"w-5 h-5"})}),e.jsx("button",{onClick:()=>M(t.id),className:"p-3 rounded-xl hover:bg-red-100 transition-colors text-red-500",children:e.jsx(De,{className:"w-5 h-5"})})]})]},t.id)}),s.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(gs,{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:"请点击右上角扫码添加您的闲鱼账号"})]}),s.length>0&&fe.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。"})]})]}),u&&he.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container relative",style:{maxWidth:"24rem"},children:[e.jsx("button",{onClick:ne,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(pe,{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:J?"重新授权账号":"扫码添加账号"}),e.jsx("p",{className:"text-gray-500 mb-8 font-medium",children:J?`请用闲鱼APP扫码,为「${J.nickname||J.remark||J.id}」刷新授权`:"请打开闲鱼APP扫描下方二维码"}),e.jsxs("div",{className:"w-64 h-64 bg-[#F7F8FA] rounded-xl mx-auto flex items-center justify-center overflow-hidden border-4 border-white shadow-inner mb-8 relative",children:[te==="loading"&&e.jsx(ke,{className:"w-10 h-10 text-[#0094f7] animate-spin"}),te==="waiting"&&e.jsx("img",{src:b,alt:"QR Code",className:"w-full h-full p-2"}),te==="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(Ae,{className:"w-8 h-8"})}),e.jsx("span",{className:"font-bold text-lg",children:"登录成功"})]}),te==="error"&&e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("span",{className:"text-red-500 font-bold mb-2",children:"获取失败"}),e.jsxs("button",{onClick:()=>ye(J||void 0),className:"text-xs bg-gray-200 px-3 py-1 rounded-full flex items-center gap-1 hover:bg-gray-300",children:[e.jsx(Se,{className:"w-3 h-3"})," 重试"]})]}),te==="verification"&&e.jsxs("div",{className:"flex flex-col items-center px-4",children:[e.jsx("span",{className:"font-bold text-gray-900 mb-2",children:"需要安全验证"}),e.jsx("span",{className:"text-xs text-gray-500 mb-3 text-center",children:E?"请用手机闲鱼扫描下方二维码完成人脸验证,验证通过后将自动登录。":"正在准备验证二维码,请保持页面打开。"}),E?e.jsx("img",{src:E,alt:"人脸验证二维码",className:"w-full max-w-[210px] rounded-xl border bg-white p-2 mb-2"}):Z?e.jsx("img",{src:Z,alt:"验证页面",className:"w-full rounded-xl border mb-2",style:{maxHeight:200,objectFit:"contain"}}):e.jsx("div",{className:"w-full h-32 bg-gray-100 rounded-xl flex items-center justify-center mb-2",children:e.jsx(ke,{className:"w-6 h-6 animate-spin text-gray-400"})}),e.jsx("span",{className:"text-xs text-gray-400",children:"等待手机验证完成,无需点击确认。"})]})]}),e.jsx("p",{className:"text-xs text-gray-400 font-medium bg-gray-50 py-2 rounded-xl",children:"二维码有效期为5分钟,请尽快扫码。"})]})})]})}),document.body),v==="edit"&&o&&he.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:o.nickname||o.remark||o.id})]}),e.jsx("button",{onClick:()=>F(null),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors flex-shrink-0",children:e.jsx(pe,{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:o.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:A.remark,onChange:t=>W({...A,remark:t.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:A.cookie,onChange:t=>W({...A,cookie:t.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长度: ",A.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(Ae,{className:"w-4 h-4 text-green-500"}),"自动确认发货"]}),e.jsx("div",{className:"text-xs text-gray-500",children:"自动将闲鱼订单标记为已发货"})]}),e.jsx("button",{type:"button",onClick:()=>W({...A,auto_confirm:!A.auto_confirm}),className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${A.auto_confirm?"bg-[#0094f7]":"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 ${A.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(ks,{className:"w-4 h-4 text-blue-500"}),"暂停处理时长(分钟)"]}),e.jsx("input",{type:"number",value:A.pause_duration,onChange:t=>W({...A,pause_duration:parseInt(t.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:"设置后会暂停处理该账号的订单,到时间后自动恢复"})]}),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(_t,{className:"w-5 h-5 text-blue-500"}),"登录信息"]}),e.jsxs("div",{className:"space-y-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:A.username,onChange:t=>W({...A,username:t.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:A.showLoginPassword?"text":"password",value:A.login_password,onChange:t=>W({...A,login_password:t.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:()=>W({...A,showLoginPassword:!A.showLoginPassword}),className:"absolute right-3 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600",children:A.showLoginPassword?e.jsx(Ge,{className:"w-5 h-5"}):e.jsx(ze,{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:A.clear_password,onChange:t=>W({...A,clear_password:t.target.checked,login_password:t.target.checked?"":A.login_password}),className:"w-4 h-4 accent-[#0094f7]"}),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:()=>W({...A,show_browser:!A.show_browser}),className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${A.show_browser?"bg-[#0094f7]":"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 ${A.show_browser?"translate-x-6":"translate-x-0"}`})})]})]})]}),re.length>0&&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(Be,{className:"w-5 h-5 text-blue-500"}),"通知渠道绑定"]}),e.jsx("p",{className:"text-xs text-gray-500 mb-4",children:"勾选后,该账号的 token 失效、自动恢复失败、风控验证等事件会推送到这些渠道"}),e.jsx("div",{className:"space-y-2",children:re.map(t=>{const y=z.includes(Number(t.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:()=>{S($=>y?$.filter(O=>O!==Number(t.id)):[...$,Number(t.id)])},className:`w-5 h-5 rounded-md border-2 flex items-center justify-center transition-colors flex-shrink-0 ${y?"bg-[#0094f7] border-[#0094f7]":"bg-white border-gray-300"}`,children:y&&e.jsx(Ae,{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:t.name}),e.jsxs("div",{className:"text-xs text-gray-500",children:[t.type,t.enabled?"":" · 已停用"]})]})]},t.id)})})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:()=>F(null),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",disabled:P,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",disabled:P,children:[P?e.jsx(ke,{className:"w-4 h-4 animate-spin"}):e.jsx(Le,{className:"w-4 h-4"}),P?"保存中...":"保存"]})]})})]})}),document.body),v==="ai-settings"&&o&&he.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(qe,{className:"w-6 h-6 text-purple-500"}),"AI助手设置"]}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:o.nickname||o.remark||o.id})]}),e.jsx("button",{onClick:()=>F(null),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors flex-shrink-0",children:e.jsx(pe,{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(qe,{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:()=>x({...m,ai_enabled:!m.ai_enabled}),className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${m.ai_enabled?"bg-[#0094f7]":"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 ${m.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:m.max_discount_percent,onChange:t=>x({...m,max_discount_percent:parseInt(t.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%"})]}),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:m.max_discount_amount,onChange:t=>x({...m,max_discount_amount:parseInt(t.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元"})]}),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:m.max_bargain_rounds,onChange:t=>x({...m,max_bargain_rounds:parseInt(t.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:m.custom_prompts,onChange:t=>x({...m,custom_prompts:t.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(ys,{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:()=>F(null),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",disabled:P,children:"取消"}),e.jsxs("button",{onClick:Ce,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",disabled:P,children:[P?e.jsx(ke,{className:"w-4 h-4 animate-spin"}):e.jsx(Le,{className:"w-4 h-4"}),P?"保存中...":"保存"]})]})})]})}),document.body)]})},zs=({status:s})=>{const a={processing:"bg-blue-100 text-blue-800",pending_ship:"bg-[#0094f7] 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"},l={processing:"处理中",pending_ship:"待发货",shipped:"已发货",completed:"已完成",cancelled:"已取消",refunding:"退款中"};return e.jsx("span",{className:`px-3 py-1.5 rounded-lg text-xs font-bold ${a[s]||a.cancelled}`,children:l[s]||s})},al=()=>{const[s,a]=d.useState([]),[l,h]=d.useState([]),[g,p]=d.useState([]),[k,_]=d.useState({}),[u,q]=d.useState("all"),[b,Y]=d.useState(""),[te,B]=d.useState(1),[Q,T]=d.useState(1),[Z,H]=d.useState(!1),[E,X]=d.useState(!1),[ee,I]=d.useState(!1),[J,U]=d.useState(!1),[v,F]=d.useState(null),[o,C]=d.useState(null),[re,K]=d.useState({}),[z,S]=d.useState(!1),[A,W]=d.useState(""),[m,x]=d.useState(!1),[P,N]=d.useState(null),[se,D]=d.useState(null),[i,R]=d.useState(null),[ne,ae]=d.useState(null),c=t=>{if(!b.trim())return t;const y=b.toLowerCase().trim();return t.filter($=>{var O,oe,r,L,ie,$e;return((O=$.order_id)==null?void 0:O.toLowerCase().includes(y))||((oe=$.item_id)==null?void 0:oe.toLowerCase().includes(y))||((r=$.buyer_id)==null?void 0:r.toLowerCase().includes(y))||((L=$.item_title)==null?void 0:L.toLowerCase().includes(y))||((ie=$.receiver_name)==null?void 0:ie.toLowerCase().includes(y))||(($e=$.receiver_phone)==null?void 0:$e.toLowerCase().includes(y))})},f=async()=>{H(!0);try{if(b.trim()){let t=[],y=1,$=!0;for(;$;){const O=await Rs(void 0,u,y,100);t=[...t,...O.data],$=y<O.total_pages,y++}h(t),a(c(t)),T(1)}else{const t=await Rs(void 0,u,te,20);h(t.data),a(c(t.data)),T(t.total_pages)}}catch(t){console.error("加载订单失败:",t)}finally{H(!1)}};d.useEffect(()=>{a(c(l))},[l,b]);const V=(t,y)=>{if(y&&y.trim())return y;if(k[t])return k[t];const $=g.find(O=>{if(y&&O.item_title){const oe=y.toLowerCase(),r=O.item_title.toLowerCase();return r.includes(oe)||oe.includes(r)}return!1});return $!=null&&$.item_title?$.item_title:"未知商品"},le=t=>{const y={};t.forEach($=>{$.item_id&&(y[$.item_id]=$.item_title||$.item_id)}),_(y)};d.useEffect(()=>{f(),We().then(t=>{p(t),le(t)}).catch(t=>{console.error("加载商品列表失败:",t)})},[u,te,b]);const M=async()=>{H(!0);try{const t=await pa();await f(),t!=null&&t.message&&alert(t.message)}catch(t){console.error("同步订单失败:",t),alert((t==null?void 0:t.message)||"同步失败,请重试")}finally{H(!1)}},ge=t=>{W(t),N(null),S(!0)},ve=async t=>{var y;x(!0),N(null);try{const $=await ha([A],t),O=(y=$==null?void 0:$.results)==null?void 0:y[0];O!=null&&O.success?(N({success:!0,message:O.message}),f()):N({success:!1,message:(O==null?void 0:O.message)||"发货失败"})}catch($){N({success:!1,message:($==null?void 0:$.message)||"请求失败"})}finally{x(!1)}},be=t=>{F(t),X(!0)},_e=t=>{C({...t}),I(!0)},Ce=async()=>{if(!(!o||!o.order_id))try{const t={};o.status!==void 0&&(t.order_status=o.status),o.buyer_id!==void 0&&(t.buyer_id=o.buyer_id),o.amount!==void 0&&(t.amount=o.amount),o.receiver_name!==void 0&&(t.receiver_name=o.receiver_name),o.receiver_phone!==void 0&&(t.receiver_phone=o.receiver_phone),o.receiver_address!==void 0&&(t.receiver_address=o.receiver_address),o.item_id!==void 0&&(t.item_id=o.item_id),o.quantity!==void 0&&(t.quantity=o.quantity),await xa(o.order_id,t),I(!1),C(null),f()}catch(t){console.error("更新订单失败:",t),alert("更新失败,请重试")}},we=async()=>{if(se)try{const t=new FormData;t.append("file",se),await ga(t),U(!1),D(null),f(),alert("订单导入成功")}catch(t){alert((t==null?void 0:t.message)||"导入失败,请检查文件格式")}},ye=async t=>{R(t);try{const y=await ua(t);y.success?await f():alert(y.message||"同步失败")}catch(y){console.error("同步订单失败:",y),alert((y==null?void 0:y.message)||"同步失败,请重试")}finally{R(null)}},fe=async t=>{if(confirm("确认删除该订单吗?删除后无法恢复。")){ae(t);try{await ma(t),h(y=>y.filter($=>$.order_id!==t))}catch(y){console.error("删除订单失败:",y),alert((y==null?void 0:y.message)||"删除失败,请重试"),await f()}finally{ae(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:f,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(Se,{className:`w-5 h-5 ${Z?"animate-spin":""}`})}),e.jsxs("button",{onClick:()=>U(!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(Pe,{className:"w-4 h-4"}),"插入订单"]}),e.jsxs("button",{onClick:M,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(Ss,{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-[#FAFAFA]",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:"shipped",v:"已发货"},{k:"pending_ship",v:"待发货"},{k:"cancelled",v:"已取消"},{k:"refunding",v:"其他"}].map(t=>e.jsx("button",{onClick:()=>{q(t.k),B(1),Y("")},className:`px-5 py-2 rounded-lg text-sm font-bold transition-all whitespace-nowrap ${u===t.k?"bg-white text-black shadow-sm":"text-gray-500 hover:text-gray-700"}`,children:t.v},t.k))}),e.jsxs("div",{className:"relative w-full md:w-auto group",children:[e.jsx(kt,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 group-focus-within:text-[#0094f7] transition-colors"}),e.jsx("input",{type:"text",placeholder:"搜索订单号/商品/买家...",value:b,onChange:t=>{Y(t.target.value),B(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:s.map(t=>e.jsxs("tr",{className:"hover:bg-[#FFFDE7]/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:t.item_image?e.jsx("img",{src:t.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(Xe,{})})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-bold text-gray-900 line-clamp-1 text-sm",children:V(t.item_id,t.item_title)}),e.jsxs("div",{className:"text-xs text-gray-500 mt-1 font-medium",children:["订单ID: ",t.order_id]}),e.jsxs("div",{className:"text-xs text-gray-400 mt-0.5",children:["数量: ",t.quantity," • ",t.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:t.buyer_id}),t.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:t.receiver_name})]}),t.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:t.receiver_phone})]}),t.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:t.receiver_address})]})]})}),e.jsx("td",{className:"px-6 py-5 text-base font-extrabold text-gray-900 font-feature-settings-tnum",children:t.amount?`¥${t.amount}`:e.jsx("span",{className:"text-xs text-amber-600 font-bold",children:"待获取"})}),e.jsx("td",{className:"px-6 py-5",children:e.jsx(zs,{status:t.status})}),e.jsxs("td",{className:"px-6 py-5 text-right",children:[t.status==="pending_ship"&&e.jsx("button",{onClick:()=>ge(t.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=${t.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(et,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>be(t),className:"mr-2 text-gray-400 hover:text-blue-600 p-2 rounded-xl hover:bg-blue-50 transition-colors",title:"查看详情",children:e.jsx(ze,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>_e(t),className:"mr-2 text-gray-400 hover:text-black p-2 rounded-xl hover:bg-gray-100 transition-colors",title:"编辑订单",children:e.jsx(Ue,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>ye(t.order_id),disabled:i===t.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(Se,{className:`w-4 h-4 ${i===t.order_id?"animate-spin":""}`})}),e.jsx("button",{onClick:()=>fe(t.order_id),disabled:ne===t.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(De,{className:"w-4 h-4"})})]})]},t.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:["第 ",te," 页 / 共 ",Q," 页"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{disabled:te<=1,onClick:()=>B(t=>t-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(St,{className:"w-5 h-5"})}),e.jsx("button",{disabled:te>=Q,onClick:()=>B(t=>t+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(Ct,{className:"w-5 h-5"})})]})]})]}),E&&v&&he.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:()=>X(!1),className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",children:e.jsx(pe,{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:v.order_id})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"状态"}),e.jsx(zs,{status:v.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:v.amount?`¥${v.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:v.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:v.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:[v.item_image&&e.jsx("img",{src:v.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:V(v.item_id,v.item_title)}),e.jsxs("div",{className:"text-sm text-gray-500",children:["商品ID: ",v.item_id]}),v.item_price&&e.jsxs("div",{className:"text-sm text-gray-500 mt-1",children:["标价: ¥",v.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:v.buyer_id})]}),v.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:v.receiver_name})]}),v.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:v.receiver_phone})]}),v.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:v.receiver_address})]})]})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:()=>X(!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:"关闭"}),v.status==="pending_ship"&&e.jsx("button",{onClick:()=>{X(!1),ge(v.order_id)},className:"flex-1 px-6 py-3 rounded-xl ios-btn-primary font-bold shadow-lg shadow-blue-200",children:"立即发货"})]})})]})}),document.body),J&&he.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:()=>U(!1),className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",children:e.jsx(pe,{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:t=>{var y;return D(((y=t.target.files)==null?void 0:y[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 格式"})]}),se&&e.jsx("div",{className:"p-3 bg-blue-50 rounded-xl",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ke,{className:"w-4 h-4 text-blue-600"}),e.jsx("span",{className:"text-sm font-medium text-blue-900",children:se.name})]})})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:()=>U(!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.jsx("button",{onClick:we,disabled:!se,className:"flex-1 px-6 py-3 rounded-xl ios-btn-primary font-bold shadow-lg shadow-blue-200 disabled:opacity-50",children:"导入订单"})]})})]})}),document.body),z&&he.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:()=>{S(!1),N(null)},className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",children:e.jsx(pe,{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:()=>ve("status_only"),disabled:m,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(Ss,{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:()=>ve("full_delivery"),disabled:m,className:"w-full text-left p-4 rounded-xl border-2 border-gray-200 hover:border-[#0094f7] 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(Xe,{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:"自动匹配发货规则、获取卡券、发送卡券信息给买家,并修改发货状态。 适用于订单既没有发送卡券给买家、也没有修改发货状态的情况。"})]})]})}),m&&e.jsxs("div",{className:"flex items-center justify-center gap-2 py-3",children:[e.jsx(Se,{className:"w-4 h-4 animate-spin text-gray-500"}),e.jsx("span",{className:"text-sm text-gray-500",children:"正在处理中..."})]}),P&&e.jsxs("div",{className:`p-3 rounded-xl text-sm ${P.success?"bg-green-50 text-green-800":"bg-red-50 text-red-800"}`,children:[P.success?"✓ ":"✗ ",P.message]})]}),e.jsx("div",{className:"modal-footer",children:e.jsx("button",{onClick:()=>{S(!1),N(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:P!=null&&P.success?"完成":"取消"})})]})}),document.body),ee&&o&&he.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:()=>I(!1),className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",children:e.jsx(pe,{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:o.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:o.status,onChange:t=>C({...o,status:t.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:o.buyer_id,onChange:t=>C({...o,buyer_id:t.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:o.amount,onChange:t=>C({...o,amount:parseFloat(t.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:o.receiver_name||"",onChange:t=>C({...o,receiver_name:t.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:o.receiver_phone||"",onChange:t=>C({...o,receiver_phone:t.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:o.receiver_address||"",onChange:t=>C({...o,receiver_address:t.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:o.item_title||"",onChange:t=>C({...o,item_title:t.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:()=>I(!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:Ce,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Le,{className:"w-4 h-4"}),"保存更改"]})]})})]})}),document.body)]})},Us=()=>({name:"",type:"data",content:"",description:"",enabled:!0,delay_seconds:0,api_method:"GET",api_timeout:10,api_headers:"",api_params:""}),ll=()=>{const[s,a]=d.useState([]),[l,h]=d.useState(!1),[g,p]=d.useState(!1),[k,_]=d.useState(null),[u,q]=d.useState({}),[b,Y]=d.useState(Us),[te,B]=d.useState(!1),[Q,T]=d.useState("create"),[Z,H]=d.useState(null),[E,X]=d.useState(null),[ee,I]=d.useState(!1),[J,U]=d.useState(""),[v,F]=d.useState(""),[o,C]=d.useState(null);d.useEffect(()=>{Ie().then(a)},[]);const re=({type:i})=>{switch(i){case"text":return e.jsx(Cs,{className:"w-5 h-5 text-blue-500"});case"image":return e.jsx($s,{className:"w-5 h-5 text-purple-500"});case"api":return e.jsx(Is,{className:"w-5 h-5 text-blue-500"});default:return e.jsx(us,{className:"w-5 h-5 text-gray-500"})}},K=i=>{var R,ne,ae,c,f;_(i),q({id:i.id,name:i.name||"",type:i.type||"text",api_url:((R=i.api_config)==null?void 0:R.url)||"",api_method:((ne=i.api_config)==null?void 0:ne.method)||"GET",api_timeout:((ae=i.api_config)==null?void 0:ae.timeout)||10,api_headers:((c=i.api_config)==null?void 0:c.headers)||"",api_params:((f=i.api_config)==null?void 0:f.params)||"",text_content:i.text_content||"",data_content:i.data_content||"",image_url:i.image_url||"",delay_seconds:i.delay_seconds||0,description:i.description||"",enabled:i.enabled}),h(!0)},z=async()=>{var i,R,ne,ae,c,f,V,le;if(k){if(!((i=u.name)!=null&&i.trim())){alert("请输入卡密名称");return}if(!u.type){alert("请选择卡密类型");return}try{const M={name:u.name.trim(),type:u.type,description:(R=u.description)==null?void 0:R.trim(),delay_seconds:u.delay_seconds||0,enabled:u.enabled??!0};u.type==="api"?M.api_config={url:(ne=u.api_url)==null?void 0:ne.trim(),method:u.api_method,timeout:u.api_timeout||10,headers:((ae=u.api_headers)==null?void 0:ae.trim())||void 0,params:((c=u.api_params)==null?void 0:c.trim())||void 0}:u.type==="text"?M.text_content=((f=u.text_content)==null?void 0:f.trim())||"":u.type==="data"?M.data_content=((V=u.data_content)==null?void 0:V.trim())||"":u.type==="image"&&(M.image_url=((le=u.image_url)==null?void 0:le.trim())||""),await Ts(k.id,M),h(!1),Ie().then(a)}catch(M){console.error("更新卡密失败:",M),alert("更新失败,请重试")}}},S=async i=>{if(confirm("确认删除该卡密吗?"))try{await Na(i),Ie().then(a)}catch(R){console.error("删除卡密失败:",R),alert("删除失败,请重试")}},A=async()=>{if(!b.name.trim()){alert("请输入卡密名称");return}if(!b.content.trim()){alert(b.type==="api"?"请输入 API 地址":"请输入卡密内容");return}try{const i={name:b.name.trim(),type:b.type,description:b.description.trim(),enabled:b.enabled,delay_seconds:b.delay_seconds};b.type==="text"&&(i.text_content=b.content.trim()),b.type==="data"&&(i.data_content=b.content.trim()),b.type==="image"&&(i.image_url=b.content.trim()),b.type==="api"&&(i.api_config={url:b.content.trim(),method:b.api_method,timeout:b.api_timeout,headers:b.api_headers.trim()||void 0,params:b.api_params.trim()||void 0}),await ja(i),p(!1),Y(Us()),Ie().then(a)}catch(i){console.error("添加卡密失败:",i),alert("添加失败,请重试")}},W=async i=>{try{await Ts(i.id,{...i,enabled:!i.enabled}),Ie().then(a)}catch(R){console.error("切换状态失败:",R)}},m=async i=>{try{await navigator.clipboard.writeText(String(i)),alert(`已复制卡密组ID:${i}`)}catch{prompt("复制卡密组ID",String(i))}},x=s.filter(i=>i.type==="data"),P=()=>{const ne=[["名称","类型","内容","描述","启用","延迟秒","多规格","规格名","规格值"],...[["VIP月卡","data",`VIP-MONTH-001
|
||
VIP-MONTH-002
|
||
VIP-MONTH-003`,"按行消费的卡密队列","是","0","否","",""],["感谢文案","text","感谢购买,如有问题联系客服~","固定文本","是","0","否","",""],["教程图","image","https://cdn.example.com/tutorial.jpg","图片URL","是","0","否","",""]]].map(V=>V.map(le=>`"${String(le).replace(/"/g,'""')}"`).join(",")).join(`
|
||
`),ae=new Blob(["\uFEFF"+ne],{type:"text/csv;charset=utf-8"}),c=URL.createObjectURL(ae),f=document.createElement("a");f.href=c,f.download="卡密组批量导入模板.csv",document.body.appendChild(f),f.click(),f.remove(),URL.revokeObjectURL(c)},N=async()=>{if(Z){I(!0),X(null);try{const i=await va(Z);if(X(i),i.created>0){const R=await Ie();a(R)}}catch(i){X({error:(i==null?void 0:i.message)||"上传失败"})}finally{I(!1)}}},se=async()=>{if(!(!J||!v.trim())){I(!0),C(null);try{const i=await wa(J,v);C({added:i.added}),F("");const R=await Ie();a(R)}catch(i){alert("追加失败:"+((i==null?void 0:i.message)||"未知错误"))}finally{I(!1)}}},D=()=>{var i;T("create"),H(null),X(null),U((i=x[0])!=null&&i.id?String(x[0].id):""),F(""),C(null),B(!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:D,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(Ke,{className:"w-5 h-5"}),"批量导入"]}),e.jsxs("button",{onClick:()=>p(!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(Pe,{className:"w-5 h-5"}),"添加新卡密"]})]})]}),e.jsxs("div",{className:"ios-card rounded-xl overflow-hidden shadow-lg border-0 bg-white",children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full 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-8 py-5 w-[18%]",children:"卡密名称"}),e.jsx("th",{className:"px-6 py-5 w-[12%]",children:"卡密组ID"}),e.jsx("th",{className:"px-6 py-5 w-[10%]",children:"类型"}),e.jsx("th",{className:"px-6 py-5 w-[22%]",children:"内容/库存"}),e.jsx("th",{className:"px-6 py-5 w-[18%]",children:"描述"}),e.jsx("th",{className:"px-6 py-5 w-[10%]",children:"状态"}),e.jsx("th",{className:"px-6 py-5 w-[10%] text-right",children:"操作"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50",children:s.map(i=>{let R="";return i.type==="data"&&i.data_content?R=`库存: ${i.data_content.split(`
|
||
`).filter(ae=>ae.trim()).length} 条`:i.type==="text"&&i.text_content?R=i.text_content.substring(0,20)+(i.text_content.length>20?"...":""):i.type==="api"&&i.api_config?R=i.api_config.url:i.type==="image"&&i.image_url&&(R="图片链接"),e.jsxs("tr",{className:"hover:bg-[#FFFDE7]/50 transition-colors group",children:[e.jsx("td",{className:"px-8 py-5",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-gray-50 rounded-xl group-hover:bg-white transition-colors",children:e.jsx(re,{type:i.type})}),e.jsx("span",{className:"font-bold text-gray-900",children:i.name})]})}),e.jsx("td",{className:"px-6 py-5",children:e.jsxs("button",{onClick:()=>m(i.id),className:"inline-flex items-center gap-2 rounded-xl bg-gray-100 px-3 py-2 font-mono text-xs font-extrabold text-gray-700 hover:bg-gray-200 transition-colors",title:"复制卡密组ID,用于批量铺货表格",children:[i.id,e.jsx($t,{className:"w-3.5 h-3.5"})]})}),e.jsx("td",{className:"px-6 py-5",children:e.jsx("span",{className:`px-3 py-1.5 rounded-lg text-xs font-bold ${i.type==="text"?"bg-blue-50 text-blue-600":i.type==="data"?"bg-purple-50 text-purple-600":i.type==="api"?"bg-blue-50 text-blue-600":"bg-pink-50 text-pink-600"}`,children:i.type==="text"?"文本":i.type==="data"?"批量":i.type==="api"?"API":"图片"})}),e.jsx("td",{className:"px-6 py-5",children:e.jsx("span",{className:"text-sm text-gray-600 font-mono block truncate",title:R,children:R})}),e.jsx("td",{className:"px-6 py-5",children:e.jsx("span",{className:"text-sm text-gray-500 block max-w-[200px] truncate",title:i.description||"-",children:i.description||"-"})}),e.jsx("td",{className:"px-6 py-5",children:e.jsx("button",{onClick:()=>W(i),className:`w-12 h-8 rounded-full relative transition-colors ${i.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 ${i.enabled?"left-5":"left-1"}`})})}),e.jsx("td",{className:"px-6 py-5",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("button",{onClick:()=>K(i),className:"p-2 text-gray-400 hover:text-black hover:bg-gray-100 rounded-xl transition-colors",title:"编辑",children:e.jsx(Ue,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>S(i.id),className:"p-2 text-gray-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors",children:e.jsx(De,{className:"w-5 h-5"})})]})})]},i.id)})})]})}),s.length===0&&e.jsxs("div",{className:"py-20 text-center text-gray-400",children:[e.jsx(Hs,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),e.jsx("p",{children:"暂无卡密配置,请点击右上角添加。"})]})]}),l&&k&&he.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:()=>h(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",children:e.jsx(pe,{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:u.name||"",onChange:i=>q({...u,name:i.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:u.type||"text",onChange:i=>q({...u,type:i.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:"批量数据"}),e.jsx("option",{value:"api",children:"API接口"}),e.jsx("option",{value:"image",children:"图片"})]})]})]}),u.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:u.api_url||"",onChange:i=>q({...u,api_url:i.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:u.api_method||"GET",onChange:i=>q({...u,api_method:i.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:u.api_timeout||10,onChange:i=>q({...u,api_timeout:parseInt(i.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:u.api_headers||"",onChange:i=>q({...u,api_headers:i.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:u.api_params||"",onChange:i=>q({...u,api_params:i.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}'})]})]}),u.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:u.text_content||"",onChange:i=>q({...u,text_content:i.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-32 resize-none",placeholder:"请输入要发送的固定文字内容..."})]})]}),u.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:u.data_content||"",onChange:i=>q({...u,data_content:i.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:u.data_content?u.data_content.split(`
|
||
`).filter(i=>i.trim()).length:0})," 条"]})]})]}),u.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:u.image_url||"",onChange:i=>q({...u,image_url:i.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 地址"})]}),u.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:u.image_url,alt:"预览",className:"max-w-full max-h-48 rounded-xl border border-gray-200",onError:i=>{i.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:u.delay_seconds||0,onChange:i=>q({...u,delay_seconds:parseInt(i.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:u.description||"",onChange:i=>q({...u,description:i.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:()=>q({...u,enabled:!u.enabled}),className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${u.enabled?"bg-[#0094f7]":"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 ${u.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:()=>h(!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:z,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Le,{className:"w-4 h-4"}),"保存更改"]})]})})]})}),document.body),g&&he.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:()=>p(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors flex-shrink-0",title:"关闭",children:e.jsx(pe,{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:b.name,onChange:i=>Y({...b,name:i.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-4 gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>Y({...b,type:"data",content:""}),className:`p-3 rounded-xl font-bold transition-all ${b.type==="data"?"bg-[#0094f7] text-white":"bg-gray-100 text-gray-600 hover:bg-gray-200"}`,children:[e.jsx(us,{className:"w-5 h-5 mx-auto mb-1"}),"批量库存"]}),e.jsxs("button",{type:"button",onClick:()=>Y({...b,type:"text",content:""}),className:`p-3 rounded-xl font-bold transition-all ${b.type==="text"?"bg-[#0094f7] text-white":"bg-gray-100 text-gray-600"}`,children:[e.jsx(Cs,{className:"w-5 h-5 mx-auto mb-1"}),"文本"]}),e.jsxs("button",{type:"button",onClick:()=>Y({...b,type:"image",content:""}),className:`p-3 rounded-xl font-bold transition-all ${b.type==="image"?"bg-[#0094f7] text-white":"bg-gray-100 text-gray-600"}`,children:[e.jsx($s,{className:"w-5 h-5 mx-auto mb-1"}),"图片"]}),e.jsxs("button",{type:"button",onClick:()=>Y({...b,type:"api",content:""}),className:`p-3 rounded-xl font-bold transition-all ${b.type==="api"?"bg-[#0094f7] text-white":"bg-gray-100 text-gray-600"}`,children:[e.jsx(Is,{className:"w-5 h-5 mx-auto mb-1"}),"API"]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:b.type==="data"?"库存内容(一行一个)":b.type==="text"?"固定回复内容":b.type==="image"?"图片 URL":"API 地址"}),b.type==="api"?e.jsx("input",{type:"url",value:b.content,onChange:i=>Y({...b,content:i.target.value}),placeholder:"https://api.example.com/get-code",className:"w-full ios-input px-4 py-3 rounded-xl"}):b.type==="image"?e.jsx("input",{type:"url",value:b.content,onChange:i=>Y({...b,content:i.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"https://example.com/card.png"}):e.jsx("textarea",{value:b.content,onChange:i=>Y({...b,content:i.target.value}),className:`w-full ios-input px-4 py-3 rounded-xl resize-none text-sm ${b.type==="data"?"h-48 font-mono":"h-32"}`,placeholder:b.type==="data"?`CODE-123456
|
||
CODE-789012
|
||
...`:"请输入每次发货时发送的固定文字"}),b.type==="data"&&e.jsxs("p",{className:"text-xs text-gray-500",children:["当前库存:",e.jsx("span",{className:"font-bold text-[#0094f7]",children:b.content.split(`
|
||
`).filter(i=>i.trim()).length})," 条"]})]}),b.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:b.api_method,onChange:i=>Y({...b,api_method:i.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:b.api_timeout,onChange:i=>Y({...b,api_timeout:parseInt(i.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:b.api_headers,onChange:i=>Y({...b,api_headers:i.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:b.api_params,onChange:i=>Y({...b,api_params:i.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:b.description,onChange:i=>Y({...b,description:i.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:b.delay_seconds,onChange:i=>Y({...b,delay_seconds:parseInt(i.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:()=>p(!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:A,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Pe,{className:"w-4 h-4"}),"添加卡密"]})]})})]})}),document.body),te&&he.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:()=>B(!1),className:"w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center",children:e.jsx(pe,{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:()=>T("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 ${Q==="create"?"bg-[#0094f7] text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(It,{className:"w-4 h-4"}),"批量创建卡密组"]}),e.jsxs("button",{onClick:()=>T("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 ${Q==="append"?"bg-[#0094f7] text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(Ke,{className:"w-4 h-4"}),"往单个组充卡密"]})]}),Q==="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/api;data 类型的"内容"按行存卡密(CSV 单元格内换行需用引号包裹)。']}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:P,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(At,{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(Ke,{className:"w-4 h-4"}),Z?Z.name:"选择 .xlsx / .csv / .tsv",e.jsx("input",{type:"file",accept:".xlsx,.csv,.tsv",className:"hidden",onChange:i=>{var R;return H(((R=i.target.files)==null?void 0:R[0])||null)}})]})]}),E&&!E.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:["共 ",E.total," 行 · 成功 ",E.created," · 失败 ",E.failed]}),E.failed>0&&e.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1",children:E.rows.filter(i=>!i.success).map(i=>e.jsxs("div",{className:"text-xs text-red-600",children:["第 ",i.row_no," 行「",i.name,"」:",i.error]},i.row_no))})]})]}):e.jsx("div",{className:"space-y-4",children:x.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:J,onChange:i=>U(i.target.value),className:"w-full ios-input px-4 py-3 rounded-xl text-sm",children:x.map(i=>e.jsxs("option",{value:String(i.id),children:[i.name,"(ID: ",i.id,")"]},i.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:v,onChange:i=>F(i.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:"一行一个卡密号,空行自动忽略。会追加到该组现有库存末尾。"})]}),o&&e.jsxs("div",{className:"rounded-xl bg-green-50 border border-green-200 p-3 text-sm text-green-700 font-bold",children:["已追加 ",o.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:()=>B(!1),className:"px-5 py-2.5 rounded-xl bg-gray-100 hover:bg-gray-200 font-bold text-gray-700 transition-colors",children:"关闭"}),Q==="create"?e.jsxs("button",{onClick:N,disabled:!Z||ee,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[ee?e.jsx(ke,{className:"w-4 h-4 animate-spin"}):e.jsx(Ke,{className:"w-4 h-4"}),ee?"处理中...":"上传创建"]}):e.jsxs("button",{onClick:se,disabled:!J||!v.trim()||ee||x.length===0,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[ee?e.jsx(ke,{className:"w-4 h-4 animate-spin"}):e.jsx(Pe,{className:"w-4 h-4"}),ee?"处理中...":"追加卡密"]})]})]})}),document.body)]})},rl=s=>{const a=String(s||"").trim();return a?/^[¥¥]/.test(a)?a:`¥${a}`:"-"},nl=({onConfigureDelivery:s})=>{const[a,l]=d.useState([]),[h,g]=d.useState([]),[p,k]=d.useState([]),[_,u]=d.useState(""),[q,b]=d.useState(!1),[Y,te]=d.useState(!1),[B,Q]=d.useState(!1),[T,Z]=d.useState(!1),[H,E]=d.useState(!1),[X,ee]=d.useState(!1),[I,J]=d.useState(!1),[U,v]=d.useState("upload"),[F,o]=d.useState(null),[C,re]=d.useState(null),[K,z]=d.useState(null),[S,A]=d.useState(null),[W,m]=d.useState(null),[x,P]=d.useState({}),[N,se]=d.useState({cookie_id:"",item_id:"",item_title:"",item_price:"",item_image:""}),[D,i]=d.useState({cookie_id:"",title:"",description:"",price:"",original_price:"",quantity:"1",postage_mode:"free",postage:"",images:[]}),[R,ne]=d.useState([]);d.useEffect(()=>{if(!X||D.images.length===0){ne([]);return}const r=D.images.map((L,ie)=>({key:L.name+ie,url:URL.createObjectURL(L)}));return ne(r),()=>{r.forEach(L=>URL.revokeObjectURL(L.url))}},[X,D.images]);const ae=async()=>{const r=await We();l(r)},c=async()=>{g(await rs())};d.useEffect(()=>{Promise.all([Ns(),We(),rs()]).then(([r,L,ie])=>{k(r),l(L),g(ie)}).catch(r=>console.error("加载商品配置失败:",r))},[]),d.useEffect(()=>{if(!I||!(S!=null&&S.id)||S.status!=="running")return;const r=window.setInterval(async()=>{try{const L=await es(S.id);A(L),L.status!=="running"&&(v("done"),await ae(),await c())}catch(L){console.error("刷新批量铺货进度失败:",L)}},3e3);return()=>window.clearInterval(r)},[I,S==null?void 0:S.id,S==null?void 0:S.status]);const f=async()=>{if(!_)return alert("请先选择账号");b(!0);try{const r=await _a(_);await ae(),alert((r==null?void 0:r.message)||"商品同步完成")}catch(r){console.error("同步商品失败:",r),alert((r==null?void 0:r.message)||"同步失败,请重试")}finally{b(!1)}},V=r=>{m(r),P({...r}),Z(!0)},le=async()=>{if(W)try{await Pa(W.cookie_id,W.item_id,{item_title:x.item_title||"",item_description:x.item_description||"",item_category:x.item_category||"",item_price:x.item_price||"",item_detail:x.item_detail||W.item_detail||""}),await ae(),await c(),Z(!1),m(null)}catch(r){console.error("更新商品失败:",r),alert("更新失败,请重试")}},M=async r=>{if(confirm(`确认删除商品"${r.item_title}"吗?`))try{await ka(r.cookie_id,r.item_id),l(L=>L.filter(ie=>!(ie.cookie_id===r.cookie_id&&ie.item_id===r.item_id)))}catch(L){console.error("删除商品失败:",L),alert("删除失败,请重试")}},ge=async()=>{try{if(!N.cookie_id||!N.item_id){alert("请选择账号并填写商品ID");return}await Sa(N.cookie_id,{item_id:N.item_id,item_title:N.item_title,item_price:N.item_price,item_detail:N.item_image?JSON.stringify({item_image:N.item_image}):""}),await ae(),E(!1),se({cookie_id:"",item_id:"",item_title:"",item_price:"",item_image:""})}catch(r){console.error("添加商品失败:",r),alert("添加失败,请重试")}},ve=async()=>{if(!D.cookie_id)return alert("请选择发布账号");if(!D.title.trim())return alert("请填写商品标题");if(!D.price.trim())return alert("请填写商品价格");if(!D.quantity||Number(D.quantity)<=0)return alert("库存数量必须大于 0");if(D.images.length===0)return alert("至少上传 1 张商品图片");if(D.postage_mode==="fixed"&&!D.postage.trim())return alert("请填写一口价邮费");te(!0);try{const r=await Ca(D);if(await ae(),ee(!1),i({cookie_id:_||"",title:"",description:"",price:"",original_price:"",quantity:"1",postage_mode:"free",postage:"",images:[]}),r!=null&&r.item_id){const L={id:r.item_id,cookie_id:D.cookie_id,item_id:r.item_id,item_title:r.item_title||D.title,item_price:r.item_price||D.price,item_image:r.item_image};s(L),alert("商品发布成功,ID: "+r.item_id+",已为你打开发货规则配置")}else alert("商品发布成功")}catch(r){console.error("发布商品失败:",r);const L=r==null?void 0:r.payload;if((L==null?void 0:L.code)==="stock_permission_missing"){alert("发布失败:该账号没有库存发布权限,无法按库存数量发布商品。请换账号或先在闲鱼确认库存能力。");return}alert((r==null?void 0:r.message)||"发布失败,请重试")}finally{te(!1)}},be=()=>{v("upload"),z(null),A(null),o(null),re(null),J(!0)},_e=async()=>{if(!F)return alert("请先上传商品表格");if(!_)return alert("请先选择默认发布账号");Q(!0);try{const r=await $a({file:F,imagesZip:C,defaultCookieId:_});z(r),A(null),v("preview")}catch(r){console.error("批量铺货预检失败:",r),alert((r==null?void 0:r.message)||"预检失败,请检查表格和图片 zip")}finally{Q(!1)}},Ce=async()=>{if(K!=null&&K.preview_id){if(K.valid<=0)return alert("没有可发布的商品行");Q(!0);try{const r=await Ia(K.preview_id),L=await es(r.batch_id||K.preview_id);A(L),v(L.status==="running"?"running":"done")}catch(r){console.error("启动批量铺货失败:",r),alert((r==null?void 0:r.message)||"启动发布任务失败")}finally{Q(!1)}}},we=async()=>{if(S!=null&&S.id&&confirm("确认取消当前批量铺货任务吗?正在发布的单个商品可能会继续完成。")){Q(!0);try{await Aa(S.id),A(await es(S.id)),v("done")}catch(r){alert((r==null?void 0:r.message)||"取消失败")}finally{Q(!1)}}},ye=async()=>{if(S!=null&&S.id){Q(!0);try{await Da(S.id),A(await es(S.id)),v("running")}catch(r){alert((r==null?void 0:r.message)||"重试失败")}finally{Q(!1)}}},fe=()=>{const ie=[["账号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(n=>n.map(j=>`"${String(j).replace(/"/g,'""')}"`).join(",")).join(`
|
||
`),$e=new Blob(["\uFEFF"+ie],{type:"text/csv;charset=utf-8"}),Je=URL.createObjectURL($e),Fe=document.createElement("a");Fe.href=Je,Fe.download="批量铺货模板.csv",document.body.appendChild(Fe),Fe.click(),Fe.remove(),URL.revokeObjectURL(Je)},t=()=>{se(r=>({...r,cookie_id:_||r.cookie_id})),E(!0)},y=()=>{i(r=>({...r,cookie_id:_||r.cookie_id})),ee(!0)},$=r=>h.filter(L=>L.cookie_id===r.cookie_id&&L.item_id===r.item_id),O=r=>{switch(r){case"preview":return"待确认";case"pending":return"等待中";case"running":return"发布中";case"success":return"成功";case"failed":return"失败";case"completed":return"已完成";case"partially_failed":return"部分失败";case"canceled":return"已取消";default:return r||"-"}},oe=r=>{switch(r){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"}};return e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[e.jsxs("div",{className:"flex justify-between items-center",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 gap-3",children:[e.jsxs("select",{className:"ios-input px-4 py-3 rounded-xl text-sm",value:_,onChange:r=>u(r.target.value),children:[e.jsx("option",{value:"",children:"选择账号以同步"}),p.map(r=>e.jsx("option",{value:r.id,children:r.nickname},r.id))]}),e.jsxs("button",{onClick:f,disabled:q||!_,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(Se,{className:`w-4 h-4 ${q?"animate-spin":""}`}),"同步商品"]}),e.jsxs("button",{onClick:t,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(Pe,{className:"w-4 h-4"}),"添加商品"]}),e.jsxs("button",{onClick:y,className:"px-5 py-3 rounded-2xl font-bold bg-emerald-600 text-white hover:bg-emerald-700 transition-colors flex items-center gap-2 shadow-lg shadow-emerald-100",children:[e.jsx(os,{className:"w-4 h-4"}),"发布商品"]}),e.jsxs("button",{onClick:be,className:"px-5 py-3 rounded-2xl font-bold bg-blue-600 text-white hover:bg-blue-700 transition-colors flex items-center gap-2 shadow-lg shadow-blue-100",children:[e.jsx(Ze,{className:"w-4 h-4"}),"批量铺货"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-4",children:[a.map(r=>{const L=$(r),ie=L.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:()=>V(r),className:"p-1.5 bg-white/90 backdrop-blur rounded-lg shadow-md text-gray-600 hover:bg-[#0094f7] hover:text-white transition-colors",title:"编辑",children:e.jsx(Ue,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:()=>M(r),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(De,{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:[r.item_image?e.jsx("img",{src:r.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(Xs,{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:rl(r.item_price)})]}),e.jsx("h3",{className:"font-bold text-gray-900 line-clamp-2 text-xs mb-1.5 h-8 leading-4",children:r.item_title}),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: ",r.item_id]}),e.jsxs("span",{className:`inline-flex items-center gap-1 font-bold ${ie?"text-emerald-600":"text-amber-600"}`,children:[ie?e.jsx(tt,{className:"w-3 h-3"}):e.jsx(Dt,{className:"w-3 h-3"}),ie?`${L.length} 规则`:"未配置"]})]}),e.jsx("div",{className:"space-y-2 mt-auto",children:e.jsxs("button",{onClick:()=>s(r),className:`w-full flex items-center justify-between gap-1 px-2.5 py-2 rounded-lg text-[11px] font-extrabold transition-all ${ie?"bg-gray-900 text-white hover:bg-black":"bg-[#0094f7] text-white hover:bg-[#0071e3] shadow-md shadow-blue-100"}`,children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Pt,{className:"w-3.5 h-3.5"}),ie?"查看发货规则":"关联发货规则"]}),e.jsx(bs,{className:"w-3.5 h-3.5"})]})})]},`${r.cookie_id}-${r.item_id}`)}),a.length===0&&e.jsxs("div",{className:"col-span-full py-20 text-center text-gray-400",children:[e.jsx(Gs,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),"暂无商品数据,请选择账号进行同步"]})]}),T&&W&&he.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: ",W.item_id]})]}),e.jsx("button",{onClick:()=>Z(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",children:e.jsx(pe,{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:x.item_title||"",onChange:r=>P({...x,item_title:r.target.value})}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"价格",value:x.item_price||"",onChange:r=>P({...x,item_price:r.target.value})}),e.jsx("input",{className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"分类",value:x.item_category||"",onChange:r=>P({...x,item_category:r.target.value})}),e.jsx("textarea",{className:"w-full ios-input px-4 py-3 rounded-xl h-28 resize-none",placeholder:"描述",value:x.item_description||"",onChange:r=>P({...x,item_description:r.target.value})})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("button",{onClick:le,className:"w-full ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Le,{className:"w-4 h-4"}),"保存"]})})]})}),document.body),H&&he.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:()=>E(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",title:"关闭",children:e.jsx(pe,{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:N.cookie_id,onChange:r=>se({...N,cookie_id:r.target.value}),children:[e.jsx("option",{value:"",children:"选择账号"}),p.map(r=>e.jsx("option",{value:r.id,children:r.nickname||r.remark||r.id},r.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:N.item_id,onChange:r=>se({...N,item_id:r.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:N.item_price,onChange:r=>se({...N,item_price:r.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:N.item_title,onChange:r=>se({...N,item_title:r.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:N.item_image,onChange:r=>se({...N,item_image:r.target.value})})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("button",{onClick:ge,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(Pe,{className:"w-4 h-4"}),"添加商品"]})})]})}),document.body),X&&he.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:()=>ee(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",title:"关闭",children:e.jsx(pe,{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:D.cookie_id,onChange:r=>i({...D,cookie_id:r.target.value}),children:[e.jsx("option",{value:"",children:"选择账号"}),p.map(r=>e.jsx("option",{value:r.id,children:r.nickname||r.remark||r.id},r.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:D.title,onChange:r=>i({...D,title:r.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:D.quantity,onChange:r=>i({...D,quantity:r.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:D.description,onChange:r=>i({...D,description:r.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:D.price,onChange:r=>i({...D,price:r.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:D.original_price,onChange:r=>i({...D,original_price:r.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:D.postage_mode,onChange:r=>i({...D,postage_mode:r.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:"无需邮寄"})]})]})]}),D.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:D.postage,onChange:r=>i({...D,postage:r.target.value})})]}),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(Ze,{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:D.images.length?"已选择 "+D.images.length+" 张":"支持 JPG / PNG / GIF"}),e.jsx("input",{className:"hidden",type:"file",accept:"image/*",multiple:!0,onChange:r=>i({...D,images:Array.from(r.target.files||[]).slice(0,9)})})]}),R.length>0&&e.jsx("div",{className:"grid grid-cols-4 sm:grid-cols-6 gap-3",children:R.map(r=>e.jsx("div",{className:"aspect-square rounded-xl bg-gray-100 overflow-hidden border border-gray-100",children:e.jsx("img",{src:r.url,alt:"",className:"w-full h-full object-cover"})},r.key))})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("button",{disabled:Y,onClick:ve,className:"w-full bg-emerald-600 hover:bg-emerald-700 disabled:opacity-60 text-white px-6 py-3.5 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(os,{className:"w-4 h-4"}),Y?"正在发布...":"发布到闲鱼"]})})]})}),document.body),I&&he.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:()=>J(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",title:"关闭",children:e.jsx(pe,{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(([r,L])=>e.jsx("div",{className:`rounded-xl px-3 py-2 text-center text-xs font-extrabold border ${U===r?"bg-blue-600 text-white border-blue-600":"bg-gray-50 text-gray-500 border-gray-100"}`,children:L},r))}),U==="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:fe,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:_,onChange:r=>u(r.target.value),children:[e.jsx("option",{value:"",children:"选择账号"}),p.map(r=>e.jsx("option",{value:r.id,children:r.nickname||r.remark||r.id},r.id))]}),e.jsx("p",{className:"text-xs text-gray-500",children:"表格中“账号ID”为空时,会使用这里选择的账号。"})]}),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(Ze,{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:F?F.name:"支持 .xlsx / .csv / .tsv"}),e.jsx("input",{className:"hidden",type:"file",accept:".xlsx,.csv,.tsv",onChange:r=>{var L;return o(((L=r.target.files)==null?void 0:L[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(Ze,{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:C?C.name:"表格图片字段使用 zip 内相对路径"}),e.jsx("input",{className:"hidden",type:"file",accept:".zip",onChange:r=>{var L;return re(((L=r.target.files)==null?void 0:L[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","没有在上方选择默认账号时填写","填写账号 ID;已经选择默认账号时可以留空"],["标题","每个商品都要填","填写买家能看到的商品标题"],["描述","可以留空","留空时会使用商品标题作为描述"],["价格","每个商品都要填","只填数字,例如 19.90"],["原价","可以留空","需要展示划线原价时填写,例如 29.90"],["库存","可以留空","留空按 1 件处理;填写时必须大于 0"],["邮费模式","可以留空","留空表示包邮;包邮填 free,固定邮费填 fixed"],["邮费","邮费模式填 fixed 时填写","只填数字,例如 8.00"],["图片","每个商品都要填","填写 zip 内图片路径或图片网址;多张图片用英文分号隔开"],["付款后自动发货","需要付款后自动发货时填写","填“是”表示开启;不需要时填“否”或留空"],["付款后发送的卡密","“付款后自动发货”填“是”时填写","从“卡密库存”页面取得卡密组 ID,按上方示例填写"],["评价后发送赠品","需要评价赠品时填写","填“是”表示开启;不需要时填“否”或留空"],["评价后发送的卡密","“评价后发送赠品”填“是”时填写","格式和付款后发送的卡密相同,也可以同时发送多个卡密组"],["超时未评价时提醒","需要自动求评价时填写","填“是”表示开启;不需要时填“否”或留空"],["发货几小时后提醒","“超时未评价时提醒”填“是”时填写","填写等待小时数;留空按 72 小时处理"],["提醒内容","“超时未评价时提醒”填“是”时填写","填写要发送给买家的求评价消息"],["最多提醒几次","可以留空","留空只提醒 1 次"]].map(([r,L,ie])=>e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 font-bold text-gray-900 whitespace-nowrap",children:r}),e.jsx("td",{className:`px-3 py-2 min-w-[210px] font-bold ${L==="每个商品都要填"?"text-red-600":L==="可以留空"?"text-gray-500":"text-amber-700"}`,children:L}),e.jsx("td",{className:"px-3 py-2 min-w-[260px]",children:ie})]},r))})]})})]})]}),U==="preview"&&K&&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:K.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:K.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:K.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("tbody",{className:"divide-y divide-gray-50",children:K.rows.map(r=>{var L,ie;return e.jsxs("tr",{className:"hover:bg-gray-50",children:[e.jsx("td",{className:"px-4 py-3 font-mono text-xs",children:r.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 ${r.valid?"bg-emerald-50 text-emerald-700 border-emerald-100":"bg-red-50 text-red-700 border-red-100"}`,children:r.valid?"可发布":"需修正"})}),e.jsx("td",{className:"px-4 py-3 font-bold text-gray-900 max-w-[240px] truncate",children:r.title||"-"}),e.jsxs("td",{className:"px-4 py-3 text-gray-600",children:["¥",r.price||"-"," / ",r.quantity||1]}),e.jsxs("td",{className:"px-4 py-3 text-gray-600",children:[((L=r.images)==null?void 0:L.length)||0," 张"]}),e.jsx("td",{className:"px-4 py-3 text-red-600 text-xs max-w-[280px]",children:((ie=r.errors)==null?void 0:ie.join(";"))||"-"})]},r.row_no)})})]})})]}),(U==="running"||U==="done")&&S&&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 ${oe(S.status)}`,children:[e.jsx("div",{className:"text-xs font-bold opacity-70",children:"任务状态"}),e.jsx("div",{className:"text-xl font-extrabold mt-1",children:O(S.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:S.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:S.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:S.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:S.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:"商品ID"}),e.jsx("th",{className:"px-4 py-3",children:"错误原因"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50",children:S.rows.map(r=>e.jsxs("tr",{className:"hover:bg-gray-50",children:[e.jsx("td",{className:"px-4 py-3 font-mono text-xs",children:r.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 ${oe(r.status)}`,children:O(r.status)})}),e.jsx("td",{className:"px-4 py-3 font-bold text-gray-900 max-w-[260px] truncate",children:r.title}),e.jsx("td",{className:"px-4 py-3 text-xs font-mono",children:r.item_url?e.jsx("a",{href:r.item_url,target:"_blank",rel:"noreferrer",className:"text-blue-600 hover:underline",children:r.item_id}):r.item_id||"-"}),e.jsx("td",{className:"px-4 py-3 text-red-600 text-xs max-w-[340px]",children:r.error_message||"-"})]},r.id))})]})})]})]}),e.jsxs("div",{className:"modal-footer",children:[U==="upload"&&e.jsxs("button",{disabled:B||!F||!_,onClick:_e,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(Se,{className:`w-4 h-4 ${B?"animate-spin":""}`}),B?"正在预检...":"开始预检"]}),U==="preview"&&K&&e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{disabled:B,onClick:()=>v("upload"),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:B||K.valid<=0,onClick:Ce,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(os,{className:"w-4 h-4"}),B?"启动中...":`确认发布 ${K.valid} 个商品`]})]}),(U==="running"||U==="done")&&S&&e.jsxs("div",{className:"flex gap-3 w-full",children:[S.status==="running"?e.jsx("button",{disabled:B,onClick:we,className:"flex-1 px-6 py-3.5 rounded-xl bg-gray-900 text-white hover:bg-black font-bold",children:"取消任务"}):e.jsx("button",{onClick:()=>window.open(`/items/publish-batches/${S.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:"下载结果"}),S.failed>0&&S.status!=="running"&&e.jsxs("button",{disabled:B,onClick:ye,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(Se,{className:`w-4 h-4 ${B?"animate-spin":""}`}),"重试失败项"]}),S.status!=="running"&&e.jsx("button",{onClick:()=>{J(!1),ae(),c()},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)]})},Ws="https://dashscope.aliyuncs.com/compatible-mode/v1",il=[{value:"debug",label:"Debug"},{value:"info",label:"Info"},{value:"warn",label:"Warn"},{value:"error",label:"Error"}],ol=new Set(["smtp_server","smtp_port","smtp_user","smtp_password","smtp_from","registration_enabled","show_default_login_info","login_captcha_enabled","item_sync_enabled","item_sync_interval","item_sync_max_pages","default_reply"]),dl=()=>{const[s,a]=d.useState(null),[l,h]=d.useState(!1),[g,p]=d.useState(""),[k,_]=d.useState(!1),[u,q]=d.useState([]),[b,Y]=d.useState(!1),[te,B]=d.useState(""),[Q,T]=d.useState(!1),Z=d.useRef(null),[H,E]=d.useState(!1),[X,ee]=d.useState(!1),[I,J]=d.useState(!1),[U,v]=d.useState(!1),[F,o]=d.useState(null),[C,re]=d.useState({new_username:"",current_password:"",new_password:"",confirm_password:""});d.useEffect(()=>{z(),nt().then(x=>{x.username&&re(P=>({...P,new_username:x.username||""}))}).catch(()=>{})},[]),d.useEffect(()=>{const x=P=>{var N;(N=Z.current)!=null&&N.contains(P.target)||T(!1)};return document.addEventListener("mousedown",x),()=>document.removeEventListener("mousedown",x)},[]);const K=async(x,P=!1)=>{const N=x||s,se=(N==null?void 0:N.ai_api_url)||(N==null?void 0:N.ai_base_url)||Ws;Y(!0),B("");try{const D=await Ba(se,(N==null?void 0:N.ai_api_key)||"");q(D),T(P&&D.length>0),!(N!=null&&N.ai_model)&&D.length>0&&a(i=>i&&{...i,ai_model:D[0]})}catch(D){q([]),T(!1),B(D.message||"读取模型失败")}finally{Y(!1)}},z=()=>{h(!0),p(""),ot().then(x=>{a(x),K(x)}).catch(x=>{a(null),p(x.message||"加载配置失败")}).finally(()=>h(!1))},S=async()=>{if(s){_(!0);try{const x=Object.fromEntries(Object.entries(s).filter(([P,N])=>!ol.has(P)&&N!==void 0&&N!==null));await dt(x),alert("系统配置已保存")}catch(x){alert("保存失败:"+x.message)}finally{_(!1)}}},A=async x=>{x.preventDefault(),o(null);const P=C.new_username.trim();if(P.length<3){o({type:"error",text:"用户名至少需要 3 个字符"});return}if(!C.current_password){o({type:"error",text:"请输入当前密码确认身份"});return}if(C.new_password&&C.new_password.length<8){o({type:"error",text:"新密码至少需要 8 个字符"});return}if(C.new_password!==C.confirm_password){o({type:"error",text:"两次输入的新密码不一致"});return}v(!0);try{const N=await Xt({current_password:C.current_password,new_username:P,new_password:C.new_password||void 0});if(!N.success){o({type:"error",text:N.message||"登录凭据更新失败"});return}o({type:"success",text:N.message||"登录凭据已更新"}),window.setTimeout(()=>window.location.reload(),1400)}catch(N){o({type:"error",text:N.message||"登录凭据更新失败"})}finally{v(!1)}};if(!s)return e.jsx("div",{className:"p-8 text-center text-gray-400",children:g||(l?"加载配置中...":"暂无配置")});const W=s.ai_model||"",m=u;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(ys,{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:z,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(Se,{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(Lt,{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:s.log_level||"info",onChange:x=>a({...s,log_level:x.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:il.map(x=>e.jsx("option",{value:x.value,children:x.label},x.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:s.log_format||"text",onChange:x=>a({...s,log_format:x.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:s.renewal_log_retention_days??10,onChange:x=>a({...s,renewal_log_retention_days:parseInt(x.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-[#0094f7] text-white",children:e.jsx(Zs,{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:s.ai_api_url||Ws,onChange:x=>a({...s,ai_api_url:x.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:H?"text":"password",value:s.ai_api_key||"",onChange:x=>a({...s,ai_api_key:x.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:()=>E(!H),className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600 transition-colors",children:H?e.jsx(Ge,{className:"w-4 h-4"}):e.jsx(ze,{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:Z,className:"relative flex flex-col sm:flex-row gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx("input",{value:W,onFocus:()=>u.length>0&&T(!0),onChange:x=>{a({...s,ai_model:x.target.value}),u.length>0&&T(!0)},onKeyDown:x=>{x.key==="Escape"&&T(!1),x.key==="ArrowDown"&&u.length>0&&T(!0)},className:"w-full ios-input px-4 py-3 pr-10 rounded-xl",placeholder:"从接口读取或手动输入模型名"}),e.jsx("button",{type:"button",onClick:()=>u.length>0&&T(x=>!x),disabled:u.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(Ft,{className:`w-4 h-4 transition-transform ${Q?"rotate-180":""}`})}),Q&&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(x=>e.jsxs("button",{type:"button",onClick:()=>{a({...s,ai_model:x}),T(!1)},className:"w-full px-4 py-2.5 text-left text-sm text-gray-700 hover:bg-blue-50 hover:text-[#0094f7] flex items-center justify-between gap-3",children:[e.jsx("span",{className:"truncate",children:x}),x===W&&e.jsx(Ae,{className:"w-4 h-4 shrink-0 text-[#0094f7]"})]},x)):e.jsx("div",{className:"px-4 py-3 text-sm text-gray-400",children:"没有匹配的模型"})})]}),e.jsxs("button",{type:"button",onClick:()=>K(void 0,!0),disabled:b,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(Se,{className:`w-4 h-4 ${b?"animate-spin":""}`}),"读取模型"]})]}),te?e.jsx("p",{className:"text-xs text-red-500",children:te}):e.jsx("p",{className:"text-xs text-gray-500",children:u.length>0?`已从当前 API 地址读取到 ${u.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.jsx("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-900 text-white",children:e.jsx(As,{className:"w-4 h-4"})}),"登录凭据"]}),e.jsxs("form",{onSubmit:A,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(Et,{className:"absolute left-4 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400"}),e.jsx("input",{type:"text",value:C.new_username,onChange:x=>re({...C,new_username:x.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:X?"text":"password",value:C.current_password,onChange:x=>re({...C,current_password:x.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:()=>ee(!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(Ge,{className:"w-4 h-4"}):e.jsx(ze,{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:I?"text":"password",value:C.new_password,onChange:x=>re({...C,new_password:x.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:()=>J(!I),className:"absolute right-2 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600",title:I?"隐藏密码":"显示密码",children:I?e.jsx(Ge,{className:"w-4 h-4"}):e.jsx(ze,{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:I?"text":"password",value:C.confirm_password,onChange:x=>re({...C,confirm_password:x.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl text-sm",placeholder:"再次输入新密码",autoComplete:"new-password"})]})]}),F&&e.jsxs("div",{className:`flex items-start gap-2 rounded-xl px-3 py-2.5 text-sm font-medium ${F.type==="success"?"bg-green-50 text-green-700":"bg-red-50 text-red-700"}`,children:[e.jsx(at,{className:"w-4 h-4 mt-0.5 flex-shrink-0"}),e.jsx("span",{children:F.text})]}),e.jsxs("button",{type:"submit",disabled:U||!C.new_username||!C.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(As,{className:"w-4 h-4"}),U?"正在更新...":"更新登录凭据"]})]})]})})]}),e.jsx("div",{className:"fixed bottom-10 right-10 z-30",children:e.jsxs("button",{onClick:S,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(Le,{className:"w-6 h-6"}),k?"保存中...":"保存所有配置"]})})]})},Re={order_paid:{label:"付款后自动发货",shortLabel:"自动发货",description:"闲鱼付款系统卡片进入自动化中心后,先发送卡密,成功后再确认发货。",flow:["付款系统卡片","匹配商品/规格","发送卡密","确认发货"],accent:"blue",icon:Xe},buyer_reviewed:{label:"评价后发送赠品",shortLabel:"评价赠品",description:"闲鱼评价系统卡片进入自动化中心后,给买家发送赠品卡密。",flow:["评价系统卡片","匹配商品/规格","发送赠品"],accent:"emerald",icon:Rt},review_missing_timeout:{label:"超时未评价求评价",shortLabel:"求评价",description:"计划任务扫描已发货未评价订单,到期后发送求评价文案。",flow:["计划任务扫描","已发货未评价","达到等待时间","发送提醒"],accent:"amber",icon:lt}},ps=["order_paid","buyer_reviewed","review_missing_timeout"],cl="亲,商品使用满意的话,麻烦给个评价,谢谢~",Ve=()=>({spec_name:"",spec_value:"",card_id:0,delivery_count:1,enabled:!0}),mt=s=>{if(!s)return{};try{const a=JSON.parse(s);return a&&typeof a=="object"&&!Array.isArray(a)?a:{}}catch{return{}}},Te=(s,a={})=>{const l=mt(s);return JSON.stringify({after_shipped_hours:Number(l.after_shipped_hours||72),max_attempts:Number(l.max_attempts||1),...a})},Qe=(s,a)=>{var h;const l=((h=Re[s])==null?void 0:h.label)||"自动化规则";return a?`${l} - ${a}`:l},Js=s=>{const a=(s||"").trim();return a?Object.values(Re).some(l=>a===l.label||a.startsWith(`${l.label} -`)):!0},Ye=(s,a=0)=>{if(s==="review_missing_timeout")return[{action_type:"send_text",message_template:cl,enabled:!0,sort_order:1}];const l={action_type:"send_card",card_id:a,delivery_count:1,enabled:!0,sort_order:1};return s==="order_paid"?[l,{action_type:"confirm_shipment",enabled:!0,sort_order:2}]:[l]},xl=s=>{var l,h;if(s.trigger_type==="review_missing_timeout")return((h=(l=s.actions)==null?void 0:l.find(g=>g.action_type==="send_text"))==null?void 0:h.message_template)||"发送求评价文案";const a=(s.actions||[]).filter(g=>g.action_type==="send_card");return a.length?a.map(g=>g.card_name||`卡密 ${g.card_id}`).join(" / "):"未配置卡密库存"},Vs=(s,a=!1)=>{const l={blue:a?"border-blue-500 bg-blue-50 text-blue-700":"border-blue-100 bg-blue-50/60 text-blue-700 hover:border-blue-300",emerald:a?"border-emerald-500 bg-emerald-50 text-emerald-700":"border-emerald-100 bg-emerald-50/60 text-emerald-700 hover:border-emerald-300",amber:a?"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[s]||l.blue},ml=s=>s?"bg-emerald-100 text-emerald-700":"bg-gray-200 text-gray-500",ts=s=>(s==null?void 0:s.nickname)||(s==null?void 0:s.remark)||(s==null?void 0:s.id)||"未知账号",pl=s=>s===!0||s===1||s==="1",ul=({initialDeliveryTarget:s,onDeliveryTargetHandled:a})=>{var $e,Je,Fe;const[l,h]=d.useState("automation"),[g,p]=d.useState([]),[k,_]=d.useState([]),[u,q]=d.useState({}),[b,Y]=d.useState([]),[te,B]=d.useState([]),[Q,T]=d.useState([]),[Z,H]=d.useState(!1),[E,X]=d.useState(""),[ee,I]=d.useState(!1),[J,U]=d.useState(!1),[v,F]=d.useState(!1),[o,C]=d.useState(null),[re,K]=d.useState(null),[z,S]=d.useState({cookie_id:"",enabled:!1,reply_content:"",reply_once:!1,reply_image_url:""});b.find(n=>n.id===E);const A=d.useCallback(async()=>{const[n,j,w,G]=await Promise.all([Ns(),Ie(),We(),Bs()]);Y(n),B(j),T(w),q(G),X(ce=>{var je;return ce||((je=n[0])==null?void 0:je.id)||""})},[]),W=d.useCallback(async()=>{p(await rs())},[]),m=d.useCallback(async()=>{if(!E){_([]);return}_(await Ra(E))},[E]),x=d.useCallback(async()=>{q(await Bs())},[]),P=d.useCallback(async()=>{H(!0);try{l==="automation"?await W():l==="reply"?await m():await x()}finally{H(!1)}},[l,W,x,m]);d.useEffect(()=>{A()},[A]),d.useEffect(()=>{P()},[P]);const N=d.useMemo(()=>g.filter(n=>!E||n.cookie_id===E),[g,E]),se=d.useMemo(()=>b.filter(n=>!E||n.id===E),[b,E]),D=d.useMemo(()=>{var j;const n={order_paid:[],buyer_reviewed:[],review_missing_timeout:[]};for(const w of N)(j=n[w.trigger_type])==null||j.push(w);return n},[N]),i=d.useMemo(()=>{const n=(o==null?void 0:o.cookie_id)||E;return Q.filter(j=>j.cookie_id===n)},[o==null?void 0:o.cookie_id,Q,E]),R=d.useMemo(()=>{if(!(!(o!=null&&o.cookie_id)||!(o!=null&&o.item_id)))return Q.find(n=>n.cookie_id===o.cookie_id&&n.item_id===o.item_id)},[o==null?void 0:o.cookie_id,o==null?void 0:o.item_id,Q]),ne=pl(R==null?void 0:R.is_multi_spec),ae=(o==null?void 0:o.trigger_type)||"order_paid",c=Re[ae],f=mt(o==null?void 0:o.config_json),V=d.useCallback((n="order_paid",j=E,w="")=>{const G=Q.find(je=>je.cookie_id===j&&je.item_id===w),ce=(G==null?void 0:G.item_title)||w;return{name:Qe(n,ce),trigger_type:n,cookie_id:j,item_id:w,item_title:(G==null?void 0:G.item_title)||"",item_keyword:ce,card_group_id:0,priority:100,enabled:!0,config_json:n==="review_missing_timeout"?Te():"{}",actions:Ye(n),variants:n==="review_missing_timeout"?[]:[Ve()]}},[Q,E]),le=d.useCallback(n=>{var w,G;const j=n.trigger_type||"order_paid";C({...n,trigger_type:j,config_json:j==="review_missing_timeout"?Te(n.config_json):n.config_json||"{}",actions:(w=n.actions)!=null&&w.length?n.actions.map(ce=>({...ce})):Ye(j,n.card_group_id),variants:(G=n.variants)!=null&&G.length?n.variants.map(ce=>({...ce})):j==="review_missing_timeout"?[]:[Ve()]}),I(!0)},[]);d.useEffect(()=>{if(!s)return;let n=!1;return(async()=>{h("automation"),X(s.cookieId),H(!0);try{const[w,G,ce]=await Promise.all([rs(),We(),Ie().catch(xe=>(console.warn("加载卡密库存失败,不阻断打开自动化规则",xe),[]))]);if(n)return;p(w),T(G),B(ce);const je=w.find(xe=>xe.cookie_id===s.cookieId&&xe.item_id===s.itemId&&xe.trigger_type==="order_paid");if(je)le(je);else{const xe=G.find(Ee=>Ee.cookie_id===s.cookieId&&Ee.item_id===s.itemId);C({...V("order_paid",s.cookieId,s.itemId),item_title:(xe==null?void 0:xe.item_title)||"",item_keyword:(xe==null?void 0:xe.item_title)||s.itemId,name:Qe("order_paid",(xe==null?void 0:xe.item_title)||s.itemId)}),I(!0)}}catch(w){console.error("打开商品自动化规则失败",w),alert("无法加载该商品的自动化规则")}finally{n||(H(!1),a==null||a())}})(),()=>{n=!0}},[V,s,a,le]);const M=(n="order_paid")=>{if(!E){alert("请先选择账号");return}C(V(n)),I(!0)},ge=n=>{var G,ce,je,xe,Ee;if(!o)return;const j=((ce=(G=o.variants)==null?void 0:G.find(ue=>ue.card_id))==null?void 0:ce.card_id)||((xe=(je=o.actions)==null?void 0:je.find(ue=>ue.action_type==="send_card"))==null?void 0:xe.card_id)||o.card_group_id||0,w=(R==null?void 0:R.item_title)||o.item_title||o.item_id||"";C({...o,trigger_type:n,name:Js(o.name)?Qe(n,w):o.name,card_group_id:j,config_json:n==="review_missing_timeout"?Te(o.config_json):"{}",actions:Ye(n,j),variants:n==="review_missing_timeout"?[]:(Ee=o.variants)!=null&&Ee.length?o.variants:[{...Ve(),card_id:j}]})},ve=n=>{if(!o)return;const j=Q.find(G=>G.cookie_id===(o.cookie_id||E)&&G.item_id===n),w=(j==null?void 0:j.item_title)||n;C({...o,item_id:n,item_title:(j==null?void 0:j.item_title)||"",item_keyword:w,name:Js(o.name)?Qe(ae,w):o.name})},be=($e=o==null?void 0:o.variants)!=null&&$e.length?o.variants:[Ve()],_e=(n,j)=>{var G;if(!o)return;const w=be.map((ce,je)=>je===n?{...ce,...j}:ce);C({...o,variants:w,card_group_id:((G=w[0])==null?void 0:G.card_id)||0})},Ce=()=>{if(!o)return;const n=be[be.length-1];C({...o,variants:[...be,{...Ve(),spec_name:ne&&(n==null?void 0:n.spec_name)||"",spec_value:ne&&(n==null?void 0:n.spec_value)||""}]})},we=async()=>{var G,ce,je,xe,Ee;if(!o)return;const n=o.trigger_type||"order_paid";if(!o.cookie_id){alert("请选择账号");return}const j=(G=o.variants)!=null&&G.length?o.variants:[];if(n!=="review_missing_timeout"){if(!j.length||j.some(ue=>!ue.card_id)){alert(n==="buyer_reviewed"?"请选择评价赠品卡密库存":"请选择发货卡密库存");return}if(ne&&j.some(ue=>!ue.spec_name.trim()||!ue.spec_value.trim())){alert("多规格商品必须填写每一行的规格名称和规格值");return}}if(n==="review_missing_timeout"&&!(((je=(ce=o.actions)==null?void 0:ce.find(gt=>gt.action_type==="send_text"))==null?void 0:je.message_template)||"").trim()){alert("请填写求评价文案");return}const w=n==="review_missing_timeout"?[]:j.map(ue=>({...ue,spec_name:ne?ue.spec_name.trim():"",spec_value:ne?ue.spec_value.trim():"",delivery_count:Math.max(1,Number(ue.delivery_count)||1),enabled:ue.enabled!==!1}));try{await Ms({...o,trigger_type:n,name:(o.name||"").trim()||Qe(n,(R==null?void 0:R.item_title)||o.item_id||""),config_json:n==="review_missing_timeout"?Te(o.config_json):o.config_json||"{}",actions:(xe=o.actions)!=null&&xe.length?o.actions:Ye(n,((Ee=w[0])==null?void 0:Ee.card_id)||o.card_group_id||0),variants:w}),I(!1),await Promise.all([W(),A()]),alert("保存成功")}catch(ue){console.error("保存自动化规则失败:",ue),alert("保存失败:"+ue.message)}},ye=async n=>{if(confirm("确定删除该自动化规则吗?"))try{await Fa(n),await W(),alert("删除成功")}catch(j){alert("删除失败:"+j.message)}},fe=async n=>{try{await Ms({...n,enabled:!n.enabled}),await W()}catch(j){alert("操作失败:"+j.message)}},t=()=>{if(!E){alert("请先选择账号");return}K({keyword:"",reply_content:"",match_type:"fuzzy",enabled:!0}),U(!0)},y=async()=>{var j,w,G;if(!re||!E)return;const n=!!((j=re.reply_content)!=null&&j.trim()||(w=re.image_url)!=null&&w.trim());if(!((G=re.keyword)!=null&&G.trim())||!n){alert("请填写关键词和回复内容");return}try{await Oa({...re,match_type:"fuzzy",enabled:!0},E),U(!1),await m(),alert("保存成功")}catch(ce){alert("保存失败:"+ce.message)}},$=async n=>{if(!(!E||!confirm("确定删除该回复规则吗?")))try{await Ta(n,E),await m(),alert("删除成功")}catch(j){alert("删除失败:"+j.message)}},O=async(n=E)=>{if(!n){alert("请先选择账号");return}try{const j=await Ya(n);S({cookie_id:n,enabled:j.enabled,reply_content:j.reply_content,reply_once:j.reply_once,reply_image_url:j.reply_image_url||""})}catch{S({cookie_id:n,enabled:!1,reply_content:"",reply_once:!1,reply_image_url:""})}F(!0)},oe=async()=>{if(!z.cookie_id){alert("请先选择账号");return}if(z.enabled&&!z.reply_content.trim()&&!z.reply_image_url.trim()){alert("启用默认回复时,请填写回复内容或图片 URL");return}try{await Ka(z.cookie_id,{enabled:z.enabled,reply_content:z.reply_content,reply_once:z.reply_once,reply_image_url:z.reply_image_url}),F(!1),await x(),alert("保存成功")}catch(n){alert("保存失败:"+n.message)}},r=async n=>{if(confirm("确定删除该账号默认回复吗?"))try{await Ga(n),await x(),alert("删除成功")}catch(j){alert("删除失败:"+j.message)}},L=async n=>{if(confirm("确定清空该账号的默认回复记录吗?清空后可重新对所有会话使用“只回复一次”。"))try{await Xa(n),alert("清空成功")}catch(j){alert("清空失败:"+j.message)}},ie=l==="automation"?"新建自动化":l==="reply"?"新增关键词":"编辑默认回复";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:"系统通知卡片只进入自动化判断;买家消息进入关键词、默认或 AI 回复。"})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[e.jsxs("select",{value:E,onChange:n=>X(n.target.value),className:"ios-input px-4 py-3 rounded-2xl text-sm min-w-64",children:[e.jsx("option",{value:"",children:"全部账号"}),b.map(n=>e.jsx("option",{value:n.id,children:ts(n)},n.id))]}),e.jsxs("button",{onClick:P,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 transition-colors",children:[e.jsx(Se,{className:`w-4 h-4 ${Z?"animate-spin":""}`}),"刷新"]}),e.jsxs("button",{onClick:l==="automation"?()=>M("order_paid"):l==="reply"?t:()=>void O(),disabled:!E,className:"ios-btn-primary px-5 py-3 rounded-2xl text-sm font-extrabold flex items-center justify-center gap-2 disabled:opacity-50",children:[e.jsx(Pe,{className:"w-4 h-4"}),ie]})]})]}),e.jsx("div",{className:"flex flex-wrap gap-2 p-2 bg-gray-100/50 rounded-2xl",children:[{id:"automation",label:"交易自动化",icon:hs},{id:"reply",label:"关键词回复",icon:as},{id:"default",label:"账号默认回复",icon:qe}].map(n=>{const j=n.icon;return e.jsxs("button",{onClick:()=>h(n.id),className:`inline-flex items-center gap-2 px-5 py-2.5 rounded-xl text-sm font-bold transition-all ${l===n.id?"bg-[#0094f7] text-white shadow-md":"bg-white text-gray-600 hover:text-black hover:bg-gray-50"}`,children:[e.jsx(j,{className:"w-4 h-4"}),n.label]},n.id)})}),l==="automation"&&e.jsxs("div",{className:"grid grid-cols-1 2xl:grid-cols-[360px_1fr] gap-6",children:[e.jsxs("aside",{className:"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:ps.map(n=>{const j=Re[n],w=j.icon;return e.jsx("button",{type:"button",onClick:()=>M(n),className:`w-full text-left rounded-2xl border p-4 transition-colors ${Vs(j.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(w,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-extrabold",children:j.label}),e.jsx("div",{className:"text-xs opacity-75 mt-1 leading-5",children:j.description})]})]})},n)})})]}),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-4",children:"规则概览"}),e.jsx("div",{className:"space-y-3",children:ps.map(n=>{const j=Re[n],w=j.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(w,{className:"w-4 h-4 text-gray-500"}),e.jsx("span",{className:"text-sm font-bold text-gray-700",children:j.shortLabel})]}),e.jsx("span",{className:"text-sm font-black text-gray-900",children:D[n].length})]},n)})})]})]}),e.jsx("section",{className:"space-y-4",children:N.length===0?e.jsxs("div",{className:"bg-white rounded-xl border border-dashed border-gray-200 p-16 text-center",children:[e.jsx(hs,{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.jsx("p",{className:"text-gray-500 mt-2",children:"从左侧选择一个模板开始配置。"})]}):N.map(n=>{const j=Re[n.trigger_type],w=j.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 ${Vs(j.accent,!0)}`,children:e.jsx(w,{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:n.name}),e.jsx("span",{className:`px-2.5 py-1 rounded-full text-xs font-bold ${ml(n.enabled)}`,children:n.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:j.label}),e.jsx("span",{className:"px-2.5 py-1 rounded-lg bg-gray-100 text-gray-600",children:n.item_title||n.item_id||"账号级规则"}),e.jsx("span",{className:"px-2.5 py-1 rounded-lg bg-blue-50 text-blue-700",children:xl(n)})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsxs("button",{onClick:()=>le(n),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(Ue,{className:"w-4 h-4"}),"编辑"]}),e.jsx("button",{onClick:()=>fe(n),className:`px-4 py-2 rounded-xl text-sm font-bold ${n.enabled?"bg-amber-50 text-amber-700 hover:bg-amber-100":"bg-emerald-50 text-emerald-700 hover:bg-emerald-100"}`,children:n.enabled?"禁用":"启用"}),e.jsx("button",{onClick:()=>ye(n.id),className:"p-2.5 rounded-xl text-red-500 hover:bg-red-50",title:"删除",children:e.jsx(De,{className:"w-4 h-4"})})]})]})},n.id)})})]}),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(ls,{className:"w-4 h-4"}),"这里只处理买家用户消息;系统通知不会进入关键词或 AI 回复。"]}),e.jsxs("div",{className:"space-y-3",children:[k.map(n=>e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between p-5 rounded-2xl border border-gray-100 bg-[#F7F8FA] 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:["“",n.keyword,"”"]})]}),e.jsx("div",{className:"bg-white p-3 rounded-xl border border-gray-100 text-sm text-gray-600 leading-relaxed",children:n.type==="image"&&n.image_url?n.image_url:n.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:()=>{K({...n}),U(!0)},className:"p-2 text-gray-400 hover:text-black hover:bg-gray-100 rounded-xl transition-colors",title:"编辑",children:e.jsx(Ue,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>$(n.id),className:"p-2 text-gray-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors",title:"删除",children:e.jsx(De,{className:"w-5 h-5"})})]})]},n.id)),k.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(ls,{className:"w-4 h-4"}),"默认回复只处理买家用户消息;关键词未命中且 AI 未接管时才会使用。"]}),e.jsxs("div",{className:"space-y-3",children:[se.map(n=>{const j=u[n.id],w=!!(j!=null&&j.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 ${w?"border-purple-100 bg-purple-50/50 hover:bg-white hover:shadow-lg":"border-gray-100 bg-[#F7F8FA] 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 ${w?"bg-purple-600 text-white":"bg-gray-200 text-gray-400"}`,children:e.jsx(qe,{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:ts(n)}),e.jsx("span",{className:`px-2 py-0.5 rounded-lg text-xs font-bold ${w?"bg-green-100 text-green-700":"bg-gray-200 text-gray-500"}`,children:w?"已启用":"未启用"}),(j==null?void 0:j.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:w?j.reply_content||j.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 O(n.id),className:"p-2 text-gray-400 hover:text-black hover:bg-gray-100 rounded-xl transition-colors",title:"编辑",children:e.jsx(Ue,{className:"w-4 h-4"})}),w&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>void L(n.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 r(n.id),className:"p-2 text-gray-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors",title:"删除",children:e.jsx(De,{className:"w-5 h-5"})})]})]})]},n.id)}),se.length===0&&e.jsx("div",{className:"text-center py-20 text-gray-400",children:"暂无账号"})]})]}),ee&&o&&he.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:o.id?"编辑自动化规则":"新建自动化规则"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:c.description})]}),e.jsx("button",{onClick:()=>I(!1),className:"w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center",title:"关闭",children:e.jsx(pe,{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:ps.map(n=>{const j=Re[n],w=j.icon,G=ae===n;return e.jsx("button",{type:"button",onClick:()=>ge(n),className:`w-full rounded-2xl p-4 text-left border transition-all ${G?"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(w,{className:`w-5 h-5 mt-0.5 ${G?"text-[#0094f7]":"text-white"}`}),e.jsxs("div",{children:[e.jsx("div",{className:"font-black",children:j.label}),e.jsx("div",{className:`text-xs mt-1 leading-5 ${G?"text-gray-500":"text-gray-400"}`,children:j.description})]})]})},n)})}),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:c.flow.map((n,j)=>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:j+1}),e.jsx("span",{className:"text-sm font-bold text-gray-100",children:n})]},n))})]})]}),e.jsx("div",{className:"p-6 overflow-y-auto bg-[#F7F8FA]",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(tt,{className:"w-5 h-5 text-[#0094f7]"}),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:o.name||"",onChange:n=>C({...o,name:n.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:o.cookie_id||"",onChange:n=>C({...o,cookie_id:n.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:"选择账号"}),b.map(n=>e.jsx("option",{value:n.id,children:ts(n)},n.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"关联商品"}),e.jsxs("select",{value:o.item_id||"",onChange:n=>ve(n.target.value),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"账号级规则(不限定商品)"}),i.map(n=>e.jsx("option",{value:n.item_id,children:n.item_title||n.item_id},`${n.cookie_id}-${n.item_id}`))]})]})]}),R&&ae!=="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:R.item_title||R.item_id}),e.jsx("span",{className:`px-3 py-1.5 rounded-lg text-xs font-bold ${ne?"bg-blue-50 text-blue-700":"bg-gray-100 text-gray-500"}`,children:ne?"多规格商品":"普通商品"}),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:"多规格状态来自闲鱼商品本身,发布后不能在这里修改;系统会在买家付款后读取订单详情,按实际购买规格和数量匹配下面的发货规则。"})]})]}),ae!=="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(Ot,{className:"w-5 h-5 text-[#0094f7]"}),e.jsx("h4",{className:"font-black text-gray-900",children:ae==="buyer_reviewed"?"赠品库存":"发货库存"})]}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:ne?"每条发货内容绑定一个订单规格;同一规格可添加多条内容并全部发送。":"可添加多条发货内容,买家付款后会按顺序全部发送。"})]}),e.jsxs("button",{type:"button",onClick:Ce,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(Pe,{className:"w-3.5 h-3.5"}),"添加发货内容"]})]}),e.jsx("div",{className:"space-y-3",children:be.map((n,j)=>e.jsxs("div",{className:`grid grid-cols-1 gap-3 items-end rounded-2xl border border-gray-200 p-4 ${ne?"md:grid-cols-[1fr_1fr_1.4fr_110px_40px]":"md:grid-cols-[1.4fr_110px_40px]"}`,children:[ne&&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:n.spec_name,onChange:w=>_e(j,{spec_name:w.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:n.spec_value,onChange:w=>_e(j,{spec_value:w.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:n.card_id||"",onChange:w=>_e(j,{card_id:Number(w.target.value)}),className:"w-full ios-input px-3 py-2.5 rounded-lg",children:[e.jsx("option",{value:"",children:"请选择卡密库存"}),te.filter(w=>w.enabled).map(w=>e.jsx("option",{value:w.id,children:w.name},w.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:n.delivery_count,onChange:w=>_e(j,{delivery_count:Math.max(1,Number(w.target.value)||1)}),className:"w-full ios-input px-3 py-2.5 rounded-lg"})]}),e.jsx("button",{type:"button",disabled:be.length===1,onClick:()=>C({...o,variants:be.filter((w,G)=>G!==j)}),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(De,{className:"w-4 h-4"})})]},n.id||j))})]}):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(lt,{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-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:"number",min:"1",value:Number(f.after_shipped_hours||72),onChange:n=>C({...o,config_json:Te(o.config_json,{after_shipped_hours:Math.max(1,Number(n.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(f.max_attempts||1),onChange:n=>C({...o,config_json:Te(o.config_json,{max_attempts:Math.max(1,Number(n.target.value)||1)})}),className:"w-full ios-input px-4 py-3 rounded-xl"})]}),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("textarea",{value:((Fe=(Je=o.actions)==null?void 0:Je.find(n=>n.action_type==="send_text"))==null?void 0:Fe.message_template)||"",onChange:n=>{var j;return C({...o,actions:((j=o.actions)!=null&&j.length?o.actions:Ye("review_missing_timeout")).map(w=>w.action_type==="send_text"?{...w,message_template:n.target.value}:w)})},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("input",{type:"number",value:o.priority||100,onChange:n=>C({...o,priority:Number(n.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:o.enabled!==!1,onChange:n=>C({...o,enabled:n.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:()=>I(!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:we,className:"flex-1 ios-btn-primary px-6 py-3 rounded-2xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Le,{className:"w-4 h-4"}),"保存自动化规则"]})]})]})}),document.body),J&&re&&he.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:re.id?"编辑回复规则":"新增回复规则"}),e.jsx("button",{onClick:()=>U(!1),className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",children:e.jsx(pe,{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.jsx("input",{type:"text",value:re.keyword||"",onChange:n=>K({...re,keyword:n.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.jsx("textarea",{value:re.reply_content||"",onChange:n=>K({...re,reply_content:n.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:()=>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:y,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(fs,{className:"w-4 h-4"}),"保存规则"]})]})]})]})}),document.body),v&&he.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:()=>F(!1),className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",title:"关闭",children:e.jsx(pe,{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:z.cookie_id,onChange:n=>S({...z,cookie_id:n.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"选择账号"}),b.map(n=>e.jsx("option",{value:n.id,children:ts(n)},n.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:()=>S({...z,enabled:!z.enabled}),className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${z.enabled?"bg-[#0094f7]":"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 ${z.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:z.reply_content,onChange:n=>S({...z,reply_content:n.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:z.reply_image_url,onChange:n=>S({...z,reply_image_url:n.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:z.reply_once,onChange:n=>S({...z,reply_once:n.target.checked}),className:"w-4 h-4 rounded"})]}),e.jsxs("div",{className:"flex gap-3 pt-4",children:[e.jsx("button",{onClick:()=>F(!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:oe,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Le,{className:"w-4 h-4"}),"保存默认回复"]})]})]})]})}),document.body)]})},Me={bark:{label:"Bark",icon:Be,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:"闲鱼助手"},{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:as,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:as,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:as,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:Tt,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:fs,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:rt,fields:[{key:"to_email",label:"收件邮箱",placeholder:"[email protected]",required:!0},{key:"smtp_server",label:"覆盖 SMTP 服务器",placeholder:"smtp.qq.com",help:"留空时使用上方系统级 SMTP 配置"},{key:"smtp_port",label:"覆盖 SMTP 端口",placeholder:"587",type:"number",help:"留空时使用系统级 SMTP 端口"},{key:"smtp_user",label:"覆盖发件邮箱",placeholder:"[email protected]",help:"留空时使用系统级发件邮箱"},{key:"smtp_password",label:"覆盖密码 / 授权码",type:"password",help:"留空时使用系统级授权码"}],guide:{steps:["先在页面上方保存系统级 SMTP 服务器、端口、发件邮箱和授权码","邮件渠道只需要填写收件邮箱","如果某个渠道要使用不同发件邮箱,再填写下面的覆盖 SMTP 字段"],note:"收件邮箱会写入 to_email;SMTP 字段留空时后端会复用系统级 SMTP 配置。"}}},pt=[{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:"后台任务或系统级异常"}],hl=s=>!s||s.length===0?"全部事件":s.map(l=>{var h;return((h=pt.find(g=>g.value===l))==null?void 0:h.label)||l}).join("、"),gl=({isAdmin:s=!1})=>{const[a,l]=d.useState([]),[h,g]=d.useState(!0),[p,k]=d.useState(!1),[_,u]=d.useState(null),[q,b]=d.useState(!1),[Y,te]=d.useState(""),[B,Q]=d.useState(null),[T,Z]=d.useState({}),[H,E]=d.useState(!1),[X,ee]=d.useState(!1),[I,J]=d.useState({name:"",type:"bark",enabled:!0,config:{},event_types:[]}),U=async()=>{g(!0);try{const m=await xt();l(m.data||[])}catch(m){console.error("加载通知渠道失败",m)}finally{g(!1)}},v=async()=>{try{const m=await ot();Z(m||{})}catch(m){console.error("加载 SMTP 配置失败",m)}},F=async()=>{E(!0);try{await dt({smtp_server:T.smtp_server||"",smtp_port:T.smtp_port||587,smtp_user:T.smtp_user||"",smtp_password:T.smtp_password||"",smtp_from:T.smtp_from||""}),o("success","SMTP 配置已保存")}catch(m){o("error",(m==null?void 0:m.message)||"保存失败")}finally{E(!1)}};d.useEffect(()=>{U(),s?v():Z({})},[s]);const o=(m,x)=>{Q({type:m,text:x}),window.setTimeout(()=>Q(null),3e3)},C=()=>{u(null),J({name:"",type:"bark",enabled:!0,config:{},event_types:[]}),k(!0)},re=m=>{u(m),J({name:m.name,type:m.type,enabled:m.enabled,config:{...m.config||{}},event_types:m.event_types||[]}),k(!0)},K=async()=>{const m=Me[I.type];for(const x of m.fields)if(x.required&&!String(I.config[x.key]||"").trim()){o("error",`请填写 ${x.label}`);return}if(!I.name.trim()){o("error","请填写渠道名称");return}b(!0);try{const x={name:I.name.trim(),type:I.type,config:I.config,event_types:I.event_types,enabled:I.enabled};_?await qs(_.id,x):await Ua(x),k(!1),await U(),o("success",_?"已更新":"已创建")}catch(x){console.error("保存失败",x),o("error",(x==null?void 0:x.message)||"保存失败")}finally{b(!1)}},z=async m=>{if(confirm(`确认删除渠道「${m.name}」吗?已绑定该渠道的账号会自动解绑。`))try{await Wa(m.id),await U(),o("success","已删除")}catch(x){o("error",(x==null?void 0:x.message)||"删除失败")}},S=async m=>{try{await qs(m.id,{enabled:!m.enabled}),l(x=>x.map(P=>P.id===m.id?{...P,enabled:!P.enabled}:P))}catch(x){o("error",(x==null?void 0:x.message)||"切换失败")}},A=async m=>{te(m.id);try{await Qa(m.id),o("success","测试通知已发送,请检查对应渠道")}catch(x){o("error",(x==null?void 0:x.message)||"发送失败")}finally{te("")}},W=Me[I.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:U,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(Se,{className:"w-4 h-4"}),"刷新"]}),e.jsxs("button",{onClick:C,className:"ios-btn-primary px-5 py-2.5 rounded-xl font-bold flex items-center gap-2",children:[e.jsx(Pe,{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(Be,{className:"w-5 h-5 text-[#0094f7] 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:"触发风控验证"}),":可能需要扫码完成验证(警告)"]})]})]})]})}),h?e.jsx("div",{className:"flex justify-center py-20",children:e.jsx(ke,{className:"w-8 h-8 text-[#0094f7] animate-spin"})}):a.length===0?e.jsxs("div",{className:"ios-card rounded-xl p-12 bg-white text-center",children:[e.jsx(Be,{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:a.map(m=>{const x=Me[m.type]||Me.webhook,P=x.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(P,{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:x.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:x.fields.map(N=>{var se;return(se=m.config)==null?void 0:se[N.key]}).filter(Boolean).map((N,se)=>e.jsx("span",{className:"mr-3",children:String(N).length>40?String(N).slice(0,40)+"…":String(N)},se))}),e.jsxs("div",{className:"text-xs text-gray-400 mt-1 truncate",children:["订阅:",hl(m.event_types)]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx("button",{onClick:()=>S(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:()=>A(m),disabled:Y===m.id,className:"px-3 py-1.5 rounded-lg text-xs font-bold bg-blue-50 text-[#0094f7] hover:bg-blue-100 transition-colors flex items-center gap-1 disabled:opacity-50",children:[Y===m.id?e.jsx(ke,{className:"w-3 h-3 animate-spin"}):e.jsx(fs,{className:"w-3 h-3"}),"测试"]}),e.jsx("button",{onClick:()=>re(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(st,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>z(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(De,{className:"w-4 h-4"})})]})]},m.id)})}),s&&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(rt,{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:T.smtp_server||"",onChange:m=>Z({...T,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:T.smtp_port||587,onChange:m=>Z({...T,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:T.smtp_user||"",onChange:m=>Z({...T,smtp_user:m.target.value}),placeholder:"[email protected]",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:T.smtp_password||"",onChange:m=>Z({...T,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:()=>ee(!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(Ge,{className:"w-4 h-4"}):e.jsx(ze,{className:"w-4 h-4"})})]}),e.jsx("p",{className:"text-xs text-gray-500",children:"QQ 邮箱需使用授权码(QQ 邮箱设置 → 账号 → 开启 SMTP → 生成授权码)"})]}),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:T.smtp_from||"",onChange:m=>Z({...T,smtp_from:m.target.value}),placeholder:"闲鱼自动回复系统",className:"w-full ios-input px-4 py-3 rounded-xl text-sm"})]}),e.jsxs("button",{onClick:F,disabled:H,className:"ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[H?e.jsx(ke,{className:"w-4 h-4 animate-spin"}):e.jsx(Le,{className:"w-4 h-4"}),H?"保存中...":"保存 SMTP 配置"]})]}),p&&he.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:_?"编辑通知渠道":"新建通知渠道"}),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(pe,{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:I.name,onChange:m=>J({...I,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(Me).map(m=>{const x=Me[m],P=x.icon,N=I.type===m;return e.jsxs("button",{type:"button",onClick:()=>J({...I,type:m,config:{}}),className:`p-3 rounded-xl border-2 flex flex-col items-center gap-1.5 transition-all ${N?"border-[#0094f7] bg-blue-50":"border-gray-100 hover:border-gray-300"}`,children:[e.jsx(P,{className:`w-5 h-5 ${N?"text-[#0094f7]":"text-gray-500"}`}),e.jsx("span",{className:`text-xs font-bold ${N?"text-[#0094f7]":"text-gray-600"}`,children:x.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(Be,{className:"w-4 h-4 text-amber-600"}),e.jsxs("span",{className:"text-sm font-bold text-amber-800",children:["如何获取 ",W.label," 配置?"]})]}),e.jsx("ol",{className:"space-y-1.5 text-xs text-amber-900/90 leading-5 list-decimal pl-5",children:W.guide.steps.map((m,x)=>e.jsx("li",{children:m},x))}),W.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:W.guide.urlFormat})]}),W.guide.note&&e.jsxs("p",{className:"text-xs text-amber-800/80 leading-5 pt-1",children:["💡 ",W.guide.note]})]}),e.jsx("div",{className:"space-y-3",children:W.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(I.config[m.key]||""),onChange:x=>J({...I,config:{...I.config,[m.key]:x.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))}),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:pt.map(m=>{const x=I.event_types.includes(m.value);return e.jsxs("button",{type:"button",onClick:()=>{const P=x?I.event_types.filter(N=>N!==m.value):[...I.event_types,m.value];J({...I,event_types:P})},className:`text-left rounded-xl border px-3 py-2.5 transition-colors ${x?"border-[#0094f7] 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 ${x?"bg-[#0094f7] border-[#0094f7]":"border-gray-300"}`,children:x&&e.jsx(Ae,{className:"w-3 h-3 text-white"})}),e.jsx("span",{className:`text-sm font-bold ${x?"text-[#0094f7]":"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:()=>J({...I,enabled:!I.enabled}),className:`relative w-11 h-6 rounded-full transition-colors ${I.enabled?"bg-[#0094f7]":"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 ${I.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:K,disabled:q,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[q?e.jsx(ke,{className:"w-4 h-4 animate-spin"}):e.jsx(Ae,{className:"w-4 h-4"}),q?"保存中...":"保存"]})]})]})}),document.body),B&&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",style:{background:B.type==="success"?"#10b981":"#ef4444",color:"white"},children:[B.type==="success"?e.jsx(Ae,{className:"w-4 h-4"}):e.jsx(pe,{className:"w-4 h-4"}),B.text]})]})},ut={"/app/dashboard":"dashboard","/app/accounts":"accounts","/app/orders":"orders","/app/cards":"cards","/app/items":"items","/app/rules":"rules","/app/notifications":"notifications","/app/settings":"settings"},Qs=Object.fromEntries(Object.entries(ut).map(([s,a])=>[a,s])),Ys=()=>ut[window.location.pathname]||"dashboard",bl=/Win/i.test(navigator.platform||navigator.userAgent),yl=()=>{const[s,a]=d.useState(!1),[l,h]=d.useState(!1),[g,p]=d.useState(Ys),[k,_]=d.useState(!0),[u,q]=d.useState(!1),[b,Y]=d.useState(""),[te,B]=d.useState(""),[Q,T]=d.useState(!1),[Z,H]=d.useState(""),[E,X]=d.useState(),ee=v=>{const F=v==="settings"&&!l?"dashboard":v,o=Qs[F];o&&o!==window.location.pathname&&window.history.pushState({},"",o),p(F)};d.useEffect(()=>{const v=()=>p(Ys());return window.addEventListener("popstate",v),()=>window.removeEventListener("popstate",v)},[]),d.useEffect(()=>{nt().then(F=>{if((F==null?void 0:F.initialized)===!1){q(!0),a(!1),h(!1);return}q(!1),F!=null&&F.authenticated?(a(!0),h(F.is_admin===!0)):h(!1)}).catch(()=>{a(!1),h(!1)}).finally(()=>_(!1));const v=()=>{a(!1),h(!1)};return window.addEventListener("auth:logout",v),()=>window.removeEventListener("auth:logout",v)},[]),d.useEffect(()=>{!k&&s&&!l&&g==="settings"&&(window.history.replaceState({},"",Qs.dashboard),p("dashboard"))},[k,s,l,g]);const I=async v=>{v.preventDefault(),T(!0),H("");try{const F=await Kt({username:b,password:te});F.success?(a(!0),h(F.is_admin===!0)):H(F.message||"登录失败")}catch(F){const o=F instanceof Error?F.message:String(F);H(o||"登录失败")}finally{T(!1)}},J=async()=>{try{await Gt()}catch(v){console.error("退出登录失败",v)}finally{a(!1),h(!1)}};if(k)return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-[#f5f5f7]",children:e.jsx(ke,{className:"w-8 h-8 text-[#0094f7] animate-spin"})});if(u)return e.jsxs("div",{className:"min-h-screen flex items-center justify-center bg-[#F4F5F7] 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-[0_20px_60px_-15px_rgba(0,0,0,0.05)] 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:"w-24 h-24 bg-[#0094f7] squircle flex items-center justify-center mx-auto mb-6 transition-all duration-500 p-4",style:{filter:"drop-shadow(0 8px 20px rgba(0,148,247,0.3))"},children:e.jsx("img",{src:"/static/ydisks-logo.svg",alt:"Ydisks",className:"w-full h-full"})}),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:"为避免默认口令风险,管理员必须通过服务器本机 CLI 初始化。"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"p-4 rounded-2xl bg-gray-50 border border-gray-100",children:[e.jsx("div",{className:"text-sm font-bold text-gray-900 mb-2",children:"请在服务器上执行:"}),e.jsx("pre",{className:"text-xs bg-black text-white p-4 rounded-2xl overflow-x-auto",children:bl?'.\\xianyu-server.exe -init-admin -db data\\xianyu_data.db -admin-password "请设置密码"':"./xianyu-server -init-admin -db data/xianyu_data.db -admin-password '请设置密码'"}),e.jsx("div",{className:"text-xs text-gray-500 mt-2",children:"完成后刷新页面即可进入登录。"})]}),e.jsxs("button",{type:"button",onClick:()=>window.location.reload(),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",children:["我已初始化,刷新 ",e.jsx(bs,{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(!s)return e.jsxs("div",{className:"min-h-screen flex items-center justify-center bg-[#F4F5F7] 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-[0_20px_60px_-15px_rgba(0,0,0,0.05)] 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:"w-24 h-24 bg-[#0094f7] squircle flex items-center justify-center mx-auto mb-6 transition-all duration-500 cursor-pointer group p-4",style:{filter:"drop-shadow(0 8px 20px rgba(0,148,247,0.3))"},children:e.jsx("img",{src:"/static/ydisks-logo.svg",alt:"Ydisks",className:"w-full h-full 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:I,className:"space-y-5",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"relative group",children:[e.jsx(gs,{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:b,onChange:v=>Y(v.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(Mt,{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:te,onChange:v=>B(v.target.value),className:"w-full ios-input pl-14 pr-6 py-4.5 rounded-2xl text-base h-14"})]})]}),Z&&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(at,{className:"w-4 h-4"})," ",Z]}),e.jsx("button",{type:"submit",disabled:Q,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:Q?e.jsx(ke,{className:"w-5 h-5 animate-spin"}):e.jsxs(e.Fragment,{children:["立即登录 ",e.jsx(bs,{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 U=()=>{switch(g){case"dashboard":return e.jsx(ms,{});case"accounts":return e.jsx(tl,{});case"orders":return e.jsx(al,{});case"cards":return e.jsx(ll,{});case"items":return e.jsx(nl,{onConfigureDelivery:v=>{X({cookieId:v.cookie_id,itemId:v.item_id,requestId:Date.now()}),ee("rules")}});case"rules":return e.jsx(ul,{initialDeliveryTarget:E,onDeliveryTargetHandled:()=>X(void 0)});case"notifications":return e.jsx(gl,{isAdmin:l});case"settings":return l?e.jsx(dl,{}):e.jsx(ms,{});default:return e.jsx(ms,{})}};return e.jsxs("div",{className:"flex min-h-screen bg-[#F4F5F7] text-[#111]",children:[e.jsx(Vt,{activeTab:g,isAdmin:l,onNavigate:ee,onLogout:J}),e.jsxs("main",{className:"flex-1 ml-64 p-8 md:p-12 overflow-y-auto h-screen relative scroll-smooth",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:"max-w-[1400px] mx-auto pb-10",children:U()})]})]})},ht=document.getElementById("root");if(!ht)throw new Error("Could not find root element to mount to");const fl=bt.createRoot(ht);fl.render(e.jsx(yt.StrictMode,{children:e.jsx(yl,{})}));
|