mirror of
https://github.com/MatrixSeven/file-transfer-go.git
synced 2026-02-04 03:25:03 +08:00
1 line
80 KiB
JavaScript
1 line
80 KiB
JavaScript
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[974],{2176:(e,s,t)=>{"use strict";t.d(s,{default:()=>G});var a=t(5155),l=t(2115),n=t(5695),r=t(3559),c=t(2596),i=t(9688);function o(){for(var e=arguments.length,s=Array(e),t=0;t<e;t++)s[t]=arguments[t];return(0,i.QP)((0,c.$)(s))}let d=r.bL,m=l.forwardRef((e,s)=>{let{className:t,...l}=e;return(0,a.jsx)(r.B8,{ref:s,className:o("inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",t),...l})});m.displayName=r.B8.displayName;let x=l.forwardRef((e,s)=>{let{className:t,...l}=e;return(0,a.jsx)(r.l9,{ref:s,className:o("inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm",t),...l})});x.displayName=r.l9.displayName;let u=l.forwardRef((e,s)=>{let{className:t,...l}=e;return(0,a.jsx)(r.UC,{ref:s,className:o("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",t),...l})});u.displayName=r.UC.displayName;var h=t(9869),g=t(1497),f=t(4738),p=t(9099);function b(){return(0,a.jsxs)("div",{className:"text-center mb-6 animate-fade-in-up",children:[(0,a.jsx)("h1",{className:"text-2xl sm:text-3xl md:text-4xl font-bold bg-gradient-to-r from-blue-600 via-purple-600 to-indigo-600 bg-clip-text text-transparent mb-2",children:"文件快传"}),(0,a.jsxs)("p",{className:"text-sm sm:text-base text-slate-600 max-w-xl mx-auto leading-relaxed px-4 mb-3",children:["安全、快速、简单的传输服务",(0,a.jsx)("br",{}),(0,a.jsx)("span",{className:"text-xs sm:text-sm text-slate-500",children:"基于WebRTC的端到端服务 - 无需注册,即传即用"})]}),(0,a.jsxs)("div",{className:"flex items-center justify-center gap-2 mb-4",children:[(0,a.jsxs)("a",{href:"https://github.com/MatrixSeven/file-transfer-go",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 px-3 py-1.5 text-xs sm:text-sm text-slate-600 hover:text-slate-800 bg-slate-100 hover:bg-slate-200 rounded-full transition-colors duration-200 border border-slate-200 hover:border-slate-300",children:[(0,a.jsx)(p.A,{className:"w-3 h-3 sm:w-4 sm:h-4"}),(0,a.jsx)("span",{className:"font-medium",children:"开源项目"})]}),(0,a.jsx)("span",{className:"text-xs text-slate-400",children:"|"}),(0,a.jsx)("a",{href:"https://github.com/MatrixSeven/file-transfer-go",target:"_blank",rel:"noopener noreferrer",className:"text-xs text-slate-500 hover:text-slate-700 hover:underline transition-colors duration-200",children:"https://github.com/MatrixSeven/file-transfer-go"})]}),(0,a.jsx)("div",{className:"w-64 sm:w-80 md:w-96 lg:w-[32rem] xl:w-[40rem] h-0.5 bg-gradient-to-r from-blue-400 via-purple-400 to-indigo-400 mx-auto mt-2 mb-2 opacity-60"})]})}var j=t(9509);let v=function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";try{if(void 0!==j&&j.env)return j.env[e]||s}catch(e){}return s},N={isDev:"development"===v("NODE_ENV"),isProd:"production"===v("NODE_ENV"),isStatic:!0,api:{backendUrl:v("GO_BACKEND_URL","http://localhost:8080"),baseUrl:v("NEXT_PUBLIC_API_BASE_URL","http://localhost:3000"),directBackendUrl:v("NEXT_PUBLIC_BACKEND_URL")||window.location.origin,wsUrl:v("NEXT_PUBLIC_WS_URL")||(()=>{{if("localhost"===window.location.hostname&&("3000"===window.location.port||"3001"===window.location.port))return"ws://localhost:8080/ws/p2p";let e="https:"===window.location.protocol?"wss:":"ws:";return"".concat(e,"//").concat(window.location.host,"/ws/p2p")}})()},timeout:{api:3e4,ws:6e4},retry:{max:3,delay:1e3}};function w(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"data",[s,t]=(0,l.useState)({isConnected:!1,isConnecting:!1,isWebSocketConnected:!1,error:null}),a=(0,l.useRef)(null),n=(0,l.useRef)(null),r=(0,l.useRef)(null),c=(0,l.useRef)(null),i=(0,l.useRef)(null),o=(0,l.useRef)(null),d=[{urls:"stun:stun.l.google.com:19302"},{urls:"stun:stun.miwifi.com"},{urls:"stun:turn.cloudflare.com:3478"}],m=(0,l.useCallback)(e=>{t(s=>({...s,...e}))},[]),x=(0,l.useCallback)(()=>{c.current&&(clearTimeout(c.current),c.current=null),r.current&&(r.current.close(),r.current=null),n.current&&(n.current.close(),n.current=null),a.current&&(a.current.close(),a.current=null)},[]),u=(0,l.useCallback)(async(s,t)=>{try{let a=await s.createOffer({offerToReceiveAudio:!1,offerToReceiveVideo:!1});await s.setLocalDescription(a);let l=setTimeout(()=>{t.readyState===WebSocket.OPEN&&(t.send(JSON.stringify({type:"offer",payload:s.localDescription})),console.log("[".concat(e,"] 发送 offer (超时发送)")))},3e3);"complete"===s.iceGatheringState?(clearTimeout(l),t.readyState===WebSocket.OPEN&&(t.send(JSON.stringify({type:"offer",payload:s.localDescription})),console.log("[".concat(e,"] 发送 offer (ICE收集完成)")))):s.onicegatheringstatechange=()=>{"complete"===s.iceGatheringState&&(clearTimeout(l),t.readyState===WebSocket.OPEN&&(t.send(JSON.stringify({type:"offer",payload:s.localDescription})),console.log("[".concat(e,"] 发送 offer (ICE收集完成)"))))}}catch(s){console.error("[".concat(e,"] 创建 offer 失败:"),s),m({error:"创建连接失败",isConnecting:!1})}},[e,m]),h=(0,l.useCallback)(s=>{if("string"==typeof s.data)try{let t=JSON.parse(s.data);console.log("[".concat(e,"] 收到消息:"),t.type),i.current&&i.current(t)}catch(s){console.error("[".concat(e,"] 解析消息失败:"),s)}else s.data instanceof ArrayBuffer&&(console.log("[".concat(e,"] 收到数据:"),s.data.byteLength,"bytes"),o.current&&o.current(s.data))},[e]),g=(0,l.useCallback)(async(t,l)=>{if(console.log("=== [".concat(e,"] WebRTC 连接开始 ===")),console.log("[".concat(e,"] 房间代码:"),t,"角色:",l),s.isConnecting)return void console.warn("[".concat(e,"] 正在连接中,跳过重复连接请求"));if(s.isConnected)return void console.warn("[".concat(e,"] 已经连接,跳过重复连接请求"));x(),m({isConnecting:!0,error:null}),c.current=setTimeout(()=>{console.warn("[".concat(e,"] 连接超时")),m({error:"连接超时,请检查网络状况或重新尝试",isConnecting:!1}),x()},3e4);try{let s=new RTCPeerConnection({iceServers:d,iceCandidatePoolSize:10});n.current=s;let i=N.api.wsUrl.replace("/ws/p2p","/ws/webrtc"),o=new WebSocket("".concat(i,"?code=").concat(t,"&role=").concat(l,"&channel=").concat(e));if(a.current=o,o.onopen=()=>{console.log("[".concat(e,"] WebSocket 连接已建立")),m({isWebSocketConnected:!0}),"sender"===l&&u(s,o)},o.onmessage=async t=>{try{let a=JSON.parse(t.data);switch(console.log("[".concat(e,"] 收到信令消息:"),a.type),a.type){case"offer":if("stable"===s.signalingState){await s.setRemoteDescription(new RTCSessionDescription(a.payload));let t=await s.createAnswer();await s.setLocalDescription(t),o.send(JSON.stringify({type:"answer",payload:t})),console.log("[".concat(e,"] 发送 answer"))}break;case"answer":"have-local-offer"===s.signalingState&&(await s.setRemoteDescription(new RTCSessionDescription(a.payload)),console.log("[".concat(e,"] 处理 answer 完成")));break;case"ice-candidate":a.payload&&s.remoteDescription&&(await s.addIceCandidate(new RTCIceCandidate(a.payload)),console.log("[".concat(e,"] 添加 ICE 候选")));break;case"error":console.error("[".concat(e,"] 信令错误:"),a.error),m({error:a.error,isConnecting:!1})}}catch(s){console.error("[".concat(e,"] 处理信令消息失败:"),s)}},o.onerror=s=>{console.error("[".concat(e,"] WebSocket 错误:"),s),m({error:"WebSocket连接失败,请检查网络连接",isConnecting:!1})},o.onclose=()=>{console.log("[".concat(e,"] WebSocket 连接已关闭")),m({isWebSocketConnected:!1})},s.onicecandidate=s=>{s.candidate&&o.readyState===WebSocket.OPEN&&(o.send(JSON.stringify({type:"ice-candidate",payload:s.candidate})),console.log("[".concat(e,"] 发送 ICE 候选")))},s.onconnectionstatechange=()=>{switch(console.log("[".concat(e,"] 连接状态变化:"),s.connectionState),s.connectionState){case"connected":c.current&&(clearTimeout(c.current),c.current=null),m({isConnected:!0,isConnecting:!1,error:null});break;case"failed":m({error:"WebRTC连接失败,可能是网络防火墙阻止了连接",isConnecting:!1,isConnected:!1});break;case"disconnected":m({isConnected:!1}),c.current&&(clearTimeout(c.current),c.current=null);break;case"closed":m({isConnected:!1,isConnecting:!1})}},"sender"===l){let t=s.createDataChannel(e,{ordered:!0,maxRetransmits:3});r.current=t,t.onopen=()=>{console.log("[".concat(e,"] 数据通道已打开 (发送方)"))},t.onmessage=h,t.onerror=s=>{console.error("[".concat(e,"] 数据通道错误:"),s),m({error:"数据通道连接失败,可能是网络环境受限",isConnecting:!1})}}else s.ondatachannel=s=>{let t=s.channel;r.current=t,t.onopen=()=>{console.log("[".concat(e,"] 数据通道已打开 (接收方)"))},t.onmessage=h,t.onerror=s=>{console.error("[".concat(e,"] 数据通道错误:"),s),m({error:"数据通道连接失败,可能是网络环境受限",isConnecting:!1})}}}catch(s){console.error("[".concat(e,"] 连接失败:"),s),m({error:s instanceof Error?s.message:"连接失败",isConnecting:!1})}},[e,m,x,u,h,s.isConnecting,s.isConnected]),f=(0,l.useCallback)(()=>{console.log("[".concat(e,"] 断开 WebRTC 连接")),x(),t({isConnected:!1,isConnecting:!1,isWebSocketConnected:!1,error:null})},[e,x]),p=(0,l.useCallback)(s=>{let t=r.current;if(!t||"open"!==t.readyState)return console.error("[".concat(e,"] 数据通道未准备就绪")),!1;try{return t.send(JSON.stringify(s)),console.log("[".concat(e,"] 发送消息:"),s.type),!0}catch(s){return console.error("[".concat(e,"] 发送消息失败:"),s),!1}},[e]),b=(0,l.useCallback)(s=>{let t=r.current;if(!t||"open"!==t.readyState)return console.error("[".concat(e,"] 数据通道未准备就绪")),!1;try{return t.send(s),console.log("[".concat(e,"] 发送数据:"),s.byteLength,"bytes"),!0}catch(s){return console.error("[".concat(e,"] 发送数据失败:"),s),!1}},[e]),j=(0,l.useCallback)(e=>{i.current=e},[]),v=(0,l.useCallback)(e=>{o.current=e},[]),w=(0,l.useCallback)(()=>{var e;return(null==(e=r.current)?void 0:e.readyState)||"closed"},[]);return{...s,connect:g,disconnect:f,sendMessage:p,sendData:b,setMessageHandler:j,setDataHandler:v,getChannelState:w}}function y(){let e=function(){let e=w("file-transfer"),[s,t]=(0,l.useState)({isTransferring:!1,progress:0,error:null,receivedFiles:[]}),a=(0,l.useRef)(new Map),n=(0,l.useRef)(null),r=(0,l.useRef)(new Set),c=(0,l.useRef)(new Set),i=(0,l.useRef)(new Set),o=(0,l.useRef)(new Set),d=(0,l.useCallback)(e=>{t(s=>({...s,...e}))},[]),m=(0,l.useCallback)(e=>{switch(console.log("文件传输处理消息:",e.type),e.type){case"file-metadata":let s=e.payload;console.log("开始接收文件:",s.name),a.current.set(s.id,{metadata:s,chunks:[],receivedChunks:0}),d({isTransferring:!0,progress:0});break;case"file-chunk-info":n.current=e.payload,console.log("准备接收文件块:",e.payload);break;case"file-complete":let{fileId:l}=e.payload,i=a.current.get(l);if(i){let e=new File([new Blob(i.chunks,{type:i.metadata.type})],i.metadata.name,{type:i.metadata.type});console.log("文件接收完成:",e.name),t(s=>({...s,receivedFiles:[...s.receivedFiles,{id:l,file:e}],isTransferring:!1,progress:100})),r.current.forEach(s=>s({id:l,file:e})),a.current.delete(l)}break;case"file-list":console.log("收到文件列表:",e.payload),o.current.forEach(s=>s(e.payload));break;case"file-request":let{fileId:m,fileName:x}=e.payload;console.log("收到文件请求:",x,m),c.current.forEach(e=>e(m,x))}},[d]),x=(0,l.useCallback)(e=>{if(!n.current)return void console.warn("收到数据但没有对应的块信息");let{fileId:s,chunkIndex:t,totalChunks:l}=n.current,r=a.current.get(s);if(r){r.chunks[t]=e,r.receivedChunks++;let a=r.receivedChunks/l*100;d({progress:a}),i.current.forEach(e=>e({fileId:s,fileName:r.metadata.name,progress:a})),console.log("文件 ".concat(r.metadata.name," 接收进度: ").concat(a.toFixed(1),"%")),n.current=null}},[d]);(0,l.useEffect)(()=>(e.setMessageHandler(m),e.setDataHandler(x),()=>{e.setMessageHandler(null),e.setDataHandler(null)}),[e.setMessageHandler,e.setDataHandler,m,x]);let u=(0,l.useCallback)((s,t)=>e.connect(s,t),[e.connect]),h=(0,l.useCallback)(async(s,t)=>{if("open"!==e.getChannelState())return void d({error:"连接未就绪"});let a=t||"file_".concat(Date.now(),"_").concat(Math.random().toString(36).substr(2,9)),l=Math.ceil(s.size/262144);console.log("开始发送文件:",s.name,"文件ID:",a,"总块数:",l),d({isTransferring:!0,progress:0,error:null});try{e.sendMessage({type:"file-metadata",payload:{id:a,name:s.name,size:s.size,type:s.type}});for(let t=0;t<l;t++){let n=262144*t,r=Math.min(n+262144,s.size),c=s.slice(n,r);e.sendMessage({type:"file-chunk-info",payload:{fileId:a,chunkIndex:t,totalChunks:l}});let o=await c.arrayBuffer();e.sendData(o);let m=(t+1)/l*100;d({progress:m}),i.current.forEach(e=>e({fileId:a,fileName:s.name,progress:m})),t%10==0&&await new Promise(e=>setTimeout(e,10))}e.sendMessage({type:"file-complete",payload:{fileId:a}}),d({isTransferring:!1,progress:100}),console.log("文件发送完成:",s.name)}catch(e){console.error("发送文件失败:",e),d({error:e instanceof Error?e.message:"发送失败",isTransferring:!1})}},[e.getChannelState,e.sendMessage,e.sendData,d]),g=(0,l.useCallback)(s=>{if("open"!==e.getChannelState())return void console.error("数据通道未准备就绪,无法发送文件列表");console.log("发送文件列表:",s),e.sendMessage({type:"file-list",payload:s})},[e.getChannelState,e.sendMessage]),f=(0,l.useCallback)((s,t)=>{if("open"!==e.getChannelState())return void console.error("数据通道未准备就绪,无法请求文件");console.log("请求文件:",t,s),e.sendMessage({type:"file-request",payload:{fileId:s,fileName:t}})},[e.getChannelState,e.sendMessage]),p=(0,l.useCallback)(e=>(r.current.add(e),()=>{r.current.delete(e)}),[]),b=(0,l.useCallback)(e=>(c.current.add(e),()=>{c.current.delete(e)}),[]),j=(0,l.useCallback)(e=>(i.current.add(e),()=>{i.current.delete(e)}),[]),v=(0,l.useCallback)(e=>(o.current.add(e),()=>{o.current.delete(e)}),[]);return{isConnected:e.isConnected,isConnecting:e.isConnecting,isWebSocketConnected:e.isWebSocketConnected,connectionError:e.error,...s,connect:u,disconnect:e.disconnect,sendFile:h,sendFileList:g,requestFile:f,onFileReceived:p,onFileRequested:b,onFileProgress:j,onFileListReceived:v}}(),s=function(){let e=w("text-transfer"),[s,t]=(0,l.useState)({messages:[],isTyping:!1,error:null}),a=(0,l.useRef)(new Set),n=(0,l.useRef)(new Set),r=(0,l.useRef)(new Set),c=(0,l.useRef)(null),i=(0,l.useCallback)(e=>{t(s=>({...s,...e}))},[]),o=(0,l.useCallback)(e=>{switch(e.type){case"text-message":let s=e.payload;console.log("收到文字消息:",s.text),t(e=>({...e,messages:[...e.messages,{id:s.id,text:s.text,timestamp:new Date(s.timestamp),sender:"peer"}]})),a.current.forEach(e=>e(s));break;case"typing-status":let{isTyping:l}=e.payload;i({isTyping:l}),n.current.forEach(e=>e(l));break;case"real-time-text":let{text:c}=e.payload;console.log("收到实时文本:",c),r.current.forEach(e=>e(c));break;case"text-clear":console.log("收到清空消息指令"),i({messages:[]})}},[i]);(0,l.useEffect)(()=>(e.setMessageHandler(o),()=>{e.setMessageHandler(null)}),[e.setMessageHandler,o]);let d=(0,l.useCallback)((s,t)=>e.connect(s,t),[e.connect]),m=(0,l.useCallback)(s=>{if("open"!==e.getChannelState())return void i({error:"连接未就绪"});let a={id:"msg_".concat(Date.now(),"_").concat(Math.random().toString(36).substr(2,9)),text:s,timestamp:new Date().toISOString()};console.log("发送文字消息:",s),e.sendMessage({type:"text-message",payload:a})?t(e=>({...e,messages:[...e.messages,{id:a.id,text:a.text,timestamp:new Date(a.timestamp),sender:"self"}],error:null})):i({error:"发送消息失败"})},[e.getChannelState,e.sendMessage,i]),x=(0,l.useCallback)(s=>{"open"===e.getChannelState()&&(e.sendMessage({type:"typing-status",payload:{isTyping:s}}),s?(c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{x(!1)},3e3)):c.current&&(clearTimeout(c.current),c.current=null))},[e.getChannelState,e.sendMessage]);(0,l.useCallback)(s=>{"open"===e.getChannelState()&&e.sendMessage({type:"real-time-text",payload:{text:s}})},[e.getChannelState,e.sendMessage]);let u=(0,l.useCallback)(()=>{i({messages:[]}),"open"===e.getChannelState()&&e.sendMessage({type:"text-clear",payload:{}})},[e.getChannelState,e.sendMessage,i]),h=(0,l.useCallback)(e=>(a.current.add(e),()=>{a.current.delete(e)}),[]),g=(0,l.useCallback)(e=>(n.current.add(e),()=>{n.current.delete(e)}),[]);return{isConnected:e.isConnected,isConnecting:e.isConnecting,isWebSocketConnected:e.isWebSocketConnected,connectionError:e.error,...s,connect:d,disconnect:e.disconnect,sendMessage:m,sendTypingStatus:x,clearMessages:u,onMessageReceived:h,onTypingStatus:g}}(),t=(0,l.useCallback)((s,t)=>(console.log("连接文件传输通道..."),e.connect(s,t)),[e.connect]),a=(0,l.useCallback)((e,t)=>(console.log("连接文字传输通道..."),s.connect(e,t)),[s.connect]),n=(0,l.useCallback)(async(e,s)=>{console.log("=== 启动 WebRTC 多功能传输 ==="),console.log("房间代码:",e,"角色:",s),console.log("将建立独立的文件传输和文字传输连接"),await Promise.all([t(e,s),a(e,s)]),console.log("所有传输通道连接完成")},[t,a]),r=(0,l.useCallback)(()=>{console.log("断开所有 WebRTC 传输连接"),e.disconnect(),s.disconnect()},[e.disconnect,s.disconnect]);return{isConnected:e.isConnected,isConnecting:e.isConnecting,isWebSocketConnected:e.isWebSocketConnected,error:e.connectionError||e.error,isTransferring:e.isTransferring,transferProgress:e.progress,receivedFiles:e.receivedFiles,connect:e.connect,disconnect:e.disconnect,sendFile:e.sendFile,requestFile:e.requestFile,sendFileList:e.sendFileList,onFileRequested:e.onFileRequested,onFileReceived:e.onFileReceived,onFileProgress:e.onFileProgress,onFileListReceived:e.onFileListReceived,connectAll:n,disconnectAll:r,file:{isConnected:e.isConnected,isConnecting:e.isConnecting,isWebSocketConnected:e.isWebSocketConnected,connectionError:e.connectionError,isTransferring:e.isTransferring,progress:e.progress,error:e.error,receivedFiles:e.receivedFiles,connect:e.connect,disconnect:e.disconnect,sendFile:e.sendFile,sendFileList:e.sendFileList,requestFile:e.requestFile,onFileReceived:e.onFileReceived,onFileRequested:e.onFileRequested,onFileProgress:e.onFileProgress,onFileListReceived:e.onFileListReceived},text:{isConnected:s.isConnected,isConnecting:s.isConnecting,isWebSocketConnected:s.isWebSocketConnected,connectionError:s.connectionError,messages:s.messages,isTyping:s.isTyping,error:s.error,connect:s.connect,disconnect:s.disconnect,sendMessage:s.sendMessage,sendTypingStatus:s.sendTypingStatus,clearMessages:s.clearMessages,onMessageReceived:s.onMessageReceived,onTypingStatus:s.onTypingStatus},hasAnyConnection:e.isConnected||s.isConnected,isAnyConnecting:e.isConnecting||s.isConnecting,hasAnyError:!!(e.connectionError||s.connectionError)}}var C=t(9708);let k=(0,t(2085).F)("inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),S=l.forwardRef((e,s)=>{let{className:t,variant:l,size:n,asChild:r=!1,...c}=e,i=r?C.DX:"button";return(0,a.jsx)(i,{className:o(k({variant:l,size:n,className:t})),ref:s,...c})});S.displayName="Button";var R=t(6801),T=t(1788),F=t(7213),E=t(9803),W=t(227),D=t(9022),M=t(7434),A=t(4416),L=t(6862);function z(e){let{value:s,size:t=200,className:n="",title:r="扫码传输"}=e,c=(0,l.useRef)(null),[i,o]=(0,l.useState)("");return((0,l.useEffect)(()=>{(async()=>{try{c.current&&s&&(await L.toCanvas(c.current,s,{width:t,margin:2,color:{dark:"#1e293b",light:"#ffffff"}}),o(""))}catch(e){console.error("生成二维码失败:",e),o("生成二维码失败")}})()},[s,t]),i)?(0,a.jsx)("div",{className:"flex items-center justify-center bg-slate-100 rounded-lg ".concat(n),style:{width:t,height:t},children:(0,a.jsx)("p",{className:"text-sm text-slate-500",children:i})}):(0,a.jsxs)("div",{className:n,children:[r&&(0,a.jsx)("h3",{className:"text-sm font-medium text-slate-700 text-center mb-3",children:r}),(0,a.jsx)("div",{className:"flex justify-center",children:(0,a.jsx)("canvas",{ref:c,className:"rounded-lg",style:{maxWidth:"100%",height:"auto"}})})]})}function P(e){let{selectedFiles:s,fileList:t=[],onFilesChange:n,onGenerateCode:r,pickupCode:c,pickupLink:i,onCopyCode:o,onCopyLink:d,onAddMoreFiles:m,onRemoveFile:x,onClearFiles:u,onReset:g,disabled:f=!1,isConnected:p=!1,isWebSocketConnected:b=!1}=e,[j,v]=(0,l.useState)(!1),N=(0,l.useRef)(null),w=(0,l.useCallback)(e=>{e.preventDefault(),v(!0)},[]),y=(0,l.useCallback)(e=>{e.preventDefault(),e.currentTarget.contains(e.relatedTarget)||v(!1)},[]),C=(0,l.useCallback)(e=>{e.preventDefault(),v(!1);let t=Array.from(e.dataTransfer.files);t.length>0&&n([...s,...t])},[s,n]),k=(0,l.useCallback)(e=>{let t=Array.from(e.target.files||[]);t.length>0&&n([...s,...t])},[s,n]),R=(0,l.useCallback)(e=>{let t=s.filter((s,t)=>t!==e);n(t),x&&x(t)},[s,n,x]),T=(0,l.useCallback)(()=>{N.current&&N.current.click()},[]);return 0!==s.length||c?(0,a.jsxs)("div",{className:"space-y-4 sm:space-y-6",children:[(0,a.jsxs)("div",{children:[(0,a.jsxs)("div",{className:"flex items-center mb-4 sm:mb-6",children:[(0,a.jsxs)("div",{className:"flex items-center space-x-3 flex-1",children:[(0,a.jsx)("div",{className:"w-10 h-10 bg-gradient-to-br from-emerald-500 to-teal-500 rounded-xl flex items-center justify-center",children:(0,a.jsx)(M.A,{className:"w-5 h-5 text-white"})}),(0,a.jsxs)("div",{children:[(0,a.jsx)("h3",{className:"text-lg font-semibold text-slate-800",children:"已选择文件"}),(0,a.jsxs)("p",{className:"text-sm text-slate-500",children:[s.length," 个文件准备传输"]})]})]}),(0,a.jsx)("div",{className:"w-px h-12 bg-slate-200 mx-4"}),(0,a.jsxs)("div",{className:"text-right",children:[(0,a.jsx)("div",{className:"text-sm text-slate-500 mb-1",children:"连接状态"}),(0,a.jsxs)("div",{className:"flex items-center justify-end space-x-3 text-sm",children:[(0,a.jsx)("div",{className:"flex items-center space-x-1",children:b?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"w-2 h-2 rounded-full bg-emerald-500 animate-pulse"}),(0,a.jsx)("span",{className:"text-emerald-600",children:"WS"})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"w-2 h-2 rounded-full bg-slate-400"}),(0,a.jsx)("span",{className:"text-slate-600",children:"WS"})]})}),(0,a.jsx)("div",{className:"text-slate-300",children:"|"}),(0,a.jsx)("div",{className:"flex items-center space-x-1",children:p?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"w-2 h-2 rounded-full bg-emerald-500 animate-pulse"}),(0,a.jsx)("span",{className:"text-emerald-600",children:"RTC"})]}):c?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"w-2 h-2 rounded-full bg-orange-500 animate-pulse"}),(0,a.jsx)("span",{className:"text-orange-600",children:"RTC"})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"w-2 h-2 rounded-full bg-slate-400"}),(0,a.jsx)("span",{className:"text-slate-600",children:"RTC"})]})})]})]})]}),(0,a.jsx)("div",{className:"space-y-3 mb-4 sm:mb-6",children:s.map((e,s)=>{var l;let n=t.find(s=>s.name===e.name&&s.size===e.size);null==n||n.status;let r=(null==n?void 0:n.progress)||0,c=(null==n?void 0:n.status)||"ready";return(0,a.jsxs)("div",{className:"group bg-gradient-to-r from-slate-50 to-blue-50 border border-slate-200 rounded-xl hover:shadow-md transition-all duration-200",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between p-3 sm:p-4",children:[(0,a.jsxs)("div",{className:"flex items-center space-x-3 sm:space-x-4 min-w-0 flex-1",children:[(0,a.jsx)("div",{className:"w-10 h-10 sm:w-12 sm:h-12 bg-gradient-to-br from-blue-500 to-indigo-500 rounded-lg flex items-center justify-center flex-shrink-0",children:(l=e.type).startsWith("image/")?(0,a.jsx)(F.A,{className:"w-5 h-5 text-white"}):l.startsWith("video/")?(0,a.jsx)(E.A,{className:"w-5 h-5 text-white"}):l.startsWith("audio/")?(0,a.jsx)(W.A,{className:"w-5 h-5 text-white"}):l.includes("zip")||l.includes("rar")?(0,a.jsx)(D.A,{className:"w-5 h-5 text-white"}):(0,a.jsx)(M.A,{className:"w-5 h-5 text-white"})}),(0,a.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,a.jsx)("p",{className:"font-medium text-slate-800 truncate text-sm sm:text-base",children:e.name}),(0,a.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,a.jsx)("p",{className:"text-xs sm:text-sm text-slate-500",children:(e=>{if(0===e)return"0 Bytes";let s=Math.floor(Math.log(e)/Math.log(1024));return parseFloat((e/Math.pow(1024,s)).toFixed(2))+" "+["Bytes","KB","MB","GB"][s]})(e.size)}),"downloading"===c&&(0,a.jsxs)("div",{className:"flex items-center space-x-1",children:[(0,a.jsx)("div",{className:"w-1 h-1 bg-orange-500 rounded-full animate-pulse"}),(0,a.jsx)("span",{className:"text-xs text-orange-600 font-medium",children:"传输中"})]}),"completed"===c&&(0,a.jsxs)("div",{className:"flex items-center space-x-1",children:[(0,a.jsx)("div",{className:"w-1 h-1 bg-emerald-500 rounded-full"}),(0,a.jsx)("span",{className:"text-xs text-emerald-600 font-medium",children:"已完成"})]})]})]})]}),(0,a.jsx)(S,{variant:"ghost",size:"sm",onClick:()=>R(s),disabled:f||"downloading"===c,className:"opacity-0 group-hover:opacity-100 text-slate-400 hover:text-red-500 hover:bg-red-50 transition-all duration-200 flex-shrink-0 ml-2 disabled:opacity-50",children:(0,a.jsx)(A.A,{className:"w-4 h-4"})})]}),("downloading"===c||"completed"===c)&&r>0&&(0,a.jsx)("div",{className:"px-3 sm:px-4 pb-3 sm:pb-4",children:(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsxs)("div",{className:"flex justify-between text-xs text-slate-600",children:[(0,a.jsx)("span",{children:"downloading"===c?"正在发送...":"发送完成"}),(0,a.jsxs)("span",{className:"font-medium",children:[r.toFixed(1),"%"]})]}),(0,a.jsx)("div",{className:"w-full bg-slate-200 rounded-full h-2",children:(0,a.jsx)("div",{className:"h-2 rounded-full transition-all duration-300 ".concat("completed"===c?"bg-gradient-to-r from-emerald-500 to-emerald-600":"bg-gradient-to-r from-orange-500 to-orange-600"),style:{width:"".concat(r,"%")}})})]})})]},"".concat(e.name,"-").concat(e.size,"-").concat(s))})}),(0,a.jsxs)("div",{className:"flex flex-col sm:flex-row gap-3",children:[!c&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(S,{onClick:r,disabled:f||0===s.length,className:"button-primary text-white px-6 sm:px-8 py-3 rounded-xl font-medium flex-1 min-w-0 shadow-lg",children:[(0,a.jsx)(h.A,{className:"w-5 h-5 mr-2"}),"生成取件码"]}),(0,a.jsx)(S,{onClick:m,variant:"outline",disabled:f,className:"px-6 sm:px-8 py-3 rounded-xl font-medium",children:"添加文件"}),(0,a.jsx)(S,{onClick:g,variant:"outline",disabled:f,className:"text-red-600 hover:bg-red-50 px-6 sm:px-8 py-3 rounded-xl font-medium",children:"重新选择"})]}),c&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(S,{variant:"outline",onClick:m,disabled:f,className:"px-6 py-3 rounded-xl border-slate-300 text-slate-600 hover:bg-slate-50 flex-1",children:"添加更多文件"}),s.length>0&&u&&(0,a.jsx)(S,{variant:"outline",onClick:u,disabled:f,className:"px-6 py-3 rounded-xl border-orange-300 text-orange-600 hover:bg-orange-50",children:"清空文件"})]}),(0,a.jsx)(S,{variant:"outline",onClick:g,disabled:f,className:"px-6 py-3 rounded-xl border-red-300 text-red-600 hover:bg-red-50",children:"关闭房间"})]})]}),c&&(0,a.jsxs)("div",{className:"border-t border-slate-200 pt-6",children:[(0,a.jsx)("div",{className:"flex items-center mb-6",children:(0,a.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,a.jsx)("div",{className:"w-10 h-10 bg-gradient-to-br from-emerald-500 to-teal-500 rounded-xl flex items-center justify-center",children:(0,a.jsx)(M.A,{className:"w-5 h-5 text-white"})}),(0,a.jsxs)("div",{children:[(0,a.jsx)("h3",{className:"text-lg font-semibold text-slate-800",children:"取件码生成成功!"}),(0,a.jsx)("p",{className:"text-sm text-slate-600",children:"分享以下信息给接收方"})]})]})}),(0,a.jsxs)("div",{className:"flex flex-col lg:flex-row lg:items-start gap-6 lg:gap-8 mb-8",children:[(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsx)("label",{className:"block text-sm font-medium text-slate-700 mb-3",children:"取件码"}),(0,a.jsx)("div",{className:"flex flex-col items-center rounded-xl border border-slate-200 p-6 h-40 justify-center bg-slate-50",children:(0,a.jsx)("div",{className:"text-2xl font-bold font-mono bg-gradient-to-r from-emerald-600 to-teal-600 bg-clip-text text-transparent tracking-wider",children:c})}),(0,a.jsx)(S,{onClick:o,className:"w-full px-4 py-2.5 bg-emerald-500 hover:bg-emerald-600 text-white rounded-lg font-medium shadow transition-all duration-200 mt-3",children:"复制取件码"})]}),(0,a.jsx)("div",{className:"hidden lg:block w-px bg-slate-200 h-64 mt-6"}),i&&(0,a.jsxs)("div",{className:"flex-1",children:[(0,a.jsx)("label",{className:"block text-sm font-medium text-slate-700 mb-3",children:"扫码传输"}),(0,a.jsx)("div",{className:"flex flex-col items-center rounded-xl border border-slate-200 p-6 h-40 justify-center bg-slate-50",children:(0,a.jsx)(z,{value:i,size:120,title:"",className:"w-auto"})}),(0,a.jsx)("div",{className:"w-full px-4 py-2.5 bg-blue-500 text-white rounded-lg font-medium shadow transition-all duration-200 mt-3 text-center",children:"使用手机扫码快速访问"})]})]}),i&&(0,a.jsx)("div",{className:"space-y-3",children:(0,a.jsxs)("div",{className:"flex gap-3",children:[(0,a.jsx)("div",{className:"flex-1 code-display rounded-lg p-3 bg-slate-50 border border-slate-200",children:(0,a.jsx)("div",{className:"text-sm text-slate-700 break-all font-mono leading-relaxed",children:i})}),(0,a.jsx)(S,{onClick:d,className:"px-4 py-2.5 bg-blue-500 hover:bg-blue-600 text-white rounded-lg font-medium shadow transition-all duration-200 shrink-0",children:"复制链接"})]})})]})]}):(0,a.jsxs)("div",{className:"space-y-6",children:[(0,a.jsxs)("div",{className:"flex items-center",children:[(0,a.jsxs)("div",{className:"flex items-center space-x-3 flex-1",children:[(0,a.jsx)("div",{className:"w-10 h-10 bg-gradient-to-br from-blue-500 to-indigo-500 rounded-xl flex items-center justify-center",children:(0,a.jsx)(h.A,{className:"w-5 h-5 text-white"})}),(0,a.jsxs)("div",{children:[(0,a.jsx)("h2",{className:"text-lg font-semibold text-slate-800",children:"选择文件"}),(0,a.jsx)("p",{className:"text-sm text-slate-600",children:"拖拽文件到下方区域或点击选择文件"})]})]}),(0,a.jsx)("div",{className:"w-px h-12 bg-slate-200 mx-4"}),(0,a.jsxs)("div",{className:"text-right",children:[(0,a.jsx)("div",{className:"text-sm text-slate-500 mb-1",children:"连接状态"}),(0,a.jsxs)("div",{className:"flex items-center justify-end space-x-3 text-sm",children:[(0,a.jsxs)("div",{className:"flex items-center space-x-1",children:[(0,a.jsx)("div",{className:"w-2 h-2 rounded-full bg-slate-400"}),(0,a.jsx)("span",{className:"text-slate-600",children:"WS"})]}),(0,a.jsx)("div",{className:"text-slate-300",children:"|"}),(0,a.jsxs)("div",{className:"flex items-center space-x-1",children:[(0,a.jsx)("div",{className:"w-2 h-2 rounded-full bg-slate-400"}),(0,a.jsx)("span",{className:"text-slate-600",children:"RTC"})]})]})]})]}),(0,a.jsxs)("div",{className:"upload-area rounded-xl p-6 sm:p-8 md:p-12 text-center cursor-pointer ".concat(j?"drag-active":""),onDragOver:w,onDragLeave:y,onDrop:C,onClick:T,children:[(0,a.jsxs)("div",{className:"transition-all duration-300 ".concat(j?"scale-110":""),children:[(0,a.jsx)("div",{className:"w-16 h-16 sm:w-20 sm:h-20 mx-auto mb-4 sm:mb-6 bg-gradient-to-br from-blue-100 to-indigo-100 rounded-full flex items-center justify-center",children:(0,a.jsx)(h.A,{className:"w-8 h-8 sm:w-10 sm:h-10 transition-colors duration-300 ".concat(j?"text-blue-600":"text-slate-400")})}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)("p",{className:"text-lg sm:text-xl font-medium text-slate-700",children:j?"释放文件":"拖拽文件到这里"}),(0,a.jsxs)("p",{className:"text-sm sm:text-base text-slate-500",children:["或者 ",(0,a.jsx)("span",{className:"text-blue-600 font-medium underline",children:"点击选择文件"})]}),(0,a.jsx)("p",{className:"text-xs sm:text-sm text-slate-400 mt-4",children:"支持多个文件同时上传,WebRTC点对点传输"})]})]}),(0,a.jsx)("input",{ref:N,type:"file",multiple:!0,className:"hidden",onChange:k,disabled:f})]})]})}let U=l.forwardRef((e,s)=>{let{className:t,type:l,...n}=e;return(0,a.jsx)("input",{type:l,className:o("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",t),ref:s,...n})});function I(e){let{onJoinRoom:s,files:t,onDownloadFile:n,isConnected:r,isConnecting:c,isWebSocketConnected:i=!1,downloadedFiles:o,error:d=null,onReset:m}=e,[x,u]=(0,l.useState)(""),[h,g]=(0,l.useState)(!1),{showToast:f}=(0,R.d)(),p=async e=>{try{g(!0),console.log("开始验证取件码:",e);let s=await fetch("/api/room-info?code=".concat(e)),t=await s.json();if(console.log("验证响应:",{status:s.status,data:t}),!s.ok||!t.success){let e=t.message||"取件码验证失败";return f(e,"error"),console.log("验证失败:",e),!1}return console.log("取件码验证成功:",t.room),!0}catch(e){return console.error("验证取件码时发生错误:",e),f("网络错误,请检查连接后重试","error"),!1}finally{g(!1)}},b=(0,l.useCallback)(async e=>{if(e.preventDefault(),6===x.length){let e=x.toUpperCase();await p(e)&&s(e)}},[x,s]),j=(0,l.useCallback)(e=>{let s=e.target.value.replace(/[^A-Z0-9]/g,"").toUpperCase();s.length<=6&&u(s)},[]);return(l.useEffect(()=>{if(d&&!c&&!r&&!h){let e=setTimeout(()=>{console.log("重置取件码输入"),u("")},3e3);return()=>clearTimeout(e)}},[d,c,r,h]),(r||c)&&0===t.length)?(0,a.jsxs)("div",{children:[(0,a.jsxs)("div",{className:"flex items-center mb-6",children:[(0,a.jsxs)("div",{className:"flex items-center space-x-3 flex-1",children:[(0,a.jsx)("div",{className:"w-10 h-10 bg-gradient-to-br from-blue-500 to-indigo-500 rounded-xl flex items-center justify-center",children:(0,a.jsx)(T.A,{className:"w-5 h-5 text-white"})}),(0,a.jsxs)("div",{children:[(0,a.jsx)("h2",{className:"text-lg font-semibold text-slate-800",children:"等待文件"}),(0,a.jsx)("p",{className:"text-sm text-slate-600",children:r?"已连接到房间,等待发送方选择文件...":"正在连接到房间..."})]})]}),(0,a.jsx)("div",{className:"w-px h-12 bg-slate-200 mx-4"}),(0,a.jsxs)("div",{className:"text-right",children:[(0,a.jsx)("div",{className:"text-sm text-slate-500 mb-1",children:"连接状态"}),(0,a.jsxs)("div",{className:"flex items-center justify-end space-x-3 text-sm",children:[(0,a.jsx)("div",{className:"flex items-center space-x-1",children:i?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"w-2 h-2 rounded-full bg-emerald-500 animate-pulse"}),(0,a.jsx)("span",{className:"text-emerald-600",children:"WS"})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"w-2 h-2 rounded-full bg-orange-500 animate-pulse"}),(0,a.jsx)("span",{className:"text-orange-600",children:"WS"})]})}),(0,a.jsx)("div",{className:"text-slate-300",children:"|"}),(0,a.jsx)("div",{className:"flex items-center space-x-1",children:r?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"w-2 h-2 rounded-full bg-emerald-500 animate-pulse"}),(0,a.jsx)("span",{className:"text-emerald-600",children:"RTC"})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"w-2 h-2 rounded-full bg-orange-500 animate-pulse"}),(0,a.jsx)("span",{className:"text-orange-600",children:"RTC"})]})})]})]})]}),(0,a.jsxs)("div",{className:"text-center",children:[(0,a.jsx)("div",{className:"flex items-center justify-center space-x-4 mb-6",children:(0,a.jsxs)("div",{className:"flex items-center",children:[(0,a.jsx)("div",{className:"w-3 h-3 rounded-full mr-2 ".concat(r?"bg-emerald-500 animate-pulse":"bg-orange-500 animate-spin")}),(0,a.jsx)("span",{className:"text-sm font-medium ".concat(r?"text-emerald-600":"text-orange-600"),children:r?"连接已建立":"连接中..."})]})}),(0,a.jsx)("div",{className:"flex justify-center space-x-1 mb-6",children:[void 0,void 0,void 0].map((e,s)=>(0,a.jsx)("div",{className:"w-2 h-2 bg-blue-500 rounded-full animate-bounce",style:{animationDelay:"".concat(.1*s,"s")}},s))}),(0,a.jsx)("div",{className:"p-4 bg-gradient-to-r from-blue-50 to-indigo-50 rounded-xl border border-blue-200",children:(0,a.jsxs)("p",{className:"text-xs sm:text-sm text-slate-600 text-center",children:["\uD83D\uDCA1 ",(0,a.jsx)("span",{className:"font-medium",children:"提示:"}),"房间已连接,发送方清空文件列表后您会看到此界面,等待对方重新选择文件"]})})]})]}):t.length>0?(0,a.jsxs)("div",{className:"space-y-4 sm:space-y-6",children:[(0,a.jsxs)("div",{className:"flex items-center",children:[(0,a.jsxs)("div",{className:"flex items-center space-x-3 flex-1",children:[(0,a.jsx)("div",{className:"w-10 h-10 bg-gradient-to-br from-emerald-500 to-teal-500 rounded-xl flex items-center justify-center",children:(0,a.jsx)(T.A,{className:"w-5 h-5 text-white"})}),(0,a.jsxs)("div",{children:[(0,a.jsx)("h3",{className:"text-lg font-semibold text-slate-800",children:"可下载文件"}),(0,a.jsx)("p",{className:"text-sm text-slate-500",children:r?(0,a.jsx)("span",{className:"text-emerald-600",children:"✅ 已连接,可以下载文件"}):(0,a.jsx)("span",{className:"text-amber-600",children:"⏳ 正在建立连接..."})})]})]}),(0,a.jsx)("div",{className:"w-px h-12 bg-slate-200 mx-4"}),(0,a.jsxs)("div",{className:"text-right",children:[(0,a.jsx)("div",{className:"text-sm text-slate-500 mb-1",children:"连接状态"}),(0,a.jsxs)("div",{className:"flex items-center justify-end space-x-3 text-sm",children:[(0,a.jsx)("div",{className:"flex items-center space-x-1",children:i?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"w-2 h-2 rounded-full bg-emerald-500 animate-pulse"}),(0,a.jsx)("span",{className:"text-emerald-600",children:"WS"})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"w-2 h-2 rounded-full bg-slate-400"}),(0,a.jsx)("span",{className:"text-slate-600",children:"WS"})]})}),(0,a.jsx)("div",{className:"text-slate-300",children:"|"}),(0,a.jsx)("div",{className:"flex items-center space-x-1",children:r?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"w-2 h-2 rounded-full bg-emerald-500 animate-pulse"}),(0,a.jsx)("span",{className:"text-emerald-600",children:"RTC"})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"w-2 h-2 rounded-full bg-orange-500 animate-pulse"}),(0,a.jsx)("span",{className:"text-orange-600",children:"RTC"})]})})]}),(0,a.jsxs)("div",{className:"mt-1 text-xs text-slate-400",children:[t.length," 个文件"]})]})]}),(0,a.jsx)("div",{children:(0,a.jsx)("div",{className:"space-y-3 sm:space-y-4",children:t.map(e=>{var s;let t="downloading"===e.status,l="completed"===e.status,c=null==o?void 0:o.has(e.id),i=e.progress;return console.log("文件状态:",{fileName:e.name,status:e.status,progress:e.progress,isDownloading:t,currentProgress:i}),(0,a.jsxs)("div",{className:"bg-gradient-to-r from-slate-50 to-blue-50 border border-slate-200 rounded-xl p-3 sm:p-4 hover:shadow-md transition-all duration-200",children:[(0,a.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between mb-3 gap-3",children:[(0,a.jsxs)("div",{className:"flex items-center space-x-3 sm:space-x-4 flex-1 min-w-0",children:[(0,a.jsx)("div",{className:"w-10 h-10 sm:w-12 sm:h-12 bg-gradient-to-br from-blue-500 to-indigo-500 rounded-lg flex items-center justify-center flex-shrink-0",children:(s=e.type).startsWith("image/")?(0,a.jsx)(F.A,{className:"w-5 h-5 text-white"}):s.startsWith("video/")?(0,a.jsx)(E.A,{className:"w-5 h-5 text-white"}):s.startsWith("audio/")?(0,a.jsx)(W.A,{className:"w-5 h-5 text-white"}):s.includes("zip")||s.includes("rar")?(0,a.jsx)(D.A,{className:"w-5 h-5 text-white"}):(0,a.jsx)(M.A,{className:"w-5 h-5 text-white"})}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsx)("p",{className:"font-medium text-slate-800 truncate text-sm sm:text-base",children:e.name}),(0,a.jsx)("p",{className:"text-sm text-slate-500",children:(e=>{if(0===e)return"0 Bytes";let s=Math.floor(Math.log(e)/Math.log(1024));return parseFloat((e/Math.pow(1024,s)).toFixed(2))+" "+["Bytes","KB","MB","GB"][s]})(e.size)}),c&&(0,a.jsx)("p",{className:"text-xs text-emerald-600 font-medium",children:"✅ 传输完成,点击保存"}),t&&(0,a.jsxs)("p",{className:"text-xs text-blue-600 font-medium",children:["⏳ 传输中...",i.toFixed(1),"%"]})]})]}),(0,a.jsxs)(S,{onClick:()=>n(e.id),disabled:!r||t,className:"px-6 py-2 rounded-lg font-medium shadow-lg transition-all duration-200 hover:shadow-xl ".concat(c?"bg-gradient-to-r from-blue-500 to-indigo-500 hover:from-blue-600 hover:to-indigo-600 text-white":t?"bg-slate-300 text-slate-500 cursor-not-allowed":"bg-gradient-to-r from-emerald-500 to-teal-500 hover:from-emerald-600 hover:to-teal-600 text-white"),children:[(0,a.jsx)(T.A,{className:"w-4 h-4 mr-2"}),t?"传输中...":c?"保存文件":"开始传输"]})]}),(t||l)&&i>0&&(0,a.jsxs)("div",{className:"mt-3 space-y-2",children:[(0,a.jsxs)("div",{className:"flex justify-between text-sm text-slate-600",children:[(0,a.jsx)("span",{children:c?"传输完成":"正在传输..."}),(0,a.jsxs)("span",{className:"font-medium",children:[i.toFixed(1),"%"]})]}),(0,a.jsx)("div",{className:"w-full bg-slate-200 rounded-full h-2",children:(0,a.jsx)("div",{className:"h-2 rounded-full transition-all duration-300 ".concat(c?"bg-gradient-to-r from-emerald-500 to-emerald-600":"bg-gradient-to-r from-emerald-500 to-teal-500"),style:{width:"".concat(i,"%")}})})]})]},e.id)})})})]}):(0,a.jsxs)("div",{children:[(0,a.jsxs)("div",{className:"flex items-center mb-6 sm:mb-8",children:[(0,a.jsxs)("div",{className:"flex items-center space-x-3 flex-1",children:[(0,a.jsx)("div",{className:"w-10 h-10 bg-gradient-to-br from-emerald-500 to-teal-500 rounded-xl flex items-center justify-center",children:(0,a.jsx)(T.A,{className:"w-5 h-5 text-white"})}),(0,a.jsxs)("div",{children:[(0,a.jsx)("h2",{className:"text-lg font-semibold text-slate-800",children:"输入取件码"}),(0,a.jsx)("p",{className:"text-sm text-slate-600",children:"请输入6位取件码来获取文件"})]})]}),(0,a.jsx)("div",{className:"w-px h-12 bg-slate-200 mx-4"}),(0,a.jsxs)("div",{className:"text-right",children:[(0,a.jsx)("div",{className:"text-sm text-slate-500 mb-1",children:"连接状态"}),(0,a.jsxs)("div",{className:"flex items-center justify-end space-x-3 text-sm",children:[(0,a.jsx)("div",{className:"flex items-center space-x-1",children:c?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"w-2 h-2 rounded-full bg-orange-500 animate-pulse"}),(0,a.jsx)("span",{className:"text-orange-600",children:"WS"})]}):i?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"w-2 h-2 rounded-full bg-emerald-500 animate-pulse"}),(0,a.jsx)("span",{className:"text-emerald-600",children:"WS"})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"w-2 h-2 rounded-full bg-slate-400"}),(0,a.jsx)("span",{className:"text-slate-600",children:"WS"})]})}),(0,a.jsx)("div",{className:"text-slate-300",children:"|"}),(0,a.jsx)("div",{className:"flex items-center space-x-1",children:r?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"w-2 h-2 rounded-full bg-emerald-500 animate-pulse"}),(0,a.jsx)("span",{className:"text-emerald-600",children:"RTC"})]}):c?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"w-2 h-2 rounded-full bg-orange-500 animate-pulse"}),(0,a.jsx)("span",{className:"text-orange-600",children:"RTC"})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"w-2 h-2 rounded-full bg-slate-400"}),(0,a.jsx)("span",{className:"text-slate-600",children:"RTC"})]})})]})]})]}),(0,a.jsxs)("form",{onSubmit:b,className:"space-y-4 sm:space-y-6",children:[(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)(U,{value:x,onChange:j,placeholder:"请输入取件码",className:"text-center text-2xl sm:text-3xl tracking-[0.3em] sm:tracking-[0.5em] font-mono h-12 sm:h-16 border-2 border-slate-200 rounded-xl focus:border-emerald-500 focus:ring-emerald-500 bg-white/80 backdrop-blur-sm pb-2 sm:pb-4",maxLength:6,disabled:h||c}),(0,a.jsx)("div",{className:"absolute inset-x-0 -bottom-4 sm:-bottom-6 flex justify-center space-x-1 sm:space-x-2",children:[...Array(6)].map((e,s)=>(0,a.jsx)("div",{className:"w-1.5 h-1.5 sm:w-2 sm:h-2 rounded-full transition-all duration-200 ".concat(s<x.length?"bg-emerald-500":"bg-slate-300")},s))})]}),(0,a.jsx)("div",{className:"h-3 sm:h-4"}),(0,a.jsxs)("p",{className:"text-center text-xs sm:text-sm text-slate-500",children:[x.length,"/6 位"]})]}),(0,a.jsx)(S,{type:"submit",className:"w-full h-10 sm:h-12 bg-gradient-to-r from-emerald-500 to-teal-500 hover:from-emerald-600 hover:to-teal-600 text-white text-base sm:text-lg font-medium rounded-xl shadow-lg transition-all duration-200 hover:shadow-xl hover:scale-105 disabled:opacity-50 disabled:scale-100",disabled:6!==x.length||h||c,children:h?(0,a.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,a.jsx)("div",{className:"w-5 h-5 border-2 border-white border-t-transparent rounded-full animate-spin"}),(0,a.jsx)("span",{children:"验证中..."})]}):c?(0,a.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,a.jsx)("div",{className:"w-5 h-5 border-2 border-white border-t-transparent rounded-full animate-spin"}),(0,a.jsx)("span",{children:"连接中..."})]}):(0,a.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,a.jsx)(T.A,{className:"w-5 h-5"}),(0,a.jsx)("span",{children:"开始接收"})]})})]}),(0,a.jsx)("div",{className:"mt-6 p-4 bg-gradient-to-r from-blue-50 to-indigo-50 rounded-xl border border-blue-200",children:(0,a.jsxs)("p",{className:"text-sm text-slate-600 text-center",children:["\uD83D\uDCA1 ",(0,a.jsx)("span",{className:"font-medium",children:"提示:"}),"取件码由发送方提供,有效期为24小时"]})})]})}U.displayName="Input";let _=()=>{let e=(0,n.useSearchParams)(),s=(0,n.useRouter)(),{showToast:t}=(0,R.d)(),[r,c]=(0,l.useState)([]),[i,o]=(0,l.useState)([]),[d,m]=(0,l.useState)(new Map),[x,u]=(0,l.useState)(null),[g,f]=(0,l.useState)(""),[p,b]=(0,l.useState)("send"),[j,v]=(0,l.useState)(!1),N=(0,l.useRef)(null),{isConnected:w,isConnecting:C,isWebSocketConnected:k,error:F,connect:E,disconnect:W,sendFile:D,sendFileList:M,requestFile:A,onFileReceived:L,onFileListReceived:z,onFileRequested:U,onFileProgress:_}=y(),B=(0,l.useCallback)(async e=>{console.log("=== 加入房间 ==="),console.log("取件码:",e);let s=e.trim();if(!s||6!==s.length)return void t("请输入正确的6位取件码","error");if(C||w)return void console.log("已在连接中或已连接,跳过重复的房间状态检查");try{console.log("检查房间状态...");let e=await fetch("/api/room-info?code=".concat(s));if(!e.ok)throw Error("HTTP ".concat(e.status,": 无法检查房间状态"));let n=await e.json();if(!n.success){var a,l;let e=n.message||"房间不存在或已过期";(null==(a=n.message)?void 0:a.includes("expired"))?e="房间已过期,请联系发送方重新创建":(null==(l=n.message)?void 0:l.includes("not found"))&&(e="房间不存在,请检查取件码是否正确"),t(e,"error");return}if(!n.sender_online)return void t("发送方不在线,请确认取件码是否正确或联系发送方","error");console.log("房间状态检查通过,开始连接..."),f(s),E(s,"receiver"),t("正在连接到房间: ".concat(s),"success")}catch(s){console.error("检查房间状态失败:",s);let e="检查房间状态失败";s instanceof Error&&(e=s.message.includes("network")||s.message.includes("fetch")?"网络连接失败,请检查网络状况":s.message.includes("timeout")?"请求超时,请重试":s.message.includes("HTTP 404")?"房间不存在,请检查取件码":s.message.includes("HTTP 500")?"服务器错误,请稍后重试":s.message),t(e,"error")}},[C,w,t,E]);(0,l.useEffect)(()=>{let s=e.get("mode"),t=e.get("type"),a=e.get("code");!j&&"webrtc"===t&&s&&["send","receive"].includes(s)&&(console.log("=== 处理初始URL参数 ==="),console.log("URL模式:",s,"类型:",t,"取件码:",a),b(s),v(!0),a&&"receive"===s&&(console.log("URL中有取件码,自动加入房间"),setTimeout(()=>{C||w||B(a)},100)))},[e,j,B,C,w]);let O=(0,l.useCallback)(t=>{console.log("=== 手动切换模式 ==="),console.log("新模式:",t),b(t);let a=new URLSearchParams(e.toString());a.set("type","webrtc"),a.set("mode",t),"send"===t&&a.delete("code"),s.push("?".concat(a.toString()),{scroll:!1})},[e,s]),H=()=>Date.now().toString(36)+Math.random().toString(36).substr(2),q=async()=>{if(0===r.length)return void t("需要选择文件才能创建传输房间","error");try{console.log("=== 创建房间 ==="),console.log("选中文件数:",r.length);let e=await fetch("/api/create-room",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"file",files:r.map(e=>({name:e.name,size:e.size,type:e.type,lastModified:e.lastModified}))})}),s=await e.json();if(!e.ok)throw Error(s.error||"创建房间失败");let a=s.code;f(a),console.log("房间创建成功,取件码:",a),E(a,"sender"),t("房间创建成功,取件码: ".concat(a),"success")}catch(s){console.error("创建房间失败:",s);let e="创建房间失败";s instanceof Error&&(e=s.message.includes("network")||s.message.includes("fetch")?"网络连接失败,请检查网络后重试":s.message.includes("timeout")?"请求超时,请重试":s.message.includes("server")||s.message.includes("500")?"服务器错误,请稍后重试":s.message),t(e,"error")}};(0,l.useEffect)(()=>z(e=>{console.log("=== 收到文件列表更新 ==="),console.log("文件列表:",e),console.log("当前模式:",p),"receive"===p&&o(e)}),[z,p]);let[J,G]=(0,l.useState)("");(0,l.useEffect)(()=>{if(F&&F!==J){console.log("=== 连接错误处理 ==="),console.log("错误信息:",F),console.log("当前模式:",p);let e=F;F.includes("WebSocket")?e="服务器连接失败,请检查网络连接或稍后重试":F.includes("数据通道")?e="数据通道连接失败,请重新尝试连接":F.includes("连接超时")?e="连接超时,请检查网络状况或重新尝试":F.includes("连接失败")?e="WebRTC连接失败,可能是网络环境限制,请尝试刷新页面":F.includes("信令错误")?e="信令服务器错误,请稍后重试":F.includes("创建连接失败")&&(e="无法建立P2P连接,请检查网络设置"),t(e,"error"),G(F),(F.includes("连接失败")||F.includes("数据通道连接失败")||F.includes("WebSocket"))&&(console.log("严重连接错误,清理传输状态"),u(null),o(e=>e.map(e=>"downloading"===e.status?{...e,status:"ready",progress:0}:e)))}},[F,p,t,J]),(0,l.useEffect)(()=>L(e=>{console.log("=== 接收到文件 ==="),console.log("文件:",e.file.name,"ID:",e.id),m(s=>new Map(s.set(e.id,e.file))),o(s=>s.map(s=>s.id===e.id?{...s,status:"completed",progress:100}:s))}),[L]),(0,l.useEffect)(()=>_(e=>{if(!w||F)return void console.log("连接已断开,忽略进度更新:",e.fileName);console.log("=== 文件进度更新 ==="),console.log("文件:",e.fileName,"ID:",e.fileId,"进度:",e.progress),u({fileId:e.fileId,fileName:e.fileName,progress:e.progress}),o(s=>s.map(s=>{if(s.id===e.fileId||s.name===e.fileName){let t=e.progress,a=t>=100?"completed":"downloading";return console.log("更新文件 ".concat(s.name," 进度: ").concat(s.progress," -> ").concat(t)),{...s,progress:t,status:a}}return s})),e.progress>=100&&"send"===p&&u(null)}),[_,p,w,F]),(0,l.useEffect)(()=>U((e,s)=>{if(console.log("=== 收到文件请求 ==="),console.log("文件:",s,"ID:",e,"当前模式:",p),"send"===p){if(!w||F){console.log("连接已断开,无法发送文件"),t("连接已断开,无法发送文件","error");return}console.log("当前选中的文件列表:",r.map(e=>e.name));let a=r.find(e=>e.name===s);if(!a){console.error("找不到匹配的文件:",s),console.log("可用文件:",r.map(e=>"".concat(e.name," (").concat(e.size," bytes)"))),t("无法找到文件: ".concat(s),"error");return}console.log("找到匹配文件,开始发送:",a.name,"ID:",e,"文件大小:",a.size),o(t=>t.map(t=>t.id===e||t.name===s?{...t,status:"downloading",progress:0}:t));try{D(a,e)}catch(a){console.error("发送文件失败:",a),t("发送文件失败: ".concat(s),"error"),o(t=>t.map(t=>t.id===e||t.name===s?{...t,status:"ready",progress:0}:t))}}else console.warn("接收模式下收到文件请求,忽略")}),[U,p,r,D,w,F]),(0,l.useEffect)(()=>{console.log("=== WebSocket状态变化 ==="),console.log("WebSocket连接状态:",k),console.log("WebRTC连接状态:",w),console.log("连接中状态:",C),k||w||C||!g||(t("与服务器的连接已断开,请重新连接","error"),console.log("WebSocket断开,清理传输状态"),u(null),o(e=>e.map(e=>"downloading"===e.status?{...e,status:"ready",progress:0}:e))),k&&C&&!w&&console.log("WebSocket已连接,正在建立P2P连接...")},[k,w,C,g,t]),(0,l.useEffect)(()=>{(w||C)&&!F||(x&&(console.log("连接断开,清理当前传输文件状态:",x.fileName),u(null)),o(e=>e.some(e=>"downloading"===e.status)?(console.log("重置正在传输的文件状态"),e.map(e=>"downloading"===e.status?{...e,status:"ready",progress:0}:e)):e))},[w,C,F,x]),(0,l.useEffect)(()=>{if(console.log("=== WebRTC连接状态变化 ==="),console.log("连接状态:",{isConnected:w,isConnecting:C,isWebSocketConnected:k,pickupCode:g,mode:p,selectedFilesCount:r.length,fileListCount:i.length}),w,C&&g&&console.log("正在建立WebRTC连接..."),w&&!F&&g&&"send"===p&&r.length>0)if(0===i.length){console.log("创建文件列表并发送...");let e=r.map(e=>({id:H(),name:e.name,size:e.size,type:e.type,status:"ready",progress:0}));o(e),setTimeout(()=>{w&&!F&&M(e)},500)}else i.length>0&&(console.log("发送现有文件列表..."),setTimeout(()=>{w&&!F&&M(i)},500))},[w,C,k,g,p,r.length,F]);let K=g?"".concat(window.location.origin,"?type=webrtc&mode=receive&code=").concat(g):"";return(0,a.jsxs)("div",{className:"space-y-4 sm:space-y-6",children:[(0,a.jsx)("div",{className:"flex justify-center mb-6",children:(0,a.jsxs)("div",{className:"bg-white/80 backdrop-blur-sm rounded-xl p-1 shadow-lg",children:[(0,a.jsxs)(S,{variant:"send"===p?"default":"ghost",onClick:()=>O("send"),className:"px-6 py-2 rounded-lg",children:[(0,a.jsx)(h.A,{className:"w-4 h-4 mr-2"}),"发送文件"]}),(0,a.jsxs)(S,{variant:"receive"===p?"default":"ghost",onClick:()=>O("receive"),className:"px-6 py-2 rounded-lg",children:[(0,a.jsx)(T.A,{className:"w-4 h-4 mr-2"}),"接收文件"]})]})}),"send"===p?(0,a.jsx)("div",{className:"bg-white/80 backdrop-blur-sm rounded-xl p-4 sm:p-6 shadow-lg border border-white/20 animate-fade-in-up",children:(0,a.jsx)(P,{selectedFiles:r,fileList:i,onFilesChange:c,onGenerateCode:q,pickupCode:g,pickupLink:K,onCopyCode:()=>{navigator.clipboard.writeText(g),t("取件码已复制","success")},onCopyLink:()=>{let e="".concat(window.location.origin,"?type=webrtc&mode=receive&code=").concat(g);navigator.clipboard.writeText(e),t("取件链接已复制","success")},onAddMoreFiles:()=>{var e;null==(e=N.current)||e.click()},onRemoveFile:c,onClearFiles:()=>{console.log("=== 清空文件 ==="),c([]),o([]),w&&g&&M([])},onReset:()=>{console.log("=== 重置房间 ==="),W(),f(""),c([]),o([]),m(new Map)},disabled:!!x,isConnected:w,isWebSocketConnected:k})}):(0,a.jsx)("div",{className:"bg-white/80 backdrop-blur-sm rounded-xl p-4 sm:p-6 shadow-lg border border-white/20 animate-fade-in-up",children:(0,a.jsx)(I,{onJoinRoom:B,files:i,onDownloadFile:e=>{d.get(e)?(e=>{let s=d.get(e);if(!s)return;let a=URL.createObjectURL(s),l=document.createElement("a");l.href=a,l.download=s.name,document.body.appendChild(l),l.click(),document.body.removeChild(l),URL.revokeObjectURL(a),t("".concat(s.name," 已保存到下载文件夹"),"success")})(e):(e=>{if("receive"!==p)return console.error("requestFile只能在接收模式下调用");if(!w||F)return t("连接已断开,请重新连接后再试","error");let s=i.find(s=>s.id===e);if(!s){console.error("找不到文件信息:",e),t("找不到文件信息","error");return}console.log("=== 开始请求文件 ==="),console.log("文件信息:",{name:s.name,id:e,size:s.size}),console.log("当前文件状态:",s.status),console.log("WebRTC连接状态:",{isConnected:w,isTransferring:!!x}),o(s=>{let t=s.map(s=>s.id===e?{...s,status:"downloading",progress:0}:s);return console.log("更新后的文件列表:",t.find(s=>s.id===e)),t}),console.log("调用hook的requestFile...");try{A(e,s.name)}catch(a){console.error("请求文件失败:",a),t("请求文件失败: ".concat(s.name),"error"),o(s=>s.map(s=>s.id===e?{...s,status:"ready",progress:0}:s))}})(e)},isConnected:w,isConnecting:C,isWebSocketConnected:k,downloadedFiles:d,error:F,onReset:()=>{if(console.log("=== 重置连接状态 ==="),W(),f(""),o([]),m(new Map),"receive"===p){let t=new URLSearchParams(e.toString());t.delete("code"),s.push("?".concat(t.toString()),{scroll:!1})}}})}),(0,a.jsx)("input",{ref:N,type:"file",multiple:!0,onChange:e=>(e=>{console.log("=== 文件选择 ==="),console.log("新文件:",e.map(e=>e.name)),c(s=>[...s,...e]);let s=e.map(e=>({id:H(),name:e.name,size:e.size,type:e.type,status:"ready",progress:0}));o(e=>{let t=[...e,...s];return console.log("更新后的文件列表:",t),w&&g&&(console.log("立即同步文件列表到对端"),setTimeout(()=>M(t),100)),t})})(Array.from(e.target.files||[])),className:"hidden"})]})};var B=t(4357),O=t(8164),H=t(2486);let q=()=>{let e=(0,n.useSearchParams)(),s=(0,n.useRouter)(),{showToast:t}=(0,R.d)(),[r,c]=(0,l.useState)("send"),[i,o]=(0,l.useState)(""),[d,m]=(0,l.useState)(""),[x,u]=(0,l.useState)([]),[h,f]=(0,l.useState)(""),[p,b]=(0,l.useState)(!1),[j,v]=(0,l.useState)(!1),[N,w]=(0,l.useState)(null),C=(0,l.useRef)(null),k=(0,l.useRef)(null),E=(0,l.useRef)(null),W=(0,l.useRef)(null),{text:D,file:M,connectAll:L,disconnectAll:P,hasAnyConnection:U,isAnyConnecting:I,hasAnyError:_}=y(),q=(0,l.useCallback)(async e=>{let s=e.trim().toUpperCase();if(!s||6!==s.length)return void t("请输入正确的6位取件码","error");if(I)return void console.log("已经在连接中,跳过重复请求");if(U)return void console.log("已经连接,跳过重复请求");try{o(s),await L(s,"receiver"),t("成功加入消息房间: ".concat(s),"success")}catch(e){console.error("加入房间失败:",e),t(e instanceof Error?e.message:"加入房间失败","error")}},[I,U,L]);(0,l.useEffect)(()=>{let s=e.get("mode"),t=e.get("type"),a=e.get("code");if(!j&&"message"===t&&s&&["send","receive"].includes(s)&&(console.log("=== 处理初始URL参数 ==="),console.log("URL模式:",s,"类型:",t,"取件码:",a),c(s),v(!0),a&&"receive"===s)){m(a);let e=setTimeout(()=>{U||I||q(a)},100);return()=>clearTimeout(e)}},[e,j,U,I,q]);let J=(0,l.useCallback)(t=>{console.log("=== 切换模式 ===",t),c(t);let a=new URLSearchParams(e.toString());a.set("type","message"),a.set("mode",t),"send"===t&&a.delete("code"),s.push("?".concat(a.toString()),{scroll:!1})},[e,s]);(0,l.useEffect)(()=>D.onMessageReceived(e=>{u(s=>[...s,{id:e.id,type:"text",content:e.text,timestamp:new Date(e.timestamp),sender:"peer"}])}),[D.onMessageReceived]),(0,l.useEffect)(()=>D.onTypingStatus(e=>{b(e)}),[D.onTypingStatus]),(0,l.useEffect)(()=>M.onFileReceived(e=>{if(e.file.type.startsWith("image/")){let s=new FileReader;s.onload=s=>{var t;let a=null==(t=s.target)?void 0:t.result;u(s=>[...s,{id:e.id,type:"image",content:a,timestamp:new Date,sender:"peer",fileName:e.file.name}])},s.readAsDataURL(e.file)}}),[M.onFileReceived]),(0,l.useEffect)(()=>{var e;null==(e=C.current)||e.scrollIntoView({behavior:"smooth"})},[x]);let G=async()=>{try{let e=await fetch("/api/create-room",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"message",initialText:h.trim()||"",hasImages:!1,maxFileSize:5242880,settings:{enableRealTimeText:!0,enableImageTransfer:!0}})}),s=await e.json();if(!e.ok)throw Error(s.error||"创建房间失败");let a=s.code;o(a),await L(a,"sender"),h.trim()&&setTimeout(()=>{K()},1e3),t("消息房间创建成功!取件码: ".concat(a),"success")}catch(e){console.error("创建房间失败:",e),t(e instanceof Error?e.message:"创建房间失败","error")}},K=()=>{if(!h.trim()||!D.isConnected)return;let e={id:"msg_".concat(Date.now()),type:"text",content:h.trim(),timestamp:new Date,sender:"self"};u(s=>[...s,e]),D.sendMessage(h.trim()),f(""),E.current&&(E.current.style.height="40px")},V=e=>{let s=e.target.value;f(s);let t=e.target;t.style.height="40px",t.style.height="".concat(Math.min(t.scrollHeight,120),"px"),D.isConnected&&(D.sendTypingStatus(s.length>0),W.current&&clearTimeout(W.current),s.length>0&&(W.current=setTimeout(()=>{D.sendTypingStatus(!1)},2e3)))},X=i?"".concat(window.location.origin,"?type=message&mode=receive&code=").concat(i):"";return(0,a.jsxs)("div",{className:"space-y-4 sm:space-y-6",children:[(0,a.jsx)("div",{className:"flex justify-center mb-6",children:(0,a.jsxs)("div",{className:"bg-white/80 backdrop-blur-sm rounded-xl p-1 shadow-lg",children:[(0,a.jsxs)(S,{variant:"send"===r?"default":"ghost",onClick:()=>J("send"),className:"px-6 py-2 rounded-lg",children:[(0,a.jsx)(g.A,{className:"w-4 h-4 mr-2"}),"发送消息"]}),(0,a.jsxs)(S,{variant:"receive"===r?"default":"ghost",onClick:()=>J("receive"),className:"px-6 py-2 rounded-lg",children:[(0,a.jsx)(T.A,{className:"w-4 h-4 mr-2"}),"接收消息"]})]})}),(0,a.jsx)("div",{className:"bg-white/80 backdrop-blur-sm rounded-xl p-4 sm:p-6 shadow-lg border border-white/20 animate-fade-in-up",children:"send"===r?(0,a.jsx)("div",{className:"space-y-6",children:i?(0,a.jsxs)("div",{className:"space-y-6",children:[(0,a.jsxs)("div",{className:"bg-emerald-50 border border-emerald-200 rounded-xl p-6",children:[(0,a.jsx)("h3",{className:"text-lg font-semibold text-emerald-800 mb-4",children:"消息房间已创建"}),(0,a.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"text-sm text-emerald-700 mb-2",children:"取件码"}),(0,a.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,a.jsx)("span",{className:"text-3xl font-mono font-bold text-emerald-800 bg-white px-4 py-2 rounded-lg",children:i}),(0,a.jsx)(S,{onClick:()=>{navigator.clipboard.writeText(i),t("取件码已复制","success")},size:"sm",variant:"outline",children:(0,a.jsx)(B.A,{className:"w-4 h-4"})})]})]}),(0,a.jsxs)(S,{onClick:()=>{let e=window.location.origin+window.location.pathname,s="".concat(e,"?type=message&mode=receive&code=").concat(i);navigator.clipboard.writeText(s).then(()=>{t("分享链接已复制","success")}).catch(()=>{t("复制失败,请手动复制","error")})},className:"w-full",size:"sm",children:[(0,a.jsx)(O.A,{className:"w-4 h-4 mr-2"}),"复制分享链接"]})]}),(0,a.jsx)("div",{className:"flex items-center justify-center",children:(0,a.jsx)(z,{value:X,size:120})})]})]}),U?(0,a.jsx)("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-3",children:(0,a.jsx)("p",{className:"text-blue-700 text-sm",children:"✅ 已连接,开始实时聊天"})}):(0,a.jsx)("div",{className:"bg-amber-50 border border-amber-200 rounded-lg p-4",children:(0,a.jsxs)("div",{className:"text-center",children:[(0,a.jsx)("p",{className:"text-amber-700 mb-2",children:"等待对方连接..."}),(0,a.jsx)("div",{className:"animate-spin rounded-full h-6 w-6 border-b-2 border-amber-600 mx-auto"})]})}),U&&(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsx)("div",{className:"bg-slate-50 rounded-lg p-4 max-h-80 overflow-y-auto",children:0===x.length?(0,a.jsx)("p",{className:"text-slate-500 text-center",children:"开始发送消息吧!"}):(0,a.jsxs)("div",{className:"space-y-3",children:[x.map(e=>(0,a.jsx)("div",{className:"flex ".concat("self"===e.sender?"justify-end":"justify-start"),children:(0,a.jsx)("div",{className:"max-w-xs ".concat("self"===e.sender?"bg-emerald-500 text-white":"bg-white"," rounded-lg p-3 shadow"),children:"text"===e.type?(0,a.jsx)("p",{className:"break-words",children:e.content}):(0,a.jsxs)("div",{children:[(0,a.jsx)("img",{src:e.content,alt:e.fileName,className:"max-w-full h-auto rounded cursor-pointer",onClick:()=>w(e.content)}),(0,a.jsx)("p",{className:"text-xs mt-1 opacity-75",children:e.fileName})]})})},e.id)),p&&(0,a.jsx)("div",{className:"flex justify-start",children:(0,a.jsx)("div",{className:"bg-gray-200 rounded-lg p-3",children:(0,a.jsx)("p",{className:"text-gray-600 text-sm",children:"对方正在输入..."})})}),(0,a.jsx)("div",{ref:C})]})}),(0,a.jsxs)("div",{className:"flex space-x-2",children:[(0,a.jsx)(S,{onClick:()=>{var e;return null==(e=k.current)?void 0:e.click()},variant:"outline",size:"sm",children:(0,a.jsx)(F.A,{className:"w-4 h-4"})}),(0,a.jsx)("textarea",{ref:E,value:h,onChange:V,placeholder:"输入消息...",className:"flex-1 px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-emerald-500 focus:border-transparent resize-none",rows:1,style:{minHeight:"40px",maxHeight:"120px"},onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),K())}}),(0,a.jsx)(S,{onClick:K,disabled:!h.trim(),className:"bg-emerald-500 hover:bg-emerald-600",children:(0,a.jsx)(H.A,{className:"w-4 h-4"})})]})]})]}):(0,a.jsxs)("div",{className:"space-y-6",children:[(0,a.jsxs)("div",{className:"flex items-center",children:[(0,a.jsxs)("div",{className:"flex items-center space-x-3 flex-1",children:[(0,a.jsx)("div",{className:"w-10 h-10 bg-gradient-to-br from-emerald-500 to-green-500 rounded-xl flex items-center justify-center",children:(0,a.jsx)(g.A,{className:"w-5 h-5 text-white"})}),(0,a.jsxs)("div",{children:[(0,a.jsx)("h2",{className:"text-lg font-semibold text-slate-800",children:"文本消息"}),(0,a.jsx)("p",{className:"text-sm text-slate-600",children:"输入消息内容,支持文字和图片传输"})]})]}),(0,a.jsx)("div",{className:"w-px h-12 bg-slate-200 mx-4"}),(0,a.jsxs)("div",{className:"text-right",children:[(0,a.jsx)("div",{className:"text-sm text-slate-500 mb-1",children:"连接状态"}),(0,a.jsxs)("div",{className:"flex items-center justify-end space-x-3 text-sm",children:[(0,a.jsxs)("div",{className:"flex items-center space-x-1",children:[(0,a.jsx)("div",{className:"w-2 h-2 rounded-full ".concat(D.isWebSocketConnected?"bg-green-500":"bg-slate-400")}),(0,a.jsx)("span",{className:"text-slate-600",children:"WS"})]}),(0,a.jsx)("div",{className:"text-slate-300",children:"|"}),(0,a.jsxs)("div",{className:"flex items-center space-x-1",children:[(0,a.jsx)("div",{className:"w-2 h-2 rounded-full ".concat(D.isConnected?"bg-green-500":"bg-slate-400")}),(0,a.jsx)("span",{className:"text-slate-600",children:"RTC"})]})]})]})]}),(0,a.jsx)("div",{className:"border-2 border-dashed border-slate-300 rounded-xl p-6",children:(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-sm font-medium text-slate-700 mb-2",children:"消息内容"}),(0,a.jsx)("textarea",{ref:E,value:h,onChange:V,placeholder:"输入要发送的消息...",className:"w-full px-4 py-3 border border-slate-300 rounded-lg focus:ring-2 focus:ring-emerald-500 focus:border-transparent resize-none",rows:4,style:{minHeight:"100px",maxHeight:"200px"}}),(0,a.jsxs)("div",{className:"mt-2 text-xs text-slate-500",children:[h.length,"/50000 字符 • 支持实时同步"]})]}),(0,a.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,a.jsxs)(S,{onClick:()=>{var e;return null==(e=k.current)?void 0:e.click()},variant:"outline",size:"sm",className:"flex items-center space-x-1",children:[(0,a.jsx)(F.A,{className:"w-4 h-4"}),(0,a.jsx)("span",{children:"添加图片"})]}),(0,a.jsx)("span",{className:"text-xs text-slate-500",children:"支持 JPG, PNG, GIF 格式,最大 5MB"})]})]})}),(0,a.jsx)("div",{className:"flex justify-center",children:(0,a.jsx)(S,{onClick:G,disabled:I,className:"px-8 py-3 bg-emerald-500 hover:bg-emerald-600 text-white rounded-xl shadow-lg",children:I?"创建中...":"创建消息房间"})})]})}):(0,a.jsxs)("div",{className:"space-y-6",children:[(0,a.jsxs)("div",{className:"flex items-center",children:[(0,a.jsxs)("div",{className:"flex items-center space-x-3 flex-1",children:[(0,a.jsx)("div",{className:"w-10 h-10 bg-gradient-to-br from-blue-500 to-indigo-500 rounded-xl flex items-center justify-center",children:(0,a.jsx)(T.A,{className:"w-5 h-5 text-white"})}),(0,a.jsxs)("div",{children:[(0,a.jsx)("h2",{className:"text-lg font-semibold text-slate-800",children:"接收消息"}),(0,a.jsx)("p",{className:"text-sm text-slate-600",children:"输入取件码或通过分享链接加入房间"})]})]}),(0,a.jsx)("div",{className:"w-px h-12 bg-slate-200 mx-4"}),(0,a.jsxs)("div",{className:"text-right",children:[(0,a.jsx)("div",{className:"text-sm text-slate-500 mb-1",children:"连接状态"}),(0,a.jsxs)("div",{className:"flex items-center justify-end space-x-3 text-sm",children:[(0,a.jsxs)("div",{className:"flex items-center space-x-1",children:[(0,a.jsx)("div",{className:"w-2 h-2 rounded-full ".concat(D.isWebSocketConnected?"bg-green-500":"bg-slate-400")}),(0,a.jsx)("span",{className:"text-slate-600",children:"WS"})]}),(0,a.jsx)("div",{className:"text-slate-300",children:"|"}),(0,a.jsxs)("div",{className:"flex items-center space-x-1",children:[(0,a.jsx)("div",{className:"w-2 h-2 rounded-full ".concat(D.isConnected?"bg-green-500":"bg-slate-400")}),(0,a.jsx)("span",{className:"text-slate-600",children:"RTC"})]})]})]})]}),U?(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-4",children:[(0,a.jsx)("h4",{className:"font-semibold text-blue-800 mb-1",children:"已连接到消息房间"}),(0,a.jsxs)("p",{className:"text-blue-700",children:["取件码: ",i]})]}),(0,a.jsx)("div",{className:"bg-slate-50 rounded-lg p-4 max-h-80 overflow-y-auto",children:0===x.length?(0,a.jsx)("p",{className:"text-slate-500 text-center",children:"等待接收消息..."}):(0,a.jsxs)("div",{className:"space-y-3",children:[x.map(e=>(0,a.jsx)("div",{className:"flex ".concat("self"===e.sender?"justify-end":"justify-start"),children:(0,a.jsx)("div",{className:"max-w-xs ".concat("self"===e.sender?"bg-blue-500 text-white":"bg-white"," rounded-lg p-3 shadow"),children:"text"===e.type?(0,a.jsx)("p",{className:"break-words",children:e.content}):(0,a.jsxs)("div",{children:[(0,a.jsx)("img",{src:e.content,alt:e.fileName,className:"max-w-full h-auto rounded cursor-pointer",onClick:()=>w(e.content)}),(0,a.jsx)("p",{className:"text-xs mt-1 opacity-75",children:e.fileName})]})})},e.id)),p&&(0,a.jsx)("div",{className:"flex justify-start",children:(0,a.jsx)("div",{className:"bg-gray-200 rounded-lg p-3",children:(0,a.jsx)("p",{className:"text-gray-600 text-sm",children:"对方正在输入..."})})}),(0,a.jsx)("div",{ref:C})]})}),(0,a.jsxs)("div",{className:"flex space-x-2",children:[(0,a.jsx)(S,{onClick:()=>{var e;return null==(e=k.current)?void 0:e.click()},variant:"outline",size:"sm",children:(0,a.jsx)(F.A,{className:"w-4 h-4"})}),(0,a.jsx)("textarea",{ref:E,value:h,onChange:V,placeholder:"回复消息...",className:"flex-1 px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent resize-none",rows:1,style:{minHeight:"40px",maxHeight:"120px"},onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),K())}}),(0,a.jsx)(S,{onClick:K,disabled:!h.trim(),children:(0,a.jsx)(H.A,{className:"w-4 h-4"})})]})]}):(0,a.jsx)("div",{className:"border-2 border-dashed border-slate-300 rounded-xl p-6",children:(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"block text-sm font-medium text-slate-700 mb-2",children:"输入6位取件码"}),(0,a.jsxs)("div",{className:"flex space-x-2",children:[(0,a.jsx)("input",{type:"text",value:d,onChange:e=>m(e.target.value.toUpperCase()),placeholder:"取件码",maxLength:6,className:"flex-1 px-4 py-3 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent font-mono text-lg text-center"}),(0,a.jsx)(S,{onClick:()=>q(d),disabled:!d.trim()||I,className:"px-6",children:I?"连接中...":"加入"})]})]})})]})}),(0,a.jsx)("input",{ref:k,type:"file",accept:"image/*",onChange:e=>{var s;let a=null==(s=e.target.files)?void 0:s[0];if(!a)return;if(!a.type.startsWith("image/"))return void t("请选择图片文件","error");if(a.size>5242880)return void t("图片文件大小不能超过5MB","error");let l=new FileReader;l.onload=e=>{var s;let t=null==(s=e.target)?void 0:s.result,l={id:"img_".concat(Date.now()),type:"image",content:t,timestamp:new Date,sender:"self",fileName:a.name};u(e=>[...e,l]),M.isConnected&&M.sendFile(a)},l.readAsDataURL(a),e.target.value=""},className:"hidden"}),N&&(0,a.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-75 flex items-center justify-center z-50",onClick:()=>w(null),children:(0,a.jsxs)("div",{className:"relative max-w-4xl max-h-4xl",children:[(0,a.jsx)("img",{src:N,alt:"预览",className:"max-w-full max-h-full"}),(0,a.jsx)(S,{onClick:()=>w(null),className:"absolute top-4 right-4 bg-white text-black hover:bg-gray-200",size:"sm",children:(0,a.jsx)(A.A,{className:"w-4 h-4"})})]})}),_&&(0,a.jsx)("div",{className:"text-center",children:(0,a.jsx)(S,{onClick:()=>{o(""),m(""),u([]),f(""),b(!1),w(null),P();let t=new URLSearchParams(e.toString());t.set("type","message"),t.set("mode",r),t.delete("code"),s.push("?".concat(t.toString()),{scroll:!1})},variant:"outline",children:"重新开始"})})]})};function J(){let e=(0,n.useSearchParams)(),[s,t]=(0,l.useState)("message"),[r,c]=(0,l.useState)(!1);return(0,l.useEffect)(()=>{if(!r){let s=e.get("type");console.log("=== HomePage URL处理 ==="),console.log("URL type参数:",s),console.log("所有搜索参数:",Object.fromEntries(e.entries())),"text"===s?(console.log("检测到text类型,重定向到message标签页"),t("message")):"webrtc"===s?(console.log("检测到webrtc类型,切换到webrtc标签页(文件传输)"),t("webrtc")):s&&["message","desktop"].includes(s)?(console.log("切换到对应标签页:",s),t(s)):console.log("没有有效的type参数,保持默认标签页"),c(!0)}},[e,r]),(0,a.jsx)("div",{className:"min-h-screen bg-gradient-to-br from-slate-50 to-blue-50",children:(0,a.jsxs)("div",{className:"container mx-auto px-4 py-4 sm:py-6 md:py-8",children:[(0,a.jsx)("div",{className:"text-center mb-6 sm:mb-8",children:(0,a.jsx)(b,{})}),(0,a.jsx)("div",{className:"max-w-4xl mx-auto",children:(0,a.jsxs)(d,{value:s,onValueChange:t,className:"w-full",children:[(0,a.jsx)("div",{className:"mb-6",children:(0,a.jsxs)(m,{className:"grid w-full grid-cols-3 max-w-xl mx-auto h-auto bg-white/90 backdrop-blur-sm shadow-lg rounded-xl p-2 border border-slate-200",children:[(0,a.jsxs)(x,{value:"webrtc",className:"flex items-center justify-center space-x-2 px-3 py-3 text-sm font-medium rounded-lg transition-all duration-200 hover:bg-slate-50 data-[state=active]:bg-blue-500 data-[state=active]:text-white data-[state=active]:shadow-md data-[state=active]:hover:bg-blue-600",children:[(0,a.jsx)(h.A,{className:"w-4 h-4"}),(0,a.jsx)("span",{className:"hidden sm:inline",children:"文件传输"}),(0,a.jsx)("span",{className:"sm:hidden",children:"文件"})]}),(0,a.jsxs)(x,{value:"message",className:"flex items-center justify-center space-x-2 px-3 py-3 text-sm font-medium rounded-lg transition-all duration-200 hover:bg-slate-50 data-[state=active]:bg-emerald-500 data-[state=active]:text-white data-[state=active]:shadow-md data-[state=active]:hover:bg-emerald-600",children:[(0,a.jsx)(g.A,{className:"w-4 h-4"}),(0,a.jsx)("span",{className:"hidden sm:inline",children:"文本消息"}),(0,a.jsx)("span",{className:"sm:hidden",children:"消息"})]}),(0,a.jsxs)(x,{value:"desktop",className:"flex items-center justify-center space-x-2 px-3 py-3 text-sm font-medium rounded-lg transition-all duration-200 hover:bg-slate-50 data-[state=active]:bg-purple-500 data-[state=active]:text-white data-[state=active]:shadow-md data-[state=active]:hover:bg-purple-600 relative",children:[(0,a.jsx)(f.A,{className:"w-4 h-4"}),(0,a.jsx)("span",{className:"hidden sm:inline",children:"共享桌面"}),(0,a.jsx)("span",{className:"sm:hidden",children:"桌面"}),(0,a.jsx)("span",{className:"text-xs bg-orange-100 text-orange-600 px-1.5 py-0.5 rounded ml-1 absolute -top-1 -right-1",children:"开发中"})]})]})}),(0,a.jsxs)("div",{children:[(0,a.jsx)(u,{value:"webrtc",className:"mt-0 animate-fade-in-up",children:(0,a.jsx)(_,{})}),(0,a.jsx)(u,{value:"message",className:"mt-0 animate-fade-in-up",children:(0,a.jsx)(q,{})}),(0,a.jsx)(u,{value:"desktop",className:"mt-0 animate-fade-in-up",children:(0,a.jsx)("div",{className:"max-w-md mx-auto p-8 bg-white/90 backdrop-blur-sm rounded-2xl shadow-lg border border-slate-200",children:(0,a.jsxs)("div",{className:"text-center",children:[(0,a.jsx)("div",{className:"w-16 h-16 mx-auto mb-4 bg-gradient-to-br from-purple-100 to-purple-200 rounded-full flex items-center justify-center",children:(0,a.jsx)(f.A,{className:"w-8 h-8 text-purple-600"})}),(0,a.jsx)("h3",{className:"text-xl font-semibold text-slate-800 mb-2",children:"桌面共享"}),(0,a.jsx)("p",{className:"text-slate-600 mb-4",children:"此功能正在开发中..."}),(0,a.jsx)("div",{className:"bg-purple-50 border border-purple-200 rounded-lg p-4",children:(0,a.jsx)("p",{className:"text-sm text-purple-700",children:"\uD83D\uDEA7 敬请期待!我们正在为您开发实时桌面共享功能"})}),(0,a.jsx)("p",{className:"text-xs text-slate-500 mt-4",children:"目前请使用文件传输功能"})]})})})]})]})})]})})}let G=function(){return(0,a.jsx)(l.Suspense,{fallback:(0,a.jsx)("div",{className:"min-h-screen flex items-center justify-center",children:"加载中..."}),children:(0,a.jsx)(J,{})})}},5018:(e,s,t)=>{Promise.resolve().then(t.bind(t,2176))},6801:(e,s,t)=>{"use strict";t.d(s,{ToastProvider:()=>c,d:()=>r});var a=t(5155),l=t(2115);let n=(0,l.createContext)(void 0),r=()=>{let e=(0,l.useContext)(n);if(!e)throw Error("useToast must be used within a ToastProvider");return e},c=e=>{let{children:s}=e,[t,r]=(0,l.useState)([]),c=(0,l.useCallback)(function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"success",t=Date.now().toString(),a={id:t,message:e,type:s};r(e=>[...e,a]),setTimeout(()=>{r(e=>e.filter(e=>e.id!==t))},3e3)},[]),i=(0,l.useCallback)(e=>{r(s=>s.filter(s=>s.id!==e))},[]);return(0,a.jsxs)(n.Provider,{value:{showToast:c},children:[s,(0,a.jsx)("div",{className:"fixed top-4 left-1/2 transform -translate-x-1/2 z-50 space-y-2",children:t.map(e=>(0,a.jsx)("div",{className:"\n max-w-sm p-4 rounded-xl shadow-lg backdrop-blur-sm transform transition-all duration-300 ease-in-out\n ".concat("success"===e.type?"bg-emerald-50/90 border border-emerald-200 text-emerald-800":"","\n ").concat("error"===e.type?"bg-red-50/90 border border-red-200 text-red-800":"","\n ").concat("info"===e.type?"bg-blue-50/90 border border-blue-200 text-blue-800":"","\n animate-slide-in-down\n "),onClick:()=>i(e.id),children:(0,a.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,a.jsxs)("div",{className:"flex-shrink-0",children:["success"===e.type&&(0,a.jsx)("div",{className:"w-6 h-6 bg-emerald-500 rounded-full flex items-center justify-center",children:(0,a.jsx)("svg",{className:"w-4 h-4 text-white",fill:"currentColor",viewBox:"0 0 20 20",children:(0,a.jsx)("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})})}),"error"===e.type&&(0,a.jsx)("div",{className:"w-6 h-6 bg-red-500 rounded-full flex items-center justify-center",children:(0,a.jsx)("svg",{className:"w-4 h-4 text-white",fill:"currentColor",viewBox:"0 0 20 20",children:(0,a.jsx)("path",{fillRule:"evenodd",d:"M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z",clipRule:"evenodd"})})}),"info"===e.type&&(0,a.jsx)("div",{className:"w-6 h-6 bg-blue-500 rounded-full flex items-center justify-center",children:(0,a.jsx)("svg",{className:"w-4 h-4 text-white",fill:"currentColor",viewBox:"0 0 20 20",children:(0,a.jsx)("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z",clipRule:"evenodd"})})})]}),(0,a.jsx)("p",{className:"text-sm font-medium",children:e.message})]})},e.id))})]})}}},e=>{e.O(0,[103,441,964,358],()=>e(e.s=5018)),_N_E=e.O()}]); |