"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _reactNativeVisionCamera = require("react-native-vision-camera");
var _Create = _interopRequireDefault(require("../../features/story/Create"));
var _useCamera = require("../../hooks/useCamera");
var _reactNative = require("react-native");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const CreateStoryScreen = ({
  navigation,
  route
}) => {
  const {
    targetId,
    targetType
  } = route.params;
  (0, _useCamera.useRequestPermission)({
    onRequestPermissionFailed: () => {
      _reactNative.Linking.openSettings();
    },
    shouldCall: true
  });
  const backCamera = (0, _reactNativeVisionCamera.useCameraDevice)('back');
  const frontCamera = (0, _reactNativeVisionCamera.useCameraDevice)('front');
  if (!frontCamera && !backCamera) {
    _reactNative.Alert.alert('Camera Error', 'Cannot open camera', [{
      text: 'Go Back',
      onPress: () => {
        navigation.goBack();
      }
    }]);
    return null;
  }
  const handleCreateStory = () => {
    const state = navigation.getState();
    const routes = state.routes;
    const currentIndex = state.index;
    if (currentIndex > 0) {
      const previousRoute = routes[currentIndex - 1];
      const previousRouteName = previousRoute.name;
      if (previousRouteName === 'ViewStory' || previousRouteName === 'StoryTargetSelection') {
        navigation.pop(2);
        return;
      }
    }
    navigation.goBack();
  };
  return /*#__PURE__*/React.createElement(_Create.default, {
    targetId: targetId,
    targetType: targetType,
    onCreateStory: handleCreateStory
  });
};
var _default = exports.default = CreateStoryScreen;
//# sourceMappingURL=CreateStoryScreen.js.map