/**
 * @license
 * Copyright Tyler Technologies, Inc. 
 * License: Apache-2.0
 */
import { __decorate } from "tslib";
import { customElement, attachShadowTemplate, coreProperty, coerceBoolean, elementParents } from '@tylertech/forge-core';
import { FocusIndicatorComponent } from '../../focus-indicator/focus-indicator';
import { StateLayerComponent } from '../../state-layer/state-layer';
import { CalendarMenuAdapter } from './calendar-menu-adapter';
import { CALENDAR_MENU_CONSTANTS } from './calendar-menu-constants';
import { CalendarMenuCore } from './calendar-menu-core';
import { BaseComponent } from '../../core/base/base-component';
const template = '<template><div class=\"forge-calendar-menu\" part=\"root\"></div></template>';
const styles = '.forge-calendar-menu{background-color:var(--forge-theme-surface,#fff);position:relative;height:100%;width:100%;overflow:hidden}.forge-calendar-menu__view{position:absolute;top:0;left:0;height:100%;width:100%;background-color:inherit}.forge-calendar-menu__grid{max-height:var(--forge-calendar-menu-max-height,320px);display:grid;gap:16px;justify-items:center;-webkit-box-align:center;align-items:center;padding:8px;-webkit-box-sizing:border-box;box-sizing:border-box}.forge-calendar-menu__grid--three-col{grid-template-columns:repeat(3,1fr)}.forge-calendar-menu__grid--four-col{grid-template-columns:repeat(4,1fr)}.forge-calendar-menu__list{position:relative;background-color:inherit}.forge-calendar-menu__list__wrapper{position:relative;height:100%;overflow:auto}.forge-calendar-menu__list__wrapper::-webkit-scrollbar{height:var(--forge-scrollbar-height,16px);width:var(--forge-scrollbar-width,16px)}.forge-calendar-menu__list__wrapper::-webkit-scrollbar-track{background-color:var(--forge-scrollbar-track-container,var(--forge-theme-surface-container-low,#ebebeb))}.forge-calendar-menu__list__wrapper::-webkit-scrollbar-track:hover{background-color:var(--forge-scrollbar-track-container-hover,var(--forge-theme-surface-container-low,#ebebeb))}.forge-calendar-menu__list__wrapper::-webkit-scrollbar-corner{background-color:var(--forge-scrollbar-track-container,var(--forge-theme-surface-container-low,#ebebeb))}.forge-calendar-menu__list__wrapper::-webkit-scrollbar-thumb{height:var(--forge-scrollbar-thumb-min-height,32px);width:var(--forge-scrollbar-thumb-min-width,32px);border-radius:var(--forge-scrollbar-border-radius,var(--forge-shape-full,9999px));border-width:var(--forge-scrollbar-border-width,3px);border-style:solid;border-color:transparent;background-color:var(--forge-scrollbar-thumb-container,var(--forge-theme-surface-container-medium,#c2c2c2));background-clip:content-box}.forge-calendar-menu__list__wrapper::-webkit-scrollbar-thumb:hover{background-color:var(--forge-scrollbar-thumb-container-hover,var(--forge-theme-surface-container-high,#9e9e9e))}.forge-calendar-menu__item--grid{-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;font-family:var(--forge-typography-body1-font-family, var(--forge-typography-font-family, \"Roboto\", sans-serif));font-size:var(--forge-typography-body1-font-size, calc(var(--forge-typography-font-size, 1rem) * var(--forge-typography-body-font-size-scale, .875)));font-weight:var(--forge-typography-body1-font-weight,400);line-height:var(--forge-typography-body1-line-height, calc(var(--forge-typography-font-size, 1rem) * var(--forge-typography-body-line-height-scale, 1.125)));letter-spacing:var(--forge-typography-body1-letter-spacing, .0357142857em);text-transform:var(--forge-typography-body1-text-transform,inherit);-webkit-text-decoration:var(--forge-typography-body1-text-decoration,inherit);text-decoration:var(--forge-typography-body1-text-decoration,inherit);display:-webkit-box;display:flex;-webkit-box-pack:center;justify-content:center;-webkit-box-align:center;align-items:center;position:relative;width:100%;height:100%;border-radius:4px;overflow:hidden;font-weight:500;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.forge-calendar-menu__item--grid:not([disabled]){border:1px solid var(--forge-theme-outline,#e0e0e0);cursor:pointer}.forge-calendar-menu__item--grid[disabled]{color:var(--forge-theme-text-low,rgba(0,0,0,.38))}.forge-calendar-menu__item--grid.forge-calendar-menu__item--selected{background-color:var(--forge-theme-primary,#3f51b5);color:var(--forge-theme-on-primary,#fff)}.forge-calendar-menu__item--grid.forge-calendar-menu__item--selected forge-focus-indicator{--forge-focus-indicator-color:var(--forge-theme-primary-container, #d1d5ed)}.forge-calendar-menu__item--list{display:-webkit-box;display:flex;-webkit-box-align:center;align-items:center;-webkit-box-pack:center;justify-content:center;margin:0 4px;width:calc(100% - 8px);height:48px;border-radius:4px;overflow:hidden;text-align:center;cursor:pointer;position:relative}.forge-calendar-menu__item--list.forge-calendar-menu__item--selected{background-color:var(--forge-theme-primary,#3f51b5);color:var(--forge-theme-on-primary,#fff)}.forge-calendar-menu__item--list.forge-calendar-menu__item--selected forge-focus-indicator{--forge-focus-indicator-color:var(--forge-theme-primary-container)}.forge-calendar-menu__item--focused,.forge-calendar-menu__item:focus{outline:0}.forge-calendar-menu--open{-webkit-animation-duration:.2s;animation-duration:.2s;-webkit-animation-name:scale-open;animation-name:scale-open;-webkit-transform-origin:top center;transform-origin:top center}.forge-calendar-menu--open[data-animation=fade]{-webkit-animation-name:fade-in;animation-name:fade-in}.forge-calendar-menu--open[data-animation=none]{-webkit-animation-duration:1ms;animation-duration:1ms}@media (prefers-reduced-motion){.forge-calendar-menu--open{-webkit-animation-name:fade-in;animation-name:fade-in}}.forge-calendar-menu--closing{-webkit-animation-duration:.2s;animation-duration:.2s;-webkit-animation-name:scale-closed;animation-name:scale-closed;-webkit-transform-origin:top center;transform-origin:top center}.forge-calendar-menu--closing[data-animation=fade]{-webkit-animation-name:fade-out;animation-name:fade-out}.forge-calendar-menu--closing[data-animation=none]{-webkit-animation-duration:1ms;animation-duration:1ms}@media (prefers-reduced-motion){.forge-calendar-menu--closing{-webkit-animation-name:fade-out;animation-name:fade-out}}.forge-calendar-menu--slide-right .forge-calendar-menu__view:first-child{-webkit-animation-duration:.2s;animation-duration:.2s;-webkit-animation-name:slide-out-to-right;animation-name:slide-out-to-right}@media (prefers-reduced-motion){.forge-calendar-menu--slide-right .forge-calendar-menu__view:first-child{-webkit-animation-name:fade-out;animation-name:fade-out}}.forge-calendar-menu--slide-right .forge-calendar-menu__view:last-child{-webkit-animation-duration:.2s;animation-duration:.2s;-webkit-animation-name:slide-in-from-left;animation-name:slide-in-from-left}@media (prefers-reduced-motion){.forge-calendar-menu--slide-right .forge-calendar-menu__view:last-child{-webkit-animation-name:fade-in;animation-name:fade-in}}.forge-calendar-menu--slide-left .forge-calendar-menu__view:first-child{-webkit-animation-duration:.2s;animation-duration:.2s;-webkit-animation-name:slide-out-to-left;animation-name:slide-out-to-left}@media (prefers-reduced-motion){.forge-calendar-menu--slide-left .forge-calendar-menu__view:first-child{-webkit-animation-name:fade-out;animation-name:fade-out}}.forge-calendar-menu--slide-left .forge-calendar-menu__view:last-child{-webkit-animation-duration:.2s;animation-duration:.2s;-webkit-animation-name:slide-in-from-right;animation-name:slide-in-from-right}@media (prefers-reduced-motion){.forge-calendar-menu--slide-left .forge-calendar-menu__view:last-child{-webkit-animation-name:fade-in;animation-name:fade-in}}.forge-calendar-menu--replacing-view .forge-calendar-menu__view:first-child{-webkit-animation-duration:.2s;animation-duration:.2s;-webkit-animation-name:fade-out;animation-name:fade-out}.forge-calendar-menu--replacing-view .forge-calendar-menu__view:last-child{-webkit-animation-duration:.2s;animation-duration:.2s;-webkit-animation-name:fade-in;animation-name:fade-in}#scroll-spy-bottom{position:absolute;bottom:0;height:48px;pointer-events:none}#scroll-spy-top{position:absolute;top:0;height:48px;pointer-events:none}@-webkit-keyframes scale-open{from{opacity:0;-webkit-transform:scale(.4);transform:scale(.4)}to{opacity:1;-webkit-transform:scale(1);transform:scale(1)}}@keyframes scale-open{from{opacity:0;-webkit-transform:scale(.4);transform:scale(.4)}to{opacity:1;-webkit-transform:scale(1);transform:scale(1)}}@-webkit-keyframes scale-closed{from{opacity:1;-webkit-transform:scale(1);transform:scale(1)}to{opacity:0;-webkit-transform:scale(.4);transform:scale(.4)}}@keyframes scale-closed{from{opacity:1;-webkit-transform:scale(1);transform:scale(1)}to{opacity:0;-webkit-transform:scale(.4);transform:scale(.4)}}@-webkit-keyframes fade-in{from{opacity:0}to{opacity:1}}@keyframes fade-in{from{opacity:0}to{opacity:1}}@-webkit-keyframes fade-out{from{opacity:1}to{opacity:0}}@keyframes fade-out{from{opacity:1}to{opacity:0}}@-webkit-keyframes slide-in-from-left{from{-webkit-transform:translateX(-100%);transform:translateX(-100%)}to{-webkit-transform:translateX(0);transform:translateX(0)}}@keyframes slide-in-from-left{from{-webkit-transform:translateX(-100%);transform:translateX(-100%)}to{-webkit-transform:translateX(0);transform:translateX(0)}}@-webkit-keyframes slide-in-from-right{from{-webkit-transform:translateX(100%);transform:translateX(100%)}to{-webkit-transform:translateX(0);transform:translateX(0)}}@keyframes slide-in-from-right{from{-webkit-transform:translateX(100%);transform:translateX(100%)}to{-webkit-transform:translateX(0);transform:translateX(0)}}@-webkit-keyframes slide-out-to-left{from{-webkit-transform:translateX(0);transform:translateX(0)}to{-webkit-transform:translateX(-100%);transform:translateX(-100%)}}@keyframes slide-out-to-left{from{-webkit-transform:translateX(0);transform:translateX(0)}to{-webkit-transform:translateX(-100%);transform:translateX(-100%)}}@-webkit-keyframes slide-out-to-right{from{-webkit-transform:translateX(0);transform:translateX(0)}to{-webkit-transform:translateX(100%);transform:translateX(100%)}}@keyframes slide-out-to-right{from{-webkit-transform:translateX(0);transform:translateX(0)}to{-webkit-transform:translateX(100%);transform:translateX(100%)}}:host{display:block;position:absolute;top:0;left:0;height:100%;width:100%}:host([hidden]){display:none}:host([forge-popover-context=true]) .forge-calendar-menu{background-color:var(--forge-theme-surface-bright,#fff)}';
/**
 * @internal
 * @tag forge-calendar-menu
 */
