using Microsoft.AspNetCore.Components;
using Seenginx.Models;
using Seenginx.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;

namespace Seenginx.Pages
{
	public class NginxBase : ComponentBase
	{
		[Inject]
		public INginxService NginxService { get; set; }

		public string InputSearch { get; set; }

		public List<ConfigFile> ConfigFiles { get; set; } = new List<ConfigFile>();
		public ConfigFile SelectedFile { get; set; }
		public List<string> Filters { get; set; } = new List<string>();
		public List<int> FilteredOutFiles { get; set; } = new List<int>();

		public Dictionary<string, string> FilterFolder { get; set; } = new Dictionary<string, string>();

		protected override async Task OnInitializedAsync()
		{
			ConfigFiles.AddRange(await NginxService.GetFilesAsync());
			Filters.AddRange(new List<string> { "All", "Root", "Conf.d", "Available", "Enabled" });
			FilterFolder.Add("All", null);
			FilterFolder.Add("Root", "/");
			FilterFolder.Add("Conf.d", "/conf.d");
			FilterFolder.Add("Available", "/sites-available");
			FilterFolder.Add("Enabled", "/sites-enabled");
			await base.OnInitializedAsync();
		}

		public async Task SelectedFileChanged(ConfigFile configFile)
		{
			SelectedFile = configFile;
		}

		public async Task AddFile()
		{
		}
		public async Task UpdateFile(ConfigFile configFile)
		{
		}
		public async Task DeleteFile(ConfigFile configFile)
		{
		}
	}
}
