Component({
  data: {
    reply: '',
    summaryLabel: '',
    cards: [],
    actions: [],
  },
  lifetimes: {
    created() {
      const { NotificationType } = wx.modelContext
      this._viewCtx = wx.modelContext.getViewContext(this)
      wx.modelContext.getContext(this).on(NotificationType.Result, (data) => {
        const result = data && data.result ? data.result : {}
        const structured = result.structuredContent || {}
        const meta = result._meta || {}
        this.setData({
          reply: structured.reply || '',
          summaryLabel: structured.accountSummary && structured.accountSummary.label ? structured.accountSummary.label : '',
          cards: meta.cards || structured.cards || [],
          actions: meta.actions || structured.actions || [],
        })
      })
    },
  },
  methods: {
    openCard(event) {
      const url = event.currentTarget.dataset.url
      if (!url) return
      this._viewCtx.openDetailPage({ url })
    },
    openAction(event) {
      const url = event.currentTarget.dataset.url
      if (!url) return
      this._viewCtx.openDetailPage({ url })
    },
  },
})