let CalendarMenuComponent = class CalendarMenuComponent extends BaseComponent {
    static get observedAttributes() {
        return [CALENDAR_MENU_CONSTANTS.attributes.ANIMATION_TYPE, CALENDAR_MENU_CONSTANTS.attributes.PREVENT_FOCUS];
    }
    constructor() {
        super();
        attachShadowTemplate(this, template, styles);
        this._core = new CalendarMenuCore(new CalendarMenuAdapter(this));
    }
    connectedCallback() {
        // To simulate the :host-context() selector for Firefox until they implement it, we need to determine if the
        // calendar is within a popup for auto-styling the calendar when included within a popup. Check to see if
        // any of the parents of this element are a popup.
        if (!this.hasAttribute(CALENDAR_MENU_CONSTANTS.attributes.POPOVER_CONTEXT) &&
            elementParents(this).some(el => el.tagName.toLowerCase() === 'forge-popover')) {
            this.setAttribute(CALENDAR_MENU_CONSTANTS.attributes.POPOVER_CONTEXT, 'true');
        }
        this._core.initialize();
    }
    disconnectedCallback() {
        this._core.destroy();
    }
    attributeChangedCallback(name, oldValue, newValue) {
        switch (name) {
            case CALENDAR_MENU_CONSTANTS.attributes.ANIMATION_TYPE:
                this.animationType = newValue;
                break;
            case CALENDAR_MENU_CONSTANTS.attributes.PREVENT_FOCUS:
                this.preventFocus = coerceBoolean(newValue);
                break;
        }
    }
    animateIn(options, direction, setFocus = false) {
        this._core.animateIn(options, direction, setFocus);
    }
    close() {
        this._core.close();
    }
    moveFocusDown() {
        this._core.moveFocusDown();
    }
    moveFocusBackward() {
        return this._core.moveFocusBackward();
    }
    moveFocusForward() {
        return this._core.moveFocusForward();
    }
    moveFocusUp() {
        this._core.moveFocusUp();
    }
    openAsGrid(options, setFocus = false) {
        this._core.openAsGrid(options, setFocus);
    }
    openAsList(options, setFocus = false) {
        this._core.openAsList(options, setFocus);
    }
    selectFocusedItem() {
        this._core.selectFocusedItem();
    }
};
__decorate([
    coreProperty()
], CalendarMenuComponent.prototype, "animationType", void 0);
__decorate([
    coreProperty()
], CalendarMenuComponent.prototype, "preventFocus", void 0);
CalendarMenuComponent = __decorate([
    customElement({
        name: CALENDAR_MENU_CONSTANTS.elementName,
        dependencies: [StateLayerComponent, FocusIndicatorComponent]
    })
], CalendarMenuComponent);
export { CalendarMenuComponent };
