Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

4.0 KB
Raw Blame
import { schoolHolidayBand } from '../../../components/Vacay/holidayVisual'
import { localDateStr, monthLead } from '../../../vacay/monthGrid'
import { dayVisual, hatchTint, type DayVisualContext } from './vacayDayModel'

interface MVacayMonthProps {
  year: number
  month: number
  /** mini = year-grid tile cells, full = single-month edit cells */
  variant: 'mini' | 'full'
  weekStart: number
  ctx: DayVisualContext
  tripDates: Set<string>
  tripDotColor: string
  /** mini cells zoom into that month, full cells log the day (#1811). */
  onDayTap: (date: string) => void
}

/**
 * One month of day cells. The mini variant lives in the 2-column year grid
 * (6px radius, 8.5px digits), the full variant in the edit view's single
 * month card (8px radius, 12px digits). Cells are position:relative so the
 * trip-overlap dot can sit in the corner.
 */
export default function MVacayMonth({
  year, month, variant, weekStart, ctx, tripDates, tripDotColor, onDayTap,
}: MVacayMonthProps) {
  const lead = monthLead(year, month, weekStart)
  const daysInMonth = new Date(year, month + 1, 0).getDate()
  const mini = variant === 'mini'

  return (
    <div className={`grid grid-cols-7 ${mini ? 'gap-[2px]' : 'gap-[3px]'}`}>
      {Array.from({ length: lead }, (_, i) => <span key={`lead-${i}`} />)}
      {Array.from({ length: daysInMonth }, (_, i) => {
        const day = i + 1
        const dateStr = localDateStr(year, month, day)
        const dayOfWeek = new Date(year, month, day).getDay()
        const visual = dayVisual(dateStr, dayOfWeek, ctx)
        return (
          <button
            key={day}
            type="button"
            aria-label={dateStr}
            onClick={() => onDayTap(dateStr)}
            className={`relative flex aspect-square items-center justify-center font-geist font-bold ${
              mini ? 'rounded-[6px] text-[0.53125rem]' : 'rounded-lg text-[0.75rem]'
            }`}
            style={{ background: visual.background, color: visual.numColor, boxShadow: visual.boxShadow, textShadow: visual.textShadow }}
          >
            {/* 2+ people: equal-width segment overlays, each solid (vacation) or hatched (comp) (#1074). */}
            {visual.segments && visual.segments.length > 1 && (
              <div className="absolute inset-0 overflow-hidden" style={{ borderRadius: 'inherit' }} aria-hidden>
                {visual.segments.map((seg, si) => (
                  <div
                    key={si}
                    className="absolute top-0 h-full"
                    style={{
                      left: `${(si * 100) / visual.segments!.length}%`,
                      width: `${100 / visual.segments!.length}%`,
                      background: seg.comp ? hatchTint(seg.color) : seg.color,
                    }}
                  />
                ))}
              </div>
            )}
            <span className="relative z-[1]">{day}</span>
            {tripDates.has(dateStr) && (
              <span
                aria-hidden
                className={`absolute rounded-full ${
                  mini ? 'end-[2px] top-[2px] h-[3px] w-[3px]' : 'end-[4px] top-[4px] h-[5px] w-[5px]'
                }`}
                style={{ background: tripDotColor }}
              />
            )}
            {visual.half && (
              <span
                aria-hidden
                className={`absolute rounded-full ${
                  mini ? 'end-[2px] bottom-[2px] h-[3px] w-[3px]' : 'end-[4px] bottom-[4px] h-[5px] w-[5px]'
                }`}
                style={{ background: '#f97316' }}
              />
            )}
            {visual.school && visual.school.length > 0 && (
              <span
                aria-hidden
                className={`absolute rounded-full ${
                  mini ? 'inset-x-[2px] bottom-[1.5px] h-[1.5px]' : 'inset-x-[4px] bottom-[3px] h-[2.5px]'
                }`}
                style={{ background: schoolHolidayBand(visual.school) }}
              />
            )}
          </button>
        )
      })}
    </div>
  )
}