// This file was generated by build-components.mjs
// ANY EDITS WILL BE OVERWRITTEN!

import {
  type DropzoneProps,
  Dropzone as PreactDropzone,
} from '@uppy/components'
import { h as preactH, render as preactRender } from 'preact'
import { shallowEqualObjects } from 'shallow-equal'
import { defineComponent, h, onMounted, ref, watch } from 'vue'
import { useUppyContext } from '../useUppyContext.js'

export default defineComponent<Omit<DropzoneProps, 'ctx'>>({
  name: 'Dropzone',
  setup(props, { attrs }) {
    const containerRef = ref<HTMLElement | null>(null)
    const ctx = useUppyContext()

    function renderDropzone() {
      if (containerRef.value) {
        preactRender(
          preactH(PreactDropzone, {
            ...(attrs as DropzoneProps),
            ctx,
          } satisfies DropzoneProps),
          containerRef.value,
        )
      }
    }

    onMounted(() => {
      renderDropzone()
    })

    watch(ctx, () => {
      renderDropzone()
    })

    watch(
      () => props,
      (current, old) => {
        if (!shallowEqualObjects(current, old)) {
          renderDropzone()
        }
      },
    )

    return () => h('div', { ref: containerRef })
  },
})
