/**
 * DevExtreme (cjs/ui/diagram/diagram.options_update.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/
 */
"use strict";
exports.default = void 0;
var _diagram = _interopRequireDefault(require("./diagram.bar"));
var _diagram2 = require("./diagram.importer");

function _interopRequireDefault(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    }
}

function _inheritsLoose(subClass, superClass) {
    subClass.prototype = Object.create(superClass.prototype);
    subClass.prototype.constructor = subClass;
    _setPrototypeOf(subClass, superClass)
}

function _setPrototypeOf(o, p) {
    _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(o, p) {
        o.__proto__ = p;
        return o
    };
    return _setPrototypeOf(o, p)
}
let DiagramOptionsUpdateBar = function(_DiagramBar) {
    _inheritsLoose(DiagramOptionsUpdateBar, _DiagramBar);

    function DiagramOptionsUpdateBar(owner) {
        var _this;
        _this = _DiagramBar.call(this, owner) || this;
        const {
            DiagramCommand: DiagramCommand
        } = (0, _diagram2.getDiagram)();
        _this.commandOptions = {};
        _this.commandOptions[DiagramCommand.Fullscreen] = "fullScreen";
        _this.commandOptions[DiagramCommand.ZoomLevel] = function(value) {
            if ("object" === typeof this._getOption("zoomLevel")) {
                this._setOption("zoomLevel.value", value)
            } else {
                this._setOption("zoomLevel", value)
            }
        };
        _this.commandOptions[DiagramCommand.SwitchAutoZoom] = function(value) {
            const {
                AutoZoomMode: AutoZoomMode
            } = (0, _diagram2.getDiagram)();
            switch (value) {
                case AutoZoomMode.FitContent:
                    this._setOption("autoZoomMode", "fitContent");
                    break;
                case AutoZoomMode.FitToWidth:
                    this._setOption("autoZoomMode", "fitWidth");
                    break;
                case AutoZoomMode.Disabled:
                    this._setOption("autoZoomMode", "disabled")
            }
        };
        _this.commandOptions[DiagramCommand.ToggleSimpleView] = "simpleView";
        _this.commandOptions[DiagramCommand.ShowGrid] = "showGrid";
        _this.commandOptions[DiagramCommand.SnapToGrid] = "snapToGrid";
        _this.commandOptions[DiagramCommand.GridSize] = function(value) {
            if ("object" === typeof this._getOption("gridSize")) {
                this._setOption("gridSize.value", value)
            } else {
                this._setOption("gridSize", value)
            }
        };
        _this.commandOptions[DiagramCommand.ViewUnits] = "viewUnits";
        _this.commandOptions[DiagramCommand.PageSize] = function(value) {
            const pageSize = this._getOption("pageSize");
            if (void 0 === pageSize || pageSize.width !== value.width || pageSize.height !== value.height) {
                this._setOption("pageSize", value)
            }
        };
        _this.commandOptions[DiagramCommand.PageLandscape] = function(value) {
            this._setOption("pageOrientation", value ? "landscape" : "portrait")
        };
        _this.commandOptions[DiagramCommand.ViewUnits] = function(value) {
            const {
                DiagramUnit: DiagramUnit
            } = (0, _diagram2.getDiagram)();
            switch (value) {
                case DiagramUnit.In:
                    this._setOption("viewUnits", "in");
                    break;
                case DiagramUnit.Cm:
                    this._setOption("viewUnits", "cm");
                    break;
                case DiagramUnit.Px:
                    this._setOption("viewUnits", "px")
            }
        };
        _this.commandOptions[DiagramCommand.PageColor] = "pageColor";
        _this._updateLock = 0;
        return _this
    }
    var _proto = DiagramOptionsUpdateBar.prototype;
    _proto.getCommandKeys = function() {
        return Object.keys(this.commandOptions).map((function(key) {
            return parseInt(key)
        }))
    };
    _proto.setItemValue = function(key, value) {
        if (this.isUpdateLocked()) {
            return
        }
        this.beginUpdate();
        try {
            if ("function" === typeof this.commandOptions[key]) {
                this.commandOptions[key].call(this, value)
            } else {
                this._setOption(this.commandOptions[key], value)
            }
        } finally {
            this.endUpdate()
        }
    };
    _proto.beginUpdate = function() {
        this._updateLock++
    };
    _proto.endUpdate = function() {
        this._updateLock--
    };
    _proto.isUpdateLocked = function() {
        return this._updateLock > 0
    };
    _proto._getOption = function(name) {
        return this._owner.option(name)
    };
    _proto._setOption = function(name, value) {
        this._owner.option(name, value)
    };
    return DiagramOptionsUpdateBar
}(_diagram.default);
var _default = DiagramOptionsUpdateBar;
exports.default = _default;
module.exports = exports.default;
module.exports.default = exports.default;
