PageSourceSearch

https://xynergy.ai/_next/static/chunks/6163.f86f9d71053ef52b.js

js xynergy.ai collected 2026-10-05 16:02:22 UTC 45,342 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6163],{3953:(e,t,n)=>{n.d(t,{AM:()=>l,Wv:()=>d,dT:()=>o,hl:()=>c});var a=n(85047),s=n(31615),i=n(79068),r=n(34961);let l=i.bL,d=i.l9,o=i.Mz,c=s.forwardRef(({className:e,align:t="center",sideOffset:n=4,...s},l)=>(0,a.jsx)(i.ZL,{children:(0,a.jsx)(i.UC,{ref:l,align:t,sideOffset:n,className:(0,r.cn)("z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...s})}));c.displayName=i.UC.displayName},16163:(e,t,n)=>{n.r(t),n.d(t,{EditInsuranceProductDialog:()=>M,default:()=>U});var a=n(85047),s=n(31615),i=n(18534),r=n(6386),l=n(46048);function d(){return{coverage:{value:{sections:[]},isLoading:!1,isSaving:!1,isSummarizing:!1},terms:{value:{blocks:[]},isLoading:!1,isSaving:!1,isSummarizing:!1},benefit:{items:[],isLoading:!1,isSaving:!1},rate:{doc:null,isLoading:!1,isExtracting:!1},underwriting:{doc:null,form:{underwritingRules:"",minInsuredAmountWan:"",maxInsuredAmountWan:""},sourceFiles:[],selectedFileId:"",isExtracting:!1,isSaving:!1}}}function o(e,t){if("initFromProduct"===t.type){let n=t.product,a=(0,l.aL)(n.coverageSummary),s=(0,l.Zu)(n.termsSummary),i=Array.isArray(n.benefitItems)?n.benefitItems:[],r=t.sourceFiles,d=function(e,t){if(e&&t.some(t=>t.id&&t.id===e||t.storagePath===e))return e;let n=t[0];return n?.id??n?.storagePath??""}(e.underwriting.selectedFileId,r);return{...e,coverage:{...e.coverage,value:a},terms:{...e.terms,value:s},benefit:{...e.benefit,items:i},rate:{...e.rate,doc:{...n,id:n.id}},underwriting:{...e.underwriting,doc:{...n,id:n.id},form:{underwritingRules:"string"==typeof n.underwritingRules?n.underwritingRules:"",minInsuredAmountWan:"number"==typeof n.minInsuredAmountWan?n.minInsuredAmountWan:"",maxInsuredAmountWan:"number"==typeof n.maxInsuredAmountWan?n.maxInsuredAmountWan:""},sourceFiles:r,selectedFileId:d}}}if("setCoverageValue"===t.type)return{...e,coverage:{...e.coverage,value:t.value}};if("setTermsValue"===t.type)return{...e,terms:{...e.terms,value:t.value}};if("setBenefitItems"===t.type)return{...e,benefit:{...e.benefit,items:t.items}};if("setRateDoc"===t.type)return{...e,rate:{...e.rate,doc:t.doc}};if("setUnderwritingForm"===t.type)return{...e,underwriting:{...e.underwriting,form:t.form}};if("setUnderwritingSelectedFileId"===t.type)return{...e,underwriting:{...e.underwriting,selectedFileId:t.id}};if("setFlags"===t.type){let[n,a]=t.path.split(".");if("coverage"===n)return{...e,coverage:{...e.coverage,[a]:t.value}};if("terms"===n)return{...e,terms:{...e.terms,[a]:t.value}};if("benefit"===n)return{...e,benefit:{...e.benefit,[a]:t.value}};if("rate"===n)return{...e,rate:{...e.rate,[a]:t.value}};if("underwriting"===n)return{...e,underwriting:{...e.underwriting,[a]:t.value}}}return e}var c=n(28022),u=n(97769),m=n(21410),x=n(866),h=n(96968),p=n(21582),g=n(62557),v=n(11787),f=n(54306),j=n(3198),y=n(65952);function b(e){let t=e.medicalGapRules;return t&&"object"==typeof t&&!Array.isArray(t)?{...t}:{}}function w(e,t){e(e=>{let n=t(b(e));return{...e,medicalGapRules:Object.keys(n).length>0?n:void 0}})}let N=s.memo(function({formData:e,setFormData:t}){let n=b(e),s=n.dailyFromActualExpense??{mode:"none"},i=String(s.mode??"none"),r=!!n.hospitalMedicalAndSurgerySharedLimit,l=n.surgerySplit??{},d="number"==typeof l.outpatientShareOfSurgeryTarget&&Number.isFinite(l.outpatientShareOfSurgeryTarget)?Math.round(100*l.outpatientShareOfSurgeryTarget):"";return(0,a.jsxs)("div",{className:"rounded-lg border border-dashed p-4 space-y-4 bg-muted/20",children:[(0,a.jsx)("p",{className:"text-sm font-medium",children:"缺口聚合規則(醫療)"}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground leading-relaxed",children:"供儀表板/雷達/保額缺口:實支保額可併計住院日額、住院醫療與手術共用限額、手術目標拆估等。未綁商品之保單不套用。"}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(h.J,{children:"實支併入住院日額"}),(0,a.jsxs)(p.l6,{value:i,onValueChange:e=>{w(t,()=>{let t={mode:e};return"percentOfCoverage"===e&&(t={mode:"percentOfCoverage",percent:10}),"fixedWanPerDay"===e&&(t={mode:"fixedWanPerDay",wanPerDay:.3}),"fromBenefitTag"===e&&(t={mode:"fromBenefitTag",tag:"日額"}),{...n,dailyFromActualExpense:t}})},children:[(0,a.jsx)(p.bq,{children:(0,a.jsx)(p.yv,{})}),(0,a.jsxs)(p.gC,{children:[(0,a.jsx)(p.eb,{value:"none",children:"不併計"}),(0,a.jsx)(p.eb,{value:"percentOfCoverage",children:"依實支保額(元)比例"}),(0,a.jsx)(p.eb,{value:"fixedWanPerDay",children:"固定日額(萬/日→換算元)"}),(0,a.jsx)(p.eb,{value:"fromBenefitTag",children:"依理賠項目關鍵字加總"})]})]}),"percentOfCoverage"===i?(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(h.J,{className:"shrink-0 text-xs",children:"比例(0–100)"}),(0,a.jsx)(x.p,{type:"number",min:0,max:100,className:"w-28",value:"number"==typeof s.percent?s.percent:"",onChange:e=>{let a=Number(e.target.value);w(t,()=>({...n,dailyFromActualExpense:{mode:"percentOfCoverage",percent:Number.isFinite(a)?Math.min(100,Math.max(0,a)):0}}))}}),(0,a.jsx)("span",{className:"text-xs text-muted-foreground",children:"%"})]}):null,"fixedWanPerDay"===i?(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(h.J,{className:"shrink-0 text-xs",children:"萬/日"}),(0,a.jsx)(x.p,{type:"number",min:0,step:.1,className:"w-28",value:"number"==typeof s.wanPerDay?s.wanPerDay:"",onCh
1ange:e=>{let a=Number(e.target.value);w(t,()=>({...n,dailyFromActualExpense:{mode:"fixedWanPerDay",wanPerDay:Number.isFinite(a)&&a>=0?a:0}}))}})]}):null,"fromBenefitTag"===i?(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(h.J,{className:"shrink-0 text-xs",children:"關鍵字"}),(0,a.jsx)(x.p,{className:"max-w-xs",value:"string"==typeof s.tag?s.tag:"",onChange:e=>w(t,()=>({...n,dailyFromActualExpense:{mode:"fromBenefitTag",tag:e.target.value||"日額"}}))})]}):null]}),(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(g.S,{id:"sharedMedSurg",checked:r,onCheckedChange:e=>w(t,()=>({...n,hospitalMedicalAndSurgerySharedLimit:!0===e}))}),(0,a.jsx)(h.J,{htmlFor:"sharedMedSurg",className:"text-sm font-normal cursor-pointer",children:"住院醫療費用保險金與手術共用同一限額(缺口池)"})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(h.J,{className:"text-xs",children:"手術建議目標拆估:門診手術占比(0–100,選填)"}),(0,a.jsx)(x.p,{type:"number",min:0,max:100,className:"w-32",placeholder:"空白=不顯示拆估",value:""===d?"":d,onChange:e=>{let a=e.target.value.trim();if(""===a)return void w(t,e=>{let{surgerySplit:t,...n}=e;return n});let s=Number(a);if(!Number.isFinite(s))return;let i=Math.min(100,Math.max(0,s))/100;w(t,()=>({...n,surgerySplit:{outpatientShareOfSurgeryTarget:i}}))}})]})]})});var C=n(10250),A=n(72723),S=n(34071),F=n(38187),k=n(3953);function P({productId:e,field:t,verification:n,provenance:i,getToken:r,toast:l,onVerifiedChange:d,compact:o=!1}){var u;
1let[x,h]=(0,s.useState)(!1),p=!!n,g=!!(i&&(null!=i.confidence||i.sourceSnippet||i.sourcePage)),f=async()=>{if(!e)return void l({title:"請先儲存商品",description:"新建商品需先儲存後才能標記審核",variant:"destructive"});h(!0);try{let n=await r();await (0,c.KF)({id:e,token:n,field:t,verified:!p});let a=p?void 0:{verifiedBy:"you",verifiedAt:new Date};d?.(a),l({title:p?"已取消核對":"已標記為已核對"})}catch(e){l({title:"操作失敗",description:(0,c.Jo)(e,"請稍後再試"),variant:"destructive"})}finally{h(!1)}};return(0,a.jsxs)("span",{className:"inline-flex items-center gap-1.5 align-middle",children:[(0,a.jsxs)(m.$,{type:"button",variant:"ghost",size:"sm",className:`h-6 px-1.5 ${p?"text-emerald-600 hover:text-emerald-700":"text-muted-foreground hover:text-foreground"}`,onClick:f,disabled:x,title:p?`已由 ${n?.verifiedBy??""} 於 ${function(e){if(!e?.verifiedAt)return"";try{return(e.verifiedAt instanceof Date?e.verifiedAt:new Date(e.verifiedAt)).toLocaleString()}catch{return String(e.verifiedAt)}}(n)} 核對`:"標記為已核對",children:[x?(0,a.jsx)(v.A,{className:"h-3.5 w-3.5 animate-spin"}):p?(0,a.jsx)(C.A,{className:"h-3.5 w-3.5"}):(0,a.jsx)(A.A,{className:"h-3.5 w-3.5"}),!o&&(0,a.jsx)("span",{className:"ml-1 text-xs",children:p?"已核對":"未核對"})]}),g&&(0,a.jsxs)(k.AM,{children:[(0,a.jsx)(k.Wv,{asChild:!0,children:(0,a.jsxs)("button",{type:"button",className:"inline-flex h-5 items-center gap-1 rounded-full bg-muted px-1.5 text-[10px] text-muted-foreground hover:bg-muted/80",title:"抽取來源(AI)",children:[(0,a.jsx)("span",{className:`inline-block h-2 w-2 rounded-full ${"number"!=typeof(u=i?.confidence)?"bg-muted-foreground/30":u>=.85?"bg-emerald-500":u>=.6?"bg-amber-500":"bg-rose-500"}`}),i?.confidence!=null&&(0,a.jsxs)("span",{children:[Math.round(100*i.confidence),"%"]}),(0,a.jsx)(S.A,{className:"h-3 w-3"})]})}),(0,a.jsx)(k.hl,{className:"w-80 text-xs",align:"start",children:(0,a.jsxs)("div",{className:"space-y-1.5",children:[(0,a.jsx)("div",{className:"font-medium",children:"AI 抽取來源"}),i?.confidence!=null&&(0,a.jsxs)("div",{children:["把握度:",(0,a.jsxs)(F.E,{variant:"outline",children:[Math.round(100*i.confidence),"%"]})]}),i?.sourcePage&&(0,a.jsxs)("div",{children:["來源頁碼:第 ",i.sourcePage," 頁"]}),i?.model&&(0,a.jsxs)("div",{className:"text-muted-foreground",children:["模型:",i.model]}),i?.sourceSnippet&&(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"text-muted-foreground",children:"原文片段:"}),(0,a.jsx)("div",{className:"mt-0.5 max-h-32 overflow-auto whitespace-pre-wrap rounded border bg-muted/40 p-2 text-foreground",children:i.sourceSnippet})]})]})})]})]})}let I=["twd","usd","jpy","eur"],R=s.memo(function(e){let t,n,{formOpen:d,setFormOpen:o,formData:c,setFormData:u,editingProduct:b,editingProductSourceFiles:w,editingProductSourceFilesLoading:C,isSubmitting:A,submitForm:S,onProductNameChange:F,onPremiumCurrencyChange:k,getToken:R,toast:W}=e,[T,O]=(0,s.useState)({}),$=b?.extractionProvenance??{},E=b?.fieldVerifications??{},D=e=>({productId:b?.id,field:e,verification:void 0!==T[e]?T[e]:E[e],provenance:$[e],getToken:R??(async()=>""),toast:W??(()=>{}),onVerifiedChange:t=>O(n=>({...n,[e]:t}))}),J=!!(b?.id&&R&&W),z=I.includes(c.premiumCurrency)?String(c.premiumCurrency):"twd";return(0,a.jsxs)(r.av,{value:"basic",className:"flex-1 overflow-y-auto mt-4 min-h-0",children:[(0,a.jsxs)("div",{className:"grid gap-4 py-4",children:[(0,a.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)(h.J,{children:"保險公司"}),(0,a.jsxs)(p.l6,{value:String(c.insurerCode||""),onValueChange:e=>u(t=>({...t,insurerCode:e})),children:[(0,a.jsx)(p.bq,{children:(0,a.jsx)(p.yv,{placeholder:"請選擇"})}),(0,a.jsx)(p.gC,{children:y._4.map(e=>(0,a.jsx)(p.eb,{value:e.value,children:e.label},e.value))})]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(h.J,{children:"大類"}),(0,a.jsxs)(p.l6,{value:String(c.category||"life"),onValueChange:e=>{let t=(0,j.Wr)(e),n=c.productType,a="string"==typeof n&&t.some(e=>e.value===n);u(t=>({...t,category:e,productType:a?t.productType:""}))},children:[(0,a.jsx)(p.bq,{children:(0,a.jsx)(p.yv,{})}),(0,a.jsxs)(p.gC,{children:[(0,a.jsx)(p.eb,{value:"life",children:"壽險"}),(0,a.jsx)(p.eb,{value:"property",children:"產險"}),(0,a.jsx)(p.eb,{value:"medical",children:"醫療"})]})]})]})]}),(0,a.jsxs)("div",{children:[(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsx)(h.J,{children:"商品名稱 *"}),J&&(0,a.jsx)(P,{...D("productName")}
1)]}),(0,a.jsx)(x.p,{value:String(c.productName||""),onChange:e=>F(e.target.value),placeholder:"請輸入商品名稱"}),(0,a.jsx)("p",{className:"text-muted-foreground text-xs mt-1",children:"預設為新台幣;若名稱含美元/日圓/歐元等關鍵字,且尚未手動鎖定幣別,將自動帶入對應幣別。"})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(h.J,{children:"險種 *"}),(0,a.jsxs)(p.l6,{value:String(c.productType||""),onValueChange:e=>u(t=>({...t,productType:e})),children:[(0,a.jsx)(p.bq,{children:(0,a.jsx)(p.yv,{placeholder:"請選擇險種"})}),(0,a.jsx)(p.gC,{children:(0,j.Wr)(c.category||"life").map(e=>(0,a.jsx)(p.eb,{value:e.value,children:e.label},e.value))})]})]}),(0,a.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)(h.J,{children:"幣別"}),(0,a.jsxs)(p.l6,{value:z,onValueChange:k,children:[(0,a.jsx)(p.bq,{children:(0,a.jsx)(p.yv,{placeholder:"新台幣 (TWD)"})}),(0,a.jsxs)(p.gC,{children:[(0,a.jsx)(p.eb,{value:"twd",children:"新台幣 (TWD)"}),(0,a.jsx)(p.eb,{value:"usd",children:"美元 (USD)"}),(0,a.jsx)(p.eb,{value:"jpy",children:"日圓 (JPY)"}),(0,a.jsx)(p.eb,{value:"eur",children:"歐元 (EUR)"})]})]}),(0,a.jsx)("p",{className:"text-muted-foreground text-xs mt-1",children:"變更此欄後將鎖定自動推斷,直至下次重新開啟編輯。"})]}),(0,a.jsxs)("div",{children:[(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsx)(h.J,{children:"商品代碼"}),J&&(0,a.jsx)(P,{...D("productCode"),compact:!0})]}),(0,a.jsx)(x.p,{value:String(c.productCode||""),onChange:e=>u(t=>({...t,productCode:e.target.value})),placeholder:"選填,可由 AI 帶入"})]})]}),(0,a.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)(h.J,{children:"最低投保金額(萬)"}),(0,a.jsx)(x.p,{type:"number",min:0,step:.01,value:null!=c.minInsuredAmountWan&&""!==c.minInsuredAmountWan?String(c.minInsuredAmountWan):"",onChange:e=>u(t=>({...t,minInsuredAmountWan:""===e.target.value?void 0:Number(e.target.value)})),placeholder:"選填,可輸入至小數第二位"})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(h.J,{children:"最高投保金額(萬)"}),(0,a.jsx)(x.p,{type:"number",min:0,step:.01,value:null!=c.maxInsuredAmountWan&&""!==c.maxInsuredAmountWan?String(c.maxInsuredAmountWan):"",onChange:e=>u(t=>({...t,maxInsuredAmountWan:""===e.target.value?void 0:Number(e.target.value)})),placeholder:"選填,可輸入至小數第二位"})]})]}),(0,a.jsx)("div",{className:"grid grid-cols-2 gap-4",children:(0,a.jsxs)("div",{children:[(0,a.jsx)(h.J,{children:"年期(可多選)"}),(0,a.jsx)("div",{className:"flex flex-wrap gap-4 pt-2",children:j.Ox.map(e=>{let t=Array.isArray(c.termOptions)&&c.termOptions.includes(e.value);return(0,a.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,a.jsx)(g.S,{id:`term-${e.value}`,checked:t,onCheckedChange:t=>{let n=c.termOptions??[];t?u(t=>({...t,termOptions:[...n.filter(t=>t!==e.value),e.value]})):u(t=>({...t,termOptions:n.filter(t=>t!==e.value)}))}}),(0,a.jsx)(h.J,{htmlFor:`term-${e.value}`,className:"cursor-pointer font-normal",children:e.label})]},e.value)})})]})}),(0,a.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsx)(h.J,{children:"投保年齡"}),J&&(0,a.jsx)(P,{...D("ageRange"),compact:!0})]}),(0,a.jsx)(x.p,{value:String(c.ageRange||""),onChange:e=>u(t=>({...t,ageRange:e.target.value})),placeholder:"如 0歲~65歲、15歲~70歲"})]}),(0,a.jsxs)("div",{children:[(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsx)(h.J,{children:"最高保障到幾歲"}),J&&(0,a.jsx)(P,{...D("coveragePeriod"),compact:!0})]}),(0,a.jsx)(x.p,{value:String(c.coveragePeriod||""),onChange:e=>u(t=>({...t,coveragePeriod:e.target.value})),placeholder:"如 99 歲、終身"})]})]}),"medical"===String(c.category)?(0,a.jsx)(N,{formData:c,setFormData:u}):null,"edit"===d&&b?.id?(0,a.jsxs)("div",{children:[(0,a.jsx)(h.J,{children:"本商品已連結的檔案"}),C?(0,a.jsx)("div",{className:"mt-2",children:(0,a.jsx)(f.default,{size:32})}):0===w.length?(0,a.jsx)("p",{className:"text-muted-foreground text-sm mt-2",children:"尚無已連結檔案"}):(0,a.jsx)("ul",{className:"mt-2 list-none space-y-3 p-0 text-sm",children:(t=["terms","rate"],[...(n=[...new Set(w.map(e=>e.type))]).filter(e=>t.includes(e)).sort((e,n)=>t.indexOf(e)-t.indexOf(n)),...n.filter(e=>!t.includes(e))].map(e=>{let t=w.filter(t=>t.type===e);return 0===t.length?null:(0,a.jsxs)("li",{children:[(0,a.jsx)("div",{className:"text-muted-foreground mb-1",children:(0,l.wz)(e)}),(0,a.jsx)("ul",{className:"m-0 list-disc space-y-1 pl-5",children:t.map(e=>(0,a.jsx)("li",{className:"break-all",children:e.fileName},e.id??e.storagePath))})]},e)}))})]}):null]}),(0,a.jsxs)(i.Es,{children:[(0,a.jsx)(m.$,{variant:"outline",onClick:()=>o(null),children:"取消"}),(0,a.jsxs)(m.$,{onClick:S,disabled:A,children:[A?(0,a.jsx)(v.A,{className:"h-4 w-4 animate-spin mr-2"}):null,"儲存"]}
1)]})]})});var W=n(10892),T=n(54296);let O=s.memo(function(e){let{value:t,isLoading:n,isSaving:s,isSummarizing:l,onChange:d,onClose:o,onSummarize:c,onSave:u}=e;return(0,a.jsxs)(r.av,{value:"coverage",className:"flex-1 overflow-hidden flex flex-col mt-4 min-h-0",children:[n?(0,a.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,a.jsx)(v.A,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):(0,a.jsxs)("div",{className:"overflow-y-auto flex-1 space-y-4 pr-1",children:[t.sections.map((e,n)=>(0,a.jsxs)("div",{className:"rounded-lg border bg-muted/30 p-3 space-y-2",children:[(0,a.jsx)(x.p,{placeholder:"區塊標題(如:因罹癌導致)",value:e.title,onChange:a=>{let s={...t,sections:[...t.sections]};s.sections[n]={...e,title:a.target.value},d(s)},className:"font-medium"}),(0,a.jsxs)("div",{className:"space-y-1.5",children:[e.items.map((e,s)=>(0,a.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,a.jsx)(x.p,{placeholder:"條件/說明",value:e.description??"",onChange:a=>{let i={...t,sections:[...t.sections]},r={...i.sections[n],items:[...i.sections[n].items]};r.items[s]={...e,description:a.target.value||void 0},i.sections[n]=r,d(i)},className:"flex-1 min-w-[120px]"}),(0,a.jsx)(x.p,{placeholder:"金額",value:e.amount??"",onChange:a=>{let i={...t,sections:[...t.sections]},r={...i.sections[n],items:[...i.sections[n].items]};r.items[s]={...e,amount:a.target.value||void 0},i.sections[n]=r,d(i)},className:"w-28 text-right"}),(0,a.jsx)(m.$,{type:"button",variant:"ghost",size:"icon",className:"h-8 w-8 shrink-0",onClick:()=>{let e={...t,sections:[...t.sections]},a={...e.sections[n],items:e.sections[n].items.filter((e,t)=>t!==s)};e.sections[n]=a,d(e)},children:(0,a.jsx)(T.A,{className:"h-4 w-4"})})]},s)),(0,a.jsx)(m.$,{type:"button",variant:"outline",size:"sm",onClick:()=>{let e={...t,sections:[...t.sections]},a={...e.sections[n],items:[...e.sections[n].items,{}]};e.sections[n]=a,d(e)},children:"新增項目"})]}),(0,a.jsx)(W.T,{placeholder:"補充說明(選填,可多行)",value:e.supplement??"",onChange:a=>{let s={...t,sections:[...t.sections]};s.sections[n]={...e,supplement:a.target.value||void 0},d(s)}
1,className:"min-h-[60px] text-sm",rows:2}),(0,a.jsx)("div",{className:"flex justify-end",children:(0,a.jsx)(m.$,{type:"button",variant:"ghost",size:"sm",onClick:()=>d({...t,sections:t.sections.filter((e,t)=>t!==n)}),children:"移除區塊"})})]},n)),(0,a.jsx)(m.$,{type:"button",variant:"outline",onClick:()=>d({...t,sections:[...t.sections,{title:"",items:[]}]}),children:"新增區塊"})]}),(0,a.jsxs)(i.Es,{children:[(0,a.jsx)(m.$,{variant:"outline",onClick:o,children:"取消"}),(0,a.jsxs)(m.$,{type:"button",variant:"secondary",onClick:c,disabled:n||l,children:[l?(0,a.jsx)(v.A,{className:"h-4 w-4 animate-spin mr-2"}):null,"依條款擷取"]}),(0,a.jsxs)(m.$,{onClick:u,disabled:n||s,children:[s?(0,a.jsx)(v.A,{className:"h-4 w-4 animate-spin mr-2"}):null,"儲存"]})]})]})}),$=s.memo(function(e){let{value:t,isLoading:n,isSaving:s,isSummarizing:l,onChange:d,onClose:o,onSummarize:c,onSave:u}=e;return(0,a.jsxs)(r.av,{value:"terms",className:"flex-1 overflow-hidden flex flex-col mt-4 min-h-0",children:[n?(0,a.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,a.jsx)(v.A,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):(0,a.jsxs)("div",{className:"overflow-y-auto flex-1 space-y-4 pr-1",children:[t.blocks.map((e,n)=>(0,a.jsxs)("div",{className:"rounded-lg border bg-muted/30 p-3 space-y-2",children:[(0,a.jsx)(x.p,{placeholder:"區塊標題(選填)",value:e.title??"",onChange:a=>{let s={...t,blocks:[...t.blocks]};s.blocks[n]={...e,title:a.target.value||void 0},d(s)},className:"font-medium"}),(0,a.jsx)(W.T,{placeholder:"內容",value:e.content,onChange:a=>{let s={...t,blocks:[...t.blocks]};s.blocks[n]={...e,content:a.target.value},d(s)},className:"min-h-[80px]",rows:3}),(0,a.jsx)("div",{className:"flex justify-end",children:(0,a.jsx)(m.$,{type:"button",variant:"ghost",size:"sm",onClick:()=>d({...t,blocks:t.blocks.filter((e,t)=>t!==n)}),children:"移除區塊"})})]},n)),(0,a.jsx)(m.$,{type:"button",variant:"outline",onClick:()=>d({...t,blocks:[...t.blocks,{content:""}]}),children:"新增區塊"})]}),(0,a.jsxs)(i.Es,{children:[(0,a.jsx)(m.$,{variant:"outline",onClick:o,children:"取消"}),(0,a.jsxs)(m.$,{type:"button",variant:"secondary",onClick:c,disabled:n||l,children:[l?(0,a.jsx)(v.A,{className:"h-4 w-4 animate-spin mr-2"}):null,"依條款擷取"]}),(0,a.jsxs)(m.$,{onClick:u,disabled:n||s,children:[s?(0,a.jsx)(v.A,{className:"h-4 w-4 animate-spin mr-2"}):null,"儲存"]})]})]})});var E=n(2962),D=n(42119);let J=s.memo(function(e){let{items:t,planAmounts:n,isLoading:l,isSaving:d,onChange:o,onClose:c,onSave:u}
1=e,[h,p]=(0,s.useState)([]),[g,f]=(0,s.useState)(""),j=(0,s.useMemo)(()=>(function(e,t,n){let a=[],s=new Set;if(e)for(let t of Object.keys(e)){let e=t.trim();!e||s.has(e)||(s.add(e),a.push(e))}for(let e of n){let t=String(e).trim();!t||s.has(t)||(s.add(t),a.push(t))}let i=[];for(let e of t)if(e.amountByPlan)for(let t of Object.keys(e.amountByPlan)){let e=t.trim();e&&!s.has(e)&&(s.add(e),i.push(e))}return i.sort(),a.push(...i),a})(n,t,h),[n,t,h]),y=5+j.length;return(0,a.jsxs)(r.av,{value:"benefit",className:"flex-1 overflow-hidden flex flex-col mt-4 min-h-0",children:[l?(0,a.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,a.jsx)(v.A,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):0===t.length?(0,a.jsx)("p",{className:"text-muted-foreground text-sm py-4",children:"尚無理賠項目。請在列表使用「摘要」或於編輯表單中擷取。"}):(0,a.jsxs)("div",{className:"flex flex-col gap-3 min-h-0",children:[(0,a.jsxs)("div",{className:"flex flex-wrap items-end gap-2 text-sm",children:[(0,a.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,a.jsx)("span",{className:"text-muted-foreground",children:"新增計劃欄(代碼)"}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)(x.p,{value:g,onChange:e=>f(e.target.value),placeholder:"例如:甲、計畫一",className:"h-8 w-40"}),(0,a.jsxs)(m.$,{type:"button",variant:"secondary",size:"sm",className:"h-8 gap-1",onClick:()=>{let e=g.trim();if(e){if(j.includes(e))return void f("");p(t=>t.includes(e)?t:[...t,e]),f("")}},children:[(0,a.jsx)(D.A,{className:"h-3.5 w-3.5"}),"新增欄"]})]})]}),n&&0!==Object.keys(n).length?null:(0,a.jsx)("p",{className:"text-muted-foreground text-xs max-w-md",children:"此商品尚未設定 planAmounts 時,仍可手動新增計劃欄並填寫各項目之對照金額;建議於基本/費率資料補上 planAmounts 以利與保單計劃別一致。"})]}),(0,a.jsx)("div",{className:"rounded-md border overflow-x-auto overflow-y-auto max-h-[50vh]",children:(0,a.jsxs)(E.XI,{children:[(0,a.jsx)(E.A0,{children:(0,a.jsxs)(E.Hj,{children:[(0,a.jsx)(E.nd,{className:"min-w-[8rem]",children:"名稱"}),(0,a.jsx)(E.nd,{className:"min-w-[8rem]",children:"說明"}),(0,a.jsx)(E.nd,{className:"text-right min-w-[7rem]",children:"金額/上限"}),j.map(e=>(0,a.jsxs)(E.nd,{className:"text-right min-w-[6.5rem] text-xs whitespace-nowrap",children:["計劃 ",e]},e)),(0,a.jsx)(E.nd,{className:"min-w-[5rem]",children:"大類"}),(0,a.jsx)(E.nd,{className:"w-10"})]})}),(0,a.jsx)(E.BF,{children:t.map((e,n)=>{let i=0===n||(t[n-1]?.category??"")!==(e.category??"");return(0,a.jsxs)(s.Fragment,{children:[i?(0,a.jsx)(E.Hj,{className:"bg-muted/50 hover:bg-muted/50",children:(0,a.jsx)(E.nA,{colSpan:y,className:"font-medium text-sm py-1.5",children:e.category?.trim()||"其他"})}):null,(0,a.jsxs)(E.Hj,{children:[(0,a.jsx)(E.nA,{className:"p-1.5",children:(0,a.jsx)(x.p,{value:e.name,onChange:a=>{let s=[...t];s[n]={...e,name:a.target.value},o(s)},className:"h-8 font-medium"})}),(0,a.jsx)(E.nA,{className:"p-1.5",children:(0,a.jsx)(x.p,{value:e.description??"",onChange:a=>{let s=[...t];s[n]={...e,description:a.target.value||void 0},o(s)},className:"h-8 text-sm"})}),(0,a.jsx)(E.nA,{className:"p-1.5 text-right",children:(0,a.jsx)(x.p,{value:e.amount??"",onChange:a=>{let s=[...t];s[n]={...e,amount:a.target.value||void 0},o(s)},className:"h-8 text-right"})}),j.map(s=>(0,a.jsx)(E.nA,{className:"p-1.5 text-right",children:(0,a.jsx)(x.p,{value:e.amountByPlan?.[s]??"",onChange:e=>((e,n,a)=>{let s=[...t],i=s[e];if(!i)return;let r={...i.amountByPlan??{}};a.trim()?r[n]=a:delete r[n];let l={...i};Object.keys(r).length>0?l.amountByPlan=r:delete l.amountByPlan,s[e]=l,o(s)})(n,s,e.target.value),className:"h-8 text-right text-xs",placeholder:"—"})},s)),(0,a.jsx)(E.nA,{className:"p-1.5",children:(0,a.jsx)(x.p,{value:e.category??"",onChange:a=>{let s=[...t];s[n]={...e,category:a.target.value||void 0},o(s)},className:"h-8 text-sm"})}),(0,a.jsx)(E.nA,{className:"p-1.5",children:(0,a.jsx)(m.$,{type:"button",variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>o(t.filter((e,t)=>
1t!==n)),children:(0,a.jsx)(T.A,{className:"h-4 w-4 text-destructive"})})})]})]},n)})})]})})]}),(0,a.jsxs)(i.Es,{children:[(0,a.jsx)(m.$,{variant:"outline",onClick:c,children:"關閉"}),t.length>0?(0,a.jsxs)(m.$,{onClick:u,disabled:l||d,children:[d?(0,a.jsx)(v.A,{className:"h-4 w-4 animate-spin mr-2"}):null,"儲存"]}):null]})]})}),z=s.memo(function(e){let{doc:t,isLoading:n,isExtracting:s,onClose:l,onExtract:d}=e;return(0,a.jsxs)(r.av,{value:"rate",className:"flex-1 overflow-hidden flex flex-col mt-4 min-h-0",children:[n?(0,a.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,a.jsx)(v.A,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):(0,a.jsxs)(a.Fragment,{children:[t?.rateTable&&Array.isArray(t.rateTable)&&t.rateTable.length>0&&(!t.accidentRateTable||!Array.isArray(t.accidentRateTable)||0===t.accidentRateTable.length)?(0,a.jsx)("div",{className:"rounded-md border overflow-x-auto overflow-y-auto max-h-[45vh]",children:(0,a.jsxs)(E.XI,{children:[(0,a.jsx)(E.A0,{children:(0,a.jsxs)(E.Hj,{children:[(0,a.jsx)(E.nd,{children:"計畫/保額"}),(0,a.jsx)(E.nd,{children:"性別"}),(0,a.jsx)(E.nd,{children:"年期"}),(0,a.jsx)(E.nd,{children:"年齡"}),(0,a.jsx)(E.nd,{className:"text-right",children:"年繳保費(元)"})]})}),(0,a.jsx)(E.BF,{children:t.rateTable.map((e,t)=>(0,a.jsxs)(E.Hj,{children:[(0,a.jsx)(E.nA,{children:e.plan??"-"}),(0,a.jsx)(E.nA,{children:"male"===e.gender?"男":"female"===e.gender?"女":"-"}),(0,a.jsx)(E.nA,{children:e.term??"-"}),(0,a.jsx)(E.nA,{children:e.age}),(0,a.jsx)(E.nA,{className:"text-right",children:Number(e.premium).toLocaleString(void 0,{maximumFractionDigits:2})})]},t))})]})}):null,t?.accidentRateTable&&Array.isArray(t.accidentRateTable)&&t.accidentRateTable.length>0?(0,a.jsx)("div",{className:"rounded-md border overflow-x-auto overflow-y-auto max-h-[45vh] mt-2",children:(0,a.jsxs)(E.XI,{children:[(0,a.jsx)(E.A0,{children:(0,a.jsxs)(E.Hj,{children:[(0,a.jsx)(E.nd,{children:"職業類別"}),(0,a.jsx)(E.nd,{className:"text-right",children:"年繳保費(元)"})]})}),(0,a.jsx)(E.BF,{children:t.accidentRateTable.map((e,t)=>(0,a.jsxs)(E.Hj,{children:[(0,a.jsx)(E.nA,{children:e.occupationClass}),(0,a.jsx)(E.nA,{className:"text-right",children:Number(e.premium).toLocaleString(void 0,{maximumFractionDigits:2})})]},t))})]})}):null,!t||t.rateTable&&0!==t.rateTable.length||t.accidentRateTable&&0!==t.accidentRateTable.length?null:(0,a.jsx)("p",{className:"text-muted-foreground text-sm py-4",children:"尚無費率表。請上傳費率 PDF 後點「擷取費率表」。"}),(0,a.jsx)("div",{className:"mt-2",children:(0,a.jsxs)(m.$,{variant:"secondary",size:"sm",onClick:d,disabled:s,children:[s?(0,a.jsx)(v.A,{className:"h-4 w-4 animate-spin mr-2"}):null,"擷取費率表"]})})]}),(0,a.jsx)(i.Es,{children:(0,a.jsx)(m.$,{onClick:l,children:"關閉"})})]})}),L=s.memo(function(e){let{sourceFiles:t,selectedFileId:n,onSelectedFileIdChange:l,form:d,onFormChange:o,isExtracting:c,isSaving:u,onExtract:g,onUpload:f,isUploading:j,onSave:y,onClose:b}=e,[w,N]=(0,s.useState)([]);return(0,a.jsxs)(r.av,{value:"underwriting",className:"flex-1 overflow-hidden flex flex-col mt-4 min-h-0",children:[(0,a.jsxs)("div",{className:"space-y-4 overflow-y-auto",children:[(0,a.jsxs)("div",{className:"grid gap-2",children:[(0,a.jsx)(h.J,{children:"擷取來源"}),0===t.length?(0,a.jsx)("p",{className:"text-muted-foreground text-sm",children:"請先上傳 PDF 或圖片"}):(0,a.jsxs)("div",{className:"flex gap-2 items-center flex-wrap",children:[(0,a.jsxs)(p.l6,{value:n,onValueChange:l,children:[(0,a.jsx)(p.bq,{className:"w-[280px]",children:(0,a.jsx)(p.yv,{placeholder:"選擇檔案"})}),(0,a.jsx)(p.gC,{children:t.map(e=>{let t=e.id??e.storagePath;return(0,a.jsxs)(p.eb,{value:t,title:e.originalFileName?`原檔:${e.originalFileName}`:void 0,children:[e.fileName,"general"!==e.type?` (${e.type})`:""]},t)})})]}),(0,a.jsxs)(m.$,{variant:"secondary",size:"sm",onClick:g,disabled:c||!n,children:[c?(0,a.jsx)(v.A,{className:"h-4 w-4 animate-spin mr-2"}):null,"擷取投保規則"]})]})]}),(0,a.jsxs)("div",{className:"grid gap-2",children:[(0,a.jsx)(h.J,{children:"新增來源檔案(投保規則)"}),(0,a.jsxs)("div",{className:"flex flex-wrap items-end gap-2",children:[(0,a.jsx)(x.p,{type:"file",accept:".pdf,application/pdf,.png,image/png,.jpg,.jpeg,image/jpeg",multiple:!0,onChange:e=>N(Array.from(e.target.files||[]))}),(0,a.jsxs)(m.$,{type:"button",onClick:async()=>{N([]),await f(w)},disabled:j||0===w.length,children:[j?(0,a.jsx)(v.A,{className:"h-4 w-4 animate-spin mr-2"}):null,"上傳並加入來源"]})]}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:"上傳後請選擇檔案,再按「擷取投保規則」。"})]}),(0,a.jsxs)("div",{className:"grid gap-2",children:[(0,a.jsx)(h.J,{children:"投保規則"}),(0,a.jsx)(W.T,{value:d.underwritingRules,onChange:e=>o({...d,underwritingRules:e.target.value}),placeholder:"健康告知、職業限制、主約/附約限制等",rows:5,className:"resize-y"})]}),(0,a.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,a.jsxs)("div",{className:"grid gap-2",children:[(0,a.jsx)(h.J,{children:"最低投保金額(萬元)"}),(0,a.jsx)(x.p,{type:"number",min:0,step:1,value:""===d.minInsuredAmountWan?"":d.minInsuredAmountWan,onChange:e=>o({...d,minInsuredAmountWan:""===e.target.value?"":Number(e.target.value)}),placeholder:"選填"})]}),(0,a.jsxs)("div",{className:"grid gap-2",children:[(0,a.jsx)(h.J,{children:"最高投保金額(萬元)"}),(0,a.jsx)(x.p,{type:"number",min:0,step:1,value:""===d.maxInsuredAmountWan?"":d.maxInsuredAmountWan,onChange:e=>o({...d,maxInsuredAmountWan:""===e.target.value?"":Number(e.target.value)}),placeholder:"選填"})]})]})]}),(0,a.jsxs)(i.Es,{children:[(0,a.jsx)(m.$,{variant:"outline",onClick:b,children:"關閉"}),(0,a.jsxs)(m.$,{onClick:y,disabled:u,children:[u?(0,a.jsx)(v.A,{className:"h-4 w-4 animate-spin mr-2"}):null,"儲存"]}
1)]})]})});function B(e){let t,n=e.amountByPlan;if(n&&"object"==typeof n){let e={};for(let[t,a]of Object.entries(n)){let n=t.trim();if(!n||"string"!=typeof a)continue;let s=a.trim();s&&(e[n]=s)}Object.keys(e).length>0&&(t=e)}let a={name:e.name.trim()};return e.description?.trim()&&(a.description=e.description.trim()),e.amount?.trim()&&(a.amount=e.amount.trim()),t&&(a.amountByPlan=t),e.category?.trim()&&(a.category=e.category.trim()),a}function M(e){let{open:t,onOpenChange:n,getToken:m,toast:x,loadList:h,reloadEditingProductSourceFiles:p,formOpen:g,setFormOpen:v,formData:f,setFormData:j,editingProduct:y,setEditingProduct:b,editingProductSourceFiles:w,editingProductSourceFilesLoading:N,isSubmitting:C,submitForm:A,onProductNameChange:S,onPremiumCurrencyChange:F,onRateExtractedDoc:k}=e,[P,I]=(0,s.useReducer)(o,void 0,d),[W,T]=(0,s.useState)(!1);(0,s.useEffect)(()=>{"edit"===g&&y?.id&&I({type:"initFromProduct",product:y,sourceFiles:w})},[g,y,w]);let E=async()=>{if(y?.id){I({type:"setFlags",path:"coverage.isSaving",value:!0});try{let e=await m();await (0,c.HF)({id:y.id,token:e,payload:{coverageSummary:P.coverage.value}}),x({title:"已儲存保障摘要"})}catch(e){x({title:"儲存失敗",description:(0,c.Jo)(e,"請稍後再試"),variant:"destructive"})}finally{I({type:"setFlags",path:"coverage.isSaving",value:!1})}}},D=async()=>{if(y?.id){I({type:"setFlags",path:"coverage.isSummarizing",value:!0});try{let e=await m();await (0,c.SG)({id:y.id,token:e});let t=await (0,c.$q)({id:y.id,token:e});I({type:"setCoverageValue",value:(0,l.aL)(t.coverageSummary)}),x({title:"已依條款擷取保障摘要"})}catch(e){x({title:"摘要失敗",description:(0,c.Jo)(e,"請稍後再試"),variant:"destructive"})}finally{I({type:"setFlags",path:"coverage.isSummarizing",value:!1})}}},M=async()=>{if(y?.id){I({type:"setFlags",path:"terms.isSaving",value:!0});try{let e=await m();await (0,c.HF)({id:y.id,token:e,payload:{termsSummary:P.terms.value}}),x({title:"已儲存條款摘要"})}catch(e){x({title:"儲存失敗",description:(0,c.Jo)(e,"請稍後再試"),variant:"destructive"})}finally{I({type:"setFlags",path:"terms.isSaving",value:!1})}}},U=async()=>{if(y?.id){I({type:"setFlags",path:"terms.isSummarizing",value:!0});try{let e=await m();await (0,c.SG)({id:y.id,token:e});let t=await (0,c.$q)({id:y.id,token:e});I({type:"setTermsValue",value:(0,l.Zu)(t.termsSummary)}),x({title:"已依條款擷取條款摘要"})}catch(e){x({title:"摘要失敗",description:(0,c.Jo)(e,"請稍後再試"),variant:"destructive"})}finally{I({type:"setFlags",path:"terms.isSummarizing",value:!1})}}},V=async()=>{if(!y?.id)return;let e=P.benefit.items.map(B);for(let t=0;t<e.length;t++){let n=u.Qp.safeParse(e[t]);if(!n.success){let e=n.error.issues.map(e=>e.message).join(";");x({title:"理賠項目資料有誤",description:`第 ${t+1} 筆:${e}`,variant:"destructive"});return}}I({type:"setFlags",path:"benefit.isSaving",value:!0});try{let t=await m();await (0,c.HF)({id:y.id,token:t,payload:{benefitItems:e}}),I({type:"setBenefitItems",items:e}),x({title:"已儲存理賠項目"}),b(t=>t?{...t,benefitItems:e}:null)}catch(e){x({title:"儲存失敗",description:(0,c.Jo)(e,"請稍後再試"),variant:"destructive"})}finally{I({type:"setFlags",path:"benefit.isSaving",value:!1})}},_=async()=>{if(y?.id){I({type:"setFlags",path:"rate.isExtracting",value:!0});try{let e=await m();await (0,c.a3)({id:y.id,token:e});let t=await (0,c.$q)({id:y.id,token:e}),n={...t,id:t.id??y.id};I({type:"setRateDoc",doc:n}),k(n),x({title:"費率表擷取完成"})}catch(e){x({title:"擷取費率表失敗",description:(0,c.Jo)(e,"請稍後再試"),variant:"destructive"})}finally{I({type:"setFlags",path:"rate.isExtracting",value:!1})}}},H=async()=>{if(y?.id&&P.underwriting.selectedFileId){I({type:"setFlags",path:"underwriting.isExtracting",value:!0});try{let e=await m(),t=P.underwriting.selectedFileId,n=P.underwriting.sourceFiles.find(e=>e.id&&e.id===t||e.storagePath===t),a=n?.id&&n.id===t?{sourceFileId:n.id}:{storagePath:n?.storagePath||t};if(!a.sourceFileId&&!a.storagePath)throw Error("找不到選擇的來源檔");let s=await (0,c.Y_)({id:y.id,token:e,payload:a});I({type:"setUnderwritingForm",form:{underwritingRules:s.underwritingRules??"",minInsuredAmountWan:null!=s.minInsuredAmountWan?s.minInsuredAmountWan:"",maxInsuredAmountWan:null!=s.maxInsuredAmountWan?s.maxInsuredAmountWan:""}}),x({title:"投保規則擷取完成"})}catch(e){x({title:"擷取投保規則失敗",description:(0,c.Jo)(e,"請稍後再試"),variant:"destructive"})}finally{I({type:"setFlags",path:"underwriting.isExtracting",value:!1})}}},q=async e=>{if(y?.id&&0!==e.length){T(!0);try{let t=await m(),n=new FormData;for(let t of e)n.append("files[]",t);let a=await fetch(`/api/admin/insurance-products/${y.id}/source-files/upload`,{method:"POST",headers:(0,l.Pw)(t),body:n}),s=await a.json().catch(()=>({}));if(!a.ok)throw Error(s?.error||`HTTP ${a.status}`);x({title:"上傳完成",description:`已加入 ${Array.isArray(s?.created)?s.created.length:0} 筆來源檔`}),await p()}catch(e){x({title:"上傳失敗",description:e instanceof Error?e.message:"請稍後再試",variant:"destructive"})}finally{T(!1)}}},X=async()=>
1{if(y?.id){I({type:"setFlags",path:"underwriting.isSaving",value:!0});try{let e=await m(),t={underwritingRules:P.underwriting.form.underwritingRules||void 0,minInsuredAmountWan:""!==P.underwriting.form.minInsuredAmountWan&&null!=P.underwriting.form.minInsuredAmountWan?Number(P.underwriting.form.minInsuredAmountWan):void 0,maxInsuredAmountWan:""!==P.underwriting.form.maxInsuredAmountWan&&null!=P.underwriting.form.maxInsuredAmountWan?Number(P.underwriting.form.maxInsuredAmountWan):void 0};await (0,c.HF)({id:y.id,token:e,payload:t}),x({title:"已儲存投保規則"}),b(e=>e?{...e,...t}:null),await h()}catch(e){x({title:"儲存失敗",description:(0,c.Jo)(e,"請稍後再試"),variant:"destructive"})}finally{I({type:"setFlags",path:"underwriting.isSaving",value:!1})}}},G=t&&null!==g,K=(0,s.useMemo)(()=>"basic",[]);return(0,a.jsx)(i.lG,{open:G,onOpenChange:e=>!e&&v(null),children:(0,a.jsxs)(i.Cf,{className:"max-h-[90vh] overflow-hidden flex flex-col max-w-3xl [&::-webkit-scrollbar]:hidden [scrollbar-width:none]",children:[(0,a.jsxs)(i.c7,{children:[(0,a.jsx)(i.L3,{children:"編輯保險商品"}),(0,a.jsx)(i.rr,{children:"填寫後儲存,新建立的商品預設為待審。可切換分頁編輯保障摘要、條款、理賠項目、費率表與投保規則。"})]}),(0,a.jsxs)(r.tU,{defaultValue:K,className:"flex-1 overflow-hidden flex flex-col min-h-0",children:[(0,a.jsxs)(r.j7,{className:"w-full grid grid-cols-6 shrink-0",children:[(0,a.jsx)(r.Xi,{value:"basic",children:"基本資料"}),(0,a.jsx)(r.Xi,{value:"coverage",children:"保障摘要"}),(0,a.jsx)(r.Xi,{value:"terms",children:"條款摘要"}),(0,a.jsx)(r.Xi,{value:"benefit",children:"理賠項目"}),(0,a.jsx)(r.Xi,{value:"rate",children:"費率表"}),(0,a.jsx)(r.Xi,{value:"underwriting",children:"投保規則"})]}),(0,a.jsx)(R,{formOpen:g,setFormOpen:v,formData:f,setFormData:j,editingProduct:y,editingProductSourceFiles:w,editingProductSourceFilesLoading:N,isSubmitting:C,submitForm:A,onProductNameChange:S,onPremiumCurrencyChange:F,getToken:m,toast:x}),(0,a.jsx)(O,{value:P.coverage.value,isLoading:P.coverage.isLoading,isSaving:P.coverage.isSaving,isSummarizing:P.coverage.isSummarizing,onChange:e=>I({type:"setCoverageValue",value:e}),onClose:()=>v(null),onSummarize:D,onSave:E}),(0,a.jsx)($,{value:P.terms.value,isLoading:P.terms.isLoading,isSaving:P.terms.isSaving,isSummarizing:P.terms.isSummarizing,onChange:e=>I({type:"setTermsValue",value:e}),onClose:()=>v(null),onSummarize:U,onSave:M}),(0,a.jsx)(J,{items:P.benefit.items,planAmounts:function(e){let t=e?.planAmounts;if(!t||"object"!=typeof t||Array.isArray(t))return;let n={};for(let[e,a]of Object.entries(t)){let t=e.trim();t&&"number"==typeof a&&Number.isFinite(a)&&a>=0&&(n[t]=a)}return Object.keys(n).length?n:void 0}(y??P.rate.doc),isLoading:P.benefit.isLoading,isSaving:P.benefit.isSaving,onChange:e=>I({type:"setBenefitItems",items:e}),onClose:()=>v(null),onSave:V}),(0,a.jsx)(z,{doc:P.rate.doc,isLoading:P.rate.isLoading,isExtracting:P.rate.isExtracting,onClose:()=>v(null),onExtract:_}),(0,a.jsx)(L,{sourceFiles:P.underwriting.sourceFiles,selectedFileId:P.underwriting.selectedFileId,onSelectedFileIdChange:e=>I({type:"setUnderwritingSelectedFileId",id:e}),form:P.underwriting.form,onFormChange:e=>I({type:"setUnderwritingForm",form:e}),isExtracting:P.underwriting.isExtracting,isSaving:P.underwriting.isSaving,onExtract:H,onUpload:q,isUploading:W,onSave:X,onClose:()=>v(null)})]})]})})}let U=M},79068:(e,t,n)=>{n.d(t,{Mz:()=>V,UC:()=>q,ZL:()=>H,bL:()=>U,l9:()=>_});var a=n(31615),s=n(79213),i=n(60102),r=n(96468),l=n(90099),d=n(25365),o=n(7847),c=n(52787),u=n(6521),m=n(65069),x=n(18456),h=n(76519),p=n(58384),g=n(46759),v=n(72369),f=n(16683),j=n(85047),y="Popover",[b,w]=(0,r.A)(y,[u.Bk]),N=(0,u.Bk)(),[C,A]=b(y),S=e=>{let{__scopePopover:t,children:n,open:s,defaultOpen:i,onOpenChange:r,modal:l=!1}=e,d=N(t),o=a.useRef(null),[m,x]=a.useState(!1),[h,p]=(0,g.i)({prop:s,defaultProp:i??!1,onChange:r,caller:y});return(0,j.jsx)(u.bL,{...d,children:(0,j.jsx)(C,{scope:t,contentId:(0,c.B)(),triggerRef:o,open:h,onOpenChange:p,onOpenToggle:a.useCallback(()=>p(e=>!e),[p]),hasCustomAnchor:m,onCustomAnchorAdd:a.useCallback(()=>x(!0),[]),onCustomAnchorRemove:a.useCallback(()=>x(!1),[]),modal:l,children:n})})};S.displayName=y;var F="PopoverAnchor",k=a.forwardRef((e,t)=>
1{let{__scopePopover:n,...s}=e,i=A(F,n),r=N(n),{onCustomAnchorAdd:l,onCustomAnchorRemove:d}=i;return a.useEffect(()=>(l(),()=>d()),[l,d]),(0,j.jsx)(u.Mz,{...r,...s,ref:t})});k.displayName=F;var P="PopoverTrigger",I=a.forwardRef((e,t)=>{let{__scopePopover:n,...a}=e,r=A(P,n),l=N(n),d=(0,i.s)(t,r.triggerRef),o=(0,j.jsx)(h.sG.button,{type:"button","aria-haspopup":"dialog","aria-expanded":r.open,"aria-controls":r.contentId,"data-state":M(r.open),...a,ref:d,onClick:(0,s.mK)(e.onClick,r.onOpenToggle)});return r.hasCustomAnchor?o:(0,j.jsx)(u.Mz,{asChild:!0,...l,children:o})});I.displayName=P;var R="PopoverPortal",[W,T]=b(R,{forceMount:void 0}),O=e=>{let{__scopePopover:t,forceMount:n,children:a,container:s}=e,i=A(R,t);return(0,j.jsx)(W,{scope:t,forceMount:n,children:(0,j.jsx)(x.C,{present:n||i.open,children:(0,j.jsx)(m.Z,{asChild:!0,container:s,children:a})})})};O.displayName=R;var $="PopoverContent",E=a.forwardRef((e,t)=>{let n=T($,e.__scopePopover),{forceMount:a=n.forceMount,...s}=e,i=A($,e.__scopePopover);return(0,j.jsx)(x.C,{present:a||i.open,children:i.modal?(0,j.jsx)(J,{...s,ref:t}):(0,j.jsx)(z,{...s,ref:t})})});E.displayName=$;var D=(0,p.TL)("PopoverContent.RemoveScroll"),J=a.forwardRef((e,t)=>{let n=A($,e.__scopePopover),r=a.useRef(null),l=(0,i.s)(t,r),d=a.useRef(!1);return a.useEffect(()=>{let e=r.current;
1if(e)return(0,v.Eq)(e)},[]),(0,j.jsx)(f.A,{as:D,allowPinchZoom:!0,children:(0,j.jsx)(L,{...e,ref:l,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:(0,s.mK)(e.onCloseAutoFocus,e=>{e.preventDefault(),d.current||n.triggerRef.current?.focus()}),onPointerDownOutside:(0,s.mK)(e.onPointerDownOutside,e=>{let t=e.detail.originalEvent,n=0===t.button&&!0===t.ctrlKey;d.current=2===t.button||n},{checkForDefaultPrevented:!1}),onFocusOutside:(0,s.mK)(e.onFocusOutside,e=>e.preventDefault(),{checkForDefaultPrevented:!1})})})}),z=a.forwardRef((e,t)=>{let n=A($,e.__scopePopover),s=a.useRef(!1),i=a.useRef(!1);return(0,j.jsx)(L,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:t=>{e.onCloseAutoFocus?.(t),t.defaultPrevented||(s.current||n.triggerRef.current?.focus(),t.preventDefault()),s.current=!1,i.current=!1},onInteractOutside:t=>{e.onInteractOutside?.(t),t.defaultPrevented||(s.current=!0,"pointerdown"===t.detail.originalEvent.type&&(i.current=!0));let a=t.target;n.triggerRef.current?.contains(a)&&t.preventDefault(),"focusin"===t.detail.originalEvent.type&&i.current&&t.preventDefault()}})}),L=a.forwardRef((e,t)=>{let{__scopePopover:n,trapFocus:a,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:r,onEscapeKeyDown:c,onPointerDownOutside:m,onFocusOutside:x,onInteractOutside:h,...p}=e,g=A($,n),v=N(n);return(0,d.Oh)(),(0,j.jsx)(o.n,{asChild:!0,loop:!0,trapped:a,onMountAutoFocus:s,onUnmountAutoFocus:i,children:(0,j.jsx)(l.qW,{asChild:!0,disableOutsidePointerEvents:r,onInteractOutside:h,onEscapeKeyDown:c,onPointerDownOutside:m,onFocusOutside:x,onDismiss:()=>g.onOpenChange(!1),children:(0,j.jsx)(u.UC,{"data-state":M(g.open),role:"dialog",id:g.contentId,...v,...p,ref:t,style:{...p.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})}),B="PopoverClose";function M(e){return e?"open":"closed"}a.forwardRef((e,t)=>{let{__scopePopover:n,...a}=e,i=A(B,n);return(0,j.jsx)(h.sG.button,{type:"button",...a,ref:t,onClick:(0,s.mK)(e.onClick,()=>i.onOpenChange(!1))})}).displayName=B,a.forwardRef((e,t)=>{let{__scopePopover:n,...a}=e,s=N(n);return(0,j.jsx)(u.i3,{...s,...a,ref:t})}).displayName="PopoverArrow";var U=S,V=k,_=I,H=O,q=E}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.