import { markRaw, defineAsyncComponent } from 'vue' import translation from 'src/i18n' import { langToLocale } from 'src/utils/languageUtils' export default { name: 'appointment', data: { dateTime: '', duration: 0, german: { title: '', place: '', person: '', freeText: '' }, english: { title: '', place: '', person: '', freeText: '' }, errors: [] }, renderDesktop: (element, lang) => { const durationArray = element.data.duration.toString().split('.') // [hours, fraction of hours -> minutes] const durationHours = durationArray[0] > 0 ? `${durationArray[0]}` : `${durationArray[0]} ${translation[langToLocale(lang)].appointmentElement.hour}` const durationMinutes = durationArray[1] > 0 ? `${('0.' + durationArray[1]) * 60}` : '' // generate deeplinks if dateTime is in expected format DD.MM.YYYY HH:MM, else use default values let date = new Date() let endDate = new Date() let title = '' let location = '' let description = '' if (element.data.dateTime.match(/^\d{2}\.\d{2}\.\d{4} \d{2}:\d{2}$/)) { date = new Date(element.data.dateTime.split(' ')[0].split('.').reverse().join('-') + 'T' + element.data.dateTime.split(' ')[1] + ':00') endDate = new Date(date.getTime() + element.data.duration * 60 * 60 * 1000) title = encodeURIComponent(element.data[lang].title) location = encodeURIComponent(element.data[lang].place) description = encodeURIComponent(element.data[lang].person + '-\n' + element.data[lang].freeText) } const outlookCom = `https://outlook.live.com/owa/?path=/calendar/action/compose&rru=addevent&startdt=${ date.getFullYear() + '-' +// YYYY- String(date.getMonth() + 1).padStart(2, '0') + '-' + // MM- String(date.getDate()).padStart(2, '0') + 'T' + // DDT String(date.getHours()).padStart(2, '0') + ':' + // HH: String(date.getMinutes()).padStart(2, '0') + ':' + // MM: String(date.getSeconds()).padStart(2, '0') // SS }&enddt=${ endDate.getFullYear() + '-' +// YYYY- String(endDate.getMonth() + 1).padStart(2, '0') + '-' + // MM- String(endDate.getDate()).padStart(2, '0') + 'T' + // DDT String(endDate.getHours()).padStart(2, '0') + ':' + // HH: String(endDate.getMinutes()).padStart(2, '0') + ':' + // MM: String(endDate.getSeconds()).padStart(2, '0') // SS }&subject=${title}&location=${location}&body=${description}` const googleCalendar = `https://calendar.google.com/calendar/render?action=TEMPLATE&text=${title}&dates=${ date.getFullYear() + // YYYY String(date.getMonth() + 1).padStart(2, '0') + // MM String(date.getDate()).padStart(2, '0') + // DD 'T' + String(date.getHours()).padStart(2, '0') + // HH String(date.getMinutes()).padStart(2, '0') + // MM '00' + // SS '/' + endDate.getFullYear() + // YYYY String(endDate.getMonth() + 1).padStart(2, '0') + // MM String(endDate.getDate()).padStart(2, '0') + // DD 'T' + String(endDate.getHours()).padStart(2, '0') + // HH String(endDate.getMinutes()).padStart(2, '0') + // MM '00' // SS }&location=${location}&details=${description}` const office365 = outlookCom.replace('outlook.live.com', 'outlook.office.com') return `
` + (element.data[lang].freeText ? ` ` : '') + `

🕑

${element.data[lang].title}

` + (element.data.duration > 0 ? ` ` : '') + (element.data[lang].place ? ` ` : '') + (element.data[lang].person ? ` ` : '') + `
${translation[langToLocale(lang)].appointmentElement.when}: ${element.data.dateTime}
${translation[langToLocale(lang)].appointmentElement.duration}: ${durationHours > 0 ? `${durationHours} ` + (durationHours > 1 ? translation[langToLocale(lang)].appointmentElement.hours : translation[langToLocale(lang)].appointmentElement.hour) : ''} ${durationMinutes > 0 ? `${durationMinutes} ` + translation[langToLocale(lang)].appointmentElement.minutes : ''}
${translation[langToLocale(lang)].appointmentElement.where}: ${element.data[lang].place}
${translation[langToLocale(lang)].appointmentElement.who}: ${element.data[lang].person}

${element.data[lang].freeText}

Outlook.com |  Office 365 |  Google Calendar

` }, renderMobile: (element, lang) => { const durationArray = element.data.duration.toString().split('.') // [hours, fraction of hours -> minutes] const durationHours = durationArray[0] > 0 ? `${durationArray[0]}` : `${durationArray[0]} ${translation[langToLocale(lang)].appointmentElement.hour}` const durationMinutes = durationArray[1] > 0 ? `${('0.' + durationArray[1]) * 60}` : '' // generate deeplinks if dateTime is in expected format DD.MM.YYYY HH:MM, else use default values let date = new Date() let endDate = new Date() let title = '' let location = '' let description = '' if (element.data.dateTime.match(/^\d{2}\.\d{2}\.\d{4} \d{2}:\d{2}$/)) { date = new Date(element.data.dateTime.split(' ')[0].split('.').reverse().join('-') + 'T' + element.data.dateTime.split(' ')[1] + ':00') endDate = new Date(date.getTime() + element.data.duration * 60 * 60 * 1000) title = encodeURIComponent(element.data[lang].title) location = encodeURIComponent(element.data[lang].place) description = encodeURIComponent(element.data[lang].person + '-\n' + element.data[lang].freeText) } const outlookCom = `https://outlook.live.com/owa/?path=/calendar/action/compose&rru=addevent&startdt=${ date.getFullYear() + '-' +// YYYY- String(date.getMonth() + 1).padStart(2, '0') + '-' + // MM- String(date.getDate()).padStart(2, '0') + 'T' + // DDT String(date.getHours()).padStart(2, '0') + ':' + // HH: String(date.getMinutes()).padStart(2, '0') + ':' + // MM: String(date.getSeconds()).padStart(2, '0') // SS }&enddt=${ endDate.getFullYear() + '-' +// YYYY- String(endDate.getMonth() + 1).padStart(2, '0') + '-' + // MM- String(endDate.getDate()).padStart(2, '0') + 'T' + // DDT String(endDate.getHours()).padStart(2, '0') + ':' + // HH: String(endDate.getMinutes()).padStart(2, '0') + ':' + // MM: String(endDate.getSeconds()).padStart(2, '0') // SS }&subject=${title}&location=${location}&body=${description}` const googleCalendar = `https://calendar.google.com/calendar/render?action=TEMPLATE&text=${title}&dates=${ date.getFullYear() + // YYYY String(date.getMonth() + 1).padStart(2, '0') + // MM String(date.getDate()).padStart(2, '0') + // DD 'T' + String(date.getHours()).padStart(2, '0') + // HH String(date.getMinutes()).padStart(2, '0') + // MM '00' + // SS '/' + endDate.getFullYear() + // YYYY String(endDate.getMonth() + 1).padStart(2, '0') + // MM String(endDate.getDate()).padStart(2, '0') + // DD 'T' + String(endDate.getHours()).padStart(2, '0') + // HH String(endDate.getMinutes()).padStart(2, '0') + // MM '00' // SS }&location=${location}&details=${description}` const office365 = outlookCom.replace('outlook.live.com', 'outlook.office.com') return ` ` + (element.data[lang].freeText ? ` ` : '') + `

🕑

${element.data[lang].title}

` + (element.data.duration > 0 ? ` ` : '') + (element.data[lang].place ? ` ` : '') + (element.data[lang].person ? ` ` : '') + `
${translation[langToLocale(lang)].appointmentElement.when}: ${element.data.dateTime}
${translation[langToLocale(lang)].appointmentElement.duration}: ${durationHours > 0 ? `${durationHours} ` + (durationHours > 1 ? translation[langToLocale(lang)].appointmentElement.hours : translation[langToLocale(lang)].appointmentElement.hour) : ''} ${durationMinutes > 0 ? `${durationMinutes} ` + translation[langToLocale(lang)].appointmentElement.minutes : ''}
${translation[langToLocale(lang)].appointmentElement.where}: ${element.data[lang].place}
${translation[langToLocale(lang)].appointmentElement.who}: ${element.data[lang].person}

${element.data[lang].freeText}

Outlook.com |  Office 365 |  Google Calendar

` }, component: markRaw(defineAsyncComponent(() => import('src/components/NewsletterElements/AppointmentElement.vue')) ) }