import { defineStore } from "pinia";

export const useStore = defineStore("hrm-dev", {
  state: () => ({
    viewport: undefined,
    login: undefined,
    dealer: undefined,
    token: undefined,
    common: undefined,
    settings: [],
    showmodal: undefined,
    snackbar: undefined,
    country: undefined,
    lang: "vi",
    branch: {},
    rights: [],
    menu: [
      {
        id: 1,
        category: "topmenu",
        classify: "left",
        code: "dashboard",
        vi: "Dashboard",
        link: null,
        view: true,
        detail: {
          base: "Dashboard",
          component: "DashboardMaster",
        },
      },
      {
        id: 2,
        category: "topmenu",
        classify: "left",
        code: "hrm",
        vi: "Quản lý nhân sự",
        link: null,
        view: true,
        detail: {
          base: "HRM",
          component: "HRMMaster",
        },
      },
      {
        id: 3,
        category: "topmenu",
        classify: "left",
        code: "rollcall",
        vi: "Chấm công",
        link: null,
        view: true,
        detail: {
          base: "Rollcall",
          component: "RollcallMaster",
        },
      },
      {
        id: 4,
        category: "topmenu",
        classify: "left",
        code: "salary",
        vi: "Tính lương",
        link: null,
        view: false,
        detail: {
          base: "Salary",
          component: "SalaryMaster",
        },
      },
      {
        id: 5,
        category: "topmenu",
        classify: "left",
        code: "kpi_efficiency",
        vi: "KPI & Hiệu suất",
        link: null,
        view: false,
        detail: {
          base: "Kpi",
          component: "KpiMaster",
        },
      },
      {
        id: 6,
        category: "topmenu",
        classify: "left",
        code: "employee",
        vi: "Cổng nhân viên",
        link: null,
        view: false,
        detail: {
          base: "Employee",
          component: "EmployeeMaster",
        },
      },
      {
        id: 7,
        category: "topmenu",
        classify: "left",
        code: "rights",
        vi: "Phân quyền",
        link: null,
        view: false,
        detail: {
          base: "Rights",
          component: "RightsMaster",
        },
      },
    ],
  }),

  actions: {
    commit(name, data) {
      this[name] = data;
    },

    removeSnackbar() {
      this.snackbar = undefined;
    },
  },

  persist: {
    pick: ["token", "login", "lang", "menu"],
    storage: piniaPluginPersistedstate.localStorage(),
  },
});
