@* Static AB Legacy address builder: file type + file number + element → N7:0 *@
@using ZB.MOM.WW.OtOpcUa.AdminUI.Components.Shared.Drivers.Pickers

<div class="row g-3">
    <div class="col-md-3">
        <label class="form-label">File type</label>
        <select class="form-select form-select-sm" @bind="_fileType" @bind:after="OnChangedAsync">
            <option value="N">N — Integer</option>
            <option value="B">B — Binary/Bit</option>
            <option value="F">F — Float</option>
            <option value="I">I — Input</option>
            <option value="O">O — Output</option>
            <option value="S">S — Status</option>
            <option value="T">T — Timer</option>
            <option value="C">C — Counter</option>
            <option value="R">R — Control</option>
        </select>
    </div>
    <div class="col-md-3">
        <label class="form-label">File number</label>
        <input type="number" class="form-control form-control-sm" min="0" max="999"
               @bind="_fileNumber" @bind:after="OnChangedAsync" />
        <div class="form-text">e.g. 7 for N7</div>
    </div>
    <div class="col-md-3">
        <label class="form-label">Element</label>
        <input type="number" class="form-control form-control-sm" min="0" max="9999"
               @bind="_element" @bind:after="OnChangedAsync" />
        <div class="form-text">e.g. 0 for N7:0</div>
    </div>
</div>

<div class="mt-3">
    <span class="text-muted small">Result:</span>
    <code class="mono ms-2">@_built</code>
</div>

@code {
    [Parameter] public string CurrentAddress { get; set; } = "";
    [Parameter] public EventCallback<string> CurrentAddressChanged { get; set; }

    private string _fileType = "N";
    private int _fileNumber = 7;
    private int _element = 0;
    private string _built = "";

    protected override void OnInitialized()
    {
        _built = AbLegacyAddressBuilder.Build(_fileType, _fileNumber, _element);
        _ = CurrentAddressChanged.InvokeAsync(_built);
    }

    private async Task OnChangedAsync()
    {
        _built = AbLegacyAddressBuilder.Build(_fileType, _fileNumber, _element);
        await CurrentAddressChanged.InvokeAsync(_built);
    }
}
