/**
 * Copyright © Volker Schukai and all contributing authors, {{copyRightYear}}. All rights reserved.
 * Node module: @schukai/monster
 *
 * This source code is licensed under the GNU Affero General Public License version 3 (AGPLv3).
 * The full text of the license can be found at: https://www.gnu.org/licenses/agpl-3.0.en.html
 *
 * For those who do not wish to adhere to the AGPLv3, a commercial license is available.
 * Acquiring a commercial license allows you to use this software without complying with the AGPLv3 terms.
 * For more information about purchasing a commercial license, please contact Volker Schukai.
 *
 * SPDX-License-Identifier: AGPL-3.0
 */

import { instanceSymbol } from "../../constants.mjs";
import { registerCustomElement } from "../../dom/customelement.mjs";
import { ContextHelpStyleSheet } from "./stylesheet/context-help.mjs";
import { ContextBase } from "./context-base.mjs";

export { ContextHelp };

/**
 * A context help control.
 *
 * @fragments /fragments/components/form/context-help
 *
 * @example /examples/components/form/context-help-simple
 * @example /examples/components/form/context-help-inline-guidance
 *
 * @since 3.29.0
 * @copyright Volker Schukai
 * @summary A contextual help block for inline guidance, field descriptions and lightweight explanations.
 */
class ContextHelp extends ContextBase {
	/**
	 * This method is called by the `instanceof` operator.
	 * @return {symbol}
	 */
	static get [instanceSymbol]() {
		return Symbol.for(
			"@schukai/monster/components/form/context-help@@instance",
		);
	}

	/**
	 * To set the options via the HTML tag, the attribute `data-monster-options` must be used.
	 * @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
	 *
	 * The individual configuration values can be found in the table.
	 *
	 * @property {Object} templates - The templates for the control.
	 * @property {string} templates.main - The main template.
	 * @property {string} mode - The mode of the popper. Possible values are `click`, `enter` and `hover`.
	 * @property {string} content - The content of the popper.
	 * @property {object} popper - The popper options.
	 * @property {string} popper.placement - The placement of the popper. Possible values are `top`, `bottom`, `left`, `right`, `auto`, `auto-start`, `auto-end`, `top-start`, `top-end`, `bottom-start`, `bottom-end`, `right-start`, `right-end`, `left-start`, `left-end`.
	 * @extends {CustomControl}
	 */
	get defaults() {
		return Object.assign({}, super.defaults, {
			templates: {
				main: getTemplate(),
			},
			mode: "auto",
		});
	}

	/**
	 * @return {string}
	 */
	static getTag() {
		return "monster-context-help";
	}

	/**
	 * @return {CSSStyleSheet[]}
	 */
	static getCSSStyleSheet() {
		return [ContextHelpStyleSheet];
	}
}

/**
 * @private
 * @return {string}
 */
function getTemplate() {
	// language=HTML
	return `
        <div data-monster-role="control" part="control">
            
            <div data-monster-role="button" part="button"><svg class="hidden" 
				xmlns="http://www.w3.org/2000/svg" 
				width="1.2em" 
				height="1.2em" 
				viewBox="0 0 16 16">
                <path fill="var(--monster-color-primary-1)" 
					  d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM5.496 6.033h.825c.138 0 .248-.113.266-.25.09-.656.54-1.134 1.342-1.134.686 0 1.314.343 1.314 1.168 0 .635-.374.927-.965 1.371-.673.489-1.206 1.06-1.168 1.987l.003.217a.25.25 0 0 0 .25.246h.811a.25.25 0 0 0 .25-.25v-.105c0-.718.273-.927 1.01-1.486.609-.463 1.244-.977 1.244-2.056 0-1.511-1.276-2.241-2.673-2.241-1.267 0-2.655.59-2.75 2.286a.237.237 0 0 0 .241.247zm2.325 6.443c.61 0 1.029-.394 1.029-.927 0-.552-.42-.94-1.029-.94-.584 0-1.009.388-1.009.94 0 .533.425.927 1.01.927z"/>
            </svg></div>

            <div data-monster-role="popper" part="popper" tabindex="-1" class="monster-color-primary-1">
                <div data-monster-role="arrow"></div>
                <div part="content" class="flex">
                    <slot></slot>
                </div>
            </div>
            
        </div>
    `;
}

registerCustomElement(ContextHelp);
