<!--
    Copyright (c) 2015, Texas Instruments Incorporated
    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions
    are met:

    *   Redistributions of source code must retain the above copyright
        notice, this list of conditions and the following disclaimer.
        notice, this list of conditions and the following disclaimer in the
        documentation and/or other materials provided with the distribution.
    *   Neither the name of Texas Instruments Incorporated nor the names of
        its contributors may be used to endorse or promote products derived
        from this software without specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
    OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
    WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
    OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
    EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../ti-widget-common-behaviors/ti-widget-common-behaviors.html">
<link rel="import" href="../paper-icon-button/paper-icon-button.html">
<link rel="import" href="../iron-icons/device-icons.html">
<link rel="import" href="../ti-widget-common/ti-widget-toggle-button.html">
<link rel="import" href="ti-tile-properties.html">
<link rel="import" href="ti-tile-base.html">
<link rel="import" href="ti-tile-styles.html">
<!--
`ti-tile-toggleswitch` is switch that can be used to send a true (ON) or false (OFF) value to the target

Example:

    <ti-tile-toggleswitch></ti-tile-toggleswitch>

See demo for a full working example of how to use this component.

@group Instrument Tiles
@element ti-tile-toggleswitch
@demo demo.html
@extends ti-tile-base
@homepage ../../../ti-guicomposer-helpindex/demo.html
-->
<dom-module id='ti-tile-toggleswitch'  >

    <template>
        <style include="ti-tile-styles">
            :host {
                width: 150px;
                min-width:100px;
                min-height:100px;
            }
            #instrument_div {
            	padding-left: 1em;
            	padding-right: 1em;
                text-align: center;
            }
            #instrument {
                position: static;
            }
            #label_div {
            	text-align:center;
            }
        </style>
        <div id="containerDiv" layout vertical style$="background-color:{{backgroundColor}};padding:{{containerPadding}};">
	        <div id="shadow-bottom" fit  class$="paper-material-bottom-z-[[elevation]]"></div>
	        <div id="shadow-top" fit  class$="paper-material-top-z-[[elevation]]"></div>
            <div id="tileTitle" style$="display:flex;align-items:center;justify-content:left;top:0;left:0;width:calc(100%+26px);margin:-13px;[[titleStyle]];">
                <span style="vertical-align:middle;margin:13px;text-align:left;">[[titleText]]</span>
            </div>
            <div id="instrument_div" flex layout vertical center-justified>
                <ti-widget-toggle-button id="instrument" checked="{{value}}"  toggle-color="{{toggleColor}}" ms-debounce-period="{{msDebouncePeriod}}" text-align="center"></ti-widget-toggle-button>
                <label id="label_div" style$="{{_getTitleStyle(_fontColor,_fontSize,_fontWeight)}}">
                    {{_getSwitchState(value)}}
                </label>
            </div>
            <template is="dom-if" restamp="true" if="{{_isInDesigner}}">
                <paper-icon-button id="editIcon"  class="pointer" icon="create" on-tap="editProperties" title="edit tile properties" style$="[[_getIconStyle(_iconColor)]]" ></paper-icon-button>
                <paper-icon-button id="moveLeftIcon" class="pointer" icon="arrow-back" on-tap="moveLeft" title="move tile left" style$="[[_getArrowStyle(_arrowStyle,_iconColor)]]"></paper-icon-button>
                <paper-icon-button id="moveRightIcon" class="pointer" icon="arrow-forward" on-tap="moveRight" title="move tile right" style$="[[_getArrowStyle(_arrowStyle,_iconColor)]]"></paper-icon-button>
                <paper-icon-button id="resizeIcon" class="resize" icon="device:signal-cellular-0-bar"  title="resize tile"  style$="[[_getIconStyle(_resizeCornerColor)]]"></paper-icon-button>
                <paper-icon-button id="pinIcon" class="pointer" icon="{{_pinIcon}}" on-tap="togglePin" style$="[[_getIconStyle(_iconColor)]]"></paper-icon-button>
            </template>

        </div>
        <content></content>
    </template>
    <script>
        Polymer ({
            is: 'ti-tile-toggleswitch',


            hostAttributes: {
            },
            behaviors: [TiTileBase],
            properties: {
                /**
                 * The ON/OFF value to display in the switch
                 *
                 * @attribute value
                 * @type Boolean
                 * @default false
                 */
                value: {
                    notify: true,
                    type: Boolean,
                    value: false
                },
                /**
                 * The title to display at the top of the tile
                 *
                 * @attribute titleText
                 * @type string
                 * @default ''
                 */
                titleText: {
                    notify: true,
                    type: String,
                    value: "Switch"
                },
                /**
                 * The color to use for the toggle button 
                 *
                 * @attribute toggleColor
                 * @type string
                 * @default "#008000"
                 */
                toggleColor: {
                    notify: true,
                    type: String,
                    value: "#008000"
                },
                /**
                 * Specifies the period after the checked property has been changed that the switch will ignore
                 * changes to the value of the checked property
                 *
                 * @attribute msDebouncePeriod
                 * @type number
                 * @default 0
                 **/
                msDebouncePeriod: {
                    notify: true,
                    type: Number,
                    value: 0
                }
            },

            getCategory: function() {
                return 'Control';
            },
            getComponentName: function() {
                return 'Toggle Switch';
            },
            _getSwitchState: function(checked){
                var result = 'OFF';
                if (checked){
                    result = 'ON';
                }
                return result;
            }

        });
    </script>
</dom-module>
