"use strict";

exports.__esModule = true;
exports.OperatorFilterPicker = void 0;
var _react = _interopRequireWildcard(require("react"));
var _mobxReactLite = require("mobx-react-lite");
var _designSystem = require("@wix/design-system");
var _bexCore = require("@wix/bex-core");
var _react2 = require("@wix/bex-core/react");
var _useOperatorFilterState = require("../../hooks/useOperatorFilterState");
var _wixUiIconsCommon = require("@wix/wix-ui-icons-common");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/OperatorFilterPicker/OperatorFilterPicker.tsx";
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (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 (const 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); }
function _OperatorFilterPicker(props) {
  var _state$value;
  const {
    filter,
    allowedOperators
  } = props;
  const {
    translate: t
  } = (0, _react2.useWixPatternsContainer)();
  const state = (0, _useOperatorFilterState.useOperatorFilterState)({
    filter,
    allowedOperators
  });
  (0, _react.useEffect)(() => state.init(), [state]);
  const operatorOptions = allowedOperators.map(op => (0, _designSystem.listItemSelectBuilder)({
    id: op,
    title: t((0, _bexCore.getOperatorLabel)(op)),
    label: t((0, _bexCore.getOperatorLabel)(op))
  }));
  const showValueInput = state.operatorNeedsValue();
  return /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
    dataHook: `operator-picker-${filter.name}`,
    direction: "vertical",
    gap: "12px",
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 52,
      columnNumber: 5
    }
  }, /*#__PURE__*/_react.default.createElement(_designSystem.FormField, {
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 57,
      columnNumber: 7
    }
  }, /*#__PURE__*/_react.default.createElement(_designSystem.DropdownBase, {
    options: operatorOptions,
    selectedId: state.operator,
    onSelect: option => state.setOperator(option.id),
    dataHook: "operator-picker-operator-dropdown",
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 58,
      columnNumber: 9
    }
  }, ({
    toggle
  }) => /*#__PURE__*/_react.default.createElement(_designSystem.TextButton, {
    skin: "dark",
    onClick: toggle,
    suffixIcon: /*#__PURE__*/_react.default.createElement(_wixUiIconsCommon.ChevronDown, {
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 68,
        columnNumber: 27
      }
    }),
    size: "small",
    dataHook: "operator-picker-trigger",
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 65,
      columnNumber: 13
    }
  }, t((0, _bexCore.getOperatorLabel)(state.operator))))), showValueInput && /*#__PURE__*/_react.default.createElement(_designSystem.FormField, {
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 79,
      columnNumber: 9
    }
  }, /*#__PURE__*/_react.default.createElement(_designSystem.Input, {
    border: 'round',
    value: ((_state$value = state.value) == null ? void 0 : _state$value.toString()) || '',
    placeholder: t('cairo.filterOperator.valuePlaceholder'),
    onChange: e => state.setValue(e.target.value),
    onBlur: () => state.applyImmediately(),
    onKeyDown: e => {
      if (e.key === 'Enter') {
        state.applyImmediately();
      }
    },
    dataHook: "operator-picker-value-input",
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 80,
      columnNumber: 11
    }
  })));
}
const OperatorFilterPicker = exports.OperatorFilterPicker = (0, _mobxReactLite.observer)(_OperatorFilterPicker);
//# sourceMappingURL=OperatorFilterPicker.js.map