"use client" import type React from "react" import { useState } from "react" import { Topbar } from "@/components/topbar" import { Card, CardContent, CardDescription, 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 { Plus, Search, Filter, MoreHorizontal, Eye, Edit, Trash2 } from "lucide-react" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" import { useTranslation } from "@/lib/i18n" type Deal = { id: string; dealName: string; client: string stage: "Lead" | "Qualified" | "Proposal" | "Negotiation" | "Closed Won" | "Closed Lost" value: number; probability: number; owner: string; ownerAvatar: string expectedClose: string; description: string; createdAt: string } const initialDeals: Deal[] = [ { id: "DEAL-001", dealName: "Enterprise Software License", client: "TechCorp Inc.", stage: "Negotiation", value: 45000, probability: 75, owner: "Jane Doe", ownerAvatar: "https://images.unsplash.com/photo-1494790108755-2616b612b786?w=150&h=150&fit=crop&crop=face", expectedClose: "2024-02-15", description: "Large enterprise software licensing deal for 500+ users", createdAt: "2023-12-01" }, { id: "DEAL-002", dealName: "Marketing Automation Setup", client: "StartupXYZ", stage: "Proposal", value: 12500, probability: 60, owner: "Mike Roberts", ownerAvatar: "https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?w=150&h=150&fit=crop&crop=face", expectedClose: "2024-01-30", description: "Complete marketing automation platform implementation", createdAt: "2023-12-15" }, { id: "DEAL-003", dealName: "Cloud Migration Project", client: "Global Solutions", stage: "Qualified", value: 78000, probability: 40, owner: "Sarah Johnson", ownerAvatar: "https://images.unsplash.com/photo-1438761681033-6461ffad8d80?w=150&h=150&fit=crop&crop=face", expectedClose: "2024-03-01", description: "Full cloud infrastructure migration and optimization", createdAt: "2023-11-20" }, { id: "DEAL-004", dealName: "CRM Implementation", client: "Retail Chain Co.", stage: "Closed Won", value: 25000, probability: 100, owner: "Alex Lee", ownerAvatar: "https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=150&h=150&fit=crop&crop=face", expectedClose: "2024-01-15", description: "Custom CRM implementation for retail operations", createdAt: "2023-10-15" }, ] const getStageColor = (stage: Deal["stage"]) => { const colors = { Lead: "bg-gray-100 text-gray-800", Qualified: "bg-blue-100 text-blue-800", Proposal: "bg-yellow-100 text-yellow-800", Negotiation: "bg-orange-100 text-orange-800", "Closed Won": "bg-green-100 text-green-800", "Closed Lost": "bg-red-100 text-red-800" } return colors[stage] } export default function DealsPage() { const { t } = useTranslation() const [deals, setDeals] = useState(initialDeals) const [searchTerm, setSearchTerm] = useState("") const [stageFilter, setStageFilter] = useState("all") const [isDialogOpen, setIsDialogOpen] = useState(false) const [editingDeal, setEditingDeal] = useState(null) const filteredDeals = deals.filter((deal) => { const matchesSearch = deal.dealName.toLowerCase().includes(searchTerm.toLowerCase()) || deal.client.toLowerCase().includes(searchTerm.toLowerCase()) const matchesStage = stageFilter === "all" || deal.stage === stageFilter return matchesSearch && matchesStage }) const handleAddDeal = (dealData: Partial) => { const newDeal: Deal = { id: `DEAL-${String(deals.length + 1).padStart(3, "0")}`, dealName: dealData.dealName || "", client: dealData.client || "", stage: dealData.stage || "Lead", value: dealData.value || 0, probability: dealData.probability || 0, owner: dealData.owner || "Current User", ownerAvatar: "https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?w=150&h=150&fit=crop&crop=face", expectedClose: dealData.expectedClose || "", description: dealData.description || "", createdAt: new Date().toISOString().split("T")[0], } setDeals([...deals, newDeal]); setIsDialogOpen(false) } const handleEditDeal = (dealData: Partial) => { if (editingDeal) { setDeals(deals.map((deal) => (deal.id === editingDeal.id ? { ...deal, ...dealData } : deal))) setEditingDeal(null); setIsDialogOpen(false) } } const handleDeleteDeal = (dealId: string) => { setDeals(deals.filter((deal) => deal.id !== dealId)) } return (

{t("deals.title")}

{t("deals.description")}

{ setIsDialogOpen(false); setEditingDeal(null) }} />
setSearchTerm(e.target.value)} />
{t("deals.gridView")} {t("deals.listView")}
{filteredDeals.map((deal) => (
{deal.dealName} {deal.client}
{t("deals.actions")} {t("deals.viewDetails")} { setEditingDeal(deal); setIsDialogOpen(true) }}> {t("deals.editDeal")} handleDeleteDeal(deal.id)}> {t("deals.deleteDeal")}
{deal.stage} {deal.probability}%
${deal.value.toLocaleString()}
{deal.owner.split(" ").map((n) => n[0]).join("")} {deal.owner}
{t("deals.expectedClose")} {new Date(deal.expectedClose).toLocaleDateString()}
))}
{filteredDeals.map((deal) => (

{deal.dealName}

{deal.client}

{deal.stage}
${deal.value.toLocaleString()}
{deal.owner.split(" ").map((n) => n[0]).join("")} {deal.owner}
{new Date(deal.expectedClose).toLocaleDateString()}
{t("deals.actions")} {t("deals.viewDetails")} { setEditingDeal(deal); setIsDialogOpen(true) }}> {t("deals.editDeal")} handleDeleteDeal(deal.id)}> {t("deals.deleteDeal")}
))}
) } function DealDialog({ deal, onSave, onCancel }: { deal: Deal | null; onSave: (data: Partial) => void; onCancel: () => void }) { const { t } = useTranslation() const [formData, setFormData] = useState({ dealName: deal?.dealName || "", client: deal?.client || "", stage: deal?.stage || "Lead", value: deal?.value || 0, probability: deal?.probability || 0, expectedClose: deal?.expectedClose || "", description: deal?.description || "", }) const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); onSave(formData) } return ( {deal ? t("deals.editTitle") : t("deals.addTitle")} {deal ? t("deals.editDesc") : t("deals.addDesc")}
setFormData({ ...formData, dealName: e.target.value })} required />
setFormData({ ...formData, client: e.target.value })} required />
setFormData({ ...formData, probability: Number(e.target.value) })} />
setFormData({ ...formData, value: Number(e.target.value) })} required />
setFormData({ ...formData, expectedClose: e.target.value })} required />