import { Dimensions } from "react-native";

const { width, height } = Dimensions.get("window");
// Guideline sizes are based on standard ~5" screen mobile device
const guidelineBaseWidth = width;
const guidelineBaseHeight = height;

const isLandscape = width > height;
const isPortait = !isLandscape;

const scale = (size) => (width / guidelineBaseWidth) * size;
const verticalScale = (size) => (height / guidelineBaseHeight) * size;
const moderateScale = (size, factor = 0.5) =>
  (size + (scale(size) - size)) * factor;
const fontScale = (size) => Math.min(scale(size), verticalScale(size));

const getMaxWidth = () => {
  return Math.round(
    Math.max(Dimensions.get("screen").height, Dimensions.get("screen").width)
  );
};

const getMinWidth = () => {
  return Math.round(
    Math.min(Dimensions.get("screen").height, Dimensions.get("screen").width)
  );
};

const getOrientation = () => {
  const { width, height } = Dimensions.get("window");
  const isLandscape = width > height;
  return isLandscape ? "LANDSCAPE" : "PORTRAIT";
};

export {
  scale,
  verticalScale,
  moderateScale,
  fontScale,
  getMaxWidth,
  getMinWidth,
  isLandscape,
  isPortait,
  getOrientation,
};
