"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Calendar = void 0;
const react_1 = __importStar(require("react"));
const varsUtilities_1 = require("../../varsUtilities");
const inlines_1 = require("inlines");
const Text_1 = require("../Text");
const utils_1 = require("../../utils");
const Calendar = ({ selectedDay, selectedMonth, selectedYear, days, setSelectedDay, }) => {
    const [daysArr, setDaysArr] = (0, react_1.useState)([]);
    const daysInMonth = (month, year) => {
        return new Date(year, month, 0).getDate();
    };
    // to determine the current day
    const dateObj = new Date();
    const currentMonth = dateObj.getMonth();
    const currentYear = dateObj.getFullYear();
    const presentDay = dateObj.getDate();
    const tempArr = [];
    // const tempArr: unknown | any = []
    // Calender layout offset
    (0, react_1.useEffect)(() => {
        tempArr.splice(0, tempArr.length);
        for (let i = 1; i <= daysInMonth(selectedMonth, selectedYear); i++) {
            tempArr.push({ day: i, month: selectedMonth, year: selectedYear });
        }
        // add some offset for the days layout
        if (days[new Date(`${selectedMonth} 1, ${selectedYear}`).getDay()] === 'Sun') {
            tempArr.unshift('x', 'x', 'x', 'x', 'x', 'x');
        }
        if (days[new Date(`${selectedMonth} 1, ${selectedYear}`).getDay()] === 'Sat') {
            tempArr.unshift('x', 'x', 'x', 'x', 'x');
        }
        if (days[new Date(`${selectedMonth} 1, ${selectedYear}`).getDay()] === 'Fri') {
            tempArr.unshift('x', 'x', 'x', 'x');
        }
        if (days[new Date(`${selectedMonth} 1, ${selectedYear}`).getDay()] === 'Thu') {
            tempArr.unshift('x', 'x', 'x');
        }
        if (days[new Date(`${selectedMonth} 1, ${selectedYear}`).getDay()] === 'Wed') {
            tempArr.unshift('x', 'x');
        }
        if (days[new Date(`${selectedMonth} 1, ${selectedYear}`).getDay()] === 'Tue') {
            tempArr.unshift('x');
        }
        if (days[new Date(`${selectedMonth} 1, ${selectedYear}`).getDay()] === 'Mon') {
            // tempArr.unshift()
        }
        setDaysArr(tempArr);
    }, [selectedMonth, selectedYear]);
    return (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement(inlines_1.styled.div, { style: {
                display: 'flex',
                textAlign: 'center',
                color: (0, varsUtilities_1.color)('content', 'default', 'secondary'),
                padding: '0px 20px',
                marginTop: 4,
                marginBottom: '-10px',
                justifyContent: 'center',
                '& div': {
                    width: '26px',
                    textAlign: 'center',
                    margin: '4px',
                },
            } },
            react_1.default.createElement(Text_1.Text, { selectable: "none" }, "M"),
            react_1.default.createElement(Text_1.Text, { selectable: "none" }, "T"),
            react_1.default.createElement(Text_1.Text, { selectable: "none" }, "W"),
            react_1.default.createElement(Text_1.Text, { selectable: "none" }, "T"),
            react_1.default.createElement(Text_1.Text, { selectable: "none" }, "F"),
            react_1.default.createElement(Text_1.Text, { selectable: "none" }, "S"),
            react_1.default.createElement(Text_1.Text, { selectable: "none" }, "S")),
        react_1.default.createElement(inlines_1.styled.div, { style: { padding: '10px 20px' } }, daysArr.map((val, i) => val === 'x' ? (react_1.default.createElement(inlines_1.styled.div, { key: i, style: {
                width: 26,
                height: 26,
                margin: '4px',
                display: 'inline-flex',
                borderRadius: 4,
                alignItems: 'center',
                justifyContent: 'center',
                opacity: 0,
            } }, ".")) : (react_1.default.createElement(Text_1.Text, { style: {
                border: val.day === presentDay &&
                    +selectedMonth === currentMonth + 1 &&
                    +selectedYear === currentYear
                    ? `1px solid ${(0, varsUtilities_1.color)('border', 'brand', 'strong')}`
                    : '',
                background: val.day === +selectedDay
                    ? (0, varsUtilities_1.color)('action', 'primary', 'normal')
                    : '',
                color: val.day === +selectedDay
                    ? (0, varsUtilities_1.color)('content', 'inverted', 'primary')
                    : (0, varsUtilities_1.color)('content', 'default', 'primary'),
                borderRadius: 4,
                boxSizing: 'border-box',
                width: 26,
                height: 26,
                margin: '4px',
                textAlign: 'center',
                display: 'inline-flex',
                alignItems: 'center',
                justifyContent: 'center',
                '&:hover': {
                    background: val.day === +selectedDay
                        ? (0, varsUtilities_1.color)('action', 'primary', 'hover')
                        : (0, varsUtilities_1.color)('action', 'neutral', 'subtleHover'),
                    cursor: 'pointer',
                },
                [utils_1.BpTablet]: {
                    '&:hover': {
                        background: 'transparent',
                    },
                },
            }, key: i, onClick: () => {
                setSelectedDay(val.day < 10 ? `0${val.day}` : `${val.day}`);
            } }, val.day)))),
        react_1.default.createElement(inlines_1.styled.div, { style: {
                borderBottom: `1px solid ${(0, varsUtilities_1.color)('border', 'default', 'strong')}`,
            } })));
};
exports.Calendar = Calendar;
//# sourceMappingURL=Calendar.js.map