<script setup>
import {computed} from 'vue'
import LineMarker from './LineMarker.vue'
const props=defineProps({
    itemData:{
        type:Object,
        default:{}
    }
})

const svgWidth=computed(()=>{
    const width = Math.abs(props.itemData.start[0] - props.itemData.end[0])
    return width < 25 ? 25 : width
}) 

const svgHeight=computed(()=>{
    const height = Math.abs(props.itemData.start[1] - props.itemData.end[1])
    return height < 25 ? 25 : height
}) 


</script>





<template>
    <div 
        class="line-shape-box"
        :style="{
            top: itemData.percentageTop*100 + '%',
            left: itemData.percentageLeft*100 + '%'
        }"
    >
        <svg 
            overflow="visible" 
            :width="svgWidth"
            :height="svgHeight"
        >
            <defs>
                <LineMarker
                    v-if="itemData.points[0]"
                    :id="itemData.id"
                    position="start"
                    :type="itemData.points[0]"
                    :color="itemData.color"
                    :baseSize="itemData.strokeWidth"
                />
                <LineMarker
                    v-if="itemData.points[1]"
                    :id="itemData.id"
                    position="end"
                    :type="itemData.points[1]"
                    :color="itemData.color"
                    :baseSize="itemData.strokeWidth"
                />
            </defs>
            <path   
                :d="`M ${itemData.start[0]}, ${itemData.start[1]} L ${itemData.end[0]}, ${itemData.end[1]}`" 
                fill="none"
                :stroke="itemData.color"
                :stroke-width="itemData.strokeWidth" 
                :stroke-dasharray="itemData.style === 'dashed' ? '10 6' : '0 0'"
                :marker-start="itemData.points[0] ? `url(#${itemData.id}-${itemData.points[0]}-start)` : ''"
                :marker-end="itemData.points[1] ? `url(#${itemData.id}-${itemData.points[1]}-end)` : ''" 
            ></path>
        </svg>
    </div>
</template>

<style lang="scss" scoped>
.line-shape-box{
    position: absolute;
    pointer-events: none;
    transform-origin: 0 0;
    svg{
        overflow:visible;
        transform-origin: 0 0;
    }
}
</style>