// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
"use strict";
var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var widget_1 = require('./widget');
var _ = require('underscore');
var widget_int_1 = require('./widget_int');
var d3format = require('d3-format').format;
var FloatModel = (function (_super) {
    __extends(FloatModel, _super);
    function FloatModel() {
        _super.apply(this, arguments);
    }
    FloatModel.prototype.defaults = function () {
        return _.extend(_super.prototype.defaults.call(this), {
            _model_name: "FloatModel",
            value: 0,
            disabled: false,
        });
    };
    return FloatModel;
}(widget_1.LabeledDOMWidgetModel));
exports.FloatModel = FloatModel;
var BoundedFloatModel = (function (_super) {
    __extends(BoundedFloatModel, _super);
    function BoundedFloatModel() {
        _super.apply(this, arguments);
    }
    BoundedFloatModel.prototype.defaults = function () {
        return _.extend(_super.prototype.defaults.call(this), {
            _model_name: "BoundedFloatModel",
            step: 1.0,
            max: 100.0,
            min: 0.0
        });
    };
    return BoundedFloatModel;
}(FloatModel));
exports.BoundedFloatModel = BoundedFloatModel;
var FloatSliderModel = (function (_super) {
    __extends(FloatSliderModel, _super);
    function FloatSliderModel() {
        _super.apply(this, arguments);
    }
    FloatSliderModel.prototype.defaults = function () {
        return _.extend(_super.prototype.defaults.call(this), {
            _model_name: "FloatSliderModel",
            _view_name: "FloatSliderView",
            orientation: "horizontal",
            _range: false,
            readout: true,
            readout_format: '.2f',
            slider_color: null,
            continuous_update: true
        });
    };
    FloatSliderModel.prototype.initialize = function (attributes, options) {
        _super.prototype.initialize.call(this, attributes, options);
        this.on('change:readout_format', this.update_readout_format, this);
        this.update_readout_format();
    };
    FloatSliderModel.prototype.update_readout_format = function () {
        this.readout_formatter = d3format(this.get('readout_format'));
    };
    return FloatSliderModel;
}(BoundedFloatModel));
exports.FloatSliderModel = FloatSliderModel;
var FloatSliderView = (function (_super) {
    __extends(FloatSliderView, _super);
    function FloatSliderView() {
        _super.apply(this, arguments);
        this._parse_value = parseFloat;
        // matches: whitespace?, float, whitespace?, [-:], whitespace?, float
        this._range_regex = /^\s*([+-]?(?:\d*\.?\d+|\d+\.)(?:[eE][+-]?\d+)?)\s*[-:]\s*([+-]?(?:\d*\.?\d+|\d+\.)(?:[eE][+-]?\d+)?)/;
    }
    /**
     * Validate the value of the slider before sending it to the back-end
     * and applying it to the other views on the page.
     */
    FloatSliderView.prototype._validate_slide_value = function (x) {
        return x;
    };
    return FloatSliderView;
}(widget_int_1.IntSliderView));
exports.FloatSliderView = FloatSliderView;
var FloatTextModel = (function (_super) {
    __extends(FloatTextModel, _super);
    function FloatTextModel() {
        _super.apply(this, arguments);
    }
    FloatTextModel.prototype.defaults = function () {
        return _.extend(_super.prototype.defaults.call(this), {
            _model_name: "FloatTextModel",
            _view_name: "FloatTextView"
        });
    };
    return FloatTextModel;
}(FloatModel));
exports.FloatTextModel = FloatTextModel;
var FloatTextView = (function (_super) {
    __extends(FloatTextView, _super);
    function FloatTextView() {
        _super.apply(this, arguments);
        this._parse_value = parseFloat;
    }
    return FloatTextView;
}(widget_int_1.IntTextView));
exports.FloatTextView = FloatTextView;
