/**
 * @dyna-grid/core - Advanced Data Grid / Data Table supporting Javascript / Web Components
 * @version v1.0.5
 * @link 
 * @license 
 */
"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
var dyColorPanel_1 = require("./dyColorPanel");
var dyDialog_1 = require("./dyDialog");
var dyPickerField_1 = require("./dyPickerField");
var dom_1 = require("../utils/dom");
var DyColorPicker = /** @class */ (function (_super) {
    __extends(DyColorPicker, _super);
    function DyColorPicker(config) {
        var _this = _super.call(this, config, 'dy-color-picker', 'colorPicker') || this;
        if (config && config.color) {
            _this.value = config.color;
        }
        return _this;
    }
    DyColorPicker.prototype.postConstruct = function () {
        _super.prototype.postConstruct.call(this);
        if (this.value) {
            this.setValue(this.value);
        }
    };
    DyColorPicker.prototype.showPicker = function () {
        var _this = this;
        var eGuiRect = this.getGui().getBoundingClientRect();
        var colorDialog = this.createBean(new dyDialog_1.DyDialog({
            closable: false,
            modal: true,
            hideTitleBar: true,
            minWidth: 190,
            width: 190,
            height: 250,
            x: eGuiRect.right - 190,
            y: eGuiRect.top - 250
        }));
        this.isPickerDisplayed = true;
        dom_1.addCssClass(colorDialog.getGui(), 'dy-color-dialog');
        var colorPanel = this.createBean(new dyColorPanel_1.DyColorPanel({ picker: this }));
        colorPanel.addDestroyFunc(function () {
            if (colorDialog.isAlive()) {
                _this.destroyBean(colorDialog);
            }
        });
        colorDialog.setParentComponent(this);
        colorDialog.setBodyComponent(colorPanel);
        colorPanel.setValue(this.getValue());
        colorDialog.addDestroyFunc(function () {
            // here we check if the picker was already being
            // destroyed to avoid a stack overflow
            if (!_this.isDestroyingPicker) {
                _this.isDestroyingPicker = true;
                if (colorPanel.isAlive()) {
                    _this.destroyBean(colorPanel);
                }
            }
            else {
                _this.isDestroyingPicker = false;
            }
            if (_this.isAlive()) {
                _this.getFocusableElement().focus();
            }
            _this.isPickerDisplayed = false;
        });
        return colorDialog;
    };
    DyColorPicker.prototype.setValue = function (color) {
        if (this.value === color) {
            return this;
        }
        this.eDisplayField.style.backgroundColor = color;
        return _super.prototype.setValue.call(this, color);
    };
    DyColorPicker.prototype.getValue = function () {
        return this.value;
    };
    return DyColorPicker;
}(dyPickerField_1.DyPickerField));
exports.DyColorPicker = DyColorPicker;

//# sourceMappingURL=dyColorPicker.js.map
