using System;
using System.Runtime.CompilerServices;
using System.Windows.Input;
using Xamarin.Forms;

namespace InABox.Mobile
{

    public class MobileCard : Frame
    {
        private readonly BindableProperty IsClickableProperty = BindableProperty.Create(
            nameof(IsClickable),
            typeof(bool),
            typeof(MobileCard),
            false);

        public bool IsClickable
        {
            get => (bool)GetValue(IsClickableProperty);
            set => SetValue(IsClickableProperty, value);
        }
        
        public MobileCard()
        {
            CornerRadius = 5;
            Margin = 0;
            Padding = 2;
            BorderColor = Color.Gray;
            BackgroundColor = Color.White;
            HasShadow = false;
            IsEnabled = true;
            GestureRecognizers.Add(new TapGestureRecognizer
            {
                Command = new Command(OnClick)
            });
        }
        
        public event EventHandler Clicked;
        
        protected virtual async void OnClick()
        {
            if (IsEnabled && IsClickable)
            {
                Scale = 0.5;
                await this.ScaleTo(1, 150);
                Clicked?.Invoke(this, EventArgs.Empty);
            }
        }
        

    }
}