"use strict";

import { useRef } from 'react';
import { View, Text } from 'react-native';
import { Ionicons } from '@expo/vector-icons';
import HighFive from '../../../assets/illustrations/HighFive';
import TextField from '../../components/internal/TextField';
import GroupedPillButtons from '../../components/internal/GroupedPillButtons';
import { toast } from '../../../lib/sonner';
import { useI18n } from '../../hooks/useI18n';
import { stepStyles } from '../../styles/spacing';
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
const RecoverRequestStep = ({
  colors,
  styles,
  navigate,
  nextStep,
  identifier,
  setIdentifier,
  errorMessage,
  setErrorMessage,
  isLoading,
  setIsLoading,
  oxyServices
}) => {
  const inputRef = useRef(null);
  const {
    t
  } = useI18n();
  const baseStyles = stepStyles;
  const handleIdentifierChange = text => {
    setIdentifier(text);
    if (errorMessage) setErrorMessage('');
  };
  const handleRequest = async () => {
    if (!identifier || identifier.length < 3) {
      setErrorMessage(t('recover.username.errorRequired') || 'Please enter your username.');
      setTimeout(() => inputRef.current?.focus(), 0);
      return;
    }
    setErrorMessage('');
    setIsLoading(true);
    try {
      toast.info(t('recover.noEmail'));
    } finally {
      setIsLoading(false);
    }
  };
  const handleRequestWithFocus = () => {
    if (!identifier) {
      setTimeout(() => inputRef.current?.focus(), 0);
    }
    handleRequest();
  };
  return /*#__PURE__*/_jsxs(_Fragment, {
    children: [/*#__PURE__*/_jsx(View, {
      style: [baseStyles.container, baseStyles.sectionSpacing, {
        alignItems: 'flex-start'
      }],
      children: /*#__PURE__*/_jsx(HighFive, {
        width: 100,
        height: 100
      })
    }), /*#__PURE__*/_jsxs(View, {
      style: [baseStyles.container, baseStyles.sectionSpacing, baseStyles.header],
      children: [/*#__PURE__*/_jsx(Text, {
        style: [styles.modernTitle, baseStyles.title, {
          color: colors.text,
          marginBottom: 0,
          marginTop: 0
        }],
        children: t('recover.title')
      }), /*#__PURE__*/_jsx(Text, {
        style: [styles.modernSubtitle, baseStyles.subtitle, {
          color: colors.secondaryText,
          marginBottom: 0,
          marginTop: 0
        }],
        children: t('recover.noEmail')
      })]
    }), /*#__PURE__*/_jsx(View, {
      style: [baseStyles.container, baseStyles.sectionSpacing],
      children: /*#__PURE__*/_jsx(TextField, {
        ref: inputRef,
        label: t('recover.username.label'),
        leading: /*#__PURE__*/_jsx(Ionicons, {
          name: "mail-outline",
          size: 24,
          color: colors.secondaryText
        }),
        value: identifier,
        onChangeText: handleIdentifierChange,
        autoCapitalize: "none",
        autoCorrect: false,
        testID: "recover-identifier-input",
        variant: "filled",
        error: errorMessage || undefined,
        helperText: t('recover.username.helper') || 'Enter your username or email',
        editable: !isLoading,
        onSubmitEditing: handleRequestWithFocus,
        autoFocus: true,
        accessibilityLabel: t('recover.username.label'),
        accessibilityHint: t('recover.username.helper') || 'Enter your username or email to recover your account',
        style: {
          marginBottom: 0
        }
      })
    }), /*#__PURE__*/_jsx(View, {
      style: [baseStyles.container, baseStyles.sectionSpacing, baseStyles.buttonContainer],
      children: /*#__PURE__*/_jsx(GroupedPillButtons, {
        buttons: [{
          text: t('common.actions.back'),
          onPress: () => navigate('SignIn'),
          icon: 'arrow-back',
          variant: 'transparent'
        }, {
          text: t('common.actions.continue'),
          onPress: handleRequest,
          icon: 'information-circle-outline',
          variant: 'primary',
          loading: isLoading,
          disabled: isLoading || !identifier || identifier.length < 3
        }],
        colors: colors
      })
    })]
  });
};
export default RecoverRequestStep;
//# sourceMappingURL=RecoverRequestStep.js.map