@* Galaxy device form — informational only. Galaxy connects to a single mxaccessgw gateway configured on
   the driver, so there is no per-device connection endpoint to author. The DeviceConfig is round-tripped
   verbatim (Test-connect uses the driver's gateway settings via the merged config). *@
@using ZB.MOM.WW.OtOpcUa.AdminUI.Components.Shared.Drivers.DeviceForms

<section class="panel notice rise" style="animation-delay:.04s">
    <div class="panel-head">Connection</div>
    <div style="padding:1rem" class="text-muted">
        Galaxy connects to a single <strong>mxaccessgw</strong> gateway configured on the driver — there is
        no per-device endpoint to author here. Edit the gateway endpoint / API key on the driver's config.
    </div>
</section>

@code {
    /// <summary>The device's DeviceConfig JSON (round-tripped verbatim — Galaxy has no per-device endpoint).</summary>
    [Parameter] public string DeviceConfigJson { get; set; } = "{}";
    /// <summary>Fired when the (preserved) DeviceConfig changes — no-op UI, kept for the modal contract.</summary>
    [Parameter] public EventCallback<string> DeviceConfigJsonChanged { get; set; }

    private GalaxyDeviceModel _model = new();
    private string? _lastParsed;

    protected override void OnParametersSet()
    {
        if (!string.Equals(_lastParsed, DeviceConfigJson, StringComparison.Ordinal))
        {
            _model = GalaxyDeviceModel.FromJson(DeviceConfigJson);
            _lastParsed = DeviceConfigJson;
        }
    }

    /// <summary>Serializes the (preserved) DeviceConfig JSON.</summary>
    public string GetConfigJson() => _model.ToJson();
}
