Files
Ydisks-Xianyu-Helper/internal/webui/static/assets/AccountList-Dvf5SO5g.js
T

4 lines
55 KiB
JavaScript

import{r,j as e,b as xe,c as rs}from"./react-vendor-C_od1ZSF.js";import{f as Qe,u as $e,r as ls,h as ns,i as os,j as is,k as ds,l as cs,m as xs,s as us,n as ms,o as bs,p as hs,q as gs,t as fs,v as ps,w as js,x as ws,y as ys,z as Ns,A as vs,B as _s,C as ks}from"./index-BmJe6Y8O.js";import{X as ue,n as Cs,f as G,o as Ss,p as Oe,q as ze,r as Ge,s as le,t as We,K as Rs,u as As,v as qs,a as Ps,w as ge,b as Is,i as Ve,x as Ls,k as Se,Q as Re,R as Ts,y as Ds,z as Es,F as Ae,H as Qs}from"./icons-vendor-ThcsWkZG.js";const $s=new Set(["expired","cancelled","error","not_found"]),Bs=()=>{let t=0;return{next:(()=>(t+=1,t)),cancel:(()=>{t+=1}),isCurrent:(s=>s===t)}},Us=(t={setInterval:globalThis.setInterval.bind(globalThis),clearInterval:globalThis.clearInterval.bind(globalThis)})=>{let s=null,n=null,a=-1,b=0;const x=()=>{b+=1,n==null||n.abort(),n=null,s!==null&&(t.clearInterval(s),s=null)};return{start:(c,g,m,j=2e3)=>{x();const f=b;n=new AbortController;const u=n.signal;s=t.setInterval(()=>{a===f||f!==b||(a=f,(async()=>{var R,k;try{const p=await g(c,u);if(p.status==="success"){x(),await m.onSuccess(p);return}if(p.status==="scanned"){(R=m.onScanned)==null||R.call(m,p);return}if(p.status==="verification_required"){(k=m.onVerificationRequired)==null||k.call(m,p);return}p.status&&$s.has(p.status)&&(x(),m.onTerminalError(p))}catch(p){if(u.aborted||f!==b)return;x(),m.onPollError(p)}finally{a===f&&(a=-1)}})())},j)},stop:x,isActive:(()=>s!==null)}},Be=t=>({account_id:t.id,auto_rate_enabled:t.auto_rate_enabled===!0,rate_content:t.rate_content||"不错的买家,交易愉快",auto_polish_enabled:t.auto_polish_enabled===!0,polish_time:t.polish_time||"03:00",last_rate_scan_at:t.last_rate_scan_at,last_polish_date:t.last_polish_date,last_polish_at:t.last_polish_at}),X=(t,s,n)=>t===s&&!n.aborted,ke=(t,s)=>t instanceof Error?t.message:s,Ce=t=>t instanceof Error&&t.message==="请求已取消",Ue=(t,s)=>!t&&s==="",Ms=({account:t,onSaved:s})=>{const[n,a]=r.useState(()=>Be(t)),[b,x]=r.useState(!0),[o,c]=r.useState(!1),[g,m]=r.useState(""),[j,f]=r.useState(""),[u,R]=r.useState(null),[k,p]=r.useState(null),A=r.useRef(0),T=r.useRef(null);r.useEffect(()=>{var v;const S=++A.current;(v=T.current)==null||v.abort();const w=new AbortController;return T.current=w,a(Be(t)),R(null),f(""),c(!1),m(""),p(null),x(!0),Qe(t.id,{signal:w.signal}).then(C=>{X(A.current,S,w.signal)&&a(C)}).catch(C=>{X(A.current,S,w.signal)&&!Ce(C)&&f(ke(C,"加载任务设置失败"))}).finally(()=>{X(A.current,S,w.signal)&&x(!1)}),(()=>w.abort())},[t.id]),r.useEffect(()=>(()=>{var S;return(S=T.current)==null?void 0:S.abort()}),[]);const J=r.useCallback(async()=>{var v;if(!Ue(o,g))return;const S=++A.current;(v=T.current)==null||v.abort();const w=new AbortController;T.current=w,c(!0),f(""),p(null);try{const C=await $e(t.id,n,{signal:w.signal});if(!X(A.current,S,w.signal))return;a(C),s(C)}catch(C){X(A.current,S,w.signal)&&!Ce(C)&&(f(ke(C,"保存失败")),p(()=>J))}finally{X(A.current,S,w.signal)&&c(!1)}},[t.id,n,s,g,o]),P=r.useCallback(async S=>{var C;if(!Ue(o,g)||!t.enabled)return;const w=++A.current;(C=T.current)==null||C.abort();const v=new AbortController;T.current=v,m(S),f(""),R(null),p(null);try{await $e(t.id,n,{signal:v.signal});const I=await ls(t.id,S,{signal:v.signal}),W=await Qe(t.id,{signal:v.signal});if(!X(A.current,w,v.signal))return;R(I.summary),a(W),s(W)}catch(I){X(A.current,w,v.signal)&&!Ce(I)&&(f(ke(I,"任务执行失败")),p(()=>(()=>P(S))))}finally{X(A.current,w,v.signal)&&m("")}},[t.enabled,t.id,n,s,g,o]),D=r.useCallback(async()=>{k&&await k()},[k]);return{form:n,loading:b,saving:o,running:g,summary:u,error:j,retryAvailable:k!==null,setForm:a,save:J,run:P,retry:D}},Me=({checked:t,onChange:s,label:n})=>e.jsx("button",{type:"button","aria-label":n,"aria-pressed":t,onClick:s,className:`relative h-8 w-14 shrink-0 rounded-full transition-colors ${t?"bg-sky-500":"bg-slate-300"}`,children:e.jsx("span",{className:`absolute left-1 top-1 h-6 w-6 rounded-full bg-white shadow-sm transition-transform ${t?"translate-x-6":""}`})}),Os=({account:t,onClose:s,onSaved:n})=>{const{form:a,loading:b,saving:x,running:o,error:c,summary:g,retryAvailable:m,setForm:j,save:f,run:u,retry:R}=Ms({account:t,onSaved:n});return e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"640px"},role:"dialog","aria-modal":"true","aria-labelledby":"account-task-title",children:[e.jsxs("div",{className:"modal-header",children:[e.jsxs("div",{children:[e.jsx("h3",{id:"account-task-title",className:"text-2xl font-extrabold text-slate-950",children:"账号自动任务"}),e.jsx("p",{className:"mt-1 text-sm text-slate-500",children:t.nickname||t.remark||t.id})]}),e.jsx("button",{type:"button",onClick:s,className:"rounded-xl p-2 text-slate-400 hover:bg-slate-100 hover:text-slate-700","aria-label":"关闭",children:e.jsx(ue,{className:"h-5 w-5"})})]}),e.jsxs("div",{className:"modal-body space-y-5",children:[b&&e.jsx("div",{className:"rounded-xl bg-slate-50 px-4 py-3 text-sm text-slate-500",children:"正在读取任务设置..."}),e.jsx("section",{className:"rounded-2xl border border-slate-200 bg-white p-5",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-xl bg-emerald-50 text-emerald-600",children:e.jsx(Cs,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-black text-slate-900",children:"自动评价"}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-slate-500",children:"持续扫描待评价订单,按订单执行;不是每日任务。"})]}),e.jsx(Me,{checked:a.auto_rate_enabled,onChange:(()=>j(k=>({...k,auto_rate_enabled:!k.auto_rate_enabled}))),label:"自动评价"})]}),e.jsx("label",{className:"mt-4 block text-xs font-extrabold text-slate-600",children:"统一好评文案"}),e.jsx("textarea",{"aria-label":"统一好评文案",value:a.rate_content,maxLength:500,onChange:(k=>j(p=>({...p,rate_content:k.target.value}))),className:"mt-2 h-24 w-full resize-none rounded-xl border border-slate-200 bg-slate-50 px-3 py-2.5 text-sm leading-6 text-slate-800 placeholder:text-slate-400 outline-none focus:border-sky-400 focus:ring-2 focus:ring-sky-100"}),e.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3",children:[e.jsxs("span",{className:"text-xs text-slate-400",children:["最近扫描:",a.last_rate_scan_at?new Date(a.last_rate_scan_at*1e3).toLocaleString("zh-CN"):"尚未执行"]}),e.jsxs("button",{type:"button",disabled:o!==""||!t.enabled,onClick:(()=>void u("auto_rate")),className:"flex items-center gap-2 rounded-xl bg-emerald-50 px-3 py-2 text-xs font-extrabold text-emerald-700 hover:bg-emerald-100 disabled:opacity-50",children:[o==="auto_rate"?e.jsx(G,{className:"h-4 w-4 animate-spin"}):e.jsx(Ss,{className:"h-4 w-4"}),"立即评价"]})]})]})]})}),e.jsx("section",{className:"rounded-2xl border border-slate-200 bg-white p-5",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-xl bg-amber-50 text-amber-600",children:e.jsx(Oe,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-black text-slate-900",children:"每日自动擦亮"}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-slate-500",children:"每个账号每天最多执行一次,按北京时间判断。"})]}),e.jsx(Me,{checked:a.auto_polish_enabled,onChange:(()=>j(k=>({...k,auto_polish_enabled:!k.auto_polish_enabled}))),label:"每日自动擦亮"})]}),e.jsxs("div",{className:"mt-4 flex items-end justify-between gap-4",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-extrabold text-slate-600",children:"每日执行时间"}),e.jsx("input",{type:"time",value:a.polish_time,onChange:(k=>j(p=>({...p,polish_time:k.target.value}))),className:"mt-2 block rounded-xl border border-slate-200 bg-slate-50 px-3 py-2 text-sm font-bold text-slate-800 outline-none focus:border-sky-400"})]}),e.jsxs("button",{type:"button",disabled:o!==""||!t.enabled,onClick:(()=>void u("auto_polish")),className:"flex items-center gap-2 rounded-xl bg-amber-50 px-3 py-2 text-xs font-extrabold text-amber-700 hover:bg-amber-100 disabled:opacity-50",children:[o==="auto_polish"?e.jsx(G,{className:"h-4 w-4 animate-spin"}):e.jsx(ze,{className:"h-4 w-4"}),"立即擦亮"]})]}),e.jsxs("div",{className:"mt-3 text-xs text-slate-400",children:["上次完成:",a.last_polish_at?new Date(a.last_polish_at*1e3).toLocaleString("zh-CN"):"尚未执行"]})]})]})}),g&&e.jsxs("div",{className:"rounded-xl border border-sky-100 bg-sky-50 px-4 py-3 text-sm text-sky-900",children:["本次发现 ",g.found," 项,成功 ",g.success,",失败 ",g.failed,",跳过 ",g.skipped,"。",g.message||""]}),c&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-xl border border-red-100 bg-red-50 px-4 py-3 text-sm font-medium text-red-700",children:[e.jsx("span",{children:c}),m&&e.jsx("button",{type:"button",className:"font-bold underline",onClick:(()=>void R()),children:"重试"})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex w-full gap-3",children:[e.jsx("button",{type:"button",onClick:s,disabled:x||o!=="",className:"flex-1 rounded-xl bg-gray-100 px-6 py-3 font-bold text-gray-700 transition-colors hover:bg-gray-200 disabled:opacity-50",children:"关闭"}),e.jsxs("button",{type:"button",onClick:(()=>void f()),disabled:x||o!==""||a.auto_rate_enabled&&!a.rate_content.trim(),className:"ios-btn-primary flex flex-1 items-center justify-center gap-2 rounded-xl px-6 py-3 font-bold disabled:opacity-50",children:[x?e.jsx(G,{className:"h-4 w-4 animate-spin"}):e.jsx(Ge,{className:"h-4 w-4"}),"保存"]})]})})]})})},Ke=({src:t,alt:s,className:n=""})=>e.jsx("img",{src:t,alt:s,className:`block aspect-square h-auto w-full object-contain ${n}`.trim()}),zs=({account:t,editForm:s,setEditForm:n,saving:a,onClose:b,onSave:x,onRestartPause:o,longLogin:c,onToggleLongLogin:g,passwordLoginView:m,onPasswordLogin:j,onCancelPasswordLogin:f,notifChannels:u,selectedChannelIds:R,bindingsLoaded:k,bindingsLoading:p,bindingsLoadError:A,onRetryBindings:T,onToggleChannel:J,onSettingsDirty:P})=>{const D=(_,U)=>{n(te=>({...te,[_]:U}))},S=()=>void b(),w=()=>void x(),v=_=>D("remark",_.target.value),C=_=>D("cookie",_.target.value),I=()=>D("auto_confirm",!s.auto_confirm),W=_=>D("pause_duration",parseInt(_.target.value,10)||0),Y=()=>void o(),Z=()=>void g(),F=_=>D("username",_.target.value),$=_=>n(U=>({...U,login_password:_.target.value,clear_password:!1})),V=()=>D("showLoginPassword",!s.showLoginPassword),B=_=>n(U=>({...U,clear_password:_.target.checked,login_password:_.target.checked?"":U.login_password})),M=()=>D("show_browser",!s.show_browser),O=()=>void f(),K=()=>void j(),L=()=>void T(),se=_=>{k&&(J(_),P())},ne=_=>{const U=R.includes(Number(_.id)),te=()=>se(Number(_.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:te,disabled:!k,className:`w-5 h-5 rounded-md border-2 flex items-center justify-center transition-colors flex-shrink-0 ${U?"bg-brand border-brand":"bg-white border-gray-300"}`,children:U&&e.jsx(le,{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:_.name}),e.jsxs("div",{className:"text-xs text-gray-500",children:[_.type,_.enabled?"":" · 已停用"]})]})]},_.id)};return xe.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:t.nickname||t.remark||t.id})]}),e.jsx("button",{onClick:S,className:"p-2 rounded-xl hover:bg-gray-100 transition-colors flex-shrink-0",children:e.jsx(ue,{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:t.id,disabled:!0,className:"w-full ios-input px-4 py-3 rounded-xl bg-gray-50 text-gray-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"备注"}),e.jsx("input",{type:"text",value:s.remark,onChange:v,placeholder:"为账号添加备注",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"Cookie"}),e.jsx("textarea",{value:s.cookie,onChange:C,placeholder:"更新账号Cookie",className:"w-full ios-input px-4 py-3 rounded-xl h-32 resize-none font-mono text-xs"}),e.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:["当前Cookie长度: ",s.cookie.length," 字符"]})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-gray-50 rounded-xl",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"font-bold text-gray-900 flex items-center gap-2",children:[e.jsx(le,{className:"w-4 h-4 text-green-500"}),"自动确认发货"]}),e.jsx("div",{className:"text-xs text-gray-500",children:"自动将闲鱼订单标记为已发货"})]}),e.jsx("button",{type:"button",onClick:I,className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${s.auto_confirm?"bg-brand":"bg-gray-300"}`,children:e.jsx("span",{className:`absolute left-1 top-1 w-6 h-6 bg-white rounded-full shadow-md transition-transform duration-300 ${s.auto_confirm?"translate-x-6":"translate-x-0"}`})})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-700 mb-2 flex items-center gap-2",children:[e.jsx(We,{className:"w-4 h-4 text-blue-500"}),"暂停处理时长(分钟)"]}),e.jsx("input",{type:"number",value:s.pause_duration,onChange:W,placeholder:"0",min:"0",max:"1440",className:"w-full ios-input px-4 py-3 rounded-xl"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"设置后会暂停处理该账号的订单,到时间后自动恢复"}),s.pause_duration>0&&!t.paused&&s.pause_duration===(t.pause_duration||0)&&e.jsx("button",{type:"button",disabled:a,onClick:Y,className:"mt-3 px-4 py-2 rounded-xl bg-amber-50 text-amber-700 hover:bg-amber-100 text-sm font-bold disabled:opacity-50",children:"立即按当前时长重新暂停"})]}),e.jsxs("div",{className:"border-t border-gray-200 pt-6",children:[e.jsxs("h3",{className:"text-lg font-bold text-gray-900 mb-4 flex items-center gap-2",children:[e.jsx(Rs,{className:"w-5 h-5 text-blue-500"}),"登录信息"]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 rounded-xl bg-blue-50 p-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-bold text-gray-900",children:"保存登录信息"}),e.jsx("div",{className:"mt-1 text-xs text-gray-500",children:"状态直接读取并修改闲鱼官方长登录设置"}),c.error&&e.jsx("div",{className:"mt-1 text-xs text-red-600",children:c.error})]}),e.jsx("button",{type:"button","aria-label":"保存登录信息",disabled:c.loading||c.saving||!c.canOpen,onClick:Z,className:`relative h-8 w-14 flex-shrink-0 rounded-full transition-colors ${c.enabled?"bg-brand":"bg-gray-300"} disabled:cursor-not-allowed disabled:opacity-50`,children:e.jsx("span",{className:`absolute left-1 top-1 h-6 w-6 rounded-full bg-white shadow-md transition-transform ${c.enabled?"translate-x-6":"translate-x-0"}`})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"用户名"}),e.jsx("input",{type:"text",value:s.username,onChange:F,placeholder:"闲鱼账号/手机号",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"登录密码"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:s.showLoginPassword?"text":"password",value:s.login_password,onChange:$,placeholder:"用于自动登录",className:"w-full ios-input px-4 py-3 rounded-xl pr-12"}),e.jsx("button",{type:"button",onClick:V,className:"absolute right-3 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600",children:s.showLoginPassword?e.jsx(As,{className:"w-5 h-5"}):e.jsx(qs,{className:"w-5 h-5"})})]}),e.jsxs("label",{className:"mt-3 flex items-center gap-3 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:s.clear_password,onChange:B,className:"w-4 h-4 accent-brand"}),e.jsx("span",{className:"text-sm font-bold text-gray-700",children:"清空已保存密码"})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-bold text-gray-900",children:"登录时显示浏览器"}),e.jsx("div",{className:"text-xs text-gray-500",children:"调试时可开启查看登录过程"})]}),e.jsx("button",{type:"button",onClick:M,className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${s.show_browser?"bg-brand":"bg-gray-300"}`,children:e.jsx("span",{className:`absolute left-1 top-1 w-6 h-6 bg-white rounded-full shadow-md transition-transform duration-300 ${s.show_browser?"translate-x-6":"translate-x-0"}`})})]}),e.jsxs("div",{className:"rounded-xl border border-blue-100 bg-blue-50 p-4 space-y-3",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-bold text-blue-950",children:"立即执行账号密码登录"}),e.jsx("div",{className:"text-xs text-blue-700 mt-1",children:"需要在上方重新输入本次登录密码;成功后后端会更新 Cookie 和保存的登录信息。"})]}),m.status==="processing"||m.status==="verification_required"?e.jsx("button",{type:"button",onClick:O,className:"px-4 py-2 rounded-xl bg-white text-red-600 font-bold text-sm border border-red-100",children:"取消登录"}):e.jsx("button",{type:"button",onClick:K,className:"px-4 py-2 rounded-xl bg-blue-600 text-white font-bold text-sm whitespace-nowrap",children:"密码登录刷新授权"})]}),m.message&&e.jsx("div",{className:`text-sm font-medium ${m.status==="failed"?"text-red-700":m.status==="success"?"text-green-700":"text-blue-800"}`,children:m.message}),m.status==="verification_required"&&e.jsxs("div",{className:"rounded-xl border border-amber-200 bg-amber-50 p-3 text-amber-900",children:[e.jsx("div",{className:"font-extrabold",children:"账号已触发平台风控,需要完成人脸识别"}),e.jsx("div",{className:"text-xs mt-1 leading-5",children:"请在闲鱼 App 或已打开的登录浏览器中按提示完成验证。本页面不会提供可直接打开的风控链接。"}),m.qrCodeUrl&&e.jsx("div",{className:"mt-3 aspect-square w-48 overflow-hidden rounded-xl border bg-white",children:e.jsx(Ke,{src:m.qrCodeUrl,alt:"密码登录风控二维码",className:"p-2"})})]})]})]})]}),(u.length>0||p||A)&&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(Ps,{className:"w-5 h-5 text-blue-500"}),"通知渠道绑定"]}),e.jsx("p",{className:"text-xs text-gray-500 mb-4",children:"勾选后,该账号的 token 失效、自动恢复失败、风控验证等事件会推送到这些渠道"}),p&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-500",children:[e.jsx(G,{className:"w-4 h-4 animate-spin"}),"正在加载通知绑定"]}),A&&!p&&e.jsxs("div",{className:"mb-3 rounded-xl bg-amber-50 p-3 text-sm text-amber-800 flex items-center justify-between gap-3",children:[e.jsx("span",{children:A}),e.jsx("button",{type:"button",className:"font-bold whitespace-nowrap",onClick:L,children:"重试"})]}),e.jsx("div",{className:"space-y-2",children:u.map(ne)})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:S,className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",disabled:a,children:"取消"}),e.jsxs("button",{onClick:w,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",disabled:a,children:[a?e.jsx(G,{className:"w-4 h-4 animate-spin"}):e.jsx(le,{className:"w-4 h-4"}),a?"保存中...":"保存"]})]})})]})}),document.body)},Gs=({account:t,settings:s,saving:n,onChange:a,onClose:b,onSave:x})=>{const o=u=>a({...s,...u}),c=()=>o({ai_enabled:!s.ai_enabled}),g=u=>o({max_discount_percent:parseInt(u.target.value,10)||0}),m=u=>o({max_discount_amount:parseInt(u.target.value,10)||0}),j=u=>o({max_bargain_rounds:parseInt(u.target.value,10)||1}),f=u=>o({custom_prompts:u.target.value});return xe.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(ge,{className:"w-6 h-6 text-purple-500"}),"AI助手设置"]}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:t.nickname||t.remark||t.id})]}),e.jsx("button",{onClick:b,className:"p-2 rounded-xl hover:bg-gray-100 transition-colors flex-shrink-0","aria-label":"关闭 AI 设置",children:e.jsx(ue,{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(ge,{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:c,className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${s.ai_enabled?"bg-brand":"bg-gray-300"}`,"aria-label":"切换 AI 自动回复",children:e.jsx("span",{className:`absolute left-1 top-1 w-6 h-6 bg-white rounded-full shadow-md transition-transform duration-300 ${s.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:s.max_discount_percent,onChange:g,className:"w-full ios-input px-4 py-3 rounded-xl",min:"0",max:"100"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"例如:10 表示最多降价 10%;设为 0 表示不允许降价"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"最大折扣金额 (元)"}),e.jsx("input",{type:"number",value:s.max_discount_amount,onChange:m,className:"w-full ios-input px-4 py-3 rounded-xl",min:"0"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"例如:100 表示最多降价 100 元;设为 0 表示不允许降价"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"最大砍价轮次"}),e.jsx("input",{type:"number",value:s.max_bargain_rounds,onChange:j,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:s.custom_prompts,onChange:f,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(Is,{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:b,className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",disabled:n,children:"取消"}),e.jsxs("button",{onClick:(()=>void x()),className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",disabled:n,children:[n?e.jsx(G,{className:"w-4 h-4 animate-spin"}):e.jsx(Ge,{className:"w-4 h-4"}),n?"保存中...":"保存"]})]})})]})}),document.body)},Ws=(t,s)=>{if(!t||!s)return!1;const n=Date.parse(t),a=Date.parse(s);return Number.isFinite(n)&&Number.isFinite(a)&&a<n},Vs=(t,s)=>t.map(n=>{const a=s[n.id];return!a||Ws(n.runtime_updated_at,a.updated_at)?n:{...n,runtime_state:a.state,runtime_message:a.message||"",runtime_connected:a.connected,runtime_updated_at:a.updated_at}}),Ks=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"}}},Hs=rs.memo(function({account:s,refreshing:n,deleting:a,onRefreshProfile:b,onReauthorize:x,onEdit:o,onAI:c,onTasks:g,onToggle:m,onDelete:j}){const f=Ks(s),u=s.runtime_state==="auth_expired"||s.runtime_state==="verification_required";return e.jsx("div",{className:"ios-card rounded-xl p-6 group transition-all duration-300 hover:border-brand",children:e.jsxs("div",{className:"flex min-w-0 items-start gap-5 sm:gap-8",children:[e.jsxs("div",{className:"relative",children:[s.avatar_url?e.jsx("img",{src:s.avatar_url,alt:s.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(Ve,{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 ${f.dot}`,children:s.runtime_state==="online"&&e.jsx(le,{className:"w-3 h-3 text-white"})})]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2.5 mb-1",children:[e.jsx("h3",{className:"text-xl font-extrabold text-gray-900 break-words",children:s.nickname||s.remark||`账号 ${s.id.substring(0,6)}...`}),e.jsx("span",{className:`px-2.5 py-0.5 rounded-lg text-xs font-bold ${f.badge}`,children:f.label}),s.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(ge,{className:"w-3 h-3"})," AI"]}),s.auto_rate_enabled&&e.jsxs("span",{className:"flex items-center gap-1 rounded-lg bg-emerald-100 px-2.5 py-0.5 text-xs font-bold text-emerald-700",children:[e.jsx(Ls,{className:"h-3 w-3"})," 自动评价"]}),s.auto_polish_enabled&&e.jsxs("span",{className:"flex items-center gap-1 rounded-lg bg-amber-100 px-2.5 py-0.5 text-xs font-bold text-amber-700",children:[e.jsx(Oe,{className:"h-3 w-3"})," 每日擦亮"]}),s.auto_confirm&&e.jsxs("span",{className:"flex items-center gap-1 rounded-lg bg-blue-50 px-2.5 py-0.5 text-xs font-bold text-blue-700",children:[e.jsx(le,{className:"h-3 w-3"})," 自动确认发货"]}),s.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:s.profile_error,children:[e.jsx(Se,{className:"w-3 h-3"})," 资料未同步"]})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-between gap-4",children:[e.jsxs("div",{className:"text-sm font-medium text-gray-500",children:[e.jsx("p",{children:s.remark||"暂无备注"}),e.jsxs("p",{className:"font-mono text-xs text-gray-400",children:["ID: ",s.id]})]}),s.runtime_message&&s.runtime_state!=="online"&&s.runtime_state!=="disabled"&&e.jsxs("div",{className:`mb-3 flex flex-wrap items-center gap-2 text-sm font-medium ${u?"text-red-700":"text-amber-700"}`,children:[e.jsx(Se,{className:"w-4 h-4 flex-shrink-0"}),e.jsx("span",{children:s.runtime_message}),u&&e.jsxs("button",{type:"button",onClick:(()=>x(s)),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(Re,{className:"w-3.5 h-3.5"})," 重新授权"]})]}),s.paused&&e.jsxs("span",{className:"flex items-center gap-1.5 rounded-lg bg-blue-50 px-3 py-1.5 text-xs font-bold text-blue-700",children:[e.jsx(We,{className:"h-3 w-3"})," 暂停处理中"]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-end gap-2",children:[e.jsx("button",{onClick:(()=>b(s)),disabled:n,className:"p-3 rounded-xl transition-colors text-gray-600 hover:bg-gray-100 disabled:opacity-50",title:"刷新昵称和头像",children:e.jsx(Ts,{className:`w-5 h-5 ${n?"animate-spin":""}`})}),e.jsx("button",{onClick:(()=>x(s)),className:`p-3 rounded-xl transition-colors ${u?"text-red-600 bg-red-50 hover:bg-red-100":"text-blue-600 hover:bg-blue-50"}`,title:"重新扫码授权当前账号",children:e.jsx(Re,{className:"w-5 h-5"})}),e.jsx("button",{onClick:(()=>o(s)),className:"p-3 rounded-xl hover:bg-gray-100 transition-colors text-gray-600",title:"编辑账号",children:e.jsx(Ds,{className:"w-5 h-5"})}),e.jsx("button",{onClick:(()=>c(s)),className:"p-3 rounded-xl hover:bg-purple-100 transition-colors text-purple-600",title:"AI设置",children:e.jsx(ge,{className:"w-5 h-5"})}),e.jsx("button",{onClick:(()=>g(s)),className:"p-3 rounded-xl hover:bg-amber-100 transition-colors text-amber-600",title:"自动评价与每日擦亮",children:e.jsx(ze,{className:"w-5 h-5"})}),e.jsx("button",{onClick:(()=>m(s.id,s.enabled)),className:`p-3 rounded-xl transition-colors ${s.enabled?"text-green-600 hover:bg-green-50":"text-gray-400 hover:bg-gray-100"}`,title:s.enabled?"停用账号":"启用账号",children:e.jsx(Es,{className:"w-5 h-5"})}),e.jsx("button",{onClick:(()=>j(s)),disabled:a,className:"p-3 rounded-xl hover:bg-red-100 transition-colors text-red-500 disabled:cursor-not-allowed disabled:opacity-40",title:a?"删除中…":`删除账号 ${s.nickname||s.remark||s.id}`,children:a?e.jsx(G,{className:"w-5 h-5 animate-spin"}):e.jsx(Ae,{className:"w-5 h-5"})})]})]})]})]})})}),Xs=({account:t,deleting:s,error:n,onClose:a,onConfirm:b})=>xe.createPortal(e.jsx("div",{className:"modal-overlay-centered",role:"presentation",children:e.jsxs("div",{className:"h-fit w-full max-w-[400px] self-center overflow-hidden rounded-2xl border border-white/80 bg-white shadow-modal",role:"dialog","aria-modal":"true","aria-labelledby":"delete-account-title","aria-describedby":"delete-account-description",children:[e.jsxs("div",{className:"relative overflow-hidden border-b border-red-100 bg-gradient-to-br from-red-50 via-white to-orange-50 px-5 py-5",children:[e.jsx("div",{className:"absolute -right-12 -top-16 h-36 w-36 rounded-full bg-red-200/35 blur-2xl"}),e.jsxs("div",{className:"relative flex items-start gap-4",children:[e.jsx("div",{className:"flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-xl bg-red-600 text-white shadow-md shadow-red-200",children:e.jsx(Ae,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h3",{id:"delete-account-title",className:"text-lg font-extrabold tracking-tight text-gray-950",children:"删除这个账号?"}),e.jsx("p",{id:"delete-account-description",className:"mt-1 text-xs leading-5 text-gray-600",children:"删除后,该账号的关联配置也会一并清理,此操作无法撤销。"})]}),e.jsx("button",{type:"button",onClick:a,disabled:s,className:"flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-full text-gray-400 transition-colors hover:bg-white hover:text-gray-700 disabled:cursor-not-allowed disabled:opacity-40","aria-label":"关闭删除确认",children:e.jsx(ue,{className:"h-5 w-5"})})]})]}),e.jsxs("div",{className:"px-5 py-4",children:[e.jsxs("div",{className:"rounded-xl border border-gray-100 bg-gray-50/80 px-4 py-3",children:[e.jsx("div",{className:"text-sm font-extrabold text-gray-900",children:t.nickname||t.remark||"未命名账号"}),t.remark&&t.nickname&&e.jsxs("div",{className:"mt-1 text-sm text-gray-500",children:["备注:",t.remark]}),e.jsxs("div",{className:"mt-1.5 break-all font-mono text-[11px] text-gray-400",children:["ID: ",t.id]})]}),s&&e.jsxs("div",{className:"mt-4 flex items-center gap-3 rounded-xl border border-blue-100 bg-blue-50 px-4 py-3",role:"progressbar","aria-label":"正在删除账号",children:[e.jsx(G,{className:"h-5 w-5 flex-shrink-0 animate-spin text-brand"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-extrabold text-blue-950",children:"正在删除账号"}),e.jsx("div",{className:"mt-0.5 text-xs text-blue-700",children:"正在清理关联数据,请保持页面打开…"})]})]}),n&&e.jsxs("div",{className:"mt-4 flex items-start gap-3 rounded-xl border border-red-100 bg-red-50 px-4 py-3",role:"alert",children:[e.jsx(Se,{className:"mt-0.5 h-5 w-5 flex-shrink-0 text-red-600"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-extrabold text-red-800",children:"删除失败"}),e.jsx("div",{className:"mt-1 text-xs leading-5 text-red-700",children:n})]})]})]}),e.jsxs("div",{className:"flex gap-3 border-t border-gray-100 bg-gray-50/70 px-5 py-4",children:[e.jsx("button",{type:"button",onClick:a,disabled:s,className:"flex-1 rounded-xl bg-white px-5 py-3 text-sm font-extrabold text-gray-700 ring-1 ring-gray-200 transition-colors hover:bg-gray-100 disabled:cursor-not-allowed disabled:opacity-50",children:"取消"}),e.jsx("button",{type:"button",onClick:(()=>void b()),disabled:s,className:"flex flex-1 items-center justify-center gap-2 rounded-xl bg-red-600 px-5 py-3 text-sm font-extrabold text-white shadow-lg shadow-red-200 transition-colors hover:bg-red-700 disabled:cursor-not-allowed disabled:bg-red-400",children:s?e.jsxs(e.Fragment,{children:[e.jsx(G,{className:"h-4 w-4 animate-spin"}),"处理中"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ae,{className:"h-4 w-4"}),"确认删除"]})})]})]})}),document.body),Js=({faceQrUrl:t,verificationScreenshot:s})=>e.jsxs("div",{className:"w-full min-w-0 max-h-[min(64vh,28rem)] overflow-y-auto overscroll-contain px-1 py-2 text-center",children:[e.jsx("div",{className:"mx-auto mb-2 flex h-10 w-10 items-center justify-center rounded-full bg-amber-100 text-amber-700",children:e.jsx(Qs,{className:"h-5 w-5","aria-hidden":"true"})}),e.jsx("h4",{className:"break-words text-base font-extrabold leading-6 text-amber-900",children:"需要完成安全风控验证"}),e.jsx("p",{className:"mx-auto mt-1 max-w-[15rem] break-words text-xs leading-5 text-amber-800",children:"当前账号触发了闲鱼平台风控。请使用手机闲鱼 App 扫描下方二维码,并按 App 提示完成人脸识别。"}),e.jsx("div",{className:"mx-auto mt-3 flex min-h-36 w-full max-w-[12rem] items-center justify-center overflow-hidden rounded-xl border border-amber-200 bg-white p-2 shadow-sm",children:t?e.jsx("img",{src:t,alt:"闲鱼安全风控验证二维码",className:"block max-h-44 w-full object-contain"}):s?e.jsx("img",{src:s,alt:"闲鱼风控验证页面",className:"block max-h-44 w-full object-contain"}):e.jsxs("div",{className:"flex flex-col items-center gap-2 text-amber-700",children:[e.jsx(G,{className:"h-6 w-6 animate-spin","aria-hidden":"true"}),e.jsx("span",{className:"text-xs font-bold",children:"正在准备风控二维码…"})]})}),e.jsx("p",{className:"mx-auto mt-2 max-w-[15rem] break-words text-[11px] leading-4 text-gray-500",children:"请勿在浏览器中打开验证链接。完成验证后系统会自动检测并刷新登录状态,无需手动确认。"})]}),Ys=({target:t,status:s,codeUrl:n,errorMessage:a,faceQrUrl:b,verificationScreenshot:x,onClose:o})=>xe.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container relative",style:{maxWidth:"26rem"},children:[e.jsx("button",{onClick:o,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","aria-label":"关闭二维码登录",children:e.jsx(ue,{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:t?"重新授权账号":"扫码添加账号"}),e.jsx("p",{className:"text-gray-500 mb-8 font-medium",children:t?`请用闲鱼APP扫码,为「${t.nickname||t.remark||t.id}」刷新授权`:"请打开闲鱼APP扫描下方二维码"}),e.jsxs("div",{className:`w-full bg-surface-subtle rounded-xl mx-auto flex items-center justify-center overflow-hidden border-4 border-white shadow-inner mb-6 relative ${s==="verification"?"max-w-72 min-h-64 h-auto p-2":"max-w-64 aspect-square"}`,children:[s==="loading"&&e.jsx(G,{className:"w-10 h-10 text-brand animate-spin"}),s==="waiting"&&e.jsx(Ke,{src:n,alt:"闲鱼登录二维码",className:"p-2"}),s==="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(le,{className:"w-8 h-8"})}),e.jsx("span",{className:"font-bold text-lg",children:"登录成功"})]}),s==="error"&&e.jsxs("div",{className:"px-5 text-center",children:[e.jsx("span",{className:"block text-red-600 font-bold",children:"二维码获取失败"}),e.jsx("span",{className:"mt-2 block text-xs leading-5 text-gray-500",children:a||"请关闭窗口后重新发起扫码登录。"})]}),s==="verification"&&e.jsx(Js,{faceQrUrl:b,verificationScreenshot:x})]}),s!=="verification"&&e.jsx("p",{className:"text-xs text-gray-400 font-medium bg-gray-50 py-2 rounded-xl",children:"二维码有效期为5分钟,请尽快扫码。"})]})})]})}),document.body),Zs=(t,s)=>t.map(n=>{var a,b,x,o,c;return{...n,ai_enabled:((a=s[n.id])==null?void 0:a.ai_enabled)??!1,max_discount_percent:((b=s[n.id])==null?void 0:b.max_discount_percent)??10,max_discount_amount:((x=s[n.id])==null?void 0:x.max_discount_amount)??100,max_bargain_rounds:((o=s[n.id])==null?void 0:o.max_bargain_rounds)??3,custom_prompts:((c=s[n.id])==null?void 0:c.custom_prompts)??""}}),Fs=()=>{const[t,s]=r.useState([]),[n,a]=r.useState(!0),b=r.useRef(0),x=r.useRef(null),o=r.useCallback(async()=>{var m;const c=++b.current;(m=x.current)==null||m.abort();const g=new AbortController;x.current=g,a(!0);try{const j={signal:g.signal},[f,u]=await Promise.allSettled([ns(j),os(j)]);if(c!==b.current)return;if(f.status==="rejected")throw f.reason;const R=u.status==="fulfilled"?u.value:{};u.status==="rejected"&&console.error("加载 AI 设置失败:",u.reason),s(Zs(f.value,R))}catch(j){c===b.current&&!g.signal.aborted&&console.error("加载账号失败:",j)}finally{c===b.current&&a(!1)}},[]);return r.useEffect(()=>{let c=!1,g=null;const m=new AbortController,j=async()=>{try{const u=await is({signal:m.signal,timeoutMs:1e4});c||s(R=>Vs(R,u))}catch(u){c||console.error("加载账号运行状态失败:",u)}finally{c||(g=window.setTimeout(()=>void j(),2e3))}};return o().finally(()=>{c||j()}),()=>{var u;c=!0,m.abort(),b.current+=1,(u=x.current)==null||u.abort(),g!==null&&window.clearTimeout(g)}},[o]),{accounts:t,setAccounts:s,loading:n,loadAccounts:o}},et=(t,s)=>t!==(s.pause_duration||0),st=(t,s)=>{const n=s.username!==(t.username||""),a=s.show_browser!==(t.show_browser||!1),b=s.login_password!=="",x=s.clear_password===!0;if(!n&&!a&&!b&&!x)return null;const o={username:s.username,show_browser:s.show_browser};return x?o.clear_password=!0:b&&(o.login_password=s.login_password),o},ee=(t,s,n,a)=>t===s&&n===a,tt=t=>t.status==="success"?{sessionId:"",status:"success",message:t.message||"账号密码登录成功,授权信息已更新",qrCodeUrl:""}:t.status==="processing"||t.status==="verification_required"?{sessionId:"",status:t.status,message:t.message||(t.status==="verification_required"?"账号触发风控,需要完成人脸识别":"登录处理中"),qrCodeUrl:t.qr_code_url||""}:{sessionId:"",status:"failed",message:t.error||t.message||"密码登录失败,请检查账号信息后重试",qrCodeUrl:""},at=(t,s)=>t&&s,rt=({editingAccount:t,setEditingAccount:s,setActiveModal:n,editForm:a,setEditForm:b,loadAccounts:x})=>{const[o,c]=r.useState({loading:!1,saving:!1,canOpen:!1,enabled:!1,error:""}),[g,m]=r.useState([]),[j,f]=r.useState([]),[u,R]=r.useState(!1),[k,p]=r.useState(!1),[A,T]=r.useState(!1),[J,P]=r.useState(""),[D,S]=r.useState({ai_enabled:!1,max_discount_percent:10,max_discount_amount:100,max_bargain_rounds:3,custom_prompts:""}),[w,v]=r.useState(!1),[C,I]=r.useState({sessionId:"",status:"idle",message:"",qrCodeUrl:""}),W=r.useRef(0),Y=r.useRef(null),Z=r.useRef(0),F=r.useRef(null),$=r.useRef(0),V=r.useRef(null),B=r.useRef(0),M=r.useRef(""),O=r.useRef(null),K=r.useRef(null),L=r.useCallback(()=>{K.current!==null&&(window.clearTimeout(K.current),K.current=null)},[]),se=r.useCallback(async l=>{var E;const i=++W.current;(E=Y.current)==null||E.abort();const y=new AbortController;Y.current=y,p(!0),R(!1),T(!1),P("");const[q,N]=await Promise.allSettled([ds({signal:y.signal}),cs(l,{signal:y.signal})]);ee(i,W.current,l,l)&&(q.status==="fulfilled"?m(q.value.data||[]):(m([]),P("通知渠道列表加载失败,请重试")),N.status==="fulfilled"?(f(N.value||[]),R(!0)):(f([]),P("通知绑定加载失败;本次保存不会修改现有绑定")),p(!1))},[]),ne=r.useCallback(l=>{f(i=>i.includes(l)?i.filter(y=>y!==l):[...i,l]),T(!0)},[]),_=r.useCallback(async l=>{var N,E;const i=++Z.current;(N=F.current)==null||N.abort();const y=new AbortController;F.current=y,B.current+=1,M.current=l.id,(E=O.current)==null||E.abort(),L(),I({sessionId:"",status:"idle",message:"",qrCodeUrl:""}),s(l),b({remark:l.remark||"",cookie:l.value||"",auto_confirm:l.auto_confirm||!1,pause_duration:l.pause_duration||0,username:l.username||"",login_password:l.login_password||"",show_browser:l.show_browser||!1,showLoginPassword:!1,clear_password:!1}),n("edit"),c({loading:!0,saving:!1,canOpen:!1,enabled:!1,error:""});const[,q]=await Promise.allSettled([se(l.id),xs(l.id,{signal:y.signal})]);i===Z.current&&(q.status==="fulfilled"?c({loading:!1,saving:!1,canOpen:q.value.can_open_long_login,enabled:q.value.enabled,error:""}):c({loading:!1,saving:!1,canOpen:!1,enabled:!1,error:"无法读取闲鱼保存登录信息状态"}))},[L,se,n,b,s]),U=r.useCallback(async()=>{if(!t||o.loading||o.saving||!o.canOpen)return;const l=!o.enabled;c(i=>({...i,saving:!0,error:""}));try{const i=await us(t.id,l);c({loading:!1,saving:!1,canOpen:i.can_open_long_login,enabled:i.enabled,error:""})}catch(i){c(y=>({...y,saving:!1,error:i instanceof Error?i.message:"保存登录信息设置失败"}))}},[t,o]),te=r.useCallback(async l=>{var q;const i=++$.current;(q=V.current)==null||q.abort();const y=new AbortController;V.current=y,s(l),n("ai-settings"),v(!0);try{const N=await ms(l.id,{signal:y.signal});if(!ee(i,$.current,l.id,l.id))return;S({ai_enabled:N.ai_enabled??!1,max_discount_percent:N.max_discount_percent??10,max_discount_amount:N.max_discount_amount??100,max_bargain_rounds:N.max_bargain_rounds??3,custom_prompts:N.custom_prompts??""})}catch(N){ee(i,$.current,l.id,l.id)&&console.error("加载 AI 设置失败:",N)}finally{ee(i,$.current,l.id,l.id)&&v(!1)}},[n,s]),fe=r.useCallback(async()=>{if(!(!t||w)){v(!0);try{await bs(t.id,D),n(null),await x()}catch(l){console.error("更新 AI 设置失败:",l)}finally{v(!1)}}},[D,t,x,w,n]),pe=r.useCallback(async()=>{if(!(!t||w)){v(!0);try{const l={};a.remark!==(t.remark||"")&&(l.remark=a.remark),a.cookie&&a.cookie!==(t.value||"")&&(l.cookie=a.cookie),a.auto_confirm!==t.auto_confirm&&(l.auto_confirm=a.auto_confirm),et(a.pause_duration,t)&&(l.pause_duration=a.pause_duration);const i=st(t,a);i&&Object.assign(l,i),at(u,A)&&(l.channel_ids=j),Object.keys(l).length>0&&await hs(t.id,l),n(null),await x()}catch(l){console.error("更新账号失败:",l)}finally{v(!1)}}},[A,u,a,t,x,j,w,n]),me=r.useCallback(async()=>{if(!(!t||a.pause_duration<=0||w)){v(!0);try{const l=await gs(t.id,a.pause_duration);s(i=>i&&{...i,pause_duration:a.pause_duration,paused:(l==null?void 0:l.paused)===!0,paused_until:Number((l==null?void 0:l.paused_until)||0)}),await x()}catch(l){console.error("重新暂停失败:",l)}finally{v(!1)}}},[a.pause_duration,t,x,w,s]),oe=r.useCallback(async(l,i,y)=>{var N;(N=O.current)==null||N.abort();const q=new AbortController;O.current=q;try{const E=await fs(l,q.signal);if(!ee(i,B.current,y,M.current))return;const de={...tt(E),sessionId:l};if(E.status==="success"){L(),I(de),b(Ne=>({...Ne,login_password:"",showLoginPassword:!1})),await x();return}if(E.status==="processing"||E.status==="verification_required"){I(de),L(),K.current=window.setTimeout(()=>void oe(l,i,y),1500);return}L(),I(de)}catch(E){if(!ee(i,B.current,y,M.current))return;L(),I({sessionId:l,status:"failed",message:E instanceof Error?E.message:"查询密码登录状态失败",qrCodeUrl:""})}},[L,x,b]),je=r.useCallback(async()=>{var q;if(!t)return;const l=a.username.trim();if(!l||!a.login_password)return;L(),(q=O.current)==null||q.abort();const i=++B.current;M.current=t.id;const y=new AbortController;O.current=y,I({sessionId:"",status:"processing",message:"正在启动密码登录…",qrCodeUrl:""});try{const N=await ps({account_id:t.id,account:l,password:a.login_password,show_browser:a.show_browser},{signal:y.signal});if(!ee(i,B.current,t.id,M.current))return;if(!N.success||!N.session_id)throw new Error(N.message||"无法启动密码登录");I({sessionId:N.session_id,status:"processing",message:N.message||"登录处理中",qrCodeUrl:""}),await oe(N.session_id,i,t.id)}catch(N){if(!ee(i,B.current,t.id,M.current))return;I({sessionId:"",status:"failed",message:N instanceof Error?N.message:"启动密码登录失败",qrCodeUrl:""})}},[L,a.login_password,a.show_browser,a.username,t,oe]),ie=r.useCallback(async()=>{var i;const l=C.sessionId;B.current+=1,M.current="",(i=O.current)==null||i.abort(),L(),l&&await js(l).catch(()=>{}),I({sessionId:"",status:"idle",message:"",qrCodeUrl:""})},[L,C.sessionId]),we=r.useCallback(async()=>{var l,i,y;(l=Y.current)==null||l.abort(),Z.current+=1,(i=F.current)==null||i.abort(),(y=V.current)==null||y.abort(),(C.status==="processing"||C.status==="verification_required")&&await ie(),n(null)},[ie,C.status,n]),ye=r.useCallback(()=>{var l;$.current+=1,(l=V.current)==null||l.abort(),n(null)},[n]);return r.useEffect(()=>(()=>{var l,i,y,q;(l=Y.current)==null||l.abort(),(i=F.current)==null||i.abort(),(y=V.current)==null||y.abort(),(q=O.current)==null||q.abort(),L()}),[L]),{longLogin:o,notifChannels:g,selectedChannelIds:j,bindingsLoaded:u,bindingsLoading:k,bindingsDirty:A,bindingsLoadError:J,aiSettings:D,saving:w,passwordLoginView:C,setAiSettings:S,setBindingsDirty:T,setEditForm:b,openEditModal:_,closeEditModal:we,openAIModal:te,closeAIModal:ye,loadNotificationBindings:se,toggleNotificationChannel:ne,handleLongLoginToggle:U,handleSaveAISettings:fe,handleSaveEdit:pe,handleRestartPause:me,handlePasswordLogin:je,handleCancelPasswordLogin:ie}},it=()=>{const{accounts:t,setAccounts:s,loading:n,loadAccounts:a}=Fs(),[b,x]=r.useState(""),[o,c]=r.useState(""),[g,m]=r.useState(""),[j,f]=r.useState(null),[u,R]=r.useState(""),[k,p]=r.useState(!1),[A,T]=r.useState(""),[J,P]=r.useState("pending"),[D,S]=r.useState(""),[w,v]=r.useState(""),[C,I]=r.useState(""),[W,Y]=r.useState(null),[Z,F]=r.useState(null),[$,V]=r.useState(null),[B,M]=r.useState(null),[O,K]=r.useState({remark:"",cookie:"",auto_confirm:!1,pause_duration:0,username:"",login_password:"",show_browser:!1,showLoginPassword:!1,clear_password:!1}),L=rt({editingAccount:$,setEditingAccount:V,setActiveModal:F,editForm:O,setEditForm:K,loadAccounts:a}),{longLogin:se,notifChannels:ne,selectedChannelIds:_,bindingsLoaded:U,bindingsLoading:te,bindingsLoadError:fe,aiSettings:pe,saving:me,passwordLoginView:oe,setAiSettings:je,setBindingsDirty:ie,openEditModal:we,closeEditModal:ye,openAIModal:l,closeAIModal:i,loadNotificationBindings:y,toggleNotificationChannel:q,handleLongLoginToggle:N,handleSaveAISettings:E,handleSaveEdit:de,handleRestartPause:Ne,handlePasswordLogin:He,handleCancelPasswordLogin:Xe}=L,be=r.useRef(null),ae=r.useRef(null),re=r.useRef(null),ce=r.useRef(null);be.current===null&&(be.current=Us()),ae.current===null&&(ae.current=Bs());const he=()=>{ce.current!==null&&(window.clearTimeout(ce.current),ce.current=null)},ve=()=>{var d;(d=be.current)==null||d.stop()},Je=()=>{var d,h;(d=re.current)==null||d.abort(),(h=ae.current)==null||h.cancel(),ve(),he(),p(!1)},Ye=()=>{he(),ce.current=window.setTimeout(()=>{ce.current=null,p(!1),a()},1e3)};r.useEffect(()=>(()=>{var d,h;ve(),(d=ae.current)==null||d.cancel(),(h=re.current)==null||h.abort(),he()}),[]);const Ze=async(d,h)=>{await Ns(d,!h),a()},Fe=d=>{g||(R(""),f(d))},es=()=>{g||(R(""),f(null))},ss=async()=>{const d=j;if(!(!d||g)){m(d.id),R("");try{await _s(d.id),s(h=>h.filter(Q=>Q.id!==d.id)),f(null)}catch(h){console.error("删除账号失败:",h),R((h==null?void 0:h.message)||"删除账号失败,请稍后重试")}finally{m("")}}},ts=async d=>{c(d.id);try{const h=await vs(d.id);h!=null&&h.profile_error&&alert("资料刷新失败:"+h.profile_error),await a()}catch(h){console.error("刷新账号资料失败:",h),alert((h==null?void 0:h.message)||"刷新账号资料失败,请先重新授权该账号")}finally{c("")}},as=async(d,h)=>{const Q=await ks(d,h==null?void 0:h.id);if(!Q.success||!Q.account_id)throw new Error(Q.message||"保存扫码授权失败");return Q.account_id},qe=async d=>{var Ie,Le,Te,De;ve(),(Ie=re.current)==null||Ie.abort();const h=new AbortController;re.current=h;const Q=ae.current.next();he();const Pe=d||null;Y(Pe),p(!0),P("loading"),S(""),T(""),v(""),I("");try{const z=await ws({signal:h.signal});if(!((Le=ae.current)!=null&&Le.isCurrent(Q)))return;if(!z.success||!z.qr_code_url||!z.session_id)throw new Error(z.message||"闲鱼未返回可用的登录二维码");if(z.success&&z.qr_code_url&&z.session_id){const Ee=z.session_id;T(z.qr_code_url),P("waiting"),(Te=be.current)==null||Te.start(Ee,ys,{onSuccess:(async()=>{try{if(!await as(Ee,Pe)){P("error");return}}catch(H){console.error("保存扫码授权失败",H),P("error");return}P("success"),Ye()}),onScanned:(()=>{P("waiting")}),onTerminalError:(()=>{P("error")}),onPollError:(H=>{console.error("轮询扫码状态失败",H),P("error")}),onVerificationRequired:(H=>{P("verification"),H.face_qr_url&&I(H.face_qr_url),H.verification_screenshot&&v(H.verification_screenshot)})})}}catch(z){if(!((De=ae.current)!=null&&De.isCurrent(Q)))return;S(z instanceof Error?z.message:"二维码获取失败,请稍后重试"),P("error")}finally{re.current===h&&(re.current=null)}};if(n)return e.jsx("div",{className:"p-20 flex justify-center",children:e.jsx(G,{className:"w-8 h-8 text-brand animate-spin"})});const _e=t.filter(d=>{const h=b.trim().toLowerCase();return h?[d.id,d.nickname,d.remark,d.username,d.runtime_message].some(Q=>(Q||"").toLowerCase().includes(h)):!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:b,onChange:(d=>x(d.target.value)),placeholder:"搜索昵称 / 备注 / 账号ID",className:"ios-input px-4 py-3 rounded-2xl text-sm w-full sm:w-72"}),e.jsxs("button",{onClick:(()=>qe()),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(Re,{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:["当前显示 ",_e.length," / ",t.length," 个账号"]}),e.jsx("div",{className:"text-blue-700",children:"如果某个账号只显示 ID,点该账号右侧“刷新资料”;若刷新失败,先点二维码重新授权。"})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-6",children:[_e.map(d=>e.jsx(Hs,{account:d,refreshing:o===d.id,deleting:g===d.id,onRefreshProfile:ts,onReauthorize:qe,onEdit:we,onAI:l,onTasks:M,onToggle:Ze,onDelete:Fe},d.id)),t.length===0&&e.jsxs("div",{className:"ios-card p-12 text-center",children:[e.jsx("div",{className:"w-20 h-20 bg-gray-100 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(Ve,{className:"w-10 h-10 text-gray-400"})}),e.jsx("h3",{className:"text-lg font-bold text-gray-900",children:"暂无账号"}),e.jsx("p",{className:"text-gray-500 mt-1",children:"请点击右上角扫码添加您的闲鱼账号"})]}),t.length>0&&_e.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。"})]})]}),B&&xe.createPortal(e.jsx(Os,{account:B,onClose:(()=>M(null)),onSaved:(d=>{s(h=>h.map(Q=>Q.id===B.id?{...Q,auto_rate_enabled:d.auto_rate_enabled,rate_content:d.rate_content,auto_polish_enabled:d.auto_polish_enabled,polish_time:d.polish_time,last_rate_scan_at:d.last_rate_scan_at,last_polish_date:d.last_polish_date,last_polish_at:d.last_polish_at}:Q))})}),document.body),j&&e.jsx(Xs,{account:j,deleting:g===j.id,error:u,onClose:es,onConfirm:ss}),k&&e.jsx(Ys,{target:W,status:J,codeUrl:A,errorMessage:D,faceQrUrl:C,verificationScreenshot:w,onClose:Je}),Z==="edit"&&$&&e.jsx(zs,{account:$,editForm:O,setEditForm:K,saving:me,onClose:ye,onSave:de,onRestartPause:Ne,longLogin:se,onToggleLongLogin:N,passwordLoginView:oe,onPasswordLogin:He,onCancelPasswordLogin:Xe,notifChannels:ne,selectedChannelIds:_,bindingsLoaded:U,bindingsLoading:te,bindingsLoadError:fe,onRetryBindings:(()=>y($.id)),onToggleChannel:q,onSettingsDirty:(()=>ie(!0))}),Z==="ai-settings"&&$&&e.jsx(Gs,{account:$,settings:pe,saving:me,onChange:je,onClose:i,onSave:E})]})};export{it as default};