@page "/setting/auto-number-sequence"
@using Indotalent.Features.Setting.AutoNumberSequence.Cqrs
@using MudBlazor

@if (_isShowingForm)
{
    <_AutoNumberSequenceForm ExistingData="_selectedData"
                             ReadOnly="_isReadOnly"
                             OnCancel="BackToTable"
                             OnSuccess="HandleSuccess" />
}
else
{
    <_AutoNumberSequenceDataTable OnEdit="(item) => ShowForm(item, false)"
                                  OnView="(item) => ShowForm(item, true)" />
}

@code {
    private bool _isShowingForm = false;
    private bool _isReadOnly = false;
    private GetAutoNumberSequenceListResponse? _selectedData;

    private void ShowForm(GetAutoNumberSequenceListResponse data, bool readOnly)
    {
        _selectedData = data;
        _isReadOnly = readOnly;
        _isShowingForm = true;
    }

    private void BackToTable()
    {
        _isShowingForm = false;
        _selectedData = null;
        _isReadOnly = false;
    }

    private void HandleSuccess()
    {
        _isShowingForm = false;
        _selectedData = null;
        _isReadOnly = false;
    }
}