"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _reactNative = require("react-native");
var _react = require("react");
var _reactNativeSvg = require("react-native-svg");
var _CreatePostChooseTargetModal = _interopRequireDefault(require("../CreatePostChooseTargetModal/CreatePostChooseTargetModal"));
var _xml = require("../../../../core/assets/icons/xml");
var _style = require("./style");
var _reactNativePaper = require("react-native-paper");
var _uiSlice = _interopRequireDefault(require("../../../../core/stores/slices/uiSlice"));
var _store = require("../../../../core/stores/store");
var _native = require("@react-navigation/native");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const PostTypeChoiceModal = () => {
  const styles = (0, _style.useStyles)();
  const theme = (0, _reactNativePaper.useTheme)();
  const dispatch = (0, _store.useUIKitDispatch)();
  const navigation = (0, _native.useNavigation)();
  const {
    closePostTypeChoiceModal
  } = _uiSlice.default.actions;
  const {
    showPostTypeChoiceModal,
    userId,
    targetId,
    targetName,
    targetType
  } = (0, _store.useUIKitSelector)(state => state.ui);
  const [postType, setPostType] = (0, _react.useState)();
  const [createPostModalVisible, setCreatePostModalVisible] = (0, _react.useState)(false);
  const onChooseType = type => {
    if (!(targetId && targetName && targetType)) {
      setPostType(type);
      setCreatePostModalVisible(true);
      return;
    }
    if (type === 'post') {
      navigation.navigate('CreatePost', {
        targetId,
        targetType
      });
    } else if (type === 'livestream') {
      navigation.navigate('CreateLivestream', {
        targetId,
        targetName,
        targetType
      });
    } else if (type === 'poll') {
      navigation.navigate('PollPostComposer', {
        targetId,
        targetName,
        targetType
      });
    }
    closeCreatePostModal();
  };
  const closeCreatePostModal = () => {
    setCreatePostModalVisible(false);
    closeModal();
  };
  const closeModal = () => {
    _reactNative.Animated.timing(slideAnimation, {
      toValue: 0,
      duration: 300,
      useNativeDriver: true
    }).start(() => {
      dispatch(closePostTypeChoiceModal());
    });
  };
  const slideAnimation = (0, _react.useRef)(new _reactNative.Animated.Value(0)).current;
  (0, _react.useEffect)(() => {
    if (showPostTypeChoiceModal) {
      _reactNative.Animated.timing(slideAnimation, {
        toValue: 1,
        duration: 300,
        useNativeDriver: true
      }).start();
    }
  }, [slideAnimation, showPostTypeChoiceModal]);
  const modalStyle = {
    transform: [{
      translateY: slideAnimation.interpolate({
        inputRange: [0, 1],
        outputRange: [600, 0] // Adjust this value to control the sliding distance
      })
    }]
  };
  return /*#__PURE__*/React.createElement(_reactNative.Modal, {
    animationType: "fade",
    transparent: true,
    visible: showPostTypeChoiceModal,
    onRequestClose: closeModal
  }, /*#__PURE__*/React.createElement(_reactNative.Pressable, {
    onPress: closeModal,
    style: styles.modalContainer
  }, /*#__PURE__*/React.createElement(_reactNative.Animated.View, {
    style: [styles.modalContent, modalStyle]
  }, /*#__PURE__*/React.createElement(_reactNative.TouchableOpacity, {
    onPress: () => onChooseType('post'),
    style: styles.modalRow
  }, /*#__PURE__*/React.createElement(_reactNativeSvg.SvgXml, {
    xml: (0, _xml.postIconOutlined)(theme.colors.base),
    width: "24",
    height: "24"
  }), /*#__PURE__*/React.createElement(_reactNative.Text, {
    style: styles.postText
  }, "Post")), /*#__PURE__*/React.createElement(_reactNative.TouchableOpacity, {
    onPress: () => onChooseType('poll'),
    style: styles.modalRow
  }, /*#__PURE__*/React.createElement(_reactNativeSvg.SvgXml, {
    xml: (0, _xml.pollIcon)(theme.colors.base),
    width: "24",
    height: "24"
  }), /*#__PURE__*/React.createElement(_reactNative.Text, {
    style: styles.postText
  }, "Poll")), /*#__PURE__*/React.createElement(_reactNative.TouchableOpacity, {
    onPress: () => onChooseType('livestream'),
    style: styles.modalRow
  }, /*#__PURE__*/React.createElement(_reactNativeSvg.SvgXml, {
    xml: (0, _xml.livestreamIcon)(theme.colors.base),
    width: "24",
    height: "24"
  }), /*#__PURE__*/React.createElement(_reactNative.Text, {
    style: styles.postText
  }, "Livestream")), /*#__PURE__*/React.createElement(_CreatePostChooseTargetModal.default, {
    visible: createPostModalVisible,
    onClose: closeCreatePostModal,
    userId: userId,
    onSelect: closeCreatePostModal,
    postType: postType
  }))));
};
var _default = exports.default = /*#__PURE__*/(0, _react.memo)(PostTypeChoiceModal);
//# sourceMappingURL=PostTypeChoiceModal.js.map