using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;

namespace AppLibs.Libs
{
    public enum LayoutOptions
    {
        Default,
        None,
        Custom
    }
    public class LayoutAttribute : Attribute, IActionFilter
    {

        private string _layoutName;

        public LayoutAttribute():this(LayoutOptions.Default)
        {
        }

        public LayoutAttribute(LayoutOptions option, string layoutName = "")
        {
            switch (option)
            {
                case LayoutOptions.Default:
                    _layoutName = "Async";
                    break;
                case LayoutOptions.Custom:
                    _layoutName = layoutName;
                    break;
                case LayoutOptions.None:
                    _layoutName = "None";
                    break;
            }    
        }

        void IActionFilter.OnActionExecuted(ActionExecutedContext context)
        {

        }

        void IActionFilter.OnActionExecuting(ActionExecutingContext context)
        {
            Controller? controller = context.Controller as Controller;
            if (controller != null)
            {
                controller.ViewData["LayoutName"] = this._layoutName;
            }
        }
    }
}
