import { computed, defineComponent, type PropType, ref } from 'vue'; import type { BCMSLanguage, BCMSTemplate } from '@becomes/cms-sdk/types'; import BCMSIcon from '../icon'; import type { BCMSEntryFilters, BCMSEntryFiltersOption } from '../../types'; import BCMSButton from '../button'; import { BCMSSelect } from '../input'; import pluralize from 'pluralize'; import { useTranslation } from '../../translations'; const component = defineComponent({ props: { template: { type: Object as PropType, required: true, }, languages: { type: Array as PropType, required: true }, visibleLanguage: { type: Object as PropType<{ data: BCMSLanguage; index: number }>, required: true, }, disableAddEntry: Boolean, entryCount: { type: Number, default: 0, }, }, emits: { selectLanguage: (_: string) => { return true; }, addEntry: () => { return true; }, filter: (_filter: BCMSEntryFilters) => { return true; }, }, setup(props, ctx) { const translations = computed(() => { return useTranslation(); }); function getFilters(): BCMSEntryFilters { return { search: { name: '', }, isOpen: false, options: [ { label: translations.value.page.entries.filters.input.dateCreated.label, fromDate: { year: -1, month: -1, day: -1, }, }, { label: translations.value.page.entries.filters.input.dateUpdated.label, toDate: { year: -1, month: -1, day: -1, }, }, ], }; } const filters = ref(getFilters()); const isFiltering = computed(() => { return !!( filters.value.search.name || filters.value.options.some((option: BCMSEntryFiltersOption) => { return option.fromDate?.year !== -1 && option.toDate?.year !== -1; }) ); }); let searchDebounceTimer: any; const isEmpty = computed(() => { return props.entryCount === 0; }); // const toggler = ref(null); return () => (

{props.template.label}

{isEmpty.value ? translations.value.page.entries.filters.emptyState.subtitle : translations.value.page.entries.filters.entriesCount({ count: props.entryCount, pluralEntry: pluralize('entry', props.entryCount), })}

{(!isEmpty.value || isFiltering.value) && (
{ clearTimeout(searchDebounceTimer); searchDebounceTimer = setTimeout(() => { ctx.emit( 'filter', window.bcms.util.object.instance(filters.value), ); }, 300); }} /> {/* {filters.value.isOpen ? (
(filters.value.isOpen = false)} > {filters.value.options.map((filterOption) => { return (
{filterOption.fromDate ? ( { if (filterOption.fromDate) { if (value === 0) { filterOption.fromDate = { year: -1, month: -1, day: -1, }; } else { const date = new Date(value); filterOption.fromDate.year = date.getFullYear(); filterOption.fromDate.month = date.getMonth() + 1; filterOption.fromDate.day = date.getDate(); } ctx.emit('filter', filters.value); } }} /> ) : filterOption.toDate ? ( { if (filterOption.toDate) { if (value === 0) { filterOption.toDate = { year: -1, month: -1, day: -1, }; } else { const date = new Date(value); filterOption.toDate.year = date.getFullYear(); filterOption.toDate.month = date.getMonth() + 1; filterOption.toDate.day = date.getDate(); } ctx.emit('filter', filters.value); } }} /> ) : ( '' )}
); })}
) : ( '' )}
*/} {/* */}
)}
{props.languages.length > 1 && !isEmpty.value && ( { return { label: `${e.name}`, value: e._id }; })} onChange={(option) => { ctx.emit('selectLanguage', option.value); }} class="xs:max-w-[200px]" /> )} { ctx.emit('addEntry'); }} class="flex-shrink-0" > {translations.value.page.entries.filters.emptyState.actionText({ label: props.template.label.toLowerCase(), })}
); }, }); export default component;