import { ref } from 'vue';
import { defineStore } from 'pinia';

export const DEFAULT_WIDTH = 1920;
export const DEFAULT_HEIGHT = 1080;
export const usePageSizeStore = defineStore('pageSize', () => {
  // 缩放比例
  const minRatio = ref(1);
  // 旋转的角度
  const rotate = ref('0deg');

  const computePageSize = () => {
    //获取屏幕尺寸
    const windowWidth = document.body.clientWidth;
    const windowHeight = document.body.clientHeight;

    // //最小边适配
    const ratioWidth = windowWidth / DEFAULT_WIDTH;
    const ratioHeight = windowHeight / DEFAULT_HEIGHT;

    console.log({ ratioWidth, ratioHeight });

    if (ratioWidth < ratioHeight) {
      minRatio.value = ratioWidth;
    } else {
      minRatio.value = ratioHeight;
    }
  };

  return { computePageSize, ratio: minRatio, rotate };
});

export default usePageSizeStore;
