1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[196,1641],{14022:(e,t,s)=>{s.d(t,{getTierConfig:()=>r,nU:()=>i});let a={rookie:{id:"rookie",name:"æ°æ",color:"#94A3B8",minUniqueClients:0,minRating:0,maxFee:null,order:0},normal:{id:"normal",name:"æ®é",color:"#8B7355",minUniqueClients:10,minRating:4.5,maxFee:3e3,order:1},elite:{id:"elite",name:"èè±",color:"#C0C0C0",minUniqueClients:100,minRating:4.5,maxFee:12e3,order:2},epic:{id:"epic",name:"å²è©©",color:"#FFD700",minUniqueClients:1e3,minRating:4.5,maxFee:24e3,order:3},legendary:{id:"legendary",name:"å³èªª",color:"#9B59B6",minUniqueClients:1e4,minRating:4.5,maxFee:null,order:4},special:{id:"special",name:"ç¹æ®",color:"#E74C3C",minUniqueClients:0,minRating:0,maxFee:null,order:5},gm:{id:"gm",name:"GM",color:"#991B1B",minUniqueClients:0,minRating:0,maxFee:null,order:6}};function r(e){return a[e]}function i(){return Object.values(a).sort((e,t)=>e.order-t.order)}},23381:(e,t,s)=>{s.d(t,{kC:()=>i,wV:()=>r});let a=["threads","facebook","instagram"];function r(e){return a.includes(e)}function i(e){return"app"===e.platform?null:r(e.platform)?e.metaId?.trim()||e.subtitle?.trim()||null:e.subtitle?.trim()||null}},27243:(e,t,s)=>{s.d(t,{Mi:()=>n,VQ:()=>l});let a=e=>{let t=(e??"").slice(0,10).replace(/-/g,"");return/^\d{8}$/.test(t)?t:""},r=()=>{let e=new Date,t=String(e.getFullYear()).slice(2),s=String(e.getMonth()+1).padStart(2,"0"),a=String(e.getDate()).padStart(2,"0");return`${t}${s}${a}`},i=(e,t)=>{if(!t||!e.startsWith(t))return null;let s=e.slice(t.length);return/^\d+$/.test(s)?parseInt(s,10):null},l=(e,t=[],s)=>{let l,n=a(e)||`20${r()}`,d=((l=a(e))?l.slice(2):"")||r(),c=0;for(let e of t){if(s?.excludeEntryId&&e.id===s.excludeEntryId)continue;let t=e?.version??"",a=Math.max((d?i(t,d):null)??0,i(t,n)??0);a>c&&(c=a)}let o=Math.min(c+1,9);return`${d}${o}`},n=e=>{let t=e??"";return/^\d{8}\d+$/.test(t)?t.slice(4,8):/^\d{6}\d+$/.test(t)?t.slice(2,6):t.replace(/\D/g,"").slice(-4)||t}},28022:(e,t,s)=>{s.d(t,{$q:()=>m,HF:()=>x,Jo:()=>v,KF:()=>y,SG:()=>p,Vm:()=>b,Y_:()=>f,a3:()=>j,ll:()=>w,yH:()=>N});var a=s(15418),r=s(97769),i=s(46048);let l=a.Yj().min(1).max(150).refine(e=>!e.includes("/"),"id ä¸å¯å
å« '/'"),n=a.Ik({error:a.L5().optional()}).passthrough(),d=a.Ik({ok:a.zM()}).passthrough(),c=r.tW.partial().passthrough().and(a.Ik({id:a.Yj()}));async function o(e){return await e.json().catch(()=>null)}function u(e){let t=n.safeParse(e);if(!t.success)return null;let s=t.data.error;return s?"string"==typeof s?s:"string"==typeof s?.message?s.message:null:null}async function m(e){let t=l.parse(e.id),s=await fetch(`/api/admin/insurance-products/${t}`,{headers:(0,i.Pw)(e.token)}),a=await o(s);if(!s.ok)throw Error(u(a)||`HTTP ${s.status}`);let r=c.safeParse(a);if(!r.success)throw Error("åææ ¼å¼é¯èª¤ï¼GET insurance productï¼");return r.data}let h=r.tW.partial().omit({updatedAt:!0}).passthrough();async function x(e){let t=l.parse(e.id),s=h.parse(e.payload),a=await fetch(`/api/admin/insurance-products/${t}`,{method:"PATCH",headers:{...(0,i.Pw)(e.token),"Content-Type":"application/json"},body:JSON.stringify(s)}),r=await o(a);if(!a.ok)throw Error(u(r)||`HTTP ${a.status}`);if(d.safeParse(r).success)return}async function p(e){let t=l.parse(e.id),s=await fetch(`/api/admin/insurance-products/${t}/summarize`,{method:"POST",headers:(0,i.Pw)(e.token)}),a=await o(s);if(!s.ok)throw Error(400===s.status?"æ¤ååå°ç¡æ¢æ¬¾ä¾æºæªï¼è«å
ä¸å³ PDF æåçå¾åä½¿ç¨æè¦":u(a)||`HTTP ${s.status}`)}async function j(e){let t=l.parse(e.id),s=await fetch(`/api/admin/insurance-products/${t}/extract-rate`,{method:"POST",headers:(0,i.Pw)(e.token)}),a=await o(s);if(!s.ok)throw Error(u(a)||`HTTP ${s.status}`)}let g=a.Ik({sourceFileId:a.Yj().min(1).max(150).optional(),storagePath:a.Yj().min(1).max(2e3).optional()}).refine(e=>!!e.sourceFileId||!!e.storagePath,{message:"éæä¾ sourceFileId æ storagePath"});async function f(e){let t=l.parse(e.id),s=g.parse(e.payload),r=await fetch(`/api/admin/insurance-products/${t}/extract-underwriting`,{method:"POST",headers:{...(0,i.Pw)(e.token),"Content-Type":"application/json"},body:JSON.stringify(s)}),n=await o(r);if(!r.ok)throw Error(u(n)||`HTTP ${r.status}`);let d=a.Ik({underwritingRules:a.Yj().optional(),minInsuredAmountWan:a.ai().optional(),maxInsuredAmountWan:a.ai().optional()}).passthrough().safeParse(n);return d.success?d.data:{}}function v(e,t){return e?"string"==typeof e?e:e instanceof Error?e.message:t:t}async function y(e){let t=l.parse(e.id),s=await fetch(`/api/admin/insurance-products/${t}/verify-field`,{method:"POST",headers:{...(0,i.Pw)(e.token),"Content-Type":"application/json"},body:JSON.stringify({field:e.field,verified:e.verified,...e.valueHash?{valueHash:e.valueHash}:{}})}),a=await o(s);if(!s.ok)throw Error(u(a)||`HTTP ${s.status}`)}async function b(e){let t=await fetch("/api/admin/insurance-products/batch-ingest",{method:"POST",headers:{...(0,i.Pw)(e.token),"Content-Type":"application/json"},body:JSON.stringify({productIds:e.productIds})}),s=await o(t);if(!t.ok)throw Error(u(s)||`HTTP ${t.status}`);let r=a.Ik({jobId:a.Yj().min(1)}).safeParse(s);if(!r.success)throw Error("åææ ¼å¼é¯èª¤ï¼create batch-ingest jobï¼");return r.data}async function w(e){let t=await fetch(`/api/admin/insurance-products/batch-ingest/${e.jobId}`,{headers:(0,i.Pw)(e.token)}),s=await o(t);if(!t.ok)throw Error(u(s)||`HTTP ${t.status}`);return s}async function N(e){let t=await fetch(`/api/admin/insurance-products/batch-ingest/${e.jobId}/next`,{method:"POST",headers:(0,i.Pw)(e.token)}),s=await o(t);if(!t.ok)throw Error(u(s)||`HTTP ${t.status}`);let r=a.Ik({done:a.zM(),productId:a.Yj().optional(),status:a.Yj().optional(),error:a.Yj().optional(),needsReview:a.zM().optional()}).safeParse(s);if(!r.success)throw Error("åææ ¼å¼é¯èª¤ï¼process next batch-ingestï¼");return r.data}},29363:(e,t,s)=>{s.d(t,{I:()=>i});var a=s(15418);let r=a.Ik({enabled:a.zM().default(!1),message:a.Yj().max(500).optional(),reason:a.Yj().max(500).optional(),updatedAt:a.bz().optional(),updatedBy:a.Yj().min(1).optional()});function i(e){return r.parse(e??{})}},43967:(e,t,s)=>{s.d(t,{M:()=>u});var a=s(31615),r=s(57376),i=s(76458),l=s(24571),n=s(56312);function d(e){let t=e=>{if(void 0!==e&&("number"!=typeof e||Number.isFinite(e))){if(Array.isArray(e))return e.map(e=>t(e)).filter(e=>void 0!==e);if(null!==e&&"object"==typeof e&&!(e instanceof Date)&&!(e instanceof l.Timestamp)){let s={};for(let[a,r]of Object.entries(e)){let e=t(r);void 0!==e&&(s[a]=e)}return s}return e}},s={};for(let[a,r]of Object.entries(e)){let e=t(r);void 0!==e&&(s[a]=e)}return s}var c=s(73521);let o={async list(e){try{let t;if(!i.db)throw Error("Firestore å°æªåå§å");t=e?(0,l.P)((0,l.rJ)(i.db,i.CREDIT_CARD_TEMPLATES),(0,l._M)("bank","
1==",e),(0,l._M)("isActive","==",!0)):(0,l.P)((0,l.rJ)(i.db,i.CREDIT_CARD_TEMPLATES),(0,l._M)("isActive","==",!0));let s=(await (0,l.GG)(t)).docs.map(e=>({id:e.id,...e.data()}));return{ok:!0,data:s||[]}}catch(e){return{ok:!1,error:e?.message||"list_templates_failed"}}},async get(e){try{if(!i.db)throw Error("Firestore å°æªåå§å");if(!e)throw Error("æ¨¡æ¿ ID æªæä¾");let t=(0,l.doc)(i.db,i.CREDIT_CARD_TEMPLATES,e),s=await (0,l.getDoc)(t);if(!s.exists())return{ok:!0,data:null};return{ok:!0,data:{...s.data(),id:s.id}}}catch(e){return{ok:!1,error:e?.message||"get_template_failed"}}},async create(e){try{if(!i.db)throw Error("Firestore å°æªåå§å");let t=l.Timestamp.now(),s={...e,createdAt:t,updatedAt:t},a=n.ZR.parse(s),r=d(a),c=await (0,l.gS)((0,l.rJ)(i.db,i.CREDIT_CARD_TEMPLATES),r);return{ok:!0,data:c.id}}catch(e){if(e?.issues&&Array.isArray(e.issues)){let t=e.issues[0];return{ok:!1,error:`é©è失æï¼${t?.message||"è«æª¢æ¥è¡¨å®è³æ"}`}}return{ok:!1,error:e?.message||"create_template_failed"}}},async update(e,t){try{if(!i.db)throw Error("Firestore å°æªåå§å");if(!e)throw Error("æ¨¡æ¿ ID æªæä¾");let s=(0,l.doc)(i.db,i.CREDIT_CARD_TEMPLATES,e),a=await (0,l.getDoc)(s);if(!a.exists())throw Error("模æ¿ä¸åå¨");let r=l.Timestamp.now(),c=d({...a.data(),...t,updatedAt:r}),o=n.ZR.parse(c);return await (0,l.mZ)(s,d(o)),{ok:!0}}catch(e){return{ok:!1,error:e?.message||"update_template_failed"}}},async delete(e){try{if(!i.db)throw Error("Firestore å°æªåå§å");if(!e)throw Error("æ¨¡æ¿ ID æªæä¾");let t=(0,l.doc)(i.db,i.CREDIT_CARD_TEMPLATES,e);if(!(await (0,l.getDoc)(t)).exists())throw Error("模æ¿ä¸åå¨");return await (0,l.kd)(t),{ok:!0}}catch(e){return{ok:!1,error:e?.message||"delete_template_failed"}}},async findByBankAndName(e,t){try{if(!i.db)throw Error("Firestore å°æªåå§å");if(!e||!t)throw Error("éè¡åå稱çºå¿
å¡«");let s=(0,l.P)((0,l.rJ)(i.db,i.CREDIT_CARD_TEMPLATES),(0,l._M)("bank","==",e),(0,l._M)("name","==",t),(0,l._M)("isActive","==",!0)),a=await (0,l.GG)(s);if(a.empty)return{ok:!0,data:null};let r=a.docs[0];return{ok:!0,data:{...r.data(),id:r.id}}}catch(e){return{ok:!1,error:e?.message||"find_template_failed"}}},async addBenefit(e,t,s){try{if(!i.db)throw Error("Firestore å°æªåå§å");if(!e)throw Error("æ¨¡æ¿ ID æªæä¾");if(!s)throw Error("ç¨æ¶ ID æªæä¾");let a=(0,l.doc)(i.db,i.CREDIT_CARD_TEMPLATES,e),r=await (0,l.getDoc)(a);if(!r.exists())throw Error("模æ¿ä¸åå¨");let c=r.data(),o=c.benefits||[],u={...t,createdBy:s},m=[...o,u],h=l.Timestamp.now(),x=d({...c,benefits:m,updatedAt:h,lastUpdatedBy:s}),p=n.ZR.parse(x);return await (0,l.mZ)(a,d(p)),{ok:!0}}catch(e){if(e?.issues&&Array.isArray(e.issues)){let t=e.issues[0];return{ok:!1,error:`é©è失æï¼${t?.message||"è«æª¢æ¥è³æ"}`}}return{ok:!1,error:e?.message||"add_benefit_failed"}}},async updateBenefit(e,t,s,a){try{if(!i.db)throw Error("Firestore å°æªåå§å");if(!e)throw Error("æ¨¡æ¿ ID æªæä¾");if(!t)throw Error("åªæ ID æªæä¾");if(!a)throw Error("ç¨æ¶ ID æªæä¾");let r=(0,l.doc)(i.db,i.CREDIT_CARD_TEMPLATES,e),c=await (0,l.getDoc)(r);if(!c.exists())throw Error("模æ¿ä¸åå¨");let o=c.data(),u=o.benefits||[],m=u.findIndex(e=>e.id===t);if(-1===m)throw Error("åªæ ä¸åå¨");let h=u[m];if(h.createdBy!==a)return{ok:!1,error:"ç¡æ¬éä¿®æ¹æ¤åªæ ï¼åªææ°å¢è
å¯ä»¥ä¿®æ¹"};let x={...h,...s,id:h.id,createdBy:h.createdBy},p=[...u];p[m]=x;let j=l.Timestamp.now(),g=d({...o,benefits:p,updatedAt:j,lastUpdatedBy:a}),f=n.ZR.parse(g);return await (0,l.mZ)(r,d(f)),{ok:!0}}catch(e){if(e?.issues&&Array.isArray(e.issues)){let t=e.issues[0];return{ok:!1,error:`é©è失æï¼${t?.message||"è«æª¢æ¥è³æ"}`}}return{ok:!1,error:e?.message||"update_benefit_failed"}}},async deleteBenefit(e,t,s){try{if(!i.db)throw Error("Firestore å°æªåå§å");if(!e)throw Error("æ¨¡æ¿ ID æªæä¾");if(!t)throw Error("åªæ ID æªæä¾");if(!s)throw Error("ç¨æ¶ ID æªæä¾");let a=(0,l.doc)(i.db,i.CREDIT_CARD_TEMPLATES,e),r=await (0,l.getDoc)(a);if(!r.exists())throw Error("模æ¿ä¸åå¨");let c=r.data(),o=c.benefits||[],u=o.find(e=>e.id===t);
1if(!u)throw Error("åªæ ä¸åå¨");if(u.createdBy!==s)return{ok:!1,error:"ç¡æ¬éåªé¤æ¤åªæ ï¼åªææ°å¢è
å¯ä»¥åªé¤"};let m=o.filter(e=>e.id!==t),h=l.Timestamp.now(),x=d({...c,benefits:m,updatedAt:h,lastUpdatedBy:s}),p=n.ZR.parse(x);return await (0,l.mZ)(a,d(p)),{ok:!0}}catch(e){if(e?.issues&&Array.isArray(e.issues)){let t=e.issues[0];return{ok:!1,error:`é©è失æï¼${t?.message||"è«æª¢æ¥è³æ"}`}}return{ok:!1,error:e?.message||"delete_benefit_failed"}}},async checkBenefitPermission(e,t,s){try{if(!i.db)throw Error("Firestore å°æªåå§å");if(!e)throw Error("æ¨¡æ¿ ID æªæä¾");if(!t)throw Error("åªæ ID æªæä¾");if(!s)throw Error("ç¨æ¶ ID æªæä¾");let a=(0,l.doc)(i.db,i.CREDIT_CARD_TEMPLATES,e),r=await (0,l.getDoc)(a);if(!r.exists())return{ok:!1,error:"模æ¿ä¸åå¨"};let n=(r.data().benefits||[]).find(e=>e.id===t);if(!n)return{ok:!1,error:"åªæ ä¸åå¨"};let d=n.createdBy===s;return{ok:!0,data:d}}catch(e){return{ok:!1,error:e?.message||"check_permission_failed"}}}};function u(e){let{user:t}=(0,c.A)(),[s,i]=(0,a.useState)(!1),[l,n]=(0,a.useState)(null),{data:d,mutate:u,isLoading:m}=(0,r.Ay)(e?`credit-card-templates-${e}`:"credit-card-templates",async()=>{let t=await o.list(e);if(!t.ok)throw Error(t.error||"å徿¨¡æ¿å表失æ");return t.data||[]},{revalidateOnFocus:!1,revalidateOnReconnect:!0}),h=(0,a.useCallback)(async e=>{i(!0),n(null);try{let t=await o.get(e);if(!t.ok)throw Error(t.error||"å徿¨¡æ¿å¤±æ");return t.data}catch(e){throw n(e.message),e}finally{i(!1)}},[]),x=(0,a.useCallback)(async e=>{i(!0),n(null);try{let t=await o.create(e);if(!t.ok)throw Error(t.error||"å»ºç«æ¨¡æ¿å¤±æ");return await u(),t.data}catch(e){throw n(e.message),e}finally{i(!1)}},[u]),p=(0,a.useCallback)(async(e,t)=>{i(!0),n(null);try{let s=await o.update(e,t);if(!s.ok)throw Error(s.error||"æ´æ°æ¨¡æ¿å¤±æ");await u()}catch(e){throw n(e.message),e}finally{i(!1)}},[u]),j=(0,a.useCallback)(async e=>{i(!0),n(null);try{let t=await o.delete(e);if(!t.ok)throw Error(t.error||"åªé¤æ¨¡æ¿å¤±æ");await u()}catch(e){throw n(e.message),e}finally{i(!1)}},[u]),g=(0,a.useCallback)(async(e,t)=>{i(!0),n(null);try{let s=await o.findByBankAndName(e,t);if(!s.ok)throw Error(s.error||"æ¥æ¾æ¨¡æ¿å¤±æ");return s.data}catch(e){throw n(e.message),e}finally{i(!1)}},[]),f=(0,a.useCallback)(async(e,s)=>{if(!t?.uid)throw Error("è«å
ç»å
¥");i(!0),n(null);try{let a=await o.addBenefit(e,s,t.uid);if(!a.ok)throw Error(a.error||"æ°å¢åªæ 失æ");await u()}catch(e){throw n(e.message),e}finally{i(!1)}},[t?.uid,u]),v=(0,a.useCallback)(async(e,s,a)=>{if(!t?.uid)throw Error("è«å
ç»å
¥");i(!0),n(null);try{let r=await o.updateBenefit(e,s,a,t.uid);if(!r.ok)throw Error(r.error||"æ´æ°åªæ 失æ");await u()}catch(e){throw n(e.message),e}finally{i(!1)}},[t?.uid,u]);return{templates:d||[],loading:s||m,error:l,getTemplate:h,createTemplate:x,updateTemplate:p,deleteTemplate:j,findByBankAndName:g,addBenefit:f,updateBenefit:v,deleteBenefit:(0,a.useCallback)(async(e,s)=>{if(!t?.uid)throw Error("è«å
ç»å
¥");i(!0),n(null);try{let a=await o.deleteBenefit(e,s,t.uid);if(!a.ok)throw Error(a.error||"åªé¤åªæ 失æ");await u()}catch(e){throw n(e.message),e}finally{i(!1)}},[t?.uid,u]),canModifyBenefit:(0,a.useCallback)(async(e,s)=>{if(!t?.uid)return!1;try{let a=await o.checkBenefitPermission(e,s,t.uid);if(!a.ok)return!1;return a.data||!1}catch(e){return!1}},[t?.uid]),mutate:u}}},46048:(e,t,s)=>{s.d(t,{Eo:()=>n,Jt:()=>l,Pw:()=>i,Zu:()=>c,aL:()=>d,wz:()=>o});var a=s(73529),r=s(31102);function i(e){return{Authorization:`Bearer ${e}`}}function l(e,t){if(!e)return"-";let s=e.replace(/[\uFF0Dï¼\u2013â\u2014â]/g,"-"),i=s.replace(/\s*-\s*(æ¢æ¬¾|è²»ç|DM)(_[^\s]*)?\s*$/i,"").trim()||s,l=(0,a.O7)(i).replace(/\s+/g," ").trim()||s;return(0,r.Ng)(l,t)}function n(e){let t=String(e.productType??""),s=/æå¤/.test(t),a="number"==typeof e.referencePremium&&Number.isFinite(e.referencePremium)&&e.referencePremium>0;return s?Array.isArray(e.accidentRateTable)&&e.accidentRateTable.length>0?{ok:!0}:{ok:!1,reason:"é æè²»çè¡¨ï¼æå¤éªçºè·æ¥é¡å¥è²»çè¡¨ï¼æè½ä¸æ¶"}:Array.isArray(e.rateTable)&&e.rateTable.length>0||a?{ok:!0}:{ok:!1,reason:"é æè²»çè¡¨ï¼æååè³æå·²å
·åãåèä¿è²»ãï¼referencePremiumï¼å¤§æ¼ 0ï¼æè½ä¸æ¶ï¼ä¾å¦å¯å
¥ï¼æ·åæå¾ï¼æå©çè®åå
1çç¡å¹´é½¡è²»çæ ¼ä¹ååï¼"}}function d(e){return e?"string"==typeof e?{sections:[{title:"ä¿éæè¦",items:e.trim()?[{description:e.trim()}]:[]}]}:e&&"object"==typeof e&&Array.isArray(e.sections)?e:{sections:[]}:{sections:[]}}function c(e){return e?"string"==typeof e?{blocks:e.trim()?[{content:e.trim()}]:[]}:e&&"object"==typeof e&&Array.isArray(e.blocks)?e:{blocks:[]}:{blocks:[]}}function o(e){return"terms"===e?"æ¢æ¬¾":"rate"===e?"è²»ç":"general"===e?"æä¿è¦å":"å
¶ä»"}},46122:(e,t,s)=>{s.d(t,{Rh:()=>l,W8:()=>r,YA:()=>i});var a=s(15418);let r=["ç¾éåé¥","黿¸åé¥","éç¨åé¥","åªæ æ´»å","å
¶ä»"],i=a.Ik({id:a.Yj().min(1),category:a.Yj().min(1).max(50),title:a.Yj().min(1).max(100),description:a.Yj().max(500).optional(),rate:a.ai().min(0).max(100).optional(),conditions:a.Yj().max(500).optional(),validUntil:a.Yj().regex(/^\d{4}-\d{2}-\d{2}$/).optional(),isActive:a.zM().default(!0),isVerified:a.zM().default(!1),verifiedCount:a.ai().int().min(0).default(0),errorReportCount:a.ai().int().min(0).default(0),lastVerifiedAt:a.bz().optional(),createdBy:a.Yj().min(1)}),l=a.Ik({name:a.Yj().min(1).max(100),bank:a.Yj().min(1).max(50),categories:a.YO(a.Yj()).default([]),benefits:a.YO(i).default([]),isActive:a.zM().default(!0),createdAt:a.bz(),updatedAt:a.bz(),createdBy:a.Yj().optional(),lastUpdatedBy:a.Yj().optional()})},56312:(e,t,s)=>{s.d(t,{Fb:()=>d,UW:()=>i,ZR:()=>l,_T:()=>c,nt:()=>n,r4:()=>o});var a=s(15418),r=s(46122);let i=r.YA,l=r.Rh,n=a.Ik({userId:a.Yj().min(1,"userId ä¸è½çºç©º"),name:a.Yj().min(1,"å¡çå稱çºå¿
å¡«").max(100,"å¡çå稱ä¸è½è¶
é 100 åå
"),bank:a.Yj().min(1,"ç¼å¡éè¡çºå¿
å¡«").max(50,"ç¼å¡éè¡ä¸è½è¶
é 50 åå
"),cardNumber:a.Yj().regex(/^\d{4}$/,"å¡èå¾å碼å¿
é çº 4 使¸å").optional(),expiryDate:a.Yj().regex(/^\d{2}\/\d{2}$/,"å°ææ¥æ ¼å¼å¿
é çº MM/YYï¼ä¾å¦ï¼12/25ï¼"),creditLimit:a.ai().positive("ä¿¡ç¨é¡åº¦å¿
é å¤§æ¼ 0"),currency:a.Yj().length(3,"å¹£å¥å¿
é æ¯ 3 ååå
").default("TWD"),billingDate:a.ai().int().min(1,"右宿¥å¿
é å¨ 1-31 ä¹é").max(31,"右宿¥å¿
é å¨ 1-31 ä¹é"),paymentDueDate:a.ai().int().min(1,"繳款æ¥å¿
é å¨ 1-31 ä¹é").max(31,"繳款æ¥å¿
é å¨ 1-31 ä¹é"),benefits:a.YO(i).optional().default([]),reminderEnabled:a.zM().default(!0),reminderDaysBefore:a.ai().int().min(1,"æé天æ¸å¿
é å¨ 1-30 ä¹é").max(30,"æé天æ¸å¿
é å¨ 1-30 ä¹é").default(3),expiryReminderEnabled:a.zM().default(!0),expiryReminderDaysBefore:a.ai().int().min(1,"å°ææ¥æé天æ¸å¿
é å¨ 1-90 ä¹é").max(90,"å°ææ¥æé天æ¸å¿
é å¨ 1-90 ä¹é").default(30),notes:a.Yj().max(1e3,"å註ä¸è½è¶
é 1000 åå
").optional(),isActive:a.zM().default(!0),createdAt:a.bz(),updatedAt:a.bz().optional()}),d=n.omit({userId:!0,createdAt:!0,updatedAt:!0});a.Ik({templateId:a.Yj().min(1,"æ¨¡æ¿ ID ä¸è½çºç©º"),benefitId:a.Yj().min(1,"åªæ ID ä¸è½çºç©º"),type:a.k5(["verify","report_error"]),userId:a.Yj().min(1,"ç¨æ¶ ID ä¸è½çºç©º"),status:a.k5(["pending","approved","rejected"]).default("pending"),evidence:a.Yj().url("èæå¿
é çºææç URL").optional(),description:a.Yj().min(1,"說æçºå¿
å¡«").max(1e3,"說æä¸è½è¶
é 1000 åå
"),referenceUrl:a.Yj().url("åèç¶²åå¿
é çºææç URL").optional(),verifiedCount:a.ai().int().min(0).optional(),errorReportCount:a.ai().int().min(0).optional(),createdAt:a.bz(),reviewedAt:a.bz().optional(),reviewedBy:a.Yj().optional()}),a.Ik({templateId:a.Yj().min(1,"æ¨¡æ¿ ID ä¸è½çºç©º"),benefitId:a.Yj().optional(),type:a.k5(["add","update","delete"]),suggestedBenefit:i.optional(),userId:a.Yj().min(1,"ç¨æ¶ ID ä¸è½çºç©º"),status:a.k5(["pending","approved","rejected"]).default("pending"),verifyCount:a.ai().int().min(0).default(0),description:a.Yj().max(1e3,"說æä¸è½è¶
é 1000 åå
").optional(),createdAt:a.bz(),appliedAt:a.bz().optional(),reviewedBy:a.Yj().optional()});let c=a.Ik({url:a.Yj().url("ç¶²åæ ¼å¼ä¸æ£ç¢º").refine(e=>e.startsWith("http://")||e.startsWith("https://"),{message:"ç¶²åå¿
é 以 http:// æ https:// éé "}),userId:a.Yj().min(1,"ç¨æ¶ ID ä¸è½çºç©º"),status:a.k5(["pending","processed","rejected"]).default("pending"),createdAt:a.bz(),processedAt:a.bz().optional(),templateId:a.Yj().optional(),note:a.Yj().max(500,"å註ä¸è½è¶
é 500 åå
").optional()}),o=a.Ik({templateId:a.Yj().min(1,"æ¨¡æ¿ ID ä¸è½çºç©º"),userId:a.Yj().min(1,"ç¨æ¶ ID ä¸è½çºç©º"),description:a.Yj().max(1e3,"說æä¸è½è¶
é 1000 åå
").optional(),referenceUrl:a.Yj().url("åèç¶²åæ ¼å¼ä¸æ£ç¢º").optional(),createdAt:a.bz()})},64311:(e,t,s)=>{s.d(t,{IS:()=>d,ks:()=>o});var a=s(24571),r=s(76458),i=s(18654);let l={completed:!1,completedAt:null,skipped:!1,skippedAt:null,stepsCompleted:{accountCreated:!1,firstIncomeRecorded:!1},featureProgress:{}};async function n(e){if(!r.db||!e)return null;try{let t=(0,a.doc)(r.db,r.USERS,e),s=await (0,a.getDoc)(t);if(!s.exists())return null;let i=s.data().onboarding;if(!i)return l;let n={...l,...i,stepsCompleted:{...l.stepsCompleted,...i.stepsCompleted||{}}};return void 0===n.globalFlowCompleted&&(n.globalFlowCompleted=!1),void 0===n.globalFlowVersion&&(n.globalFlowVersion=1),n}catch(e){return(0,i.vV)("åå¾ onboarding çæ
失æ:",e),null}}async function d(e){let t=await n(e);return t?{globalFlowVersion:t.globalFlowVersion??1,globalFlowCompleted:t.globalFlowCompleted??!1,globalFlowCompletedAt:t.globalFlowCompletedAt??null,goal:t.goal??null,lastStep:t.lastStep??null,skippedAt:t.skippedAt??null}:null}async function c(e,t){if(r.db&&e)try{let s=(0,a.doc)(r.db,r.USERS,e),d=await n(e)||l,c={globalFlowVersion:t.globalFlowVersion??d.globalFlowVersion??1,globalFlowCompleted:t.globalFlowCompleted??d.globalFlowCompleted??!1,globalFlowCompletedAt:void 0!==t.globalFlowCompletedAt?t.globalFlowCompletedAt:
1d.globalFlowCompletedAt??null,goal:void 0!==t.goal?t.goal:d.goal??null,lastStep:void 0!==t.lastStep?t.lastStep:d.lastStep??null,skippedAt:void 0!==t.skippedAt?t.skippedAt:d.skippedAt??null};await (0,a.mZ)(s,{"onboarding.globalFlowVersion":c.globalFlowVersion,"onboarding.globalFlowCompleted":c.globalFlowCompleted,"onboarding.globalFlowCompletedAt":c.globalFlowCompletedAt,"onboarding.goal":c.goal,"onboarding.lastStep":c.lastStep,"onboarding.skippedAt":c.skippedAt,updatedAt:(0,a.serverTimestamp)()}),(0,i.fH)("First Run onboarding çæ
å·²æ´æ°",{uid:e,updates:t})}catch(e){throw(0,i.vV)("æ´æ° First Run onboarding çæ
失æ:",e),e}}async function o(e){await c(e,{globalFlowCompleted:!1,globalFlowCompletedAt:null,goal:null,lastStep:null,skippedAt:null})}},65952:(e,t,s)=>{s.d(t,{$1:()=>r,JS:()=>n,KM:()=>c,_4:()=>a,ch:()=>d,hn:()=>l,ps:()=>i});let a=(0,s(3198).DE)(),r=5,i=100,l=500,n=[{value:"__all__",label:"å
¨é¨"},{value:"listed",label:"䏿¶"},{value:"unlisted",label:"䏿¶"}],d=[{value:"__all__",label:"å
¨é¨"},{value:"life",label:"壽éª"},{value:"property",label:"ç¢éª"},{value:"medical",label:"é«ç"}],c={insurerCode:"",category:"life",productType:"",productName:"",productCode:"",premiumCurrency:"twd",premiumRateType:"",ageRange:"",coveragePeriod:"",productRole:"",minInsuredAmountWan:void 0,maxInsuredAmountWan:void 0,termOption:"",termOptions:[],coverageSummary:"",termsSummary:"",isDiscontinued:!1,effectiveDate:"",sourceUrl:"",reviewStatus:"unlisted",medicalGapRules:void 0}},70196:(e,t,s)=>{s.r(t),s.d(t,{default:()=>s9});var a,r=s(85047),i=s(31615),l=s(26052),n=s.n(l),d=s(46377),c=s(49793),o=s(47678),u=s(41178),m=s(73521),h=s(57376),x=s(30233);async function p(){try{let{db:e,functions:t}=await Promise.resolve().then(s.bind(s,76458));return!!(e&&t)}catch{return!1}}var j=s(76458),g=s(19548),f=s(6386),v=s(39461),y=s(82520),b=s(21410),w=s(96968),N=s(38187),k=s(21016),C=s(51577),A=s(34619),S=s(94430),T=s(77606),I=s(40975),E=s(2416),$=s(54306),R=s(34961);let D={sm:40,md:64,lg:96};function P({size:e="md",text:t="",className:s,fullScreen:a=!1,variant:i="orbit"}){return(0,r.jsx)($.default,{variant:i,size:D[e],text:t,fullScreen:a,className:(0,R.cn)(a&&"min-h-screen",s)})}var F=s(29222),O=s(18654),_=s(24571),U=s(29363),z=s(18534),B=s(54296),L=s(34071);function Y({isOpen:e,onClose:t,onConfirm:s,action:a,isLoading:i=!1,reason:l="",onReasonChange:n}){return(0,r.jsx)(z.lG,{open:e,onOpenChange:t,children:(0,r.jsxs)(z.Cf,{className:"sm:max-w-[500px]",children:[(0,r.jsxs)(z.c7,{children:[(0,r.jsxs)(z.L3,{className:"flex items-center gap-2",children:[(()=>{if(!a)return(0,r.jsx)(E.A,{className:"h-5 w-5"});if(a.icon)return a.icon;switch(a.type){case"danger":return(0,r.jsx)(B.A,{className:"h-5 w-5 text-red-500"});case"warning":return(0,r.jsx)(E.A,{className:"h-5 w-5 text-yellow-500"});case"info":return(0,r.jsx)(L.A,{className:"h-5 w-5 text-blue-500"});default:return(0,r.jsx)(E.A,{className:"h-5 w-5"})}})(),a.title]}),(0,r.jsx)(z.rr,{children:a.description})]}),a.details&&a.details.length>0&&(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)("h4",{className:"text-sm font-medium",children:"æä½è©³æ
ï¼"}),(0,r.jsx)("ul",{className:"text-sm text-muted-foreground space-y-1",children:a.details.map((e,t)=>(0,r.jsxs)("li",{className:"flex items-start gap-2",children:[(0,r.jsx)("span",{className:"text-muted-foreground",children:"â¢"}),(0,r.jsx)("span",{children:e})]},t))})]}),a.requiresReason&&(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("label",{className:"text-sm font-medium",children:["æä½åå ",(0,r.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,r.jsx)("textarea",{className:"w-full p-2 border rounded-md resize-none",rows:3,placeholder:"è«èªªæå·è¡æ¤æä½çåå ...",value:l,onChange:e=>n?.(e.target.value)})]}),"danger"===a.type&&(0,r.jsxs)(k.Fc,{children:[(0,r.jsx)(E.A,{className:"h-4 w-4"}),(0,r.jsxs)(k.TN,{children:[(0,r.jsx)("strong",{children:"è¦åï¼"})," æ¤æä½ç¡æ³å¾©åï¼è«ç¢ºèªæ¨è¦ç¹¼çºå·è¡ã"]})]}),(0,r.jsxs)(z.Es,{className:"flex justify-between",children:[(0,r.jsx)(b.$,{variant:"outline",onClick:t,disabled:i,children:a.cancelText||"åæ¶"}),(0,r.jsx)(b.$,{variant:a&&"danger"===a.type?"destructive":"default",onClick:()=>s(l),disabled:!(a&&(!a.requiresReason||l.trim())&&1)||i,children:i?"èçä¸...":a.confirmText})]})]})})}function J(){let[e,t]=(0,i.useState)(!1),[s,a]=(0,i.useState)(null),[r,l]=(0,i.useState)(!1),[n,d]=(0,i.useState)(""),c=(0,i.useCallback)(e=>new Promise(s=>{a(e),t(!0),d(""),l(!1),e.__resolve=s}),[]),o=(0,i.useCallback)(()=>{t(!1),a(null),d(""),l(!1),s&&s.__resolve&&s.__resolve({confirmed:!1})},[s]);return{isOpen:e,action:s,isLoading:r,reason:n,showConfirmation:c,hideConfirmation:o,setLoa
1ding:(0,i.useCallback)(e=>{l(e)},[]),setReason:(0,i.useCallback)(e=>{d(e)},[])}}function M({users:e,advisors:t,suggestions:s}){let{toast:a}=(0,u.dj)(),{handleError:l,handleAsyncError:n}=function(){let{toast:e}=(0,u.dj)(),t=(0,i.useCallback)((t,s={})=>{let{showToast:a=!0,logError:r=!0,fallbackMessage:i="ç¼çæªç¥é¯èª¤ï¼è«ç¨å¾å試"}=s;return r&&(0,O.vV)("ErrorHandler caught error:",t),a&&e({variant:"destructive",title:"æä½å¤±æ",description:t?.message||t?.error||i}),t},[e]),s=(0,i.useCallback)(async(e,s={})=>{try{return await e()}catch(e){return t(e,s),null}},[t]);return{handleError:t,handleAsyncError:s}}(),{user:d}=(0,m.A)(),{isOpen:c,action:o,isLoading:h,reason:x,showConfirmation:p,hideConfirmation:f,setLoading:v,setReason:$}=J(),R=(0,F.R)(null),D=(0,F.R)(null),z=(0,i.useRef)(!1),B=(0,i.useRef)(!1),[L,W]=(0,i.useState)({enabled:!1}),[V,Z]=(0,i.useState)(!0),[H,q]=(0,i.useState)(""),G=(0,i.useMemo)(()=>!!L?.enabled,[L?.enabled]);(0,i.useEffect)(()=>{if(!j.db)return void Z(!1);Z(!0);let e=(0,_.doc)(j.db,"
1system","maintenance"),t=(0,_.aQ)(e,e=>{try{let t=e.exists()?e.data():{},s=(0,U.I)(t);W(s),q(s.message||"")}catch(e){g.Cp(e instanceof Error?e:Error(String(e)),{level:"error",extra:{message:"[AdminDashboard] è§£æç¶è·è¨å®å¤±æ"},tags:{source:"AdminDashboard.onSnapshot.parseMaintenanceSettings"}})}finally{Z(!1)}},e=>{g.Cp(e instanceof Error?e:Error(String(e)),{level:"error",extra:{message:"[AdminDashboard] è®åç¶è·è¨å®å¤±æ"},tags:{source:"AdminDashboard.onSnapshot.error"}}),Z(!1)});return()=>t()},[]);let X=(0,i.useCallback)(async(e,t)=>{if(!j.db)return void a({variant:"destructive",title:"æä½å¤±æ",description:"Firestore æªåå§å"});if(!d?.uid)return void a({variant:"destructive",title:"æä½å¤±æ",description:"å°æªç»å
¥æç¡æ³åå¾ä½¿ç¨è
è³è¨"});try{v(!0),await (0,_.setDoc)((0,_.doc)(j.db,"system","maintenance"),{enabled:e,message:H?.trim()||"",reason:t.trim(),updatedAt:(0,_.serverTimestamp)(),updatedBy:d.uid},{merge:!0}),a({title:e?"å·²åç¨ç¶è·æ¨¡å¼":"å·²ééç¶è·æ¨¡å¼",description:e?"使ç¨è
å°è¢«å°åç¶è·é ":"æåå·²æ¢å¾©"})}catch(t){g.Cp(t instanceof Error?t:Error(String(t)),{level:"error",extra:{message:"[AdminDashboard] æ´æ°ç¶è·è¨å®å¤±æ",nextEnabled:e},tags:{source:"AdminDashboard.updateMaintenance"}}),a({variant:"destructive",title:"æä½å¤±æ",description:t?.message||"ç¡æ³æ´æ°ç¶è·æ¨¡å¼ï¼è«ç¨å¾å試"})}finally{v(!1)}},[H,v,a,d?.uid]),K=(0,i.useCallback)(async()=>{let e=await p({type:"warning",title:"系統ç¶è·æ¨¡å¼",description:"æ¨å³å°åç¨ç³»çµ±ç¶è·æ¨¡å¼ã卿¤æéï¼ç¨æ¶å°ç¡æ³åå系統ã",confirmText:"åç¨ç¶è·æ¨¡å¼",cancelText:"åæ¶",details:["ææç¨æ¶å°è¢«ç»åº","系統å°é¡¯ç¤ºç¶è·é é¢","管çå¡ä»å¯æ£å¸¸åå","è«ç¢ºä¿å¨ç¶è·å®æå¾ééç¶è·æ¨¡å¼"],requiresReason:!0});!e.confirmed||e.reason?.trim()&&await X(!0,e.reason)},[p,X]),Q=(0,i.useCallback)(async()=>{let e=await p({type:"warning",title:"éé系統ç¶è·æ¨¡å¼",description:"æ¨å³å°éé系統ç¶è·æ¨¡å¼ãç¨æ¶å°å¯æ¢å¾©åå系統ã",confirmText:"ééç¶è·æ¨¡å¼",cancelText:"åæ¶",details:["ç¨æ¶å°å¯éæ°åå系統","建è°ç¢ºèªä¸»è¦åè½å·²æ¢å¾©æ£å¸¸"],requiresReason:!0});!e.confirmed||e.reason?.trim()&&await X(!1,e.reason)},[p,X]),ee=(0,i.useCallback)(async()=>{if(z.current)return;let e=!1;(async()=>{try{z.current=!0,R.setLoading(!0);let t=setTimeout(()=>{e||(e=!0,z.current=!1,R.setError("è«æ±è¶
æï¼è«ç¨å¾å試"),R.setLoading(!1),a({title:"è¼å
¥å¤±æ",description:"è«æ±è¶
æï¼è«ç¨å¾å試",variant:"destructive"}))},1e4),s=await fetch("/api/ecpay/status");if(clearTimeout(t),e){z.current=!1,R.setLoading(!1);return}if(!s.ok)throw Error(`HTTP ${s.status}: ${s.statusText}`);let r=await s.json();if(e){z.current=!1,R.setLoading(!1);return}if(r.success&&r.data)R.setData(r.data);else throw Error(r.error||"ç¡æ³ç²åç¶ çç°å¢çæ
")}catch(s){if(e)return;z.current=!1;let t=s instanceof Error?s.message:"ç¡æ³ç²åç¶ çæ¯ä»ç°å¢çæ
";R.setError(t),a({title:"è¼å
¥å¤±æ",description:t,variant:"destructive"})}})()},[R,a]);return(0,i.useEffect)(()=>{R.state.data||ee()},[]),(0,i.useEffect)(()=>{if(!R.state.isLoading){if(B.current)if(!R.state.data&&!R.state.error)return;else B.current=!1;try{B.current=!0,D.setLoading(!0);let e={firebase:!0,ecpay:!!R.state.data||!R.state.error,database:!0,auth:!0,functions:!0},t=Object.values(e).some(e=>!1===e);D.setData({overall:t?"warning":"normal",services:e,lastChecked:new Date().toISOString()}),D.setLoading(!1)}catch(t){B.current=!1;let e=t instanceof Error?t.message:"系統çæ
檢æ¥å¤±æ";D.setError(e),D.setLoading(!1)}}},[R.state.isLoading,R.state.data,R.state.error]),(0,r.jsxs)("div",{className:"space-y-6",children:[(0,r.jsxs)("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:[(0,r.jsxs)(y.Zp,{children:[(0,r.jsxs)(y.aR,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[(0,r.jsx)(y.ZB,{className:"text-sm font-medium",children:"ç¸½ç¨æ¶æ¸"}),(0,r.jsx)(C.A,{className:"h-4 w-4 text-muted-foreground"})]}),(0,r.jsxs)(y.Wu,{children:[(0,r.jsx)("div",{className:"text-2xl font-bold",children:e.length}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:"已註åç¨æ¶"})]})]}),(0,r.jsxs)(y.Zp,{children:[(0,r.jsxs)(y.aR,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[(0,r.jsx)(y.ZB,{className:"text-sm font-medium",children:"顧忏é"}),(0,r.jsx)(A.A,{className:"h-4 w-4 text-muted-foreground"})]}),(0,r.jsxs)(y.Wu,{children:[(0,r.jsx)("div",{className:"text-2xl font-bold",children:t.length}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:"æ´»èºé¡§å"})]})]}),(0,r.jsxs)(y.Zp,{children:[(0,r.jsxs)(y.aR,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[(0,r.jsx)(y.ZB,{className:"text-sm font-medium",children:"å»ºè°æ¸é"}),(0,r.jsx)(S.A,{className:"h-4 w-4 text-muted-foreground"})]}),(0,r.jsxs)(y.Wu,{children:[(0,r.jsx)("div",{className:"text-2xl font-bold",children:s.length}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:"ç¨æ¶å»ºè°"})]})]}),(0,r.jsxs)(y.Zp,{children:[(0,r.jsxs)(y.aR,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[(0,r.jsx)(y.ZB,{className:"text-sm font-medium",children:"系統çæ
"}),(0,r.jsx)(T.A,{className:"h-4 w-4 text-muted-foreground"})]}),(0,r.jsx)(y.Wu,{children:D.state.isLoading?(0,r.jsx)(P,{size:"sm",text:"檢æ¥ä¸..."}):D.state.error?(0,r.jsx)("div",{className:"text-2xl font-bold text-red-600",children:"é¯èª¤"}):D.state.data?(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)("div",{className:`text-2xl font-bold ${"normal"===D.state.data.overall?"text-green-600":"warning"===D.state.data.overall?"text-yellow-600":"text-red-600"}`,children:"normal"===D.state.data.overall?"æ£å¸¸":"warning"===D.state.data.overall?"è¦å":"é¯èª¤"}),(0,r.jsx)("div",{className:"text-xs text-muted-foreground",children:"normal"===D.state.data.overall?"æææåéè¡ä¸":"warning"===D.state.data.overall?"é¨åæåç°å¸¸":"系統ç°å¸¸"}),(0,r.jsxs)("div",{className:"text-xs text-muted-foreground",children:["æå¾æª¢æ¥: ",new Date(D.state.data.lastChecked).toLocaleTimeString()]})]}):(0,r.jsx)("div",{className:"text-2xl font-bold text-gray-400",children:"æªç¥"})})]})]}),(0,r.jsxs)(y.Zp,{children:[(0,r.jsxs)(y.aR,{children:[(0,r.jsxs)(y.ZB,{className:"flex items-center gap-2",children:[(0,r.jsx)(I.A,{className:"h-5 w-5"}),"ç¶ çæ¯ä»ç°å¢çæ
"]}),(0,r.jsx)(y.BT,{children:"æ¥çç¶åç¶ çæ¯ä»ç°å¢é
ç½®"})]}),(0,r.jsx)(y.Wu,{children:R.state.isLoading?(0,r.jsx)(P,{size:"lg"}):R.state.error?(0,r.jsx)("div",{className:"text-center py-8",children:(0,r.jsxs)(k.Fc,{className:"mb-4",children:[(0,r.jsx)(E.A,{className:"h-4 w-4"}),(0,r.jsxs)(k.TN,{children:[(0,r.jsx)("p",{className:"text-red-600 font-medium mb-2",children:"ç¡æ³è¼å
¥ç¶ çæ¯ä»çæ
"}),(0,r.jsx)("p",{className:"text-sm text-muted-foreground mb-4",children:R.state.error}),(0,r.jsx)(b.$,{variant:"outline",size:"sm",onClick:()=>{z.current=!1,R.reset(),ee()},children:"é試"})]})]})}):R.state.data?(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"grid gap-4 md:grid-cols-2",children:[(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w.J,{className:"text-sm font-medium",children:"ç¶åç°å¢"}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)(N.E,{variant:R.state.data.isProduction?"default":"secondary",children:R.state.data.environment}),R.state.data.isProduction?(0,r.jsx)(E.A,{className:"h-4 w-4 text-orange-500"}):(0,r.jsx)(T.A,{className:"h-4 w-4 text-blue-500"})]})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w.J,{className:"text-sm font-medium",children:"API URL"}),(0,r.jsx)("div",{className:"text-sm text-muted-foreground font-mono",children:R.state.data.apiUrl})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w.J,{className:"text-sm font-medium",children:"ååºä»£è"}),(0,r.jsx)("div",{className:"text-sm text-muted-foreground font-mono",children:R.state.data.merchantId})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w.J,{className:"text-sm font-medium",children:"çæ
"}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("div",{className:"w-2 h-2 bg-green-500 rounded-full"}),(0,r.jsx)("span",{className:"text-sm",children:"飿¥æ£å¸¸"})]})]})]}),R.state.data.isProduction&&(0,r.jsxs)(k.Fc,{children:[(0,r.jsx)(E.A,{className:"h-4 w-4"}),(0,r.jsxs)(k.TN,{children:[(0,r.jsx)("strong",{children:"æ£å¼ç°å¢è¦åï¼"}
1)," æ¨ç®åæ£å¨ä½¿ç¨ç¶ çæ¯ä»çæ£å¼ç°å¢ï¼ææäº¤æé½å°ç¢ç實éè²»ç¨ã"]})]})]}):(0,r.jsx)("div",{className:"text-center py-8",children:(0,r.jsx)("p",{className:"text-muted-foreground mb-4",children:"ç¡æ³è¼å
¥ç¶ çæ¯ä»çæ
"})})})]}),(0,r.jsxs)(y.Zp,{children:[(0,r.jsxs)(y.aR,{children:[(0,r.jsxs)(y.ZB,{className:"flex items-center gap-2",children:[(0,r.jsx)(E.A,{className:"h-5 w-5"}),"系統ç¶è·æ¨¡å¼"]}),(0,r.jsx)(y.BT,{children:"åç¨å¾ï¼ä½¿ç¨è
æè¢«å°åç¶è·é ï¼ç®¡çå¡ä»å¯é²å¾å°ééï¼"})]}),(0,r.jsxs)(y.Wu,{children:[V?(0,r.jsx)(P,{size:"lg",variant:"outline"}):(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)(w.J,{className:"text-sm font-medium",children:"ç®åçæ
"}),(0,r.jsx)(N.E,{variant:G?"destructive":"secondary",children:G?"ç¶è·ä¸":"æ£å¸¸"})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w.J,{className:"text-sm font-medium",children:"ç¶è·è¨æ¯ï¼é¡¯ç¤ºæ¼ç¶è·é ï¼"}),(0,r.jsx)("textarea",{className:"w-full p-2 border rounded-md resize-none",rows:3,placeholder:"ä¾å¦ï¼ç³»çµ±åç´ä¸ï¼é è¨ 30 åé徿¢å¾©ã",value:H,onChange:e=>q(e.target.value)})]}),(0,r.jsx)("div",{className:"flex flex-wrap gap-3",children:G?(0,r.jsx)(b.$,{variant:"outline",onClick:Q,disabled:h,children:h?"èçä¸...":"ééç¶è·æ¨¡å¼"}):(0,r.jsx)(b.$,{onClick:K,disabled:h,children:h?"èçä¸...":"åç¨ç¶è·æ¨¡å¼"})})]}),o&&(0,r.jsx)(Y,{isOpen:c,onClose:f,onConfirm:e=>{if(o){if(o.requiresReason&&(!e||!e.trim()))return void a({variant:"destructive",title:"æä½å¤±æ",description:"è«å¡«å¯«æä½åå ã"});void 0!==e&&$(e),o.__resolve&&o.__resolve({confirmed:!0,reason:e||x})}},action:o,isLoading:h,reason:x,onReasonChange:$})]})]})]})}var W=s(866),V=s(10892),Z=s(21582),H=s(19726),q=s(15139),G=s(5779),X=s(42165);function K({filters:e,onFiltersChange:t,onReset:s,totalCount:a,isSearching:i}){let{isAdmin:l,isLoading:n,error:d}=(0,v.q)();return n?(0,r.jsx)(y.Zp,{children:(0,r.jsx)(y.Wu,{className:"p-8",children:(0,r.jsx)($.default,{size:64})})}):d?(0,r.jsx)(y.Zp,{children:(0,r.jsx)(y.Wu,{className:"p-8",children:(0,r.jsx)("div",{className:"flex items-center justify-center",children:(0,r.jsxs)("div",{className:"text-center",children:[(0,r.jsx)("div",{className:"text-destructive mb-2",children:"â ï¸"}),(0,r.jsx)("p",{className:"text-destructive font-medium",children:"æ¬é檢æ¥å¤±æ"}),(0,r.jsx)("p",{className:"text-muted-foreground text-sm",children:d})]})})})}):l?(0,r.jsxs)(y.Zp,{className:"w-full",children:[(0,r.jsx)(y.aR,{children:(0,r.jsxs)(y.ZB,{className:"flex items-center gap-2",children:[(0,r.jsx)(q.A,{className:"h-5 w-5"}),"ç¨æ¶æå°è篩é¸"]})}),(0,r.jsxs)(y.Wu,{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w.J,{htmlFor:"search",children:"æå°ç¨æ¶"}),(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsx)(G.A,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground"}),(0,r.jsx)(W.p,{id:"search",placeholder:"æå°é»åéµä»¶ãå§åæç¨æ¶ ID...",value:e.searchTerm,onChange:e=>t({searchTerm:e.target.value}),className:"pl-10"})]})]}),(0,r.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w.J,{htmlFor:"role",children:"è§è²"}),(0,r.jsxs)(Z.l6,{value:e.role||"all",onValueChange:e=>t({role:e}),children:[(0,r.jsx)(Z.bq,{children:(0,r.jsx)(Z.yv,{placeholder:"鏿è§è²"})}),(0,r.jsxs)(Z.gC,{children:[(0,r.jsx)(Z.eb,{value:"all",children:"å
¨é¨è§è²"}),(0,r.jsx)(Z.eb,{value:"admin",children:"管çå¡"}),(0,r.jsx)(Z.eb,{value:"user",children:"ä¸è¬ç¨æ¶"})]})]})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w.J,{htmlFor:"emailVerified",children:"éµç®±é©è"}),(0,r.jsxs)(Z.l6,{value:e.emailVerified||"all",onValueChange:e=>t({emailVerified:e}),children:[(0,r.jsx)(Z.bq,{children:(0,r.jsx)(Z.yv,{placeholder:"鏿é©èçæ
"})}),(0,r.jsxs)(Z.gC,{children:[(0,r.jsx)(Z.eb,{value:"all",children:"å
¨é¨çæ
"}),(0,r.jsx)(Z.eb,{value:"verified",children:"å·²é©è"}),(0,r.jsx)(Z.eb,{value:"unverified",children:"æªé©è"})]})]})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w.J,{htmlFor:"sortBy",children:"æåºæ¹å¼"}),(0,r.jsxs)(Z.l6,{value:e.sortBy||"lastSignIn",onValueChange:e=>t({sortBy:e}),children:[(0,r.jsx)(Z.bq,{children:(0,r.jsx)(Z.yv,{placeholder:"鏿æåºæ¹å¼"})}),(0,r.jsxs)(Z.gC,{children:[(0,r.jsx)(Z.eb,{value:"createdAt",children:"註åæé"}),(0,r.jsx)(Z.eb,{value:"lastSignIn",children:"æå¾ç»å
¥"}),(0,r.jsx)(Z.eb,{value:"email",children:"é»åéµä»¶"})]})]})]})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w.J,{children:"æåºé åº"}),(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(b.$,{variant:"desc"===e.sortOrder?"default":"outline",size:"sm",onClick:()=>t({sortOrder:"desc"}),children:"éåº"}),(0,r.jsx)(b.$,{variant:"asc"===e.sortOrder?"default":"outline",size:"sm",onClick:()=>t({sortOrder:"asc"}),children:"ååº"})]})]}),(0,r.jsxs)("div",{className:"flex items-center justify-between pt-4 border-t",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)(N.E,{variant:"secondary",children:i?"æå°ä¸...":`æ¾å° ${a} åç¨æ¶`}),(e.searchTerm||"all"!==e.role||"all"!==e.emailVerified)&&(0,r.jsxs)(N.E,{variant:"outline",className:"flex items-center gap-1",children:[(0,r.jsx)(q.A,{className:"h-3 w-3"}),"å·²å¥ç¨ç¯©é¸"]})]}),(0,r.jsxs)(b.$,{variant:"outline",size:"sm",onClick:s,className:"flex items-center gap-1",children:[(0,r.jsx)(X.A,{className:"h-3 w-3"}),"é置篩é¸"]})]})]})]}):(0,r.jsx)(y.Zp,{children:(0,r.jsx)(y.Wu,{className:"p-8",children:(0,r.jsx)("div",{className:"flex items-center justify-center",children:(0,r.jsxs)("div",{className:"text-center",children:[(0,r.jsx)(H.A,{className:"h-12 w-12 text-destructive mx-auto mb-4"}),(0,r.jsx)("p",{className:"text-destructive font-medium text-lg",children:"åå被æçµ"}),(0,r.jsx)("p",{className:"text-muted-foreground",children:"æ¨æ²æç®¡ç塿¬éä¾ååç¨æ¶ç®¡çåè½"})]})})})})}var Q=s(79579),ee=s(78308),et=s(80345),es=s(32898),ea=s(67592),er=s(63533),ei=s(9807),el=s(14188);function en({users:e,onUserSelect:t,onResetPassword:s,onViewUser:a,onPromoteToAdvisor:i,onDemoteFromAdvisor:l,isLoading:n=!1}){let d=e=>{if(!e)return"ç¡è³æ";try{let t;if("object"==typeof e&&null!==e)if("toDate"in e&&"function"==typeof e.toDate)t=e.toDate();else if("seconds"in e||"_seconds"in e){let s=e.seconds||e._seconds||0,a=e.nanoseconds||e._nanoseconds||0;t=new Date(1e3*s+a/1e6)}else t=e instanceof Date?e:new Date(String(e));else if("string"==typeof e){if(!e.trim())return"ç¡è³æ";t=new Date(e)}else{if("number"!=typeof e)return"ç¡è³æ";t=new Date(e>1e12?e:1e3*e)}if(isNaN(t.getTime()))return"ç¡è³æ";return t.toLocaleDateString("zh-TW",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}catch(e){return"ç¡è³æ"}};return n?(0,r.jsx)("div",{className:"space-y-4",children:[void 0,void 0,void 0].map((e,t)=>(0,r.jsx)(y.Zp,{className:"animate-pulse",children:(0,r.jsx)(y.Wu,{className:"p-4",children:(0,r.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,r.jsx)("div",{className:"w-10 h-10 bg-gray-200 rounded-full"}),(0,r.jsxs)("div",{className:"flex-1 space-y-2",children:[(0,r.jsx)("div",{className:"h-4 bg-gray-200 rounded w-1/4"}),(0,r.jsx)("div",{className:"h-3 bg-gray-200 rounded w-1/2"})]}),(0,r.jsx)("div",{className:"w-20 h-6 bg-gray-200 rounded"})]})})},t))}):0===e.length?(0,r.jsx)(y.Zp,{children:(0,r.jsxs)(y.Wu,{className:"p-8 text-center",children:[(0,r.jsx)(ee.A,{className:"h-12 w-12 text-muted-foreground mx-auto mb-4"}),(0,r.jsx)("h3",{className:"text-lg font-medium mb-2",children:"æ²ææ¾å°ç¨æ¶"}),(0,r.jsx)("p",{className:"text-muted-foreground",children:"è«åè©¦èª¿æ´æå°æ¢ä»¶æç¯©é¸å¨"})]})}):(0,r.jsx)("div",{className:"space-y-4",children:e.map(e=>{var n;return(0,r.jsx)(y.Zp,{className:"hover:shadow-md transition-shadow",children:(0,r.jsx)(y.Wu,{className:"p-4",children:(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsxs)("div",{className:"flex items-center space-x-4 cursor-pointer flex-1",onClick:()=>t(e),children:[(0,r.jsx)(Q.H,{userId:e.uid,size:"medium",className:"h-10 w-10"}),(0,r.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[(0,r.jsx)("h3",{className:"font-medium truncate",children:e.displayName||e.email}),"admin"===(n=e.role)?(0,r.jsxs)(N.E,{variant:"default",className:"flex items-center gap-1",children:[(0,r.jsx)(H.A,{className:"h-3 w-3"}),"管çå¡"]}):"advisor"===n?(0,r.jsxs)(N.E,{variant:"outline",className:"flex items-center gap-1 border-blue-500 text-blue-500",children:[(0,r.jsx)(ee.A,{className:"h-3 w-3"}
1),"é¡§å"]}):(0,r.jsxs)(N.E,{variant:"secondary",className:"flex items-center gap-1",children:[(0,r.jsx)(ee.A,{className:"h-3 w-3"}),"ç¨æ¶"]}),e.emailVerified?(0,r.jsxs)(N.E,{variant:"default",className:"flex items-center gap-1",children:[(0,r.jsx)(et.A,{className:"h-3 w-3"}),"å·²é©è"]}):(0,r.jsxs)(N.E,{variant:"destructive",className:"flex items-center gap-1",children:[(0,r.jsx)(es.A,{className:"h-3 w-3"}),"æªé©è"]})]}),(0,r.jsxs)("div",{className:"flex items-center gap-4 text-sm text-muted-foreground",children:[(0,r.jsxs)("div",{className:"flex items-center gap-1",children:[(0,r.jsx)(ea.A,{className:"h-3 w-3"}),(0,r.jsx)("span",{className:"truncate",children:e.email})]}),(0,r.jsxs)("div",{className:"flex items-center gap-1",children:[(0,r.jsx)(er.A,{className:"h-3 w-3"}),(0,r.jsxs)("span",{children:["註å: ",d(e.createdAt)]})]}),e.lastSignInTime&&(0,r.jsxs)("div",{className:"flex items-center gap-1",children:[(0,r.jsx)(ei.A,{className:"h-3 w-3"}),(0,r.jsxs)("span",{children:["ç»å
¥: ",d(e.lastSignInTime)]})]})]})]})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,r.jsxs)(b.$,{variant:"outline",size:"sm",onClick:t=>{t.stopPropagation(),a(e)},className:"flex items-center gap-1",children:[(0,r.jsx)(el.A,{className:"h-3 w-3"}),"檢è¦"]}),e.role?.toLowerCase()==="advisor"&&l&&(0,r.jsxs)(b.$,{variant:"outline",size:"sm",onClick:t=>{t.stopPropagation(),l(e)},className:"flex items-center gap-1 text-orange-600 hover:text-orange-700",children:[(0,r.jsx)(ee.A,{className:"h-3 w-3"}),"ç§»é¤é¡§åæ¬é"]}),e.role?.toLowerCase()!=="admin"&&e.role?.toLowerCase()!=="advisor"&&i&&(0,r.jsxs)(b.$,{variant:"outline",size:"sm",onClick:t=>{t.stopPropagation(),i(e)},className:"flex items-center gap-1",children:[(0,r.jsx)(ee.A,{className:"h-3 w-3"}),"åç´çºé¡§å"]}),(0,r.jsx)(b.$,{variant:"outline",size:"sm",onClick:t=>{t.stopPropagation(),s(e)},children:"éè¨å¯ç¢¼"})]})]})})},e.uid)})})}class ed{static instance;logs=[];static getInstance(){return ed.instance||(ed.instance=new ed),ed.instance}generateId(){return`log_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}getClientInfo(){return{ipAddress:this.getClientIP(),userAgent:navigator.userAgent}}getClientIP(){return"127.0.0.1"}log(e,t,s){let a={id:this.generateId(),timestamp:new Date().toISOString(),userId:t,userEmail:s,action:e.action,targetType:e.targetType,targetId:e.targetId,targetName:e.targetName,details:e.details,result:e.result||"success",errorMessage:e.errorMessage,...this.getClientInfo()};return this.logs.push(a),a}logPasswordReset(e,t,s,a){return this.log({action:"password_reset",targetType:"user",targetId:s,targetName:a,details:`éè¨ç¨æ¶ ${a} çå¯ç¢¼`,result:"success"},e,t)}logUserDelete(e,t,s,a){return this.log({action:"user_delete",targetType:"user",targetId:s,targetName:a,details:`åªé¤ç¨æ¶ ${a}`,result:"success"},e,t)}logUserRoleChange(e,t,s,a,r){return this.log({action:"user_role_change",targetType:"user",targetId:s,targetName:a,details:`å°ç¨æ¶ ${a} çè§è²è®æ´çº ${r}`,result:"success"},e,t)}logSystemAction(e,t,s,a){return this.log({action:s,targetType:"system",details:a,result:"success"},e,t)}logError(e,t,s,a,r="system"){return this.log({action:s,targetType:r,details:`æä½å¤±æ: ${s}`,result:"failure",errorMessage:a},e,t)}logFirestoreCreate(e,t,s,a){return this.log({action:"firestore_create",targetType:"firestore",targetId:a,targetName:`${s}/${a}`,details:`å»ºç«æä»¶ï¼${s}/${a}`,result:"success"},e,t)}logFirestoreUpdate(e,t,s,a){return this.log({action:"firestore_update",targetType:"firestore",targetId:a,targetName:`${s}/${a}`,details:`æ´æ°æä»¶ï¼${s}/${a}`,result:"success"},e,t)}logFirestoreDelete(e,t,s,a,r){return this.log({action:"firestore_delete",targetType:"firestore",targetId:a,targetName:`${s}/${a}`,details:`åªé¤æä»¶ï¼${s}/${a}${r?`ï¼åå ï¼${r}`:""}`,result:"success"},e,t)}getAllLogs(){return[...this.logs]}filterLogs(e){return this.logs.filter(t=>(!e.startDate||!(t.timestamp<e.startDate))&&(!e.endDate||!(t.timestamp>e.endDate))&&(!e.action||t.action===e.action)&&(!e.targetType||t.targetType===e.targetType)&&(!e.result||t.result===e.result)&&(!e.userId||t.userId===e.userId)&&!0)}clearLogs(){this.logs=[]}exportToCSV(){return[["æé","æä½è
","æä½","ç®æ¨é¡å","ç®æ¨","詳æ
","çµæ","é¯èª¤è¨æ¯"],...this.logs.map(e=>[e.timestamp,e.userEmail,e.action,e.targetType,e.targetName||"",e.details,e.result,e.errorMessage||""])].map(e=>e.join(",")).join("\n")}}let ec=ed.getInstance();function eo({users:e,onUserUpdate:t,onViewUser:a}){let{toast:l}=(0,u.dj)(),{filters:n,filteredUsers:d,totalCount:c,isSearching:o,updateFilters:h,resetFilters:x}=function(e){let[t,s]=(0,i.useState)({searchTerm:"",role:"all",emailVerified:"all",sortBy:"lastSignIn",sortOrder:"desc"}),a=(0,i.useMemo)(()=>
1({searchTerm:t.searchTerm||"",role:t.role||"all",emailVerified:t.emailVerified||"all",sortBy:t.sortBy||"lastSignIn",sortOrder:t.sortOrder||"desc"}),[t]),[r,l]=(0,i.useState)(!1),n=(0,i.useMemo)(()=>{l(!0);let t=[...e.map(e=>({...e,role:e.role||"user"}))];if(a.searchTerm){let e=a.searchTerm.toLowerCase();t=t.filter(t=>t.email?.toLowerCase().includes(e)||t.displayName?.toLowerCase().includes(e)||t.uid?.toLowerCase().includes(e))}if("all"!==a.role&&(t=t.filter(e=>(e.role||"user")===a.role)),"all"!==a.emailVerified){let e="verified"===a.emailVerified;t=t.filter(t=>t.emailVerified===e)}return t.sort((e,t)=>{let s,r;switch(a.sortBy){case"createdAt":s=new Date(e.createdAt).getTime(),r=new Date(t.createdAt).getTime();break;case"lastSignIn":s=e.lastSignInTime?new Date(e.lastSignInTime).getTime():0,r=t.lastSignInTime?new Date(t.lastSignInTime).getTime():0;break;case"email":s=e.email?.toLowerCase()||"",r=t.email?.toLowerCase()||"";break;default:return 0}return"asc"===a.sortOrder?s>r?1:-1:s<r?1:-1}),l(!1),t},[e,a]),d=(0,i.useCallback)(e=>{s(t=>({...t,...e}))},[]),c=(0,i.useCallback)(()=>{s({searchTerm:"",role:"all",emailVerified:"all",sortBy:"lastSignIn",sortOrder:"desc"})},[]);return{filters:a,filteredUsers:n,totalCount:n.length,isSearching:r,updateFilters:d,resetFilters:c}}(e),{showConfirmation:p,isOpen:j,action:g,isLoading:f,reason:v,hideConfirmation:C,setReason:A}=J(),{user:S}=(0,m.A)(),[T,I]=(0,i.useState)(!1),[$,R]=(0,i.useState)(null),[D,P]=(0,i.useState)(!1),[F,_]=(0,i.useState)(""),[U,B]=(0,i.useState)(""),[L,M]=(0,i.useState)(!1),[Z,H]=(0,i.useState)(!1),[q,G]=(0,i.useState)(!1),[X,Q]=(0,i.useState)(""),[ee,et]=(0,i.useState)(null),es=(0,i.useCallback)(async e=>{et(e),Q(e.displayName||""),G(!0)},[]),ea=(0,i.useCallback)(async()=>{if(ee){if(!X||!X.trim())return void l({variant:"destructive",title:"è«è¼¸å
¥é¡§åå§å",description:"é¡§åå§åçºå¿
å¡«æ¬ä½"});if(X.includes("@"))return void l({variant:"destructive",title:"å§åæ ¼å¼é¯èª¤",description:"é¡§åå§åä¸è½å
å« @ 符è"});M(!0),G(!1);try{let{httpsCallable:e}=await Promise.resolve().then(s.bind(s,71931)),{functions:a,auth:r}=await Promise.resolve().then(s.bind(s,76458));if(!a)throw Error("Firebase Functions æªåå§å");if(r&&r.currentUser){let e=await r.currentUser.getIdToken(!0);(0,O.fH)("ID Token 已巿°:",e?"æå":"失æ")}else throw(0,O.vV)("ç¡æ³ç²åç¶å使ç¨è
"),Error("ç¡æ³ç²åç¶å使ç¨è
");let i=e(a,"promoteUserToAdvisor");await i({uid:ee.uid,advisorName:X.trim(),reason:v||"管çå¡åç´ç¨æ¶çºé¡§å"}),S&&ec.logUserRoleChange(S.uid,S.email||"",ee.uid,ee.email,"advisor"),l({title:"â
åç´æå",description:`å·²æåå° ${ee.email} åç´çºé¡§åï¼å§åï¼${X}ï¼ã`}),et(null),Q(""),t()}catch(e){(0,O.vV)("åç´çºé¡§åé¯èª¤:",e),e?.code==="unauthenticated"||e?.message?.includes("401")?l({variant:"destructive",title:"身份é©è失æ",description:"è«éæ°ç»å
¥å¾å試ã"}):e?.code==="already-exists"?l({variant:"destructive",title:"åç´å¤±æ",description:"è©²ç¨æ¶å·²ç¶æ¯é¡§åã"}):e?.code==="invalid-argument"&&e?.message?.includes("advisor name")?l({variant:"destructive",title:"å§åæ ¼å¼é¯èª¤",description:e?.message||"é¡§åå§åä¸è½çºç©ºæå
å«ç¹æ®åå
ã"}):l({variant:"destructive",title:"åç´å¤±æ",description:e?.message||"è«ç¨å¾å試ã"})}finally{M(!1)}}},[ee,X,v,S,l,t]),er=(0,i.useCallback)(async e=>{let a,r=await p((a=e.email||e.uid,{type:"warning",title:"ç§»é¤é¡§åæ¬é",description:`æ¨å³å°ç§»é¤ ${a} ç顧忬éãç¨æ¶å°æ¢å¾©çºä¸è¬ç¨æ¶ã`,confirmText:"確èªç§»é¤",cancelText:"åæ¶",details:["ç¨æ¶è§è²å°è®æ´çºä¸è¬ç¨æ¶","é¡§åè³æå°æ¨è¨çºå·²åç¨","ç¨æ¶å°ç¡æ³åæ¥åé ç´","ç¨æ¶å°æ¶å°éç¥","æ¤æä½æè¨éå¨å¯©è¨æ¥èªä¸"],requiresReason:!0}));if(!r.confirmed)return;let i=r.reason||v;if(!i||!i.trim())return void l({variant:"destructive",title:"æä½å¤±æ",description:"è«å¡«å¯«ç§»é¤åå ã"});H(!0);try{let{httpsCallable:a}=await Promise.resolve().then(s.bind(s,71931)),{functions:r,auth:n}=await Promise.resolve().then(s.bind(s,76458));if(!r)throw Error("Firebase Functions æªåå§å");if(n&&n.currentUser){let e=await n.currentUser.getIdToken(!0);(0,O.fH)("ID Token 已巿°:",e?"æå":"失æ")}else throw(0,O.vV)("ç¡æ³ç²åç¶å使ç¨è
"),Error("ç¡æ³ç²åç¶å使ç¨è
");let d=a(r,"demoteAdvisorToUser");await d({uid:e.uid,reason:i.trim()}),S&&ec.logUserRoleChange(S.uid,S.email||"",e.uid,e.email,"user"),l({title:"â
ç§»é¤æå",description:`å·²æåç§»é¤ ${e.email} ç顧忬éãç¨æ¶å·²æ¢å¾©çºä¸è¬ç¨æ¶ã`}),t()}catch(e){(0,O.vV)("ç§»é¤é¡§åæ¬éé¯èª¤:",e),e?.code==="unauthenticated"||e?.message?.includes("401")?l({variant:"destructive",title:"身份é©è失æ",description:"è«éæ°ç»å
¥å¾å試ã"}):e?.code==="invalid-argument"&&e?.message?.includes("Reason")?l({variant:"destructive",title:"æä½å¤±æ",description:"è«å¡«å¯«ç§»é¤åå ã"}):l({variant:"destructive",title:"ç§»é¤å¤±æ",description:e?.message||"è«ç¨å¾å試ã"})}finally{H(!1)}},[p,v,S,l,t]),ei=async()=>{let e;if(!$||!F)return void l({variant:"destructive",title:"éè¨å¤±æ",description:"è«é¸æä½¿ç¨è
並輸å
¥æ°å¯ç¢¼ã"});if((await p((e=$.email,{type:"warning",title:"éè¨ç¨æ¶å¯ç¢¼",description:`æ¨å³å°éè¨ ${e} çå¯ç¢¼ãç¨æ¶å°éè¦æ°å¯ç¢¼æè½ç»å
¥ã`,confirmText:"確èªéè¨",cancelText:"åæ¶",details:["ç¨æ¶å°æ¶å°æ°å¯ç¢¼éç¥","èå¯ç¢¼å°ç«å³å¤±æ","建è°éç¥ç¨æ¶æ°å¯ç¢¼"],requiresReason:!0}))).confirmed){if(!Object.values({minLength:F.length>=8,hasUpperCase:/[A-Z]/.test(F),hasLowerCase:/[a-z]/.test(F),hasNumber:/\d/.test(F),hasSpecialChar:/[!@#$%^&*(),.?":{}|<>]/.test(F)}).every(Boolean))return void l({variant:"destructive",title:"å¯ç¢¼æ ¼å¼é¯èª¤",description:"æ°å¯ç¢¼å¿
é ç¬¦åæææ ¼å¼è¦æ±ï¼è³å° 8 ååå
ãå
å«å¤§
1å°å¯«åæ¯ãæ¸ååç¹æ®åå
ã"});P(!0);try{let{httpsCallable:e}=await Promise.resolve().then(s.bind(s,71931)),{functions:a,auth:r}=await Promise.resolve().then(s.bind(s,76458));if(!a)throw Error("Firebase Functions æªåå§å");if(r&&r.currentUser){let e=await r.currentUser.getIdToken(!0);(0,O.fH)("ID Token 已巿°:",e?"æå":"失æ")}else throw(0,O.vV)("ç¡æ³ç²åç¶å使ç¨è
"),Error("ç¡æ³ç²åç¶å使ç¨è
");let i=e(a,"resetUserPassword");await i({uid:$.uid,newPassword:F,reason:U}),S&&ec.logPasswordReset(S.uid,S.email||"",$.uid,$.email),l({title:"â
å¯ç¢¼éè¨æå",description:`å·²æåçº ${$.email} éè¨å¯ç¢¼ãæ°å¯ç¢¼å·²çæï¼ä½¿ç¨è
䏿¬¡ç»å
¥æéè¦ä½¿ç¨æ°å¯ç¢¼ã`}),I(!1),R(null),_(""),B(""),t()}catch(e){(0,O.vV)("éè¨å¯ç¢¼é¯èª¤:",e),e?.code==="unauthenticated"||e?.message?.includes("401")?l({variant:"destructive",title:"身份é©è失æ",description:"è«éæ°ç»å
¥å¾å試ã"}):l({variant:"destructive",title:"éè¨å¤±æ",description:e?.message||"è«ç¨å¾å試ã"})}finally{P(!1)}}};return(0,r.jsxs)("div",{className:"space-y-6",children:[(0,r.jsx)(K,{filters:n,onFiltersChange:h,onReset:x,totalCount:c,isSearching:o}),(0,r.jsx)(en,{users:d,onUserSelect:e=>{R(e),I(!0)},onResetPassword:e=>{R(e),I(!0)},onViewUser:a,onPromoteToAdvisor:es,onDemoteFromAdvisor:er,isLoading:o}),(0,r.jsx)("div",{className:"grid gap-4",style:{display:"none"},children:e.map(e=>(0,r.jsx)(y.Zp,{children:(0,r.jsx)(y.Wu,{className:"p-4",children:(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsxs)("div",{className:"space-y-1",children:[(0,r.jsx)("p",{className:"font-medium",children:e.email}),(0,r.jsxs)("p",{className:"text-sm text-muted-foreground",children:["註åæé: ",new Date(e.createdAt).toLocaleDateString("zh-TW"),e.lastSignInTime&&` | æå¾ç»å
¥: ${new Date(e.lastSignInTime).toLocaleDateString("zh-TW")}`]}),(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(N.E,{variant:e.emailVerified?"default":"secondary",children:e.emailVerified?"å·²é©è":"æªé©è"}),e.displayName&&(0,r.jsx)(N.E,{variant:"outline",children:e.displayName}),"admin"===e.role&&(0,r.jsx)(N.E,{variant:"destructive",children:"管çå¡"})]})]}),(0,r.jsx)("div",{className:"flex gap-2",children:(0,r.jsx)(b.$,{variant:"outline",onClick:()=>{R(e),I(!0)},children:"éè¨å¯ç¢¼"})})]})})},e.uid))}),(0,r.jsx)(z.lG,{open:T,onOpenChange:I,children:(0,r.jsxs)(z.Cf,{className:"sm:max-w-[500px]",children:[(0,r.jsxs)(z.c7,{children:[(0,r.jsx)(z.L3,{children:"éè¨ä½¿ç¨è
å¯ç¢¼"}),(0,r.jsxs)(z.rr,{children:["çº ",$?.email," éè¨å¯ç¢¼"]})]}),(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w.J,{htmlFor:"new-password",children:"æ°å¯ç¢¼"}),(0,r.jsx)(W.p,{id:"new-password",type:"password",autoComplete:"new-password",value:F,onChange:e=>_(e.target.value),placeholder:"è«è¼¸å
¥æ°å¯ç¢¼ï¼è³å° 8 ååå
ï¼"}),(0,r.jsxs)("div",{className:"text-sm text-muted-foreground space-y-1",children:[(0,r.jsx)("p",{className:"font-medium",children:"å¯ç¢¼æ ¼å¼è¦æ±ï¼"}),(0,r.jsxs)("ul",{className:"list-disc list-inside space-y-0.5",children:[(0,r.jsx)("li",{className:F.length>=8?"text-green-600":"text-gray-500",children:"â è³å° 8 ååå
"}),(0,r.jsx)("li",{className:/[A-Z]/.test(F)?"text-green-600":"text-gray-500",children:"â å
å«å¤§å¯«åæ¯"}),(0,r.jsx)("li",{className:/[a-z]/.test(F)?"text-green-600":"text-gray-500",children:"â å
å«å°å¯«åæ¯"}),(0,r.jsx)("li",{className:/\d/.test(F)?"text-green-600":"text-gray-500",children:"â å
嫿¸å"}),(0,r.jsx)("li",{className:/[!@#$%^&*(),.?":{}|<>]/.test(F)?"text-green-600":"text-gray-500",children:"â å
å«ç¹æ®åå
"})]})]})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w.J,{htmlFor:"reset-reason",children:"éè¨åå "}),(0,r.jsx)(V.T,{id:"reset-reason",value:U,onChange:e=>B(e.target.value),placeholder:"è«èªªæéè¨å¯ç¢¼çåå ï¼é¸å¡«ï¼",rows:3})]})]}),(0,r.jsxs)(z.Es,{children:[(0,r.jsx)(b.$,{variant:"outline",onClick:()=>I(!1),children:"åæ¶"}),(0,r.jsx)(b.$,{onClick:ei,disabled:D||!F||F.length<8,children:D?"éè¨ä¸...":"éè¨å¯ç¢¼"})]})]})}),(0,r.jsx)(z.lG,{open:q,onOpenChange:G,children:(0,r.jsxs)(z.Cf,{className:"sm:max-w-[500px]",children:[(0,r.jsxs)(z.c7,{children:[(0,r.jsx)(z.L3,{children:"åç´çºé¡§å - 輸å
¥é¡§åå§å"}),(0,r.jsxs)(z.rr,{children:["æ£å¨çº ",ee?.email," è¨å®é¡§åè³æ"]})]}),(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)(k.Fc,{children:[(0,r.jsx)(E.A,{className:"h-4 w-4"}),(0,r.jsxs)(k.TN,{children:["è«è¼¸å
¥é¡§åçç實å§åï¼æ¤å§åå°é¡¯ç¤ºå¨é¡§åå表ä¸ã",(0,r.jsx)("br",{}),(0,r.jsx)("strong",{children:"注æï¼"}),"å§åä¸è½å
å« @ ç¬¦èæ Email å°åã"]})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w.J,{htmlFor:"advisor-name",children:"é¡§åå§å *"}),(0,r.jsx)(W.p,{id:"advisor-name",type:"text",value:X,onChange:e=>Q(e.target.value),placeholder:"è«è¼¸å
¥é¡§åçç實å§å",autoFocus:!0,onKeyDown:e=>{"Enter"===e.key&&X&&!X.includes("@")&&ea()}}),X&&X.includes("@")&&(0,r.jsx)("p",{className:"text-sm text-red-500",children:"â ï¸ å§åä¸è½å
å« @ 符è"}),X&&!X.trim()&&(0,r.jsx)("p",{className:"text-sm text-red-500",children:"â ï¸ å§åä¸è½çºç©º"})]})]}),(0,r.jsxs)(z.Es,{children:[(0,r.jsx)(b.$,{variant:"outline",onClick:()=>{G(!1),et(null),Q("")},children:"åæ¶"}),(0,r.jsx)(b.$,{onClick:ea,disabled:!X||!X.trim()||X.includes("@")||L,children:L?"åç´ä¸...":"確èªåç´"})]})]})}),g&&(0,r.jsx)(Y,{isOpen:j,onClose:C,onConfirm:async e=>{if(g){if(g.requiresReason&&(!e||!e.trim()))return void l({variant:"destructive",title:"æä½å¤±æ",description:"è«å¡«å¯«ç§»é¤åå ã"});void 0!==e&&A(e),g.__resolve&&g.__resolve({confirmed:!0,reason:e||v})}},action:g,isLoading:f,reason:v,onReasonChange:A})]})}
1var eu=s(60373),em=s(18569),eh=s(57321),ex=s(90508),ep=s(74265);function ej({advisors:e,onAdvisorUpdate:t,updateAdvisor:s,deleteAdvisor:a}){let{toast:l}=(0,u.dj)(),[n,d]=(0,i.useState)(null),[c,o]=(0,i.useState)(!1),[m,h]=(0,i.useState)(!1),x=(0,i.useRef)(null),p=(0,i.useCallback)(()=>{d(null)},[]),j=(0,i.useCallback)(e=>{d(e)},[]),g=(0,i.useCallback)(async e=>{if(!n)return void l({variant:"destructive",title:"æä½å¤±æ",description:"è«é¸æè¦ç·¨è¼¯çé¡§åã"});try{o(!0);let a={name:e.name,company:e.company||"",officeAddress:e.officeAddress||"",specialties:e.specialties,serviceAreas:e.serviceAreas,certifications:e.certifications||[],fee:e.fee,yearsOfExperience:e.yearsOfExperience||0,weeklySchedule:e.weeklySchedule||{},specificDates:e.specificDates||{},avatar:e.avatar,website:e.website||null,socialMedia:e.socialMedia.length>0?e.socialMedia:null,advanceBookingDays:e.advanceBookingDays,bookingWindowDays:e.bookingWindowDays,customerReviews:n?.customerReviews||[]};Object.keys(n).forEach(e=>{a.hasOwnProperty(e)||"id"===e||(a[e]=n[e])}),await s(n.id,a),l({title:"æ´æ°æåï¼",description:"é¡§åè³æå·²æåæ´æ°ã"}),p(),t()}catch(e){throw(0,O.vV)("å²åé¡§åæç¼çé¯èª¤:",e),l({variant:"destructive",title:"æä½å¤±æ",description:"系統ç¼çé¯èª¤ï¼è«ç¨å¾å試ã"}),e}finally{o(!1)}},[n,s,t,p,l]),f=(0,i.useCallback)(async()=>{if(n)try{h(!0),await a(n.id),l({title:"åªé¤æåï¼",description:"é¡§åè³æå·²æååªé¤ã"}),p(),t()}catch(e){throw(0,O.vV)("åªé¤é¡§åæç¼çé¯èª¤:",e),l({variant:"destructive",title:"åªé¤å¤±æ",description:e instanceof Error?e.message:"系統ç¼çé¯èª¤ï¼è«ç¨å¾å試ã"}),e}finally{h(!1)}},[n,a,t,p,l]);return(0,r.jsxs)("div",{className:"space-y-6",children:[(0,r.jsx)("div",{className:"flex flex-col justify-between gap-4 sm:flex-row sm:items-center",children:(0,r.jsx)("div",{className:"flex flex-wrap gap-2"})}),n&&(0,r.jsxs)(y.Zp,{className:"mt-6",children:[(0,r.jsx)(y.aR,{children:(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(y.ZB,{children:"編輯顧å"}),(0,r.jsx)(y.BT,{children:"ä¿®æ¹é¡§åè³æ"})]}),(0,r.jsx)(b.$,{variant:"ghost",size:"sm",onClick:()=>d(null),children:(0,r.jsx)(X.A,{className:"h-4 w-4"})})]})}),(0,r.jsx)(y.Wu,{children:(0,r.jsx)(ex.A,{ref:x,initialData:{name:n.name,company:n.company||"",officeAddress:n.officeAddress||"",specialties:n.specialties,serviceAreas:n.serviceAreas,certifications:n.certifications||[],fee:n.fee,yearsOfExperience:n.yearsOfExperience||0,weeklySchedule:n.weeklySchedule||{},specificDates:n.specificDates||{},avatar:n.avatar,website:n.website||"",socialMedia:n.socialMedia||[],advanceBookingDays:n.advanceBookingDays??ep.X.ADVANCE_BOOKING_DAYS,bookingWindowDays:n.bookingWindowDays??ep.X.BOOKING_WINDOW_DAYS,userId:n.userId,id:n.id},userId:n?.userId,onSave:g,onDelete:f,showDeleteButton:!0,isDeleting:m,showCancelButton:!0,onCancel:()=>d(null),isSaving:c,avatarInputId:"admin-avatar"})})]}),(0,r.jsx)("div",{className:"grid gap-6 md:grid-cols-2 lg:grid-cols-3",children:e.map(e=>{let t,s;return(0,r.jsxs)(y.Zp,{className:(0,R.cn)("overflow-hidden cursor-pointer transition-all",n?.id===e.id&&"ring-2 ring-primary"),onClick:()=>j(e),children:[(0,r.jsx)(y.aR,{className:"pb-3",children:(0,r.jsxs)("div",{className:"flex items-start justify-between",children:[(0,r.jsxs)("div",{className:"flex items-center gap-3",children:[(0,r.jsxs)(eu.eu,{className:"h-11 w-11",children:[(0,r.jsx)(eu.BK,{src:e.avatar,alt:e.name}),(0,r.jsx)(eu.q5,{children:e.name.substring(0,2)})]}),(0,r.jsx)("div",{children:(0,r.jsx)(y.ZB,{className:"text-base",children:e.name})})]}),(0,r.jsxs)(N.E,{variant:"outline",className:"flex items-center gap-1",children:[(0,r.jsx)(A.A,{className:"h-3 w-3 fill-yellow-400 text-yellow-400"}),e.rating]})]})}),(0,r.jsx)(y.Wu,{className:"pb-3",children:(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsx)("div",{className:"flex flex-wrap gap-1.5",children:e.specialties.map((e,t)=>(0,r.jsx)(N.E,{variant:"secondary",className:"text-xs",children:e},t))}),(0,r.jsxs)("div",{className:"grid grid-cols-1 gap-2 text-sm",children:[(0,r.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,r.jsx)(em.A,{className:"h-3.5 w-3.5 text-muted-foreground"}),(0,r.jsx)("span",{className:"text-muted-foreground",children:"æåå°å:"}),(0,r.jsx)("span",{className:"font-medium",children:e.serviceAreas.join(", ")})]}),(0,r.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,r.jsx)(eh.A,{className:"h-3.5 w-3.5 text-muted-foreground"}),(0,r.jsx)("span",{className:"text-muted-foreground",children:"諮詢費ç¨:"}),(0,r.jsx)("span",{className:"font-medium",children:e.fee})]}),(0,r.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,r.jsx)(ei.A,{className:"h-3.5 w-3.5 text-muted-foreground"}),(0,r.jsx)("span",{className:"text-muted-foreground",children:"å¯é ç´æé:"}),(0,r.jsx)("span",{className:"font-medium",children:(t=e.weeklySchedule&&Object.values(e.weeklySchedule).some(e=>Array.isArray(e)&&e.length>0),s=e.specificDates&&Object.values(e.specificDates).some(e=>Array.isArray(e)&&e.length>0),t||s?"å·²è¨å®":"æªè¨å®")})]})]})]})})]},e.id)})})]})}var eg=s(2962),ef=s(85183),ev=s(98896),ey=s(22573),eb=s(14022);function ew({tier:e="rookie",size:t="medium",className:s}){let a=(0,eb.getTierConfig)(e);return(0,r.jsx)(N.E,{className:(0,R.cn)("font-semibold border-2",{small:"text-xs px-2 py-0.5",medium:"text-sm px-2.5 py-1",large:"text-base px-3 py-1.5"}[t],s),style:{backgroundColor:`${a.color}20`,borderColor:a.color,color:a.color},children:a.name})}function eN(){let{toast:e}=(0,u.dj)(),{user:t}=(0,m.A)(),[s,a]=(0,i.useState)([]),[l,n]=(0,i.useState)([]),[d,c]=(0,i.useState)(!0),[o,h]=(0,i.useState)(""),[x,p]=(0,i.useState)("all"),[g,f]=(0,i.useState)(null),[v,k]=(0,i.useState)(!1),[A,S]=(0,i.useState)(!1),[T,I]=(0,i.useState)(!1),[E,R]=(0,i.useState)(!1),[D,P]=(0,i.useState)("rookie"),[F,O]=(0,i.useState)([]),[U,B]=(0,i.useState)({}),L=(0,i.useCallback)(async()=>{try{if(c(!0),!j.db){a([]),n([]),B({}),c(!1);return}let e=await (0,_.GG)((0,_.P)((0,_.rJ)(j.db,"advisors"),(0,_.My)("name"))),t=[],s=await (0,_.GG)((0,_.rJ)(j.db,"users")),r=new Map;
1s.forEach(e=>{let t=e.data(),s=t?.role?.toLowerCase();"admin"===s&&t?.email&&r.set(t.email,"admin")}),e.forEach(e=>{let s=e.data(),a=s.tier||"rookie";s.email&&r.has(s.email)&&(a="gm"),t.push({id:e.id,name:s.name||"",email:s.email||"",tier:a,tierStats:s.tierStats||{totalConsultations:0,uniqueClients:0,averageRating:0,totalReviews:0},tierUpdatedAt:s.tierUpdatedAt?.toDate?.()?.toISOString(),fee:s.fee||0,rating:s.rating||0,reviews:s.reviews||0})}),a(t),n(t);let i={};t.forEach(e=>{let t=e.tier||"rookie";i[t]=(i[t]||0)+1}),B(i)}catch(t){console.error("è¼å
¥é¡§åè³æå¤±æ:",t),e({variant:"destructive",title:"è¼å
¥å¤±æ",description:"ç¡æ³è¼å
¥é¡§åè³æï¼è«ç¨å¾å試ã"})}finally{c(!1)}},[e]);(0,i.useEffect)(()=>{L()},[L]),(0,i.useEffect)(()=>{let e=[...s];if(o){let t=o.toLowerCase();e=e.filter(e=>e.name.toLowerCase().includes(t)||e.email?.toLowerCase().includes(t))}"all"!==x&&(e=e.filter(e=>e.tier===x)),n(e)},[s,o,x]);let Y=(0,i.useCallback)(async(s,a)=>{if(t)try{R(!0);let r=await t.getIdToken(),i=await fetch("/api/admin/advisor-tier",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`},body:JSON.stringify({action:"assign",advisorId:s,tier:a})});if(!i.ok){let e=await i.json();throw Error(e.error||"ææ´¾çç´å¤±æ")}e({title:"ææ´¾æå",description:"çç´å·²æåææ´¾ã"}),k(!1),f(null),await L()}catch(t){console.error("ææ´¾çç´å¤±æ:",t),e({variant:"destructive",title:"ææ´¾å¤±æ",description:t.message||"ç¡æ³ææ´¾çç´ï¼è«ç¨å¾å試ã"})}finally{R(!1)}},[t,e,L]),J=(0,i.useCallback)(async s=>{if(t)try{I(!0);let a=await t.getIdToken(),r=await fetch("/api/admin/advisor-tier",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({action:"recalculate",advisorId:s})});if(!r.ok){let e=await r.json();throw Error(e.error||"éæ°è¨ç®å¤±æ")}e({title:"è¨ç®å®æ",description:"çç´å·²éæ°è¨ç®ã"}),await L()}catch(t){console.error("éæ°è¨ç®çç´å¤±æ:",t),e({variant:"destructive",title:"è¨ç®å¤±æ",description:t.message||"ç¡æ³éæ°è¨ç®çç´ï¼è«ç¨å¾å試ã"})}finally{I(!1)}},[t,e,L]),M=(0,i.useCallback)(async s=>{if(t)try{let e=await t.getIdToken(),a=await fetch(`/api/admin/advisor-tier/history?advisorId=${s}`,{headers:{Authorization:`Bearer ${e}`}});if(!a.ok)throw Error("è¼å
¥æ·å²å¤±æ");let r=await a.json();O(r.history||[])}catch(t){console.error("è¼å
¥çç´æ·å²å¤±æ:",t),e({variant:"destructive",title:"è¼å
¥å¤±æ",description:"ç¡æ³è¼å
¥çç´æ·å²ï¼è«ç¨å¾å試ã"})}},[t,e]),V=(0,i.useCallback)(async e=>{f(e),S(!0),await M(e.id)},[M]);return(0,i.useEffect)(()=>{g&&v&&P(g.tier||"rookie")},[g,v]),(0,r.jsxs)("div",{className:"space-y-6",children:[(0,r.jsxs)(y.Zp,{children:[(0,r.jsx)(y.aR,{children:(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(y.ZB,{children:"é¡§åçç´ç®¡ç"}),(0,r.jsx)(y.BT,{children:"ç®¡çææé¡§åççç´ãæ¥ççµ±è¨åæ·å²è¨é"})]}),(0,r.jsxs)(b.$,{onClick:L,disabled:d,variant:"outline",children:[(0,r.jsx)(ef.A,{className:`h-4 w-4 mr-2 ${d?"animate-spin":""}`}),"éæ°æ´ç"]})]})}),(0,r.jsxs)(y.Wu,{children:[(0,r.jsxs)("div",{className:"flex flex-col md:flex-row gap-4 mb-6",children:[(0,r.jsxs)("div",{className:"flex-1 relative",children:[(0,r.jsx)(G.A,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground"}),(0,r.jsx)(W.p,{placeholder:"æå°é¡§åå稱æ Email...",value:o,onChange:e=>h(e.target.value),className:"pl-10"})]}),(0,r.jsxs)(Z.l6,{value:x,onValueChange:e=>p(e),children:[(0,r.jsx)(Z.bq,{className:"w-full md:w-[200px]",children:(0,r.jsx)(Z.yv,{placeholder:"鏿çç´"})}),(0,r.jsxs)(Z.gC,{children:[(0,r.jsx)(Z.eb,{value:"all",children:"ææçç´"}),(0,eb.nU)().map(e=>(0,r.jsx)(Z.eb,{value:e.id,children:e.name},e.id))]})]})]}),d?(0,r.jsx)($.default,{className:"py-8",size:64}):0===l.length?(0,r.jsx)("div",{className:"text-center py-8 text-muted-foreground",children:"æ²ææ¾å°ç¬¦åæ¢ä»¶çé¡§å"}):(0,r.jsx)("div",{className:"border rounded-lg overflow-hidden",children:(0,r.jsxs)(eg.XI,{children:[(0,r.jsx)(eg.A0,{children:(0,r.jsxs)(eg.Hj,{children:[(0,r.jsx)(eg.nd,{children:"é¡§åå稱"}),(0,r.jsx)(eg.nd,{children:"Email"}),(0,r.jsx)(eg.nd,{children:"ç¶åçç´"}),(0,r.jsx)(eg.nd,{children:"å®¢æ¶æ¸"}),(0,r.jsx)(eg.nd,{children:"è©å¹"}),(0,r.jsx)(eg.nd,{children:"广 ¼"}),(0,r.jsx)(eg.nd,{children:"æå¾æ´æ°"}),(0,r.jsx)(eg.nd,{className:"text-right",children:"æä½"})]})}),(0,r.jsx)(eg.BF,{children:l.map(e=>(0,r.jsxs)(eg.Hj,{children:[(0,r.jsx)(eg.nA,{className:"font-medium",children:e.name}),(0,r.jsx)(eg.nA,{className:"text-sm text-muted-foreground",children:e.email||"-"}),(0,r.jsx)(eg.nA,{children:(0,r.jsx)(ew,{tier:e.tier||"rookie",size:"small"})}),(0,r.jsx)(eg.nA,{children:(0,r.jsxs)("div",{className:"flex items-center gap-1",children:[(0,r.jsx)(C.A,{className:"h-3 w-3 text-muted-foreground"}
1),e.tierStats?.uniqueClients||0]})}),(0,r.jsx)(eg.nA,{children:(0,r.jsxs)("div",{className:"flex items-center gap-1",children:[(0,r.jsx)("span",{children:e.tierStats?.averageRating.toFixed(1)||e.rating.toFixed(1)}),(0,r.jsxs)("span",{className:"text-muted-foreground text-sm",children:["(",e.tierStats?.totalReviews||e.reviews,")"]})]})}),(0,r.jsxs)(eg.nA,{children:["NT$ ",e.fee.toLocaleString()]}),(0,r.jsx)(eg.nA,{className:"text-sm text-muted-foreground",children:e.tierUpdatedAt?new Date(e.tierUpdatedAt).toLocaleDateString("zh-TW"):"-"}),(0,r.jsx)(eg.nA,{className:"text-right",children:(0,r.jsxs)("div",{className:"flex items-center justify-end gap-2",children:["gm"!==e.tier&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(b.$,{variant:"outline",size:"sm",onClick:()=>{f(e),k(!0)},children:[(0,r.jsx)(ev.A,{className:"h-3 w-3 mr-1"}),"ææ´¾çç´"]}),(0,r.jsxs)(b.$,{variant:"outline",size:"sm",onClick:()=>J(e.id),disabled:T,children:[(0,r.jsx)(ef.A,{className:`h-3 w-3 mr-1 ${T?"animate-spin":""}`}),"éæ°è¨ç®"]})]}),(0,r.jsxs)(b.$,{variant:"outline",size:"sm",onClick:()=>V(e),children:[(0,r.jsx)(ey.A,{className:"h-3 w-3 mr-1"}),"æ·å²"]})]})})]},e.id))})]})})]})]}),(0,r.jsx)(z.lG,{open:v,onOpenChange:e=>{k(e),e||(f(null),P("rookie"))},children:(0,r.jsxs)(z.Cf,{children:[(0,r.jsxs)(z.c7,{children:[(0,r.jsx)(z.L3,{children:"ææ´¾çç´"}),(0,r.jsxs)(z.rr,{children:["çºé¡§å ",(0,r.jsx)("strong",{children:g?.name})," æåææ´¾çç´"]})]}),(0,r.jsxs)("div",{className:"space-y-4 py-4",children:[(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w.J,{children:"鏿çç´"}),(0,r.jsxs)(Z.l6,{value:D,onValueChange:e=>P(e),defaultValue:g?.tier||"rookie",children:[(0,r.jsx)(Z.bq,{children:(0,r.jsx)(Z.yv,{})}),(0,r.jsx)(Z.gC,{children:(0,eb.nU)().map(e=>(0,r.jsx)(Z.eb,{value:e.id,children:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)(ew,{tier:e.id,size:"small"}),(0,r.jsx)("span",{children:e.name})]})},e.id))})]})]}),(0,r.jsx)("div",{className:"text-sm text-muted-foreground",children:(0,r.jsx)("p",{children:"注æï¼æåææ´¾ççç´ä¸æèªåæ´æ°ï¼é¤é管çå¡åæ¬¡ä¿®æ¹æéæ°è¨ç®ã"})})]}),(0,r.jsxs)(z.Es,{children:[(0,r.jsx)(b.$,{variant:"outline",onClick:()=>k(!1),disabled:E,children:"åæ¶"}),(0,r.jsx)(b.$,{onClick:()=>{g&&Y(g.id,D)},disabled:E,children:E?"ææ´¾ä¸...":"ç¢ºèªææ´¾"})]})]})}),(0,r.jsx)(z.lG,{open:A,onOpenChange:S,children:(0,r.jsxs)(z.Cf,{className:"max-w-2xl",children:[(0,r.jsxs)(z.c7,{children:[(0,r.jsx)(z.L3,{children:"çç´æ·å²è¨é"}),(0,r.jsxs)(z.rr,{children:["é¡§å ",(0,r.jsx)("strong",{children:g?.name})," ççç´è®æ´æ·å²"]})]}),(0,r.jsx)("div",{className:"max-h-[500px] overflow-y-auto",children:0===F.length?(0,r.jsx)("div",{className:"text-center py-8 text-muted-foreground",children:"å°ç¡æ·å²è¨é"}):(0,r.jsx)("div",{className:"space-y-4",children:F.map((e,t)=>(0,r.jsx)(y.Zp,{children:(0,r.jsxs)(y.Wu,{className:"pt-4",children:[(0,r.jsxs)("div",{className:"flex items-start justify-between",children:[(0,r.jsxs)("div",{className:"flex items-center gap-3",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[e.fromTier?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(ew,{tier:e.fromTier,size:"small"}),(0,r.jsx)("span",{className:"text-muted-foreground",children:"â"})]}):null,(0,r.jsx)(ew,{tier:e.toTier,size:"small"})]}),(0,r.jsx)(N.E,{variant:"auto"===e.reason?"default":"secondary",children:"auto"===e.reason?"èªå":"æå"})]}),(0,r.jsx)("div",{className:"text-right text-sm text-muted-foreground",children:new Date(e.createdAt).toLocaleString("zh-TW")})]}),e.changedBy&&(0,r.jsxs)("div",{className:"mt-2 text-xs text-muted-foreground",children:["æä½è
: ",e.changedBy]})]})},e.id))})})]})})]})}var ek=s(3208);function eC({suggestions:e,onSuggestionUpdate:t,updateSuggestionStatus:s,deleteSuggestion:a}){let{toast:l}=(0,u.dj)(),n=(0,i.useCallback)(async(e,a)=>{try{await s(e,a),l({title:"çæ
å·²æ´æ°"}),t()}catch(e){l({variant:"destructive",title:"çæ
æ´æ°å¤±æ",description:e instanceof Error?e.message:"è«ç¨å¾å試ã"})}},[l,t,s]),d=(0,i.useCallback)(async e=>{try{await a(e),l({title:"建è°å·²åªé¤"}),t()}catch(e){l({variant:"destructive",title:"åªé¤å¤±æ",description:e instanceof Error?e.message:"ç¡æ³åªé¤å»ºè°ï¼è«ç¨å¾å試ã"})}},[l,t,a]);return(0,r.jsx)("div",{className:"mt-2",children:(0,r.jsx)("div",{className:"overflow-x-auto",children:(0,r.jsxs)("table",{className:"min-w-full text-sm border border-gray-700 rounded-lg bg-background/80",children:[(0,r.jsx)("thead",{className:"bg-muted",children:(0,r.jsxs)("tr",{children:[(0,r.jsx)("th",{className:"px-4 py-2 text-left font-semibold",children:"建è°é¡å"}),(0,r.jsx)("th",{className:"px-4 py-2 text-left font-semibold",children:"çæ
"}),(0,r.jsx)("th",{className:"px-4 py-2 text-left font-semibold",children:"æè¿°"}),(0,r.jsx)("th",{className:"px-4 py-2 text-left font-semibold",children:"ä½è
"}),(0,r.jsx)("th",{className:"px-4 py-2 text-left font-semibold",children:"æ¥æ"}),(0,r.jsx)("th",{className:"px-4 py-2 text-left font-semibold",children:"æä½"})]})}),(0,r.jsxs)("tbody",{children:[0===e.length&&(0,r.jsx)("tr",{children:(0,r.jsx)("td",{colSpan:6,className:"text-center text-muted-foreground py-4",children:"ç®åæ²æå»ºè°"})}),e.map(e=>(0,r.jsxs)("tr",{className:"border-b border-gray-700 hover:bg-muted/50 transition",children:[(0,r.jsx)("td",{className:"px-4 py-2",children:"feature"===e.type?"æ°åè½":"improvement"===e.type?"æ¹å":"é¯
1誤"}),(0,r.jsx)("td",{className:"px-4 py-2",children:(0,r.jsxs)(Z.l6,{value:e.status||"pending",onValueChange:t=>n(e.id,t),children:[(0,r.jsx)(Z.bq,{id:`status-select-${e.id}`,className:"w-24 cursor-pointer",children:(0,r.jsx)(Z.yv,{placeholder:"å¾
èç"})}),(0,r.jsxs)(Z.gC,{children:[(0,r.jsx)(Z.eb,{value:"pending",children:"å¾
èç"}),(0,r.jsx)(Z.eb,{value:"planned",children:"è¦åä¸"}),(0,r.jsx)(Z.eb,{value:"in_progress",children:"é²è¡ä¸"}),(0,r.jsx)(Z.eb,{value:"done",children:"已宿"})]})]})}),(0,r.jsxs)("td",{className:"px-4 py-2 break-words max-w-xs",children:[e.description?.slice(0,50),e.description?.length>50?"...":""]}),(0,r.jsxs)("td",{className:"px-4 py-2 flex items-center gap-2",children:[(0,r.jsx)(eu.eu,{className:"h-5 w-5",children:(0,r.jsx)(eu.q5,{children:e.author?.[0]})}),(0,r.jsx)("span",{children:e.author})]}),(0,r.jsx)("td",{className:"px-4 py-2",children:e.date}),(0,r.jsx)("td",{className:"px-4 py-2",children:(0,r.jsx)(ek.j,{ariaLabel:`å»ºè°æä½ï¼${e.id}`,items:[{id:"delete",label:"åªé¤",icon:B.A,destructive:!0,onSelect:()=>d(e.id)}]})})]},e.id))]})]})})})}var eA=s(11787),eS=s(8643);function eT(){let{logs:e,filters:t,isLoading:s,totalCount:a,loadLogs:l,updateFilters:n,resetFilters:d,exportLogs:c,clearLogs:o}=function(){let{user:e}=(0,m.A)(),[t,s]=(0,i.useState)([]),[a,r]=(0,i.useState)(!1),[l,n]=(0,i.useState)(0),[d,c]=(0,i.useState)({dateRange:{start:new Date(Date.now()-2592e6).toISOString().split("T")[0],end:new Date().toISOString().split("T")[0]},action:"all",targetType:"all",result:"all",userId:""}),o=(0,i.useCallback)(async()=>{if(e){r(!0);try{let t=new URLSearchParams;d.dateRange.start&&t.append("startDate",d.dateRange.start),d.dateRange.end&&t.append("endDate",d.dateRange.end),d.action&&"all"!==d.action&&t.append("action",d.action),t.append("limit","100"),t.append("offset","0");let a=await fetch(`/api/admin/logs?${t.toString()}`,{headers:{Authorization:`Bearer ${await e.getIdToken()}`,"Content-Type":"application/json"}});if(!a.ok)throw Error(`HTTP error! status: ${a.status}`);let r=await a.json(),i=r.logs.map(e=>({id:e.id,timestamp:e.timestamp,userId:e.adminUid,userEmail:"",action:e.action,targetType:"user",targetId:e.targetUid,targetName:e.targetUid,details:e.details,result:e.result,ipAddress:"",userAgent:""}));s(i),n(r.totalCount)}catch(e){s([]),n(0)}finally{r(!1)}}},[e,d]),u=(0,i.useCallback)(e=>{c(t=>({...t,...e}))},[]),h=(0,i.useCallback)(()=>{c({dateRange:{start:new Date(Date.now()-2592e6).toISOString().split("T")[0],end:new Date().toISOString().split("T")[0]},action:"",targetType:"",result:"",userId:""})},[]),x=(0,i.useCallback)(async()=>{try{let e=t.map(e=>`${e.timestamp},${e.userEmail},${e.action},${e.targetType},${e.details},${e.result}`).join("\n"),s=new Blob([e],{type:"text/csv"}),a=window.URL.createObjectURL(s),r=document.createElement("a");r.href=a,r.download=`audit-logs-${new Date().toISOString().split("T")[0]}.csv`,r.click(),window.URL.revokeObjectURL(a)}catch(e){}},[t]);return{logs:t,filters:d,isLoading:a,totalCount:l,loadLogs:o,updateFilters:u,resetFilters:h,exportLogs:x,clearLogs:(0,i.useCallback)(async()=>{try{s([]),n(0)}catch(e){}},[])}}();return(0,r.jsxs)("div",{className:"space-y-6",children:[(0,r.jsxs)(y.Zp,{children:[(0,r.jsx)(y.aR,{children:(0,r.jsxs)(y.ZB,{className:"flex items-center gap-2",children:[(0,r.jsx)(q.A,{className:"h-5 w-5"}),"æä½æ¥èªç¯©é¸"]})}),(0,r.jsxs)(y.Wu,{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:[(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w.J,{htmlFor:"dateStart",children:"éå§æ¥æ"}),(0,r.jsx)(W.p,{id:"dateStart",type:"date",value:t.dateRange.start,onChange:e=>n({dateRange:{...t.dateRange,start:e.target.value}})})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w.J,{htmlFor:"dateEnd",children:"çµææ¥æ"}),(0,r.jsx)(W.p,{id:"dateEnd",type:"date",value:t.dateRange.end,onChange:e=>n({dateRange:{...t.dateRange,end:e.target.value}})})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w.J,{htmlFor:"action",children:"æä½é¡å"}),(0,r.jsxs)(Z.l6,{value:t.action||"all",onValueChange:e=>n({action:e}),children:[(0,r.jsx)(Z.bq,{children:(0,r.jsx)(Z.yv,{placeholder:"鏿æä½é¡å"})}),(0,r.jsxs)(Z.gC,{children:[(0,r.jsx)(Z.eb,{value:"all",children:"å
¨é¨æä½"}),(0,r.jsx)(Z.eb,{value:"reset_user_password",children:"éè¨å¯ç¢¼"})]})]})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w.J,{htmlFor:"result",children:"æä½çµæ"}),(0,r.jsxs)(Z.l6,{value:t.result||"all",onValueChange:e=>n({result:e}),children:[(0,r.jsx)(Z.bq,{children:(0,r.jsx)(Z.yv,{placeholder:"é¸æçµæ"})}),(0,r.jsxs)(Z.gC,{children:[(0,r.jsx)(Z.eb,{value:"all",children:"å
¨é¨çµæ"}),(0,r.jsx)(Z.eb,{value:"success",children:"æå"}),(0,r.jsx)(Z.eb,{value:"failure",children:"失æ"}),(0,r.jsx)(Z.eb,{value:"warning",children:"è¦å"})]})]})]})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsxs)(b.$,{onClick:l,disabled:s,children:[(0,r.jsx)(G.A,{className:"h-4 w-4 mr-2"}),s?(0,r.jsx)(eA.A,{className:"h-4 w-4 animate-spin"}):"æå°æ¥èª"]}),(0,r.jsx)(b.$,{variant:"outline",onClick:d,children:"é置篩é¸"}),(0,r.jsxs)(b.$,{variant:"outline",onClick:c,children:[(0,r.jsx)(eS.A,{className:"h-4 w-4 mr-2"}),"å°åº"]}),(0,r.jsxs)(b.$,{variant:"destructive",onClick:o,children:[(0,r.jsx)(B.A,{className:"h-4 w-4 mr-2"}),"æ¸
餿¥èª"]})]})]})]}),(0,r.jsxs)(y.Zp,{children:[(0,r.jsx)(y.aR,{children:(0,r.jsxs)(y.ZB,{className:"flex items-center justify-between",children:[(0,r.jsxs)("span",{children:["æä½æ¥èª (",a,")"]}),(0,r.jsx)(N.E,{variant:"secondary",children:s?(0,r.jsx)(eA.A,{className:"h-4 w-4 animate-spin"}):`${e.length} æ¢è¨é`})]})}),(0,r.jsx)(y.Wu,{children:s?(0,r.jsx)("div",{className:"space-y-4",children:[void 0,void 0,void 0].map((e,t)=>(0,r.jsxs)("div",{className:"animate-pulse",children:[(0,r.jsx)("div",{className:"h-4 bg-gray-200 rounded w-3/4 mb-2"}),(0,r.jsx)("div",{className:"h-3 bg-gray-200 rounded w-1/2"})]},t))}):0===e.length?(0,r.jsxs)("div",{className:"text-center py-8",children:[(0,r.jsx)(ei.A,{className:"h-12 w-12 text-muted-foreground mx-auto mb-4"}),(0,r.jsx)("h3",{className:"text-lg font-medium mb-2",children:"æ²ææ¾å°æä½æ¥èª"}),(0,r.jsx)("p",{className:"text-muted-foreground",children:"è«èª¿æ´ç¯©é¸æ¢ä»¶æé¸æä¸åçæ¥æç¯å"})]}):(0,r.jsx)("div",{className:"space-y-4",children:e.map(e=>{var t;let s;return(0,r.jsx)("div",{className:"border rounded-lg p-4 hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors",children:(0,r.jsx)("div",{className:"flex items-start justify-between",children:(0,r.jsxs)("div",{className:"flex items-start space-x-3",children:["reset_user_password"===e.action?(0,r.jsx)(ee.A,{className:"h-4 w-4 text-orange-500"}):(0,r.jsx)(ei.A,{className:"h-4 w-4 text-gray-500"}),(0,r.jsxs)("div",{className:"flex-1",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,r.jsx)("h4",{className:"font-medium",children:e.details}),(e=>{switch(e){case"success":return(0,r.jsxs)(N.E,{variant:"default",className:"flex items-center gap-1",children:[(0,r.jsx)(et.A,{className:"h-3 w-3"}),"æå"]});case"failure":return(0,r.jsxs)(N.E,{variant:"destructive",className:"flex items-center gap-1",children:[(0,r.jsx)(es.A,{className:"h-3 w-3"}),"失æ"]});case"warning":return(0,r.jsxs)(N.E,{variant:"secondary",className:"flex items-center gap-1",children:[(0,r.jsx)(E.A,{className:"h-3 w-3"}),"è¦å"]});default:return(0,r.jsx)(N.E,{variant:"outline",children:e})}})(e.result),(t=e.targetType,s={user:"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200",admin:"bg-purple-100 text-purple-800 dark:bg-purple-900 dark:text-purple-200",system:"bg-gray-100 text-gray-800 dark:bg-gray-900 dark:text-gray-200",subscription:"bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200",payment:"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-200"},(0,r.jsx)(N.E,{className:s[t]||s.system,children:t}))]}),(0,r.jsxs)("div",{className:"text-sm text-muted-foreground space-y-1",children:[(0,r.jsxs)("div",{className:"flex items-center gap-4",children:[(0,r.jsxs)("span",{children:["æä½è
: ",e.userEmail]}),(0,r.jsxs)("span",{children:["æé: ",new Date(e.timestamp).toLocaleStr
1ing("zh-TW",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"})]})]}),e.targetName&&(0,r.jsxs)("div",{children:["ç®æ¨: ",e.targetName]}),e.errorMessage&&(0,r.jsxs)("div",{className:"text-red-600 dark:text-red-400",children:["é¯èª¤: ",e.errorMessage]})]})]})]})})},e.id)})})})]})]})}var eI=s(42119),eE=s(25450),e$=s(27703);let eR=[{name:e$.I.users,label:"usersï¼ç¨æ¶ï¼",access:"readWrite",columns:[{key:"email",label:"Email",kind:"text",widthClassName:"w-[260px]"},{key:"role",label:"è§è²",kind:"badge",widthClassName:"w-[110px]"},{key:"emailVerified",label:"å·²é©è",kind:"boolean",widthClassName:"w-[90px]"},{key:"createdAt",label:"å»ºç«æé",kind:"date",widthClassName:"w-[170px]"}],filters:[{key:"role",label:"è§è²",type:"select",options:[{label:"user",value:"user"},{label:"admin",value:"admin"},{label:"advisor",value:"advisor"}]},{key:"email",label:"Email",type:"text",placeholder:"宿´ Emailï¼ç弿¯å°ï¼"},{key:"emailVerified",label:"å·²é©è",type:"switch"}]},{name:e$.I.transactions,label:"transactionsï¼äº¤æï¼",access:"readWrite",columns:[{key:"userId",label:"userId",kind:"text",widthClassName:"w-[240px]"},{key:"type",label:"é¡å",kind:"badge",widthClassName:"w-[110px]"},{key:"amount",label:"éé¡",kind:"number",widthClassName:"w-[130px]"},{key:"date",label:"æ¥æ",kind:"date",widthClassName:"w-[150px]"}],filters:[{key:"userId",label:"userId",type:"text",placeholder:"宿´ userIdï¼ç弿¯å°ï¼"},{key:"type",label:"type",type:"select",options:[{label:"income",value:"income"},{label:"expense",value:"expense"}]},{key:"accountId",label:"accountId",type:"text",placeholder:"宿´ accountIdï¼ç弿¯å°ï¼"}]},{name:e$.I.accounts,label:"accountsï¼å¸³æ¶ï¼",access:"readWrite",columns:[{key:"userId",label:"userId",kind:"text",widthClassName:"w-[240px]"},{key:"name",label:"å稱",kind:"text",widthClassName:"w-[200px]"},{key:"type",label:"é¡å",kind:"badge",widthClassName:"w-[110px]"},{key:"balance",label:"é¤é¡",kind:"number",widthClassName:"w-[130px]"}],filters:[{key:"userId",label:"userId",type:"text",placeholder:"宿´ userIdï¼ç弿¯å°ï¼"},{key:"type",label:"type",type:"select",options:[{label:"income",value:"income"},{label:"expense",value:"expense"}]}]},{name:e$.I.bookings,label:"bookingsï¼é ç´ï¼",access:"readWrite",columns:[{key:"userId",label:"userId",kind:"text",widthClassName:"w-[240px]"},{key:"advisorId",label:"advisorId",kind:"text",widthClassName:"w-[240px]"},{key:"status",label:"çæ
",kind:"badge",widthClassName:"w-[130px]"},{key:"date",label:"æ¥æ",kind:"date",widthClassName:"w-[150px]"}],filters:[{key:"userId",label:"userId",type:"text"},{key:"advisorId",label:"advisorId",type:"text"},{key:"status",label:"status",type:"select",options:[{label:"draft",value:"draft"},{label:"pending",value:"pending"},{label:"authorized",value:"authorized"},{label:"paid",value:"paid"},{label:"cancelled",value:"cancelled"}]}]},{name:e$.I.advisors,label:"advisorsï¼é¡§åï¼",access:"readWrite",columns:[{key:"name",label:"å稱",kind:"text"},{key:"title",label:"é é",kind:"text"},{key:"fee",label:"è²»ç¨",kind:"number"}],filters:[{key:"name",label:"name",type:"text"}]},{name:e$.I.insuranceProducts,label:"insuranceProductsï¼ä¿éªååç®éï¼",access:"readWrite",columns:[{key:"productName",label:"ååå稱",kind:"text",widthClassName:"w-[240px]"},{key:"insurerCode",label:"ä¿éªå
¬å¸",kind:"text",widthClassName:"w-[120px]"},{key:"category",label:"大é¡",kind:"badge",widthClassName:"w-[90px]"},{key:"productType",label:"éªç¨®",kind:"text",widthClassName:"w-[120px]"},{key:"reviewStatus",label:"䏿¶çæ
",kind:"badge",widthClassName:"w-[90px]"},{key:"referencePremium",label:"åèä¿è²»",kind:"number",widthClassName:"w-[100px]"},{key:"updatedAt",label:"æ´æ°æé",kind:"date",widthClassName:"w-[170px]"}],filters:[{key:"reviewStatus",label:"䏿¶çæ
",type:"select",options:[{label:"䏿¶",value:"listed"},{label:"䏿¶",value:"unlisted"}]},{key:"insurerCode",label:"ä¿éªå
¬å¸",type:"text",placeholder:"insurerCodeï¼çå¼ï¼"},{key:"category",label:"大é¡",type:"select",options:[{label:"壽éª",value:"life"},{label:"ç¢éª",value:"property"},{label:"é«ç",value:"medical"}]}]},{name:e$.I.insurancePolicies,label:"insurancePoliciesï¼ä¿å®ï¼",access:"readWrite"},{name:e$.I.userDocuments,label:"userDocumentsï¼ä½¿ç¨è
æä»¶ï¼",access:"readWrite"},{name:e$.I.insuranceDocuments,label:"insuranceDocumentsï¼ä¿éªæä»¶ï¼",access:"readWrite"},{name:e$.I.changelog,label:"changelogï¼æ´æ°ç´éï¼",access:"readWrite",columns:[{key:"version",label:"çæ¬è
1",kind:"text",widthClassName:"w-[120px]"},{key:"date",label:"ç¼å¸æ¥æ",kind:"text",widthClassName:"w-[150px]"},{key:"createdAt",label:"å»ºç«æé",kind:"date",widthClassName:"w-[170px]"}],filters:[{key:"version",label:"çæ¬è",type:"text",placeholder:"宿´çæ¬èï¼ç弿¯å°ï¼"},{key:"date",label:"ç¼å¸æ¥æ",type:"text",placeholder:"ç¼å¸æ¥æï¼ç弿¯å°ï¼"}]},{name:e$.I.suggestions,label:"suggestionsï¼é¡æ/建è°ï¼",access:"readWrite"},{name:e$.I.assets,label:"assetsï¼è³ç¢ï¼",access:"readWrite",columns:[{key:"userId",label:"userId",kind:"text"},{key:"name",label:"å稱",kind:"text"},{key:"value",label:"å¹å¼",kind:"number"}],filters:[{key:"userId",label:"userId",type:"text"}]},{name:e$.I.liabilities,label:"liabilitiesï¼è² åµï¼",access:"readWrite",columns:[{key:"userId",label:"userId",kind:"text"},{key:"name",label:"å稱",kind:"text"},{key:"amount",label:"éé¡",kind:"number"}],filters:[{key:"userId",label:"userId",type:"text"}]},{name:e$.I.goals,label:"goalsï¼ç®æ¨ï¼",access:"readWrite",columns:[{key:"userId",label:"userId",kind:"text"},{key:"name",label:"å稱",kind:"text"},{key:"targetAmount",label:"ç®æ¨éé¡",kind:"number"}],filters:[{key:"userId",label:"userId",type:"text"}]},{name:e$.I.investments,label:"investmentsï¼æè³ï¼",access:"readWrite",columns:[{key:"userId",label:"userId",kind:"text"},{key:"symbol",label:"æ¨ç",kind:"text"},{key:"type",label:"é¡å",kind:"badge"}],filters:[{key:"userId",label:"userId",type:"text"},{key:"type",label:"type",type:"text"}]},{name:e$.I.income_distribution_rules,label:"income_distribution_rulesï¼æ¶å
¥åé
ï¼",access:"readWrite"},{name:e$.I.financial_indicators,label:"financial_indicatorsï¼ææ¨ï¼",access:"readWrite"},{name:e$.I.monthly_unallocated,label:"monthly_unallocatedï¼æ¯ææªåé
ï¼",access:"readWrite"},{name:e$.I.account_monthly_balances,label:"account_monthly_balancesï¼æé¤é¡ï¼",access:"readWrite"},{name:e$.I.bookingConsents,label:"bookingConsentsï¼åææ¸ï¼",access:"readOnly",note:"åææ¸éå¸¸ä¸æè¢«ä¿®æ¹æåªé¤ã"},{name:e$.I.reviews,label:"reviewsï¼è©è«ï¼",access:"readWrite"},{name:e$.I.advanceDirectives,label:"advanceDirectivesï¼é ç«é«ç決å®ï¼",access:"readWrite"},{name:e$.I.guardianshipMandates,label:"guardianshipMandatesï¼æå®ç£è·ï¼",access:"readWrite"},{name:e$.I.adminLogs,label:"admin_logsï¼ç®¡ç塿¥èªï¼",access:"readOnly",note:"åªè®ï¼ç±ç³»çµ±å¯«å
¥ï¼é¿å
å½é ç¨½æ ¸ç´éã"},{name:e$.I.userLoginLogs,label:"userLoginLogsï¼ç»å
¥ç´éï¼",access:"readOnly",note:"åªè®ï¼ç»å
¥ç´éä¸æä¿®æ¹æåªé¤ã"},{name:e$.I.emailTemplates,label:"emailTemplatesï¼éµä»¶æ¨¡æ¿ï¼",access:"readOnly",note:"ç®åå
å
許è®åï¼å¦é管çè«å¦è¡éæ¾ã"},{name:e$.I.emailLogs,label:"emailLogsï¼éµä»¶æ¥èªï¼",access:"readOnly"},{name:e$.I.emailQueue,label:"emailQueueï¼éµä»¶ä½åï¼",access:"blocked",note:"ç¦æ¢éé UI æä½ï¼é¿å
å½±é¿ç³»çµ±å¯ä¿¡æµç¨ã"},{name:e$.I.emailCooldowns,label:"emailCooldownsï¼éµä»¶å·å»ï¼",access:"readOnly"},{name:e$.I.monitoringEvents,label:"monitoringEventsï¼ç£æ§äºä»¶ï¼",access:"readOnly"},{name:e$.I.deleted_user_emails,label:"deleted_user_emailsï¼å·²åªé¤ Email è¨éï¼",access:"readOnly"},{name:e$.I.registration_attempts,label:"registration_attemptsï¼è¨»åå試ï¼",access:"readOnly"},{name:e$.I.referral_usage,label:"referral_usageï¼æ¨è¦ç¢¼ä½¿ç¨ï¼",access:"readOnly"}];eR.map(e=>e.name);var eD=s(15418);let eP=eD.Ik({error:eD.bz()});async function eF(e){try{let t=await e.json(),s=eP.safeParse(t);if(!s.success)return`HTTP ${e.status}`;let a=s.data.error;if("string"==typeof a)return a;return`HTTP ${e.status}`}catch{return`HTTP ${e.status}`}}function eO(e){return{Authorization:`Bearer ${e}`}}let e_=eD.Ik({docs:eD.YO(eD.Ik({id:eD.Yj(),data:eD.g1(eD.Yj(),eD.L5())})),nextCursor:eD.Yj().nullable()});async function eU(e){let t=new URLSearchParams;e.limit&&t.set("limit",String(e.limit)),e.cursor&&t.set("cursor",e.cursor),e.filters&&Object.keys(e.filters).length&&t.set("filters",JSON.stringify(e.filters));let s=await fetch(`/api/admin/firestore/${encodeURIComponent(e.collection)}?${t.toString()}`,{method:"GET",headers:{...eO(e.idToken)}});if(!s.ok)throw Error(await eF(s));let a=await s.json();return e_.parse(a)}eD.Ik({id:eD.Yj(),data:eD.g1(eD.Yj(),eD.L5())});let ez=eD.Ik({id:eD.Yj()});async function eB(e){let t=await fetch(`/api/admin/firestore/${encodeURIComponent(e.collection)}`,{method:"POST",headers:{"Content-Type":"application/json",...eO(e.idToken)},body:JSON.stringify({docId:e.docId,data:e.data})});if(!t.ok)throw Error(await eF(t));let s=await t.json();return ez.parse(s)}let eL=eD.Ik({ok:eD.eu(!0)});async function eY(e){let t=await fetch(`/api/admin/firestore/${encodeURIComponent(e.collection)}/${encodeURIComponent(e.docId)}`,{method:"PATCH",headers:{"Content-Type":"application/json",...eO(e.idToken)},body:JSON.stringify({data:e.data,merge:e.merge??!0})});if(!t.ok)throw Error(await eF(t));eL.parse(await t.json())}async function eJ(e){let t=await fetch(`/api/admin/firestore/${encodeURIComponent(e.collection)}/${encodeURIComponent(e.docId)}`,{method:"DELETE",headers:{...eO(e.idToken)}});if(!t.ok)throw Error(await eF(t));eL.parse(await t.json())}var eM=s(78954);let eW=eD.Yj().min(1,"æ¬ä½å稱ä¸å¯çºç©º").max(128,"æ¬ä½å稱éé·").refine(e=>!e.includes("."),"æ¬ä½å稱æ«ä¸æ¯æ´ '.'ï¼é¿å
æå¤æ´æ°å·¢çæ¬ä½ï¼"),eV=eD.Yj().min(1,"Doc ID ä¸å¯çºç©º").max(150,"Doc ID éé·").refine(e=>!e.includes("/"),"Doc ID ä¸å¯å
å« '/'");function eZ(e){try{return JSON.stringify(e,null,2)}catch{return""}}function eH(e){let{open:t,onOpenChange:s,title:a,description:l,submitLabel:n,isSubmitting:d,showDocId:c,initialDocId:o,initialData:u,onSubmit:m}=e,h=(0,i.useMemo)(()=>Object.entries(u??{}).map(([e,t])=>{let s="boolean"==typeof t?"boolean":"number"==typeof t?"number":"string"==typeof t?"string":"json";return"boolean"===s?{key:e,type:s,value:!!t}:"number"===s||"string"===s?{key:e,type:s,value:String(t??"")}:{key:e,type:s,value:eZ(t)}}),[u]),[x,p]=(0,i.useState)(!1),[j,g]=(0,i.useState)(o??""),[f,v]=(0,i.useState)(h),[y,N]=(0,i.useState)(eZ(u??{})),[C,A]=(0,i.useState)("");(0,i.useEffect)(()=>{t&&(A(""),g(o??""),v(h),N(eZ(u??{})))},[t,o,h,u]);let S=async()=>{A("");try{let e,t=c&&j.trim()?eV.parse(j.trim()):void 0;if(x){let t=eD.L5().safeParse(JSON.parse(y||"{}"));if(!t.success)throw Error("JSON æ ¼å¼é¯èª¤");if(!t.data||"object"!=typeof t.data||Array.isArray(t.data))throw Error("JSON å¿
é æ¯ç©ä»¶ï¼objectï¼");e=t.data}else e=function(e){let t={};for(let s of e){let e=eW.safeParse(s.key);if(!e.success)throw Error(e.error.issues[0]?.message||"æ¬ä½å稱é¯èª¤");if(Object.prototype.hasOwnProperty.call(t,e.data))throw Error(`æ¬ä½å稱éè¤ï¼${e.data}`);if("boolean"===s.type){t[e.data]=!!s.value;continue}if("number"===s.type){if("string"!=typeof s.value)throw Error(`æ¬ä½ ${e.data} çæ¸å¼æ ¼å¼é¯èª¤`);let a=Number(s.value);if(!Number.isFinite(a))throw Error(`æ¬ä½ ${e.data} å¿
é æ¯æ¸å`);t[e.data]=a;continue}if("string"===s.type){t[e.data]="string"==typeof s.value?s.value:String(s.value);continue}if("string"!=typeof s.value)throw Error(`æ¬ä½ ${e.data} ç JSON æ ¼å¼é¯èª¤`);if(!s.value.trim()){t[e.data]=null;continue}try{t[e.data]=JSON.parse(s.value)}catch{throw Error(`æ¬ä½ ${e.data} ç JSON è§£æå¤±æ`)}}return t}(f);await m({docId:t,data:e}),s(!1)}catch(e){A(e instanceof Error?e.message:"æä½å¤±æ")}};return(0,r.jsx)(z.lG,{open:t,onOpenChange:s,children:(0,r.jsxs)(z.Cf,{className:"sm:max-w-[720px] max-h-[85vh] grid-rows-[auto,1fr,auto]",children:[(0,r.jsxs)(z.c7,{children:[(0,r.jsx)(z.L3,{children:a}),l?(0,r.jsx)(z.rr,{children:l}):null]}),(0,r.jsxs)("div",{className:"space-y-4 min-h-0 overflow-y-auto scrollbar-hide pr-1",children:[c?(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w.J,{htmlFor:"docId",children:"Doc IDï¼é¸å¡«ï¼"}),(0,r.jsx)(W.p,{id:"docId",value:j,onChange:e=>g(e.target.value),placeholder:"ç空åèªåç¢ç"}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:"æç¤ºï¼Doc ID ä¸å¯å
å« '/'"})]}):null,(0,r.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,r.jsxs)("div",{className:"space-y-0.5",children:[(0,r.jsx)("p",{className:"text-sm font-medium",children:"編輯模å¼"}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:"ç°¡å®æ¬ä½ç¨è¡¨å®æ¨¡å¼ï¼è¤éç©ä»¶å»ºè° JSON 模å¼ã"})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:"表å®"}),(0,r.jsx)(eM.d,{checked:x,onCheckedChange:p}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:"JSON"})]})]}),x?(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w.J,{htmlFor:"json",children:"è³æï¼JSON Objectï¼"}),(0,r.jsx)(V.T,{id:"json",value:y,onChange:e=>N(e.target.value),rows:14,className:"font-mono text-xs"}),(0,r.jsxs)("p",{className:"text-xs text-muted-foreground",children:["æ¯æ´ç¹æ®æä½ï¼",(0,r.jsx)("code",{children:'{"__op":"serverTimestamp"}'}),"ã",(0,r.jsx)("code",{children:'{"__op":"deleteField"}'}),"ã",(0,r.jsx)("code",{children:'{"__op":"increment","by":1}'})]})]}):(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsx)(w.J,{children:"æ¬ä½"}),(0,r.jsx)(b.$,{type:"button",variant:"outline",size:"sm",onClick:()=>v(e=>[...e,{key:"",type:"string",value:""}]),children:"æ°å¢æ¬ä½"})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[0===f.length?(0,r.jsx)("p",{className:"text-sm text-muted-foreground",children:"å°ç¡æ¬ä½ï¼
1é»ãæ°å¢æ¬ä½ãéå§ã"}):null,f.map((e,t)=>(0,r.jsxs)("div",{className:"grid grid-cols-12 gap-2 items-start",children:[(0,r.jsx)("div",{className:"col-span-4",children:(0,r.jsx)(W.p,{value:e.key,onChange:e=>{let s=e.target.value;v(e=>e.map((e,a)=>a===t?{...e,key:s}:e))},placeholder:"æ¬ä½å稱"})}),(0,r.jsx)("div",{className:"col-span-3",children:(0,r.jsxs)(Z.l6,{value:e.type,onValueChange:e=>{v(s=>s.map((s,a)=>a!==t?s:"boolean"===e?{...s,type:e,value:!!s.value}:"json"===e?{...s,type:e,value:"string"==typeof s.value?s.value:"null"}:{...s,type:e,value:"string"==typeof s.value?s.value:""}))},children:[(0,r.jsx)(Z.bq,{children:(0,r.jsx)(Z.yv,{placeholder:"åå¥"})}),(0,r.jsxs)(Z.gC,{children:[(0,r.jsx)(Z.eb,{value:"string",children:"string"}),(0,r.jsx)(Z.eb,{value:"number",children:"number"}),(0,r.jsx)(Z.eb,{value:"boolean",children:"boolean"}),(0,r.jsx)(Z.eb,{value:"json",children:"json"})]})]})}),(0,r.jsx)("div",{className:"col-span-4",children:"boolean"===e.type?(0,r.jsxs)("div",{className:"flex items-center gap-2 h-10 px-2 border rounded-md",children:[(0,r.jsx)(eM.d,{checked:!!e.value,onCheckedChange:e=>v(s=>s.map((s,a)=>a===t?{...s,value:e}:s))}),(0,r.jsx)("span",{className:"text-sm text-muted-foreground",children:e.value?"true":"false"})]}):"json"===e.type?(0,r.jsx)(V.T,{value:"string"==typeof e.value?e.value:"",onChange:e=>v(s=>s.map((s,a)=>a===t?{...s,value:e.target.value}:s)),rows:2,className:"font-mono text-xs",placeholder:'ä¾å¦ï¼{"a":1} æ [1,2]'}):(0,r.jsx)(W.p,{value:"string"==typeof e.value?e.value:"",onChange:e=>v(s=>s.map((s,a)=>a===t?{...s,value:e.target.value}:s)),placeholder:"number"===e.type?"æ¸å":"æå"})}),(0,r.jsx)("div",{className:"col-span-1 flex justify-end",children:(0,r.jsx)(b.$,{type:"button",variant:"ghost",size:"sm",onClick:()=>v(e=>e.filter((e,s)=>s!==t)),children:"åª"})})]},`${e.key}-${t}`))]})]}),C?(0,r.jsx)(k.Fc,{variant:"destructive",children:(0,r.jsx)(k.TN,{children:C})}):null]}),(0,r.jsxs)(z.Es,{children:[(0,r.jsx)(b.$,{type:"button",variant:"outline",onClick:()=>s(!1),disabled:!!d,children:"åæ¶"}),(0,r.jsx)(b.$,{type:"button",onClick:S,disabled:!!d,children:d?"èçä¸...":n})]})]})})}var eq=s(76842);async function eG(e){if(e)try{await navigator.clipboard.writeText(e)}catch{}}function eX(){let{user:e}=(0,m.A)(),{toast:t}=(0,u.dj)(),[s,a]=(0,i.useState)(eR[0]?.name||"users"),l=(0,i.useMemo)(()=>(function(e){if(e)return eR.find(t=>t.name===e)})(s),[s]),n=(0,i.useMemo)(()=>l?.columns||[],[l]),d=(0,i.useMemo)(()=>l?.filters||[],[l]),[c,o]=(0,i.useState)(20),[h,x]=(0,i.useState)([]),[p,j]=(0,i.useState)(null),[g,f]=(0,i.useState)(!1),[v,C]=(0,i.useState)(!1),[A,S]=(0,i.useState)(null),[T,I]=(0,i.useState)(""),E=(0,i.useMemo)(()=>{let e=T.trim().toLowerCase();return e?h.filter(t=>t.id.toLowerCase().includes(e)||(function(e){try{let t=JSON.stringify(e);if(t.length<=2e3)return t;return`${t.slice(0,2e3)}â¦`}catch{return"[unserializable]"}})(t.data).toLowerCase().includes(e)):h},[h,T]),[R,D]=(0,i.useState)({}),[P,F]=(0,i.useState)(!1),[O,_]=(0,i.useState)(!1),[U,z]=(0,i.useState)(null),{showConfirmation:L,isOpen:M,action:V,isLoading:H,reason:q,hideConfirmation:G,setReason:X}=J(),[K,Q]=(0,i.useState)({}),ee=(0,i.useRef)({});(0,i.useEffect)(()=>{ee.current=K},[K]);let et=(0,i.useCallback)(async()=>{if(!e)throw Error("ç¨æ¶æªç»å
¥");return await e.getIdToken()},[e]),es=(0,i.useCallback)(async()=>{S(null),f(!0);try{let e=await et(),t={};for(let e of d){let s=ee.current[e.key];if("switch"===e.type){"boolean"==typeof s&&(t[e.key]=s);continue}"string"==typeof s&&s.trim()&&(t[e.key]=s.trim())}let a=await eU({idToken:e,collection:s,limit:c,filters:t});x(a.docs),j(a.nextCursor)}catch(e){S(e instanceof Error?e.message:"è¼å
¥å¤±æ")}finally{f(!1)}},[s,c,et,d]),ea=(0,i.useCallback)(async()=>{if(p){S(null),f(!0);try{let e=await et(),t={};for(let e of d){let s=ee.current[e.key];if("switch"===e.type){"boolean"==typeof s&&(t[e.key]=s);continue}"string"==typeof s&&s.trim()&&(t[e.key]=s.trim())}let a=await eU({idToken:e,collection:s,limit:c,cursor:p,filters:t});x(e=>[...e,...a.docs]),j(a.nextCursor)}catch(e){S(e instanceof Error?e.message:"è¼å
¥å¤±æ")}finally{f(!1)}}},[s,c,p,et,d]);(0,i.useEffect)(()=>{D({}),Q({})},[s]),(0,i.useEffect)(()=>{es()},[es]);let er=l?.access==="readWrite",ei=l?.access==="blocked",el=async a=>{C(!0);try{if(!er)throw Error("æ¤ collection ç®åçºå¯è®æç¦æ¢æä½");let r=await et(),{id:i}=await eB({idToken:r,collection:s,docId:a.docId,data:a.data});e?.email&&ec.logFirestoreCreate(e.uid,e.email,s,i),t({title:"å»ºç«æå",description:`已建ç«
1æä»¶ï¼${i}`}),await es()}catch(e){throw t({title:"建ç«å¤±æ",description:e instanceof Error?e.message:"建ç«å¤±æ",variant:"destructive"}),e}finally{C(!1)}},en=async a=>{if(U){C(!0);try{if(!er)throw Error("æ¤ collection ç®åçºå¯è®æç¦æ¢æä½");let r=await et();await eY({idToken:r,collection:s,docId:U.id,data:a.data,merge:!0}),e?.email&&ec.logFirestoreUpdate(e.uid,e.email,s,U.id),t({title:"æ´æ°æå",description:`å·²æ´æ°ï¼${U.id}`}),await es()}catch(e){throw t({title:"æ´æ°å¤±æ",description:e instanceof Error?e.message:"æ´æ°å¤±æ",variant:"destructive"}),e}finally{C(!1)}}},ed=async a=>{if(!er)return void t({title:"ç¦æ¢æä½",description:"æ¤ collection ç®åçºå¯è®æç¦æ¢æä½",variant:"destructive"});let r=await L({type:"danger",title:"åªé¤æä»¶",description:`æ¨å³å°åªé¤ ${s}/${a}ï¼æ¤æä½ç¡æ³å¾©åã`,confirmText:"確èªåªé¤",cancelText:"åæ¶",details:["æ¤æä½ææ°¸ä¹
åªé¤æä»¶","è«ç¢ºèªæ²æå
¶ä»æµç¨ä¾è³´æ¤è³æ"],requiresReason:!0});if(!r.confirmed)return;let i=r.reason||q;G(),C(!0);try{let r=await et();await eJ({idToken:r,collection:s,docId:a}),e?.email&&ec.logFirestoreDelete(e.uid,e.email,s,a,i),t({title:"åªé¤æå",description:`å·²åªé¤ï¼${a}`}),await es()}catch(e){t({title:"åªé¤å¤±æ",description:e instanceof Error?e.message:"åªé¤å¤±æ",variant:"destructive"})}finally{C(!1)}};return(0,r.jsxs)("div",{className:"space-y-6",children:[(0,r.jsxs)(y.Zp,{children:[(0,r.jsxs)(y.aR,{className:"flex flex-row items-center justify-between gap-3",children:[(0,r.jsx)(y.ZB,{children:"è³æåº«ç®¡çï¼Firestore CRUDï¼"}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsxs)(b.$,{variant:"outline",size:"sm",onClick:()=>es(),disabled:g,children:[(0,r.jsx)(ef.A,{className:"h-4 w-4 mr-2"}),"éæ°æ´ç"]}),(0,r.jsxs)(b.$,{onClick:()=>F(!0),disabled:!er||ei,children:[(0,r.jsx)(eI.A,{className:"h-4 w-4 mr-2"}),"æ°å¢æä»¶"]})]})]}),(0,r.jsxs)(y.Wu,{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"grid grid-cols-12 gap-3",children:[(0,r.jsxs)("div",{className:"col-span-12 md:col-span-4 space-y-2",children:[(0,r.jsx)(w.J,{children:"Collection"}),(0,r.jsxs)(Z.l6,{value:s,onValueChange:a,children:[(0,r.jsx)(Z.bq,{children:(0,r.jsx)(Z.yv,{placeholder:"鏿 collection"})}),(0,r.jsx)(Z.gC,{children:eR.map(e=>(0,r.jsx)(Z.eb,{value:e.name,children:e.label},e.name))})]}),l?.note?(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:l.note}):null]}),(0,r.jsxs)("div",{className:"col-span-12 md:col-span-2 space-y-2",children:[(0,r.jsx)(w.J,{children:"æ¯æ¬¡è¼å
¥çæ¸"}),(0,r.jsxs)(Z.l6,{value:String(c),onValueChange:e=>o(Number(e)),children:[(0,r.jsx)(Z.bq,{children:(0,r.jsx)(Z.yv,{placeholder:"çæ¸"})}),(0,r.jsxs)(Z.gC,{children:[(0,r.jsx)(Z.eb,{value:"10",children:"10"}),(0,r.jsx)(Z.eb,{value:"20",children:"20"}),(0,r.jsx)(Z.eb,{value:"50",children:"50"}),(0,r.jsx)(Z.eb,{value:"100",children:"100"})]})]})]}),(0,r.jsxs)("div",{className:"col-span-12 md:col-span-3 space-y-2",children:[(0,r.jsx)(w.J,{children:"æå°ï¼Doc ID æå
§å®¹ï¼"}),(0,r.jsx)(W.p,{value:T,onChange:e=>I(e.target.value),placeholder:"輸å
¥ééµå..."})]}),(0,r.jsxs)("div",{className:"col-span-12 md:col-span-3 space-y-2",children:[(0,r.jsx)(w.J,{children:"å¸¸ç¨æ¬ä½ç¯©é¸"}),d.length?(0,r.jsxs)("div",{className:"flex flex-wrap gap-2",children:[d.map(e=>{if("switch"===e.type){let t=!!K[e.key];return(0,r.jsxs)(b.$,{type:"button",variant:t?"default":"outline",size:"sm",onClick:()=>Q(s=>({...s,[e.key]:!t})),children:[e.label,":",t?"æ¯":"å¦"]},e.key)}if("select"===e.type&&e.options?.length){let t="string"==typeof K[e.key]?K[e.key]:"";return(0,r.jsxs)(Z.l6,{value:t,onValueChange:t=>Q(s=>({...s,[e.key]:"__all__"===t?"":t})),children:[(0,r.jsx)(Z.bq,{className:"h-9 w-[160px]",children:(0,r.jsx)(Z.yv,{placeholder:e.label})}),(0,r.jsxs)(Z.gC,{children:[(0,r.jsx)(Z.eb,{value:"__all__",children:"ï¼å
¨é¨ï¼"}),e.options.map(e=>(0,r.jsx)(Z.eb,{value:e.value,children:e.label},e.value))]})]},e.key)}let t="string"==typeof K[e.key]?K[e.key]:"";return(0,r.jsx)(W.p,{value:t,onChange:t=>Q(s=>({...s,[e.key]:t.target.value})),placeholder:e.placeholder||e.label,className:"h-9 w-[180px]"},e.key)}),(0,r.jsx)(b.$,{type:"button",variant:"outline",size:"sm",onClick:()=>es(),disabled:g,children:"å¥ç¨"}),(0,r.jsx)(b.$,{type:"button",variant:"ghost",size:"sm",onClick:()=>{Q({}),es()},disabled:g,children:"æ¸
é¤"})]}):(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:"æ¤ collection å°æªè¨å®å¸¸ç¨ç¯©é¸ã"})]})]}),e?null:(0,r.jsx)(k.Fc,{variant:"destructive",children:(0,r.jsx)(k.TN,{children:"å°æªç»å
¥ï¼ç¡æ³ä½¿ç¨è³æåº«ç®¡çåè½ã"})}),A?(0,r.jsx)(k.Fc,{variant:"destructive",children:(0,r.jsx)(k.TN,{children:A})}):null,(0,r.jsx)("div",{className:"border rounded-md",children:(0,r.jsxs)(eg.XI,{children:[(0,r.jsx)(eg.A0,{children:(0,r.jsxs)(eg.Hj,{children:[(0,r.jsx)(eg.nd,{className:"w-[240px]",children:"Doc ID"}),n.map(e=>(0,r.jsx)(eg.nd,{className:e.widthClassName,children:e.label},e.key)),(0,r.jsx)(eg.nd,{className:"w-[140px]",children:"æ´å¤"}),(0,r.jsx)(eg.nd,{className:"w-[200px] text-right",children:"æä½"})]})}),(0,r.jsx)(eg.BF,{children:0===E.length?(0,r.jsx)(eg.Hj,{children:(0,r.jsx)(eg.nA,{colSpan:4+n.length,className:"text-center py-8",children:g?(0,r.jsx)($.default,{size:48}):"æ²æè³æ"})}):E.map(e=>(0,r.jsxs)(i.Fragment,{children:[(0,r.jsxs)(eg.Hj,{children:[(0,r.jsx)(eg.nA,{className:"align-top",children:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"font-mono text-xs",children:e.id}),(0,r.jsx)(b.$,{type:"button",variant:"ghost",size:"sm",className:"px-2",onClick:()=>{eG(e.id),t({title:"å·²è¤è£½ Doc ID"})},children:(0,r.jsx)(eq.A,{className:"h-4 w-4"})})]})}),n.map(t=>{let s=function(e,t){if(e)return e[t]}(e.data,t.key);if("boolean"===t.kind){let e=!!s;return(0,r.jsx)(eg.nA,{className:"align-top",children:(0,r.jsx)(N.E,{variant:e?"default":"secondary",children:e?"æ¯":"å¦"})},t.key)}if("badge"===t.kind){let e=null==s?"-":String(s);return(0,r.jsx)(eg.nA,{className:"align-top",children:(0,r.jsx)(N.E,{variant:"admin"===e?"destructive":"outline",children:e})},t.key)}return"date"===t.kind?(0,r.jsx)(eg.nA,{className:"align-top text-sm text-muted-foreground",children:function(e){if(!e)return"-";if("string"==typeof e){let t=new Date(e);
1return Number.isNaN(t.getTime())?e:t.toLocaleString("zh-TW")}return String(e)}(s)},t.key):"number"===t.kind?(0,r.jsx)(eg.nA,{className:"align-top text-sm",children:function(e){if(null==e)return"-";if("number"==typeof e)return e.toLocaleString("zh-TW");let t=Number(e);return Number.isFinite(t)?t.toLocaleString("zh-TW"):String(e)}(s)},t.key):(0,r.jsx)(eg.nA,{className:"align-top text-sm",children:null==s?"-":String(s)},t.key)}),(0,r.jsx)(eg.nA,{className:"align-top",children:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)(b.$,{type:"button",variant:"outline",size:"sm",onClick:()=>D(t=>({...t,[e.id]:!t[e.id]})),children:R[e.id]?"æ¶å":"å±é"}),(0,r.jsx)(b.$,{type:"button",variant:"ghost",size:"sm",onClick:()=>{eG(JSON.stringify(e.data,null,2)),t({title:"å·²è¤è£½ JSON"})},children:"è¤è£½"})]})}),(0,r.jsx)(eg.nA,{className:"align-top text-right",children:(0,r.jsx)("div",{className:"flex justify-end",children:(0,r.jsx)(ek.j,{ariaLabel:`æä»¶åæä½ï¼${e.id}`,items:[{id:"edit",label:"編輯",icon:eE.A,disabled:!er||ei,onSelect:()=>{z(e),_(!0)}},{id:"delete",label:"åªé¤",icon:B.A,destructive:!0,disabled:!er||ei||v,onSelect:()=>ed(e.id)}]})})})]}),R[e.id]?(0,r.jsx)(eg.Hj,{children:(0,r.jsx)(eg.nA,{colSpan:4+n.length,className:"bg-muted/30",children:(0,r.jsx)("div",{className:"grid grid-cols-12 gap-3",children:(0,r.jsxs)("div",{className:"col-span-12",children:[(0,r.jsx)("p",{className:"text-xs text-muted-foreground mb-2",children:"JSONï¼å®æ´ï¼"}),(0,r.jsx)("pre",{className:"text-xs leading-5 p-3 rounded-md border bg-background overflow-auto max-h-[320px]",children:JSON.stringify(e.data,null,2)})]})})})}):null]},e.id))})]})}),(0,r.jsxs)("div",{className:"flex justify-between items-center",children:[(0,r.jsxs)("p",{className:"text-xs text-muted-foreground",children:["å·²è¼å
¥ï¼",h.length," çï¼é¡¯ç¤ºï¼",E.length," çï¼"]}),(0,r.jsx)("div",{className:"flex gap-2",children:(0,r.jsx)(b.$,{variant:"outline",onClick:()=>ea(),disabled:!p||g,children:"è¼å
¥æ´å¤"})})]})]})]}),(0,r.jsx)(eH,{open:P,onOpenChange:F,title:"æ°å¢æä»¶",description:`Collectionï¼${s}`,submitLabel:"建ç«",isSubmitting:v,showDocId:!0,onSubmit:el}),(0,r.jsx)(eH,{open:O,onOpenChange:e=>{_(e),e||z(null)},title:"編輯æä»¶",description:U?`${s}/${U.id}`:`Collectionï¼${s}`,submitLabel:"æ´æ°",isSubmitting:v,showDocId:!1,initialData:U?.data??{},onSubmit:async({data:e})=>en({data:e})}),V?(0,r.jsx)(Y,{isOpen:M,onClose:G,onConfirm:async()=>{V.__resolve&&V.__resolve(!0)},action:V,isLoading:H,reason:q,onReasonChange:X}):null]})}var eK=s(6274),eQ=s(8947);let e0=[{label:"éç¶ è²ç³»",value:"from-teal-500 via-cyan-500 to-emerald-500"},{label:"ç´
ç´«è²ç³»",value:"from-red-500 via-purple-500 to-pink-500"},{label:"èç´«è²ç³»",value:"from-blue-500 via-indigo-500 to-purple-500"},{label:"æ©ç´
è²ç³»",value:"from-orange-500 via-red-500 to-pink-500"},{label:"ç¶ è²ç³»",value:"from-green-500 via-emerald-500 to-teal-500"},{label:"ç´«ç´
è²ç³»",value:"from-purple-500 via-pink-500 to-rose-500"},{label:"éè²ç³»",value:"from-cyan-500 via-blue-500 to-indigo-500"},{label:"ç¥çè²ç³»",value:"from-amber-500 via-orange-500 to-red-500"},{label:"éèèè·ç³»",value:"from-indigo-500 via-slate-500 to-sky-500"},{label:"ç«ç°ç´«ç¾
èç³»",value:"from-rose-400 via-fuchsia-500 to-violet-600"}];var e1=s(27243),e2=s(93315),e4=s(51976),e3=s(20290),e5=s(39558),e6=s(56620);let e8=({label:e,items:t,onUpdateItem:s,onAddItem:a,onRemoveItem:i,placeholder:l})=>(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,r.jsx)(w.J,{children:e}),(0,r.jsxs)(b.$,{type:"button",variant:"outline",size:"sm",onClick:a,children:[(0,r.jsx)(eI.A,{className:"w-4 h-4 mr-1"}),"æ°å¢"]})]}),(0,r.jsx)("div",{className:"space-y-2",children:t.map((e,a)=>(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(V.T,{value:e,onChange:e=>s(a,e.target.value),placeholder:l,rows:2,className:"flex-1"}),t.length>1&&(0,r.jsx)(b.$,{type:"button",variant:"ghost",size:"icon",onClick:()=>i(a),children:(0,r.jsx)(B.A,{className:"w-4 h-4"})})]},a))})]}),e7=({formData:e,isEditing:t,uploadingImage:s,imagePreview:a,onDateChange:l,onImageUrlChange:n,onRandomGradientClick:d,onSummaryChange:c,onImageUpload:o,onRemoveImage:u,onSave:m,onCancel:h,loading:x,gradientOptions:p,sections:j})=>{let g=(0,i.useRef)(null),[f,v]=(0,i.useState)(!1);return(0,i.useEffect)(()=>{v(!1)},[a,e.imageUrl]),(0,r.jsxs)(y.Zp,{children:[(0,r.jsx)(y.aR,{children:(0,r.jsx)(y.ZB,{children:t?"ç·¨è¼¯æ´æ°ç´é":"æ°å¢æ´æ°ç´é"})}),(0,r.jsxs)(y.Wu,{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w.J,{htmlFor:"version",children:"çæ¬è
1"}),(0,r.jsx)(W.p,{id:"version",value:e.version,readOnly:!0,disabled:!0,placeholder:"便¥æèªåç¢ç"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.J,{htmlFor:"date",children:"ç¼å¸æ¥æ *"}),(0,r.jsx)("div",{onClick:()=>{let e=document.getElementById("date");e&&("showPicker"in e&&"function"==typeof e.showPicker?e.showPicker():e.click())},className:"cursor-pointer",children:(0,r.jsx)(W.p,{id:"date",type:"date",value:e.date,onChange:e=>l(e.target.value),className:"cursor-pointer",onClick:e=>{e.stopPropagation();let t=e.target;"showPicker"in t&&"function"==typeof t.showPicker?t.showPicker():t.click()}})})]})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w.J,{children:"漸層主é¡"}),(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,r.jsxs)(b.$,{type:"button",variant:"outline",size:"sm",onClick:d,className:"shrink-0",children:[(0,r.jsx)(e4.A,{className:"w-4 h-4 mr-2"}),"鍿©æ´æèæ¯"]}),e.gradient&&(0,r.jsxs)("span",{className:"text-sm text-muted-foreground",children:["ç®åï¼",p.find(t=>t.value===e.gradient)?.label??"èªè¨"]})]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(w.J,{htmlFor:"imageUrl",children:"åçï¼å¯é¸ï¼"}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(W.p,{id:"imageUrl",value:e.imageUrl||"",onChange:e=>n(e.target.value),placeholder:"/changelog/images/version-2.1.png",className:"flex-1"}),(0,r.jsx)(b.$,{type:"button",variant:"outline",onClick:()=>{g.current?.click()},disabled:s,children:s?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(eA.A,{className:"w-4 h-4 mr-2 animate-spin"}),"ä¸å³ä¸..."]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e3.A,{className:"w-4 h-4 mr-2"}),"é¸ææªæ¡"]})}),e.imageUrl&&(0,r.jsxs)(b.$,{type:"button",variant:"outline",onClick:u,disabled:s,className:"text-destructive hover:text-destructive",children:[(0,r.jsx)(es.A,{className:"w-4 h-4 mr-2"}),"ç§»é¤"]}),(0,r.jsx)("input",{id:"changelog-image-input",ref:g,type:"file",accept:"image/*",className:"hidden",disabled:s,onChange:e=>{let t=e.target.files?.[0];t&&o(t)}})]}),!e.version&&(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:"è«å
鏿ç¼å¸æ¥æä»¥ç¢ççæ¬èæè½ä¸å³åç"}),(e.imageUrl||a)&&(0,r.jsxs)("div",{className:"relative w-full h-48 rounded-lg overflow-hidden border",children:[!f&&(0,r.jsx)(e6.default,{src:a||e.imageUrl||"",alt:"é 覽",fill:!0,sizes:"100vw",className:"object-cover",onError:()=>v(!0)}),f&&(0,r.jsx)("div",{className:"absolute inset-0 flex items-center justify-center text-muted-foreground text-sm",children:"åçè¼å
¥å¤±æ"}),s&&(0,r.jsx)("div",{className:"absolute inset-0 bg-black/50 flex items-center justify-center",children:(0,r.jsxs)("div",{className:"flex flex-col items-center gap-2 text-white",children:[(0,r.jsx)(eA.A,{className:"w-6 h-6 animate-spin"}),(0,r.jsx)("span",{className:"text-sm",children:"ä¸å³ä¸..."})]})})]}),e.imageUrl&&(0,r.jsxs)("p",{className:"text-xs text-muted-foreground break-all",children:["åçè·¯å¾ï¼",e.imageUrl]})]})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w.J,{htmlFor:"summary",children:"說æï¼é¸å¡«ï¼"}),(0,r.jsx)(V.T,{id:"summary",value:e.summary??"",onChange:e=>c(e.target.value),placeholder:"ä¸å¥è©±éå ´ / 說æï¼ä¾å¦ï¼éçè®è¨å¸³æ´è¼é¬â¦",className:"min-h-[80px] resize-y",maxLength:200}),(0,r.jsxs)("p",{className:"text-xs text-muted-foreground",children:[e.summary?.length??0," / 200 åï¼æé¡¯ç¤ºå¨è®æ´å
§å®¹ä¸æ¹ï¼ä¸¦ç¨æ¼ Threads è²¼æå
§æã"]})]}),j.map(e=>(0,r.jsx)(e8,{label:e.label,items:e.items,onUpdateItem:e.onUpdate,onAddItem:e.onAdd,onRemoveItem:e.onRemove,placeholder:e.placeholder},e.label)),(0,r.jsxs)("div",{className:"flex gap-2 justify-end",children:[(0,r.jsxs)(b.$,{variant:"outline",onClick:h,disabled:x,children:[(0,r.jsx)(X.A,{className:"w-4 h-4 mr-2"}),"åæ¶"]}),(0,r.jsxs)(b.$,{onClick:m,disabled:x,children:[(0,r.jsx)(e5.A,{className:"w-4 h-4 mr-2"}),"å²å"]})]})]})]})};var e9=s(4153);let te=`ã${e9._K.app.name}æ´æ°ã`,tt=[{id:"profile",label:"å人ä»ç´¹",text:"æ´å¤è©³æ
è App é£çµè«è³å人ä»ç´¹æ¥çã"},{id:"link-in_bio",label:"é£çµå¨å人ä»ç´¹",text:"App ä¸è¼èæ´å¤è³è¨è«è¦å人ä»ç´¹é£çµã"},{id:"bio",label:"åäººæªæ¡",text:"宿´èªªæè App é£çµå¨åäººæªæ¡ã"},{id:"profile_link",label:"黿å人ä»ç´¹",text:"æ³äºè§£æ´å¤ï¼è«é»æå人ä»ç´¹ä¸çé£çµã"}];function ts(){let e=tt.find(e=>"profile"===e.id);return e?.text??tt[0]?.text??""}let ta=[{key:"majorChanges",title:"éå¤§è®æ´"},{key:"architectureChanges",title:"æ¶æ§è®æ´"},{key:"newFeatures",title:"æ°å¢åè½"},{key:"improvements",title:"åè½æ¹é²"},{key:"fixes",title:"ä¿®è£"}],tr=e=>(e??[]).filter(e=>""!==e.trim()),ti=({formData:e})=>{let[t,s]=(0,i.useState)(!1);(0,i.useEffect)(()=>{s(!1)},[e.imageUrl]);let a=e.summary?.trim(),l=ta.map(t=>({title:t.title,items:tr(e[t.key])})).filter(e=>e.items.length>0);return e.version?(0,r.jsxs)("div",{className:"space-y-4",children:[e.date&&(0,r.jsx)("p",{className:"text-sm font-medium text-muted-foreground",children:e.date}),(0,r.jsxs)("div",{className:`relative overflow-hidden rounded-2xl bg-gradient-to-br ${e.gradient} p-6 md:p-8 shadow-xl`,children:[(0,r.jsx)("div",{className:"absolute top-0 right-0 w-32 h-32 bg-white/10 rounded-full blur-2xl"}),(0,r.jsx)("div",{className:"absolute bottom-0 left-0 w-24 h-24 bg-white/10 rounded-full blur-xl"}),(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsxs)("div",{className:"flex items-start justify-between mb-6",children:[(0,r.jsxs)("h2",{className:"text-2xl md:text-3xl font-bold text-white",children:["Version ",e.version]}),(0,r.jsx)("div",{className:"text-6xl md:text-7xl font-bold text-white/20",children:(0,e1.Mi)(e.version)})]}),e.imageUrl&&""!==e.imageUrl.trim()&&(0,r.jsxs)("div",{className:"mb-6 rounded-lg overflow-hidden",children:[!t&&(0,r.jsx)(e6.default,{src:e.imageUrl,alt:`Version ${e.ver
1sion} æ´æ°åç`,width:1200,height:480,className:"w-full h-auto object-cover max-h-64",onError:()=>s(!0)}),t&&(0,r.jsx)("div",{className:"flex h-40 items-center justify-center text-sm text-white/70",children:"åçè¼å ¥å¤±æ"})]}),a&&(0,r.jsx)("p",{className:"text-white/90 mb-4",children:a}),l.length>0?(0,r.jsx)("div",{className:"space-y-5",children:l.map(e=>(0,r.jsxs)("div",{children:[(0,r.jsx)("h3",{className:"text-lg font-semibold text-white/90 mb-2",children:e.title}),(0,r.jsx)("ul",{className:"space-y-2",children:e.items.map((e,t)=>(0,r.jsxs)("li",{className:"text-white/90 flex items-start gap-2",children:[(0,r.jsx)("span",{className:"text-white/70 mt-1.5",children:"â¢"}),(0,r.jsx)("span",{children:e})]},t))})]},e.title))}):(0,r.jsx)("div",{className:"text-white/60 text-sm italic",children:"è«å¡«å¯«è®æ´å §å®¹ä»¥é¡¯ç¤ºé 覽"})]})]})]}):(0,r.jsx)("div",{className:"text-center py-8 text-muted-foreground text-sm",children:"è«é¸æç¼å¸æ¥æä»¥é¡¯ç¤ºé 覽"})},tl=({formData:e})=>{let[t,s]=(0,i.useState)(tt[0]?.id??""),a=(0,i.useMemo)(()=>({majorChanges:tr(e.majorChanges),architectureChanges:tr(e.architectureChanges),newFeatures:tr(e.newFeatures),improvements:tr(e.improvements),fixes:tr(e.fixes)}),[e.majorChanges,e.architectureChanges,e.newFeatures,e.improvements,e.fixes]),l=!!e.version&&Object.values(a).some(e=>e.length>0),n=(0,i.useMemo)(()=>l?function(e,t){let s=[];s.push(te),s.push(e.version);let a=(e.summary??e.threadsDevNotes)?.trim(),r=(e.highlights??[]).map(e=>e.trim()).filter(Boolean);if(r.length>0)for(let e of(s.push(""),a&&s.push(a),r))s.push(`⢠${e}`);else a&&(s.push(""),s.push(a)),s.push(...function(e){let t=[];for(let{label:s,items:a}of[{label:"éå¤§è®æ´",items:e.majorChanges},{label:"æ¶æ§è®æ´",items:e.architectureChanges},{label:"æ°å¢åè½",items:e.newFeatures},{label:"åè½æ¹é²",items:e.improvements},{label:"ä¿®è£",items:e.fixes}]){if(!a?.length)continue;t.push("");let e=Math.min(a.length,3);t.push(`${s}:`);for(let s=0;s<e;s++)t.push(`⢠${a[s]}`);a.length>e&&t.push(`â¦ å ± ${a.length} é `)}return t}(e));let i=t?.ctaText??ts(),l=` 2 3${i}`,n=s.join("\n").trim(),d=n+l;if(d.length<=500)return d;let c=500-l.length-3;return c<=0?i:n.slice(0,c)+"â¦"+l}({version:e.version,date:e.date,summary:e.summary??null,...a},{ctaText:function(e){if(!e)return ts();let t=tt.find(t=>t.id===e);return t?.text??ts()}(t)}):"",[l,e.version,e.date,e.summary,a,t]);return l?(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsx)("div",{className:"rounded-lg border bg-muted/30 p-4 text-sm whitespace-pre-wrap max-h-80 overflow-y-auto",children:n}),(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,r.jsx)("label",{htmlFor:"preview-cta",className:"text-xs text-muted-foreground shrink-0",children:"çµå°¾ CTA"}),(0,r.jsx)("select",{id:"preview-cta",value:t,onChange:e=>s(e.target.value),className:"flex-1 max-w-[60%] rounded-md border bg-background px-2 py-1 text-sm",children:tt.map(e=>(0,r.jsx)("option",{value:e.id,children:e.label},e.id))})]}),(0,r.jsxs)("p",{className:"text-xs text-muted-foreground text-right",children:[n.length," / ",500," å"]})]}):(0,r.jsx)("div",{className:"text-center py-8 text-muted-foreground text-sm",children:"å¡«å¯«çæ¬èè®æ´å §å®¹å¾å³å¯é 覽 Threads è²¼æ"})},tn=({formData:e})=>(0,r.jsxs)(y.Zp,{children:[(0,r.jsx)(y.aR,{children:(0,r.jsxs)(y.ZB,{className:"flex items-center gap-2",children:[(0,r.jsx)(el.A,{className:"w-5 h-5"}),"é 覽"]})}),(0,r.jsx)(y.Wu,{children:(0,r.jsxs)(f.tU,{defaultValue:"website",children:[(0,r.jsxs)(f.j7,{className:"max-w-xs",children:[(0,r.jsx)(f.Xi,{value:"website",className:"flex-1",children:"ç¶²ç«å¡ç"}),(0,r.jsx)(f.Xi,{value:"threads",className:"flex-1",children:"Threads è²¼æ"})]}),(0,r.jsx)(f.av,{value:"website",children:(0,r.jsx)(ti,{formData:e})}),(0,r.jsx)(f.av,{value:"threads",children:(0,r.jsx)(tl,{formData:e})})]})})]});var td=s(95513),tc=s(10250),to=s(55790);let tu=e=>[...e.majorChanges??[],...e.architectureChanges??[],...e.newFeatures??[],...e.improvements??[],...e.fixes??[]].filter(e=>""!==e.trim()),tm=({title:e,items:t})=>t&&0!==t.length?(0,r.jsxs)("div",{className:"mb-4 last:mb-0",children:[(0,r.jsx)("h4",{className:"font-semibold mb-2",children:e}),(0,r.jsx)("ul",{className:"list-disc list-inside space-y-1 ml-2",children:t.map((e,t)=>(0,r.jsx)("li",{children:e},t))})]}):null,th=({entries:e,loading:t,onEdit:s,onDelete:a})=>{let[l,n]=(0,i.useState)(new Set),d=e=>n(t=>{let s=new Set(t);return s.has(e)?s.delete(e):s.add(e),s});return t&&0===e.length?(0,r.jsx)($.default,{className:"py-8",size:64,variant:"outline"}):0===e.length?(0,r.jsx)(y.Zp,{children:(0,r.jsx)(y.Wu,{className:"py-8 text-center text-muted-foreground",children:"å°ç¡æ´æ°ç´é"})}):(0,r.jsx)("div",{className:"space-y-2",children:e.map((e,i)=>{let n=(e.highlights??[]).filter(e=>""!==e.trim()),c=e.summary?.trim(),o=c??tu(e)[0]??n[0]??"ï¼ç¡å §å®¹ï¼",u=l.has(e.id);return(0,r.jsxs)("div",{className:"rounded-lg border bg-card overflow-hidden",children:[(0,r.jsxs)("div",{className:"flex items-center gap-3 p-3",children:[(0,r.jsx)("button",{type:"button",onClick:()=>d(e.id),"aria-label":u?"æ¶å":"å±é","aria-expanded":u,className:"shrink-0 text-muted-foreground hover:text-foreground transition-transform",children:(0,r.jsx)(td.A,{className:`w-4 h-4 transition-transform ${u?"rotate-90":""}`})}),(0,r.jsxs)("button",{type:"button",onClick:()=>d(e.id),className:"flex-1 min-w-0 text-left",children:[(0,r.jsxs)("div",{className:"flex items-baseline gap-2",children:[(0,r.jsxs)("span",{className:"font-semibold",children:["Version ",e.version]}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground shrink-0",children:e.date})]}),(0,r.jsx)("p",{className:"text-sm text-muted-foreground truncate",children:o})]}),e.threadsPublishedAt&&(0,r.jsxs)(N.E,{variant:"secondary",className:"shrink-0 gap-1",children:[(0,r.jsx)(tc.A,{className:"w-3 h-3"}),"å·²ç¼ä½"]}
3),(0,r.jsx)(ek.j,{ariaLabel:`æ´æ°ç´é Version ${e.version}`,items:[{id:"edit",label:"編輯",icon:to.A,disabled:t,onSelect:()=>s(i)},{id:"delete",label:"åªé¤",icon:B.A,destructive:!0,disabled:t,onSelect:()=>a(i)}]})]}),u&&(0,r.jsx)("div",{className:"border-t p-3",children:(0,r.jsxs)("div",{className:`p-4 rounded-lg bg-gradient-to-br ${e.gradient} text-white`,children:[c&&(0,r.jsx)("p",{className:"mb-3 text-white/90",children:c}),n.length>0&&0===tu(e).length?(0,r.jsx)("ul",{className:"list-disc list-inside space-y-1",children:n.map((e,t)=>(0,r.jsx)("li",{children:e},t))}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(tm,{title:"éå¤§è®æ´",items:e.majorChanges}),(0,r.jsx)(tm,{title:"æ¶æ§è®æ´",items:e.architectureChanges}),(0,r.jsx)(tm,{title:"æ°å¢åè½",items:e.newFeatures}),(0,r.jsx)(tm,{title:"åè½æ¹é²",items:e.improvements}),(0,r.jsx)(tm,{title:"ä¿®è£",items:e.fixes})]})]})})]},e.id)})})};var tx=s(99185),tp=s(17749);function tj({entryId:e,version:t,published:s,publishing:a,onPublish:l,onDismiss:n}){let{displayText:d,ctaOptions:c,selectedCtaId:o,setSelectedCtaId:u,loading:h,error:x}=function(e,t){let{user:s}=(0,m.A)(),[a,r]=(0,i.useState)(""),[l,n]=(0,i.useState)([]),[d,c]=(0,i.useState)(""),[o,u]=(0,i.useState)(!1),[h,x]=(0,i.useState)(null),p=(0,i.useCallback)(async e=>{if(s){u(!0),x(null);try{let t=await s.getIdToken(),a=await fetch(`/api/changelog/${e}/publish-threads/preview`,{headers:{Authorization:`Bearer ${t}`}}),i=await a.json().catch(()=>({}));if(!a.ok){x(i.error??"ç¡æ³è¼å ¥é 覽"),r(""),n([]),c("");return}r(i.previewText??""),n(i.ctaOptions??[]),c(i.ctaOptions?.[0]?.id??"")}finally{u(!1)}}},[s]);(0,i.useEffect)(()=>{t&&e&&p(e)},[t,e,p]);let j=(0,i.useMemo)(()=>{if(!a||!d)return a;let e=l.find(e=>e.id===d);return e?function(e,t){if(!e)return e;let s=e.lastIndexOf("\n\n"),a=s>=0?e.slice(0,s):e;return`${a} 4 5${t}`}(a,e.text):a},[a,d,l]);return{previewText:a,displayText:j,ctaOptions:l,selectedCtaId:d,setSelectedCtaId:c,loading:o,error:h}}(e,!0);return(0,r.jsxs)(y.Zp,{className:"border-primary/40",children:[(0,r.jsxs)(y.aR,{children:[(0,r.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,r.jsxs)(y.ZB,{className:"flex items-center gap-2",children:[(0,r.jsx)(tc.A,{className:"w-5 h-5 text-emerald-500"}),"å·²å²å ",t]}),(0,r.jsx)(b.$,{variant:"ghost",size:"icon",onClick:n,"aria-label":"éé",children:(0,r.jsx)(X.A,{className:"w-4 h-4"})})]}),(0,r.jsx)("p",{className:"text-sm text-muted-foreground",children:s?"æ¤çæ¬å·²ç¼ä½è³ Threadsã":"æ¯å¦è¦å°éåæ´æ°ç¼ä½å° Threadsï¼"})]}),(0,r.jsxs)(y.Wu,{className:"space-y-4",children:[h&&(0,r.jsx)("div",{className:"text-sm text-muted-foreground py-2",children:"è¼å ¥é 覽ä¸â¦"}),x&&(0,r.jsx)("div",{className:"text-sm text-destructive py-2",children:x}),!h&&!x&&d&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"rounded-lg border bg-muted/30 p-4 text-sm whitespace-pre-wrap max-h-72 overflow-y-auto",children:d}),!s&&(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w.J,{children:"çµå°¾ CTA"}),(0,r.jsx)(tx.z,{value:o,onValueChange:u,className:"grid gap-2 sm:grid-cols-2",children:c.map(e=>(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsx)(tx.C,{value:e.id,id:`ref-cta-${e.id}`}),(0,r.jsx)(w.J,{htmlFor:`ref-cta-${e.id}`,className:"font-normal cursor-pointer",children:e.label})]},e.id))})]}),(0,r.jsx)("div",{className:"flex flex-wrap gap-2 justify-end",children:s?(0,r.jsxs)(b.$,{variant:"secondary",disabled:!0,children:[(0,r.jsx)(tc.A,{className:"w-4 h-4 mr-2"}),"å·²ç¼ä½è³ Threads"]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(b.$,{variant:"outline",onClick:n,disabled:a,children:"æ«ä¸ç¼ä½"}),(0,r.jsxs)(b.$,{onClick:()=>o&&l(e,o),disabled:a||!o,children:[(0,r.jsx)(tp.A,{className:"w-4 h-4 mr-2"}),a?"ç¼ä½ä¸â¦":"ç¼ä½å° Threads"]})]})})]})]})]})}let tg=[{key:"majorChanges",label:"éå¤§è®æ´",placeholder:"è¼¸å ¥éå¤§è®æ´é ç®..."},{key:"architectureChanges",label:"æ¶æ§è®æ´",placeholder:"è¼¸å ¥æ¶æ§è®æ´é ç®..."},{key:"newFeatures",label:"æ°å¢åè½",placeholder:"è¼¸å ¥æ°å¢åè½é ç®..."},{key:"improvements",label:"åè½æ¹é²",placeholder:"è¼¸å ¥åè½æ¹é²é ç®..."},{key:"fixes",label:"ä¿®è£",placeholder:"è¼¸å ¥ä¿®è£é ç®..."}],tf=()=>({version:"",date:"",summary:"",majorChanges:[""],architectureChanges:[""],newFeatures:[""],improvements:[""],fixes:[""],gradient:"",ctaDestinations:[],imageUrl:void 0}),tv=e=>e&&e.length>0?e:[""];function ty(){let[e,t]=(0,i.useState)(!1),[s,a]=(0,i.useState)(null),[l,n]=(0,i.useState)(tf()),[d,c]=(0,i.useState)(null),{entries:o,loading:h,saveEntry:x,deleteEntry:p,confirmPublishToThreads:j,publishingThreadsId:g,getRandomGradient:f,gradientOptions:v}=(()=>{let{toast:e}=(0,u.dj)(),{user:t}=(0,m.A)(),{entries:s,loading:a,reload:r}=function(){let[e,t]=(0,i.useState)([]),[s,a]=(0,i.useState)(!0),[r,l]=(0,i.useState)(null),n=(0,i.useCallback)(async()=>{a(!0),l(null);try{let e=await fetch("/api/changelog?fresh=1",{cache:"no-store"});if(!e.ok)throw Error(`HTTP error! status: ${e.status}`);let s=await e.json();t(s.entries||[])}catch(t){let e=t instanceof Error?t:Error("è¼å ¥æ´æ°æ¥èªå¤±æ");l(e),console.error("è¼å ¥æ´æ°æ¥èªå¤±æ:",e)}finally{a(!1)}},[]);return(0,i.useEffect)(()=>{n()},[n]),{entries:e,loading:s,error:r,reload:n}}(),[l,n]=(0,i.useState)(!1),[d,c]=(0,i.useState)(!1),[o,h]=(0,i.useState)(null),x=(0,i.useCallback)(()=>e0[Math.floor(Math.random()*e0.length)].value,[]),p=async e=>{let t=e.clone(),s=e.headers.get("content-type");if(s?.includes("application/json"))try{let t=await e.json();if("string"==typeof t.error)return t.error;if(t.error?.message)return t.error.message;if(t.error)return JSON.stringify(t.error);return"æªç¥é¯èª¤"}catch(s){try{let e=await t.text();if(e&&e.trim())return e.trim()}catch(e){}return`HTTP ${e.status}: ${e.statusText}`}try{let t=await e.text();if(t&&t.trim())return t.trim()}catch(e){}return`HTTP ${e.status}: ${e.statusText}`},j=(0,i.useCallback)(async(s,a,i)=>{if(!t)return e({variant:"destructive",title:"é¯èª¤",description:"è«å ç»å ¥"}),null;if(!s.version||!s.date)return e({variant:"destructive",title:"é¯èª¤",description:"è«å¡«å¯«æ¥æä»¥ç¢ççæ¬è"}),null;let l=(s.majorChanges??[]).filter(e=>""!==e.trim()),d=(s.architectureChanges??[]).filter(e=>""!==e.trim()),c=(s.newFeatures??[]).filter(e=>""!==e.trim()),o=(s.improvements??[]).filter(e=>""!==e.trim()),u=(s.fixes??[]).filter(e=>""!==e.trim());if(!(l.length>0||d.length>0||c.length>0||o.length>0||u.length>0))return e({variant:"destructive",title:"é¯èª¤",description:"è³å°éè¦å¡«å¯«ä¸é è®æ´å §å®¹"}),null;let m=s.imageUrl?.trim(),h=m&&m.length>0?m:void 0,j=s.gradient?.trim()?s.gradient:x(),g=s.summary?.trim(),f={version:s.version.trim(),date:s.date.trim(),majorChanges:l,architectureChanges:d,newFeatures:c,improvements:o,fixes:u,highlights:[],gradient:j,ctaDestinations:s.ctaDestinations??[],...void 0!==h&&{imageUrl:h},...void 0!==g&&""!==g&&{summary:g}};try{if(n(!0),a){if(i){let s=i.imageUrl;if(s&&!h)try{await (0,eQ.NQ)(s,()=>t.getIdToken())}catch(e){console.error("åªé¤èåç失æ:",e)}let a={...f,imageUrl:s&&!h?null:h},r=await fetch("/api/changelog",{method:"PATCH",headers:{"Content-Type":"application/json",Authorization:`Bearer ${await t.getIdToken()}`},body:JSON.stringify({id:i.id,...a}
5)});if(!r.ok){let e=await p(r);throw Error(e||"æ´æ°å¤±æ")}e({title:"æå",description:"å·²æ´æ°æ´æ°ç´é"})}}else{let s=await fetch("/api/changelog",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${await t.getIdToken()}`},body:JSON.stringify(f)});if(!s.ok){let e=await p(s);throw Error(e||"æ°å¢å¤±æ")}let a=await s.json().catch(()=>({}));return e({title:"æå",description:"å·²æ°å¢æ´æ°ç´é"}),await r(),a.id??null}return await r(),i?.id??null}catch(t){return console.error("å²å失æ:",t),e({variant:"destructive",title:"å²å失æ",description:t instanceof Error?t.message:"è«ç¨å¾å試"}),null}finally{n(!1)}},[t,e,r,x]);return{entries:s,loading:a||l||d,saving:l,deleting:d,saveEntry:j,deleteEntry:(0,i.useCallback)(async s=>{if(!confirm("確å®è¦åªé¤æ¤æ´æ°ç´éåï¼"))return!1;if(!t)return e({variant:"destructive",title:"é¯èª¤",description:"è«å
ç»å
¥"}),!1;try{c(!0);let a=await fetch(`/api/changelog?id=${s.id}`,{method:"DELETE",headers:{Authorization:`Bearer ${await t.getIdToken()}`}}),i=a.ok?await a.json().catch(()=>({})):null,l=i?.alreadyDeleted===!0;if(!a.ok){if(404===a.status)return await r(),e({title:"å·²æ´æ°å表",description:"è©²çæ´æ°ç´éå·²ä¸åå¨ï¼å·²éæ°è¼å
¥å表"}),!0;let t=await p(a);throw Error(t||"åªé¤å¤±æ")}return e({title:"å·²åªé¤",description:l?"該çè¨éå·²ä¸åå¨ï¼å·²æ´æ°å表":"æ´æ°ç´éå·²åªé¤"}),await r(),!0}catch(t){return console.error("åªé¤å¤±æ:",t),e({variant:"destructive",title:"åªé¤å¤±æ",description:t instanceof Error?t.message:"è«ç¨å¾å試"}),!1}finally{c(!1)}},[t,e,r]),confirmPublishToThreads:(0,i.useCallback)(async(s,a)=>{if(!t)return!1;h(s);try{let i=await fetch(`/api/changelog/${s}/publish-threads`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${await t.getIdToken()}`},body:JSON.stringify({ctaId:a})}),l=await i.json().catch(()=>({}));if(!i.ok)return e({variant:"destructive",title:"ç¼ä½å¤±æ",description:l.error??"ç¼ä½è³ Threads 失æ"}),!1;return e({title:"å·²ç¼ä½è³ Threads"}),await r(),!0}finally{h(null)}},[t,e,r]),publishingThreadsId:o,getRandomGradient:x,gradientOptions:e0}})(),w=(0,i.useCallback)((e,t)=>{n(s=>({...s,[e]:t}))},[]),{handleDateChange:N,getInitialVersion:k}=(({formData:e,entries:t,isAdding:s,isEditing:a,editingEntryId:r,onVersionChange:l})=>{let n=(0,i.useCallback)(()=>t.map(e=>({id:e.id,version:e.version})),[t]),d=(0,i.useCallback)(e=>(0,e1.VQ)(e,n(),{excludeEntryId:a?r:void 0}),[n,a,r]),c=(0,i.useCallback)(e=>{(s||a)&&l(d(e))},[s,a,d,l]);return{computeVersionForDate:d,handleDateChange:c,getInitialVersion:(0,i.useCallback)(t=>(0,e1.VQ)(t??e.date,n(),{excludeEntryId:a?r:void 0}),[n,e.date,a,r])}})({formData:l,entries:o,isAdding:e,isEditing:null!==s,editingEntryId:null!==s&&s>=0?o[s]?.id:void 0,onVersionChange:(0,i.useCallback)(e=>{n(t=>({...t,version:e}))},[])}),{uploadingImage:C,imagePreview:A,handleImageUpload:S,handleRemoveImage:T,cleanup:I}=(({version:e,onImageUrlChange:t,editingIndex:s,entries:a})=>{let{toast:r}=(0,u.dj)(),{user:l}=(0,m.A)(),[n,d]=(0,i.useState)(!1),[c,o]=(0,i.useState)(null),h=(0,i.useRef)(null),x=(0,i.useCallback)(e=>e.type.startsWith("image/")?e.size>0xa00000?"åç大å°ä¸è½è¶
é 10MB":null:"åªæ¯æ´åçæ ¼å¼",[]),p=(0,i.useCallback)(async i=>{if(!l)return void r({variant:"destructive",title:"é¯èª¤",description:"è«å
ç»å
¥"});let n=e||"latest";if(!n||"latest"===n)return void r({variant:"destructive",title:"é¯èª¤",description:"è«å
å¡«å¯«çæ¬è"});let c=x(i);if(c)return void r({variant:"destructive",title:"é¯èª¤",description:c});let u=URL.createObjectURL(i);o(u);try{let e;d(!0);let c=()=>l.getIdToken(),m=null!=s&&a&&s>=0&&s<a.length?a[s]?.imageUrl:void 0;e=null!==s&&m&&(0,e2.w2)(m)?(await (0,eQ.HP)({file:i,version:n,oldImageUrl:m,getToken:c})).downloadURL:await (0,eQ.Ds)(i,n,c),t(e),URL.revokeObjectURL(u),o(null),r({title:"æå",description:"åçä¸å³æå"})}catch(e){URL.revokeObjectURL(u),o(null),console.error("åçä¸å³å¤±æ:",e),r({variant:"destructive",title:"ä¸å³å¤±æ",description:e instanceof Error?e.message:"è«ç¨å¾å試"})}finally{d(!1),h.current&&(h.current.value="")}},[l,e,s,a,x,t,r]),j=(0,i.useCallback)(()=>{c&&(URL.revokeObjectURL(c),o(null)),t(void 0),h.current&&(h.current.value="")},[c,t]),g=(0,i.useCallback)(()=>{c&&URL.revokeObjectURL(c)},[c]);return{uploadingImage:n,imagePreview:c,fileInputRef:h,handleImageUpload:p,handleRemoveImage:j,cleanup:g}})({version:l.version,onImageUrlChange:(0,i.useCallback)(e=>{n(t=>({...t,imageUrl:e}))},[]),editingIndex:s,entries:o});(0,i.useEffect)(()=>I,[I]);let E=(0,i.useCallback)(()=>{let e,s=(e=new Date,`${e.getFullYear()}
5-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`);n({...tf(),date:s,version:k(s),gradient:f()}),t(!0),a(null),c(null)},[f,k]),$=(0,i.useCallback)(e=>{if(e<0||e>=o.length)return;let s=o[e],r=s.gradient?.trim()?s.gradient:f(),i=s.majorChanges??[],l=s.architectureChanges??[],d=s.newFeatures??[],u=s.improvements??[],m=s.fixes??[],h=[i,l,d,u,m].some(e=>e.filter(e=>""!==e.trim()).length>0),x=(s.highlights??[]).filter(e=>""!==e.trim());n({version:s.version,date:s.date,summary:s.summary??s.threadsDevNotes??"",majorChanges:tv(i),architectureChanges:tv(l),newFeatures:!h&&x.length>0?x:tv(d),improvements:tv(u),fixes:tv(m),gradient:r,ctaDestinations:s.ctaDestinations??[],imageUrl:s.imageUrl||void 0}),a(e),t(!1),c(null)},[o,f]),R=(0,i.useCallback)(()=>{n(tf()),t(!1),a(null)},[]),D=(0,i.useCallback)(e=>{w("date",e),N(e)},[w,N]),P=(0,i.useCallback)(async()=>{let e=null!==s&&s>=0&&s<o.length,t=e?o[s]:void 0,a=await x(l,e,t);a&&(c({id:a,version:l.version}),R())},[l,s,o,x,R]),F=(0,i.useCallback)(async e=>{e<0||e>=o.length||await p(o[e])},[o,p]),O=(0,i.useCallback)(()=>{w("gradient",f())},[f,w]),_=(0,i.useCallback)((e,t,s)=>{n(a=>{let r=[...a[e]??[]];return r[t]=s,{...a,[e]:r}})},[]),U=(0,i.useCallback)(e=>{n(t=>({...t,[e]:[...t[e]??[],""]}))},[]),z=(0,i.useCallback)((e,t)=>{n(s=>{let a=s[e]??[];return a.length<=1?s:{...s,[e]:a.filter((e,s)=>s!==t)}})},[]),B=(0,i.useMemo)(()=>tg.map(e=>({label:e.label,placeholder:e.placeholder,items:tv(l[e.key]),onUpdate:(t,s)=>_(e.key,t,s),onAdd:()=>U(e.key),onRemove:t=>z(e.key,t)})),[l,_,U,z]),L=d?o.find(e=>e.id===d.id):void 0,Y=e||null!==s;return(0,r.jsxs)("div",{className:"space-y-6",children:[(0,r.jsx)("div",{className:"flex items-center justify-between",children:(0,r.jsxs)("div",{children:[(0,r.jsx)("h2",{className:"text-2xl font-bold",children:"æ´æ°ç´é管ç"}),(0,r.jsx)("p",{className:"text-muted-foreground",children:"管çç¢åæ´æ°ç´éå
§å®¹"})]})}),(0,r.jsxs)("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6 items-start",children:[(0,r.jsxs)("div",{className:"space-y-6 order-2 lg:order-1",children:[Y&&(0,r.jsx)(tn,{formData:l}),(0,r.jsx)(th,{entries:o,loading:h,onEdit:$,onDelete:F})]}),(0,r.jsx)("div",{className:"space-y-6 order-1 lg:order-2 self-start lg:sticky lg:top-4",children:Y?(0,r.jsx)(e7,{formData:l,isEditing:null!==s,uploadingImage:C,imagePreview:A,onDateChange:D,onImageUrlChange:e=>w("imageUrl",e),onRandomGradientClick:O,onSummaryChange:e=>w("summary",e),onImageUpload:S,onRemoveImage:T,onSave:P,onCancel:R,loading:h,gradientOptions:v,sections:B}):d?(0,r.jsx)(tj,{entryId:d.id,version:d.version,published:!!L?.threadsPublishedAt,publishing:g===d.id,onPublish:j,onDismiss:()=>c(null)}):(0,r.jsx)(y.Zp,{className:"border-dashed",children:(0,r.jsxs)(y.Wu,{className:"py-16 text-center text-muted-foreground space-y-4",children:[(0,r.jsx)(eK.A,{className:"w-10 h-10 mx-auto opacity-50"}),(0,r.jsx)("p",{className:"text-sm",children:"é»æãæ°å¢çæ¬ãå»ºç«æ´æ°ï¼æå¾å·¦å´åè¡¨é¸æä¸ç編輯ã"}),(0,r.jsxs)(b.$,{variant:"outline",onClick:E,disabled:h,children:[(0,r.jsx)(eI.A,{className:"w-4 h-4 mr-2"}),"æ°å¢çæ¬"]})]})})})]})]})}var tb=s(62937),tw=s(38410),tN=s(97839);async function tk(e){let t=e.clone(),s=e.headers.get("content-type");if(s?.includes("application/json"))try{let t=await e.json();if("string"==typeof t.error)return t.error;return"æªç¥é¯èª¤"}catch{try{let e=await t.text();if(e.trim())return e.trim()}catch{}}try{let t=await e.text();if(t.trim())return t.trim()}catch{}return`HTTP ${e.status}: ${e.statusText}`}async function tC(e){try{let t=await e.json();if("string"==typeof t.error)return t.error}catch{}return`HTTP ${e.status}: ${e.statusText}`}var tA=s(23381);function tS(e){let t=Date.parse(e);return Number.isNaN(t)?0:t}let tT=()=>{let e;return{displayName:"",metaId:"",subtitle:"",avatarUrl:"",body:"",platform:"threads",publishedAt:(e=new Date,`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`),published:!0}};function tI(e){return e?e.slice(0,10).replace(/-/g,"/"):""}function tE(){let{testimonials:e,loading:t,saving:s,deleting:a,saveTestimonial:l,deleteTestimonial:n,reload:d}=function(){let{user:e}=(0,m.A)(),{toast:t}=(0,u.dj)(),[s,a]=(0,i.useState)([]),[r,l]=(0,i.useState)(!0),[n,d]=(0,i.useState)(!1),[c,o]=(0,i.useState)(!1),h=(0,i.useCallback)(async()=>
5{if(!e)throw Error("è«å
ç»å
¥");let t=await e.getIdToken();return{Authorization:`Bearer ${t}`,"Content-Type":"application/json"}},[e]),x=(0,i.useCallback)(async()=>{if(!e){a([]),l(!1);return}l(!0);try{let e=await h(),t=await fetch("/api/homepage-testimonials?admin=true",{headers:e});if(!t.ok)throw Error(await tk(t));let s=await t.json();a(s.testimonials??[])}catch(e){(0,O.vV)("è¼å
¥å¥½è©ç®¡çå表失æ",e),t({variant:"destructive",title:"è¼å
¥å¤±æ",description:e instanceof Error?e.message:"ç¡æ³è¼å
¥å¥½è©å表"})}finally{l(!1)}},[e,h,t]);(0,i.useEffect)(()=>{x()},[x]);let p=(0,i.useCallback)(async(s,a)=>{if(!e)return t({variant:"destructive",title:"é¯èª¤",description:"è«å
ç»å
¥"}),!1;d(!0);try{let e=await h(),r=String(s.metaId??"").trim(),i=String(s.subtitle??"").trim(),l=a?{metaId:r||"",subtitle:i||""}:{...r?{metaId:r}:{},...i?{subtitle:i}:{}},n={...s,...l,...s.avatarUrl?.toString().trim()?{avatarUrl:s.avatarUrl.toString().trim()}:{},...s.sourceReviewId?.trim()?{sourceReviewId:s.sourceReviewId.trim()}:{}};if(a){let s=await fetch(`/api/homepage-testimonials/${a.id}`,{method:"PATCH",headers:e,body:JSON.stringify(n)});if(!s.ok)throw Error(await tk(s));t({title:"å·²æ´æ°",description:"好è©å·²æ´æ°"})}else{let s=await fetch("/api/homepage-testimonials",{method:"POST",headers:e,body:JSON.stringify(n)});if(!s.ok)throw Error(await tk(s));t({title:"å·²æ°å¢",description:"好è©å·²æ°å¢"})}return await x(),!0}catch(e){return(0,O.vV)("å²å好è©å¤±æ",e),t({variant:"destructive",title:"å²å失æ",description:e instanceof Error?e.message:"ç¡æ³å²å好è©"}),!1}finally{d(!1)}},[e,h,t,x]),j=(0,i.useCallback)(async s=>{if(!e)return!1;o(!0);try{let e=await h(),a=await fetch(`/api/homepage-testimonials/${s}`,{method:"DELETE",headers:e});if(!a.ok)throw Error(await tk(a));return t({title:"å·²åªé¤",description:"好è©å·²åªé¤"}),await x(),!0}catch(e){return(0,O.vV)("åªé¤å¥½è©å¤±æ",e),t({variant:"destructive",title:"åªé¤å¤±æ",description:e instanceof Error?e.message:"ç¡æ³åªé¤å¥½è©"}),!1}finally{o(!1)}},[e,h,t,x]);return{testimonials:s,loading:r,saving:n,deleting:c,reload:x,saveTestimonial:p,deleteTestimonial:j}}(),{reviews:c,loading:o,publishingId:h,publishToHomepage:x}=function(e){let{user:t}=(0,m.A)(),{toast:s}=(0,u.dj)(),[a,r]=(0,i.useState)([]),[l,n]=(0,i.useState)(!0),[d,c]=(0,i.useState)(null),o=(0,i.useCallback)(async()=>{if(!t)throw Error("è«å
ç»å
¥");let e=await t.getIdToken();return{Authorization:`Bearer ${e}`,"Content-Type":"application/json"}},[t]),h=(0,i.useCallback)(async()=>{if(!t){r([]),n(!1);return}n(!0);try{let e=await o(),t=await fetch("/api/reviews/platform?admin=true",{headers:e});if(!t.ok)throw Error(await tC(t));let s=await t.json();r(s.reviews??[])}catch(e){(0,O.vV)("è¼å
¥ç«å
§è©å¹å¤±æ",e),s({variant:"destructive",title:"è¼å
¥å¤±æ",description:e instanceof Error?e.message:"ç¡æ³è¼å
¥ç«å
§è©å¹"})}finally{n(!1)}},[t,o,s]);(0,i.useEffect)(()=>{h()},[h]);let x=(0,i.useCallback)(async a=>{if(!t)return!1;c(a.id);try{let t=await o(),r=await fetch(`/api/reviews/platform/${a.id}/publish`,{method:"POST",headers:t});if(!r.ok)throw Error(await tC(r));return s({title:"å·²ç¼å¸è³é¦é ",description:"好è©å·²ç´æ¥é¡¯ç¤ºå¨é¦é "}),await h(),e?.(),!0}catch(e){return(0,O.vV)("ç¼å¸ç«å
§è©å¹è³é¦é 失æ",e),s({variant:"destructive",title:"ç¼å¸å¤±æ",description:e instanceof Error?e.message:"ç¡æ³ç¼å¸è³é¦é "}),!1}finally{c(null)}},[t,o,s,h,e]);return{reviews:a,loading:l,publishingId:d,reload:h,publishToHomepage:x}}(d),[p,j]=(0,i.useState)(!1),[g,f]=(0,i.useState)(null),[v,k]=(0,i.useState)(tT()),C=(0,i.useCallback)((e,t)=>{k(s=>({...s,[e]:t}))},[]),A=()=>{j(!1),f(null),k(tT())},S=async()=>{var e,t,s;let a,r,i;if(g?.platform==="app"){await l((e=v.published,{displayName:g.displayName,body:g.body,platform:"app",publishedAt:g.publishedAt.slice(0,10),published:e,sourceType:"in_app",rating:g.rating,layoutSize:"sm",sortOrder:tS(g.publishedAt),...g.sourceReviewId?{sourceReviewId:g.sourceReviewId}:{}}),g)&&A();return}!v.displayName.trim()||(0,tA.wV)(v.platform)&&!v.metaId.trim()||await l((t=v,s=g??void 0,a=t.platform,r=t.metaId.trim(),i=t.subtitle.trim(),{displayName:t.displayName.trim(),body:t.body.trim(),platform:a,publishedAt:t.publishedAt,published:t.published,sourceType:"app"===a?"in_app":"social",rating:5,layoutSize:"sm",sortOrder:tS(t.publishedAt),...(0,tA.wV)(a)&&r?{metaId:r}:{},...!(0,tA.wV)(a)&&i?{subtitle:i}:{},...t.avatarUrl.trim()?{avatarUrl:t.avatarUrl.trim()}:{},...s?.sourceReviewId?{sourceReviewId:s.sourceReviewId}:{}}),g??void 0)&&A()},T=g?.platform==="app",I=async e=>{window.confirm("確å®è¦åªé¤æ¤å好è©ï¼")&&(await n(e),g?.id===e&&A())};return(0,r.jsxs)("div",{className:"space-y-6",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("h2",{className:"text-2xl font-bold",children:"é¦é 好è©ç®¡ç"}),(0,r.jsx)("p",{className:"text-sm text-muted-foreground mt-1",children:"社群好è©å¯æåæ°å¢ï¼ç·¨è¼¯ï¼ç«å
§ 4â5 æè©å¹èªå顯示æ¼é¦é ï¼3 æå以ä¸é卿¤å¯©æ ¸ç¼å¸ã"})]}),!p&&(0,r.jsxs)(b.$,{onClick:()=>{k(tT()),f(null),j(!0)},children:[(0,r.jsx)(eI.A,{className:"mr-2 h-4 w-4"}),"æ°å¢ç¤¾ç¾¤å¥½è©"]})]}),p&&(0,r.jsxs)(y.Zp,{children:[(0,r.jsx)(y.aR,{children:(0,r.jsx)(y.ZB,{children:T?"編輯ç«å
§å¥½è©":g?"編輯社群好è©":"æ°å¢ç¤¾ç¾¤å¥½è©"})}),(0,r.jsxs)(y.Wu,{className:"space-y-4",children:[T?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"space-y-2 rounded-lg border border-border/60 bg-muted/20 p-4",children:[(0,r.jsx)("p",{className:"font-semibold",children:g.displayName}),g.rating?(0,r.jsxs)("p",{className:"text-sm text-muted-foreground",children:[g.rating," æ"]}):null,(0,r.jsx)("p",{className:"text-sm text-muted-foreground whitespace-pre-wrap",children:g.body})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)(eM.d,{id:"published",checked:v.published,onCheckedChange:e=>C("published",e)}),(0,r.jsx)(w.J,{htmlFor:"published",children:"ç¼å¸è³é¦é "})]})]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"grid gap-4 md:grid-cols-2",children:[(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w.J,{htmlFor:"displayName",children:"顯示å稱 *"}),(0,r.jsx)(W.p,{id:"displayName",value:v.displayName,onChange:e=>C("displayName",e.target.value)})]}),(0,tA.wV)(v.platform)?(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w.J,{htmlFor:"metaId",children:"Meta ID *"}),(0,r.jsx)(W.p,{id:"metaId",value:v.metaId,onChange:e=>C("metaId",e.target.value),placeholder:"@username æè²¼æ ID"})]}):(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w.J,{htmlFor:"subtitle",children:"坿¨é¡"}),(0,r.jsx)(W.p,{id:"subtitle",value:v.subtitle,onChange:e=>C("subtitle",e.target.value)})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w.J,{htmlFor:"avatarUrl",children:"é å URL"}),(0,r.jsx)(W.p,{id:"avatarUrl",value:v.avatarUrl,onChange:e=>C("avatarUrl",e.target.value),placeholder:"https:// æ /images/..."})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w.J,{htmlFor:"publishedAt",children:"é¡¯ç¤ºæ¥æ *"}),(0,r.jsx)(W.p,{id:"publishedAt",type:"date",value:v.publishedAt,onChange:e=>C("publishedAt",e.target.value)})]}),(0,r.jsxs)("div",{className:"space-y-2 md:col-span-2",children:[(0,r.jsx)(w.J,{children:"å¹³å°"}),(0,r.jsxs)(Z.l6,{value:v.platform,onValueChange:e=>{C("platform",e),(0,tA.wV)(e)?C("subtitle",""):C("metaId","")},children:[(0,r.jsx)(Z.bq,{className:"md:max-w-xs",children:(0,r.jsx)(Z.yv,{})}),(0,r.jsxs)(Z.gC,{children:[(0,r.jsx)(Z.eb,{value:"threads",children:"Threads"}),(0,r.jsx)(Z.eb,{value:"facebook",children:"Facebook"}),(0,r.jsx)(Z.eb,{value:"instagram",children:"Instagram"}),(0,r.jsx)(Z.eb,{value:"other",children:"å
¶ä»"})]})]})]})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w.J,{htmlFor:"body",children:"è©è«å
§å®¹ï¼é¸å¡«ï¼"}),(0,r.jsx)(V.T,{id:"body",rows:4,value:v.body,onChange:e=>C("body",e.target.value)})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)(eM.d,{id:"published",checked:v.published,onCheckedChange:e=>C("published",e)}),(0,r.jsx)(w.J,{htmlFor:"published",children:"ç¼å¸è³é¦é "})]})]}),(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(b.$,{onClick:S,disabled:s,children:s?"å²åä¸â¦":"å
5²å"}),(0,r.jsx)(b.$,{variant:"outline",onClick:A,disabled:s,children:"åæ¶"})]})]})]}),(0,r.jsxs)(y.Zp,{children:[(0,r.jsx)(y.aR,{children:(0,r.jsxs)(y.ZB,{children:["å¾
å¯©æ ¸ç«å
§è©å¹ï¼3 æå以ä¸ï¼(",c.length,")"]})}),(0,r.jsx)(y.Wu,{children:o?(0,r.jsx)($.default,{size:48,className:"py-4"}):0===c.length?(0,r.jsx)("p",{className:"text-sm text-muted-foreground",children:"ç®åæ²æå¾
å¯©æ ¸çç«å
§è©å¹ï¼3 æå以ä¸ï¼"}):(0,r.jsx)("div",{className:"space-y-3",children:c.map(e=>(0,r.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-start justify-between gap-3 p-4 rounded-lg border border-border/60 bg-muted/20",children:[(0,r.jsxs)("div",{className:"min-w-0 flex-1 space-y-1",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,r.jsx)("span",{className:"font-semibold",children:e.userName}),(0,r.jsxs)(N.E,{variant:"outline",children:[e.rating," æ"]}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:"string"==typeof e.createdAt?tI(e.createdAt):""})]}),(0,r.jsx)("p",{className:"text-sm text-muted-foreground line-clamp-3",children:e.comment})]}),(0,r.jsxs)(b.$,{size:"sm",variant:"secondary",onClick:()=>x(e),disabled:h===e.id,children:[(0,r.jsx)(e3.A,{className:"mr-2 h-4 w-4"}),h===e.id?"èçä¸â¦":"ç¼å¸è³é¦é "]})]},e.id))})})]}),(0,r.jsxs)(y.Zp,{children:[(0,r.jsx)(y.aR,{children:(0,r.jsxs)(y.ZB,{children:["好è©å表 (",e.length,")"]})}),(0,r.jsx)(y.Wu,{children:t?(0,r.jsx)($.default,{size:48,className:"py-4"}):0===e.length?(0,r.jsx)("p",{className:"text-sm text-muted-foreground",children:"å°ç¡å¥½è©ï¼è«æ°å¢æå·è¡ç¨®åè
³æ¬"}):(0,r.jsx)("div",{className:"space-y-3",children:e.map(e=>{let t="app"===e.platform;return(0,r.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-start justify-between gap-3 p-4 rounded-lg border border-border/60 bg-muted/20",children:[(0,r.jsxs)("div",{className:"min-w-0 flex-1 space-y-1",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,r.jsx)("span",{className:"font-semibold",children:e.displayName}),(0,r.jsx)(N.E,{variant:"outline",children:e.platform}),t&&e.rating?(0,r.jsxs)(N.E,{variant:"secondary",children:[e.rating," æ"]}):null,!e.published&&(0,r.jsx)(N.E,{variant:"destructive",children:"è稿"}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:tI(e.publishedAt)})]}),(0,r.jsx)("p",{className:"text-sm text-muted-foreground line-clamp-2",children:e.body})]}),(0,r.jsxs)(tN.rI,{children:[(0,r.jsx)(tN.ty,{asChild:!0,children:(0,r.jsxs)(b.$,{variant:"ghost",size:"icon",className:"h-8 w-8 shrink-0",children:[(0,r.jsx)(tb.A,{className:"h-4 w-4"}),(0,r.jsx)("span",{className:"sr-only",children:"æä½é¸å®"})]})}),(0,r.jsxs)(tN.SQ,{align:"end",children:[(0,r.jsxs)(tN._2,{onClick:()=>(e=>{if(f(e),"app"===e.platform){k({...tT(),displayName:e.displayName,body:e.body,published:e.published}),j(!0);return}k({displayName:e.displayName,metaId:e.metaId??((0,tA.wV)(e.platform)?e.subtitle??"":""),subtitle:e.subtitle??"",avatarUrl:e.avatarUrl??"",body:e.body,platform:e.platform,publishedAt:e.publishedAt.slice(0,10),published:e.published}),j(!0)})(e),children:[(0,r.jsx)(tw.A,{className:"mr-2 h-4 w-4"}),"編輯"]}),(0,r.jsxs)(tN._2,{className:"text-destructive focus:text-destructive",onClick:()=>I(e.id),disabled:a,children:[(0,r.jsx)(B.A,{className:"mr-2 h-4 w-4"}),"åªé¤"]})]})]})]},e.id)})})})]})]})}var t$=s(42603),tR=s(8958),tD=s(86754),tP=s(68341),tF=s(53833);let tO=[{type:"NOTIFICATION",label:"éç¥æé"},{type:"FINANCIAL",label:"財åæé"},{type:"ERROR",label:"é¯èª¤"},{type:"WARNING",label:"è¦å"},{type:"SUCCESS",label:"æå"},{type:"COMPLETE",label:"ä»»å宿"},{type:"BACKTEST_COMPLETE",label:"忏¬å®æ"}];function t_(){let{toast:e}=(0,u.dj)(),{playSoundForTest:t}=(0,t$.f)(),[s,a]=(0,i.useState)(null),[l,n]=(0,i.useState)({}),d=async s=>{a(s),n(e=>({...e,[s]:void 0}));try{let a=await t(s);n(e=>({...e,[s]:a}));let r=tO.find(e=>e.type===s),i=r?.label??s;a?e({title:"ææ¾æå",description:`${i} è·¯å¾æ£ç¢ºä¸å¯ææ¾`}):e({title:"ææ¾å¤±æ",description:`${i} è·¯å¾å¯è½é¯èª¤ææªæ¡ä¸åå¨`,variant:"destructive"})}catch(t){n(e=>({...e,[s]:!1})),e({title:"測試失æ",description:"ç¼çé¯èª¤ï¼è«ç¨å¾å試",variant:"destructive"})}finally{a(null)}};return(0,r.jsxs)(y.Zp,{children:[(0,r.jsxs)(y.aR,{children:[(0,r.jsxs)(y.ZB,{className:"flex items-center gap-2",children:[(0,r.jsx)(tD.A,{className:"h-5 w-5"}),"é³ææ¸¬è©¦"]}),(0,r.jsx)(y.BT,{children:"ä¾åºææ¾åé³æä»¥ç¢ºèªæªæ¡è·¯å¾æ¯å¦æ£ç¢ºãæªæ¡æ¯å¦åå¨"})]}),(0,r.jsx)(y.Wu,{children:(0,r.jsx)("div",{className:"rounded-lg border overflow-hidden",children:(0,r.jsxs)("table",{className:"w-full text-sm",children:[(0,r.jsx)("thead",{children:(0,r.jsxs)("tr",{className:"border-b bg-muted/50",children:[(0,r.jsx)("th",{className:"text-left font-medium p-3",children:"鳿"}),(0,r.jsx)("th",{className:"text-left font-medium p-3",children:"è·¯å¾"}),(0,r.jsx)("th",{className:"text-right font-medium p-3 w-32",children:"測試"})]})}),(0,r.jsx)("tbody",{children:tO.map(({type:e,label:t})=>{let a=(0,tR.Z6)(e),i=s===e,n=l[e];return(0,r.jsxs)("tr",{className:"border-b last:border-b-0",children:[(0,r.jsx)("td",{className:"p-3 font-medium",children:t}),(0,r.jsx)("td",{className:"p-3 text-muted-foreground font-mono text-xs break-all",children:a}),(0,r.jsx)("td",{className:"p-3 text-right",children:(0,r.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[!0===n&&(0,r.jsx)(tP.A,{className:"h-4 w-4 text-green-600"}),!1===n&&(0,r.jsx)(X.A,{className:"h-4 w-4 text-destructive"}),(0,r.jsxs)(b.$,{variant:"ghost",size:"sm",onClick:()=>d(e),disabled:i,children:[(0,r.jsx)(tF.A,{className:"h-4 w-4 mr-1"}),i?"ææ¾ä¸â¦":"ææ¾"]})]})})]},e)})})]})})})]})}var tU=s(64311),tz=s(81154),tB=s(93773);let tL=[{id:"firestore",label:"Firestore",description:"æª¢æ¥ Firestore é£ç·"},{id:"health",label:"ééµ API å¥åº·",description:"å½ç¸½å¤å API å¥åº·çæ
"}];async function tY(){let{auth:e}=await Promise.resolve().then(s.bind(s,76458)),t=e?.currentUser;if(!t)throw Error("æªç»å
¥");let a=await t.getIdToken(!0);return{Authorization:`Bearer ${a}`}}function tJ(){let{user:e}=(0,m.A)(),{toast:t}=(0,u.dj)(),s=(0,d.useRouter)(),[a,l]=(0,i.useState)([]),[n,c]=(0,i.useState)(null),[o,h]=(0,i.useState)([]),[x,p]=(0,i.useState)([]),[j,f]=(0,i.useState)(null),[v,w]=(0,i.useState)(null),[N,k]=(0,i.useState)(!1),[C,A]=(0,i.useState)(!1),S=(0,i.useCallback)(async s=>{if(e){c(s),l(e=>e.filter(e=>e.id!==s));try{let e=await tY(),a=await fetch(`/api/admin/test/${s}`,{headers:e}),r=await a.json().catch(()=>({})),i=a.ok&&(!0===r.success||!0===r.ok),n={id:s,success:i,message:r.message??r.error??(i?"éé":"失æ"),details:r.details,at:new Date().toISOString()};l(e=>[...e,n]),i?t({title:`${tL.find(e=>e.id===s)?.label} éé`}):t({variant:"destructive",title:`${tL.find(e=>e.id===s)?.label} 失æ`,description:n.message})}catch(a){let e=a instanceof Error?a:Error(String(a));g.Cp(e,{level:"error",extra:{message:"[TestPanel] æ¨¡çµæ¸¬è©¦è«æ±å¤±æ",id:s},tags:{source:"AdminTestPanel.runModuleTest"}}),l(t=>[...t,{id:s,success:!1,message:e.message,at:new Date().toISOString()}]),t({variant:"destructive",title:"è«æ±å¤±æ",description:e.message})}finally{c(null)}}},[e,t]),T=(0,i.useCallback)(async()=>
5{if(e){for(let e of(c("all"),l([]),tL))await S(e.id);c(null),t({title:"å
¨é¨æ¨¡çµæ¸¬è©¦å·²å®æ"})}},[e,S,t]),I=(0,i.useCallback)(async()=>{if(e){k(!0),w(null);try{let e=await tY(),s=await fetch("/api/admin/test/cleanup",{method:"POST",headers:{...e,"Content-Type":"application/json"},body:JSON.stringify({confirm:"I_UNDERSTAND"})}),a=await s.json().catch(()=>({})),r={success:s.ok,firestore:a.firestore,storage:a.storage,error:a.error};w(r),s.ok?t({title:"æ¸
ç宿",description:"測試使ç¨è
è³æå·²æ¸
ç"}):t({variant:"destructive",title:"æ¸
ç失æ",description:a.error})}catch(s){let e=s instanceof Error?s:Error(String(s));g.Cp(e,{level:"error",extra:{message:"[TestPanel] æ¸
çè«æ±å¤±æ"},tags:{source:"AdminTestPanel.runCleanup"}}),w({success:!1,error:e.message}),t({variant:"destructive",title:"æ¸
ç失æ",description:e.message})}finally{k(!1)}}},[e,t]),E=(0,i.useCallback)(async()=>{if(e){A(!0);try{await (0,tU.ks)(e.uid),t({title:"å·²éè¨æ°æå¼å°",description:"å³å°åå¾å表æ¿éæ°é«é©å¼å°â¦"}),setTimeout(()=>{s.push("/dashboard"),s.refresh()},700)}catch(s){let e=s instanceof Error?s:Error(String(s));g.Cp(e,{level:"error",extra:{message:"[TestPanel] éè¨æ°æå¼å°å¤±æ"},tags:{source:"AdminTestPanel.resetFirstRun"}}),t({variant:"destructive",title:"éè¨å¤±æ",description:e.message}),A(!1)}}},[e,t,s]),$=(0,i.useCallback)(async()=>{try{let e=await fetch("/api/admin/test/flows",{headers:await tY()});if(!e.ok)return;let t=await e.json();h(Array.isArray(t.flows)?t.flows:[])}catch{h([])}},[]),R=(0,i.useCallback)(async s=>{if(e){f(s),p([]),w(null);try{let e=await tY();await fetch("/api/admin/test/cleanup",{method:"POST",headers:{...e,"Content-Type":"application/json"},body:JSON.stringify({confirm:"I_UNDERSTAND"})}),p(e=>[...e,{stepId:"cleanup-before",title:"æ¸
çæ¸¬è©¦è³æï¼Beforeï¼",status:"passed"}]);let a=await fetch("/api/admin/test/flow/run",{method:"POST",headers:{...e,"Content-Type":"application/json"},body:JSON.stringify({flowId:s})}),r=await a.json().catch(()=>({})),i=Array.isArray(r.steps)?r.steps:[];p(e=>[...e,...i]);let l=await fetch("/api/admin/test/cleanup",{method:"POST",headers:{...e,"Content-Type":"application/json"},body:JSON.stringify({confirm:"I_UNDERSTAND"})});p(e=>[...e,{stepId:"cleanup-after",title:"æ¸
çæ¸¬è©¦è³æï¼Finallyï¼",status:"passed"}]);let n=await l.json().catch(()=>({}));n.success&&(n.firestore||n.storage)?w({success:!0,firestore:n.firestore,storage:n.storage}):r.cleanupSummary&&w(r.cleanupSummary),i.every(e=>"passed"===e.status)?t({title:"æµç¨æ¸¬è©¦å®æ",description:"æææ¥é©éé"}):t({variant:"destructive",title:"æµç¨æ¸¬è©¦å¤±æ",description:"é¨åæ¥é©æªéé"})}catch(a){let e=a instanceof Error?a:Error(String(a));g.Cp(e,{level:"error",extra:{message:"[TestPanel] æµç¨æ¸¬è©¦å¤±æ",flowId:s},tags:{source:"AdminTestPanel.runFlow"}}),p(t=>[...t,{stepId:"error",title:"å·è¡é¯èª¤",status:"failed",message:e.message}]),t({variant:"destructive",title:"æµç¨æ¸¬è©¦å¤±æ",description:e.message})}finally{f(null)}}},[e,t]);return(0,i.useEffect)(()=>{$()},[$]),(0,r.jsxs)("div",{className:"space-y-6",children:[(0,r.jsxs)(y.Zp,{children:[(0,r.jsxs)(y.aR,{children:[(0,r.jsxs)(y.ZB,{className:"flex items-center gap-2",children:[(0,r.jsx)(tz.A,{className:"h-5 w-5"}),"æ°æå¼å°æ¸¬è©¦"]}),(0,r.jsx)(y.BT,{children:"éè¨ç®å帳èç First Run çæ
ï¼ä¸¦åå¾å表æ¿éæ°é«é©æ°æå¼å°ï¼å¯åè¦æ¸¬è©¦ï¼"})]}),(0,r.jsxs)(y.Wu,{className:"space-y-2",children:[(0,r.jsxs)(b.$,{variant:"outline",size:"sm",disabled:C||!e,onClick:E,children:[C?(0,r.jsx)(eA.A,{className:"h-4 w-4 animate-spin mr-2"}):(0,r.jsx)(tz.A,{className:"h-4 w-4 mr-2"}),"éè¨æ°æå¼å°"]}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:"å
å½±é¿ä½ èªå·±ç帳èï¼æ¸
é¤ globalFlowCompleted / skippedAtï¼ï¼ä¸æåªé¤ä»»ä½è²¡åè³æã"})]})]}),(0,r.jsxs)(y.Zp,{children:[(0,r.jsxs)(y.aR,{children:[(0,r.jsxs)(y.ZB,{className:"flex items-center gap-2",children:[(0,r.jsx)(tB.A,{className:"h-5 w-5"}),"æ¨¡çµæ¸¬è©¦"]}),(0,r.jsx)(y.BT,{children:"Firestoreãééµ API å¥åº·æª¢æ¥ï¼çµæå³æé¡¯ç¤º"})]}),(0,r.jsxs)(y.Wu,{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"flex flex-wrap gap-2",children:[tL.map(e=>(0,r.jsxs)(b.$,{variant:"outline",size:"sm",disabled:null!==n,onClick:()=>S(e.id),children:[n===e.id?(0,r.jsx)(eA.A,{className:"h-4 w-4 animate-spin mr-2"}):null,e.label]},e.id)),(0,r.jsxs)(b.$,{variant:"default",size:"sm",disabled:null!==n,onClick:T,children:["all"===n?(0,r.jsx)(eA.A,{className:"h-4 w-4 animate-spin mr-2"}):null,"å·è¡å
¨é¨"]})]}),a.length>0&&(0,r.jsx)("div",{className:"rounded-md border bg-muted/30 p-3 font-mono text-sm max-h-48 overflow-y-auto",children:a.map((e,t)=>(0,r.jsxs)("div",{className:"flex items-center gap-2 py-1",children:[e.success?(0,r.jsx)(tP.A,{className:"h-4 w-4 text-green-600"}):(0,r.jsx)(X.A,{className:"h-4 w-4 text-red-600"}),(0,r.jsxs)("span",{children:["[",e.id,"]"]}),(0,r.jsx)("span",{children:e.message}),e.details&&(0,r.jsx)("span",{className:"text-muted-foreground",children:JSON.stringify(e.details)})]},`${e.id}-${t}`))})]})]}),(0,r.jsxs)(y.Zp,{children:[(0,r.jsxs)(y.aR,{children:[(0,r.jsxs)(y.ZB,{className:"flex items-center gap-2",children:[(0,r.jsx)(B.A,{className:"h-5 w-5"}),"æ¸¬è©¦è³ææ¸
ç"]}),(0,r.jsx)(y.BT,{children:"æ¸
çåºå®æ¸¬è©¦ä½¿ç¨è
ç Firestore è Storage è³æï¼ç½å宿¸¬è©¦å¸³èï¼"})]}),(0,r.jsxs)(y.Wu,{className:"space-y-4",children:[(0,r.jsxs)(b.$,{variant:"outline",size:"sm",disabled:N,onClick:I,children:[N?(0,r.jsx)(eA.A,{className:"h-4 w-4 animate-spin mr-2"}):null,"å·è¡æ¸
ç"]}),v&&(0,r.jsx)("div",{className:"rounded-md border bg-muted/30 p-3 text-sm",children:v.success?(0,r.jsxs)(r.Fragment,{children:[v.firestore&&(0,r.jsxs)("p",{children:["Firestore: ",Object.entries(v.firestore).map(([e,t])=>`${e}=${t}
5`).join(", ")]}),null!=v.storage&&(0,r.jsxs)("p",{children:["Storage åªé¤æ¸: ",v.storage.deletedCount]})]}):(0,r.jsx)("p",{className:"text-destructive",children:v.error})})]})]}),(0,r.jsxs)(y.Zp,{children:[(0,r.jsxs)(y.aR,{children:[(0,r.jsxs)(y.ZB,{className:"flex items-center gap-2",children:[(0,r.jsx)(tF.A,{className:"h-5 w-5"}),"æµç¨æ¸¬è©¦"]}),(0,r.jsx)(y.BT,{children:"è¨å®æªé©
åç E2E æµç¨ï¼Before æ¸
ç â å·è¡ â Finally æ¸
çï¼"})]}),(0,r.jsxs)(y.Wu,{className:"space-y-4",children:[(0,r.jsx)(b.$,{variant:"outline",size:"sm",onClick:$,children:"è¼å
¥æµç¨æ¸
å®"}),0===o.length&&(0,r.jsx)("p",{className:"text-muted-foreground text-sm",children:"å°ç¡æµç¨æè«å
è¼å
¥æµç¨æ¸
å®"}),(0,r.jsx)("ul",{className:"list-disc list-inside space-y-1",children:o.map(e=>(0,r.jsxs)("li",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"font-medium",children:e.name}),(0,r.jsx)("span",{className:"text-muted-foreground text-sm",children:e.description}),(0,r.jsxs)(b.$,{variant:"ghost",size:"sm",disabled:null!==j,onClick:()=>R(e.id),children:[j===e.id?(0,r.jsx)(eA.A,{className:"h-4 w-4 animate-spin"}):(0,r.jsx)(tF.A,{className:"h-4 w-4"}),"å·è¡"]})]},e.id))}),x.length>0&&(0,r.jsx)("div",{className:"rounded-md border bg-muted/30 p-3 font-mono text-sm max-h-64 overflow-y-auto",children:x.map((e,t)=>(0,r.jsxs)("div",{className:"flex items-center gap-2 py-1",children:["passed"===e.status?(0,r.jsx)(tP.A,{className:"h-4 w-4 text-green-600"}):(0,r.jsx)(X.A,{className:"h-4 w-4 text-red-600"}),(0,r.jsxs)("span",{children:["[",e.stepId,"]"]}),(0,r.jsx)("span",{children:e.title}),e.message&&(0,r.jsx)("span",{className:"text-muted-foreground",children:e.message})]},t))})]})]})]})}function tM(){let{user:e}=(0,m.A)(),[t,s]=(0,i.useState)(null),[a,l]=(0,i.useState)(!0),[n,d]=(0,i.useState)(null);if((0,i.useEffect)(()=>{if(!e)return void l(!1);let t=!1;return l(!0),d(null),e.getIdToken().then(e=>fetch("/api/admin/onboarding-metrics",{headers:{Authorization:`Bearer ${e}`}})).then(e=>{if(!e.ok)throw Error(403===e.status?"æ¬éä¸è¶³":e.statusText);return e.json()}).then(e=>{t||s(e)}).catch(e=>{t||d(e instanceof Error?e.message:"è¼å
¥å¤±æ")}).finally(()=>{t||l(!1)}),()=>{t=!0}},[e]),a)return(0,r.jsx)(y.Zp,{children:(0,r.jsx)(y.Wu,{className:"pt-6",children:(0,r.jsx)($.default,{size:48})})});if(n)return(0,r.jsx)(y.Zp,{children:(0,r.jsx)(y.Wu,{className:"pt-6",children:(0,r.jsx)("p",{className:"text-destructive",children:n})})});if(!t)return(0,r.jsx)(y.Zp,{children:(0,r.jsx)(y.Wu,{className:"pt-6",children:(0,r.jsx)("p",{className:"text-muted-foreground",children:"å°ç¡è³æ"})})});let{total:c,completed:o,skipped:u,activationRate:h,stepDropoff:x}=t;return(0,r.jsx)("div",{className:"space-y-6",children:(0,r.jsxs)(y.Zp,{children:[(0,r.jsxs)(y.aR,{children:[(0,r.jsx)(y.ZB,{children:"First Run Onboarding ææ¨"}),(0,r.jsx)(y.BT,{children:"ä¾ Firestore users éåä¹ onboarding æ¬ä½å½ç¸½ï¼å
æ onboarding çç¨æ¶è¨å
¥ï¼"})]}),(0,r.jsxs)(y.Wu,{className:"space-y-6",children:[(0,r.jsxs)("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:[(0,r.jsxs)("div",{className:"rounded-lg border p-4",children:[(0,r.jsx)("p",{className:"text-sm text-muted-foreground",children:"ç´å
¥çµ±è¨ç¨æ¶æ¸"}),(0,r.jsx)("p",{className:"text-2xl font-bold",children:c})]}),(0,r.jsxs)("div",{className:"rounded-lg border p-4",children:[(0,r.jsx)("p",{className:"text-sm text-muted-foreground",children:"Activation Rateï¼å®æçï¼"}),(0,r.jsxs)("p",{className:"text-2xl font-bold",children:[h,"%"]})]}),(0,r.jsxs)("div",{className:"rounded-lg border p-4",children:[(0,r.jsx)("p",{className:"text-sm text-muted-foreground",children:"已宿"}),(0,r.jsx)("p",{className:"text-2xl font-bold",children:o})]}),(0,r.jsxs)("div",{className:"rounded-lg border p-4",children:[(0,r.jsx)("p",{className:"text-sm text-muted-foreground",children:"å·²ç¥é"}),(0,r.jsx)("p",{className:"text-2xl font-bold",children:u})]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("h3",{className:"mb-2 font-semibold",children:"Step Drop-offï¼åæ¥é©äººæ¸ï¼"}),(0,r.jsxs)("ul",{className:"space-y-1 text-sm",children:[(0,r.jsxs)("li",{children:["welcome_goal: ",x.welcome_goal??0]}),(0,r.jsxs)("li",{children:["accounts: ",x.accounts??0]}),(0,r.jsxs)("li",{children:["cashflow: ",x.cashflow??0]}),(0,r.jsxs)("li",{children:["investment: ",x.investment??0]}),(0,r.jsxs)("li",{children:["done: ",x.done??0]})]})]})]})]})})}var tW=s(27012);function tV({children:e}){let{isOpen:t,action:s,isLoading:a,reason:i,hideConfirmation:l,setLoading:n,setReason:d}=J(),c=async e=>{if(s)try{n(!0),await new Promise(e=>setTimeout(e,1e3)),l()}catch(e){n(!1)}};return(0,r.jsxs)(r.Fragment,{children:[e,s&&(0,r.jsx)(Y,{isOpen:t,onClose:l,onConfirm:c,action:s,isLoading:a,reason:i,onReasonChange:d})]})}var tZ=s(31283),tH=s(37014),tq=s(43967);function tG(){let{toast:e}=(0,u.dj)(),[t,s]=(0,i.useState)([]),[a,l]=(0,i.useState)(!0),[n,d]=(0,i.useState)(null),[c,o]=(0,i.useState)(null),[m,h]=(0,i.useState)(!1),{createTemplate:x}=(0,tq.M)(),p=(0,i.useCallback)(async()=>
5{if(j.db)try{l(!0);let e=(0,_.P)((0,_.rJ)(j.db,j.CREDIT_CARD_TEMPLATE_REQUESTS),(0,_._M)("status","==","pending"),(0,_.My)("createdAt","desc")),t=(await (0,_.GG)(e)).docs.map(e=>({id:e.id,...e.data()}));s(t)}catch(t){(0,O.vV)("è¼å
¥å»ºè°æ°å¢å¡çä½å失æ",t),e({title:"è¼å
¥å¤±æ",description:t.message||"ç¡æ³è¼å
¥ä½å",variant:"destructive"})}finally{l(!1)}},[e]);(0,i.useEffect)(()=>{p()},[p]);let g=async t=>{d(t.id),h(!0);try{let s=(await (0,tH.callFn)("renderAndParseCreditCardPage",{url:t.url})).data;if(s?.error)return void e({title:"è§£æå¤±æ",description:s.message||"ç¡æ³åå¾é 颿çºé¯èª¤é ",variant:"destructive"});o({request:t,preview:{bank:s.bank,cardName:s.cardName,benefits:s.benefits||[]}})}catch(t){(0,O.vV)("renderAndParseCreditCardPage 失æ",t),e({title:"è§£æå¤±æ",description:t.message||"ç¡æ³è§£æç¶²å",variant:"destructive"})}finally{h(!1),d(null)}},f=async()=>{if(!c||!j.db)return;let{request:t,preview:s}=c;if(!s.bank||!s.cardName)return void e({title:"è³æä¸å®æ´",description:"ç¡æ³å»ºç«å¡çï¼ç¼ºå°éè¡æå¡çå稱",variant:"destructive"});h(!0);try{let a=await x({name:s.cardName,bank:s.bank,categories:[],benefits:s.benefits||[],isActive:!0,createdAt:_.Timestamp.now(),updatedAt:_.Timestamp.now()});await (0,_.mZ)((0,_.doc)(j.db,j.CREDIT_CARD_TEMPLATE_REQUESTS,t.id),{status:"processed",processedAt:_.Timestamp.now(),templateId:a||""}),e({title:"èçæå",description:"已建ç«ç¼è¡ä¸å¡ç"}),o(null),p()}catch(t){(0,O.vV)("建ç«ç¼è¡ä¸å¡ç失æ",t),e({title:"建ç«å¤±æ",description:t.message||"ç¡æ³å»ºç«ç¼è¡ä¸å¡ç",variant:"destructive"})}finally{h(!1)}},v=async t=>{if(confirm("確å®è¦æçµæ¤è«æ±åï¼")&&j.db)try{await (0,_.mZ)((0,_.doc)(j.db,j.CREDIT_CARD_TEMPLATE_REQUESTS,t),{status:"rejected",processedAt:_.Timestamp.now()}),e({title:"å·²æçµ",description:"è«æ±å·²æ¨è¨çºå·²æçµ"}),p()}catch(t){(0,O.vV)("æçµè«æ±å¤±æ",t),e({title:"æä½å¤±æ",description:t.message||"ç¡æ³æçµè«æ±",variant:"destructive"})}};return(0,r.jsxs)("div",{className:"space-y-6",children:[(0,r.jsxs)(y.Zp,{children:[(0,r.jsxs)(y.aR,{children:[(0,r.jsx)(y.ZB,{children:"å»ºè°æ°å¢å¡çä½å"}),(0,r.jsx)(y.BT,{children:"èçç¨æ¶æäº¤çå»ºè°æ°å¢ç¼è¡ä¸å¡çè«æ±"})]}),(0,r.jsx)(y.Wu,{children:a?(0,r.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,r.jsx)(eA.A,{className:"h-6 w-6 animate-spin"})}):0===t.length?(0,r.jsx)("div",{className:"text-center py-8 text-muted-foreground",children:"ç®åæ²æå¾
èççè«æ±"}):(0,r.jsxs)(eg.XI,{children:[(0,r.jsx)(eg.A0,{children:(0,r.jsxs)(eg.Hj,{children:[(0,r.jsx)(eg.nd,{children:"ç¶²å"}),(0,r.jsx)(eg.nd,{children:"æäº¤æé"}),(0,r.jsx)(eg.nd,{children:"æä½"})]})}),(0,r.jsx)(eg.BF,{children:t.map(e=>(0,r.jsxs)(eg.Hj,{children:[(0,r.jsx)(eg.nA,{children:(0,r.jsxs)("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:underline flex items-center gap-1",children:[e.url,(0,r.jsx)(tZ.A,{className:"h-3 w-3"})]})}),(0,r.jsx)(eg.nA,{children:e.createdAt?function(e){let t=e?.toDate?.();if(!t)return"-";let s=new Date().getTime()-t.getTime(),a=Math.floor(s/6e4),r=Math.floor(s/36e5),i=Math.floor(s/864e5);return a<1?"åå":a<60?`${a} åéå`:r<24?`${r} å°æå`:i<30?`${i} 天å`:t.toLocaleString("zh-TW")}(e.createdAt):"-"}),(0,r.jsx)(eg.nA,{children:(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(b.$,{size:"sm",onClick:()=>g(e),disabled:n===e.id||m,children:n===e.id||m?(0,r.jsx)(eA.A,{className:"h-4 w-4 animate-spin"}):"èç"}),(0,r.jsx)(b.$,{size:"sm",variant:"outline",onClick:()=>v(e.id),children:(0,r.jsx)(es.A,{className:"h-4 w-4"})})]})})]},e.id))})]})})]}),(0,r.jsx)(z.lG,{open:!!c,onOpenChange:e=>!e&&o(null),children:(0,r.jsxs)(z.Cf,{className:"max-w-2xl",children:[(0,r.jsxs)(z.c7,{children:[(0,r.jsx)(z.L3,{children:"é 覽ç¼è¡ä¸å¡ç"}),(0,r.jsx)(z.rr,{children:"確èªè³è¨ç¡èª¤å¾ï¼é»æã建ç«å¡çãå³å¯æ°å¢å°ç¼è¡ä¸å¡çå表"})]}),c&&(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"text-sm font-medium",children:"éè¡"}),(0,r.jsx)("p",{className:"text-sm text-muted-foreground",children:c.preview.bank||"æªè§£æå°éè¡"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"text-sm font-medium",children:"å¡çå稱"}),(0,r.jsx)("p",{className:"text-sm text-muted-foreground",children:c.preview.cardName||"æªè§£æå°å¡çå稱"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"text-sm font-medium",children:"åªæ æ¸é"}),(0,r.jsxs)("p",{className:"text-sm text-muted-foreground",children:[Array.isArray(c.preview.benefits)?c.preview.benefits.length:0," é
"]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"text-sm font-medium",children:"åå§ç¶²å"}),(0,r.jsxs)("a",{href:c.request.url,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-blue-600 hover:underline flex items-center gap-1",children:[c.request.url,(0,r.jsx)(tZ.A,{className:"h-3 w-3"})]})]})]}),(0,r.jsxs)(z.Es,{children:[(0,r.jsx)(b.$,{variant:"outline",onClick:()=>o(null),disabled:m,children:"åæ¶"}),(0,r.jsx)(b.$,{onClick:f,disabled:m||!c?.preview.bank||!c?.preview.cardName,children:m?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(eA.A,{className:"mr-2 h-4 w-4 animate-spin"}),"建ç«ä¸..."]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(tc.A,{className:"mr-2 h-4 w-4"}),"建ç«å¡ç"]})})]})]})})]})}var tX=s(62557),tK=s(26345),tQ=s(7004),t0=s(36297);let t1="credit_card_crawl_config",t2="default",t4=t0.SX.map(e=>e.label),t3=[/æ¨éè¦åç¨\s*JavaScript\s*æè½å·è¡æ¤æç¨ç¨å¼\.?/i,/You need to enable JavaScript to run this app\.?/i];function t5(e){if(null==e||""===e)return"";let t=e.trim();for(let e of t3)t=t.replace(e,"").trim();return t}function t6(e){return!!e.appliedAt}function t8(e){return(e.pipelineVersion??1)<2}function t7(e){return e.runId??e.id}function t9(e){let t=e?.toDate?.();
5return t?t.toLocaleString("zh-TW"):""}let se={title:"",description:"",conditions:"",category:"",rate:"",validUntil:""};function st(){let{toast:e}=(0,u.dj)(),[t,s]=(0,i.useState)("review"),[a,l]=(0,i.useState)(()=>({banks:t4.map(e=>({bankName:e,entryUrls:[]})),limits:{perSeedMaxLinks:20}})),[n,d]=(0,i.useState)(!0),[c,o]=(0,i.useState)(!1),[m,h]=(0,i.useState)(null),[x,p]=(0,i.useState)(""),[g,v]=(0,i.useState)(null),[C,A]=(0,i.useState)(!1),[S,T]=(0,i.useState)([]),[I,E]=(0,i.useState)(null),[$,R]=(0,i.useState)(null),[D,P]=(0,i.useState)(new Set),[F,U]=(0,i.useState)(null),[z,L]=(0,i.useState)({}),[Y,J]=(0,i.useState)({}),[M,Z]=(0,i.useState)(new Set),[H,q]=(0,i.useState)(new Set),[G,X]=(0,i.useState)(new Set),K=(0,i.useRef)(!1),[Q,ee]=(0,i.useState)(null),[et,es]=(0,i.useState)(se);(0,i.useEffect)(()=>{if(!j.db)return void d(!1);let e=(0,_.doc)(j.db,t1,t2);(0,_.getDoc)(e).then(e=>{var t;let s;l((t=e.exists()?e.data():void 0,s=Array.isArray(t?.banks)?t.banks:[],{banks:t4.map(e=>{let t=s.find(t=>t.bankName===e);return{bankName:e,entryUrls:Array.isArray(t?.entryUrls)?t.entryUrls:[]}}),limits:{perSeedMaxLinks:20}}))}).catch(e=>{(0,O.vV)("è®åç¬åè¨å®å¤±æ",e),U("ç¡æ³è¼å
¥è¨å®")}).finally(()=>d(!1))},[]),(0,i.useEffect)(()=>{if(!j.db)return;let e=(0,_.P)((0,_.rJ)(j.db,"credit_card_benefit_jobs"),(0,_.My)("createdAt","desc"),(0,_.AB)(40)),t=(0,_.aQ)(e,e=>{let t=e.docs.map(e=>({id:e.id,...e.data()}));if(T(t),!K.current&&t.length>0){let e=t7(t[0]),s=t.filter(t=>t7(t)===e&&"completed"===t.status&&!t6(t)&&!t8(t));Z(new Set(s.length>0?s.map(e=>e.id):[t[0].id])),K.current=!0}},e=>{(0,O.vV)("ç£è½ä»»åå表失æ",e)});return()=>t()},[]);let ea=e=>z[e.id]??e.preview?.updates??[],er=e=>Y[e.id]??e.preview?.unmatchedBenefits??[],ei=(e,t)=>{e(e=>{let s=new Set(e);return s.has(t)?s.delete(t):s.add(t),s})},el=async(t,s,a="å·²å²åè¨å®")=>{if(j.db){o(!0),U(null);try{let r=(0,_.doc)(j.db,t1,t2);await (0,_.setDoc)(r,{banks:t,limits:s,updatedAt:(0,_.serverTimestamp)()},{merge:!0}),e({title:a})}catch(s){let t=s?.message??"å²å失æ";U(t),(0,O.vV)("å²åç¬åè¨å®å¤±æ:",s),e({title:"é¯èª¤",description:t,variant:"destructive"})}finally{o(!1)}}},en=async(e,t)=>{let s=a.banks[e];if(!s)return;let r=s.entryUrls.filter((e,s)=>s!==t),i=a.banks.map((t,s)=>s===e?{...t,entryUrls:r}:t);l(e=>({...e,banks:i})),await el(i,a.limits)},ed=async e=>{let t=x.trim(),s=a.banks[e];if(!t||!s){h(null),p("");return}let r=a.banks.map((s,a)=>a===e?{...s,entryUrls:[...s.entryUrls,t]}:s);l(e=>({...e,banks:r})),h(null),p(""),await el(r,a.limits,"å·²å å
¥ä¸¦å²å")},ec=()=>{h(null),p("")},eo=async t=>{let r=a.banks[t];if(!r)return;let i=r.entryUrls.filter(e=>e.trim().startsWith("http"));if(0===i.length)return void e({title:"è«å
æ°å¢è©²éè¡çå
¥å£ç¶²å",variant:"destructive"});v(t),U(null);try{let t=(await (0,tH.callFn)("enqueueCreditCardBenefitsCrawl",{seedUrls:i,bankName:r.bankName})).data;e({title:"å·²æå
¥ä½å",description:t?.jobId?"ä»»å已建ç«ï¼è«è³ã檢è¦ãé æ¥çé²åº¦èçµæã":"è«ç¨å¾æ¼æª¢è¦é æ¥çã"}),s("review")}catch(e){em(e)}finally{v(null)}},eu=async()=>{A(!0),U(null);try{let t=(await (0,tH.callFn)("enqueueCreditCardBenefitsCrawl",{})).data;e({title:"å·²æå
¥ä½å",description:`å·²çº ${t?.jobIds?.length??0} å®¶éè¡å»ºç«ä»»åï¼è«è³ã檢è¦ãé æ¥çé²åº¦èçµæã`}),s("review")}catch(e){em(e)}finally{A(!1)}},em=t=>{let s=t?.code??"",a=t?.message??"æå
¥ä½å失æ";"permission-denied"===s&&(a="å
é管çå¡ä½¿ç¨"),"unauthenticated"===s&&(a="è«éæ°ç»å
¥"),U(a),(0,O.vV)("æå
¥ä¿¡ç¨å¡åªæ ç¬åä½å失æ:",t),e({title:"é¯èª¤",description:a,variant:"destructive"})},eh=()=>{ee(null),es(se)},ex=(e,t,s)=>!D.has(`${e.id}:${t}:${s}`),ep=async t=>{let s=ea(t).filter((e,s)=>ex(t,"update",s)).map(e=>({templateId:e.templateId,templateName:e.templateName,bank:e.bank,benefits:e.benefits??[]})),a=er(t).filter((e,s)=>ex(t,"unmatched",s)).map(e=>({bank:e.bank,cardName:e.cardName,benefits:e.benefits??[]}));if(s.length+a.length===0)return void e({title:"è«è³å°å¾é¸ä¸å¼µå¡ç",variant:"destructive"});E(t.id),U(null);try{let r=(await (0,tH.callFn)("aiUpdateCreditCardBenefits",{proposedUpdates:s,newCards:a,jobId:t.id})).data;e({title:"宿",description:r.message??`å·²æ´æ° ${r.updated??0} å¼µå¡ç`});let i=e=>{let s={...e};return delete s[t.id],s};L(i),J(i)}catch(s){let t=s?.message??"確èªå¯«å
¥å¤±æ";
5U(t),(0,O.vV)("ä¿¡ç¨å¡åªæ 寫å
¥å¤±æ:",s),e({title:"é¯èª¤",description:t,variant:"destructive"})}finally{E(null)}},ej=async t=>{if(("completed"===t.status||"failed"===t.status)&&confirm("確å®è¦åªé¤æ¤ä»»åï¼åªé¤å¾ç¡æ³å¾©åã")){R(t.id),U(null);try{await (0,tH.callFn)("deleteCreditCardBenefitJob",{jobId:t.id}),e({title:"å·²åªé¤ä»»å"})}catch(s){let t=s?.message??"åªé¤å¤±æ";U(t),(0,O.vV)("åªé¤ç¬åä»»å失æ:",s),e({title:"é¯èª¤",description:t,variant:"destructive"})}finally{R(null)}}},eg=S[0],ef=eg?t7(eg):null,ev=ef?S.filter(e=>t7(e)===ef):[],ey=ev.filter(e=>"completed"===e.status),eb=ey.filter(e=>!t6(e)&&!t8(e)),ew=e=>ev.filter(t=>t.status===e).length,eN=ew("queued")+ew("running"),eC=(e,t)=>e.reduce((e,s)=>e+t(s),0),eS=[{label:"æåé æ¸",value:eC(ey,e=>e.summary?.totalFetched??0)},{label:"è§£æå¡ç",value:eC(ey,e=>e.summary?.cardsFromLayer1??0)},{label:"å¾
ç¢ºèªæ´æ°",value:eC(eb,e=>ea(e).length),accent:!0},{label:"å¾
æ°å¢å¡ç",value:eC(eb,e=>er(e).length)},{label:"失æé ",value:eC(ey,e=>e.summary?.failedUrls?.length??0),danger:!0}];if(n)return(0,r.jsx)("div",{className:"flex items-center justify-center p-8",children:(0,r.jsx)(eA.A,{className:"h-8 w-8 animate-spin text-muted-foreground"})});let eT=(t,s,a,i,l,n)=>{let d=`${t.id}:${s}:${a}`,c=H.has(d),o=!D.has(d),u=i.accent&&o;return(0,r.jsxs)("div",{className:`rounded-md border overflow-hidden ${u?"border-primary/40":""} ${n&&!o?"opacity-60":""}`,children:[(0,r.jsxs)("div",{className:`flex items-center justify-between gap-2 px-3 py-2 ${u?"bg-primary/5":""}`,children:[n&&(0,r.jsx)(tX.S,{checked:o,onCheckedChange:()=>ei(P,d),"aria-label":`寫å
¥ã${i.name}ã`}),(0,r.jsxs)("button",{type:"button",className:"flex items-center gap-2 min-w-0 flex-1 text-left",onClick:()=>ei(q,d),"aria-expanded":c,children:[c?(0,r.jsx)(tK.A,{className:"h-4 w-4 shrink-0 text-muted-foreground"}):(0,r.jsx)(td.A,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),(0,r.jsx)("span",{className:"font-medium truncate",children:i.name}),i.bank&&(0,r.jsx)("span",{className:"text-xs text-muted-foreground shrink-0",children:i.bank})]}),(0,r.jsxs)("span",{className:"text-xs text-muted-foreground shrink-0",children:[i.count," çåªæ "]})]}),c&&(0,r.jsxs)("div",{className:"px-3 pb-3 pt-1 space-y-2",children:[(i.sourceUrls?.length??0)>0&&(0,r.jsx)("div",{className:"flex flex-wrap gap-x-3 gap-y-1 text-xs",children:i.sourceUrls.map((e,t)=>(0,r.jsxs)("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-0.5 text-primary hover:underline",children:["便ºé ",i.sourceUrls.length>1?` ${t+1}`:"",(0,r.jsx)(tZ.A,{className:"h-3 w-3"})]},e))}),0===l.length?(0,r.jsx)("p",{className:"text-sm text-muted-foreground",children:"å°ç¡åªæ å
§å®¹"}):l.map((i,l)=>((t,s,a,i,l)=>{if(Q?.jobId===t.id&&Q.source===s&&Q.cardIdx===a&&Q.benefitIdx===l)return(0,r.jsxs)("div",{className:"rounded-md border p-3 space-y-3 bg-muted/30",children:[(0,r.jsxs)("div",{className:"grid gap-2",children:[(0,r.jsx)(w.J,{className:"text-xs",children:"æ¨é¡"}),(0,r.jsx)(W.p,{value:et.title,onChange:e=>es(t=>({...t,title:e.target.value})),placeholder:"åªæ æ¨é¡"})]}),(0,r.jsxs)("div",{className:"grid gap-2",children:[(0,r.jsx)(w.J,{className:"text-xs",children:"說æ"}),(0,r.jsx)(V.T,{value:et.description,onChange:e=>es(t=>({...t,description:e.target.value})),rows:2,placeholder:"åªæ 說æ"})]}),(0,r.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,r.jsxs)("div",{className:"grid gap-2",children:[(0,r.jsx)(w.J,{className:"text-xs",children:"åé¡"}),(0,r.jsx)(W.p,{value:et.category,onChange:e=>es(t=>({...t,category:e.target.value})),placeholder:"åé¡"})]}),(0,r.jsxs)("div",{className:"grid gap-2",children:[(0,r.jsx)(w.J,{className:"text-xs",children:"åé¥çï¼%ï¼"}),(0,r.jsx)(W.p,{type:"number",value:et.rate,onChange:e=>es(t=>({...t,rate:e.target.value})),placeholder:"æ¸å"})]})]}),(0,r.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,r.jsxs)("div",{className:"grid gap-2",children:[(0,r.jsx)(w.J,{className:"text-xs",children:"æ¢ä»¶"}),(0,r.jsx)(W.p,{value:et.conditions,onChange:e=>es(t=>({...t,conditions:e.target.value})),placeholder:"ä½¿ç¨æ¢ä»¶"})]}),(0,r.jsxs)("div",{className:"grid gap-2",children:[(0,r.jsx)(w.J,{className:"text-xs",children:"ææè³"}
5),(0,r.jsx)(W.p,{value:et.validUntil,onChange:e=>es(t=>({...t,validUntil:e.target.value})),placeholder:"ä¾ï¼2025-12-31"})]})]}),(0,r.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,r.jsx)(b.$,{type:"button",variant:"outline",size:"sm",onClick:eh,children:"åæ¶"}),(0,r.jsx)(b.$,{type:"button",size:"sm",onClick:()=>(t=>{if(!Q)return;let s=e=>({...e,title:et.title.trim()||e.title,description:et.description.trim()||void 0,conditions:et.conditions.trim()||void 0,category:et.category.trim()||e.category,rate:et.rate.trim()?Number(et.rate):void 0,validUntil:et.validUntil.trim()||void 0});if("update"===Q.source){let e=ea(t).map((e,t)=>{if(t!==Q.cardIdx)return e;let a=(e.benefits??[]).map((e,t)=>t===Q.benefitIdx?s(e):e);return{...e,benefits:a}});L(s=>({...s,[t.id]:e}))}else{let e=er(t).map((e,t)=>{if(t!==Q.cardIdx)return e;let a=(e.benefits??[]).map((e,t)=>t===Q.benefitIdx?s(e):e);return{...e,benefits:a}});J(s=>({...s,[t.id]:e}))}eh(),e({title:"å·²æ´æ°æ¤çåªæ ï¼å°æªå¯«å
¥ï¼æã確èªå¯«å
¥ãå¾çæï¼"})})(t),children:"å²å"})]})]},i.id);let n=t5(i.title),d=t5(i.description),c=t5(i.conditions),o=t5(i.category),u="completed"===t.status&&!t6(t)&&!t8(t);return(0,r.jsxs)("div",{className:"rounded-md border p-3 text-sm flex justify-between items-start gap-2",children:[(0,r.jsxs)("div",{className:"min-w-0 flex-1 space-y-1",children:[n&&(0,r.jsx)("div",{className:"font-medium",children:n}),o&&(0,r.jsxs)("div",{className:"text-muted-foreground",children:["åé¡ï¼",o]}),d&&(0,r.jsx)("div",{className:"text-muted-foreground",children:d}),null!=i.rate&&(0,r.jsxs)("div",{className:"text-muted-foreground",children:["åé¥çï¼",i.rate,"%"]}),c&&(0,r.jsxs)("div",{className:"text-muted-foreground",children:["æ¢ä»¶ï¼",c]}),i.validUntil&&(0,r.jsxs)("div",{className:"text-muted-foreground",children:["ææè³ï¼",i.validUntil]})]}),u&&(0,r.jsx)(b.$,{type:"button",variant:"ghost",size:"sm",className:"h-7 shrink-0 px-2",onClick:()=>{ee({jobId:t.id,source:s,cardIdx:a,benefitIdx:l}),es({title:i.title??"",description:i.description??"",conditions:i.conditions??"",category:i.category??"",rate:null!=i.rate?String(i.rate):"",validUntil:i.validUntil??""})},"aria-label":"編輯æ¤çåªæ ",children:(0,r.jsx)(tw.A,{className:"h-3.5 w-3.5"})})]},i.id)})(t,s,a,i,l))]})]},d)};return(0,r.jsxs)(f.tU,{value:t,onValueChange:e=>s(e),children:[(0,r.jsxs)(f.j7,{className:"mb-4",children:[(0,r.jsx)(f.Xi,{value:"review",children:"檢è¦"}),(0,r.jsx)(f.Xi,{value:"operate",children:"æä½"})]}),F&&(0,r.jsx)(k.Fc,{variant:"destructive",className:"mb-4",children:(0,r.jsx)(k.TN,{children:F})}),(0,r.jsxs)(f.av,{value:"review",className:"space-y-5",children:[eg?(0,r.jsxs)("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2.5 flex-wrap",children:[(0,r.jsx)("span",{className:`inline-block h-2.5 w-2.5 rounded-full ${eN>0?"bg-muted-foreground":ew("failed")>0?"bg-amber-500":"bg-green-500"}`}),(0,r.jsxs)("span",{className:"font-medium",children:["ææ°ä¸æ¹ \xb7 ",t9(eg.createdAt)]}),(0,r.jsxs)("span",{className:"text-sm text-muted-foreground",children:[ev.length," å®¶éè¡ï¼å®æ ",ew("completed"),eN>0&&`ãé²è¡ä¸ ${eN}`,ew("failed")>0&&`ã失æ ${ew("failed")}`,eb.length>0&&` \xb7 å¾
å¯©æ ¸ ${eb.length} å®¶`]})]}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:"䏿¬¡èªåæ´æ° \xb7 æ¯é±ä¸ 03:00"})]}):(0,r.jsx)("p",{className:"text-sm text-muted-foreground",children:"å°ç¡ä»»åã坿¼ãæä½ãé å·è¡ï¼æçå¾
æ¯é±ä¸ 03:00 èªåæ´æ°ã"}),ey.length>0&&(0,r.jsx)("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-5 gap-3",children:eS.map(e=>(0,r.jsxs)("div",{className:`rounded-md p-3 ${e.accent?"bg-primary/10":"bg-muted/50"}`,children:[(0,r.jsx)("div",{className:`text-xs ${e.accent?"text-primary":"text-muted-foreground"}`,children:e.label}),(0,r.jsx)("div",{className:`text-2xl font-medium ${e.accent?"text-primary":e.danger&&e.value>0?"text-destructive":""}`,children:e.value})]},e.label))}),(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsx)(w.J,{children:"æ´æ°ç´é"}),0===S.length?(0,r.jsx)("p",{className:"text-sm text-muted-foreground",children:"å°ç¡ä»»å"}):(0,r.jsx)("div",{className:"space-y-3",children:S.map(e=>{let t,s=M.has(e.id),a=ea(e),i=er(e),l=t6(e),n=t8(e),d="completed"===e.status&&!l&&!n,c=a.filter((t,s)=>ex(e,"update",s)).length,o=i.filter((t,s)=>ex(e,"unmatched",s)).length,u=G.has(e.id),m=e.preview?.sourceUrls??[],h=e.preview?.detailPageResults??[],x=e.summary?.failedUrls?.length??0,p=e.summary?.skippedUrls?.length??0;return(0,r.jsxs)("div",{className:"rounded-lg border bg-card",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 px-4 py-3 flex-wrap",children:[(0,r.jsxs)("button",{type:"button",className:"flex items-center gap-2 min-w-0",onClick:()=>ei(Z,e.id),"aria-expanded":s,children:[s?(0,r.jsx)(tK.A,{className:"h-4 w-4 text-muted-foreground"}):(0,r.jsx)(td.A,{className:"h-4 w-4 text-muted-foreground"}),"running"===e.status&&(0,r.jsx)(eA.A,{className:"h-4 w-4 animate-spin text-muted-foreground"}),(0,r.jsx)("span",{className:"font-medium",children:(t="system-scheduler"===e.createdBy?"èªå":"æå",`${e.bankName??"å
¨é¨éè¡"} \xb7 ${t}`)}),e.createdAt&&(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:t9(e.createdAt)})]}),(0,r.jsxs)("div",{className:"ml-auto flex items-center gap-2",children:[l?(0,r.jsxs)(N.E,{variant:"secondary",className:"gap-1",children:[(0,r.jsx)(tc.A,{className:"h-3 w-3"}),"已寫å
¥"]}):(0,r.jsxs)(N.E,{variant:"completed"===e.status?"default":"failed"===e.status?"destructive":"running"===e.status?"secondary":"outline",children:["queued"===e.status&&"ä½åä¸","running"===e.status&&"å·è¡ä¸","completed"===e.status&&"已宿","failed"===e.status&&"失æ"]}),("completed"===e.status||"failed"===e.status)&&(0,r.jsx)(ek.j,{ariaLabel:"ä»»åæä½",triggerClassName:"h-8 w-8",items:[{id:"delete-job",label:"åªé¤",icon:B.A,destructive:!0,loading:$===e.id,onSelect:()=>ej(e)}]})]})]}),s&&(0,r.jsxs)("div",{className:"px-4 pb-4 space-y-4",children:["failed"===e.status&&e.errorMessage&&(0,r.jsxs)(k.Fc,{variant:"destructive",children:[(0,r.jsx)(tQ.A,{className:"h-4 w-4"}),(0,r.jsx)(k.TN,{children:e.errorMessage})]}),("running"===e.status||"queued"===e.status)&&(0,r.jsx)("p",{className:"text-sm text-muted-foreground",children:"queued"===e.status?"å·²æå
¥ä½åï¼çå¾
éå§â¦":"ç¬åèè§£æé²è¡ä¸ï¼é常 3â9 åé宿ï¼å®æå¾çµææèªååºç¾ã"}),"completed"===e.status&&(0,r.jsxs)(r.Fragment,{children:[e.summary&&(0,r.jsxs)("div",{className:"text-sm text-muted-foreground",children:["è§£æ ",e.summary.cardsFromLayer1??0," å¼µ \xb7 æ´æ° ",a.length," \xb7 æ°å¢ ",i.length,x>0&&` \xb7 失æ ${x} é `,p>0&&` \xb7 龿ç¥é ${p} é `]}),n&&!l&&(0,r.jsxs)(k.Fc,{variant:"destructive",children:[(0,r.jsx)(tQ.A,{className:"h-4 w-4"}),(0,r.jsx)(k.TN,{children:"æ¤çºèçè§£ææµç¨ççµæï¼å¡çå°æå¯è½é¯ç½®ï¼å·²åç¨å¯«å
¥ãè«éæ°å·è¡ç¬åã"})]}),l&&(0,r.jsxs)(k.Fc,{children:[(0,r.jsx)(tc.A,{className:"h-4 w-4"}),(0,r.jsxs)(k.TN,{children:["å·²æ¼ ",t9(e.appliedAt)," 確èªå¯«å
¥ï¼æ´æ° ",e.appliedCount??0," å¼µãæ°å¢ ",e.appliedCreatedCount??0," å¼µã"]}
5)]}),a.length>0&&(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)(w.J,{className:"text-xs",children:["æ´æ°æ¢æå¡çï¼",a.length,"ï¼"]}),a.map((t,s)=>eT(e,"update",s,{name:t.templateName??t.templateId,bank:t.bank,count:t.benefits?.length??0,accent:d,sourceUrls:t.sourceUrls},t.benefits??[],d))]}),i.length>0&&(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)(w.J,{className:"text-xs",children:["æ°å¢å¡çï¼",i.length,"ï¼\xb7 確èªå¾å»ºç«æ°æ¨¡æ¿"]}),i.map((t,s)=>eT(e,"unmatched",s,{name:t.cardName,bank:t.bank,count:t.benefits?.length??0,accent:d,sourceUrls:t.sourceUrls},t.benefits??[],d))]}),0===a.length&&0===i.length&&(0,r.jsx)("p",{className:"text-sm text-muted-foreground",children:"æ¬æ¬¡æªè§£æå°ä»»ä½å¡çåªæ ãè«ç¢ºèªå
¥å£ç¶²åçºä¿¡ç¨å¡å表é ï¼ä¸è©³æ
é å
å«åªæ å
§æã"}),d&&a.length+i.length>0&&(0,r.jsxs)(b.$,{size:"sm",onClick:()=>ep(e),disabled:I===e.id||c+o===0,children:[I===e.id?(0,r.jsx)(eA.A,{className:"h-4 w-4 animate-spin mr-2"}):(0,r.jsx)(tc.A,{className:"h-4 w-4 mr-2"}),"確èªå¯«å
¥ï¼æ´æ° ",c," å¼µãæ°å¢ ",o," å¼µ"]}),(m.length>0||h.length>0)&&(0,r.jsxs)("div",{className:"rounded-md border",children:[(0,r.jsxs)("button",{type:"button",className:"flex items-center gap-2 w-full px-3 py-2 text-left",onClick:()=>ei(X,e.id),"aria-expanded":u,children:[u?(0,r.jsx)(tK.A,{className:"h-4 w-4 text-muted-foreground"}):(0,r.jsx)(td.A,{className:"h-4 w-4 text-muted-foreground"}),(0,r.jsxs)("span",{className:"text-xs text-muted-foreground",children:["便ºæç´°ï¼é¤é¯ç¨ï¼\xb7 ",m.length," 便º \xb7 ",h.length," 詳æ
é "]})]}),u&&(0,r.jsxs)("div",{className:"px-3 pb-3 space-y-3",children:[m.length>0&&(0,r.jsxs)("div",{className:"space-y-1",children:[(0,r.jsx)(w.J,{className:"text-xs",children:"è³æä¾æºç¶²å"}),(0,r.jsxs)("ul",{className:"list-disc list-inside text-xs text-muted-foreground max-h-40 overflow-y-auto",children:[m.slice(0,30).map((e,t)=>(0,r.jsx)("li",{children:(0,r.jsxs)("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-0.5 text-primary hover:underline",children:[e,(0,r.jsx)(tZ.A,{className:"h-3 w-3"})]})},t)),m.length>30&&(0,r.jsxs)("li",{children:["⦠å
± ",m.length," ç"]})]})]}),h.length>0&&(0,r.jsxs)("div",{className:"space-y-1",children:[(0,r.jsx)(w.J,{className:"text-xs",children:"詳æ
é èåªæ "}),(0,r.jsx)("ul",{className:"text-xs text-muted-foreground space-y-1 max-h-48 overflow-y-auto",children:h.map((e,t)=>{let s=e.benefitCount??(e.updates?.flatMap(e=>e.benefits??[]).length??0)+(e.unmatchedBenefits?.flatMap(e=>e.benefits??[]).length??0);return(0,r.jsxs)("li",{className:"flex items-center gap-2",children:[(0,r.jsxs)("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-0.5 text-primary hover:underline truncate",children:[e.url.length>48?`${e.url.slice(0,48)}â¦`:e.url,(0,r.jsx)(tZ.A,{className:"h-3 w-3 shrink-0"})]}),(0,r.jsxs)("span",{className:"shrink-0",children:[e.bank??"â","ï¼",e.cardName??"â"," \xb7 ",s," ç"]})]},`${e.url}-${t}`)})})]})]})]})]})]})]},e.id)})})]})]}),(0,r.jsx)(f.av,{value:"operate",children:(0,r.jsxs)(y.Zp,{children:[(0,r.jsxs)(y.aR,{className:"flex flex-row items-start justify-between gap-4 space-y-0",children:[(0,r.jsxs)("div",{className:"space-y-1.5",children:[(0,r.jsx)(y.ZB,{children:"ä¿¡ç¨å¡åªæ ç¬åè¨å®"}),(0,r.jsx)(y.BT,{children:"ä¾éè¡åçµè¨å®å
¥å£ç¶²åï¼æ¯å®¶éè¡åèªä¸çä»»åï¼å
å¾å
¥å£é ååºå¡çï¼åé塿å詳æ
é 並以 AI è§£æåªæ ï¼çµæè«è³ã檢è¦ãé å¯©æ ¸ä¸¦ç¢ºèªå¯«å
¥ãæ¯å®¶éè¡æå¤å±é 20 åé£çµã"})]}),(0,r.jsxs)(b.$,{type:"button",size:"sm",className:"shrink-0",onClick:eu,disabled:C,children:[C?(0,r.jsx)(eA.A,{className:"h-4 w-4 animate-spin mr-2"}):(0,r.jsx)(tF.A,{className:"h-4 w-4 mr-2"}),"å
¨é¨éè¡ç«å³å·è¡"]})]}),(0,r.jsx)(y.Wu,{className:"space-y-4",children:(0,r.jsx)("div",{className:"max-h-[520px] overflow-y-auto space-y-3 [scrollbar-width:none] [-ms-overflow-style:none] [&::-webkit-scrollbar]:hidden",children:a.banks.map((e,t)=>(0,r.jsxs)("div",{className:"rounded-md border p-3 space-y-3",children:[(0,r.jsx)("h3",{className:"font-medium",children:e.bankName}),(0,r.jsxs)("div",{className:"space-y-2",children:[0===e.entryUrls.length&&m!==t&&(0,r.jsx)("p",{className:"text-sm text-muted-foreground",children:"å°ç¡ç¶²åï¼è«é»ãæ°å¢ç¶²åã"}),e.entryUrls.map((e,s)=>(0,r.jsxs)("div",{className:"flex items-center gap-2 rounded border bg-muted/40 px-2 py-1.5 text-sm",children:[(0,r.jsx)("span",{className:"min-w-0 flex-1 truncate font-mono",title:e,children:e.length>60?`${e.slice(0,60)}...`:e}),(0,r.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:"shrink-0 text-primary hover:underline","aria-label":"卿°åé éå",children:(0,r.jsx)(tZ.A,{className:"h-3.5 w-3.5"})}),(0,r.jsx)(b.$,{type:"button",variant:"ghost",size:"sm",className:"h-7 shrink-0 px-2 text-destructive hover:text-destructive",onClick:()=>
5en(t,s),disabled:c,children:(0,r.jsx)(B.A,{className:"h-3.5 w-3.5"})})]},s)),m===t&&(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(W.p,{placeholder:"https://example.com/card-benefits",value:x,onChange:e=>p(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),ed(t)),"Escape"===e.key&&ec()},className:"font-mono text-sm",autoFocus:!0}),(0,r.jsxs)(b.$,{type:"button",size:"sm",onClick:()=>ed(t),disabled:c,children:[c?(0,r.jsx)(eA.A,{className:"h-4 w-4 animate-spin"}):null,"å å
¥"]}),(0,r.jsx)(b.$,{type:"button",variant:"outline",size:"sm",onClick:ec,children:"åæ¶"})]}),(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsxs)(b.$,{type:"button",variant:"outline",size:"sm",onClick:()=>{h(t),p("")},disabled:m===t,children:[(0,r.jsx)(eI.A,{className:"h-4 w-4 mr-1"}),"æ°å¢ç¶²å"]}),(0,r.jsxs)(b.$,{type:"button",size:"sm",onClick:()=>eo(t),disabled:0===e.entryUrls.filter(e=>e.trim().startsWith("http")).length||g===t,children:[g===t?(0,r.jsx)(eA.A,{className:"h-4 w-4 animate-spin mr-2"}):(0,r.jsx)(tF.A,{className:"h-4 w-4 mr-2"}),"å·è¡"]})]})]})]},e.bankName))})})]})})]})}var ss=s(18710),sa=s(46048),sr=s(65952);function si(e){let t=e?.error;if("string"==typeof t)return t;if(t&&"object"==typeof t&&"message"in t&&"string"==typeof t.message)return t.message;if(t&&"object"==typeof t&&"formErrors"in t){let e=[...t.formErrors??[],...Object.values(t.fieldErrors??{}).flat().filter(Boolean)];if(e.length)return e.join("ï¼")}return"è«ç¨å¾å試"}function sl(e){let t=String(e??"").trim().toLowerCase();if(t){if(/(twd|ntd|å°å¹£|æ°å°å¹£|nt\$)/.test(t))return"twd";if(/(usd|ç¾é|ç¾å
|us\$)/.test(t))return"usd";if(/(jpy|æ¥å|æ¥å
|jpÂ¥|Â¥)/.test(t))return"jpy";if(/(eur|æå
|â¬)/.test(t))return"eur"}}function sn(e,t){let s=[];if(e?.length)for(let t of e)t.plan&&s.push(t.plan),t.term&&s.push(t.term);if(t?.length)for(let e of t)e.occupationClass&&s.push(e.occupationClass);for(let e of s){if(null==e)continue;let t=String(e).trim();if(!t)continue;let s=sl(t);if(s)return s}}var sd=s(97769),sc=s(28022),so=s(20232),su=s(29343),sm=s(41746);function sh({selectedCount:e,batchIngesting:t,batchDeleteDeleting:s,batchSetListing:a,selectAllOnPage:i,clearSelection:l,onBatchIngest:n,onOpenBatchDelete:d,onOpenBatchSetListed:c}){return(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-2 rounded-md border bg-background px-3 py-2 shadow-sm",children:[(0,r.jsxs)("span",{className:"text-sm font-medium",children:["å·²é¸ ",e," ç"]}),(0,r.jsx)(b.$,{variant:"outline",size:"icon",onClick:i,title:"å
¨é¸ï¼æ¬é ï¼","aria-label":"å
¨é¸ï¼æ¬é ï¼",children:(0,r.jsx)(so.A,{className:"h-4 w-4"})}),(0,r.jsx)(b.$,{variant:"outline",size:"icon",onClick:l,title:"åæ¶å
¨é¸","aria-label":"åæ¶å
¨é¸",children:(0,r.jsx)(X.A,{className:"h-4 w-4"})}),(0,r.jsx)("div",{className:"mx-1 h-5 w-px bg-border","aria-hidden":!0}),(0,r.jsxs)(b.$,{variant:"secondary",size:"sm",onClick:n,disabled:t,title:"æ¹æ¬¡æ·åï¼å®ç模å¼ï¼æ¹æ¬¡å·¥ä½æ¨¡å¼è«ä½¿ç¨ä¸æ¹æ¹æ¬¡ ingest é²åº¦å¡ï¼",children:[t?(0,r.jsx)(eA.A,{className:"mr-1 h-3.5 w-3.5 animate-spin"}):(0,r.jsx)(ef.A,{className:"mr-1 h-3.5 w-3.5"}),"æ·å"]}),(0,r.jsxs)(b.$,{variant:"default",size:"sm",onClick:()=>c(!0),disabled:a,title:"æ¹æ¬¡ä¸æ¶",children:[a?(0,r.jsx)(eA.A,{className:"mr-1 h-3.5 w-3.5 animate-spin"}):(0,r.jsx)(su.A,{className:"mr-1 h-3.5 w-3.5"}),"䏿¶"]}),(0,r.jsxs)(b.$,{variant:"secondary",size:"sm",onClick:()=>c(!1),disabled:a,title:"æ¹æ¬¡ä¸æ¶",children:[(0,r.jsx)(sm.A,{className:"mr-1 h-3.5 w-3.5"}),"䏿¶"]}),(0,r.jsxs)(b.$,{variant:"destructive",size:"sm",onClick:d,disabled:s,title:"æ¹æ¬¡åªé¤",children:[s?(0,r.jsx)(eA.A,{className:"mr-1 h-3.5 w-3.5 animate-spin"}):(0,r.jsx)(B.A,{className:"mr-1 h-3.5 w-3.5"}),"åªé¤"]})]})}var sx=s(29778),sp=s(17770);function sj({job:e,jobId:t,running:s,pct:a,onCancel:i,onResume:l,onOpenDetail:n,onDismiss:d}){if(!t)return null;let c=e?.progress,o=e?.status??"queued",u="done"===o||"cancelled"===o||"error"===o;return(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-2 rounded-md border bg-muted/30 px-3 py-2",children:[(0,r.jsx)(sx.A,{className:"h-4 w-4 text-muted-foreground"}),(0,r.jsx)("span",{className:"text-sm font-medium",children:"æ¹æ¬¡ ingest"}),(0,r.jsx)(N.E,{variant:"done"===o?"default":"outline",children:o}),c&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("span",{className:"text-sm text-muted-foreground",children:[c.processed,"/",c.total,"ï¼",a,"%ï¼"]}),(0,r.jsxs)("span",{className:"text-xs text-emerald-600",children:["æå ",c.succeeded]}),c.failed>0&&(0,r.jsxs)("span",{className:"text-xs text-rose-600",children:["失æ ",c.failed]}),c.needsReview>0&&(0,r.jsxs)("span",{className:"text-xs text-amber-600",children:["éå¯©æ ¸ ",c.needsReview]})]}),(0,r.jsx)("div",{className:"h-1.5 min-w-[120px] flex-1 overflow-hidden rounded bg-muted",children:(0,r.jsx)("div",{className:"h-full bg-emerald-500 transition-all",style:{width:`${a}%`}})}),s&&(0,r.jsxs)(b.$,{variant:"outline",size:"sm",onClick:()=>void i(),children:[(0,r.jsx)(sp.A,{className:"mr-1 h-3.5 w-3.5"}),"åæ¶"]}),!s&&!u&&t&&(0,r.jsxs)(b.$,{variant:"outline",size:"sm",onClick:l,children:[(0,r.jsx)(ef.A,{className:"mr-1 h-3.5 w-3.5"}),"çºè·"]}),s&&!u&&(0,r.jsx)(eA.A,{className:"h-4 w-4 animate-spin text-muted-foreground"}),(0,r.jsx)(b.$,{variant:"ghost",size:"sm",onClick:n,children:"å±éæç´°"}),u&&d&&(0,r.jsx)(b.$,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:d,title:"éé","aria-label":"éé",children:(0,r.jsx)(X.A,{className:"h-3.5 w-3.5"})})]})}var sg=s(13139);function sf({open:e,onOpenChange:t,job:s,jobId:a,pct:i}){let l=s?.progress;return(0,r.jsx)(sg.cj,{open:e,onOpenChange:t,children:(0,r.jsxs)(sg.h,{side:"right",className:"w-full overflow-y-auto sm:max-w-2xl",children:[(0,r.jsxs)(sg.Fm,{children:[(0,r.jsx)(sg.qp,{children:"æ¹æ¬¡ ingest å·¥ä½æç´°"}),(0,r.jsxs)(sg.Qs,{children:["jobIdï¼",(0,r.jsx)("span",{className:"font-mono text-xs",children:a??"â"})]})]}),(0,r.jsxs)("div",{className:"mt-4 space-y-4",children:[l&&(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-2 text-sm",children:[(0,r.jsx)(N.E,{variant:s?.status==="done"?"default":"outline",children:s?.status??"queued"}),(0,r.jsxs)("span",{children:["é²åº¦ ",l.processed,"/",l.total,"ï¼",i,"%ï¼"]}),(0,r.jsxs)("span",{className:"text-emerald-600",children:["æå ",l.succeeded]}),(0,r.jsxs)("span",{className:"text-rose-600",children:["失æ ",l.failed]}),l.needsReview>0&&(0,r.jsxs)("span",{className:"text-amber-600",children:["éå¯©æ ¸ ",l.needsReview]})]}),(0,r.jsx)("div",{className:"h-2 w-full overflow-hidden rounded bg-muted",children:(0,r.jsx)("div",{className:"h-full bg-emerald-500 transition-all",style:{width:`${i}%`}})})]}),s?.items&&s.items.length>0&&(0,r.jsx)("div",{className:"overflow-auto rounded border text-xs",children:(0,r.jsxs)("table",{className:"w-full",children:[(0,r.jsx)("thead",{className:"sticky top-0 bg-muted/60",children:(0,r.jsxs)("tr",{children:[(0,r.jsx)("th",{className:"px-2 py-1 text-left",children:"#"}),(0,r.jsx)("th",{className:"px-2 py-1 text-left",children:"productId"}),(0,r.jsx)("th",{className:"px-2 py-1 text-left",children:"çæ
"}),(0,r.jsx)("th",{className:"px-2 py-1 text-left",children:"說æ"})]})}),(0,r.jsx)("tbody",{children:s.items.map((e,t)=>(0,r.jsxs)("tr",{className:"border-t",children:[(0,r.jsx)("td",{className:"px-2 py-1 text-muted-foreground",children:t+1}),(0,r.jsx)("td",{className:"px-2 py-1 font-mono",children:e.productId}),(0,r.jsxs)("td",{className:"px-2 py-1",children:["done"===e.status&&(0,r.jsxs)("span",{className:"inline-flex items-center gap-1 text-emerald-600",children:[(0,r.jsx)(tc.A,{className:"h-3.5 w-3.5"}),"done",e.needsReview?"ï¼éå¯©æ ¸ï¼":""]}),"error"===e.status&&(0,r.jsxs)("span",{className:"inline-flex items-center gap-1 text-rose-600",children:[(0,r.jsx)(es.A,{className:"h-3.5 w-3.5"}),"error"]}),"running"===e.status&&(0,r.jsxs)("span",{className:"inline-flex items-center gap-1 text-blue-600",children:[(0,r.jsx)(eA.A,{className:"h-3.5 w-3.5 animate-spin"}),"running"]}),"pending"===e.status&&(0,r.jsx)("span",{className:"text-muted-foreground",children:"pending"}),"skipped"===e.status&&(0,r.jsxs)("span",{className:"inline-flex items-center gap-1 text-amber-600",children:[(0,r.jsx)(tQ.A,{className:"h-3.5 w-3.5"}),"skipped"]})]}),(0,r.jsx)("td",{className:"px-2 py-1 text-muted-foreground",children:e.error??(e.notes&&e.notes.slice(0,2).join("ï¼"))??""})]},e.productId))})]})})]})]})})}var sv=s(88660);let sy="admin:tiiCrawlJobId";
5async function sb(){try{let{auth:e}=await Promise.resolve().then(s.bind(s,76458)),t=e?.currentUser;if(!t)return null;let a=await t.getIdToken(!0);return{Authorization:`Bearer ${a}`}}catch{return null}}function sw({onJump:e}){let[t,s]=(0,i.useState)(null),[a,l]=(0,i.useState)(null);if((0,i.useEffect)(()=>{let e=()=>s(localStorage.getItem(sy));e();let t=t=>{t.key===sy&&e()};window.addEventListener("storage",t);let a=setInterval(e,2e3);return()=>{window.removeEventListener("storage",t),clearInterval(a)}},[]),(0,i.useEffect)(()=>{if(!t)return void l(null);let e=!1,s=async()=>{try{let s=await sb();if(!s)return;let a=await fetch(`/api/admin/tii-crawl/jobs/${t}`,{headers:s});if(!a.ok)return;let r=await a.json();e||l(r)}catch{}};s();let a=setInterval(s,4e3);return()=>{e=!0,clearInterval(a)}},[t]),!t||!a||"pending"!==a.status&&"running"!==a.status)return null;let n=a.summary?.total??0,d=a.summary?.currentIndex??0;return(0,r.jsxs)(b.$,{variant:"outline",size:"sm",onClick:e,className:"h-7 gap-1.5 border-amber-500/50 bg-amber-500/10 text-amber-700 hover:bg-amber-500/20 dark:text-amber-300",children:[(0,r.jsx)(sv.A,{className:"h-3.5 w-3.5"}),(0,r.jsx)("span",{className:"text-xs",children:"ä¿ç¼ä¸å¿ç¬åä¸"}),n>0&&(0,r.jsxs)(N.E,{variant:"outline",className:"h-5 px-1.5 text-[10px]",children:[d,"/",n]}),(0,r.jsx)(tZ.A,{className:"h-3 w-3"})]})}function sN({selectedCount:e,batchIngesting:t,batchDeleteDeleting:s,batchSetListing:a,selectAllOnPage:l,clearSelection:n,onBatchIngest:d,onOpenBatchDelete:c,onOpenBatchSetListed:o,ingestJob:u,ingestJobId:m,ingestRunning:h,ingestPct:x,onCancelIngest:p,onResumeIngest:j,onJumpToSources:g}){let[f,v]=(0,i.useState)(!1),[y,b]=(0,i.useState)(!1),w=!!m&&!y,N=e>0;return N||w?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"sticky top-0 z-10 -mt-2 mb-2 space-y-2 bg-background/95 py-2 backdrop-blur supports-[backdrop-filter]:bg-background/60",children:[N&&(0,r.jsx)(sh,{selectedCount:e,batchIngesting:t,batchDeleteDeleting:s,batchSetListing:a,selectAllOnPage:l,clearSelection:n,onBatchIngest:d,onOpenBatchDelete:c,onOpenBatchSetListed:o}),(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[w&&(0,r.jsx)("div",{className:"min-w-0 flex-1",children:(0,r.jsx)(sj,{job:u,jobId:m,running:h,pct:x,onCancel:p,onResume:j,onOpenDetail:()=>v(!0),onDismiss:()=>b(!0)})}),(0,r.jsx)(sw,{onJump:g})]})]}),(0,r.jsx)(sf,{open:f,onOpenChange:v,job:u,jobId:m,pct:x})]}):(0,r.jsx)("div",{className:"sticky top-0 z-10 -mt-2 mb-2 flex justify-end bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60",children:(0,r.jsx)(sw,{onJump:g})})}var sk=s(3198);function sC({docs:e,listPage:t,totalPages:s,totalCount:a,pageSize:i,onPageChange:l,isLoading:n,error:d,filterReview:c,setFilterReview:o,filterInsurer:u,setFilterInsurer:m,filterCategory:h,setFilterCategory:x,loadList:p,selectedIds:j,ingestProduct:g,setListed:f,deleteOne:v,toggleSelectAll:w,toggleSelect:N,ingestingId:k,openEdit:C}){return(0,r.jsxs)(y.Zp,{children:[(0,r.jsxs)(y.aR,{children:[(0,r.jsx)(y.ZB,{children:"ä¿éªåå管ç"}),(0,r.jsx)(y.BT,{children:"管çä¿éªååç®éï¼å¯æ°å¢ã編輯ãç¼å¸ææçµã"})]}),(0,r.jsxs)(y.Wu,{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-4",children:[(0,r.jsxs)(Z.l6,{value:c,onValueChange:o,children:[(0,r.jsx)(Z.bq,{className:"w-[120px]",children:(0,r.jsx)(Z.yv,{placeholder:"䏿¶çæ
"})}),(0,r.jsx)(Z.gC,{children:sr.JS.map(e=>(0,r.jsx)(Z.eb,{value:e.value,children:e.label},e.value))})]}),(0,r.jsxs)(Z.l6,{value:h,onValueChange:x,children:[(0,r.jsx)(Z.bq,{className:"w-[100px]",children:(0,r.jsx)(Z.yv,{placeholder:"大é¡"})}),(0,r.jsx)(Z.gC,{children:sr.ch.map(e=>(0,r.jsx)(Z.eb,{value:e.value,children:e.label},e.value))})]}),(0,r.jsxs)(Z.l6,{value:u,onValueChange:m,children:[(0,r.jsx)(Z.bq,{className:"w-[140px]",children:(0,r.jsx)(Z.yv,{placeholder:"ä¿éªå
¬å¸"})}),(0,r.jsxs)(Z.gC,{children:[(0,r.jsx)(Z.eb,{value:"__all__",children:"å
¨é¨"}),sr._4.map(e=>(0,r.jsx)(Z.eb,{value:e.value,children:e.label},e.value))]})]}),(0,r.jsx)(b.$,{variant:"outline",size:"icon",onClick:()=>p(),disabled:n,children:(0,r.jsx)(ef.A,{className:n?"animate-spin":""})})]}),d&&(0,r.jsx)("p",{className:"text-sm text-destructive",children:d}),(0,r.jsx)("div",{className:"rounded-md border",children:n&&0===a?(0,r.jsx)("div",{className:"flex items-center justify-center py-12",children:(0,r.jsx)(eA.A,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):(0,r.jsxs)(eg.XI,{children:[(0,r.jsx)(eg.A0,{children:(0,r.jsxs)(eg.Hj,{children:[(0,r.jsx)(eg.nd,{className:"w-10",children:(0,r.jsx)(tX.S,{checked:e.length>0&&e.every(e=>j.has(e.id)),onCheckedChange:w,"aria-label":"å
¨é¸æ¬é "})}),(0,r.jsx)(eg.nd,{children:"ååå稱"}),(0,r.jsx)(eg.nd,{children:"ä¿éªå
¬å¸"}),(0,r.jsx)(eg.nd,{children:"大é¡"}),(0,r.jsx)(eg.nd,{children:"éªç¨®"}),(0,r.jsx)(eg.nd,{className:"text-right",children:"æä½"})]})}),(0,r.jsx)(eg.BF,{children:e.map(e=>{let t=(0,sa.Eo)(e),s=t.ok?"":"bg-amber-500/10",a=t.ok?void 0:`ç¡æ³ä¸æ¶ï¼${t.reason}`;return(0,r.jsxs)(eg.Hj,{className:s,children:[(0,r.jsx)(eg.nA,{className:"w-10",children:(0,r.jsx)(tX.S,{checked:j.has(e.id),onCheckedChange:()=>N(e.id),"aria-label":`é¸å ${e.productName}`})}),(0,r.jsx)(eg.nA,{className:"font-medium",children:(0,r.jsx)("span",{className:"block max-w-[360px] truncate whitespace-nowrap",title:a??(0,sa.Jt)(e.productName,e.productC
5ode),children:(0,sa.Jt)(e.productName,e.productCode)})}),(0,r.jsx)(eg.nA,{children:e.insurerCode?(0,sk.Zg)(e.insurerCode):"-"}),(0,r.jsx)(eg.nA,{children:e.category??"-"}),(0,r.jsx)(eg.nA,{children:e.productType??"-"}),(0,r.jsx)(eg.nA,{className:"text-right",children:(0,r.jsx)("div",{className:"flex justify-end",children:(0,r.jsx)(ek.j,{ariaLabel:`æä½ï¼${(0,sa.Jt)(e.productName,e.productCode)}`,items:[{id:"edit",label:"編輯",icon:tw.A,onSelect:()=>C(e)},{id:"ingest",label:"æ·å",icon:ef.A,loading:k===e.id,onSelect:()=>g(e.id)},..."listed"===e.reviewStatus||"approved"===e.reviewStatus?[{id:"unlist",label:"䏿¶",icon:sm.A,onSelect:()=>f(e.id,!1)}]:[{id:"list",label:"䏿¶",icon:su.A,onSelect:()=>f(e.id,!0)}],{id:"delete",label:"åªé¤",icon:B.A,destructive:!0,onSelect:()=>v(e.id)}]})})})]},e.id)})})]})}),a>0?(0,r.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3 text-sm",children:[(0,r.jsxs)("span",{className:"text-muted-foreground",children:["å
± ",a," çï¼æ¯é ",i," ç"]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)(b.$,{type:"button",variant:"outline",size:"sm",disabled:n||t<=1,onClick:()=>l(t-1),children:"ä¸ä¸é "}),(0,r.jsxs)("span",{className:"tabular-nums text-muted-foreground",children:["第 ",t," / ",s," é "]}),(0,r.jsx)(b.$,{type:"button",variant:"outline",size:"sm",disabled:n||t>=s,onClick:()=>l(t+1),children:"ä¸ä¸é "})]})]}):null]})]})}var sA=s(6524),sS=s(46964);function sT({uploadFiles:e,setUploadFiles:t,r2Files:s,selectedR2Paths:a,isLoadingR2Files:i,uploadResult:l,isUploading:n,onBatchUpload:d,onLoadR2Files:c,onToggleR2Path:o,onClearR2Selection:u,onBatchUploadFromR2:m}){return(0,r.jsxs)(y.Zp,{children:[(0,r.jsxs)(y.aR,{children:[(0,r.jsx)(y.ZB,{children:"æ¹æ¬¡ä¸å³æªæ¡"}),(0,r.jsx)(y.BT,{children:"æ¯æ´æ¢æ¬¾ï¼è²»ç PDFï¼ä»¥åæä¿è¦ååçï¼PNG/JPG/JPEGï¼ã系統æä¾æªåèå
§å®¹æ·åè³è¨ä¸¦å»ºç«çºå¾
審ååï¼ä¿éªå
¬å¸ç±æªå辨èï¼å¤§é¡ä¾ååå稱ééµåï¼å¦é«çãå¥åº·ã失è½ï¼èªå辨èãåçè¥ç¡æ³æ·åæä¿è¦åæè¦çºå¤±æä¸ä¸ä¿çæªæ¡ã"})]}),(0,r.jsxs)(y.Wu,{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-end gap-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(w.J,{children:"é¸ææªæ¡ï¼PDF/åçï¼å¯å¤æªï¼"}),(0,r.jsx)(W.p,{type:"file",accept:".pdf,application/pdf,.png,image/png,.jpg,.jpeg,image/jpeg",multiple:!0,className:"mt-1",onChange:e=>t(Array.from(e.target.files||[]))})]}),(0,r.jsxs)(b.$,{onClick:d,disabled:n||0===e.length,children:[n?(0,r.jsx)(eA.A,{className:"mr-2 h-4 w-4 animate-spin"}):(0,r.jsx)(e3.A,{className:"mr-2 h-4 w-4"}),"ä¸å³ä¸¦æ·å"]})]}),(0,r.jsxs)("div",{className:"space-y-2 rounded-md border p-3",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,r.jsx)("p",{className:"text-sm font-medium",children:"å¾ Cloudflareï¼tii-product-documentsï¼é¸åæªæ¡"}),(0,r.jsxs)(b.$,{type:"button",variant:"outline",size:"sm",onClick:c,disabled:i||n,children:[i?(0,r.jsx)(eA.A,{className:"mr-2 h-4 w-4 animate-spin"}):(0,r.jsx)(ef.A,{className:"mr-2 h-4 w-4"}),"è®åæ¸
å®"]}),(0,r.jsx)(b.$,{type:"button",variant:"outline",size:"sm",onClick:u,disabled:0===a.length||n,children:"æ¸
é¤é¸å"}),(0,r.jsxs)(b.$,{type:"button",size:"sm",onClick:m,disabled:n||0===a.length,children:[n?(0,r.jsx)(eA.A,{className:"mr-2 h-4 w-4 animate-spin"}):(0,r.jsx)(e3.A,{className:"mr-2 h-4 w-4"}),"å¯å
¥ä¸¦æ·å"]})]}),(0,r.jsx)("div",{className:"max-h-56 overflow-auto rounded border",children:0===s.length?(0,r.jsx)("p",{className:"p-3 text-sm text-muted-foreground",children:"å°æªè®åææ²æå¯ç¨æªæ¡ã"}):(0,r.jsx)("div",{className:"space-y-1 p-2",children:s.map(e=>(0,r.jsxs)("label",{className:"flex cursor-pointer items-center gap-2 rounded px-2 py-1 hover:bg-muted/60",children:[(0,r.jsx)(tX.S,{checked:a.includes(e),onCheckedChange:()=>o(e)}),(0,r.jsx)("span",{className:"truncate text-xs",children:e})]},e))})}),(0,r.jsxs)("p",{className:"text-xs text-muted-foreground",children:["å·²é¸å ",a.length," å Cloudflare æªæ¡ã"]})]}),l&&(0,r.jsxs)("div",{className:"rounded-md border p-3 text-sm",children:[(0,r.jsxs)("p",{className:"font-medium",children:["çµæï¼æå ",l.summary.succeeded," / 失æ ",l.summary.failed]}),(0,r.jsx)("ul",{className:"mt-2 list-inside list-disc space-y-1",children:l.results.map((e,t)=>
5(0,r.jsxs)("li",{children:[e.fileName,": ",e.success?`å·²å»ºç« ${e.productIds?.length??0} ç`:e.error]},t))})]})]})]})}let sI=(0,ss.default)(()=>s.e(1688).then(s.bind(s,1688)),{loadableGenerated:{webpack:()=>[1688]},ssr:!1});function sE(e){return(0,r.jsxs)(sA.nD,{type:"single",collapsible:!0,defaultValue:"tii",className:"space-y-2",children:[(0,r.jsxs)(sA.As,{value:"tii",className:"rounded-lg border bg-card",children:[(0,r.jsx)(sA.$m,{className:"px-4 py-3 hover:no-underline",children:(0,r.jsx)("span",{className:"font-medium",children:"ä¿ç¼ä¸å¿ç¬å"})}),(0,r.jsx)(sA.ub,{className:"px-4 pb-4",children:(0,r.jsx)(sI,{pendingAppendKeyword:e.pendingTiiKeyword})})]}),(0,r.jsxs)(sA.As,{value:"upload",className:"rounded-lg border bg-card",children:[(0,r.jsx)(sA.$m,{className:"px-4 py-3 hover:no-underline",children:(0,r.jsx)("span",{className:"font-medium",children:"æ¹æ¬¡ä¸å³æªæ¡"})}),(0,r.jsx)(sA.ub,{className:"px-4 pb-4",children:(0,r.jsx)(sT,{uploadFiles:e.uploadFiles,setUploadFiles:e.setUploadFiles,r2Files:e.r2Files,selectedR2Paths:e.selectedR2Paths,isLoadingR2Files:e.isLoadingR2Files,uploadResult:e.uploadResult,isUploading:e.isUploading,onBatchUpload:e.onBatchUpload,onLoadR2Files:e.onLoadR2Files,onToggleR2Path:e.onToggleR2Path,onClearR2Selection:e.onClearR2Selection,onBatchUploadFromR2:e.onBatchUploadFromR2})})]}),(0,r.jsxs)(sA.As,{value:"import",className:"rounded-lg border bg-card",children:[(0,r.jsx)(sA.$m,{className:"px-4 py-3 hover:no-underline",children:(0,r.jsx)("span",{className:"font-medium",children:"å¯å
¥ CSV / JSON"})}),(0,r.jsx)(sA.ub,{className:"px-4 pb-4",children:(0,r.jsxs)(y.Zp,{className:"border-0 shadow-none",children:[(0,r.jsx)(y.aR,{className:"px-0 pt-0",children:(0,r.jsx)(y.BT,{children:"å¯å
¥ CSV/JSON å¾å°ä»¥ãå¾
審ã建ç«ååãéè¤ççæ¬éµï¼å
¬å¸ï¼åååï¼çææ¥ï¼æè¢«ç¥éã"})}),(0,r.jsxs)(y.Wu,{className:"space-y-4 px-0 pb-0",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-end gap-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(w.J,{children:"鏿 CSV æ JSON"}),(0,r.jsx)(W.p,{type:"file",accept:".csv,.json,text/csv,application/json",className:"mt-1",onChange:t=>e.setImportFile(t.target.files?.[0]??null)})]}),(0,r.jsxs)(b.$,{variant:"outline",onClick:e.onImport,disabled:e.isImporting||!e.importFile,children:[e.isImporting?(0,r.jsx)(eA.A,{className:"mr-2 h-4 w-4 animate-spin"}):(0,r.jsx)(sS.A,{className:"mr-2 h-4 w-4"}),"å¯å
¥"]})]}),e.importResult&&(0,r.jsxs)("div",{className:"rounded-md border p-3 text-sm",children:[(0,r.jsxs)("p",{className:"font-medium",children:["å¯å
¥çµæï¼æå ",e.importResult.imported," çï¼å¤±æ ",e.importResult.failed," ç"]}),e.importResult.errors.length>0&&(0,r.jsxs)("ul",{className:"mt-2 list-inside list-disc space-y-1 text-destructive",children:[e.importResult.errors.slice(0,10).map((e,t)=>(0,r.jsxs)("li",{children:["第 ",e.index+1," ç: ",e.message]},t)),e.importResult.errors.length>10&&(0,r.jsxs)("li",{children:["â¦å
¶é¤ ",e.importResult.errors.length-10," çé¯èª¤"]})]})]})]})]})})]})]})}function s$({exportFormat:e,setExportFormat:t,onExport:s}){return(0,r.jsxs)(y.Zp,{children:[(0,r.jsxs)(y.aR,{children:[(0,r.jsx)(y.ZB,{children:"å¯åºååç®é"}),(0,r.jsx)(y.BT,{children:"ä¾ç®åãååå表ãåé ç篩é¸çµæå¯åºçº CSV æ JSONãå¯ä½çºå份æäº¤çµ¦å
¶ä»ç³»çµ±ä½¿ç¨ã"})]}),(0,r.jsx)(y.Wu,{children:(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-4",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)(w.J,{children:"å¯åºæ ¼å¼"}),(0,r.jsxs)(Z.l6,{value:e,onValueChange:e=>t(e),children:[(0,r.jsx)(Z.bq,{className:"w-[100px]",children:(0,r.jsx)(Z.yv,{})}),(0,r.jsxs)(Z.gC,{children:[(0,r.jsx)(Z.eb,{value:"json",children:"JSON"}),(0,r.jsx)(Z.eb,{value:"csv",children:"CSV"})]})]})]}),(0,r.jsxs)(b.$,{variant:"outline",onClick:s,children:[(0,r.jsx)(eS.A,{className:"mr-2 h-4 w-4"})," å¯åº"]})]})})]})}function sR({suggestions:e,suggestionsLoading:t,suggestionMarkingId:s,loadSuggestions:a,markSuggestionProcessed:i,onSendToTiiCrawl:l}){return(0,r.jsxs)(y.Zp,{children:[(0,r.jsxs)(y.aR,{children:[(0,r.jsx)(y.ZB,{children:"å»ºè°æ°å¢ååï¼Legacyï¼"}),(0,r.jsxs)(y.BT,{children:["æ°æäº¤å·²æ¹èµ° TOID å¯©æ ¸ä½åï¼Admin â TOID åé ï¼ãæ¤èå
顯示æ·å² ",(0,r.jsx)("code",{children:"insuranceProductSuggestions"})," ç´éï¼è«è³ TOID èçæ°ä½åã"]})]}),(0,r.jsxs)(y.Wu,{children:[(0,r.jsx)("div",{className:"flex items-center gap-2 mb-4",children:(0,r.jsxs)(b.$,{variant:"outline",size:"sm",onClick:()=>a(),disabled:t,children:[(0,r.jsx)(ef.A,{className:t?"animate-spin h-4 w-4":"h-4 w-4"}),"éæ°æ´ç"]})}),t&&0===e.length?(0,r.jsx)("div",{className:"flex justify-center py-8",children:(0,r.jsx)(eA.A,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):(0,r.jsx)("div",{className:"rounded-md border",children:(0,r.jsxs)(eg.XI,{children:[(0,r.jsx)(eg.A0,{children:(0,r.jsxs)(eg.Hj,{children:[(0,r.jsx)(eg.nd,{children:"ååå稱"}),(0,r.jsx)(eg.nd,{children:"ä¿éªå
¬å¸"}),(0,r.jsx)(eg.nd,{children:"大é¡"}),(0,r.jsx)(eg.nd,{children:"éªç¨®"}),(0,r.jsx)(eg.nd,{children:"çæ
"}),(0,r.jsx)(eg.nd,{className:"text-right",children:"æä½"})]})}),(0,r.jsx)(eg.BF,{children:0===e.length?(0,r.jsx)(eg.Hj,{children:(0,r.jsx)(eg.nA,{colSpan:6,className:"text-center text-muted-foreground",children:"å°ç¡å»ºè°"})}):e.map(e=>(0,r.jsxs)(eg.Hj,{children:[(0,r.jsx)(eg.nA,{className:"font-medium",children:(0,r.jsx)("span",{className:"block max-w-[360px] truncate whitespace-nowrap",title:e.productName??"-",children:e.productName??"-"})}),(0,r.jsx)(eg.nA,{children:e.insurerCode?(0,sk.Zg)(e.insurerCode):"-"}),(0,r.jsx)(eg.nA,{children:e.category??"-"}),(0,r.jsx)(eg.nA,{children:e.productType??"-"}),(0,r.jsx)(eg.nA,{children:(0,r.jsx)(N.E,{variant:"processed"===e.status?"default":"secondary",children:"processed"===e.status?"å·²èç":"å¾
èç"})}),(0,r.jsx)(eg.nA,{className:"text-right",children:(0,r.jsxs)("div",{className:"flex justify-end gap-1",children:["processed"!==e.status&&l&&e.productName&&(0,r.jsxs)(b.$,{variant:"ghost",size:"sm",onClick:()=>l(e.productName),title:"æååå稱éé²ä¿ç¼ä¸å¿ç¬åçééµåæ¬",children:[(0,r.jsx)(sv.A,{className:"h-4 w-4"}),"éè³ç¬å"]}),"processed"!==e.status&&(0,r.jsxs)(b.$,{variant:"ghost",size:"sm",onClick:()=>i(e.id),disabled:s===e.id,children:[s===e.id?(0,r.jsx)(eA.A,{className:"h-4 w-4 animate-spin"}):(0,r.jsx)(tP.A,{className:"h-4 w-4"}),"æ¨è¨å·²èç"]})]})})]},e.id))})]})})]})]})}var sD=s(48113);function sP({open:e,onOpenChange:t,selectedCount:s,onConfirm:a,isDeleting:i}){return(0,r.jsx)(sD.Lt,{open:e,onOpenChange:t,children:(0,r.jsxs)(sD.EO,{children:[(0,r.jsxs)(sD.wd,{
5children:[(0,r.jsx)(sD.r7,{children:"ç¢ºèªæ¹æ¬¡åªé¤"}),(0,r.jsxs)(sD.$v,{children:["確å®è¦åªé¤æé¸ç ",s," çä¿éªåååï¼æ¤æä½ç¡æ³å¾©åï¼ç¸éç便ºæªæ¡ä¹æä¸ä½µåªé¤ã"]})]}),(0,r.jsxs)(sD.ck,{children:[(0,r.jsx)(sD.Zr,{children:"åæ¶"}),(0,r.jsxs)(sD.Rx,{onClick:a,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",disabled:i,children:[i?(0,r.jsx)(eA.A,{className:"h-4 w-4 animate-spin mr-2"}):null,"åªé¤"]})]})]})})}function sF({open:e,onOpenChange:t,listed:s,count:a,sample:i,invalid:l,onConfirm:n,isSubmitting:d}){let c=l.length>0;return(0,r.jsx)(sD.Lt,{open:e,onOpenChange:t,children:(0,r.jsxs)(sD.EO,{children:[(0,r.jsxs)(sD.wd,{children:[(0,r.jsx)(sD.r7,{children:s?"ç¢ºèªæ¹æ¬¡ä¸æ¶":"ç¢ºèªæ¹æ¬¡ä¸æ¶"}),(0,r.jsx)(sD.$v,{children:s?(0,r.jsxs)(r.Fragment,{children:["å³å°ä¸æ¶ ",a," çååã䏿¶å¾åå°æè®çºå¯è¦ã"]}):(0,r.jsxs)(r.Fragment,{children:["å³å°ä¸æ¶ ",a," çååã䏿¶å¾åå°å°ä¸å¯è¦ã"]})})]}),i.length>0?(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("div",{className:"text-sm font-medium text-muted-foreground",children:["æè¦ï¼å ",i.length," çï¼"]}),(0,r.jsx)("div",{className:"max-h-60 overflow-y-auto rounded-md border",children:(0,r.jsx)("ul",{className:"divide-y",children:i.map(e=>{var t;let s="listed"===(t=e.reviewStatus)?{label:"䏿¶",variant:"default"}:"unlisted"===t?{label:"䏿¶",variant:"secondary"}:{label:t||"â",variant:"outline"};return(0,r.jsxs)("li",{className:"p-3 space-y-1",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,r.jsx)("span",{className:"font-medium truncate",children:e.productName??"â"}),(0,r.jsx)(N.E,{variant:s.variant,children:s.label})]}),(0,r.jsx)("div",{className:"text-xs text-muted-foreground",children:e.insurerCode?(0,sk.Zg)(e.insurerCode):"â"})]},e.id)})})})]}):null,c?(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)("div",{className:"text-sm font-medium text-destructive",children:"ç¡æ³å·è¡ï¼è«å
ä¿®æ£ä»¥ä¸ååï¼"}),(0,r.jsx)("div",{className:"max-h-48 overflow-y-auto rounded-md border border-destructive/30 bg-destructive/5",children:(0,r.jsx)("ul",{className:"divide-y divide-destructive/20",children:l.map(e=>(0,r.jsxs)("li",{className:"p-3 text-sm",children:[(0,r.jsx)("div",{className:"font-medium truncate",children:e.productName??"æªç¥åå"}),(0,r.jsx)("div",{className:"text-xs text-muted-foreground mb-1",children:e.insurerCode?(0,sk.Zg)(e.insurerCode):"â"}),(0,r.jsx)("div",{className:"text-muted-foreground",children:e.reason})]},e.id))})})]}):null,(0,r.jsxs)(sD.ck,{children:[(0,r.jsx)(sD.Zr,{children:"åæ¶"}),(0,r.jsxs)(sD.Rx,{onClick:n,disabled:d||c,children:[d?(0,r.jsx)(eA.A,{className:"h-4 w-4 animate-spin mr-2"}):null,s?"䏿¶":"䏿¶"]})]})]})})}async function sO(e,t={}){let s=j.auth.currentUser;if(!s)throw Error("è«å
ç»å
¥");let a=await s.getIdToken(),r=new Headers(t.headers);return r.set("Authorization",`Bearer ${a}`),fetch(e,{...t,headers:r})}function s_(){let[e,t]=(0,i.useState)("pending_review"),[s,a]=(0,i.useState)(50),[l,d]=(0,i.useState)([]),[c,o]=(0,i.useState)(!1),[u,m]=(0,i.useState)(null),[h,x]=(0,i.useState)(null),p=(0,i.useMemo)(()=>`status=${encodeURIComponent(e)}&limit=${s}`,[e,s]);async function j(){o(!0),x(null);try{let e=await sO(`/api/v1/toid/admin/submissions?${p}`);if(!e.ok)throw Error(`è®å失æï¼${e.status}`);let t=await e.json();d(Array.isArray(t.items)?t.items:[])}catch(e){x(e instanceof Error?e.message:String(e))}finally{o(!1)}}async function g(e,t){o(!0),x(null);try{let s;if("needs_changes"===t){let e=window.prompt("è«å¡«å¯«éè¦è£å
ç說æï¼æé¡¯ç¤ºçµ¦æäº¤è
ï¼ï¼","");if(null===e)return void o(!1);if(!(s=e.trim()||void 0)){x("æ¨çºãéè£å
ãæè«å¡«å¯«èªªæï¼æäº¤è
æç¥éè¦æ¹ä»éº¼"),o(!1);return}}let a=await sO(`/api/v1/toid/admin/submissions/${e}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({status:t,...s?{note:s}:{}})});if(!a.ok)throw Error(`æ´æ°å¤±æï¼${a.status}`);await j()}catch(e){x(e instanceof Error?e.message:String(e))}finally{o(!1)}}async function f(e){m(e),x(null);try{let t=await sO(`/api/v1/toid/admin/submissions/${e}/extract`,{method:"POST"});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error||`AI æ·å失æï¼${t.status}`)}await j()}catch(e){x(e instanceof Error?e.message:String(e))}finally{m(null)}}return(0,i.useEffect)(()=>{j()},[p]),(0,r.jsxs)(y.Zp,{children:[(0,r.jsxs)(y.aR,{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[(0,r.jsx)(y.ZB,{children:"TOID å¯©æ ¸ä½å"}),(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,r.jsxs)(Z.l6,{value:e,onValueChange:t,children:[(0,r.jsx)(Z.bq,{className:"w-[180px]",children:(0,r.jsx)(Z.yv,{})}),(0,r.jsxs)(Z.gC,{children:[(0,r.jsx)(Z.eb,{value:"pending_review",children:"å¯©æ ¸ä¸"}),(0,r.jsx)(Z.eb,{value:"community_review",children:"è¨è«ä¸"}),(0,r.jsx)(Z.eb,{value:"needs_changes",children:"éè£å
"}),(0,r.jsx)(Z.eb,{value:"approved",children:"å·²æ¶é"}),(0,r.jsx)(Z.eb,{value:"rejected",children:"æªéé"})]})]}),(0,r.jsx)(W.p,{className:"w-[120px]",type:"number",value:s,min:1,max:100,onChange:e=>a(Math.max(1,Math.min(100,Number(e.target.value)||50)))}
5),(0,r.jsx)(b.$,{variant:"outline",onClick:j,disabled:c,children:"éæ°æ´ç"})]})]}),(0,r.jsxs)(y.Wu,{className:"space-y-3",children:[h?(0,r.jsx)("div",{className:"text-sm text-destructive",children:h}):null,(0,r.jsxs)(eg.XI,{children:[(0,r.jsx)(eg.A0,{children:(0,r.jsxs)(eg.Hj,{children:[(0,r.jsx)(eg.nd,{children:"ID"}),(0,r.jsx)(eg.nd,{children:"åå"}),(0,r.jsx)(eg.nd,{children:"çæ
"}),(0,r.jsx)(eg.nd,{children:"æ·å"}),(0,r.jsx)(eg.nd,{children:"éä»¶"}),(0,r.jsx)(eg.nd,{children:"æä½"})]})}),(0,r.jsxs)(eg.BF,{children:[l.map(e=>(0,r.jsxs)(eg.Hj,{children:[(0,r.jsx)(eg.nA,{className:"font-mono text-xs",children:e.id}),(0,r.jsxs)(eg.nA,{children:[(0,r.jsx)("div",{className:"text-sm font-medium",children:e.productName??e.normalizedProductName??"-"}),(0,r.jsx)("div",{className:"text-xs text-muted-foreground",children:e.insurerCode??"-"})]}),(0,r.jsx)(eg.nA,{className:"text-sm",children:e.status}),(0,r.jsx)(eg.nA,{children:(0,r.jsx)(N.E,{variant:"outline",children:e.extractionStatus??"idle"})}),(0,r.jsxs)(eg.nA,{className:"space-y-1 text-sm",children:[(0,r.jsx)("div",{children:e.attachmentCount}),(e.attachments??[]).slice(0,3).map((e,t)=>{let s=e.path?`/api/storage/file?path=${encodeURIComponent(e.path)}`:e.url?(0,e2.pG)(e.url)??e.url:null;return s?(0,r.jsx)("a",{href:s,target:"_blank",rel:"noreferrer",className:"block truncate text-xs text-primary hover:underline",children:e.fileName||"éä»¶"},`${e.path??e.url??t}`):null})]}),(0,r.jsxs)(eg.nA,{className:"flex flex-wrap gap-2",children:[(0,r.jsx)(b.$,{asChild:!0,size:"sm",variant:"ghost",children:(0,r.jsx)(n(),{href:`/toid/submissions/${e.id}`,children:"檢è¦"})}),(0,r.jsx)(b.$,{size:"sm",variant:"secondary",disabled:c||u===e.id||e.attachmentCount<1,onClick:()=>f(e.id),children:u===e.id?"æ·åä¸â¦":"AI æ·å"}),(0,r.jsx)(b.$,{size:"sm",variant:"outline",disabled:c,onClick:()=>g(e.id,"needs_changes"),children:"éè£å
"}),(0,r.jsx)(b.$,{size:"sm",variant:"outline",disabled:c,onClick:()=>g(e.id,"rejected"),children:"éå"}),(0,r.jsx)(b.$,{size:"sm",disabled:c,onClick:()=>g(e.id,"approved"),children:"æ ¸å"})]})]},e.id)),l.length?null:(0,r.jsx)(eg.Hj,{children:(0,r.jsx)(eg.nA,{colSpan:6,className:"text-sm text-muted-foreground",children:c?"è¼å
¥ä¸â¦":"æ²æè³æ"})})]})]})]})]})}let sU=(0,ss.default)(()=>s.e(6163).then(s.bind(s,16163)),{loadableGenerated:{webpack:()=>[16163]},ssr:!1});function sz(){let{user:e}=(0,m.A)(),{toast:t}=(0,u.dj)(),s=(0,i.useCallback)(async()=>{if(!e)throw Error("è«å
ç»å
¥");return await e.getIdToken(!0)},[e]),[a,l]=(0,i.useState)("list"),[n,d]=(0,i.useState)(null),{pagedDocs:c,listPage:o,setListPage:h,totalPages:x,totalCount:p,pageSize:g,isLoading:v,error:y,filterReview:b,setFilterReview:w,filterInsurer:k,setFilterInsurer:C,filterCategory:A,setFilterCategory:S,loadList:T,selectedIds:I,batchIngesting:E,batchDeleteDeleting:$,batchDeleteDialogOpen:R,setBatchDeleteDialogOpen:D,ingestProduct:P,setListed:F,deleteOne:O,handleBatchIngest:U,handleBatchDelete:z,batchSetListedDialogOpen:B,setBatchSetListedDialogOpen:L,batchSetListedTarget:Y,batchSetListedDryRun:J,setBatchSetListedDryRun:M,batchSetListing:W,openBatchSetListed:V,confirmBatchSetListed:Z,toggleSelectAll:H,selectAllOnPage:q,clearSelection:G,toggleSelect:X,ingestingId:K}=function(e,t){let[s,a]=(0,i.useState)([]),[r,l]=(0,i.useState)(1),[n,d]=(0,i.useState)(!1),[c,o]=(0,i.useState)(null),[u,m]=(0,i.useState)("__all__"),[h,x]=(0,i.useState)("__all__"),[p,j]=(0,i.useState)("__all__"),[g,f]=(0,i.useState)(new Set),[v,y]=(0,i.useState)(!1),[b,w]=(0,i.useState)(!1),[N,k]=(0,i.useState)(!1),[C,A]=(0,i.useState)(!1),[S,T]=(0,i.useState)(!0),[I,E]=(0,i.useState)(null),[$,R]=(0,i.useState)(!1),[D,P]=(0,i.useState)(null),[F,O]=(0,i.useState)(null),_=(0,i.useCallback)(async()=>{d(!0),o(null);try{let t,s=await e(),r=[],i=0;for(;;){if((i+=1)>sr.hn)throw Error(`å表è¼å
¥ä¸æ·ï¼å·²è¶
é ${sr.hn} 次åé ï¼è«æª¢æ¥ API æ¸¸æ¨æ¯å¦ç°å¸¸ï¼`);let e=new URLSearchParams;e.set("limit",String(sr.ps)),t&&e.set("cursor",t),u&&"__all__"!==u&&e.set("reviewStatus",u),h&&"__all__"!==h&&e.set("insurerCode",h),p&&"__all__"!==p&&e.set("category",p);let a=await fetch(`/api/admin/insurance-products?${e.toString()}`,{headers:(0,sa.Pw)(s)});if(!a.ok){let e=await a.json().catch(()=>({}));throw Error(e?.error?.message||e?.error||`HTTP ${a.status}`)}let l=(await a.json()).docs||[];if(r.push(...l),l.length<sr.ps)break;let n=l[l.length-1]?.id;if(!n)break;t=n}a(r),l(1)}catch(e){o(e instanceof Error?e.message:"è¼å
¥å¤±æ"),a([]),l(1)}finally{d(!1)}}
5,[e,u,h,p]);(0,i.useEffect)(()=>{_()},[_]);let U=Math.max(1,Math.ceil(s.length/sr.$1)),z=(0,i.useMemo)(()=>{let e=(r-1)*sr.$1;return s.slice(e,e+sr.$1)},[s,r]);(0,i.useEffect)(()=>{l(e=>Math.min(e,U))},[U]);let B=(0,i.useCallback)(async s=>{P(s);try{let t=await e(),a=await fetch(`/api/admin/insurance-products/${s}/ingest`,{method:"POST",headers:(0,sa.Pw)(t)}),r=await a.json().catch(()=>({}));if(!a.ok)throw Error(r?.error||`HTTP ${a.status}`);await _()}catch(e){t({title:"æ·å失æ",description:e instanceof Error?e.message:"è«ç¨å¾å試",variant:"destructive"})}finally{P(null)}},[e,_,t]),L=(0,i.useCallback)(async s=>{O(s);try{let a=await e(),r=await fetch(`/api/admin/insurance-products/${s}`,{method:"PATCH",headers:{...(0,sa.Pw)(a),"Content-Type":"application/json"},body:JSON.stringify({needsReview:!1,ingestError:""})}),i=await r.json().catch(()=>({}));if(!r.ok)throw Error(i?.error?.message||i?.error||`HTTP ${r.status}`);t({title:"å·²æ¨è¨çºå·²æª¢æ¥"}),await _()}catch(e){t({title:"æ´æ°å¤±æ",description:e instanceof Error?e.message:"è«ç¨å¾å試",variant:"destructive"})}finally{O(null)}},[e,_,t]),Y=(0,i.useCallback)(async(s,a)=>{try{let r=await e(),i=await fetch(`/api/admin/insurance-products/${s}`,{method:"PATCH",headers:{"Content-Type":"application/json",...(0,sa.Pw)(r)},body:JSON.stringify({reviewStatus:a?"listed":"unlisted",updatedAt:new Date().toISOString()})}),l=await i.json().catch(()=>({}));if(!i.ok)throw Error(si(l)||`HTTP ${i.status}`);t({title:a?"已䏿¶":"已䏿¶"}),await _()}catch(e){t({title:"æä½å¤±æ",description:e instanceof Error?e.message:"è«ç¨å¾å試",variant:"destructive"})}},[e,_,t]),J=(0,i.useCallback)(async s=>{if(confirm("確å®è¦åªé¤æ¤ä¿éªååï¼"))try{let a=await e(),r=await fetch(`/api/admin/insurance-products/${s}`,{method:"DELETE",headers:(0,sa.Pw)(a)}),i=await r.json().catch(()=>({}));if(!r.ok)throw Error(si(i)||"åªé¤å¤±æ");t({title:"å·²åªé¤"}),await _()}catch(e){t({title:"åªé¤å¤±æ",description:e instanceof Error?e.message:"è«ç¨å¾å試",variant:"destructive"})}},[e,_,t]),M=(0,i.useCallback)(async()=>{let s=Array.from(g);if(0===s.length)return;y(!0);let a=await e().catch(()=>null);if(!a){t({title:"è«å
ç»å
¥",variant:"destructive"}),y(!1);return}let r=0,i=0;for(let e of s)try{(await fetch(`/api/admin/insurance-products/${e}/ingest`,{method:"POST",headers:(0,sa.Pw)(a)})).ok?r++:i++}catch{i++}y(!1),f(new Set),await _(),t({title:"æ¹æ¬¡æ·å宿",description:`æå ${r} ç${i>0?`ï¼å¤±æ ${i} ç`:""}`})},[e,_,t,g]),W=(0,i.useCallback)(()=>{f(e=>{let t=z.map(e=>e.id);if(0===t.length)return e;let s=t.every(t=>e.has(t)),a=new Set(e);if(s)for(let e of t)a.delete(e);else for(let e of t)a.add(e);return a})},[z]),V=(0,i.useCallback)(()=>{f(e=>{let t=z.map(e=>e.id);if(0===t.length)return e;let s=new Set(e);for(let e of t)s.add(e);return s})},[z]),Z=(0,i.useCallback)(()=>{f(new Set)},[]),H=(0,i.useCallback)(e=>{f(t=>{let s=new Set(t);return s.has(e)?s.delete(e):s.add(e),s})},[]),q=(0,i.useCallback)(async()=>{if(0!==g.size){k(!1),w(!0);try{let s=await e(),a=await fetch("/api/admin/insurance-products/batch-delete",{method:"POST",headers:{...(0,sa.Pw)(s),"Content-Type":"application/json"},body:JSON.stringify({ids:Array.from(g)})}),r=await a.json().catch(()=>({}));if(!a.ok)throw Error(r?.error?.message||r?.error||"æ¹æ¬¡åªé¤å¤±æ");let{deleted:i=0,failed:l=0}=r;f(new Set),await _(),l>0?t({title:"æ¹æ¬¡åªé¤å®æ",description:`æå ${i} çï¼å¤±æ ${l} ç`,variant:"destructive"}):t({title:"å·²æ¹æ¬¡åªé¤",description:`å·²åªé¤ ${i} ç`})}catch(e){t({title:"æ¹æ¬¡åªé¤å¤±æ",description:e instanceof Error?e.message:"è«ç¨å¾å試",variant:"destructive"})}finally{w(!1)}}},[e,_,t,g]),G=(0,i.useCallback)(async s=>{if(0!==g.size){T(s),R(!0);try{let t=await e(),a=await fetch("/api/admin/insurance-products/batch-set-listed",{method:"POST",headers:{...(0,sa.Pw)(t),"Content-Type":"application/json"},body:JSON.stringify({ids:Array.from(g),listed:s,dryRun:!0})}),r=await a.json().catch(()=>({}));if(!a.ok)throw Error(si(r)||"æ¹æ¬¡æä½é 覽失æ");E(r),A(!0)}catch(e){t({title:"æ¹æ¬¡æä½é 覽失æ",description:e instanceof Error?e.message:"è«ç¨å¾å試",variant:"destructive"})}finally{R(!1)}}},[e,t,g]),X=(0,i.useCallback)(async()=>
5{if(0!==g.size){R(!0);try{let s=await e(),a=await fetch("/api/admin/insurance-products/batch-set-listed",{method:"POST",headers:{...(0,sa.Pw)(s),"Content-Type":"application/json"},body:JSON.stringify({ids:Array.from(g),listed:S})}),r=await a.json().catch(()=>({}));if(!a.ok)throw Error(si(r)||"æ¹æ¬¡æä½å¤±æ");A(!1),E(null),f(new Set),await _(),t({title:S?"å·²æ¹æ¬¡ä¸æ¶":"å·²æ¹æ¬¡ä¸æ¶",description:`å·²æ´æ° ${r?.updated??g.size} ç`})}catch(e){t({title:"æ¹æ¬¡æä½å¤±æ",description:e instanceof Error?e.message:"è«ç¨å¾å試",variant:"destructive"})}finally{R(!1)}}},[e,_,t,g,S]);return{docs:s,pagedDocs:z,listPage:r,setListPage:l,totalPages:U,totalCount:s.length,pageSize:sr.$1,isLoading:n,error:c,filterReview:u,setFilterReview:m,filterInsurer:h,setFilterInsurer:x,filterCategory:p,setFilterCategory:j,loadList:_,selectedIds:g,setSelectedIds:f,batchIngesting:v,batchDeleteDeleting:b,batchDeleteDialogOpen:N,setBatchDeleteDialogOpen:k,batchSetListedDialogOpen:C,setBatchSetListedDialogOpen:A,batchSetListedTarget:S,batchSetListedDryRun:I,setBatchSetListedDryRun:E,batchSetListing:$,ingestProduct:B,markReviewed:L,setListed:Y,deleteOne:J,handleBatchIngest:M,handleBatchDelete:q,openBatchSetListed:G,confirmBatchSetListed:X,toggleSelectAll:W,selectAllOnPage:V,clearSelection:Z,toggleSelect:H,ingestingId:D,markReviewingId:F}}(s,t),{suggestions:Q,suggestionsLoading:ee,suggestionMarkingId:et,loadSuggestions:es,markSuggestionProcessed:ea}=function(e){let[t,s]=(0,i.useState)([]),[a,r]=(0,i.useState)(!1),[l,n]=(0,i.useState)(null),d=(0,i.useCallback)(async()=>{if(j.db){r(!0);try{let e=(0,_.P)((0,_.rJ)(j.db,e$.I.insuranceProductSuggestions),(0,_.AB)(100)),t=(await (0,_.GG)(e)).docs.map(e=>({id:e.id,...e.data()}));t.sort((e,t)=>{let s=e.createdAt&&"function"==typeof e.createdAt.toDate?e.createdAt.toDate().getTime():e.createdAt instanceof Date?e.createdAt.getTime():0;return(t.createdAt&&"function"==typeof t.createdAt.toDate?t.createdAt.toDate().getTime():t.createdAt instanceof Date?t.createdAt.getTime():0)-s}),s(t)}catch{s([])}finally{r(!1)}}},[]);return(0,i.useEffect)(()=>{d()},[d]),{suggestions:t,suggestionsLoading:a,suggestionMarkingId:l,loadSuggestions:d,markSuggestionProcessed:(0,i.useCallback)(async t=>{if(j.db){n(t);try{await (0,_.mZ)((0,_.doc)(j.db,e$.I.insuranceProductSuggestions,t),{status:"processed"}),s(e=>e.map(e=>e.id===t?{...e,status:"processed"}:e)),e({title:"å·²æ¨è¨çºå·²èç"})}catch{e({title:"æ´æ°å¤±æ",variant:"destructive"})}finally{n(null)}}},[e])}}(t),er=(0,i.useMemo)(()=>Q.filter(e=>"processed"!==e.status).length,[Q]),{formOpen:ei,setFormOpen:el,formData:en,setFormData:ed,editingProduct:ec,setEditingProduct:eo,editingProductSourceFiles:eu,editingProductSourceFilesLoading:em,isSubmitting:eh,openEdit:ex,submitForm:ep,reloadEditingProductSourceFiles:ej,onProductNameChange:eg,onPremiumCurrencyChange:ef,onRateExtractedDoc:ev}=function(e,t,s){let[a,r]=(0,i.useState)(null),[l,n]=(0,i.useState)(null),[d,c]=(0,i.useState)(sr.KM),[o,u]=(0,i.useState)(!1),[m,h]=(0,i.useState)(!1),[x,p]=(0,i.useState)(!1),[j,g]=(0,i.useState)([]),[f,v]=(0,i.useState)(!1),y=(0,i.useRef)(!1),b=(0,i.useCallback)(e=>{y.current=e},[]),w=(0,i.useCallback)(async()=>{if("edit"!==l||!a?.id)return void g([]);v(!0);try{let t=await e(),s=await fetch(`/api/admin/insurance-products/source-files?productId=${a.id}`,{headers:(0,sa.Pw)(t)}),r=s.ok?await s.json().catch(()=>({})):{files:[]};g(r.files??[])}catch{g([])}finally{v(!1)}},[l,a?.id,e]);(0,i.useEffect)(()=>{w()},[w]);let N=(0,i.useCallback)(async t=>{b(!1),r(t);let s={...sr.KM};for(let e of Object.keys(s))void 0!==t[e]&&null!==t[e]&&(s[e]=t[e]);if(t.productName&&"string"==typeof t.productName){let e=t.productName.replace(/[\uFF0Dï¼\u2013â\u2014â]/g,"-");s.productName=e.replace(/\s*-\s*(æ¢æ¬¾|è²»ç|DM)(_[^\s]*)?\s*$/i,"").trim()||e}t.updatedAt&&"string"==typeof t.updatedAt&&(s.updatedAt=t.updatedAt),s.reviewStatus="listed"===t.reviewStatus||"approved"===t.reviewStatus?"listed":"unlisted",s.termOptions=Array.isArray(t.termOptions)&&t.termOptions.length>0?[...t.termOptions]:t.termOption&&String(t.termOption).trim()?[String(t.termOption).trim()]:[];let a=s.productName;if(a&&a.includes("ä¸å¹´æ")){let e=s.termOptions;e&&0!==e.length?e.includes("ä¸å¹´æ")||(s.termOptions=["ä¸å¹´æ",...e.filter(e=>"ä¸å¹´æ"!==e)]):s.termOptions=["ä¸å¹´æ"]}c(s),n("edit");let i=await e();if(i&&t.id)try{let e=await fetch(`/api/admin/insurance-products/${t.id}`,{headers:(0,sa.Pw)(i)});if(e.ok){let s=await e.json();r({...s,id:s.id??t.id});let a=Array.isArray(s.rateTable)&&s.rateTable.length>0?s.rateTable:Array.isArray(s.accidentRateTable)&&s.accidentRateTable.length>0?s.accidentRateTable:[];c(e=>{let t={...e};if(a.length>0){let s=a.map(e=>e.age).filter(e=>"number"==typeof e&&Number.isFinite(e));s.length>0&&!e.ageRange&&(t={...t,ageRange:`${Math.min(...s)}-${Math.max(...s)}æ²`})}let r=t.premiumCurrency,i=null==r||""===String(r).trim();if(!y.current&&i){let e=String(t.productName??""),a=sl(e),r=sn(s.rateTable,s.accidentRateTable),i=a??r;i&&(t={...t,premiumCurrency:i})}return null!=s.medicalGapRules&&(t={...t,medicalGapRules:s.medicalGapRules}),t})}}catch{}},[e,b]),k=(0,i.useCallback)(e=>{c(t=>{let s={...t,productName:e};if(!y.current){let t=sl(e);t&&(s.premiumCurrency=t)}return s})},[]),C=(0,i.useCallback)(e=>{b(!0),c(t=>({...t,premiumCurrency:e}))},[b]),A=(0,i.useCallback)(e=>{c(t=>{if(y.current||null!=t.premiumCurrency&&""!==String(t.premiumCurrency).trim())return t;let s=sn(Array.isArray(e.rateTable)?e.rateTable:null,Array.isArray(e.accidentRateTable)?e.accidentRateTable:null);return s?{...t,premiumCurrency:s}:t})},[]),S=(0,i.useCallback)(async()=>
5{if(l&&a){if(!d.insurerCode||!d.productName||!d.productType)return void s({title:"è«å¡«å¯«å¿
å¡«æ¬ä½",description:"ä¿éªå
¬å¸ãååå稱ãéªç¨®çºå¿
å¡«",variant:"destructive"});u(!0);try{let r=await e(),i=[],l={insurerCode:d.insurerCode,category:d.category||"life",productType:d.productType,productName:d.productName,productCode:d.productCode||void 0,premiumCurrency:"usd"===d.premiumCurrency||"jpy"===d.premiumCurrency||"eur"===d.premiumCurrency?d.premiumCurrency:"twd",premiumRateType:d.premiumRateType||void 0,ageRange:d.ageRange||void 0,coveragePeriod:d.coveragePeriod||void 0,productRole:d.productRole||void 0,minInsuredAmountWan:null!=d.minInsuredAmountWan&&""!==d.minInsuredAmountWan?Number(d.minInsuredAmountWan):void 0,maxInsuredAmountWan:null!=d.maxInsuredAmountWan&&""!==d.maxInsuredAmountWan?Number(d.maxInsuredAmountWan):void 0,termOptions:Array.isArray(d.termOptions)&&d.termOptions.length>0?d.termOptions:void 0,termOption:Array.isArray(d.termOptions)&&d.termOptions.length>0?d.termOptions[0]:void 0,coverageSummary:d.coverageSummary||void 0,termsSummary:d.termsSummary||void 0,isDiscontinued:!!d.isDiscontinued,effectiveDate:d.effectiveDate||void 0,sourceUrl:d.sourceUrl||void 0,updatedAt:new Date().toISOString()};if(d.productCode||i.push("productCode"),d.premiumRateType||i.push("premiumRateType"),d.ageRange||i.push("ageRange"),d.coveragePeriod||i.push("coveragePeriod"),d.productRole||i.push("productRole"),(null==d.minInsuredAmountWan||""===d.minInsuredAmountWan)&&i.push("minInsuredAmountWan"),(null==d.maxInsuredAmountWan||""===d.maxInsuredAmountWan)&&i.push("maxInsuredAmountWan"),Array.isArray(d.termOptions)&&0!==d.termOptions.length||(i.push("termOptions"),i.push("termOption")),d.coverageSummary||i.push("coverageSummary"),d.termsSummary||i.push("termsSummary"),d.effectiveDate||i.push("effectiveDate"),d.sourceUrl||i.push("sourceUrl"),"medical"!==d.category)i.push("medicalGapRules");else if(null!=d.medicalGapRules&&"object"==typeof d.medicalGapRules){let e=sd.MJ.safeParse(d.medicalGapRules);if(e.success){let t=e.data;t.dailyFromActualExpense&&"none"!==t.dailyFromActualExpense.mode||t.hospitalMedicalAndSurgerySharedLimit||t.surgerySplit&&null!=t.surgerySplit.outpatientShareOfSurgeryTarget?l.medicalGapRules=e.data:i.push("medicalGapRules")}}i.length>0&&(l.__deleteFields=i),a?.benefitItems&&(l.benefitItems=a.benefitItems),a?.rateTable&&(l.rateTable=a.rateTable),a?.accidentRateTable&&(l.accidentRateTable=a.accidentRateTable);let c=await fetch(`/api/admin/insurance-products/${a.id}`,{method:"PATCH",headers:{"Content-Type":"application/json",...(0,sa.Pw)(r)},body:JSON.stringify(l)});if(!c.ok){let e=await c.json().catch(()=>({}));throw Error(e?.error?.message||e?.error||`HTTP ${c.status}`)}s({title:"å·²æ´æ°",description:"ä¿éªååå·²å²å"}),n(null),await t()}catch(e){s({title:"æä½å¤±æ",description:e instanceof Error?e.message:"è«ç¨å¾å試",variant:"destructive"})}finally{u(!1)}}},[l,a,d,e,t,s]),T=(0,i.useCallback)(async()=>{if(a?.id){h(!0);try{let t=await e(),i=await fetch(`/api/admin/insurance-products/${a.id}/summarize`,{method:"POST",headers:(0,sa.Pw)(t)}),l=await i.json();if(!i.ok){let e=l?.error,t=400===i.status?"æ¤ååå°ç¡æ¢æ¬¾ä¾æºæªï¼è«å
ä¸å³ PDF æåçå¾åä½¿ç¨æè¦":"string"==typeof e?e:e&&"object"==typeof e&&"string"==typeof e.message?String(e.message):`HTTP ${i.status}`;throw Error(t)}c(e=>({...e,coverageSummary:l.coverageSummary??e.coverageSummary,termsSummary:l.termsSummary??e.termsSummary,...null!=l.productCode&&""!==l.productCode?{productCode:l.productCode}:{},...null!=l.premiumCurrency&&""!==l.premiumCurrency?{premiumCurrency:l.premiumCurrency}:{},...null!=l.premiumRateType&&""!==l.premiumRateType?{premiumRateType:l.premiumRateType}:{},...null!=l.productName&&""!==l.productName?{productName:l.productName}:{},...null!=l.productType&&""!==l.productType?{productType:l.productType}:{},...null!=l.ageRange&&""!==l.ageRange?{ageRange:l.ageRange}:{},...null!=l.coveragePeriod&&""!==l.coveragePeriod?{coveragePeriod:l.coveragePeriod}:{},...null!=l.productRole&&""!==l.productRole?{productRole:l.productRole}:{}})),l.benefitItems&&Array.isArray(l.benefitItems)&&l.benefitItems.length>0&&r(e=>e?{...e,benefitItems:l.benefitItems}:null),s({title:"æè¦å®æ",description:"已便¢æ¬¾æªç¢åºä¿éæè¦ãæ¢æ¬¾æè¦èçè³ é
ç®"})}catch(e){s({title:"æè¦å¤±æ",description:e instanceof Error?e.message:"è«ç¨å¾å試",variant:"destructive"})}finally{h(!1)}}}
5,[a,e,s]),I=(0,i.useCallback)(async()=>{if(a?.id){if(!j.some(e=>"rate"===e.type))return void s({title:"ç¡æ³æ·å",description:"è«å
ä¸å³è²»ç PDF",variant:"destructive"});p(!0);try{let t=await e(),i=await fetch(`/api/admin/insurance-products/${a.id}/extract-rate`,{method:"POST",headers:(0,sa.Pw)(t)}),l=await i.json();if(!i.ok)throw Error(l?.error||`HTTP ${i.status}`);if(l.accidentRateTable&&Array.isArray(l.accidentRateTable)&&l.accidentRateTable.length>0){let e=l.accidentRateTable;r(t=>t?{...t,accidentRateTable:e}:null),l.ageRange&&"string"==typeof l.ageRange&&c(e=>({...e,ageRange:l.ageRange})),c(t=>{if(y.current)return t;let s=t.premiumCurrency;if(null!=s&&""!==String(s).trim())return t;let a=sn(null,e);return a?{...t,premiumCurrency:a}:t}),s({title:"æå¤éªè²»ç表æ·å宿",description:`å·²æ·å ${l.accidentRateTable.length} çè·æ¥é¡å¥ï¼ä¿è²»å°ç
§`})}else{let e=Array.isArray(l.rateTable)?l.rateTable:[];r(t=>t?{...t,rateTable:e}:null),l.ageRange&&"string"==typeof l.ageRange&&c(e=>({...e,ageRange:l.ageRange})),c(t=>{if(y.current)return t;let s=t.premiumCurrency;
5if(null!=s&&""!==String(s).trim())return t;let a=sn(e,null);return a?{...t,premiumCurrency:a}:t}),s({title:"è²»ç表æ·å宿",description:`å·²æ·å ${e.length} çè²»çå°ç
§`})}}catch(e){s({title:"æ·åè²»ç表失æ",description:e instanceof Error?e.message:"è«ç¨å¾å試",variant:"destructive"})}finally{p(!1)}}},[a,j,e,s]);return{formOpen:l,setFormOpen:n,formData:d,setFormData:c,editingProduct:a,setEditingProduct:r,editingProductSourceFiles:j,editingProductSourceFilesLoading:f,isSubmitting:o,isSummarizing:m,isExtractingRate:x,openEdit:N,submitForm:S,handleSummarize:T,handleExtractRate:I,reloadEditingProductSourceFiles:w,onProductNameChange:k,onPremiumCurrencyChange:C,onRateExtractedDoc:A}}(s,T,t),{exportFormat:ey,setExportFormat:eb,importFile:ew,setImportFile:eN,importResult:ek,isImporting:eC,handleExport:eA,handleImport:eS}=function(e,t,s,a){let[r,l]=(0,i.useState)("json"),[n,d]=(0,i.useState)(null),[c,o]=(0,i.useState)(!1),[u,m]=(0,i.useState)(null),h=(0,i.useCallback)(async()=>{try{let t=await e(),i=new URLSearchParams;i.set("format",r),a.filterReview&&"__all__"!==a.filterReview&&i.set("reviewStatus",a.filterReview),a.filterInsurer&&"__all__"!==a.filterInsurer&&i.set("insurerCode",a.filterInsurer),a.filterCategory&&"__all__"!==a.filterCategory&&i.set("category",a.filterCategory),i.set("limit","500");let l=await fetch(`/api/admin/insurance-products/export?${i.toString()}`,{headers:(0,sa.Pw)(t)});if(!l.ok)throw Error("å¯åºå¤±æ");let n=await l.blob(),d=URL.createObjectURL(n),c=document.createElement("a");c.href=d,c.download=`insurance-products-${Date.now()}.${r}`,c.click(),URL.revokeObjectURL(d),s({title:"å·²å¯åº"})}catch(e){s({title:"å¯åºå¤±æ",description:e instanceof Error?e.message:"è«ç¨å¾å試",variant:"destructive"})}},[e,r,a.filterReview,a.filterInsurer,a.filterCategory,s]),x=(0,i.useCallback)(async()=>{if(!n)return void s({title:"è«é¸ææªæ¡",variant:"destructive"});o(!0),m(null);try{let a=await e(),r=new FormData;r.set("file",n);let i=await fetch("/api/admin/insurance-products/import",{method:"POST",headers:(0,sa.Pw)(a),body:r}),l=await i.json();if(!i.ok)throw Error(l?.error||"æ»å
¥å¤±æ");m(l),d(null),s({title:"æ»å
¥å®æ",description:`æå ${l.imported} çï¼å¤±æ ${l.failed} ç`}),await t()}catch(e){s({title:"æ»å
¥å¤±æ",description:e instanceof Error?e.message:"è«ç¨å¾å試",variant:"destructive"})}finally{o(!1)}},[e,t,n,s]);return{exportFormat:r,setExportFormat:l,importFile:n,setImportFile:d,importResult:u,isImporting:c,handleExport:h,handleImport:x}}(s,T,t,(0,i.useMemo)(()=>({filterReview:b,filterInsurer:k,filterCategory:A}),[b,k,A])),{uploadFiles:eT,setUploadFiles:eI,r2Files:eE,selectedR2Paths:eR,isLoadingR2Files:eD,uploadResult:eP,isUploading:eF,handleBatchUpload:eO,loadR2Files:e_,toggleR2Path:eU,clearR2Selection:ez,handleBatchUploadFromR2:eB}=function(e,t,s){let[a,r]=(0,i.useState)([]),[l,n]=(0,i.useState)([]),[d,c]=(0,i.useState)([]),[o,u]=(0,i.useState)(!1),[m,h]=(0,i.useState)(!1),[x,p]=(0,i.useState)(null),j=(0,i.useCallback)(async()=>{if(0===a.length)return void t({title:"è«é¸ææªæ¡",variant:"destructive"});h(!0),p(null);let i=null;try{let s=await e(),l=new FormData;a.forEach(e=>l.append("files[]",e));let n=await fetch("/api/admin/insurance-products/upload",{method:"POST",headers:(0,sa.Pw)(s),body:l}),d=await n.json();if(!n.ok)throw Error(d?.error||`HTTP ${n.status}`);i=d,p({results:Array.isArray(d.results)?d.results:[],summary:d.summary??{total:0,succeeded:0,failed:0}}),r([]),t({title:"ä¸å³ä¸¦æ·å宿",description:`æå ${d.summary?.succeeded??0} çï¼å¤±æ ${d.summary?.failed??0} çãå表å°å¨èæ¯æ´æ°ã`})}catch(e){t({title:"ä¸å³å¤±æ",description:e instanceof Error?e.message:"è«ç¨å¾å試",variant:"destructive"})}finally{h(!1)}if(null==i)return;try{await s.loadList(),s.loadSourceFiles&&await s.loadSourceFiles()}catch{t({title:"åè¡¨æ´æ°å¤±æ",description:"ä¸å³å·²æåï¼è«æåéæ°æ´çé 颿ç¨å¾å試",variant:"destructive"})}let l=(Array.isArray(i.results)?i.results:[]).find(e=>e.success&&e.productIds?.length);if(l?.productIds?.[0]&&s.onOpenEdit)try{let t=await e(),a=await fetch(`/api/admin/insurance-products/${l.productIds[0]}`,{headers:(0,sa.Pw)(t)});if(a.ok){let e=await a.json();await s.onOpenEdit({...e,id:e.id??l.productIds[0]})}}catch{}},[e,t,a,s]),g=(0,i.useCallback)(async()=>{u(!0);try{let t=await e(),s=await fetch("/api/admin/insurance-products/r2-files?prefix=tii-product-documents/&limit=1000",{headers:(0,sa.Pw)(t)}),a=await s.json().catch(()=>({}));if(!s.ok)throw Error(a?.error||`HTTP ${s.status}`);let r=Array.isArray(a?.keys)?a.keys.filter(e=>"string"==typeof e):[];
5n(r)}catch(e){t({title:"è®å Cloudflare æªæ¡å¤±æ",description:e instanceof Error?e.message:"è«ç¨å¾å試",variant:"destructive"})}finally{u(!1)}},[e,t]),f=(0,i.useCallback)(e=>{c(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),v=(0,i.useCallback)(()=>c([]),[]),y=(0,i.useCallback)(async()=>{if(0===d.length)return void t({title:"è«å
鏿 Cloudflare æªæ¡",variant:"destructive"});h(!0),p(null);let a=null;try{let s=await e(),r=new FormData;r.append("r2Paths",JSON.stringify(d));let i=await fetch("/api/admin/insurance-products/upload",{method:"POST",headers:(0,sa.Pw)(s),body:r}),l=await i.json();if(!i.ok)throw Error(l?.error||`HTTP ${i.status}`);a=l,p({results:Array.isArray(l.results)?l.results:[],summary:l.summary??{total:0,succeeded:0,failed:0}}),c([]),t({title:"Cloudflare å¯å
¥ä¸¦æ·å宿",description:`æå ${l.summary?.succeeded??0} çï¼å¤±æ ${l.summary?.failed??0} çãå表å°å¨èæ¯æ´æ°ã`})}catch(e){t({title:"Cloudflare å¯å
¥å¤±æ",description:e instanceof Error?e.message:"è«ç¨å¾å試",variant:"destructive"})}finally{h(!1)}if(null!=a)try{await s.loadList(),s.loadSourceFiles&&await s.loadSourceFiles()}catch{t({title:"åè¡¨æ´æ°å¤±æ",description:"å¯å
¥å·²æåï¼è«æåéæ°æ´çé 颿ç¨å¾å試",variant:"destructive"})}},[e,t,d,s]);return{uploadFiles:a,setUploadFiles:r,r2Files:l,selectedR2Paths:d,isLoadingR2Files:o,uploadResult:x,isUploading:m,handleBatchUpload:j,loadR2Files:g,toggleR2Path:f,clearR2Selection:v,handleBatchUploadFromR2:y}}(s,t,(0,i.useMemo)(()=>({loadList:T,onOpenEdit:ex}),[T,ex])),eL=function(e){let{getToken:t,toast:s,onItemDone:a}=e,[r,l]=(0,i.useState)(null),[n,d]=(0,i.useState)(null),[c,o]=(0,i.useState)(!1),[u,m]=(0,i.useState)(!1),h=(0,i.useRef)(!1),x=(0,i.useRef)(a);x.current=a;let p=(0,i.useCallback)(async e=>{m(!0),h.current=!1;try{let a=await t();for(;!h.current;){let t;try{t=await (0,sc.yH)({token:a,jobId:e})}catch(e){s({title:"èç失æ",description:(0,sc.Jo)(e,"è«ç¨å¾å試"),variant:"destructive"});break}if(t.done)break;t.productId&&x.current&&x.current(t.productId),await new Promise(e=>setTimeout(e,250))}}finally{m(!1)}},[t,s]);(0,i.useEffect)(()=>{if(!r)return;let e=!1,s=async()=>{try{let s=await t(),a=await (0,sc.ll)({token:s,jobId:r});if(e||d(a),!e&&("done"===a.status||"cancelled"===a.status||"error"===a.status))return}catch{}e||setTimeout(s,1500)};return s(),()=>{e=!0}},[r,t]);let j=(0,i.useCallback)(async e=>{if(0===e.length)return void s({title:"è«å
å¾é¸åå",variant:"destructive"});o(!0);try{let a=await t(),{jobId:r}=await (0,sc.Vm)({token:a,productIds:e});l(r),d(null),p(r),s({title:"å·²å»ºç«æ¹æ¬¡å·¥ä½",description:`å
± ${e.length} çï¼å·²éå§æ¨é²`})}catch(e){s({title:"建ç«å¤±æ",description:(0,sc.Jo)(e,"è«ç¨å¾å試"),variant:"destructive"})}finally{o(!1)}},[t,p,s]),g=(0,i.useCallback)(async()=>{if(r){h.current=!0;try{let e=await t();await fetch(`/api/admin/insurance-products/batch-ingest/${r}`,{method:"DELETE",headers:(0,sa.Pw)(e)}),s({title:"å·²è¦æ±åæ¶æ¹æ¬¡å·¥ä½"})}catch(e){s({title:"忶失æ",description:(0,sc.Jo)(e,"è«ç¨å¾å試"),variant:"destructive"})}}},[r,t,s]),f=(0,i.useCallback)(()=>{r&&p(r)},[r,p]),v=n?.progress;return{jobId:r,job:n,creating:c,running:u,pct:v&&v.total>0?Math.round(v.processed/v.total*100):0,start:j,cancel:g,resume:f}}({getToken:s,toast:t,onItemDone:()=>{T()}}),eY=(0,i.useCallback)(e=>{d(e),l("sources"),setTimeout(()=>d(null),300)},[]),eJ=(0,i.useCallback)(()=>{eL.start(Array.from(I)),G()},[eL,I,G]),eM=null!==ei;return(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsx)(sN,{selectedCount:I.size,batchIngesting:E,batchDeleteDeleting:$,batchSetListing:W,selectAllOnPage:q,clearSelection:G,onBatchIngest:eJ,onOpenBatchDelete:()=>D(!0),onOpenBatchSetListed:V,ingestJob:eL.job,ingestJobId:eL.jobId,ingestRunning:eL.running,ingestPct:eL.pct,onCancelIngest:eL.cancel,onResumeIngest:eL.resume,onJumpToSources:()=>l("sources")}),(0,r.jsxs)(f.tU,{value:a,onValueChange:e=>l(e),className:"space-y-4",children:[(0,r.jsxs)(f.j7,{children:[(0,r.jsx)(f.Xi,{value:"list",children:"ååå表"}),(0,r.jsx)(f.Xi,{value:"sources",children:"æ°å¢ä¾æº"}),(0,r.jsxs)(f.Xi,{value:"suggestions",className:"gap-1.5",children:["建è°",er>0&&(0,r.jsx)(N.E,{variant:"destructive",className:"h-5 min-w-[20px] px-1 text-[10px]",children:er})]}),(0,r.jsx)(f.Xi,{value:"toid",children:"TOID å¯©æ ¸"}),(0,r.jsx)(f.Xi,{value:"export",children:"å¯åº"})]}),(0,r.jsx)(f.av,{value:"list",className:"mt-0",children:(0,r.jsx)(sC,{docs:c,listPage:o,totalPages:x,totalCount:p,pageSize:g,onPageChange:h,isLoading:v,error:y,filterReview:b,setFilterReview:w,filterInsurer:k,setFilterInsurer:C,filterCategory:A,setFilterCategory:S,loadList:T,selectedIds:I,ingestProduct:P,setListed:F,deleteOne:O,toggleSelectAll:H,toggleSelect:X,ingestingId:K,openEdit:ex})}),(0,r.jsx)(f.av,{value:"sources",className:"mt-0",children:(0,r.jsx)(sE,{pendingTiiKeyword:n,uploadFiles:eT,setUploadFiles:eI,r2Files:eE,selectedR2Paths:eR,isLoadingR2Files:eD,uploadResult:eP,isUploading:eF,onBatchUpload:eO,onLoadR2Files:e_,onToggleR2Path:eU,onClearR2Selection:ez,onBatchUploadFromR2:eB,importFile:ew,setImportFile:eN,importResult:ek,isImporting:eC,onImport:eS})}),(0,r.jsx)(f.av,{value:"suggestions",className:"mt-0",children:(0,r.jsx)(sR,{suggestions:Q,suggestionsLoading:ee,suggestionMarkingId:et,loadSuggestions:es,markSuggestionProcessed:ea,onSendToTiiCrawl:eY})}),(0,r.jsx)(f.av,{value:"toid",className:"mt-0",children:(0,r.jsx)(s_,{})}),(0,r.jsx)(f.av,{value:"export",className:"mt-0",children:(0,r.jsx)(s$,{exportFormat:ey,setExportFormat:eb,onExport:eA})})]}),(0,r.jsx)(sP,{open:R,onOpenChange:D,selectedCount:I.size,onConfirm:z,isDeleting:$}),(0,r.jsx)(sF,{open:B,onOpenChange:e=>{e||M(null),L(e)},listed:Y,count:J?.count??I.size,sample:J?.sample??[],invalid:J?.invali
5d??[],onConfirm:Z,isSubmitting:W}),eM?(0,r.jsx)(sU,{open:eM,onOpenChange:e=>!e&&el(null),getToken:s,toast:t,loadList:T,reloadEditingProductSourceFiles:ej,formOpen:ei,setFormOpen:el,formData:en,setFormData:ed,editingProduct:ec,setEditingProduct:eo,editingProductSourceFiles:eu,editingProductSourceFilesLoading:em,isSubmitting:eh,submitForm:ep,onProductNameChange:eg,onPremiumCurrencyChange:ef,onRateExtractedDoc:ev}):null]})}let sB={slug:"",title:"",summary:"",body:"",space:"guides",category:"general",audience:["public"],featureRoutes:[],order:0,published:!0,status:"draft",updatedAt:new Date().toISOString().slice(0,10),tags:[],relatedSlugs:[],relatedLearnSlugs:[]};function sL(){let{toast:e}=(0,u.dj)(),[t,s]=(0,i.useState)([]),[a,l]=(0,i.useState)(!0),[n,d]=(0,i.useState)(sB),[c,o]=(0,i.useState)(null),m=(0,i.useCallback)(async()=>{let e=j.auth.currentUser;if(!e)throw Error("æªç»å
¥");return e.getIdToken()},[]),h=(0,i.useCallback)(async()=>{l(!0);try{let e=await m(),t=await fetch("/api/admin/help/articles",{headers:{Authorization:`Bearer ${e}`}}),a=await t.json();if(!t.ok)throw Error(a.error||"è¼å
¥å¤±æ");s(a.articles??[])}catch(t){(0,O.vV)("HelpCenterManagement load",t),e({title:"è¼å
¥å¤±æ",variant:"destructive"})}finally{l(!1)}},[m,e]);(0,i.useEffect)(()=>{h()},[h]);let x=async()=>{try{let t=await m(),s={...n,status:n.status??"draft",published:"published"===n.status},a=c?`/api/admin/help/articles/${encodeURIComponent(c)}`:"/api/admin/help/articles",r=await fetch(a,{method:c?"PATCH":"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify(s)}),i=await r.json();if(!r.ok)throw Error(i.error||"å²å失æ");e({title:c?"å·²æ´æ°":"已建ç«"}),d(sB),o(null),await h()}catch(t){e({title:"å²å失æ",description:t instanceof Error?t.message:void 0,variant:"destructive"})}};return(0,r.jsxs)("div",{className:"space-y-6",children:[(0,r.jsxs)(y.Zp,{children:[(0,r.jsx)(y.aR,{children:(0,r.jsx)(y.ZB,{children:c?`編輯ï¼${c}`:"æ°å¢èªªææç« "})}),(0,r.jsxs)(y.Wu,{className:"grid gap-4 md:grid-cols-2",children:[(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w.J,{htmlFor:"slug",children:"Slug"}),(0,r.jsx)(W.p,{id:"slug",value:n.slug??"",disabled:!!c,onChange:e=>d(t=>({...t,slug:e.target.value}))})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w.J,{children:"çæ
"}),(0,r.jsxs)(Z.l6,{value:n.status??"draft",onValueChange:e=>d(t=>({...t,status:e})),children:[(0,r.jsx)(Z.bq,{children:(0,r.jsx)(Z.yv,{})}),(0,r.jsxs)(Z.gC,{children:[(0,r.jsx)(Z.eb,{value:"draft",children:"è稿"}),(0,r.jsx)(Z.eb,{value:"published",children:"å·²ç¼å¸"})]})]})]}),(0,r.jsxs)("div",{className:"space-y-2 md:col-span-2",children:[(0,r.jsx)(w.J,{htmlFor:"title",children:"æ¨é¡"}),(0,r.jsx)(W.p,{id:"title",value:n.title??"",onChange:e=>d(t=>({...t,title:e.target.value}))})]}),(0,r.jsxs)("div",{className:"space-y-2 md:col-span-2",children:[(0,r.jsx)(w.J,{htmlFor:"summary",children:"æè¦"}),(0,r.jsx)(W.p,{id:"summary",value:n.summary??"",onChange:e=>d(t=>({...t,summary:e.target.value}))})]}),(0,r.jsxs)("div",{className:"space-y-2 md:col-span-2",children:[(0,r.jsx)(w.J,{htmlFor:"body",children:"å
§æï¼Markdownï¼"}),(0,r.jsx)(V.T,{id:"body",rows:12,value:n.body??"",onChange:e=>d(t=>({...t,body:e.target.value}))})]}),(0,r.jsxs)("div",{className:"flex gap-2 md:col-span-2",children:[(0,r.jsx)(b.$,{onClick:x,children:"å²å"}),c?(0,r.jsx)(b.$,{variant:"outline",onClick:()=>{o(null),d(sB)},children:"åæ¶"}):null]})]})]}),(0,r.jsxs)(y.Zp,{children:[(0,r.jsx)(y.aR,{children:(0,r.jsxs)(y.ZB,{children:["Firestore æç« ï¼",t.length,"ï¼"]})}),(0,r.jsx)(y.Wu,{children:a?(0,r.jsx)("p",{className:"text-sm text-muted-foreground",children:"è¼å
¥ä¸â¦"}):0===t.length?(0,r.jsxs)("p",{className:"text-sm text-muted-foreground",children:["å°ç¡ CMS æç« ãå¯å·è¡ ",(0,r.jsx)("code",{className:"text-xs",children:"pnpm run migrate:help-to-firestore"})," ","èª MD å¯å
¥ã"]}):(0,r.jsx)("ul",{className:"space-y-2",children:t.map(e=>(0,r.jsxs)("li",{className:"flex items-center justify-between rounded border p-3 text-sm",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"font-medium",children:String(e.title)}),(0,r.jsxs)("p",{className:"text-muted-foreground",children:[String(e.slug)," \xb7 ",String(e.status)]})]}),(0,r.jsx)(b.$,{size:"sm",variant:"outline",onClick:()=>{o(String(e.slug)),d({slug:String(e.slug),title:String(e.title??""),summary:String(e.summary??""),body:String(e.body??""),space:e.space??"guides",category:e.category??"general",audience:e.audience??["public"],featureRoutes:e.featureRoutes??[],faqGroup:e.faqGroup,order:Number(e.order??0),status:e.status??"draft",updatedAt:String(e.updatedAt??new Date().toISOString().slice(0,10)),tags:e.tags??[],relatedSlugs:e.relatedSlugs??[],relatedLearnSlugs:e.relatedLearnSlugs??[]})},children:"編輯"})]},String(e.slug)))})})]})]})}var sY=s(35617),sJ=s(9234);async function sM(e){try{let t=await e.json();if("string"==typeof t.error)return t.error}catch{}return`HTTP ${e.status}`}function sW(e){return null===e?"å¾
å¡«":(0,sY.C)(e,{showSymbol:!0})}function sV(){let{breakdown:e,amounts:t,billingPeriods:s,loading:a,saving:l,setAmount:d,setBillingPeriod:c,previewMonthly:o,save:h}=function(){let{user:e}=(0,m.A)(),{toast:t}=(0,u.dj)(),[s,a]=(0,i.useState)(null),[r,l]=(0,i.useState)({}),[n,d]=(0,i.useState)({}),[c,o]=(0,i.useState)(!0),[h,x]=(0,i.useState)(!1),p=(0,i.useCallback)(async()=>
5{if(!e)throw Error("è«å
ç»å
¥");let t=await e.getIdToken();return{Authorization:`Bearer ${t}`,"Content-Type":"application/json"}},[e]),j=(0,i.useCallback)(e=>{let t={},s={};for(let a of e.items)t[a.id]=null===a.amountTwd?"":String(a.amountTwd),s[a.id]=a.billingPeriod;l(t),d(s)},[]),g=(0,i.useCallback)(async()=>{if(!e){a(null),o(!1);return}o(!0);try{let e=await p(),t=await fetch("/api/admin/sponsorship/cost-breakdown",{headers:e});if(!t.ok)throw Error(await sM(t));let s=(await t.json()).breakdown??(0,sJ.sN)();a(s),j(s)}catch(s){(0,O.vV)("è¼å
¥è´å©ææ¬è¡¨å¤±æ",s);let e=(0,sJ.sN)();a(e),j(e),t({variant:"destructive",title:"è¼å
¥å¤±æ",description:s instanceof Error?s.message:"ç¡æ³è¼å
¥ææ¬è¡¨"})}finally{o(!1)}},[e,p,j,t]);(0,i.useEffect)(()=>{g()},[g]);let f=(0,i.useCallback)((e,t)=>{l(s=>({...s,[e]:t}))},[]),v=(0,i.useCallback)((e,t)=>{d(s=>({...s,[e]:t}))},[]),y=(0,i.useCallback)(e=>{let t=r[e]?.trim()??"";if(!t)return null;let s=Number(t);if(!Number.isFinite(s)||s<0||!Number.isInteger(s))return null;let a=n[e]??"monthly";return(0,sJ.MV)(s,a)},[r,n]),b=(0,i.useCallback)(async()=>{if(s){x(!0);try{let e=s.items.map(e=>{let t=r[e.id]?.trim()??"",s=n[e.id]??e.billingPeriod;if(!t)return{id:e.id,amountTwd:null,billingPeriod:s};let a=Number(t);if(!Number.isFinite(a)||a<0||!Number.isInteger(a))throw Error(`${e.label} è²»ç¨é çºéè² æ´æ¸æç空ï¼å¾
å¡«ï¼`);return{id:e.id,amountTwd:a,billingPeriod:s}}),i=await p(),l=await fetch("/api/admin/sponsorship/cost-breakdown",{method:"PUT",headers:i,body:JSON.stringify({items:e})});if(!l.ok)throw Error(await sM(l));let d=(await l.json()).breakdown;a(d),j(d),t({title:"å·²å²å",description:"è´å©é ææ¬è¡¨å·²æ´æ°"})}catch(e){(0,O.vV)("å²åè´å©ææ¬è¡¨å¤±æ",e),t({variant:"destructive",title:"å²å失æ",description:e instanceof Error?e.message:"è«ç¨å¾å試"})}finally{x(!1)}}},[s,r,n,p,j,t]);return{breakdown:s,amounts:r,billingPeriods:n,loading:c,saving:h,setAmount:f,setBillingPeriod:v,previewMonthly:y,save:b,reload:g}}();if(a)return(0,r.jsx)("div",{className:"flex justify-center py-16",children:(0,r.jsx)($.default,{})});if(!e)return null;let x=e.items.every(e=>null!==o(e.id))?e.items.reduce((e,t)=>e+(o(t.id)??0),0):null;return(0,r.jsxs)(y.Zp,{children:[(0,r.jsxs)(y.aR,{className:"flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(y.ZB,{children:"è´å©çéææ¬è¡¨"}),(0,r.jsx)(y.BT,{className:"mt-1 max-w-2xl",children:"ç·¨è¼¯å¾æåæ¥è³å
¬éè´å©é ãå¯é¸æç¹³æå¹´ç¹³ï¼å¹´ç¹³é顿èªåæç®çºæåãè²»ç¨ç空å顯示ãå¾
å¡«ãï¼åè¨éå
¨é¨å¡«å¯«å¾ææå 總ã"})]}),(0,r.jsx)(b.$,{variant:"outline",size:"sm",asChild:!0,children:(0,r.jsxs)(n(),{href:"/sponsor#cost-breakdown",target:"_blank",children:[(0,r.jsx)(tZ.A,{className:"mr-2 h-4 w-4"}),"é 覽è´å©é "]})})]}),(0,r.jsxs)(y.Wu,{className:"space-y-6",children:[(0,r.jsx)("div",{className:"rounded-lg border overflow-x-auto",children:(0,r.jsxs)(eg.XI,{children:[(0,r.jsx)(eg.A0,{children:(0,r.jsxs)(eg.Hj,{className:"bg-muted/40 hover:bg-muted/40",children:[(0,r.jsx)(eg.nd,{className:"w-[100px]",children:"é
ç®"}),(0,r.jsx)(eg.nd,{children:"說æ"}),(0,r.jsx)(eg.nd,{className:"w-[110px]",children:"è¨è²»"}),(0,r.jsx)(eg.nd,{className:"w-[140px]",children:"è²»ç¨ï¼NT$ï¼"}),(0,r.jsx)(eg.nd,{className:"w-[120px] text-right",children:"æåï¼NT$ï¼"})]})}),(0,r.jsx)(eg.BF,{children:e.items.map(e=>{let a=s[e.id]??e.billingPeriod,i=o(e.id);return(0,r.jsxs)(eg.Hj,{children:[(0,r.jsx)(eg.nA,{className:"font-medium",children:e.label}),(0,r.jsx)(eg.nA,{className:"text-muted-foreground text-sm",children:e.description}),(0,r.jsx)(eg.nA,{children:(0,r.jsxs)(Z.l6,{value:a,onValueChange:t=>c(e.id,t),children:[(0,r.jsx)(Z.bq,{className:"h-9",children:(0,r.jsx)(Z.yv,{})}),(0,r.jsxs)(Z.gC,{children:[(0,r.jsx)(Z.eb,{value:"monthly",children:"æç¹³"}),(0,r.jsx)(Z.eb,{value:"yearly",children:"å¹´ç¹³"})]})]})}),(0,r.jsxs)(eg.nA,{children:[(0,r.jsxs)(w.J,{htmlFor:`cost-${e.id}`,className:"sr-only",children:[e.label," ","yearly"===a?"å¹´è²»":"æè²»"]}),(0,r.jsx)(W.p,{id:`cost-${e.id}`,type:"number",min:0,step:1,inputMode:"numeric",placeholder:"å¾
å¡«",value:t[e.id]??"",onChange:t=>d(e.id,t.target.value)}),(0,r.jsx)("p",{className:"mt-1 text-xs text-muted-foreground",children:"yearly"===a?"輸å
¥å¹´è²»":"輸å
¥æè²»"})]}),(0,r.jsxs)(eg.nA,{className:"text-right tabular-nums text-sm",children:[sW(i),"
5yearly"===a&&null!==i&&(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:"\xf7 12"})]})]},e.id)})})]})}),(0,r.jsxs)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[(0,r.jsxs)("p",{className:"text-sm text-muted-foreground",children:["æå¾æ´æ°ï¼",e.lastUpdated.replace(/-/g,"/")," \xb7 ",e.updateCadence,null!==x&&(0,r.jsxs)(r.Fragment,{children:[" \xb7 ","é 覽æåè¨ï¼",sW(x)]})]}),(0,r.jsx)(b.$,{onClick:h,disabled:l,children:l?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(eA.A,{className:"mr-2 h-4 w-4 animate-spin"}),"å²åä¸â¦"]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(e5.A,{className:"mr-2 h-4 w-4"}),"å²åææ¬è¡¨"]})})]})]})]})}let sZ=eD.Ik({kind:eD.eu("booking"),id:eD.Yj(),userId:eD.Yj().nullable(),advisorId:eD.Yj().nullable(),bookingDate:eD.Yj().nullable(),bookingTime:eD.Yj().nullable(),amount:eD.ai(),reason:eD.Yj().nullable(),paidAfterCancel:eD.zM(),paymentReference:eD.Yj().nullable(),cancelledAt:eD.Yj().nullable()}),sH=eD.Ik({kind:eD.eu("sponsorshipPayment"),id:eD.Yj(),sponsorshipId:eD.Yj(),userId:eD.Yj().nullable(),amount:eD.ai(),paymentDate:eD.Yj().nullable(),merchantTradeNo:eD.Yj().nullable(),ecpayTradeNo:eD.Yj().nullable()}),sq=eD.Ik({bookings:eD.YO(sZ),sponsorshipPayments:eD.YO(sH)});eD.Ik({kind:eD.k5(["booking","sponsorshipPayment"]),id:eD.Yj().min(1),note:eD.Yj().trim().max(200).optional()});let sG=eD.Ik({sponsorshipCount:eD.ai().int().nonnegative(),sponsorshipGross:eD.ai(),refundedCount:eD.ai().int().nonnegative(),refundedAmount:eD.ai(),sponsorshipNet:eD.ai(),bookingGross:eD.ai(),bookingPlatformFee:eD.ai()}),sX=sG.extend({month:eD.ai().int().min(1).max(12)}),sK=eD.Ik({year:eD.ai().int(),months:eD.YO(sX).length(12),totals:sG});async function sQ(e){try{let t=await e.json();if("string"==typeof t.error)return t.error}catch{}return`HTTP ${e.status}`}function s0(){let{user:e}=(0,m.A)();return(0,i.useCallback)(async(t,s)=>{if(!e)throw Error("è«å
ç»å
¥");let a=await e.getIdToken();return fetch(t,{...s,headers:{Authorization:`Bearer ${a}`,"Content-Type":"application/json",...s?.headers}})},[e])}let s1=e=>`NT$${e.toLocaleString("zh-TW")}`;function s2(e){return e?new Date(e).toLocaleString("zh-TW",{timeZone:"Asia/Taipei",hour12:!1}):"â"}function s4({value:e}){return e?(0,r.jsx)("span",{className:"font-mono text-xs",title:e,children:e.length>10?`${e.slice(0,10)}â¦`:e}):(0,r.jsx)("span",{className:"text-muted-foreground",children:"â"})}function s3(){let{queue:e,loading:t,markingId:s,reload:a,markRefunded:l}=function(){let{user:e}=(0,m.A)(),{toast:t}=(0,u.dj)(),s=s0(),[a,r]=(0,i.useState)(null),[l,n]=(0,i.useState)(!0),[d,c]=(0,i.useState)(null),o=(0,i.useCallback)(async()=>{if(!e){r(null),n(!1);return}n(!0);try{let e=await s("/api/admin/payments/refunds");if(!e.ok)throw Error(await sQ(e));r(sq.parse(await e.json()))}catch(e){(0,O.vV)("è¼å
¥å¾
鿬¾æ¸
å®å¤±æ",e),t({variant:"destructive",title:"è¼å
¥å¤±æ",description:e instanceof Error?e.message:"ç¡æ³è¼å
¥å¾
鿬¾æ¸
å®"})}finally{n(!1)}},[e,s,t]);(0,i.useEffect)(()=>{o()},[o]);let h=(0,i.useCallback)(async e=>{c(e.id);try{let a=await s("/api/admin/payments/refunds",{method:"POST",body:JSON.stringify(e)});if(!a.ok)throw Error(await sQ(a));return t({title:"å·²æ¨è¨çºå·²é款"}),await o(),!0}catch(e){return(0,O.vV)("æ¨è¨å·²é款失æ",e),t({variant:"destructive",title:"æ¨è¨å¤±æ",description:e instanceof Error?e.message:"ç¡æ³æ¨è¨å·²é款"}),!1}finally{c(null)}},[s,o,t]);return{queue:a,loading:l,markingId:d,reload:o,markRefunded:h}}(),[n,d]=(0,i.useState)(null),[c,o]=(0,i.useState)(""),h=()=>{d(null),o("")},x=async()=>{if(!n)return;let e=c.trim();await l({kind:n.kind,id:n.id,...e?{note:e}:{}})&&h()},p=e?.bookings??[],j=e?.sponsorshipPayments??[],g=p.length+j.length;return(0,r.jsxs)(y.Zp,{children:[(0,r.jsx)(y.aR,{children:(0,r.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-2",children:[(0,r.jsxs)("div",{className:"space-y-1",children:[(0,r.jsxs)(y.ZB,{className:"flex items-center gap-2",children:["å¾
鿬¾",g>0&&(0,r.jsx)(N.E,{variant:"destructive",children:g})]}
5),(0,r.jsx)(y.BT,{children:"è«å
å¨ç¶ çå» åå¾å°å®æé款ï¼åæãæ¨è¨å·²é款ããæ¨è¨å¾ææ´æ°å¸³æ¬ï¼é ç´ææ²é·é¡§åæ¶å
¥ãè´å©æèªå
¬éçµ±è¨æ£åï¼ï¼ä¸¦å¯«å
¥æä½æ¥èªã"})]}),(0,r.jsxs)(b.$,{variant:"outline",size:"sm",onClick:()=>void a(),disabled:t,children:[(0,r.jsx)(ef.A,{className:`h-4 w-4 mr-1 ${t?"animate-spin":""}`}),"éæ°æ´ç"]})]})}),(0,r.jsx)(y.Wu,{className:"space-y-6",children:t&&!e?(0,r.jsx)("div",{className:"flex justify-center py-8",children:(0,r.jsx)($.default,{})}):0===g?(0,r.jsx)("p",{className:"text-sm text-muted-foreground",children:"ç®åæ²æå¾
鿬¾é
ç®ã"}):(0,r.jsxs)(r.Fragment,{children:[p.length>0&&(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("h3",{className:"text-sm font-semibold",children:["é¡§åé ç´ï¼",p.length,"ï¼"]}),(0,r.jsx)("div",{className:"overflow-x-auto",children:(0,r.jsxs)(eg.XI,{children:[(0,r.jsx)(eg.A0,{children:(0,r.jsxs)(eg.Hj,{children:[(0,r.jsx)(eg.nd,{children:"é ç´ææ®µ"}),(0,r.jsx)(eg.nd,{className:"text-right",children:"鿬¾éé¡"}),(0,r.jsx)(eg.nd,{children:"åå "}),(0,r.jsx)(eg.nd,{children:"ç¶ çè¨å®"}),(0,r.jsx)(eg.nd,{children:"åæ¶æé"}),(0,r.jsx)(eg.nd,{children:"ç¨æ¶"}),(0,r.jsx)(eg.nd,{})]})}),(0,r.jsx)(eg.BF,{children:p.map(e=>(0,r.jsxs)(eg.Hj,{children:[(0,r.jsx)(eg.nA,{className:"whitespace-nowrap",children:[e.bookingDate,e.bookingTime].filter(Boolean).join(" ")||"â"}),(0,r.jsx)(eg.nA,{className:"text-right whitespace-nowrap",children:s1(e.amount)}),(0,r.jsx)(eg.nA,{children:(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-1",children:[e.paidAfterCancel&&(0,r.jsx)(N.E,{variant:"destructive",children:"忶徿仿¬¾"}),(0,r.jsx)("span",{className:"text-sm",children:e.reason??"â"})]})}),(0,r.jsx)(eg.nA,{children:(0,r.jsx)(s4,{value:e.paymentReference})}),(0,r.jsx)(eg.nA,{className:"whitespace-nowrap",children:s2(e.cancelledAt)}),(0,r.jsx)(eg.nA,{children:(0,r.jsx)(s4,{value:e.userId})}),(0,r.jsx)(eg.nA,{className:"text-right",children:(0,r.jsx)(b.$,{size:"sm",variant:"outline",disabled:null!==s,onClick:()=>d({kind:"booking",id:e.id,label:`é ç´ ${[e.bookingDate,e.bookingTime].filter(Boolean).join(" ")}`,amount:e.amount}),children:"æ¨è¨å·²é款"})})]},e.id))})]})})]}),j.length>0&&(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("h3",{className:"text-sm font-semibold",children:["è´å©ï¼åæ¶å¾ä»è¢«æ£æ¬¾ï¼",j.length,"ï¼"]}),(0,r.jsx)("div",{className:"overflow-x-auto",children:(0,r.jsxs)(eg.XI,{children:[(0,r.jsx)(eg.A0,{children:(0,r.jsxs)(eg.Hj,{children:[(0,r.jsx)(eg.nd,{children:"仿¬¾æé"}),(0,r.jsx)(eg.nd,{className:"text-right",children:"éé¡"}),(0,r.jsx)(eg.nd,{children:"ç¶ ç交æç·¨è"}),(0,r.jsx)(eg.nd,{children:"ç¹åºè¨å®"}),(0,r.jsx)(eg.nd,{children:"ç¨æ¶"}),(0,r.jsx)(eg.nd,{})]})}),(0,r.jsx)(eg.BF,{children:j.map(e=>(0,r.jsxs)(eg.Hj,{children:[(0,r.jsx)(eg.nA,{className:"whitespace-nowrap",children:s2(e.paymentDate)}),(0,r.jsx)(eg.nA,{className:"text-right whitespace-nowrap",children:s1(e.amount)}),(0,r.jsx)(eg.nA,{children:(0,r.jsx)(s4,{value:e.ecpayTradeNo})}),(0,r.jsx)(eg.nA,{children:(0,r.jsx)(s4,{value:e.merchantTradeNo})}),(0,r.jsx)(eg.nA,{children:(0,r.jsx)(s4,{value:e.userId})}),(0,r.jsx)(eg.nA,{className:"text-right",children:(0,r.jsx)(b.$,{size:"sm",variant:"outline",disabled:null!==s,onClick:()=>d({kind:"sponsorshipPayment",id:e.id,label:`è´å©ä»æ¬¾ï¼è¨å® ${e.merchantTradeNo??e.id}ï¼`,amount:e.amount}),children:"æ¨è¨å·²é款"})})]},e.id))})]})})]})]})}),(0,r.jsx)(sD.Lt,{open:null!==n,onOpenChange:e=>{e||null!==s||h()},children:(0,r.jsxs)(sD.EO,{children:[(0,r.jsxs)(sD.wd,{children:[(0,r.jsx)(sD.r7,{children:"確èªå·²å¨ç¶ ç宿鿬¾ï¼"}),(0,r.jsxs)(sD.$v,{children:[n?`${n.label}ï¼é款éé¡ ${s1(n.amount)}ã`:"","éè£¡åªæ´æ°å¸³æ¬ï¼ä¸æåç¶ çç¼åºéæ¬¾ï¼æ¨è¨å¾ç¡æ³å¾©åã"]})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(w.J,{htmlFor:"refund-note",children:"å註ï¼é¸å¡«ï¼ä¾å¦ç¶ ç鿬¾æ¥æï¼"}),(0,r.jsx)(V.T,{id:"refund-note",value:c,maxLength:200,onChange:e=>o(e.target.value)})]}),(0,r.jsxs)(sD.ck,{children:[(0,r.jsx)(sD.Zr,{disabled:null!==s,children:"åæ¶"}),(0,r.jsxs)(sD.Rx,{disabled:null!==s,onClick:e=>{e.preventDefault(),x()},children:[null!==s&&(0,r.jsx)(eA.A,{className:"h-4 w-4 animate-spin mr-1"}),"æ¨è¨å·²é款"]})]})]})})]})}let s5=e=>
5`NT$${e.toLocaleString("zh-TW")}`,s6=["æä»½","è´å©çæ¸","æ¶å°è´å©","鿬¾çæ¸","鿬¾éé¡","è´å©æ·¨é¡","é ç´æ¶æ¬¾","平尿åè²»"];function s8(){let e=Number(new Intl.DateTimeFormat("en-CA",{timeZone:"Asia/Taipei",year:"numeric"}).format(new Date)),[t,s]=(0,i.useState)(e),{report:a,loading:l,reload:n}=function(e){let{user:t}=(0,m.A)(),{toast:s}=(0,u.dj)(),a=s0(),[r,l]=(0,i.useState)(null),[n,d]=(0,i.useState)(!0),c=(0,i.useCallback)(async()=>{if(!t){l(null),d(!1);return}d(!0);try{let t=await a(`/api/admin/payments/sponsorship-income?year=${e}`);if(!t.ok)throw Error(await sQ(t));l(sK.parse(await t.json()))}catch(e){(0,O.vV)("è¼å
¥è´å©ææ¶å
¥å ±è¡¨å¤±æ",e),s({variant:"destructive",title:"è¼å
¥å¤±æ",description:e instanceof Error?e.message:"ç¡æ³è¼å
¥æ¶å
¥å ±è¡¨"})}finally{d(!1)}},[t,a,s,e]);return(0,i.useEffect)(()=>{c()},[c]),{report:r,loading:n,reload:c}}(t),d=[e,e-1,e-2];return(0,r.jsxs)(y.Zp,{children:[(0,r.jsx)(y.aR,{children:(0,r.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-2",children:[(0,r.jsxs)("div",{className:"space-y-1",children:[(0,r.jsx)(y.ZB,{children:"è´å©ææ¶å
¥å ±è¡¨"}),(0,r.jsx)(y.BT,{children:"æä»½ä»¥å°åæéè¨ç®ãè´å©ä¾ä»æ¬¾æéæ¸æï¼é ç´æ¶æ¬¾ä¾è«®è©¢æ¶å
¥è¨éæéæ¸æï¼å·²é款è
æé¤ï¼ï¼èè´å©åä¸åç¶ çç¹åºå¸³æ¶ï¼å¯ç¨æ¼å°å¸³ãç¨
ç±ç»è¨èå ±ç¨
éæª»è«ä»¥åç¨
å±å
¬åçºæºã"})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsxs)(Z.l6,{value:String(t),onValueChange:e=>s(Number(e)),children:[(0,r.jsx)(Z.bq,{className:"w-28",children:(0,r.jsx)(Z.yv,{})}),(0,r.jsx)(Z.gC,{children:d.map(e=>(0,r.jsxs)(Z.eb,{value:String(e),children:[e," å¹´"]},e))})]}),(0,r.jsx)(b.$,{variant:"outline",size:"sm",onClick:()=>void n(),disabled:l,children:(0,r.jsx)(ef.A,{className:`h-4 w-4 ${l?"animate-spin":""}`})}),(0,r.jsxs)(b.$,{variant:"outline",size:"sm",onClick:()=>{let e,t,s,r,i;return a&&(e=a.months.map(e=>[`${a.year}-${String(e.month).padStart(2,"0")}`,e.sponsorshipCount,e.sponsorshipGross,e.refundedCount,e.refundedAmount,e.sponsorshipNet,e.bookingGross,e.bookingPlatformFee]),t=a.totals,e.push(["åè¨",t.sponsorshipCount,t.sponsorshipGross,t.refundedCount,t.refundedAmount,t.sponsorshipNet,t.bookingGross,t.bookingPlatformFee]),s=new Blob(["\uFEFF"+[s6,...e].map(e=>e.join(",")).join("\r\n")],{type:"text/csv;charset=utf-8"}),r=URL.createObjectURL(s),void((i=document.createElement("a")).href=r,i.download=`sponsorship-income-${a.year}.csv`,i.click(),URL.revokeObjectURL(r)))},disabled:!a||l,children:[(0,r.jsx)(eS.A,{className:"h-4 w-4 mr-1"}),"å¯åº CSV"]})]})]})}),(0,r.jsx)(y.Wu,{children:l&&!a?(0,r.jsx)("div",{className:"flex justify-center py-8",children:(0,r.jsx)($.default,{})}):a?(0,r.jsx)("div",{className:"overflow-x-auto",children:(0,r.jsxs)(eg.XI,{children:[(0,r.jsx)(eg.A0,{children:(0,r.jsxs)(eg.Hj,{children:[(0,r.jsx)(eg.nd,{children:"æä»½"}),(0,r.jsx)(eg.nd,{className:"text-right",children:"è´å©çæ¸"}),(0,r.jsx)(eg.nd,{className:"text-right",children:"æ¶å°è´å©"}),(0,r.jsx)(eg.nd,{className:"text-right",children:"鿬¾"}),(0,r.jsx)(eg.nd,{className:"text-right",children:"è´å©æ·¨é¡"}),(0,r.jsx)(eg.nd,{className:"text-right",children:"é ç´æ¶æ¬¾"}),(0,r.jsx)(eg.nd,{className:"text-right",children:"平尿åè²»"})]})}),(0,r.jsxs)(eg.BF,{children:[a.months.map(e=>(0,r.jsxs)(eg.Hj,{children:[(0,r.jsxs)(eg.nA,{children:[e.month," æ"]}),(0,r.jsx)(eg.nA,{className:"text-right",children:e.sponsorshipCount}),(0,r.jsx)(eg.nA,{className:"text-right",children:s5(e.sponsorshipGross)}),(0,r.jsx)(eg.nA,{className:"text-right",children:e.refundedCount>0?`${s5(e.refundedAmount)}ï¼${e.refundedCount}ï¼`:"â"}),(0,r.jsx)(eg.nA,{className:"text-right font-medium",children:s5(e.sponsorshipNet)}),(0,r.jsx)(eg.nA,{className:"text-right",children:s5(e.bookingGross)}),(0,r.jsx)(eg.nA,{className:"text-right",children:s5(e.bookingPlatformFee)})]},e.month)),(0,r.jsxs)(eg.Hj,{className:"font-semibold",children:[(0,r.jsx)(eg.nA,{children:"åè¨"}),(0,r.jsx)(eg.nA,{className:"text-right",children:a.totals.sponsorshipCount}),(0,r.jsx)(eg.nA,{className:"text-right",children:s5(a.totals.sponsorshipGross)}),(0,r.jsx)(eg.nA,{className:"text-right",children:a.totals.refundedCount>0?s5(a.totals.refundedAmount):"â"}),(0,r.jsx)(eg.nA,{className:"text-right",children:s5(a.totals.sponsorshipNet)}),(0,r.jsx)(eg.nA,{className:"text-right",children:s5(a.totals.bookingGross)}),(0,r.jsx)(eg.nA,{className:"text-right",children:s5(a.totals.bookingPlatformFee)})]})]})]})}):null})]})}let s7=["dashboard","advisors","wishes","users","sponsorship","logs","database","insurance-products","changelog","help-center","credit-card-requests","test","sound-test"],s9=(a=function(){let{toast:e}=(0,u.dj)(),{user:t,setViewingUser:a}=(0,m.A)(),l=(0,d.useRouter)(),v=(0,d.useSearchParams)(),[y,b]=(0,i.useState)([]),[w,N]=(0,i.useState)("dashboard");(0,i.useEffect)(()=>{let e=v.get("tab");e&&("advisor-tiers"===e?N("advisors"):"onboarding-metrics"===e?N("users"):s7.includes(e)&&N(e))},[v]);let k=function(){let e=(0,i.useMemo)(()=>(0,x.l)(),[]),t=(0,i.useMemo)(()=>[],[]),s=(0,i.useMemo)(()=>[],[]),{data:a,isLoading:r,error:l,mutate:n}=(0,h.Ay)("admin/advisors",async()=>
5{if(!await p())return console.log("[useAdmin] Firebase å°æªæºå好ï¼è¿å空é£å (advisors)"),[];try{let t=await e.admin.listAdvisors();if(!t.ok)throw Error(t.error||"fetch_failed");return t.data||[]}catch(e){if(e?.message?.includes("Firebase")||e?.message?.includes("initializeApp"))return[];throw e}},{revalidateOnFocus:!1,revalidateOnReconnect:!1,shouldRetryOnError:e=>!e?.message?.includes("Firebase")&&!e?.message?.includes("initializeApp")}),{data:d,isLoading:c,error:o,mutate:u}=(0,h.Ay)("admin/suggestions",async()=>{if(!await p())return console.log("[useAdmin] Firebase å°æªæºå好ï¼è¿å空é£å (suggestions)"),[];try{let t=await e.admin.listSuggestions();if(!t.ok)throw Error(t.error||"fetch_failed");return t.data||[]}catch(e){if(e?.message?.includes("Firebase")||e?.message?.includes("initializeApp"))return[];throw e}},{revalidateOnFocus:!1,revalidateOnReconnect:!1,shouldRetryOnError:e=>!e?.message?.includes("Firebase")&&!e?.message?.includes("initializeApp")}),m=(0,i.useCallback)(async()=>{try{if(!await p()&&(console.log("[listUsers] Firebase å°æªæºå好ï¼çå¾
å¾é試..."),await new Promise(e=>setTimeout(e,500)),!await p()))return console.log("[listUsers] Firebase 仿ªæºå好ï¼è¿å空é£å"),[];console.log("[listUsers] éå§è¼å
¥ç¨æ¶...");let t=await e.admin.getAllUsers("");if(!t.ok)return console.warn("[listUsers] è¼å
¥å¤±æ:",t.error),t.error?.includes("Firebase")||t.error?.includes("å°æªåå§å"),[];let s=Array.isArray(t.data)?t.data:[];return console.log("[listUsers] æåè¼å
¥",s.length,"åç¨æ¶"),s}catch(e){return console.error("[listUsers] ç¼çé¯èª¤:",e),[]}},[e]),j=async t=>{let s=await e.admin.addAdvisor(t);if(!s.ok)throw Error(s.error||"add_failed");await n()},g=async(t,s)=>{let a=await e.admin.updateAdvisor(t,s);if(!a.ok)throw Error(a.error||"update_failed");await n()},f=async t=>{let s=await e.admin.deleteAdvisor(t);if(!s.ok)throw Error(s.error||"delete_failed");await n()},v=async(t,s)=>{let a=await e.admin.updateSuggestionStatus(t,s);if(!a.ok)throw Error(a.error||"update_status_failed");await u()},y=async t=>{let s=await e.admin.deleteSuggestion(t);
5if(!s.ok)throw Error(s.error||"delete_failed");await u()};return{advisors:a??t,suggestions:d??s,loading:r||c,error:l?.message||o?.message||null,addAdvisor:j,updateAdvisor:g,deleteAdvisor:f,updateSuggestionStatus:v,deleteSuggestion:y,listUsers:m}}(),{listUsers:C}=k,A=(0,i.useMemo)(()=>Array.isArray(k.advisors)?k.advisors:[],[k.advisors]),S=(0,i.useMemo)(()=>Array.isArray(k.suggestions)?k.suggestions:[],[k.suggestions]);return(0,i.useEffect)(()=>{let a=!0,r=!1,i=0,l=null,n=async()=>{if(!t||!j.auth){a&&b([]);return}try{let{db:e,functions:t}=await Promise.resolve().then(s.bind(s,76458));if(!e||!t)return void(i<10&&a?(i++,l=setTimeout(()=>{a&&n()},500)):a&&!r&&(r=!0))}catch(e){i<10&&a?(i++,l=setTimeout(()=>{a&&n()},500)):a&&!r&&(r=!0);return}try{if(!await t.getIdToken(!0))throw Error("ç¡æ³åå¾ä½¿ç¨è
ID Token");let e=await C();a&&(b(Array.isArray(e)?e:[]),r=!1,i=0)}catch(t){if(g.Cp(t instanceof Error?t:Error(String(t)),{level:"error",extra:{message:"[loadUsers] è¼å
¥é¯èª¤",retryCount:i},tags:{source:"AdminPage.loadUsers"}}),t?.message?.includes("Firebase")||t?.message?.includes("initializeApp")||t?.message?.includes("default Firebase app")||t?.code==="functions/unavailable"){a&&i<10&&!r&&(i++,l=setTimeout(()=>{a&&n()},1e3));return}a&&!r&&(r=!0,e({variant:"destructive",title:"è¼å
¥å¤±æ",description:t.message||"ç¡æ³è¼å
¥ä½¿ç¨è
è³æï¼è«ç¨å¾å試ã"}))}};return n(),()=>{a=!1,l&&clearTimeout(l)}},[t,e,C]),(0,r.jsx)(tW.A,{children:(0,r.jsx)(tV,{children:(0,r.jsxs)(f.tU,{value:w,onValueChange:N,children:[(0,r.jsx)("div",{className:"w-full",children:(0,r.jsxs)(f.j7,{className:"mb-6",children:[(0,r.jsx)(f.Xi,{value:"dashboard",children:"總覽"}),(0,r.jsx)(f.Xi,{value:"advisors",children:"é¡§å"}),(0,r.jsx)(f.Xi,{value:"wishes",children:"顿"}),(0,r.jsx)(f.Xi,{value:"users",children:"ç¨æ¶"}),(0,r.jsx)(f.Xi,{value:"sponsorship",children:"è´å©ï¼éæµ"}),(0,r.jsx)(f.Xi,{value:"logs",children:"æä½æ¥èª"}),(0,r.jsx)(f.Xi,{value:"database",children:"è³æåº«"}),(0,r.jsx)(f.Xi,{value:"insurance-products",children:"ä¿éªåå"}),(0,r.jsx)(f.Xi,{value:"changelog",children:"æ´æ°"}),(0,r.jsx)(f.Xi,{value:"help-center",children:"說æä¸å¿"}),(0,r.jsx)(f.Xi,{value:"testimonials",children:"好è©"}),(0,r.jsx)(f.Xi,{value:"credit-card-requests",children:"ä¿¡ç¨å¡"}),(0,r.jsx)(f.Xi,{value:"test",children:"系統測試"}),(0,r.jsx)(f.Xi,{value:"sound-test",children:"鳿"}),(0,r.jsxs)(n(),{href:"/dashboard/admin/homepage-preview",target:"_blank",className:"relative z-[1] inline-flex items-center justify-center gap-1.5 whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium text-muted-foreground transition-colors hover:rounded-md hover:bg-muted/30 hover:text-foreground/80",children:[(0,r.jsx)(c.A,{className:"h-3.5 w-3.5"}),"é¦é 試å"]}),(0,r.jsxs)(n(),{href:"/design-system",target:"_blank",className:"relative z-[1] inline-flex items-center justify-center gap-1.5 whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium text-muted-foreground transition-colors hover:rounded-md hover:bg-muted/30 hover:text-foreground/80",children:[(0,r.jsx)(o.A,{className:"h-3.5 w-3.5"}),"è¨è¨ç³»çµ±"]})]})}),(0,r.jsx)(f.av,{value:"dashboard",children:(0,r.jsx)(tW.A,{children:(0,r.jsx)(M,{users:y,advisors:A,suggestions:S})})}),(0,r.jsx)(f.av,{value:"advisors",children:(0,r.jsxs)("div",{className:"space-y-6",children:[(0,r.jsx)(tW.A,{children:(0,r.jsx)(ej,{advisors:A,onAdvisorUpdate:()=>{}
5,updateAdvisor:k.updateAdvisor,deleteAdvisor:k.deleteAdvisor})}),(0,r.jsx)(tW.A,{children:(0,r.jsx)(eN,{})})]})}),(0,r.jsx)(f.av,{value:"wishes",children:(0,r.jsx)(tW.A,{children:(0,r.jsx)(eC,{suggestions:S,onSuggestionUpdate:()=>{},updateSuggestionStatus:k.updateSuggestionStatus,deleteSuggestion:k.deleteSuggestion})})}),(0,r.jsx)(f.av,{value:"users",children:(0,r.jsxs)("div",{className:"space-y-6",children:[(0,r.jsx)(tW.A,{children:(0,r.jsx)(eo,{users:y,onUserUpdate:()=>{},onViewUser:t=>{try{if(!t?.uid)return void e({variant:"destructive",title:"é¯èª¤",description:"ç¡æ³åå¾ä½¿ç¨è
ID"});if(!t?.email)return void e({variant:"destructive",title:"é¯èª¤",description:"ç¡æ³åå¾ä½¿ç¨è
Email"});a(t.uid,t.email),e({title:"已忿ª¢è¦æ¨¡å¼",description:`æ£å¨æª¢è¦ä½¿ç¨è
ï¼${t.email}`}),l.push("/dashboard")}catch(s){g.Cp(s instanceof Error?s:Error(String(s)),{level:"error",extra:{message:"[handleViewUser] é¯èª¤",userId:t?.uid},tags:{source:"AdminPage.handleViewUser"}}),e({variant:"destructive",title:"é¯èª¤",description:s?.message||"ç¡æ³åææª¢è¦æ¨¡å¼ï¼è«ç¨å¾å試"})}}})}),(0,r.jsx)(tW.A,{children:(0,r.jsx)(tM,{})})]})}),(0,r.jsx)(f.av,{value:"sponsorship",children:(0,r.jsxs)("div",{className:"space-y-6",children:[(0,r.jsx)(tW.A,{children:(0,r.jsx)(s3,{})}),(0,r.jsx)(tW.A,{children:(0,r.jsx)(s8,{})}),(0,r.jsx)(tW.A,{children:(0,r.jsx)(sV,{})})]})}),(0,r.jsx)(f.av,{value:"logs",children:(0,r.jsx)(tW.A,{children:(0,r.jsx)(eT,{})})}),(0,r.jsx)(f.av,{value:"database",children:(0,r.jsx)(tW.A,{children:(0,r.jsx)(eX,{})})}),(0,r.jsx)(f.av,{value:"insurance-products",children:(0,r.jsx)(tW.A,{children:(0,r.jsx)(sz,{})})}),(0,r.jsx)(f.av,{value:"changelog",children:(0,r.jsx)(tW.A,{children:(0,r.jsx)(ty,{})})}),(0,r.jsx)(f.av,{value:"help-center",children:(0,r.jsx)(tW.A,{children:(0,r.jsx)(sL,{})})}),(0,r.jsx)(f.av,{value:"testimonials",children:(0,r.jsx)(tW.A,{children:(0,r.jsx)(tE,{})})}),(0,r.jsx)(f.av,{value:"test",children:(0,r.jsx)(tW.A,{children:(0,r.jsx)(tJ,{})})}),(0,r.jsx)(f.av,{value:"credit-card-requests",children:(0,r.jsxs)("div",{className:"space-y-6",children:[(0,r.jsx)(tW.A,{children:(0,r.jsx)(st,{})}),(0,r.jsx)(tW.A,{children:(0,r.jsx)(tG,{})})]})}),(0,r.jsx)(f.av,{value:"sound-test",children:(0,r.jsx)(tW.A,{children:(0,r.jsx)(t_,{})})})]})})})},function(e){let{user:t,loading:s}=(0,m.A)(),{isAdmin:l,isLoading:n}=(0,v.q)(),c=(0,d.useRouter)();return((0,i.useEffect)(()=>{s||t||c.push("/auth")},[s,t,c]),(0,i.useEffect)(()=>{n||!t||l||c.push("/dashboard")},[n,l,t,c]),s||n)?(0,r.jsx)($.default,{fullScreen:!0}):t&&l?(0,r.jsx)(a,{...e}):null})},97769:(e,t,s)=>{s.d(t,{Qp:()=>c,tW:()=>b,MJ:()=>u});var a=s(15418),r=s(3198);let i=[...r.tC,...r.pe].map(e=>e.value),l=a.Yj().refine(e=>i.includes(e),{message:`insurerCode å¿
é çºä¸åä¹ä¸ï¼${i.join(", ")}`}),n=a.k5(["life","property","medical"],{message:"category å¿
é çº lifeãproperty æ medical"}),d=a.k5(["listed","unlisted"],{message:"reviewStatus å¿
é çº listedï¼ä¸æ¶ï¼æ unlistedï¼ä¸æ¶ï¼"}),c=a.Ik({name:a.Yj().min(1,"é
ç®å稱ä¸è½çºç©º"),description:a.Yj().optional(),amount:a.Yj().optional(),amountByPlan:a.g1(a.Yj().min(1,"è¨å代碼ä¸å¯çºç©º"),a.Yj()).optional(),category:a.Yj().optional()}),o=a.gM("mode",[a.Ik({mode:a.eu("none")}),a.Ik({mode:a.eu("percentOfCoverage"),percent:a.ai().min(0).max(100)}),a.Ik({mode:a.eu("fixedWanPerDay"),wanPerDay:a.ai().nonnegative()}),a.Ik({mode:a.eu("fromBenefitTag"),tag:a.Yj().min(1)})]),u=a.Ik({dailyFromActualExpense:o.optional(),hospitalMedicalAndSurgerySharedLimit:a.zM().optional(),surgerySplit:a.Ik({outpatientShareOfSurgeryTarget:a.ai().min(0).max(1).optional()}).optional()}),m=a.Ik({plan:a.Yj().optional(),gender:a.k5(["male","female"]).optional(),term:a.Yj().optional(),age:a.ai().int().min(0),premium:a.ai().nonnegative()}),h=a.Ik({occupationClass:a.Yj().min(1),premium:a.ai().nonnegative()}),x=a.Ik({label:a.Yj().optional(),description:a.Yj().optional(),amount:a.Yj().optional()}),p=a.Ik({title:a.Yj(),items:a.YO(x),supplement:a.Yj().optional()}),j=a.Ik({sections:a.YO(p)}),g=a.Ik({title:a.Yj().optional(),content:a.Yj()}),f=a.Ik({blocks:a.YO(g)}),v=a.Ik({confidence:a.ai().min(0).max(1).optional(),sourcePage:a.ai().int().positive().optional(),sourceSnippet:a.Yj().max(500).optional(),sourceFileId:a.Yj().optional(),extractedAt:a.KC([a.p6(),a.Yj()]).optional(),model:a.Yj().optional()}),y=a.Ik({verifiedBy:a.Yj().min(1),verifiedAt:a.KC([a.p6(),a.Yj()]),valueHash:a.Yj().optional()}),b=a.Ik({insurerCode:l,category:n,productType:a.Yj().min(1,"éªç¨®ä¸è½çºç©º"),productName:a.Yj().min(1,"ååå稱ä¸è½çºç©º"),productC
5ode:a.Yj().optional(),premiumCurrency:a.k5(["twd","usd","jpy","eur"]).optional(),premiumRateType:a.k5(["èªç¶è²»ç","å¹³æºè²»ç"]).optional(),ageRange:a.Yj().optional(),coveragePeriod:a.Yj().optional(),productRole:a.Yj().optional(),minInsuredAmountWan:a.ai().nonnegative().optional(),maxInsuredAmountWan:a.ai().nonnegative().optional(),termOption:a.Yj().optional(),termOptions:a.YO(a.Yj()).optional(),referencePremium:a.ai().nonnegative("åèä¿è²»ä¸è½çºè² æ¸").optional(),rateTable:a.YO(m).optional(),rateTablePremiumBasis:a.k5(["perWan","perThousand","full"]).optional(),accidentRateTable:a.YO(h).optional(),planAmounts:a.g1(a.Yj(),a.ai().nonnegative()).optional(),benefitItems:a.YO(c).optional(),medicalGapRules:u.optional(),coverageSummary:a.vk(function(e){if(null!=e){if("string"==typeof e){let t=e.trim();if(!t)return;return{sections:[{title:"ä¿éæè¦",items:[{description:t}]}]}}if("object"==typeof e&&Array.isArray(e.sections))return e}},j.optional()),termsSummary:a.vk(function(e){if(null!=e){if("string"==typeof e){let t=e.trim();if(!t)return;return{blocks:[{content:t}]}}if("object"==typeof e&&Array.isArray(e.blocks))return e}},f.optional()),underwritingRules:a.Yj().optional(),isDiscontinued:a.zM().optional(),effectiveDate:a.KC([a.Yj(),a.p6()]).optional(),salesPeriodStart:a.KC([a.Yj(),a.p6()]).optional(),salesPeriodEnd:a.KC([a.Yj(),a.p6()]).optional().nullable(),normalizedProductName:a.Yj().optional(),normalizedEffectiveDate:a.Yj().optional(),updatedAt:a.KC([a.p6(),a.Yj()]),sourceUrl:a.Yj().url().optional().or(a.eu("")),reviewStatus:d.optional(),sourceFileName:a.Yj().optional(),sourceStoragePath:a.Yj().optional(),createdBy:a.Yj().optional(),updatedBy:a.Yj().optional(),createdAt:a.KC([a.p6(),a.Yj()]).optional(),ingestStatus:a.k5(["ok","running","error"]).optional(),lastIngestAt:a.KC([a.p6(),a.Yj()]).optional(),needsReview:a.zM().optional(),ingestError:a.Yj().optional(),extractionProvenance:a.g1(a.Yj().min(1),v).optional(),fieldVerifications:a.g1(a.Yj().min(1),y).optional(),supersedesProductId:a.Yj().optional(),supersededByProductId:a.Yj().optional()});b.required({updatedAt:!0}),b.required({updatedAt:!0,effectiveDate:!0});let w=a.k5(["rate","terms","general"]);a.Ik({fileName:a.Yj().min(1),storagePath:a.Yj().min(1),type:w,partialAmendmentOrder:a.ai().int().nonnegative().optional(),uploadedAt:a.KC([a.p6(),a.Yj()]).optional()});let N=a.k5(["manual-edit","ingest","import","batch-set-listed","verify-field"]);a.Ik({changedBy:a.Yj().min(1),changedAt:a.KC([a.p6(),a.Yj()]),source:N,diff:a.g1(a.Yj().min(1),a.Ik({before:a.L5().optional(),after:a.L5().optional()})),note:a.Yj().optional()});let k=a.k5(["pending","running","done","error","skipped"]),C=a.Ik({productId:a.Yj().min(1),status:k,startedAt:a.KC([a.p6(),a.Yj()]).optional(),finishedAt:a.KC([a.p6(),a.Yj()]).optional(),notes:a.YO(a.Yj()).optional(),error:a.Yj().optional(),needsReview:a.zM().optional()}),A=a.k5(["queued","running","done","error","cancelled"]);a.Ik({status:A,progress:a.Ik({total:a.ai().int().nonnegative(),processed:a.ai().int().nonnegative(),succeeded:a.ai().int().nonnegative(),failed:a.ai().int().nonnegative(),needsReview:a.ai().int().nonnegative()}),items:a.YO(C),createdBy:a.Yj().min(1),createdAt:a.KC([a.p6(),a.Yj()]),updatedAt:a.KC([a.p6(),a.Yj()]),cancelRequested:a.zM().optional()})}}]);
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.