// app/admin/categories/page.tsx

'use client';

import { useState } from 'react';
import {
  Tag,
  Plus,
  Edit,
  Trash2,
  CheckCircle,
  XCircle,
  Search,
  Filter,
  X,
  Save,
  Eye,
  ChevronLeft,
  ChevronRight,
  Users,
  Briefcase,
  Clock,
  TrendingUp,
} from 'lucide-react';

// Types
interface ServiceCategory {
  id: string;
  name: string;
  key: string;
  description: string;
  icon: string;
  color: string;
  isActive: boolean;
  providerCount: number;
  jobCount: number;
  createdAt: string;
  displayOrder: number;
}

// Mock data
const mockCategories: ServiceCategory[] = [
  {
    id: '1',
    name: 'Personal Care',
    key: 'personal_care',
    description: 'Assistance with bathing, dressing, grooming, and daily living activities.',
    icon: 'Heart',
    color: 'emerald',
    isActive: true,
    providerCount: 156,
    jobCount: 89,
    createdAt: '2025-01-01',
    displayOrder: 1,
  },
  {
    id: '2',
    name: 'Companionship',
    key: 'companionship',
    description: 'Social interaction, conversation, and emotional support for seniors.',
    icon: 'Users',
    color: 'blue',
    isActive: true,
    providerCount: 142,
    jobCount: 76,
    createdAt: '2025-01-01',
    displayOrder: 2,
  },
  {
    id: '3',
    name: 'Memory Care',
    key: 'memory_care',
    description: 'Specialized care for Alzheimer\'s and dementia patients.',
    icon: 'Brain',
    color: 'purple',
    isActive: true,
    providerCount: 98,
    jobCount: 54,
    createdAt: '2025-01-01',
    displayOrder: 3,
  },
  {
    id: '4',
    name: 'Respite Care',
    key: 'respite_care',
    description: 'Temporary relief for family caregivers.',
    icon: 'Clock',
    color: 'amber',
    isActive: true,
    providerCount: 87,
    jobCount: 42,
    createdAt: '2025-01-01',
    displayOrder: 4,
  },
  {
    id: '5',
    name: 'Medication Reminders',
    key: 'medication_reminders',
    description: 'Timely medication prompts and management support.',
    icon: 'Pill',
    color: 'rose',
    isActive: true,
    providerCount: 112,
    jobCount: 68,
    createdAt: '2025-01-01',
    displayOrder: 5,
  },
  {
    id: '6',
    name: 'Transportation',
    key: 'transportation',
    description: 'Safe transport to appointments, errands, and social outings.',
    icon: 'Car',
    color: 'cyan',
    isActive: true,
    providerCount: 76,
    jobCount: 45,
    createdAt: '2025-01-01',
    displayOrder: 6,
  },
  {
    id: '7',
    name: 'Meal Preparation',
    key: 'meal_preparation',
    description: 'Nutritious meal planning and cooking services.',
    icon: 'Utensils',
    color: 'orange',
    isActive: true,
    providerCount: 94,
    jobCount: 52,
    createdAt: '2025-01-01',
    displayOrder: 7,
  },
  {
    id: '8',
    name: '24/7 Support',
    key: '24_7_support',
    description: 'Round-the-clock care and monitoring services.',
    icon: 'Clock',
    color: 'indigo',
    isActive: false,
    providerCount: 34,
    jobCount: 18,
    createdAt: '2025-01-15',
    displayOrder: 8,
  },
];

const iconOptions = [
  { value: 'Heart', label: 'Heart' },
  { value: 'Users', label: 'Users' },
  { value: 'Brain', label: 'Brain' },
  { value: 'Clock', label: 'Clock' },
  { value: 'Pill', label: 'Pill' },
  { value: 'Car', label: 'Car' },
  { value: 'Utensils', label: 'Utensils' },
  { value: 'Shield', label: 'Shield' },
  { value: 'Star', label: 'Star' },
  { value: 'Award', label: 'Award' },
];

