@page "/select-bar-test"

<RadzenDataGrid Data="@Items" TItem="GridItem">
    <HeaderTemplate>
        <RadzenStack AlignItems="AlignItems.Center">
            <RadzenSelectBar TValue="int" Size="ButtonSize.Small" @bind-Value="@SelectedAnimal">
                <Items>
                    <RadzenSelectBarItem Value="1" Text="Cat " Disabled="@_disableCat" />
                    <RadzenSelectBarItem Value="2" Text="Birds" />
                </Items>
            </RadzenSelectBar>
        </RadzenStack>
    </HeaderTemplate>
    <Columns>
        <RadzenDataGridColumn Title="Name" Property="Name" />
        <RadzenDataGridColumn Title="Action">
            <Template Context="data">
                <RadzenStack  Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center" JustifyContent="JustifyContent.Center">
                    <RadzenSelectBar TValue="int" Size="ButtonSize.Small" @bind-Value="@data.Action" Change="() => CheckHeader()">
                        <Items>
                            <RadzenSelectBarItem Value="1" Text="Eats food" />
                            <RadzenSelectBarItem Value="2" Text="drinks water" />
                            <RadzenSelectBarItem Value="3" Text="flaps wings" />
                        </Items>
                    </RadzenSelectBar>
                </RadzenStack>
            </Template>
        </RadzenDataGridColumn>
    </Columns>
</RadzenDataGrid>

@code {
    public List<GridItem> Items { get; private set; }
    public int SelectedAnimal { get; private set; }

    private const int _flapsWingsAction = 3;
    private const int _birdAnimal = 2;

    private bool _disableCat;

    protected override void OnInitialized()
    {
        Items = new List<GridItem>
        {
            new() { Name = "Animal Action", Action = 1 },
            new() { Name = "Animal Action", Action = 2 }
        };
    }

    private void CheckHeader()
    {
        _disableCat = false;
        if (Items.Any(x => x.Action == _flapsWingsAction))
        {
            _disableCat = true;
            SelectedAnimal = _birdAnimal;
        }
    }

    public class GridItem
    {
        public string Name { get; set; }
        public int Action { get; set; }
    }
}