using C1.Xaml.Imaging;
using System;
using System.Collections.Generic;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;

namespace ControlExplorer.Controls.Imaging
{
    public partial class GifImages
        : UserControl, IExposeApplicationBarItems
    {
        AppBarButton _btnPlayPause = new AppBarButton();
        C1GifImage _gifImage;

        public GifImages()
        {
            InitializeComponent();

            _btnPlayPause.Label = "pause";
            _btnPlayPause.Click += _btnPlayPause_Click;

            _gifImage = new C1GifImage(new Uri("ms-appx:///Resources/Imaging/c1AnimatedGif.gif"));
            image.Source = _gifImage;
        }

        void _btnPlayPause_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            IsPlaying = !IsPlaying;
        }

        bool _isPlaying = true;
        public bool IsPlaying
        {
            get { return _isPlaying; }
            set
            {
                if (_isPlaying != value)
                {
                    _isPlaying = value;
                    if (_isPlaying)
                    {
                        _gifImage.Play();
                        _btnPlayPause.Label = "pause";
                    }
                    else
                    {
                        _gifImage.Stop();
                        _btnPlayPause.Label = "play";
                    }
                }
            }
        }

        public IEnumerable<ICommandBarElement> ApplicationBarItems
        {
            get 
            { 
                yield return _btnPlayPause; 
            }
        }
    }
}
