import React from 'react';
import { Outlet } from 'react-router-dom';
import { SecondaryNavigation } from '../navigation/SecondaryNavigation';
import { Breadcrumbs } from '../navigation/Breadcrumbs';
import { useBakeryType } from '../../hooks/useBakeryType';

const OperationsLayout: React.FC = () => {
  const { bakeryType } = useBakeryType();

  // Define navigation items based on bakery type
  const getNavigationItems = () => {
    const baseItems = [
      {
        id: 'production',
        label: bakeryType === 'individual' ? 'Producción' : 'Distribución',
        href: '/app/operations/production',
        icon: 'ChefHat',
        children: bakeryType === 'individual' ? [
          { id: 'schedule', label: 'Programación', href: '/app/operations/production/schedule' },
          { id: 'active-batches', label: 'Lotes Activos', href: '/app/operations/production/active-batches' },
          { id: 'equipment', label: 'Equipamiento', href: '/app/operations/production/equipment' }
        ] : [
          { id: 'schedule', label: 'Distribución', href: '/app/operations/production/schedule' },
          { id: 'active-batches', label: 'Asignaciones', href: '/app/operations/production/active-batches' },
          { id: 'equipment', label: 'Logística', href: '/app/operations/production/equipment' }
        ]
      },
      {
        id: 'orders',
        label: 'Pedidos',
        href: '/app/operations/orders',
        icon: 'Package',
        children: [
          { id: 'incoming', label: bakeryType === 'individual' ? 'Entrantes' : 'Puntos de Venta', href: '/app/operations/orders/incoming' },
          { id: 'in-progress', label: 'En Proceso', href: '/app/operations/orders/in-progress' },
          { id: 'supplier-orders', label: bakeryType === 'individual' ? 'Proveedores' : 'Productos', href: '/app/operations/orders/supplier-orders' }
        ]
      },
      {
        id: 'inventory',
        label: 'Inventario',
        href: '/app/operations/inventory',
        icon: 'Warehouse',
        children: [
          { id: 'stock-levels', label: bakeryType === 'individual' ? 'Ingredientes' : 'Productos', href: '/app/operations/inventory/stock-levels' },
          { id: 'movements', label: bakeryType === 'individual' ? 'Uso' : 'Distribución', href: '/app/operations/inventory/movements' },
          { id: 'alerts', label: bakeryType === 'individual' ? 'Caducidad' : 'Retrasos', href: '/app/operations/inventory/alerts' }
        ]
      },
      {
        id: 'sales',
        label: 'Ventas',
        href: '/app/operations/sales',
        icon: 'ShoppingCart',
        children: [
          { id: 'daily-sales', label: 'Ventas Diarias', href: '/app/operations/sales/daily-sales' },
          { id: 'customer-orders', label: bakeryType === 'individual' ? 'Pedidos Cliente' : 'Pedidos Punto', href: '/app/operations/sales/customer-orders' },
          { id: 'pos-integration', label: bakeryType === 'individual' ? 'TPV' : 'Multi-TPV', href: '/app/operations/sales/pos-integration' }
        ]
      }
    ];

    // Add recipes for individual bakeries, hide for central
    if (bakeryType === 'individual') {
      baseItems.push({
        id: 'recipes',
        label: 'Recetas',
        href: '/app/operations/recipes',
        icon: 'BookOpen',
        children: [
          { id: 'active-recipes', label: 'Recetas Activas', href: '/app/operations/recipes/active-recipes' },
          { id: 'development', label: 'Desarrollo', href: '/app/operations/recipes/development' },
          { id: 'costing', label: 'Costeo', href: '/app/operations/recipes/costing' }
        ]
      });
    }

    return baseItems;
  };

  return (
    <div className="flex flex-col h-full">
      <div className="bg-white border-b border-gray-200">
        <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
          <Breadcrumbs />
          <SecondaryNavigation items={getNavigationItems()} />
        </div>
      </div>
      
      <div className="flex-1 bg-gray-50">
        <div className="max-w-7xl mx-auto">
          <Outlet />
        </div>
      </div>
    </div>
  );
};

export default OperationsLayout;