using AntDesign;
using AntDesign.TableModels;
using Microsoft.AspNetCore.Components.Web;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace wispro.sp.web.Pages
{
    public partial class CustomerList
    {
        private List<entity.Customer> _Customers =new List<entity.Customer>()
            {
                new entity.Customer()
                {
                    Id=1,
                    Name = "OPPO广东移动通信有限公司",
                    Address="广东省东莞市长安镇乌沙海滨路18号",
                    Phone="4001-666-888",
                    ContactMan="刘波",
                    ResponseMan= new entity.Staff(){Name ="钟子敏",Id =1},
                    ResponseManId= 1
},
                new entity.Customer()
                {
                    Id = 2,
                    Name = "OPPO广东移动通信有限公司",
                    Address = "广东省东莞市长安镇乌沙海滨路18号",
                    Phone = "4001-666-888",
                    ContactMan = "刘波",
                    ResponseMan= new entity.Staff(){Name ="钟子敏",Id =1},
                    ResponseManId= 1
                },
                new entity.Customer()
                {
                    Id = 3,
                    Name = "OPPO广东移动通信有限公司",
                    Address = "广东省东莞市长安镇乌沙海滨路18号",
                    Phone = "4001-666-888",
                    ContactMan = "刘波",
                    ResponseMan= new entity.Staff(){Name ="钟子敏",Id =1},
                    ResponseManId= 1
                },
                new entity.Customer()
                {
                    Id = 4,
                    Name = "OPPO广东移动通信有限公司",
                    Address = "广东省东莞市长安镇乌沙海滨路18号",
                    Phone = "4001-666-888",
                    ContactMan = "刘波",
                    ResponseMan= new entity.Staff(){Name ="钟子敏",Id =1},
                    ResponseManId= 1
                },
                new entity.Customer()
                {
                    Id = 5,
                    Name = "OPPO广东移动通信有限公司",
                    Address = "广东省东莞市长安镇乌沙海滨路18号",
                    Phone = "4001-666-888",
                    ContactMan = "刘波",
                    ResponseMan= new entity.Staff(){Name ="钟子敏",Id =1},
                    ResponseManId= 1
                },
                new entity.Customer()
                {
                    Id = 6,
                    Name = "OPPO广东移动通信有限公司",
                    Address = "广东省东莞市长安镇乌沙海滨路18号",
                    Phone = "4001-666-888",
                    ContactMan = "刘波",
                    ResponseMan= new entity.Staff(){Name ="钟子敏",Id =1},
                    ResponseManId= 1
                },
                new entity.Customer()
                {
                    Id = 7,
                    Name = "OPPO广东移动通信有限公司",
                    Address = "广东省东莞市长安镇乌沙海滨路18号",
                    Phone = "4001-666-888",
                    ContactMan = "刘波",
                    ResponseMan= new entity.Staff(){Name ="钟子敏",Id =1},
                    ResponseManId= 1
                },
                new entity.Customer()
                {
                    Id = 8,
                    Name = "OPPO广东移动通信有限公司",
                    Address = "广东省东莞市长安镇乌沙海滨路18号",
                    Phone = "4001-666-888",
                    ContactMan = "刘波",
                    ResponseMan= new entity.Staff(){Name ="钟子敏",Id =1},
                    ResponseManId= 1
                },
                new entity.Customer()
                {
                    Id = 9,
                    Name = "OPPO广东移动通信有限公司",
                    Address = "广东省东莞市长安镇乌沙海滨路18号",
                    Phone = "4001-666-888",
                    ContactMan = "刘波",
                    ResponseMan= new entity.Staff(){Name ="钟子敏",Id =1},
                    ResponseManId= 1
                },
                new entity.Customer()
                {
                    Id = 10,
                    Name = "OPPO广东移动通信有限公司",
                    Address = "广东省东莞市长安镇乌沙海滨路18号",
                    Phone = "4001-666-888",
                    ContactMan = "刘波",
                    ResponseMan= new entity.Staff(){Name ="钟子敏",Id =1},
                    ResponseManId= 1
                },
                new entity.Customer()
                {
                    Id = 11,
                    Name = "OPPO广东移动通信有限公司",
                    Address = "广东省东莞市长安镇乌沙海滨路18号",
                    Phone = "4001-666-888",
                    ContactMan = "刘波",
                    ResponseMan= new entity.Staff(){Name ="钟子敏",Id =1},
                    ResponseManId= 1
                },
                new entity.Customer()
                {
                    Id = 12,
                    Name = "OPPO广东移动通信有限公司",
                    Address = "广东省东莞市长安镇乌沙海滨路18号",
                    Phone = "4001-666-888",
                    ContactMan = "刘波",
                    ResponseMan= new entity.Staff(){Name ="钟子敏",Id =1},
                    ResponseManId= 1
                },
                new entity.Customer()
                {
                    Id = 13,
                    Name = "OPPO广东移动通信有限公司",
                    Address = "广东省东莞市长安镇乌沙海滨路18号",
                    Phone = "4001-666-888",
                    ContactMan = "刘波",
                    ResponseMan= new entity.Staff(){Name ="钟子敏",Id =1},
                    ResponseManId= 1
                },
                new entity.Customer()
                {
                    Id = 14,
                    Name = "OPPO广东移动通信有限公司",
                    Address = "广东省东莞市长安镇乌沙海滨路18号",
                    Phone = "4001-666-888",
                    ContactMan = "刘波",
                    ResponseMan= new entity.Staff(){Name ="钟子敏",Id =1},
                    ResponseManId= 1
                },
                new entity.Customer()
                {
                    Id = 15,
                    Name = "OPPO广东移动通信有限公司",
                    Address = "广东省东莞市长安镇乌沙海滨路18号",
                    Phone = "4001-666-888",
                    ContactMan = "刘波",
                    ResponseMan= new entity.Staff(){Name ="钟子敏",Id =1},
                    ResponseManId= 1
                },
                new entity.Customer()
                {
                    Id = 16,
                    Name = "OPPO广东移动通信有限公司",
                    Address = "广东省东莞市长安镇乌沙海滨路18号",
                    Phone = "4001-666-888",
                    ContactMan = "刘波",
                    ResponseMan= new entity.Staff(){Name ="钟子敏",Id =1},
                    ResponseManId= 1
                },
                new entity.Customer()
                {
                    Id = 17,
                    Name = "OPPO广东移动通信有限公司",
                    Address = "广东省东莞市长安镇乌沙海滨路18号",
                    Phone = "4001-666-888",
                    ContactMan = "刘波",
                   ResponseMan= new entity.Staff(){Name ="钟子敏",Id =1},
                    ResponseManId= 1
                },
                new entity.Customer()
                {
                    Id = 18,
                    Name = "OPPO广东移动通信有限公司",
                    Address = "广东省东莞市长安镇乌沙海滨路18号",
                    Phone = "4001-666-888",
                    ContactMan = "刘波",
                    ResponseMan= new entity.Staff(){Name ="钟子敏",Id =1},
                    ResponseManId= 1
                }
            };

        IEnumerable<entity.Customer> selectedRows;
        ITable table;

        int _pageIndex = 1;
        int _pageSize = 10;
        int _total = 0;
        bool _loading = false;

        entity.Customer Editing = null;
        bool _visible = false;
        bool _isAdd = false;



        protected override void OnInitialized()
        {

            _loading = true;

            //await System.Threading.Thread.Sleep();
            //List<wispro.sp.entity.StaffGrade> data = await Http.GetFromJsonAsync<List<wispro.sp.entity.StaffGrade>>($"http://localhost:39476/api/StaffGrade/GetAll");

            _loading = false;
            _total = _Customers.Count;

        }

        private void HandlePageChange(PaginationEventArgs args)
        {
            if (_pageIndex != args.Page)
            {
                _pageIndex = args.Page;
            }

            if (_pageSize != args.PageSize)
            {
                _pageSize = args.PageSize;
            }
        }


        Dictionary<string, object> OnRow(RowData<entity.Customer> row)
        {
            Dictionary<string, object> ret = new Dictionary<string, object>();

            ret.Add("id", row.Data.Id);
            ret.Add("onclick", ((Action)delegate
            {
            //_message.Info($"row {row.Data.Grade} was clicked");
        }));


            return ret;
        }

        public void RemoveSelection(int id)
        {
            //var selected = selectedRows.Where(x => x.Id != id);
            //selectedRows = selected;
        }

        private void Delete(int id)
        {
            var DelCustumer = _Customers.Where(x => x.Id == id).FirstOrDefault<entity.Customer>();

            if (DelCustumer != null)
            {
                Editing = DelCustumer;
                _isAdd = false;
                _visible = true;
            }
            else
            {

            }
            _total = _Customers.Count;
        }

        private void Edit(int id)
        {
            Editing = _Customers.Where(x => x.Id == id).FirstOrDefault<entity.Customer>();

            if (Editing != null)
            {
                _isAdd = false;
                _visible = true;
            }
            else
            {

            }
            _total = _Customers.Count;
        }

        private void AddNew()
        {
            Editing = new entity.Customer();
            //_isAdd = true;
            _visible = true;
        }

        private async Task HandleOk(MouseEventArgs e)
        {

            //var data = await Http.PostAsJsonAsync<wispro.sp.entity.StaffGrade>($"http://localhost:39476/api/StaffGrade/Save", EditingStaff);

            //if (data.IsSuccessStatusCode)
            //{
            //    ApiSaveResponse result = await data.Content.ReadFromJsonAsync<ApiSaveResponse>();
            //    await Task.Delay(1000);

            //    if (result.Success)
            //    {
            //        await _message.Success("数据已保存!");
            //    }
            //    else
            //    {
            //        await _message.Error($"{result.ErrorMessage}");
            //    }

            //}
            //else
            //{
            //    await _message.Error($"请求发生错误 {data.StatusCode}");
            //}

            _visible = false;
        }

        private void HandleCancel(MouseEventArgs e)
        {
            Console.WriteLine(e);
            _visible = false;
        }
    }
}