const colorOptions = [
  { value: 'emerald', label: 'Emerald', bgClass: 'bg-emerald-100', textClass: 'text-emerald-700' },
  { value: 'blue', label: 'Blue', bgClass: 'bg-blue-100', textClass: 'text-blue-700' },
  { value: 'purple', label: 'Purple', bgClass: 'bg-purple-100', textClass: 'text-purple-700' },
  { value: 'amber', label: 'Amber', bgClass: 'bg-amber-100', textClass: 'text-amber-700' },
  { value: 'rose', label: 'Rose', bgClass: 'bg-rose-100', textClass: 'text-rose-700' },
  { value: 'cyan', label: 'Cyan', bgClass: 'bg-cyan-100', textClass: 'text-cyan-700' },
  { value: 'orange', label: 'Orange', bgClass: 'bg-orange-100', textClass: 'text-orange-700' },
  { value: 'indigo', label: 'Indigo', bgClass: 'bg-indigo-100', textClass: 'text-indigo-700' },
];

export default function ServiceCategoriesPage() {
  const [categories, setCategories] = useState<ServiceCategory[]>(mockCategories);
  const [searchTerm, setSearchTerm] = useState('');
  const [statusFilter, setStatusFilter] = useState('all');
  const [currentPage, setCurrentPage] = useState(1);
  const [showAddModal, setShowAddModal] = useState(false);
  const [showEditModal, setShowEditModal] = useState(false);
  const [showDeleteModal, setShowDeleteModal] = useState(false);
  const [selectedCategory, setSelectedCategory] = useState<ServiceCategory | null>(null);
  const [editingCategory, setEditingCategory] = useState<Partial<ServiceCategory>>({});

  const itemsPerPage = 10;

  const filteredCategories = categories.filter((category) => {
    const matchesSearch = category.name.toLowerCase().includes(searchTerm.toLowerCase()) ||
      category.description.toLowerCase().includes(searchTerm.toLowerCase());
    const matchesStatus = statusFilter === 'all' ||
      (statusFilter === 'active' && category.isActive) ||
      (statusFilter === 'inactive' && !category.isActive);
    return matchesSearch && matchesStatus;
  });

  const totalPages = Math.ceil(filteredCategories.length / itemsPerPage);
  const paginatedCategories = filteredCategories.slice(
    (currentPage - 1) * itemsPerPage,
    currentPage * itemsPerPage
  );

  // Statistics
  const stats = {
    total: categories.length,
    active: categories.filter(c => c.isActive).length,
    totalProviders: categories.reduce((sum, c) => sum + c.providerCount, 0),
    totalJobs: categories.reduce((sum, c) => sum + c.jobCount, 0),
  };

  const handleAddCategory = () => {
    setEditingCategory({
      name: '',
      key: '',
      description: '',
      icon: 'Heart',
      color: 'emerald',
      isActive: true,
      displayOrder: categories.length + 1,
    });
    setShowAddModal(true);
  };

  const handleEditCategory = (category: ServiceCategory) => {
    setEditingCategory(category);
    setShowEditModal(true);
  };

  const handleDeleteCategory = (category: ServiceCategory) => {
    setSelectedCategory(category);
    setShowDeleteModal(true);
  };

  const handleToggleActive = (categoryId: string) => {
    setCategories(categories.map(cat =>
      cat.id === categoryId ? { ...cat, isActive: !cat.isActive } : cat
    ));
  };

  const handleSaveCategory = () => {
    if (showAddModal) {
      const newCategory: ServiceCategory = {
        id: Date.now().toString(),
        name: editingCategory.name || '',
        key: editingCategory.key || '',
        description: editingCategory.description || '',
        icon: editingCategory.icon || 'Heart',
        color: editingCategory.color || 'emerald',
        isActive: editingCategory.isActive || false,
        providerCount: 0,
        jobCount: 0,
        createdAt: new Date().toISOString().split('T')[0],
        displayOrder: editingCategory.displayOrder || categories.length + 1,
      };
      setCategories([...categories, newCategory]);
    } else if (showEditModal && selectedCategory) {
      setCategories(categories.map(cat =>
        cat.id === selectedCategory.id
          ? { ...cat, ...editingCategory }
          : cat
      ));
    }
    setShowAddModal(false);
    setShowEditModal(false);
    setSelectedCategory(null);
  };

  const confirmDelete = () => {
    if (selectedCategory) {
      setCategories(categories.filter(cat => cat.id !== selectedCategory.id));
      setShowDeleteModal(false);
      setSelectedCategory(null);
    }
  };

  const getColorClasses = (color: string) => {
    const colors: Record<string, { bg: string; text: string; light: string }> = {
      emerald: { bg: 'bg-emerald-100', text: 'text-emerald-700', light: 'bg-emerald-50' },
      blue: { bg: 'bg-blue-100', text: 'text-blue-700', light: 'bg-blue-50' },
      purple: { bg: 'bg-purple-100', text: 'text-purple-700', light: 'bg-purple-50' },
      amber: { bg: 'bg-amber-100', text: 'text-amber-700', light: 'bg-amber-50' },
      rose: { bg: 'bg-rose-100', text: 'text-rose-700', light: 'bg-rose-50' },
      cyan: { bg: 'bg-cyan-100', text: 'text-cyan-700', light: 'bg-cyan-50' },
      orange: { bg: 'bg-orange-100', text: 'text-orange-700', light: 'bg-orange-50' },
      indigo: { bg: 'bg-indigo-100', text: 'text-indigo-700', light: 'bg-indigo-50' },
    };
    return colors[color] || colors.emerald;
  };

  return (
    <div className="space-y-6">
      {/* Page Header */}
      <div className="flex items-center justify-between">
        <div>
          <h1 className="text-2xl font-bold text-gray-900">Service Categories</h1>
          <p className="text-gray-500 mt-1">Manage care service categories for provider registration</p>
        </div>
        <button
          onClick={handleAddCategory}
          className="flex items-center gap-2 px-4 py-2 bg-emerald-600 text-white rounded-lg hover:bg-emerald-700 transition-colors"
        >
          <Plus className="w-4 h-4" />
          Add Category
        </button>
      </div>

      {/* Stats Cards */}
      <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-5">
        <div className="bg-white rounded-xl p-5 shadow-sm border border-gray-100">
          <div className="flex items-center justify-between">
            <div className="w-12 h-12 bg-emerald-100 rounded-xl flex items-center justify-center">
              <Tag className="w-6 h-6 text-emerald-600" />
            </div>
            <span className="text-2xl font-bold text-gray-900">{stats.total}</span>
          </div>
          <p className="text-sm text-gray-500 mt-2">Total Categories</p>
        </div>
        <div className="bg-white rounded-xl p-5 shadow-sm border border-gray-100">
          <div className="flex items-center justify-between">
            <div className="w-12 h-12 bg-green-100 rounded-xl flex items-center justify-center">
              <CheckCircle className="w-6 h-6 text-green-600" />
            </div>
            <span className="text-2xl font-bold text-gray-900">{stats.active}</span>
          </div>
          <p className="text-sm text-gray-500 mt-2">Active Categories</p>
        </div>
        <div className="bg-white rounded-xl p-5 shadow-sm border border-gray-100">
          <div className="flex items-center justify-between">
            <div className="w-12 h-12 bg-blue-100 rounded-xl flex items-center justify-center">
              <Users className="w-6 h-6 text-blue-600" />
            </div>
            <span className="text-2xl font-bold text-gray-900">{stats.totalProviders}</span>
          </div>
          <p className="text-sm text-gray-500 mt-2">Total Providers</p>
        </div>
        <div className="bg-white rounded-xl p-5 shadow-sm border border-gray-100">
          <div className="flex items-center justify-between">
            <div className="w-12 h-12 bg-purple-100 rounded-xl flex items-center justify-center">
              <Briefcase className="w-6 h-6 text-purple-600" />
            </div>
            <span className="text-2xl font-bold text-gray-900">{stats.totalJobs}</span>
          </div>
          <p className="text-sm text-gray-500 mt-2">Total Jobs</p>
        </div>
      </div>

      {/* Filters Bar */}
      <div className="bg-white rounded-xl p-4 shadow-sm border border-gray-100">
        <div className="flex flex-col sm:flex-row gap-4">
          <div className="flex-1 relative">
            <Search className="absolute left-3 top-1/2 -translate-y-1/2 w-5 h-5 text-gray-400" />
            <input
              type="text"
              placeholder="Search categories..."
              value={searchTerm}
              onChange={(e) => setSearchTerm(e.target.value)}
              className="w-full pl-10 pr-4 py-2.5 border border-gray-200 rounded-lg focus:border-emerald-500 focus:ring-1 focus:ring-emerald-500 outline-none text-gray-900 placeholder:text-gray-400"
            />
          </div>
          <div className="flex items-center gap-2">
            <Filter className="w-5 h-5 text-gray-400" />
            <select
              value={statusFilter}
              onChange={(e) => setStatusFilter(e.target.value)}
              className="px-4 py-2.5 border border-gray-200 rounded-lg focus:border-emerald-500 outline-none text-gray-900"
            >
              <option value="all">All Status</option>
              <option value="active">Active</option>
              <option value="inactive">Inactive</option>
            </select>
          </div>
        </div>
      </div>

      {/* Categories Table */}
      <div className="bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden">
        <div className="overflow-x-auto">
          <table className="w-full">
            <thead className="bg-gray-50 border-b border-gray-100">
              <tr>
                <th className="text-left px-6 py-4 text-sm font-semibold text-gray-600">Order</th>
                <th className="text-left px-6 py-4 text-sm font-semibold text-gray-600">Category</th>
                <th className="text-left px-6 py-4 text-sm font-semibold text-gray-600">Key</th>
                <th className="text-left px-6 py-4 text-sm font-semibold text-gray-600">Description</th>
                <th className="text-left px-6 py-4 text-sm font-semibold text-gray-600">Providers</th>
                <th className="text-left px-6 py-4 text-sm font-semibold text-gray-600">Jobs</th>
                <th className="text-left px-6 py-4 text-sm font-semibold text-gray-600">Status</th>
                <th className="text-center px-6 py-4 text-sm font-semibold text-gray-600">Actions</th>
              </tr>
            </thead>
            <tbody className="divide-y divide-gray-100">
              {paginatedCategories.map((category) => {
                const colors = getColorClasses(category.color);
                return (
                  <tr key={category.id} className="hover:bg-gray-50 transition-colors">
                    <td className="px-6 py-4">
                      <span className="text-sm text-gray-600">{category.displayOrder}</span>
                    </td>
                    <td className="px-6 py-4">
                      <div className="flex items-center gap-3">
                        <div className={`w-10 h-10 ${colors.bg} rounded-xl flex items-center justify-center`}>
                          <Tag className={`w-5 h-5 ${colors.text}`} />
                        </div>
                        <div>
                          <p className="font-medium text-gray-900">{category.name}</p>
                          <p className="text-xs text-gray-500 capitalize">{category.color}</p>
                        </div>
                      </div>
                    </td>
                    <td className="px-6 py-4">
                      <code className="text-xs bg-gray-100 px-2 py-1 rounded">{category.key}</code>
                    </td>
                    <td className="px-6 py-4">
                      <p className="text-sm text-gray-600 max-w-xs truncate">{category.description}</p>
                    </td>
                    <td className="px-6 py-4">
                      <div className="flex items-center gap-2">
                        <Users className="w-4 h-4 text-gray-400" />
                        <span className="text-sm font-medium text-gray-900">{category.providerCount}</span>
                      </div>
                    </td>
                    <td className="px-6 py-4">
                      <div className="flex items-center gap-2">
                        <Briefcase className="w-4 h-4 text-gray-400" />
                        <span className="text-sm font-medium text-gray-900">{category.jobCount}</span>
                      </div>
                    </td>
                    <td className="px-6 py-4">
                      <span className={`px-2 py-1 rounded-full text-xs font-medium ${
                        category.isActive 
                          ? 'bg-emerald-100 text-emerald-700' 
                          : 'bg-gray-100 text-gray-700'
                      }`}>
                        {category.isActive ? 'Active' : 'Inactive'}
                      </span>
                    </td>
                    <td className="px-6 py-4">
                      <div className="flex items-center justify-center gap-2">
                        <button
                          onClick={() => handleToggleActive(category.id)}
                          className={`p-1.5 rounded-lg transition-colors ${
                            category.isActive 
                              ? 'hover:bg-red-50' 
                              : 'hover:bg-emerald-50'
                          }`}
                          title={category.isActive ? 'Deactivate' : 'Activate'}
                        >
                          {category.isActive ? (
                            <XCircle className="w-4 h-4 text-red-500" />
                          ) : (
                            <CheckCircle className="w-4 h-4 text-emerald-500" />
                          )}
                        </button>
                        <button
                          onClick={() => handleEditCategory(category)}
                          className="p-1.5 rounded-lg hover:bg-gray-100 transition-colors"
                          title="Edit"
                        >
                          <Edit className="w-4 h-4 text-gray-500" />
                        </button>
                        <button
                          onClick={() => handleDeleteCategory(category)}
                          className="p-1.5 rounded-lg hover:bg-red-50 transition-colors"
                          title="Delete"
                        >
                          <Trash2 className="w-4 h-4 text-red-500" />
                        </button>
                      </div>
                    </td>
                  </tr>
                );
              })}
            </tbody>
          </table>
        </div>

        {/* Pagination */}
        {totalPages > 1 && (
          <div className="flex items-center justify-between px-6 py-4 border-t border-gray-100">
            <p className="text-sm text-gray-500">
              Showing {(currentPage - 1) * itemsPerPage + 1} to {Math.min(currentPage * itemsPerPage, filteredCategories.length)} of {filteredCategories.length} results
            </p>
            <div className="flex gap-2">
              <button
                onClick={() => setCurrentPage((p) => Math.max(1, p - 1))}
                disabled={currentPage === 1}
                className="p-2 rounded-lg border border-gray-200 disabled:opacity-50 disabled:cursor-not-allowed hover:bg-gray-50"
              >
                <ChevronLeft className="w-4 h-4" />
              </button>
              {Array.from({ length: totalPages }, (_, i) => i + 1).map((page) => (
                <button
                  key={page}
                  onClick={() => setCurrentPage(page)}
                  className={`px-3 py-1 rounded-lg ${
                    currentPage === page
                      ? 'bg-emerald-600 text-white'
                      : 'border border-gray-200 hover:bg-gray-50 text-gray-700'
                  }`}
                >
                  {page}
                </button>
              ))}
              <button
                onClick={() => setCurrentPage((p) => Math.min(totalPages, p + 1))}
                disabled={currentPage === totalPages}
                className="p-2 rounded-lg border border-gray-200 disabled:opacity-50 disabled:cursor-not-allowed hover:bg-gray-50"
              >
                <ChevronRight className="w-4 h-4" />
              </button>
            </div>
          </div>
        )}
      </div>

      {/* Add/Edit Category Modal */}
      {(showAddModal || showEditModal) && (
        <div className="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4">
          <div className="bg-white rounded-2xl max-w-2xl w-full max-h-[90vh] overflow-y-auto">
            <div className="sticky top-0 bg-white border-b border-gray-100 px-6 py-4 flex items-center justify-between">
              <h2 className="text-xl font-bold text-gray-900">
                {showAddModal ? 'Add New Category' : 'Edit Category'}
              </h2>
              <button
                onClick={() => {
                  setShowAddModal(false);
                  setShowEditModal(false);
                }}
                className="p-2 rounded-lg hover:bg-gray-100"
              >
                <X className="w-5 h-5" />
              </button>
            </div>
            <div className="p-6 space-y-6">
              <div className="grid grid-cols-2 gap-4">
                <div>
                  <label className="block text-sm font-medium text-gray-700 mb-1">
                    Category Name *
                  </label>
                  <input
                    type="text"
                    value={editingCategory.name || ''}
                    onChange={(e) => setEditingCategory({ ...editingCategory, name: e.target.value })}
                    className="w-full px-4 py-2.5 border border-gray-200 rounded-lg focus:border-emerald-500 focus:ring-1 focus:ring-emerald-500 outline-none text-gray-900"
                    placeholder="e.g., Personal Care"
                  />
                </div>
                <div>
                  <label className="block text-sm font-medium text-gray-700 mb-1">
                    Key *
                  </label>
                  <input
                    type="text"
                    value={editingCategory.key || ''}
                    onChange={(e) => setEditingCategory({ ...editingCategory, key: e.target.value.toLowerCase().replace(/\s/g, '_') })}
                    className="w-full px-4 py-2.5 border border-gray-200 rounded-lg focus:border-emerald-500 focus:ring-1 focus:ring-emerald-500 outline-none text-gray-900"
                    placeholder="e.g., personal_care"
                  />
                </div>
              </div>

              <div>
                <label className="block text-sm font-medium text-gray-700 mb-1">
                  Description *
                </label>
                <textarea
                  value={editingCategory.description || ''}
                  onChange={(e) => setEditingCategory({ ...editingCategory, description: e.target.value })}
                  rows={3}
                  className="w-full px-4 py-2.5 border border-gray-200 rounded-lg focus:border-emerald-500 focus:ring-1 focus:ring-emerald-500 outline-none text-gray-900 resize-none"
                  placeholder="Describe this service category..."
                />
              </div>

              <div className="grid grid-cols-2 gap-4">
                <div>
                  <label className="block text-sm font-medium text-gray-700 mb-1">
                    Icon
                  </label>
                  <select
                    value={editingCategory.icon || 'Heart'}
                    onChange={(e) => setEditingCategory({ ...editingCategory, icon: e.target.value })}
                    className="w-full px-4 py-2.5 border border-gray-200 rounded-lg focus:border-emerald-500 outline-none text-gray-900"
                  >
                    {iconOptions.map((icon) => (
                      <option key={icon.value} value={icon.value}>{icon.label}</option>
                    ))}
                  </select>
                </div>
                <div>
                  <label className="block text-sm font-medium text-gray-700 mb-1">
                    Color
                  </label>
                  <select
                    value={editingCategory.color || 'emerald'}
                    onChange={(e) => setEditingCategory({ ...editingCategory, color: e.target.value })}
                    className="w-full px-4 py-2.5 border border-gray-200 rounded-lg focus:border-emerald-500 outline-none text-gray-900"
                  >
                    {colorOptions.map((color) => (
                      <option key={color.value} value={color.value}>{color.label}</option>
                    ))}
                  </select>
                </div>
              </div>

              <div className="grid grid-cols-2 gap-4">
                <div>
                  <label className="block text-sm font-medium text-gray-700 mb-1">
                    Display Order
                  </label>
                  <input
                    type="number"
                    value={editingCategory.displayOrder || 0}
                    onChange={(e) => setEditingCategory({ ...editingCategory, displayOrder: parseInt(e.target.value) })}
                    className="w-full px-4 py-2.5 border border-gray-200 rounded-lg focus:border-emerald-500 focus:ring-1 focus:ring-emerald-500 outline-none text-gray-900"
                    placeholder="1"
                  />
                </div>
                <div className="flex items-end">
                  <label className="flex items-center gap-2">
                    <input
                      type="checkbox"
                      checked={editingCategory.isActive || false}
                      onChange={(e) => setEditingCategory({ ...editingCategory, isActive: e.target.checked })}
                      className="w-4 h-4 rounded border-gray-300 text-emerald-600 focus:ring-emerald-500"
                    />
                    <span className="text-sm text-gray-700">Active</span>
                  </label>
                </div>
              </div>

              {/* Preview */}
              <div className="border-t border-gray-100 pt-4">
                <p className="text-sm font-medium text-gray-700 mb-3">Preview</p>
                <div className={`inline-flex items-center gap-2 px-4 py-2 rounded-full ${getColorClasses(editingCategory.color || 'emerald').bg}`}>
                  <Tag className={`w-4 h-4 ${getColorClasses(editingCategory.color || 'emerald').text}`} />
                  <span className={`text-sm font-medium ${getColorClasses(editingCategory.color || 'emerald').text}`}>
                    {editingCategory.name || 'Category Name'}
                  </span>
                </div>
              </div>

              <div className="flex gap-3 pt-4 border-t border-gray-100">
                <button
                  onClick={() => {
                    setShowAddModal(false);
                    setShowEditModal(false);
                  }}
                  className="flex-1 px-4 py-2 border border-gray-200 rounded-lg font-medium hover:bg-gray-50"
                >
                  Cancel
                </button>
                <button
                  onClick={handleSaveCategory}
                  className="flex-1 px-4 py-2 bg-emerald-600 text-white rounded-lg font-medium hover:bg-emerald-700 flex items-center justify-center gap-2"
                >
                  <Save className="w-4 h-4" />
                  Save Category
                </button>
              </div>
            </div>
          </div>
        </div>
      )}

      {/* Delete Confirmation Modal */}
      {showDeleteModal && selectedCategory && (
        <div className="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4">
          <div className="bg-white rounded-2xl max-w-md w-full p-6">
            <div className="text-center">
              <div className="w-16 h-16 bg-red-100 rounded-full flex items-center justify-center mx-auto mb-4">
                <Trash2 className="w-8 h-8 text-red-600" />
              </div>
              <h3 className="text-xl font-bold text-gray-900 mb-2">Delete Category</h3>
              <p className="text-gray-500 mb-6">
                Are you sure you want to delete <span className="font-semibold">{selectedCategory.name}</span>?
                This action cannot be undone.
              </p>
              <div className="flex gap-3">
                <button
                  onClick={() => setShowDeleteModal(false)}
                  className="flex-1 px-4 py-2 border border-gray-200 rounded-lg font-medium hover:bg-gray-50"
                >
                  Cancel
                </button>
                <button
                  onClick={confirmDelete}
                  className="flex-1 px-4 py-2 bg-red-600 text-white rounded-lg font-medium hover:bg-red-700"
                >
                  Delete
                </button>
              </div>
            </div>
          </div>
        </div>
      )}
    </div>
  );
}