var $b4aac2eb56fa5943$exports = require("./utils.cjs");
var $89b39774f3b79dbb$exports = require("../utils/mergeProps.cjs");
var $b8ffb0adc97ab95f$exports = require("../i18n/useDateFormatter.cjs");
var $6d2f10bb8b359da5$exports = require("../interactions/useKeyboard.cjs");
var $3f0180db35edfbf7$exports = require("../utils/useLabels.cjs");
var $2522e612fa919664$exports = require("../i18n/I18nProvider.cjs");
var $ctDVS$internationalizeddate = require("@internationalized/date");
var $ctDVS$react = require("react");


function $parcel$export(e, n, v, s) {
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
}

$parcel$export(module.exports, "useCalendarGrid", function () { return $0acfec8dd0a1c8fa$export$cb95147730a423f5; });
/*
 * Copyright 2020 Adobe. All rights reserved.
 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. You may obtain a copy
 * of the License at http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under
 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
 * OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */ 







function $0acfec8dd0a1c8fa$export$cb95147730a423f5(props, state) {
    let { startDate: startDate = state.visibleRange.start, endDate: endDate = state.visibleRange.end, firstDayOfWeek: firstDayOfWeek } = props;
    let { direction: direction } = (0, $2522e612fa919664$exports.useLocale)();
    let { keyboardProps: keyboardProps } = (0, $6d2f10bb8b359da5$exports.useKeyboard)({
        shortcuts: {
            End: ()=>{
                state.focusSectionEnd();
            },
            Home: ()=>{
                state.focusSectionStart();
            },
            Escape: ()=>{
                // Cancel the selection.
                if ('setAnchorDate' in state) state.setAnchorDate(null);
                return false; // TODO: is this really correct? or should it return true when we cancel and only propagate if there's nothing to do
            }
        }
    });
    let { keyboardProps: repeatKeyboardProps } = (0, $6d2f10bb8b359da5$exports.useKeyboard)({
        shortcuts: {
            Enter: ()=>{
                state.selectFocusedDate();
            },
            ' ': ()=>{
                state.selectFocusedDate();
            },
            PageUp: ()=>{
                state.focusPreviousSection();
            },
            'Shift+PageUp': ()=>{
                state.focusPreviousSection(true);
            },
            PageDown: ()=>{
                state.focusNextSection();
            },
            'Shift+PageDown': ()=>{
                state.focusNextSection(true);
            },
            ArrowLeft: ()=>{
                if (direction === 'rtl') state.focusNextDay();
                else state.focusPreviousDay();
            },
            ArrowUp: ()=>{
                state.focusPreviousRow();
            },
            ArrowRight: ()=>{
                if (direction === 'rtl') state.focusPreviousDay();
                else state.focusNextDay();
            },
            ArrowDown: ()=>{
                state.focusNextRow();
            }
        },
        allowRepeats: true
    });
    let visibleRangeDescription = (0, $b4aac2eb56fa5943$exports.useVisibleRangeDescription)(startDate, endDate, state.timeZone, true);
    let { ariaLabel: ariaLabel, ariaLabelledBy: ariaLabelledBy } = (0, $b4aac2eb56fa5943$exports.hookData).get(state);
    let labelProps = (0, $3f0180db35edfbf7$exports.useLabels)({
        'aria-label': [
            ariaLabel,
            visibleRangeDescription
        ].filter(Boolean).join(', '),
        'aria-labelledby': ariaLabelledBy
    });
    let dayFormatter = (0, $b8ffb0adc97ab95f$exports.useDateFormatter)({
        weekday: props.weekdayStyle || 'narrow',
        timeZone: state.timeZone
    });
    let { locale: locale } = (0, $2522e612fa919664$exports.useLocale)();
    let weekDays = (0, $ctDVS$react.useMemo)(()=>{
        let isDayView = state.visibleDuration.days && state.visibleDuration.days < 7;
        let weekStart = isDayView ? startDate : (0, $ctDVS$internationalizeddate.startOfWeek)((0, $ctDVS$internationalizeddate.today)(state.timeZone), locale, firstDayOfWeek);
        let days = isDayView ? state.visibleDuration.days : 7;
        return [
            ...new Array(days).keys()
        ].map((index)=>{
            let date = weekStart.add({
                days: index
            });
            let dateDay = date.toDate(state.timeZone);
            return dayFormatter.format(dateDay);
        });
    }, [
        locale,
        state.timeZone,
        dayFormatter,
        firstDayOfWeek,
        startDate,
        state.visibleDuration.days
    ]);
    let weeksInMonth = state.getWeeksInMonth(startDate);
    return {
        gridProps: (0, $89b39774f3b79dbb$exports.mergeProps)(labelProps, {
            role: 'grid',
            'aria-readonly': state.isReadOnly || undefined,
            'aria-disabled': state.isDisabled || undefined,
            'aria-multiselectable': 'highlightedRange' in state || state.selectionMode === 'multiple' || undefined,
            onFocus: ()=>state.setFocused(true),
            onBlur: ()=>state.setFocused(false)
        }, keyboardProps, repeatKeyboardProps),
        headerProps: {
            // Column headers are hidden to screen readers to make navigating with a touch screen reader easier.
            // The day names are already included in the label of each cell, so there's no need to announce them twice.
            'aria-hidden': true
        },
        weekDays: weekDays,
        weeksInMonth: weeksInMonth
    };
}


//# sourceMappingURL=useCalendarGrid.cjs.map
