package com.imyeyu.fx.ui.components.alert;

import com.imyeyu.fx.ui.TimiFXUI;
import javafx.geometry.HPos;
import javafx.scene.control.Button;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 弹窗按钮
 *
 * @author 夜雨
 * @since 2022-01-07 09:37
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class AlertButton extends Button {

	/**
	 * 按钮通用动作，用于标记，具体事件由调用决定
	 *
	 * @author 夜雨
	 * @since 2022-01-20 00:55
	 */
	public enum Action {

		/** 同意 */
		APPLY,

		/** 好 */
		OK,

		/** 取消 */
		CANCEL,

		/** 关闭 */
		CLOSE,

		/** 确认 */
		CONFIRM,

		/** 是 */
		YES,

		/** 否 */
		NO,

		/** 完成 */
		FINISH,

		/** 上一步 */
		PREVIOUS,

		/** 下一步 */
		NEXT,

		/** 跳过 */
		SKIP,

		/** 保存 */
		SAVE,

		/** 用于自定义事件 */
		OTHER
	}

	/** 按钮所属位置 */
	HPos pos;

	/** 按钮动作 */
	Action action;

	/**
	 * 弹窗按钮构造器
	 *
	 * @param text 文本
	 */
	public AlertButton(String text) {
		this(HPos.CENTER, Action.OK, text);
	}

	/**
	 * 弹窗按钮构造器
	 *
	 * @param pos    位置
	 * @param action 动作
	 * @param text   文本
	 */
	public AlertButton(HPos pos, Action action, String text) {
		super(text);
		this.pos = pos;
		this.action = action;
	}

	/**
	 * 快速构造应用按钮
	 *
	 * @return 应用按钮
	 */
	public static AlertButton apply() {
		return new AlertButton(HPos.RIGHT, Action.APPLY, TimiFXUI.MULTILINGUAL.text("alert.apply", "应用"));
	}

	/**
	 * 快速构造明确按钮
	 *
	 * @return 明确按钮
	 */
	public static AlertButton ok() {
		return new AlertButton(HPos.RIGHT, Action.OK, TimiFXUI.MULTILINGUAL.text("alert.ok", "好"));
	}

	/**
	 * 快速构造取消按钮
	 *
	 * @return 取消按钮
	 */
	public static AlertButton cancel() {
		return new AlertButton(HPos.RIGHT, Action.CANCEL, TimiFXUI.MULTILINGUAL.text("alert.cancel", "取消"));
	}

	/**
	 * 快速构造关闭按钮
	 *
	 * @return 关闭按钮
	 */
	public static AlertButton close() {
		return new AlertButton(HPos.RIGHT, Action.CLOSE, TimiFXUI.MULTILINGUAL.text("alert.close", "关闭"));
	}

	/**
	 * 快速构造确认按钮
	 *
	 * @return 确认按钮
	 */
	public static AlertButton confirm() {
		return new AlertButton(HPos.RIGHT, Action.CONFIRM, TimiFXUI.MULTILINGUAL.text("alert.confirm", "确认"));
	}

	/**
	 * 快速构造确定按钮
	 *
	 * @return 确定按钮
	 */
	public static AlertButton yes() {
		return new AlertButton(HPos.RIGHT, Action.YES, TimiFXUI.MULTILINGUAL.text("alert.yes", "是"));
	}

	/**
	 * 快速构造否定按钮
	 *
	 * @return 否定按钮
	 */
	public static AlertButton no() {
		return new AlertButton(HPos.RIGHT, Action.NO, TimiFXUI.MULTILINGUAL.text("alert.no", "否"));
	}

	/**
	 * 快速构造完成按钮
	 *
	 * @return 完成按钮
	 */
	public static AlertButton finish() {
		return new AlertButton(HPos.RIGHT, Action.FINISH, TimiFXUI.MULTILINGUAL.text("alert.finish", "完成"));
	}

	/**
	 * 快速构造上一步按钮
	 *
	 * @return 上一步按钮
	 */
	public static AlertButton previous() {
		return new AlertButton(HPos.RIGHT, Action.PREVIOUS, TimiFXUI.MULTILINGUAL.text("alert.previous", "上一步"));
	}

	/**
	 * 快速构造下一步按钮
	 *
	 * @return 下一步按钮
	 */
	public static AlertButton next() {
		return new AlertButton(HPos.RIGHT, Action.NEXT, TimiFXUI.MULTILINGUAL.text("alert.next", "下一步"));
	}

	/**
	 * 快速构造跳过按钮
	 *
	 * @return 跳过按钮
	 */
	public static AlertButton skip() {
		return new AlertButton(HPos.RIGHT, Action.SKIP, TimiFXUI.MULTILINGUAL.text("alert.skip", "跳过"));
	}

	/**
	 * 快速构造保存按钮
	 *
	 * @return 保存按钮
	 */
	public static AlertButton save() {
		return new AlertButton(HPos.RIGHT, Action.SAVE, TimiFXUI.MULTILINGUAL.text("alert.save", "保存"));
	}
}
