import { StateCreator } from 'zustand';

export type ChickinDeleteSlice = {
  // State
  isChickinDeleteModalOpen: boolean;
  selectedChickinIdForDelete: number | null;
  isChickinDeleteLoading: boolean;
  chickinDeleteCallback: (() => Promise<void>) | null;

  // Actions
  openChickinDeleteModal: (
    chickinId: number,
    callback: () => Promise<void>
  ) => void;
  closeChickinDeleteModal: () => void;
  setChickinDeleteLoading: (loading: boolean) => void;
  resetChickinDelete: () => void;
};

export const createChickinDeleteSlice: StateCreator<
  ChickinDeleteSlice,
  [],
  [],
  ChickinDeleteSlice
> = (set) => ({
  // Initial state
  isChickinDeleteModalOpen: false,
  selectedChickinIdForDelete: null,
  isChickinDeleteLoading: false,
  chickinDeleteCallback: null,

  // Actions
  openChickinDeleteModal: (chickinId, callback) =>
    set({
      isChickinDeleteModalOpen: true,
      selectedChickinIdForDelete: chickinId,
      chickinDeleteCallback: callback,
    }),

  closeChickinDeleteModal: () =>
    set({
      isChickinDeleteModalOpen: false,
      selectedChickinIdForDelete: null,
      chickinDeleteCallback: null,
    }),

  setChickinDeleteLoading: (loading) =>
    set({ isChickinDeleteLoading: loading }),

  resetChickinDelete: () =>
    set({
      isChickinDeleteModalOpen: false,
      selectedChickinIdForDelete: null,
      isChickinDeleteLoading: false,
      chickinDeleteCallback: null,
    }),
});
