Liferay.Loader.define("dynamic-data-mapping-form-field-type@5.0.110/Grid/Grid.es", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/form', '@frontend-taglib-clay$clayui/table', 'frontend-js-react-web$react', '../FieldBase/ReactFieldBase.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 = require("@frontend-taglib-clay$clayui/form");

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

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

    var _ReactFieldBase = require("../FieldBase/ReactFieldBase.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 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 _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;
    }

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

    var TableHead = function TableHead(_ref) {
      var columns = _ref.columns;
      return (/*#__PURE__*/_react.default.createElement(_table.default.Head, null, /*#__PURE__*/_react.default.createElement(_table.default.Row, null, /*#__PURE__*/_react.default.createElement(_table.default.Cell, {
          headingCell: true
        }), columns.map(function (column, colIndex) {
          return (/*#__PURE__*/_react.default.createElement(_table.default.Cell, {
              headingCell: true,
              key: "column-".concat(column.value, "-").concat(colIndex)
            }, column.label)
          );
        })))
      );
    };

    var TableBodyColumns = function TableBodyColumns(_ref2) {
      var columns = _ref2.columns,
          disabled = _ref2.disabled,
          name = _ref2.name,
          onBlur = _ref2.onBlur,
          onChange = _ref2.onChange,
          onFocus = _ref2.onFocus,
          row = _ref2.row,
          value = _ref2.value;
      var columnLabel = Liferay.Language.get('column');
      var rowLabel = Liferay.Language.get('row');
      return columns.map(function (column, colIndex) {
        return (/*#__PURE__*/_react.default.createElement(_table.default.Cell, {
            key: "cell-".concat(column.value, "-").concat(colIndex)
          }, /*#__PURE__*/_react.default.createElement(_form.ClayRadio, {
            "aria-label": "".concat(rowLabel, ": ").concat(row.label, ", ").concat(columnLabel, ": ").concat(column.label),
            checked: column.value === value[row.value],
            className: "form-builder-grid-field",
            "data-name": row.value,
            disabled: disabled,
            name: name,
            onBlur: onBlur,
            onChange: onChange,
            onFocus: onFocus,
            value: column.value
          }))
        );
      });
    };

    var Grid = function Grid(_ref3) {
      var _ref3$columns = _ref3.columns,
          columns = _ref3$columns === void 0 ? [{
        label: 'col1',
        value: 'fieldId'
      }] : _ref3$columns,
          disabled = _ref3.disabled,
          name = _ref3.name,
          onBlur = _ref3.onBlur,
          onChange = _ref3.onChange,
          onFocus = _ref3.onFocus,
          _ref3$rows = _ref3.rows,
          rows = _ref3$rows === void 0 ? [{
        label: 'row',
        value: 'jehf'
      }] : _ref3$rows,
          value = _ref3.value,
          otherProps = _objectWithoutProperties(_ref3, ["columns", "disabled", "name", "onBlur", "onChange", "onFocus", "rows", "value"]);

      return (/*#__PURE__*/_react.default.createElement("div", _extends({
          className: "table-responsive"
        }, otherProps), !disabled && rows.map(function (row, rowIndex) {
          var inputValue = value[row.value] ? "".concat(row.value, ";").concat(value[row.value]) : '';
          return (/*#__PURE__*/_react.default.createElement(_form.ClayInput, {
              "aria-hidden": "true",
              key: "row-".concat(row.value, "-").concat(rowIndex),
              name: name,
              type: "hidden",
              value: inputValue
            })
          );
        }), /*#__PURE__*/_react.default.createElement(_table.default, {
          striped: true
        }, /*#__PURE__*/_react.default.createElement(TableHead, {
          columns: columns
        }), /*#__PURE__*/_react.default.createElement(_table.default.Body, null, rows.map(function (row, rowIndex) {
          return (/*#__PURE__*/_react.default.createElement(_table.default.Row, {
              key: "row-".concat(row.value, "-").concat(rowIndex),
              name: row.value
            }, /*#__PURE__*/_react.default.createElement(_table.default.Cell, null, row.label), /*#__PURE__*/_react.default.createElement(TableBodyColumns, {
              columns: columns,
              disabled: disabled,
              name: "".concat(name, "_").concat(row.value),
              onBlur: onBlur,
              onChange: onChange,
              onFocus: onFocus,
              row: row,
              value: value
            }))
          );
        }))))
      );
    };

    var Main = function Main(_ref4) {
      var columns = _ref4.columns,
          name = _ref4.name,
          readOnly = _ref4.readOnly,
          rows = _ref4.rows,
          _onChange = _ref4.onChange,
          onFocus = _ref4.onFocus,
          onBlur = _ref4.onBlur,
          _ref4$value = _ref4.value,
          value = _ref4$value === void 0 ? {} : _ref4$value,
          otherProps = _objectWithoutProperties(_ref4, ["columns", "name", "readOnly", "rows", "onChange", "onFocus", "onBlur", "value"]);

      var _useState = (0, _react.useState)(value),
          _useState2 = _slicedToArray(_useState, 2),
          state = _useState2[0],
          setState = _useState2[1];

      return (/*#__PURE__*/_react.default.createElement(_ReactFieldBase.FieldBase, _extends({}, otherProps, {
          name: name,
          readOnly: readOnly,
          style: null
        }), /*#__PURE__*/_react.default.createElement(Grid, {
          columns: columns,
          disabled: readOnly,
          name: name,
          onBlur: onBlur,
          onChange: function onChange(event) {
            var target = event.target;

            var value = _defineProperty({}, target.dataset.name, target.value);

            var newState = _objectSpread(_objectSpread({}, state), value);

            setState(newState);

            _onChange(event, newState);
          },
          onFocus: onFocus,
          rows: rows,
          value: state
        }))
      );
    };

    Main.displayName = 'Grid';
    var _default = Main;
    exports.default = _default;
    //# sourceMappingURL=Grid.es.js.map
  }
});
//# sourceMappingURL=Grid.es.js.map