"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.MediaFilePreview = void 0;
var _reactNative = require("react-native");
var _StyledInputComponents = require("./StyledInputComponents/StyledInputComponents");
var _icons = require("../../assets/icons");
var _StyledComponents = require("./StyledComponents");
var _react = require("react");
var _expoVideo = require("expo-video");
var _jsxRuntime = require("react/jsx-runtime");
const VideoThumb = ({
  uri,
  onPress
}) => {
  const player = (0, _expoVideo.useVideoPlayer)(uri, p => {
    p.muted = true;
  });
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.TouchableOpacity, {
    activeOpacity: 0.8,
    onPress: onPress,
    style: styles.videoThumb,
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_expoVideo.VideoView, {
      player: player,
      style: _reactNative.StyleSheet.absoluteFill,
      contentFit: "cover",
      nativeControls: false,
      surfaceType: "textureView",
      pointerEvents: "none"
    }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
      style: styles.playOverlay,
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
        style: styles.playIcon,
        children: "\u25B6"
      })
    })]
  });
};
const FullscreenPreviewVideo = ({
  uri
}) => {
  const player = (0, _expoVideo.useVideoPlayer)(uri, p => {
    p.play();
  });
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_expoVideo.VideoView, {
    player: player,
    style: styles.fullVideo,
    contentFit: "contain",
    nativeControls: true,
    surfaceType: "textureView"
  });
};
const MediaFilePreview = ({
  filePreviews,
  handleRemoveImage
}) => {
  const [previewUri, setPreviewUri] = (0, _react.useState)(null);
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_StyledInputComponents.MediaContainer, {
    children: [filePreviews.map((file, index) => {
      const isImage = file.type?.startsWith('image');
      const isVideo = file.type?.startsWith('video');
      return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
        children: [isImage ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_StyledInputComponents.MediaImage, {
          source: {
            uri: file.uri
          }
        }) : isVideo ? /*#__PURE__*/(0, _jsxRuntime.jsx)(VideoThumb, {
          uri: file.uri,
          onPress: () => setPreviewUri(file.uri)
        }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
          style: {
            width: 70,
            height: 70,
            borderRadius: 8
          },
          children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.FileIcon, {
            width: 70,
            height: 70
          })
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_StyledComponents.RemoveButton, {
          onPress: () => handleRemoveImage(index),
          children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_StyledComponents.RemoveButtonText, {
            children: "\xD7"
          })
        })]
      }, `${file.name}_${index}`);
    }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Modal, {
      visible: !!previewUri,
      animationType: "fade",
      transparent: true,
      children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.SafeAreaView, {
        style: styles.modalContainer,
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TouchableOpacity, {
          style: styles.closeButton,
          onPress: () => setPreviewUri(null),
          children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
            style: styles.closeText,
            children: "\u2715"
          })
        }), previewUri && /*#__PURE__*/(0, _jsxRuntime.jsx)(FullscreenPreviewVideo, {
          uri: previewUri
        })]
      })
    })]
  });
};
exports.MediaFilePreview = MediaFilePreview;
const styles = _reactNative.StyleSheet.create({
  videoThumb: {
    width: 70,
    height: 70,
    borderRadius: 8,
    overflow: 'hidden',
    backgroundColor: '#1a1a1a'
  },
  playOverlay: {
    ..._reactNative.StyleSheet.absoluteFillObject,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: 'rgba(0,0,0,0.3)'
  },
  playIcon: {
    fontSize: 24,
    color: '#fff'
  },
  modalContainer: {
    flex: 1,
    backgroundColor: '#000',
    justifyContent: 'center'
  },
  closeButton: {
    position: 'absolute',
    top: 60,
    right: 20,
    zIndex: 10,
    width: 36,
    height: 36,
    borderRadius: 18,
    backgroundColor: 'rgba(255,255,255,0.2)',
    justifyContent: 'center',
    alignItems: 'center'
  },
  closeText: {
    fontSize: 18,
    color: '#fff',
    fontWeight: '600'
  },
  fullVideo: {
    width: '100%',
    height: '70%'
  }
});
//# sourceMappingURL=MediaFilePreview.js.map