using DevExpress.Blazor;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TIAMSharedUI.Shared.AcComponents;

namespace TIAMSharedUI.Shared.Components
{
    public class TiamDxGridBase<T> : AcDxGridBase<T>
    {
        [Parameter]
        public new IEnumerable<T>? Data { get; set; }
        [Parameter]
        public RenderFragment? ChildContent { get; set; }
        [Parameter]
        public Dictionary<string, object>? Settings { get; set; }
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            builder.OpenComponent<DxGrid>(0);
            builder.AddAttribute(1, "Data", Data);
            builder.AddAttribute(2, "Columns", ChildContent);
            if (Settings != null)
            {
                builder.AddMultipleAttributes(3, Settings);
                //OR
                //int seq = 3;
                //foreach (var item in Settings) {
                //    builder.AddAttribute(seq++, item.Key, item.Value);
                //}
            }
            builder.CloseComponent();
        }
    }
}
