<template>

<Dialog @close="() => $emit('close')">
<h3>Are you sure you want to unsubscribe?</h3>
<button @click="() => $emit('close')">Cancel</button>
<button @click="unsubscribe">Confirm</button>
</Dialog>

</template>

<script setup>
import Dialog from "./dialog.vue"

const emit = defineEmits(['close', 'cancelSub'])
const props = defineProps(['token'])

function unsubscribe() {
  fetch(`/api/user/unsubscribe`,
	    {method: 'GET',
    		headers: {
        	"Accept": "application/json",
        	"Authorization": `Bearer ${props.token}`,
    		},
        }).then(resp => {
          if (resp.ok) emit('cancelSub')
        })
}
</script>
