"use client" import type React from "react" import { useState } from "react" import { Topbar } from "@/components/topbar" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Badge } from "@/components/ui/badge" import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar" import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select" import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog" import { Label } from "@/components/ui/label" import { Textarea } from "@/components/ui/textarea" import { Checkbox } from "@/components/ui/checkbox" import { Plus, Search, Filter, MoreHorizontal, Eye, Edit, Trash2, Calendar, User } from "lucide-react" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" import { useTranslation } from "@/lib/i18n" type Task = { id: string; title: string; description: string status: "Todo" | "In Progress" | "Completed" | "Overdue" priority: "Low" | "Medium" | "High" | "Urgent" assignee: string; assigneeAvatar: string; dueDate: string; createdAt: string relatedTo: string; relatedType: "Deal" | "Contact" | "General" } const initialTasks: Task[] = [ { id: "TASK-001", title: "Follow up with TechCorp Inc.", description: "Schedule demo call for enterprise software license", status: "Todo", priority: "High", assignee: "Jane Doe", assigneeAvatar: "https://images.unsplash.com/photo-1494790108755-2616b612b786?w=150&h=150&fit=crop&crop=face", dueDate: "2024-01-20", createdAt: "2024-01-15", relatedTo: "Enterprise Software License", relatedType: "Deal" }, { id: "TASK-002", title: "Prepare proposal for StartupXYZ", description: "Create detailed proposal for marketing automation setup", status: "In Progress", priority: "Medium", assignee: "Mike Roberts", assigneeAvatar: "https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?w=150&h=150&fit=crop&crop=face", dueDate: "2024-01-18", createdAt: "2024-01-14", relatedTo: "Marketing Automation Setup", relatedType: "Deal" }, { id: "TASK-003", title: "Send contract to Global Solutions", description: "Finalize and send signed contract for cloud migration project", status: "Completed", priority: "High", assignee: "Sarah Johnson", assigneeAvatar: "https://images.unsplash.com/photo-1438761681033-6461ffad8d80?w=150&h=150&fit=crop&crop=face", dueDate: "2024-01-16", createdAt: "2024-01-12", relatedTo: "Cloud Migration Project", relatedType: "Deal" }, { id: "TASK-004", title: "Update CRM data", description: "Clean up and update contact information in CRM system", status: "Overdue", priority: "Low", assignee: "Alex Lee", assigneeAvatar: "https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=150&h=150&fit=crop&crop=face", dueDate: "2024-01-10", createdAt: "2024-01-08", relatedTo: "General Maintenance", relatedType: "General" }, ] const getStatusColor = (status: Task["status"]) => { const colors = { Todo: "bg-gray-100 text-gray-800", "In Progress": "bg-blue-100 text-blue-800", Completed: "bg-green-100 text-green-800", Overdue: "bg-red-100 text-red-800" } return colors[status] } const getPriorityColor = (priority: Task["priority"]) => { const colors = { Low: "bg-green-100 text-green-800", Medium: "bg-yellow-100 text-yellow-800", High: "bg-orange-100 text-orange-800", Urgent: "bg-red-100 text-red-800" } return colors[priority] } const statusMap: Record = { Todo: "tasks.todo", "In Progress": "tasks.inProgress", Completed: "tasks.completed", Overdue: "tasks.overdue" } const priorityMap: Record = { Low: "tasks.low", Medium: "tasks.medium", High: "tasks.high", Urgent: "tasks.urgent" } export default function TasksPage() { const { t } = useTranslation() const [tasks, setTasks] = useState(initialTasks) const [searchTerm, setSearchTerm] = useState("") const [statusFilter, setStatusFilter] = useState("all") const [isDialogOpen, setIsDialogOpen] = useState(false) const [editingTask, setEditingTask] = useState(null) const filteredTasks = tasks.filter((task) => { const matchesSearch = task.title.toLowerCase().includes(searchTerm.toLowerCase()) || task.description.toLowerCase().includes(searchTerm.toLowerCase()) || task.relatedTo.toLowerCase().includes(searchTerm.toLowerCase()) const matchesStatus = statusFilter === "all" || task.status === statusFilter return matchesSearch && matchesStatus }) const handleAddTask = (taskData: Partial) => { const newTask: Task = { id: `TASK-${String(tasks.length + 1).padStart(3, "0")}`, title: taskData.title || "", description: taskData.description || "", status: taskData.status || "Todo", priority: taskData.priority || "Medium", assignee: taskData.assignee || "Current User", assigneeAvatar: "https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?w=150&h=150&fit=crop&crop=face", dueDate: taskData.dueDate || "", createdAt: new Date().toISOString().split("T")[0], relatedTo: taskData.relatedTo || "", relatedType: taskData.relatedType || "General", } setTasks([...tasks, newTask]); setIsDialogOpen(false) } const handleEditTask = (taskData: Partial) => { if (editingTask) { setTasks(tasks.map((task) => (task.id === editingTask.id ? { ...task, ...taskData } : task))); setEditingTask(null); setIsDialogOpen(false) } } const handleDeleteTask = (taskId: string) => { setTasks(tasks.filter((task) => task.id !== taskId)) } const handleToggleComplete = (taskId: string) => { setTasks(tasks.map((task) => task.id === taskId ? { ...task, status: task.status === "Completed" ? "Todo" : "Completed" } : task)) } return (

{t("tasks.title")}

{t("tasks.description")}

{ setIsDialogOpen(false); setEditingTask(null) }} />
setSearchTerm(e.target.value)} />
{t("tasks.listView")} {t("tasks.boardView")}
{filteredTasks.map((task) => (
handleToggleComplete(task.id)} />

{task.title}

{t(priorityMap[task.priority])} {t(statusMap[task.status])}

{task.description}

{t("tasks.due")} {new Date(task.dueDate).toLocaleDateString()}
{task.assignee.split(" ").map((n) => n[0]).join("")} {task.assignee}
{t("tasks.relatedTo")} {task.relatedTo}
{t("tasks.actions")} {t("tasks.viewDetails")} { setEditingTask(task); setIsDialogOpen(true) }}> {t("tasks.editTask")} handleDeleteTask(task.id)}> {t("tasks.deleteTask")}
))}
{(["Todo", "In Progress", "Completed", "Overdue"] as const).map((status) => ( {t(statusMap[status])} {filteredTasks.filter((task) => task.status === status).length} {filteredTasks.filter((task) => task.status === status).map((task) => (

{task.title}

{t(priorityMap[task.priority])}

{task.description}

{new Date(task.dueDate).toLocaleDateString()}
{task.assignee.split(" ").map((n) => n[0]).join("")}
))}
))}
) } function TaskDialog({ task, onSave, onCancel }: { task: Task | null; onSave: (data: Partial) => void; onCancel: () => void }) { const { t } = useTranslation() const [formData, setFormData] = useState({ title: task?.title || "", description: task?.description || "", status: task?.status || "Todo", priority: task?.priority || "Medium", assignee: task?.assignee || "", dueDate: task?.dueDate || "", relatedTo: task?.relatedTo || "", relatedType: task?.relatedType || "General", }) const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); onSave(formData) } return ( {task ? t("tasks.editTitle") : t("tasks.addTitle")} {task ? t("tasks.editDesc") : t("tasks.addDesc")}
setFormData({ ...formData, title: e.target.value })} required />