'use client';
import React, { createContext, useContext, useMemo } from 'react';

export type ProjetoLayoutContextValue = {
  projetoId: string;
  projeto: Record<string, unknown> | null;
  loading: boolean;
};

const Ctx = createContext<ProjetoLayoutContextValue | null>(null);

export function ProjetoLayoutProvider({
  children,
  projetoId,
}: {
  children: React.ReactNode;
  projetoId: string;
  [key: string]: unknown;
}) {
  const value = useMemo(
    () => ({ projetoId: String(projetoId), projeto: null, loading: false }),
    [projetoId],
  );
  return <Ctx.Provider value={value}>{children}</Ctx.Provider>;
}

export function useProjetoLayoutContext(): ProjetoLayoutContextValue {
  return useContext(Ctx) ?? { projetoId: '', projeto: null, loading: false };
}

export function useProjetoLayoutContextOptional() {
  return useContext(Ctx);
}
