import { createContext, useContext } from "react"; import type { AnnunciId } from "~/schemas/public/Annunci"; import type { ServizioServizioId } from "~/schemas/public/Servizio"; import type { UsersId } from "~/schemas/public/Users"; import type { ServizioData } from "~/server/controllers/servizio.controller"; type ServizioContextProps = { isAdmin: boolean; userId: UsersId; servizioId: ServizioServizioId; servizio: ServizioData; }; const ServizioContext = createContext(null); export const ServizioProvider = ({ isAdmin, userId, servizioId, servizio, children, }: { isAdmin: boolean; userId: UsersId; servizioId: ServizioServizioId; servizio: ServizioData; children: React.ReactNode; }) => { return ( {children} ); }; export const useServizio = () => { const servizioContext = useContext(ServizioContext); if (!servizioContext) { throw new Error("useServizio must be used within a ServizioProvider"); } return servizioContext; }; type ServizioAnnuncioContextProps = { data: ServizioData["annunci"][number]; annuncioId: AnnunciId; }; const ServizioAnnuncioContext = createContext(null); export const ServizioAnnuncioProvider = ({ data, children, }: { data: ServizioData["annunci"][number]; children: React.ReactNode; }) => { return ( {children} ); }; export const useServizioAnnuncio = () => { const servizioAnnuncioContext = useContext(ServizioAnnuncioContext); if (!servizioAnnuncioContext) { throw new Error( "useServizioAnnuncio must be used within a ServizioAnnuncioProvider", ); } return servizioAnnuncioContext; };