@empathyco/x-components
Version:
Empathy X Components
54 lines (51 loc) • 1.78 kB
JavaScript
import { defineComponent, computed } from 'vue';
import BaseSwitch from '../../../components/base-switch.vue.js';
import { use$x } from '../../../composables/use-_x.js';
import { useState } from '../../../composables/use-state.js';
import { isArrayEmpty } from '../../../utils/array.js';
import { historyQueriesXModule } from '../x-module.js';
/**
* History Queries Switch is a component to activate or deactivate the history queries.
* This component emits events depending on the `isEnabled` value.
*
* @public
*/
var _sfc_main = defineComponent({
name: 'HistoryQueriesSwitch',
xModule: historyQueriesXModule.name,
components: {
BaseSwitch,
},
setup() {
const $x = use$x();
/**
* An object with the isEnabled value and the history queries coming from the store state.
*
* @internal
*/
const { isEnabled, historyQueries } = useState('historyQueries');
/**
* Checks if there are history queries.
*
* @returns True if there are history queries; false otherwise.
*/
const hasHistoryQueries = computed(() => !isArrayEmpty(historyQueries.value));
const disableEvent = computed(() => hasHistoryQueries.value
? 'UserClickedDisableHistoryQueries'
: 'UserClickedConfirmDisableHistoryQueries');
/**
* Emits an event based on the switch state.
*
* @internal
*/
const toggle = () => {
$x.emit(isEnabled.value ? disableEvent.value : 'UserClickedEnableHistoryQueries');
};
return {
toggle,
isEnabled,
};
},
});
export { _sfc_main as default };
//# sourceMappingURL=history-queries-switch.vue2.js.map