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