//*******************************************************************************
// Copyright (c) 2021 Cognex Corporation. All Rights Reserved
//*******************************************************************************

using Microsoft.Web.WebView2.WinForms;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cognex.InSight.WebAPI
{
  public abstract class HmiWebPageInterop
  {
    public static async Task<string> getSessionID(WebView2 webView)
    {
      object jObj = await webView.CoreWebView2.ExecuteScriptAsync("window.ResourceManager.TagManager._subscriptionGroupId");
      string sessionID = jObj.ToString();
      sessionID = sessionID.Trim('\"');
      return sessionID;
    }

    public static async Task<JToken> getResultsFromDisplay(WebView2 webView)
    {
      JToken results = null;
      string strObj = "null";
      object jObj = await webView.CoreWebView2.ExecuteScriptAsync("window.ResourceManager.TagManager._adapter.CurrentHmiResults");
      strObj = jObj.ToString();
      if (strObj != "null")
      {
        results = JObject.Parse(strObj);
      }
      return results;
    }
  }
}
