"use strict";

exports.__esModule = true;
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _buttonLink = _interopRequireDefault(require("../../atom/button-link"));
var _loader = _interopRequireDefault(require("../../atom/loader"));
var _provider = _interopRequireDefault(require("../../atom/provider"));
var _style = _interopRequireDefault(require("./style.css"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
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; }
const BrandCreateForm = (props, context) => {
  const {
    title,
    subtitle,
    description,
    field,
    onSubmit,
    submitValue,
    isPending,
    isModified
  } = props;
  const {
    translate
  } = context;
  const waitMessage = translate('Wait_creation');
  const wrapperClass = isModified || isPending || field.error ? _style.default.modifiedWrapper : _style.default.wrapper;
  const fieldClass = field.error ? _style.default.error : _style.default.defaultStyle;
  const disabled = isPending || !isModified;
  const {
    onChange
  } = field;
  const handleChange = (0, _react.useMemo)(() => e => onChange(e.target.value), [onChange]);
  const actionView = isPending ? /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.wait
  }, waitMessage), /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.loading
  }, /*#__PURE__*/_react.default.createElement(_loader.default, null))) : /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_buttonLink.default, {
    type: "primary",
    "data-name": "brand_create_submit_button",
    usage: "submit",
    customStyle: {
      display: 'inline-block',
      width: 'fit-content'
    },
    disabled: disabled,
    label: submitValue
  }));
  return /*#__PURE__*/_react.default.createElement("div", {
    className: wrapperClass
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.header
  }, /*#__PURE__*/_react.default.createElement("h1", null, title)), /*#__PURE__*/_react.default.createElement("form", {
    className: _style.default.content,
    onSubmit: onSubmit
  }, /*#__PURE__*/_react.default.createElement("h2", null, subtitle), /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.description
  }, description), /*#__PURE__*/_react.default.createElement("div", {
    className: fieldClass
  }, /*#__PURE__*/_react.default.createElement("label", null, /*#__PURE__*/_react.default.createElement("input", {
    type: "text",
    maxLength: "40",
    "data-name": "brand_create_text_input",
    placeholder: field.placeholder,
    defaultValue: field.value,
    onInput: handleChange
  }), field.label)), actionView));
};
BrandCreateForm.contextTypes = {
  translate: _provider.default.childContextTypes.translate
};
BrandCreateForm.propTypes = process.env.NODE_ENV !== "production" ? {
  title: _propTypes.default.string.isRequired,
  subtitle: _propTypes.default.string.isRequired,
  description: _propTypes.default.string.isRequired,
  field: _propTypes.default.shape({
    placeholder: _propTypes.default.string.isRequired,
    label: _propTypes.default.string.isRequired,
    onChange: _propTypes.default.func.isRequired,
    error: _propTypes.default.string,
    value: _propTypes.default.string
  }).isRequired,
  onSubmit: _propTypes.default.func.isRequired,
  submitValue: _propTypes.default.string.isRequired,
  isPending: _propTypes.default.bool,
  isModified: _propTypes.default.bool
} : {};
var _default = exports.default = BrandCreateForm;
//# sourceMappingURL=index.js.map