@* Static Wonderware Historian address builder: tag name + retrieval mode + interval
   → MyTag?mode=Cyclic&interval=60 *@
@using ZB.MOM.WW.OtOpcUa.AdminUI.Components.Shared.Drivers.Pickers

<div class="row g-3">
    <div class="col-md-4">
        <label class="form-label">Tag name</label>
        <input type="text" class="form-control form-control-sm mono" placeholder="SysTimeHour"
               @bind="_tagName" @bind:after="OnChangedAsync" />
    </div>
    <div class="col-md-3">
        <label class="form-label">Retrieval mode</label>
        <select class="form-select form-select-sm" @bind="_mode" @bind:after="OnChangedAsync">
            <option value="Last">Last</option>
            <option value="Cyclic">Cyclic</option>
            <option value="Delta">Delta</option>
        </select>
    </div>
    <div class="col-md-3">
        <label class="form-label">Interval (seconds)</label>
        <input type="number" class="form-control form-control-sm" min="1"
               @bind="_interval" @bind:after="OnChangedAsync" />
        <div class="form-text">Polling/retrieval interval.</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 _tagName = "";
    private string _mode = "Cyclic";
    private int _interval = 60;
    private string _built = "";

    protected override void OnInitialized()
    {
        _built = string.IsNullOrWhiteSpace(_tagName) ? "" : HistorianWonderwareAddressBuilder.Build(_tagName, _mode, _interval);
        _ = CurrentAddressChanged.InvokeAsync(_built);
    }

    private async Task OnChangedAsync()
    {
        _built = string.IsNullOrWhiteSpace(_tagName) ? "" : HistorianWonderwareAddressBuilder.Build(_tagName, _mode, _interval);
        await CurrentAddressChanged.InvokeAsync(_built);
    }
}
