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