package com.example.kmptpc_compose_sample.demos.foundation

import android.content.ClipData
import android.view.View
import androidx.compose.ui.draganddrop.DragAndDropEvent
import androidx.compose.ui.draganddrop.DragAndDropTransferData
import androidx.compose.ui.draganddrop.toAndroidDragEvent

actual fun createDragAndDropTransferData(item: String): DragAndDropTransferData? {
    return DragAndDropTransferData(
        clipData = ClipData.newPlainText("text/plain", item),
        flags = View.DRAG_FLAG_GLOBAL
    )
}

actual fun extractItemFromEvent(event: DragAndDropEvent): String? {
    return try {
        val dragEvent = event.toAndroidDragEvent()
        val clipData = dragEvent.clipData
        if (clipData != null && clipData.itemCount > 0) {
            clipData.getItemAt(0).text?.toString()
        } else {
            null
        }
    } catch (e: Exception) {
        null
    }
}

