const state = {
  tagList: [
    {
      path: "/home/cockpitManage",
      name: "驾驶舱",
      label: "驾驶舱",
    },
  ], // 标签列表
};

const mutations = {
  ADD_TAG(state, tag) {
    if (!state.tagList.find((t) => t.name === tag.name)) {
      state.tagList.push(tag);
    }
  },
  REMOVE_TAG(state, tag) {
    // 确保不能删除 name 为 "驾驶舱" 的标签
    if (tag.name !== "home") {
      state.tagList = state.tagList.filter((t) => t.name !== tag.name);
    }
  },
  REMOVE_OTHER_TAGS(state, tag) {
    // 确保不能删除 name 为 "驾驶舱" 的标签
    state.tagList = state.tagList.filter(
      (t) => t.name === tag.name || t.name === "home"
    );
  },
  REMOVE_ALL_TAGS(state) {
    // 确保不能删除 name 为 "驾驶舱" 的标签
    state.tagList = state.tagList.filter((t) => t.name === "home");
  },
  SET_TAG_LIST(state, tags) {
    state.tagList = tags;
  },
};

const actions = {
  addTag({ commit }, tag) {
    commit("ADD_TAG", tag);
  },
  removeTag({ commit }, tag) {
    commit("REMOVE_TAG", tag);
  },
  removeOtherTags({ commit }, tag) {
    commit("REMOVE_OTHER_TAGS", tag);
  },
  removeAllTags({ commit }) {
    commit("REMOVE_ALL_TAGS");
  },
  setTagList({ commit }, tags) {
    commit("SET_TAG_LIST", tags);
  },
};

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