import Cookies from 'js-cookie'
import { getProjectContentTypeList } from '@/api/contentManage'

const state = {
  sidebar: {
    opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true,
    withoutAnimation: false
  },
  typeList: []
}

const mutations = {
  TOGGLE_SIDEBAR: state => {
    state.sidebar.opened = !state.sidebar.opened
    state.sidebar.withoutAnimation = false
    if (state.sidebar.opened) {
      Cookies.set('sidebarStatus', 1)
    } else {
      Cookies.set('sidebarStatus', 0)
    }
  },
  SET_TYPELIST: (state, list) => {
    console.log(list)
    state.typeList = list
  }
}

const actions = {
  toggleSideBar({ commit }) {
    commit('TOGGLE_SIDEBAR')
  },
  getTypeList({ commit }, type, id) {
    getProjectContentTypeList(type, id).then(res => {
      const data = res.data
      commit('SET_TYPELIST', data)
    })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
