<template>
    <teleport to=".scene-designer .tasks" v-if="active">
        <g @mousedown="$emit('target', {target:vd, attrs:['x1', 'y1'], delta: true})" :class="{task: true, selected}" 
            v-show="showInView">
            <line :x1="vd.x1" :y1="vd.y1" :x2="parent.vd.x1" :y2="parent.vd.y1"></line>
            <svg-icon :src="`/asset/thumb/${modelValue.intro || 0}.webp`" :x="vd.x1" :y="vd.y1" :size="22"></svg-icon>
            <text :x="vd.x1" :y="vd.y1" dy="44">{{ modelValue.title }}</text>
            <image v-if="modelValue.intro" href="/static/svg/play-circle.svg" width="20" class="cursor-pointer"
                :x="vd.x1 + 25 - 10" :y="vd.y1 + 25 - 10" @click="$emit('preview', modelValue.intro)">
            </image>
        </g>
    </teleport>
    <v-card v-if="selected" :title="modelValue.title" class="mx-2" variant="text">
        <asset-selector @select="assignTaskIntro" :type="['Video']">
            <template v-slot:activator="props">
                <v-btn v-bind="props" prepend-icon="mdi-panorama-outline" color="success" block>Choose task description</v-btn>
            </template>
        </asset-selector>
        
        <v-form class="py-4">
            <v-text-field density="compact" :label="l.name" v-model="modelValue.title"></v-text-field>
            <v-textarea :label="l.description" v-model="modelValue.description"></v-textarea>
            <v-text-field density="compact" :label="l.id" v-model="modelValue.id"></v-text-field>
        </v-form>
    </v-card>
</template>

<script>
import SvgIcon from './SvgIcon.vue';
import Utils from '#/app/Utils';

export default {
  emits:['target', 'preview'],
  components: { SvgIcon },
    props:{
        //context: Object,
        modelValue: Object,
        vd: Object,
        selected: Boolean, 
        cid:String, 
        visible: Boolean,
        parent: Object
    },
    data(){
        return {
            active: false
        }
    },
    mounted(){
        this.active = true;
    },
    computed:{
        showInView(){
            this.vd.__showInView = this.visible && this.parent.visible && this.parent.__parent.visible;
            return this.vd.__showInView;
        }
    },
    steps: [['x1', 'y1']],
    name: 'task',
    modifiers: ['x1', 'y1'],
    methods:{
        intersect(v){
            return Utils.intersectPointRect([this.vd.x1, this.vd.y1], v);
        },
        assignTaskIntro(e){
            this.modelValue.intro = e.id;
            if (this.modelValue.id == this.modelValue.title){
                this.modelValue.title = e.name
            }
        }
    }
}
</script>