"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = require("react");
var _reactNative = require("react-native");
var _styles = require("./styles");
var _reactNativeSafeAreaContext = require("react-native-safe-area-context");
var _native = require("@react-navigation/native");
var _useImagePicker = _interopRequireDefault(require("../../../hooks/useImagePicker"));
var _icons = require("../../../../core/assets/icons");
var _reactNativeSvg = require("react-native-svg");
var _Typography = require("../../../../core/components/Typography/Typography");
var _reactNativePaper = require("react-native-paper");
var _bottomSheetSlice = require("../../../../core/stores/slices/bottomSheetSlice");
var _CircularProgressIndicator = require("../../../components/CircularProgressIndicator");
var _tsSdkReactNative = require("@amityco/ts-sdk-react-native");
var _Button = _interopRequireDefault(require("../../../components/Button/Button"));
var _useCamera = require("../../../hooks/useCamera");
var _netinfo = _interopRequireDefault(require("@react-native-community/netinfo"));
var _roomStatus = require("../../../enums/roomStatus");
var _ThumbnailAction = require("../components/ThumbnailAction");
var _StartLivestreamButton = require("../../../elements/StartLivestreamButton");
var _LivestreamStartingThumbnail = _interopRequireDefault(require("../../../components/LivestreamContent/LivestreamStartingThumbnail"));
var _enums = require("../../../enums");
var _useShareableLink = require("../../../../core/hooks/useShareableLink");
var _types = require("../../../types");
var _useCommunity = require("../../../hooks/useCommunity");
var _MenuButton = _interopRequireDefault(require("../../../elements/MenuButton/MenuButton"));
var _CopyLinkAction = require("../../../elements/CopyLinkAction");
var _ShareAction = require("../../../elements/ShareAction");
var _LiveTimerStatus = require("../../../elements/LiveTimerStatus");
var _CancelCreateLivestreamButton = require("../../../elements/CancelCreateLivestreamButton");
var _EndLiveStreamButton = require("../../../elements/EndLiveStreamButton");
var _AddThumbnailButton = require("../../../elements/AddThumbnailButton");
var _SwitchCameraButton = require("../../../elements/SwitchCameraButton");
var _livekitClient = require("livekit-client");
var _reactNative2 = require("@livekit/react-native");
var _RoomView = require("./RoomView");
var _reactNativeVisionCamera = require("react-native-vision-camera");
var _useRoomSubscription = require("../../../hooks/useRoomSubscription");
var _toastSlice = require("../../../../core/stores/slices/toastSlice");
var _hooks = require("../../../hooks");
var _useRoom = require("../../room/hooks/useRoom");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
// Register WebRTC globals required for LiveKit
(0, _reactNative2.registerGlobals)();
const serverUrl = 'wss://sp-live-3tr59jrk.livekit.cloud';
const calculateTime = time => {
  const hours = Math.floor(time / 3600000);
  const minutes = Math.floor(time / 60000);
  const seconds = (time % 60000 / 1000).toFixed(0);
  const hoursString = `${hours < 10 ? '0' : ''}${hours}`;
  const minutesString = `${minutes < 10 ? '0' : ''}${minutes}`;
  const secondsString = `${Number(seconds) < 10 ? '0' : ''}${seconds}`;
  return `${hours > 0 ? hoursString + ':' : ''}${minutesString}:${secondsString}`;
};
function AmityCreateLivestreamPage() {
  const styles = (0, _styles.useStyles)();
  const navigation = (0, _native.useNavigation)();
  const theme = (0, _reactNativePaper.useTheme)();
  const route = (0, _native.useRoute)();
  const [time, setTime] = (0, _react.useState)(0);
  const [title, setTitle] = (0, _react.useState)('');
  const [isLive, setIsLive] = (0, _react.useState)(false);
  const [description, setDescription] = (0, _react.useState)('');
  const [isEnding, setIsEnding] = (0, _react.useState)(false);
  const [countdown, setCountdown] = (0, _react.useState)(null);
  const [post, setPost] = (0, _react.useState)(null);
  const [roomId, setRoomId] = (0, _react.useState)('');
  const timerRef = (0, _react.useRef)(null);
  const connectionLossTimeoutRef = (0, _react.useRef)(null);
  const [isConnecting, setIsConnecting] = (0, _react.useState)(false);
  const [androidPermission, setAndroidPermission] = (0, _react.useState)(false);
  const [iOSPermission, setIOSPermission] = (0, _react.useState)(true);
  const [reconnecting, setReconnecting] = (0, _react.useState)(false);
  const [livekitParticipant, setLivekitParticipant] = (0, _react.useState)(null);
  const [isFrontCamera, setIsFrontCamera] = (0, _react.useState)(true);
  const [roomToken, setRoomToken] = (0, _react.useState)(null);
  const unsubscribeRef = (0, _react.useRef)(null);
  const room = (0, _useRoom.useRoom)(roomId);
  (0, _useRoomSubscription.useRoomSubscription)({
    room
  });
  const {
    subscribedPost
  } = (0, _hooks.usePostSubscription)((post === null || post === void 0 ? void 0 : post.postId) || '');
  const {
    showToast
  } = (0, _toastSlice.useToast)();
  const frontCamera = (0, _reactNativeVisionCamera.useCameraDevice)('front');
  const backCamera = (0, _reactNativeVisionCamera.useCameraDevice)('back');
  const cameraDevice = isFrontCamera ? frontCamera : backCamera;
  const {
    imageUri,
    isLoading,
    progress,
    uploadedImage,
    removeSelectedImage,
    openImageGallery
  } = (0, _useImagePicker.default)();
  const {
    targetId,
    targetType,
    targetName,
    pop
  } = route.params;
  const {
    openBottomSheet,
    closeBottomSheet,
    bottomSheetHeight
  } = (0, _bottomSheetSlice.useBottomSheet)();
  const {
    getShareLink
  } = (0, _useShareableLink.useShareableLink)();
  const {
    community
  } = (0, _useCommunity.useCommunity)(targetType === 'community' ? targetId : undefined);
  const canShare = targetType === 'user' || targetType === 'community' && (community === null || community === void 0 ? void 0 : community.isPublic) === true;
  const shareLink = roomId && canShare ? getShareLink(_types.ShareableLinkModel.livestreams, roomId) : null;
  const handleSharePress = () => {
    if (!shareLink) return;
    openBottomSheet({
      height: bottomSheetHeight[2],
      dark: true,
      content: /*#__PURE__*/React.createElement(_reactNative.View, null, /*#__PURE__*/React.createElement(_CopyLinkAction.CopyLinkAction, {
        dark: true,
        link: shareLink,
        pageId: _enums.PageID.create_livestream_page
      }), /*#__PURE__*/React.createElement(_ShareAction.ShareAction, {
        dark: true,
        link: shareLink,
        pageId: _enums.PageID.create_livestream_page
      }))
    });
  };
  const disabled = !(title !== null && title !== void 0 && title.trim()) || isConnecting || isLoading;
  const hasPermission = _reactNative.Platform.OS === 'android' && androidPermission || _reactNative.Platform.OS === 'ios' && iOSPermission;
  const fourHours = 4 * 60 * 60 * 1000; // 4 hours
  const countdownStart = fourHours - 10 * 1000; // Start countdown 10 seconds before end
  const toastTriggerTime = fourHours - 3 * 60 * 1000; // Show toast 3 minutes before end

  const switchCamera = (0, _react.useCallback)(async () => {
    if (isLive && livekitParticipant) {
      try {
        const cameraPublication = livekitParticipant.getTrackPublication(_livekitClient.Track.Source.Camera);
        if (cameraPublication !== null && cameraPublication !== void 0 && cameraPublication.track) {
          const videoTrack = cameraPublication.track;

          // Stop current camera
          await videoTrack.stop();

          // Get new facing mode
          const newFacingMode = isFrontCamera ? 'environment' : 'user';

          // Restart camera with new facing mode
          await videoTrack.restartTrack({
            facingMode: newFacingMode
          });

          // Toggle the camera state
          setIsFrontCamera(prev => !prev);
        }
      } catch (error) {
        console.error('Failed to switch camera:', error);
      }
    } else {
      // Just toggle the camera state for preview
      setIsFrontCamera(prev => !prev);
    }
  }, [livekitParticipant, isFrontCamera, isLive]);
  (0, _useCamera.useRequestPermission)({
    shouldCall: _reactNative.Platform.OS === 'ios',
    onRequestPermissionFailed: callback => {
      setTimeout(() => {
        callback && callback();
        setIOSPermission(false);
      }, 700);
    }
  });
  const checkPermissionAndroid = (0, _react.useCallback)(async () => {
    try {
      const cameraPermission = await _reactNative.PermissionsAndroid.request(_reactNative.PermissionsAndroid.PERMISSIONS.CAMERA, {
        title: `App Would Like to Access the Camera`,
        message: 'Allow camera access so you can take pictures, record video and share live streams to your community.',
        buttonNegative: "Don't Allow",
        buttonPositive: 'Allow'
      });
      const microphonePermission = await _reactNative.PermissionsAndroid.request(_reactNative.PermissionsAndroid.PERMISSIONS.RECORD_AUDIO, {
        title: `App Would Like to Access the Microphone`,
        message: 'Allow camera access so you can take pictures, record video and share live streams to your community.',
        buttonNegative: "Don't Allow",
        buttonPositive: 'Allow'
      });
      if (cameraPermission !== _reactNative.PermissionsAndroid.RESULTS.GRANTED || microphonePermission !== _reactNative.PermissionsAndroid.RESULTS.GRANTED) {
        setAndroidPermission(false);
      }
      if (cameraPermission === _reactNative.PermissionsAndroid.RESULTS.GRANTED && microphonePermission === _reactNative.PermissionsAndroid.RESULTS.GRANTED) setAndroidPermission(true);
    } catch (err) {
      console.warn(err);
    }
  }, []);
  const onGoLive = async () => {
    try {
      setIsLive(true);
      setIsConnecting(true);
      const {
        data: newStream
      } = await _tsSdkReactNative.RoomRepository.createRoom({
        title,
        description: description || undefined,
        thumbnailFileId: uploadedImage === null || uploadedImage === void 0 ? void 0 : uploadedImage.fileId,
        type: 'coHosts'
      });
      setRoomId(newStream.roomId);
      if (newStream) {
        const roomTokenResponse = await _tsSdkReactNative.RoomRepository.getBroadcasterData(newStream.roomId);
        setRoomToken(roomTokenResponse);
        const params = {
          targetId,
          targetType,
          dataType: 'room',
          data: {
            text: `${newStream.title}${newStream.description ? `\n\n${newStream.description}` : ''}`,
            roomId: newStream.roomId
          }
        };
        const newPost = await _tsSdkReactNative.PostRepository.createPost(params);
        setPost(newPost.data);

        // Do NOT set isConnecting to false here — keep the loading overlay
        // visible until LiveKitRoom fires onConnected, which confirms the
        // video stream is ready. Clearing it prematurely exposes the white
        // background before the camera feed appears (PDT-3089).

        // Start the timer when live stream actually starts
        if (timerRef.current) {
          clearInterval(timerRef.current);
        }
        const intervalId = setInterval(() => {
          setTime(prev => prev + 1000);
        }, 1000);
        timerRef.current = intervalId;
      }
    } catch (error) {
      setIsLive(false);
      setIsConnecting(false);
      _reactNative.Alert.alert('Cannot start live stream', 'Something went wrong while trying to complete your request. Please try again.', [{
        text: 'OK'
      }]);
    }
  };
  const confirmEndStreamAlert = () => {
    _reactNative.Alert.alert('End live stream?', 'If you end your live stream, it will also end for all your viewers.', [{
      text: 'Cancel',
      style: 'cancel'
    }, {
      style: 'destructive',
      text: 'End',
      onPress: () => {
        endLiveStream();
      }
    }]);
  };
  const endLiveStream = (0, _react.useCallback)(async (showEndPopup = false) => {
    if (room) {
      setIsEnding(true);
      try {
        await _tsSdkReactNative.RoomRepository.stopRoom(room.roomId);
      } catch (e) {
        console.log('disposeStream error', e);
      } finally {
        setIsLive(false);
        setRoomId('');
        setTitle('');
        setDescription('');
        setTime(0);
        if (timerRef.current) {
          clearInterval(timerRef.current);
          timerRef.current = null;
        }
        setIsEnding(false);
        setReconnecting(false);
        navigation.navigate('PostDetail', {
          postId: post === null || post === void 0 ? void 0 : post.postId,
          showEndPopup
        });
      }
    }
  }, [post, room, navigation]);
  (0, _react.useEffect)(() => {
    // Show toast when 3 minutes left
    if (room && time >= toastTriggerTime && time < toastTriggerTime + 1000) {
      showToast({
        type: 'informative',
        message: 'Your live will automatically end once it reaches 4-hour limit.',
        duration: 3000,
        bottomPosition: 96
      });
    }
    if (room && time >= fourHours) {
      endLiveStream(true);
      setCountdown(null);
    } else if (room && time >= countdownStart && time < fourHours) {
      // Calculate countdown from 10 to 0
      const remaining = Math.ceil((fourHours - time) / 1000);
      setCountdown(remaining);
    } else {
      setCountdown(null);
    }
  }, [endLiveStream, room, time, showToast, toastTriggerTime, fourHours, countdownStart]);
  (0, _react.useEffect)(() => {
    if (_reactNative.Platform.OS === 'android') checkPermissionAndroid();
  }, [checkPermissionAndroid]);
  (0, _react.useEffect)(() => {
    _netinfo.default.fetch().then(state => {
      setReconnecting(!state.isConnected);
    });
    let unsubscribe = _netinfo.default.addEventListener(state => {
      setReconnecting(!state.isConnected);
    });
    return () => unsubscribe();
  }, []);
  (0, _react.useEffect)(() => {
    if (reconnecting && (room === null || room === void 0 ? void 0 : room.status) === _roomStatus.RoomStatus.live) {
      connectionLossTimeoutRef.current = setTimeout(() => {
        endLiveStream();
      }, 1000 * 60 * 3);
    } else {
      if (connectionLossTimeoutRef.current) {
        clearTimeout(connectionLossTimeoutRef.current);
        connectionLossTimeoutRef.current = null;
      }
    }
    return () => {
      if (connectionLossTimeoutRef.current) {
        clearTimeout(connectionLossTimeoutRef.current);
        connectionLossTimeoutRef.current = null;
      }
    };
  }, [reconnecting, endLiveStream, room === null || room === void 0 ? void 0 : room.status]);
  (0, _react.useEffect)(() => {
    if ((room === null || room === void 0 ? void 0 : room.status) === _roomStatus.RoomStatus.terminated) {
      navigation.replace('LivestreamTerminated', {
        type: 'streamer'
      });
    }
  }, [room === null || room === void 0 ? void 0 : room.status, navigation]);
  (0, _react.useEffect)(() => {
    if (room !== null && room !== void 0 && room.isDeleted || subscribedPost !== null && subscribedPost !== void 0 && subscribedPost.isDeleted) {
      navigation.replace('PostDetail', {
        postId: subscribedPost === null || subscribedPost === void 0 ? void 0 : subscribedPost.postId
      });
    }
  }, [navigation, room === null || room === void 0 ? void 0 : room.isDeleted, subscribedPost === null || subscribedPost === void 0 ? void 0 : subscribedPost.postId, subscribedPost === null || subscribedPost === void 0 ? void 0 : subscribedPost.isDeleted]);
  (0, _react.useEffect)(() => {
    const unsubscribe = unsubscribeRef.current;
    return () => {
      unsubscribe && unsubscribe();
    };
  }, []);
  return /*#__PURE__*/React.createElement(_reactNativeSafeAreaContext.SafeAreaView, {
    style: styles.container
  }, (!isLive || isLive && reconnecting && !isEnding || isEnding) && /*#__PURE__*/React.createElement(_reactNative.View, {
    style: [styles.overlay, !hasPermission && styles.noPermissionOverlay]
  }), isLive && isConnecting && /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.startingContainer
  }, /*#__PURE__*/React.createElement(_LivestreamStartingThumbnail.default, null)), hasPermission ? roomToken ? /*#__PURE__*/React.createElement(_reactNative2.LiveKitRoom, {
    serverUrl: serverUrl,
    token: roomToken.coHostToken,
    connect: true,
    options: {
      adaptiveStream: {
        pixelDensity: 'screen'
      }
    },
    audio: {
      echoCancellation: true,
      noiseSuppression: true,
      autoGainControl: true
    },
    video: {
      facingMode: isFrontCamera ? 'user' : 'environment'
    },
    onConnected: () => {
      setIsConnecting(false);
      setReconnecting(false);
    },
    onDisconnected: () => {
      setReconnecting(true);
    }
  }, /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.cameraContainer
  }, /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.camera
  }, !isConnecting && /*#__PURE__*/React.createElement(_RoomView.RoomView, {
    onLocalParticipantReady: setLivekitParticipant,
    isFrontCamera: isFrontCamera
  })))) : /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.cameraContainer
  }, /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.camera
  }, cameraDevice && /*#__PURE__*/React.createElement(_reactNativeVisionCamera.Camera
  // eslint-disable-next-line react-native/no-inline-styles
  , {
    style: {
      flex: 1
    },
    device: cameraDevice,
    isActive: !isConnecting
  }))) : /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.permission
  }, /*#__PURE__*/React.createElement(_Typography.Typography.TitleBold, {
    style: styles.permissionTitle
  }, "Allow access to your ", '\n', " camera and microphone"), /*#__PURE__*/React.createElement(_Typography.Typography.Body, {
    style: styles.permissionDescription
  }, "This lets you record and live stream ", '\n', " from this device."), /*#__PURE__*/React.createElement(_Button.default, {
    type: "primary",
    onPress: () => _reactNative.Linking.openSettings()
  }, /*#__PURE__*/React.createElement(_Typography.Typography.BodyBold, {
    style: styles.text
  }, "Open settings"))), isEnding && /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.connecting
  }, /*#__PURE__*/React.createElement(_CircularProgressIndicator.CircularProgressIndicator, {
    size: 40,
    strokeWidth: 2
  }), /*#__PURE__*/React.createElement(_Typography.Typography.TitleBold, {
    style: styles.text
  }, "Ending live stream")), isLive ? isConnecting ? null : /*#__PURE__*/React.createElement(React.Fragment, null, !isEnding && reconnecting && /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.connecting
  }, /*#__PURE__*/React.createElement(_CircularProgressIndicator.CircularProgressIndicator, {
    size: 40,
    strokeWidth: 2
  }), /*#__PURE__*/React.createElement(_Typography.Typography.TitleBold, {
    style: styles.text
  }, "Reconnecting"), /*#__PURE__*/React.createElement(_Typography.Typography.Caption, {
    style: styles.reconnectingText
  }, "Due to poor connection, this live stream has been ", '\n', ' ', "paused. It will resume automatically ", '\n', " once the connection is stable.")), /*#__PURE__*/React.createElement(_reactNative.TouchableOpacity, {
    style: styles.closeButton,
    onPress: () => confirmEndStreamAlert()
  }, /*#__PURE__*/React.createElement(_reactNativeSvg.SvgXml, {
    xml: (0, _icons.close)(),
    width: "28",
    height: "28",
    color: theme.colors.background
  })), /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.liveRow
  }, /*#__PURE__*/React.createElement(_LiveTimerStatus.LiveTimerStatus, {
    time: calculateTime(time),
    pageId: _enums.PageID.create_livestream_page
  }), shareLink && /*#__PURE__*/React.createElement(_MenuButton.default, {
    pageId: _enums.PageID.create_livestream_page,
    variant: "vertical",
    onPress: handleSharePress
  })), countdown !== null && /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.countdownOverlay
  }, /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.countdownContainer
  }, /*#__PURE__*/React.createElement(_Typography.Typography.TitleBold, {
    style: styles.countdownText
  }, "Live stream ends in"), /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.countdownCircle
  }, /*#__PURE__*/React.createElement(_CircularProgressIndicator.CircularProgressIndicator, {
    size: 64,
    strokeWidth: 2,
    progress: (10 - countdown) / 10 * 100
  }), /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.countdownNumberContainer
  }, /*#__PURE__*/React.createElement(_Typography.Typography, {
    style: styles.countdownNumber
  }, countdown)))))) : /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.content
  }, /*#__PURE__*/React.createElement(_reactNative.View, null, /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.header
  }, /*#__PURE__*/React.createElement(_CancelCreateLivestreamButton.CancelCreateLivestreamButton, {
    pageId: _enums.PageID.create_livestream_page,
    onPress: () => {
      if (title !== null && title !== void 0 && title.trim()) return _reactNative.Alert.alert('Unsaved changes', 'Are you sure you want to discard the changes? They will be lost when you leave this page.', [{
        text: 'Cancel',
        style: 'cancel'
      }, {
        text: 'Discard',
        style: 'destructive',
        onPress: () => {
          navigation.goBack();
          if (pop === 2) navigation.goBack();
        }
      }]);
      navigation.goBack();
      if (pop === 2) navigation.goBack();
    }
  }), /*#__PURE__*/React.createElement(_reactNative.TouchableOpacity, {
    style: styles.communityButton,
    onPress: () => {
      const state = navigation.getState();
      const routes = state.routes;
      const currentIndex = state.index;
      const previousRoute = routes[currentIndex - 1];
      if ((previousRoute === null || previousRoute === void 0 ? void 0 : previousRoute.name) === 'LivestreamPostTargetSelection') {
        navigation.goBack();
      } else {
        return;
      }
    },
    activeOpacity: 0.7
  }, /*#__PURE__*/React.createElement(_Typography.Typography.Body, {
    style: styles.communityName,
    numberOfLines: 1,
    ellipsizeMode: "tail"
  }, "Live on", ' ', /*#__PURE__*/React.createElement(_Typography.Typography.BodyBold, {
    numberOfLines: 1,
    ellipsizeMode: "tail",
    style: styles.communityName
  }, targetName)), /*#__PURE__*/React.createElement(_reactNative.View, null, /*#__PURE__*/React.createElement(_reactNativeSvg.SvgXml, {
    xml: (0, _icons.arrowDown)(),
    width: 16,
    height: 16,
    color: theme.colors.background
  })))), hasPermission && /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.inputContainer
  }, /*#__PURE__*/React.createElement(_reactNative.TextInput, {
    style: styles.titleInput,
    placeholder: "Add live stream title...",
    numberOfLines: 1,
    maxLength: 30,
    placeholderTextColor: 'rgba(255, 255, 255, 0.8)',
    onChangeText: text => setTitle(text),
    value: title
  }), /*#__PURE__*/React.createElement(_reactNative.TextInput, {
    style: styles.descriptionInput,
    multiline: true,
    scrollEnabled: true,
    blurOnSubmit: true,
    placeholder: "Add description (optional)",
    placeholderTextColor: 'rgba(255, 255, 255, 0.8)',
    onChangeText: text => setDescription(text),
    value: description
  }))), /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.goLiveContainer
  }, /*#__PURE__*/React.createElement(_StartLivestreamButton.StartLivestreamButton, {
    onPress: onGoLive,
    disabled: disabled,
    pageId: _enums.PageID.create_livestream_page
  }))), /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.footer
  }, isLive && !isConnecting && /*#__PURE__*/React.createElement(_EndLiveStreamButton.EndLiveStreamButton, {
    onPress: confirmEndStreamAlert,
    pageId: _enums.PageID.create_livestream_page
  }), isLive && isConnecting && /*#__PURE__*/React.createElement(_reactNative.View, null), !isLive && /*#__PURE__*/React.createElement(React.Fragment, null, imageUri || uploadedImage ? /*#__PURE__*/React.createElement(_reactNative.TouchableOpacity, {
    activeOpacity: 0.7,
    style: styles.thumbnailButton,
    onPress: () => {
      openBottomSheet({
        height: 200,
        content: /*#__PURE__*/React.createElement(_ThumbnailAction.AmityThumbnailActionComponent, {
          onChangeThumbnail: () => {
            closeBottomSheet();
            openImageGallery({
              selectionLimit: 1,
              mediaType: 'photo',
              includeBase64: false
            });
          },
          onDeleteThumbnail: () => {
            closeBottomSheet();
            removeSelectedImage();
          }
        })
      });
    }
  }, /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.thumbnailImageContainer
  }, /*#__PURE__*/React.createElement(_reactNative.Image, {
    source: {
      uri: (uploadedImage === null || uploadedImage === void 0 ? void 0 : uploadedImage.fileUrl) || imageUri
    },
    style: styles.thumbnailImage
  }), isLoading && /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.thumbnailLoader
  }, /*#__PURE__*/React.createElement(_CircularProgressIndicator.CircularProgressIndicator, {
    size: 24,
    strokeWidth: 2,
    progress: progress
  })))) : /*#__PURE__*/React.createElement(_AddThumbnailButton.AddThumbnailButton, {
    onPress: () => openImageGallery({
      selectionLimit: 1,
      mediaType: 'photo',
      includeBase64: false
    }),
    pageId: _enums.PageID.create_livestream_page
  })), /*#__PURE__*/React.createElement(_SwitchCameraButton.SwitchCameraButton, {
    pageId: _enums.PageID.create_livestream_page,
    onPress: switchCamera
  })));
}
var _default = exports.default = AmityCreateLivestreamPage;
//# sourceMappingURL=Create.js.map