/**
 * DevExtreme (esm/__internal/ui/text_box/texteditor_button_collection/m_custom.js)
 * Version: 24.1.7-build-24272-1937
 * Build date: Sat Sep 28 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 {
    name as clickEventName
} from "../../../../events/click";
import eventsEngine from "../../../../events/core/events_engine";
import {
    end,
    start
} from "../../../../events/hover";
import Button from "../../../../ui/button";
import TextEditorButton from "./m_button";
const CUSTOM_BUTTON_HOVERED_CLASS = "dx-custom-button-hovered";
export default class CustomButton extends TextEditorButton {
    _attachEvents(instance, $element) {
        const {
            editor: editor
        } = this;
        eventsEngine.on($element, start, (() => {
            editor.$element().addClass("dx-custom-button-hovered")
        }));
        eventsEngine.on($element, end, (() => {
            editor.$element().removeClass("dx-custom-button-hovered")
        }));
        eventsEngine.on($element, clickEventName, (e => {
            e.stopPropagation()
        }))
    }
    _create() {
        const {
            editor: editor
        } = this;
        const $element = $("<div>");
        this._addToContainer($element);
        const instance = editor._createComponent($element, Button, extend({}, this.options, {
            ignoreParentReadOnly: true,
            disabled: this._isDisabled(),
            integrationOptions: this._prepareIntegrationOptions(editor)
        }));
        return {
            $element: $element,
            instance: instance
        }
    }
    _prepareIntegrationOptions(editor) {
        return extend({}, editor.option("integrationOptions"), {
            skipTemplates: ["content"]
        })
    }
    update() {
        const isUpdated = super.update();
        if (this.instance) {
            this.instance.option("disabled", this._isDisabled())
        }
        return isUpdated
    }
    _isVisible() {
        const {
            editor: editor
        } = this;
        return editor.option("visible")
    }
    _isDisabled() {
        const isDefinedByUser = void 0 !== this.options.disabled;
        if (isDefinedByUser) {
            return this.instance ? this.instance.option("disabled") : this.options.disabled
        }
        return this.editor.option("readOnly")
    }
}
