using Xamarin.Forms;
using System;
using System.ComponentModel;

namespace CupWorks.Forms.Fluent
{
    public static class GridExtension
    {
        public static TSelf AddRow<TSelf>(this TSelf self, RowDefinition rowDefinition) where TSelf : Grid
        {
            self.RowDefinitions.Add(rowDefinition);
            return self;
        }

        public static TSelf AddColumn<TSelf>(this TSelf self, ColumnDefinition columnDefinition) where TSelf : Grid
        {
            self.ColumnDefinitions.Add(columnDefinition);
            return self;
        }
        
        public static TSelf ChangeRowSpacing<TSelf>(this TSelf self, double rowSpacing) where TSelf : Grid
        {
            self.RowSpacing = rowSpacing;
            return self;
        }
        
        public static TSelf ChangeColumnSpacing<TSelf>(this TSelf self, double columnSpacing) where TSelf : Grid
        {
            self.ColumnSpacing = columnSpacing;
            return self;
        }
        
        public static TSelf ChangeColumnDefinitions<TSelf>(this TSelf self, ColumnDefinitionCollection columnDefinitions) where TSelf : Grid
        {
            self.ColumnDefinitions = columnDefinitions;
            return self;
        }
        
        public static TSelf ChangeRowDefinitions<TSelf>(this TSelf self, RowDefinitionCollection rowDefinitions) where TSelf : Grid
        {
            self.RowDefinitions = rowDefinitions;
            return self;
        }
        
        public static TSelf HandleGridLayoutChanged<TSelf>(this TSelf self, EventHandler layoutChanged) where TSelf : Grid
        {
            self.LayoutChanged += layoutChanged;
            return self;
        }
        
        public static TSelf HandleGridChildrenReordered<TSelf>(this TSelf self, EventHandler childrenReordered) where TSelf : Grid
        {
            self.ChildrenReordered += childrenReordered;
            return self;
        }
        
        public static TSelf HandleGridSizeChanged<TSelf>(this TSelf self, EventHandler sizeChanged) where TSelf : Grid
        {
            self.SizeChanged += sizeChanged;
            return self;
        }
        
        public static TSelf HandleGridMeasureInvalidated<TSelf>(this TSelf self, EventHandler measureInvalidated) where TSelf : Grid
        {
            self.MeasureInvalidated += measureInvalidated;
            return self;
        }
        
        public static TSelf HandleGridFocused<TSelf>(this TSelf self, EventHandler<FocusEventArgs> focused) where TSelf : Grid
        {
            self.Focused += focused;
            return self;
        }
        
        public static TSelf HandleGridUnfocused<TSelf>(this TSelf self, EventHandler<FocusEventArgs> unfocused) where TSelf : Grid
        {
            self.Unfocused += unfocused;
            return self;
        }
        
        public static TSelf HandleGridChildAdded<TSelf>(this TSelf self, EventHandler<ElementEventArgs> childAdded) where TSelf : Grid
        {
            self.ChildAdded += childAdded;
            return self;
        }
        
        public static TSelf HandleGridChildRemoved<TSelf>(this TSelf self, EventHandler<ElementEventArgs> childRemoved) where TSelf : Grid
        {
            self.ChildRemoved += childRemoved;
            return self;
        }
        
        public static TSelf HandleGridDescendantAdded<TSelf>(this TSelf self, EventHandler<ElementEventArgs> descendantAdded) where TSelf : Grid
        {
            self.DescendantAdded += descendantAdded;
            return self;
        }
        
        public static TSelf HandleGridDescendantRemoved<TSelf>(this TSelf self, EventHandler<ElementEventArgs> descendantRemoved) where TSelf : Grid
        {
            self.DescendantRemoved += descendantRemoved;
            return self;
        }
        
        public static TSelf HandleGridPropertyChanging<TSelf>(this TSelf self, PropertyChangingEventHandler propertyChanging) where TSelf : Grid
        {
            self.PropertyChanging += propertyChanging;
            return self;
        }
        
        public static TSelf HandleGridPropertyChanged<TSelf>(this TSelf self, PropertyChangedEventHandler propertyChanged) where TSelf : Grid
        {
            self.PropertyChanged += propertyChanged;
            return self;
        }
        
        public static TSelf HandleGridBindingContextChanged<TSelf>(this TSelf self, EventHandler bindingContextChanged) where TSelf : Grid
        {
            self.BindingContextChanged += bindingContextChanged;
            return self;
        }
    }
}