<template>
  <div class="file-upload">
    <template v-if="document">
      <document-block
        :value="{ url: document }"
        show-trash-icon
        @trash="changeDocumentUrl('')"
      />
    </template>
    <template v-else>
      <simple-file-upload
        :with-text="withText"
        :value="document"
        @link-change-url="changeDocumentUrl($event)"
      />
    </template>
  </div>
</template>

<script>
import { defineAsyncComponent } from 'vue';
const SimpleFileUpload = defineAsyncComponent(() => import('@/components/ui/file-upload/SimpleFileUpload.vue'));
const DocumentBlock = defineAsyncComponent(() =>
  import(/* webpackChunkName: "content-components" */ '@/components/content-blocks/DocumentBlock.vue')
);

export default {
  props: {
    document: {
      type: String,
      default: '',
    },
    withText: {
      type: Boolean,
      default: false,
    },
  },
  emits: ['changeDocumentUrl'],
  components: { SimpleFileUpload, DocumentBlock },
  methods: {
    changeDocumentUrl(val) {
      this.$emit('change-document-url', val);
    },
  },
};
</script>

<style scoped lang="scss">
@import 'styles/helpers';
</style>
