<script setup lang="ts">
import { ref } from "vue";
import { useVModel } from "@vueuse/core";
import { httpGroupList } from "/@/api/components/remoteSelect";
import RemoteSelect from "../remote-select";

const emit = defineEmits(["update:modelValue", "change"]);

const props = defineProps<{
  placeholder?: string;
  modelValue?: string;
  project_name?: string;
  disabled?: boolean;
}>();

const remoteSelectRef = ref<any>(null);

const value = useVModel(props, "modelValue");

function initalData(data) {
  remoteSelectRef.value.initalData(data);
}

defineExpose({
  initalData
});
</script>

<template>
  <RemoteSelect
    v-model="value"
    :api="httpGroupList"
    :placeholder="placeholder"
    :disabled="disabled"
    ref="remoteSelectRef"
    response-label-prop="combination"
    response-val-prop="id"
    request-prop="combination"
    @item-change="val => emit('change', val)"
    @inital="unit => (value = unit)"
  />
</template>
