Files
Ydisks-Xianyu-Helper/internal/webui/static/assets/Rules-BbKcn9Ka.js
T

2 lines
50 KiB
JavaScript

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