/**
 * Compose Store (Zustand) – stato globale della finestra di composizione.
 */

import { create } from 'zustand'
import type { MessageResponse } from '@/types/api.types'

type ComposeMode = 'normal' | 'minimized' | 'fullscreen'

interface ComposeState {
  isOpen: boolean
  mode: ComposeMode
  replyTo: MessageResponse | null
  forwardOf: MessageResponse | null
  replyAll: boolean

  openCompose: (opts?: { replyTo?: MessageResponse; forwardOf?: MessageResponse; replyAll?: boolean }) => void
  closeCompose: () => void
  setMode: (mode: ComposeMode) => void
}

export const useComposeStore = create<ComposeState>()((set) => ({
  isOpen: false,
  mode: 'normal',
  replyTo: null,
  forwardOf: null,
  replyAll: false,

  openCompose: (opts) =>
    set({
      isOpen: true,
      mode: 'normal',
      replyTo: opts?.replyTo ?? null,
      forwardOf: opts?.forwardOf ?? null,
      replyAll: opts?.replyAll ?? false,
    }),

  closeCompose: () =>
    set({
      isOpen: false,
      mode: 'normal',
      replyTo: null,
      forwardOf: null,
      replyAll: false,
    }),

  setMode: (mode) => set({ mode }),
}))
