/**
 * DevExtreme (cjs/viz/core/center_template.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/
 */
"use strict";
exports.plugins = void 0;
var _utils = require("../core/utils");
var _common = require("../../core/utils/common");
const pieChartPlugin = {
    name: "center_template_pie_chart",
    init: _common.noop,
    dispose: function() {
        this._centerTemplateGroup.linkOff().dispose()
    },
    extenders: {
        _createHtmlStructure() {
            const patchedFontOptions = (0, _utils.patchFontOptions)(this._themeManager._font);
            this._centerTemplateGroup = this._renderer.g().attr({
                class: "dxc-hole-template"
            }).linkOn(this._renderer.root, "center-template").css(patchedFontOptions).linkAppend()
        },
        _renderExtraElements() {
            this._requestChange(["CENTER_TEMPLATE"])
        }
    },
    members: {
        _renderCenterTemplate() {
            const template = this.option("centerTemplate");
            const centerTemplateGroup = this._centerTemplateGroup.clear();
            if (!template) {
                return
            }
            centerTemplateGroup.attr({
                visibility: "hidden"
            });
            const center = this._getCenter();
            this._getTemplate(template).render({
                model: this,
                container: centerTemplateGroup.element,
                onRendered: () => {
                    const group = centerTemplateGroup;
                    const bBox = group.getBBox();
                    const bBoxCenterX = bBox.x + bBox.width / 2;
                    const bBoxCenterY = bBox.y + bBox.height / 2;
                    group.move(center.x - bBoxCenterX, center.y - bBoxCenterY);
                    group.attr({
                        visibility: "visible"
                    })
                }
            })
        }
    },
    customize(constructor) {
        constructor.addChange({
            code: "CENTER_TEMPLATE",
            handler: function() {
                this._renderCenterTemplate()
            },
            option: "centerTemplate"
        })
    }
};
const gaugePlugin = {
    name: "center_template_gauge",
    init: _common.noop,
    dispose: pieChartPlugin.dispose,
    extenders: {
        _initCore() {
            this._createCenterTemplateGroup()
        },
        _renderContent() {
            const patchedFontOptions = (0, _utils.patchFontOptions)(this._themeManager._font);
            this._centerTemplateGroup.css(patchedFontOptions);
            this._requestChange(["CENTER_TEMPLATE"])
        },
        _updateExtraElements() {
            this._requestChange(["CENTER_TEMPLATE"])
        }
    },
    members: {
        _renderCenterTemplate: pieChartPlugin.members._renderCenterTemplate,
        _createCenterTemplateGroup() {
            this._centerTemplateGroup = this._renderer.g().attr({
                class: "dxg-hole-template"
            }).linkOn(this._renderer.root, "center-template").linkAppend()
        }
    },
    customize: pieChartPlugin.customize
};
const plugins = exports.plugins = {
    pieChart: pieChartPlugin,
    gauge: gaugePlugin
};
