import type { PropType } from 'vue'; import { defineComponent, onMounted, ref, watch, computed } from 'vue'; import { useUserStore } from '@store/UserStore'; import type { IUserFields } from 'model'; import { IImgGallery, IUserProfile } from 'model'; import { costanti } from '@costanti'; import { shared_consts } from '@src/common/shared_vuejs'; import { fieldsTable } from '@store/Modules/fieldsTable'; import { tools } from '@tools'; import { toolsext } from '@store/Modules/toolsext'; import { useQuasar } from 'quasar'; import { useI18n } from 'vue-i18n'; import { CMyCardPopup } from '@src/components/CMyCardPopup'; import { useRouter } from 'vue-router'; import { useCalendarStore } from '@src/store/CalendarStore'; import { useGlobalStore } from '@src/store/globalStore'; export default defineComponent({ name: 'CMyRecCard', components: { CMyCardPopup }, emits: ['setCmd', 'cmdext'], props: { table: { type: String, required: true, }, prop_myrec: { type: Object as PropType, required: false, default: null, }, indexRow: { type: Number, required: false, default: 0, }, editOn: { type: Boolean, required: false, default: false, }, margin_right: { type: Number, required: false, default: 0, }, }, setup(props, { emit }) { const userStore = useUserStore(); const calendarStore = useCalendarStore(); const globalStore = useGlobalStore(); const $q = useQuasar(); const { t } = useI18n(); const $router = useRouter(); const myrec = ref(null); const visupage = ref(false); const disabilita = computed(() => { return props.table === shared_consts.TABLES_MYBACHECAS; }); watch( () => props.prop_myrec, (newval, oldval) => { mounted(); } ); function mounted() { if (props.prop_myrec) { myrec.value = props.prop_myrec; } } function showBadge() { if (shared_consts.TABLES_SHOW_ADTYPE.includes(props.table)) { return true; } return false; } function getImgUser(profile: IUserFields) { return userStore.getImgByProfile(profile); } function naviga(path: string) { $router.push(path); } function setCmd( $q: any, cmd: number, myusername: string, value: any, groupname: string ) { emit('setCmd', $q, cmd, myusername, value, groupname); } function cmdExt(cmd: any, val1: any, val2: any) { emit('cmdext', cmd, val1, val2); } function navigaExt(obj: any) { cmdExt(costanti.CMD_SHOW_PAGE, null, obj); //let link = shared_consts.getDirectoryByTable(props.table) + '/' + obj._id //console.log('link', link) //$router.push(link) } function getNameToShow(user: IUserFields, col = null) { if (myrec.value.groupname) return myrec.value.groupname; else return userStore.getNameToShow(user, col); } function isPartecipero() { return ( props.table === shared_consts.TABLES_MYBACHECAS && calendarStore.isPartecipero(myrec.value._id, props.table) ); } function computedWidth() { //const width = tools.getwidth($q) - 20; //return `${Math.min(width, 600)}px`; // Limita la larghezza massima a 600px return '100%'; // Rimuovi la limitazione a 600px } function computedEventImageHeight() { const width = tools.getwidth($q); const isMobile = width < 768; const cardWidth = Math.min(width - 20, 600); if (isMobile) { // Mobile: aspect ratio 16:9, minimo 200px const calculatedHeight = Math.round((cardWidth - 70) * 0.5625); return `${Math.max(calculatedHeight, 200)}px`; } else { // Desktop: altezza fissa ottimale 220px return '220px'; } } onMounted(mounted); return { t, myrec, costanti, getImgUser, naviga, navigaExt, setCmd, shared_consts, userStore, tools, toolsext, fieldsTable, cmdExt, visupage, showBadge, getNameToShow, isPartecipero, calendarStore, disabilita, globalStore, computedWidth, computedEventImageHeight, }; }, });