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

import {
  Thumbnail as PreactThumbnail,
  type ThumbnailProps,
} from '@uppy/components'
import { h as preactH, render as preactRender } from '@uppy/core/utils/preact'
import { defineComponent, h, onMounted, ref, watch } from 'vue'
import { useUppyContext } from '../useUppyContext.js'

export default defineComponent({
  name: 'Thumbnail',
  props: ['file', 'width', 'height', 'images'],
  setup(props) {
    const containerRef = ref<HTMLElement | null>(null)
    const ctx = useUppyContext()

    function renderThumbnail() {
      if (containerRef.value) {
        preactRender(
          preactH(PreactThumbnail, {
            ...props,
            ctx,
          } satisfies ThumbnailProps),
          containerRef.value,
        )
      }
    }

    onMounted(() => {
      renderThumbnail()
    })

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

    watch(
      () => props,
      () => {
        renderThumbnail()
      },
      { deep: true },
    )

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