import { useState, useCallback } from 'react'; import { useParams, useNavigate } from 'react-router-dom'; import { Button } from '@components/atoms/Button'; import { useWarehouse, useLocations } from '../hooks'; import { WarehouseTypeBadge, LocationGrid, WarehouseLayout } from '../components'; import type { WarehouseLocation } from '../types'; type ViewMode = 'list' | 'layout'; export function WarehouseDetailPage() { const { id } = useParams<{ id: string }>(); const navigate = useNavigate(); const { warehouse, isLoading: loadingWarehouse, error: warehouseError } = useWarehouse(id ?? null); const { locations, isLoading: loadingLocations, deleteLocation, } = useLocations(id ?? null); const [viewMode, setViewMode] = useState('list'); const [selectedLocationId, setSelectedLocationId] = useState(); const handleBack = useCallback(() => { navigate('/warehouses'); }, [navigate]); const handleEdit = useCallback(() => { navigate(`/warehouses/${id}/edit`); }, [navigate, id]); const handleAddLocation = useCallback(() => { navigate(`/warehouses/${id}/locations/new`); }, [navigate, id]); const handleLocationClick = useCallback((location: WarehouseLocation) => { setSelectedLocationId(location.id); }, []); const handleLocationEdit = useCallback((location: WarehouseLocation) => { navigate(`/warehouses/${id}/locations/${location.id}/edit`); }, [navigate, id]); const handleLocationDelete = useCallback(async (location: WarehouseLocation) => { if (!confirm(`Esta seguro de eliminar la ubicacion "${location.name}"?`)) { return; } await deleteLocation(location.id); }, [deleteLocation]); if (warehouseError) { return (

{warehouseError}

); } if (loadingWarehouse || !warehouse) { return (
); } const address = [ warehouse.addressLine1, warehouse.addressLine2, warehouse.city, warehouse.state, warehouse.postalCode, warehouse.country, ].filter(Boolean).join(', '); return (
{/* Header */}

{warehouse.name}

{warehouse.isDefault && ( Por defecto )}

Codigo: {warehouse.code}

{/* Info Grid */}
{/* Details Card */}

Detalles

{warehouse.description && (
Descripcion
{warehouse.description}
)} {address && (
Direccion
{address}
)} {warehouse.managerName && (
Responsable
{warehouse.managerName}
)} {warehouse.phone && (
Telefono
{warehouse.phone}
)} {warehouse.email && (
Email
{warehouse.email}
)}
{/* Capacity Card */}

Capacidad

{warehouse.capacityUnits?.toLocaleString() ?? '-'}

Unidades

{warehouse.capacityVolume ? `${warehouse.capacityVolume} m3` : '-'}

Volumen

{warehouse.capacityWeight ? `${warehouse.capacityWeight} kg` : '-'}

Peso

{/* Settings Card */}

Configuracion

Permitir stock negativo
{warehouse.settings?.allowNegative ? 'Si' : 'No'}
Reorden automatico
{warehouse.settings?.autoReorder ? 'Si' : 'No'}
{/* Locations Section */}

Ubicaciones

{locations.length} ubicaciones configuradas

{/* View Toggle */}
{loadingLocations ? (
) : viewMode === 'list' ? ( ) : ( )}
); }