import { createPublish } from 'applet-page-component';
import { queryToUrl } from './index';

const getOptions = () => ({ ...createPublish(),
  data: {
    pageType: undefined,
    componentData: undefined,
    query: {},
    title: ''
  },

  onLoad(query) {
    const {
      pageType,
      title,
      ...other
    } = query;
    my.setNavigationBar({
      title
    });
    const componentData = getApp().globalData.pageTemp[pageType];
    this.setData({
      pageType,
      componentData,
      query: other,
      title
    });
  },

  onUnload() {
    Reflect.deleteProperty(getApp().globalData.pageTemp, this.data.pageType);
  },

  // 分享
  onShareAppMessage() {
    const {
      pageType,
      query,
      title
    } = this.data;
    return {
      title,
      path: `${this.route}?pageType=${pageType}&title=${title}${queryToUrl(query)}`
    };
  }

});

export default getOptions;