import Taro from '@tarojs/taro'

/**
 * 获取配置
 * @returns 
 */
export function getConfig() {
  // https://developers.weixin.qq.com/miniprogram/dev/api/base/system/wx.getSystemInfo.html
  const systemInfo = Taro.getStorageSync('systemInfo')
  const { windowWidth } = systemInfo

  // canvas
  const canvas = {
    width: windowWidth,
    // 设计稿宽高比 2.16  = height / width
    height: windowWidth * 2.16,
  }

  // 图片
  const poster = {
    width: canvas.width,
    height: canvas.width * 16 / 9, // 图片宽高 9 : 16 占用 canvas 80%
    x: 0,
    y: 0,
  }

  const marign = 22.5;
  const innerMargin = 15

  // 头像
  const avatar = {
    arc: true,  // arc 代表裁剪为圆形
    width: 66,
    height: 66,
    x: marign,
    y: poster.height + 39,
  }

  // 小程序码
  const miniCode = {
    arc: true,
    width: 99,
    height: 99,
    x: canvas.width - 99 - marign,  // 99 是宽度
    y: poster.height + 20,
  }

  // 姓名
  const name = {
    // https://developer.mozilla.org/zh-CN/docs/Web/CSS/font
    font: '15px serif',
    // https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/fillStyle
    fillStyle: '#333333',

    // 左右两边边距
    // 左右两边文字边距
    maxWidth: canvas.width - (marign * 2) - avatar.width - miniCode.width - (innerMargin * 2),

    x: marign + avatar.width + innerMargin,
    y: poster.height + 65,
  }

  // 说明
  const desc = {
    font: '10px serif',
    fillStyle: '#666666',
    maxWidth: name.maxWidth,
    x: name.x,
    y: poster.height + (89.5),
  }

  return {
    systemInfo,
    canvas,
    poster,
    miniCode,
    avatar,
    name,
    desc,
  }
}
