<script setup>
import { computed } from "vue";
import draggable from "vuedraggable/src/vuedraggable.js";

const props = defineProps({
  modelValue: {
    type: [Array, Object],
    default: () => [],
  },
});

const emit = defineEmits([
  "update:modelValue",
  "start",
  "end",
  "add",
  "remove",
  "change",
]);

const proxyModel = computed({
  get: () => props.modelValue,
  set: (value) => emit("update:modelValue", value),
});
</script>

<template>
  <draggable
    v-model="proxyModel"
    v-bind="$attrs"
    @start="emit('start', $event)"
    @end="emit('end', $event)"
    @add="emit('add', $event)"
    @remove="emit('remove', $event)"
    @change="emit('change', $event)"
  >
    <template v-for="(_, name) in $slots" :key="name" #[name]="slotProps">
      <slot :name="name" v-bind="slotProps || {}" />
    </template>
  </draggable>
</template>
