"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = require("react");
var _reactNative = require("react-native");
var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
var _vectorIcons = require("@expo/vector-icons");
var _useI18n = require("../../hooks/useI18n");
var _HighFive = _interopRequireDefault(require("../../../assets/illustrations/HighFive"));
var _GroupedPillButtons = _interopRequireDefault(require("../../components/internal/GroupedPillButtons"));
var _TextField = _interopRequireDefault(require("../../components/internal/TextField"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
const SignInUsernameStep = ({
  styles,
  fadeAnim,
  slideAnim,
  scaleAnim,
  colors,
  isAddAccountMode,
  user,
  errorMessage,
  isInputFocused,
  username,
  validationStatus,
  userProfile,
  isValidating,
  handleInputFocus,
  handleInputBlur,
  handleUsernameChange,
  handleUsernameContinue: parentHandleUsernameContinue,
  navigate
}) => {
  const inputRef = (0, _react.useRef)(null);
  const {
    t
  } = (0, _useI18n.useI18n)();

  // Animated styles - properly memoized to prevent re-renders
  const animatedStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => {
    return {
      opacity: fadeAnim.value,
      transform: [{
        translateX: slideAnim.value
      }, {
        scale: scaleAnim.value
      }]
    };
  });
  const handleUsernameContinue = () => {
    if (!username || validationStatus === 'invalid') {
      setTimeout(() => {
        inputRef.current?.focus();
      }, 0);
    }
    parentHandleUsernameContinue();
  };
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNativeReanimated.default.View, {
    style: [styles.stepContainer, animatedStyle],
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_HighFive.default, {
      width: 100,
      height: 100
    }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
      style: styles.modernHeader,
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
        style: [styles.modernTitle, {
          color: colors.text
        }],
        children: isAddAccountMode ? t('signin.addAccountTitle') || 'Add Another Account' : t('signin.title') || 'Sign In'
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
        style: [styles.modernSubtitle, {
          color: colors.secondaryText
        }],
        children: isAddAccountMode ? t('signin.addAccountSubtitle') || 'Sign in with another account' : t('signin.subtitle') || 'Sign in to continue your journey'
      })]
    }), isAddAccountMode && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
      style: [styles.modernInfoCard, {
        backgroundColor: colors.inputBackground
      }],
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_vectorIcons.Ionicons, {
        name: "information-circle",
        size: 20,
        color: colors.primary
      }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.Text, {
        style: [styles.modernInfoText, {
          color: colors.text
        }],
        children: [t('signin.currentlySignedInAs', {
          username: user?.username
        }) || 'Currently signed in as ', /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
          style: {
            fontWeight: 'bold'
          },
          children: user?.username
        })]
      })]
    }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
      style: styles.modernInputContainer,
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_TextField.default, {
        ref: inputRef,
        label: t('common.labels.username'),
        leading: /*#__PURE__*/(0, _jsxRuntime.jsx)(_vectorIcons.Ionicons, {
          name: "person-outline",
          size: 24,
          color: colors.secondaryText
        }),
        value: username,
        onChangeText: handleUsernameChange,
        onFocus: handleInputFocus,
        onBlur: handleInputBlur,
        autoCapitalize: "none",
        autoCorrect: false,
        testID: "username-input",
        variant: "filled",
        error: validationStatus === 'invalid' ? errorMessage : undefined,
        loading: validationStatus === 'validating',
        success: validationStatus === 'valid',
        onSubmitEditing: handleUsernameContinue,
        autoFocus: true
      })
    }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_GroupedPillButtons.default, {
      buttons: [{
        text: t('common.links.signUp') || 'Sign Up',
        onPress: () => navigate('SignUp'),
        icon: 'person-add',
        variant: 'transparent'
      }, {
        text: t('common.actions.continue'),
        onPress: handleUsernameContinue,
        icon: 'arrow-forward',
        variant: 'primary',
        loading: isValidating,
        testID: 'username-next-button'
      }],
      colors: colors
    })]
  });
};
var _default = exports.default = SignInUsernameStep;
//# sourceMappingURL=SignInUsernameStep.js.map