using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using System.Net.Http;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Components.Routing;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.Web.Virtualization;
using Microsoft.JSInterop;
using TestingApp;
using TestingApp.Shared;
using Telerik.Blazor;
using Telerik.Blazor.Components;

namespace TestingApp.Pages
{
    

    public partial class CopyNPasteTest
    {
        string stringValue { get; set; }
        string strAppMsg = "Hold";
        private bool blnHideMe { get; set; } = true;
        private bool blnHideGrid { get; set; } = true;
        private bool blnHideBtn { get; set; } = true;
        bool ExportAllPages { get; set; }
        public List<string> ExportColumns { get; set; } = new List<string>();
        public bool CancelExport { get; set; }

        TelerikTextBox txtBxRefSearchValue { get; set; }
        TelerikTextArea AppMsgBOX { get; set; }
        bool ldrVisible { get; set; }

        private List<string> GridData { get; set; }

        protected override async void OnInitialized()
        {
            base.OnInitialized();
            strAppMsg = "I am in TN Search!";
            blnHideGrid = true;
        }

        async Task SearchNow_OnClickHandler()
        {
            //strAppMsg = "This be an app msg: You clicked my Search Now Button!";
            //setAppMsg();

            ldrVisible = true;
            await Task.Delay(1);
            // await getData();
            ldrVisible = false;

            blnHideGrid = false;
        }

        public async Task onSearchValueChange(KeyboardEventArgs e)
        {
            await Task.Delay(1);  // needed according to Telerik to capture that first character

            // Note! it has no value on the first character, NULL, but once 2nd one typed in tis good to go.
            if (stringValue is not null)
            {
                if (stringValue.Length > 0)
                {
                    blnHideBtn = false;
                }
                else
                {
                    blnHideBtn = true;
                };
            };


        }

        private void setAppMsg()
        {
            if (blnHideMe == true)
            {
                blnHideMe = false;
            }
            else
            {
                blnHideMe = true;
            };

        }

        public void OnBeforeExcelExport(GridBeforeExcelExportEventArgs args)
        {
            if (ExportColumns.Any())
            {
                args.Columns = args.Columns.Where(col => ExportColumns.Contains(col.Field)).ToList();
            }

            args.IsCancelled = CancelExport;
        }

        public void OnRowClickHandler(GridRowClickEventArgs args)
        {
            //   Int64 intCustID = ((SodaTools.Data.TNSearchResult)args.Item).CustID;
            Int64 intCustID = 0;

            if (intCustID > 0)
            {
                strAppMsg = "I have got the CustID from the Row: " + intCustID.ToString();
                setAppMsg();
                string strURL = "https://spectrotel.rev.io/Customers/Customer_Profile.aspx?Customer_ID=" + intCustID.ToString();
          //      JSRuntime.InvokeVoidAsync("open", strURL, "_blank");
            };
        }
    }
}