import {
  FOCUS_ON_INPUT,
  NEXT_PAGE,
  PREVIOUS_PAGE,
  RESET,
  SET_CURRENT_PAGE, SET_PERSONAL, SET_SLIDE_INFO,
  SET_SRC, SET_TOTAL_PAGES, TOGGLE_SHOW_DISCUSSION, UNSET_SLIDE_INFO, USE_FOCUS
} from "@/store/types/pdf-types";

export default {
  state: {
    src: "",
    slideInfo: {},
    totalPages: 0,
    currentPage: 1,
    showDiscussion: true,
    focus: false,
    personal: localStorage.getItem("personal") || false
  },

  mutations: {
    [SET_SLIDE_INFO] (state, payload) {
      state.slideInfo = payload.slideInfo;
    },
    [UNSET_SLIDE_INFO] (state) {
      state.slideInfo = {};
    },
    [PREVIOUS_PAGE] (state) {
      state.currentPage = state.currentPage > 1 ? state.currentPage - 1 : state.currentPage;
    },
    [NEXT_PAGE] (state) {
      state.currentPage = state.currentPage < state.totalPages ? state.currentPage + 1 : state.currentPage;
    },
    [SET_CURRENT_PAGE] (state, payload) {
      state.currentPage = payload.currentPage;
    },
    [SET_TOTAL_PAGES] (state, payload) {
      state.totalPages = payload.totalPages;
    },
    [SET_SRC] (state, payload) {
      state.src = payload.src;
    },
    [TOGGLE_SHOW_DISCUSSION] (state) {
      state.showDiscussion = !state.showDiscussion;
    },
    [FOCUS_ON_INPUT] (state) {
      state.focus = true;
    },
    [USE_FOCUS] (state) {
      state.focus = false;
    },
    [SET_PERSONAL] (state, payload) {
      state.personal = payload.personal;
      localStorage.setItem("personal", state.personal);
    },
    [RESET] (state) {
      state.src = "";
      state.totalPages = 0;
      state.currentPage = 1;
      state.focus = false;
    }
  }
};
