/**
 * DevExtreme (esm/__internal/ui/calendar/m_calendar.navigator.js)
 * Version: 23.2.9 (build 24294-0112)
 * Build date: Sun Oct 20 2024
 *
 * Copyright (c) 2012 - 2024 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
import _extends from "@babel/runtime/helpers/esm/extends";
import $ from "../../../core/renderer";
import Button from "../../../ui/button";
import {
    isFluent,
    isMaterial
} from "../../../ui/themes";
import Widget from "../widget";
var CALENDAR_NAVIGATOR_CLASS = "dx-calendar-navigator";
var CALENDAR_NAVIGATOR_PREVIOUS_MONTH_CLASS = "dx-calendar-navigator-previous-month";
var CALENDAR_NAVIGATOR_NEXT_MONTH_CLASS = "dx-calendar-navigator-next-month";
var CALENDAR_NAVIGATOR_PREVIOUS_VIEW_CLASS = "dx-calendar-navigator-previous-view";
var CALENDAR_NAVIGATOR_NEXT_VIEW_CLASS = "dx-calendar-navigator-next-view";
var CALENDAR_NAVIGATOR_DISABLED_LINK_CLASS = "dx-calendar-disabled-navigator-link";
var CALENDAR_NAVIGATOR_CAPTION_BUTTON_CLASS = "dx-calendar-caption-button";
var BUTTON_TEXT_CLASS = "dx-button-text";
class Navigator extends Widget {
    _getDefaultOptions() {
        return _extends(_extends({}, super._getDefaultOptions()), {
            onClick: void 0,
            onCaptionClick: void 0,
            type: "normal",
            stylingMode: "outlined",
            text: ""
        })
    }
    _defaultOptionsRules() {
        return super._defaultOptionsRules().concat([{
            device: () => isMaterial(),
            options: {
                type: "default",
                stylingMode: "text"
            }
        }, {
            device: () => isFluent(),
            options: {
                type: "normal",
                stylingMode: "text"
            }
        }])
    }
    _init() {
        super._init();
        this._initActions()
    }
    _initActions() {
        this._clickAction = this._createActionByOption("onClick");
        this._captionClickAction = this._createActionByOption("onCaptionClick")
    }
    _initMarkup() {
        super._initMarkup();
        $(this.element()).addClass(CALENDAR_NAVIGATOR_CLASS);
        this._renderButtons();
        this._renderCaption()
    }
    _renderButtons() {
        var {
            rtlEnabled: rtlEnabled,
            type: type,
            stylingMode: stylingMode,
            focusStateEnabled: focusStateEnabled
        } = this.option();
        this._prevButton = this._createComponent($("<div>"), Button, {
            focusStateEnabled: focusStateEnabled,
            icon: rtlEnabled ? "chevronright" : "chevronleft",
            onClick: e => {
                this._clickAction({
                    direction: -1,
                    event: e
                })
            },
            type: type,
            stylingMode: stylingMode,
            integrationOptions: {}
        });
        var $prevButton = $(this._prevButton.element()).addClass(CALENDAR_NAVIGATOR_PREVIOUS_VIEW_CLASS).addClass(CALENDAR_NAVIGATOR_PREVIOUS_MONTH_CLASS);
        this._nextButton = this._createComponent($("<div>"), Button, {
            focusStateEnabled: focusStateEnabled,
            icon: rtlEnabled ? "chevronleft" : "chevronright",
            onClick: e => {
                this._clickAction({
                    direction: 1,
                    event: e
                })
            },
            type: type,
            stylingMode: stylingMode,
            integrationOptions: {}
        });
        var $nextButton = $(this._nextButton.element()).addClass(CALENDAR_NAVIGATOR_NEXT_VIEW_CLASS).addClass(CALENDAR_NAVIGATOR_NEXT_MONTH_CLASS);
        this._caption = this._createComponent($("<div>").addClass(CALENDAR_NAVIGATOR_CAPTION_BUTTON_CLASS), Button, {
            focusStateEnabled: focusStateEnabled,
            onClick: e => {
                this._captionClickAction({
                    event: e
                })
            },
            type: type,
            stylingMode: stylingMode,
            template: (_, content) => {
                var {
                    text: text
                } = this.option();
                var viewCaptionTexts = text.split(" - ");
                viewCaptionTexts.forEach(captionText => {
                    $(content).append($("<span>").addClass(BUTTON_TEXT_CLASS).text(captionText))
                })
            },
            integrationOptions: {}
        });
        var $caption = this._caption.$element();
        this.$element().append($prevButton, $caption, $nextButton)
    }
    _renderCaption() {
        var _a;
        null === (_a = this._caption) || void 0 === _a ? void 0 : _a.option("text", this.option("text"))
    }
    toggleButton(buttonPrefix, value) {
        var buttonName = "_".concat(buttonPrefix, "Button");
        var button = this[buttonName];
        if (button) {
            button.option("disabled", value);
            button.$element().toggleClass(CALENDAR_NAVIGATOR_DISABLED_LINK_CLASS, value)
        }
    }
    _optionChanged(args) {
        switch (args.name) {
            case "text":
                this._renderCaption();
                break;
            default:
                super._optionChanged(args)
        }
    }
}
export default Navigator;
