"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _OxyContext = require("../context/OxyContext");
var _Avatar = _interopRequireDefault(require("../components/Avatar"));
var _vectorIcons = require("@expo/vector-icons");
var _sonner = require("../../lib/sonner");
var _authStore = require("../stores/authStore");
var _styles = require("../styles");
var _GroupedPillButtons = _interopRequireDefault(require("../components/internal/GroupedPillButtons"));
var _useI18n = require("../hooks/useI18n");
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); }
/**
 * Post-signup welcome & onboarding screen.
 * - Greets the newly registered user
 * - Lets them immediately set / change their avatar using existing FileManagement picker
 * - Only when the user presses "Continue" do we invoke onAuthenticated to finish flow & close sheet
 */const WelcomeNewUserScreen = ({
  navigate,
  onAuthenticated,
  theme,
  newUser
}) => {
  const {
    user,
    oxyServices
  } = (0, _OxyContext.useOxy)();
  const {
    t
  } = (0, _useI18n.useI18n)();
  const updateUser = (0, _authStore.useAuthStore)(s => s.updateUser);
  const currentUser = user || newUser; // fallback
  const colors = (0, _styles.useThemeColors)(theme);
  const styles = (0, _react.useMemo)(() => createStyles(theme), [theme]);

  // Animation state
  const fadeAnim = (0, _react.useRef)(new _reactNative.Animated.Value(1)).current;
  const slideAnim = (0, _react.useRef)(new _reactNative.Animated.Value(0)).current;
  const [currentStep, setCurrentStep] = (0, _react.useState)(0);
  const avatarUri = currentUser?.avatar ? oxyServices.getFileDownloadUrl(currentUser.avatar, 'thumb') : undefined;

  // Steps content
  const welcomeTitle = currentUser?.username ? t('welcomeNew.welcome.titleWithName', {
    username: currentUser.username
  }) || `Welcome, ${currentUser.username} 👋` : t('welcomeNew.welcome.title') || 'Welcome 👋';
  const steps = [{
    key: 'welcome',
    title: welcomeTitle,
    body: t('welcomeNew.welcome.body') || "You just created an account in a calm, ethical space. A few quick things — then you're in."
  }, {
    key: 'account',
    title: t('welcomeNew.account.title') || 'One Account. Simple.',
    bullets: [t('welcomeNew.account.bullets.0') || 'One identity across everything', t('welcomeNew.account.bullets.1') || 'No re‑signing in all the time', t('welcomeNew.account.bullets.2') || 'Your preferences stay with you']
  }, {
    key: 'principles',
    title: t('welcomeNew.principles.title') || 'What We Stand For',
    bullets: [t('welcomeNew.principles.bullets.0') || 'Privacy by default', t('welcomeNew.principles.bullets.1') || 'No manipulative feeds', t('welcomeNew.principles.bullets.2') || 'You decide what to share', t('welcomeNew.principles.bullets.3') || 'No selling your data']
  }, {
    key: 'karma',
    title: t('welcomeNew.karma.title') || 'Karma = Trust & Growth',
    body: t('welcomeNew.karma.body') || 'Oxy Karma is a points system that reacts to what you do. Helpful, respectful, constructive actions earn it. Harmful or low‑effort stuff chips it away. More karma can unlock benefits; low karma can limit features. It keeps things fair and rewards real contribution.'
  }, {
    key: 'avatar',
    title: t('welcomeNew.avatar.title') || 'Make It Yours',
    body: t('welcomeNew.avatar.body') || 'Add an avatar so people recognize you. It will show anywhere you show up here. Skip if you want — you can add it later.',
    showAvatar: true
  }, {
    key: 'ready',
    title: t('welcomeNew.ready.title') || "You're Ready",
    body: t('welcomeNew.ready.body') || 'Explore. Contribute. Earn karma. Stay in control.'
  }];
  const totalSteps = steps.length;
  const avatarStepIndex = steps.findIndex(s => s.showAvatar);
  const animateToStep = next => {
    _reactNative.Animated.timing(fadeAnim, {
      toValue: 0,
      duration: 180,
      useNativeDriver: _reactNative.Platform.OS !== 'web'
    }).start(() => {
      setCurrentStep(next);
      slideAnim.setValue(-40);
      _reactNative.Animated.parallel([_reactNative.Animated.timing(fadeAnim, {
        toValue: 1,
        duration: 220,
        useNativeDriver: _reactNative.Platform.OS !== 'web'
      }), _reactNative.Animated.spring(slideAnim, {
        toValue: 0,
        useNativeDriver: _reactNative.Platform.OS !== 'web',
        friction: 9
      })]).start();
    });
  };
  const nextStep = (0, _react.useCallback)(() => {
    if (currentStep < totalSteps - 1) animateToStep(currentStep + 1);
  }, [currentStep, totalSteps]);
  const prevStep = (0, _react.useCallback)(() => {
    if (currentStep > 0) animateToStep(currentStep - 1);
  }, [currentStep]);
  const skipToAvatar = (0, _react.useCallback)(() => {
    if (avatarStepIndex >= 0) animateToStep(avatarStepIndex);
  }, [avatarStepIndex]);
  const finish = (0, _react.useCallback)(() => {
    if (onAuthenticated && currentUser) onAuthenticated(currentUser);
  }, [onAuthenticated, currentUser]);
  const openAvatarPicker = (0, _react.useCallback)(() => {
    navigate('FileManagement', {
      selectMode: true,
      multiSelect: false,
      disabledMimeTypes: ['video/', 'audio/', 'application/pdf'],
      afterSelect: 'back',
      onSelect: async file => {
        if (!file.contentType.startsWith('image/')) {
          _sonner.toast.error(t('editProfile.toasts.selectImage') || 'Please select an image file');
          return;
        }
        try {
          // Update file visibility to public for avatar
          try {
            await oxyServices.assetUpdateVisibility(file.id, 'public');
            console.log('[WelcomeNewUser] Avatar visibility updated to public');
          } catch (visError) {
            console.warn('[WelcomeNewUser] Failed to update avatar visibility, continuing anyway:', visError);
          }
          await updateUser({
            avatar: file.id
          }, oxyServices);
          _sonner.toast.success(t('editProfile.toasts.avatarUpdated') || 'Avatar updated');
        } catch (e) {
          _sonner.toast.error(e.message || t('editProfile.toasts.updateAvatarFailed') || 'Failed to update avatar');
        }
      }
    });
  }, [navigate, updateUser, oxyServices]);
  const step = steps[currentStep];
  const pillButtons = (0, _react.useMemo)(() => {
    if (currentStep === totalSteps - 1) {
      return [{
        text: t('welcomeNew.actions.back') || 'Back',
        onPress: prevStep,
        icon: 'arrow-back',
        variant: 'transparent'
      }, {
        text: t('welcomeNew.actions.enter') || 'Enter',
        onPress: finish,
        icon: 'log-in-outline',
        variant: 'primary'
      }];
    }
    if (currentStep === 0) {
      const arr = [];
      if (avatarStepIndex > 0) arr.push({
        text: t('welcomeNew.actions.skip') || 'Skip',
        onPress: skipToAvatar,
        icon: 'play-skip-forward',
        variant: 'transparent'
      });
      arr.push({
        text: t('welcomeNew.actions.next') || 'Next',
        onPress: nextStep,
        icon: 'arrow-forward',
        variant: 'primary'
      });
      return arr;
    }
    if (step.showAvatar) {
      return [{
        text: t('welcomeNew.actions.back') || 'Back',
        onPress: prevStep,
        icon: 'arrow-back',
        variant: 'transparent'
      }, {
        text: avatarUri ? t('welcomeNew.actions.continue') || 'Continue' : t('welcomeNew.actions.skip') || 'Skip',
        onPress: nextStep,
        icon: 'arrow-forward',
        variant: 'primary'
      }];
    }
    return [{
      text: t('welcomeNew.actions.back') || 'Back',
      onPress: prevStep,
      icon: 'arrow-back',
      variant: 'transparent'
    }, {
      text: t('welcomeNew.actions.next') || 'Next',
      onPress: nextStep,
      icon: 'arrow-forward',
      variant: 'primary'
    }];
  }, [currentStep, totalSteps, prevStep, nextStep, finish, skipToAvatar, avatarStepIndex, step.showAvatar, avatarUri]);
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
    style: styles.container,
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
      style: styles.progressContainer,
      children: steps.map((s, i) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
        style: [styles.progressDot, i === currentStep ? {
          backgroundColor: colors.primary,
          width: 22
        } : {
          backgroundColor: colors.border
        }]
      }, s.key))
    }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Animated.View, {
      style: {
        opacity: fadeAnim,
        transform: [{
          translateX: slideAnim
        }]
      },
      children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.ScrollView, {
        contentContainerStyle: styles.scrollInner,
        showsVerticalScrollIndicator: false,
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
          style: styles.title,
          children: step.title
        }), step.body && /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
          style: styles.body,
          children: step.body
        }), Array.isArray(step.bullets) && step.bullets.length > 0 && /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
          style: styles.bulletContainer,
          children: step.bullets.map(b => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
            style: styles.bulletRow,
            children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_vectorIcons.Ionicons, {
              name: "ellipse",
              size: 8,
              color: colors.primary,
              style: {
                marginTop: 6
              }
            }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
              style: styles.bulletText,
              children: b
            })]
          }, b))
        }), step.showAvatar && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
          style: styles.avatarSection,
          children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Avatar.default, {
            size: 120,
            name: currentUser?.username,
            uri: avatarUri,
            theme: theme,
            style: styles.avatar
          }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.TouchableOpacity, {
            style: styles.changeAvatarButton,
            onPress: openAvatarPicker,
            children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_vectorIcons.Ionicons, {
              name: "image-outline",
              size: 18,
              color: "#FFFFFF"
            }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
              style: styles.changeAvatarText,
              children: avatarUri ? t('welcomeNew.avatar.change') || 'Change Avatar' : t('welcomeNew.avatar.add') || 'Add Avatar'
            })]
          })]
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_GroupedPillButtons.default, {
          buttons: pillButtons,
          colors: colors
        })]
      })
    })]
  });
};
const createStyles = theme => {
  const isDark = theme === 'dark';
  const textColor = isDark ? '#FFFFFF' : '#000000';
  const secondary = isDark ? '#CCCCCC' : '#555555';
  const cardBg = isDark ? '#1E1E1E' : '#FFFFFF';
  const border = isDark ? '#333333' : '#E0E0E0';
  const primary = '#007AFF';
  return _reactNative.StyleSheet.create({
    container: {
      width: '100%',
      paddingHorizontal: 20
    },
    scrollInner: {
      paddingBottom: 12
    },
    title: {
      fontSize: 42,
      fontFamily: _reactNative.Platform.OS === 'web' ? 'Phudu' : 'Phudu-Bold',
      fontWeight: _reactNative.Platform.OS === 'web' ? 'bold' : undefined,
      letterSpacing: -1,
      color: textColor,
      marginBottom: 12
    },
    body: {
      fontSize: 16,
      lineHeight: 22,
      color: secondary,
      marginBottom: 28,
      maxWidth: 620
    },
    bulletContainer: {
      gap: 10,
      marginBottom: 32
    },
    bulletRow: {
      flexDirection: 'row',
      alignItems: 'flex-start',
      gap: 10
    },
    bulletText: {
      flex: 1,
      fontSize: 15,
      lineHeight: 20,
      color: secondary
    },
    avatarSection: {
      width: '100%',
      alignItems: 'center',
      marginBottom: 40
    },
    avatar: {
      marginBottom: 16,
      borderWidth: 4,
      borderColor: primary + '40'
    },
    changeAvatarButton: {
      flexDirection: 'row',
      alignItems: 'center',
      backgroundColor: primary,
      paddingHorizontal: 18,
      paddingVertical: 10,
      borderRadius: 35,
      gap: 8
    },
    changeAvatarText: {
      color: '#FFFFFF',
      fontSize: 15,
      fontWeight: '600'
    },
    progressContainer: {
      flexDirection: 'row',
      width: '100%',
      justifyContent: 'center',
      marginBottom: 24,
      marginTop: 4
    },
    progressDot: {
      height: 10,
      width: 10,
      borderRadius: 5,
      marginHorizontal: 6,
      backgroundColor: border
    },
    navBar: {
      flexDirection: 'row',
      alignItems: 'center',
      width: '100%',
      gap: 12,
      marginTop: 8
    },
    navButton: {
      flexDirection: 'row',
      alignItems: 'center',
      gap: 6,
      paddingHorizontal: 14,
      paddingVertical: 10,
      borderRadius: 12
    },
    backButton: {
      backgroundColor: cardBg,
      borderWidth: 1,
      borderColor: border
    },
    skipButton: {
      marginLeft: 'auto',
      backgroundColor: 'transparent',
      paddingHorizontal: 4
    },
    navText: {
      fontSize: 14,
      fontWeight: '500'
    },
    primaryButton: {
      flexDirection: 'row',
      alignItems: 'center',
      justifyContent: 'center',
      gap: 8,
      backgroundColor: primary,
      paddingVertical: 18,
      borderRadius: 16,
      width: '100%'
    },
    primaryButtonText: {
      color: '#FFFFFF',
      fontSize: 16,
      fontWeight: '600',
      letterSpacing: 0.5
    }
  });
};
var _default = exports.default = WelcomeNewUserScreen;
//# sourceMappingURL=WelcomeNewUserScreen.js.map