// Copyright © Selmo Technology GmbH. All Rights Reserved

using Microsoft.AspNetCore.Components;
using SelmoStudio.Hmi.Server.Service;

namespace SelmoStudio.Hmi.Server.Settings.Components
{
    public partial class SettingsComponent
    {
        private List<string> _settingOptions;
        private string _selectedSettingOption;

        private List<string> _settingOptionsAuthorisedPolicy1;
        private string _selectedSettingOptionAuthorisedPolicy1;

        private List<string> _settingOptionsAuthorisedPolicy2;
        private string _selectedSettingOptionAuthorisedPolicy2;

        [Inject]
        private IHmiLanguageService _hmiLanguageService { get; set; }

        private async Task SettingsDropDownCallBack(object value)
        {
            if (value is string selectedOption)
            {
                _selectedSettingOption = selectedOption;
            }

            await Task.CompletedTask;
        }

        private async Task AuthorisedPolicy1DropDownCallBack(object value)
        {
            if (value is string selectedOption)
            {
                _selectedSettingOptionAuthorisedPolicy1 = selectedOption;
            }

            await Task.CompletedTask;
        }

        private async Task AuthorisedPolicy2DropDownCallBack(object value)
        {
            if (value is string selectedOption)
            {
                _selectedSettingOptionAuthorisedPolicy2 = selectedOption;
            }

            await Task.CompletedTask;
        }

        protected override void OnInitialized()
        {
            _settingOptions = GetTestOptions();
            _selectedSettingOption = _settingOptions[1];

            _settingOptionsAuthorisedPolicy1 = GetTestOptions();
            _selectedSettingOptionAuthorisedPolicy1 = _settingOptionsAuthorisedPolicy1[1];

            _settingOptionsAuthorisedPolicy2 = GetTestOptions();
            _selectedSettingOptionAuthorisedPolicy2 = _settingOptionsAuthorisedPolicy2[0];

            _hmiLanguageService.OnLanguageSet += OnLanguageSet;

            base.OnInitialized();
        }

        private void OnLanguageSet()
        {
            InvokeAsync(() => StateHasChanged());
        }

        private List<string> GetTestOptions()
        {
            return new List<string> { "Option 1", "Option 2", "Option 3" };
        }

        public void Dispose()
        {
            if (_hmiLanguageService != null)
            {
                _hmiLanguageService.OnLanguageSet -= OnLanguageSet;
            }
        }
    }
}