using System.Collections.Generic;
using System.Threading.Tasks;
using Blazored.Toast.Services;
using DiplomovaPrace.Contracts.ProductCategories.InputModels;
using DiplomovaPrace.Contracts.ProductCategories.ViewModels;
using DiplomovaPrace.Web.Admin.Services;
using DiplomovaPrace.Web.Admin.Store.ProductCategoryUseCase;
using Fluxor;
using Microsoft.AspNetCore.Components;

namespace DiplomovaPrace.Web.Admin.Pages.ProductCategories
{
	public partial class CreateProductCategory
	{
		[Inject]
		public IState<ProductCategoryState> ProductCategoryState { get; set; }

		[Inject]
		private IProductCategoryService ProductCategoryService { get; set; }

		[Inject]
		private IToastService ToastService { get; set; }

		private ProductCategoryIM productCategory = new();

		private List<ProductCategoryDto> productCategories = new();

		protected override async Task OnInitializedAsync()
		{
			await base.OnInitializedAsync().ConfigureAwait(false);
			await ProductCategoryService.RequestProductCategoriesAsync().ConfigureAwait(false);

			productCategories = ProductCategoryState.Value.ProductCategories;
		}

		private async Task HandleSubmitAsync()
		{
			await ProductCategoryService.CreateProductCategoryAsync(productCategory).ConfigureAwait(false);
		}
	}
}
