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

namespace CupWorks.Forms.Fluent
{
    public static class ContentViewExtension
    {
        public static TSelf ChangeContentViewContent<TSelf>(this TSelf self, View content) where TSelf : ContentView
        {
            self.Content = content;
            return self;
        }
        
        public static TSelf HandleContentViewLayoutChanged<TSelf>(this TSelf self, EventHandler layoutChanged) where TSelf : ContentView
        {
            self.LayoutChanged += layoutChanged;
            return self;
        }
        
        public static TSelf HandleContentViewChildrenReordered<TSelf>(this TSelf self, EventHandler childrenReordered) where TSelf : ContentView
        {
            self.ChildrenReordered += childrenReordered;
            return self;
        }
        
        public static TSelf HandleContentViewSizeChanged<TSelf>(this TSelf self, EventHandler sizeChanged) where TSelf : ContentView
        {
            self.SizeChanged += sizeChanged;
            return self;
        }
        
        public static TSelf HandleContentViewMeasureInvalidated<TSelf>(this TSelf self, EventHandler measureInvalidated) where TSelf : ContentView
        {
            self.MeasureInvalidated += measureInvalidated;
            return self;
        }
        
        public static TSelf HandleContentViewFocused<TSelf>(this TSelf self, EventHandler<FocusEventArgs> focused) where TSelf : ContentView
        {
            self.Focused += focused;
            return self;
        }
        
        public static TSelf HandleContentViewUnfocused<TSelf>(this TSelf self, EventHandler<FocusEventArgs> unfocused) where TSelf : ContentView
        {
            self.Unfocused += unfocused;
            return self;
        }
        
        public static TSelf HandleContentViewChildAdded<TSelf>(this TSelf self, EventHandler<ElementEventArgs> childAdded) where TSelf : ContentView
        {
            self.ChildAdded += childAdded;
            return self;
        }
        
        public static TSelf HandleContentViewChildRemoved<TSelf>(this TSelf self, EventHandler<ElementEventArgs> childRemoved) where TSelf : ContentView
        {
            self.ChildRemoved += childRemoved;
            return self;
        }
        
        public static TSelf HandleContentViewDescendantAdded<TSelf>(this TSelf self, EventHandler<ElementEventArgs> descendantAdded) where TSelf : ContentView
        {
            self.DescendantAdded += descendantAdded;
            return self;
        }
        
        public static TSelf HandleContentViewDescendantRemoved<TSelf>(this TSelf self, EventHandler<ElementEventArgs> descendantRemoved) where TSelf : ContentView
        {
            self.DescendantRemoved += descendantRemoved;
            return self;
        }
        
        public static TSelf HandleContentViewPropertyChanging<TSelf>(this TSelf self, PropertyChangingEventHandler propertyChanging) where TSelf : ContentView
        {
            self.PropertyChanging += propertyChanging;
            return self;
        }
        
        public static TSelf HandleContentViewPropertyChanged<TSelf>(this TSelf self, PropertyChangedEventHandler propertyChanged) where TSelf : ContentView
        {
            self.PropertyChanged += propertyChanged;
            return self;
        }
        
        public static TSelf HandleContentViewBindingContextChanged<TSelf>(this TSelf self, EventHandler bindingContextChanged) where TSelf : ContentView
        {
            self.BindingContextChanged += bindingContextChanged;
            return self;
        }
    }
}