1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[9558],{7730:(e,t,s)=>{"use strict";s.d(t,{MaintenanceGate:()=>f});var r=s(31615),a=s(46377),n=s(30274),i=s(24571),l=s(73521),d=s(39461),o=s(76458),c=s(19548),u=s(29363);let m=["/dashboard/admin","/maintenance","/learn"];function f({children:e}){let t=(0,a.useRouter)(),s=(0,a.usePathname)()||"/",x=(0,r.useRef)(s),{user:h,auth:p}=(0,l.A)(),{isAdmin:v,isLoading:g}=(0,d.q)(),[j,b]=(0,r.useState)(null),[N,w]=(0,r.useState)(!0),y=(0,r.useRef)(!1);(0,r.useEffect)(()=>{x.current=s},[s]),(0,r.useEffect)(()=>{if(!o.db){b({enabled:!1}),w(!1);return}w(!0);let e=(0,i.doc)(o.db,"system","maintenance");return(0,i.aQ)(e,e=>{try{let t=e.exists()?e.data():{};b((0,u.I)(t))}catch(e){c.Cp(e instanceof Error?e:Error(String(e)),{level:"error",extra:{message:"[MaintenanceGate] è§£æç¶è·è¨å®å¤±æ",pathname:x.current},tags:{source:"MaintenanceGate.onSnapshot.parseMaintenanceSettings"}}),b({enabled:!1})}finally{w(!1)}},e=>{c.Cp(e instanceof Error?e:Error(String(e)),{level:"error",extra:{message:"[MaintenanceGate] ç£è½ç¶è·è¨å®å¤±æ",pathname:x.current},tags:{source:"MaintenanceGate.onSnapshot.error"}}),b({enabled:!1}),w(!1)})},[]);let E=!!j?.enabled,k=E&&!m.some(e=>s===e||s.startsWith(`${e}/`))&&!v;return((0,r.useEffect)(()=>{if(!E){y.current=!1;return}v||g||k&&(h&&p&&!y.current&&(y.current=!0,(0,n.signOut)(p).catch(e=>{c.Cp(e instanceof Error?e:Error(String(e)),{level:"error",extra:{message:"[MaintenanceGate] signOut 失æ",pathname:s},tags:{source:"MaintenanceGate.signOut"}})})),t.replace("/maintenance"))},[p,E,v,g,s,t,k,h]),N)?e:k?null:e}},13242:(e,t,s)=>{"use strict";s.d(t,{Toaster:()=>h});var r=s(85047),a=s(41178),n=s(31615),i=s(28367),l=s(42165),d=s(34961);let o=i.Kq,c=n.forwardRef(({className:e,...t},s)=>(0,r.jsx)(i.LM,{ref:s,className:(0,d.cn)("fixed top-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:left-1/2 sm:top-0 sm:-translate-x-1/2 sm:flex-col md:max-w-[420px]",e),...t}));c.displayName=i.LM.displayName;let u=n.forwardRef(({className:e,variant:t="default",...s},a)=>(0,r.jsx)(i.bL,{ref:a,className:(0,d.cn)("group pointer-events-auto relative flex w-full items-center justify-between space-x-4 overflow-hidden rounded-md border p-6 pr-8 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full bg-background/80 backdrop-blur-sm","destructive"===t&&"destructive group border-destructive bg-destructive/80 text-destructive-foreground",e),...s}));u.displayName=i.bL.displayName;let m=n.forwardRef(({className:e,...t},s)=>(0,r.jsx)(i.hE,{ref:s,className:(0,d.cn)("text-sm font-semibold",e),...t}));m.displayName=i.hE.displayName;let f=n.forwardRef(({className:e,...t},s)=>(0,r.jsx)(i.VY,{ref:s,className:(0,d.cn)("text-sm opacity-90",e),...t}));f.displayName=i.VY.displayName;let x=n.forwardRef(({className:e,...t},s)=>(0,r.jsx)(i.bm,{ref:s,className:(0,d.cn)("absolute right-2 top-2 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-2 group-hover:opacity-100",e),"toast-close":"",...t,children:(0,r.jsx)(l.A,{className:"h-4 w-4"})}));function h(){let{toasts:e}=(0,a.dj)();return(0,r.jsxs)(o,{children:[e.map(function({id:e,title:t,description:s,action:a,...n}){return(0,r.jsxs)(u,{...n,children:[(0,r.jsxs)("div",{className:"grid gap-1",children:[t&&(0,r.jsx)(m,{children:t}),s&&(0,r.jsx)(f,{children:s})]}),a,(0,r.jsx)(x,{})]},e)}),(0,r.jsx)(c,{})]})}x.displayName=i.bm.displayName,n.forwardRef(({className:e,...t},s)=>(0,r.jsx)(i.rc,{ref:s,className:(0,d.cn)("inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium ring-offset-background transition-colors hover:bg-secondary focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive",e),...t})).displayName=i.rc.displayName},17830:(e,t,s)=>{"use strict";s.r(t),s.d(t,{initAmplitudeOnce:()=>f,isAmplitudeEnabled:()=>c,isAmplitudeSessionReplayEnabled:()=>u,setAmplitudeUserId:()=>
1h,shouldSendAmplitude:()=>o,trackAmplitudeEvent:()=>x});var r=s(27125),a=s(92487),n=s(32407);let i=null,l=null;function d(){return i||(i=(0,r.Q)()),i}function o(){let e=window.location.hostname;return"localhost"!==e&&"127.0.0.1"!==e&&"preview"!==n.env.NEXT_PUBLIC_VERCEL_ENV}function c(){return!!o()}function u(){return"true"===n.env.NEXT_PUBLIC_AMPLITUDE_SESSION_REPLAY}let m={autocapture:{attribution:!0,pageViews:!0,sessions:!0,formInteractions:!0,fileDownloads:!0,elementInteractions:!0},logLevel:a.$.Error};function f(){if(!c())return Promise.resolve();if(l)return l;let e="7da27e7a1f961553fe483a2bb5d141c2";if(!e)return Promise.resolve();let t=d();return l=(u()?t.initAll(e,{analytics:m,sessionReplay:{sampleRate:1}}):t.init(e,m).promise).catch(e=>{throw l=null,e})}function x(e,t){if(!c())return;let s={...t,page:t?.page??window.location?.pathname??""};f().then(()=>{d().track(e,s)}).catch(()=>{})}function h(e){c()&&f().then(()=>{let t=d();e?t.setUserId(e):t.reset()}).catch(()=>{})}},18534:(e,t,s)=>{"use strict";s.d(t,{Cf:()=>f,Es:()=>h,HM:()=>u,L3:()=>p,c7:()=>x,lG:()=>d,rr:()=>v,zM:()=>o});var r=s(85047),a=s(31615),n=s(49083),i=s(42165),l=s(34961);let d=n.bL,o=n.l9,c=n.ZL,u=n.bm,m=a.forwardRef(({className:e,...t},s)=>(0,r.jsx)(n.hJ,{ref:s,className:(0,l.cn)("fixed inset-0 z-50 bg-black/80 transition-opacity duration-200 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:opacity-0 data-[state=closed]:pointer-events-none",e),...t}));m.displayName=n.hJ.displayName;let f=a.forwardRef(({className:e,children:t,asChild:s,overlayClassName:a,...d},o)=>{let u=(0,l.cn)("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",e);return s?(0,r.jsxs)(c,{children:[(0,r.jsx)(m,{className:a}),(0,r.jsx)(n.UC,{ref:o,className:u,asChild:!0,...d,children:t})]}):(0,r.jsxs)(c,{children:[(0,r.jsx)(m,{className:a}),(0,r.jsxs)(n.UC,{ref:o,className:u,...d,children:[t,(0,r.jsxs)(n.bm,{className:"absolute right-4 top-4 roun
1ded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[(0,r.jsx)(i.A,{className:"h-4 w-4"}),(0,r.jsx)("span",{className:"sr-only",children:"Close"})]})]})]})});f.displayName=n.UC.displayName;let x=({className:e,...t})=>(0,r.jsx)("div",{className:(0,l.cn)("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});x.displayName="DialogHeader";let h=({className:e,...t})=>(0,r.jsx)("div",{className:(0,l.cn)("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",e),...t});h.displayName="DialogFooter";let p=a.forwardRef(({className:e,...t},s)=>(0,r.jsx)(n.hE,{ref:s,className:(0,l.cn)("text-lg font-semibold leading-none tracking-tight",e),...t}));p.displayName=n.hE.displayName;let v=a.forwardRef(({className:e,...t},s)=>(0,r.jsx)(n.VY,{ref:s,className:(0,l.cn)("text-sm text-muted-foreground",e),...t}));v.displayName=n.VY.displayName},29363:(e,t,s)=>{"use strict";s.d(t,{I:()=>n});var r=s(15418);let a=r.Ik({enabled:r.zM().default(!1),message:r.Yj().max(500).optional(),reason:r.Yj().max(500).optional(),updatedAt:r.bz().optional(),updatedBy:r.Yj().min(1).optional()});function n(e){return a.parse(e??{})}},30145:(e,t,s)=>{"use strict";s.d(t,{default:()=>d});var r=s(85047),a=s(18710);let n=(0,a.default)(()=>s.e(2406).then(s.bind(s,72406)),{loadableGenerated:{webpack:()=>[72406]},loading:()=>null}),i=(0,a.default)(()=>s.e(59).then(s.bind(s,70059)),{loadableGenerated:{webpack:()=>[70059]},loading:()=>null}),l=(0,a.default)(()=>s.e(3428).then(s.bind(s,3428)),{loadableGenerated:{webpack:()=>[3428]},loading:()=>null});function d(){return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n,{}),(0,r.jsx)(i,{}),(0,r.jsx)(l,{})]})}},30424:()=>{},38187:(e,t,s)=>{"use strict";s.d(t,{E:()=>d});var r=s(85047),a=s(31615),n=s(63610),i=s(34961);let l=(0,n.F)("inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}}),d=a.forwardRef(({className:e,variant:t,...s},a)=>(0,r.jsx)("div",{ref:a,className:(0,i.cn)(l({variant:t}),e),...s}));d.displayName="Badge"},39461:(e,t,s)=>{"use strict";s.d(t,{q:()=>d});var r=s(31615),a=s(73521),n=s(18654),i=s(24571),l=s(76458);function d(){let{user:e,loading:t}=(0,a.A)(),[d,o]=(0,r.useState)(!1),[c,u]=(0,r.useState)(!0),[m,f]=(0,r.useState)(null),x=(0,r.useCallback)(async()=>{if(!e)return o(!1),u(!1),!1;try{u(!0),f(null);try{let t=await (await Promise.resolve().then(s.bind(s,30274))).getIdTokenResult(e,!0),r=(t?.claims||{}).role;if(void 0!==r&&("admin"===r||!0===r))return o(!0),u(!1),!0}catch{}try{await e.getIdToken(!0)}catch{}if(!l.db)throw Error("Firestore æªåå§å");let t=(0,i.doc)(l.db,"users",e.uid),r=await (0,i.getDoc)(t);if(!r.exists()){for(let e=0;e<6&&(await new Promise(e=>setTimeout(e,500)),!(r=await (0,i.getDoc)(t)).exists());e++);if(!r.exists())throw Error("ç¨æ¶è³æä¸åå¨")}let a=r.data(),n=a?.role,d="string"==typeof n?n.toLowerCase().trim():!0===n?"admin":"user",c="admin"===d;return o(c),u(!1),c}catch(e){return(0,n.vV)("檢æ¥ç®¡ç塿¬éé¯èª¤:",e),f(e.message||"æ¬é檢æ¥å¤±æ"),o(!1),u(!1),!1}},[e]);return(0,r.useEffect)(()=>{t||(e?x():(o(!1),u(!1),f(null)))},[e,t,x]),{isAdmin:d,isLoading:c,error:m,checkPermission:x}}},76042:(e,t,s)=>{Promise.resolve().then(s.bind(s,84323)),Promise.resolve().then(s.bind(s,30145)),Promise.resolve().then(s.bind(s,7730)),Promise.resolve().then(s.bind(s,90474)),Promise.resolve().then(s.bind(s,13242)),Promise.resolve().then(s.t.bind(s,28225,23)),Promise.resolve().then(s.t.bind(s,30424,23))},77405:(e,t,s)=>{"use strict";s.d(t,{a:()=>a});var r=s(31615);function a(){let[e,t]=r.useState(void 0);return r.useEffect(()=>{let e=window.matchMedia("(max-width: 767px)"),s=()=>{t(window.innerWidth<768)};return e.addEventListener("change",s),t(window.innerWidth<768),()=>e.removeEventListener("change",s)},[]),!!e}},80712:(e,t,s)=>{"use strict";s.d(t,{k:()=>G,v:()=>B});var r=s(85047),a=s(31615),n=s(24571),i=s(18534),l=s(11787),d=s(84569),o=s(73521),c=s(41178),u=s(34961),m=s(35347),f=s(93806),x=s(77405),h=s(18654),p=s(44832),v=s(8058),g=s(85084),j=s(60373),b=s(38187),N=s(79579);function w({rooms:e,selectedRoomId:t,onSelectRoom:s,currentUserId:a,isLoading:n,isAdvisor:i,selectedRoom:d,isMobile:o=!1}){let c=d&&!e.some(e=>e.id===d.id)?[d,...e]:e;return(0,r.jsx)("div",{className:(0,u.cn)("flex flex-col",o?"w-full":"w-80 border-r"),children:(0,r.jsxs)("div",{className:"flex-1 overflow-y-auto",children:[(0,r.jsx)("div",{className:"p-4 border-b",children:(0,r.jsx)("h3",{className:"font-semibold",children:"å°è©±"})}),(0,r.jsxs)("div",{className:"p-2",children:[c.map(e=>
1{let n=e.userId===a,l=n?e.advisorName||"é¡§å":e.userDisplayName||"ç¨æ¶",d=n?e.advisorAvatar:null,o=i?e.unreadCountAdvisor:e.unreadCountUser;return(0,r.jsx)("button",{onClick:()=>s(e),className:(0,u.cn)("w-full p-3 rounded-lg transition-colors text-left",t===e.id?"bg-accent":"hover:bg-accent/50"),children:(0,r.jsxs)("div",{className:"flex items-center gap-3",children:[n?(0,r.jsx)(j.eu,{className:"h-10 w-10",children:d?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(j.BK,{src:d,alt:l}),(0,r.jsx)(j.q5,{children:l.substring(0,2)})]}):(0,r.jsx)(j.q5,{children:l.substring(0,2)})}):(0,r.jsx)(N.H,{userId:e.userId,size:"medium",className:"h-10 w-10"}),(0,r.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,r.jsx)("div",{className:"font-medium truncate",children:l}),(0,r.jsx)("div",{className:"text-sm text-muted-foreground truncate",children:e.lastMessage||"å°æªæè¨æ¯"})]}),o>0&&(0,r.jsx)(b.E,{variant:"destructive",className:"ml-auto",children:o>99?"99+":o})]})},e.id)}),n&&0===e.length&&(0,r.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,r.jsx)(l.A,{className:"h-6 w-6 animate-spin text-muted-foreground"})}),!n&&0===e.length&&!d&&(0,r.jsx)("div",{className:"text-center text-muted-foreground py-8",children:(0,r.jsx)("p",{children:i?"ç®åæ²æè天å°è±¡":"ç®åæ²æè天室"})})]})]})})}var y=s(21410),E=s(866),k=s(56560);let I=a.forwardRef(({className:e,children:t,...s},a)=>(0,r.jsxs)(k.bL,{ref:a,className:(0,u.cn)("relative overflow-hidden",e),...s,children:[(0,r.jsx)(k.LM,{className:"h-full w-full rounded-[inherit]",children:t}),(0,r.jsx)(C,{}),(0,r.jsx)(k.OK,{})]}));I.displayName=k.bL.displayName;let C=a.forwardRef(({className:e,orientation:t="vertical",...s},a)=>(0,r.jsx)(k.VM,{ref:a,orientation:t,className:(0,u.cn)("flex touch-none select-none transition-colors","vertical"===t&&"h-full w-2.5 border-l border-l-transparent p-[1px]","horizontal"===t&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...s,children:(0,r.jsx)(k.lr,{className:"relative flex-1 rounded-full bg-border"})}));C.displayName=k.VM.displayName;var A=s(48113),S=s(97839),R=s(62937),M=s(54296),L=s(52226),D=s(81154),P=s(9789);function T({room:e,selectedAdvisor:t,messages:s,currentUserId:n,isAdvisor:i,inputValue:d,onInputChange:m,onSendMessage:f,isSending:x,onKeyPress:h,isLoadingMessages:p=!1,onRoomDeleted:v,isMobile:g=!1,onBack:b,onRetry:w}){let k=(0,a.useRef)(null),{user:C}=(0,o.A)(),{toast:z}=(0,c.dj)(),[V,O]=(0,a.useState)(!1),[U,_]=(0,a.useState)(!1);(0,a.useEffect)(()=>{k.current?.scrollIntoView({behavior:"smooth"})},[s]);let F=e.userId===n,G=F?e.advisorName||t?.name||"é¡§å":e.userDisplayName||"ç¨æ¶",B=F?"財åé¡§å":e.userEmail||"ç¨æ¶",Y=async()=>{if(C){_(!0);try{let t=await C.getIdToken(),s=await fetch(`/api/chat/rooms/${encodeURIComponent(e.id)}`,{method:"DELETE",headers:{Authorization:`Bearer ${t}`}});if(!s.ok){let e=await s.json().catch(()=>({})),t=e?.error||s.statusText||"åªé¤å¤±æ";z({title:"åªé¤å¤±æ",description:t,variant:"destructive"});return}O(!1),v?.(e.id)}catch{z({title:"åªé¤å¤±æ",description:"è«ç¨å¾å試ã",variant:"destructive"})}finally{_(!1)}}},$=F?(0,r.jsxs)(j.eu,{children:[(0,r.jsx)(j.BK,{src:e.advisorAvatar||t?.avatar,alt:G}),(0,r.jsx)(j.q5,{children:(G||"é¡§").substring(0,2)})]}):(0,r.jsx)(N.H,{userId:e.userId,size:"medium"}),K=(0,r.jsxs)(S.rI,{children:[(0,r.jsx)(S.ty,{asChild:!0,children:(0,r.jsx)(y.$,{variant:"ghost",size:"icon",className:"h-8 w-8 flex-shrink-0",children:(0,r.jsx)(R.A,{className:"h-4 w-4"})})}),(0,r.jsx)(S.SQ,{align:"end",children:(0,r.jsxs)(S._2,{className:"text-destructive focus:text-destructive",onClick:()=>O(!0),children:[(0,r.jsx)(M.A,{className:"h-4 w-4"}),"åªé¤è天室"]})})]});return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"p-4 border-b border-border flex items-center gap-3",children:g?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(y.$,{variant:"ghost",size:"icon",className:"h-8 w-8 flex-shrink-0 -ml-2",onClick:b,"aria-label":"è¿å",children:(0,r.jsx)(L.A,{className:"h-5 w-5"})}),(0,r.jsxs)("div",{className:"flex-1 min-w-0 text-center",children:[(0,r.jsx)("div",{className:"font-semibold truncate text-foreground",children:G}),(0,r.jsx)("div",{className:"text-xs text-muted-foreground truncate",children:B})]}),$,K]}):(0,r.jsxs)(r.Fragment,{children:[$,(0,r.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,r.jsx)("div",{className:"font-semibold text-foreground",children:G}),(0,r.jsx)("div",{className:"text-sm text-muted-foreground",children:B})]}),K]})}),(0,r.jsx)(A.Lt,{open:V,onOpenChange:O,children:(0,r.jsxs)(A.EO,{children:[(0,r.jsxs)(A.wd,{children:[(0,r.jsx)(A.r7,{children:"åªé¤è天室"}
1),(0,r.jsx)(A.$v,{children:"確å®è¦åªé¤æ¤è天室åï¼æ¤æä½å°æ°¸ä¹
åªé¤ææè¨æ¯ä¸ç¡æ³å¾©åã"})]}),(0,r.jsxs)(A.ck,{children:[(0,r.jsx)(A.Zr,{disabled:U,children:"åæ¶"}),(0,r.jsx)(A.Rx,{onClick:e=>{e.preventDefault(),Y()},disabled:U,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:U?(0,r.jsx)(l.A,{className:"h-4 w-4 animate-spin"}):"åªé¤"})]})]})}),(0,r.jsx)(I,{className:"flex-1 p-4",children:(0,r.jsxs)("div",{className:"space-y-4",children:[p&&0===s.length?(0,r.jsx)("div",{className:"space-y-4",children:[1,2,3].map(e=>(0,r.jsxs)("div",{className:(0,u.cn)("flex gap-3",e%2==0?"flex-row-reverse":"flex-row"),children:[(0,r.jsx)("div",{className:"h-8 w-8 rounded-full bg-muted animate-pulse flex-shrink-0"}),(0,r.jsxs)("div",{className:"flex flex-col gap-1 max-w-[70%]",children:[(0,r.jsx)("div",{className:"rounded-lg px-4 py-2 bg-muted animate-pulse h-10 w-32"}),(0,r.jsx)("div",{className:"h-3 w-12 bg-muted animate-pulse rounded"})]})]},e))}):0===s.length?(0,r.jsx)("div",{className:"flex flex-col items-center justify-center py-12 text-center text-muted-foreground",children:(0,r.jsx)("p",{children:"å°ç¡è¨æ¯ï¼éå§å°è©±å§"})}):s.map(s=>{let a=s.senderId===n,i=function(e){if(!e)return"";try{let t=e.toDate(),s=new Date,r=new Date(s.getFullYear(),s.getMonth(),s.getDate());if(new Date(t.getFullYear(),t.getMonth(),t.getDate()).getTime()===r.getTime())return t.toLocaleTimeString("zh-TW",{hour:"2-digit",minute:"2-digit"});return t.toLocaleString("zh-TW",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}catch{return""}}(s.createdAt)||"--",l=null!=s.readAt?"å·²è®":null,d="sending"===s.status,o="failed"===s.status;return(0,r.jsxs)("div",{className:(0,u.cn)("flex gap-3",a?"flex-row-reverse":"flex-row"),children:[(()=>{if(a)return(0,r.jsx)(N.H,{userId:n,size:"small",className:"h-8 w-8 flex-shrink-0"});if("user"===s.senderType)return(0,r.jsx)(N.H,{userId:e.userId,size:"small",className:"h-8 w-8 flex-shrink-0"});let i=e.advisorAvatar||t?.avatar,l=e.advisorName||t?.name||"é¡§å";return(0,r.jsxs)(j.eu,{className:"h-8 w-8 flex-shrink-0",children:[(0,r.jsx)(j.BK,{src:i||void 0,alt:l}),(0,r.jsx)(j.q5,{children:(l||"é¡§").substring(0,2)})]})})(),(0,r.jsxs)("div",{className:(0,u.cn)("flex flex-col gap-1 max-w-[70%]",a?"items-end":"items-start"),children:[(0,r.jsx)("div",{className:(0,u.cn)("rounded-2xl px-4 py-2",a?"bg-primary text-primary-foreground":"bg-muted",d&&"opacity-70"),children:(0,r.jsx)("p",{className:"text-sm whitespace-pre-wrap break-words",children:s.content||""})}),!o&&(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:i}),a&&d&&(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:"å³éä¸â¦"}),a&&o&&(0,r.jsxs)("button",{type:"button",onClick:()=>w?.(s),className:"flex items-center gap-1 text-xs text-destructive hover:underline",children:[(0,r.jsx)(D.A,{className:"h-3 w-3"}),"å³é失æï¼é»æé試"]}),a&&!d&&!o&&(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:l??"å·²éé"})]})]},s.id)}),(0,r.jsx)("div",{ref:k})]})}),(0,r.jsx)("div",{className:"p-4 border-t border-border",children:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)(E.p,{value:d,onChange:e=>{let t=e.target.value;t.length<=500&&m(t)},onKeyPress:h,placeholder:"輸å
¥è¨æ¯...",disabled:x,maxLength:500,className:"rounded-full border-border/60 bg-muted/40 px-4 focus-visible:ring-1 focus-visible:ring-accent"}),(0,r.jsx)(y.$,{onClick:f,disabled:!d.trim()||x,size:"icon",className:"rounded-full flex-shrink-0 bg-gradient-to-br from-blue-500 to-purple-500 text-white hover:opacity-90 disabled:opacity-40",children:x?(0,r.jsx)(l.A,{className:"h-4 w-4 animate-spin"}):(0,r.jsx)(P.A,{className:"h-4 w-4"})})]})})]})}var z=s(54611),V=s(31862);function O({open:e,onOpenChange:t,preselectedAdvisorId:s}){let{user:j}=(0,o.A)(),{toast:b}=(0,c.dj)(),{isAdvisor:N}=(0,m.b)(),{advisor:y,loading:E}=(0,f.s)(),k=(0,x.a)(),{displayName:I}=(0,V.M)(j?.uid),[C,A]=(0,a.useState)(null),[S,R]=(0,a.useState)(null),[M,L]=(0,a.useState)(""),[D,P]=(0,a.useState)(!1),[U,_]=(0,a.useState)([]),F=(0,a.useRef)(0),{chatRooms:G,isLoading:B}=function({userId:e,isAdvisor:t,advisorId:s,enabled:r=!0}
1){let[n,i]=(0,a.useState)([]),[l,d]=(0,a.useState)(!0),[o,c]=(0,a.useState)(null),u=s??null;return(0,a.useEffect)(()=>{if(!r||!e){i([]),d(!0),c(null);return}i([]),d(!0),c(null);let s=e=>{i(e),d(!1),c(null)},a=t?p.M.getAdvisorChatRooms(u,e,s):p.M.getUserChatRooms(e,s);return()=>{a()}},[r,e,t,u]),{chatRooms:n,isLoading:l,error:o}}({userId:j?.uid??null,isAdvisor:N,advisorId:y?.id,enabled:e&&!!j&&(!N||!E)}),{messages:Y,isLoading:$}=function({chatRoomId:e,enabled:t=!0}){let[s,r]=(0,a.useState)([]),[n,i]=(0,a.useState)(!0),[l,d]=(0,a.useState)(null);return(0,a.useEffect)(()=>{if(!t||!e){r([]),i(!1),d(null);return}r([]),i(!0),d(null);let s=v.s.getMessages(e,e=>{r(e),i(!1),d(null)});return()=>{s(),i(!1)}},[t,e]),{messages:s,isLoading:n,error:l}}({chatRoomId:S?.id??null,enabled:!!S});(0,a.useEffect)(()=>{if(!e||!j||!s)return;let t=!1;return P(!0),g.advisorOperations.getAllAdvisors().then(async e=>{if(t)return;let r=e.find(e=>e.id===s);if(r){A(r);let e=await (0,z.L)(j.uid)||j.displayName||void 0;return p.M.createChatRoom(j.uid,r.id,r.name,r.avatar,e,j.email||void 0)}}).then(e=>{!t&&e&&R(e)}).catch(e=>{t||((0,h.vV)("è¼å
¥é¡§åæå»ºç«è天室失æ",e),b({title:"é¯èª¤",description:"ç¡æ³éåè天ï¼è«ç¨å¾å試ã",variant:"destructive"}))}).finally(()=>{t||P(!1)}),()=>{t=!0}},[e,j,s,b]),(0,a.useEffect)(()=>{C&&j&&(async()=>{try{let e=await (0,z.L)(j.uid)||j.displayName||void 0,t=await p.M.createChatRoom(j.uid,C.id,C.name,C.avatar,e,j.email||void 0);R(t)}catch(e){(0,h.vV)("建ç«è天室失æ:",e),b({title:"é¯èª¤",description:"ç¡æ³å»ºç«è天室ï¼è«ç¨å¾å試ã",variant:"destructive"})}})()},[C,j,b]),(0,a.useEffect)(()=>{S&&j&&(async()=>{try{await v.s.markMessagesAsRead(S.id,j.uid)}catch(e){(0,h.vV)("æ¨è¨å·²è®å¤±æ:",e)}})()},[S,j]),(0,a.useEffect)(()=>{let e=S?.id;e?_(t=>t.filter(t=>t.roomId===e)):_([])},[S?.id]);let K=(0,a.useCallback)(async e=>{_(t=>t.map(t=>t.tempId===e.tempId?{...t,status:"sending"}:t));try{await v.s.sendMessage(e.roomId,e.senderId,e.senderType,e.senderName,e.content),F.current=Date.now(),_(t=>t.filter(t=>t.tempId!==e.tempId))}catch(t){(0,h.vV)("ç¼éè¨æ¯å¤±æ:",t),_(t=>t.map(t=>t.tempId===e.tempId?{...t,status:"failed"}:t)),b({title:"ç¼é失æ",description:t instanceof Error?t.message:"ç¡æ³ç¼éè¨æ¯ï¼è«ç¨å¾å試ã",variant:"destructive"})}},[b]),q=(0,a.useCallback)(async()=>{if(!M.trim()||!S||!j||Date.now()-F.current<1e3)return;let e=S.userId===j.uid,t=null!=y&&S.advisorId===y.id;if(!e&&!t)return void b({title:"ç¡æ¬éç¼é",description:"æ¨ä¸æ¯æ¤è天室çåèè
ã",variant:"destructive"});let s=M.trim();if(s.length>500)return void b({title:"è¨æ¯éé·",description:"è¨æ¯å
§å®¹æå¤ 500 åã",variant:"destructive"});let r=e?I||j.displayName||j.email?.split("@")[0]||"ç¨æ¶":S.advisorName||y?.name||"é¡§å",a=`local-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,i={id:a,tempId:a,roomId:S.id,senderId:j.uid,senderType:e?"user":"advisor",senderName:r,content:s,createdAt:n.Timestamp.now(),readAt:null,status:"sending"};L(""),F.current=Date.now(),_(e=>[...e,i]),await K(i)},[M,S,j,b,y,K,I]),H=(0,a.useCallback)(e=>{if(!e.tempId)return;let t=U.find(t=>t.tempId===e.tempId);t&&K(t)},[U,K]),W=(0,a.useMemo)(()=>{let e=S?.id;if(!e)return Y;let t=U.filter(t=>t.roomId===e);return 0===t.length?Y:[...Y,...t]},[Y,U,S?.id]),Q=!!C&&!S,J=D||Q,X=!!S||J,Z=!k||!X,ee=!k||X;return(0,r.jsx)(i.lG,{open:e,onOpenChange:t,children:(0,r.jsxs)(i.Cf,{className:(0,u.cn)("max-w-4xl h-[80vh] flex flex-col p-0",k&&"h-screen w-screen max-w-full max-h-full rounded-none"),children:[(0,r.jsx)(i.c7,{className:(0,u.cn)("px-6 py-4 border-b border-border",k&&"sr-only"),children:(0,r.jsx)(i.L3,{children:"è天室"})}),(0,r.jsxs)("div",{className:"flex flex-1 overflow-hidden",children:[Z&&(0,r.jsx)(w,{rooms:G,selectedRoomId:S?.id??null,onSelectRoom:R,currentUserId:j?.uid,isLoading:B,isAdvisor:N,selectedRoom:S,isMobile:k}),ee&&(0,r.jsxs)("div",{className:"flex-1 flex flex-col min-w-0",children:[J&&(0,r.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,r.jsxs)("div",{className:"flex flex-col items-center gap-3 text-muted-foreground",children:[(0,r.jsx)(l.A,{className:"h-8 w-8 animate-spin"}),(0,r.jsx)("p",{children:"建ç«è天室ä¸â¦"})]})}),!J&&S&&(0,r.jsx)(T,{room:S,selectedAdvisor:C,messages:W,currentUserId:j?.uid,isAdvisor:N,inputValue:M,onInputChange:L,onSendMessage:q,isSending:!1,onKeyPress:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),q())},isLoadingMessages:$,onRoomDeleted:()=>R(null),isMobile:k,onBack:()=>R(null),onRetry:H}),!J&&!S&&(0,r.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,r.jsxs)("div",{className:"text-center text-muted-foreground",children:[(0,r.jsx)(d.A,{className:"h-12 w-12 mx-auto mb-4 opacity-50"}),(0,r.jsx)("p",{children:"éå§è天"})]})})]})]})]})})}class U extends a.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e,t){(0,h.vV)("[ErrorBoundary]",{error:e,componentStack:t?.componentStack}),this.props.onError?.(e,t)}render(){return this.state.hasError&&void 0!==this.props.fallback?this.props.fallback:this.state.hasError?null:this.props.children}}let _={openChat:()=>{},closeChat:()=>{},isOpen:!1},F=(0,a.createContext)(_);function G({children:e}){let[t,s]=(0,a.useState)(!1),[n,i]=(0,a.useState)(void 0),l=(0,a.useCallback)(e=>{i(e),s(!0)},[]),d=(0,a.useCallback)(()=>{s(!1),i(void 0)},[]),o=(0,a.useCallback)(e=>{s(e),e||i(void 0)},[]);return(0,r.jsxs)(F.Provider,{value:{openChat:l,closeChat:d,isOpen:t},children:[e,(0,r.jsx)(U,{fallback:null,children:(0,r.jsx)(O,{open:t,onOpenChange:o,preselectedAdvisorId:n})})]})}function B(){return(0,a.useContext)(F)??_}},84323:(e,t,s)=>{"use strict";s.d(t,{ThemeProvider:()=>n});var r=s(85047);s(31615);var a=s(99922);function n({children:e,...t}){return(0,r.jsx)(a.N,{...t,children:e})}},90474:(e,t,s)=>{"use strict";s.d(t,{default:()=>u});var r=s(85047),a=s(46377),n=s(73521),i=s(64498),l=s(80712),d=s(31615),o=s(17830);function c(){let{user:e,loading:t}=(0,n.A)();return(0,d.useEffect)(()=>{(0,o.isAmplitudeEnabled)()&&!t&&(0,o.setAmplitudeUserId)(e?.uid??null)},[e?.uid,t]),null}function u({children:e}){return"/"===(0,a.usePathname)()?(0,r.jsx)(r.Fragment,{children:e}):(0,r.jsxs)(n.O,{children:[(0,r.jsx)(c,{}),(0,r.jsx)(i.h,{children:(0,r.jsx)(l.k,{children:e})})]})}}},e=>{e.O(0,[9246,6901,6062,8721,2811,6277,274,9291,7629,5418,7355,8133,8594,6821,2931,5120,7125,5871,6162,4498,5084,6323,5035,3118,1936,7358],()=>e(e.s=76042)),_N_E=e.O()}]);
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.