"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _createSimpleDialog = require("./createSimpleDialog");

var _createSimpleDialog2 = _interopRequireDefault(_createSimpleDialog);

var _teselagenReactComponents = require("teselagen-react-components");

var _lodash = require("lodash");

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

// Single validation function - from & to have the same range
var validate = function validate(val, vals, props) {
  var _get = (0, _lodash.get)(props, "extraProps.from", {}),
      min = _get.min,
      max = _get.max;

  if (min && val < min || max && val > max) {
    return "Invalid position";
  }
  if (vals.from > vals.to) {
    return "Wrong from/to order";
  }
};

exports.default = (0, _createSimpleDialog2.default)({
  formName: "selectDialog",
  fields: [{ name: "from", component: _teselagenReactComponents.NumericInputField, validate: validate }, { name: "to", component: _teselagenReactComponents.NumericInputField, validate: validate }],
  dialogProps: { title: "Select Range", height: 270 }
});
module.exports = exports["default"];