//
//  Copyright 2012  Xamarin Inc.
//
//    Licensed under the Apache License, Version 2.0 (the "License");
//    you may not use this file except in compliance with the License.
//    You may obtain a copy of the License at
//
//        http://www.apache.org/licenses/LICENSE-2.0
//
//    Unless required by applicable law or agreed to in writing, software
//    distributed under the License is distributed on an "AS IS" BASIS,
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//    See the License for the specific language governing permissions and
//    limitations under the License.

using System;

using MonoTouch.UIKit;

namespace hawkeye.Core
{
    /// <summary>
    /// Theme class for appling UIAppearance to the app, and holding app level resources (colors and images)
    /// 
    /// * Notice use of Lazy&lt;T&gt;, so images are not loaded until requested
    /// </summary>
    public static class Theme
    {
        #region Images

        #region BackButton

        private static readonly Lazy<UIImage> _backbutton =
            new Lazy<UIImage>(
                () => UIImage.FromFile("Images/backbutton.png").CreateResizableImage(new UIEdgeInsets(15, 15, 15, 5)));

        /// <summary>
        /// Standard back button for UINavigationBar
        /// </summary>
        public static UIImage BackButton
        {
            get { return _backbutton.Value; }
        }

        #endregion

        #region ToolBar

        private static readonly Lazy<UIImage> _bluebar = new Lazy<UIImage>(() => UIImage.FromFile("Images/bluebar.png"));

        /// <summary>
        /// Image for default UIToolbar
        /// </summary>
        public static UIImage ToolBar
        {
            get { return _bluebar.Value; }
        }

        #endregion

        #endregion

        #region Colors

        #region IndicatorColor

        private static readonly Lazy<UIColor> _indicatorColor = new Lazy<UIColor>(() => UIColor.FromRGB(0x77, 0x77, 0x77));

        /// <summary>
        /// General indicator color for the entire app
        /// </summary>
        public static UIColor IndicatorColor
        {
            get { return _indicatorColor.Value; }
        }

        #endregion

        #endregion

        /// <summary>
        /// Apply UIAppearance to this application, this is iOS's version of "styling"
        /// </summary>
        public static void Apply()
        {
            UIActivityIndicatorView.Appearance.Color = IndicatorColor;

            UIToolbar.Appearance.SetBackgroundImage(ToolBar, UIToolbarPosition.Any, UIBarMetrics.Default);

            UIBarButtonItem.Appearance.SetBackButtonBackgroundImage(BackButton, UIControlState.Normal, UIBarMetrics.Default);
        }

        private const string FontName = "HelveticaNeue-Medium";
        private const string BoldFontName = "HelveticaNeue-Bold";

        /// <summary>
        /// Returns the default font with a certain size
        /// </summary>
        public static UIFont FontOfSize(float size)
        {
            return UIFont.FromName(FontName, size);
        }

        /// <summary>
        /// Returns the default font with a certain size
        /// </summary>
        public static UIFont BoldFontOfSize(float size)
        {
            return UIFont.FromName(BoldFontName, size);
        }
    }
}