"use client" import type React from "react" import { useState, useEffect } from "react" import { useRouter, useSearchParams } from "next/navigation" import { useAuth } from "@/contexts/auth-context" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select" import { Badge } from "@/components/ui/badge" import { Alert, AlertDescription } from "@/components/ui/alert" import { Separator } from "@/components/ui/separator" import { Brain, User, Mail, Building, Lock, Loader2, CheckCircle, AlertTriangle, Shield, Code } from "lucide-react" export default function RegisterPage() { const router = useRouter() const searchParams = useSearchParams() const { register, isLoading } = useAuth() const [formData, setFormData] = useState({ name: "", email: "", password: "", confirmPassword: "", department: "", }) const [error, setError] = useState("") const [success, setSuccess] = useState("") const [isSubmitting, setIsSubmitting] = useState(false) // 從 URL 參數獲取邀請資訊 const invitationToken = searchParams.get("token") const invitedEmail = searchParams.get("email") const invitedRole = searchParams.get("role") || "user" const isInvitedUser = !!(invitationToken && invitedEmail) useEffect(() => { if (isInvitedUser) { setFormData((prev) => ({ ...prev, email: decodeURIComponent(invitedEmail), })) } }, [isInvitedUser, invitedEmail]) const handleInputChange = (field: string, value: string) => { setFormData((prev) => ({ ...prev, [field]: value })) setError("") } const getRoleText = (role: string) => { switch (role) { case "admin": return "管理員" case "developer": return "開發者" case "user": return "一般用戶" default: return role } } const getRoleIcon = (role: string) => { switch (role) { case "admin": return case "developer": return case "user": return default: return } } const getRoleColor = (role: string) => { switch (role) { case "admin": return "bg-purple-100 text-purple-800 border-purple-200" case "developer": return "bg-green-100 text-green-800 border-green-200" case "user": return "bg-blue-100 text-blue-800 border-blue-200" default: return "bg-gray-100 text-gray-800 border-gray-200" } } const getRoleDescription = (role: string) => { switch (role) { case "admin": return "可以訪問管理後台,管理用戶和審核應用" case "developer": return "可以提交 AI 應用申請,參與平台建設" case "user": return "可以瀏覽和收藏應用,參與評價互動" default: return "" } } const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setError("") setIsSubmitting(true) // 表單驗證 if (!formData.name || !formData.email || !formData.password || !formData.department) { setError("請填寫所有必填欄位") setIsSubmitting(false) return } if (formData.password !== formData.confirmPassword) { setError("密碼確認不一致") setIsSubmitting(false) return } if (formData.password.length < 6) { setError("密碼長度至少需要 6 個字符") setIsSubmitting(false) return } try { const success = await register({ name: formData.name, email: formData.email, password: formData.password, department: formData.department, }) if (success) { setSuccess("註冊成功!正在跳轉...") setTimeout(() => { router.push("/") }, 2000) } else { setError("註冊失敗,請檢查資料或聯繫管理員") } } catch (err) { setError("註冊過程中發生錯誤,請稍後再試") } setIsSubmitting(false) } if (success) { return (

註冊成功!

歡迎加入強茂集團 AI 展示平台

正在跳轉到首頁...

) } return (
{/* Header */}

強茂集團 AI 展示平台

{isInvitedUser ? (

完成註冊

您已受邀加入平台,請完成以下資訊

) : (

建立帳戶

加入強茂集團 AI 展示平台

)}
註冊資訊 {isInvitedUser ? "請填寫您的個人資訊完成註冊" : "請填寫以下資訊建立您的帳戶"} {/* Invitation Info */} {isInvitedUser && (

邀請資訊

電子郵件: {invitedEmail}
預設角色:
{getRoleIcon(invitedRole)} {getRoleText(invitedRole)}

{getRoleDescription(invitedRole)}

)} {/* Error/Success Messages */} {error && ( {error} )}
handleInputChange("name", e.target.value)} placeholder="請輸入您的姓名" className="pl-10" disabled={isSubmitting} />
handleInputChange("email", e.target.value)} placeholder="請輸入電子郵件" className="pl-10" disabled={isSubmitting || isInvitedUser} readOnly={isInvitedUser} />
{isInvitedUser &&

此電子郵件由邀請連結自動填入

}
handleInputChange("password", e.target.value)} placeholder="請輸入密碼(至少 6 個字符)" className="pl-10" disabled={isSubmitting} />
handleInputChange("confirmPassword", e.target.value)} placeholder="請再次輸入密碼" className="pl-10" disabled={isSubmitting} />

已有帳戶?{" "}

{/* Role Information */} {!isInvitedUser && ( 角色說明 了解不同角色的權限和功能

一般用戶

可以瀏覽和收藏應用,參與評價互動

開發者

可以提交 AI 應用申請,參與平台建設

管理員

可以訪問管理後台,管理用戶和審核應用

注意:新註冊用戶預設為一般用戶角色。如需其他角色權限,請聯繫管理員進行調整。

)}
) }