import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { useEffect } from "react";
import { useAppLayout } from "../../contexts";
import { CrudProvider } from "../../contexts/CrudContext";
import { empresaService, personaService, } from "../docMockServices";
import { ListCrudDocsContentPersonas } from "./ListCrudDocsContentPersonas";
import { Collection, TabPanel, TabsGroup } from "../../components";
import { ListCrudDocsContentEmpresas } from "./ListCrudDocsContentEmpresas";
import { useParams } from "react-router-dom";
import { ListCrudDocsContentEmpresaSingle } from "./ListCrudDocsContentEmpresaSingle";
export const ListCrudDocs = () => {
    const { listarPaginados, eliminar, editar, agregar } = personaService;
    const { listarPaginados: listarPaginadosEmpresa, buscarPorId, editar: editarEmpresa, eliminar: eliminarEmpresa, } = empresaService;
    const { setNavBarLeftNode } = useAppLayout();
    useEffect(() => {
        setNavBarLeftNode(_jsx("h3", { className: "text-2xl font-semibold", children: "CrudContext" }));
        return () => {
            setNavBarLeftNode(_jsx(_Fragment, {}));
        };
    }, [setNavBarLeftNode]);
    const { id } = useParams();
    return (_jsx(Collection, { children: _jsxs(TabsGroup, { tabs: [
                { id: "personas", label: "Personas" },
                { id: "empresas", label: "Empresas" },
            ], paramName: "tab", children: [_jsx(TabPanel, { tabId: "personas", children: _jsx(CrudProvider, { getPromise: listarPaginados, postPromise: {
                            execute: agregar,
                            successMessage: "Persona agregada correctamente",
                        }, putPromise: {
                            execute: (persona) => editar(persona.id, persona),
                            successMessage: "Cambios guardados",
                        }, deletePromise: {
                            execute: eliminar,
                            successMessage: "Persona eliminada correctamente",
                        }, urlParams: ["filtro", "idEmpresa"], children: _jsx(ListCrudDocsContentPersonas, {}) }) }), _jsx(TabPanel, { tabId: "empresas", children: _jsx(CrudProvider, { getPromise: listarPaginadosEmpresa, putPromise: {
                            execute: (empresa) => editarEmpresa(empresa.id, empresa),
                            successMessage: "Cambios guardados",
                        }, deletePromise: {
                            execute: eliminarEmpresa,
                            successMessage: "Persona eliminada correctamente",
                        }, getItemPromise: (params) => buscarPorId(params?.toString() || ""), pageParam: "paginaEmpresa", urlParams: ["filtroEmpresa", "idEmpresaEmpresa"], singleItemId: id, children: id ? (_jsx(ListCrudDocsContentEmpresaSingle, {})) : (_jsx(ListCrudDocsContentEmpresas, {})) }) })] }) }));
};
