"use client";

import { create } from "zustand";

interface CurrentDocumentState {
  documentId: string | null;
  readOnly: boolean;
  disableDownload: boolean;
  disableCopy: boolean;
  setCurrent: (documentId: string, readOnly: boolean, disableDownload: boolean, disableCopy: boolean) => void;
  clearIfMatch: (documentId: string) => void;
}

export const useCurrentDocumentStore = create<CurrentDocumentState>((set, get) => ({
  documentId: null,
  readOnly: false,
  disableDownload: false,
  disableCopy: false,
  setCurrent: (documentId, readOnly, disableDownload, disableCopy) =>
    set({ documentId, readOnly, disableDownload, disableCopy }),
  clearIfMatch: (documentId) => {
    const state = get();
    if (state.documentId === documentId) {
      set({ documentId: null, readOnly: false, disableDownload: false, disableCopy: false });
    }
  },
}));
