/** * date-header.js * =============== * A single date-column header cell. * Shows weekday, day number, holiday / event icons, highlight toggle. */ import { formatDateForId, isWeekend, weekendsAreWorkingDays, crosshairActive, hoveredDateStr, highlightedDateStr, toggleColHighlight } from '../../services/planner-state.js'; import { getHoliday, getSpecialDay } from '../../services/data-service.js'; export default { name: 'DateHeader', props: { date: { type: Date, required: true } }, setup(props) { const dateStr = Vue.computed(() => formatDateForId(props.date)); const rootClass = Vue.computed(() => { const cls = ['date-header-root', 'date-header-hover-trigger']; if (isWeekend(props.date) && !weekendsAreWorkingDays.value) cls.push('date-header-bg-weekend'); if (highlightedDateStr.value === dateStr.value) cls.push('date-header-reading-active'); if (crosshairActive.value && hoveredDateStr.value === dateStr.value) cls.push('date-header-col-hovered'); return cls.join(' '); }); const isWkndNonWorking = Vue.computed(() => isWeekend(props.date) && !weekendsAreWorkingDays.value); const isSat = Vue.computed(() => props.date.getDay() === 6); const dayLabelClass = Vue.computed(() => { if (isWkndNonWorking.value) return isSat.value ? 'date-header-text-sat' : 'date-header-text-sun'; return 'text-grey-5'; }); const dayNumClass = Vue.computed(() => { if (isWkndNonWorking.value) return isSat.value ? 'date-header-text-sat' : 'date-header-text-sun'; return 'text-grey-9'; }); const weekdayShort = Vue.computed(() => props.date.toLocaleDateString('en-US', { weekday: 'short' }) ); const dayNum = Vue.computed(() => props.date.getDate()); const monthShort = Vue.computed(() => props.date.toLocaleDateString('en-US', { month: 'short' }) ); const holiday = Vue.computed(() => getHoliday(props.date)); const specialDay = Vue.computed(() => getSpecialDay(props.date)); const isHighlighted = Vue.computed(() => highlightedDateStr.value === dateStr.value); const onEnter = () => { hoveredDateStr.value = dateStr.value; }; const onLeave = () => { hoveredDateStr.value = null; }; const onToggle = () => { toggleColHighlight(props.date); }; return { rootClass, dayLabelClass, dayNumClass, weekdayShort, dayNum, monthShort, holiday, specialDay, isHighlighted, dateStr, onEnter, onLeave, onToggle }; }, template: `