﻿
using HutongGames.PlayMaker;

namespace SRDebugger.Playmaker.Actions
{

	[ActionCategory("SRDebugger")]
	[Tooltip("Show the bug reporter sheet. Can optionally populate the description field with custom data.")]
	public class BugReportSheet : FsmStateAction
	{

		[Tooltip("Event to send once the user has completed the bug report process.")]
		public FsmEvent onSuccess;

		[Tooltip("Event to send once if user has cancelled or an error occured.")]
		public FsmEvent onCancel;

		[UIHint(UIHint.Variable)]
		[Tooltip("Store the success state in a bool variable.")]
		public FsmBool storeSuccessResult;


		[Tooltip("String to populate the description field with.")]
		public FsmString message;

		[Tooltip("Set to true to take a screenshot before the bug report sheet opens. Otherwise it will be captured just before sending the bug report.")]
		public FsmBool takeScreenshotNow;

		public override void Reset()
		{
			base.Reset();
			onSuccess = null;
			onCancel = null;
			message = null;
		}

		public override void OnEnter()
		{
			var description = message.Value;
			var takeScreenshot = takeScreenshotNow.Value;

			SRDebug.Instance.ShowBugReportSheet(success => {
				
				Fsm.Event(success ? onSuccess : onCancel);
				storeSuccessResult.Value = success;

			}, takeScreenshot, description);
		}

	}

}