using FastReport.Controls;
using FastReport.Utils;
using System;
using System.Drawing;
using System.Windows.Forms;

namespace FastReport.Gauge.Radial
{
    internal partial class RadialGaugeEditorForm : GaugeEditorForm
    {
#region Fields

        private Label lblType;
        private FlagsControl flagsControlType;
        private Label lblPosition;
        private FlagsControl flagsControlPosition;

#endregion // Fields

#region Constructors

        /// <inheritdoc />
        public RadialGaugeEditorForm() : base()
        {
            InitializeComponent();
            Localize();
            UIUtils.CheckRTL(this);
            UpdateDpiDependencies();
        }

        /// <inheritdoc />
        public RadialGaugeEditorForm(GaugeObject gauge) : base(gauge)
        {
            InitializeComponent();
            Localize();
            UIUtils.CheckRTL(this);
            UpdateDpiDependencies();
        }

        #endregion //Constructors

        #region ProtectedMethods

        /// <inheritdoc />
        protected override void Init()
        {
            base.Init();

#region ControlsDesign

            if (Gauge != null)
            {
                try
                {
                    lblType = new Label();
                    flagsControlType = new FlagsControl();
                    lblPosition = new Label();
                    flagsControlPosition = new FlagsControl();
                    int margin = 5;

                    lblType.AutoSize = true;
                    lblType.Margin = new Padding(margin);
                    lblType.Location = new Point(btnGeneralBorder.Location.X, btnGeneralBorder.Location.Y + btnGeneralBorder.Size.Height + margin * 2);
                    lblType.Name = "lblType";
                    lblType.Text = "Type :";
                    flagsControlType.AllowMultipleFlags = false;
                    flagsControlType.BorderStyle = BorderStyle.FixedSingle;
                    flagsControlType.Margin = new Padding(margin);
                    flagsControlType.Location = new Point(btnGeneralFill.Location.X, lblType.Location.Y);
                    flagsControlType.Name = "flagsControlType";
                    flagsControlType.Flags = (Gauge as RadialGauge).Type;
                    flagsControlType.Width = btnGeneralFill.Width;

                    lblPosition.AutoSize = true;
                    lblPosition.Margin = new Padding(margin);
                    lblPosition.Location = new Point(lblType.Location.X, flagsControlType.Location.Y + flagsControlType.Size.Height + margin * 2);
                    lblPosition.Name = "lblPosition";
                    lblPosition.Text = "Position :";
                    flagsControlPosition.BorderStyle = BorderStyle.FixedSingle;
                    flagsControlPosition.Margin = new Padding(margin);
                    flagsControlPosition.Location = new Point(flagsControlType.Location.X, lblPosition.Location.Y);
                    flagsControlPosition.Name = "flagsControlType";
                    flagsControlPosition.Flags = (Gauge as RadialGauge).Position;
                    flagsControlPosition.Width = btnGeneralFill.Width;

                    pgGeneral.Controls.AddRange(new Control[] { lblType, flagsControlType, lblPosition, flagsControlPosition });
                }
                catch (Exception ex)
                {
                    if (!Config.WebMode)
                    {
                        FRMessageBox.Error(ex.Message);
                    }
                }
            }

#endregion // ControlsDesign
        }

        /// <inheritdoc />
        protected override void GaugeEditorForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (this.DialogResult == DialogResult.OK)
            {
                base.GaugeEditorForm_FormClosing(sender, e);
                try
                {
                    (Gauge as RadialGauge).Type = (RadialGaugeType)flagsControlType.Flags;
                    (Gauge as RadialGauge).Position = (RadialGaugePosition)flagsControlPosition.Flags;
                }
                catch (Exception ex)
                {
                    if (!Config.WebMode)
                    {
                        FRMessageBox.Error(ex.Message);
                    }
                }
            }
        }

#endregion // Protected Methods

        /// <inheritdoc />
        public override void Localize()
        {
            base.Localize();
            MyRes res = new MyRes("Objects,Gauge,GaugeForms,RadialGauge");
            Text = res.Get("");
            res = new MyRes("Objects,Gauge,GaugeForms,PageGeneral");
            lblType.Text = res.Get("Type");
            lblPosition.Text = res.Get("Position");
        }
    }
}
