import { createSlice } from '@reduxjs/toolkit';

const initialState = {
  thumbnailDraftPreview: null,
  thumbnails: null,
  published: false,
  draft: false,
  processing: false,
  processingJob: null,

  processingPercentage: null,

  isLoading: false,
  isDirty: false,

  shouldOpenGenerateByAiConfirm: false,

  isGeneratingAvailable: false,
  causes: [],
};

export const slice = createSlice({
  name: '@@AIWORKBENCH/THUMBNAIL',
  initialState,
  reducers: {
    getThumbnailAction: (state) => state,
    setThumbnailDraftAction: (state) => state,
    generateByAiAction: (state) => state,
    uploadAction: (state) => state,
    publishAction: (state) => state,
    setThumbnailFromVideoFrameAction: (state) => state,
    updateThumbnailInVideoListOrDetailAction: (state) => state,
    setAction: (state, action) => {
      Object.keys(action.payload).forEach((key) => {
        state[key] = action.payload[key];
      });
    },
    toggleConfirmForGenerateByAiConfirmAction: (state, action) => {
      state.shouldOpenGenerateByAiConfirm = action.payload;
    },
    unmountAction: (state) => {
      state.thumbnailDraftPreview = null;
      state.thumbnails = null;
      state.isDirty = false;
    },
  },
});

export const {
  getThumbnailAction,
  setThumbnailDraftAction,
  generateByAiAction,
  uploadAction,
  publishAction,
  setThumbnailFromVideoFrameAction,
  setAction,
  toggleConfirmForGenerateByAiConfirmAction,
  unmountAction,
  updateThumbnailInVideoListOrDetailAction,
} = slice.actions;
