// AUTO-INJECTED DRAG LOGIC
const __autoDragElement = ref(null)
const __autoDropInfo = ref({
    targetId: null,
    direction: null
})

const __autoDragStart = (e, id) => {
    __autoDragElement.value = id
    e.dataTransfer.effectAllowed = 'move'
}

const __autoDragOver = (e, targetId) => {
    e.preventDefault()
    const rect = e.currentTarget.getBoundingClientRect()
    __autoDropInfo.value = {
        targetId,
        direction: e.clientX - rect.left < rect.width / 2 ? 'left' : 'right'
    }
}

const __autoDragLeave = () => {
    __autoDropInfo.value = { targetId: null, direction: null }
}

const __autoDragDrop = (e, targetId) => {
    e.preventDefault()
    if (!__autoDragElement.value || !targetId) return

    // 构造请求数据
    const data = `${__autoDragElement.value}-${targetId}-${__autoDropInfo.value.direction}`;

    // 发送 POST 请求
    fetch('http://localhost:8080/test/changecode', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded', // 或 'text/plain' 根据后端需求
        },
        body: data
    })
        .catch(error => {
            console.error('请求失败:', error);
        });

    __autoDragElement.value = null
    __autoDropInfo.value = { targetId: null, direction: null }
}