<script setup>
import StandardEntityModal from "~/components/StandardEntityModal.vue";

const props = defineProps({
  type: {
    type: String,
    required: true
  },
  id: {
    type: String,
  },
  createQuery: {
    type: Object,
  },
  buttonShow: {
    type: Boolean,
    default: true
  },
  buttonEdit: {
    type: Boolean,
    default: true
  },
  buttonCreate: {
    type: Boolean,
    default: true
  }
})

const emit = defineEmits(["returnData"])


const modal = useModal()



</script>

<template>
  <UButton
      variant="outline"
      class="w-25 ml-2"
      v-if="props.id && props.buttonShow"
      icon="i-heroicons-eye"
      @click="modal.open(StandardEntityModal, {
        id: props.id,
        type: props.type,
        mode: 'show',
      })"
  />
  <UButton
      variant="outline"
      class="w-25 ml-2"
      v-if="props.id && props.buttonEdit"
      icon="i-heroicons-pencil-solid"
      @click="modal.open(StandardEntityModal, {
        id: props.id,
        type: props.type,
        mode: 'edit',
        onReturnData(data) {
          emit('returnData', data)
        }
      })"
  />
  <UButton
      variant="outline"
      class="w-25 ml-2"
      v-if="!props.id && props.buttonCreate"
      icon="i-heroicons-plus"
      @click="modal.open(StandardEntityModal, {
        type: props.type,
        mode: 'create',
        createQuery: props.createQuery,
        onReturnData(data) {
          emit('returnData', data)
        }
      })"
  />
</template>

<style scoped>

</style>