PageSourceSearch

https://nekowa.com/assets/index-Ci3s9Vyp.js

js nekowa.com collected 2026-09-24 14:48:35 UTC 278,205 bytes, 35 lines download raw bytes

1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/quotation-YPonZd3R.js","assets/utils-DRBGurlB.js","assets/react-DBTFCQ9V.js","assets/AdminDashboard-B67y0Pqp.js","assets/firebase-DUmv6NEE.js","assets/QuotationTemplateManager-BJYo1naX.js","assets/CreditTransactionsPage-asDA6-_A.js","assets/RemunerationMaster-DriJz1tb.js","assets/EmptyState-DnRCpYKD.js","assets/FileSaver.min-4ypyifxH.js","assets/CountUp-lmPQUSKx.js","assets/TableSkeleton-Dv2e2avs.js","assets/QuotationMaster-BHc-4KOb.js","assets/QuotationClients-DlGN4FCn.js","assets/QuotationTemplateSettings-D0ONyExy.js","assets/PersonalAccountSettings-6XwlL9gM.js","assets/AccountSettings-DRRYg87y.js","assets/HealthRecords-Dg2OI53m.js","assets/DataSettings-Cyif8SBv.js","assets/Dashboard-BcSgB8A9.js","assets/UserManagement-BEz4gokO.js","assets/KolTracking-DFmMxzxi.js","assets/AgentRevenue-Bkhd16e9.js","assets/ExecutorSettlement-sOCkRSH1.js","assets/ProjectSettings-S2YhI8dU.js","assets/ProjectMgmtExecutors-DHSXoq2I.js","assets/ProjectMgmtProfitSharing-B4cNS1WQ.js","assets/projectMgmtCase-DikpW2vl.js","assets/ProjectMgmtRevenue-sYH4WRym.js","assets/ProjectMgmtPerformance-D0Y-hw8B.js","assets/index-8JwjhRSi.js","assets/PersonnelManagement-BHXDPOTw.js","assets/LandingPage-OoxLD_Gw.js","assets/PrivacyPolicy-BnKKRFJg.js","assets/CalendarSettings-B4hk6B0-.js","assets/CalendarProjectDetail-DwsnHZDE.js","assets/LaborReceiptListPage-I_Vj8XLS.js","assets/laborReceiptPdfImages-Bxhep7k9.js","assets/CreditBalanceBadge-CF_QKFBD.js","assets/CreditConfirmDialogs-BtQyoS6P.js","assets/laborReceiptStatus-CnZhXQse.js","assets/format-CdRYU-v6.js","assets/LaborReceiptFormPage-DnKcZxQw.js","assets/BankAccountInput-ByPw2qVp.js","assets/ImagePreview-CTY-7vV4.js","assets/LaborReceiptDetailPage-DLFwFB-m.js","assets/incomeTypes-rSvOMh9w.js","assets/LaborReceiptSettingsPage-CRaHW1ZF.js","assets/SigningPage-BUEJopPq.js","assets/UserDashboardPage-kGos5Vbe.js","assets/SignedDocumentsListPage-Dbz0wFKe.js","assets/SignedDocumentDetailPage-DCo6MqRS.js","assets/CompanyCreditTransactionsPage-DFd-Juw2.js","assets/CompanyBillingPage-BZrb3oSV.js","assets/InvitePage-cMi2Q1lP.js","assets/RegisterCompanyPage-ZYbvwoUS.js"])))=>i.map(i=>d[i]);
2import{r as i,R as Dt,u as Qt,a as Ye,L as Es,O as Ea,b as ga,c as Nr,N as Pt,d as _s,e as q,f as As,B as Is}from"./react-DBTFCQ9V.js";import{g as Ps,i as Ts,a as Ds,p as zs,b as Ls,c as Rs,d as Os,e as Ms,f as $s,q as X,o as ge,h as se,j as Y,k as We,w as we,l as Re,u as de,T as V,m as te,n as ve,r as ke,s as Nt,t as Xe,v as Jt,x as _a,y as Sr,z as Fs,A as Bs,B as Ze,C as Us,D as va,E as qs,F as kr,G as fa,H as Ws,I as Aa,J as zt,K as Hs,R as Vs,L as ma,M as Gs,N as Cr}from"./firebase-DUmv6NEE.js";import{P as Ks,C as Qe,a as Ne,b as ct,c as ze,d as Er,e as _r,X as ye,f as Xt,g as Le,S as Ar,L as Ir,h as Pr,F as Be,A as ya,D as Tr,U as Lt,i as Ja,j as Rt,B as Ys,k as Zt,l as Qs,m as Js,n as De,o as Dr,p as Oe,q as be,r as ja,M as Ot,K as Xs,s as Xa,t as Za,E as Zs,u as en,v as st,w as tn,I as an,x as Ue,y as er,z as rn,G as zr,H as sn,J as nn,N as ea,O as ta,T as Mt,Q as Ia,R as qe,V as it,W as Tt,Y as Lr,Z as Rr,_ as on,$ as ln,a0 as cn,a1 as tr,a2 as dn,a3 as un,a4 as xn,a5 as mn,a6 as ar,a7 as pn,a8 as rr,a9 as bn,aa as pa,ab as hn,ac as gn,ad as vn,ae as fn}from"./utils-DRBGurlB.js";(function(){const a=document.createElement("link").relList;if(a&&a.supports&&a.supports("modulepreload"))return;for(const o of document.querySelectorAll('link[rel="modulepreload"]'))s(o);new MutationObserver(o=>{for(const d of o)if(d.type==="childList")for(const c of d.addedNodes)c.tagName==="LINK"&&c.rel==="modulepreload"&&s(c)}).observe(document,{childList:!0,subtree:!0});function r(o){const d={};return o.integrity&&(d.integrity=o.integrity),o.referrerPolicy&&(d.referrerPolicy=o.referrerPolicy),o.crossOrigin==="use-credentials"?d.credentials="include":o.crossOrigin==="anonymous"?d.credentials="omit":d.credentials="same-origin",d}function s(o){if(o.ep)return;o.ep=!0;const d=r(o);fetch(o.href,d)}})();var Or={exports:{}},aa={};/**
3 * @license React
4 * react-jsx-runtime.production.js
5 *
6 * Copyright (c) Meta Platforms, Inc. and affiliates.
7 *
8 * This source code is licensed under the MIT license found in the
9 * LICENSE file in the root directory of this source tree.
10 */var yn=Symbol.for("react.transitional.element"),jn=Symbol.for("react.fragment");function Mr(t,a,r){var s=null;if(r!==void 0&&(s=""+r),a.key!==void 0&&(s=""+a.key),"key"in a){r={};for(var o in a)o!=="key"&&(r[o]=a[o])}else r=a;return a=r.ref,{$$typeof:yn,type:t,key:s,ref:a!==void 0?a:null,props:r}}aa.Fragment=jn;aa.jsx=Mr;aa.jsxs=Mr;Or.exports=aa;var e=Or.exports;const wn="modulepreload",Nn=function(t){return"/"+t},sr={}
10,H=function(a,r,s){let o=Promise.resolve();if(r&&r.length>0){document.getElementsByTagName("link");const c=document.querySelector("meta[property=csp-nonce]"),u=(c==null?void 0:c.nonce)||(c==null?void 0:c.getAttribute("nonce"));o=Promise.allSettled(r.map(f=>{if(f=Nn(f),f in sr)return;sr[f]=!0;const x=f.endsWith(".css"),l=x?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${f}"]${l}`))return;const b=document.createElement("link");if(b.rel=x?"stylesheet":wn,x||(b.as="script"),b.crossOrigin="",b.href=f,u&&b.setAttribute("nonce",u),document.head.appendChild(b),x)return new Promise((y,j)=>{b.addEventListener("load",y),b.addEventListener("error",()=>j(new Error(`Unable to preload CSS for ${f}`)))})}))}function d(c){const u=new Event("vite:preloadError",{cancelable:!0});if(u.payload=c,window.dispatchEvent(u),!u.defaultPrevented)throw c}return o.then(c=>{for(const u of c||[])u.status==="rejected"&&d(u.reason);return a().catch(d)})};function St(t,a){i.useEffect(()=>{if(!t)return;const r=s=>{s.key==="Escape"&&a()};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[t,a])}function Fe(t){return{role:"button",tabIndex:0,onClick:t,onKeyDown:a=>{a.key!=="Enter"&&a.key!==" "&&a.key!=="Spacebar"||(a.preventDefault(),t(a))}}}const jt=256,Sn=200,kn=420,$r="sidebarWidth",$t=t=>Number.isFinite(t)?Math.min(kn,Math.max(Sn,Math.round(t))):jt,Cn=()=>{try{const t=localStorage.getItem($r);return t===null?jt:$t(parseInt(t,10))}catch{return jt}},nr=t=>{try{localStorage.setItem($r,String($t(t)))}catch{}},Bl={name:"",idNumber:"",date:new Date().toISOString().split("T")[0],totalAmount:"",healthTax:null,partTimeTax:null,professionalTax:null,netAmount:0,address:"",regAddress:"",itemCode:"50",note:"",collabNote:"",hasHealthRecord:!1,isAutoCalc:!0,companyName:"拼經紀娛樂工作室"},or={serialNumber:0,status:"negotiating",month:new Date().toISOString().slice(0,7),assignee:"",projectName:"",clientName:"",acBc:"",collaborationItem:"",hasLottery:!1,cueStatus:"",contentStatus:"",productStatus:"",isProductRecycled:!1,amountTotal:0,taxAmount:0,amountGross:0,costExtra:0,remunerationId:null,remunerationSerial:null,invoiceStatus:"pending",invoiceNumber:"",quotationStatus:"pending",isQuotationSigned:!1,invoiceTitle:"",invoiceTaxId:"",paymentStatus:"unpaid",paymentDate:null,bankAccountLast5:"",splitShares:[{id:"default_agency",name:"公司",percentage:20,cost:0,isCoveringCost:!1,isAgent:!0},{id:"default_kol",name:"KOL",percentage:80,cost:0,isCoveringCost:!0,isAgent:!1}],note:""},Ul={quoteDate:new Date().toISOString().slice(0,10),clientName:"",clientContact:"",clientTaxId:"",clientAddress:"",clientEmail:"",clientPhone:"",clientId:"",clientContactId:"",termsOverride:"",projectName:"",contactPerson:"",items:[],subtotal:0,taxMode:"auto",taxAmount:0,totalWithTax:0,note:""},En={name:"",productionContent:"",editor:"",bcStatus:"",bcDeliveryDate:null,payer:"",amount:0,paymentDate:null,note:""},wa={view:!1,create:!1,edit:!1,delete:!1},_n={dashboard:{view:!0,create:!1,edit:!1,delete:!1}},ql={category:"kol",title:"",photoUrl:void 0,name:"",idNumber:"",businessEmail:"",phone:"",registeredAddress:"",contactAddress:"",prReceiver:"",prPhone:"",prAddress:"",prNote:"",otherReceivers:[],bankAccountName:"",bankName:"",bankCode:"",bankBranch:"",bankAccountNumber:"",cloudSpace:{materialPackUrl:"",shotListUrl:"",portraitPhotosUrl:""},shirtSize:void 0,hoodieSize:void 0,mbti:"",cognitiveFunctions:""},Wl={category:"staff",title:"",photoUrl:void 0,position:"",workEmail:"",phone:"",name:"",idNumber:"",registeredAddress:"",contactAddress:"",bankAccountName:"",bankName:"",bankCode:"",bankAccountNumber:"",prReceiver:"",prPhone:"",prAddress:"",prNote:"",mbti:"",cognitiveFunctions:""},Hl=["XS","S","M","L","XL","XXL","XXXL"],Vl=["INTJ","INTP","ENTJ","ENTP","INFJ","INFP","ENFJ","ENFP","ISTJ","ISFJ","ESTJ","ESFJ","ISTP","ISFP","ESTP","ESFP"],ft={kol:{enabled:!0,ytTwitchSync:!0,apifySync:!0},remuneration:{enabled:!0},healthRecords:{enabled:!0},personnel:{enabled:!0},projects:{enabled:!0},calendar:{enabled:!0,googleSync:!0},agentRevenue:{enabled:!0},executorSettlement:{enabled:!0},laborReceipt:{enabled:!0},creditHistory:{enabled:!0},projectManagement:{enabled:!0},quotation:{enabled:!1}},Gl={fields:{identity:{enabled:!0,name:!0,nationality:!0,idNumber:!0,phone:!0,address:!0,regAddress:!0},idPhotos:{enabled:!0,front:!0,back:!0},payment:{enabled:!0,bankName:!0,bankCode:!0,bankBranch:!0,accountNumber:!0,accountName:!0},bankbook:{enabled:!0},confirmation:{enabled:!0,text:"本人確認以上資料正確無誤,同意依此辦理勞務報酬事宜。"},signature:{enabled:!0}},updatedAt:null,updatedBy:""},Kl={status:"draft",fillingMode:"signer_fill",signerEmail:"",signerName:"",signerNationality:"台灣",hasSecondGenHealthInsurance:!1,signerIdNumber:"",signerPhone:"",signerAddress:"",signerRegAddress:"",paymentMethod:"transfer",bankAccountName:"",bankName:"",bankCode:"",bankBranch:"",bankAccountNumber:"",idFrontUrl:"",idBackUrl:"",bankbookUrl:"",serviceDescription:"",servicePeriodStart:new Date().toISOString().split("T")[0],servicePeriodEnd:new Date().toISOString().split("T")[0],incomeType:"50",paymentAmount:0,withholdingTax:0,healthInsurance:0,netAmount:0,paymentDate:"",note:"",signatureUrl:"",signedAt:null,signedByUid:"",auditLog:null,pdfUrl:"",pdfHash:"",emailSentAt:null,emailMessageId:"",signingToken:"",signingTokenHash:"",tokenExpiresAt:null,voidedAt:null,voidedBy:"",voidReason:""},An={apiKey:"AIzaSyBh13BaODwNguSL9ic_uaQMpGfZxKsNIzk",authDomain:"nekowa-e2342.firebaseapp.com",projectId:"nekowa-e2342",storageBucket:"nekowa-e2342.firebasestorage.app",messagingSenderId:"235995517574",appId:"1:235995517574:web:ad276c4234496ec5b5f707",measurementId:"G-Q9KCZNF0RZ"};let $e=null,ot=null,Na=null,wt=null,Sa=null,he=null,Je={type:"company"};const lr=t=>{Je={type:"personal",uid:t},console.log(`📍 Data context: personal (${t})`)},Yl=()=>Je,Fr=()=>{if(Je.type==="personal")return["users",Je.uid];const t=Z();if(!t)throw new Error("Company ID not set");return["companies",t]},je=()=>{try{if($e&&ot)return!0;const a=Ps().find(r=>r.name==="nekowa");a?$e=a:$e=Ts(An,"nekowa");try{ot=Ds($e,{localCache:zs({tabManager:Ls(void 0)})})}catch{ot=Rs($e)}return Na=Os($e),Sa=Ms($e,"asia-east1"),wt=$s($e),console.log("✅ Nekowa Firebase initialized (Firestore persistent cache + Storage)"),!0}catch(t){return console.error("❌ Failed to initialize Nekowa Firebase:",t),!1}},ra=t=>{he=t,Je={type:"company"},console.log(`📍 Current company set to: ${t}`)},Z=()=>
10{if(he)return he;if(typeof window<"u"){const t=localStorage.getItem("savedTaxId");if(t)return he=t,ot||je(),t}return null},ne=()=>(ot||je(),ot),Br=()=>(Na||je(),Na),ie=()=>(wt||je(),wt),ae=()=>(Sa||je(),Sa),In=async()=>{const t=Z();return t?await Wr(t):null};ne();const Ql={get currentUser(){var t;return((t=ie())==null?void 0:t.currentUser)??null},onAuthStateChanged:t=>{var a;return(a=ie())==null?void 0:a.onAuthStateChanged(t)}},Ur=(t,a)=>{const r=a||he;if(!r)throw new Error("Company ID not set. Call setCurrentCompanyId first.");return We(ne(),"companies",r,t)},qr=t=>Ur("users",t),Jl=t=>Ur("labor_receipts",t),Xl=t=>{const a=t||he;if(!a)throw new Error("Company ID not set. Call setCurrentCompanyId first.");return te(ne(),"companies",a,"counters","labor_receipt")},Zl=t=>{const a=t||he;if(!a)throw new Error("Company ID not set. Call setCurrentCompanyId first.");return te(ne(),"companies",a,"settings","labor_receipt_config")},Wr=async t=>{const a=te(ne(),"companies",t),{getDoc:r}=await H(async()=>{const{getDoc:o}=await import("./firebase-DUmv6NEE.js").then(d=>d.S);return{getDoc:o}},[]),s=await r(a);return s.exists()?{id:s.id,...s.data()}:null},Pn=async t=>{var r,s,o,d,c,u,f,x,l,b,y,j,w,v,T,S;const a=t||he;if(!a)return ft;try{const k=await Wr(a);if(!k)return ft;const A=k,D=A.modules||{};if(a===he){const N=A.status||"active";Pa=N==="active"?Tn(A):N}return{kol:{enabled:((r=D.kol)==null?void 0:r.enabled)??!0,ytTwitchSync:((s=D.kol)==null?void 0:s.ytTwitchSync)??A.ytTwitchSyncEnabled??!1,apifySync:((o=D.kol)==null?void 0:o.apifySync)??A.apifyEnabled??!1,kolApiBaseUrl:((d=D.kol)==null?void 0:d.kolApiBaseUrl)??A.kolApiBaseUrl},remuneration:{enabled:((c=D.remuneration)==null?void 0:c.enabled)??!0},healthRecords:{enabled:((u=D.healthRecords)==null?void 0:u.enabled)??!0},personnel:{enabled:((f=D.personnel)==null?void 0:f.enabled)??!0},projects:{enabled:((x=D.projects)==null?void 0:x.enabled)??!0},calendar:{enabled:((l=D.calendar)==null?void 0:l.enabled)??!0,googleSync:((b=D.calendar)==null?void 0:b.googleSync)??A.calendarSyncEnabled??!0},agentRevenue:{enabled:((y=D.agentRevenue)==null?void 0:y.enabled)??!0},executorSettlement:{enabled:((j=D.executorSettlement)==null?void 0:j.enabled)??!0},laborReceipt:{enabled:((w=D.laborReceipt)==null?void 0:w.enabled)??!0},creditHistory:{enabled:((v=D.creditHistory)==null?void 0:v.enabled)??!0},projectManagement:{enabled:((T=D.projectManagement)==null?void 0:T.enabled)??!0},quotation:{enabled:((S=D.quotation)==null?void 0:S.enabled)??!1}}}catch(k){return console.error("[Nekowa] Error getting company modules:",k),ft}};let nt=null,ka=null,Pa=null;const cr=()=>Pa,ir=t=>typeof(t==null?void 0:t.toMillis)=="function"?t.toMillis():t!=null&&t.seconds?t.seconds*1e3:0,Tn=t=>{const a=t==null?void 0:t.billing;if(!a)return"unpaid";const r=Date.now();return ir(a.validUntil)>r||ir(a.trialUntil)>r?"active":"unpaid"},Dn=()=>nt&&ka===he?nt:ft,dr=async()=>he?(nt=await Pn(he),ka=he,nt):(nt=ft,ka=null,Pa=null,nt),zn=["dashboard","remuneration","health_records","settings","kol_tracking","agent_revenue","executor_settlement","users","project_settings","personnel","calendar","labor_receipt","credit_history","project_mgmt_executors","project_mgmt_profit","project_mgmt_revenue","project_mgmt_performance","quotation"],Ln=async t=>{var u,f;if(!he)return console.error("[Nekowa] Company ID not set"),null;const{getDoc:a,setDoc:r,updateDoc:s}=await H(async()=>{const{getDoc:x,setDoc:l,updateDoc:b}=await import("./firebase-DUmv6NEE.js").then(y=>y.S);return{getDoc:x,setDoc:l,updateDoc:b}},[]),o=qr(),d=te(o,t.uid);let c;try{c=await a(d)}catch(x){return console.error("[Nekowa] Error fetching user doc:",x),null}if(c.exists()){const x=c.data(),l=x.permissions||{},b={lastLogin:V.now(),email:t.email},y={...l},j=x.role==="admin";zn.forEach(w=>{y[w]||(y[w]=j?{view:!0,create:!0,edit:!0,delete:!0}:wa)});try{return await s(d,b),{...x,...b,permissions:y,id:t.uid}}catch(w){return console.error("[Nekowa] Error updating user doc:",w),{...x,permissions:y,id:t.uid}}}else{const x=(u=t.email)==null?void 0:u.split("@")[0],l=t.displayName||((f=t.email)==null?void 0:f.split("@")[0]),b={email:t.email,username:x,displayName:l,lastLogin:V.now(),createdAt:V.now(),role:"user",permissions:_n,companyId:he};try{return await r(d,b),{...b,id:t.uid}}catch(y){return console.error("[Nekowa] Error creating user doc:",y
10),{...b,id:t.uid}}}},Rn=async t=>{if(!he)return null;try{const{getDoc:a}=await H(async()=>{const{getDoc:d}=await import("./firebase-DUmv6NEE.js").then(c=>c.S);return{getDoc:d}},[]),r=qr(),s=te(r,t),o=await a(s);return o.exists()?{...o.data(),id:t}:null}catch(a){return console.error("[Nekowa] Error getting user profile:",a),null}},On=async()=>{if(wt)try{await wt.signOut(),console.log("✅ Nekowa auth signed out")}catch(t){console.warn("Nekowa auth signOut error:",t)}he=null,console.log("🔄 Nekowa Firebase reset")},Ta=()=>ne(),W=t=>{const a=Ta(),[r,s]=Fr();return We(a,r,s,t)},M=(t,a)=>{const r=Ta(),[s,o]=Fr();return te(r,s,o,t,a)},Da=()=>Br(),Hr=t=>{if(Je.type==="personal")return`users/${Je.uid}/${t}`;const a=Z();if(!a)throw new Error("Company ID not set");return`companies/${a}/${t}`},et=()=>ae(),tt=()=>{var t,a;return((a=(t=ie())==null?void 0:t.currentUser)==null?void 0:a.uid)||null},at=()=>Z(),za=async()=>{var r;return((r=(await Y(ae(),"getMyCompanies")({})).data)==null?void 0:r.companies)||[]},ec=async()=>{const r=(await Y(ae(),"getMyUsername")({})).data;return{username:(r==null?void 0:r.username)??null,changeUsed:(r==null?void 0:r.changeUsed)===!0}},tc=async t=>{var s;return(s=(await Y(ae(),"setUsername")({username:t})).data)==null?void 0:s.username},Mn=async(t,a)=>{var r;try{return((r=(await Y(ae(),"lookupEmailByGlobalUsername")({username:t,turnstileToken:a})).data)==null?void 0:r.email)??null}catch(s){if((s==null?void 0:s.code)==="functions/not-found")return null;throw s}},ac=async()=>(await Y(ae(),"passkeyRegisterStart")({})).data,rc=async(t,a)=>{await Y(ae(),"passkeyRegisterFinish")({response:t,deviceName:a})},$n=async()=>(await Y(ae(),"passkeyLoginStart")({})).data,Fn=async(t,a)=>(await Y(ae(),"passkeyLoginFinish")({sessionId:t,response:a})).data.token,sc=async()=>(await Y(ae(),"getMyPasskeys")({})).data.passkeys||[],nc=async t=>{await Y(ae(),"deletePasskey")({credentialId:t})},oc=async(t,a)=>{await Y(ae(),"renamePasskey")({credentialId:t,deviceName:a})},kt="remunerations",Ct="health_records",sa="employees",Bn="users",dt="project_tables",He="projects",na="project_remunerations",oa="project_misc_expenses",la="executor_settlements",ca="personnel",xt="calendar_projects",Et="calendar_sheets",mt="calendar_entries",Un=async()=>{const t=M("system_settings","project_module"),a=await Re(t);return a.exists()?a.data().assignees||[]:[]},lc=async t=>{const a=M("system_settings","project_module");return await Xe(a,{assignees:t},{merge:!0})},cc=async t=>{const a=ie();return Bs(a,t)},ic=async t=>{const a=ae(),r=Y(a,"sendInvitation"),s=t.companyId||Z();if(!s)throw new Error("Company ID missing");return(await r({...t,companyId:s})).data},dc=async(t,a)=>{const r=ae(),s=Y(r,"revokeInvitation"),o=Z();if(!o)throw new Error("Company ID missing");return await s({companyId:o,inviteId:t}),{success:!0}},uc=async(t,a)=>{je();const r=ae();return(await Y(r,"getInvitationInfo")({companyId:t,token:a})).data},xc=async t=>{je();const a=ae();return(await Y(a,"acceptInvitation")(t)).data},mc=async()=>{const t=Z();if(!t)throw new Error("Company ID missing");const a=ne();return(await se(X(We(a,"companies",t,"invitations"),ge("createdAt","desc")))).docs.map(s=>({id:s.id,...s.data()}))},pc=async(t,a)=>{var c;je();const s=(c=ie().currentUser)==null?void 0:c.uid;if(!s)throw new Error("Not authenticated");const o=`users/${s}/company_applications/${a}/${Date.now()}_${t.name}`,d=Jt(Br(),o);return await _a(d,t),o},bc=async t=>{je();const a=ae();return(await Y(a,"registerCompany")(t)).data},qn=async t=>{const a=ae(),r=Y(a,"createCheckoutSession"),s=Z();if(!s)throw new Error("Company ID missing");return(await r({companyId:s})).data},hc=async t=>{const a=ae(),r=Y(a,"createPortalSession"),s=Z();if(!s)throw new Error("Company ID missing");return(await r({companyId:s})).data},gc=async(t,a)=>{const r=ae(),s=Y(r,"manageMySubscription"),o=(a==null?void 0:a.companyId)||Z();if(!o)throw new Error("Company ID missing");return(await s({companyId:o,action:t,seats:a==null?void 0:a.seats})).data},vc=async(t,a)=>{const r=ae(),s=Y(r,"createCreditCheckout"),o=Z();if(!o)throw new Error("Company ID missing");return(await s({companyId:o,pack:t})).data},fc=async(t,a,r,s)=>{const o=ae();return(await Y(o,"adminManageSubscription")({companyId:t,action:a,withRefund:r,chargeId:s})).data},yc=async t=>{const a=ae();return(await Y(a,"deleteCompanyDeep")({companyId:t})).data},jc=async()=>{je();const t=ae();
10return(await Y(t,"getMyUsername")({})).data},wc=async(t,a,r)=>{const s=ae(),o=Y(s,"updateUser"),d=Z();if(!d)throw new Error("Company ID missing");return await o({companyId:d,targetUid:t,data:a}),{success:!0}},Nc=async t=>{const a=ae(),r=Y(a,"deleteUser"),s=Z();if(!s)throw new Error("Company ID missing");return await r({companyId:s,targetUid:t}),{success:!0}},Sc=async(t,a)=>{const r=Da();if(!r)throw new Error("Storage not initialized");const s=Hr(a),o=Jt(r,s),d=await _a(o,t);return await Sr(d.ref)},kc=async t=>{if(!t)return;const a=Da();if(!a)throw new Error("Storage not initialized");try{const r=t.match(/\/o\/(.+?)\?/);if(!r||!r[1]){console.warn("Could not extract storage path from URL:",t);return}const s=decodeURIComponent(r[1]),o=Jt(a,s);await Fs(o)}catch(r){if(r.code==="storage/object-not-found"){console.warn("Image not found in storage, skipping deletion:",t);return}throw r}},Cc=async()=>{const t=X(W(kt),ge("createdAt","desc"));return(await se(t)).docs.map(r=>({...r.data(),id:r.id}))},Ec=async t=>await ke(W(kt),{...t,createdAt:V.now()}),_c=async(t,a)=>await de(M(kt,t),a),Ac=async t=>await ve(M(kt,t)),Ic=async t=>{const a=t.map(r=>ke(W(kt),{...r,createdAt:V.now()}));return Promise.all(a)},Pc=async()=>{const t=X(W(Ct),ge("createdAt","desc"));return(await se(t)).docs.map(r=>({...r.data(),id:r.id}))},Tc=async t=>await ke(W(Ct),{...t,createdAt:V.now()}),Dc=async(t,a)=>await de(M(Ct,t),a),zc=async t=>await ve(M(Ct,t)),Lc=async t=>{const a=t.map(r=>ke(W(Ct),{...r,createdAt:V.now()}));return Promise.all(a)},Rc=async()=>{const t=X(W(sa),ge("createdAt","desc"));return(await se(t)).docs.map(r=>({...r.data(),id:r.id}))},Oc=async t=>await ke(W(sa),{...t,createdAt:V.now()}),Mc=async(t,a)=>await de(M(sa,t),a),$c=async t=>await ve(M(sa,t)),Fc=async()=>{const t=Z();return t?(await se(We(ne(),"companies",t,"kols"))).docs.map(r=>({...r.data(),id:r.id})).sort((r,s)=>(s.createdAt||0)-(r.createdAt||0)):[]},Bc=async t=>{const a=Z();if(!a)throw new Error("No company configured");const r={name:t.name||"",twitchUrl:t.twitchUrl||"",youtubeUrl:t.youtubeUrl||"",instagramUrl:t.instagramUrl||"",facebookUrl:t.facebookUrl||"",twitchSubs:Number(t.twitchSubs)||0,twitchAverageViewers:Number(t.twitchAverageViewers)||0,twitchPeakViewers:Number(t.twitchPeakViewers)||0,twitchHoursStreamed:Number(t.twitchHoursStreamed)||0,twitchHoursWatched:Number(t.twitchHoursWatched)||0,twitchFollowersGained:Number(t.twitchFollowersGained)||0,youtubeSubs:Number(t.youtubeSubs)||0,youtubeViews:Number(t.youtubeViews)||0,youtubeVideos:Number(t.youtubeVideos)||0,facebookFollowers:Number(t.facebookF
10ollowers)||0,instagramFollowers:Number(t.instagramFollowers)||0,isFbSyncEnabled:t.isFbSyncEnabled!==void 0?t.isFbSyncEnabled:!0,isIgSyncEnabled:t.isIgSyncEnabled!==void 0?t.isIgSyncEnabled:!0,lastUpdated:t.lastUpdated||null,createdAt:Date.now()};return(await ke(We(ne(),"companies",a,"kols"),r)).id},Uc=async(t,a)=>{const r=Z();if(!r)throw new Error("No company configured");const s=JSON.parse(JSON.stringify(a));await de(te(ne(),"companies",r,"kols",t),s)},qc=async t=>(await se(We(ne(),"companies",t,"kols"))).docs.map(r=>({...r.data(),id:r.id})),Wc=async(t,a,r)=>{const s=JSON.parse(JSON.stringify(r));await de(te(ne(),"companies",t,"kols",a),s)},Hc=async t=>{const a=Z();if(!a)throw new Error("No company configured");await ve(te(ne(),"companies",a,"kols",t))},ur={autoUpdate:!1,twitchEnabled:!1,youtubeEnabled:!1,apifyEnabled:!1,syncIntervalHours:6},Vc=async t=>{const a=t||Z();if(!a)return console.warn("No company ID for getWorkerKolSettings"),ur;try{const r=await Re(te(ne(),"companies",a,"workerSettings","kol"));if(r.exists()){const s=r.data();return{autoUpdate:s.autoUpdate??!1,twitchEnabled:s.twitchEnabled??!1,youtubeEnabled:s.youtubeEnabled??!1,apifyEnabled:s.apifyEnabled??!1,syncIntervalHours:s.syncIntervalHours??6,lastSyncedAt:s.lastSyncedAt}}return ur}catch(r){throw console.error("Failed to update worker kol settings:",r),r}},Gc=async t=>{var o;const a=t||Z();if(!a)throw new Error("No company ID");const r=await((o=ie().currentUser)==null?void 0:o.getIdToken());if(!r)throw new Error("User not authenticated");const s=await fetch(`https://nekowa-worker.linty1997.workers.dev/api/v1/kol/sync/${a}`,{method:"POST",headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json","X-Company-ID":a}});if(!s.ok){const d=await s.json().catch(()=>({error:"Unknown error"}));throw new Error(d.error||"Sync failed")}return await s.json()},Kc=async(t,a)=>{const r=a||Z();if(!r)throw new Error("No company ID for updateWorkerKolSettings");const s={};Object.keys(t).forEach(o=>{const d=t[o];d!==void 0&&(s[o]=d)}),Object.keys(s).length>0&&await Xe(te(ne(),"companies",r,"workerSettings","kol"),s,{merge:!0})},Yc=async t=>{const a=t||Z();if(!a)throw new Error("No company ID");await de(te(ne(),"companies",a,"workerSettings","kol"),{lastSyncedAt:va()})},Wn=async(t=!1)=>{try{let a=X(W(dt),ge("createdAt","desc"));return t||(a=X(W(dt),we("isArchived","==",!1),ge("createdAt","desc"))),(await se(a)).docs.map(s=>({...s.data(),id:s.id}))}catch(a){if(a.code==="permission-denied")return[];throw a}},Hn=t=>{const a=X(W(dt),ge("createdAt","desc"));return kr(a,r=>{const s=r.docs.map(o=>({...o.data(),id:o.id}));t(s)},r=>{t([])})},Qc=async t=>await ke(W(dt),{...t,isArchived:!1,createdAt:V.now()}),Jc=async(t,a)=>await de(M(dt,t),a),Xc=async t=>await ve(M(dt,t)),xr=async t=>{try{const a=X(W(He),we("tableId","==",t));return(await se(a)).docs.map(s=>({...s.data(),id:s.id}))}catch(a){if(a.code==="permission-denied")return[];throw a}},Vr=async t=>{const a=X(W(He),we("remunerationId","==",t));return(await se(a)).docs.map(s=>({...s.data(),id:s.id}))},Vn=async t=>await ke(W(He),{...t,createdAt:V.now()}),yt=async(t,a)=>await de(M(He,t),a),Gn=async t=>await ve(M(He,t)),La=async t=>{const a=X(W(na),we("tableId","==",t));return(await se(a)).docs.map(s=>({...s.data(),id:s.id}))},Ft=async t=>await ke(W(na),{...t,createdAt:V.now()}),Bt=async(t,a)=>await de(M(na,t),a),Gr=async t=>await ve(M(na,t)),Kn=async t=>{try{const a=X(W(oa),we("tableId","==",t));return(await se(a)).docs.map(s=>({...s.data(),id:s.id}))}catch(a){if(a.code==="permission-denied")return[];throw a}},Yn=async t=>await ke(W(oa),{...t,createdAt:V.now(),updatedAt:V.now()}),Qn=async(t,a)=>await de(M(oa,t),{...a,updatedAt:V.now()}),Jn=async t=>await ve(M(oa,t)),Zc=async(t={})=>{const a=W(la);let r;if(t.executorName)r=X(a,we("executorName","==",t.executorName));else if(t.scope&&t.scope.length>0){if(t.scope.length>30)throw new Error(`executorScope 超過 Firestore in 上限(30 個):${t.scope.length}`);r=X(a,we("executorName","in",t.scope))}else r=X(a);return(await se(r)).docs.map(o=>({...o.data(),id:o.id}))},ei=async(t,a)=>await de(M(la,t),a),Kr=()=>{const t=new Date;return String(t.getFullYear()).slice(2)+String(t.getMonth()+1).padStart(2,"0")+String(t.getDate()).padStart(2,"0")},Yr=(t,a)=>{const s=((t==null?void 0:t.date)===a&&(t==null?void 0:t.count)||0)+1;return{serialNumber:`${a}${String(s).padStart(3,"0")}`,nextCount:s}},ti=async(t,a)=>{const r=Z();if(!r)throw new Error("未設定公司 ID");const s=Array.from(new Set(t.map(l=>l.projectId)));if(s.length===0)throw new Error("沒有要結算的項目");if(s.length>200)throw new Error("一次最多結算 200 個商案,請分批操作");const o=ne(),d=te(o,"companies",r,"counters","executor_settlements"),c=We(o,"companies",r,la),u=te(c),f=Kr();return await Nt(o,async l=>{const b=await l.get(d),y=s.map(k=>te(o,"companies",r,He,k)),j=await Promise.all(y.map(k=>l.get(k))),w=new Map;t.forEach(k=>{w.has(k.projectId)||w.set(k.projectId,new Set),w.get(k.projectId).add(k.shareId)});for(let k=0;k<j.length;k++){const A=j[k],D=s[k];if(!A.exists())throw new Error(`商案已不存在 (id: ${D}),請重新整理頁面`);const N=A.data(),R=N.splitShares||[],I=w.get(D);for(const m of I){const _=R.find(L=>L.id===m);if(!_)throw new Error(`商案 #${N.serialNumber} 的分潤項目已不存在,請重新整理頁面`);if(_.settledId)throw new Error(`商案 #${N.serialNumber} 的「${_.name}」已被結算單 #${_.settledSerial} 鎖定,請重新整理頁面`)}}const v=b.exists()?b.data():null,{serialNumber:T,nextCount:S}=Yr(v,f);
10l.set(u,{...a,serialNumber:T,createdAt:V.now()});for(let k=0;k<j.length;k++){const A=j[k],D=s[k],R=A.data().splitShares||[],I=w.get(D),m=R.map(_=>I.has(_.id)?{..._,settledId:u.id,settledSerial:T}:_);l.update(y[k],{splitShares:m})}return l.set(d,{date:f,count:S,lastUpdated:qs()}),{id:u.id,serialNumber:T}})},ai=async(t,a,r=[])=>{if(!Z())throw new Error("未設定公司 ID");if(!t)throw new Error("userId 不可為空");if(a.length===0&&r.length===0)return{added:0,removed:0,touchedProjects:0};const o=new Set(a),d=new Set(r),c=await se(W(He)),u=[];let f=0,x=0;c.forEach(l=>{const y=l.data().splitShares||[];let j=!1;const w=y.map(v=>{let T=Array.isArray(v.executorUserIds)?v.executorUserIds:typeof v.executorUserId=="string"?[v.executorUserId]:[],S=!1;if(o.has(v.name)&&!T.includes(t)&&(T=[...T,t],f++,S=!0),d.has(v.name)&&T.includes(t)&&(T=T.filter(A=>A!==t),x++,S=!0),!S)return v;j=!0;const k={...v,executorUserIds:T};return"executorUserId"in k&&delete k.executorUserId,k});j&&u.push({ref:l.ref,splitShares:w})});for(let l=0;l<u.length;l+=450){const b=Ze(ne());u.slice(l,l+450).forEach(y=>b.update(y.ref,{splitShares:y.splitShares})),await b.commit()}return{added:f,removed:x,touchedProjects:u.length}},ri=async t=>{const a=Z();if(!a)throw new Error("未設定公司 ID");const r=ne(),s=te(r,"companies",a,la,t);await Nt(r,async o=>{const d=await o.get(s);if(!d.exists())throw new Error("結算單已不存在(可能已被刪除)");const u=d.data().sourceShares||[],f=Array.from(new Set(u.map(y=>y.projectId))),x=f.map(y=>te(r,"companies",a,He,y)),l=await Promise.all(x.map(y=>o.get(y))),b=new Map;u.forEach(y=>{b.has(y.projectId)||b.set(y.projectId,new Set),b.get(y.projectId).add(y.shareId)});for(let y=0;y<l.length;y++){const j=l[y];if(!j.exists())continue;const w=f[y],T=j.data().splitShares||[],S=b.get(w),k=T.map(A=>S.has(A.id)&&A.settledId===t?{...A,settledId:null,settledSerial:null}:A);o.update(x[y],{splitShares:k})}o.delete(s)})},Xn=async()=>{const t=X(W(Bn),ge("role"));return(await se(t)).docs.map(r=>({...r.data(),id:r.id}))},si=async()=>{const t=X(W(ca),ge("createdAt","desc"));return(await se(t)).docs.map(r=>({...r.data(),id:r.id}))},Ut=t=>{if(t==null)return null;if(Array.isArray(t))return t.map(a=>Ut(a)).filter(a=>a!=null);if(typeof t=="object"){const a={};return Object.keys(t).forEach(r=>{const s=Ut(t[r]);s!=null&&(a[r]=s)}),a}return t},ni=async t=>{const a=Ut({...t,createdAt:V.now(),updatedAt:V.now()});return await ke(W(ca),a)},oi=async(t,a)=>{const r=Ut({...a,updatedAt:V.now()});return await de(M(ca,t),r)},li=async t=>await ve(M(ca,t)),ia="project_mgmt_executors",ut="project_mgmt_cases",Se="project_mgmt_revenues",ci=async()=>{const t=X(W(ia),ge("createdAt","asc"));return(await se(t)).docs.map(r=>({...r.data(),id:r.id}))},ii=async(t,a,r)=>{const s=M(ia,t);if((await Re(s)).exists())throw new Error("此帳號已在執行人員名冊中");const d={uid:t,nickname:a.trim(),active:!0,createdAt:V.now(),updatedAt:V.now(),createdBy:r};return await Xe(s,d),d},di=async(t,a)=>await de(M(ia,t),{...a,updatedAt:V.now()}),ui=async(t,a)=>{const r=Z();if(!r)throw new Error("Company ID missing");return(await Y(ae(),"renameProjectMgmtExecutor")({companyId:r,uid:t,nickname:a})).data},xi=async t=>await ve(M(ia,t)),mi=async t=>{const a=X(W(Se),we("uid","==",t),Us(1));return!(await se(a)).empty},pi=async()=>{const t=X(W(ut),ge("date","desc"));return(await se(t)).docs.map(r=>({...r.data(),id:r.id}))},Ra=async t=>{const a=X(W(Se),we("caseId","==",t));return(await se(a)).docs.map(s=>({...s.data(),id:s.id}))},bi=async(t={})=>{const a=W(Se),r=t.uid?X(a,we("uid","==",t.uid)):X(a);return(await se(r)).docs.map(o=>({...o.data(),id:o.id}))},hi=async()=>{var r;const{getDoc:t}=await H(async()=>{const{getDoc:s}=await import("./firebase-DUmv6NEE.js").then(o=>o.S);return{getDoc:s}},[]),a=await t(M("project_mgmt_config","main"));return a.exists()?((r=a.data())==null?void 0:r.companyTitles)||[]:[]},gi=async t=>{const{setDoc:a}=await H(async()=>{const{setDoc:r}=await import("./firebase-DUmv6NEE.js").then(s=>s.S);return{setDoc:r}},[]);await a(M("project_mgmt_config","main"),{companyTitles:t,updatedAt:V.now()},{merge:!0})},vi=async(t,a,r)=>{const s=Ze(ne()),o=V.now(),d=r?M(ut,r):te(W(ut)),c=Array.from(new Set(a.map(w=>w.uid))),u={...t,participantUids:c,updatedAt:o};r?s.update(d,u):s.set(d,{...u,createdAt:o});const f=r?await Ra(r):[],x=new Set(a.filter(w=>w.id).map(w=>w.id)),l=f.filter(w=>!x.has(w.id)),b=l.filter(w=>w.settledId);if(b.length>0)throw new Error(`「${b[0].nickname}」的明細已結算(#${b[0].settledSerial}),不可移除。請先刪除對應結算單解鎖。`);l.forEach(w=>s.delete(M(Se,w.id)));const y={caseId:d.id,caseName:t.name,caseDate:t.date,remittanceStatus:t.remittanceStatus},j=new Set(f.filter(w=>w.settledId).map(w=>w.id));return a.forEach(w=>{const{id:v,...T}=w;v&&j.has(v)?s.update(M(Se,v),{receiptUrl:T.receiptUrl,...y,updatedAt:o}):v?s.update(M(Se,v),{...T,...y,updatedAt:o}):s.set(te(W(Se)),{...T,...y,createdAt:o,updatedAt:o})}),await s.commit(),d.id},fi=async t=>{const a=Z();if(!a)throw new Error("Company ID missing");return(await Y(ae(),"aiParseProfitCases",{timeout:3e5})({companyId:a,pastedText:t})).data},yi=async t=>{const r=t.reduce((c,u)=>c+1+u.revenues.length,0);if(r>450)throw new Error(`一次匯入的資料量過大(${r} 個寫入操作,上限 450),請分批匯入`);const s=Ze(ne()),o=V.now(),d=[];for(const{caseData:c,revenues:u}of t){const f=te(W(ut)),x=Array.from(new Set(u.map(b=>b.uid)));s.set(f,{...c,participantUids:x,createdAt:o,updatedAt:o});const l={caseId:f.id,caseName:c.name,caseDate:c.date,remittanceStatus:c.remittanceStatus};for(const b of u)s.set(te(W(Se)),{...b,...l,createdAt:o,updatedAt:o});d.push(f.id)}return await s.commit(),d},ji=async(t,a,r)=>{const s=await Ra(t),o=Ze(ne()),d=V.now();o.update(M(ut,t),{remittanceStatus:a,remittanceDate:r,updatedAt:d}
10),s.forEach(c=>o.update(M(Se,c.id),{remittanceStatus:a,updatedAt:d})),await o.commit()},wi=async t=>{const a=await Ra(t),r=a.filter(o=>o.settledId);if(r.length>0)throw new Error(`此案件有 ${r.length} 筆已結算的明細(如 #${r[0].settledSerial}),不可刪除。請先刪除對應結算單解鎖。`);const s=Ze(ne());s.delete(M(ut,t)),a.forEach(o=>s.delete(M(Se,o.id))),await s.commit()},da="project_mgmt_settlements",Ni=async(t={})=>{const a=W(da),r=t.uid?X(a,we("uid","==",t.uid)):X(a);return(await se(r)).docs.map(o=>({...o.data(),id:o.id}))},Si=async(t={})=>{const a=Z();if(!a)throw new Error("Company ID missing");return(await Y(ae(),"getProjectMgmtPerformanceStats")({companyId:a,...t})).data},ki=async(t,a)=>await de(M(da,t),a),Ci=async(t,a)=>{if(t.length===0)throw new Error("未選取任何明細");if(t.length>200)throw new Error("單次結算最多 200 筆明細");const r=ne(),s=Z();if(!s)throw new Error("Company ID not set");const o=te(r,"companies",s,"counters","project_mgmt_settlements"),d=te(W(da));return await Nt(r,async c=>{const u=await c.get(o),f=await Promise.all(t.map(w=>c.get(M(Se,w))));let x=null;f.forEach((w,v)=>{if(!w.exists())throw new Error(`明細已不存在(${t[v]}),請重新整理後再試`);const T=w.data();if(T.settledId)throw new Error(`「${T.caseName}」的明細已被結算(#${T.settledSerial}),請重新整理後再試`);const S=T.currency||"TWD";if(x===null)x=S;else if(x!==S)throw new Error(`不可混合幣別結算:「${T.caseName}」為 ${S},其他明細為 ${x}。請分開結算`)});const l=Kr(),b=u.exists()?u.data():{},{serialNumber:y,nextCount:j}=Yr(b,l);return c.set(d,{...a,currency:x||"TWD",serialNumber:y,createdAt:V.now()}),t.forEach(w=>{c.update(M(Se,w),{settledId:d.id,settledSerial:y,updatedAt:V.now()})}),c.set(o,{date:l,count:j}),{settlementId:d.id,serialNumber:y}})},Ei=async t=>{const a=ne(),r=M(da,t);await Nt(a,async s=>{const o=await s.get(r);if(!o.exists())throw new Error("結算單已不存在");const c=(o.data().sourceRevenues||[]).map(f=>f.revenueId);(await Promise.all(c.map(f=>s.get(M(Se,f))))).forEach((f,x)=>{if(!f.exists())return;f.data().settledId===t&&s.update(M(Se,c[x]),{settledId:va(),settledSerial:va(),updatedAt:V.now()})}),s.delete(r)})},_i=async(t,a)=>{const r=Da();if(!r)throw new Error("Storage not initialized");const o=`${Date.now()}_${t.name}`,d=Hr(`personnel_photos/${a}/${o}`),c=Jt(r,d),u=await _a(c,t);return await Sr(u.ref)},_e=()=>Ta(),Ai=async()=>{_e();const t=X(W(xt),ge("createdAt","desc"));return(await se(t)).docs.map(r=>({...r.data(),id:r.id}))},Ii=async t=>{_e();const a=M(xt,t),r=await Re(a);return r.exists()?{...r.data(),id:t}:null},Pi=async t=>{_e();const a=Object.fromEntries(Object.entries(t).filter(([r,s])=>s!==void 0));return await ke(W(xt),{...a,createdAt:V.now(),updatedAt:V.now()})},Ti=async(t,a)=>await de(M(xt,t),{...a,updatedAt:V.now()}),Di=async t=>{const a=_e(),r=X(W(Et),we("projectId","==",t)),s=await se(r);for(const d of s.docs){const c=X(W(mt),we("sheetId","==",d.id)),u=await se(c),f=Ze(a);u.docs.forEach(x=>{f.delete(x.ref)}),u.docs.length>0&&await f.commit(),await ve(d.ref)}const o=M(xt,t);return await ve(o)},zi=async t=>{_e();const a=X(W(Et),we("projectId","==",t),ge("sortOrder","asc"));return(await se(a)).docs.map(s=>({...s.data(),id:s.id}))},Li=async t=>(_e(),await ke(W(Et),{...t,createdAt:V.now()})),Ri=async(t,a)=>{_e();const r=M(Et,t);return await de(r,a)},Oi=async(t,a=!1,r=!0)=>{const s=_e();if(a){const d=await Zn(t);if(r)try{const u=d.filter(f=>f.googleEventId).map(f=>eo(f.id,"delete").catch(x=>console.warn(`Failed to sync delete entry ${f.id}:`,x)));await Promise.all(u)}
10catch(u){console.error("Error syncing deletions:",u)}const c=Ze(s);d.forEach(u=>{c.delete(M(mt,u.id))}),await c.commit()}const o=M(Et,t);return await ve(o)},Zn=async t=>{_e();const a=X(W(mt),we("sheetId","==",t));return(await se(a)).docs.map(o=>({...o.data(),id:o.id})).sort((o,d)=>{var f,x,l,b,y,j;const c=((x=(f=o.createdAt)==null?void 0:f.toMillis)==null?void 0:x.call(f))||((l=o.createdAt)==null?void 0:l.seconds)*1e3||0,u=((y=(b=d.createdAt)==null?void 0:b.toMillis)==null?void 0:y.call(b))||((j=d.createdAt)==null?void 0:j.seconds)*1e3||0;return c-u})},Mi=async t=>(_e(),await ke(W(mt),{...t,createdAt:V.now(),updatedAt:V.now()})),$i=async(t,a)=>{_e();const r=M(mt,t);return await de(r,{...a,updatedAt:V.now()})},Fi=async t=>{_e();const a=M(mt,t);return await ve(a)},eo=async(t,a="update")=>{const r=at();if(!r)return console.warn("No company set, cannot sync"),{synced:!1,reason:"No company configured"};const s=tt();if(!s)return console.warn("No user logged in, cannot sync"),{synced:!1,reason:"User not logged in"};const o=et(),d=Y(o,"syncCalendarEntry");try{return(await d({taxId:r,entryId:t,action:a,userId:s})).data}catch(c){return console.error("Sync calendar entry error:",c),{synced:!1,reason:c.message}}},to=t=>{_e();const a=X(W(xt),ge("createdAt","desc"));return kr(a,r=>{const s=r.docs.map(o=>({...o.data(),id:o.id}));t(s)},r=>{t([])})},Bi=async()=>{const t=et(),a=Y(t,"getGoogleAuthUrl"),r=at();if(!r)throw new Error("No company selected");const s=tt();if(!s)throw new Error("User not logged in");const o=typeof window<"u"?window.location.origin:"https://nekowa.com";return(await a({taxId:r,userId:s,origin:o})).data},Ui=async()=>{const t=et(),a=Y(t,"checkGoogleAuthStatus"),r=at();if(!r)return{authorized:!1};const s=tt();if(!s)return{authorized:!1};try{return(await a({taxId:r,userId:s})).data}catch(o){return console.error("Error checking Google auth status:",o),{authorized:!1,error:!0}}},qi=async()=>{const t=et(),a=Y(t,"deleteGoogleOAuthTokens"),r=at();if(!r)return{success:!1,error:"No company selected"};const s=tt();if(!s)return{success:!1,error:"User not logged in"};try{return(await a({taxId:r,userId:s})).data}catch(o){return console.error("Error deleting Google OAuth tokens:",o),{success:!1,error:o.message}}},Wi=async(t,a,r)=>{const s=at();if(!s)return{success:!1,error:"No company selected"};const o=tt();if(!o)return{success:!1,error:"User not logged in"};const d=et(),c=Y(d,"createGoogleCalendar");try{return(await c({taxId:s,calendarName:t,description:a,userId:o,timeZone:r})).data}catch(u){return console.error("Create Google Calendar error:",u),{success:!1,error:u.message}}},Hi=async(t,a)=>{const r=at();if(!r)return{success:!1,error:"No company selected"};const s=tt();if(!s)return{success:!1,error:"User not logged in"};const o=et(),d=Y(o,"updateCalendarColor");try{return(await d({taxId:r,userId:s,calendarId:t,backgroundColor:a})).data}catch(c){return console.error("Update calendar color error:",c),{success:!1,error:c.message}}},Vi=async t=>{const a=at();if(!a)return{success:!1,error:"No company selected"};const r=tt();if(!r)return{success:!1,error:"User not logged in"};if(t==="primary"||t.endsWith("@gmail.com")||t.endsWith("@googlemail.com"))return{success:!1,error:"Cannot delete primary calendar"};const s=et(),o=Y(s,"deleteGoogleCalendar");try{return(await o({taxId:a,userId:r,calendarId:t})).data}catch(d){return console.error("Delete Google Calendar error:",d),{success:!1,error:d.message}}},ua="quotations",Qr="quotation_templates",Jr="quotation_config",Gi=async()=>{const t=X(W(ua),ge("quoteDate","desc"));return(await se(t)).docs.map(r=>({...r.data(),id:r.id}))},Ki=async t=>{const{computeNextMonthlySerial:a}=await H(async()=>{const{computeNextMonthlySerial:c}=await import("./quotation-YPonZd3R.js");return{computeNextMonthlySerial:c}},__vite__mapDeps([0,1,2])),r=ne(),s=M("counters","quotation"),o=te(W(ua)),d=new Date().toISOString().slice(0,7).replace("-","");return await Nt(r,async c=>{const u=await c.get(s),f=u.exists()?u.data():{},{serial:x,nextCount:l}=a(f,d),b=V.now();return c.set(o,{...t,serial:x,createdAt:b,updatedAt:b}),c.set(s,{month:d,count:l}),{id:o.id,serial:x}})},Yi=async(t,a)=>{await de(M(ua,t),{...a,updatedAt:V.now()})},Qi=async t=>{await ve(M(ua,t))},Ji=async()=>{const t=await Re(M(Jr,"main")),a=t.exists()?t.data().activeTemplateId:null;if(!a)return null;const r=await Re(M(Qr,a));return r.exists()?{...r.data(),id:r.id}:null},qt=t=>We(ne(),"companies",t,Qr),Wt=t=>te(ne(),"companies",t,Jr,"main"),Xi=async t=>{const[a,r]=await Promise.all([se(X(qt(t),ge("createdAt","desc"))),Re(Wt(t))]);return{templates:a.docs.map(s=>({...s.data(),id:s.id})),activeTemplateId:r.exists()?r.data().activeTemplateId??null:null}},Zi=async(t,a,r)=>{const s=V.now();if(r)return await de(te(qt(t),r),{...a,updatedAt:s}),r;const o=te(qt(t));return await Xe(o,{...a,createdAt:s,updatedAt:s}),o.id},ed=async(t,a)=>{const r=await Re(Wt(t)),s=r.exists()?r.data().activeTemplateId:null;await ve(te(qt(t),a)),s===a&&await Xe(Wt(t),{activeTemplateId:null,updatedAt:V.now()},{merge:!0})},td=async(t,a)=>{await Xe(Wt(t),{activeTemplateId:a,updatedAt:V.now()},{merge:!0})},Ht="quotation_clients",ad=async()=>{const t=X(W(Ht),ge("name"));return(await se(t)).docs.map(r=>({...r.data(),id:r.id}))},rd=async(t,a)=>{const r=V.now();if(a)return await de(M(Ht,a),{...t,updatedAt:r}),a;const s=te(W(Ht));return await Xe(s,{...t,createdAt:r,updatedAt:r}),s.id},sd=async t=>{await ve(M(Ht,t))},Xr="-apple-system, BlinkMacSystemFont, 'Inter', 'PingFang TC', 'Microsoft JhengHei', 'Noto Sans TC', sans-serif",ao=Xr,bt={default:{id:"default",name:"鋼藍",nameEn:"Steel",icon:"◈",colors:{bgPage:"#0E1012",bgCard:"#171A1D",bgCardAlt:"#1F2327",border:"#31363b",borderHover:"#3f454b",textPrimary:"#E8EBEE",textSecondary:"#a1a4a7",textMuted:"#8e9193",textFaint:"#7d8286",accent:"#7FB3DA",accentHover:"#9AC6E6",accentCta:"#E0B072",success:"#4FC08D",warning:"#E8A85C",error:"#E8807A",buttonText:"#08151E",buttonTextAlt:"#E8EBEE",idPurple:"#c084fc",idOrange:"#fb923c",idPink:"#f472b6",idCyan:"#5FC4D8",idIndigo:"#818cf8"}}
10,"pure-black":{id:"pure-black",name:"曜金暗色",nameEn:"Onyx Gold",icon:"◆",colors:{bgPage:"#08080A",bgCard:"#131316",bgCardAlt:"#1C1C20",border:"#363434",borderHover:"#494644",textPrimary:"#F4F2EF",textSecondary:"#a8a6a5",textMuted:"#8c8c8c",textFaint:"#7e7d80",accent:"#D9AF64",accentHover:"#E7C282",accentCta:"#C8964B",success:"#56C08C",warning:"#E8935A",error:"#E58079",buttonText:"#171104",buttonTextAlt:"#F4F2EF",idPurple:"#c084fc",idOrange:"#fb923c",idPink:"#f472b6",idCyan:"#63BFCE",idIndigo:"#818cf8"}},"midnight-finance":{id:"midnight-finance",name:"玫瑰金夜色",nameEn:"Rose Gold Night",icon:"🌸",colors:{bgPage:"#120C0F",bgCard:"#1C1418",bgCardAlt:"#251A20",border:"#44343a",borderHover:"#5b454c",textPrimary:"#F7EDF1",textSecondary:"#ada3a7",textMuted:"#948c8f",textFaint:"#877c82",accent:"#F08CBC",accentHover:"#F7A9CE",accentCta:"#E3B36A",success:"#58C08F",warning:"#E8A25E",error:"#D2685E",buttonText:"#1B0A12",buttonTextAlt:"#F7EDF1",idPurple:"#c084fc",idOrange:"#fb923c",idPink:"#f472b6",idCyan:"#62BFD1",idIndigo:"#818cf8"}},"warm-espresso":{id:"warm-espresso",name:"暖調咖啡",nameEn:"Warm Espresso",icon:"☕",colors:{bgPage:"#14110F",bgCard:"#1E1A17",bgCardAlt:"#27221E",border:"#433b36",borderHover:"#564e46",textPrimary:"#F5F0EB",textSecondary:"#aca7a3",textMuted:"#94918d",textFaint:"#87827c",accent:"#E8945A",accentHover:"#F0AC7C",accentCta:"#E0B96B",success:"#5CBE8B",warning:"#E3BC66",error:"#E07A72",buttonText:"#1A0E06",buttonTextAlt:"#F5F0EB",idPurple:"#c084fc",idOrange:"#fb923c",idPink:"#f472b6",idCyan:"#63BACD",idIndigo:"#818cf8"}},"soft-cream":{id:"soft-cream",name:"夢幻櫻花",nameEn:"Sakura Dream",icon:"💕",colors:{bgPage:"#FBF3F5",bgCard:"#FFFFFF",bgCardAlt:"#F7EAEE",border:"#e5d8dc",borderHover:"#d8c4cb",textPrimary:"#2E1620",textSecondary:"#5C4951",textMuted:"#73656b",textFaint:"#817379",accent:"#C2185B",accentHover:"#A5124D",accentCta:"#B45309",success:"#1E7A45",warning:"#A85B00",error:"#C0342B",buttonText:"#FFFFFF",buttonTextAlt:"#2E1620",idPurple:"#9333ea",idOrange:"#c2410c",idPink:"#db2777",idCyan:"#0E6E80",idIndigo:"#4f46e5"}}},mr="default",pr="nekowa-theme";function Zr(){const[t,a]=i.useState(()=>typeof window<"u"&&localStorage.getItem(pr)||mr),r=i.useCallback(o=>{var f,x;const d=bt[o];if(!d){console.warn(`Theme "${o}" not found, falling back to default`);return}const c=document.documentElement,u=d.colors;c.style.setProperty("--bg-page",u.bgPage),c.style.setProperty("--bg-card",u.bgCard),c.style.setProperty("--bg-card-alt",u.bgCardAlt),c.style.setProperty("--border",u.border),c.style.setProperty("--border-hover",u.borderHover),c.style.setProperty("--text-primary",u.textPrimary),c.style.setProperty("--text-secondary",u.textSecondary),c.style.setProperty("--text-muted",u.textMuted),c.style.setProperty("--text-faint",u.textFaint),c.style.setProperty("--accent",u.accent),c.style.setProperty("--accent-hover",u.accentHover),c.style.setProperty("--accent-cta",u.accentCta),c.style.setProperty("--success",u.success),c.style.setProperty("--warning",u.warning),c.style.setProperty("--error",u.error),c.style.setProperty("--button-text",u.buttonText),c.style.setProperty("--button-text-alt",u.buttonTextAlt),c.style.setProperty("--id-purple",u.idPurple),c.style.setProperty("--id-orange",u.idOrange),c.style.setProperty("--id-pink",u.idPink),c.style.setProperty("--id-cyan",u.idCyan),c.style.setProperty("--id-indigo",u.idIndigo),c.style.setProperty("--font-sans",((f=d.fonts)==null?void 0:f.sans)||Xr),c.style.setProperty("--font-display",((x=d.fonts)==null?void 0:x.display)||ao),document.body.style.backgroundColor=u.bgPage,document.body.style.color=u.textPrimary},[]);i.useEffect(()=>{r(t)},[t,r]);const s=i.useCallback(o=>{if(!bt[o]){console.warn(`Theme "${o}" not found`);return}localStorage.setItem(pr,o),a(o),r(o)},[r]);return{currentTheme:t,setTheme:s,theme:bt[t],themes:bt,themeList:Object.values(bt)}}const es=({compact:t=!1})=>{const{currentTheme:a,setTheme:r,themeList:s}=Zr(),[o,d]=Dt.useState(!1);return St(o,()=>d(!1)),t?e.jsx("div",{className:"flex items-center gap-1",children:s.map(c=>e.jsx("button",{onClick:()=>
10r(c.id),title:c.name,className:`w-7 h-7 rounded-lg flex items-center justify-center text-sm transition-all duration-200
11              ${a===c.id?"ring-2 ring-[var(--accent)] bg-[var(--bg-card-alt)] scale-110":"hover:bg-[var(--bg-card-alt)] opacity-60 hover:opacity-100"}`,children:c.icon},c.id))}):e.jsxs("div",{className:"relative",children:[e.jsxs("button",{onClick:()=>d(!o),className:"flex items-center gap-2 px-3 py-2 rounded-lg text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-card-alt)] transition-all text-sm font-medium",children:[e.jsx(Ks,{size:16}),e.jsx("span",{className:"hidden sm:inline",children:"主題"})]}),o&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>d(!1)}),e.jsxs("div",{className:"absolute bottom-full left-0 mb-2 w-48 bg-[var(--bg-card)] border border-[var(--border)] rounded-xl shadow-xl z-50 overflow-hidden nk-in-up",children:[e.jsx("div",{className:"p-2 border-b border-[var(--border)]",children:e.jsx("span",{className:"text-12 font-bold text-[var(--text-muted)] uppercase tracking-wider px-2",children:"選擇主題"})}),e.jsx("div",{className:"p-1",children:s.map(c=>e.jsxs("button",{onClick:()=>{r(c.id),d(!1)},className:`w-full flex items-center gap-3 px-3 py-2.5 rounded-lg transition-all duration-150
12                    ${a===c.id?"bg-[var(--accent)]/10 text-[var(--accent)]":"text-[var(--text-secondary)] hover:bg-[var(--bg-card-alt)] hover:text-[var(--text-primary)]"}`,children:[e.jsx("span",{className:"text-lg",children:c.icon}),e.jsx("span",{className:"flex-1 text-left text-sm font-medium",children:c.name}),a===c.id&&e.jsx(Qe,{size:16,className:"text-[var(--accent)]"})]},c.id))})]})]})]})},ts=(t,a)=>{var r,s;return a==="account_settings"||t.role==="admin"?!0:((s=(r=t.permissions)==null?void 0:r[a])==null?void 0:s.view)===!0},ro=[{group:"主要功能",items:[{id:"dashboard",path:"/dashboard",label:"儀表板",icon:e.jsx(Pr,{size:20}),moduleId:"dashboard"}]},{group:"勞報管理",items:[{id:"remuneration",path:"/remuneration",label:"勞報單總表",icon:e.jsx(Be,{size:18}),moduleId:"remuneration"},{id:"labor_receipt",path:"/labor-receipts",label:"勞報單簽收系統",icon:e.jsx(Be,{size:18}),moduleId:"labor_receipt"},{id:"health_records",path:"/health-records",label:"健保紀錄",icon:e.jsx(ya,{size:18}),moduleId:"health_records"},{id:"settings",path:"/settings",label:"資料設定",icon:e.jsx(Tr,{size:18}),moduleId:"settings"}]},{group:"報價管理",items:[{id:"quotation",path:"/quotations",label:"報價單",icon:e.jsx(Be,{size:18}),moduleId:"quotation"},{id:"quotation_clients",path:"/quotation-clients",label:"客戶資料",icon:e.jsx(Lt,{size:18}),moduleId:"quotation"},{id:"quotation_template",path:"/quotation-template-settings",label:"模板設定",icon:e.jsx(Ar,{size:18}),moduleId:"quotation"}]},{group:"數據追蹤",items:[{id:"kol_tracking",path:"/kol-tracking",label:"KOL 頻道數據",icon:e.jsx(Ja,{size:18}),moduleId:"kol_tracking"},{id:"agent_revenue",path:"/agent-revenue",label:"執行經紀收益",icon:e.jsx(Ja,{size:18}),moduleId:"agent_revenue"},{id:"executor_settlement",path:"/executor-settlement",label:"執行經紀結算",icon:e.jsx(Rt,{size:18}),moduleId:"executor_settlement"}]},{group:"專案管理",items:[{id:"project_mgmt_executors",path:"/project-mgmt/executors",label:"執行人員",icon:e.jsx(Lt,{size:18}),moduleId:"project_mgmt_executors"},{id:"project_mgmt_profit",path:"/project-mgmt/profit-sharing",label:"分潤表",icon:e.jsx(Be,{size:18}),moduleId:"project_mgmt_profit"},{id:"project_mgmt_revenue",path:"/project-mgmt/revenue",label:"執行收益",icon:e.jsx(Rt,{size:18}),moduleId:"project_mgmt_revenue"},{id:"project_mgmt_performance",path:"/project-mgmt/performance",label:"績效追蹤",icon:e.jsx(ya,{size:18}),moduleId:"project_mgmt_performance"}]}],so=[{group:"系統管理",items:[{id:"project_settings",path:"/project-settings",label:"商案執行設定",icon:e.jsx(Ys,{size:18}),moduleId:"project_settings"},{id:"calendar_settings",path:"/calendar-settings",label:"日曆排程設定",icon:e.jsx(Zt,{size:18}),moduleId:"calendar"}
12,{id:"personnel",path:"/personnel",label:"人員管理",icon:e.jsx(Lt,{size:18}),moduleId:"personnel"},{id:"users",path:"/users",label:"用戶管理",icon:e.jsx(Lt,{size:20}),moduleId:"users"},{id:"credit_history",path:"/credit-transactions",label:"點數明細",icon:e.jsx(Qs,{size:18}),moduleId:"credit_history"},{id:"company_billing",path:"/billing",label:"方案與點數",icon:e.jsx(Xt,{size:18}),moduleId:"company_billing"}]},{group:"個人中心",items:[{id:"account_settings",path:"/account",label:"帳號設置",icon:e.jsx(ct,{size:20}),moduleId:"account_settings"}]}],no=({onLogout:t,user:a,onClose:r,isCollapsed:s=!1,onToggleCollapse:o})=>{var me;const d=Qt(),c=Ye(),[u,f]=i.useState([]),[x,l]=i.useState([]),[b,y]=i.useState({"KOL 商案執行":!0,日曆排程:!0,主要功能:!0,勞報管理:!0,報價管理:!0,數據追蹤:!0,專案管理:!0,系統管理:!0,個人中心:!0}),[j,w]=i.useState(!1);i.useEffect(()=>{const C=()=>{w(window.innerWidth<1024)};return C(),window.addEventListener("resize",C),()=>window.removeEventListener("resize",C)},[]);const v=j?!1:s,[T,S]=i.useState(()=>Cn()),[k,A]=i.useState(!1),D=C=>{C.preventDefault(),C.target.setPointerCapture(C.pointerId),A(!0)},N=C=>{k&&S($t(C.clientX))},R=C=>{k&&(C.target.releasePointerCapture(C.pointerId),A(!1),nr($t(C.clientX)))},I=()=>{S(jt),nr(jt)},[m,_]=i.useState(null),[L,$]=i.useState([]),[B,U]=i.useState(!1);St(B,()=>U(!1));const n=Z();i.useEffect(()=>{In().then(_),za().then($).catch(()=>$([]))},[]);const p=C=>{U(!1),!(!C||C===n)&&(ra(C),localStorage.setItem("savedTaxId",C),window.location.href="/dashboard")};i.useEffect(()=>{const C=Hn(ee=>{const le=[...ee].filter(Ce=>!Ce.isArchived).sort((Ce,fe)=>{const ce=Ce.name.match(/\((\d+)\)/),_t=fe.name.match(/\((\d+)\)/),Ve=ce?parseInt(ce[1],10):1/0,Ge=_t?parseInt(_t[1],10):1/0;return Ve!==Ge?Ve-Ge:Ce.name.localeCompare(fe.name,"zh-Hant")});f(le)});return()=>C()},[]),i.useEffect(()=>{try{const C=to(ee=>{const le=ee.filter(Ce=>!Ce.isArchived);l(le)});return()=>C()}catch{return console.log("Calendar projects subscription skipped - client not initialized"),()=>{}}},[]),i.useEffect(()=>{const C=()=>{const le=window.matchMedia("(min-width: 1024px)").matches?v?72:256:0;document.documentElement.style.setProperty("--sidebar-width",`${le}px`)};return C(),window.addEventListener("resize",C),()=>window.removeEventListener("resize",C)},[v]);const g=C=>{y(ee=>({...ee,[C]:!ee[C]}))},P=C=>ts(a,C),E={kol_tracking:"kol",remuneration:"remuneration",health_records:"healthRecords",settings:"remuneration",personnel:"personnel",project_settings:"projects",calendar_settings:"calendar",calendar:"calendar",agent_revenue:"agentRevenue",executor_settlement:"executorSettlement",labor_receipt:"laborReceipt",quotation:"quotation",quotation_clients:"quotation",quotation_template:"quotation",credit_history:"creditHistory",project_mgmt_executors:"projectManagement",project_mgmt_profit:"projectManagement",project_mgmt_revenue:"projectManagement",project_mgmt_performance:"projectManagement"},z=C=>{if(["dashboard","users","account_settings","personnel","credit_history","company_billing"].includes(C))return!0;const le=E[C];if(!le)return!0;const fe=Dn()[le];return C==="quotation"||C==="quotation_clients"||C==="quotation_template"?(fe==null?void 0:fe.enabled)===!0:(fe==null?void 0:fe.enabled)!==!1},K=C=>C==="/dashboard"?c.pathname==="/dashboard"||c.pathname==="/":c.pathname.startsWith(C),re=C=>e.jsxs("button",{onClick:()=>{d(C.path),r==null||r()},title:v?C.label:void 0,className:`nk-nav nk-press w-full flex items-center gap-3 px-3 py-2.5 rounded-xl transition-all duration-200 group relative
13         ${v?"justify-center":""}
14         ${K(C.path)?"bg-[var(--accent)]/10 text-[var(--accent)] font-bold shadow-inner":"text-[var(--text-secondary)] hover:bg-[var(--bg-card-alt)] hover:text-[var(--text-primary)] font-medium"}
15       `,children:[e.jsx("div",{className:`nk-nav-icon transition-colors flex-shrink-0 ${K(C.path)?"text-[var(--accent)]":"text-[var(--text-muted)] group-hover:text-[var(--text-secondary)]"}`,children:C.icon}),!v&&e.jsx("span",{className:"truncate",children:C.label}),K(C.path)&&!v&&e.jsx("div",{className:"nk-here absolute right-2 w-1.5 h-1.5 rounded-full bg-[var(--accent)]"})]},C.id);return e.jsxs("div",{className:`${v?"w-[72px]":j?"w-64":""} relative h-screen bg-[var(--bg-card)] border-r border-[var(--border)] flex flex-col flex-shrink-0 ${k?"":"transition-all duration-300"}`,style:!v&&!j?{width:T}:void 0,children:[!v&&!j&&e.jsx("div",{onPointerDown:D,onPointerMove:N,onPointerUp:R,onPointerCancel:R,onDoubleClick:I,title:"拖曳調整側欄寬度;雙擊還原預設",className:`absolute top-0 right-0 w-1.5 h-full cursor-col-resize z-20 transition-colors ${k?"bg-[var(--accent)]/50":"hover:bg-[var(--accent)]/30"}`}
15),e.jsxs("div",{className:`relative ${v?"p-3":"p-6"} flex items-center gap-3 border-b border-[var(--border)] transition-all duration-300`,children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-[var(--accent)] flex items-center justify-center font-bold text-[var(--button-text)] flex-shrink-0",children:(m==null?void 0:m.logoText)||((me=m==null?void 0:m.name)==null?void 0:me.charAt(0))||"N"}),!v&&(L.length>=1?e.jsxs("button",{type:"button",onClick:()=>U(C=>!C),className:`flex-1 min-w-0 text-left flex items-center gap-2 rounded-lg px-2 py-1.5 -mx-1 border transition-all group ${B?"bg-[var(--bg-card-alt)] border-[var(--accent)]":"border-transparent hover:bg-[var(--bg-card-alt)] hover:border-[var(--border)]"}`,title:`${(m==null?void 0:m.displayTitle)||(m==null?void 0:m.name)||""}(點擊切換公司 / 個人空間)`,children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h1",{className:"text-base font-bold tracking-wide text-[var(--text-primary)] leading-tight line-clamp-2 break-words",children:(m==null?void 0:m.displayTitle)||(m==null?void 0:m.name)||"Nekowa"}),e.jsx("span",{className:"text-12 text-[var(--accent)] font-bold tracking-wider",children:"切換 ▾"})]}),e.jsx(Ne,{size:18,className:`text-[var(--accent)] flex-shrink-0 transition-transform ${B?"rotate-180":""}`})]}):e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h1",{className:"text-base font-bold tracking-wide text-[var(--text-primary)] leading-tight line-clamp-2 break-words",title:(m==null?void 0:m.displayTitle)||(m==null?void 0:m.name),children:(m==null?void 0:m.displayTitle)||(m==null?void 0:m.name)||"Nekowa"}),e.jsx("span",{className:"text-12 text-[var(--text-muted)] font-mono tracking-widest",children:a.role==="admin"?"ADMIN":"USER"})]})),!v&&B&&L.length>=1&&e.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>U(!1)}),!v&&B&&L.length>=1&&e.jsxs("div",{className:"absolute left-3 right-3 top-full mt-1 z-50 bg-[var(--bg-card)] border border-[var(--border)] rounded-xl shadow-2xl overflow-hidden max-h-80 overflow-y-auto",children:[L.length>1&&e.jsxs("div",{className:"px-4 py-2 text-12 font-bold uppercase tracking-wider text-[var(--text-muted)] border-b border-[var(--border)] bg-[var(--bg-card-alt)]/40",children:["我的公司(",L.length,")"]}),L.map(C=>e.jsxs("button",{type:"button",onClick:()=>p(C.taxId),className:`w-full text-left px-4 py-3 flex items-start justify-between gap-2 border-b border-[var(--border)]/40 hover:bg-[var(--bg-card-alt)] transition-colors ${C.taxId===n?"bg-[var(--bg-card-alt)]":""}`,children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm font-bold text-[var(--text-primary)] break-words leading-snug",children:C.displayTitle}),e.jsxs("div",{className:"text-12 text-[var(--text-muted)] font-mono mt-0.5",children:[C.taxId," · ",C.role==="admin"?"ADMIN":"USER"]})]}),C.taxId===n&&e.jsx(Qe,{size:16,className:"text-[var(--accent)] flex-shrink-0 mt-0.5"})]},C.taxId)),e.jsxs("button",{type:"button",onClick:()=>{U(!1),window.location.href="/user"},className:"w-full text-left px-4 py-3 flex items-center gap-2 hover:bg-[var(--bg-card-alt)] transition-colors",children:[e.jsx(ct,{size:16,className:"text-[var(--text-muted)] flex-shrink-0"}),e.jsx("div",{className:"min-w-0",children:e.jsx("div",{className:"text-sm font-bold text-[var(--text-primary)]",children:"個人空間"})})]}),e.jsxs("button",{type:"button",onClick:()=>{U(!1),window.location.href="/register"},className:"w-full text-left px-4 py-3 flex items-center gap-2 border-t border-[var(--border)]/40 hover:bg-[var(--bg-card-alt)] transition-colors",children:[e.jsx(ze,{size:16,className:"text-[var(--text-muted)] flex-shrink-0"}),e.jsx("div",{className:"text-sm font-bold text-[var(--text-secondary)]",children:"建立公司"})]})]}),o&&e.jsx("button",{onClick:o,className:"hidden lg:flex p-1.5 rounded-lg text-[var(--text-muted)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-card-alt)] transition-colors shrink-0","aria-label":v?"展開選單":"收合選單",title:v?"展開選單":"收合選單",children:v?e.jsx(Er,{size:18}):e.jsx(_r,{size:18})}),r&&e.jsx("button",{onClick:r,className:"lg:hidden p-1.5 rounded-lg text-[var(--text-muted)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-card-alt)] transition-colors shrink-0","aria-label":"關閉選單",children:e.jsx(ye,{size:20})})]}),!v&&(m==null?void 0:m.billing)&&(()=>{const C=ce=>typeof(ce==null?void 0:ce.toMillis)=="function"?ce.toMillis():ce!=null&&ce.seconds?ce.seconds*1e3:0,ee=Date.now(),le=C(m.billing.trialUntil),Ce=C(m.billing.validUntil),fe=le>ee?{text:`試用至 ${new Date(le).toLocaleDateString()}`,cls:"text-blue-400"}:Ce>ee?{text:`方案有效至 ${new Date(Ce).toLocaleDateString()}`,cls:"text-[var(--text-muted)]"}:{text:"訂閱已到期",cls:"text-[var(--error)]"};return e.jsxs("button",{onClick:()=>d("/billing"),className:`w-full px-4 py-1.5 text-13 font-medium text-left border-b border-[var(--border)] hover:bg-[var(--bg-card-alt)] transition-colors flex items-center gap-1.5 ${fe.cls}`,title:"前往方案與點數",children:[e.jsx(Xt,{size:11,className:"shrink-0"}),fe.text]})})(),e.jsxs("nav",{className:`flex-1 overflow-y-auto py-4 ${v?"px-2":"px-3"} space-y-4 custom-scrollbar transition-all duration-300`,children:[ro.map(C=>{const ee=C.items.filter(le=>P(le.moduleId)&&z(le.id));return ee.length===0?null:e.jsxs("div",{children:[v?e.jsx("div",{className:"my-2 border-t border-[var(--border)]"}):e.jsxs("div",{className:"mb-1 px-3 py-1 flex items-center justify-between cursor-pointer group/header",...Fe(()=>g(C.group)),children:[e.jsx("span",{className:"text-12 font-bold text-[var(--text-muted)] uppercase tracking-widest flex items-center gap-2 group-hover/header:text-[var(--text-secondary)] transition-colors",children:C.group}),b[C.group]?e.jsx(Ne,{size:12,className:"text-[var(--text-muted)]"}):e.jsx(Le,{size:12,className:"text-[var(--text-muted)]"})]}),(v||b[C.group])&&e.jsx("div",{className:"space-y-1 nk-in-left",children:ee.map(le=>re(le))})]},C.group)}),u.length>0&&e.jsxs("div",{children:[v?e.jsx("div",{className:"my-2 border-t border-[var(--border)]"}):e.jsxs("div",{className:"mb-1 px-3 py-1 flex items-center justify-between cursor-pointer group/header",...Fe(()=>g("KOL 商案執行")),children:[e.jsx("span",{className:"text-12 font-bold text-[var(--text-muted)] uppercase tracking-widest flex items-center gap-2 group-hover/header:text-[var(--text-secondary)] transition-colors",children:"KOL 商案執行"}),b["KOL 商案執行"]?e.jsx(Ne,{size:12,className:"text-[var(--text-muted)]"}):e.jsx(Le,{size:12,className:"text-[var(--text-muted)]"})]}),(v||b["KOL 商案執行"])&&e.jsx("div",{className:"space-y-1 nk-in-left",children:u.map(C=>P(`project_table_${C.id}`)?re({id:C.id,path:`/projects/${C.id}`,label:C.name,icon:e.jsx(Js,{size:18})}):null)})]}),(()=>{const C=P("calendar")||x.some(ee=>P(`calendar_project_${ee.id}`));return x.length===0||!C?null:e.jsxs("div",{children:[v?e.jsx("div",{className:"my-2 border-t border-[var(--border)]"}):e.jsxs("div",{className:"mb-1 px-3 py-1 flex items-center justify-between cursor-pointer group/header",...Fe(()=>g("日曆排程")),children:[e.jsx("span",{className:"text-12 font-bold text-[var(--text-muted)] uppercase tracking-widest flex items-center gap-2 group-hover/header:text-[var(--text-secondary)] transition-colors",children:"日曆排程"}),b.日曆排程?e.jsx(Ne,{size:12,className:"text-[var(--text-muted)]"}):e.jsx(Le,{size:12,className:"text-[var(--text-muted)]"})]}),(v||b.日曆排程)&&e.jsx("div",{className:"space-y-1 nk-in-left",children:x.map(ee=>!P("calendar")&&!P(`calendar_project_${ee.id}`)?null:re({id:ee.id,path:`/calendar/${ee.id}`,label:ee.name,icon:e.jsx(Zt,{size:18})}))})]})})(),so.map(C=>{const ee=C.items.filter(le=>P(le.moduleId)&&z(le.id));return ee.length===0?null:e.jsxs("div",{children:[v?e.jsx("div",{className:"my-2 border-t border-[var(--border)]"}):e.jsxs("div",{className:"mb-1 px-3 py-1 flex items-center justify-between cursor-pointer group/header",...Fe(()=>g(C.group)),children:[e.jsx("span",{className:"text-12 font-bold text-[var(--text-muted)] uppercase tracking-widest flex items-center gap-2 group-hover/header:text-[var(--text-secondary)] transition-colors",children:C.group}),b[C.group]?e.jsx(Ne,{size:12,className:"text-[var(--text-muted)]"}):e.jsx(Le,{size:12,className:"text-[var(--text-muted)]"})]}),(v||b[C.group])&&e.jsx("div",{className:"space-y-1 nk-in-left",children:ee.map(le=>re(le))})]},C.group)})]}),e.jsxs("div",{className:`${v?"p-2":"p-4"} border-t border-[var(--border)] bg-[var(--bg-card)]/50 transition-all duration-300`,children:[!v&&e.jsxs("div",{className:"mb-3 px-2",children:[e.jsx("div",{className:"text-12 font-bold text-[var(--text-muted)] uppercase tracking-wider mb-2",children:"主題"}),e.jsx(es,{compact:!0})]}),e.jsxs("div",{className:`flex items-center gap-3 mb-4 cursor-pointer hover:bg-[var(--bg-card-alt)] p-2 rounded-lg transition-colors ${v?"justify-center":"px-2"}`,...Fe(()=>d("/account")),title:v?a.displayName||a.email:void 0,children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-[var(--bg-card-alt)] border border-[var(--border)] flex items-center justify-center text-xs font-bold text-[var(--text-secondary)] uppercase flex-shrink-0",children:(a.displayName||a.email).charAt(0)}),!v&&e.jsxs("div",{className:"flex-1 overflow-hidden",children:[e.jsx("div",{className:"text-sm font-bold text-[var(--text-primary)] truncate",children:a.displayName||"未設定"}),e.jsx("div",{className:"text-xs text-[var(--text-muted)] truncate",children:a.email})]}),!v&&e.jsx(Ar,{size:14,className:"text-[var(--text-muted)]"})]}),e.jsxs("button",{onClick:t,title:v?"登出系統":void 0,className:"w-full flex items-center justify-center gap-2 px-4 py-2 text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:bg-[var(--error)]/20 hover:border-[var(--error)]/30 border border-transparent roun
15ded-lg transition-all text-sm font-bold",children:[e.jsx(Ir,{size:16}),!v&&e.jsx("span",{children:"登出系統"})]})]})]})},Oa=({delayMs:t=160})=>e.jsx("div",{className:"flex items-center justify-center py-24",style:{animation:`nk-fallback-in .2s ease-out ${t}ms backwards`},role:"status","aria-label":"載入中",children:e.jsx("div",{className:"w-7 h-7 border-2 border-[var(--border)] border-t-[var(--accent)] rounded-full animate-spin"})}),br="G-Q9KCZNF0RZ";let Vt=!1;function oo(){if(!(Vt||typeof window>"u"))try{window.dataLayer=window.dataLayer||[],window.gtag=function(){window.dataLayer.push(arguments)},window.gtag("js",new Date),window.gtag("config",br,{send_page_view:!1});const t=document.createElement("script");t.async=!0,t.src=`https://www.googletagmanager.com/gtag/js?id=${br}`,document.head.appendChild(t),Vt=!0}catch{}}function lo(t){return t.startsWith("/sign/")?"/sign":t.startsWith("/invite/")?"/invite":t}const co=[["/labor-receipts","勞報單簽收系統"],["/project-settings","商案設定"],["/calendar-settings","日曆設置"],["/project-mgmt/executors","執行人員"],["/project-mgmt/profit-sharing","分潤表"],["/project-mgmt/revenue","執行收益"],["/remuneration","勞報單總表"],["/health-records","健保紀錄"],["/settings","資料設定"],["/kol-tracking","KOL 數據追蹤"],["/agent-revenue","經紀收入"],["/executor-settlement","執行經紀結算"],["/personnel","人事管理"],["/projects/","商案執行"],["/calendar/","日曆排程"],["/billing","方案與點數"],["/account","帳號設置"],["/users","用戶管理"],["/user","個人空間"],["/dashboard","儀表板"],["/login","登入"],["/register","公司註冊"],["/sign","簽署頁"],["/invite","邀請頁"],["/privacy","隱私政策"],["/admin","平台管理"]];function io(t){if(t==="/")return"首頁";for(const[a,r]of co)if(t===a||t.startsWith(a))return r;return t}function uo(t){if(!(!Vt||!window.gtag))try{const a=lo(t);window.gtag("event","page_view",{page_path:a,page_location:`${window.location.origin}${a}`,page_title:io(a)})}catch{}}function lt(t,a){if(!(!Vt||!window.gtag))try{window.gtag("event",t,a||{})}catch{}}function ht(t){const a=new Uint8Array(t);let r="";for(const o of a)r+=String.fromCharCode(o);return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function as(t){const a=t.replace(/-/g,"+").replace(/_/g,"/"),r=(4-a.length%4)%4,s=a.padEnd(a.length+r,"="),o=atob(s),d=new ArrayBuffer(o.length),c=new Uint8Array(d);for(let u=0;u<o.length;u++)c[u]=o.charCodeAt(u);return d}function rs(){return xo.stubThis((globalThis==null?void 0:globalThis.PublicKeyCredential)!==void 0&&typeof globalThis.PublicKeyCredential=="function")}const xo={stubThis:t=>t};function mo(t){const{id:a}=t;return{...t,id:as(a),transports:t.transports}}function po(t){return t==="localhost"||/^((xn--[a-z0-9-]+|[a-z0-9]+(-[a-z0-9]+)*)\.)+([a-z]{2,}|xn--[a-z0-9-]+)$/i.test(t)}class gt extends Error{constructor({message:a,code:r,cause:s,name:o}){super(a,{cause:s}),Object.defineProperty(this,"code",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.name=o??s.name,this.code=r}}class bo{constructor(){Object.defineProperty(this,"controller",{enumerable:!0,configurable:!0,writable:!0,value:void 0})}createNewAbortSignal(){if(this.controller){const r=new Error("Cancelling existing WebAuthn API call for new one");r.name="AbortError",this.controller.abort(r)}const a=new AbortController;return this.controller=a,a.signal}cancelCeremony(){if(this.controller){const a=new Error("Manually cancelling existing WebAuthn API call");a.name="AbortError",this.controller.abort(a),this.controller=void 0}}}const ho=new bo,go=["cross-platform","platform"];function vo(t){if(t&&!(go.indexOf(t)<0))return t}function fo(){if(!rs())return ba.stubThis(new Promise(a=>a(!1)));const t=globalThis.PublicKeyCredential;return(t==null?void 0:t.isConditionalMediationAvailable)===void 0?ba.stubThis(new Promise(a=>a(!1))):ba.stubThis(t.isConditionalMediationAvailable())}const ba={stubThis:t=>t};function yo({error:t,options:a}){const{publicKey:r}=a;if(!r)throw Error("options was missing required publicKey property");if(t.name==="AbortError"){if(a.signal instanceof AbortSignal)return new gt({message:"Authentication ceremony was sent an abort signal",code:"ERROR_CEREMONY_ABORTED",cause:t})}else{if(t.name==="NotAllowedError")return new gt({message:t.message,code:"ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY",cause:t});if(t.name==="SecurityError"){const s=globalThis.location.hostname;if(po(s)){if(r.rpId!==s)return new gt({message:`The RP ID "${r.rpId}
15" is invalid for this domain`,code:"ERROR_INVALID_RP_ID",cause:t})}else return new gt({message:`${globalThis.location.hostname} is an invalid domain`,code:"ERROR_INVALID_DOMAIN",cause:t})}else if(t.name==="UnknownError")return new gt({message:"The authenticator was unable to process the specified options, or could not create a new assertion signature",code:"ERROR_AUTHENTICATOR_GENERAL_ERROR",cause:t})}return t}async function jo(t){var j,w;!t.optionsJSON&&t.challenge&&(console.warn("startAuthentication() was not called correctly. It will try to continue with the provided options, but this call should be refactored to use the expected call structure instead. See https://simplewebauthn.dev/docs/packages/browser#typeerror-cannot-read-properties-of-undefined-reading-challenge for more information."),t={optionsJSON:t});const{optionsJSON:a,useBrowserAutofill:r=!1,verifyBrowserAutofillInput:s=!0}=t;if(!rs())throw new Error("WebAuthn is not supported in this browser");let o;((j=a.allowCredentials)==null?void 0:j.length)!==0&&(o=(w=a.allowCredentials)==null?void 0:w.map(mo));const d={...a,challenge:as(a.challenge),allowCredentials:o},c={};if(r){if(!await fo())throw Error("Browser does not support WebAuthn autofill");if(document.querySelectorAll("input[autocomplete$='webauthn']").length<1&&s)throw Error('No <input> with "webauthn" as the only or last value in its `autocomplete` attribute was detected');c.mediation="conditional",d.allowCredentials=[]}c.publicKey=d,c.signal=ho.createNewAbortSignal();let u;try{u=await navigator.credentials.get(c)}catch(v){throw yo({error:v,options:c})}if(!u)throw new Error("Authentication was not completed");const{id:f,rawId:x,response:l,type:b}=u;let y;return l.userHandle&&(y=ht(l.userHandle)),{id:f,rawId:ht(x),response:{authenticatorData:ht(l.authenticatorData),clientDataJSON:ht(l.clientDataJSON),signature:ht(l.signature),userHandle:y},type:b,clientExtensionResults:u.getClientExtensionResults(),authenticatorAttachment:vo(u.authenticatorAttachment)}}const wo="0x4AAAAAACJBrvZ1fCIzWhYf",No="https://nekowa-worker.linty1997.workers.dev/api/v1/turnstile/verify",So=!1,ko=wo,Co=()=>{const t=i.useId(),[a,r]=i.useState(""),[s,o]=i.useState(""),[d,c]=i.useState(!1),[u,f]=i.useState(!1),[x,l]=i.useState(null),[b,y]=i.useState(null),j=i.useRef(null),w=i.useRef(null),[v,T]=i.useState(!1),[S,k]=i.useState(null),[A,D]=i.useState(null),[N,R]=i.useState(""),[I,m]=i.useState(null),[_,L]=i.useState(!1);i.useEffect(()=>{je();const E=localStorage.getItem("savedUsername");E&&(r(E),c(!0));const z=document.getElementById("turnstile-script");
15if(!window.turnstile&&!z){const K=document.createElement("script");K.id="turnstile-script",K.src="https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit",K.async=!0,K.defer=!0,document.body.appendChild(K)}return()=>{if(window.turnstile&&w.current)try{window.turnstile.remove(w.current)}catch{}}},[]),i.useEffect(()=>{const E=()=>{if(j.current){if(!window.turnstile){setTimeout(E,500);return}if(w.current)try{window.turnstile.remove(w.current)}catch{}try{j.current.innerHTML="";const K=window.turnstile.render(j.current,{sitekey:ko,theme:"dark",action:"login",size:"flexible",appearance:"always",callback:re=>{y(re),l(null)},"expired-callback":()=>y(null),"error-callback":()=>l("驗證元件載入失敗,請重新整理頁面")});w.current=K}catch(K){console.error("Turnstile Render Exception:",K)}}},z=setTimeout(E,500);return()=>clearTimeout(z)},[]);const $=()=>{if(window.turnstile&&w.current)try{window.turnstile.reset(w.current)}catch{}y(null)},B=E=>{ra(E),localStorage.setItem("savedTaxId",E),window.location.href="/dashboard"},U=async()=>{const E=await za();if(!E||E.length===0){localStorage.removeItem("savedTaxId"),window.location.href="/user";return}if(E.length===1){B(E[0].taxId);return}m(E)},n=async E=>{if(E.preventDefault(),!a.trim()||!s){l("請輸入帳號與密碼");return}if(!b){l("請勾選並完成機器人驗證");return}f(!0),l(null);try{const z=a.includes("@");let K=a.trim();if(z){if(!So){const re=await fetch(No,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:b})}),me=await re.json().catch(()=>({success:!1}));if(!re.ok||!me.success)throw new Error("安全驗證失敗,請重新整理頁面再試")}}else{const re=await Mn(a.trim(),b);if(!re)throw{code:"auth/invalid-credential"};K=re}await fa(ie(),K,s),lt("login",{method:"password"}),d?localStorage.setItem("savedUsername",a.trim()):localStorage.removeItem("savedUsername"),await U()}catch(z){z.code==="auth/invalid-credential"||z.code==="auth/user-not-found"||z.code==="auth/wrong-password"?l("帳號或密碼錯誤"):z.code==="auth/too-many-requests"||z.code==="functions/resource-exhausted"?l("嘗試次數過多,請稍後再試"):l(z.message||"登入失敗,請檢查網路連線"),$()}finally{f(!1)}},p=async()=>{var E;T(!0),l(null);try{await Aa(ie(),new zt),lt("login",{method:"google"}),await U()}catch(z){if(z.code==="auth/account-exists-with-different-credential"){const K=zt.credentialFromError(z),re=((E=z.customData)==null?void 0:E.email)||"";k(K),D(re),l(`此 Email(${re})已有密碼登入,請輸入密碼以綁定 Google`)}else z.code==="auth/popup-closed-by-user"?l("登入視窗已關閉,請重試"):z.code==="auth/popup-blocked"?l("登入視窗被封鎖,請允許彈出視窗"):l(z.message||"Google 登入失敗")}finally{T(!1)}},g=async()=>{var E;L(!0),l(null);try{const{options:z,sessionId:K}=await $n(),re=await jo({optionsJSON:z}),me=await Fn(K,re);await Hs(ie(),me),lt("login",{method:"passkey"}),await U()}catch(z){(z==null?void 0:z.name)==="NotAllowedError"||(E=z==null?void 0:z.message)!=null&&E.includes("cancel")?l("已取消 Passkey 登入"):l("Passkey 登入失敗,請改用帳密或 Google")}finally{L(!1)}},P=async()=>{if(!(!A||!S||!N)){T(!0),l(null);try{const E=await fa(ie(),A,N);await Ws(E.user,S),k(null),D(null),R(""),await U()}catch(E){E.code==="auth/invalid-credential"||E.code==="auth/wrong-password"?l("密碼錯誤,請重試"):l(E.message||"綁定失敗")}finally{T(!1)}}};return e.jsxs("div",{className:"min-h-screen flex items-center justify-center bg-[var(--bg-page)] relative overflow-hidden font-display selection:bg-[var(--accent)]/30 text-[var(--text-primary)]",children:[e.jsxs("div",{className:"absolute inset-0 z-0 pointer-events-none",children:[e.jsx("div",{className:"absolute inset-0 bg-[linear-gradient(rgba(255,255,255,0.015)_1px,transparent_1px),linear-gradient(90deg,rgba(255,255,255,0.015)_1px,transparent_1px)] bg-[size:80px_80px] [mask-image:radial-gradient(ellipse_at_center,black,transparent_75%)]"}),e.jsx("div",{className:"absolute top-[-15%] left-[-10%] w-[46%] h-[46%] rounded-full bg-[var(--accent)]/[0.07] blur-[130px]"}
15),e.jsx("div",{className:"absolute bottom-[-15%] right-[-10%] w-[46%] h-[46%] rounded-full bg-[var(--accent-cta)]/[0.05] blur-[130px]"})]}),e.jsxs("div",{className:"z-10 w-full max-w-[420px] px-4",children:[e.jsxs("div",{className:"bg-[var(--bg-card)] border border-white/[0.08] rounded-2xl shadow-2xl shadow-black/60 p-8",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsxs("div",{className:"inline-flex items-center gap-2.5 mb-3",children:[e.jsx("span",{className:"w-2 h-2 rounded-[3px] bg-[var(--accent)]"}),e.jsx("span",{className:"text-[24px] font-semibold tracking-[-0.01em]",children:"Nekowa"})]}),e.jsx("p",{className:"text-[var(--text-muted)] text-14",children:"登入您的帳號"})]}),x&&e.jsxs("div",{className:"mb-6 p-3 rounded-xl bg-red-500/[0.08] border border-red-500/20 flex items-center gap-2 text-red-400 text-14",children:[e.jsx(De,{size:16,className:"flex-shrink-0"}),e.jsx("span",{children:x})]}),e.jsxs("form",{onSubmit:n,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:`${t}-0`,className:"text-xs font-medium text-[var(--text-muted)] tracking-wide ml-1",children:"帳號 / Email"}),e.jsxs("div",{className:"relative group",children:[e.jsx(Dr,{className:"absolute left-4 top-1/2 -translate-y-1/2 text-[var(--text-muted)] group-focus-within:text-[var(--accent)] transition-colors",size:18}),e.jsx("input",{id:`${t}-0`,type:"text",value:a,onChange:E=>r(E.target.value),placeholder:"輸入帳號或 Email",className:"w-full bg-white/[0.03] border border-white/[0.1] text-[var(--text-primary)] rounded-xl py-3 px-4 pl-12 focus:border-[var(--accent)]/60 focus:bg-white/[0.05] outline-none transition-colors placeholder-[var(--text-faint)] text-sm"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:`${t}-1`,className:"text-xs font-medium text-[var(--text-muted)] tracking-wide ml-1",children:"密碼"}),e.jsxs("div",{className:"relative group",children:[e.jsx(Oe,{className:"absolute left-4 top-1/2 -translate-y-1/2 text-[var(--text-muted)] group-focus-within:text-[var(--accent)] transition-colors",size:18}),e.jsx("input",{id:`${t}-1`,type:"password",value:s,onChange:E=>o(E.target.value),placeholder:"••••••••",className:"w-full bg-white/[0.03] border border-white/[0.1] text-[var(--text-primary)] rounded-xl py-3 px-4 pl-12 focus:border-[var(--accent)]/60 focus:bg-white/[0.05] outline-none transition-colors placeholder-[var(--text-faint)] tracking-widest text-sm"})]})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none text-xs text-[var(--text-muted)] ml-1",children:[e.jsx("input",{type:"checkbox",checked:d,onChange:E=>c(E.target.checked),className:"accent-[var(--accent)]"}),"記住帳號"]}),e.jsx("div",{ref:j,className:"flex items-center justify-center w-full my-2 min-h-[70px]"}),e.jsx("button",{type:"submit",disabled:u,className:"w-full flex items-center justify-center gap-2 bg-[var(--accent)] hover:bg-[var(--accent-hover)] disabled:bg-white/[0.06] disabled:text-[var(--text-faint)] text-[var(--bg-page)] font-semibold py-3 px-6 rounded-full transition-colors text-sm",children:u?e.jsx(be,{size:18,className:"animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"登入"}),e.jsx(ja,{size:16})]})})]}),e.jsxs("div",{className:"mt-4",children:[e.jsxs("div",{className:"flex items-center gap-3 my-3",children:[e.jsx("div",{className:"flex-1 h-px bg-white/[0.08]"}),e.jsx("span",{className:"text-xs text-[var(--text-faint)]",children:"或"}),e.jsx("div",{className:"flex-1 h-px bg-white/[0.08]"})]}),A?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("p",{className:"text-xs text-[var(--accent-hover)] ml-1",children:["輸入「",A,"」的密碼以綁定 Google(僅需一次)"]}),e.jsxs("div",{className:"relative group",children:[e.jsx(Oe,{className:"absolute left-4 top-1/2 -translate-y-1/2 text-[var(--text-muted)]",size:18}),e.jsx("input",{"aria-label":"輸入密碼以綁定",type:"password",value:N,onChange:E=>R(E.target.value),placeholder:"輸入密碼以綁定",className:"w-full bg-white/[0.03] border border-white/[0.1] text-[var(--text-primary)] rounded-xl py-3 px-4 pl-12 focus:border-[var(--accent)]/60 outline-none transition-colors placeholder-[var(--text-faint)] tracking-widest text-sm"})]}),e.jsxs("button",{type:"button",onClick:P,disabled:v||!N,className:"w-full flex items-center justify-center gap-2 bg-[var(--accent)] hover:bg-[var(--accent-hover)] disabled:bg-white/[0.06] disabled:text-[var(--text-faint)] text-[var(--bg-page)] font-semibold py-3 px-6 rounded-full transition-colors text-sm",children:[v?e.jsx(be,{size:18,className:"animate-spin"}):e.jsx(Qe,{size:16}),"完成綁定並登入"]}),e.jsx("button",{type:"button",onClick:()=>{D(null),k(null),R(""),l(null)},className:"w-full text-xs text-[var(--text-muted)] hover:text-[var(--text-primary)] transition-colors",children:"取消"})]}):e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs("button",{type:"button",onClick:p,disabled:v,className:"w-full flex items-center justify-center gap-2 bg-[var(--text-primary)] hover:bg-white disabled:opacity-50 text-[var(--bg-page)] font-semibold py-3 px-6 rounded-full transition-colors text-sm",children:[v?e.jsx(be,{size:18,className:"animate-spin"}):e.jsx(Ot,{size:16}),"使用 Google 登入"]}),e.jsxs("button",{type:"button",onClick:g,disabled:_,className:"w-full flex items-center justify-center gap-2 border border-white/[0.14] hover:border-white/30 disabled:opacity-50 text-[var(--text-primary)] font-medium py-3 px-6 rounded-full transition-colors text-sm",children:[_?e.jsx(be,{size:18,className:"animate-spin"}):e.jsx(Xs,{size:16}),"使用 Passkey 登入"]})]})]}),I&&e.jsx("div",{className:"fixed inset-0 z-[60] bg-black/70 backdrop-blur-sm flex items-center justify-center p-4",children:e.jsxs("div",{className:"w-full max-w-sm bg-[var(--bg-card)] border border-white/[0.08] rounded-2xl shadow-2xl overflow-hidden",children:[e.jsxs("div",{className:"px-5 py-4 border-b border-white/[0.06]",children:[e.jsx("h3",{className:"font-semibold",children:"選擇公司"}),e.jsx("p",{className:"text-xs text-[var(--text-muted)] mt-0.5",children:"你的帳號屬於多家公司,請選擇要進入的公司"})]}),e.jsx("div",{className:"max-h-80 overflow-y-auto",children:I.map(E=>e.jsxs("button",{type:"button",onClick:()=>
15B(E.taxId),className:"w-full text-left px-5 py-3 border-b border-white/[0.04] last:border-0 hover:bg-white/[0.04] transition-colors",children:[e.jsx("div",{className:"text-sm font-semibold text-[var(--text-primary)] break-words leading-snug",children:E.displayTitle}),e.jsxs("div",{className:"text-13 text-[var(--text-muted)] tabular-nums mt-0.5",children:[E.taxId," · ",E.role==="admin"?"ADMIN":"USER"]})]},E.taxId))})]})})]}),e.jsxs("div",{className:"mt-8 text-center",children:[e.jsx(Es,{to:"/",className:"text-14 text-[var(--text-muted)] hover:text-[var(--text-primary)] transition-colors",children:"← 返回首頁"}),e.jsx("p",{className:"mt-2 text-13 text-[var(--text-faint)]",children:"© 2025 Nekowa"})]})]})]})},Eo=()=>{const t=i.useId(),a=Qt(),[r,s]=i.useState("email"),[o,d]=i.useState("phone"),[c,u]=i.useState(""),[f,x]=i.useState(""),[l,b]=i.useState(""),[y,j]=i.useState(""),[w,v]=i.useState(!1),[T,S]=i.useState(null),k=i.useRef(null),A=i.useRef(null),[D,N]=i.useState(!1),[R,I]=i.useState(null);i.useEffect(()=>{const p=ie();return k.current&&!A.current&&(A.current=new Vs(p,k.current,{size:"invisible",callback:()=>{console.log("reCAPTCHA verified")},"expired-callback":()=>{console.log("reCAPTCHA expired")}})),()=>{A.current&&(A.current.clear(),A.current=null)}},[]);const m=async p=>{const g=ne();if(!(await Re(te(g,"system_admins",p))).exists())throw new Error("PERMISSION_DENIED");return!0},_=async p=>{if(p.preventDefault(),!l.trim()||!y.trim()){I("請輸入電子郵件和密碼");return}N(!0),I(null);const g=ie();try{const P=await fa(g,l,y);await m(P.user.uid),a("/admin/dashboard")}catch(P){console.error("Email login error:",P),g.currentUser&&await ma(g),P.message==="PERMISSION_DENIED"?I("您沒有管理員權限"):P.code==="auth/user-not-found"?I("找不到此電子郵件的帳號"):P.code==="auth/wrong-password"?I("密碼錯誤"):P.code==="auth/invalid-email"?I("電子郵件格式錯誤"):P.code==="auth/too-many-requests"?I("登入嘗試次數過多,請稍後再試"):P.code==="auth/invalid-credential"?I("電子郵件或密碼錯誤"):I(P.message||"登入失敗")}finally{N(!1)}},L=async()=>{N(!0),I(null);const p=ie();try{const g=new zt,P=await Aa(p,g);await m(P.user.uid),a("/admin/dashboard")}catch(g){console.error("Google login error:",g),p.currentUser&&await ma(p),g.message==="PERMISSION_DENIED"?I("您沒有管理員權限"):g.code==="auth/popup-closed-by-user"?I("登入已取消"):g.code==="auth/popup-blocked"?I("彈出視窗被阻止,請允許彈出視窗"):I(g.message||"Google 登入失敗")}finally{N(!1)}},$=async p=>{if(p.preventDefault(),!c.trim()){I("請輸入手機號碼");return}let g=c.trim();g.startsWith("0")?g="+886"+g.substring(1):g.startsWith("+")||(g="+886"+g),N(!0),I(null);const P=ie();try{if(!A.current)throw new Error("reCAPTCHA 尚未初始化,請重新整理頁面");const E=await Gs(P,g,A.current);S(E),d("verify")}catch(E){console.error("Send SMS error:",E),E.code==="auth/invalid-phone-number"?I("手機號碼格式錯誤"):E.code==="auth/too-many-requests"?I("發送次數過多,請稍後再試"):E.code==="auth/captcha-check-failed"?I("reCAPTCHA 驗證失敗,請重新整理頁面"):I(E.message||"發送驗證碼失敗")}finally{N(!1)}},B=async p=>{if(p.preventDefault(),!f.trim()){I("請輸入驗證碼");return}if(!T){I("驗證狀態已過期,請重新發送驗證碼");return}N(!0),I(null);const g=ie();try{const P=await T.confirm(f);await m(P.user.uid),a("/admin/dashboard")}catch(P){console.error("Verify code error:",P),g.currentUser&&await ma(g),P.message==="PERMISSION_DENIED"?I("您沒有管理員權限"):P.code==="auth/invalid-verification-code"?I("驗證碼錯誤"):P.code==="auth/code-expired"?I("驗證碼已過期,請重新發送"):I(P.message||"驗證失敗")}finally{N(!1)}},U=()=>{d("phone"),x(""),S(null),I(null)},n=p=>{s(p),I(null),d("phone")};return e.jsxs("div",{className:"min-h-screen flex items-center justify-center bg-gray-950 relative overflow-hidden font-sans selection:bg-purple-500/30 text-white",children:[e.jsxs("div",{className:"absolute top-0 left-0 w-full h-full overflow-hidden z-0 pointer-events-none",children:[e.jsx("div",{className:"absolute top-[-20%] left-[-10%] w-[50%] h-[50%] rounded-full bg-purple-600/10 blur-[120px] animate-pulse"}),e.jsx("div",{className:"absolute bottom-[-20%] right-[-10%] w-[50%] h-[50%] rounded-full bg-pink-600/10 blur-[120px] animate-pulse delay-1000"}),e.jsx("div",{className:"absolute top-[40%] left-[40%] w-[30%] h-[30%] rounded-full bg-indigo-600/5 blur-[100px] animate-pulse delay-700"})]}),e.jsx("div",{ref:k,id:"recaptcha-admin-login"}),e.jsxs("div",{className:"z-10 w-full max-w-[420px] p-8 mx-4",children:[e.jsxs("div",{className:"bg-gray-900/40 backdrop-blur-xl border border-white/10 rounded-3xl shadow-2xl p-8 relative overflow-hidden",children:[e.jsx("div",{className:"absolute top-0 left-0 w-full h-1 bg-gradient-to-r from-purple-500 via-pink-500 to-indigo-500"}),e.jsxs("div",{className:"text-center mb-6 mt-2",children:[e.jsx("div",{className:"mx-auto w-16 h-16 rounded-2xl bg-gradient-to-br from-purple-600 to-pink-700 flex items-center justify-center mb-4 shadow-xl shadow-purple-500/20 transform hover:scale-105 transition-transform duration-300",children:e.jsx(Xa,{size:28,className:"text-white"})}),e.jsx("h2",{className:"text-2xl font-bold text-white mb-1 tracking-tight",children:"Nekowa 管理中心"}),e.jsx("p",{className:"text-xs text-gray-500",children:"Unified Management Console"})]}),e.jsxs("div",{className:"flex gap-1 p-1 bg-gray-950/50 rounded-xl mb-6",children:[e.jsxs("button",{onClick:()=>n("email"),className:`flex-1 py-2 px-3 rounded-lg text-xs font-medium transition-all ${r==="email"?"bg-gradient-to-r from-purple-600 to-pink-600 text-white shadow-lg":"text-gray-400 hover:text-white"}`,children:[e.jsx(Ot,{size:14,className:"inline mr-1.5"}),"Email"]}),e.jsxs("button",{onClick:()=>n("phone"),className:`flex-1 py-2 px-3 rounded-lg text-xs font-medium transition-all ${r==="phone"?"bg-gradient-to-r from-purple-600 to-pink-600 text-white shadow-lg":"text-gray-400 hover:text-white"}`,children:[e.jsx(Za,{size:14,className:"inline mr-1.5"}),"SMS"]}),e.jsx("button",{onClick:()=>n("google"),className:`flex-1 py-2 px-3 rounded-lg text-xs font-medium transition-all ${r==="google"?"bg-gradient-to-r from-purple-600 to-pink-600 text-white shadow-lg":"text-gray-400 hover:text-white"}`,children:"Google"})]}),R&&e.jsxs("div",{className:"mb-6 p-3 rounded-xl bg-red-500/10 border border-red-500/20 flex items-center gap-2 text-red-400 text-sm nk-in-down",children:[e.jsx(De,{size:16,className:"flex-shrink-0"}),e.jsx("span",{children:R})]}),r==="email"&&e.jsxs("form",{onSubmit:_,className:"space-y-4 mb-6",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:`${t}-0`,className:"text-xs font-bold text-gray-400 uppercase tracking-wider ml-1",children:"電子郵件"}),e.jsxs("div",{className:"relative group",children:[e.jsx(Ot,{className:"absolute left-4 top-1/2 -translate-y-1/2 text-gray-500 group-focus-within:text-purple-400 transition-colors",size:18}),e.jsx("input",{id:`${t}
15-0`,type:"email",value:l,onChange:p=>b(p.target.value),placeholder:"[email protected]",className:"w-full bg-gray-950/50 border border-gray-700/50 text-white rounded-xl py-3 px-4 pl-12 focus:border-purple-500 focus:bg-gray-900 focus:ring-1 focus:ring-purple-500 outline-none transition-all placeholder-gray-600 text-sm"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:`${t}-1`,className:"text-xs font-bold text-gray-400 uppercase tracking-wider ml-1",children:"密碼"}),e.jsxs("div",{className:"relative group",children:[e.jsx(Oe,{className:"absolute left-4 top-1/2 -translate-y-1/2 text-gray-500 group-focus-within:text-purple-400 transition-colors",size:18}),e.jsx("input",{id:`${t}-1`,type:w?"text":"password",value:y,onChange:p=>j(p.target.value),placeholder:"••••••••",className:"w-full bg-gray-950/50 border border-gray-700/50 text-white rounded-xl py-3 px-4 pl-12 pr-12 focus:border-purple-500 focus:bg-gray-900 focus:ring-1 focus:ring-purple-500 outline-none transition-all placeholder-gray-600 text-sm"}),e.jsx("button",{type:"button",onClick:()=>v(!w),className:"absolute right-4 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-300 transition-colors",children:w?e.jsx(Zs,{size:18}):e.jsx(en,{size:18})})]})]}),e.jsx("button",{type:"submit",disabled:D,className:"w-full flex items-center justify-center gap-2 bg-gradient-to-r from-purple-600 to-pink-600 hover:from-purple-500 hover:to-pink-500 disabled:from-gray-800 disabled:to-gray-800 disabled:text-gray-500 disabled:cursor-not-allowed text-white font-bold py-3 px-6 rounded-xl transition-all duration-300 shadow-lg shadow-purple-900/30 hover:shadow-purple-500/40 hover:-translate-y-0.5 active:translate-y-0 text-sm",children:D?e.jsx(be,{size:18,className:"animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"登入"}),e.jsx(ja,{size:16})]})})]}),r==="google"&&e.jsxs("div",{className:"mb-6",children:[e.jsx("button",{onClick:L,disabled:D,className:"w-full flex items-center justify-center gap-3 bg-white hover:bg-gray-100 disabled:bg-gray-700 disabled:text-gray-500 disabled:cursor-not-allowed text-gray-900 font-bold py-3 px-6 rounded-xl transition-all duration-300 shadow-lg hover:shadow-xl hover:-translate-y-0.5 active:translate-y-0 text-sm",children:D?e.jsx(be,{size:18,className:"animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",children:[e.jsx("path",{fill:"#4285F4",d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"}),e.jsx("path",{fill:"#34A853",d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"}),e.jsx("path",{fill:"#FBBC05",d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"}),e.jsx("path",{fill:"#EA4335",d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"})]}),e.jsx("span",{children:"使用 Google 帳號登入"})]})}),e.jsx("p",{className:"text-center text-xs text-gray-500 mt-4",children:"點擊後將開啟 Google 登入視窗"})]}),r==="phone"&&o==="phone"&&e.jsxs("form",{onSubmit:$,className:"space-y-4 mb-6",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:`${t}-2`,className:"text-xs font-bold text-gray-400 uppercase tracking-wider ml-1",children:"手機號碼"}),e.jsxs("div",{className:"relative group",children:[e.jsx(Za,{className:"absolute left-4 top-1/2 -translate-y-1/2 text-gray-500 group-focus-within:text-purple-400 transition-colors",size:18}),e.jsx("input",{id:`${t}-2`,type:"tel",value:c,onChange:p=>u(p.target.value),placeholder:"0912345678",className:"w-full bg-gray-950/50 border border-gray-700/50 text-white rounded-xl py-3 px-4 pl-12 focus:border-purple-500 focus:bg-gray-900 focus:ring-1 focus:ring-purple-500 outline-none transition-all placeholder-gray-600 text-sm tracking-widest font-mono"})]}),e.jsx("p",{className:"text-12 text-gray-500 ml-1",children:"將會發送驗證碼簡訊至此號碼"})]}),e.jsx("button",{type:"submit",disabled:D,className:"w-full flex items-center justify-center gap-2 bg-gradient-to-r from-purple-600 to-pink-600 hover:from-purple-500 hover:to-pink-500 disabled:from-gray-800 disabled:to-gray-800 disabled:text-gray-500 disabled:cursor-not-allowed text-white font-bold py-3 px-6 rounded-xl transition-all duration-300 shadow-lg shadow-purple-900/30 hover:shadow-
15purple-500/40 hover:-translate-y-0.5 active:translate-y-0 text-sm",children:D?e.jsx(be,{size:18,className:"animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"發送驗證碼"}),e.jsx(ja,{size:16})]})})]}),r==="phone"&&o==="verify"&&e.jsxs("form",{onSubmit:B,className:"space-y-4 mb-6",children:[e.jsx("button",{type:"button",onClick:U,className:"flex items-center gap-1 text-gray-400 hover:text-white text-xs mb-2 transition-colors",children:"← 返回"}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:`${t}-3`,className:"text-xs font-bold text-gray-400 uppercase tracking-wider ml-1",children:"驗證碼"}),e.jsxs("div",{className:"relative group",children:[e.jsx(Oe,{className:"absolute left-4 top-1/2 -translate-y-1/2 text-gray-500 group-focus-within:text-purple-400 transition-colors",size:18}),e.jsx("input",{id:`${t}-3`,type:"text",value:f,onChange:p=>x(p.target.value),placeholder:"輸入 6 位數驗證碼",maxLength:6,className:"w-full bg-gray-950/50 border border-gray-700/50 text-white rounded-xl py-3 px-4 pl-12 focus:border-purple-500 focus:bg-gray-900 focus:ring-1 focus:ring-purple-500 outline-none transition-all placeholder-gray-600 text-sm tracking-widest font-mono text-center text-xl"})]}),e.jsxs("p",{className:"text-12 text-gray-500 ml-1",children:["已發送簡訊至 ",c]})]}),e.jsx("button",{type:"submit",disabled:D,className:"w-full flex items-center justify-center gap-2 bg-gradient-to-r from-purple-600 to-pink-600 hover:from-purple-500 hover:to-pink-500 disabled:from-gray-800 disabled:to-gray-800 disabled:text-gray-500 disabled:cursor-not-allowed text-white font-bold py-3 px-6 rounded-xl transition-all duration-300 shadow-lg shadow-purple-900/30 hover:shadow-purple-500/40 hover:-translate-y-0.5 active:translate-y-0 text-sm",children:D?e.jsx(be,{size:18,className:"animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"驗證並登入"}),e.jsx(Xa,{size:16})]})})]}),e.jsx("div",{className:"text-center border-t border-gray-800 pt-4 mt-4",children:e.jsx("a",{href:"/login",className:"text-xs text-gray-500 hover:text-gray-300 transition-colors",children:"← 返回一般登入"})})]}),e.jsx("div",{className:"mt-8 text-center",children:e.jsx("p",{className:"mt-2 text-12 text-gray-600 opacity-60",children:"Admin Console · Secure Access Only"})})]})]})},_o=[{group:"主要功能",items:[{id:"home",path:"/user",label:"個人首頁",icon:e.jsx(Pr,{size:20})}]},{group:"勞報管理",items:[{id:"remuneration",path:"/user/remuneration",label:"勞報單總表",icon:e.jsx(Be,{size:18})},{id:"health-records",path:"/user/health-records",label:"健保紀錄",icon:e.jsx(ya,{size:18})},{id:"settings",path:"/user/settings",label:"資料設定",icon:e.jsx(Tr,{size:18})}]},{group:"文件",items:[{id:"documents",path:"/user/documents",label:"我的簽署歷史",icon:e.jsx(Be,{size:18})}]},{group:"個人中心",items:[{id:"account",path:"/user/account",label:"帳號設置",icon:e.jsx(ct,{size:20})}]}],Ao=({onLogout:t,user:a,onClose:r,isCollapsed:s=!1,onToggleCollapse:o})=>{const d=Qt(),c=Ye(),[u,f]=i.useState({主要功能:!0,勞報管理:!0,文件:!0,個人中心:!0}),[x,l]=i.useState(!1);i.useEffect(()=>{const N=()=>l(window.innerWidth<1024);return N(),window.addEventListener("resize",N),()=>window.removeEventListener("resize",N)},[]);const b=x?!1:s,[y,j]=i.useState([]),[w,v]=i.useState(!1);St(w,()=>v(!1)),i.useEffect(()=>{za().then(j).catch(()=>j([]))},[]);const T=N=>{v(!1),ra(N),localStorage.setItem("savedTaxId",N),window.location.href="/dashboard"};i.useEffect(()=>{const N=()=>{const I=window.matchMedia("(min-width: 1024px)").matches?b?72:256:0;document.documentElement.style.setProperty("--sidebar-width",`${I}px`)};return N(),window.addEventListener("resize",N),()=>window.removeEventListener("resize",N)},[b]);const S=N=>{f(R=>({...R,[N]:!R[N]}))},k=N=>N==="/user"?c.pathname==="/user":c.pathname.startsWith(N),A=a.displayName||a.email||"使用者",D=N=>e.jsxs("button",{onClick:()=>{d(N.path),r==null||r()},title:b?N.label:void 0,className:`w-full flex items-center gap-3 px-3 py-2.5 rounded-xl transition-all duration-200 group relative
16        ${b?"justify-center":""}
17        ${k(N.path)?"bg-[var(--accent)]/10 text-[var(--accent)] font-bold shadow-inner":"text-[var(--text-secondary)] hover:bg-[var(--bg-card-alt)] hover:text-[var(--text-primary)] font-medium"}
18      `,children:[e.jsx("div",{className:`transition-colors flex-shrink-0 ${k(N.path)?"text-[var(--accent)]":"text-[var(--text-muted)] group-hover:text-[var(--text-secondary)]"}`,children:N.icon}),!b&&e.jsx("span",{className:"truncate",children:N.label}),k(N.path)&&!b&&e.jsx("div",{className:"absolute right-2 w-1.5 h-1.5 rounded-full bg-[var(--accent)]"})]},N.id);return e.jsxs("div",{className:`${b?"w-[72px]":"w-64"} h-screen bg-[var(--bg-card)] border-r border-[var(--border)] flex flex-col flex-shrink-0 transition-all duration-300`,children:[e.jsxs("div",{className:`relative ${b?"p-3":"p-6"} flex items-center gap-3 border-b border-[var(--border)] transition-all duration-300`,children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-[var(--accent)] flex items-center justify-center font-bold text-[var(--button-text)] flex-shrink-0",children:e.jsx(ct,{size:18})}),!b&&(y.length>=1?e.jsxs("button",{type:"button",onClick:()=>v(N=>!N),className:`flex-1 min-w-0 text-left flex items-center gap-2 rounded-lg px-2 py-1.5 -mx-1 border transition-all group ${w?"bg-[var(--bg-card-alt)] border-[var(--accent)]":"border-transparent hover:bg-[var(--bg-card-alt)] hover:border-[var(--border)]"}`,title:"切換公司 / 個人空間",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h1",{className:"text-base font-bold tracking-wide text-[var(--text-primary)] leading-tight",children:"個人空間"}),e.jsx("span",{className:"text-12 text-[var(--accent)] font-bold tracking-wider",children:"切換 ▾"})]}),e.jsx(Ne,{size:18,className:`text-[var(--accent)] flex-shrink-0 transition-transform ${w?"rotate-180":""}`})]}):e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h1",{className:"text-base font-bold tracking-wide text-[var(--text-primary)] leading-tight",children:"個人空間"}),e.jsx("span",{className:"text-12 text-[var(--text-muted)] font-mono tracking-widest",children:"PERSONAL"})]})),!b&&w&&y.length>=1&&e.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>v(!1)}),!b&&w&&e.jsxs("div",{className:"absolute left-3 right-3 top-full mt-1 z-50 bg-[var(--bg-card)] border border-[var(--border)] rounded-xl shadow-2xl overflow-hidden max-h-80 overflow-y-auto",children:[e.jsxs("div",{className:"px-4 py-2 text-12 font-bold uppercase tracking-wider text-[var(--text-muted)] border-b border-[var(--border)] bg-[var(--bg-card-alt)]/40",children:["我的公司(",y.length,")"]}),y.map(N=>e.jsxs("button",{type:"button",onClick:()=>T(N.taxId),className:"w-full text-left px-4 py-3 flex items-start justify-between gap-2 border-b border-[var(--border)]/40 hover:bg-[var(--bg-card-alt)] transition-colors",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm font-bold text-[var(--text-primary)] break-words leading-snug",children:N.displayTitle}),e.jsxs("div",{className:"text-12 text-[var(--text-muted)] font-mono mt-0.5",children:[N.taxId," · ",N.role==="admin"?"ADMIN":"USER"]})]}),e.jsx(st,{size:16,className:"text-[var(--text-muted)] flex-shrink-0 mt-0.5"})]},N.taxId)),e.jsxs("div",{className:"w-full text-left px-4 py-3 flex items-center gap-2 bg-[var(--bg-card-alt)]",children:[e.jsx(ct,{size:16,className:"text-[var(--accent)] flex-shrink-0"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm font-bold text-[var(--text-primary)]",children:"個人空間"}),e.jsx("div",{className:"text-12 text-[var(--text-muted)]",children:"目前所在"})]}),e.jsx(Qe,{size:16,className:"text-[var(--accent)] flex-shrink-0"})]}),e.jsxs("button",{type:"button",onClick:()=>{window.location.href="/register"},className:"w-full text-left px-4 py-3 flex items-center gap-2 border-t border-[var(--border)]/40 hover:bg-[var(--bg-card-alt)] transition-colors",children:[e.jsx(ze,{size:16,className:"text-[var(--text-muted)] flex-shrink-0"}),e.jsx("div",{className:"text-sm font-bold text-[var(--text-secondary)]",children:"建立公司"})]})]}),o&&e.jsx("button",{onClick:o,className:"hidden lg:flex p-1.5 rounded-lg text-[var(--text-muted)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-card-alt)] transition-colors shrink-0","aria-label":b?"展開選單":"收合選單",title:b?"展開選單":"收合選單",children:b?e.jsx(Er,{size:18}):e.jsx(_r,{size:18})}),r&&e.jsx("button",{onClick:r,className:"lg:hidden p-1.5 rounded-lg text-[var(--text-muted)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-card-alt)] transition-colors shrink-0","aria-label":"關閉選單",children:e.jsx(ye,{size:20})})]}),e.jsx("nav",{className:`flex-1 overflow-y-auto py-4 ${b?"px-2":"px-3"} space-y-4 custom-scrollbar transition-all duration-300`,children:_o.map(N=>e.jsxs("div",{children:[b?e.jsx("div",{className:"my-2 border-t border-[var(--border)]"}):e.jsxs("div",{className:"mb-1 px-3 py-1 flex items-center justify-between cursor-pointer group/header",...Fe(()=>S(N.group)),children:[e.jsx("span",{className:"text-12 font-bold text-[var(--text-muted)] uppercase tracking-widest flex items-center gap-2 group-hover/header:text-[var(--text-secondary)] transition-colors",children:N.group}),u[N.group]?e.jsx(Ne,{size:12,className:"text-[var(--text-muted)]"}):e.jsx(Le,{size:12,className:"text-[var(--text-muted)]"})]}),(b||u[N.group])&&e.jsx("div",{className:"space-y-1 nk-in-left",children:N.items.map(R=>D(R))})]},N.group))}),e.jsxs("div",{className:`${b?"p-2":"p-4"} border-t border-[var(--border)] bg-[var(--bg-card)]/50 transition-all duration-300`,children:[!b&&e.jsxs("div",{className:"mb-3 px-2",children:[e.jsx("div",{className:"text-12 font-bold text-[var(--text-muted)] uppercase tracking-wider mb-2",children:"主題"}),e.jsx(es,{compact:!0})]}),e.jsxs("div",{className:`flex items-center gap-3 mb-4 p-2 rounded-lg ${b?"justify-center":"px-2"}`,children:[a.photoURL?e.jsx("img",{src:a.photoURL,alt:"",className:"w-8 h-8 rounded-full border border-[var(--border)] flex-shrink-0"}):e.jsx("div",{className:"w-8 h-8 rounded-full bg-[var(--bg-card-alt)] border border-[var(--border)] flex items-center justify-center text-xs font-bold text-[var(--text-secondary)] uppercase flex-shrink-0",children:A.charAt(0)}),!b&&e.jsxs("div",{className:"flex-1 overflow-hidden",children:[e.jsx("div",{className:"text-sm font-bold text-[var(--text-primary)] truncate",children:a.displayName||"個人帳號"}),e.jsx("div",{className:"text-xs text-[var(--text-muted)] truncate",children:a.email})]})]}),e.jsxs("button",{onClick:t,title:b?"登出":void 0,className:"w-full flex items-center justify-center gap-2 px-4 py-2 text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:bg-[var(--error)]/20 hover:border-[var(--error)]/30 border border-transparent roun
18ded-lg transition-all text-sm font-bold",children:[e.jsx(Ir,{size:16}),!b&&e.jsx("span",{children:"登出"})]})]})]})},Io=()=>{const t=Ye(),[a,r]=i.useState(!0),[s,o]=i.useState(null),[d,c]=i.useState(!1),[u,f]=i.useState(null),[x,l]=i.useState(!1);St(x,()=>l(!1));const[b,y]=i.useState(()=>localStorage.getItem("personalSidebarCollapsed")==="true");i.useEffect(()=>{je();const S=ie(),k=Cr(S,A=>{o(A),A&&lr(A.uid),r(!1)});return()=>k()},[]),i.useEffect(()=>{l(!1)},[t.pathname]);const j=()=>{y(S=>{const k=!S;return localStorage.setItem("personalSidebarCollapsed",String(k)),k})},w=async()=>{c(!0),f(null);try{const S=ie(),k=new zt;k.addScope("email"),k.addScope("profile");const A=await Aa(S,k);o(A.user),lr(A.user.uid)}catch(S){S.code==="auth/popup-closed-by-user"?f("登入視窗已關閉,請重試"):S.code==="auth/popup-blocked"?f("登入視窗被封鎖,請允許彈出視窗"):f(S.message||"登入失敗,請稍後再試")}finally{c(!1)}},v=async()=>{try{await ie().signOut(),o(null)}catch(S){console.error("Logout error:",S)}};if(a)return e.jsxs("div",{className:"min-h-screen bg-[var(--bg-page)] flex flex-col items-center justify-center gap-4",children:[e.jsx("div",{className:"w-7 h-7 border-2 border-[var(--border)] border-t-[var(--accent)] rounded-full animate-spin"}),e.jsx("span",{className:"text-sm text-[var(--text-muted)]",children:"載入中…"})]});if(!s)return e.jsx("div",{className:"min-h-screen bg-[var(--bg-page)] flex items-center justify-center p-4",children:e.jsxs("div",{className:"bg-[var(--bg-card)] border border-[var(--border)] rounded-2xl shadow-xl p-8 max-w-md w-full",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("div",{className:"w-16 h-16 bg-[var(--accent)]/10 border border-[var(--accent)]/20 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(Dr,{size:32,className:"text-[var(--accent)]"})}),e.jsx("h1",{className:"text-2xl font-bold text-[var(--text-primary)] mb-2",children:"個人帳號"}),e.jsx("p",{className:"text-[var(--text-secondary)]",children:"登入以查看您的個人空間"})]}),u&&e.jsx("div",{className:"bg-[var(--error)]/10 border border-[var(--error)]/30 rounded-lg p-3 mb-4",children:e.jsx("p",{className:"text-sm text-[var(--error)]",children:u})}),e.jsxs("button",{onClick:w,disabled:d,className:"w-full flex items-center justify-center gap-3 py-3 px-4 bg-[var(--bg-card-alt)] border border-[var(--border)] rounded-xl font-medium text-[var(--text-primary)] hover:border-[var(--border-hover)] transition-all disabled:opacity-50 disabled:cursor-not-allowed",children:[d?e.jsx(be,{size:20,className:"animate-spin"}):e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",children:[e.jsx("path",{fill:"#4285F4",d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"}),e.jsx("path",{fill:"#34A853",d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"}),e.jsx("path",{fill:"#FBBC05",d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"}),e.jsx("path",{fill:"#EA4335",d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"})]}),e.jsx("span",{children:"使用 Google 帳號登入"})]}),e.jsxs("a",{href:"/",className:"mt-6 flex items-center justify-center gap-2 py-2 text-sm text-[var(--text-secondary)] hover:text-[var(--text-primary)] transition-colors",children:[e.jsx(tn,{size:16})," 回首頁"]})]})});const T={displayName:s.displayName,email:s.email,photoURL:s.photoURL};return e.jsxs("div",{className:"flex h-screen w-screen bg-[var(--bg-page)] overflow-hidden",children:[!x&&e.jsx("button",{onClick:()=>l(!0),className:"fixed top-4 left-4 z-[80] lg:hidden p-2 bg-[var(--bg-card)] border border-[var(--border)] rounded-xl text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-card-alt)] transition-all shadow-lg","aria-label":"開啓選單",children:e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("line",{x1:"3",y1:"6",x2:"21",y2:"6"}),e.jsx("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),e.jsx("line",{x1:"3",y1:"18",x2:"21",y2:"18"})]})}),x&&e.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm z-[60] lg:hidden",onClick:()=>l(!1)}),e.jsx("div",{className:`
19        fixed lg:relative inset-y-0 left-0 z-[70]
20        transform transition-transform duration-300 ease-in-out
21        ${x?"translate-x-0":"-translate-x-full lg:translate-x-0"}
22      `,children:e.jsx(Ao,{onLogout:v,user:T,onClose:()=>l(!1),isCollapsed:b,onToggleCollapse:j})}),e.jsxs("main",{className:"flex-1 overflow-y-auto h-full relative w-full",children:[e.jsx("div",{className:"absolute top-0 left-0 w-full h-0.5 bg-[var(--accent)] z-10"}),e.jsx("div",{className:"nk-page",children:e.jsx(i.Suspense,{fallback:e.jsx(Oa,{}),children:e.jsx(Ea,{context:{user:s,logout:v}})})},t.pathname)]})]})},Po=({message:t,type:a="success",onClose:r})=>{i.useEffect(()=>{if(a==="loading")return;const d=setTimeout(r,3e3);return()=>clearTimeout(d)},[r,a]);const s={success:"bg-[var(--success)]/10 border-[var(--success)]/20 text-[var(--success)]",error:"bg-[var(--error)]/10 border-[var(--error)]/20 text-[var(--error)]",info:"bg-[var(--accent)]/10 border-[var(--accent)]/20 text-[var(--accent)]",loading:"bg-[var(--warning)]/10 border-[var(--warning)]/20 text-[var(--warning)]",
22warning:"bg-[var(--warning)]/10 border-[var(--warning)]/20 text-[var(--warning)]"},o={success:Ue,error:De,info:an,loading:be,warning:De}[a];return e.jsx("div",{className:"fixed bottom-6 right-6 z-[100] nk-in-up",children:e.jsxs("div",{className:`flex items-center gap-3 px-4 py-3 rounded-xl shadow-2xl border ${s[a]} backdrop-blur-md min-w-[300px]`,children:[e.jsx(o,{size:20,className:`shrink-0 ${a==="loading"?"animate-spin":""}`}),e.jsx("span",{className:"font-bold text-sm flex-1",children:t}),a!=="loading"&&e.jsx("button",{onClick:r,className:"ml-2 hover:opacity-70 transition-opacity p-1",children:e.jsx(ye,{size:16})})]})})},To=new Set(["input","select","textarea"]),xe=({label:t,children:a,className:r="",required:s=!1,labelClassName:o="text-12 font-bold text-[var(--text-muted)] uppercase tracking-widest block ml-1"})=>{var j;const d=i.useId(),c=Dt.isValidElement(a)?a:null,u=c?c.type:null,f=(j=c==null?void 0:c.props)==null?void 0:j.id,x=!!c&&(typeof u=="string"?To.has(u):typeof u=="function"),l=f??d,b=x&&!f,y=x;return e.jsxs("div",{className:`space-y-1.5 ${r}`,children:[e.jsxs("label",{htmlFor:y?l:void 0,className:o,children:[t,s&&e.jsx("span",{className:"text-[var(--error)]",children:" *"})]}),b?Dt.cloneElement(c,{id:l}):a]})},ss=()=>typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now();let Gt=null,Kt=null,ns=0;const Do=1200;typeof window<"u"&&(window.addEventListener("pointerdown",t=>{Gt=t.clientX,Kt=t.clientY,ns=ss()},{capture:!0,passive:!0}),window.addEventListener("keydown",()=>{Gt=null,Kt=null},{capture:!0,passive:!0}));const zo=()=>Gt===null||Kt===null||ss()-ns>Do?null:{x:Gt,y:Kt},Lo=t=>{const a=zo();if(!a)return null;const r=t.getBoundingClientRect();if(r.width===0||r.height===0)return null;const s=c=>Math.max(-150,Math.min(250,c)),o=s((a.x-r.left)/r.width*100),d=s((a.y-r.top)/r.height*100);return`${o.toFixed(1)}% ${d.toFixed(1)}%`};function Ro(t){const a=i.useRef(null),r=i.useCallback(()=>{const s=a.current;if(!s)return;const o=Lo(s);s.style.transformOrigin=o??""},[]);return i.useLayoutEffect(()=>{t&&r()},[t,r]),a}const Oo=({children:t})=>{const a=document.getElementById("modal-root");return a?ga.createPortal(t,a):ga.createPortal(t,document.body)},pe=({children:t,isOpen:a,onClose:r,closeOnBackdropClick:s=!0,zIndex:o=50,backdropClass:d="bg-black/80",blur:c=!0,maxWidth:u="max-w-lg",maxHeight:f,contentClassName:x="",animate:l=!0,ariaLabel:b="對話框"})=>{const y=Ro(a),j=i.useRef(null);if(i.useEffect(()=>{if(!a)return;const v=T=>{T.key==="Escape"&&r&&(T.stopPropagation(),r())};return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[a,r]),i.useEffect(()=>{var S;if(!a)return;j.current=document.activeElement;const v=y.current;return(S=(v==null?void 0:v.querySelector('button:not([disabled]), [href], input:not([disabled]):not([type="hidden"]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'))??v)==null||S.focus({preventScroll:!0}),()=>{var k,A;(A=(k=j.current)==null?void 0:k.focus)==null||A.call(k,{preventScroll:!0})}},[a,y]),!a)return null;const w=v=>{s&&v.target===v.currentTarget&&r&&r()};return e.jsx(Oo,{children:e.jsx("div",{className:`fixed inset-0 z-[${o}] ${d} ${c?"backdrop-blur-sm":""} ${l?"nk-in":""}`,style:{zIndex:o},onClick:w,children:e.jsx("div",{ref:y,className:`w-[calc(100vw-2rem)] ${u} ${f||""} ${x} ${l?"nk-in-modal":""}`,style:{position:"fixed",left:"calc(50vw + var(--sidebar-width, 0px) / 2)",top:"50vh",transform:"translate(-50%, -50%)",zIndex:o+1},onClick:v=>v.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":b,tabIndex:-1,children:t})})})},os="公司",Mo=[os],Yt={50:.05,"9A":.1,"9B":.1},Ma=.0211,$o=90501,Fo=2e3,$a=29500,Bo=2e4,ls=20001,Uo=.05,nd={50:"50 薪資 (5%)","9A":"9A 執行業務 (10%)","9B":"9B 稿費 (10%)"},Ke=t=>t.name===os,qo=(t,a)=>!!(t.isAgent===!0||a!=null&&a.some(r=>r.name===t.name&&r.isAgent===!0)||t.isAgent===void 0&&Ke(t)),od=(t,a)=>qo(t,a)&&!Ke(t),vt=t=>!!t.settledId,hr=t=>Mo.includes(t.trim()),ld=(t,a,r)=>{if(t.isAutoCalc===!1&&t.amount!==void 0)return t.amount;const s=a-r;return Math.round(s*(t.percentage/100))+(Number(t.cost)||0)},cd=(t,a,r)=>{let s;if(a==="50")s=t>=$o?Math.round(t*Yt[a]):0;else{const c=t*Yt[a];s=c>Fo?Math.round(c):0}let o=0;r||(o=t>=(a==="50"?$a:Bo)?Math.round(t*Ma):0);const d=t-s-o;return{withholdingTax:s,healthInsurance:o,netAmount:d}},Wo=({initialData:t,onClose:a,onSave:r,assigneeOptions:s=[],isFinancialLocked:o=!1,readOnly:d=!1})=>{const c=i.useId(),[u,f]=i.useState(JSON.parse(JSON.stringify(t))),[x,l]=i.useState("basic"),[b,y]=i.useState([]);i.useEffect(()=>{if(d)return;let m=!0;return Xn().then(_=>{m&&y(_)}).catch(()=>{}),()=>{m=!1}},[d]);const j=(m,_)=>{f(L=>{const $={...L,[m]:_};if(m==="amountTotal"){const B=Number(_)||0;$.taxAmount=Math.round(B*.05),$.amountGross=B+$.taxAmount}return $})},w=m=>m.reduce((_,L)=>_+(Number(L.cost)||0),0),v=(m,_,L)=>{f($=>{const B=$.splitShares.map(U=>{if(U.id!==m||_==="name"&&Ke(U)||_==="name"&&typeof L=="string"&&hr(L)&&!Ke(U)||vt(U)&&(_==="percentage"||_==="cost"||_==="amount"||_==="isAutoCalc"))return U;const n={...U,[_]:L};if(n.isAutoCalc!==!1&&(_==="percentage"||_==="cost"||_==="name")){const p=$.amountTotal-w($.splitShares.map(g=>g.id===m?n:g));n.amount=Math.round(p*(n.percentage/100))+(Number(n.cost)||0)}return n});return{...$,splitShares:B,costExtra:w(B)}})},T=(m,_)=>{f(L=>{const $=L.splitShares.map(B=>
22{if(B.id!==m)return B;const U={...B,isAutoCalc:_};if(_){const n=L.amountTotal-L.costExtra;U.amount=Math.round(n*(B.percentage/100))+(Number(B.cost)||0)}return U});return{...L,splitShares:$}})},S=(m,_)=>{f(L=>({...L,splitShares:L.splitShares.map($=>$.id===m?{...$,amount:_}:$)}))},k=()=>{f(m=>({...m,splitShares:[...m.splitShares,{id:Date.now().toString(),name:"新對象",percentage:0,cost:0,isCoveringCost:!1}]}))},A=(m,_)=>{f(L=>({...L,splitShares:L.splitShares.map($=>{if($.id!==m||Ke($)||vt($))return $;const B=_.displayName||_.username||_.email||$.name,U=hr(B)?$.name:B;return{...$,name:U,isAgent:!0,executorUserIds:_.id?[_.id]:[]}})}))},D=m=>{f(_=>({..._,splitShares:_.splitShares.map(L=>{if(L.id!==m||vt(L))return L;const $={...L,isAgent:!1};return delete $.executorUserIds,$})}))},N=m=>{f(_=>{const L=_.splitShares.find(B=>B.id===m);if(L&&Ke(L)||L&&vt(L))return _;const $=_.splitShares.filter(B=>B.id!==m);return{..._,splitShares:$,costExtra:w($)}})},R=u.splitShares.reduce((m,_)=>m+_.percentage,0),I=u.splitShares.flatMap(m=>m.executorUserIds||[]);return e.jsxs(pe,{isOpen:!0,onClose:a,maxWidth:"max-w-5xl",contentClassName:"bg-[var(--bg-card)] border border-[var(--border)] h-[85vh] rounded-3xl shadow-2xl flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"p-6 border-b border-[var(--border)] bg-[var(--bg-page)] flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-2xl font-bold text-[var(--text-primary)] flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-[var(--accent)]/20 rounded-xl text-[var(--accent)]",children:e.jsx(Be,{size:20})}),u.id?"編輯專案":"新增專案"]}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsxs("span",{className:"text-xs font-mono text-[var(--text-muted)] bg-[var(--bg-card-alt)] px-2 py-0.5 rounded border border-[var(--border)]",children:["#",u.serialNumber]}),e.jsx("span",{className:"text-xs text-[var(--text-secondary)]",children:u.projectName||"未命名專案"})]})]}),e.jsx("button",{onClick:a,className:"p-2 hover:bg-[var(--bg-card-alt)] rounded-xl transition-all text-[var(--text-secondary)] hover:text-[var(--text-primary)]",children:e.jsx(ye,{size:24})})]}),e.jsxs("div",{className:"flex border-b border-[var(--border)] bg-[var(--bg-card)]",children:[e.jsx(ha,{active:x==="basic",onClick:()=>l("basic"),icon:e.jsx(Be,{size:16}),label:"基本資訊"}),e.jsx(ha,{active:x==="logistics",onClick:()=>l("logistics"),icon:e.jsx(er,{size:16}),label:"執行與物流"}),e.jsx(ha,{active:x==="finance",onClick:()=>l("finance"),icon:e.jsx(rn,{size:16}),label:"財務對帳"})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4 md:p-6 lg:p-8 custom-scrollbar bg-[var(--bg-card)]",children:e.jsxs("div",{className:"max-w-4xl mx-auto space-y-8",children:[o&&e.jsxs("div",{className:"p-4 bg-[var(--accent)]/10 border border-[var(--accent)]/30 rounded-2xl flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-[var(--accent)]/20 rounded-xl",children:e.jsx(De,{size:20,className:"text-[var(--accent)]"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-bold text-[var(--accent)]",children:"財務欄位已鎖定"}),e.jsx("p",{className:"text-xs text-[var(--accent)]/70",children:"此專案已結帳,金額與分潤配置無法修改。您仍可更新報價單、稅務、展工、及備註。"})]})]}),x==="basic"&&e.jsxs("div",{className:"grid grid-cols-12 gap-6 nk-in-up",children:[e.jsx(xe,{label:"專案名稱",className:"col-span-12",children:e.jsx("input",{"aria-label":"輸入專案標題",type:"text",value:u.projectName,onChange:m=>j("projectName",m.target.value),className:"input-modern",placeholder:"輸入專案標題",required:!0})}),e.jsx(xe,{label:"執行月份",className:"col-span-6 md:col-span-4",children:e.jsx("input",{"aria-label":"執行月份",type:"month",value:u.month,onChange:m=>j("month",m.target.value),className:"input-modern font-mono"})}),e.jsx(xe,{label:"指派人",className:"col-span-6 md:col-span-4",children:e.jsx("select",{value:u.assignee,onChange:m=>j("assignee",m.target.value),className:"input-modern",children:s.map(m=>e.jsx("option",{value:m,children:m},m))})}),e.jsx(xe,{label:"專案狀態",className:"col-span-12 md:col-span-4",children:e.jsxs("select",{value:u.status,onChange:m=>j("status",m.target.value),className:"input-modern",children:[e.jsx("option",{value:"negotiating",children:"洽談中"}),e.jsx("option",{value:"reviewing",children:"審稿中"}),e.jsx("option",{value:"executing",children:"執行中"}),e.jsx("option",{value:"closed",children:"已結案"})]})}),e.jsx(xe,{label:"廠商名稱",className:"col-span-12 md:col-span-8",children:e.jsx("input",{"aria-label":"客戶或公司名稱",type:"text",value:u.clientName,onChange:m=>j("clientName",m.target.value),className:"input-modern",placeholder:"客戶或公司名稱"})}),e.jsx(xe,{label:"AC/BC",className:"col-span-12 md:col-span-4",children:e.jsxs("select",{value:u.acBc,onChange:m=>j("acBc",m.target.value),className:"input-modern",children:[e.jsx("option",{value:"",children:"無"}),e.jsx("option",{value:"AC",children:"AC"}),e.jsx("option",{value:"BC",children:"BC"}),e.jsx("option",{value:"AC+BC",children:"AC+BC"})]})}),e.jsx("div",{className:"col-span-12 md:col-span-6",children:e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer p-3 bg-[var(--bg-card-alt)] rounded-xl border border-[var(--border)] w-full hover:border-[var(--accent)]/30 transition-all select-none",children:[e.jsx("input",{type:"checkbox",checked:u.quotationStatus==="issued",onChange:m=>j("quotationStatus",m.target.checked?"issued":"pending"),className:"checkbox-modern"}),e.jsx("span",{className:"text-sm font-bold text-[var(--text-primary)]",children:"報價單已開立"})]})}),e.jsx("div",{className:"col-span-12 md:col-span-6",children:e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer p-3 bg-[var(--bg-card-alt)] rounded-xl border border-[var(--border)] w-full hover:border-[var(--accent)]/30 transition-all select-none",children:[e.jsx("input",{type:"checkbox",checked:u.isQuotationSigned,onChange:m=>j("isQuotationSigned",m.target.checked),className:"checkbox-modern"}),e.jsx("span",{className:"text-sm font-bold text-[var(--text-primary)]",children:"報價單已回簽"})]})}),e.jsx(xe,{label:"專案備註",className:"col-span-12",children:e.jsx("textarea",{"aria-label":"輸入其他細節...",value:u.note,onChange:m=>j("note",m.target.value),className:"input-modern h-32 resize-none",placeholder:"輸入其他細節..."})})]}),x==="logistics"&&e.jsxs("div",{className:"grid grid-cols-12 gap-6 nk-in-up",children:[e.jsx(xe,{label:"合作項目",className:"col-span-12 md:col-span-8",children:e.jsx("input",{"aria-label":"例:影片x1, 圖文x2",type:"text",value:u.collaborationItem,onChange:m=>j("collaborationItem",m.target.value),className:"input-modern",placeholder:"ä¾
22‹ï¼šå½±ç‰‡x1, 圖文x2"})}),e.jsx("div",{className:"col-span-12 md:col-span-4 flex items-end pb-1",children:e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer p-3 bg-[var(--bg-card-alt)] rounded-xl border border-[var(--border)] w-full hover:border-[var(--id-purple)]/30 transition-all select-none",children:[e.jsx("input",{type:"checkbox",checked:u.hasLottery,onChange:m=>j("hasLottery",m.target.checked),className:"checkbox-modern"}),e.jsx("span",{className:"text-sm font-bold text-[var(--text-primary)]",children:"包含抽獎活動"})]})}),e.jsx(xe,{label:"CUE 表連結",className:"col-span-12",children:e.jsxs("div",{className:"relative",children:[e.jsx("input",{"aria-label":"https://...",type:"text",value:u.cueStatus,onChange:m=>j("cueStatus",m.target.value),className:"input-modern pl-10",placeholder:"https://..."}),e.jsx(zr,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-[var(--text-muted)]"})]})}),e.jsxs("div",{className:"col-span-12 grid grid-cols-1 md:grid-cols-2 gap-6 bg-[var(--bg-card-alt)]/40 p-6 rounded-2xl border border-[var(--border)]",children:[e.jsxs("div",{className:"col-span-2 text-xs font-bold text-[var(--text-muted)] uppercase tracking-widest flex items-center gap-2 mb-2",children:[e.jsx(er,{size:14})," 物流狀態"]}),e.jsx(xe,{label:"3C 產品收到沒?",children:e.jsxs("select",{value:u.productStatus,onChange:m=>j("productStatus",m.target.value),className:"input-modern",children:[e.jsx("option",{value:"",children:"未設定"}),e.jsx("option",{value:"已收到",children:"已收到"}),e.jsx("option",{value:"尚未收到",children:"尚未收到"})]})}),e.jsx("div",{className:"flex items-end pb-1",children:e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer p-3 bg-[var(--bg-card-alt)] border border-[var(--border)] rounded-xl w-full hover:border-[var(--id-purple)]/30 transition-all select-none",children:[e.jsx("input",{type:"checkbox",checked:u.isProductRecycled,onChange:m=>j("isProductRecycled",m.target.checked),className:"checkbox-modern"}),e.jsx("span",{className:"text-sm font-bold text-[var(--text-primary)]",children:"產品需回收"})]})}),e.jsx(xe,{label:"物流備註 / 產品內容",className:"col-span-2",children:e.jsx("input",{"aria-label":"產品寄送編號或品項...",type:"text",value:u.contentStatus,onChange:m=>j("contentStatus",m.target.value),className:"input-modern",placeholder:"產品寄送編號或品項..."})})]})]}),x==="finance"&&e.jsxs("div",{className:"grid grid-cols-12 gap-8 nk-in-up",children:[e.jsxs("div",{className:"col-span-12 lg:col-span-6 space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h4",{className:"font-bold text-[var(--text-primary)] flex items-center gap-2",children:[e.jsx(sn,{size:18,className:"text-[var(--id-purple)]"}),"利潤分潤",o&&e.jsx("span",{className:"text-12 bg-[var(--accent)]/20 text-[var(--accent)] px-2 py-0.5 rounded font-bold",children:"已鎖定"})]}),!o&&e.jsxs("button",{type:"button",onClick:k,className:"text-xs bg-[var(--bg-card-alt)] hover:bg-[var(--bg-card-alt)] text-[var(--accent)] px-3 py-1.5 rounded-lg border border-[var(--border)] transition-all flex items-center gap-1 font-bold",children:[e.jsx(ze,{size:14})," 新增"]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"bg-[var(--bg-card-alt)]/40 p-4 rounded-2xl border border-[var(--id-orange)]/20",children:[e.jsx("label",{htmlFor:`${c}-0`,className:"text-12 font-bold text-[var(--id-orange)] uppercase tracking-widest block mb-2",children:"額外扣除總成本 (代墊/剪輯 - 下方自動彙整)"}),e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-[var(--id-orange)] font-mono font-bold",children:"-$"}),e.jsx("input",{id:`${c}-0`,type:"number",readOnly:!0,value:u.costExtra,className:"w-full bg-[var(--bg-card-alt)] border border-[var(--id-orange)]/30 rounded-xl py-2 px-10 text-[var(--id-orange)] font-mono font-bold outline-none cursor-not-allowed"})]})]}),e.jsx("div",{className:"space-y-3",children:u.splitShares.map(m=>{const _=u.amountTotal-u.costExtra,L=Math.round(_*(m.percentage/100))+(Number(m.cost)||0),$=m.isAutoCalc===!1?m.amount??L:L,B=m.isAutoCalc!==!1,U=Ke(m),n=vt(m),p=o||U,g=o||n,P=m.isAgent===!0&&!U,E=!o&&
22!U&&!n;return e.jsxs("div",{className:`bg-[var(--bg-card-alt)]/50 p-4 rounded-2xl border group relative ${o?"border-[var(--accent)]/20 opacity-80":n?"border-[var(--id-purple)]/30":"border-[var(--border)]"}`,children:[(U||n||P)&&e.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[U&&e.jsxs("span",{className:"flex items-center gap-1 text-11 font-bold text-[var(--id-purple)] bg-[var(--id-purple)]/10 px-1.5 py-0.5 rounded border border-[var(--id-purple)]/20",children:[e.jsx(nn,{size:9})," 公司本體"]}),P&&e.jsxs("span",{className:"flex items-center gap-1 text-11 font-bold text-[var(--success)] bg-[var(--success)]/10 px-1.5 py-0.5 rounded border border-[var(--success)]/20",children:["經紀人",E&&e.jsx("button",{type:"button",onClick:()=>D(m.id),title:"取消經紀人綁定",className:"hover:text-[var(--error)] transition-colors",children:e.jsx(ye,{size:9})})]}),n&&e.jsxs("span",{className:"flex items-center gap-1 text-11 font-bold text-[var(--accent)] bg-[var(--accent)]/10 px-1.5 py-0.5 rounded border border-[var(--accent)]/20",children:[e.jsx(Oe,{size:9})," 已結算 #",m.settledSerial]})]}),e.jsxs("div",{className:"flex gap-3 mb-2",children:[e.jsxs("div",{className:"flex-1 relative",children:[e.jsx("span",{className:"text-12 text-[var(--text-muted)] font-bold uppercase block mb-1",children:"對象"}),E?e.jsx(Ho,{value:m.name,users:b,usedUids:I,onTypeName:z=>v(m.id,"name",z),onPick:z=>A(m.id,z)}):e.jsx("input",{"aria-label":"分潤對象姓名",type:"text",value:m.name,onChange:z=>v(m.id,"name",z.target.value),disabled:p,title:U?"公司本體名稱為系統保留,不可修改":void 0,className:`w-full bg-[var(--bg-card-alt)] border border-[var(--border)] rounded-lg px-3 py-1.5 text-sm text-[var(--text-primary)] focus:border-[var(--accent)] outline-none ${p?"cursor-not-allowed opacity-60":""}`})]}),e.jsxs("div",{className:"w-20",children:[e.jsx("span",{className:"text-12 text-[var(--text-muted)] font-bold uppercase block mb-1",children:"比例 %"}),e.jsx("input",{"aria-label":"分潤比例(%)",type:"number",value:m.percentage,onChange:z=>v(m.id,"percentage",Number(z.target.value)),disabled:g,className:`w-full bg-[var(--bg-card-alt)] border border-[var(--border)] rounded-lg px-3 py-1.5 text-sm font-mono text-center text-[var(--text-primary)] focus:border-[var(--accent)] outline-none ${g?"cursor-not-allowed opacity-60":""}`})]}),e.jsxs("div",{className:"w-28",children:[e.jsx("span",{className:"text-12 text-[var(--id-orange)] font-bold uppercase block mb-1",children:"負擔成本"}),e.jsx("input",{"aria-label":"負擔成本",type:"number",value:m.cost||0,onChange:z=>v(m.id,"cost",Number(z.target.value)),disabled:g,className:`w-full bg-[var(--bg-card-alt)] border border-[var(--id-orange)]/20 rounded-lg px-3 py-1.5 text-sm font-mono text-center text-[var(--id-orange)] focus:border-[var(--id-orange)] outline-none ${g?"cursor-not-allowed opacity-60":""}`})]})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-2 pt-2 border-t border-[var(--border)]",children:[e.jsxs("label",{className:`flex items-center gap-2 select-none ${g?"cursor-not-allowed opacity-60":"cursor-pointer"}`,children:[e.jsx("input",{type:"checkbox",checked:B,onChange:z=>T(m.id,z.target.checked),disabled:g,className:"checkbox-modern"}),e.jsx("span",{className:"text-12 font-bold text-[var(--text-secondary)]",children:"自動計算"})]}),e.jsxs("div",{className:"flex-1 flex items-center gap-2",children:[e.jsx("span",{className:"text-12 font-bold text-[var(--success)] uppercase",children:"金額"}),B?e.jsxs("div",{className:"flex-1 bg-[var(--success)]/5 border border-[var(--success)]/20 rounded-lg px-3 py-1.5 text-sm font-mono font-bold text-[var(--success)] text-center",children:["$",$.toLocaleString()]}):e.jsxs("div",{className:"flex-1 relative",children:[e.jsx("span",{className:"absolute left-2 top-1/2 -translate-y-1/2 text-[var(--success)] font-mono text-sm",children:"$"}),e.jsx("input",{"aria-label":"分潤金額",type:"number",value:m.amount??L,onChange:z=>S(m.id,Number(z.target.value)),disabled:g,className:`w-full bg-[var(--bg-card-alt)] border rounded-lg pl-6 pr-3 py-1.5 text-sm font-mono text-center focus:outline-none ${g?"cursor-not-allowed opacity-60":""} ${(m.amount??0)>u.amountTotal?"border-[var(--error)]/50 text-[var(--error)] focu
22s:border-[var(--error)]":"border-[var(--success)]/30 text-[var(--success)] focus:border-[var(--success)]"}`}),(m.amount??0)>u.amountTotal&&e.jsx("span",{className:"absolute right-2 top-1/2 -translate-y-1/2 text-[var(--error)]",title:"金額超過總預算",children:e.jsx(De,{size:14})})]})]})]}),!B&&(m.amount??0)>u.amountTotal&&e.jsxs("div",{className:"mt-2 p-2 bg-[var(--error)]/10 border border-[var(--error)]/20 rounded-lg text-[var(--error)] text-12 font-bold flex items-center gap-1.5",children:[e.jsx(De,{size:12})," 警告:此金額已超過專案總預算 ($",u.amountTotal.toLocaleString(),")"]}),!o&&!U&&!n&&e.jsx("div",{className:"flex justify-end mt-1",children:e.jsx("button",{onClick:()=>N(m.id),className:"text-[var(--text-muted)] hover:text-[var(--error)] opacity-0 group-hover:opacity-100 transition-opacity",children:e.jsx(ye,{size:14})})})]},m.id)})}),R!==100&&e.jsxs("div",{className:"p-3 bg-[var(--error)]/10 border border-[var(--error)]/20 rounded-xl text-[var(--error)] text-xs font-bold flex items-center gap-2",children:[e.jsx(De,{size:14})," 分潤總和不等於 100% (目前: ",R,"%)"]})]})]}),e.jsxs("div",{className:"col-span-12 lg:col-span-6 space-y-6 bg-[var(--bg-card-alt)]/30 p-6 rounded-3xl border border-[var(--border)]",children:[e.jsxs("h4",{className:"font-bold text-[var(--text-primary)] flex items-center gap-2 border-b border-[var(--border)] pb-4",children:[e.jsx(Xt,{size:18,className:"text-[var(--accent)]"}),"發票與支付"]}),e.jsxs("div",{className:"space-y-6",children:[e.jsx(xe,{label:"總金額 (未稅)",children:e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"absolute left-4 top-1/2 -translate-y-1/2 text-[var(--accent)] font-mono font-bold",children:"$"}),e.jsx("input",{"aria-label":"總金額",type:"number",value:u.amountTotal,onChange:m=>j("amountTotal",Number(m.target.value)),disabled:o,className:`w-full bg-[var(--bg-card-alt)] border border-[var(--accent)]/30 text-[var(--text-primary)] rounded-xl py-4 px-10 text-3xl font-mono font-bold outline-none focus:border-[var(--accent)] ${o?"cursor-not-allowed opacity-60":""}`})]})}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(xe,{label:"5% 稅金",children:e.jsx("input",{"aria-label":"稅額",type:"number",value:u.taxAmount,onChange:m=>j("taxAmount",Number(m.target.value)),disabled:o,className:`input-modern bg-[var(--bg-card-alt)]/50 text-[var(--text-secondary)] font-mono ${o?"cursor-not-allowed opacity-60":""}`})}),e.jsx(xe,{label:"含稅總額",children:e.jsx("input",{"aria-label":"含稅總額",type:"number",value:u.amountGross,onChange:m=>j("amountGross",Number(m.target.value)),disabled:o,className:`input-modern font-mono font-bold ${o?"cursor-not-allowed opacity-60":""}`})})]}),e.jsx("div",{className:"h-px bg-[var(--border)]"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(xe,{label:"發票狀態",children:e.jsxs("select",{value:u.invoiceStatus,onChange:m=>j("invoiceStatus",m.target.value),className:"input-modern",children:[e.jsx("option",{value:"pending",children:"尚未開立"}),e.jsx("option",{value:"issued",children:"已開立"}),e.jsx("option",{value:"labor_receipt",children:"勞報單"}),e.jsx("option",{value:"invoice",children:"發票"})]})}),e.jsx(xe,{label:"匯款進度",children:e.jsxs("select",{value:u.paymentStatus,onChange:m=>j("paymentStatus",m.target.value),className:"input-modern",children:[e.jsx("option",{value:"unpaid",children:"尚未匯款"}),e.jsx("option",{value:"paid",children:"完成匯款"})]})}),e.jsx(xe,{label:"統一編號",className:"col-span-1",children:e.jsx("input",{"aria-label":"8碼",type:"text",value:u.invoiceTaxId,onChange:m=>j("invoiceTaxId",m.target.value),className:"input-modern font-mono",placeholder:"8碼"})}),e.jsx(xe,{label:"匯款帳號 (後五碼)",className:"col-span-1",children:e.jsx("input",{"aria-label":"5位數字",type:"text",maxLength:5,value:u.bankAccountLast5,onChange:m=>j("bankAccountLast5",m.target.value),className:"input-modern font-mono",placeholder:"5位數字"})}),e.jsx(xe,{label:"入帳日期",className:"col-span-2",children:e.jsx("input",{"aria-label":"匯款日期",type:"date",value:u.paymentDate||"",onChange:m=>j("paymentDate",m.target.value),className:"input-modern font-mono"})})]})]})]})]})]})}),e.jsxs("div",{className:"p-6 border-t border-[var(--border)] bg-[var(--bg-page)] flex justify-end gap-3",children:[e.jsx("button",{onClick:a,className:"px-6 py-2.5 rounded-xl text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-card-alt)] transition-all font-bold",children:"取消"}),!d&&e.jsxs("button",{onClick:()=>r(u),className:"px-8 py-2.5 bg-[var(--accent)] hover:bg-[var(--accent-hover)] text-[var(--button-text)] rounded-xl font-bold shadow-lg shadow-blue-500/20 flex items-center gap-2 active:scale-95 transition-all",children:[e.jsx(ea,{size:18}),"儲存變更"]})]})]})},Ho=({value:t,users:a,usedUids:r,onTypeName:s,onPick:o})=>{const[d,c]=i.useState(!1),u=(t||"").trim().toLowerCase(),f=l=>l.displayName||l.username||l.email||"",x=a.filter(l=>l.id&&!r.includes(l.id)).filter(l=>u===""||u==="新對象"?!0:f(l).toLowerCase().includes(u)||(l.email||"").toLowerCase().includes(u)).slice(0,8);return e.jsxs("div",{className:"relative",children:[e.jsx("input",{"aria-label":"輸入å
22ç¨±ï¼Œæˆ–選公司成員為經紀人",type:"text",value:t,onChange:l=>{s(l.target.value),c(!0)},onFocus:()=>c(!0),onBlur:()=>setTimeout(()=>c(!1),120),placeholder:"輸入名稱,或選公司成員為經紀人",className:"w-full bg-[var(--bg-card-alt)] border border-[var(--border)] rounded-lg px-3 py-1.5 text-sm text-[var(--text-primary)] focus:border-[var(--accent)] outline-none"}),d&&x.length>0&&e.jsx("div",{className:"absolute z-30 left-0 right-0 mt-1 bg-[var(--bg-card)] border border-[var(--border)] rounded-lg shadow-xl max-h-48 overflow-y-auto custom-scrollbar",children:x.map(l=>e.jsxs("button",{type:"button",onMouseDown:b=>{b.preventDefault(),o(l),c(!1)},className:"w-full text-left px-3 py-2 hover:bg-[var(--bg-card-alt)] transition-colors flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--text-primary)] truncate",children:f(l)}),e.jsx("span",{className:"text-11 text-[var(--success)] font-bold shrink-0",children:"設為經紀人"})]},l.id))})]})},ha=({active:t,onClick:a,icon:r,label:s})=>e.jsxs("button",{onClick:a,className:`flex-1 py-4 flex items-center justify-center gap-2 text-sm font-bold border-b-2 transition-all ${t?"border-[var(--accent)] text-[var(--accent)] bg-[var(--accent)]/5":"border-transparent text-[var(--text-muted)] hover:text-[var(--text-secondary)] hover:bg-[var(--bg-card-alt)]"}`,children:[r," ",s]}),Vo=({tableId:t,onClose:a,defaultKOLName:r,permission:s,projects:o})=>{const d=i.useId(),[c,u]=i.useState([]),[f,x]=i.useState(!0),[l,b]=i.useState(null),[y,j]=i.useState("default"),w=i.useMemo(()=>{if(y==="default")return c;const n=[...c];return y==="pending"?n.sort((p,g)=>p.isPaid!==g.isPaid?p.isPaid?1:-1:!p.paymentDate&&!g.paymentDate?0:p.paymentDate?g.paymentDate?g.paymentDate.localeCompare(p.paymentDate):-1:1):y==="serial"?n.sort((p,g)=>(parseInt(p.serialNumber)||0)-(parseInt(g.serialNumber)||0)):y==="paymentDate"?n.sort((p,g)=>!p.paymentDate&&!g.paymentDate?0:p.paymentDate?g.paymentDate?g.paymentDate.localeCompare(p.paymentDate):-1:1):y==="netAmount"&&n.sort((p,g)=>(g.netAmount||0)-(p.netAmount||0)),n},[c,y]),[v,T]=i.useState(null),[S,k]=i.useState(null),[A,D]=i.useState(!1),N=(s==null?void 0:s.edit)===!0;i.useEffect(()=>{R()},[t]);const R=async()=>{x(!0);try{const n=await La(t);u(n)}catch(n){console.error(n)}finally{x(!1)}},I=()=>{const n=new Date;return new Intl.DateTimeFormat("zh-TW",{timeZone:"Asia/Taipei",year:"numeric",month:"2-digit",day:"2-digit"}).format(n).replace(/\//g,"-")},m=n=>{if(!Number.isInteger(n.amountPayable))return`應付金額含小數: ${n.amountPayable}`;if(!Number.isInteger(n.healthTax||0))return`健保費含小數: ${n.healthTax}`;if(!Number.isInteger(n.professionalTax||0))return`執業稅含小數: ${n.professionalTax}`;if(!Number.isInteger(n.netAmount))return`實領金額含小數: ${n.netAmount}`;const p=n.amountPayable-(n.healthTax||0)-(n.professionalTax||0);if(Math.abs(p-n.netAmount)>0)return`實領金額不符 (差異: ${Math.abs(p-n.netAmount)})`;if(n.id){const g=o.filter(P=>P.remunerationId===n.id);if(g.length>0){const P=g.reduce((E,z)=>{const re=(z.splitShares||[]).find(C=>C.name==="KOL");if(!re)return E;if(re.isAutoCalc===!1&&re.amount!==void 0)return E+re.amount;const me=z.amountTotal-z.costExtra;return E+(Math.round(me*(re.percentage/100))+(Number(re.cost)||0))},0);if(Math.abs(P-n.amountPayable)>0)return`金額與來源不符 (來源合計: ${P} vs 此單: ${n.amountPayable})`}}return null},_=n=>{if(!n.isAutoCalc)return n;const p=Number(n.amountPayable)||0,g=p>=$a?Math.round(p*Ma):0,P=p>=ls?Math.round(p*Yt["9A"]):0;return{...n,healthTax:g,professionalTax:P,netAmount:p-g-P}},L=async n=>{if(n.preventDefault(),!l)return;let p;l.isAutoCalc?p=_(l):p=l;try{p.id?await Bt(p.id,p):await Ft({...p,tableId:t}),b(null),R()}catch(g){console.error(g)}},$=async()=>{if(!(!S||!S.id))try{const n={...S,isPaid:!0,paymentDate:I()};await Bt(S.id,n),k(null),R()}catch(n){console.error(n)}},B=async()=>{if(!(!v||!v.id)){D(!0);try{const p=(await Vr(v.id)).map(g=>yt(g.id,{remunerationId:null,remunerationSerial:null}));await Promise.all(p),await Gr(v.id),T(null),R()}catch(n){console.error(n)}finally{D(!1)}}},U=()=>{const p=((c.length>0?Math.max(...c.map(g=>parseInt(g.serialNumber)||0)):0)+1).toString();b({tableId:t,serialNumber:p,kolName:r||"",amountPayable:0,healthTax:0,professionalTax:0,netAmount:0,isPaid:!1,paymentDate:null,link:"",isAutoCalc:!0,projectSerials:[],month:new Date().toISOString().slice(0,7)})};return e.jsxs(pe,{isOpen:!0,onClose:a,zIndex:60,maxWidth:"max-w-[1440px]",contentClassName:"bg-[var(--bg-page)] border border-[var(--border)] w-[calc(100vw-2rem)] h-[85vh] rounded-[32px] shadow-2xl flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"p-6 border-b border-[var(--border)] bg-[var(--bg-card)] flex justify-between items-center shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-12 h-12 bg-[var(--success)]/10 rounded-2xl flex items-center justify-center text-[var(--success)] border border-[var(--success)]/20",children:e.jsx(Rt,{size:24})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-bold text-[var(--text-primary)] tracking-tight",children:"專案勞報單管理"}),e.jsx("p",{className:"text-xs text-[var(--text-muted)] font-medium mt
22-0.5",children:"針對此商案的 KOL 款項、稅金與支付進度進行對帳"})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 h-10 bg-[var(--bg-card)] border border-[var(--border)] rounded-xl",children:[e.jsx(ta,{size:14,className:"text-[var(--text-muted)]"}),e.jsxs("select",{"aria-label":"排序方式",value:y,onChange:n=>j(n.target.value),className:"bg-transparent text-xs font-bold text-[var(--text-primary)] focus:outline-none cursor-pointer",children:[e.jsx("option",{value:"default",className:"bg-[var(--bg-card)]",children:"預設(不排序)"}),e.jsx("option",{value:"pending",className:"bg-[var(--bg-card)]",children:"待結帳優先(未付+新→舊)"}),e.jsx("option",{value:"serial",className:"bg-[var(--bg-card)]",children:"勞報編號(小→大)"}),e.jsx("option",{value:"paymentDate",className:"bg-[var(--bg-card)]",children:"入帳日期(新→舊)"}),e.jsx("option",{value:"netAmount",className:"bg-[var(--bg-card)]",children:"實領金額(大→小)"})]})]}),N?e.jsxs("button",{onClick:U,className:"flex items-center gap-2 px-5 py-2.5 bg-[var(--accent)] hover:bg-[var(--accent-hover)] text-[var(--button-text)] rounded-xl text-xs font-bold transition-all shadow-lg shadow-blue-900/20 active:scale-95 h-10",children:[e.jsx(ze,{size:16})," 新增領款紀錄"]}):e.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 bg-[var(--bg-card-alt)] text-[var(--text-muted)] rounded-xl text-xs font-bold h-10 border border-[var(--border)]",children:[e.jsx(Oe,{size:14})," 僅有檢視權限"]}),e.jsx("button",{onClick:a,className:"p-2.5 hover:bg-[var(--bg-card-alt)] rounded-xl text-[var(--text-muted)] hover:text-[var(--text-primary)] transition-all border border-[var(--border)]",children:e.jsx(ye,{size:20})})]})]}),e.jsx("div",{className:"flex-1 overflow-auto bg-[var(--bg-page)] custom-scrollbar",children:e.jsx("div",{className:"p-6",children:e.jsx("div",{className:"bg-[var(--bg-card)] rounded-2xl border border-[var(--border)] shadow-xl min-w-[1100px]",children:e.jsxs("table",{className:"w-full text-center border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-[var(--bg-card-alt)] border-b-2 border-[var(--border)]",children:[e.jsx("th",{className:"sticky top-0 z-10 shadow-lg shadow-black/50 py-3 px-4 text-13 font-bold text-[var(--text-muted)] uppercase tracking-widest w-24 bg-[var(--bg-card-alt)] rounded-tl-2xl",children:"勞報編號"}),e.jsx("th",{className:"sticky top-0 z-10 shadow-lg shadow-black/50 py-3 px-4 text-13 font-bold text-[var(--text-secondary)] uppercase tracking-widest text-left bg-[var(--bg-card-alt)]",children:"領款人 (KOL)"}),e.jsx("th",{className:"sticky top-0 z-10 shadow-lg shadow-black/50 py-3 px-4 text-13 font-bold text-[var(--id-purple)] uppercase tracking-widest w-32 bg-[var(--bg-card-alt)]",children:"來源編號"}),e.jsx("th",{className:"sticky top-0 z-10 shadow-lg shadow-black/50 py-3 px-4 text-13 font-bold text-[var(--accent)] uppercase tracking-widest w-32 bg-[var(--bg-card-alt)]",children:"應付總額"}),e.jsx("th",{className:"sticky top-0 z-10 shadow-lg shadow-black/50 py-3 px-2 text-13 font-bold text-[var(--error)]/70 uppercase tracking-widest w-28 bg-[var(--bg-card-alt)]",children:"二代健保 (2.11%)"}),e.jsx("th",{className:"sticky top-0 z-10 shadow-lg shadow-black/50 py-3 px-2 text-13 font-bold text-[var(--error)]/70 uppercase tracking-widest w-28 bg-[var(--bg-card-alt)]",children:"扣繳稅額 (10%)"}),e.jsx("th",{className:"sticky top-0 z-10 shadow-lg shadow-black/50 py-3 px-4 text-13 font-bold text-[var(--success)] uppercase tracking-widest w-32 bg-[var(--bg-card-alt)]",children:"實領金額"}),e.jsx("th",{className:"sticky top-0 z-10 shadow-lg shadow-black/50 py-3 px-4 text-13 font-bold text-[var(--text-secondary)] uppercase tracking-widest w-32 bg-[var(--bg-card-alt)]",children:"支付狀態"}),e.jsx("th",{className:"sticky top-0 z-10 shadow-lg shadow-black/50 py-3 px-4 text-13 font-bold text-[var(--text-secondary)] uppercase tracking-widest w-32 bg-[var(--bg-card-alt)]",children:"入帳日期"}),e.jsx("th",{className:"sticky top-0 z-10 shadow-lg shadow-black/50 py-3 px-4 text-13 font-bold text-[var(--text-muted)] uppercase tracking-widest w-32 bg-[var(--bg-card-alt)] rounded-tr-2xl",children:"操作"})]})}),e.jsx("tbody",{className:"divide-y divide-[var(--border)] nk-list nk-zebra",children:f?e.jsx("tr",{children:e.jsx("td",{colSpan:10,className:"py-20 text-center text-[var(--text-muted)] animate-pulse text-sm",children:"載入中..."})}):w.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:10,className:"py-20 text-center text-[var(--text-muted)] italic text-sm",children:"目前尚無領款紀錄"})}):w.map(n=>{const p=o.find(P=>P.remunerationId===n.id),g=n.month||(p==null?void 0:p.month);return e.jsxs("tr",{className:"hover:bg-[var(--bg-card-alt)] transition-colors group",children:[e.jsxs("td",{className:"py-4 px-4 font-mono text-12 text-[var(--text-muted)]",children:["#",n.serialNumber||"---",g&&e.jsx("div",{className:"text-11 text-[var(--text-muted)] font-bold mt-1 bg-[var(--bg-card-alt)] px-1.5 py-0.5 rounded border border-[var(--border)] w-fit mx-auto",children:g})]}),e.jsx("td",{className:"py-4 px-4 text-sm font-bold text-[var(--text-primary)] text-left",children:e.jsxs("div",{className:"flex items-center gap-2",children:[n.kolName,m(n)&&e.jsx("span",{title:m(n)||"",className:"cursor-help",children:e.jsx(Mt,{size:14,className:"text-[var(--warning)]"})})]})}),e.jsx("td",{className:"py-4 px-4",children:e.jsx("div",{className:"flex flex-col items-start gap-1",children:n.projectSerials&&n.projectSerials.length>0?n.projectSerials.map(P=>{const E=o.find(z=>String(z.serialNumber)===P);return e.jsxs("div",{className:"flex items-center gap-1.5 max-w-[240px]",children:[e.jsxs("span",{className:"text-13 font-mono bg-[var(--id-purple)]/10 text-[var(--id-purple)] px-1.5 py-0.5 rounded border border-[var(--id-purple)]/20 shrink-0",children:["#",P]}),E&&e.jsx("span",{className:"text-13 text-[var(--text-secondary)] truncate",title:E.projectName,children:E.projectName})]},P)}):e.jsx("span",{className:"text-[var(--text-muted)]",children:"-"})})}),e.jsxs("td",{className:"py-4 px-4 text-sm font-mono font-bold text-[var(--accent)]",children:["NT$",n.amountPayable.toLocaleStr
22ing()]}),e.jsxs("td",{className:"py-4 px-2 text-xs font-mono text-[var(--error)]/80",children:["-",n.healthTax.toLocaleString()]}),e.jsxs("td",{className:"py-4 px-2 text-xs font-mono text-[var(--error)]/80",children:["-",n.professionalTax.toLocaleString()]}),e.jsxs("td",{className:"py-4 px-4 text-base font-mono font-bold text-[var(--success)]",children:["NT$",n.netAmount.toLocaleString()]}),e.jsx("td",{className:"py-4 px-4",children:e.jsx("div",{className:"flex justify-center",children:n.isPaid?e.jsxs("span",{className:"flex items-center gap-1.5 px-2.5 py-0.5 rounded bg-[var(--success)]/10 text-[var(--success)] border border-[var(--success)]/20 text-12 font-bold",children:[e.jsx(Ue,{size:12})," 已結清"]}):e.jsxs("span",{className:"flex items-center gap-1.5 px-2.5 py-0.5 rounded bg-[var(--error)]/10 text-[var(--error)] border border-[var(--error)]/20 text-12 font-bold",children:[e.jsx(Ia,{size:12})," 未支付"]})})}),e.jsx("td",{className:"py-4 px-4 font-mono text-13 text-[var(--text-muted)]",children:n.paymentDate||"-"}),e.jsx("td",{className:"py-4 px-4 text-center",children:e.jsxs("div",{className:"flex justify-center gap-1",children:[N&&!n.isPaid&&e.jsx("button",{onClick:()=>k(n),className:"p-1.5 text-[var(--text-muted)] hover:text-[var(--success)] hover:bg-[var(--success)]/10 rounded-lg transition-all",title:"快速標記已支付",children:e.jsx(Ue,{size:16})}),N&&e.jsx("button",{onClick:()=>b(n),className:"p-1.5 text-[var(--text-muted)] hover:text-[var(--accent)] hover:bg-[var(--accent)]/10 rounded-lg transition-all",title:"編輯",children:e.jsx(qe,{size:16})}),N&&e.jsx("button",{onClick:()=>T(n),className:"p-1.5 text-[var(--text-muted)] hover:text-[var(--error)] hover:bg-[var(--error)]/10 rounded-lg transition-all",title:"刪除",children:e.jsx(it,{size:16})}),!N&&e.jsx("span",{className:"text-12 text-[var(--text-muted)] italic",children:"僅檢視"})]})})]},n.id)})})]})})})}),e.jsxs("div",{className:"p-6 bg-[var(--bg-card)] border-t border-[var(--border)] flex items-center justify-between shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-8",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-12 text-[var(--text-muted)] font-bold uppercase tracking-wider mb-1",children:"本案應付總計 (未稅)"}),e.jsxs("p",{className:"text-xl font-bold text-[var(--text-primary)] font-mono leading-none",children:["NT$",c.reduce((n,p)=>n+p.amountPayable,0).toLocaleString()]})]}),e.jsx("div",{className:"w-px h-8 bg-[var(--border)]"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-12 text-[var(--text-muted)] font-bold uppercase tracking-wider mb-1",children:"本案實領總計"}),e.jsxs("p",{className:"text-xl font-bold text-[var(--success)] font-mono leading-none",children:["NT$",c.reduce((n,p)=>n+p.netAmount,0).toLocaleString()]})]})]}),e.jsx("p",{className:"text-12 text-[var(--text-muted)] font-bold italic select-none",children:"此表資料僅與該商案關聯,不計入年度勞報總表"})]}),e.jsx(pe,{isOpen:!!l,onClose:()=>b(null),zIndex:70,maxWidth:"max-w-lg",contentClassName:"bg-[var(--bg-card)] border border-[var(--border)] w-full rounded-3xl shadow-2xl overflow-hidden",children:e.jsxs("form",{onSubmit:L,children:[e.jsxs("div",{className:"p-6 border-b border-[var(--border)] bg-[var(--bg-card-alt)] flex justify-between items-center",children:[e.jsxs("h4",{className:"font-bold text-[var(--text-primary)] flex items-center gap-2",children:[l!=null&&l.id?e.jsx(qe,{size:18,className:"text-[var(--accent)]"}):e.jsx(ze,{size:18,className:"text-[var(--success)]"}),l!=null&&l.id?"編輯領款資料":"新增領款紀錄"]}),e.jsx("button",{type:"button",onClick:()=>b(null),className:"text-[var(--text-muted)] hover:text-[var(--text-primary)] transition-all",children:e.jsx(ye,{size:20})})]}),e.jsxs("div",{className:"p-8 space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:`${d}-0`,className:"text-12 font-bold text-[var(--text-muted)] uppercase tracking-widest ml-1",children:"KOL 名稱"}),e.jsx("input",{id:`${d}-0`,required:!0,type:"text",value:(l==null?void 0:l.kolName)||"",onChange:n=>l&&b({...l,kolName:n.target.value}),className:"input-modern bg-[var(--bg-card-alt)]",placeholder:"領款人名稱"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("span",{id:`${d}-g0`,className:"text-12 font-bold text-[var(--text-muted)] uppercase tracking-widest ml-1",children:"勞報編號"}),e.jsxs("div",{role:"group","aria-labelledby":`${d}-g0`,className:"grid grid-cols-2 gap-2",children:[e.jsx("input",{"aria-label":"自動產生",disabled:!0,type:"text",value:(l==null?void 0:l.serialNumber)||"",className:"input-modern bg-[var(--bg-card)] text-[var(--text-muted)] font-mono curs
22or-not-allowed border-[var(--border)]",placeholder:"自動產生"}),e.jsx("input",{"aria-label":"執行月份",type:"month",value:(l==null?void 0:l.month)||"",onChange:n=>l&&b({...l,month:n.target.value}),className:"input-modern bg-[var(--bg-card-alt)] font-mono text-xs"})]})]})]}),e.jsxs("div",{className:"p-4 bg-[var(--bg-card-alt)] rounded-2xl border border-[var(--accent)]/20",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsx("span",{className:"text-12 font-bold text-[var(--accent)] uppercase tracking-widest",children:"應付總額 (未稅)"}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[e.jsx("input",{type:"checkbox",checked:(l==null?void 0:l.isAutoCalc)||!1,onChange:n=>l&&b({...l,isAutoCalc:n.target.checked}),className:"checkbox-modern"}),e.jsx("span",{className:"text-12 font-bold text-[var(--text-secondary)]",children:"自動計算稅金"})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"absolute left-4 top-1/2 -translate-y-1/2 text-[var(--accent)] font-mono font-bold",children:"$"}),e.jsx("input",{"aria-label":"0",required:!0,type:"number",value:(l==null?void 0:l.amountPayable)||"",onChange:n=>l&&b({...l,amountPayable:Number(n.target.value)}),className:"w-full bg-[var(--bg-card)] border border-[var(--accent)]/30 text-[var(--text-primary)] rounded-xl py-3 px-10 text-2xl font-mono font-bold outline-none focus:border-[var(--accent)]",placeholder:"0"})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:`${d}-1`,className:"text-12 font-bold text-[var(--text-muted)] uppercase tracking-widest ml-1",children:"二代健保 (2.11%)"}),e.jsx("input",{id:`${d}-1`,type:"number",disabled:l==null?void 0:l.isAutoCalc,value:l?l.isAutoCalc?_(l).healthTax:l.healthTax:"",onChange:n=>l&&b({...l,healthTax:Number(n.target.value)}),className:"input-modern bg-[var(--bg-card-alt)] text-xs font-mono disabled:opacity-50"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:`${d}-2`,className:"text-12 font-bold text-[var(--text-muted)] uppercase tracking-widest ml-1",children:"扣繳稅額 (10%)"}),e.jsx("input",{id:`${d}-2`,type:"number",disabled:l==null?void 0:l.isAutoCalc,value:l?l.isAutoCalc?_(l).professionalTax:l.professionalTax:"",onChange:n=>l&&b({...l,professionalTax:Number(n.target.value)}),className:"input-modern bg-[var(--bg-card-alt)] text-xs font-mono disabled:opacity-50"})]}),e.jsxs("div",{className:"space-y-1.5 text-center",children:[e.jsx("label",{htmlFor:`${d}-3`,className:"text-12 font-bold text-[var(--success)] uppercase tracking-widest block",children:"實領金額"}),l!=null&&l.isAutoCalc?e.jsxs("div",{className:"h-10 flex items-center justify-center font-mono font-bold text-[var(--success)] bg-[var(--success)]/5 rounded-xl border border-[var(--success)]/10",children:["$",_(l).netAmount.toLocaleString()]}):e.jsx("input",{id:`${d}-3`,type:"number",value:(l==null?void 0:l.netAmount)||"",onChange:n=>l&&b({...l,netAmount:Number(n.target.value)}),className:"input-modern bg-[var(--bg-card-alt)] text-sm font-mono text-[var(--success)] text-center"})]})]}),e.jsx("div",{className:"h-px bg-[var(--border)] my-4"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("span",{className:"text-12 font-bold text-[var(--text-muted)] uppercase tracking-widest ml-1",children:"支付狀態"}),e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer p-3 bg-[var(--bg-card-alt)] rounded-xl border border-[var(--border)] hover:border-[var(--border-hover)] transition-all h-10",children:[e.jsx("input",{type:"checkbox",checked:(l==null?void 0:l.isPaid)||!1,onChange:n=>{if(!l)return;const p=n.target.checked;b({...l,isPaid:p,paymentDate:p&&!l.paymentDate?I():l.paymentDate})},className:"checkbox-modern"}),e.jsx("span",{className:"text-xs font-bold text-[var(--text-primary)] tracking-wide",children:"標記為已支付"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:`${d}-4`,className:"text-12 font-bold text-[var(--text-muted)] uppercase tracking-widest ml-1",children:"入帳 / 預定日期"}),e.jsx("input",{id:`${d}-4`,type:"date",value:(l==null?void 0:l.paymentDate)||"",onChange:n=>l&&b({...l,paymentDate:n.target.value}),className:"input-modern bg-[var(--bg-card-alt)] font-mono text-xs h-10"})]})]})]}),e.jsxs("div",{className:"p-6 bg-[var(--bg-card-alt)] border-t border-[var(--border)] flex gap-3",children:[e.jsx("button",{type:"button",onClick:()=>b(null),className:"flex-1 py-3 rounded-xl text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-card-alt)] transition-all font-bold text-sm",children:"取消"}),e.jsxs("button",{type:"submit",className:"flex-1 py-3 bg-[var(--accent)] hover:bg-[var(--accent-hover)] text-[var(--button-text)] rounded-xl font-bold shadow-lg shadow-blue-500/20 transition-all flex items-center justify-center gap-2 active:scale-95",children:[e.jsx(ea,{size:18}),"確認儲存"]}
22)]})]})}),e.jsx(pe,{isOpen:!!S,onClose:()=>k(null),zIndex:80,maxWidth:"max-w-md",contentClassName:"bg-[var(--bg-card)] border border-[var(--success)]/30 p-10 rounded-[32px] w-full shadow-2xl",children:e.jsxs("div",{className:"flex flex-col items-center text-center gap-6",children:[e.jsx("div",{className:"w-16 h-16 bg-[var(--success)]/10 rounded-full flex items-center justify-center text-[var(--success)] border border-[var(--success)]/20",children:e.jsx(Ue,{size:32})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-xl font-bold text-[var(--text-primary)]",children:"確認支付款項?"}),e.jsxs("div",{className:"text-sm text-[var(--text-secondary)] leading-relaxed px-4",children:["將標記 ",e.jsx("span",{className:"text-[var(--text-primary)] font-bold",children:S==null?void 0:S.kolName})," 的款項為已支付,並自動帶入今日日期 (",e.jsx("span",{className:"text-[var(--accent)] font-mono font-bold",children:I()}),")。"]})]}),e.jsxs("div",{className:"flex gap-4 w-full mt-2",children:[e.jsx("button",{onClick:()=>k(null),className:"flex-1 py-3 bg-[var(--bg-card-alt)] text-[var(--text-secondary)] rounded-2xl font-bold text-sm hover:bg-[var(--bg-card-alt)] transition-all",children:"取消"}),e.jsx("button",{onClick:$,className:"flex-1 py-3 bg-[var(--success)] text-[var(--button-text)] rounded-2xl font-bold text-sm hover:bg-[var(--success)] shadow-lg shadow-green-900/20 active:scale-95 transition-all",children:"確認支付"})]})]})}),e.jsx(pe,{isOpen:!!v,onClose:()=>T(null),zIndex:80,maxWidth:"max-w-md",contentClassName:"bg-[var(--bg-card)] border border-[var(--error)]/30 p-10 rounded-[32px] w-full shadow-2xl",children:e.jsxs("div",{className:"flex flex-col items-center text-center gap-6",children:[e.jsx("div",{className:"w-16 h-16 rounded-full bg-[var(--error)]/10 flex items-center justify-center text-[var(--error)] border border-[var(--success)]/20",children:A?e.jsx(be,{size:32,className:"animate-spin"}):e.jsx(it,{size:32})}),e.jsxs("div",{className:"space-y-4 w-full",children:[e.jsx("h3",{className:"text-xl font-bold text-[var(--text-primary)]",children:"確定要刪除?"}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-[var(--text-secondary)] text-sm leading-relaxed",children:"此動作將永久移除此筆勞報紀錄。"}),(v==null?void 0:v.projectSerials)&&v.projectSerials.length>0&&e.jsxs("div",{className:"bg-[var(--id-orange)]/10 border border-[var(--id-orange)]/20 p-4 rounded-2xl flex gap-3 items-start text-left",children:[e.jsx(Mt,{size:18,className:"text-[var(--id-orange)] shrink-0 mt-0.5"}),e.jsxs("p",{className:"text-13 text-[var(--id-orange)] leading-tight font-medium",children:["注意:刪除後將會同步還原關聯專案 (",e.jsx("span",{className:"font-mono text-[var(--text-primary)] font-bold",children:v.projectSerials.join(", ")}),") 的結帳鎖定狀態。"]}
22)]})]})]}),e.jsxs("div",{className:"flex gap-4 w-full mt-2",children:[e.jsx("button",{disabled:A,onClick:()=>T(null),className:"flex-1 py-3 bg-[var(--bg-card-alt)] text-[var(--text-secondary)] rounded-2xl font-bold text-sm hover:bg-[var(--bg-card-alt)] transition-all disabled:opacity-50",children:"取消"}),e.jsx("button",{disabled:A,onClick:B,className:"flex-1 py-3 bg-[var(--error)] text-[var(--button-text)] rounded-2xl font-bold text-sm hover:bg-[var(--error)] shadow-lg shadow-red-900/20 active:scale-95 transition-all disabled:opacity-50",children:A?"處理中...":"確認刪除並還原"})]})]})})]})},Go=({tableId:t,onClose:a,defaultKOLName:r,permission:s,projects:o})=>{const d=i.useId(),[c,u]=i.useState([]),[f,x]=i.useState(!0),[l,b]=i.useState(null),[y,j]=i.useState("default"),w=i.useMemo(()=>{if(y==="default")return c;const n=[...c];return y==="pending"?n.sort((p,g)=>p.isPaid!==g.isPaid?p.isPaid?1:-1:!p.paymentDate&&!g.paymentDate?0:p.paymentDate?g.paymentDate?g.paymentDate.localeCompare(p.paymentDate):-1:1):y==="serial"?n.sort((p,g)=>(parseInt(p.serialNumber)||0)-(parseInt(g.serialNumber)||0)):y==="paymentDate"?n.sort((p,g)=>!p.paymentDate&&!g.paymentDate?0:p.paymentDate?g.paymentDate?g.paymentDate.localeCompare(p.paymentDate):-1:1):y==="netAmount"&&n.sort((p,g)=>(g.netAmount||0)-(p.netAmount||0)),n},[c,y]),[v,T]=i.useState(null),[S,k]=i.useState(null),[A,D]=i.useState(!1),N=(s==null?void 0:s.edit)===!0;i.useEffect(()=>{R()},[t]);const R=async()=>{x(!0);try{const p=(await La(t)).filter(g=>g.type==="b2b");u(p)}catch(n){console.error(n)}finally{x(!1)}},I=()=>{const n=new Date;return new Intl.DateTimeFormat("zh-TW",{timeZone:"Asia/Taipei",year:"numeric",month:"2-digit",day:"2-digit"}).format(n).replace(/\//g,"-")},m=n=>{if(!Number.isInteger(n.amountPayable))return`應付金額含小數: ${n.amountPayable}`;if(!Number.isInteger(n.professionalTax||0))return`稅金含小數: ${n.professionalTax}`;if(!Number.isInteger(n.netAmount))return`實領金額含小數: ${n.netAmount}`;const p=Math.round(n.amountPayable*.05),g=n.amountPayable+p;if(Math.abs(g-n.netAmount)>0)return`實領金額不符 (差異: ${Math.abs(g-n.netAmount)})`;if(n.id){const P=o.filter(E=>E.remunerationId===n.id);if(P.length>0){const E=P.reduce((z,K)=>{const me=(K.splitShares||[]).find(ee=>ee.name==="KOL");if(!me)return z;if(me.isAutoCalc===!1&&me.amount!==void 0)return z+me.amount;const C=K.amountTotal-K.costExtra;return z+(Math.round(C*(me.percentage/100))+(Number(me.cost)||0))},0);if(Math.abs(E-n.amountPayable)>0)return`金額與來源不符 (來源合計: ${E} vs 此單: ${n.amountPayable})`}}return null},_=n=>{if(!n.isAutoCalc)return n;const p=Number(n.amountPayable)||0,g=Math.round(p*.05);return{...n,healthTax:0,professionalTax:g,netAmount:p+g}},L=async n=>{if(n.preventDefault(),!l)return;const p=_(l);try{p.id?await Bt(p.id,p):await Ft({...p,tableId:t,type:"b2b"}),b(null),R()}catch(g){console.error(g)}},$=async()=>{if(!(!S||!S.id))try{const n={...S,isPaid:!0,paymentDate:I()};await Bt(S.id,n),k(null),R()}catch(n){console.error(n)}},B=async()=>{if(!(!v||!v.id)){D(!0);try{const p=(await Vr(v.id)).map(g=>yt(g.id,{remunerationId:null,remunerationSerial:null}));await Promise.all(p),await Gr(v.id),T(null),R()}catch(n){console.error(n)}finally{D(!1)}}},U=()=>{const p=((c.length>0?Math.max(...c.map(g=>parseInt(g.serialNumber)||0)):0)+1).toString();b({tableId:t,serialNumber:p,kolName:r||"",amountPayable:0,healthTax:0,professionalTax:0,netAmount:0,isPaid:!1,paymentDate:null,link:"",isAutoCalc:!0,projectSerials:[],type:"b2b",month:new Date().toISOString().slice(0,7)})};return e.jsxs(pe,{isOpen:!0,onClose:a,zIndex:60,maxWidth:"max-w-[1440px]",contentClassName:"bg-[var(--bg-page)] border border-[var(--border)] w-[calc(100vw-2rem)] h-[85vh] rounded-[32px] shadow-2xl flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"p-6 border-b border-[var(--border)] bg-[var(--bg-card)] flex justify-between items-center shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-12 h-12 bg-[var(--id-orange)]/10 rounded-2xl flex items-center justify-center text-[var(--id-orange)] border border-[var(--id-orange)]/20",children:e.jsx(st,{size:24})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-bold text-[var(--text-primary)] tracking-tight",children:"B2B 對帳管理"}),e.jsx("p",{className:"text-xs text-[var(--text-muted)] font-medium mt
22-0.5",children:"針對此商案的 B2B 款項進行對帳(固定 5% 扣稅)"})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 h-10 bg-[var(--bg-card)] border border-[var(--border)] rounded-xl",children:[e.jsx(ta,{size:14,className:"text-[var(--text-muted)]"}),e.jsxs("select",{"aria-label":"排序方式",value:y,onChange:n=>j(n.target.value),className:"bg-transparent text-xs font-bold text-[var(--text-primary)] focus:outline-none cursor-pointer",children:[e.jsx("option",{value:"default",className:"bg-[var(--bg-card)]",children:"預設(不排序)"}),e.jsx("option",{value:"pending",className:"bg-[var(--bg-card)]",children:"待結帳優先(未付+新→舊)"}),e.jsx("option",{value:"serial",className:"bg-[var(--bg-card)]",children:"B2B 編號(小→大)"}),e.jsx("option",{value:"paymentDate",className:"bg-[var(--bg-card)]",children:"入帳日期(新→舊)"}),e.jsx("option",{value:"netAmount",className:"bg-[var(--bg-card)]",children:"實領金額(大→小)"})]})]}),N?e.jsxs("button",{onClick:U,className:"flex items-center gap-2 px-5 py-2.5 bg-orange-600 hover:bg-orange-500 text-white rounded-xl text-xs font-bold transition-all shadow-lg shadow-orange-900/20 active:scale-95 h-10",children:[e.jsx(ze,{size:16})," 新增 B2B 紀錄"]}):e.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 bg-[var(--bg-card-alt)] text-[var(--text-muted)] rounded-xl text-xs font-bold h-10 border border-[var(--border)]",children:[e.jsx(Oe,{size:14})," 僅有檢視權限"]}),e.jsx("button",{onClick:a,className:"p-2.5 hover:bg-[var(--bg-card-alt)] rounded-xl text-[var(--text-muted)] hover:text-[var(--text-primary)] transition-all border border-[var(--border)]",children:e.jsx(ye,{size:20})})]})]}),e.jsx("div",{className:"flex-1 overflow-auto bg-[var(--bg-page)] custom-scrollbar",children:e.jsx("div",{className:"p-6",children:e.jsx("div",{className:"bg-[var(--bg-card)] rounded-2xl border border-[var(--border)] shadow-xl min-w-[900px]",children:e.jsxs("table",{className:"w-full text-center border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-[var(--bg-card-alt)] border-b-2 border-[var(--border)]",children:[e.jsx("th",{className:"sticky top-0 z-10 shadow-lg shadow-black/50 py-3 px-3 text-13 font-bold text-[var(--text-muted)] uppercase tracking-widest w-20 text-center bg-[var(--bg-card-alt)] rounded-tl-2xl",children:"B2B 編號"}),e.jsx("th",{className:"sticky top-0 z-10 shadow-lg shadow-black/50 py-3 px-3 text-13 font-bold text-[var(--text-secondary)] uppercase tracking-widest text-left w-32 bg-[var(--bg-card-alt)]",children:"領款人 (KOL)"}),e.jsx("th",{className:"sticky top-0 z-10 shadow-lg shadow-black/50 py-3 px-3 text-13 font-bold text-[var(--id-purple)] uppercase tracking-widest text-left bg-[var(--bg-card-alt)]",children:"來源編號"}),e.jsx("th",{className:"sticky top-0 z-10 shadow-lg shadow-black/50 py-3 px-3 text-13 font-bold text-[var(--accent)] uppercase tracking-widest w-28 text-center bg-[var(--bg-card-alt)]",children:"應付總額"}),e.jsx("th",{className:"sticky top-0 z-10 shadow-lg shadow-black/50 py-3 px-2 text-13 font-bold text-[var(--id-orange)] uppercase tracking-widest w-20 text-center bg-[var(--bg-card-alt)]",children:"5% 稅金"}),e.jsx("th",{className:"sticky top-0 z-10 shadow-lg shadow-black/50 py-3 px-3 text-13 font-bold text-[var(--success)] uppercase tracking-widest w-32 text-center bg-[var(--bg-card-alt)]",children:"實領金額 (含稅)"}),e.jsx("th",{className:"sticky top-0 z-10 shadow-lg shadow-black/50 py-3 px-3 text-13 font-bold text-[var(--text-secondary)] uppercase tracking-widest w-20 text-center bg-[var(--bg-card-alt)]",children:"支付狀態"}),e.jsx("th",{className:"sticky top-0 z-10 shadow-lg shadow-black/50 py-3 px-3 text-13 font-bold text-[var(--text-secondary)] uppercase tracking-widest w-24 text-center bg-[var(--bg-card-alt)]",children:"入帳日期"}),e.jsx("th",{className:"sticky top-0 z-10 shadow-lg shadow-black/50 py-3 px-3 text-13 font-bold text-[var(--text-muted)] uppercase tracking-widest w-16 text-center bg-[var(--bg-card-alt)] rounded-tr-2xl",children:"操作"})]})}),e.jsx("tbody",{className:"divide-y divide-[var(--border)] nk-list nk-zebra",children:f?e.jsx("tr",{children:e.jsx("td",{colSpan:9,className:"py-20 text-center text-[var(--text-muted)] animate-pulse text-sm",children:"載入中..."})}):w.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:9,className:"py-20 text-center text-[var(--text-muted)] italic text-sm",children:"目前尚無 B2B 結帳紀錄"})}):w.map(n=>{const p=o.find(P=>P.remunerationId===n.id),g=n.month||(p==null?void 0:p.month);return e.jsxs("tr",{className:"hover:bg-[var(--bg-card-alt)] transition-colors group",children:[e.jsxs("td",{className:"py-4 px-3 font-mono text-12 text-[var(--text-muted)] text-center",children:["#",n.serialNumber||"---",g&&e.jsx("div",{className:"text-11 text-[var(--text-muted)] font-bold mt-1 bg-[var(--bg-card-alt)] px-1.5 py-0.5 rounded border border-[var(--border)] w-fit mx-auto",children:g})]}),e.jsx("td",{className:"py-4 px-3 text-sm font-bold text-[var(--text-primary)] text-left",children:e.jsxs("div",{className:"flex items-center gap-2",children:[n.kolName,m(n)&&e.jsx("span",{title:m(n)||"",className:"cursor-help",children:e.jsx(Mt,{size:14,className:"text-[var(--warning)]"})})]})}),e.jsx("td",{className:"py-4 px-3",children:e.jsx("div",{className:"flex flex-col items-start gap-1",children:n.projectSerials&&n.projectSerials.length>0?n.projectSerials.map(P=>{const E=o.find(z=>String(z.serialNumber)===P);return e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("span",{className:"text-13 font-mono bg-[var(--id-purple)]/10 text-[var(--id-purple)] px-1.5 py-0.5 rounded border border-[var(--id-purple)]/20 shrink-0",children:["#",P]}),E&&e.jsx("span",{className:"text-13 text-[var(--text-secondary)] truncate",title:E.projectName,children:E.projectName})]},P)}):e.jsx("span",{className:"text-[var(--text-muted)]",children:"-"})})}),e.jsxs("td",{className:"py-4 px-3 text-sm font-mono font-bold text-[var(--accent)] text-center",children:["NT$",n.amountPayable.toLocaleStr
22ing()]}),e.jsxs("td",{className:"py-4 px-2 text-xs font-mono text-[var(--id-orange)] text-center",children:["+",n.professionalTax.toLocaleString()]}),e.jsxs("td",{className:"py-4 px-3 text-base font-mono font-bold text-[var(--success)] text-center",children:["NT$",n.netAmount.toLocaleString()]}),e.jsx("td",{className:"py-4 px-3",children:e.jsx("div",{className:"flex justify-center",children:n.isPaid?e.jsxs("span",{className:"flex items-center gap-1.5 px-2.5 py-0.5 rounded bg-[var(--success)]/10 text-[var(--success)] border border-[var(--success)]/20 text-12 font-bold",children:[e.jsx(Ue,{size:12})," 已結清"]}):e.jsxs("span",{className:"flex items-center gap-1.5 px-2.5 py-0.5 rounded bg-[var(--error)]/10 text-[var(--error)] border border-[var(--error)]/20 text-12 font-bold",children:[e.jsx(Ia,{size:12})," 未支付"]})})}),e.jsx("td",{className:"py-4 px-3 font-mono text-13 text-[var(--text-muted)] text-center",children:n.paymentDate||"-"}),e.jsx("td",{className:"py-4 px-4 text-center",children:e.jsxs("div",{className:"flex justify-center gap-1",children:[N&&!n.isPaid&&e.jsx("button",{onClick:()=>k(n),className:"p-1.5 text-[var(--text-muted)] hover:text-[var(--success)] hover:bg-[var(--success)]/10 rounded-lg transition-all",title:"快速標記已支付",children:e.jsx(Ue,{size:16})}),N&&e.jsx("button",{onClick:()=>b(n),className:"p-1.5 text-[var(--text-muted)] hover:text-[var(--accent)] hover:bg-[var(--accent)]/10 rounded-lg transition-all",title:"編輯",children:e.jsx(qe,{size:16})}),N&&e.jsx("button",{onClick:()=>T(n),className:"p-1.5 text-[var(--text-muted)] hover:text-[var(--error)] hover:bg-[var(--error)]/10 rounded-lg transition-all",title:"刪除",children:e.jsx(it,{size:16})}),!N&&e.jsx("span",{className:"text-12 text-[var(--text-muted)] italic",children:"僅檢視"})]})})]},n.id)})})]})})})}),e.jsxs("div",{className:"p-6 bg-[var(--bg-card)] border-t border-[var(--border)] flex items-center justify-between shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-8",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-12 text-[var(--text-muted)] font-bold uppercase tracking-wider mb-1",children:"本案 B2B 應付總計"}),e.jsxs("p",{className:"text-xl font-bold text-[var(--text-primary)] font-mono leading-none",children:["NT$",c.reduce((n,p)=>n+p.amountPayable,0).toLocaleString()]})]}),e.jsx("div",{className:"w-px h-8 bg-[var(--border)]"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-12 text-[var(--text-muted)] font-bold uppercase tracking-wider mb-1",children:"本案 B2B 實領總計"}),e.jsxs("p",{className:"text-xl font-bold text-[var(--success)] font-mono leading-none",children:["NT$",c.reduce((n,p)=>n+p.netAmount,0).toLocaleString()]})]})]}),e.jsx("p",{className:"text-12 text-[var(--text-muted)] font-bold italic select-none",children:"此表資料僅與該商案關聯(固定扣稅 5%)"})]}),e.jsx(pe,{isOpen:!!l,onClose:()=>b(null),zIndex:70,maxWidth:"max-w-lg",contentClassName:"bg-[var(--bg-card)] border border-[var(--border)] w-full rounded-3xl shadow-2xl overflow-hidden",children:e.jsxs("form",{onSubmit:L,children:[e.jsxs("div",{className:"p-6 border-b border-[var(--border)] bg-[var(--bg-card-alt)] flex justify-between items-center",children:[e.jsxs("h4",{className:"font-bold text-[var(--text-primary)] flex items-center gap-2",children:[l!=null&&l.id?e.jsx(qe,{size:18,className:"text-[var(--accent)]"}):e.jsx(ze,{size:18,className:"text-[var(--id-orange)]"}),l!=null&&l.id?"編輯 B2B 紀錄":"新增 B2B 紀錄"]}),e.jsx("button",{type:"button",onClick:()=>b(null),className:"text-[var(--text-muted)] hover:text-[var(--text-primary)] transition-all",children:e.jsx(ye,{size:20})})]}),e.jsxs("div",{className:"p-8 space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:`${d}-0`,className:"text-12 font-bold text-[var(--text-muted)] uppercase tracking-widest ml-1",children:"領款人名稱"}),e.jsx("input",{id:`${d}-0`,required:!0,type:"text",value:(l==null?void 0:l.kolName)||"",onChange:n=>l&&b({...l,kolName:n.target.value}),className:"input-modern bg-[var(--bg-card-alt)]",placeholder:"領款人名稱"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("span",{id:`${d}-g0`,className:"text-12 font-bold text-[var(--text-muted)] uppercase tracking-widest ml-1",children:"B2B 編號"}),e.jsxs("div",{role:"group","aria-labelledby":`${d}-g0`,className:"grid grid-cols-2 gap-2",children:[e.jsx("input",{"aria-label":"自動產生",disabled:!0,type:"text",value:(l==null?void 0:l.serialNumber)||"",className:"input-modern bg-[var(--bg-card-alt)] text-[var(--text-muted)] font-mono curs
22or-not-allowed border-[var(--border)]",placeholder:"自動產生"}),e.jsx("input",{"aria-label":"執行月份",type:"month",value:(l==null?void 0:l.month)||"",onChange:n=>l&&b({...l,month:n.target.value}),className:"input-modern bg-[var(--bg-card-alt)] font-mono text-xs"})]})]})]}),e.jsxs("div",{className:"p-4 bg-[var(--bg-card-alt)] rounded-2xl border border-[var(--id-orange)]/20",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsx("span",{className:"text-12 font-bold text-[var(--id-orange)] uppercase tracking-widest",children:"應付總額 (未稅)"}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[e.jsx("input",{type:"checkbox",checked:(l==null?void 0:l.isAutoCalc)||!1,onChange:n=>l&&b({...l,isAutoCalc:n.target.checked}),className:"checkbox-modern"}),e.jsx("span",{className:"text-12 font-bold text-[var(--text-secondary)]",children:"自動計算稅金 (5%)"})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"absolute left-4 top-1/2 -translate-y-1/2 text-[var(--id-orange)] font-mono font-bold",children:"$"}),e.jsx("input",{"aria-label":"0",required:!0,type:"number",value:(l==null?void 0:l.amountPayable)||"",onChange:n=>l&&b({...l,amountPayable:Number(n.target.value)}),className:"w-full bg-[var(--bg-card-alt)] border border-[var(--id-orange)]/30 text-[var(--text-primary)] rounded-xl py-3 px-10 text-2xl font-mono font-bold outline-none focus:border-[var(--id-orange)]",placeholder:"0"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:`${d}-1`,className:"text-12 font-bold text-[var(--id-orange)] uppercase tracking-widest ml-1",children:"5% 稅金"}),e.jsx("input",{id:`${d}-1`,type:"number",disabled:l==null?void 0:l.isAutoCalc,value:l?l.isAutoCalc?_(l).professionalTax:l.professionalTax:"",onChange:n=>l&&b({...l,professionalTax:Number(n.target.value)}),className:"input-modern bg-[var(--bg-card-alt)] text-xs font-mono disabled:opacity-50"})]}),e.jsxs("div",{className:"space-y-1.5 text-center",children:[e.jsx("span",{className:"text-12 font-bold text-[var(--success)] uppercase tracking-widest block",children:"實領金額 (含稅)"}),e.jsxs("div",{className:"h-10 flex items-center justify-center font-mono font-bold text-[var(--success)] bg-[var(--success)]/5 rounded-xl border border-[var(--success)]/10",children:["$",l?(l.isAutoCalc?_(l).netAmount:l.amountPayable+l.professionalTax).toLocaleString():"0"]})]})]}),e.jsx("div",{className:"h-px bg-[var(--border)] my-4"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("span",{className:"text-12 font-bold text-[var(--text-muted)] uppercase tracking-widest ml-1",children:"支付狀態"}),e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer p-3 bg-[var(--bg-card-alt)] rounded-xl border border-[var(--border)] hover:border-[var(--border-hover)] transition-all h-10",children:[e.jsx("input",{type:"checkbox",checked:(l==null?void 0:l.isPaid)||!1,onChange:n=>{if(!l)return;const p=n.target.checked;b({...l,isPaid:p,paymentDate:p&&!l.paymentDate?I():l.paymentDate})},className:"checkbox-modern"}),e.jsx("span",{className:"text-xs font-bold text-[var(--text-secondary)] tracking-wide",children:"標記為已支付"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:`${d}-2`,className:"text-12 font-bold text-[var(--text-muted)] uppercase tracking-widest ml-1",children:"入帳 / 預定日期"}),e.jsx("input",{id:`${d}-2`,type:"date",value:(l==null?void 0:l.paymentDate)||"",onChange:n=>l&&b({...l,paymentDate:n.target.value}),className:"input-modern bg-[var(--bg-card-alt)] font-mono text-xs h-10"})]})]})]}),e.jsxs("div",{className:"p-6 bg-[var(--bg-card-alt)] border-t border-[var(--border)] flex gap-3",children:[e.jsx("button",{type:"button",onClick:()=>b(null),className:"flex-1 py-3 rounded-xl text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-card-alt)] transition-all font-bold text-sm",children:"取消"}),e.jsxs("button",{type:"submit",className:"flex-1 py-3 bg-orange-600 hover:bg-orange-500 text-white rounded-xl font-bold shadow-lg shadow-orange-500/20 transition-all flex items-center justify-center gap-2 active:scale-95",children:[e.jsx(ea,{size:18}),"確認儲存"]}
22)]})]})}),e.jsx(pe,{isOpen:!!S,onClose:()=>k(null),zIndex:80,maxWidth:"max-w-md",contentClassName:"bg-[var(--bg-card)] border border-[var(--success)]/30 p-10 rounded-[32px] w-full shadow-2xl",children:e.jsxs("div",{className:"flex flex-col items-center text-center gap-6",children:[e.jsx("div",{className:"w-16 h-16 bg-[var(--success)]/10 rounded-full flex items-center justify-center text-[var(--success)] border border-[var(--success)]/20",children:e.jsx(Ue,{size:32})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-xl font-bold text-[var(--text-primary)]",children:"確認支付款項?"}),e.jsxs("div",{className:"text-sm text-[var(--text-secondary)] leading-relaxed px-4",children:["將標記 ",e.jsx("span",{className:"text-[var(--text-primary)] font-bold",children:S==null?void 0:S.kolName})," 的 B2B 款項為已支付,並自動帶入今日日期 (",e.jsx("span",{className:"text-[var(--id-orange)] font-mono font-bold",children:I()}),")。"]})]}),e.jsxs("div",{className:"flex gap-4 w-full mt-2",children:[e.jsx("button",{onClick:()=>k(null),className:"flex-1 py-3 bg-[var(--bg-card-alt)] text-[var(--text-secondary)] rounded-2xl font-bold text-sm hover:bg-[var(--bg-card-alt)] transition-all",children:"取消"}),e.jsx("button",{onClick:$,className:"flex-1 py-3 bg-[var(--success)] text-[var(--button-text)] rounded-2xl font-bold text-sm hover:bg-[var(--success)] shadow-lg shadow-green-900/20 active:scale-95 transition-all",children:"確認支付"})]})]})}),e.jsx(pe,{isOpen:!!v,onClose:()=>T(null),zIndex:80,maxWidth:"max-w-md",contentClassName:"bg-[var(--bg-card)] border border-[var(--error)]/30 p-10 rounded-[32px] w-full shadow-2xl",children:e.jsxs("div",{className:"flex flex-col items-center text-center gap-6",children:[e.jsx("div",{className:"w-16 h-16 rounded-full bg-[var(--error)]/10 flex items-center justify-center text-[var(--error)] border border-[var(--error)]/20",children:A?e.jsx(be,{size:32,className:"animate-spin"}):e.jsx(it,{size:32})}),e.jsxs("div",{className:"space-y-4 w-full",children:[e.jsx("h3",{className:"text-xl font-bold text-[var(--text-primary)]",children:"確定要刪除?"}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-[var(--text-secondary)] text-sm leading-relaxed",children:"此動作將永久移除此筆 B2B 結帳紀錄。"}),(v==null?void 0:v.projectSerials)&&v.projectSerials.length>0&&e.jsxs("div",{className:"bg-[var(--id-orange)]/10 border border-[var(--id-orange)]/20 p-4 rounded-2xl flex gap-3 items-start text-left",children:[e.jsx(Mt,{size:18,className:"text-[var(--id-orange)] shrink-0 mt-0.5"}),e.jsxs("p",{className:"text-13 text-[var(--id-orange)] leading-tight font-medium",children:["注意:刪除後將會同步還原關聯專案 (",e.jsx("span",{className:"font-mono text-[var(--text-primary)] font-bold",children:v.projectSerials.join(", ")}),") 的結帳鎖定狀態。"]}
22)]})]})]}),e.jsxs("div",{className:"flex gap-4 w-full mt-2",children:[e.jsx("button",{disabled:A,onClick:()=>T(null),className:"flex-1 py-3 bg-[var(--bg-card-alt)] text-[var(--text-secondary)] rounded-2xl font-bold text-sm hover:bg-[var(--bg-card-alt)] transition-all disabled:opacity-50",children:"取消"}),e.jsx("button",{disabled:A,onClick:B,className:"flex-1 py-3 bg-[var(--error)] text-[var(--button-text)] rounded-2xl font-bold text-sm hover:bg-[var(--error)] shadow-lg shadow-red-900/20 active:scale-95 transition-all disabled:opacity-50",children:A?"處理中...":"確認刪除並還原"})]})]})})]})},gr=({id:t,value:a,onChange:r,placeholder:s="選擇日期",className:o})=>{const[d,c]=i.useState(!1),[u,f]=i.useState("days"),[x,l]=i.useState({top:0,left:0}),[b,y]=i.useState(()=>{if(a){const[n,p]=a.split("-").map(Number);return new Date(n,p-1,1)}return new Date}),[j,w]=i.useState(()=>{const n=b.getFullYear();return n-n%12}),v=i.useRef(null),T=i.useRef(null);i.useEffect(()=>{if(a){const[n,p]=a.split("-").map(Number);y(new Date(n,p-1,1))}},[a]),i.useEffect(()=>{if(!d)return;const n=P=>{var z,K;const E=P.target;(z=T.current)!=null&&z.contains(E)||(K=v.current)!=null&&K.contains(E)||c(!1)},p=P=>{var E;(E=T.current)!=null&&E.contains(P.target)||c(!1)},g=()=>c(!1);return window.addEventListener("mousedown",n),window.addEventListener("scroll",p,!0),window.addEventListener("resize",g),()=>{window.removeEventListener("mousedown",n),window.removeEventListener("scroll",p,!0),window.removeEventListener("resize",g)}},[d]);const S=()=>{if(!d&&v.current){const n=v.current.getBoundingClientRect();l({top:n.bottom+window.scrollY+4,left:n.left+window.scrollX}),f("days")}c(!d)},k=n=>{const p=b.getFullYear(),g=String(b.getMonth()+1).padStart(2,"0"),P=String(n).padStart(2,"0");r(`${p}-${g}-${P}`),c(!1)},A=n=>{y(new Date(b.getFullYear(),n,1)),f("days")},D=n=>{y(new Date(n,b.getMonth(),1)),f("months")},N=a?(()=>{const[n,p,g]=a.split("-");return`${n}/${p}/${g}`})():"",R=b.getFullYear(),I=b.getMonth(),m=new Date(R,I+1,0).getDate(),_=new Date(R,I,1).getDay(),L=new Date().toISOString().split("T")[0],$=new Date().getFullYear(),B=new Date().getMonth(),U=["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"];return e.jsxs(e.Fragment,{children:[e.jsxs("button",{ref:v,type:"button",onClick:S,className:`flex items-center gap-2 bg-[var(--bg-page)] border border-[var(--border)] rounded-lg px-3 py-2 text-sm text-left transition-all focus:ring-2 focus:ring-[var(--accent)] focus:border-transparent outline-none ${a?"text-[var(--text-primary)]":"text-[var(--text-muted)]"} ${o||""}`,children:[e.jsx(Zt,{size:14,className:"text-[var(--text-muted)] shrink-0"}),e.jsx("span",{className:"flex-1 min-w-0",children:N||s}),a&&e.jsx("span",{...Fe(n=>{n.stopPropagation(),r("")}),className:"text-[var(--text-muted)] hover:text-[var(--error)] transition-colors shrink-0",children:e.jsx(ye,{size:14})})]}),d&&ga.createPortal(e.jsxs("div",{ref:T,className:"fixed z-[9999] bg-[var(--bg-card)] border border-[var(--border)] rounded-xl shadow-2xl p-4 w-[280px]",style:{top:x.top,left:x.left},children:[u==="years"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("button",{onClick:()=>w(n=>n-12),className:"p-1.5 hover:bg-[var(--bg-card-alt)] rounded-lg text-[var(--text-muted)] hover:text-[var(--text-primary)] transition-colors",children:e.jsx(Tt,{size:16})}),e.jsxs("span",{className:"text-sm font-bold text-[var(--text-primary)]",children:[j," - ",j+11]}),e.jsx("button",{onClick:()=>w(n=>n+12),className:"p-1.5 hover:bg-[var(--bg-card-alt)] rounded-lg text-[var(--text-muted)] hover:text-[var(--text-primary)] transition-colors",children:e.jsx(Le,{size:16})})]}),e.jsx("div",{className:"grid grid-cols-3 gap-2",children:Array.from({length:12}).map((n,p)=>{const g=j+p,P=g===R,E=g===$;return e.jsx("button",{onClick:()=>D(g),className:`py-2 rounded-lg text-sm transition-colors
23                        ${P?"bg-[var(--accent)] text-white font-bold":"hover:bg-[var(--bg-card-alt)] text-[var(--text-secondary)]"}
24                        ${!P&&E?"border border-[var(--accent)] text-[var(--accent)] font-medium":""}
25                      `,children:g},g)})})]}),u==="months"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("button",{onClick:()=>y(new Date(R-1,I,1)),className:"p-1.5 hover:bg-[var(--bg-card-alt)] rounded-lg text-[var(--text-muted)] hover:text-[var(--text-primary)] transition-colors",children:e.jsx(Tt,{size:16})}),e.jsxs("button",{onClick:()=>{w(R-R%12),f("years")},className:"text-sm font-bold text-[var(--text-primary)] hover:text-[var(--accent)] transition-colors",children:[R,"å¹´"]}),e.jsx("button",{onClick:()=>y(new Date(R+1,I,1)),className:"p-1.5 hover:bg-[var(--bg-card-alt)] rounded-lg text-[var(--text-muted)] hover:text-[var(--text-primary)] transition-colors",children:e.jsx(Le,{size:16})})]}),e.jsx("div",{className:"grid grid-cols-3 gap-2",children:U.map((n,p)=>{const g=p===I&&R===b.getFullYear(),P=p===B&&R===$;return e.jsx("button",{onClick:()=>A(p),className:`py-2 rounded-lg text-sm transition-colors
26                        ${g?"bg-[var(--accent)] text-white font-bold":"hover:bg-[var(--bg-card-alt)] text-[var(--text-secondary)]"}
27                        ${!g&&P?"border border-[var(--accent)] text-[var(--accent)] font-medium":""}
28                      `,children:n},p)})})]}),u==="days"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("button",{onClick:()=>y(new Date(R,I-1,1)),className:"p-1.5 hover:bg-[var(--bg-card-alt)] rounded-lg text-[var(--text-muted)] hover:text-[var(--text-primary)] transition-colors",children:e.jsx(Tt,{size:16})}),e.jsxs("button",{onClick:()=>f("months"),className:"text-sm font-bold text-[var(--text-primary)] hover:text-[var(--accent)] transition-colors",children:[R,"年 ",I+1,"月"]}),e.jsx("button",{onClick:()=>y(new Date(R,I+1,1)),className:"p-1.5 hover:bg-[var(--bg-card-alt)] rounded-lg text-[var(--text-muted)] hover:text-[var(--text-primary)] transition-colors",children:e.jsx(Le,{size:16})})]}),e.jsx("div",{className:"grid grid-cols-7 gap-1 text-center mb-1",children:["日","一","二","三","四","五","六"].map(n=>e.jsx("span",{className:"text-xs text-[var(--text-muted)] font-medium py-1",children:n},n))}),e.jsxs("div",{className:"grid grid-cols-7 gap-1",children:[Array.from({length:_}).map((n,p)=>e.jsx("div",{},`e-${p}`)),Array.from({length:m}).map((n,p)=>{const g=p+1,P=`${R}-${String(I+1).padStart(2,"0")}-${String(g).padStart(2,"0")}`,E=a===P,z=L===P;return e.jsx("button",{onClick:()=>k(g),className:`w-8 h-8 rounded-full flex items-center justify-center text-sm transition-colors
29                        ${E?"bg-[var(--accent)] text-white font-bold":"hover:bg-[var(--bg-card-alt)] text-[var(--text-secondary)]"}
30                        ${!E&&z?"border border-[var(--accent)] text-[var(--accent)] font-medium":""}
31                      `,children:g},g)})]}),e.jsx("button",{onClick:()=>{const n=new Date;y(new Date(n.getFullYear(),n.getMonth(),1)),r(L),c(!1)},className:"w-full mt-3 py-1.5 text-xs text-[var(--accent)] hover:bg-[var(--accent)]/10 rounded-lg transition-colors",children:"今天"})]})]}),document.body)]})},vr=[{value:"delivery_date",label:"交件時間填寫",icon:e.jsx(Rr,{size:11}),style:"bg-[var(--accent)]/10 text-[var(--accent)] border-[var(--accent)]/20"},{value:"completed",label:"已完成",icon:e.jsx(Ue,{size:11}),style:"bg-[var(--success)]/10 text-[var(--success)] border-[var(--success)]/20"},{value:"in_progress",label:"製作中",icon:e.jsx(on,{size:11}),style:"bg-[var(--warning)]/10 text-[var(--warning)] border-[var(--warning)]/20"},{value:"awaiting_notice",label:"待通知",icon:e.jsx(ln,{size:11}),style:"bg-[var(--text-muted)]/10 text-[var(--text-secondary)] border-[var(--text-muted)]/20"}],Ko=[{value:"kol_self",label:"KOL 自付"},{value:"agent_advance",label:"經紀人墊"}],Yo=({tableId:t,tableName:a,onClose:r,permission:s})=>{var U;const o=i.useId(),[d,c]=i.useState([]),[u,f]=i.useState(!0),[x,l]=i.useState(null),[b,y]=i.useState(null),[j,w]=i.useState(!1),[v,T]=i.useState(!1),[S,k]=i.useState("default"),A=(s==null?void 0:s.edit)===!0,D=(s==null?void 0:s.delete)===!0;i.useEffect(()=>{N()},[t]);const N=async()=>{f(!0);try{const n=await Kn(t);c(n)}catch(n){console.error("[MiscExpense] fetch failed",n)}finally{f(!1)}},R=i.useMemo(()=>
31{if(S==="default")return d;const n=[...d];return S==="paymentDate"?n.sort((p,g)=>!p.paymentDate&&!g.paymentDate?0:p.paymentDate?g.paymentDate?g.paymentDate.localeCompare(p.paymentDate):-1:1):S==="amount"?n.sort((p,g)=>(g.amount||0)-(p.amount||0)):S==="name"&&n.sort((p,g)=>(p.name||"").localeCompare(g.name||"")),n},[d,S]),I=i.useMemo(()=>d.reduce((n,p)=>n+(Number(p.amount)||0),0),[d]),m=()=>{l({...En,tableId:t})},_=async n=>{if(n.preventDefault(),!!x&&!(!x.name||!x.name.trim())){w(!0);try{const p={tableId:t,name:x.name.trim(),productionContent:x.productionContent||"",editor:x.editor||"",bcStatus:x.bcStatus||"",bcDeliveryDate:x.bcStatus==="delivery_date"&&x.bcDeliveryDate||null,payer:x.payer||"",amount:Number(x.amount)||0,paymentDate:x.paymentDate||null,note:x.note||""};x.id?await Qn(x.id,p):await Yn(p),l(null),await N()}catch(p){console.error("[MiscExpense] save failed",p)}finally{w(!1)}}},L=async()=>{if(b!=null&&b.id){T(!0);try{await Jn(b.id),y(null),await N()}catch(n){console.error("[MiscExpense] delete failed",n)}finally{T(!1)}}},$=(n,p)=>{if(!n)return e.jsx("span",{className:"text-[var(--text-muted)]",children:"-"});const g=vr.find(P=>P.value===n);return g?e.jsxs("div",{className:"flex flex-col items-center gap-1",children:[e.jsxs("span",{className:`inline-flex items-center gap-1 text-12 font-bold px-2 py-0.5 rounded border ${g.style}`,children:[g.icon," ",g.label]}),n==="delivery_date"&&p&&e.jsx("span",{className:"text-11 font-mono text-[var(--accent)]",children:p})]}):e.jsx("span",{className:"text-[var(--text-muted)]",children:"-"})},B=n=>{if(!n)return e.jsx("span",{className:"text-[var(--text-muted)]",children:"-"});const p=n==="kol_self"?"KOL 自付":"經紀人墊",g=n==="kol_self"?"bg-[var(--id-pink)]/10 text-[var(--id-pink)] border-[var(--id-pink)]/20":"bg-[var(--id-purple)]/10 text-[var(--id-purple)] border-[var(--id-purple)]/20";return e.jsx("span",{className:`inline-block text-12 font-bold px-2 py-0.5 rounded border ${g}`,children:p})};return e.jsxs(pe,{isOpen:!0,onClose:r,zIndex:60,maxWidth:"max-w-[1440px]",contentClassName:"bg-[var(--bg-page)] border border-[var(--border)] w-[calc(100vw-2rem)] h-[85vh] rounded-[32px] shadow-2xl flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"p-6 border-b border-[var(--border)] bg-[var(--bg-card)] flex justify-between items-center shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-12 h-12 bg-[var(--id-purple)]/10 rounded-2xl flex items-center justify-center text-[var(--id-purple)] border border-[var(--id-purple)]/20",children:e.jsx(Lr,{size:24})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-bold text-[var(--text-primary)] tracking-tight",children:"雜支紀錄"}),e.jsxs("p",{className:"text-xs text-[var(--text-muted)] font-medium mt-0.5",children:[a?e.jsx("span",{className:"text-[var(--text-primary)]",children:a}):"此表"," 獨立記錄製作端雜費,不影響商案分潤與結帳"]})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 h-10 bg-[var(--bg-card)] border border-[var(--border)] rounded-xl",children:[e.jsx(ta,{size:14,className:"text-[var(--text-muted)]"}),e.jsxs("select",{"aria-label":"排序方式",value:S,onChange:n=>k(n.target.value),className:"bg-transparent text-xs font-bold text-[var(--text-primary)] focus:outline-none cursor-pointer",children:[e.jsx("option",{value:"default",className:"bg-[var(--bg-card)]",children:"預設(不排序)"}),e.jsx("option",{value:"paymentDate",className:"bg-[var(--bg-card)]",children:"付款結帳日(新→舊)"}),e.jsx("option",{value:"amount",className:"bg-[var(--bg-card)]",children:"費用(大→小)"}),e.jsx("option",{value:"name",className:"bg-[var(--bg-card)]",children:"名稱"})]})]}),A?e.jsxs("button",{onClick:m,className:"flex items-center gap-2 px-5 py-2.5 bg-purple-600 hover:bg-purple-500 text-white rounded-xl text-xs font-bold transition-all shadow-lg shadow-purple-900/20 active:scale-95 h-10",children:[e.jsx(ze,{size:16})," 新增雜支"]}):e.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 bg-[var(--bg-card-alt)] text-[var(--text-muted)] rounded-xl text-xs font-bold h-10 border border-[var(--border)]",children:[e.jsx(Oe,{size:14})," 僅有檢視權限"]}),e.jsx("button",{onClick:r,className:"p-2.5 hover:bg-[var(--bg-card-alt)] rounded-xl text-[var(--text-muted)] hover:text-[var(--text-primary)] transition-all border border-[var(--border)]",children:e.jsx(ye,{size:20})})]})]}),e.jsx("div",{className:"flex-1 overflow-auto bg-[var(--bg-page)] custom-scrollbar",children:e.jsx("div",{className:"p-6",children:e.jsx("div",{className:"bg-[var(--bg-card)] rounded-2xl border border-[var(--border)] shadow-xl min-w-[1100px]",children:e.jsxs("table",{className:"w-full text-center border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-[var(--bg-card-alt)] border-b-2 border-[var(--border)]",children:[e.jsx("th",{className:"sticky top-0 z-10 shadow-lg shadow-black/50 py-3 px-4 text-13 font-bold text-[var(--text-secondary)] uppercase tracking-widest text-left bg-[var(--bg-card-alt)] rounded-tl-2xl",children:"名稱"}),e.jsx("th",{className:"sticky top-0 z-10 shadow-lg shadow-black/50 py-3 px-4 text-13 font-bold text-[var(--text-secondary)] uppercase tracking-widest text-left bg-[var(--bg-card-alt)]",children:"製作內容"}),e.jsx("th",{className:"sticky top-0 z-10 shadow-lg shadow-black/50 py-3 px-4 text-13 font-bold text-[var(--text-secondary)] uppercase tracking-widest bg-[var(--bg-card-alt)] w-28",children:"片師"}),e.jsx("th",{className:"sticky top-0 z-10 shadow-lg shadow-black/50 py-3 px-4 text-13 font-bold text-[var(--accent)] uppercase tracking-widest bg-[var(--bg-card-alt)] w-40",children:"BC"}),e.jsx("th",{className:"sticky top-0 z-10 shadow-lg shadow-black/50 py-3 px-4 text-13 font-bold text-[var(--text-secondary)] uppercase tracking-widest bg-[var(--bg-card-alt)] w-32",children:"付款人"}),e.jsx("th",{className:"sticky top-0 z-10 shadow-lg shadow-black/50 py-3 px-4 text-13 font-bold text-[var(--success)] uppercase tracking-widest bg-[var(--bg-card-alt)] w-32",children:"費用"}),e.jsx("th",{className:"sticky top-0 z-10 shadow-lg shadow-black/50 py-3 px-4 text-13 font-bold text-[var(--text-secondary)] uppercase tracking-widest bg-[var(--bg-card-alt)] w-32",children:"付款結帳日"}),e.jsx("th",{className:"sticky top-0 z-10 shadow-lg shadow-black/50 py-3 px-4 text-13 font-bold text-[var(--text-muted)] uppercase tracking-widest bg-[var(--bg-card-alt)] w-28 rounded-tr-2xl",children:"操作"})]})}),e.jsx("tbody",{className:"divide-y divide-[var(--border)] nk-list nk-zebra",children:u?e.jsx("tr",{children:e.jsx("td",{colSpan:8,className:"py-20 text-center text-[var(--text-muted)] animate-pulse text-sm",children:"載入中..."})}):R.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:8,className:"py-20 text-center text-[var(--text-muted)] italic text-sm",children:"目前尚無雜支紀錄"})}):R.map(n=>e.jsxs("tr",{className:"hover:bg-[var(--bg-card-alt)] transition-colors group",children:[e.jsx("td",{className:"py-4 px-4 text-sm font-bold text-[var(--text-primary)] text-left",children:n.name||e.jsx("span",{className:"text-[var(--text-muted)]",children:"-"})}),e.jsx("td",{className:"py-4 px-4 text-14 text-[var(--text-primary)] text-left max-w-[260px]",children:e.jsx("div",{className:"truncate",title:n.productionContent||"",children:n.productionContent||e.jsx("span",{className:"text-[var(--text-muted)]",children:"-"})})}),e.jsx("td",{className:"py-4 px-4 text-xs text-[var(--text-primary)]",children:n.editor||e.jsx("span",{className:"text-[var(--text-muted)]",children:"-"})}),e.jsx("td",{className:"py-4 px-4",children:$(n.bcStatus,n.bcDeliveryDate)}),e.jsx("td",{className:"py-4 px-4",children:B(n.payer)}),e.jsx("td",{className:"py-4 px-4 text-sm font-mono font-bold text-[var(--success)]",children:n.amount?`NT$${Number(n.amount).toLocaleStr
31ing()}`:e.jsx("span",{className:"text-[var(--text-muted)]",children:"-"})}),e.jsx("td",{className:"py-4 px-4 font-mono text-13 text-[var(--text-secondary)]",children:n.paymentDate||e.jsx("span",{className:"text-[var(--text-muted)]",children:"-"})}),e.jsx("td",{className:"py-4 px-4",children:e.jsxs("div",{className:"flex justify-center gap-1",children:[A&&e.jsx("button",{onClick:()=>l(n),className:"p-1.5 text-[var(--text-muted)] hover:text-[var(--accent)] hover:bg-[var(--accent)]/10 rounded-lg transition-all",title:"編輯",children:e.jsx(qe,{size:16})}),D&&e.jsx("button",{onClick:()=>y(n),className:"p-1.5 text-[var(--text-muted)] hover:text-[var(--error)] hover:bg-[var(--error)]/10 rounded-lg transition-all",title:"刪除",children:e.jsx(it,{size:16})}),!A&&!D&&e.jsx("span",{className:"text-12 text-[var(--text-muted)] italic",children:"僅檢視"})]})})]},n.id))})]})})})}),e.jsxs("div",{className:"p-6 bg-[var(--bg-card)] border-t border-[var(--border)] flex items-center justify-between shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-8",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-12 text-[var(--text-muted)] font-bold uppercase tracking-wider mb-1",children:"雜支總筆數"}),e.jsx("p",{className:"text-xl font-bold text-[var(--text-primary)] font-mono leading-none",children:d.length})]}),e.jsx("div",{className:"w-px h-8 bg-[var(--border)]"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-12 text-[var(--text-muted)] font-bold uppercase tracking-wider mb-1",children:"雜支總金額"}),e.jsxs("p",{className:"text-xl font-bold text-[var(--id-purple)] font-mono leading-none",children:["NT$",I.toLocaleString()]})]})]}),e.jsx("p",{className:"text-12 text-[var(--text-muted)] font-bold italic select-none",children:"此表雜支紀錄獨立保存,不計入分潤與勞報結帳"})]}),e.jsx(pe,{isOpen:!!x,onClose:()=>l(null),zIndex:70,maxWidth:"max-w-2xl",contentClassName:"bg-[var(--bg-card)] border border-[var(--border)] w-full rounded-3xl shadow-2xl overflow-hidden",children:e.jsxs("form",{onSubmit:_,children:[e.jsxs("div",{className:"p-6 border-b border-[var(--border)] bg-[var(--bg-card-alt)] flex justify-between items-center",children:[e.jsxs("h4",{className:"font-bold text-[var(--text-primary)] flex items-center gap-2",children:[x!=null&&x.id?e.jsx(qe,{size:18,className:"text-[var(--accent)]"}):e.jsx(ze,{size:18,className:"text-[var(--id-purple)]"}),x!=null&&x.id?"編輯雜支紀錄":"新增雜支紀錄"]}),e.jsx("button",{type:"button",onClick:()=>l(null),className:"text-[var(--text-muted)] hover:text-[var(--text-primary)] transition-all",children:e.jsx(ye,{size:20})})]}),e.jsxs("div",{className:"p-8 space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("label",{htmlFor:`${o}-0`,className:"text-12 font-bold text-[var(--text-muted)] uppercase tracking-widest ml-1",children:["名稱 ",e.jsx("span",{className:"text-[var(--error)]",children:"*"})]}),e.jsx("input",{id:`${o}-0`,required:!0,type:"text",value:(x==null?void 0:x.name)||"",onChange:n=>x&&l({...x,name:n.target.value}),className:"input-modern bg-[var(--bg-card-alt)]",placeholder:"例如:英雄聯盟、活動名稱..."})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:`${o}-1`,className:"text-12 font-bold text-[var(--text-muted)] uppercase tracking-widest ml-1",children:"片師"}),e.jsx("input",{id:`${o}-1`,type:"text",value:(x==null?void 0:x.editor)||"",onChange:n=>x&&l({...x,editor:n.target.value}),className:"input-modern bg-[var(--bg-card-alt)]",placeholder:"負責剪輯人員(選填)"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:`${o}-2`,className:"text-12 font-bold text-[var(--text-muted)] uppercase tracking-widest ml-1",children:"製作內容"}),e.jsx("input",{id:`${o}-2`,type:"text",value:(x==null?void 0:x.productionContent)||"",onChange:n=>x&&l({...x,productionContent:n.target.value}),className:"input-modern bg-[var(--bg-card-alt)]",placeholder:"例如:精華剪輯 / 短影音 / 配音(選填)"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("span",{className:"text-12 font-bold text-[var(--text-muted)] uppercase tracking-widest ml-1",children:"BC"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",onClick:()=>x&&l({...x,bcStatus:"",bcDeliveryDate:null}),className:`px-3 py-1.5 rounded-lg text-13 font-bold border transition-all ${x!=null&&x.bcStatus?"bg-[var(--bg-card-alt)] text-[var(--text-muted)] border-[var(--border)] hover:text-[var(--text-primary)]":"bg-[var(--bg-card-alt)] text-[var(--text-primary)] border-[var(--border-hover)]"}`,children:"未設定"}),vr.map(n=>e.jsxs("button",{type:"button",onClick:()=>x&&l({...x,bcStatus:n.value}),className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-13 font-bold border transition-all ${(x==null?void 0:x.bcStatus)===n.value?n.style:"bg-[var(--bg-card-alt)] text-[var(--text-muted)] border-[var(--border)] hover:text-[var(--text-primary)]"}`,children:[n.icon," ",n.label]},n.value))]}),(x==null?void 0:x.bcStatus)==="delivery_date"&&e.jsxs("div",{className:"pt-2",children:[e.jsx("label",{htmlFor:`${o}-0`,className:"text-12 font-bold text-[var(--accent)] uppercase tracking-widest ml-1 block mb-1.5",children:"交件日期(選填)"}),e.jsx(gr,{id:`${o}-0`,value:(x==null?void 0:x.bcDeliveryDate)||"",onChange:n=>x&&l({...x,bcDeliveryDate:n||null}),placeholder:"選擇交件日期",className:"w-full max-w-[240px] bg-[var(--bg-card-alt)]"})]})]}),e.jsx("div",{className:"h-px bg-[var(--border)]"}),e.jsxs("div",{className:"grid grid-cols-3 gap-4 items-end",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:`${o}-3`,className:"text-12 font-bold text-[var(--text-muted)] uppercase tracking-widest ml-1",children:"付款人"}),e.jsxs("select",{id:`${o}-3`,value:(x==null?void 0:x.payer)||"",onChange:n=>x&&l({...x,payer:n.target.value}),className:"input-modern bg-[var(--bg-card-alt)]",children:[e.jsx("option",{value:"",children:"未指定"}),Ko.map(n=>e.jsx("option",{value:n.value,children:n.label},n.value))]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:`${o}-4`,className:"text-12 font-bold text-[var(--success)] uppercase tracking-widest ml-1",children:"費用 (TWD)"}),e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-[var(--success)]/70 font-mono text-xs",children:"$"}),e.jsx("input",{id:`${o}-4`,type:"number",value:(x==null?void 0:x.amount)||"",onChange:n=>x&&l({...x,amount:Number(n.target.value)||0}),className:"input-modern bg-[var(--bg-card-alt)] font-mono pl-7",placeholder:"0"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:`${o}-1`,className:"text-12 font-bold text-[var(--text-muted)] uppercase tracking-widest ml-1",children:"付款結帳日"}),e.jsx(gr,{id:`${o}-1`,value:(x==null?void 0:x.paymentDate)||"",onChange:n=>x&&l({...x,paymentDate:n||null}),placeholder:"選擇日期",className:"w-full bg-[var(--bg-card-alt)]"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:`${o}-5`,className:"text-12 font-bold text-[var(--text-muted)] uppercase tracking-widest ml-1",children:"備註"}),e.jsx("textarea",{id:`${o}
31-5`,value:(x==null?void 0:x.note)||"",onChange:n=>x&&l({...x,note:n.target.value}),className:"input-modern bg-[var(--bg-card-alt)] min-h-[60px] resize-none",placeholder:"其他備註(選填)",rows:2})]})]}),e.jsxs("div",{className:"p-6 bg-[var(--bg-card-alt)] border-t border-[var(--border)] flex gap-3",children:[e.jsx("button",{type:"button",onClick:()=>l(null),disabled:j,className:"flex-1 py-3 rounded-xl text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-card-alt)] transition-all font-bold text-sm disabled:opacity-50",children:"取消"}),e.jsxs("button",{type:"submit",disabled:j||!((U=x==null?void 0:x.name)!=null&&U.trim()),className:"flex-1 py-3 bg-purple-600 hover:bg-purple-500 disabled:bg-[var(--bg-card-alt)] disabled:cursor-not-allowed text-white rounded-xl font-bold shadow-lg shadow-purple-500/20 transition-all flex items-center justify-center gap-2 active:scale-95",children:[j?e.jsx(be,{size:18,className:"animate-spin"}):e.jsx(ea,{size:18}),j?"儲存中...":"確認儲存"]})]})]})}),e.jsx(pe,{isOpen:!!b,onClose:()=>y(null),zIndex:80,maxWidth:"max-w-md",contentClassName:"bg-[var(--bg-card)] border border-[var(--error)]/30 p-10 rounded-[32px] w-full shadow-2xl",children:e.jsxs("div",{className:"flex flex-col items-center text-center gap-6",children:[e.jsx("div",{className:"w-16 h-16 rounded-full bg-[var(--error)]/10 flex items-center justify-center text-[var(--error)] border border-[var(--error)]/20",children:v?e.jsx(be,{size:32,className:"animate-spin"}):e.jsx(De,{size:32})}),e.jsxs("div",{className:"space-y-3 w-full",children:[e.jsx("h3",{className:"text-xl font-bold text-[var(--text-primary)]",children:"確定要刪除?"}),e.jsxs("p",{className:"text-[var(--text-secondary)] text-sm leading-relaxed",children:["將永久移除這筆雜支紀錄",(b==null?void 0:b.name)&&e.jsxs(e.Fragment,{children:[":",e.jsx("span",{className:"text-[var(--text-primary)] font-bold",children:b.name})]}),"。此操作無法復原。"]})]}),e.jsxs("div",{className:"flex gap-4 w-full mt-2",children:[e.jsx("button",{disabled:v,onClick:()=>y(null),className:"flex-1 py-3 bg-[var(--bg-card-alt)] text-[var(--text-secondary)] rounded-2xl font-bold text-sm hover:bg-[var(--bg-card-alt)] transition-all disabled:opacity-50",children:"取消"}),e.jsx("button",{disabled:v,onClick:L,className:"flex-1 py-3 bg-[var(--error)] text-white rounded-2xl font-bold text-sm hover:bg-[var(--error)] shadow-lg shadow-red-900/20 active:scale-95 transition-all disabled:opacity-50",children:v?"處理中...":"確認刪除"})]})]})})]})},Qo=({currentYear:t,currentMonthStr:a,onChange:r,className:s})=>{const[o,d]=i.useState(!1),[c,u]=i.useState(t),f=i.useRef(null);i.useEffect(()=>{const w=v=>{f.current&&!f.current.contains(v.target)&&d(!1)};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[]);const x=w=>{const v=`${c}-${(w+1).toString().padStart(2,"0")}`;r(c,v),d(!1)},l=()=>{r(c,""),d(!1)},b=()=>{r(null,""),d(!1)},y=["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],j=t===null?"不限年度":a?`${a.split("-")[0]}年 ${parseInt(a.split("-")[1])}月`:`${t}年 全年度`;return e.jsxs("div",{className:`relative ${s}`,ref:f,children:[e.jsxs("div",{...Fe(()=>d(!o)),className:"w-full bg-[var(--bg-card-alt)] border border-[var(--border)] hover:bg-[var(--bg-card-alt)] text-[var(--text-primary)] rounded-xl px-4 py-2 pl-9 cursor-pointer flex items-center justify-between transition-all select-none h-10",children:[e.jsx(Rr,{className:"absolute left-3 top-1/2 -translate-y-1/2 text-[var(--text-muted)]",size:16}),e.jsx("span",{className:"text-xs font-bold font-mono",children:j}),e.jsx(Ne,{size:14,className:`text-[var(--text-muted)] transition-transform ${o?"rotate-180":""}`})]}),o&&e.jsxs("div",{className:"absolute top-full right-0 sm:left-0 sm:right-auto mt-2 w-[calc(100vw-2rem)] sm:w-72 max-w-[288px] bg-[var(--bg-card)] border border-[var(--border)] rounded-2xl shadow-2xl z-[60] p-2 nk-in-down",children:[e.jsxs("div",{className:"flex items-center justify-between p-2 mb-2",children:[e.jsx("button",{onClick:()=>u(w=>(w??new Date().getFullYear())-1),className:"p-1.5 hover:bg-[var(--bg-card-alt)] rounded-lg text-[var(--text-secondary)]",children:e.jsx(Tt,{size:16})}),e.jsx("span",{className:"font-bold text-[var(--text-primary)] font-mono",children:c??new Date().getFullYear()}),e.jsx("button",{onClick:()=>u(w=>(w??new Date().getFullYear())+1),className:"p-1.5 hover:bg-[var(--bg-card-alt)] rounded-lg text-[var(--text-secondary)]",children:e.jsx(Le,{size:16})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-1",children:[y.map((w,v)=>e.jsx("button",{onClick:()=>x(v),className:"py-2 text-xs font-bold text-[var(--text-secondary)] hover:bg-[var(--accent)] hover:text-[var(--button-text)] rounded-lg transition-all",children:w},v)),e.jsx("button",{onClick:l,className:"col-span-3 py-2 mt-2 bg-[var(--bg-card-alt)] hover:bg-[var(--bg-card-alt)] text-[var(--text-primary)] rounded-lg text-xs font-bold",children:"全年度顯示"}),e.jsx("button",{onClick:b,className:"col-span-3 py-2 mt-1 bg-purple-600/20 hover:bg-purple-600/30 text-[var(--id-purple)] border border-[var(--id-purple)]/30 rounded-lg text-xs font-bold",children:"不限年度"})]})]})]})},Jo=({permission:t})=>{const{tableId:a}=Nr(),[r,s]=i.useState(null),[o,d]=i.useState([]),[c,u]=i.useState([]),[f,x]=i.useState([]),[l,b]=i.useState(!0),[y,j]=i.useState(null),[w,v]=i.useState(new Date().getFullYear()),[T,S]=i.useState(`${new Date().getFullYear()}
31-${String(new Date().getMonth()+1).padStart(2,"0")}`),[k,A]=i.useState(""),[D,N]=i.useState("serialNumber"),[R,I]=i.useState({key:"serialNumber",direction:"desc"}),[m,_]=i.useState("all"),[L,$]=i.useState("all"),[B,U]=i.useState("all"),[n,p]=i.useState("all"),[g,P]=i.useState("all"),[E,z]=i.useState("all"),[K,re]=i.useState(new Set),[me,C]=i.useState(!1),[ee,le]=i.useState(null),[Ce,fe]=i.useState(!1),[ce,_t]=i.useState(null),[Ve,Ge]=i.useState(null),[ds,Fa]=i.useState(!1),[us,Ba]=i.useState(!1),[xs,Ua]=i.useState(!1),[qa,xa]=i.useState(null),[ms,At]=i.useState(!1),[Wa,Ha]=i.useState(!1),[ps,It]=i.useState(!1),[Va,Ga]=i.useState(!1),Ae=t||{view:!1,create:!1,edit:!1,delete:!1};i.useEffect(()=>{a&&rt(a),bs()},[a]);const bs=async()=>{try{const h=await Un();x(h)}catch(h){console.error(h)}},rt=async h=>{b(!0);try{const[O,Q,G]=await Promise.all([Wn(!0),xr(h),La(h)]),J=O.find(F=>F.id===h)||null;s(J),d(Q),u(G)}catch{Ee("載入資料失敗","error")}finally{b(!1)}},Ee=(h,O="success")=>{j({id:Date.now(),message:h,type:O})},pt=i.useMemo(()=>o.filter(h=>{const O=h.month?parseInt(h.month.split("-")[0]):0;if(w!==null&&O!==w||T&&h.month!==T||m!=="all"&&h.assignee!==m||L!=="all"&&h.status!==L||B==="issued"&&h.quotationStatus!=="issued"||B==="signed"&&!h.isQuotationSigned||B==="unsigned"&&h.isQuotationSigned||B==="pending"&&(h.quotationStatus==="issued"||h.isQuotationSigned)||n!=="all"&&h.invoiceStatus!==n||g!=="all"&&h.paymentStatus!==g)return!1;if(E!=="all"){const Q=!!h.remunerationId,G=c.find(F=>F.id===h.remunerationId),J=(G==null?void 0:G.isPaid)||!1;if(E==="paid"&&(!Q||!J)||E==="unpaid"&&Q&&J)return!1}return h.projectName.toLowerCase().includes(k.toLowerCase())||h.clientName.toLowerCase().includes(k.toLowerCase())}).sort((h,O)=>{const Q=R.direction==="asc"?1:-1;if(D==="month"){const G=h.month||"",J=O.month||"";return G===J?(h.serialNumber-O.serialNumber)*Q:G<J?-1*Q:G>J?1*Q:0}else return(h.serialNumber-O.serialNumber)*Q}),[o,w,T,m,k,R,D,L,B,n,g,E,c]),Ka=i.useMemo(()=>pt.reduce((h,O)=>({revenue:h.revenue+(Number(O.amountTotal)||0),outstanding:h.outstanding+(O.paymentStatus==="unpaid"&&Number(O.amountTotal)||0)}),{revenue:0,outstanding:0}),[pt]),Me=i.useMemo(()=>o.filter(h=>K.has(h.id)),[o,K]),Ya=(h,O,Q)=>{if(h.isAutoCalc===!1&&h.amount!==void 0)return h.amount;const G=O-Q;return Math.round(G*(h.percentage/100))+(Number(h.cost)||0)},Te=i.useMemo(()=>Me.reduce((h,O)=>{const Q=O.splitShares.find(J=>J.name==="KOL"),G=Q?Ya(Q,O.amountTotal,O.costExtra):0;return h+G},0),[Me]),hs=(h,O)=>{Ae.edit&&(O.target.closest("button")||O.target.closest("a")||h.remunerationId||re(Q=>{const G=new Set(Q);return G.has(h.id)?G.delete(h.id):G.add(h.id),G}))},gs=async()=>{var h;if(!Ae.edit){Ee("權限不足:無法進行對帳操作","error");return}if(K.size!==0){Ha(!0);try{const Q=((c.length>0?Math.max(...c.map(ue=>parseInt(ue.serialNumber)||0)):0)+1).toString(),G=Te>=$a?Math.round(Te*Ma):0,J=Te>=ls?Math.round(Te*Yt["9A"]):0,F=Te-G-J,Ie={tableId:a,serialNumber:Q,kolName:(r==null?void 0:r.name)||"專案結帳",amountPayable:Te,healthTax:G,professionalTax:J,netAmount:F,isPaid:!1,paymentDate:null,link:"",isAutoCalc:!0,projectSerials:Me.map(ue=>ue.serialNumber.toString()),month:((h=Me[0])==null?void 0:h.month)||new Date().toISOString().slice(0,7)},Pe=await Ft(Ie);await Promise.all(Me.map(ue=>yt(ue.id,{remunerationId:Pe.id,remunerationSerial:Q}))),Ee(`對帳成功!已產生勞報單 #${Q}`),re(new Set),At(!1),rt(a)}catch{Ee("對帳失敗","error")}finally{Ha(!1)}}},vs=async()=>{var h;if(!Ae.edit){Ee("權限不足:無法進行 B2B 結帳操作","error");return}if(K.size!==0){Ga(!0);try{const O=c.filter(ue=>ue.type==="b2b"),G=((O.length>0?Math.max(...O.map(ue=>parseInt(ue.serialNumber)||0)):0)+1).toString(),J=Math.round(Te*Uo),F=Te+J,Ie={tableId:a,serialNumber:G,kolName:(r==null?void 0:r.name)||"B2B 結帳",amountPayable:Te,healthTax:0,professionalTax:J,netAmount:F,isPaid:!1,paymentDate:null,link:"",isAutoCalc:!0,projectSerials:Me.map(ue=>ue.serialNumber.toString()),type:"b2b",month:((h=Me[0])==null?void 0:h.month)||new Date().toISOString().slice(0,7)},Pe=await Ft(Ie);await Promise.all(Me.map(ue=>yt(ue.id,{remunerationId:Pe.id,remunerationSerial:G}))),Ee(`B2B 結帳成功!已產生 B2B 紀錄 #${G}`),re(new Set),It(!1),rt(a)}catch{Ee("B2B 結帳失敗","error")}finally{Ga(!1)}}},Qa=async h=>{if(h)le(h);else{const O=await xr(a),Q=O.length>0?Math.max(...O.map(J=>J.serialNumber||0)):0,G=(r==null?void 0:r.defaultSplitShares)||or.splitShares;le({...or,serialNumber:Q+1,tableId:a,month:T||`${w}-01`,assignee:f[0]||"",splitShares:JSON.parse(JSON.stringify(G))})}C(!0)},fs=async h=>{try{h.id?await yt(h.id,h):await Vn(h),C(!1),rt(a),Ee("儲存成功")}catch{Ee("儲存失敗","error")}},ys=async()=>
31{if(Ve)try{await Gn(Ve),d(h=>h.filter(O=>O.id!==Ve)),Ge(null),Ee("專案已刪除")}catch{Ee("刪除失敗","error")}},js=h=>({negotiating:"洽談中",reviewing:"審稿中",executing:"執行中",closed:"已結案",planning:"規劃中",cancelled:"已取消"})[h]||h,ws=h=>({pending:"待處理",issued:"已開立",labor_receipt:"勞報單",invoice:"發票",group_receipt:"收據"})[h]||h,Ns=()=>{try{const h=pt.map(F=>{const Ie=F.splitShares.map(ue=>`${ue.name}:${ue.percentage}%`).join("; "),Pe=F.splitShares.map(ue=>`${ue.name}:$${ue.cost||0}`).join("; ");return{序號:F.serialNumber,執行月份:F.month,指派人:F.assignee,專案名稱:F.projectName,專案狀態:js(F.status),"AC/BC":F.acBc||"",廠商名稱:F.clientName,合作項目:F.collaborationItem,是否抽獲:F.hasLottery?"有":"無","CUE 表連結":F.cueStatus,內容狀態:F.contentStatus,產品狀態:F.productStatus,產品是否回收:F.isProductRecycled?"是":"否","總金額(未稅)":F.amountTotal,稅金:F.taxAmount,含稅總額:F.amountGross,額外成本:F.costExtra,分潤配置:Ie,分潤成本:Pe,報價單狀態:F.quotationStatus==="issued"?"已開立":"未開立",報價單已回簽:F.isQuotationSigned?"是":"否",發票狀態:ws(F.invoiceStatus),發票號碼:F.invoiceNumber||"",發票抬頭:F.invoiceTitle||"",統一編號:F.invoiceTaxId||"",匯款進度:F.paymentStatus==="paid"?"已收款":"未收款",入帳日期:F.paymentDate||"",銀行帳號後五碼:F.bankAccountLast5||"",勞報編號:F.remunerationSerial||"",關聯勞報ID:F.remunerationId||"",專案備註:F.note||""}}),O=pa.json_to_sheet(h),Q=[{wch:8},{wch:12},{wch:10},{wch:30},{wch:12},{wch:10},{wch:20},{wch:25},{wch:10},{wch:40},{wch:20},{wch:12},{wch:12},{wch:15},{wch:12},{wch:15},{wch:12},{wch:30},{wch:30},{wch:12},{wch:12},{wch:12},{wch:15},{wch:20},{wch:12},{wch:12},{wch:12},{wch:15},{wch:12},{wch:20},{wch:40}];O["!cols"]=Q;const G=pa.book_new();pa.book_append_sheet(G,O,"商案執行進度");const J=`商案執行進度_${(r==null?void 0:r.name)||"未命名"}_${new Date().toISOString().slice(0,10)}.xlsx`;hn(G,J),Ee(`成功匯出 ${pt.length} 筆資料`,"success")}catch(h){console.error("匯出失敗:",h),Ee("匯出失敗,請稍後再試","error")}},Ss=()=>{$("all"),U("all"),p("all"),P("all"),z("all"),_("all"),A("")},ks=({status:h,acBc:O})=>{const Q={negotiating:"bg-[var(--warning)]/10 text-[var(--warning)] border-[var(--warning)]/20",reviewing:"bg-[var(--id-purple)]/10 text-[var(--id-purple)] border-[var(--id-purple)]/20",executing:"bg-[var(--accent)]/10 text-[var(--accent)] border-[var(--accent)]/20",closed:"bg-[var(--success)]/10 text-[var(--success)] border-[var(--success)]/20"},G={negotiating:"洽談",reviewing:"審稿",executing:"執行",closed:"已結案"};return e.jsxs("div",{className:"flex flex-col items-center gap-1",children:[e.jsx("span",{className:`px-2.5 py-0.5 rounded text-13 font-bold border ${Q[h]}`,children:G[h]}),O&&e.jsx("span",{className:"text-11 font-bold bg-[var(--id-pink)]/10 text-[var(--id-pink)] px-1.5 rounded-full border border-[var(--id-pink)]/20 tracking-tighter",children:O})]})},Cs=({status:h})=>{const O={pending:{label:"待處理",style:"bg-[var(--error)]/10 text-[var(--error)] border-[var(--error)]/20"},issued:{label:"已開立",style:"bg-[var(--success)]/10 text-[var(--success)] border-[var(--success)]/20"},labor_receipt:{label:"勞報單",style:"bg-[var(--accent)]/10 text-[var(--accent)] border-[var(--accent)]/20"},invoice:{label:"發票",style:"bg-[var(--id-indigo)]/10 text-[var(--id-indigo)] border-[var(--id-indigo)]/20"},group_receipt:{label:"收據",style:"bg-[var(--id-cyan)]/10 text-[var(--id-cyan)] border-[var(--id-cyan)]/20"}},{label:Q,style:G}=O[h]||O.pending;return e.jsx("span",{className:`text-11 px-1.5 py-0.5 rounded font-bold border ${G}`,children:Q})};return e.jsxs("div",{className:"p-4 md:p-6 h-full font-sans flex flex-col bg-[var(--bg-page)]",children:[y&&e.jsx(Po,{message:y.message,type:y.type,onClose:()=>j(null)}),e.jsxs("div",{className:"flex flex-col gap-4 mb-5 shrink-0",children:[e.jsxs("div",{className:"flex flex-col xl:flex-row xl:items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold text-[var(--text-primary)] flex items-center gap-2",children:r==null?void 0:r.name}),e.jsx("p",{className:"text-[var(--text-muted)] text-xs mt-0.5",children:"商案執行進度與分潤表"})]}),e.jsxs("div",{className:"flex items-center gap-5 bg-[var(--bg-card)] border border-[var(--border)] p-2.5 px-6 rounded-2xl",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-11 text-[var(--text-muted)] font-bold uppercase tracking-widest text-center",children:"篩選總收"}),e.jsxs("div",{className:"text-lg font-bold text-[var(--text-primary)] font-mono leading-none",children:["NT$",
31Ka.revenue.toLocaleString()]})]}),e.jsx("div",{className:"w-px h-6 bg-[var(--border)]"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-11 text-[var(--text-muted)] font-bold uppercase tracking-widest text-center text-[var(--error)]/80",children:"未收帳款"}),e.jsxs("div",{className:"text-lg font-bold text-[var(--error)] font-mono leading-none",children:["NT$",Ka.outstanding.toLocaleString()]})]})]})]}),e.jsxs("div",{className:"flex flex-col bg-[var(--bg-card)] border border-[var(--border)] p-4 rounded-2xl gap-4",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row items-stretch sm:items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row items-stretch sm:items-center gap-3 flex-1",children:[e.jsxs("div",{className:"relative group flex-1 sm:max-w-[260px]",children:[e.jsx(cn,{className:"absolute left-3 top-1/2 -translate-y-1/2 text-[var(--text-muted)]",size:14}),e.jsx("input",{"aria-label":"搜尋專案...",type:"text",value:k,onChange:h=>A(h.target.value),placeholder:"搜尋專案...",className:"w-full bg-[var(--bg-card-alt)] border border-[var(--border)] text-[var(--text-primary)] pl-8 pr-4 py-2 rounded-xl focus:border-[var(--accent)] outline-none transition-all text-14 h-10"})]}),e.jsx(Qo,{currentYear:w,currentMonthStr:T,onChange:(h,O)=>{v(h),S(O)},className:"w-full sm:w-44"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>Ba(!0),className:"flex items-center gap-2 px-4 py-2 bg-[var(--id-orange)]/10 text-[var(--id-orange)] border border-[var(--id-orange)]/20 rounded-xl text-xs font-bold h-10 shadow-sm transition-all hover:bg-[var(--id-orange)]/20",children:[e.jsx(st,{size:14})," B2B 對帳"]}),e.jsxs("button",{onClick:()=>Fa(!0),className:"flex items-center gap-2 px-4 py-2 bg-[var(--success)]/10 text-[var(--success)] border border-[var(--success)]/20 rounded-xl text-xs font-bold h-10 shadow-sm transition-all hover:bg-[var(--success)]/20",children:[e.jsx(tr,{size:14})," 勞報管理"]}),e.jsxs("button",{onClick:()=>Ua(!0),className:"flex items-center gap-2 px-4 py-2 bg-[var(--id-purple)]/10 text-[var(--id-purple)] border border-[var(--id-purple)]/20 rounded-xl text-xs font-bold h-10 shadow-sm transition-all hover:bg-[var(--id-purple)]/20",children:[e.jsx(Lr,{size:14})," 雜支紀錄"]}),e.jsx("button",{onClick:Ns,className:"p-2.5 bg-[var(--bg-card-alt)] text-[var(--text-secondary)] hover:text-[var(--text-primary)] rounded-xl border border-[var(--border)] h-10 hover:bg-[var(--bg-card-alt)] transition-all",title:"匯出 Excel",children:e.jsx(dn,{size:14})}),Ae.create&&e.jsxs("button",{onClick:()=>Qa(),className:"flex items-center gap-2 px-5 py-2 bg-[var(--accent)] hover:bg-[var(--accent-hover)] text-[var(--button-text)] rounded-xl text-xs font-bold shadow-md h-10 transition-all",children:[e.jsx(ze,{size:16})," 新增"]})]})]}),e.jsxs("div",{className:"flex items-center gap-4 flex-wrap border-t border-[var(--border)] pt-3",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("span",{className:"text-12 font-bold text-[var(--text-muted)] uppercase tracking-widest flex items-center gap-1",children:[e.jsx(un,{size:12})," 進階篩選:"]})}),e.jsxs("div",{className:"relative min-w-[100px]",children:[e.jsxs("select",{"aria-label":"篩選:指派",value:m,onChange:h=>_(h.target.value),className:"w-full bg-[var(--bg-card-alt)] border border-[var(--border)] text-[var(--text-primary)] pl-3 pr-8 py-1.5 rounded-lg appearance-none focus:border-[var(--accent)] outline-none transition-all text-13 font-bold h-8",children:[e.jsx("option",{value:"all",children:"指派: 全部"}),f.map(h=>e.jsx("option",{value:h,children:h},h))]}),e.jsx(Ne,{className:"absolute right-2 top-1/2 -translate-y-1/2 text-[var(--text-muted)] pointer-events-none",size:10})]}),e.jsxs("div",{className:"relative min-w-[100px]",children:[e.jsxs("select",{"aria-label":"篩選:狀態",value:L,onChange:h=>$(h.target.value),className:"w-full bg-[var(--bg-card-alt)] border border-[var(--border)] text-[var(--text-primary)] pl-3 pr-8 py-1.5 rounded-lg appearance-none focus:border-[var(--accent)] outline-none transition-all text-13 font-bold h-8",children:[e.jsx("option",{value:"all",children:"狀態: 全部"}),e.jsx("option",{value:"negotiating",children:"洽談中"}),e.jsx("option",{value:"reviewing",children:"審稿中"}),e.jsx("option",{value:"executing",children:"執行中"}),e.jsx("option",{value:"closed",children:"已結案"})]}),e.jsx(Ne,{className:"absolute right-2 top-1/2 -translate-y-1/2 text-[var(--text-muted)] pointer-events-none",size:10})]}),e.jsxs("div",{className:"relative min-w-[100px]",children:[e.jsxs("select",{"aria-label":"篩選:報價單",value:
31B,onChange:h=>U(h.target.value),className:"w-full bg-[var(--bg-card-alt)] border border-[var(--border)] text-[var(--text-primary)] pl-3 pr-8 py-1.5 rounded-lg appearance-none focus:border-[var(--accent)] outline-none transition-all text-13 font-bold h-8",children:[e.jsx("option",{value:"all",children:"報價單: 全部"}),e.jsx("option",{value:"pending",children:"未處理"}),e.jsx("option",{value:"issued",children:"已開立"}),e.jsx("option",{value:"unsigned",children:"未回簽"}),e.jsx("option",{value:"signed",children:"已回簽"})]}),e.jsx(Ne,{className:"absolute right-2 top-1/2 -translate-y-1/2 text-[var(--text-muted)] pointer-events-none",size:10})]}),e.jsxs("div",{className:"relative min-w-[100px]",children:[e.jsxs("select",{"aria-label":"篩選:發票開立",value:n,onChange:h=>p(h.target.value),className:"w-full bg-[var(--bg-card-alt)] border border-[var(--border)] text-[var(--text-primary)] pl-3 pr-8 py-1.5 rounded-lg appearance-none focus:border-[var(--accent)] outline-none transition-all text-13 font-bold h-8",children:[e.jsx("option",{value:"all",children:"發票開立: 全部"}),e.jsx("option",{value:"pending",children:"待處理"}),e.jsx("option",{value:"issued",children:"已開立"}),e.jsx("option",{value:"labor_receipt",children:"勞報單"}),e.jsx("option",{value:"invoice",children:"發票"}),e.jsx("option",{value:"group_receipt",children:"收據"})]}),e.jsx(Ne,{className:"absolute right-2 top-1/2 -translate-y-1/2 text-[var(--text-muted)] pointer-events-none",size:10})]}),e.jsxs("div",{className:"relative min-w-[100px]",children:[e.jsxs("select",{"aria-label":"篩選:廠商匯款",value:g,onChange:h=>P(h.target.value),className:"w-full bg-[var(--bg-card-alt)] border border-[var(--border)] text-[var(--text-primary)] pl-3 pr-8 py-1.5 rounded-lg appearance-none focus:border-[var(--accent)] outline-none transition-all text-13 font-bold h-8",children:[e.jsx("option",{value:"all",children:"廠商匯款: 全部"}),e.jsx("option",{value:"unpaid",children:"未收款"}),e.jsx("option",{value:"paid",children:"已收款"})]}),e.jsx(Ne,{className:"absolute right-2 top-1/2 -translate-y-1/2 text-[var(--text-muted)] pointer-events-none",size:10})]}),e.jsxs("div",{className:"relative min-w-[100px]",children:[e.jsxs("select",{"aria-label":"篩選:KOL匯款",value:E,onChange:h=>z(h.target.value),className:"w-full bg-[var(--bg-card-alt)] border border-[var(--border)] text-[var(--text-primary)] pl-3 pr-8 py-1.5 rounded-lg appearance-none focus:border-[var(--accent)] outline-none transition-all text-13 font-bold h-8",children:[e.jsx("option",{value:"all",children:"KOL匯款: 全部"}),e.jsx("option",{value:"unpaid",children:"未支付"}),e.jsx("option",{value:"paid",children:"已支付"})]}),e.jsx(Ne,{className:"absolute right-2 top-1/2 -translate-y-1/2 text-[var(--text-muted)] pointer-events-none",size:10})]}),e.jsxs("button",{onClick:Ss,className:"text-12 font-bold text-[var(--text-muted)] hover:text-[var(--error)] flex items-center gap-1 px-2 py-1 rounded hover:bg-[var(--error)]/10 transition-all",children:[e.jsx(xn,{size:12})," 重設篩選"]}),e.jsxs("div",{className:"flex items-center gap-2 md:ml-auto md:pl-4 md:border-l border-[var(--border)] order-first md:order-last",children:[e.jsxs("span",{className:"text-12 font-bold text-[var(--text-muted)] uppercase tracking-widest flex items-center gap-1",children:[e.jsx(ta,{size:12})," 排序:"]}),e.jsxs("div",{className:"flex items-center bg-[var(--bg-card-alt)] rounded-lg p-0.5 border border-[var(--border)]",children:[e.jsxs("button",{onClick:()=>{N("serialNumber"),I({key:"serialNumber",direction:"desc"})},className:`flex items-center gap-1 px-2.5 py-1 rounded-md text-12 font-bold transition-all ${D==="serialNumber"?"bg-[var(--accent)] text-[var(--button-text)] shadow-sm":"text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-card-alt)]"}`,children:[e.jsx(mn,{size:10})," 序號"]}),e.jsxs("button",{onClick:()=>{N("month"),I({key:"month",direction:"desc"})},className:`flex items-center gap-1 px-2.5 py-1 rounded-md text-12 font-bold transition-all ${D==="month"?"bg-[var(--accent)] text-[var(--button-text)] shadow-sm":"text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-card-alt)]"}`,children:[e.jsx(Zt,{size:10})," 執行月份"]})]})]})]})]})]}),e.jsx("div",{className:"flex-1 overflow-auto bg-[var(--bg-card)] rounded-2xl border border-[var(--border)] shadow-2xl relative z-10 custom-scrollbar",children:e.jsxs("table",{className:"w-full text-center border-collapse min-w-[1400px]",children:[e.jsx("thead",{className:"sticky top-0 z-20 bg-[var(--bg-card-alt)] shadow-sm",children:e.jsxs("tr",{children:[e.jsx("th",{className:"py-3 px-2 text-13 font-bold text-[var(--text-muted)] border-b border-[var(--border)] w-10",children:"#"}),e.jsx("th",{className:"py-3 px-2 text-13 font-bold text-[var(--text-secondary)] border-b border-[var(--border)] w-20",children:"狀態"}),e.jsx("th",{className:"py-3 px-4 text-13 font-bold text-[var(--text-secondary)] border-b border-[var(--border)] w-[300px] text-center",children:"專案名稱 / 指派"}),e.jsx("th",{className:"py-3 px-4 text-13 font-bold text-[var(--text-secondary)] border-b border-[var(--border)] w-24",children:"報價單"}),e.jsx("th",{className:"py-3 px-4 text-13 font-bold text-[var(--text-secondary)] border-b border-[var(--border)] w-44",children:"合作內容 / 廠商"}),e.jsx("th",{className:"py-3 px-4 text-13 font-bold text-[var(--text-secondary)] border-b border-[var(--border)] w-24",children:"CUE / 備註"}),e.jsx("th",{className:"py-3 px-2 text-13 font-bold text-[var(--text-secondary)] border-b border-[var(--border)] w-20",children:"物流"}),e.jsx("th",{className:"py-3 px-4 text-13 font-bold text-[var(--accent)] border-b border-[var(--border)] w-32",children:"預算 (未稅)"}),e.jsx("th",{className:"py-3 px-4 text-13 font-bold text-[var(--success)] border-b border-[var(--border)] w-36",children:"KOL 分潤"}),e.jsx("th",{className:"py-3 px-2 text-13 font-bold text-[var(--text-secondary)] border-b border-[var(--border)] w-28",children:"財務"}),e.jsx("th",{className:"py-3 px-4 text-13 font-bold text-[var(--text-secondary)] border-b border-[var(--border)] w-28",children:"操作"})]})}),e.jsx("tbody",{className:"divide-y divide-[var(--border)] nk-list nk-zebra",children:pt.map(h=>{const O=h.splitShares.find(Pe=>Pe.name==="KOL"),Q=O?Ya(O,h.amountTotal,h.costExtra):0,G=K.has(h.id),J=c.find(Pe=>Pe.id===h.remunerationId),F=!!h.remunerationId,Ie=(J==null?void 0:J.isPaid)===!0;return e.jsxs("tr",{onClick:Pe=>hs(h,Pe),className:`transition-all group border-b border-[var(--border)] last:border-0 ${F?"cursor-not-allowed opacity-80":"cursor-pointer hover:bg-[var(--bg-card-alt)]"} ${G?"bg-[var(--accent)]/10":""}`,children:[e.jsx("td",{className:"py-4 px-2 text-center font-mono text-[var(--text-muted)] text-12",children:e.jsxs("div",{className:"flex flex-col items-center gap-1",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1",children:[F&&e.jsx(Oe,{size:10,
31className:"text-[var(--accent)]/70"}),h.serialNumber]}),h.month&&e.jsx("div",{className:"text-11 text-[var(--text-muted)] font-bold bg-[var(--bg-card-alt)] px-1.5 py-0.5 rounded border border-[var(--border)] whitespace-nowrap",children:h.month})]})}),e.jsx("td",{className:"py-4 px-2 text-center",children:e.jsx(ks,{status:h.status,acBc:h.acBc})}),e.jsx("td",{className:"py-4 px-4 text-center",children:e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("span",{className:"font-bold text-[var(--text-primary)] text-14 group-hover:text-[var(--accent)] transition-colors leading-tight",children:h.projectName}),e.jsxs("span",{className:"text-12 text-[var(--id-indigo)]/80 font-bold uppercase tracking-tight mt-1",children:["@",h.assignee]})]})}),e.jsx("td",{className:"py-4 px-4 text-center",children:e.jsxs("div",{className:"flex flex-col items-center gap-1",children:[h.quotationStatus==="issued"&&e.jsx("span",{className:"px-2 py-0.5 rounded text-12 font-bold bg-[var(--accent)]/10 text-[var(--accent)] border border-[var(--accent)]/20",children:"已開立"}),h.isQuotationSigned&&e.jsx("span",{className:"px-2 py-0.5 rounded text-12 font-bold bg-[var(--success)]/10 text-[var(--success)] border border-[var(--success)]/20",children:"已回簽"}),!h.quotationStatus&&!h.isQuotationSigned&&e.jsx("span",{className:"text-[var(--text-muted)]",children:"-"})]})}),e.jsx("td",{className:"py-4 px-4 text-center",children:e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("span",{className:"text-xs text-[var(--text-primary)] truncate max-w-[150px] font-medium",children:h.collaborationItem||"-"}),e.jsx("span",{className:"text-13 text-supplier truncate max-w-[150px] mt-0.5",children:h.clientName})]})}),e.jsx("td",{className:"py-4 px-4 text-center",children:e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[h.cueStatus?e.jsx("a",{href:h.cueStatus,target:"_blank",rel:"noopener noreferrer",title:`CUE 表連結: ${h.cueStatus}`,className:"p-1.5 bg-[var(--id-purple)]/10 text-[var(--id-purple)] rounded-lg hover:bg-[var(--id-purple)]/20 transition-all border border-[var(--id-purple)]/20",children:e.jsx(zr,{size:14})}):null,h.note?e.jsx("button",{onClick:()=>xa(h.note),title:`備註內容: ${h.note}`,className:"p-1.5 bg-[var(--bg-card-alt)] text-[var(--text-secondary)] rounded-lg hover:bg-[var(--bg-card-alt)] transition-all border border-[var(--border)]",children:e.jsx(ar,{size:14})}):null,!h.cueStatus&&!h.note&&e.jsx("span",{className:"text-[var(--text-muted)]",children:"-"})]})}),e.jsx("td",{className:"py-4 px-2 text-center",children:e.jsxs("div",{className:"flex flex-col items-center gap-1",children:[h.productStatus==="已收到"?e.jsx("span",{className:"text-11 font-bold text-[var(--success)] bg-[var(--success)]/10 px-1 rounded border border-[var(--success)]/20",children:"已收"}):h.productStatus==="尚未收到"?e.jsx("span",{className:"text-11 font-bold text-[var(--warning)] bg-[var(--warning)]/10 px-1 rounded border border-[var(--warning)]/20",children:"未收"}):e.jsx("span",{className:"text-[var(--text-muted)]",children:"-"}),h.isProductRecycled&&e.jsx("span",{className:"text-11 bg-[var(--accent)]/10 text-[var(--accent)] px-1 rounded font-extrabold uppercase border border-[var(--accent)]/20",children:"回收"})]})}),e.jsxs("td",{className:"py-4 px-4 text-center font-mono font-bold text-[var(--accent)] text-14",children:["NT$",h.amountTotal.toLocaleString()]}),e.jsx("td",{className:"py-4 px-4 text-center",children:e.jsxs("div",{className:"flex flex-col items-center gap-0.5",children:[e.jsxs("span",{className:"font-mono font-bold text-[var(--success)] text-14",children:["NT$",Q.toLocaleString()]}),F?e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:`text-11 font-bold px-1.5 rounded border flex items-center gap-1 ${Ie?"bg-[var(--accent)]/10 text-[var(--accent)] border-[var(--accent)]/20":"bg-[var(--warning)]/10 text-[var(--warning)] border-[var(--warning)]/20"}`,children:[(J==null?void 0:J.type)==="b2b"?e.jsx(st,{size:10}):e.jsx(tr,{size:10}),"#",h.remunerationSerial," ",Ie?"已支付":"待支付"]}),(J==null?void 0:J.paymentDate)&&e.jsx("span",{className:"text-11 text-[var(--accent)] font-mono mt-0.5",children:J.paymentDate})]}):e.jsx("span",{className:"text-11 font-bold text-[var(--text-muted)]",children:"未支付"})]})}),e.jsx("td",{className:"py-4 px-2 text-center",children:e.jsxs("div",{className:"flex flex-col items-center gap-1",children:[h.paymentStatus==="paid"?e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-12 font-bold text-[var(--success)] flex items-center gap-1",children:[e.jsx("div",{className:"w-1 h-1 rounded-full bg-[var(--success)]"}),"已收款"]}),h.paymentDate&&e.jsx("span",{className:"text-11 text-[var(--success)] font-mono",children:h.paymentDate})]}):e.jsxs("span",{className:"text-12 font-bold text-[var(--error)] flex items-center gap-1",children:[e.jsx("div",{className:"w-1 h-1 rounded-full bg-[var(--error)]"}),"未收款"]}),e.jsx("div",{className:"mt-0.5",children:e.jsx(Cs,{status:h.invoiceStatus})})]})}),e.jsx("td",{className:"py-4 px-4 text-center",children:e.jsxs("div",{className:"flex items-center justify-center gap-1.5 transition-opacity",children:[e.jsx("button",{onClick:()=>{_t(h),fe(!0)},className:"p-1.5 text-[var(--text-muted)] hover:text-[var(--id-purple)] rounded-lg transition-all",title:"拆帳",children:e.jsx(Rt,{size:16})}),e.jsx("button",{onClick:()=>Qa(h),className:`p-1.5 rounded-lg transition-all ${F?"text-[var(--accent)]/70 hover:text-[var(--accent)]":"text-[var(--text-muted)] hover:text-[var(--accent)]"}`,title:Ae.edit?F?"編輯 (財務鎖定)":"編輯":"檢視詳情",children:Ae.edit?e.jsx(qe,{size:16}):e.jsx(qe,{size:16,className:"opacity-60"})}),Ae.delete&&!F&&e.jsx("button",{onClick:()=>Ge(h.id),className:"p-1.5 text-[var(--text-muted)] hover:text-[var(--error)] rounded-lg transition-all",title:"刪除",children:e.jsx(it,{size:16})}),F&&e.jsx("span",{className:"text-11 text-[var(--accent)]/70 italic",children:"財務鎖定"})]})})]}
31,h.id)})})]})}),K.size>0&&Ae.edit&&e.jsx("div",{className:"fixed bottom-8 left-1/2 -translate-x-1/2 z-50 nk-in-up",children:e.jsxs("div",{className:"bg-[var(--bg-card)] border border-[var(--accent)]/30 rounded-2xl shadow-2xl p-4 flex items-center gap-6 backdrop-blur-xl ring-4 ring-black/20",children:[e.jsxs("div",{className:"flex items-center gap-3 pl-2",children:[e.jsx("div",{className:"w-10 h-10 bg-[var(--accent)] rounded-xl flex items-center justify-center text-[var(--button-text)] shadow-lg",children:e.jsx(pn,{size:20})}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-[var(--text-primary)] font-bold text-sm",children:["已選取 ",K.size," 個專案"]}),e.jsxs("p",{className:"text-[var(--accent)] font-mono text-xs",children:["小計: NT$",Te.toLocaleString()]})]})]}),e.jsx("div",{className:"w-px h-10 bg-[var(--border)] mx-2"}),e.jsxs("button",{onClick:()=>At(!0),className:"flex items-center gap-2 px-6 py-2.5 bg-[var(--accent)] hover:bg-[var(--accent-hover)] text-[var(--button-text)] rounded-xl text-xs font-bold transition-all active:scale-95 shadow-lg shadow-blue-900/20",children:[e.jsx(rr,{size:16})," 勞報結帳"]}),e.jsxs("button",{onClick:()=>It(!0),className:"flex items-center gap-2 px-6 py-2.5 bg-orange-600 hover:bg-orange-500 text-white rounded-xl text-xs font-bold transition-all active:scale-95 shadow-lg shadow-orange-900/20",children:[e.jsx(st,{size:16})," B2B結帳"]})]})}),me&&ee&&e.jsx(Wo,{initialData:ee,onClose:()=>C(!1),onSave:fs,assigneeOptions:f,isFinancialLocked:!!ee.remunerationId,readOnly:!Ae.edit}),ds&&e.jsx(Vo,{tableId:a,onClose:()=>{Fa(!1),rt(a)},defaultKOLName:r==null?void 0:r.name,permission:Ae,projects:o}),us&&e.jsx(Go,{tableId:a,onClose:()=>{Ba(!1),rt(a)},defaultKOLName:r==null?void 0:r.name,permission:Ae,projects:o}),xs&&e.jsx(Yo,{tableId:a,tableName:r==null?void 0:r.name,onClose:()=>Ua(!1),permission:Ae}),e.jsx(pe,{isOpen:ms,onClose:()=>At(!1),zIndex:130,maxWidth:"max-w-sm",contentClassName:"bg-[var(--bg-card)] border border-[var(--accent)]/30 p-8 rounded-[32px] w-full shadow-2xl",children:e.jsxs("div",{className:"flex flex-col items-center text-center gap-5",children:[e.jsx("div",{className:"w-16 h-16 bg-[var(--accent)]/10 rounded-full flex items-center justify-center text-[var(--accent)] text-3xl",children:e.jsx(rr,{size:32})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-bold text-[var(--text-primary)] mb-2",children:"確認勞報結帳?"}),e.jsx("p",{className:"text-[var(--text-secondary)] text-sm",children:"系統將為選取的專案產生一筆勞報紀錄(預設為未支付)。"})]}),e.jsxs("div",{className:"flex gap-3 w-full mt-2",children:[e.jsx("button",{onClick:()=>At(!1),className:"flex-1 py-2.5 bg-[var(--bg-card-alt)] text-[var(--text-secondary)] rounded-xl font-bold text-xs hover:bg-[var(--bg-card-alt)] transition-all",children:"取消"}),e.jsxs("button",{onClick:gs,disabled:Wa,className:"flex-1 py-2.5 bg-[var(--accent)] text-[var(--button-text)] rounded-xl font-bold text-xs hover:bg-[var(--accent-hover)] shadow-lg flex items-center justify-center gap-2",children:[Wa?e.
31jsx(be,{size:16,className:"animate-spin"}):e.jsx(Qe,{size:16}),"確認對帳"]})]})]})}),e.jsx(pe,{isOpen:ps,onClose:()=>It(!1),zIndex:130,maxWidth:"max-w-sm",contentClassName:"bg-[var(--bg-card)] border border-[var(--id-orange)]/30 p-8 rounded-[32px] w-full shadow-2xl",children:e.jsxs("div",{className:"flex flex-col items-center text-center gap-5",children:[e.jsx("div",{className:"w-16 h-16 bg-[var(--id-orange)]/10 rounded-full flex items-center justify-center text-[var(--id-orange)] text-3xl",children:e.jsx(st,{size:32})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-bold text-[var(--text-primary)] mb-2",children:"確認 B2B 結帳?"}),e.jsx("p",{className:"text-[var(--text-secondary)] text-sm",children:"系統將為選取的專案產生一筆 B2B 結帳紀錄(固定 5% 扣稅)。"})]}),e.jsxs("div",{className:"flex gap-3 w-full mt-2",children:[e.jsx("button",{onClick:()=>It(!1),className:"flex-1 py-2.5 bg-[var(--bg-card-alt)] text-[var(--text-secondary)] rounded-xl font-bold text-xs hover:bg-[var(--bg-card-alt)] transition-all",children:"取消"}),e.jsxs("button",{onClick:vs,disabled:Va,className:"flex-1 py-2.5 bg-orange-600 text-white rounded-xl font-bold text-xs hover:bg-orange-500 shadow-lg flex items-center justify-center gap-2",children:[Va?e.jsx(be,{size:16,className:"animate-spin"}):e.jsx(Qe,{size:16}),"確認結帳"]})]})]})}),e.jsxs(pe,{isOpen:!!qa,onClose:()=>xa(null),zIndex:110,maxWidth:"max-w-md",contentClassName:"bg-[var(--bg-card)] border border-[var(--border)] p-6 rounded-2xl w-full shadow-2xl",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsxs("h3",{className:"text-xs font-bold text-[var(--text-secondary)] uppercase tracking-widest flex items-center gap-2",children:[e.jsx(ar,{size:16,className:"text-[var(--accent)]"})," 專案備註"]}),e.jsx("button",{onClick:()=>xa(null),className:"text-[var(--text-muted)] hover:text-[var(--text-primary)]",children:e.jsx(ye,{size:18})})]}),e.jsx("div",{className:"bg-[var(--bg-card-alt)] p-4 rounded-xl border border-[var(--border)] text-[var(--text-primary)] text-14 leading-relaxed min-h-[100px] whitespace-pre-wrap",children:qa})]}),e.jsx(pe,{isOpen:!!Ve,onClose:()=>Ge(null),zIndex:120,maxWidth:"max-w-xs",contentClassName:"bg-[var(--bg-card)] border border-[var(--error)]/30 p-8 rounded-2xl w-full shadow-2xl",children:e.jsxs("div",{className:"flex flex-col items-center text-center gap-4",children:[e.jsx("div",{className:"w-12 h-12 bg-[var(--error)]/10 rounded-full flex items-center justify-center text-[var(--error)]",children:e.jsx(De,{size:24})}),e.jsx("h3",{className:"text-lg font-bold text-[var(--text-primary)]",children:"確認刪除專案?"}),e.jsxs("div",{className:"flex gap-2 w-full mt-2",children:[e.jsx("button",{onClick:()=>Ge(null),className:"flex-1 py-2.5 bg-[var(--bg-card-alt)] text-[var(--text-secondary)] rounded-xl font-bold text-xs hover:bg-[var(--bg-card-alt)]",children:"取消"}),e.jsx("button",{onClick:ys,className:"flex-1 py-2.5 bg-[var(--error)] text-[var(--button-text)] rounded-xl font-bold text-xs hover:bg-[var(--error)]/90",children:"刪除"})]})]})}),e.jsx(pe,{isOpen:Ce&&!!ce,onClose:()=>fe(!1),zIndex:100,maxWidth:"max-w-lg",contentClassName:"bg-[var(--bg-card)] border border-[var(--border)] p-8 rounded-[32px] w-full shadow-2xl overflow-hidden relative",children:Ce&&ce&&(()=>{const h=ce.amountTotal-ce.costExtra;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"absolute top-0 left-0 w-full h-1.5 bg-[var(--accent)]"}),e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-2xl font-bold text-[var(--text-primary)] tracking-tight",children:"利潤拆帳分析"}),e.jsx("p",{className:"text-[var(--text-muted)] text-13 mt-1 uppercase tracking-widest font-bold",children:ce.projectName})]}),e.jsx("button",{onClick:()=>fe(!1),className:"text-[var(--text-muted)] hover:text-[var(--text-primary)] p-2 hover:bg-[var(--bg-card-alt)] rounded-xl transition-all",children:e.jsx(ye,{size:24})})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"bg-[var(--bg-card-alt)] p-5 rounded-2xl border border-[var(--border)] flex flex-col items-center",children:[e.jsx("p",{className:"text-12 text-[var(--text-muted)] font-bold uppercase mb-2 tracking-widest",children:"總預算 (未稅)"}),e.jsxs("p",{className:"text-xl font-bold text-[var(--text-primary)] font-mono",children:["NT$",ce.amountTotal.toLocaleStr
31ing()]})]}),e.jsxs("div",{className:"bg-[var(--bg-card-alt)] p-5 rounded-2xl border border-[var(--id-orange)]/20 flex flex-col items-center",children:[e.jsx("p",{className:"text-12 text-[var(--id-orange)] font-bold uppercase mb-2 tracking-widest",children:"代墊/成本總計"}),e.jsxs("p",{className:"text-xl font-bold text-[var(--id-orange)] font-mono",children:["- $",ce.costExtra.toLocaleString()]})]})]}),e.jsxs("div",{className:"flex items-center gap-3 py-2",children:[e.jsx("div",{className:"h-px flex-1 bg-[var(--border)]"}),e.jsxs("span",{className:"text-12 font-bold text-[var(--text-muted)] uppercase tracking-widest flex items-center gap-2",children:[e.jsx(bn,{size:12})," 利潤分配明細"]}),e.jsx("div",{className:"h-px flex-1 bg-[var(--border)]"})]}),e.jsx("div",{className:"space-y-3",children:ce.splitShares.map(O=>{const Q=Math.round(h*(O.percentage/100)),G=Number(O.cost)||0,J=Q+G,F=O.isAutoCalc===!1&&O.amount!==void 0?O.amount:J,Ie=O.isAutoCalc===!1;return e.jsxs("div",{className:`bg-[var(--bg-card-alt)] p-5 rounded-[24px] border ${Ie?"border-[var(--warning)]/30":"border-[var(--border)]"} flex justify-between items-center group hover:border-[var(--id-purple)]/30 transition-all duration-300`,children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[var(--text-primary)] font-bold text-lg",children:O.name}),e.jsxs("span",{className:"text-12 font-bold bg-[var(--bg-card-alt)] text-[var(--text-secondary)] px-2 py-0.5 rounded-full border border-[var(--border)]",children:[O.percentage,"%"]}),Ie&&e.jsx("span",{className:"text-11 font-bold bg-[var(--warning)]/10 text-[var(--warning)] px-1.5 py-0.5 rounded border border-[var(--warning)]/20",children:"手動"})]}),e.jsxs("div",{className:"flex items-center gap-3 text-13 font-medium",children:[e.jsxs("span",{className:"text-[var(--text-muted)]",children:["利潤: $",Q.toLocaleString()]}),G>0&&e.jsxs("span",{className:"text-[var(--id-orange)]/80 flex items-center gap-1",children:[e.jsx("div",{className:"w-1 h-1 rounded-full bg-[var(--id-orange)]/50"}),"代墊回補: +$",G.toLocaleString()]})]})]}),e.jsxs("div",{className:"text-right",children:[e.jsxs("div",{className:"text-[var(--success)] font-mono font-bold text-2xl",children:["NT$",F.toLocaleString()]}),e.jsx("p",{className:"text-11 text-[var(--text-muted)] font-bold uppercase mt-1 tracking-tighter",children:Ie?"手動設定金額":"最終應領總額"})]})]},O.id)})})]}),e.jsx("div",{className:"mt-8 pt-6 border-t border-[var(--border)] flex justify-center",children:e.jsx("p",{className:"text-12 text-[var(--text-muted)] font-medium italic",children:"計算方式:(總額 - 總成本) × 分潤比 + 個人代墊成本 = 最終金額"})})]})})()})]})},cs=(t,a)=>{var r;return t?a==="account_settings"?{view:!0,create:!0,edit:!0,delete:!0}:t.role==="admin"?{view:!0,create:!0,edit:!0,delete:!0}:((r=t.permissions)==null?void 0:r[a])||wa:wa},Xo=({userProfile:t})=>{const{tableId:a}=Nr(),r=cs(t,`project_table_${a}`);return e.jsx(Jo,{permission:r})},Zo=({children:t})=>{const{pathname:a}=Ye(),r=i.useRef(null);return i.useEffect(()=>{const s=r.current;s&&(s.classList.remove("nk-page"),s.offsetWidth,s.classList.add("nk-page"))},[a]),e.jsx("div",{ref:r,className:"nk-page",children:t})},el=["勞報單電子簽收系統(線上簽名+PDF 存證)","KOL 頻道數據追蹤(Twitch/YouTube/FB/IG)","商案執行與分潤結算","日曆排程與 Google Calendar 同步","成員權限管理,不限人數","持續功能更新與 Email 客戶支援"],is=({canRefresh:t})=>e.jsxs("div",{className:"flex gap-3",children:[e.jsxs("button",{onClick:()=>{window.location.href="/user"},className:"flex-1 flex items-center justify-center gap-2 py-3 bg-[var(--bg-card-alt)] border border-[var(--border)] rounded-xl font-bold text-[var(--text-primary)] hover:border-[var(--border-hover)] transition-all",children:[e.jsx(ct,{size:18})," 前往個人空間"]}),t&&e.jsxs("button",{onClick:()=>window.location.reload(),className:"flex-1 flex items-center justify-center gap-2 py-3 bg-[var(--accent)] text-[var(--button-text)] rounded-xl font-bold hover:bg-[var(--accent-hover)] transition-all",children:[e.jsx(fn,{size:18})," 重新整理狀態"]})]}),tl=()=>{const t=Qt(),[a,r]=i.useState(!1),[s,o]=i.useState(null),d=async()=>{r(!0),o(null),lt("begin_checkout",{checkout_type:"subscription",source:"paywall"});try{const{url:c}=await qn();window.location.href=c}catch(c){o((c==null?void 0:c.message)||"無法開啟付款頁面,請改用信件聯繫我們"),r(!1)}};return e.jsx("div",{className:"min-h-screen bg-[var(--bg-page)] flex items-center justify-center p-4",children:e.jsx("div",{className:"max-w-lg w-full",children:e.jsxs("div",{className:"bg-[var(--bg-card)] border border-[var(--accent)]/30 rounded-2xl shadow-xl overflow-hidden relative",children:[e.jsx("div",{className:"absolute top-0 left-0 w-full h-1.5 bg-[var(--accent)]"}),e.jsxs("div",{className:"p-8 pb-6 text-center",children:[e.jsx("span",{className:"inline-block text-13 font-bold px-3 py-1 rounded-full bg-[var(--accent)]/10 text-[var(--accent)] border border-[var(--accent)]/20 uppercase tracking-widest mb-5",children:"訂閱方案"}),e.jsx("h1",{className:"text-xl font-bold text-[var(--text-primary)] mb-1",children:"服務尚未啟用"}),e.jsx("p",{className:"text-sm text-[var(--text-secondary)]",children:"您的訂閱已到期或尚未開通,續訂å¾
31Œå³å¯ç¹¼çºŒä½¿ç”¨ã€‚"}),e.jsxs("div",{className:"flex items-end justify-center gap-1.5 mt-6",children:[e.jsx("span",{className:"text-[52px] font-bold tracking-tight text-[var(--text-primary)] leading-none tabular-nums",children:"US$3.99"}),e.jsx("span",{className:"text-sm text-[var(--text-muted)] mb-1.5",children:"/ 人 / 月"})]}),e.jsx("p",{className:"text-xs text-[var(--text-muted)] mt-2",children:"依「用戶管理」中的成員人數計費,不限人數"})]}),e.jsx("div",{className:"px-8 pb-6",children:e.jsxs("div",{className:"bg-[var(--bg-card-alt)] border border-[var(--border)] rounded-xl p-5",children:[e.jsx("p",{className:"text-13 font-bold text-[var(--text-muted)] uppercase tracking-widest mb-3",children:"解鎖完整功能"}),e.jsx("ul",{className:"space-y-2.5",children:el.map(c=>e.jsxs("li",{className:"flex items-center gap-2.5 text-sm text-[var(--text-primary)]",children:[e.jsx(Qe,{size:15,className:"text-[var(--accent)] flex-shrink-0"}),c]},c))})]})}),e.jsxs("div",{className:"px-8 pb-8",children:[s&&e.jsx("div",{className:"bg-[var(--error)]/10 border border-[var(--error)]/30 rounded-lg p-3 mb-3",children:e.jsx("p",{className:"text-sm text-[var(--error)]",children:s})}),e.jsxs("button",{onClick:d,disabled:a,className:"w-full flex items-center justify-center gap-2 py-3.5 bg-[var(--accent)] text-[var(--button-text)] rounded-xl font-bold hover:bg-[var(--accent-hover)] transition-all mb-1.5 disabled:opacity-60",children:[a?e.jsx(be,{size:17,className:"animate-spin"}):e.jsx(Xt,{size:17}),a?"正在前往付款頁面…":"前往付款啟用"]}),e.jsxs("p",{className:"text-13 text-[var(--text-muted)] text-center mb-3",children:["首次訂閱享 ",e.jsx("span",{className:"text-[var(--accent)] font-bold",children:"7 天免費試用"}),",試用結束依當時成員人數扣款"]}),e.jsxs("button",{onClick:()=>t("/labor-receipts"),className:"w-full flex items-center justify-center gap-2 py-3 bg-[var(--bg-card-alt)] border border-[var(--border)] rounded-xl font-bold text-[var(--text-primary)] hover:border-[var(--border-hover)] transition-all mb-3",children:[e.jsx(vn,{size:17})," 前往勞報單簽收系統"]}),e.jsxs("p",{className:"text-13 text-[var(--text-muted)] text-center mb-3",children:["勞報單簽收系統按點數計費,",e.jsx("span",{className:"text-[var(--text-secondary)] font-bold",children:"無需訂閱即可繼續使用"}),"(含點數加購)"]}),e.jsx(is,{canRefresh:!0}),e.jsxs("p",{className:"text-13 text-[var(--text-muted)] text-center mt-4",children:["付款成功後點「重新整理狀態」即可恢復使用・需要協助請洽",e.jsxs("a",{href:"mailto:[email protected]?subject=Nekowa 訂閱付款",className:"underline hover:text-[var(--text-secondary)] inline-flex items-center gap-1 ml-1",children:[e.jsx(Ot,{size:11}),"[email protected]"]})]})]})]})})})},al=({status:t})=>{if(t==="unpaid")return e.jsx(tl,{});const a=t==="pending";return e.jsx("div",{className:"min-h-screen bg-[var(--bg-page)] flex items-center justify-center p-4",children:e.jsxs("div",{className:"bg-[var(--bg-card)] border border-[var(--border)] rounded-2xl shadow-xl p-8 max-w-md w-full text-center",children:[e.jsx("div",{className:`w-16 h-16 rounded-full flex items-center justify-center mx-auto mb-4 border ${a?"bg-[var(--warning)]/10 border-[var(--warning)]/20":"bg-[var(--error)]/10 border-[var(--error)]/20"}`,children:a?e.jsx(Ia,{size:30,className:"text-[var(--warning)]"}):e.jsx(gn,{size:30,className:"text-[var(--error)]"})}),e.jsx("h1",{className:"text-xl font-bold text-[var(--text-primary)] mb-3",children:a?"公司審核中":"公司未通過審核"}),e.jsx("p",{className:"text-sm text-[var(--text-secondary)] leading-relaxed mb-6",children:a?"您的公司註冊資料已提交,平台正在審核營業登記文件。審核通過並完成付款後即可開始使用。":"很抱歉,您的公司註冊未通過審核。若有疑問或需補件,請聯繫平台客服協助處理。"}),e.jsx(is,{canRefresh:a})]})})},rl=i.lazy(()=>H(()=>import("./AdminDashboard-B67y0Pqp.js"),__vite__mapDeps([3,2,4,1,5,0]))),sl=i.lazy(()=>H(()=>import("./CreditTransactionsPage-asDA6-_A.js"),__vite__mapDeps([6,2,4,1]))),fr=i.lazy(()=>H(()=>import("./RemunerationMaster-DriJz1tb.js"),__vite__mapDeps([7,8,2,1,9,4,10,11]))),nl=i.lazy(()=>H(()=>import("./QuotationMaster-BHc-4KOb.js"),__vite__mapDeps([12,8,2,0,1,11,10,4]))),ol=i.lazy(()=>H(()=>import("./QuotationClients-DlGN4FCn.js"),__vite__mapDeps([13,8,2,11,1,4]))),ll=i.lazy(()=>H(()=>import("./QuotationTemplateSettings-D0ONyExy.js"),__vite__mapDeps([14,5,2,1,0,4]))),cl=i.lazy(()=>H(()=>import("./PersonalAccountSettings-6XwlL9gM.js"),__vite__mapDeps([15,2,16,4,1]))),yr=i.lazy(()=>H(()=>import("./HealthRecords-Dg2OI53m.js"),__vite__mapDeps([17,8,2,1,11,4]))),jr=i.lazy(()=>H(()=>import("./DataSettings-Cyif8SBv.js"),__vite__mapDeps([18,8,2,11,1,4]))),il=i.lazy(()=>H(()=>import("./Dashboard-BcSgB8A9.js"),__vite__mapDeps([19,2,10,1,4]))),dl=i.lazy(()=>H(()=>import("./UserManagement-BEz4gokO.js"),__vite__mapDeps([20,2,1,4]))),ul=i.lazy(()=>H(()=>import("./AccountSettings-DRRYg87y.js"),__vite__mapDeps([16,2,4,1]))),xl=i.lazy(()=>H(()=>import("./KolTracking-DFmMxzxi.js"),__vite__mapDeps([21,8,2,1,4]))),ml=i.lazy(()=>H(()=>import("./AgentRevenue-Bkhd16e9.js"),__vite__mapDeps([22,8,2,1,4]))),pl=i.lazy(()=>H(()=>import("./ExecutorSettlement-sOCkRSH1.js"),__vite__mapDeps([23,8,2,1,4]))),bl=i.lazy(()=>H(()=>import("./ProjectSettings-S2YhI8dU.js"),__vite__mapDeps([24,8,2,1,4]))),hl=i.lazy(()=>H(()=>import("./ProjectMgmtExecutors-DHSXoq2I.js"),__vite__mapDeps([25,8,2,1,4]))),gl=i.lazy(()=>H(()=>import("./ProjectMgmtProfitSharing-B4cNS1WQ.js"),__vite__mapDeps([26,8,2,1,27,4]))),vl=i.lazy(()=>H(()=>import("./ProjectMgmtRevenue-sYH4WRym.js"),__vite__mapDeps([28,8,2,1,4]))),fl=i.lazy(()=>H(()=>import("./ProjectMgmtPerformance-D0Y-hw8B.js"),__vite__mapDeps([29,2,1,27,30,4]))),yl=i.lazy(()=>H(()=>import("./PersonnelManagement-BHXDPOTw.js"),__vite__mapDeps([31,8,2,1,4]))),jl=i.lazy(()=>H(()=>import("./LandingPage-OoxLD_Gw.js"),__vite__mapDeps([32,2,1,4]))),wl=i.lazy(()=>H(()=>import("./PrivacyPolicy-BnKKRFJg.js"),__vite__mapDeps([33,1,2,4]))),Nl=i.lazy(()=>H(()=>import("./CalendarSettings-B4hk6B0-.js"),__vite__mapDeps([34,2,1,4]))),Sl=i.lazy(()=>H(()=>import("./CalendarProjectDetail-DwsnHZDE.js"),__vite__mapDeps([35,2,1,4]))),kl=i.lazy(()=>H(()=>import("./LaborReceiptListPage-I_Vj8XLS.js"),__vite__mapDeps([36,8,2,4,37,9,38,1,39,40,11,41]))),wr=i.lazy(()=>H(()=>import("./LaborReceiptFormPage-DnKcZxQw.js"),__vite__mapDeps([42,2,4,43,30,1,38,39,44,41]))),Cl=i.lazy(()=>H(()=>
31import("./LaborReceiptDetailPage-DLFwFB-m.js"),__vite__mapDeps([45,8,2,4,37,9,44,1,38,39,40,46,41]))),El=i.lazy(()=>H(()=>import("./LaborReceiptSettingsPage-CRaHW1ZF.js"),__vite__mapDeps([47,2,4,1]))),_l=i.lazy(()=>H(()=>import("./SigningPage-BUEJopPq.js"),__vite__mapDeps([48,2,4,1,43,30,46,44]))),Al=i.lazy(()=>H(()=>import("./UserDashboardPage-kGos5Vbe.js"),__vite__mapDeps([49,2,4,41,1]))),Il=i.lazy(()=>H(()=>import("./SignedDocumentsListPage-Dbz0wFKe.js"),__vite__mapDeps([50,2,4,46,41,1]))),Pl=i.lazy(()=>H(()=>import("./SignedDocumentDetailPage-DCo6MqRS.js"),__vite__mapDeps([51,2,4,37,9,44,1,41]))),Tl=i.lazy(()=>H(()=>import("./CompanyCreditTransactionsPage-DFd-Juw2.js"),__vite__mapDeps([52,2,4,1,38]))),Dl=i.lazy(()=>H(()=>import("./CompanyBillingPage-BZrb3oSV.js"),__vite__mapDeps([53,2,4,1]))),zl=i.lazy(()=>H(()=>import("./InvitePage-cMi2Q1lP.js"),__vite__mapDeps([54,2,4,1]))),Ll=i.lazy(()=>H(()=>import("./RegisterCompanyPage-ZYbvwoUS.js"),__vite__mapDeps([55,2,4,1])));oo();const oe=({user:t,moduleId:a,children:r})=>t?a&&!ts(t,a)?e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-gray-500 gap-4",children:[e.jsx("div",{className:"text-6xl",children:"🔒"}),e.jsx("div",{className:"text-xl font-bold",children:"權限不足"}),e.jsx("p",{children:"您沒有權限存取此頁面,請聯繫管理員。"})]}):r?e.jsx(e.Fragment,{children:r}):e.jsx(Ea,{}):e.jsx(Pt,{to:"/login",replace:!0}),Rl=({user:t,onLogout:a})=>{const[r,s]=i.useState(!1);St(r,()=>s(!1));const[o,d]=i.useState(()=>localStorage.getItem("sidebarCollapsed")==="true"),c=Ye();i.useEffect(()=>{s(!1)},[c.pathname]);const u=()=>{d(f=>{const x=!f;return localStorage.setItem("sidebarCollapsed",String(x)),x})};return e.jsxs("div",{className:"flex h-screen w-screen bg-[var(--bg-page)] overflow-hidden",children:[!r&&e.jsx("button",{onClick:()=>s(!0),className:"fixed top-4 left-4 z-[80] lg:hidden p-2 bg-[var(--bg-card)] border border-[var(--border)] rounded-xl text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-card-alt)] transition-all shadow-lg","aria-label":"開啓選單",children:e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("line",{x1:"3",y1:"6",x2:"21",y2:"6"}),e.jsx("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),e.jsx("line",{x1:"3",y1:"18",x2:"21",y2:"18"})]})}),r&&e.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm z-[60] lg:hidden",onClick:()=>s(!1)}),e.jsx("div",{className:`
32        fixed lg:relative inset-y-0 left-0 z-[70]
33        transform transition-transform duration-300 ease-in-out
34        ${r?"translate-x-0":"-translate-x-full lg:translate-x-0"}
35      `,children:e.jsx(no,{onLogout:a,user:t,onClose:()=>s(!1),isCollapsed:o,onToggleCollapse:u})}),e.jsxs("main",{className:"flex-1 overflow-y-auto h-full relative w-full",children:[e.jsx("div",{className:"absolute top-0 left-0 w-full h-0.5 bg-[var(--accent)] z-10"}),e.jsx(Zo,{children:e.jsx(i.Suspense,{fallback:e.jsx(Oa,{}),children:e.jsx(Ea,{})})})]})]})},Ol=()=>{const t=Ye();i.useEffect(()=>{uo(t.pathname)},[t.pathname]);const[a,r]=i.useState(null),[s,o]=i.useState(null),[d,c]=i.useState(!0),[u,f]=i.useState(null),x=async()=>{await dr();let S=cr();S===null&&(await new Promise(k=>setTimeout(k,1200)),await dr(),S=cr()),console.log(`[Billing] 公司 ${Z()} 訂閱狀態 = ${S}`),f(S)};Zr(),console.log("[App] Rendering. Loading:",d,"User:",a==null?void 0:a.email);const l=async(S,k)=>{try{const{isPageLoad:A}=await H(async()=>{const{isPageLoad:m}=await import("./detectPageLoad-BDcXRVgE.js");return{isPageLoad:m}},[]);if(!A()){console.log("[Activity] Skip recording - SPA navigation");return}console.log("[Activity] Page load detected, recording activity...");const{getDeviceInfo:D}=await H(async()=>{const{getDeviceInfo:m}=await import("./deviceInfo-CrDybfBu.js");return{getDeviceInfo:m}},[]),{httpsCallable:N}=await H(async()=>{const{httpsCallable:m}=await import("./firebase-DUmv6NEE.js").then(_=>_.U);return{httpsCallable:m}},[]),R=D();await N(ae(),"recordUserActivity")({companyId:S,deviceInfo:R}),console.log("[Activity] User activity recorded successfully")}catch(A){console.warn("[Activity] Failed to record activity:",A)}};i.useEffect(()=>{let S=!0;return(async()=>{const A=window.location.pathname;if(A==="/user"||A.startsWith("/user/")){console.log("[Auth] Personal route - ski
35p company restore, context owned by PersonalLayout"),je(),c(!1);return}if(A==="/register"||A.startsWith("/invite/")){console.log("[Auth] Standalone public route - skip company restore"),je(),c(!1);return}const D=new URLSearchParams(window.location.search),N=D.get("payment")?D.get("company"):null;N&&localStorage.setItem("savedTaxId",N);const R=D.get("payment");R==="success"?lt("purchase",{checkout_type:"subscription"}):R==="credits_success"&&lt("purchase",{checkout_type:"credits"});const I=localStorage.getItem("savedTaxId");if(console.log("[Auth] Nekowa mode - checking for saved session..."),I){console.log("[Auth] Restoring nekowa session for taxId:",I),je(),ra(I);const m=ie();Cr(m,async _=>{S&&(_?(console.log("[Auth] Nekowa user restored:",_.email),r(_),await x(),await b(_.uid,_),await l(I)):(console.log("[Auth] No nekowa user found"),r(null),o(null),c(!1)))})}else console.log("[Auth] No saved taxId, user needs to login"),c(!1)})(),()=>{S=!1}},[]);const b=async(S,k)=>{var A;try{if(window.location.pathname.startsWith("/admin")){console.log("[App] On admin route, skipping profile sync"),c(!1);return}const N=window.location.pathname;if(N==="/user"||N.startsWith("/user/")){console.log("[App] On personal route, skipping company profile sync"),c(!1);return}if(N==="/register"||N.startsWith("/invite/")){console.log("[App] On standalone public route, skipping company profile sync"),c(!1);return}const R=Z();if(!R){console.log("[App] No company ID set, skipping profile sync"),c(!1);return}console.log("[App] Syncing user profile (Nekowa)...");const I=k||((A=ie())==null?void 0:A.currentUser);if(I){const m=await Ln(I);if(m)o(m),await l(R,I);else{const _=await Rn(S);o(_)}}}catch(D){console.error("Error loading user profile:",D)}finally{c(!1)}},y=async()=>{try{await On()}catch(S){console.error("Logout error:",S)}r(null),o(null)},j=S=>cs(s,S),w=()=>{var I,m,_,L;const k=Ye().pathname.split("/")[2];if(!((s==null?void 0:s.role)==="admin"||((m=(I=s==null?void 0:s.permissions)==null?void 0:I.calendar)==null?void 0:m.view)===!0||((L=(_=s==null?void 0:s.permissions)==null?void 0:_[`calendar_project_${k}`])==null?void 0:L.view)===!0))return e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-gray-500 gap-4",children:[e.jsx("div",{className:"text-6xl",children:"🔒"}),e.jsx("div",{className:"text-xl font-bold",children:"權限不足"}),e.jsx("p",{children:"您沒有權限存取此日曆專案,請聯繫管理員。"})]});const D=j(`calendar_project_${k}`),N=j("calendar"),R={view:D.view||N.view,create:D.create||N.create,edit:D.edit||N.edit,delete:D.delete||N.delete};return e.jsx(Sl,{permission:R})};if(d)return e.jsxs("div",{className:"h-screen w-screen bg-[var(--bg-page)] flex flex-col items-center justify-center text-[var(--text-primary)] gap-4",children:[e.jsx("div",{className:"w-7 h-7 border-2 border-[var(--border)] border-t-[var(--accent)] rounded-full animate-spin"}),e.jsx("span",{className:"text-sm text-[var(--text-muted)]",children:"載入中…"})]});const v=t.pathname.startsWith("/admin"),T=t.pathname==="/register"||t.pathname.startsWith("/invite/");{const S=t.pathname,k=!(S==="/"||S==="/privacy"||S==="/login"||S.startsWith("/sign/")||S==="/user"||S.startsWith("/user/")||v||T);if(a&&s&&k){if(u===null)return e.jsxs("div",{className:"h-screen w-screen bg-[var(--bg-page)] flex flex-col items-center justify-center text-[var(--text-primary)] gap-4",children:[e.jsx("div",{className:"w-7 h-7 border-2 border-[var(--border)] border-t-[var(--accent)] rounded-full animate-spin"}),e.jsx("span",{className:"text-sm text-[var(--text-muted)]",children:"確認訂閱狀態中…"})]});if(u==="pending"||u==="rejected"||u==="unpaid"){if(u==="unpaid"&&S==="/dashboard")return e.jsx(Pt,{to:"/labor-receipts",replace:!0});const A=S.startsWith("/labor-receipts")||S==="/billing"||S==="/account";if(!(u==="unpaid"&&A))return e.jsx(al,{status:u})}}}return a&&!s&&!v&&!T?e.jsxs("div",{className:"h-screen w-screen bg-[var(--bg-page)] flex flex-col items-center justify-center text-[var(--text-primary)] gap-4",children:[e.jsx("div",{className:"w-7 h-7 border-2 border-[var(--border)] border-t-[var(--accent)] rounded-full animate-spin"}),e.jsx("span",{className:"text-sm text-[var(--text-muted)]",children:"載入中…"})]}):e.jsx(i.Suspense,{fallback:e.jsx(Oa,{}),children:e.jsxs(_s,{children:[e.jsx(q,{path:"/",element:e.jsx(jl,{})}),e.jsx(q,{path:"/privacy",element:e.jsx(wl,{})}),e.jsx(q,{path:"/sign/:companyId/:receiptId/:token",element:e.jsx(_l,{})}),e.jsx(q,{path:"/invite/:companyId/:token",element:e.jsx(zl,{})}),e.jsx(q,{path:"/register",element:e.jsx(Ll,{})}),e.jsxs(q,{path:"/user",element:e.jsx(Io,{}),children:[e.jsx(q,{index:!0,element:e.jsx(Al,{})}),e.jsx(q,{path:"documents",element:e.jsx(Il,{})}),e.jsx(q,{path:"documents/:id",element:e.jsx(Pl,{})}),e.jsx(q,{path:"remuneration",element:e.jsx(fr,{permission:{view:!0,create:!0,edit:!0,delete:!0}})}),e.jsx(q,{path:"health-records",element:e.jsx(yr,{permission:{view:!0,create:!0,edit:!0,delete:!0}})}),e.jsx(q,{path:"settings",element:e.jsx(jr,{permission:{view:!0,create:!0,edit:!0,delete:!0}})}),e.jsx(q,{path:"account",element:e.jsx(cl,{})})]}),e.jsx(q,{path:"/admin",element:e.jsx(Eo,{})}),e.jsx(q,{path:"/admin/dashboard",element:e.jsx(rl,{})}),e.jsx(q,{path:"/admin/credit-transactions",element:e.jsx(sl,{})}),e.jsx(q,{path:"/login",element:a?e.jsx(Pt,{to:"/dashboard",replace:!0}):e.jsx(Co,{})}),e.jsx(q,{element:e.jsx(oe,{user:s}),children:e.jsxs(q,{element:e.jsx(Rl,{user:s,onLogout:y}),children:[e.jsx(q,{path:"dashboard",element:e.jsx(oe,{user:s,moduleId:"dashboard",children:e.jsx(il,{})})}),e.jsx(q,{path:"users",element:e.jsx(oe,{user:s,moduleId:"users",children:e.jsx(dl,{permission:j("users")})})}),e.jsx(q,{path:"remuneration",element:e.jsx(oe,{user:s,moduleId:"remuneration",children:e.jsx(fr,{permission:j("remuneration")})})}),e.jsx(q,{path:"quotations",element:e.jsx(oe,{user:s,moduleId:"quotation",children:e.jsx(nl,{permission:j("quotation")})})}),e.jsx(q,{path:"quotation-clients",element:e.jsx(oe,{user:s,moduleId:"quotation",children:e.jsx(ol,{permission:j("quotation")})})}),e.jsx(q,{path:"quotation-template-settings",element:e.jsx(oe,{user:s,moduleId:"quotation",children:e.jsx(ll,{permission:j("quotation")})})}),e.jsx(q,{path:"health-records",element:e.jsx(oe,{user:s,moduleId:"health_records",children:e.jsx(yr,{permission:j("health_records")})})}),e.jsx(q,{path:"settings",element:e.jsx(oe,{user:s,moduleId:"settings",children:e.jsx(jr,{permission:j("settings")})})}),e.jsx(q,{path:"kol-tracking",element:e.jsx(oe,{user:s,moduleId:"kol_tracking",children:e.jsx(xl,{permission:j("kol_tracking")})})}),e.jsx(q,{path:"agent-revenue",element:e.jsx(oe,{user:s,moduleId:"agent_revenue",children:e.jsx(ml,{permission:j("agent_revenue")})})}),e.jsx(q,{path:"executor-settlement",element:e.jsx(oe,{user:s,moduleId:"executor_settlement",children:e.jsx(pl,{permission:j("executor_settlement"),user:s})})}),e.jsx(q,{path:"personnel",element:e.jsx(oe,{user:s,moduleId:"personnel",children:e.jsx(yl,{permission:j("personnel")})})}),e.jsx(q,{path:"project-settings",element:e.jsx(oe,{user:s,moduleId:"project_settings",children:e.jsx(bl,{permission:j("project_settings")})})}),e.jsx(q,{path:"projects/:tableId",element:e.jsx(Xo,{userProfile:s})}),e.jsx(q,{path:"account",element:e.jsx(oe,{user:s,moduleId:"account_settings",children:e.jsx(ul,{user:s,onUpdate:()=>b(s.id)})})}),e.jsx(q,{path:"billing",element:e.jsx(oe,{user:s,children:e.jsx(Dl,{user:s})})}),e.jsx(q,{path:"calendar-settings",element:e.jsx(oe,{user:s,moduleId:"calendar",children:e.jsx(Nl,{permission:j("calendar"),isAdmin:(s==null?void 0:s.role)==="admin"})})}),e.jsx(q,{path:"calendar/:projectId",element:e.jsx(w,{})}),e.jsx(q,{path:"labor-receipts",element:e.jsx(oe,{user:s,moduleId:"labor_receipt",children:e.jsx(kl,{permission:j("labor_receipt")})})}),e.jsx(q,{path:"labor-receipts/create",element:e.jsx(oe,{user:s,moduleId:"labor_receipt",children:e.jsx(wr,{mode:"create"})})}),e.jsx(q,{path:"labor-receipts/:id",element:e.jsx(oe,{user:s,moduleId:"labor_receipt",children:e.jsx(Cl,{})})}),e.jsx(q,{path:"labor-receipts/:id/edit",element:e.jsx(oe,{user:s,moduleId:"labor_receipt",children:e.jsx(wr,{mode:"edit"})})}),e.jsx(q,{path:"labor-receipts/settings",element:e.jsx(oe,{user:s,moduleId:"labor_receipt",children:e.jsx(El,{})})}),e.jsx(q,{path:"project-mgmt/executors",element:e.jsx(oe,{user:s,moduleId:"project_mgmt_executors",children:e.jsx(hl,{permission:j("project_mgmt_executors")})})}),e.jsx(q,{path:"project-mgmt/profit-sharing",element:e.jsx(oe,{user:s,moduleId:"project_mgmt_profit",children:e.jsx(gl,{permission:j("project_mgmt_profit")})})}),e.jsx(q,{path:"project-mgmt/revenue",element:e.jsx(oe,{user:s,moduleId:"project_mgmt_revenue",children:e.jsx(vl,{permission:j("project_mgmt_revenue"),user:s})})}),e.jsx(q,{path:"project-mgmt/performance",element:e.jsx(oe,{user:s,moduleId:"project_mgmt_performance",children:e.jsx(fl,{permission:j("project_mgmt_performance"),user:s})})}),e.jsx(q,{path:"credit-transactions",element:e.jsx(oe,{user:s,moduleId:"credit_history",children:e.jsx(Tl,{permission:j("credit_history")})})})]})}),e.jsx(q,{path:"*",element:e.jsx(Pt,{to:a?"/":"/login",replace:!0})})]})})};
35console.log("[System] Initializing React App (v2)...");const Ca=document.getElementById("root");if(!Ca)throw new Error("Could not find root element to mount to");try{As.createRoot(Ca).render(e.jsx(Dt.StrictMode,{children:e.jsx(Is,{children:e.jsx(Ol,{})})})),console.log("[System] App mounted successfully.")}catch(t){console.error("[System] Critical render error:",t),Ca.innerHTML=`<div style="color:red; padding:20px;"><h3>Critical Startup Error</h3><pre>${String(t)}</pre></div>`}export{ec as $,_c as A,Ec as B,pe as C,ft as D,Bo as E,Ma as F,Yt as G,$a as H,Bl as I,Ul as J,Gi as K,Ji as L,ad as M,Yi as N,Ki as O,ls as P,Qi as Q,rd as R,$o as S,Po as T,sd as U,Z as V,Xi as W,Zi as X,ed as Y,td as Z,H as _,qc as a,fi as a$,Lc as a0,Dc as a1,Tc as a2,zc as a3,Sc as a4,Mc as a5,Oc as a6,kc as a7,$c as a8,Fc as a9,ac as aA,rc as aB,hc as aC,Uc as aD,Bc as aE,Hc as aF,Pn as aG,Zc as aH,ld as aI,cd as aJ,nd as aK,ti as aL,ri as aM,ei as aN,Un as aO,Ke as aP,Jc as aQ,Qc as aR,hr as aS,lc as aT,Xc as aU,ci as aV,di as aW,mi as aX,ii as aY,ui as aZ,xi as a_,Xn as aa,Wn as ab,Ai as ac,xr as ad,od as ae,zn as af,Dn as ag,mc as ah,wc as ai,dc as aj,_n as ak,cc as al,ai as am,Nc as an,gt as ao,po as ap,rs as aq,mo as ar,as,ho as at,ht as au,vo as av,sc as aw,tc as ax,oc as ay,nc as az,Wc as b,yi as b0,pi as b1,hi as b2,Ra as b3,ji as b4,vi as b5,gi as b6,wi as b7,bi as b8,Ni as b9,Vi as bA,Di as bB,Ii as bC,Li as bD,Oi as bE,Fi as bF,Ri as bG,Mi as bH,Jl as bI,gr as bJ,Wr as bK,Fo as bL,Kl as bM,Gl as bN,Zl as bO,Xl as bP,St as bQ,je as bR,gc as bS,qn as bT,vc as bU,uc as bV,jc as bW,xc as bX,ra as bY,pc as bZ,bc as b_,Ci as ba,ki as bb,Ei as bc,Si as bd,ql as be,Wl as bf,Vl as bg,xe as bh,Hl as bi,_i as bj,si as bk,oi as bl,ni as bm,li as bn,lt as bo,Ui as bp,Bi as bq,qi as br,Ti as bs,Pi as bt,zi as bu,Zn as bv,$i as bw,Wi as bx,Hi as by,eo as bz,Ql as c,ie as d,ne as e,fc as f,Vc as g,Br as h,ae as i,e as j,ic as k,yc as l,W as m,Yl as n,In as o,M as p,Ro as q,Yc as r,Cc as s,Gc as t,Kc as u,Pc as v,Rc as w,Fe as x,Ac as y,Ic as z};

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.