/**
 * Vendor Template
 * 
 * Purpose: Template for vendor-related requests (purchase orders, invoices, etc.)
 * Used by: Vendors, procurement team
 */

import {
  ClipboardList,
  TrendingUp,
  FileText,
  Activity,
  MessageSquare,
  Package,
} from 'lucide-react';
import { RequestDetailTemplate } from '../types/template.types';
import { OverviewTab } from '../components/tabs/OverviewTab';
import { WorkflowTab } from '../components/tabs/WorkflowTab';
import { DocumentsTab } from '../components/tabs/DocumentsTab';
import { ActivityTab } from '../components/tabs/ActivityTab';
import { WorkNotesTab } from '../components/tabs/WorkNotesTab';

/**
 * Vendor Template Configuration
 */
export const vendorTemplate: RequestDetailTemplate = {
  id: 'vendor',
  name: 'Vendor Request',
  description: 'Template for vendor-related requests',

  // Tab configuration
  tabs: [
    {
      id: 'overview',
      label: 'Overview',
      icon: ClipboardList,
      component: OverviewTab,
      order: 1,
    },
    {
      id: 'workflow',
      label: 'Workflow',
      icon: TrendingUp,
      component: WorkflowTab,
      order: 2,
    },
    {
      id: 'documents',
      label: 'Documents',
      icon: FileText,
      component: DocumentsTab,
      order: 3,
    },
    {
      id: 'activity',
      label: 'Activity',
      icon: Activity,
      component: ActivityTab,
      order: 4,
    },
    {
      id: 'worknotes',
      label: 'Work Notes',
      icon: MessageSquare,
      component: WorkNotesTab,
      badge: (context) => context.unreadWorkNotes || null,
      order: 5,
    },
  ],

  defaultTab: 'overview',

  // Header configuration
  header: {
    showBackButton: true,
    showRefreshButton: true,
    showShareSummaryButton: false,
  },

  // Quick actions configuration
  quickActions: {
    enabled: true,
    customActions: [
      {
        id: 'track-shipment',
        label: 'Track Shipment',
        icon: Package,
        action: async (context) => {
          const { toast } = await import('sonner');
          toast.info('Shipment tracking feature coming soon');
        },
        visible: (context) => context.request?.type === 'purchase-order',
        variant: 'outline',
      },
    ],
  },

  // Layout configuration
  layout: {
    showQuickActionsSidebar: true,
    fullWidthTabs: ['worknotes'],
  },

  // Access control
  canAccess: (user, request) => {
    const allowedRoles = ['vendor', 'procurement', 'admin'];
    return allowedRoles.includes(user?.role) || user?.userId === request?.initiator?.userId;
  },
};

