import { ArrowLeft, FileText, Calendar, User, Building2, CheckCircle2, Clock, AlertCircle, Upload, Download, Eye, ArrowRight, Shield, MessageSquare } from 'lucide-react'; import { Button } from '../ui/button'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '../ui/card'; import { Badge } from '../ui/badge'; import { Tabs, TabsContent, TabsList, TabsTrigger } from '../ui/tabs'; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '../ui/table'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from '../ui/dialog'; import { Textarea } from '../ui/textarea'; import { Label } from '../ui/label'; import { Input } from '../ui/input'; import { useState } from 'react'; import { User as UserType } from '../../lib/mock-data'; import { toast } from 'sonner'; import { mockConstitutionalChangeRequests } from './ConstitutionalChangePage'; interface ConstitutionalChangeDetailsProps { requestId: string; onBack: () => void; currentUser: UserType | null; onOpenWorknote?: (requestId: string, requestType: 'relocation' | 'constitutional-change' | 'fnf' | 'resignation' | 'termination', requestTitle: string) => void; } // Workflow stages as per the process flow const workflowStages = [ { id: 1, name: 'Request Created', key: 'created', role: 'Dealer' }, { id: 2, name: 'ASM Review', key: 'asm', role: 'ASM' }, { id: 3, name: 'RBM Review', key: 'rbm', role: 'RBM' }, { id: 4, name: 'DD ZM Review', key: 'dd-zm', role: 'DD-ZM' }, { id: 5, name: 'ZBH Review', key: 'zbh', role: 'ZBH' }, { id: 6, name: 'DD Lead Review', key: 'dd-lead', role: 'DD Lead' }, { id: 7, name: 'FDD Review', key: 'fdd', role: 'FDD' }, { id: 8, name: 'DD Head Review', key: 'dd-head', role: 'DD Head' }, { id: 9, name: 'NBH Review', key: 'nbh', role: 'NBH' }, { id: 10, name: 'Docs Collection by DD H.O', key: 'docs-collection', role: 'DD H.O' }, { id: 11, name: 'New Code Creation', key: 'code-creation', role: 'DD Admin' }, { id: 12, name: 'New LOA Issuance', key: 'loa-issuance', role: 'DD Admin' }, { id: 13, name: 'Closure of Request', key: 'closure', role: 'System' } ]; // Document requirements mapping (same as in ConstitutionalChangePage) const documentRequirements: Record = { 'Partnership': [1, 2, 3, 4, 8, 9, 10, 16], 'LLP': [1, 2, 3, 7, 8, 9, 10, 16], 'Pvt Ltd': [1, 2, 3, 5, 6, 7, 8, 10, 16], 'Proprietorship': [1, 2, 3, 10, 16] }; const documentNames: Record = { 1: 'GST', 2: 'Firm Pan Copy', 3: 'Self attested KYC\'s', 4: 'Partnership Agreement (Notarised)', 5: 'MOA (Applicable for Only Pvt.Ltd)', 6: 'AOA (Applicable for Only Pvt.Ltd)', 7: 'COI (Applicable for Only Pvt.Ltd & LLP)', 8: 'BPA - Business Purchase Agreement', 9: 'Firm Registration Certificate (Partnership)', 10: 'Cancelled Cheque', 11: 'LLP Agreement (Notarised)', 12: 'ZBH Approval', 13: 'NBH Approval', 14: 'RBM Approval', 15: 'DD-Lead Approval', 16: 'Declaration / Authorization Letter' }; // Mock uploaded documents const mockUploadedDocuments = [ { docNumber: 1, fileName: 'GST_Certificate.pdf', uploadedOn: '2025-12-15', uploadedBy: 'Dealer', status: 'Verified' }, { docNumber: 2, fileName: 'Firm_PAN.pdf', uploadedOn: '2025-12-15', uploadedBy: 'Dealer', status: 'Verified' }, { docNumber: 3, fileName: 'KYC_Documents.pdf', uploadedOn: '2025-12-15', uploadedBy: 'Dealer', status: 'Pending Verification' }, { docNumber: 4, fileName: 'Partnership_Agreement_Notarised.pdf', uploadedOn: '2025-12-16', uploadedBy: 'Dealer', status: 'Verified' }, ]; // Mock workflow history const mockWorkflowHistory = [ { stage: 'Request Created', actor: 'Amit Sharma (Dealer)', action: 'Created', date: '2025-12-15 10:30 AM', comments: 'Submitted constitutional change request from Proprietorship to Partnership', status: 'Completed' }, { stage: 'ASM Review', actor: 'Rajesh Kumar (ASM)', action: 'Approved', date: '2025-12-16 02:15 PM', comments: 'Verified dealer credentials and approved for next stage', status: 'Completed' }, { stage: 'RBM Review', actor: 'Priya Sharma (RBM)', action: 'Under Review', date: '2025-12-17 09:00 AM', comments: 'Documents under verification', status: 'In Progress' }, ]; // Mock worknotes - Discussion platform for this request const initialWorknotes = [ { id: 1, user: 'Rajesh Kumar', role: 'ASM', message: 'I have reviewed the partnership agreement. All partners have proper KYC documentation. Looks good to proceed.', timestamp: '2025-12-16 11:30 AM', avatar: 'RK' }, { id: 2, user: 'Priya Sharma', role: 'RBM', message: 'Can we get clarification on the profit sharing ratio mentioned in the partnership deed? It seems different from what was discussed.', timestamp: '2025-12-17 02:45 PM', avatar: 'PS' }, { id: 3, user: 'Amit Sharma', role: 'Dealer', message: 'The profit sharing ratio is 60:40 as per the partnership deed. This was agreed upon by all partners and is correctly reflected in the document.', timestamp: '2025-12-17 04:15 PM', avatar: 'AS' }, { id: 4, user: 'Priya Sharma', role: 'RBM', message: 'Thank you for the clarification. I have verified the BPA and other statutory documents. Everything appears to be in order.', timestamp: '2025-12-18 10:00 AM', avatar: 'PS' } ]; const getTypeColor = (type: string) => { switch(type) { case 'Proprietorship': return 'bg-purple-100 text-purple-700 border-purple-300'; case 'Partnership': return 'bg-blue-100 text-blue-700 border-blue-300'; case 'LLP': return 'bg-indigo-100 text-indigo-700 border-indigo-300'; case 'Pvt Ltd': return 'bg-cyan-100 text-cyan-700 border-cyan-300'; default: return 'bg-slate-100 text-slate-700 border-slate-300'; } }; const getStatusColor = (status: string) => { if (status === 'Completed' || status === 'Verified') return 'bg-green-100 text-green-700 border-green-300'; if (status.includes('Review') || status.includes('Pending') || status === 'In Progress') return 'bg-yellow-100 text-yellow-700 border-yellow-300'; if (status.includes('Rejected')) return 'bg-red-100 text-red-700 border-red-300'; return 'bg-slate-100 text-slate-700 border-slate-300'; }; export function ConstitutionalChangeDetails({ requestId, onBack, currentUser, onOpenWorknote }: ConstitutionalChangeDetailsProps) { const [isActionDialogOpen, setIsActionDialogOpen] = useState(false); const [actionType, setActionType] = useState<'approve' | 'reject' | 'hold'>('approve'); const [comments, setComments] = useState(''); const [isUploadDialogOpen, setIsUploadDialogOpen] = useState(false); const [isWorknoteDialogOpen, setIsWorknoteDialogOpen] = useState(false); const [worknotes, setWorknotes] = useState(initialWorknotes); const [newWorknote, setNewWorknote] = useState(''); // Find the request const request = mockConstitutionalChangeRequests.find(r => r.id === requestId); if (!request) { return (

