interface Gallery {
  label?: string;
  src: string;
}

// module/chats/components/message-analysis/message-analysis.ts

const defaultGallery = {
  'tongueImgUrl': '',
  'tongueBackImgUrl': '',
  'faceImgUrl': '',
}

Component({
  properties: {
    payload: { type: Object, value: { title: '', description: '' } },
    active: { type: Boolean, value: false },
  },
  data: {
    examples: [
      { label: '舌面举例', src: '../../assets/tongue-1.png' },
      { label: '舌下举例', src: '../../assets/tongue-2.png' },
      { label: '面部举例', src: '../../assets/face-1.png' },
    ] as Gallery[],
    source: [] as Gallery[],
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onConfirm() {
      if (this.data.source.length) return;
      wx.navigateTo({
        url: '/module/chats/pages/analysis/analysis',
        events: { update: (data: any[]) => this._update(data) }
      });
    },
    onCancel() {
      this.triggerEvent('next', defaultGallery);
    },

    _update(source: (Gallery & { target: string; })[]) {
      this.setData({ source });
      const data = {} as AnyObject;
      for (const item of source) { data[item.target] = item.src; }
      this.triggerEvent('next', {
        ...defaultGallery,
        ...data,
      });
    }
  }
})