"use client";
import { createContext, useContext } from 'react';
import { useDashboardState } from './use-dashboard-state';

const DashboardContext = createContext(null);

export function DashboardProvider({ children }) {
  // Composer prompt lives local to ChatPanel (P5), so keystrokes do not
  // re-run useDashboardState — context value reference is stable on the
  // typing path and useDashboard() consumers (CanvasSection, etc.) do not
  // re-render until a real state slice changes.
  const value = useDashboardState();
  return (
    <DashboardContext.Provider value={value}>
      {children}
    </DashboardContext.Provider>
  );
}

export function useDashboard() {
  const ctx = useContext(DashboardContext);
  if (ctx === null) {
    throw new Error('useDashboard must be used inside <DashboardProvider>');
  }
  return ctx;
}
