"use strict";

import { useRef, useCallback, useEffect } from 'react';
import { View, Text, TouchableOpacity, StatusBar } from 'react-native';
import Animated, { useAnimatedStyle } from 'react-native-reanimated';
import { Ionicons } from '@expo/vector-icons';
import Avatar from '../../components/Avatar';
import { useI18n } from '../../hooks/useI18n';
import GroupedPillButtons from '../../components/internal/GroupedPillButtons';
import TextField from '../../components/internal/TextField';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
const SignInPasswordStep = ({
  styles,
  fadeAnim,
  slideAnim,
  scaleAnim,
  colors,
  userProfile,
  username,
  theme,
  logoAnim,
  errorMessage,
  isInputFocused,
  password,
  showPassword,
  handleInputFocus,
  handleInputBlur,
  handlePasswordChange,
  handleSignIn: parentHandleSignIn,
  isLoading,
  prevStep,
  navigate
}) => {
  const inputRef = useRef(null);
  const {
    t
  } = useI18n();

  // Animated styles - properly memoized to prevent re-renders
  const containerAnimatedStyle = useAnimatedStyle(() => {
    return {
      opacity: fadeAnim.value,
      transform: [{
        translateX: slideAnim.value
      }, {
        scale: scaleAnim.value
      }]
    };
  });
  const logoAnimatedStyle = useAnimatedStyle(() => {
    return {
      transform: [{
        scale: logoAnim.value
      }]
    };
  });

  // Focus password input on error or when step becomes active
  useEffect(() => {
    if (errorMessage) {
      setTimeout(() => {
        inputRef.current?.focus();
      }, 0);
    }
  }, [errorMessage]);
  const handleSignIn = useCallback(() => {
    if (!password || errorMessage) {
      setTimeout(() => {
        inputRef.current?.focus();
      }, 0);
    }
    parentHandleSignIn();
  }, [password, errorMessage, parentHandleSignIn]);
  return /*#__PURE__*/_jsxs(Animated.View, {
    style: [styles.stepContainer, containerAnimatedStyle],
    children: [/*#__PURE__*/_jsxs(View, {
      style: styles.modernUserProfileContainer,
      children: [/*#__PURE__*/_jsxs(Animated.View, {
        style: [styles.avatarContainer, logoAnimatedStyle],
        children: [/*#__PURE__*/_jsx(Avatar, {
          name: userProfile?.displayName || userProfile?.name || username,
          size: 100,
          theme: theme,
          style: styles.modernUserAvatar,
          backgroundColor: colors.primary + '20'
        }), /*#__PURE__*/_jsx(View, {
          style: [styles.statusIndicator, {
            backgroundColor: colors.primary
          }]
        })]
      }), /*#__PURE__*/_jsx(Text, {
        style: [styles.modernUserDisplayName, {
          color: colors.text
        }],
        children: userProfile?.displayName || userProfile?.name || username
      }), /*#__PURE__*/_jsxs(Text, {
        style: [styles.modernUsernameSubtext, {
          color: colors.secondaryText
        }],
        children: ["@", username]
      })]
    }), /*#__PURE__*/_jsxs(View, {
      style: styles.modernInputContainer,
      children: [/*#__PURE__*/_jsx(TextField, {
        ref: inputRef,
        label: t('common.labels.password'),
        leading: /*#__PURE__*/_jsx(Ionicons, {
          name: "lock-closed-outline",
          size: 24,
          color: colors.secondaryText
        }),
        value: password,
        onChangeText: handlePasswordChange,
        onFocus: handleInputFocus,
        onBlur: handleInputBlur,
        secureTextEntry: !showPassword,
        autoCapitalize: "none",
        autoCorrect: false,
        testID: "password-input",
        variant: "filled",
        error: errorMessage || undefined,
        onSubmitEditing: handleSignIn,
        autoFocus: true
      }), /*#__PURE__*/_jsxs(View, {
        style: {
          flexDirection: 'row',
          alignItems: 'center',
          marginBottom: 16
        },
        children: [/*#__PURE__*/_jsxs(Text, {
          style: [styles.footerText, {
            color: colors.text
          }],
          children: [t('signin.forgotPrompt') || 'Forgot your password?', " "]
        }), /*#__PURE__*/_jsx(TouchableOpacity, {
          onPress: () => navigate('RecoverAccount', {
            returnTo: 'SignIn',
            returnStep: 1,
            returnData: {
              username,
              userProfile
            }
          }),
          children: /*#__PURE__*/_jsx(Text, {
            style: [styles.modernLinkText, {
              color: colors.primary
            }],
            children: t('common.links.recoverAccount')
          })
        })]
      })]
    }), /*#__PURE__*/_jsx(GroupedPillButtons, {
      buttons: [{
        text: t('common.actions.back'),
        onPress: prevStep,
        icon: 'arrow-back',
        variant: 'transparent'
      }, {
        text: t('common.actions.signIn'),
        onPress: handleSignIn,
        icon: 'log-in',
        variant: 'primary',
        loading: isLoading,
        testID: 'login-button'
      }],
      colors: colors
    }), /*#__PURE__*/_jsxs(View, {
      style: styles.securityNotice,
      children: [/*#__PURE__*/_jsx(Ionicons, {
        name: "shield-checkmark",
        size: 14,
        color: colors.secondaryText
      }), /*#__PURE__*/_jsx(Text, {
        style: [styles.securityText, {
          color: colors.secondaryText
        }],
        children: t('signin.security.dataSecure') || 'Your data is encrypted and secure'
      })]
    }), /*#__PURE__*/_jsx(StatusBar, {
      barStyle: theme === 'dark' ? 'light-content' : 'dark-content',
      backgroundColor: colors.background
    })]
  });
};
export default SignInPasswordStep;
//# sourceMappingURL=SignInPasswordStep.js.map