"use strict";

exports.__esModule = true;
exports.default = void 0;
var _snakeCase2 = _interopRequireDefault(require("lodash/fp/snakeCase"));
var _map2 = _interopRequireDefault(require("lodash/fp/map"));
var _keys2 = _interopRequireDefault(require("lodash/fp/keys"));
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _classnames = _interopRequireDefault(require("classnames"));
var _autocomplete = _interopRequireDefault(require("../../atom/autocomplete"));
var _select = _interopRequireDefault(require("../../atom/select"));
var _selectMultiple = _interopRequireDefault(require("../select-multiple"));
var _inputText = _interopRequireDefault(require("../../atom/input-text"));
var _inputColor = _interopRequireDefault(require("../../atom/input-color"));
var _inputCheckbox = _interopRequireDefault(require("../../atom/input-checkbox"));
var _inputReadonly = _interopRequireDefault(require("../../atom/input-readonly"));
var _inputSwitch = _interopRequireDefault(require("../../atom/input-switch"));
var _brandUploadBox = _interopRequireDefault(require("../brand-upload-box"));
var _brandDownloadBox = _interopRequireDefault(require("../brand-download-box"));
var _button = _interopRequireDefault(require("../../atom/button"));
var _inputTextarea = _interopRequireDefault(require("../../atom/input-textarea"));
var _inputHtml = _interopRequireDefault(require("../../atom/input-html"));
var _inputDoublestep = _interopRequireDefault(require("../../atom/input-doublestep"));
var _inputFileDraggable = _interopRequireDefault(require("../../atom/input-file-draggable"));
var _setupSlider = _interopRequireDefault(require("../setup-slider"));
var _setupSections = _interopRequireDefault(require("../setup-sections"));
var _title = _interopRequireDefault(require("../../atom/title"));
var _coorpManagerRoles = _interopRequireDefault(require("../coorp-manager-roles"));
var _titleAndCheckboxWrapper = _interopRequireDefault(require("../title-and-checkbox-wrapper"));
var _buttonLink = _interopRequireDefault(require("../../atom/button-link"));
var _titleAndInput = _interopRequireDefault(require("../../organism/title-and-input"));
var _style = _interopRequireDefault(require("./style.css"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
const inputContainerStyle = {
  default: _style.default.defaultWidth,
  medium: _style.default.mediumWidth,
  large: _style.default.largeWidth
};
const buildInput = field => {
  const {
    type,
    ...rest
  } = field;
  switch (type) {
    case 'autoComplete':
      return /*#__PURE__*/_react.default.createElement(_autocomplete.default, field);
    case 'color':
      return /*#__PURE__*/_react.default.createElement(_inputColor.default, field);
    case 'readonly':
      return /*#__PURE__*/_react.default.createElement(_inputReadonly.default, field);
    case 'switch':
      return /*#__PURE__*/_react.default.createElement(_inputSwitch.default, field);
    case 'textarea':
      return /*#__PURE__*/_react.default.createElement(_inputTextarea.default, field);
    case 'html':
      return /*#__PURE__*/_react.default.createElement(_inputHtml.default, field);
    case 'doublestep':
      return /*#__PURE__*/_react.default.createElement(_inputDoublestep.default, field);
    case 'select':
      return /*#__PURE__*/_react.default.createElement(_select.default, _extends({}, field, {
        theme: 'coorpmanager'
      }));
    case 'selectMultiple':
      return /*#__PURE__*/_react.default.createElement(_selectMultiple.default, field);
    case 'checkbox':
      return /*#__PURE__*/_react.default.createElement(_inputCheckbox.default, field);
    case 'image':
      return /*#__PURE__*/_react.default.createElement("div", {
        className: _style.default.imageUploadContainer
      }, /*#__PURE__*/_react.default.createElement(_inputFileDraggable.default, field));
    case 'bulkUpload':
      return /*#__PURE__*/_react.default.createElement("div", {
        className: _style.default.bulkUploadContainer
      }, /*#__PURE__*/_react.default.createElement(_inputFileDraggable.default, field));
    case 'slider':
      return /*#__PURE__*/_react.default.createElement(_setupSlider.default, field);
    case 'sections':
      return /*#__PURE__*/_react.default.createElement(_setupSections.default, field);
    case 'text':
    case 'password':
      return /*#__PURE__*/_react.default.createElement(_inputText.default, field);
    case 'downloadbox':
      return /*#__PURE__*/_react.default.createElement(_brandDownloadBox.default, field);
    case 'uploadbox':
      return /*#__PURE__*/_react.default.createElement(_brandUploadBox.default, field);
    case 'button':
    case 'link':
      return /*#__PURE__*/_react.default.createElement(_buttonLink.default, _extends({}, field, {
        type: "primary",
        label: field.submitValue,
        link: field.href ? {
          href: field.href,
          target: field.target,
          download: field.download
        } : null,
        customStyle: {
          width: 'fit-content'
        }
      }));
    case 'buttonLink':
      return /*#__PURE__*/_react.default.createElement(_buttonLink.default, _extends({}, field, {
        type: field.buttonType
      }));
    case 'roles':
      return /*#__PURE__*/_react.default.createElement(_coorpManagerRoles.default, field);
    case 'titleAndCheckBoxWrapper':
      return /*#__PURE__*/_react.default.createElement(_titleAndCheckboxWrapper.default, field);
    case 'titleAndInput':
      return /*#__PURE__*/_react.default.createElement(_titleAndInput.default, field);
    default:
      return /*#__PURE__*/_react.default.createElement(_inputText.default, _extends({}, rest, {
        type: 'text'
      }));
  }
};
const buildField = (field, title, index) => {
  const input = buildInput(field);
  const {
    theme,
    size = 'default'
  } = field.type === 'titleAndInput' ? field.field : field;
  const styleInput = theme === 'coorpmanager' || theme === 'skillDetail' ? inputContainerStyle[size] : _style.default.field;
  const isMassiveBattle = field.type === 'titleAndInput' && title === 'Massive Battle';
  const styleField = isMassiveBattle ? _style.default.fieldMassiveBattle : styleInput;
  return /*#__PURE__*/_react.default.createElement("div", {
    className: styleField,
    key: index
  }, input);
};
const defineLayoutClass = layout => {
  if (layout === 'grid') return (0, _classnames.default)(_style.default.grid);else if (layout === 'bulkLayout') return (0, _classnames.default)(_style.default.layoutBulk);else return (0, _classnames.default)(null);
};
const BrandFormGroup = props => {
  const {
    title,
    subtitle = '',
    fieldsLayout = '',
    groupLayout = '',
    fields = [],
    titleSize,
    subtitleSize = 'standard'
  } = props;
  const fieldsList = _map2.default.convert({
    cap: false
  })((field, index) => buildField(field, title, index), fields);
  const layout = (0, _react.useMemo)(() => defineLayoutClass(fieldsLayout), [fieldsLayout]);
  return /*#__PURE__*/_react.default.createElement("div", {
    "data-name": `brand_form_group_${(0, _snakeCase2.default)(title)}`,
    className: (0, _classnames.default)(_style.default.wrapper, groupLayout === 'grid' && _style.default.groupGrid)
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.titleWrapper
  }, /*#__PURE__*/_react.default.createElement(_title.default, {
    title: title,
    subtitle: subtitle,
    titleSize: titleSize,
    subtitleSize: subtitleSize,
    type: 'form-group'
  })), /*#__PURE__*/_react.default.createElement("div", {
    className: layout
  }, fieldsList));
};
BrandFormGroup.propTypes = process.env.NODE_ENV !== "production" ? {
  title: _propTypes.default.string,
  subtitle: _propTypes.default.string,
  titleSize: _propTypes.default.string,
  subtitleSize: _propTypes.default.string,
  fieldsLayout: _propTypes.default.string,
  groupLayout: _propTypes.default.string,
  fields: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.shape({
    ..._autocomplete.default.propTypes,
    type: _propTypes.default.oneOf(['autoComplete']),
    size: _propTypes.default.oneOf((0, _keys2.default)(inputContainerStyle))
  }), _propTypes.default.shape({
    ..._inputColor.default.propTypes,
    type: _propTypes.default.oneOf(['color'])
  }), _propTypes.default.shape({
    ..._inputReadonly.default.propTypes,
    type: _propTypes.default.oneOf(['readonly'])
  }), _propTypes.default.shape({
    ..._inputText.default.propTypes,
    type: _propTypes.default.oneOf(['password']),
    size: _propTypes.default.oneOf((0, _keys2.default)(inputContainerStyle))
  }), _propTypes.default.shape({
    ..._inputSwitch.default.propTypes,
    type: _propTypes.default.oneOf(['switch'])
  }), _propTypes.default.shape({
    ..._inputTextarea.default.propTypes,
    type: _propTypes.default.oneOf(['textarea']),
    size: _propTypes.default.oneOf((0, _keys2.default)(inputContainerStyle))
  }), _propTypes.default.shape({
    ..._inputHtml.default.propTypes,
    type: _propTypes.default.oneOf(['html'])
  }), _propTypes.default.shape({
    ..._inputDoublestep.default.propTypes,
    type: _propTypes.default.oneOf(['doublestep'])
  }), _propTypes.default.shape({
    ..._select.default.propTypes,
    type: _propTypes.default.oneOf(['select']),
    size: _propTypes.default.oneOf((0, _keys2.default)(inputContainerStyle))
  }), _propTypes.default.shape({
    ..._inputCheckbox.default.propTypes,
    type: _propTypes.default.oneOf(['checkbox'])
  }), _propTypes.default.shape({
    ..._inputFileDraggable.default.propTypes,
    type: _propTypes.default.oneOf(['image'])
  }), _propTypes.default.shape({
    ..._inputFileDraggable.default.propTypes,
    type: _propTypes.default.oneOf(['bulkImage'])
  }), _propTypes.default.shape({
    ..._setupSlider.default.propTypes,
    type: _propTypes.default.oneOf(['slider'])
  }), _propTypes.default.shape({
    ..._setupSections.default.propTypes,
    type: _propTypes.default.oneOf(['sections'])
  }), _propTypes.default.shape({
    ..._inputText.default.propTypes,
    type: _propTypes.default.oneOf(['text', 'password']),
    size: _propTypes.default.oneOf((0, _keys2.default)(inputContainerStyle))
  }), _propTypes.default.shape({
    ..._brandDownloadBox.default.propTypes,
    type: _propTypes.default.oneOf(['downloadbox'])
  }), _propTypes.default.shape({
    ..._brandUploadBox.default.propTypes,
    type: _propTypes.default.oneOf(['uploadbox'])
  }), _propTypes.default.shape({
    ..._button.default.propTypes,
    type: _propTypes.default.oneOf(['button'])
  }), _propTypes.default.shape({
    ..._buttonLink.default.propTypes,
    buttonType: _buttonLink.default.propTypes.type,
    type: _propTypes.default.oneOf(['buttonLink'])
  }), _propTypes.default.shape({
    ..._selectMultiple.default.propTypes,
    type: _propTypes.default.oneOf(['selectMultiple'])
  }), _propTypes.default.shape({
    ..._coorpManagerRoles.default.propTypes,
    type: _propTypes.default.oneOf(['roles'])
  }), _propTypes.default.shape(_inputText.default.propTypes), _propTypes.default.shape({
    ..._titleAndInput.default.propTypes,
    type: _propTypes.default.oneOf(['titleAndInput'])
  })]))
} : {};
var _default = exports.default = BrandFormGroup;
//# sourceMappingURL=index.js.map