using System;
using System.Collections.Generic;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;


namespace ControlExplorer.Controls.LayoutPanels
{
    public partial class DemoWrapPanel
        : UserControl, IExposeApplicationBarItems
    {
        AppBarButton _btnAddItem = new AppBarButton();

        public DemoWrapPanel()
        {
            InitializeComponent();

            _btnAddItem.Label = "add item";
            _btnAddItem.Icon = new SymbolIcon(Symbol.Add);
            _btnAddItem.Click += _btnAddItem_Click;

            panel.Children.Clear();
            for (int i = 0; i < 9; i++)
            {
                AddItem();
            }
        }

        int[] _widths = { 140, 140, 160, 200, 140, 140, 100 };

        string[] _colors = { "#FF008B9C", "#FF0094D6", "#FF497331", "#FF9DCFC3", "#FF005B84" };
        Random _rnd = new Random();
        private void AddItem()
        {
            panel.Children.Add(new ContentControl() 
            {
                Content = (panel.Children.Count + 1).ToString(),
                Width = _rnd.PickOne<int>(_widths),
                Background = new SolidColorBrush(_rnd.PickOne<string>(_colors).ToColor()),
                Template = (ControlTemplate)Resources["PanelItemTemplate"]
            });
        }

        void _btnAddItem_Click(object sender, RoutedEventArgs e)
        {
            AddItem();
        }

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

}