internal async Task TabRenderCompletedAsync(BTabPanel tabPanel)
 {
     if (OnRenderCompleted != null)
     {
         await OnRenderCompleted(tabPanel);
     }
 }
        internal async Task CloseTabAsync(BTabPanel tab)
        {
            if (OnTabClosing.HasDelegate)
            {
                var arg = new BClosingEventArgs <BTabPanel>();
                arg.Target = tab;
                await OnTabClosing.InvokeAsync(arg);

                if (arg.Cancel)
                {
                    return;
                }
            }

            ResetActiveTab(tab);
            RequireRender = true;
            if (OnTabClose.HasDelegate)
            {
                _ = OnTabClose.InvokeAsync(tab);
            }
            else
            {
                StateHasChanged();
            }
        }
        internal void AddTab(BTabPanel tab)
        {
            if (Exists(tab.Name))
            {
                return;
            }

            Console.WriteLine(tab.Title);
            tabPanels.Add(tab);
        }
        internal async Task UpdateHeaderSizeAsync(BTabPanel tabPanel, float barWidth, float barOffsetLeft)
        {
            if (headerSizeUpdated)
            {
                await TabRenderCompletedAsync(tabPanel);

                return;
            }
            headerSizeUpdated = true;
            BarWidth          = barWidth;
            BarOffsetLeft     = barOffsetLeft;
            RequireRender     = true;
            StateHasChanged();
        }
        internal async Task <bool> SetActivateTabAsync(BTabPanel tab)
        {
            if (OnActiveTabChanging.HasDelegate)
            {
                var arg = new BChangeEventArgs <BTabPanel>();
                arg.NewValue = tab;
                arg.OldValue = ActiveTab;
                await OnActiveTabChanging.InvokeAsync(arg);

                if (arg.DisallowChange)
                {
                    return(false);
                }
            }
            if (DataSource == null)
            {
                foreach (var tabPanel in tabPanels)
                {
                    if (tabPanel == tab)
                    {
                        tabPanel.Activate();
                        continue;
                    }
                    tabPanel.DeActivate();
                }
            }
            else
            {
                foreach (var item in DataSource)
                {
                    item.IsActive = item.Name == tab.Name;
                }
            }
            ActiveTab = tab;
            var eventArgs = new BChangeEventArgs <BTabPanel>();

            eventArgs.OldValue = ActiveTab;
            eventArgs.NewValue = tab;
            RequireRender      = true;
            if (OnActiveTabChanged.HasDelegate)
            {
                await OnActiveTabChanged.InvokeAsync(eventArgs);
            }
            else
            {
                StateHasChanged();
            }
            return(true);
        }
        private TabOption ResetActiveTab(BTabPanel tab)
        {
            if (DataSource == null)
            {
                return(null);
            }
            if (DataSource.Count <= 0)
            {
                return(null);
            }
            var activeOption = DataSource.FirstOrDefault(x => x.IsActive);
            var activeIndex  = DataSource.IndexOf(activeOption);

            if (activeOption.Title != tab.Title)
            {
                var removingIndex = DataSource.IndexOf(DataSource.FirstOrDefault(x => x.Name == tab.Name));
                DataSource.RemoveAt(removingIndex);
                if (activeIndex > removingIndex)
                {
                    activeIndex--;
                }
                return(activeOption);
            }
            DataSource.RemoveAt(activeIndex);
            var newActiveIndex = activeIndex;

            if (newActiveIndex >= DataSource.Count - 1)
            {
                newActiveIndex = DataSource.Count - 1;
            }
            if (newActiveIndex == -1)
            {
                return(null);
            }
            activeOption          = DataSource.ElementAt(newActiveIndex);
            activeOption.IsActive = true;
            return(activeOption);
        }