Liferay.Loader.define("commerce-frontend-js@3.0.26/components/dataset_display/views/table/TableHeadRow", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/icon', '@frontend-taglib-clay$clayui/table', 'frontend-js-react-web$classnames', 'frontend-js-react-web$prop-types', 'frontend-js-react-web$react', '../../../data_renderers/CheckboxRenderer', '../../DatasetDisplayContext'], 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 _icon = _interopRequireDefault(require("@frontend-taglib-clay$clayui/icon"));

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

    var _classnames = _interopRequireDefault(require("frontend-js-react-web$classnames"));

    var _propTypes = _interopRequireDefault(require("frontend-js-react-web$prop-types"));

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

    var _CheckboxRenderer = _interopRequireDefault(require("../../../data_renderers/CheckboxRenderer"));

    var _DatasetDisplayContext = _interopRequireDefault(require("../../DatasetDisplayContext"));

    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 _extends() {
      _extends = Object.assign || function (target) {
        for (var i = 1; i < arguments.length; i++) {
          var source = arguments[i];for (var key in source) {
            if (Object.prototype.hasOwnProperty.call(source, key)) {
              target[key] = source[key];
            }
          }
        }return target;
      };return _extends.apply(this, arguments);
    }

    function ownKeys(object, enumerableOnly) {
      var keys = Object.keys(object);if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);if (enumerableOnly) symbols = symbols.filter(function (sym) {
          return Object.getOwnPropertyDescriptor(object, sym).enumerable;
        });keys.push.apply(keys, symbols);
      }return keys;
    }

    function _objectSpread(target) {
      for (var i = 1; i < arguments.length; i++) {
        var source = arguments[i] != null ? arguments[i] : {};if (i % 2) {
          ownKeys(Object(source), true).forEach(function (key) {
            _defineProperty(target, key, source[key]);
          });
        } else if (Object.getOwnPropertyDescriptors) {
          Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
        } else {
          ownKeys(Object(source)).forEach(function (key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
          });
        }
      }return target;
    }

    function _defineProperty(obj, key, value) {
      if (key in obj) {
        Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true });
      } else {
        obj[key] = value;
      }return obj;
    }

    function TableHeadCell(props) {
      var sortingKey = props.sortingKey || (Array.isArray(props.fieldName) ? props.fieldName[0] : props.fieldName);
      var sortingMatch = props.sorting.find(function (el) {
        return el.key === sortingKey;
      });

      return (/*#__PURE__*/_react.default.createElement(_table.default.Cell, {
          className: (0, _classnames.default)(props.contentRenderer && "content-renderer-".concat(props.contentRenderer), props.expandableColumns ? props.expand && 'table-cell-expand-small' : 'table-cell-expand-smaller'),
          headingCell: true,
          headingTitle: true
        }, props.sortable ? /*#__PURE__*/_react.default.createElement("a", {
          className: "inline-item text-nowrap text-truncate-inline",
          "data-senna-off": true,
          href: "#",
          onClick: function handleSortingCellClick(e) {
            e.preventDefault();

            if (sortingMatch) {
              var updatedSortedElements = props.sorting.map(function (el) {
                return el.key === sortingKey ? _objectSpread(_objectSpread({}, el), {}, {
                  direction: el.direction === 'asc' ? 'desc' : 'asc'
                }) : el;
              });
              props.updateSorting(updatedSortedElements);
            } else {
              props.updateSorting([{
                direction: 'asc',
                key: sortingKey
              }]);
            }
          }
        }, props.label || '', /*#__PURE__*/_react.default.createElement("span", {
          className: "inline-item inline-item-after sorting-icons-wrapper"
        }, /*#__PURE__*/_react.default.createElement(_icon.default, {
          className: (0, _classnames.default)('sorting-icon', sortingMatch && sortingMatch.direction === 'asc' && 'active'),
          draggable: true,
          symbol: "order-arrow-up"
        }), /*#__PURE__*/_react.default.createElement(_icon.default, {
          className: (0, _classnames.default)('sorting-icon', sortingMatch && sortingMatch.direction === 'desc' && 'active'),
          draggable: true,
          symbol: "order-arrow-down"
        }))) : props.label || '')
      );
    }

    function TableHeadRow(props) {
      var _useContext = (0, _react.useContext)(_DatasetDisplayContext.default),
          actionLoading = _useContext.actionLoading;

      return (/*#__PURE__*/_react.default.createElement(_table.default.Head, null, /*#__PURE__*/_react.default.createElement(_table.default.Row, null, props.selectable && /*#__PURE__*/_react.default.createElement(_table.default.Cell, {
          headingCell: true
        }, props.items.length && props.selectionType === 'multiple' ? /*#__PURE__*/_react.default.createElement(_CheckboxRenderer.default, {
          checked: !!props.selectedItemsValue.length,
          disabled: actionLoading,
          indeterminate: !!props.selectedItemsValue.length && props.items.length !== props.selectedItemsValue.length,
          name: "table-head-selector",
          onChange: function handleCheckboxClick() {
            if (props.selectedItemsValue.length === props.items.length) {
              return props.selectItems([]);
            }

            return props.selectItems(props.items.map(function (item) {
              return item[props.selectedItemsKey];
            }));
          }
        }) : null), function getColumns(fields) {
          var expandableColumns = fields.reduce(function (expandable, field) {
            return expandable || Boolean(field.expand);
          }, false);
          return fields.map(function (field, i) {
            return (/*#__PURE__*/_react.default.createElement(TableHeadCell, _extends({}, field, {
                expandableColumns: expandableColumns,
                key: field.sortingKey || field.fieldName || i,
                sorting: props.sorting,
                updateSorting: props.updateSorting
              }))
            );
          });
        }(props.schema.fields), props.showActionItems && /*#__PURE__*/_react.default.createElement(_table.default.Cell, {
          headingCell: true
        })))
      );
    }

    var _default = TableHeadRow;
    exports.default = _default;
    //# sourceMappingURL=TableHeadRow.js.map
  }
});
//# sourceMappingURL=TableHeadRow.js.map