using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using C1.Silverlight;
using C1.Silverlight.Gauge;

namespace Factories
{
    public partial class FactoryDecorator : UserControl
    {
        public FactoryDecorator()
        {
            InitializeComponent();

            smallGaugeMask.MouseLeftButtonDown += (s, e) =>
            {
                showLargeGauge.Begin();
                largeGauge.Visibility = Visibility.Visible;
                smallGauge.Visibility = Visibility.Collapsed;
            };

            Action hideLargeGauge = () =>
            {
                showLargeGauge.Stop();
                largeGauge.Visibility = Visibility.Collapsed;
                smallGauge.Visibility = Visibility.Visible;
            };
            gauges.MouseLeave += (s,e) => hideLargeGauge();
            largeGauge.MouseLeftButtonDown += (s,e) => hideLargeGauge();

            Storyboard.SetTarget(smallGaugeColor, (smallGauge.Decorators[0] as C1GaugeRange).Fill);
            Storyboard.SetTargetProperty(smallGaugeColor, new PropertyPath("Color"));
            smallGauge.ValueChanged += (s, e) => UpdateSmallGaugeColor();
            UpdateSmallGaugeColor();
        }

        void UpdateSmallGaugeColor()
        {
            smallGaugeColor.Begin();
            smallGaugeColor.Seek(TimeSpan.FromSeconds((smallGauge.Value - smallGauge.Minimum) / (smallGauge.Maximum - smallGauge.Minimum)));
            smallGaugeColor.Pause();
        }
    }
}
