<script setup>

// Use this in any component after injecting from the Index.vue provided Dialog
//
// const subscriptionRequiredDialog = inject('subscriptionRequiredDialog');
// subscriptionRequiredDialog.value.open();

import { ref, useTemplateRef } from 'vue';
import { Dialog, Button } from 'pankow';
import DashboardModel from '../models/DashboardModel.js';

const dashboardModel = DashboardModel.create();

const dialog = useTemplateRef('dialog');
const consoleServerOrigin = ref('https://console.cloudron.io');

defineExpose({
  async open() {
    const [error, result] = await dashboardModel.config();
    if (error) return console.error(error);

    consoleServerOrigin.value = result.consoleServerOrigin;

    dialog.value.open();
  }
});

</script>

<template>
  <Dialog ref="dialog" title="Subscription required" :show-x="true">
    <p>To use this feature a Cloudron subscription needs to be set up</p>
    <Button :href="`${consoleServerOrigin}/#/claim/${cloudronId}`" target="_blank">Set up</Button>
  </Dialog>
</template>
