<!--
  - Copyright (c) 2022.
  - Author Peter Placzek (tada5hi)
  - For the full copyright and license information,
  - view the LICENSE file that was distributed with this source code.
  -->

<script>
import Qrious from 'qrious';
import {addInvitation} from "@/domains/invitation/api";

export default {
    props: {
        code: String
    },
    data() {
        return {
            generator: undefined,
            busy: false,

            codeBase64: undefined
        }
    },
    created() {
        this.init();
        this.generate();
    },
    watch: {
        code(val, oldVal) {
            if(val === oldVal) return;

            this.generate();
        }
    },
    methods: {
        init() {
            if(process.server) return;

            this.generator = new Qrious({
                size: 250
            });
        },
        generate() {
            if(!this.generator) return;

            this.generator.value = this.code;

            this.codeBase64 = this.generator.toDataURL('image/jpeg');
        }
    },
}
</script>
<template>
    <div>
        <template v-if="codeBase64">
            <img :src="codeBase64" class="img-thumbnail">
        </template>
    </div>
</template>
