@page "/Settings/Beacon"
@using LANCommander.Models;
@layout SettingsLayout
@inject SettingService SettingService
@inject IPXRelayService IPXRelayService
@inject IMessageService MessageService
@attribute [Authorize(Roles = "Administrator")]

<PageHeader Title="Beacon" />

<div style="padding: 0 24px;">
    <Form Model="Settings" Layout="@FormLayout.Vertical">
        <FormItem Label="Enable">
            <Text Type="@TextElementType.Secondary">Enabling the beacon will allow clients on the same network to auto-discover the LANCommander address.</Text>
            <Switch @bind-Checked="context.Beacon.Enabled" />
        </FormItem>

        <FormItem Label="Address">
            <Text Type="@TextElementType.Secondary">Use this to customize the address that is broadcasted to clients. Default: http://&lt;Server IP&gt;:@context.Port</Text>
            <Input @bind-Value="Settings.Beacon.Address" />
        </FormItem>

        <FormItem>
            <Button OnClick="Save" Type="@ButtonType.Primary">Save</Button>
        </FormItem>
    </Form>
</div>

@code {
    LANCommanderSettings Settings;

    protected override async Task OnInitializedAsync()
    {
        Settings = SettingService.GetSettings();
    }

    private void Save()
    {
        try
        {
            SettingService.SaveSettings(Settings);
            MessageService.Success("Settings saved!");
        }
        catch
        {
            MessageService.Error("An unknown error occurred.");
        }
    }
}
