"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.fitMediaDimensions = exports.defaultMediaDims = exports.MEDIA_MAX_W = exports.MEDIA_MAX_H = void 0;
var _reactNative = require("react-native");
// Shared sizing for inline media bubbles (images + video posters).
// Goal: show the media UNCROPPED, just scaled, preserving aspect ratio —
// portrait stays portrait, landscape stays landscape.
const screenW = _reactNative.Dimensions.get('window').width;

// Box the media must fit inside. Width adapts to the screen so it never
// blows past the bubble's max-width on small phones, but caps on tablets.
const MEDIA_MAX_W = exports.MEDIA_MAX_W = Math.min(260, Math.round(screenW * 0.64));
const MEDIA_MAX_H = exports.MEDIA_MAX_H = 320;
// Keep thumbnails from collapsing into a sliver (very wide/tall media).
const MEDIA_MIN_W = 140;
const MEDIA_MIN_H = 120;
// Neutral 4:3 placeholder used before the natural size is known.
const defaultMediaDims = () => ({
  width: MEDIA_MAX_W,
  height: Math.round(MEDIA_MAX_W * 0.75)
});

// Fit (natW × natH) inside the box, preserving aspect ratio. Never
// upscales beyond the source resolution (avoids blur), but bumps very
// small media up to a sensible minimum so it stays tappable.
exports.defaultMediaDims = defaultMediaDims;
const fitMediaDimensions = (natW, natH) => {
  if (!natW || !natH) {
    return defaultMediaDims();
  }
  let scale = Math.min(MEDIA_MAX_W / natW, MEDIA_MAX_H / natH);
  if (scale > 1) {
    scale = 1;
  }
  let width = Math.round(natW * scale);
  let height = Math.round(natH * scale);
  if (width < MEDIA_MIN_W || height < MEDIA_MIN_H) {
    const up = Math.max(MEDIA_MIN_W / width, MEDIA_MIN_H / height);
    width = Math.min(MEDIA_MAX_W, Math.round(width * up));
    height = Math.min(MEDIA_MAX_H, Math.round(height * up));
  }
  return {
    width,
    height
  };
};
exports.fitMediaDimensions = fitMediaDimensions;
//# sourceMappingURL=mediaDimensions.js.map