/**
 * 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 { Base } from "../../../types/base.mjs";
import { validateString } from "../../../types/validate.mjs";

export { State, getStateInstanceFor };

/**
 * @private
 * @type {symbol}
 */
const internalSymbol = Symbol("internalSymbol");

/**
 * This State class represent a State with presentation
 *
 * @since 1.5.0
 * @copyright Volker Schukai
 */
class State extends Base {
	/**
	 *
	 * @param {string} state
	 * @param {string} presentation
	 * @throws {TypeError} value is not a string
	 */
	constructor(state, presentation) {
		super();
		this[internalSymbol] = {};
		this[internalSymbol].state = validateString(state);
		this[internalSymbol].presentation = validateString(presentation);
	}

	/**
	 * @property {String} state
	 */
	get state() {
		return this[internalSymbol].state;
	}

	/**
	 * @property {String} presentation
	 */
	get presentation() {
		return this[internalSymbol].presentation;
	}

	/**
	 * @return {Monster.Components.Form.Types.State}
	 */
	getClone() {
		return new State(
			this[internalSymbol].state,
			this[internalSymbol].presentation,
		);
	}
}

/**
 * @since 1.5.0
 * @param state
 * @return {Monster.Components.Form.Types.State}
 */
function getStateInstanceFor(state) {
	switch (state) {
		case "stateless":
			return new State("stateless", "");
		case "successful":
			return new State(
				"successful",
				'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="successful" viewBox="0 0 16 16"><path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"/><path d="M10.97 4.97a.235.235 0 0 0-.02.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-1.071-1.05z"/></svg>',
			);
		case "activity":
			return new State(
				"activity",
				'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="activity" viewBox="0 0 16 16"><circle cx="8" cy="8" r="8"/></svg>',
			);
		case "failed": // https://icons.getbootstrap.com/icons/exclamation-circle/
			return new State(
				"failed",
				'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="failed" viewBox="0 0 16 16"><path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"/><path d="M7.002 11a1 1 0 1 1 2 0 1 1 0 0 1-2 0zM7.1 4.995a.905.905 0 1 1 1.8 0l-.35 3.507a.552.552 0 0 1-1.1 0L7.1 4.995z"/></svg>',
			);
		default:
			return new State(state, "");
	}
}
