<template>
     <v-card-actions class="py-0">
        <v-btn
            color="orange"
            text
            small
            class="text-no-transform"
            @click="OnOpenCourse"
        >
            {{ __('Deschide') }}
        </v-btn>
    </v-card-actions>
</template>

<script>
    import Openknolyxcourse from './Requests/Openknolyxcourse.request';

    export default {
        props: {
            curs: {required: true},
        },

        data: () => ({
            openCourseKnolyxRequest: null,
        }),

        methods: {

            OnOpenCourse(e) {
                let method = 'OnOpenCourse' + _.capitalize(this.curs.type);
                  this[method]();
            },

            OnOpenCourseLink() {
                window.open(this.curs.url, '_blank');
            },

            OnOpenCourseFisier() {
                this.$emit('preview', this.curs);
            },

            OnOpenCourseYoutube() {
                this.$emit('preview', this.curs);
            },

            OnOpenCourseKnolyx() {
                this.openCourseKnolyxRequest
                    .ResetData()
                    .SetData({
                        curs_id: this.curs.id,
                        url: this.curs.my_url,
                        user_id: this.$user.id,
                    })
                    .Request([                        
                        response => {
                            window.open(this.curs.my_url, '_blank');
                        }
                    ])
            }
        },

        created() {
            this.openCourseKnolyxRequest = new Openknolyxcourse(null);
        },

        name: 'CursCardActions',
    }
</script>