import React, { createContext, useContext, useState, ReactNode } from 'react';

interface ClaudeTerminalContextType {
  // Terminal visibility state
  isOpen: boolean;
  setIsOpen: (open: boolean) => void;
  isExpanded: boolean;
  setIsExpanded: (expanded: boolean) => void;

  // Connection state (updated by the terminal component)
  isConnected: boolean;
  setIsConnected: (connected: boolean) => void;
}

const ClaudeTerminalContext = createContext<ClaudeTerminalContextType | undefined>(undefined);

export const ClaudeTerminalProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
  const [isOpen, setIsOpen] = useState(false);
  const [isExpanded, setIsExpanded] = useState(false);
  const [isConnected, setIsConnected] = useState(false);

  return (
    <ClaudeTerminalContext.Provider value={{
      isOpen,
      setIsOpen,
      isExpanded,
      setIsExpanded,
      isConnected,
      setIsConnected
    }}>
      {children}
    </ClaudeTerminalContext.Provider>
  );
};

export const useClaudeTerminal = () => {
  const context = useContext(ClaudeTerminalContext);
  if (context === undefined) {
    throw new Error('useClaudeTerminal must be used within a ClaudeTerminalProvider');
  }
  return context;
};
