<script setup lang="ts">
import { computed } from 'vue';
import { modules } from '../modules/index';

const props = defineProps<{
  item: any
}>();

const moduleDef = computed(() => modules[props.item.moduleName]);

// Create a render function component on the fly
const RenderedModule = () => {
  if (moduleDef.value && typeof moduleDef.value.render === 'function') {
    return moduleDef.value.render(props.item.params || {});
  }
  return null;
};
</script>

<template>
  <div 
    v-if="moduleDef"
    :style="{ gridColumn: `span ${moduleDef.width} / span ${moduleDef.width}`, gridRow: `span ${moduleDef.height} / span ${moduleDef.height}` }"
  >
    <RenderedModule />
  </div>
  <div 
    v-else 
    class="flex items-center justify-center p-5 rounded-2xl bg-red-500/10 border border-red-500/20 text-red-400 text-sm"
  >
    Unknown Module: {{ item.moduleName }}
  </div>
</template>
