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

import {
  type FilesGridProps,
  FilesGrid as PreactFilesGrid,
} 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<FilesGridProps, 'ctx'>>({
  name: 'FilesGrid',
  setup(props, { attrs }) {
    const containerRef = ref<HTMLElement | null>(null)
    const ctx = useUppyContext()

    function renderFilesGrid() {
      if (containerRef.value) {
        preactRender(
          preactH(PreactFilesGrid, {
            ...(attrs as FilesGridProps),
            ctx,
          } satisfies FilesGridProps),
          containerRef.value,
        )
      }
    }

    onMounted(() => {
      renderFilesGrid()
    })

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

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

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