using CefSharp;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FOW0000
{
    public partial class fHappyNarae : Form
    {
        public fHappyNarae()
        {
            InitializeComponent();
            this.wb1.FrameLoadEnd += Wb1_FrameLoadEnd;
            this.wb1.AddressChanged += Wb1_AddressChanged;
            this.wb1.StatusMessage += Wb1_StatusMessage;
        }

        private void Wb1_StatusMessage(object sender, StatusMessageEventArgs e)
        {
            sbstat.Text = e.Value;
        }

        private void Wb1_AddressChanged(object sender, AddressChangedEventArgs e)
        {
            sburl.Text = e.Address;
        }


        private void Wb1_FrameLoadEnd(object sender, FrameLoadEndEventArgs e)
        {
            Console.WriteLine("Frame End : " + e.Url); ;
            //if (e.Url.Contains("logfail.jsp?LoginDNS=null"))
            //{
            //    var frame = this.wb1.GetMainFrame();
            //    var visitor = new SourceVisitor((text) =>
            //    {
            //        BeginInvoke(new Action(() =>
            //        {
            //            MessageBox.Show(text.Substring(0, 100));
            //        }));
            //    });

            //    frame.GetSource(visitor);
            //}
        }
        //public class SourceVisitor : IStringVisitor
        //{
        //    private readonly Action<string> _callback;

        //    public SourceVisitor(Action<string> callback)
        //    {
        //        _callback = callback;
        //    }

        //    public override void Visit(string value)
        //    {
        //        _callback(value);
        //    }
        //    public override Dispose()
        //    {

        //    }
        //}


        private void fHappyNarae_Load(object sender, EventArgs e)
        {
            wb1.Load("https://www.happynarae.com/fullsize/frist_web/logfail.jsp?LoginDNS=null");
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            wb1.Load("https://www.happynarae.com/fullsize/frist_web/logfail.jsp?LoginDNS=null");
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            var script = "f_sub_menu_click(&quot;/havis/havis_custom/202auth/order/cust_order_05.jsp&quot;,&quot;/havis/fullsize/help_desk/202auth/main/cust_order_05.html&quot;,&quot;3&quot;);";
            script = script.Replace("&quot;", "\"");
            var command = string.Format(script);
            this.wb1.GetMainFrame().ExecuteJavaScriptAsync(command);
        }
    }
}
