Component({
  data: {
    reply: '',
    card: null,
  },
  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 || {}
        const cards = meta.cards || structured.cards || []
        this.setData({
          reply: structured.reply || '',
          card: cards[0] || null,
        })
      })
    },
  },
  methods: {
    onOpenPage(event) {
      const url = event.currentTarget.dataset.url
      if (!url) return
      this._viewCtx.openDetailPage({ url })
    },
  },
})
