/**
 * DevExtreme (ui/text_box/action_button_collection/button.js)
 * Version: 19.1.0 (build 19071)
 * Build date: Tue Mar 12 2019
 *
 * Copyright (c) 2012 - 2019 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
var _createClass = function() {
    function defineProperties(target, props) {
        for (var i = 0; i < props.length; i++) {
            var descriptor = props[i];
            descriptor.enumerable = descriptor.enumerable || false;
            descriptor.configurable = true;
            if ("value" in descriptor) {
                descriptor.writable = true
            }
            Object.defineProperty(target, descriptor.key, descriptor)
        }
    }
    return function(Constructor, protoProps, staticProps) {
        if (protoProps) {
            defineProperties(Constructor.prototype, protoProps)
        }
        if (staticProps) {
            defineProperties(Constructor, staticProps)
        }
        return Constructor
    }
}();
var _renderer = require("../../../core/renderer");
var _renderer2 = _interopRequireDefault(_renderer);

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

function _classCallCheck(instance, Constructor) {
    if (!(instance instanceof Constructor)) {
        throw new TypeError("Cannot call a class as a function")
    }
}
var ActionButton = function() {
    function ActionButton(name, editor, _ref) {
        var _ref$location = _ref.location,
            location = void 0 === _ref$location ? "after" : _ref$location;
        _classCallCheck(this, ActionButton);
        this.instance = null;
        this.$container = null;
        this.$placeMarker = null;
        this.editor = editor;
        this.location = location;
        this.name = name
    }
    _createClass(ActionButton, [{
        key: "_addPlaceMarker",
        value: function($container) {
            this.$placeMarker = (0, _renderer2.default)("<div>").appendTo($container)
        }
    }, {
        key: "_addToContainer",
        value: function($element) {
            var $placeMarker = this.$placeMarker,
                $container = this.$container;
            $placeMarker ? $placeMarker.replaceWith($element) : $element.appendTo($container)
        }
    }, {
        key: "_attachEvents",
        value: function() {
            throw "Not implemented"
        }
    }, {
        key: "_create",
        value: function() {
            throw "Not implemented"
        }
    }, {
        key: "_isRendered",
        value: function() {
            return !!this.instance
        }
    }, {
        key: "_isVisible",
        value: function() {
            throw "Not implemented"
        }
    }, {
        key: "_shouldRender",
        value: function() {
            return this._isVisible() && !this._isRendered()
        }
    }, {
        key: "dispose",
        value: function() {
            var instance = this.instance,
                $placeMarker = this.$placeMarker;
            if (instance) {
                instance.dispose ? instance.dispose() : instance.remove();
                this.instance = null
            }
            $placeMarker && $placeMarker.remove()
        }
    }, {
        key: "render",
        value: function() {
            var $container = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : this.$container;
            this.$container = $container;
            if (this._isVisible()) {
                var _create2 = this._create(),
                    instance = _create2.instance,
                    $element = _create2.$element;
                this.instance = instance;
                this._attachEvents(instance, $element)
            } else {
                this._addPlaceMarker($container)
            }
        }
    }, {
        key: "update",
        value: function() {
            if (this._shouldRender()) {
                this.render()
            }
            return !!this.instance
        }
    }]);
    return ActionButton
}();
exports.default = ActionButton;
