using System;
using System.Windows.Forms;
using FastReport.Format;
using FastReport.Controls;
using FastReport.Dialog;
using System.Reflection;
using FastReport.Utils;

namespace FastReport
{
    partial class TextObjectBase : ICustomDataTreeItemsProvider
    {
        #region Private Methods
        private bool ShouldSerializeBrackets()
        {
            return Brackets != "[,]";
        }

        private bool ShouldSerializePadding()
        {
            return Padding != new Padding(2, 0, 2, 0);
        }

        private bool ShouldSerializeFormat()
        {
            return (formats.Count == 1 && !(formats[0] is GeneralFormat)) || formats.Count > 1;
        }
        #endregion

        #region Public Methods
        /// <inheritdoc/>
        public override void AssignFormat(ReportComponentBase source)
        {
            base.AssignFormat(source);
            TextObjectBase src = source as TextObjectBase;
            if (src == null)
                return;

            Formats.Assign(src.Formats);
        }

        /// <inheritdoc/>
        public virtual void ProvideCustomItems(DataTreeView tree)
        {
            TreeNode dialogNode = null;

            foreach (Base c in Report.AllObjects)
            {
                if (c is DialogControl)
                {
                    PropertyInfo bindableProp = (c as DialogControl).BindableProperty;
                    if (bindableProp != null)
                    {
                        if (dialogNode == null)
                        {
                            dialogNode = tree.Nodes.Add(Res.Get("Designer,ToolWindow,Dictionary,DialogControls"));
                            dialogNode.ImageIndex = 136;
                            dialogNode.SelectedImageIndex = dialogNode.ImageIndex;
                        }

                        TreeNode node = dialogNode.Nodes.Add(c.Name + "." + bindableProp.Name);
                        node.ImageIndex = DataTreeHelper.GetTypeImageIndex(bindableProp.PropertyType);
                        node.SelectedImageIndex = node.ImageIndex;
                    }
                }
            }
        }
        #endregion
    }
}
