using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using FastReport.Export.OoXML;
using FastReport.Web.Application.Localizations;

namespace FastReport.Web.Blazor.Components.Internal.ExportSettings
{
    public partial class DocxExportSettings : ExportSettingsBase
    {
        const string Wysiwyg = nameof(Word2007Export.Wysiwyg);
        const string PrintOptimized = nameof(Word2007Export.PrintOptimized);
        const string DoNotExpandShiftReturn = nameof(Word2007Export.DoNotExpandShiftReturn);
        const string MatrixBased = nameof(Word2007Export.MatrixBased);
        const string ParagraphBased = nameof(Word2007Export.ParagraphBased);

        DocxExportSettingsLocalization localization;


        protected override void OnInitialized()
        {
            base.OnInitialized();
            ExportParameters["RowHeightIs"] = "Exactly";
            ExportParameters[MatrixBased] = "false";
            ExportParameters[Wysiwyg] = "true";
            ExportParameters[PrintOptimized] = "true";
        }

        protected override void LocalizeForm()
        {
            var res = WebReport.Res;
            localization = new DocxExportSettingsLocalization(res);
        }


        void OnWysiwygClick(MouseEventArgs e)
        {
            ChangeBoolValue(Wysiwyg);
        }

        void OnPrintOptimizedClick(MouseEventArgs e)
        {
            ChangeBoolValue(PrintOptimized);
        }

        void OnDoNotExpandShiftReturnClick(MouseEventArgs e)
        {
            ChangeBoolValue(DoNotExpandShiftReturn);
        }

        public void OnRenderModeChange(ChangeEventArgs e)
        {
            if ((e.Value as string) == "table")
            {
                ExportParameters[MatrixBased] = "true";
                ExportParameters.Remove(ParagraphBased);
            }
            else if ((e.Value as string) == "layers")
            {
                ExportParameters[MatrixBased] = "false";
                ExportParameters.Remove(ParagraphBased);
            }
            else if ((e.Value as string) == "paragraphs")
            {
                ExportParameters.Remove(MatrixBased);
                ExportParameters[ParagraphBased] = "true";
            }
        }

    }
}
