"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.EditUser = EditUser;
var _reactNativeSafeAreaContext = require("react-native-safe-area-context");
var _components = require("./components");
var _reactNative = require("react-native");
var _reactHookForm = require("react-hook-form");
var _hooks = require("./hooks");
var _FormInput = _interopRequireDefault(require("../../../components/FormInput"));
var _constants = require("../../../../core/constants");
var _enums = require("../../../enums");
var _ActionButton = _interopRequireDefault(require("../../../elements/ActionButton"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function EditUser({
  userId
}) {
  const {
    user,
    styles,
    isDirty,
    isValid,
    control,
    onSubmit,
    isSubmitting,
    handleSubmit,
    accessibilityId,
    isDisplayNameDisabled
  } = (0, _hooks.useEditUser)(userId);
  return /*#__PURE__*/React.createElement(_reactNativeSafeAreaContext.SafeAreaView, {
    testID: accessibilityId,
    style: styles.container
  }, /*#__PURE__*/React.createElement(_components.TopBar, {
    isFormDirty: isDirty
  }), /*#__PURE__*/React.createElement(_reactNative.KeyboardAvoidingView, {
    style: styles.keyboardAvoidingView,
    behavior: _reactNative.Platform.OS === 'ios' ? 'padding' : 'height'
  }, /*#__PURE__*/React.createElement(_reactNative.ScrollView, {
    contentContainerStyle: styles.contentContainer
  }, /*#__PURE__*/React.createElement(_reactHookForm.Controller, {
    name: "image",
    control: control,
    render: ({
      field: {
        onChange,
        value
      }
    }) => /*#__PURE__*/React.createElement(_components.ImageUpload, {
      user: user,
      value: value,
      onChange: onChange
    })
  }), /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.inputContainer
  }, /*#__PURE__*/React.createElement(_reactHookForm.Controller, {
    name: "displayName",
    control: control,
    render: ({
      field: {
        onChange,
        onBlur,
        value
      }
    }) => /*#__PURE__*/React.createElement(_FormInput.default, {
      value: value,
      onBlur: onBlur,
      multiline: false,
      onChangeText: onChange,
      placeholder: "Enter your display name",
      pageId: _enums.PageID.edit_user_profile_page,
      maxLength: _constants.CHARACTER_LIMIT.USER_DISPLAY_NAME,
      elementId: _enums.ElementID.user_display_name_title,
      editable: !isDisplayNameDisabled
    })
  })), /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.inputContainer
  }, /*#__PURE__*/React.createElement(_reactHookForm.Controller, {
    name: "description",
    control: control,
    render: ({
      field: {
        onChange,
        onBlur,
        value
      }
    }) => /*#__PURE__*/React.createElement(_FormInput.default, {
      optional: true,
      multiline: true,
      value: value,
      onBlur: onBlur,
      onChangeText: onChange,
      placeholder: "Enter your description",
      pageId: _enums.PageID.edit_user_profile_page,
      elementId: _enums.ElementID.user_about_title,
      maxLength: _constants.CHARACTER_LIMIT.USER_DESCRIPTION
    })
  }))), /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.submitButtonContainer
  }, /*#__PURE__*/React.createElement(_ActionButton.default, {
    onPress: handleSubmit(onSubmit),
    pageId: _enums.PageID.edit_user_profile_page,
    elementId: _enums.ElementID.update_user_profile_button,
    disabled: !isDirty || !isValid || isSubmitting
  }))));
}
//# sourceMappingURL=Edit.js.map