"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _react = _interopRequireDefault(require("react"));

var _reactMaterialize = require("react-materialize");

var _modularityFront = _interopRequireDefault(require("modularity-front"));

var _reactInputRange = _interopRequireDefault(require("react-input-range"));

require("react-input-range/lib/css/index.css");

require("./Filter.css");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

var Module = _modularityFront.default.Module;

var RangeFilter =
/*#__PURE__*/
function (_Modularity$Module) {
  _inherits(RangeFilter, _Modularity$Module);

  function RangeFilter(props) {
    var _this;

    _classCallCheck(this, RangeFilter);

    _this = _possibleConstructorReturn(this, _getPrototypeOf(RangeFilter).call(this, props));
    _this.state = _objectSpread({}, props.filter);

    var r = function r() {
      this.value = {
        min: this.options[0],
        max: this.options[1]
      };
    };

    _this.filter.onUpdate(function (f) {
      f.reset = r.bind(f);
    });

    _this.filter.value.reset = r.bind(_this.filter.value);
    return _this;
  }

  _createClass(RangeFilter, [{
    key: "checkFilter",
    value: function checkFilter(value) {
      var _this2 = this;

      var options = [value.min, value.max];
      this.filter.value.value = value;
      this.forceUpdate();

      if (!this._timer) {
        this._timer = setTimeout(function (e) {
          var value = _this2.filter.value.value;

          _this2.Filters.set(_objectSpread({}, _this2.filter.value, {
            values: [value.min, value.max]
          }));

          _this2._timer = undefined;
        }, this.refreshTime.value || 0);
      }
    }
  }, {
    key: "render",
    value: function render() {
      var _this3 = this;

      var filter = this.filter.value;
      if (!filter.value) filter.reset();
      var options = filter.options || [0, 100];
      return _react.default.createElement("div", {
        className: "flex-item"
      }, _react.default.createElement(_reactMaterialize.Row, {
        style: {
          paddingBottom: 8
        }
      }, _react.default.createElement(_reactMaterialize.Col, {
        s: 12
      }, this.filter.value.name)), _react.default.createElement(_reactMaterialize.Row, null, _react.default.createElement(_reactMaterialize.Col, {
        s: 12,
        style: {
          padding: "20px 20px"
        }
      }, _react.default.createElement(_reactInputRange.default, {
        minValue: options[0],
        maxValue: options[1],
        value: filter.value,
        onChange: function onChange(value) {
          return _this3.checkFilter(value);
        }
      }))));
    }
  }]);

  return RangeFilter;
}(_modularityFront.default.Module);

RangeFilter.Inputs = {
  filter: {
    type: Module.Types.Object
  },
  refreshTime: {
    type: Module.Types.Number
  }
};
RangeFilter.Outputs = {
  Filters: {}
};
RangeFilter.Category = 'sxoinas';
var _default = RangeFilter;
exports.default = _default;