<template>
  <div class="d-flex flex-column align-center">
    <h2 class="ma-4">{{ $t('cmf_structure_licence')}}</h2>
    <a
      href="https://www.cmf-musique.org/services/tarifs-preferentiels/"
      target="_blank"
    >
      {{ $t('cmf_licence_details_url')}}
    </a>

    <v-form
      ref="form"
      lazy-validation
    >

      <v-btn class="ma-12" @click="submit">{{ $t('generate') }}</v-btn>

    </v-form>
  </div>
</template>

<script lang="ts">
import {defineComponent, useContext} from "@nuxtjs/composition-api";
import {HTTP_METHOD, QUERY_TYPE} from "~/types/enums";
import DataPersister from "~/services/data/dataPersister";
import {DataPersisterArgs} from "~/types/interfaces";

export default defineComponent({
  name: 'OrganizationCmfLicence',
  setup() {
    const submit = async () => {
      const response = await DataPersister.request(
        '/api/export/cmf-licence/organization',
        HTTP_METHOD.POST,
        { type: QUERY_TYPE.DEFAULT, data: { format: 'pdf', async: true } } as DataPersisterArgs
      )
      console.debug(response)

      const eventSource = new EventSource("https://local.mercure.opentalent.fr/.well-known/mercure/ui/files/602066");
      eventSource.onmessage = event => {
        // Will be called every time an update is published by the server
        console.log(JSON.parse(event.data));
      }
    }

    return {
      submit
    }
  }
})
</script>
