File size: 4,808 Bytes
c21bca9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
'use client'

import React, { useState } from 'react'
import { CaretLeft, CaretRight } from '@phosphor-icons/react'
import { motion } from 'framer-motion'

export function CalendarWidget() {
    const [currentDate, setCurrentDate] = useState(new Date())
    const today = new Date()

    const monthNames = [
        'January', 'February', 'March', 'April', 'May', 'June',
        'July', 'August', 'September', 'October', 'November', 'December'
    ]

    const daysOfWeek = ['S', 'M', 'T', 'W', 'T', 'F', 'S']

    const getDaysInMonth = (date: Date) => {
        const year = date.getFullYear()
        const month = date.getMonth()
        const firstDay = new Date(year, month, 1)
        const lastDay = new Date(year, month + 1, 0)
        const daysInMonth = lastDay.getDate()
        const startingDayOfWeek = firstDay.getDay()

        const days: (number | null)[] = []
        for (let i = 0; i < startingDayOfWeek; i++) {
            days.push(null)
        }
        for (let i = 1; i <= daysInMonth; i++) {
            days.push(i)
        }
        return days
    }

    const days = getDaysInMonth(currentDate)

    const isToday = (day: number | null) => {
        if (!day) return false
        return (
            day === today.getDate() &&
            currentDate.getMonth() === today.getMonth() &&
            currentDate.getFullYear() === today.getFullYear()
        )
    }

    const previousMonth = () => {
        setCurrentDate(new Date(currentDate.getFullYear(), currentDate.getMonth() - 1))
    }

    const nextMonth = () => {
        setCurrentDate(new Date(currentDate.getFullYear(), currentDate.getMonth() + 1))
    }

    return (
        <div className="w-80 bg-white/80 backdrop-blur-xl rounded-xl shadow-2xl border border-white/40 p-4 text-gray-800">
            {/* Header */}
            <div className="flex items-center justify-between mb-4">
                <div className="font-bold text-lg">
                    {monthNames[currentDate.getMonth()]} {currentDate.getFullYear()}
                </div>
                <div className="flex space-x-1">
                    <button
                        onClick={previousMonth}
                        className="p-1 hover:bg-gray-200/50 rounded-full transition-colors"
                    >
                        <CaretLeft size={16} weight="bold" />
                    </button>
                    <button
                        onClick={nextMonth}
                        className="p-1 hover:bg-gray-200/50 rounded-full transition-colors"
                    >
                        <CaretRight size={16} weight="bold" />
                    </button>
                </div>
            </div>

            {/* Days of Week */}
            <div className="grid grid-cols-7 mb-2">
                {daysOfWeek.map((day, i) => (
                    <div key={i} className="text-center text-xs font-semibold text-gray-500">
                        {day}
                    </div>
                ))}
            </div>

            {/* Calendar Grid */}
            <div className="grid grid-cols-7 gap-1">
                {days.map((day, index) => (
                    <div
                        key={index}
                        className={`
              aspect-square flex items-center justify-center text-sm rounded-full
              ${day ? 'cursor-default' : ''}
              ${isToday(day) ? 'bg-blue-500 text-white font-bold shadow-md' : 'text-gray-700'}
              ${day && !isToday(day) ? 'hover:bg-gray-200/50' : ''}
            `}
                    >
                        {day}
                    </div>
                ))}
            </div>

            {/* Event Dots (Mock) */}
            <div className="mt-4 pt-3 border-t border-gray-200/50">
                <div className="text-xs font-semibold text-gray-500 mb-2">UPCOMING EVENTS</div>
                <div className="space-y-2">
                    <div className="flex items-center gap-2">
                        <div className="w-1 h-8 rounded-full bg-blue-500"></div>
                        <div>
                            <div className="text-xs font-bold">Team Meeting</div>
                            <div className="text-[10px] text-gray-500">10:00 AM - 11:00 AM</div>
                        </div>
                    </div>
                    <div className="flex items-center gap-2">
                        <div className="w-1 h-8 rounded-full bg-purple-500"></div>
                        <div>
                            <div className="text-xs font-bold">Project Review</div>
                            <div className="text-[10px] text-gray-500">2:00 PM - 3:30 PM</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    )
}