@namespace [Owner].Module.[Module]
@inherits ModuleBase
@inject ISettingService SettingService
@inject IStringLocalizer<Settings> Localizer

<div class="container">
    <div class="row mb-1 align-items-center">
        <Label Class="col-sm-3" For="value" HelpText="Enter a value" ResourceKey="SettingName" ResourceType="@resourceType">Name: </Label>
            <div class="col-sm-9">
                <input id="value" type="text" class="form-control" @bind="@_value" />
            </div>
    </div>
</div>

@code {
    private string resourceType = "[Owner].Module.[Module].Settings, [Owner].Module.[Module].Client.Oqtane"; // for localization
    public override string Title => "[Module] Settings";

    string _value;

    protected override async Task OnInitializedAsync()
    {
        try
        {
            Dictionary<string, string> settings = await SettingService.GetModuleSettingsAsync(ModuleState.ModuleId);
            _value = SettingService.GetSetting(settings, "SettingName", "");
        }
        catch (Exception ex)
        {
            AddModuleMessage(ex.Message, MessageType.Error);
        }
    }

    public async Task UpdateSettings()
    {
        try
        {
            Dictionary<string, string> settings = await SettingService.GetModuleSettingsAsync(ModuleState.ModuleId);
            SettingService.SetSetting(settings, "SettingName", _value);
            await SettingService.UpdateModuleSettingsAsync(settings, ModuleState.ModuleId);
        }
        catch (Exception ex)
        {
            AddModuleMessage(ex.Message, MessageType.Error);
        }
    }
}
