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

const initialState = {
  name: '',
  originalVideoId: null,

  isOpen: false,
  isPlayed: false,
  isMuted: false,

  startTrimProgress: 0,
  playProgress: 0,
  endTrimProgress: 100,

  currentTime: 0,
  duration: 0,
  isVideoDurationLessHour: false,

  startTrimTime: 0,
  endTrimTime: 0,

  // share stuff
  isShowShare: false,
  originalVideo: null,
  trimedVideo: null,
};

export const slice = createSlice({
  name: '@@COMMON/TRIM_VIDEO',
  initialState,

  reducers: {
    makeTrimAction: (state) => state,
    setStateAction: (state, action) => {
      Object.entries(action.payload).forEach(([key, value]) => {
        state[key] = value;
      });
    },
    openAction: (state) => {
      state.isOpen = true;
    },
    clearAction: () => initialState,
  },
});

export const { clearAction, makeTrimAction, openAction, setStateAction } = slice.actions;

export default slice.reducer;
