"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _expoVideo = require("expo-video");
var _reactRedux = require("react-redux");
var _chatSettingsSlice = require("../../roomStore/chatSettingsSlice");
var _MODAL_TYPES = require("../../helpers/constants/MODAL_TYPES");
var _icons = require("../../assets/icons");
var _mediaDimensions = require("../../helpers/mediaDimensions");
var _jsxRuntime = require("react/jsx-runtime");
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); }
const CustomMessageVideo = ({
  fileName,
  fileURL,
  mimetype
}) => {
  const dispatch = (0, _reactRedux.useDispatch)();
  const [dims, setDims] = (0, _react.useState)((0, _mediaDimensions.defaultMediaDims)());
  const player = (0, _expoVideo.useVideoPlayer)(fileURL, p => {
    p.muted = true;
  });
  (0, _react.useEffect)(() => {
    const sub = player.addListener('statusChange', () => {
      const size = player.videoTrack?.size;
      if (size?.width && size?.height) {
        setDims((0, _mediaDimensions.fitMediaDimensions)(size.width, size.height));
      }
    });
    return () => sub.remove();
  }, [player]);
  const handleOpen = () => {
    dispatch((0, _chatSettingsSlice.setActiveFile)({
      fileName,
      fileURL,
      mimetype
    }));
    dispatch((0, _chatSettingsSlice.setActiveModal)(_MODAL_TYPES.MODAL_TYPES.FILE_PREVIEW));
  };
  return (
    /*#__PURE__*/
    // Capture-overlay pattern: VideoView sits underneath without ANY
    // touch participation; a transparent absolute-fill <Pressable> on
    // top owns the tap. Previously we wrapped VideoView in a
    // TouchableOpacity and set `pointerEvents="none"` on the inner
    // VideoView — but on some expo-video versions / iOS the native
    // VideoView still intercepted gestures despite that hint, so
    // tapping the poster did nothing. Customer-reported #9 (video
    // preview unresponsive). The Pressable now guarantees the tap
    // reaches `handleOpen`.
    (0, _jsxRuntime.jsxs)(_reactNative.View, {
      style: [styles.wrapper, {
        width: dims.width,
        height: dims.height
      }],
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_expoVideo.VideoView, {
        player: player,
        style: styles.video,
        contentFit: "cover",
        nativeControls: false,
        surfaceType: "textureView",
        pointerEvents: "none"
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
        style: styles.overlay,
        pointerEvents: "none",
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
          style: styles.playButton,
          children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.PlayIcon, {
            width: 28,
            height: 28
          })
        })
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Pressable, {
        onPress: handleOpen
        // Sits ON TOP of VideoView + the play-button overlay; transparent
        // so the poster + play icon show through. Captures the tap and
        // routes to handleOpen → setActiveModal(FILE_PREVIEW).
        ,
        style: _reactNative.StyleSheet.absoluteFill,
        accessibilityRole: "button",
        accessibilityLabel: "Play video"
      })]
    })
  );
};
var _default = exports.default = CustomMessageVideo;
const styles = _reactNative.StyleSheet.create({
  wrapper: {
    borderRadius: 10,
    overflow: 'hidden',
    backgroundColor: '#000'
  },
  video: {
    width: '100%',
    height: '100%'
  },
  overlay: {
    ..._reactNative.StyleSheet.absoluteFillObject,
    justifyContent: 'center',
    alignItems: 'center'
  },
  playButton: {
    width: 48,
    height: 48,
    borderRadius: 24,
    backgroundColor: 'rgba(0, 0, 0, 0.55)',
    justifyContent: 'center',
    alignItems: 'center'
  }
});
//# sourceMappingURL=VideoMessage.js.map