using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;


namespace FastReport.Web.Blazor.Components
{
    public partial class Toolbar
    {
        float currentZoom;
        bool isFirstPage;
        bool isLastPage;
        const string zoomSymbol = "•";

        static readonly float[] zoomList = new[] { 300f, 200f, 150f, 100f, 90f, 75f, 50f, 25f };

        private ToolbarLocalization Localization;

        private int CurrentPage
        {
            get => WebReport.CurrentPageIndex + 1;
            set => WebReport.CurrentPageIndex = value + 1;
        }

        private int InputValue
        {
            get => CurrentPage;
            set
            {
                if (value != CurrentPage)
                {
                    // Check bounds
                    if (value > 0 && value < WebReport.TotalPages + 1)
                    {
                        WebReport.GotoPage(value - 1);
                        PageChanged.Invoke();
                    }
                }
            }
        }

        public Toolbar()
        {

        }

        private void ClickSettingsExport(Exports export)
        {
            WebReport.ExportType = export;
            ClickSettingsExport();
        }

        private void ClickSettingsExport()
        {
            WebReport.EnableModalDialog = true;
            OpenModalDialog?.Invoke();
            //WebReport.Container?.OnUpdate(false);
        }


        private void Reload()
        {
            WebReport.OnUpdate(true);
        }


        private void Zoom(float value)
        {
            WebReport.Zoom = value / 100;

            WebReport.OnUpdate();
        }

        private string Save(string exportFormat)
        {
            return WebReport.template_export_url(exportFormat);
        }

        private string Print(string printFormat)
        {
            return WebReport.template_print_url(printFormat);
        }


        private string SaveFpx => Save("fpx");
        private string SavePdf => Save("pdf");
        private string SaveXlsx => Save("xlsx");
        private string SaveDocx => Save("docx");
        private string SavePowerPoint2007 => Save("pptx");
        private string SaveText => Save("txt");
        private string SaveRtf => Save("rtf");
        private string SaveXps => Save("xps");
        private string SaveOds => Save("ods");
        private string SaveOdt => Save("odt");
        private string SaveXmlExcel => Save("xml");
        private string SaveDbf => Save("dbf");
        private string SaveCsv => Save("csv");
        private string SaveSvg => Save("svg");
        private string SaveBiff8 => Save("xls");
        private string SaveHpgl => Save("hpgl");
        private string SaveHTML => Save("html");
        //private string SaveImage => Save("jpeg");
        private string SaveJson => Save("json");
        private string SaveDxf => Save("dxf");
        private string SaveLaTeX => Save("latex");
        private string SavePpml=> Save("ppml");
        private string SavePS => Save("ps");
        private string SaveXaml => Save("xaml");
        private string SaveZpl => Save("zpl");
        //private string SaveEmail => Save(""); //Required modal window

        private string PrintHtml => Print("html");
        private string PrintPdf => Print("pdf");


        private void GotoFirst()
        {
            WebReport.FirstPage();
            PageChanged.Invoke();
        }

        private void GotoPrevious()
        {
            if (CurrentPage - 1 > 0)
            {
                WebReport.PrevPage();
                PageChanged.Invoke();
            }
        }

        private void GotoNext()
        {
            if (CurrentPage < WebReport.TotalPages)
            {
                WebReport.NextPage();
                PageChanged.Invoke();
            }
        }

        private void GotoLast()
        {
            WebReport.LastPage();
            PageChanged.Invoke();
        }

    }
}
