Liferay.Loader.define("app-builder-web@1.0.76/js/pages/table-view/TableViewSidebar.es", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/form', '@frontend-taglib-clay$clayui/layout', 'data-engine-taglib', 'frontend-js-react-web$react', '../../components/button/Button.es', './EditTableViewContext.es', './TableViewFilters.es', './utils.es'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    function _typeof(obj) {
      "@babel/helpers - typeof";
      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);
    }

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

    var _form = _interopRequireDefault(require("@frontend-taglib-clay$clayui/form"));

    var _layout = _interopRequireDefault(require("@frontend-taglib-clay$clayui/layout"));

    var _dataEngineTaglib = require("data-engine-taglib");

    var _react = _interopRequireWildcard(require("frontend-js-react-web$react"));

    var _Button = _interopRequireDefault(require("../../components/button/Button.es"));

    var _EditTableViewContext = _interopRequireWildcard(require("./EditTableViewContext.es"));

    var _TableViewFilters = _interopRequireDefault(require("./TableViewFilters.es"));

    var _utils = require("./utils.es");

    function _getRequireWildcardCache() {
      if (typeof WeakMap !== "function") return null;var cache = new WeakMap();_getRequireWildcardCache = function _getRequireWildcardCache() {
        return cache;
      };return cache;
    }

    function _interopRequireWildcard(obj) {
      if (obj && obj.__esModule) {
        return obj;
      }if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") {
        return { default: obj };
      }var cache = _getRequireWildcardCache();if (cache && cache.has(obj)) {
        return cache.get(obj);
      }var newObj = {};var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var key in obj) {
        if (Object.prototype.hasOwnProperty.call(obj, key)) {
          var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;if (desc && (desc.get || desc.set)) {
            Object.defineProperty(newObj, key, desc);
          } else {
            newObj[key] = obj[key];
          }
        }
      }newObj.default = obj;if (cache) {
        cache.set(obj, newObj);
      }return newObj;
    }

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

    function _toConsumableArray(arr) {
      return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
    }

    function _nonIterableSpread() {
      throw new TypeError("Invalid attempt to spread non-iterable instance");
    }

    function _iterableToArray(iter) {
      if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
    }

    function _arrayWithoutHoles(arr) {
      if (Array.isArray(arr)) {
        for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
          arr2[i] = arr[i];
        }return arr2;
      }
    }

    function _objectWithoutProperties(source, excluded) {
      if (source == null) return {};var target = _objectWithoutPropertiesLoose(source, excluded);var key, i;if (Object.getOwnPropertySymbols) {
        var sourceSymbolKeys = Object.getOwnPropertySymbols(source);for (i = 0; i < sourceSymbolKeys.length; i++) {
          key = sourceSymbolKeys[i];if (excluded.indexOf(key) >= 0) continue;if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;target[key] = source[key];
        }
      }return target;
    }

    function _objectWithoutPropertiesLoose(source, excluded) {
      if (source == null) return {};var target = {};var sourceKeys = Object.keys(source);var key, i;for (i = 0; i < sourceKeys.length; i++) {
        key = sourceKeys[i];if (excluded.indexOf(key) >= 0) continue;target[key] = source[key];
      }return target;
    }

    function _slicedToArray(arr, i) {
      return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
    }

    function _nonIterableRest() {
      throw new TypeError("Invalid attempt to destructure non-iterable instance");
    }

    function _iterableToArrayLimit(arr, i) {
      if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) {
        return;
      }var _arr = [];var _n = true;var _d = false;var _e = undefined;try {
        for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
          _arr.push(_s.value);if (i && _arr.length === i) break;
        }
      } catch (err) {
        _d = true;_e = err;
      } finally {
        try {
          if (!_n && _i["return"] != null) _i["return"]();
        } finally {
          if (_d) throw _e;
        }
      }return _arr;
    }

    function _arrayWithHoles(arr) {
      if (Array.isArray(arr)) return arr;
    }

    var BtnAction = function BtnAction(_ref) {
      var _ref$angle = _ref.angle,
          angle = _ref$angle === void 0 ? 'left' : _ref$angle,
          className = _ref.className,
          onClick = _ref.onClick;
      return (/*#__PURE__*/_react.default.createElement(_Button.default, {
          className: className,
          displayType: "secondary",
          onClick: onClick,
          symbol: "angle-".concat(angle)
        })
      );
    };

    var FiltersSidebarHeader = function FiltersSidebarHeader() {
      var _useContext = (0, _react.useContext)(_EditTableViewContext.default),
          _useContext2 = _slicedToArray(_useContext, 2),
          _useContext2$ = _useContext2[0],
          dataDefinition = _useContext2$.dataDefinition,
          editingLanguageId = _useContext2$.editingLanguageId,
          fieldTypes = _useContext2$.fieldTypes,
          focusedColumn = _useContext2$.focusedColumn,
          dispatch = _useContext2[1];

      var _DataDefinitionUtils$ = _dataEngineTaglib.DataDefinitionUtils.getDataDefinitionField(dataDefinition, focusedColumn),
          fieldType = _DataDefinitionUtils$.fieldType;

      return (/*#__PURE__*/_react.default.createElement(_dataEngineTaglib.Sidebar.Header, {
          className: "d-flex table-view-filters-sidebar-header"
        }, /*#__PURE__*/_react.default.createElement(_layout.default.ContentRow, {
          verticalAlign: "center"
        }, /*#__PURE__*/_react.default.createElement(_layout.default.ContentCol, null, /*#__PURE__*/_react.default.createElement(BtnAction, {
          className: "mr-2",
          onClick: function onClickBack() {
            dispatch({
              payload: {
                fieldName: null
              },
              type: _EditTableViewContext.UPDATE_FOCUSED_COLUMN
            });
          }
        })), /*#__PURE__*/_react.default.createElement(_layout.default.ContentCol, {
          expand: true
        }, /*#__PURE__*/_react.default.createElement(_dataEngineTaglib.FieldType, {
          description: (0, _utils.getFieldTypeLabel)(fieldTypes, fieldType),
          dragAlignment: "none",
          draggable: false,
          icon: fieldType,
          label: (0, _utils.getFieldLabel)(dataDefinition, editingLanguageId, focusedColumn),
          name: focusedColumn
        }))))
      );
    };

    var FieldsTabContent = function FieldsTabContent(_ref2) {
      var keywords = _ref2.keywords,
          onAddFieldName = _ref2.onAddFieldName;

      var _useContext3 = (0, _react.useContext)(_EditTableViewContext.default),
          _useContext4 = _slicedToArray(_useContext3, 1),
          _useContext4$ = _useContext4[0],
          _useContext4$$dataDef = _useContext4$.dataDefinition,
          _useContext4$$dataDef2 = _useContext4$$dataDef.dataDefinitionFields,
          dataDefinitionFields = _useContext4$$dataDef2 === void 0 ? [] : _useContext4$$dataDef2,
          defaultLanguageId = _useContext4$$dataDef.defaultLanguageId,
          fieldNames = _useContext4$.dataListView.fieldNames,
          editingLanguageId = _useContext4$.editingLanguageId,
          fieldTypes = _useContext4$.fieldTypes;

      var fieldTypesItems = [];

      var fieldTypeModel = function fieldTypeModel(_ref3) {
        var fieldType = _ref3.fieldType,
            label = _ref3.label,
            name = _ref3.name;
        return {
          description: (0, _utils.getFieldTypeLabel)(fieldTypes, fieldType),
          disabled: fieldNames.some(function (fieldName) {
            return fieldName === name;
          }),
          icon: fieldType,
          label: label[editingLanguageId] || label[defaultLanguageId],
          name: name
        };
      };

      dataDefinitionFields.forEach(function (_ref4) {
        var nestedDataDefinitionFields = _ref4.nestedDataDefinitionFields,
            dataDefinitionField = _objectWithoutProperties(_ref4, ["nestedDataDefinitionFields"]);

        if (nestedDataDefinitionFields.length) {
          fieldTypesItems.push.apply(fieldTypesItems, _toConsumableArray(nestedDataDefinitionFields.map(function (nestedField) {
            return fieldTypeModel(nestedField);
          })));
        } else {
          fieldTypesItems.push(fieldTypeModel(dataDefinitionField));
        }
      });
      fieldTypesItems.sort(function (a, b) {
        return a.label.localeCompare(b.label);
      });
      return (/*#__PURE__*/_react.default.createElement(_dataEngineTaglib.FieldTypeList, {
          dragType: _dataEngineTaglib.DragTypes.DRAG_FIELD_TYPE,
          emptyState: {
            description: Liferay.Language.get('columns-are-needed-to-create-table-views-for-this-object'),
            title: Liferay.Language.get('there-are-no-columns-yet')
          },
          fieldTypes: fieldTypesItems,
          keywords: keywords,
          onDoubleClick: function onDoubleClick(_ref5) {
            var name = _ref5.name;
            return onAddFieldName(name, fieldNames.length);
          }
        })
      );
    };

    var _default = function _default(_ref6) {
      var className = _ref6.className,
          onAddFieldName = _ref6.onAddFieldName,
          onToggle = _ref6.onToggle;

      var _useContext5 = (0, _react.useContext)(_EditTableViewContext.default),
          _useContext6 = _slicedToArray(_useContext5, 1),
          focusedColumn = _useContext6[0].focusedColumn;

      var _useState = (0, _react.useState)(''),
          _useState2 = _slicedToArray(_useState, 2),
          keywords = _useState2[0],
          setKeywords = _useState2[1];

      var displayFieldFilters = !!focusedColumn;
      return (/*#__PURE__*/_react.default.createElement("div", {
          className: className
        }, /*#__PURE__*/_react.default.createElement(_dataEngineTaglib.Sidebar, {
          className: "default"
        }, displayFieldFilters ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(FiltersSidebarHeader, null), /*#__PURE__*/_react.default.createElement(_dataEngineTaglib.Sidebar.Body, null, /*#__PURE__*/_react.default.createElement(_TableViewFilters.default, null))) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_dataEngineTaglib.Sidebar.Header, null, /*#__PURE__*/_react.default.createElement(_form.default, {
          onSubmit: function onSubmit(event) {
            return event.preventDefault();
          }
        }, /*#__PURE__*/_react.default.createElement(_dataEngineTaglib.Sidebar.SearchInput, {
          onSearch: function onSearch(keywords) {
            return setKeywords(keywords);
          }
        }, /*#__PURE__*/_react.default.createElement(_layout.default.ContentCol, null, /*#__PURE__*/_react.default.createElement(BtnAction, {
          angle: "right",
          className: "close-sidebar-btn ml-2",
          onClick: onToggle
        }))))), /*#__PURE__*/_react.default.createElement(_dataEngineTaglib.Sidebar.Body, null, !displayFieldFilters && /*#__PURE__*/_react.default.createElement(_dataEngineTaglib.Sidebar.Tabs, {
          tabs: [{
            label: Liferay.Language.get('columns'),
            render: function render() {
              return (/*#__PURE__*/_react.default.createElement(FieldsTabContent, {
                  keywords: keywords,
                  onAddFieldName: onAddFieldName
                })
              );
            }
          }, {
            label: Liferay.Language.get('filters'),
            render: function render() {
              return (/*#__PURE__*/_react.default.createElement(_TableViewFilters.default, null)
              );
            }
          }]
        })))), /*#__PURE__*/_react.default.createElement(_dataEngineTaglib.Sidebar, {
          className: "secondary"
        }, /*#__PURE__*/_react.default.createElement(BtnAction, {
          className: "m-3 open-sidebar-btn",
          onClick: onToggle
        })))
      );
    };

    exports.default = _default;
    //# sourceMappingURL=TableViewSidebar.es.js.map
  }
});
//# sourceMappingURL=TableViewSidebar.es.js.map