using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Xml.Serialization;
using CrossCutting;

namespace BallotTemplates
{
    public class TextField : BoundObject, IBoundingPolygon
    {
        public TextField()
        {
            IsRecognitionField = false;
        }

        
        
        
        [XmlAttribute("pattern")]
        [Browsable(false)]
        public string Pattern { get; set; }

        
        
        
        [XmlAttribute("value")]
        [Browsable(false)]
        public string Value { get; set; }

        
        
        
        [XmlAttribute("isRecognitionField")]
        [Browsable(false)]
        [DefaultValue(false)]
        public bool IsRecognitionField { get; set; }

        [XmlElement("contour")]
        public string Contour { get; set; }

        [XmlIgnore]
        public virtual PointF[] BoundingPolygonPoints
        {
            get
            {
                if (string.IsNullOrEmpty(Contour))
                {
                    return new PointF[] { };
                }
                var points = from pair in Contour?.Split(' ')
                    let parts = pair.Split(',')
                    select new PointF(float.Parse(parts.First(), CultureInfo.InvariantCulture), float.Parse(parts.Last(), CultureInfo.InvariantCulture));
                return points.ToArray();
            }
        }
    }
}
