"use strict";

exports.__esModule = true;
exports["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _dropdown = _interopRequireDefault(require("./dropdown"));
var _box = _interopRequireDefault(require("../../../../templates/box"));
var _flex = _interopRequireDefault(require("../../../../templates/flex"));
var _input = require("../../../../input");
var _throttleDebounce = require("throttle-debounce");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
var Comparisons = [{
  value: "all",
  label: "All"
}, {
  value: "gt",
  label: "Greater than"
}, {
  value: "eq",
  label: "Equal"
}, {
  value: "lt",
  label: "Less than"
}];
var ComparisonFilter = function ComparisonFilter(_ref) {
  var column = _ref.column;
  var setFilterValue = column.setFilterValue,
    getFilterValue = column.getFilterValue;
  var filterValue = getFilterValue();
  (0, _react.useEffect)(function () {
    setFilterValue(function (old) {
      return [Comparisons[0], old == null ? void 0 : old[1]];
    });
  }, []);
  return /*#__PURE__*/_react["default"].createElement(_flex["default"], {
    gap: 2
  }, /*#__PURE__*/_react["default"].createElement(_dropdown["default"], {
    value: filterValue ? filterValue[0] : Comparisons[0],
    options: Comparisons,
    onChange: function onChange(value) {
      return setFilterValue(function (old) {
        return [value, old == null ? void 0 : old[1]];
      });
    }
  }), /*#__PURE__*/_react["default"].createElement(_box["default"], {
    as: _input.TextInput,
    width: {
      max: 50
    },
    value: filterValue ? filterValue[1] : null,
    onChange: (0, _throttleDebounce.debounce)(300, function (e) {
      e.persist();
      setFilterValue(function (old) {
        return [old == null ? void 0 : old[0], e.target.value];
      });
    }),
    pattern: "[0-9]*(.[0-9]+)?",
    inputMode: "decimal",
    size: "tiny"
  }));
};
var _default = exports["default"] = ComparisonFilter;