<template>
  <div>
    <span>📖...</span>
    <gz-report-selector ref="reportSelector"></gz-report-selector>
  </div>
</template>

<script>
//THIS FORM IS USED WHEN CLICKING ON A REPORT URL FROM A NOTIFICATION EMAIL ETC
//it's only ever called from the router directly
export default {
  data() {
    return {};
  },
  async mounted() {
    const vm = this;
    //open report links have url format /viewreport/[objectid]/[reportid]
    //path: "/viewreport/:oid/:rid",

    const objectId = parseInt(vm.$route.params.oid);
    const reportId = parseInt(vm.$route.params.rid);

    if (!objectId || !reportId) {
      throw new Error(
        "Missing report data: oid or rid are not set, unable to render report"
      );
    }

    const reportDataOptions = {
      ReportId: reportId,
      SelectedRowIds: [objectId],
      ClientMeta: window.$gz.api.reportClientMetaData()
    };

    try {
      await vm.$refs.reportSelector.open(reportDataOptions, reportId);
    } catch (ex) {
      vm.rendering = false;
      window.$gz.errorHandler.handleFormError(ex, vm);
    }
  }
};
</script>
