"use client"

import { create } from "zustand"

type DocsAiPanelState = {
  open: boolean
  widthPx: number
  toggle: () => void
  openPanel: () => void
  closePanel: () => void
  setWidthPx: (width: number) => void
}

export const DOCS_AI_PANEL_DEFAULT_WIDTH_PX = 380
export const DOCS_AI_PANEL_MIN_WIDTH_PX = 280
export const DOCS_AI_PANEL_MAX_WIDTH_PX = 560

export const useDocsAiPanelStore = create<DocsAiPanelState>((set) => ({
  open: false,
  widthPx: DOCS_AI_PANEL_DEFAULT_WIDTH_PX,
  toggle: () => set((s) => ({ open: !s.open })),
  openPanel: () => set({ open: true }),
  closePanel: () => set({ open: false }),
  setWidthPx: (width) =>
    set({
      widthPx: Math.min(
        DOCS_AI_PANEL_MAX_WIDTH_PX,
        Math.max(DOCS_AI_PANEL_MIN_WIDTH_PX, width)
      ),
    }),
}))
