<script setup lang="ts">
import { PropType } from 'vue'
import { User } from './dbUsers'
import { Company } from './dbCompanies'
import DbFormUser from './DbFormUser.vue'
import DbFormContractor from './DbFormContractor.vue'

const props = defineProps({
  docId: { type: String, default: undefined },
  docData: { type: Object as PropType<User | Company>, default: undefined },
})

const emit = defineEmits({
  hide: () => true,
})

function isCompany(data?: Record<string, any>): boolean {
  return !data?.companyId
}
const type: 'user' | 'company' = isCompany(props.docData) ? 'company' : 'user'
</script>

<template>
  <DbFormUser v-if="type === 'user'" :docId="docId" @hide="() => emit('hide')" />
  <DbFormContractor v-else-if="type === 'company'" :docId="docId" @hide="() => emit('hide')" />
</template>
