<template>
  <v-card class="mx-auto">
    <v-list subheader>
      <v-subheader>{{ t("UserInterfaceSettings") }}</v-subheader>
      <v-list-item link to="adm-translation">
        <v-list-item-title>{{ t("PickListTemplates") }}</v-list-item-title>
      </v-list-item>
    </v-list>
  </v-card>
</template>

<script>
import UnderConstruction from "../components/underconstruction.vue";

export default {
  beforeCreate() {
    window.$gz.eventBus.$emit("menu-change", {
      isMain: true,
      icon: "cogs",
      title: window.$gz.translation.get("AdministrationGlobalSettings"),
      helpUrl: "form-adm-global-settings"
    });
  },
  created() {
    var vm = this;
    initForm(vm)
      .then(() => {
        vm.rights = window.$gz.role.getRights(window.$gz.type.UserOptions);
        // vm.formState.ready = true;
        // window.$gz.eventBus.$on("menu-click", clickHandler);
        // //UserOptions never creates a new one so this code is a little different than other forms
        // //NOTE: FOR NOW GOING TO ASSUME THIS FORM WILL ONLY EVER BE USED TO EDIT *CURRENT* USER'S USEROPTIONS
        // //SO NOT FOR EDITING OTHER USERS, WILL ASSUME THE USER EDITOR FORM FOR MANAGEMENT WILL HAVE A COMPACT VERSION
        // //OF THESE SAME FIELDS FOR THAT PURPOSE
        // //SO ALWAYS USER CURRENT LOGGED IN USER ID FOR THIS
        // //id 0 means create a new record don't load one but thats not applicable here

        // vm.getDataFromApi();
      })
      .catch(err => {
        vm.formState.ready = true;
        window.$gz.errorHandler.handleFormError(err, vm);
      });
  },
  data() {
    return {
      rights: window.$gz.role.defaultRightsObject()
    };
  },
  methods: {
    t(tKey) {
      return window.$gz.translation.get(tKey);
    }
  }
};

/////////////////////////////////
//
//
function initForm(vm) {
  return new Promise(function(resolve, reject) {
    (async function() {
      try {
        await fetchTranslatedText(vm);
      } catch (err) {
        reject(err);
      }
      resolve();
    })();
  });
}

//////////////////////////////////////////////////////////
//
// Ensures UI translated text is available
//
function fetchTranslatedText(vm) {
  return window.$gz.translation.fetch([
    "UserInterfaceSettings",
    "PickListTemplates"
  ]);
}
</script>
