using Microsoft.AspNetCore.Components;
using System.Collections.Generic;
using FastReport.Export;
using FastReport.Web.Application;

namespace FastReport.Web.Blazor.Components.Internal.ExportSettings
{
    public abstract class ExportSettingsBase
        : Microsoft.AspNetCore.Components.ComponentBase
    {
        [Parameter]
        public WebReport WebReport { get; set; }

        //protected readonly string resRoot;

        //private IWebRes Res;

        [Parameter]
        public Dictionary<string, string> ExportParameters { get; set; }

        protected override void OnParametersSet()
        {
            base.OnParametersSet();

            LocalizeForm();
            //WebReport.Res.Ro


            //Export = new T();
        }

        //protected T Export { get; set; }

        protected abstract void LocalizeForm();

        protected string IsActive(string key)
        {
            if(ExportParameters.TryGetValue(key, out string value))
            {
                return value == "true" ? "active" : "";
            }
            return "";
        }

        protected string Localize(string id)
        {
            //string result = WebReport.Res.GetInternal(id);
            //if (string.IsNullOrEmpty(result))
            //{
            //    return id;
            //}
            //return result;
            return id;
        }

        protected void ChangeBoolValue(string propName, bool defaultValueIsTrue = true)
        {
            if (ExportParameters.TryGetValue(propName, out string value))
            {
                ExportParameters[propName] = value == "true" ? "false" : "true";
            }
            else
            {
                ExportParameters[propName] = defaultValueIsTrue ? "true" : "false";
            }
        }
    }
}
