import React, { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { productSheetService } from '../../services/api'; import useFormatters from '../../hooks/useFormatters'; import ProductSheetModal from './ProductSheetModal'; import ConfirmModal from '../ConfirmModal'; const ProductSheetsTab = ({ sheets, settings, onCreated, onUpdated, onDeleted }) => { const { t } = useTranslation(); const { currency } = useFormatters(); const [showModal, setShowModal] = useState(false); const [editingSheet, setEditingSheet] = useState(null); const [deleting, setDeleting] = useState(null); const [filter, setFilter] = useState({ category: '', active: 'all' }); const [confirmModal, setConfirmModal] = useState({ show: false, sheet: null }); const handleCreate = () => { setEditingSheet(null); setShowModal(true); }; const handleEdit = (sheet) => { setEditingSheet(sheet); setShowModal(true); }; const handleDuplicate = async (sheet) => { try { const duplicated = await productSheetService.duplicate(sheet.id); onCreated(duplicated); } catch (err) { alert(err.response?.data?.message || t('common.error')); } }; const handleDelete = async (sheet) => { setConfirmModal({ show: true, sheet }); }; const executeDelete = async () => { const sheet = confirmModal.sheet; setConfirmModal({ show: false, sheet: null }); setDeleting(sheet.id); try { await productSheetService.delete(sheet.id); onDeleted(sheet.id); } catch (err) { alert(err.response?.data?.message || t('common.error')); } finally { setDeleting(null); } }; const handleSave = (savedSheet) => { if (editingSheet) { onUpdated(savedSheet); } else { onCreated(savedSheet); } setShowModal(false); }; // Filtrar fichas const filteredSheets = sheets.filter(sheet => { if (filter.category && sheet.category !== filter.category) return false; if (filter.active === 'active' && !sheet.is_active) return false; if (filter.active === 'inactive' && sheet.is_active) return false; return true; }); // Categorias únicas const categories = [...new Set(sheets.map(s => s.category).filter(Boolean))]; return ( <> {/* Header */}
{t('business.products.description')}
{t('business.products.emptyDescription')}
{t('business.products.noResults')}