type WXShareConfig = {
  type: string;
  title: string;
  description: string;
  thumbImageUrl: string;
  webpageUrl: string;
};

let config: WXShareConfig = {
  type: 'shareModal',
  title: '分享标题',
  description: '',
  thumbImageUrl: 'https://logo.png',
  webpageUrl: window.location.href.replace('/ad/', '/share/')
};

// 设置分享配置
export const setWXShareConfig = (cb?: (config: WXShareConfig) => WXShareConfig) => {
  // 留作扩展
  cb && (config = cb(config));
  const url = new URL(window.location.href);
  // 获取 url 图片
  config.thumbImageUrl = url.origin + '/yl.png';
  // 获取 title 内容
  config.title = document.title || '伊调研';
  //   描述区域待定
  config.description = '';
  //   网页地址
  config.webpageUrl = window.location.href.replace('/ad/', '/share/');
};

// 获取分享配置
export const getWXShareConfig = () => {
  setWXShareConfig();
  return config;
};
