Source: widgets/player/buttons/playpause.js

define('application/widgets/player/buttons/playpause', [
    'application/widgets/pointerfocusablebutton',
    'rofl/widgets/label'
], function (
    Button,
    Label
) {
    'use strict';

    var PLAY_CLASS = 'icon-play-v2',
        PAUSE_CLASS = 'icon-pause-v2',
        STATES = {
            PLAYING: 'playing',
            PAUSED: 'paused'
        },
        PlayButton;

    PlayButton = Button.extend({

        /**
         * Initialises the widget.
         *
         * @param {string} id - The id.
         */
        init: function init (id) {
            init.base.call(this, id);
            this._state = STATES.PLAYING;

            this.addClass(['control', 'playpause']);
            this._build();
        },

        /**
         * Builds the widget.
         *
         * @private
         */
        _build: function () {
            var icon = this._icon = new Label({ text: '', classNames: ['v-align-target', 'icon', PAUSE_CLASS] }),
                helper = new Label({ text: '', classNames: ['v-align-helper'] });

            this.appendChildWidget(helper);
            this.appendChildWidget(icon);
        },

        /**
         * Sets the state.
         *
         * @param {string} state - The current state.
         */
        setState: function (state) {
            var oldClass = this._state === STATES.PLAYING ? PAUSE_CLASS : PLAY_CLASS,
                newClass = state === STATES.PLAYING ? PAUSE_CLASS : PLAY_CLASS,
                icon = this._icon;

            if (oldClass === newClass) {
                return;
            }

            this._state = state;
            icon.removeClass(oldClass);
            icon.addClass(newClass);
        },

        /**
         * Gets the playpause button state.
         *
         * @returns {string} - The button's state.
         */
        getState: function () {
            return this._state;
        },

        /**
         * Resets the playpause button.
         */
        reset: function () {
            this.setState(STATES.PLAYING);
        }
    });

    PlayButton.STATES = STATES;

    return PlayButton;
});