Request Not Found

The constitutional change request you're looking for doesn't exist.

); } // Get required documents for this request const requiredDocs = documentRequirements[request.targetType] || []; // Calculate current stage index const getCurrentStageIndex = () => { const stageMap: Record = { 'Dealer': 1, 'ASM': 2, 'RBM': 3, 'DD-ZM': 4, 'ZBH': 5, 'DD Lead': 6, 'FDD': 7, 'DD Head': 8, 'NBH': 9, 'DD H.O': 10, 'Closed': 13 }; return stageMap[request.currentStage] || 1; }; const currentStageIndex = getCurrentStageIndex(); const handleAction = (type: 'approve' | 'reject' | 'hold') => { setActionType(type); setIsActionDialogOpen(true); }; const handleSubmitAction = (e: React.FormEvent) => { e.preventDefault(); const actionText = actionType === 'approve' ? 'approved' : actionType === 'reject' ? 'rejected' : 'put on hold'; toast.success(`Request ${actionText} successfully`); setIsActionDialogOpen(false); setComments(''); }; const handleUploadDocument = () => { toast.success('Document uploaded successfully'); setIsUploadDialogOpen(false); }; const handleAddWorknote = () => { if (newWorknote.trim()) { const newNote = { id: worknotes.length + 1, user: currentUser?.name || 'Anonymous', role: currentUser?.role || 'User', message: newWorknote, timestamp: new Date().toLocaleString(), avatar: currentUser?.name?.slice(0, 2).toUpperCase() || 'AN' }; setWorknotes([...worknotes, newNote]); setNewWorknote(''); toast.success('Worknote added successfully'); } }; return (
{/* Header */}

