Files
Ydisks-Xianyu-Helper/internal/webui/static/assets/Rules-CeggCy2B.js
T
Christ c3020bde09 修复:优化二维码风控登录与批量发布兼容性
- 优化二维码登录风控提示,支持人脸验证二维码和验证截图。

- 修复批量发布发货地持久化,并兼容旧任务地址格式。

- 加强二维码登录和通知渠道的敏感数据保护。

- 补充登录风控使用说明。
2026-08-19 22:50:03 +08:00

2 lines
58 KiB
JavaScript

import{j as e,r as o,b as Fe}from"./react-vendor-C_od1ZSF.js";import{k as Je,ae as it,af as vt,m as Nt,R as Te,N as Ye,Z as He,u as wt,n as et,I as kt,a1 as Ct,X as ke,V as ze,y as Ce,h as St,g as Rt,a6 as At,ag as $t,o as tt,ah as Mt}from"./icons-vendor-DwxdQTKt.js";import{g as Z,o as Ae,c as Ge,p as Ke,a as fe,d as Ue}from"./index-zEvleK2K.js";const Ee=(t,a)=>t.allowed_resolutions.includes(a),Pt=(t,a)=>({runs:t.runs.filter(i=>!a||i.cookie_id===a),pending_tasks:t.pending_tasks.filter(i=>!a||i.cookie_id===a)}),Lt=t=>({external_result_unknown:"外部动作结果未知",invalid_snapshot:"历史数据无法恢复",rule_unavailable:"规则不可用",partial_failure:"部分动作失败",execution_failed:"动作执行失败"})[t]||"自动化异常",It=({runs:t,pendingTasks:a,onResolveRun:i,onResolveDeferredTask:u})=>e.jsxs("section",{className:"rounded-2xl border border-red-200 bg-red-50 p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Je,{className:"w-5 h-5 text-red-600 mt-0.5"}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-black text-red-900",children:"需要人工处理的自动化任务"}),e.jsx("p",{className:"text-sm text-red-700 mt-1",children:"请先在闲鱼聊天、订单或商品列表中核对真实结果,再选择继续或重试。"})]})]}),e.jsxs("div",{className:"space-y-3",children:[t.map(r=>e.jsxs("div",{className:"rounded-xl border border-red-100 bg-white p-4 flex flex-col lg:flex-row lg:items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"font-bold text-gray-900",children:["账号 ",r.cookie_id," · 订单 ",r.order_id||"-"," · 已记录发送 ",r.sent_count," 条"]}),e.jsx("div",{className:"text-xs font-bold text-red-800 mt-1",children:Lt(r.issue_kind)}),e.jsx("div",{className:"text-xs text-red-700 mt-1 break-words",children:r.error_message})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 shrink-0",children:[Ee(r,"continue")&&e.jsx("button",{onClick:(()=>i(r.id,"continue")),className:"px-3 py-2 rounded-lg bg-emerald-100 text-emerald-800 text-xs font-bold",children:"已执行,继续下一步"}),Ee(r,"retry")&&e.jsx("button",{onClick:(()=>i(r.id,"retry")),className:"px-3 py-2 rounded-lg bg-amber-100 text-amber-800 text-xs font-bold",children:"未执行,安全重试"}),Ee(r,"cancel")&&e.jsx("button",{onClick:(()=>i(r.id,"cancel")),className:"px-3 py-2 rounded-lg bg-gray-100 text-gray-700 text-xs font-bold",children:"终止"})]})]},`run-${r.id}`)),a.map(r=>e.jsxs("div",{className:"rounded-xl border border-red-100 bg-white p-4 flex flex-col lg:flex-row lg:items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"font-bold text-gray-900",children:["账号 ",r.cookie_id," · 延迟任务重试已达 ",r.attempt_count," 次"]}),e.jsx("div",{className:"text-xs text-red-700 mt-1 break-words",children:r.error_message})]}),e.jsxs("div",{className:"flex gap-2 shrink-0",children:[e.jsx("button",{onClick:(()=>u(r.id,"retry")),className:"px-3 py-2 rounded-lg bg-amber-100 text-amber-800 text-xs font-bold",children:"重新入队"}),e.jsx("button",{onClick:(()=>u(r.id,"dismiss")),className:"px-3 py-2 rounded-lg bg-gray-100 text-gray-700 text-xs font-bold",children:"忽略"})]})]},`task-${r.id}`))]})]}),Dt=async t=>Z("/api/v1/accounts/details",void 0,t),ot=async t=>Z("/api/v1/cards",void 0,t),dt=async(t,a)=>Z("/api/v1/items",void 0,a),ct=t=>t.map(a=>{var i,u;return{id:String(a.id),name:a.name||"",trigger_type:a.trigger_type||"order_paid",item_keyword:a.item_title||a.item_id||"",cookie_id:a.cookie_id||"",item_id:a.item_id||"",item_title:a.item_title||"",card_group_id:Number(((i=(a.actions||[]).find(r=>r.action_type==="send_card"))==null?void 0:i.card_id)||0),card_group_name:((u=(a.actions||[]).find(r=>r.action_type==="send_card"))==null?void 0:u.card_name)||"",priority:a.priority||100,enabled:a.enabled||!1,config_json:a.config_json||"{}",actions:(a.actions||[]).map(r=>({id:r.id?String(r.id):void 0,action_type:r.action_type,card_id:Number(r.card_id||0),card_name:r.card_name||"",delivery_count:Number(r.delivery_count||1),message_template:r.message_template||"",delay_seconds:Number(r.delay_seconds||0),config_json:r.config_json||"{}",enabled:r.enabled!==!1,sort_order:Number(r.sort_order||0)})),variants:(a.actions||[]).filter(r=>r.action_type==="send_card").map(r=>{let y={};try{y=JSON.parse(r.config_json||"{}")}catch{}return{id:r.id?String(r.id):void 0,spec_name:y.spec_name||"",spec_value:y.spec_value||"",card_id:Number(r.card_id||0),card_name:r.card_name||"",delivery_count:Number(r.delivery_count||1),enabled:r.enabled!==!1,delay_override:y.delay_override===!0,delay_seconds:Number(r.delay_seconds||0),config_json:r.config_json||"{}"}})}}),Ft=async()=>{const t=await Z("/api/v1/automation-rules"),a=Ge(t,["data","rules","items"]);return ct(a)},Tt=async({cookieId:t,triggerType:a,enabled:i,search:u,page:r=1,pageSize:y=10}={})=>{const A=await Z("/api/v1/automation-rules",{page:r,page_size:y,cookie_id:t||void 0,trigger_type:a||void 0,enabled:i,search:(u==null?void 0:u.trim())||void 0}),C=Ae(A,["data","result"])||{},m=ct(Ge(A,["data","rules","items"]));return{success:!0,data:m,total:Number(C.total??m.length),page:Number(C.page??r),page_size:Number(C.page_size??y),total_pages:Number(C.total_pages??(m.length?1:0)),trigger_counts:Object.fromEntries(Object.entries(C.trigger_counts||{}).map(([I,T])=>[I,Number(T)]))}},zt=(t,a)=>{if(t!=="order_paid")return a.map((r,y)=>({...r,sort_order:r.sort_order||y+1}));const i=a.filter(r=>r.action_type==="send_card").map((r,y)=>({...r,sort_order:y+1})),u=a.filter(r=>r.action_type!=="send_card"&&r.action_type!=="confirm_shipment");return[...i,...u.map((r,y)=>({...r,sort_order:i.length+y+1})),{action_type:"confirm_shipment",enabled:!0,sort_order:i.length+u.length+1}]},st=async t=>{const a=t.trigger_type||"order_paid",u=[{order_paid:"付款后自动发货",buyer_reviewed:"评价后发送赠品",review_missing_timeout:"超时未评价求评价"}[a]||"自动化规则",t.item_title||t.item_id||t.cookie_id||""].filter(Boolean).join(" - "),r=(t.actions||[]).filter(m=>m.action_type!=="send_card"&&m.action_type!=="confirm_shipment"),y=t.variants&&t.variants.length>0?[...t.variants.map((m,I)=>({action_type:"send_card",card_id:m.card_id,delivery_count:m.delivery_count||1,enabled:m.enabled!==!1,sort_order:I+1,delay_seconds:m.delay_seconds||0,config_json:JSON.stringify({spec_name:m.spec_name||"",spec_value:m.spec_value||"",delay_override:m.delay_override===!0})})),...r]:t.actions&&t.actions.length>0?t.actions:[{action_type:"send_card",card_id:t.card_group_id||0,delivery_count:1,enabled:!0,sort_order:1}],A=zt(a,y),C={cookie_id:t.cookie_id||"",item_id:t.item_id||"",name:(t.name||"").trim()||u||"自动化规则",trigger_type:a,enabled:t.enabled??!0,priority:t.priority||100,config_json:t.config_json||"{}",actions:A.map((m,I)=>({action_type:m.action_type,card_id:m.card_id||0,delivery_count:m.delivery_count||1,message_template:m.message_template||"",delay_seconds:m.delay_seconds||0,config_json:m.config_json||"{}",enabled:m.enabled!==!1,sort_order:m.sort_order||I+1}))};return t.id?Ke(`/api/v1/automation-rules/${t.id}`,C):fe("/api/v1/automation-rules",C)},Et=async t=>Ue(`/api/v1/automation-rules/${t}`),Ot=async()=>{const t=await Z("/api/v1/automation-issues"),a=Ae(t,["data","result"])||{};return{runs:Array.isArray(a==null?void 0:a.runs)?a.runs:[],pending_tasks:Array.isArray(a==null?void 0:a.pending_tasks)?a.pending_tasks:[]}},qt=async(t,a)=>fe(`/api/v1/automation-runs/${t}/resolve`,{resolution:a}),Vt=async(t,a)=>fe(`/api/v1/automation-pending-tasks/${t}/resolve`,{resolution:a}),Bt=t=>({id:String((t==null?void 0:t.id)||""),keyword:(t==null?void 0:t.keyword)||"",reply:(t==null?void 0:t.reply)||"",item_id:(t==null?void 0:t.item_id)||"",type:(t==null?void 0:t.type)==="image"?"image":"text",image_url:(t==null?void 0:t.image_url)||""}),Jt=async t=>{const a=await Z(`/api/v1/reply-rules/${t}/typed`);return Ge(a,["data","items","rules"]).map(Bt)},Gt=async t=>t?(await Jt(t)).map(i=>({id:i.id,keyword:i.keyword||"",reply_content:i.reply||"",match_type:"fuzzy",enabled:!0,item_id:i.item_id||"",type:i.type==="image"?"image":"text",image_url:i.image_url||""})):[],Kt=async(t,a)=>{const i=t.type||"text",u={keyword:t.keyword||"",reply:i==="text"&&t.reply_content||"",item_id:t.item_id||"",type:i,image_url:i==="image"&&t.image_url||""};return t.id?Ke(`/api/v1/reply-rules/${a}/typed/${t.id}`,u):fe(`/api/v1/reply-rules/${a}/items`,u)},Ut=async(t,a)=>Ue(`/api/v1/reply-rules/${a}/typed/${t}`),at=async()=>{const t=await Z("/api/v1/default-replies");return Ae(t,["data","replies","items"])||{}},Wt=async t=>{const a=await Z(`/api/v1/default-replies/${t}`),i=Ae(a,["data","result"])||{};return{cookie_id:t,enabled:i.enabled||!1,reply_content:i.reply_content||"",reply_once:i.reply_once||!1,reply_image_url:i.reply_image_url||""}},Zt=async(t,a)=>Ke(`/api/v1/default-replies/${t}`,{enabled:a.enabled??!1,reply_content:a.reply_content||"",reply_once:a.reply_once??!1,reply_image_url:a.reply_image_url||""}),Xt=async t=>Ue(`/api/v1/default-replies/${t}`),Qt=async t=>fe(`/api/v1/default-replies/${t}/clear-records`,{}),Oe=()=>({submitting:!1,result:"idle"}),qe=t=>t.submitting?t:{submitting:!0,result:"idle"},Ve=(t,a)=>({...t,submitting:!1,result:a?"success":"failure"}),rt=t=>t+1,Be=(t,a,i,u)=>t===a&&i===u,Yt=t=>{const[a,i]=o.useState([]),[u,r]=o.useState({runs:[],pending_tasks:[]}),[y,A]=o.useState([]),[C,m]=o.useState({}),[I,T]=o.useState([]),[J,w]=o.useState([]),[G,D]=o.useState([]),[v,X]=o.useState(!1),q=o.useRef(0),re=o.useRef(0),[Q,K]=o.useState(0),[le,Y]=o.useState(0),[V,H]=o.useState({}),U=o.useCallback(async()=>{const P=Promise.all([Dt(),ot(),dt(),at()]),[_,j,F,ee]=await P;T(_),w(j),D(F),m(ee),t.setSelectedAccountId(ne=>{var E;return ne||((E=_[0])==null?void 0:E.id)||""})},[t.setSelectedAccountId]),n=o.useCallback(async()=>{var ee;const P=rt(q.current);q.current=P;const _=Ot().catch(ne=>(console.warn("加载自动化异常列表失败,不阻断规则展示",ne),null)),j=await Tt({cookieId:t.selectedAccountId||void 0,triggerType:t.automationTriggerFilter,enabled:t.automationStatusFilter==="all"?void 0:t.automationStatusFilter==="enabled",search:t.debouncedAutomationSearch,page:t.automationPage,pageSize:t.automationPageSize});if(!Be(P,q.current,t.selectedAccountId,t.selectedAccountId))return;i(j.data),K(j.total),Y(j.total_pages),H(j.trigger_counts||{}),j.page!==t.automationPage&&((ee=t.onAutomationPageChange)==null||ee.call(t,j.page));const F=await _;Be(P,q.current,t.selectedAccountId,t.selectedAccountId)&&F&&r(F)},[t.automationPage,t.automationPageSize,t.automationStatusFilter,t.automationTriggerFilter,t.debouncedAutomationSearch,t.onAutomationPageChange,t.selectedAccountId]),$=o.useCallback(async()=>{const P=rt(re.current);re.current=P;const _=t.selectedAccountId;if(A([]),!_)return;const j=await Gt(_);Be(P,re.current,_,t.selectedAccountId)&&A(j)},[t.selectedAccountId]),R=o.useCallback(async()=>{m(await at())},[]),z=o.useCallback(async()=>{X(!0);try{t.activeTab==="automation"?await n():t.activeTab==="reply"?await $():await R()}finally{X(!1)}},[n,R,$,t.activeTab]);return{automationRules:a,automationIssues:u,replyRules:y,defaultReplies:C,accounts:I,cards:J,items:G,automationTotal:Q,automationTotalPages:le,automationTriggerCounts:V,loading:v,setLoading:X,setAutomationRules:i,setCards:w,setItems:D,loadReferenceData:U,loadAutomationRules:n,loadReplyRules:$,loadDefaultReplies:R,refresh:z}},ae={order_paid:{label:"付款后自动发货",shortLabel:"自动发货",description:"闲鱼付款系统卡片进入自动化中心后,先发送卡密,成功后再确认发货。",flow:["付款系统卡片","匹配商品/规格","发送卡密","确认发货"],accent:"blue",icon:Nt},buyer_reviewed:{label:"评价后发送赠品",shortLabel:"评价赠品",description:"闲鱼评价系统卡片进入自动化中心后,给买家发送赠品卡密。",flow:["评价系统卡片","匹配商品/规格","发送赠品"],accent:"emerald",icon:vt},review_missing_timeout:{label:"超时未评价求评价",shortLabel:"求评价",description:"计划任务扫描已发货未评价订单,到期后发送求评价文案。",flow:["计划任务扫描","已发货未评价","达到等待时间","发送提醒"],accent:"amber",icon:it}},Se=["order_paid","buyer_reviewed","review_missing_timeout"],Ht="亲,商品使用满意的话,麻烦给个评价,谢谢~",he=()=>({spec_name:"",spec_value:"",card_id:0,delivery_count:1,enabled:!0,delay_override:!1,delay_seconds:0}),mt=t=>{if(!t)return{};try{const a=JSON.parse(t);return a&&typeof a=="object"&&!Array.isArray(a)?a:{}}catch{return{}}},ce=(t,a={})=>{const i=mt(t);return JSON.stringify({after_shipped_hours:Number(i.after_shipped_hours||72),repeat_interval_hours:Number(i.repeat_interval_hours||24),max_attempts:Number(i.max_attempts||1),...a})},ye=(t,a)=>{var u;const i=((u=ae[t])==null?void 0:u.label)||"自动化规则";return a?`${i} - ${a}`:i},lt=t=>{const a=(t||"").trim();return a?Object.values(ae).some(i=>a===i.label||a.startsWith(`${i.label} -`)):!0},_e=(t,a=0)=>{if(t==="review_missing_timeout")return[{action_type:"send_text",message_template:Ht,enabled:!0,sort_order:1}];const i={action_type:"send_card",card_id:a,delivery_count:1,enabled:!0,sort_order:1};return t==="order_paid"?[i,{action_type:"confirm_shipment",enabled:!0,sort_order:2}]:[i]},es=t=>{var i,u;if(t.trigger_type==="review_missing_timeout")return((u=(i=t.actions)==null?void 0:i.find(r=>r.action_type==="send_text"))==null?void 0:u.message_template)||"发送求评价文案";const a=(t.actions||[]).filter(r=>r.action_type==="send_card");return a.length?a.map(r=>r.card_name||`卡密 ${r.card_id}`).join(" / "):"未配置卡密库存"},nt=(t,a=!1)=>{const i={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 i[t]||i.blue},ts=t=>t?"bg-emerald-100 text-emerald-700":"bg-gray-200 text-gray-500",Re=t=>(t==null?void 0:t.nickname)||(t==null?void 0:t.remark)||(t==null?void 0:t.id)||"未知账号",ss=t=>t===!0||t===1||t==="1",as=({selectedAccountId:t,setSelectedAccountId:a,setActiveTab:i,items:u,setAutomationRules:r,setCards:y,setItems:A,setLoading:C,loadAutomationRules:m,loadReferenceData:I,loadReplyRules:T,loadDefaultReplies:J,initialDeliveryTarget:w,onDeliveryTargetHandled:G})=>{var xe;const[D,v]=o.useState(!1),[X,q]=o.useState(!1),[re,Q]=o.useState(!1),[K,le]=o.useState(Oe),[Y,V]=o.useState(Oe),[H,U]=o.useState(Oe),[n,$]=o.useState(null),[R,z]=o.useState(null),[M,P]=o.useState({cookie_id:"",enabled:!1,reply_content:"",reply_once:!1,reply_image_url:""}),_=o.useMemo(()=>n!=null&&n.cookie_id&&n.item_id?u.find(l=>l.cookie_id===n.cookie_id&&l.item_id===n.item_id):void 0,[n==null?void 0:n.cookie_id,n==null?void 0:n.item_id,u]),j=ss(_==null?void 0:_.is_multi_spec),F=(n==null?void 0:n.trigger_type)||"order_paid",ee=ae[F],ne=mt(n==null?void 0:n.config_json),E=(xe=n==null?void 0:n.variants)!=null&&xe.length?n.variants:[he()],W=o.useCallback((l="order_paid",d=t,b="")=>{const p=u.find(N=>N.cookie_id===d&&N.item_id===b),h=(p==null?void 0:p.item_title)||b;return{name:ye(l,h),trigger_type:l,cookie_id:d,item_id:b,item_title:(p==null?void 0:p.item_title)||"",item_keyword:h,card_group_id:0,priority:100,enabled:!0,config_json:l==="review_missing_timeout"?ce():"{}",actions:_e(l),variants:l==="review_missing_timeout"?[]:[he()]}},[u,t]),ue=o.useCallback(l=>{var b,p;const d=l.trigger_type||"order_paid";$({...l,trigger_type:d,config_json:d==="review_missing_timeout"?ce(l.config_json):l.config_json||"{}",actions:(b=l.actions)!=null&&b.length?l.actions.map(h=>({...h})):_e(d,l.card_group_id),variants:(p=l.variants)!=null&&p.length?l.variants.map(h=>({...h})):d==="review_missing_timeout"?[]:[he()]}),v(!0)},[]);o.useEffect(()=>{if(!w)return;let l=!1;return(async()=>{i("automation"),a(w.cookieId),C(!0);try{const[b,p,h]=await Promise.all([Ft(),dt(),ot().catch(f=>(console.warn("加载卡密库存失败,不阻断打开自动化规则",f),[]))]);if(l)return;r(b),A(p),y(h);const N=b.find(f=>f.cookie_id===w.cookieId&&f.item_id===w.itemId&&f.trigger_type==="order_paid");if(N)ue(N);else{const f=p.find(B=>B.cookie_id===w.cookieId&&B.item_id===w.itemId);$({...W("order_paid",w.cookieId,w.itemId),item_title:(f==null?void 0:f.item_title)||"",item_keyword:(f==null?void 0:f.item_title)||w.itemId,name:ye("order_paid",(f==null?void 0:f.item_title)||w.itemId)}),v(!0)}}catch(b){console.error("打开商品自动化规则失败",b),alert("无法加载该商品的自动化规则")}finally{l||(C(!1),G==null||G())}})(),(()=>{l=!0})},[W,w,G,ue,i,r,y,A,C,a]);const $e=o.useCallback((l="order_paid")=>{if(!t){alert("请先选择账号");return}$(W(l)),v(!0)},[W,t]),je=o.useCallback(l=>{var p,h,N,f,B;if(!n)return;const d=((h=(p=n.variants)==null?void 0:p.find(se=>se.card_id))==null?void 0:h.card_id)||((f=(N=n.actions)==null?void 0:N.find(se=>se.action_type==="send_card"))==null?void 0:f.card_id)||n.card_group_id||0,b=(_==null?void 0:_.item_title)||n.item_title||n.item_id||"";$({...n,trigger_type:l,name:lt(n.name)?ye(l,b):n.name,card_group_id:d,config_json:l==="review_missing_timeout"?ce(n.config_json):"{}",actions:_e(l,d),variants:l==="review_missing_timeout"?[]:(B=n.variants)!=null&&B.length?n.variants:[{...he(),card_id:d}]})},[n,_]),Me=o.useCallback(l=>{if(!n)return;const d=u.find(p=>p.cookie_id===(n.cookie_id||t)&&p.item_id===l),b=(d==null?void 0:d.item_title)||l;$({...n,item_id:l,item_title:(d==null?void 0:d.item_title)||"",item_keyword:b,name:lt(n.name)?ye(F,b):n.name})},[F,n,u,t]),pe=o.useCallback((l,d)=>{var p;if(!n)return;const b=E.map((h,N)=>N===l?{...h,...d}:h);$({...n,variants:b,card_group_id:((p=b[0])==null?void 0:p.card_id)||0})},[E,n]),Pe=o.useCallback(()=>{if(!n)return;const l=E[E.length-1];$({...n,variants:[...E,{...he(),spec_name:j&&(l==null?void 0:l.spec_name)||"",spec_value:j&&(l==null?void 0:l.spec_value)||""}]})},[E,n,j]),ve=o.useCallback(async()=>{var h,N,f,B,se;if(!n||K.submitting)return;const l=n.trigger_type||"order_paid";if(!n.cookie_id)return alert("请选择账号");const d=(h=n.variants)!=null&&h.length?n.variants:[];if(l!=="review_missing_timeout"){if(!d.length||d.some(k=>!k.card_id))return alert(l==="buyer_reviewed"?"请选择评价赠品卡密库存":"请选择发货卡密库存");if(j&&d.some(k=>!k.spec_name.trim()||!k.spec_value.trim()))return alert("多规格商品必须填写每一行的规格名称和规格值")}if(l==="review_missing_timeout"&&!(((f=(N=n.actions)==null?void 0:N.find(Le=>Le.action_type==="send_text"))==null?void 0:f.message_template)||"").trim())return alert("请填写求评价文案");const b=l==="review_missing_timeout"?[]:d.map(k=>({...k,spec_name:j?k.spec_name.trim():"",spec_value:j?k.spec_value.trim():"",delivery_count:Math.max(1,Number(k.delivery_count)||1),enabled:k.enabled!==!1}));le(qe(K));let p=!1;try{await st({...n,trigger_type:l,name:(n.name||"").trim()||ye(l,(_==null?void 0:_.item_title)||n.item_id||""),config_json:l==="review_missing_timeout"?ce(n.config_json):n.config_json||"{}",actions:(B=n.actions)!=null&&B.length?n.actions:_e(l,((se=b[0])==null?void 0:se.card_id)||n.card_group_id||0),variants:b}),v(!1),await Promise.all([m(),I()]),alert("保存成功"),p=!0}catch(k){console.error("保存自动化规则失败:",k),alert("保存失败:"+k.message)}finally{le(k=>Ve(k,p))}},[K,n,j,m,I,_]),g=o.useCallback(async l=>{if(confirm("确定删除该自动化规则吗?"))try{await Et(l),await m(),alert("删除成功")}catch(d){alert("删除失败:"+d.message)}},[m]),O=o.useCallback(async l=>{try{await st({...l,enabled:!l.enabled}),await m()}catch(d){alert("操作失败:"+d.message)}},[m]),S=o.useCallback(async(l,d)=>{if(confirm(d==="continue"?"确认外部动作已经执行成功,并跳到下一步吗?":d==="retry"?"确认外部动作没有执行,可以安全重试吗?错误判断可能造成重复发送。":"确认终止该自动化运行吗?"))try{await qt(l,d),await m()}catch(p){alert("处理失败:"+p.message)}},[m]),te=o.useCallback(async(l,d)=>{if(confirm(d==="retry"?"确认重新执行该任务吗?":"确认忽略并删除该异常任务吗?"))try{await Vt(l,d),await m()}catch(b){alert("处理失败:"+b.message)}},[m]),L=o.useCallback(()=>{if(!t)return alert("请先选择账号");z({keyword:"",reply_content:"",image_url:"",item_id:"",type:"text",match_type:"fuzzy",enabled:!0}),q(!0)},[t]),ie=o.useCallback(async()=>{var b,p,h;if(!R||!t||Y.submitting)return;const l=R.type==="image"?!!((b=R.image_url)!=null&&b.trim()):!!((p=R.reply_content)!=null&&p.trim());if(!((h=R.keyword)!=null&&h.trim())||!l)return alert("请填写关键词和回复内容");V(qe(Y));let d=!1;try{await Kt({...R,match_type:"fuzzy",enabled:!0},t),q(!1),await T(),alert("保存成功"),d=!0}catch(N){alert("保存失败:"+N.message)}finally{V(N=>Ve(N,d))}},[R,T,Y,t]),ge=o.useCallback(async l=>{if(!(!t||!confirm("确定删除该回复规则吗?")))try{await Ut(l,t),await T(),alert("删除成功")}catch(d){alert("删除失败:"+d.message)}},[T,t]),oe=o.useCallback(async(l=t)=>{if(!l)return alert("请先选择账号");try{const d=await Wt(l);P({cookie_id:l,enabled:d.enabled,reply_content:d.reply_content,reply_once:d.reply_once,reply_image_url:d.reply_image_url||""})}catch{P({cookie_id:l,enabled:!1,reply_content:"",reply_once:!1,reply_image_url:""})}Q(!0)},[t]),me=o.useCallback(async()=>{if(H.submitting)return;if(!M.cookie_id)return alert("请先选择账号");if(M.enabled&&!M.reply_content.trim()&&!M.reply_image_url.trim())return alert("启用默认回复时,请填写回复内容或图片 URL");U(qe(H));let l=!1;try{await Zt(M.cookie_id,{enabled:M.enabled,reply_content:M.reply_content,reply_once:M.reply_once,reply_image_url:M.reply_image_url}),Q(!1),await J(),alert("保存成功"),l=!0}catch(d){alert("保存失败:"+d.message)}finally{U(d=>Ve(d,l))}},[M,H,J]),Ne=o.useCallback(async l=>{if(confirm("确定删除该账号默认回复吗?"))try{await Xt(l),await J(),alert("删除成功")}catch(d){alert("删除失败:"+d.message)}},[J]),be=o.useCallback(async l=>{if(confirm("确定清空该账号的默认回复记录吗?清空后可重新对所有会话使用“只回复一次”。"))try{await Qt(l),alert("清空成功")}catch(d){alert("清空失败:"+d.message)}},[]);return{showAutomationModal:D,setShowAutomationModal:v,showReplyModal:X,setShowReplyModal:q,showDefaultModal:re,setShowDefaultModal:Q,automationSubmitState:K,replySubmitState:Y,defaultReplySubmitState:H,editingAutomationRule:n,setEditingAutomationRule:$,editingReplyRule:R,setEditingReplyRule:z,defaultForm:M,setDefaultForm:P,selectedRuleItem:_,isMultiSpecRule:j,currentTrigger:F,currentMeta:ee,reviewConfig:ne,displayVariants:E,buildAutomationDraft:W,openAutomationRule:ue,openNewAutomationRule:$e,handleTriggerChange:je,handleAutomationItemChange:Me,updateVariant:pe,appendDeliveryContent:Pe,handleSaveAutomationRule:ve,handleDeleteAutomation:g,handleToggleAutomation:O,handleResolveRunIssue:S,handleResolveDeferredIssue:te,handleAddReplyRule:L,handleSaveReplyRule:ie,handleDeleteReply:ge,openDefaultReplyModal:oe,handleSaveDefaultReply:me,handleDeleteDefaultReply:Ne,handleClearDefaultReplyRecords:be}},is=({initialDeliveryTarget:t,onDeliveryTargetHandled:a})=>{var Xe,Qe;const[i,u]=o.useState("automation"),[r,y]=o.useState(""),[A,C]=o.useState(""),[m,I]=o.useState(""),[T,J]=o.useState(""),[w,G]=o.useState("all"),[D,v]=o.useState(1),[X,q]=o.useState(10),re=Yt({activeTab:i,selectedAccountId:r,automationTriggerFilter:T,automationStatusFilter:w,debouncedAutomationSearch:m,automationPage:D,automationPageSize:X,setSelectedAccountId:y,onAutomationPageChange:v}),{automationRules:Q,automationIssues:K,replyRules:le,defaultReplies:Y,accounts:V,cards:H,items:U,loading:n,setLoading:$,automationTotal:R,automationTotalPages:z,automationTriggerCounts:M,setAutomationRules:P,setCards:_,setItems:j,loadReferenceData:F,loadAutomationRules:ee,loadReplyRules:ne,loadDefaultReplies:E,refresh:W}=re,ue=as({selectedAccountId:r,setSelectedAccountId:y,setActiveTab:u,items:U,setAutomationRules:P,setCards:_,setItems:j,setLoading:$,loadAutomationRules:ee,loadReferenceData:F,loadReplyRules:ne,loadDefaultReplies:E,initialDeliveryTarget:t,onDeliveryTargetHandled:a}),{showAutomationModal:$e,setShowAutomationModal:je,showReplyModal:Me,setShowReplyModal:pe,showDefaultModal:Pe,setShowDefaultModal:ve,editingAutomationRule:g,setEditingAutomationRule:O,editingReplyRule:S,setEditingReplyRule:te,defaultForm:L,setDefaultForm:ie,selectedRuleItem:ge,isMultiSpecRule:oe,currentTrigger:me,currentMeta:Ne,reviewConfig:be,displayVariants:xe,openAutomationRule:l,openNewAutomationRule:d,handleTriggerChange:b,handleAutomationItemChange:p,updateVariant:h,appendDeliveryContent:N,handleSaveAutomationRule:f,handleDeleteAutomation:B,handleToggleAutomation:se,handleResolveRunIssue:k,handleResolveDeferredIssue:Le,handleAddReplyRule:xt,handleSaveReplyRule:ut,handleDeleteReply:pt,openDefaultReplyModal:We,handleSaveDefaultReply:gt,handleDeleteDefaultReply:bt,handleClearDefaultReplyRecords:ht}=ue;o.useEffect(()=>{const s=window.setTimeout(()=>{v(1),I(A.trim())},300);return(()=>window.clearTimeout(s))},[A]),o.useEffect(()=>{F().catch(s=>console.error("加载规则参考数据失败",s))},[F]),o.useEffect(()=>{W().catch(s=>console.error("刷新规则页面失败",s))},[W]);const Ie=o.useMemo(()=>Q.filter(s=>!r||s.cookie_id===r),[Q,r]),we=o.useMemo(()=>Pt(K,r),[K,r]),Ze=o.useMemo(()=>V.filter(s=>!r||s.id===r),[V,r]),yt=o.useMemo(()=>{if(z<=1)return[];const s=Math.max(1,Math.min(D-2,z-4)),c=Math.min(z,s+4);return Array.from({length:c-s+1},(x,de)=>s+de)},[D,z]),De=!!(A.trim()||T||w!=="all"),_t=()=>{C(""),I(""),J(""),G("all"),v(1)},ft=o.useMemo(()=>{const s=(g==null?void 0:g.cookie_id)||r;return U.filter(c=>c.cookie_id===s)},[g==null?void 0:g.cookie_id,U,r]),jt=i==="automation"?"新建自动化":i==="reply"?"新增关键词":"编辑默认回复";return e.jsxs("div",{className:"min-w-0 space-y-8 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col xl:flex-row justify-between xl:items-end gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-4xl font-extrabold text-gray-900 tracking-tight",children:"自动化规则"}),e.jsx("p",{className:"text-gray-500 mt-2 font-medium",children:"系统通知卡片只进入自动化判断;买家消息进入关键词、默认或 AI 回复。"})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:flex-wrap gap-3",children:[e.jsxs("select",{value:r,onChange:(s=>{y(s.target.value),v(1)}),className:"ios-input w-full px-4 py-3 rounded-2xl text-sm sm:w-64",children:[e.jsx("option",{value:"",children:"全部账号"}),V.map(s=>e.jsx("option",{value:s.id,children:Re(s)},s.id))]}),e.jsxs("button",{onClick:W,className:"px-4 py-3 rounded-2xl font-bold bg-gray-100 hover:bg-gray-200 text-gray-700 flex items-center justify-center gap-2 whitespace-nowrap transition-colors",children:[e.jsx(Te,{className:`w-4 h-4 ${n?"animate-spin":""}`}),"刷新"]}),e.jsxs("button",{onClick:i==="automation"?(()=>d("order_paid")):i==="reply"?xt:(()=>void We()),disabled:!r,className:"ios-btn-primary px-5 py-3 rounded-2xl text-sm font-extrabold flex items-center justify-center gap-2 whitespace-nowrap disabled:opacity-50",children:[e.jsx(Ye,{className:"w-4 h-4"}),jt]})]})]}),e.jsx("div",{className:"flex flex-wrap gap-2 p-2 bg-gray-100/50 rounded-2xl",children:[{id:"automation",label:"交易自动化",icon:He},{id:"reply",label:"关键词回复",icon:wt},{id:"default",label:"账号默认回复",icon:et}].map(s=>{const c=s.icon;return e.jsxs("button",{onClick:(()=>u(s.id)),className:`inline-flex items-center gap-2 px-5 py-2.5 rounded-xl text-sm font-bold transition-all ${i===s.id?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:text-black hover:bg-gray-50"}`,children:[e.jsx(c,{className:"w-4 h-4"}),s.label]},s.id)})}),i==="automation"&&(we.runs.length>0||we.pending_tasks.length>0)&&e.jsx(It,{runs:we.runs,pendingTasks:we.pending_tasks,onResolveRun:((s,c)=>void k(s,c)),onResolveDeferredTask:((s,c)=>void Le(s,c))}),i==="automation"&&e.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-6 xl:grid-cols-[minmax(270px,0.72fr)_minmax(0,1.28fr)]",children:[e.jsxs("aside",{className:"min-w-0 space-y-4",children:[e.jsxs("div",{className:"bg-white rounded-xl p-5 border border-gray-100 shadow-sm",children:[e.jsx("h3",{className:"font-black text-gray-900 mb-1",children:"新建规则"}),e.jsx("p",{className:"text-sm text-gray-500 mb-4",children:"先选自动化类型,再配置对应动作。"}),e.jsx("div",{className:"space-y-3",children:Se.map(s=>{const c=ae[s],x=c.icon;return e.jsx("button",{type:"button",onClick:(()=>d(s)),className:`w-full text-left rounded-2xl border p-4 transition-colors ${nt(c.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(x,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-extrabold",children:c.label}),e.jsx("div",{className:"text-xs opacity-75 mt-1 leading-5",children:c.description})]})]})},s)})})]}),e.jsxs("div",{className:"bg-white rounded-xl p-5 border border-gray-100 shadow-sm",children:[e.jsxs("div",{className:"mb-4 flex items-center justify-between gap-3",children:[e.jsx("h3",{className:"font-black text-gray-900",children:"筛选结果构成"}),e.jsxs("span",{className:"text-xs font-bold text-gray-400",children:["共 ",R," 条"]})]}),e.jsx("div",{className:"space-y-3",children:Se.map(s=>{const c=ae[s],x=c.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(x,{className:"w-4 h-4 text-gray-500"}),e.jsx("span",{className:"text-sm font-bold text-gray-700",children:c.shortLabel})]}),e.jsx("span",{className:"text-sm font-black text-gray-900",children:M[s]||0})]},s)})})]})]}),e.jsxs("section",{className:"min-w-0 space-y-4",children:[e.jsxs("div",{className:"rounded-xl border border-gray-100 bg-surface-muted p-4 shadow-sm",children:[e.jsxs("div",{className:"flex flex-col gap-3 xl:flex-row xl:items-center",children:[e.jsxs("div",{className:"relative min-w-0 flex-1",children:[e.jsx(kt,{className:"pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsx("input",{type:"search","aria-label":"搜索自动化规则",placeholder:"搜索规则名、商品名或商品 ID...",value:A,onChange:(s=>{C(s.target.value),v(1)}),className:"ios-input w-full rounded-xl border-none bg-white py-2.5 pl-10 pr-4 text-sm shadow-sm"})]}),e.jsxs("div",{className:"relative xl:w-52",children:[e.jsx(Ct,{className:"pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsxs("select",{"aria-label":"按自动化类型筛选",value:T,onChange:(s=>{J(s.target.value),v(1)}),className:"ios-input w-full rounded-xl border-none bg-white py-2.5 pl-10 pr-9 text-sm shadow-sm",children:[e.jsx("option",{value:"",children:"全部自动化类型"}),Se.map(s=>e.jsx("option",{value:s,children:ae[s].shortLabel},s))]})]}),e.jsxs("select",{"aria-label":"按启用状态筛选",value:w,onChange:(s=>{G(s.target.value),v(1)}),className:"ios-input rounded-xl border-none bg-white px-4 py-2.5 text-sm shadow-sm xl:w-36",children:[e.jsx("option",{value:"all",children:"全部状态"}),e.jsx("option",{value:"enabled",children:"已启用"}),e.jsx("option",{value:"disabled",children:"已禁用"})]}),De&&e.jsx("button",{type:"button",onClick:_t,className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-xl bg-white text-gray-500 shadow-sm transition-colors hover:bg-gray-100 hover:text-gray-900",title:"清除筛选","aria-label":"清除筛选",children:e.jsx(ke,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"mt-3 flex items-center justify-between text-xs font-bold text-gray-400",children:[e.jsxs("span",{children:["找到 ",R," 条规则"]}),n&&e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Te,{className:"h-3.5 w-3.5 animate-spin"}),"正在更新"]})]})]}),n&&Ie.length===0?e.jsxs("div",{className:"flex min-h-56 items-center justify-center rounded-xl border border-gray-100 bg-white text-sm font-bold text-gray-400",children:[e.jsx(Te,{className:"mr-2 h-4 w-4 animate-spin"}),"正在加载规则"]}):Ie.length===0?e.jsxs("div",{className:"bg-white rounded-xl border border-dashed border-gray-200 p-16 text-center",children:[e.jsx(He,{className:"w-12 h-12 text-gray-300 mx-auto mb-4"}),e.jsx("h3",{className:"text-xl font-black text-gray-900",children:De?"没有匹配的自动化规则":"还没有自动化规则"}),e.jsx("p",{className:"text-gray-500 mt-2",children:De?"调整或清除筛选条件后再试。":"从左侧选择一个模板开始配置。"})]}):Ie.map(s=>{const c=ae[s.trigger_type],x=c.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 ${nt(c.accent,!0)}`,children:e.jsx(x,{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:s.name}),e.jsx("span",{className:`px-2.5 py-1 rounded-full text-xs font-bold ${ts(s.enabled)}`,children:s.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:c.label}),e.jsx("span",{className:"px-2.5 py-1 rounded-lg bg-gray-100 text-gray-600",children:s.item_title||s.item_id||"账号级规则"}),e.jsx("span",{className:"px-2.5 py-1 rounded-lg bg-blue-50 text-blue-700",children:es(s)})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsxs("button",{onClick:(()=>l(s)),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(ze,{className:"w-4 h-4"}),"编辑"]}),e.jsx("button",{onClick:(()=>se(s)),className:`px-4 py-2 rounded-xl text-sm font-bold ${s.enabled?"bg-amber-50 text-amber-700 hover:bg-amber-100":"bg-emerald-50 text-emerald-700 hover:bg-emerald-100"}`,children:s.enabled?"禁用":"启用"}),e.jsx("button",{onClick:(()=>B(s.id)),className:"p-2.5 rounded-xl text-red-500 hover:bg-red-50",title:"删除",children:e.jsx(Ce,{className:"w-4 h-4"})})]})]})},s.id)}),R>0&&e.jsxs("div",{className:"flex flex-col gap-3 rounded-xl border border-gray-100 bg-white px-4 py-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3 text-sm font-medium text-gray-500",children:[e.jsxs("span",{children:["第 ",D," / ",Math.max(z,1)," 页"]}),e.jsx("span",{className:"h-4 w-px bg-gray-200"}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"sr-only",children:"每页显示数量"}),e.jsx("select",{value:X,onChange:(s=>{q(Number(s.target.value)),v(1)}),className:"ios-input rounded-lg border-none bg-gray-50 px-2.5 py-2 text-sm",children:[10,20,50].map(s=>e.jsxs("option",{value:s,children:[s," 条/页"]},s))})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{type:"button",disabled:D<=1||n,onClick:(()=>v(s=>Math.max(1,s-1))),className:"flex h-9 w-9 items-center justify-center rounded-lg bg-gray-50 text-gray-600 transition-colors hover:bg-gray-100 disabled:cursor-not-allowed disabled:opacity-40","aria-label":"上一页",title:"上一页",children:e.jsx(St,{className:"h-4 w-4"})}),yt.map(s=>e.jsx("button",{type:"button",disabled:n,onClick:(()=>v(s)),className:`h-9 min-w-9 rounded-lg px-2 text-sm font-bold transition-colors ${s===D?"bg-brand text-white":"bg-gray-50 text-gray-600 hover:bg-gray-100"} disabled:cursor-not-allowed disabled:opacity-60`,"aria-label":`第 ${s} 页`,"aria-current":s===D?"page":void 0,children:s},s)),e.jsx("button",{type:"button",disabled:D>=z||n,onClick:(()=>v(s=>Math.min(z,s+1))),className:"flex h-9 w-9 items-center justify-center rounded-lg bg-gray-50 text-gray-600 transition-colors hover:bg-gray-100 disabled:cursor-not-allowed disabled:opacity-40","aria-label":"下一页",title:"下一页",children:e.jsx(Rt,{className:"h-4 w-4"})})]})]})]})]}),i==="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(Je,{className:"w-4 h-4"}),"这里只处理买家用户消息;系统通知不会进入关键词或 AI 回复。"]}),e.jsxs("div",{className:"space-y-3",children:[le.map(s=>e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between p-5 rounded-2xl border border-gray-100 bg-surface-subtle hover:bg-white hover:shadow-lg transition-all gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("span",{className:"px-3 py-1 bg-black text-white rounded-lg text-xs font-bold",children:"包含匹配"}),e.jsxs("h3",{className:"font-bold text-gray-900",children:["“",s.keyword,"”"]})]}),e.jsx("div",{className:"bg-white p-3 rounded-xl border border-gray-100 text-sm text-gray-600 leading-relaxed",children:s.type==="image"&&s.image_url?s.image_url:s.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:(()=>{te({...s}),pe(!0)}),className:"p-2 text-gray-400 hover:text-black hover:bg-gray-100 rounded-xl transition-colors",title:"编辑",children:e.jsx(ze,{className:"w-4 h-4"})}),e.jsx("button",{onClick:(()=>pt(s.id)),className:"p-2 text-gray-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors",title:"删除",children:e.jsx(Ce,{className:"w-5 h-5"})})]})]},s.id)),le.length===0&&e.jsx("div",{className:"text-center py-20 text-gray-400",children:"暂无关键词回复规则"})]})]}),i==="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(Je,{className:"w-4 h-4"}),"默认回复只处理买家用户消息;关键词未命中且 AI 未接管时才会使用。"]}),e.jsxs("div",{className:"space-y-3",children:[Ze.map(s=>{const c=Y[s.id],x=!!(c!=null&&c.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 ${x?"border-purple-100 bg-purple-50/50 hover:bg-white hover:shadow-lg":"border-gray-100 bg-surface-subtle hover:bg-white hover:shadow-lg"}`,children:[e.jsxs("div",{className:"flex items-center gap-4 min-w-0",children:[e.jsx("div",{className:`w-12 h-12 rounded-2xl flex items-center justify-center ${x?"bg-purple-600 text-white":"bg-gray-200 text-gray-400"}`,children:e.jsx(et,{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:Re(s)}),e.jsx("span",{className:`px-2 py-0.5 rounded-lg text-xs font-bold ${x?"bg-green-100 text-green-700":"bg-gray-200 text-gray-500"}`,children:x?"已启用":"未启用"}),(c==null?void 0:c.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:x?c.reply_content||c.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 We(s.id)),className:"p-2 text-gray-400 hover:text-black hover:bg-gray-100 rounded-xl transition-colors",title:"编辑",children:e.jsx(ze,{className:"w-4 h-4"})}),x&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:(()=>void ht(s.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 bt(s.id)),className:"p-2 text-gray-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors",title:"删除",children:e.jsx(Ce,{className:"w-5 h-5"})})]})]})]},s.id)}),Ze.length===0&&e.jsx("div",{className:"text-center py-20 text-gray-400",children:"暂无账号"})]})]}),$e&&g&&Fe.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:g.id?"编辑自动化规则":"新建自动化规则"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:Ne.description})]}),e.jsx("button",{onClick:(()=>je(!1)),className:"w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center",title:"关闭",children:e.jsx(ke,{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:Se.map(s=>{const c=ae[s],x=c.icon,de=me===s;return e.jsx("button",{type:"button",onClick:(()=>b(s)),className:`w-full rounded-2xl p-4 text-left border transition-all ${de?"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(x,{className:`w-5 h-5 mt-0.5 ${de?"text-brand":"text-white"}`}),e.jsxs("div",{children:[e.jsx("div",{className:"font-black",children:c.label}),e.jsx("div",{className:`text-xs mt-1 leading-5 ${de?"text-gray-500":"text-gray-400"}`,children:c.description})]})]})},s)})}),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:Ne.flow.map((s,c)=>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:c+1}),e.jsx("span",{className:"text-sm font-bold text-gray-100",children:s})]},s))})]})]}),e.jsx("div",{className:"p-6 overflow-y-auto bg-surface-subtle",children:e.jsxs("div",{className:"space-y-5",children:[e.jsxs("section",{className:"bg-white rounded-3xl border border-gray-100 p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(At,{className:"w-5 h-5 text-brand"}),e.jsx("h4",{className:"font-black text-gray-900",children:"生效范围"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"md:col-span-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"规则名称"}),e.jsx("input",{type:"text",value:g.name||"",onChange:(s=>O({...g,name:s.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:g.cookie_id||"",onChange:(s=>O({...g,cookie_id:s.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:"选择账号"}),V.map(s=>e.jsx("option",{value:s.id,children:Re(s)},s.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"关联商品"}),e.jsxs("select",{value:g.item_id||"",onChange:(s=>p(s.target.value)),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"账号级规则(不限定商品)"}),ft.map(s=>e.jsx("option",{value:s.item_id,children:s.item_title||s.item_id},`${s.cookie_id}-${s.item_id}`))]})]})]}),ge&&me!=="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:ge.item_title||ge.item_id}),e.jsx("span",{className:`px-3 py-1.5 rounded-lg text-xs font-bold ${oe?"bg-blue-50 text-blue-700":"bg-gray-100 text-gray-500"}`,children:oe?"多规格商品":"普通商品"}),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:"多规格状态来自闲鱼商品本身,发布后不能在这里修改;系统会在买家付款后读取订单详情,按实际购买规格和数量匹配下面的发货规则。"})]})]}),me!=="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($t,{className:"w-5 h-5 text-brand"}),e.jsx("h4",{className:"font-black text-gray-900",children:me==="buyer_reviewed"?"赠品库存":"发货库存"})]}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:oe?"每条发货内容绑定一个订单规格;同一规格可添加多条内容并全部发送。":"可添加多条发货内容,买家付款后会按顺序全部发送。"})]}),e.jsxs("button",{type:"button",onClick:N,className:"px-3 py-2 rounded-xl bg-gray-900 text-white text-xs font-bold hover:bg-black flex items-center gap-1.5",children:[e.jsx(Ye,{className:"w-3.5 h-3.5"}),"添加发货内容"]})]}),e.jsx("div",{className:"space-y-3",children:xe.map((s,c)=>e.jsxs("div",{className:`grid grid-cols-1 gap-3 items-end rounded-2xl border border-gray-200 p-4 ${oe?"md:grid-cols-[1fr_1fr_1.4fr_110px_40px]":"md:grid-cols-[1.4fr_110px_40px]"}`,children:[oe&&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:s.spec_name,onChange:(x=>h(c,{spec_name:x.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:s.spec_value,onChange:(x=>h(c,{spec_value:x.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:s.card_id||"",onChange:(x=>h(c,{card_id:Number(x.target.value)})),className:"w-full ios-input px-3 py-2.5 rounded-lg",children:[e.jsx("option",{value:"",children:"请选择卡密库存"}),H.filter(x=>x.enabled&&x.type!=="api").map(x=>e.jsx("option",{value:x.id,children:x.name},x.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:s.delivery_count,onChange:(x=>h(c,{delivery_count:Math.max(1,Number(x.target.value)||1)})),className:"w-full ios-input px-3 py-2.5 rounded-lg"})]}),e.jsxs("div",{className:"md:col-span-full flex flex-wrap items-center gap-3 rounded-xl bg-gray-50 px-3 py-2",children:[e.jsxs("label",{className:"flex items-center gap-2 text-xs font-bold text-gray-600 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:s.delay_override===!0,onChange:(x=>h(c,{delay_override:x.target.checked})),className:"accent-brand"}),"覆盖卡密默认延时"]}),s.delay_override&&e.jsx("input",{type:"number",min:"0",max:"3600",value:s.delay_seconds||0,onChange:(x=>h(c,{delay_seconds:Math.max(0,Number(x.target.value)||0)})),className:"w-28 ios-input px-2 py-1.5 rounded-lg text-xs","aria-label":"动作延时秒数"}),e.jsx("span",{className:"text-xs text-gray-500",children:s.delay_override?`本动作延时 ${s.delay_seconds||0} 秒`:"使用卡密默认延时"})]}),e.jsx("button",{type:"button",disabled:xe.length===1,onClick:(()=>O({...g,variants:xe.filter((x,de)=>de!==c)})),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(Ce,{className:"w-4 h-4"})})]},s.id||c))})]}):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(it,{className:"w-5 h-5 text-amber-600"}),e.jsx("h4",{className:"font-black text-gray-900",children:"求评价计划"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"发货后等待小时"}),e.jsx("input",{type:"number",min:"1",value:Number(be.after_shipped_hours||72),onChange:(s=>O({...g,config_json:ce(g.config_json,{after_shipped_hours:Math.max(1,Number(s.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(be.repeat_interval_hours||24),onChange:(s=>O({...g,config_json:ce(g.config_json,{repeat_interval_hours:Math.max(1,Number(s.target.value)||24)})})),className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"最多求评次数"}),e.jsx("input",{type:"number",min:"1",value:Number(be.max_attempts||1),onChange:(s=>O({...g,config_json:ce(g.config_json,{max_attempts:Math.max(1,Number(s.target.value)||1)})})),className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{className:"md:col-span-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"求评价文案"}),e.jsx("textarea",{value:((Qe=(Xe=g.actions)==null?void 0:Xe.find(s=>s.action_type==="send_text"))==null?void 0:Qe.message_template)||"",onChange:(s=>{var c;return O({...g,actions:((c=g.actions)!=null&&c.length?g.actions:_e("review_missing_timeout")).map(x=>x.action_type==="send_text"?{...x,message_template:s.target.value}:x)})}),className:"w-full ios-input px-4 py-3 rounded-xl h-28 resize-none"})]})]})]}),e.jsx("section",{className:"bg-white rounded-3xl border border-gray-100 p-5",children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-[180px_1fr] gap-4 items-end",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"优先级"}),e.jsx("p",{className:"text-xs text-gray-500 mb-2",children:"数字越小优先级越高;同一账号、商品和触发条件只执行优先级最高的一条规则。"}),e.jsx("input",{type:"number",value:g.priority||100,onChange:(s=>O({...g,priority:Number(s.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:g.enabled!==!1,onChange:(s=>O({...g,enabled:s.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:(()=>je(!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:f,className:"flex-1 ios-btn-primary px-6 py-3 rounded-2xl font-bold flex items-center justify-center gap-2",children:[e.jsx(tt,{className:"w-4 h-4"}),"保存自动化规则"]})]})]})}),document.body),Me&&S&&Fe.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:S.id?"编辑回复规则":"新增回复规则"}),e.jsx("button",{onClick:(()=>pe(!1)),className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",children:e.jsx(ke,{className:"w-5 h-5 text-gray-600"})})]})}),e.jsxs("div",{className:"modal-body space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"关联商品"}),e.jsxs("select",{value:S.item_id||"",onChange:(s=>te({...S,item_id:s.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"账号级回复"}),U.filter(s=>!r||s.cookie_id===r).map(s=>e.jsx("option",{value:s.item_id,children:s.item_title||s.item_id},`${s.cookie_id}-${s.item_id}`))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"回复类型"}),e.jsxs("select",{value:S.type||"text",onChange:(s=>{const c=s.target.value;te({...S,type:c,reply_content:c==="text"?S.reply_content:"",image_url:c==="image"?S.image_url:""})}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"text",children:"文字"}),e.jsx("option",{value:"image",children:"图片"})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"关键词"}),e.jsx("input",{type:"text",value:S.keyword||"",onChange:(s=>te({...S,keyword:s.target.value})),placeholder:"买家发送的关键词",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),S.type==="image"?e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"图片 URL"}),e.jsx("input",{value:S.image_url||"",onChange:(s=>te({...S,image_url:s.target.value})),placeholder:"https://...",className:"w-full ios-input px-4 py-3 rounded-xl"})]}):e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"回复内容"}),e.jsx("textarea",{value:S.reply_content||"",onChange:(s=>te({...S,reply_content:s.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:(()=>pe(!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:ut,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Mt,{className:"w-4 h-4"}),"保存规则"]})]})]})]})}),document.body),Pe&&Fe.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:(()=>ve(!1)),className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",title:"关闭",children:e.jsx(ke,{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:L.cookie_id,onChange:(s=>ie({...L,cookie_id:s.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"选择账号"}),V.map(s=>e.jsx("option",{value:s.id,children:Re(s)},s.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:(()=>ie({...L,enabled:!L.enabled})),className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${L.enabled?"bg-brand":"bg-gray-300"}`,children:e.jsx("span",{className:`absolute top-1 w-6 h-6 bg-white rounded-full shadow-md transition-transform duration-300 block ${L.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:L.reply_content,onChange:(s=>ie({...L,reply_content:s.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:L.reply_image_url,onChange:(s=>ie({...L,reply_image_url:s.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:L.reply_once,onChange:(s=>ie({...L,reply_once:s.target.checked})),className:"w-4 h-4 rounded"})]}),e.jsxs("div",{className:"flex gap-3 pt-4",children:[e.jsx("button",{onClick:(()=>ve(!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:gt,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(tt,{className:"w-4 h-4"}),"保存默认回复"]})]})]})]})}),document.body)]})};export{is as default};