Liferay.Loader.define("change-tracking-web@1.0.19/change_lists/js/ChangeTrackingDiscardView", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/breadcrumb', '@frontend-taglib-clay$clayui/pagination-bar', '@frontend-taglib-clay$clayui/table', 'frontend-js-web', 'frontend-js-react-web$react'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports["default"] = _default;

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

    var _paginationBar = require("@frontend-taglib-clay$clayui/pagination-bar");

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

    var _frontendJsWeb = require("frontend-js-web");

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

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

    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);
    }

    function _classCallCheck(instance, Constructor) {
      if (!(instance instanceof Constructor)) {
        throw new TypeError("Cannot call a class as a function");
      }
    }

    function _defineProperties(target, props) {
      for (var i = 0; i < props.length; i++) {
        var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);
      }
    }

    function _createClass(Constructor, protoProps, staticProps) {
      if (protoProps) _defineProperties(Constructor.prototype, protoProps);if (staticProps) _defineProperties(Constructor, staticProps);return Constructor;
    }

    function _possibleConstructorReturn(self, call) {
      if (call && (_typeof(call) === "object" || typeof call === "function")) {
        return call;
      }return _assertThisInitialized(self);
    }

    function _assertThisInitialized(self) {
      if (self === void 0) {
        throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
      }return self;
    }

    function _getPrototypeOf(o) {
      _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
        return o.__proto__ || Object.getPrototypeOf(o);
      };return _getPrototypeOf(o);
    }

    function _inherits(subClass, superClass) {
      if (typeof superClass !== "function" && superClass !== null) {
        throw new TypeError("Super expression must either be null or a function");
      }subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } });if (superClass) _setPrototypeOf(subClass, superClass);
    }

    function _setPrototypeOf(o, p) {
      _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
        o.__proto__ = p;return o;
      };return _setPrototypeOf(o, p);
    }

    var ChangeTrackingDiscardView = /*#__PURE__*/function (_React$Component) {
      _inherits(ChangeTrackingDiscardView, _React$Component);

      function ChangeTrackingDiscardView(props) {
        var _this;

        _classCallCheck(this, ChangeTrackingDiscardView);

        _this = _possibleConstructorReturn(this, _getPrototypeOf(ChangeTrackingDiscardView).call(this, props));
        var ctEntries = props.ctEntries,
            renderURL = props.renderURL,
            spritemap = props.spritemap,
            typeNames = props.typeNames,
            userInfo = props.userInfo;
        _this.ctEntries = ctEntries;
        _this.renderURL = renderURL;
        _this.spritemap = spritemap;
        _this.typeNames = typeNames;
        _this.userInfo = userInfo;

        for (var i = 0; i < _this.ctEntries.length; i++) {
          var entry = _this.ctEntries[i];

          var _userInfo = _this.userInfo[entry.userId.toString()];

          entry.portraitURL = _userInfo.portraitURL;
          entry.userName = _userInfo.userName;
          entry.typeName = _this.typeNames[entry.modelClassNameId.toString()];
        }

        _this.ctEntries.sort(function (a, b) {
          var titleA = a.title;
          var titleB = b.title;
          var typeNameA = a.typeName.toUpperCase();
          var typeNameB = b.typeName.toUpperCase();

          if (typeNameA < typeNameB) {
            return -1;
          }

          if (typeNameA > typeNameB) {
            return 1;
          }

          if (titleA < titleB) {
            return -1;
          }

          if (titleA > titleB) {
            return 1;
          }

          return 0;
        });

        _this.state = {
          ascending: true,
          column: 'title',
          delta: 20,
          entry: null,
          page: 1,
          renderInnerHTML: null,
          sortDirectionClass: 'order-arrow-down-active'
        };
        return _this;
      }

      _createClass(ChangeTrackingDiscardView, [{
        key: "_filterDisplayEntries",
        value: function _filterDisplayEntries(entries) {
          if (entries.length > 5) {
            entries = entries.slice(this.state.delta * (this.state.page - 1), this.state.delta * this.state.page);
          }

          return entries;
        }
      }, {
        key: "_getRenderURL",
        value: function _getRenderURL(entry) {
          var portletURL = Liferay.PortletURL.createURL(this.renderURL);
          portletURL.setParameter('ctEntryId', entry.ctEntryId);
          return portletURL.toString();
        }
      }, {
        key: "_getTableRows",
        value: function _getTableRows() {
          var _this2 = this;

          var rows = [];
          var currentTypeName = '';

          var entries = this._filterDisplayEntries(this.ctEntries);

          var _loop = function _loop(i) {
            var entry = entries[i];

            if (entry.typeName !== currentTypeName) {
              currentTypeName = entry.typeName;
              rows.push(_react["default"].createElement(_table["default"].Row, {
                divider: true
              }, _react["default"].createElement(_table["default"].Cell, {
                colSpan: 2
              }, entry.typeName)));
            }

            var cells = [];

            if (entry.portraitURL) {
              cells.push(_react["default"].createElement(_table["default"].Cell, null, _react["default"].createElement("span", {
                className: "lfr-portal-tooltip",
                title: entry.userName
              }, _react["default"].createElement("span", {
                className: "rounded-circle sticker sticker-primary"
              }, _react["default"].createElement("span", {
                className: "sticker-overlay"
              }, _react["default"].createElement("img", {
                alt: "thumbnail",
                className: "img-fluid",
                src: entry.portraitURL
              }))))));
            } else {
              var userPortraitCss = 'sticker sticker-circle sticker-light user-icon-color-';
              userPortraitCss += entry.userId % 10;
              cells.push(_react["default"].createElement(_table["default"].Cell, null, _react["default"].createElement("span", {
                className: "lfr-portal-tooltip",
                title: entry.userName
              }, _react["default"].createElement("span", {
                className: userPortraitCss
              }, _react["default"].createElement("span", {
                className: "inline-item"
              }, _react["default"].createElement("svg", {
                className: "lexicon-icon"
              }, _react["default"].createElement("use", {
                href: _this2.spritemap + '#user'
              })))))));
            }

            cells.push(_react["default"].createElement(_table["default"].Cell, null, _react["default"].createElement("button", {
              className: "change-row-button",
              onClick: function onClick() {
                return _this2._handleNavigation(entry.ctEntryId);
              }
            }, _react["default"].createElement("div", {
              className: "change-list-name"
            }, entry.title), _react["default"].createElement("div", {
              className: "change-list-description"
            }, entry.description))));
            rows.push(_react["default"].createElement(_table["default"].Row, null, cells));
          };

          for (var i = 0; i < entries.length; i++) {
            _loop(i);
          }

          return rows;
        }
      }, {
        key: "_handleDeltaChange",
        value: function _handleDeltaChange(delta) {
          this.setState({
            delta: delta,
            page: 1
          });
        }
      }, {
        key: "_handleNavigation",
        value: function _handleNavigation(entryId) {
          var _this3 = this;

          if (entryId === 0) {
            this.setState({
              entry: null,
              renderInnerHTML: null
            });
            return;
          }

          var _loop2 = function _loop2(i) {
            var entry = _this3.ctEntries[i];

            if (entry.ctEntryId === entryId) {
              _this3.setState({
                entry: entry
              });

              AUI().use('liferay-portlet-url', function () {
                (0, _frontendJsWeb.fetch)(_this3._getRenderURL(entry)).then(function (response) {
                  return response.text();
                }).then(function (text) {
                  _this3.setState({
                    renderInnerHTML: {
                      __html: text
                    }
                  });
                });
              });
              return {
                v: void 0
              };
            }
          };

          for (var i = 0; i < this.ctEntries.length; i++) {
            var _ret = _loop2(i);

            if (_typeof(_ret) === "object") return _ret.v;
          }
        }
      }, {
        key: "_handlePageChange",
        value: function _handlePageChange(page) {
          this.setState({
            page: page
          });
        }
      }, {
        key: "_handleSortColumnChange",
        value: function _handleSortColumnChange(column) {
          this.setState({
            column: column
          });
        }
      }, {
        key: "_handleSortDirectionChange",
        value: function _handleSortDirectionChange() {
          if (this.state.ascending) {
            this.setState({
              ascending: false,
              sortDirectionClass: 'order-arrow-up-active'
            });
            return;
          }

          this.setState({
            ascending: true,
            sortDirectionClass: 'order-arrow-down-active'
          });
        }
      }, {
        key: "_renderBreadcrumbs",
        value: function _renderBreadcrumbs() {
          var _this4 = this;

          var items = [{
            active: true,
            label: Liferay.Language.get('home')
          }];

          if (this.state.entry !== null) {
            items = [{
              label: Liferay.Language.get('home'),
              onClick: function onClick() {
                return _this4._handleNavigation(0);
              }
            }, {
              active: true,
              label: this.state.entry.title
            }];
          }

          return _react["default"].createElement(_breadcrumb["default"], {
            ellipsisBuffer: 1,
            items: items,
            spritemap: this.spritemap
          });
        }
      }, {
        key: "_renderEntry",
        value: function _renderEntry() {
          var content = '';

          if (this.state.renderInnerHTML !== null) {
            content = _react["default"].createElement("div", {
              className: "sheet-section",
              dangerouslySetInnerHTML: this.state.renderInnerHTML
            });
          }

          return _react["default"].createElement("div", {
            className: "sheet"
          }, _react["default"].createElement("h2", {
            className: "sheet-title"
          }, this.state.entry.description), content);
        }
      }, {
        key: "_renderPagination",
        value: function _renderPagination() {
          var _this5 = this;

          if (this.ctEntries.length <= 5) {
            return '';
          }

          return _react["default"].createElement(_paginationBar.ClayPaginationBarWithBasicItems, {
            activeDelta: this.state.delta,
            activePage: this.state.page,
            deltas: [4, 8, 20, 40, 60].map(function (size) {
              return {
                label: size
              };
            }),
            ellipsisBuffer: 3,
            onDeltaChange: function onDeltaChange(delta) {
              return _this5._handleDeltaChange(delta);
            },
            onPageChange: function onPageChange(page) {
              return _this5._handlePageChange(page);
            },
            totalItems: this.ctEntries.length
          });
        }
      }, {
        key: "_renderTable",
        value: function _renderTable() {
          return _react["default"].createElement(_react["default"].Fragment, null, _react["default"].createElement(_table["default"], {
            className: "change-lists-table",
            hover: false
          }, _react["default"].createElement(_table["default"].Head, null, _react["default"].createElement(_table["default"].Row, null, _react["default"].createElement(_table["default"].Cell, {
            headingCell: true,
            style: {
              width: '5%'
            }
          }, Liferay.Language.get('user')), _react["default"].createElement(_table["default"].Cell, {
            headingCell: true,
            style: {
              width: '95%'
            }
          }, Liferay.Language.get('change')))), _react["default"].createElement(_table["default"].Body, null, this._getTableRows())), this._renderPagination());
        }
      }, {
        key: "render",
        value: function render() {
          var content;

          if (this.state.entry === null) {
            content = this._renderTable();
          } else {
            content = this._renderEntry();
          }

          return _react["default"].createElement(_react["default"].Fragment, null, this._renderBreadcrumbs(), content);
        }
      }]);

      return ChangeTrackingDiscardView;
    }(_react["default"].Component);

    function _default(props) {
      return _react["default"].createElement(ChangeTrackingDiscardView, props);
    }
    //# sourceMappingURL=ChangeTrackingDiscardView.js.map
  }
});
//# sourceMappingURL=ChangeTrackingDiscardView.js.map