/**
 * DevExtreme (esm/ui/file_manager/ui.file_manager.dialog.js)
 * Version: 23.2.6 (build 24140-0112)
 * Build date: Sun May 19 2024
 *
 * Copyright (c) 2012 - 2024 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
import $ from "../../core/renderer";
import {
    extend
} from "../../core/utils/extend";
import {
    isDefined
} from "../../core/utils/type";
import messageLocalization from "../../localization/message";
import Widget from "../widget/ui.widget";
import Popup from "../popup/ui.popup";
var FILE_MANAGER_DIALOG_CONTENT = "dx-filemanager-dialog";
var FILE_MANAGER_DIALOG_POPUP = "dx-filemanager-dialog-popup";
class FileManagerDialogBase extends Widget {
    _initMarkup() {
        var _options$popupCssClas;
        super._initMarkup();
        this._createOnClosedAction();
        var options = this._getDialogOptions();
        var $popup = $("<div>").appendTo(this.$element());
        var popupOptions = {
            showTitle: true,
            title: options.title,
            visible: false,
            hideOnOutsideClick: true,
            contentTemplate: this._createContentTemplate.bind(this),
            toolbarItems: [{
                widget: "dxButton",
                toolbar: "bottom",
                location: "after",
                options: {
                    text: options.buttonText,
                    onClick: this._applyDialogChanges.bind(this)
                }
            }, {
                widget: "dxButton",
                toolbar: "bottom",
                location: "after",
                options: {
                    text: messageLocalization.format("dxFileManager-dialogButtonCancel"),
                    onClick: this._closeDialog.bind(this)
                }
            }],
            onInitialized: _ref => {
                var {
                    component: component
                } = _ref;
                component.registerKeyHandler("enter", this._applyDialogChanges.bind(this))
            },
            onHiding: this._onPopupHiding.bind(this),
            onShown: this._onPopupShown.bind(this),
            _wrapperClassExternal: "".concat(FILE_MANAGER_DIALOG_POPUP, " ").concat(null !== (_options$popupCssClas = options.popupCssClass) && void 0 !== _options$popupCssClas ? _options$popupCssClas : "")
        };
        if (isDefined(options.height)) {
            popupOptions.height = options.height
        }
        if (isDefined(options.maxHeight)) {
            popupOptions.maxHeight = options.maxHeight
        }
        this._popup = this._createComponent($popup, Popup, popupOptions)
    }
    show() {
        this._dialogResult = null;
        this._popup.show()
    }
    _getDialogOptions() {
        return {
            title: "Title",
            buttonText: "ButtonText",
            contentCssClass: "",
            popupCssClass: ""
        }
    }
    _createContentTemplate(element) {
        this._$contentElement = $("<div>").appendTo(element).addClass(FILE_MANAGER_DIALOG_CONTENT);
        var cssClass = this._getDialogOptions().contentCssClass;
        if (cssClass) {
            this._$contentElement.addClass(cssClass)
        }
    }
    _getDialogResult() {
        return null
    }
    _applyDialogChanges() {
        var result = this._getDialogResult();
        if (result) {
            this._dialogResult = result;
            this._closeDialog()
        }
    }
    _closeDialog() {
        this._popup.hide()
    }
    _onPopupHiding() {
        this._onClosedAction({
            dialogResult: this._dialogResult
        })
    }
    _onPopupShown() {}
    _createOnClosedAction() {
        this._onClosedAction = this._createActionByOption("onClosed")
    }
    _setTitle(newTitle) {
        this._popup.option("title", newTitle)
    }
    _setApplyButtonOptions(options) {
        this._popup.option("toolbarItems[0].options", options)
    }
    _getDefaultOptions() {
        return extend(super._getDefaultOptions(), {
            onClosed: null
        })
    }
    _optionChanged(args) {
        var name = args.name;
        switch (name) {
            case "onClosed":
                this._createOnPathChangedAction();
                break;
            default:
                super._optionChanged(args)
        }
    }
}
export default FileManagerDialogBase;
