Liferay.Loader.define("dynamic-data-mapping-form-report-web@1.0.29/js/components/list/List.es", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/button', 'dynamic-data-mapping-form-report-web$moment', 'frontend-js-react-web$react', '../../utils/data.es', '../color/Color.es', '../sidebar/SidebarContext.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 _button = _interopRequireDefault(require("@frontend-taglib-clay$clayui/button"));

    var _moment = _interopRequireDefault(require("dynamic-data-mapping-form-report-web$moment"));

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

    var _data = require("../../utils/data.es");

    var _Color = _interopRequireDefault(require("../color/Color.es"));

    var _SidebarContext = require("../sidebar/SidebarContext.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 };
    }

    /**
     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
     *
     * This library is free software; you can redistribute it and/or modify it under
     * the terms of the GNU Lesser General Public License as published by the Free
     * Software Foundation; either version 2.1 of the License, or (at your option)
     * any later version.
     *
     * This library is distributed in the hope that it will be useful, but WITHOUT
     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
     * details.
     */
    var _default = function _default(_ref) {
      var data = _ref.data,
          field = _ref.field,
          summary = _ref.summary,
          totalEntries = _ref.totalEntries,
          type = _ref.type;

      var _useContext = (0, _react.useContext)(_SidebarContext.SidebarContext),
          portletNamespace = _useContext.portletNamespace,
          toggleSidebar = _useContext.toggleSidebar;

      var formatDate = function formatDate(field) {
        var locale = themeDisplay.getLanguageId().split('_', 1).join('');
        return (0, _moment.default)(field).locale(locale).format('L');
      };

      var formatDocument = function formatDocument(field) {
        var _JSON$parse = JSON.parse(field),
            documentTitle = _JSON$parse.title,
            documentURL = _JSON$parse.url;

        return (/*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("a", {
            className: "document-title-link",
            download: documentTitle,
            href: documentURL
          }, documentTitle))
        );
      };

      var checkType = function checkType(field, type) {
        switch (type) {
          case 'color':
            return (/*#__PURE__*/_react.default.createElement(_Color.default, {
                hexColor: field
              })
            );

          case 'date':
            return formatDate(field);

          case 'document_library':
            return formatDocument(field);

          case 'image':
            return formatDocument(field);

          default:
            return field;
        }
      };

      data = (0, _data.removeEmptyValues)(data);
      return (/*#__PURE__*/_react.default.createElement("div", {
          className: "field-list"
        }, /*#__PURE__*/_react.default.createElement("ul", {
          className: "entries-list"
        }, Array.isArray(data) && data.map(function (field, index) {
          return (/*#__PURE__*/_react.default.createElement("li", {
              key: index
            }, checkType(field, type))
          );
        }), data.length == 5 && totalEntries > 5 ? /*#__PURE__*/_react.default.createElement("li", {
          id: "".concat(portletNamespace, "-see-more"),
          key: 'see-more'
        }, /*#__PURE__*/_react.default.createElement(_button.default, {
          displayType: "link",
          onClick: function onClick() {
            return toggleSidebar(field, summary, totalEntries, type);
          }
        }, Liferay.Language.get('see-all-entries'))) : null))
      );
    };

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