"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 _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
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();
  var _useState = (0, _react.useState)((filterValue == null ? void 0 : filterValue[1]) || ""),
    query = _useState[0],
    setQuery = _useState[1];
  (0, _react.useEffect)(function () {
    setFilterValue(function (old) {
      return [Comparisons[0], old == null ? void 0 : old[1]];
    });
  }, []);
  var handleComparisonChange = (0, _react.useCallback)(function (value) {
    setFilterValue(function (old) {
      return [value, old == null ? void 0 : old[1]];
    });
  }, [setFilterValue]);
  var debouncedSetFilter = (0, _react.useCallback)((0, _throttleDebounce.debounce)(300, function (value) {
    setFilterValue(function (old) {
      return [old == null ? void 0 : old[0], value];
    });
  }), [setFilterValue]);
  var handleValueChange = (0, _react.useCallback)(function (e) {
    var value = e.target.value;
    setQuery(value);
    debouncedSetFilter(value);
  }, [debouncedSetFilter]);
  return /*#__PURE__*/_react["default"].createElement(_flex["default"], {
    gap: 2
  }, /*#__PURE__*/_react["default"].createElement(_dropdown["default"], {
    value: filterValue ? filterValue[0] : Comparisons[0],
    options: Comparisons,
    onChange: handleComparisonChange
  }), /*#__PURE__*/_react["default"].createElement(_box["default"], {
    as: _input.TextInput,
    width: {
      max: 50
    },
    value: query,
    onChange: handleValueChange,
    pattern: "[0-9]*(.[0-9]+)?",
    inputMode: "decimal",
    size: "tiny"
  }));
};
var _default = exports["default"] = ComparisonFilter;