using System.Globalization;
using System.Windows.Forms;
using FastReport.Export;
using FastReport.Export.Odf;
using FastReport.Utils;
using static FastReport.Export.Odf.ODFExport;

namespace FastReport.Forms
{
    /// <summary>
    /// Form for <see cref="ODFExport"/>.
    /// For internal use only.
    /// </summary>
    public partial class ODFExportForm : BaseExportForm
    {
        /// <inheritdoc/>
        public override void Init(ExportBase export)
        {
            base.Init(export);
            MyRes res = new MyRes("Export," + ((export is ODSExport) ? "Ods" : "Odt"));
            Text = res.Get("");
            ODFExport odfExport = Export as ODFExport;
            cbOdfStandard.SelectedIndex = (int)odfExport.OdfCompliance;
            cbWysiwyg.Checked = odfExport.Wysiwyg;
            cbPageBreaks.Checked = odfExport.PageBreaks;
            cbbLocalization.Enabled = odfExport.ExportLocale;
            cbLocalization.Checked = odfExport.ExportLocale;

            cbbLocalization.Items.Add(Res.Get("Export,Misc,UseDesigerLocale"));
            foreach (var lang in CultureInfo.GetCultures(CultureTypes.AllCultures))
                cbbLocalization.Items.Add(lang.DisplayName);

            if (odfExport.Locale != null)
                cbbLocalization.SelectedItem = odfExport.Locale.DisplayName;
            else
                cbbLocalization.SelectedIndex = 0;
        }
        
        /// <inheritdoc/>
        protected override void Done()
        {
            base.Done();
            ODFExport odfExport = Export as ODFExport;
            odfExport.Wysiwyg = cbWysiwyg.Checked;
            odfExport.PageBreaks = cbPageBreaks.Checked;
            odfExport.OdfCompliance = (OdfStandard)cbOdfStandard.SelectedIndex;
            odfExport.ExportLocale = cbLocalization.Checked;

            if (cbbLocalization.SelectedIndex == -1 || cbbLocalization.SelectedIndex == 0)
                odfExport.Locale = null;
            else
                odfExport.Locale = CultureInfo.GetCultures(CultureTypes.AllCultures)[cbbLocalization.SelectedIndex - 1];
        }

        private void CbLocalization_CheckedChanged(object sender, System.EventArgs e)
        {
            cbbLocalization.Enabled = cbLocalization.Checked;
        }

        /// <inheritdoc/>
        public override void Localize()
        {
            base.Localize();
            MyRes res = new MyRes("Export,Misc");
            gbOptions.Text = res.Get("Options");
            cbWysiwyg.Text = res.Get("Wysiwyg");
            cbPageBreaks.Text = res.Get("PageBreaks");
            cbLocalization.Text = res.Get("Localization");
            res = new MyRes("Export,Odf");
            lblCompliance.Text = res.Get("Compliance");
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ODFExportForm"/> class.
        /// </summary>
        public ODFExportForm()
        {
            InitializeComponent();
        }
    }
}

