"use client"
import { accounts, mails } from "./data"
import * as React from "react"
import {
AlertCircle, Archive, ArchiveX, Clock, File, Forward, Inbox, Mail as MailIcon,
MessagesSquare, MoreVertical, Reply, ReplyAll, Search, Send, ShoppingCart,
Trash2, Users2, LucideIcon
} from "lucide-react"
import { useMail } from "./use-mail"
import { cn } from "@/lib/utils"
import { format, formatDistanceToNow, addDays, addHours, nextSaturday } from "date-fns"
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import { Calendar } from "@/components/ui/calendar"
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"
import {
ResizableHandle,
ResizablePanel,
ResizablePanelGroup,
} from "@/components/ui/resizable"
import Footer from '../footer';
import { ScrollArea } from "@/components/ui/scroll-area"
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select"
import { Separator } from "@/components/ui/separator"
import { Switch } from "@/components/ui/switch"
import {
Tabs,
TabsContent,
TabsList,
TabsTrigger,
} from "@/components/ui/tabs"
import { Textarea } from "@/components/ui/textarea"
import {
Tooltip,
TooltipContent,
TooltipTrigger,
TooltipProvider,
} from "@/components/ui/tooltip"
interface Account {
label: string
email: string
icon: React.ReactNode
}
interface Mail {
id: string
name: string
email: string
subject: string
text: string
date: string
read: boolean
labels: string[]
}
interface NavLink {
title: string
label?: string
icon: LucideIcon
variant: "default" | "ghost"
}
interface MailProps {
accounts: Account[]
mails: Mail[]
defaultLayout?: number[]
defaultCollapsed?: boolean
navCollapsedSize: number
}
function MailComponent({
accounts,
mails,
defaultLayout = [20, 32, 48],
defaultCollapsed = false,
navCollapsedSize,
}: MailProps) {
const [isCollapsed, setIsCollapsed] = React.useState(defaultCollapsed)
const [mail, setMail] = useMail()
const navLinks: NavLink[] = [
{ title: "Inbox", label: "128", icon: Inbox, variant: "default" },
{ title: "Drafts", label: "9", icon: File, variant: "ghost" },
{ title: "Sent", label: "", icon: Send, variant: "ghost" },
{ title: "Junk", label: "23", icon: ArchiveX, variant: "ghost" },
{ title: "Trash", label: "", icon: Trash2, variant: "ghost" },
{ title: "Archive", label: "", icon: Archive, variant: "ghost" },
{ title: "Social", label: "972", icon: Users2, variant: "ghost" },
{ title: "Updates", label: "342", icon: AlertCircle, variant: "ghost" },
{ title: "Forums", label: "128", icon: MessagesSquare, variant: "ghost" },
{ title: "Shopping", label: "8", icon: ShoppingCart, variant: "ghost" },
{ title: "Promotions", label: "21", icon: Archive, variant: "ghost" }
]
return (
{/* Left Sidebar */}
setIsCollapsed(true)}
onResize={() => setIsCollapsed(false)}
className={cn(isCollapsed && "min-w-[50px] transition-all duration-300 ease-in-out")}
>
{/* Middle Mail List */}
Inbox
All mail
Unread
!item.read)} />
{/* Right Mail Display */}
item.id === mail.selected) || null} />
)
}
function AccountSwitcher({ isCollapsed, accounts }: { isCollapsed: boolean, accounts: Account[] }) {
const [selectedAccount, setSelectedAccount] = React.useState(accounts[0].email)
return (
)
}
function Nav({ links, isCollapsed }: { links: NavLink[], isCollapsed: boolean }) {
return (
)
}
function MailList({ items }: { items: Mail[] }) {
const [mail, setMail] = useMail()
return (
{items.map((item) => (
))}
)
}
function MailDisplay({ mail }: { mail: Mail | null }) {
const today = new Date()
return (
Archive
Move to junk
Move to trash
Snooze until
Snooze
Reply
Reply all
Forward
Mark as unread
Star thread
Add label
Mute thread
{mail ? (
{mail.name.split(" ").map((chunk) => chunk[0]).join("")}
{mail.name}
{mail.subject}
Reply-To: {mail.email}
{mail.date && (
{format(new Date(mail.date), "PPpp")}
)}
{mail.text}
) : (
No message selected
)}
)
}
function getBadgeVariantFromLabel(label: string) {
if (["work"].includes(label.toLowerCase())) return "default"
if (["personal"].includes(label.toLowerCase())) return "outline"
return "secondary"
}
export default function MailPage() {
const layout = [20, 32, 48]; //cookies().get("react-resizable-panels:layout:mail")
const collapsed = false; //cookies().get("react-resizable-panels:collapsed")
const defaultLayout = layout// ? JSON.parse(layout.value) : undefined
const defaultCollapsed = collapsed //? JSON.parse(collapsed.value) : undefined
// Drive-specific keyboard shortcuts
// XTreeGold classic shortcut layout - two rows
// XTree/NC-style: only unique, non-browser, non-reserved keys for file ops
// No F1-F12, Ctrl+F, Ctrl+T, Ctrl+W, Ctrl+N, Ctrl+R, Ctrl+P, etc.
// Use Q, W, E, R, T, Y, U, I, O, P, A, S, D, G, H, J, K, L, Z, X, C, V, B, M with Ctrl/Shift if needed
const shortcuts = [
// File operations row (unique qkeys)
[
{ key: 'Q', label: 'Rename', action: () => console.log('Rename') },
{ key: 'W', label: 'View', action: () => console.log('View') },
{ key: 'E', label: 'Edit', action: () => console.log('Edit') },
{ key: 'R', label: 'Move', action: () => console.log('Move') },
{ key: 'T', label: 'MkDir', action: () => console.log('Make Directory') },
{ key: 'Y', label: 'Delete', action: () => console.log('Delete') },
{ key: 'U', label: 'Copy', action: () => console.log('Copy') },
{ key: 'I', label: 'Cut', action: () => console.log('Cut') },
{ key: 'O', label: 'Paste', action: () => console.log('Paste') },
{ key: 'P', label: 'Duplicate', action: () => console.log('Duplicate') },
],
// Navigation/info row (unique qkeys)
[
{ key: 'A', label: 'Select', action: () => console.log('Select') },
{ key: 'S', label: 'Select All', action: () => console.log('Select All') },
{ key: 'D', label: 'Deselect', action: () => console.log('Deselect') },
{ key: 'G', label: 'Details', action: () => console.log('Details') },
{ key: 'H', label: 'History', action: () => console.log('History') },
{ key: 'J', label: 'Share', action: () => console.log('Share') },
{ key: 'K', label: 'Star', action: () => console.log('Star') },
{ key: 'L', label: 'Download', action: () => console.log('Download') },
{ key: 'Z', label: 'Upload', action: () => console.log('Upload') },
{ key: 'X', label: 'Refresh', action: () => console.log('Refresh') },
]
];
return (
<>
{/* Footer with Status Bar */}
>
)
}