{request.id} - Constitutional Change Details

{request.dealerName} ({request.dealerCode})

{request.status}
{/* Request Overview */} Request Overview

Dealer Details

{request.dealerName}

{request.dealerCode}

{request.location}

Constitutional Change

{request.currentType} {request.targetType}

Request Information

Submitted: {request.submittedOn}

By: {request.submittedBy}

Current Stage: {request.currentStage}

Reason for Change

{request.reason}

{/* Main Content */}
Workflow Progress Documents History & Audit Trail
{/* Workflow Progress Tab */} {/* Progress Bar */}
Overall Progress {request.progressPercentage}%
{/* Workflow Stages */}
{workflowStages.map((stage, index) => { const isCompleted = index < currentStageIndex - 1; const isCurrent = index === currentStageIndex - 1; const isPending = index > currentStageIndex - 1; return (
{/* Status Icon */}
{isCompleted ? ( ) : isCurrent ? ( ) : ( )}
{index < workflowStages.length - 1 && (
)}
{/* Stage Info */}

{stage.name}

Responsible: {stage.role}

{isCompleted ? 'Completed' : isCurrent ? 'In Progress' : 'Pending'}
); })}
{/* Documents Tab */} Required for Process Existing Documents {/* Required Documents Sub-tab */}

Document Checklist

Upload Document Select the document type and upload the file
{requiredDocs.map((docNum) => { const uploaded = mockUploadedDocuments.find(d => d.docNumber === docNum); return (
{uploaded ? ( ) : ( )}

{documentNames[docNum]}

{uploaded && (

{uploaded.fileName}

)}
{uploaded ? ( {uploaded.status} ) : ( Not Uploaded )}
); })}
{/* Existing Documents Sub-tab */} {mockUploadedDocuments.length > 0 ? (

All Uploaded Documents

Document Name File Name Uploaded On Uploaded By Status Actions {mockUploadedDocuments.map((doc) => ( {documentNames[doc.docNumber]} {doc.fileName} {doc.uploadedOn} {doc.uploadedBy} {doc.status}
))}
) : (
No documents uploaded yet
)}
{/* History Tab */}
{mockWorkflowHistory.map((entry, index) => (
{entry.status === 'Completed' ? ( ) : entry.status === 'In Progress' ? ( ) : ( )}

{entry.stage}

{entry.actor}

{entry.action}

{entry.comments}

{entry.date}

))}
{/* Right Sidebar - Actions */}
{/* Current Status Card */} Current Status

Current Stage

{request.currentStage}

{/* Actions Card */} Actions
{/* Action Dialog */} {actionType === 'approve' ? 'Approve Request' : actionType === 'reject' ? 'Reject Request' : 'Put Request on Hold'} Please provide comments for this action. This will be recorded in the audit trail.