import accessibility from "../directives/accessibility.js"; import TabView from '../../../index.ci.php/public/js/components/primevue/tabview/tabview.esm.min.js'; import TabPanel from '../../../index.ci.php/public/js/components/primevue/tabpanel/tabpanel.esm.min.js'; export default { components: { tabview: TabView, tabpanel: TabPanel }, directives: { accessibility }, emits: [ 'update:modelValue', 'change', 'changed' ], props: { config: { type: [String, Array, Object, Promise], required: true }, default: String, modelValue: [String, Number, Boolean, Array, Object, Date, Function, Symbol], vertical: Boolean, border: Boolean, useprimevue: { type: Boolean, default: false } }, data() { return { current: null, tabs: {} } }, computed: { currentTab() { if (this.tabs[this.current]) return this.tabs[this.current]; return { component: 'div' }; }, value: { get() { return this.modelValue; }, set(v) { this.$emit('update:modelValue', v); } }, calcActiveIndex: function() { let keys = Object.keys(this.tabs); let index = keys.indexOf(this.default); if( index === -1 ) { return 0; } else { return index; } } }, watch: { config(n) { this.initConfig(n); } }, methods: { handleTabClick: function(index) { let keys = Object.keys(this.tabs); this.change(keys[index]); }, change(key) { this.$emit("change", key) this.current = key; this.$nextTick(() => this.$emit("changed", key)); }, initConfig(config) { if (!config) return; if (config instanceof Promise) return config .then(result => result.data) .then(this.initConfig) .catch(this.$fhcAlert.handleSystemError); if (typeof config === 'string' || config instanceof String) return this.$api .get(config) .then(result => result.data) .then(this.initConfig) .catch(this.$fhcAlert.handleSystemError); const tabs = {}; function _addToTabs(key, item) { if (!item.component) return console.error('Component missing for ' + key); tabs[key] = { component: Vue.markRaw(Vue.defineAsyncComponent(() => import(item.component))), title: Vue.computed(() => item.title || key), config: item.config, key, value: {} } } if (Array.isArray(config)) config.forEach((item, key) => _addToTabs(key, item)); else Object.entries(config).forEach(([key, item]) => _addToTabs(key, item)); if (this.current === null || !tabs[this.current]) { if (tabs[this.default]) this.current = this.default; else this.current = Object.keys(tabs)[0]; } this.tabs = tabs; } }, created() { this.initConfig(this.config); }, template: ` ` };