"use strict";

import React, { useState, useEffect } from 'react';
import { View, Text, TextInput, TouchableOpacity, StyleSheet, Modal, Platform } from 'react-native';
import { Ionicons } from '@expo/vector-icons';
import { useThemeStyles } from '../../hooks/useThemeStyles';
import { useColorScheme } from '../../hooks/use-color-scheme';
import { useI18n } from '../../hooks/useI18n';
import { fontFamilies } from '../../styles/fonts';
import { useProfileEditing } from '../../hooks/useProfileEditing';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
export const EditUsernameModal = ({
  visible,
  onClose,
  initialValue = '',
  theme = 'light',
  onSave
}) => {
  const {
    t
  } = useI18n();
  const colorScheme = useColorScheme();
  const themeStyles = useThemeStyles(theme || 'light', colorScheme);
  const colors = themeStyles.colors;
  const {
    updateField,
    isSaving
  } = useProfileEditing();
  const [username, setUsername] = useState(initialValue);
  useEffect(() => {
    if (visible) {
      setUsername(initialValue);
    }
  }, [visible, initialValue]);
  const handleSave = async () => {
    const success = await updateField('username', username);
    if (success) {
      onSave?.();
      onClose();
    }
  };
  return /*#__PURE__*/_jsx(Modal, {
    visible: visible,
    animationType: "slide",
    transparent: true,
    onRequestClose: onClose,
    children: /*#__PURE__*/_jsx(View, {
      style: styles.modalOverlay,
      children: /*#__PURE__*/_jsxs(View, {
        style: [styles.modalContent, {
          backgroundColor: colors.background
        }],
        children: [/*#__PURE__*/_jsxs(View, {
          style: styles.modalHeader,
          children: [/*#__PURE__*/_jsx(TouchableOpacity, {
            onPress: onClose,
            style: styles.closeButton,
            children: /*#__PURE__*/_jsx(Ionicons, {
              name: "close",
              size: 24,
              color: colors.text
            })
          }), /*#__PURE__*/_jsx(Text, {
            style: [styles.modalTitle, {
              color: colors.text
            }],
            children: t('editProfile.items.username.title') || 'Username'
          }), /*#__PURE__*/_jsx(TouchableOpacity, {
            onPress: handleSave,
            disabled: isSaving || !username.trim(),
            style: [styles.saveButton, {
              opacity: isSaving || !username.trim() ? 0.5 : 1
            }],
            children: /*#__PURE__*/_jsx(Text, {
              style: [styles.saveButtonText, {
                color: colors.tint
              }],
              children: isSaving ? 'Saving...' : 'Save'
            })
          })]
        }), /*#__PURE__*/_jsx(View, {
          style: styles.modalBody,
          children: /*#__PURE__*/_jsxs(View, {
            style: styles.inputGroup,
            children: [/*#__PURE__*/_jsx(Text, {
              style: [styles.label, {
                color: colors.text
              }],
              children: t('editProfile.items.username.label') || 'Username'
            }), /*#__PURE__*/_jsx(TextInput, {
              style: [styles.input, {
                backgroundColor: colors.card,
                color: colors.text,
                borderColor: colors.border
              }],
              value: username,
              onChangeText: setUsername,
              placeholder: t('editProfile.items.username.placeholder') || 'Choose a username',
              placeholderTextColor: colors.secondaryText,
              autoFocus: true,
              autoCapitalize: "none",
              autoCorrect: false,
              selectionColor: colors.tint
            })]
          })
        })]
      })
    })
  });
};
const styles = StyleSheet.create({
  modalOverlay: {
    flex: 1,
    backgroundColor: 'rgba(0, 0, 0, 0.5)',
    justifyContent: 'flex-end'
  },
  modalContent: {
    borderTopLeftRadius: 20,
    borderTopRightRadius: 20,
    paddingTop: Platform.OS === 'ios' ? 20 : 16,
    maxHeight: '80%'
  },
  modalHeader: {
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'space-between',
    paddingHorizontal: 16,
    paddingBottom: 16,
    borderBottomWidth: StyleSheet.hairlineWidth,
    borderBottomColor: '#E5E5EA'
  },
  closeButton: {
    width: 40,
    height: 40,
    alignItems: 'center',
    justifyContent: 'center'
  },
  modalTitle: {
    fontSize: 18,
    fontWeight: '600',
    fontFamily: fontFamilies.phuduSemiBold,
    flex: 1,
    textAlign: 'center'
  },
  saveButton: {
    paddingHorizontal: 16,
    paddingVertical: 8
  },
  saveButtonText: {
    fontSize: 16,
    fontWeight: '600',
    fontFamily: fontFamilies.phuduSemiBold
  },
  modalBody: {
    padding: 16,
    gap: 16
  },
  inputGroup: {
    gap: 8
  },
  label: {
    fontSize: 14,
    fontWeight: '600',
    fontFamily: fontFamilies.phuduSemiBold
  },
  input: {
    borderWidth: StyleSheet.hairlineWidth,
    borderRadius: 12,
    padding: 16,
    fontSize: 16,
    minHeight: 52
  }
});
//# sourceMappingURL=EditUsernameModal.js.map