import { toast } from '@whale.io/mini/es/utils/fn';
export * from '@whale.io/common/es/utils/fn';
let systemInfo;
/**
 * 转换rpx为px.
 *
 * @param rpx responsive pixel.
 * @returns pixel unit.
 * @see https://opendocs.alipay.com/mini/framework/acss#rpx
 */

function rpxToPx(rpx) {
  if (!systemInfo) {
    systemInfo = my.getSystemInfoSync();
  }

  return rpx * (systemInfo.windowWidth / 750);
}
/**
 * 解析小程序之间相互跳转scheme.
 *
 * @param scheme Schema需符合`alipays://platformapi/startapp?appId=&page=`形式，page中如果还有其它url参数需encode.
 * @returns
 */


function parseMiniScheme(scheme) {
  let miniParams = {};
  scheme = scheme || '';

  if (scheme.indexOf('alipays://platformapi/startapp') >= 0) {
    const schemaSegments = scheme.split('?');
    const pathParams = schemaSegments[1];
    const values = pathParams.split('&');
    values.forEach(item => {
      miniParams = miniParams || {};
      const [key, val] = item.split('=');
      miniParams[key] = val;
    });
  }

  return miniParams;
}

export { rpxToPx, toast, parseMiniScheme };