"use client";

import { create } from "zustand";

export type CommentTarget = {
  workspaceId: string;
  documentId: string;
  blockId: string | null;
};

interface CommentsUiState {
  open: boolean;
  target: CommentTarget | null;
  openForPage: (args: { workspaceId: string; documentId: string }) => void;
  openForBlock: (args: { workspaceId: string; documentId: string; blockId: string }) => void;
  close: () => void;
}

export const useCommentsUiStore = create<CommentsUiState>((set) => ({
  open: false,
  target: null,
  openForPage: ({ workspaceId, documentId }) =>
    set({
      open: true,
      target: { workspaceId, documentId, blockId: null },
    }),
  openForBlock: ({ workspaceId, documentId, blockId }) =>
    set({
      open: true,
      target: { workspaceId, documentId, blockId },
    }),
  close: () => set({ open: false }),
}));

