var __extends = (this && this.__extends) || (function () {
    var extendStatics = Object.setPrototypeOf ||
        ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
        function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "@angular/core", "@angular/forms", "../../config/config", "../ion", "../../util/util", "./segment-button"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var core_1 = require("@angular/core");
    var forms_1 = require("@angular/forms");
    var config_1 = require("../../config/config");
    var ion_1 = require("../ion");
    var util_1 = require("../../util/util");
    var segment_button_1 = require("./segment-button");
    /**
     * \@name Segment
     * \@description
     * A Segment is a group of buttons, sometimes known as Segmented Controls, that allow the user to interact with a compact group of a number of controls.
     * Segments provide functionality similar to tabs, selecting one will unselect all others. You should use a tab bar instead of a segmented control when you want to let the user move back and forth between distinct pages in your app.
     * You could use Angular 2's `ngModel` or `FormBuilder` API. For an overview on how `FormBuilder` works, checkout [Angular 2 Forms](http://learnangular2.com/forms/), or [Angular FormBuilder](https://angular.io/docs/ts/latest/api/forms/index/FormBuilder-class.html)
     *
     *
     * ```html
     * <!-- Segment in a header -->
     * <ion-header>
     *   <ion-toolbar>
     *     <ion-segment [(ngModel)]="icons" color="secondary">
     *       <ion-segment-button value="camera">
     *         <ion-icon name="camera"></ion-icon>
     *       </ion-segment-button>
     *       <ion-segment-button value="bookmark">
     *         <ion-icon name="bookmark"></ion-icon>
     *       </ion-segment-button>
     *     </ion-segment>
     *   </ion-toolbar>
     * </ion-header>
     *
     * <ion-content>
     *   <!-- Segment in content -->
     *   <ion-segment [(ngModel)]="relationship" color="primary">
     *     <ion-segment-button value="friends" (ionSelect)="selectedFriends()">
     *       Friends
     *     </ion-segment-button>
     *     <ion-segment-button value="enemies" (ionSelect)="selectedEnemies()">
     *       Enemies
     *     </ion-segment-button>
     *   </ion-segment>
     *
     *   <!-- Segment in a form -->
     *   <form [formGroup]="myForm">
     *     <ion-segment formControlName="mapStyle" color="danger">
     *       <ion-segment-button value="standard">
     *         Standard
     *       </ion-segment-button>
     *       <ion-segment-button value="hybrid">
     *         Hybrid
     *       </ion-segment-button>
     *       <ion-segment-button value="sat">
     *         Satellite
     *       </ion-segment-button>
     *     </ion-segment>
     *   </form>
     * </ion-content>
     * ```
     *
     *
     * \@demo /docs/v2/demos/src/segment/
     * @see {\@link /docs/v2/components#segment Segment Component Docs}
     * @see [Angular 2 Forms](http://learnangular2.com/forms/)
     */
    var Segment = (function (_super) {
        __extends(Segment, _super);
        /**
         * @param {?} config
         * @param {?} elementRef
         * @param {?} renderer
         * @param {?} ngControl
         */
        function Segment(config, elementRef, renderer, ngControl) {
            var _this = _super.call(this, config, elementRef, renderer, 'segment') || this;
            _this._disabled = false;
            /**
             * \@output {Any} Emitted when a segment button has been changed.
             */
            _this.ionChange = new core_1.EventEmitter();
            /**
             * @hidden
             */
            _this.onChange = function (_) { };
            /**
             * @hidden
             */
            _this.onTouched = function (_) { };
            if (ngControl) {
                ngControl.valueAccessor = _this;
            }
            return _this;
        }
        Object.defineProperty(Segment.prototype, "disabled", {
            /**
             * \@input {boolean} If true, the user cannot interact with any of the buttons in the segment.
             * @return {?}
             */
            get: function () {
                return this._disabled;
            },
            /**
             * @param {?} val
             * @return {?}
             */
            set: function (val) {
                var _this = this;
                this._disabled = util_1.isTrueProperty(val);
                if (this._buttons) {
                    this._buttons.forEach(function (button) {
                        button._setElementClass('segment-button-disabled', _this._disabled);
                    });
                }
            },
            enumerable: true,
            configurable: true
        });
        /**
         * @hidden
         * Write a new value to the element.
         * @param {?} value
         * @return {?}
         */
        Segment.prototype.writeValue = function (value) {
            this.value = util_1.isPresent(value) ? value : '';
            if (this._buttons) {
                var /** @type {?} */ buttons = this._buttons.toArray();
                for (var _i = 0, buttons_1 = buttons; _i < buttons_1.length; _i++) {
                    var button = buttons_1[_i];
                    button.isActive = (button.value === this.value);
                }
            }
        };
        /**
         * @hidden
         * @return {?}
         */
        Segment.prototype.ngAfterViewInit = function () {
            var _this = this;
            this._buttons.forEach(function (button) {
                button.ionSelect.subscribe(function (selectedButton) {
                    _this.writeValue(selectedButton.value);
                    _this.onChange(selectedButton.value);
                    _this.ionChange.emit(selectedButton);
                });
                if (util_1.isPresent(_this.value)) {
                    button.isActive = (button.value === _this.value);
                }
                if (util_1.isTrueProperty(_this._disabled)) {
                    button._setElementClass('segment-button-disabled', _this._disabled);
                }
            });
        };
        /**
         * @hidden
         * Set the function to be called when the control receives a change event.
         * @param {?} fn
         * @return {?}
         */
        Segment.prototype.registerOnChange = function (fn) { this.onChange = fn; };
        /**
         * @hidden
         * Set the function to be called when the control receives a touch event.
         * @param {?} fn
         * @return {?}
         */
        Segment.prototype.registerOnTouched = function (fn) { this.onTouched = fn; };
        return Segment;
    }(ion_1.Ion));
    Segment.decorators = [
        { type: core_1.Directive, args: [{
                    selector: 'ion-segment'
                },] },
    ];
    /**
     * @nocollapse
     */
    Segment.ctorParameters = function () { return [
        { type: config_1.Config, },
        { type: core_1.ElementRef, },
        { type: core_1.Renderer, },
        { type: forms_1.NgControl, decorators: [{ type: core_1.Optional },] },
    ]; };
    Segment.propDecorators = {
        'ionChange': [{ type: core_1.Output },],
        '_buttons': [{ type: core_1.ContentChildren, args: [segment_button_1.SegmentButton,] },],
        'disabled': [{ type: core_1.Input },],
    };
    exports.Segment = Segment;
    function Segment_tsickle_Closure_declarations() {
        /** @type {?} */
        Segment.decorators;
        /**
         * @nocollapse
         * @type {?}
         */
        Segment.ctorParameters;
        /** @type {?} */
        Segment.propDecorators;
        /** @type {?} */
        Segment.prototype._disabled;
        /**
         * @hidden
         * @type {?}
         */
        Segment.prototype.value;
        /**
         * \@output {Any} Emitted when a segment button has been changed.
         * @type {?}
         */
        Segment.prototype.ionChange;
        /**
         * @hidden
         * @type {?}
         */
        Segment.prototype._buttons;
        /**
         * @hidden
         * @type {?}
         */
        Segment.prototype.onChange;
        /**
         * @hidden
         * @type {?}
         */
        Segment.prototype.onTouched;
    }
});
//# sourceMappingURL=segment.js.map