@* Static Modbus address builder: register type + offset + length → 4x00001-4 *@
@using ZB.MOM.WW.OtOpcUa.AdminUI.Components.Shared.Drivers.Pickers

<div class="row g-3">
    <div class="col-md-4">
        <label class="form-label">Register type</label>
        <select class="form-select form-select-sm" @bind="_regType" @bind:after="OnChangedAsync">
            <option value="Coil">Coil (0x)</option>
            <option value="DiscreteInput">DiscreteInput (1x)</option>
            <option value="Input">Input (3x)</option>
            <option value="Holding">Holding (4x)</option>
        </select>
    </div>
    <div class="col-md-3">
        <label class="form-label">Offset</label>
        <input type="number" class="form-control form-control-sm" min="0" max="99999"
               @bind="_offset" @bind:after="OnChangedAsync" />
    </div>
    <div class="col-md-3">
        <label class="form-label">Length</label>
        <input type="number" class="form-control form-control-sm" min="1" max="125"
               @bind="_length" @bind:after="OnChangedAsync" />
    </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 _regType = "Holding";
    private int _offset = 1;
    private int _length = 1;
    private string _built = "";

    protected override void OnInitialized()
    {
        _built = ModbusAddressBuilder.Build(_regType, _offset, _length);
        _ = CurrentAddressChanged.InvokeAsync(_built);
    }

    private async Task OnChangedAsync()
    {
        _built = ModbusAddressBuilder.Build(_regType, _offset, _length);
        await CurrentAddressChanged.InvokeAsync(_built);
    }
}
