<script lang="ts" setup>
import { enumPageComponentTemplate, enumPageComponentKey, enumPageComponentLayouts } from "@/definitions/enum";
import { Article_Card_Default, Article_Card_Audio, Article_Card_Video, Article_Card_Video_Hightlight,Article_Card_Miss_Hightlight } from "./index";

const _props = defineProps<{
  settings: any;
  component?: any;
  content?: any;
}>();

const definedDynamicComponent: Record<string, any> = {
  [enumPageComponentLayouts[enumPageComponentTemplate[enumPageComponentKey.ARTICLE]["ARTICLE_CARD"]]["CARD_DEFAULT"]]: Article_Card_Default,
  [enumPageComponentLayouts[enumPageComponentTemplate[enumPageComponentKey.ARTICLE]["ARTICLE_CARD"]]["CARD_AUDIO"]]: Article_Card_Audio,
  [enumPageComponentLayouts[enumPageComponentTemplate[enumPageComponentKey.ARTICLE]["ARTICLE_CARD"]]["CARD_VIDEO"]]: Article_Card_Video,
  [enumPageComponentLayouts[enumPageComponentTemplate[enumPageComponentKey.ARTICLE]["ARTICLE_CARD"]]["CARD_VIDEO_HIGHLIGHT"]]: Article_Card_Video_Hightlight,
  [enumPageComponentLayouts[enumPageComponentTemplate[enumPageComponentKey.ARTICLE]["ARTICLE_CARD"]]["CARD_MISS_HIGHLIGHT"]]: Article_Card_Miss_Hightlight,
};

const getCurrentComponent = computed(() => {
  return _props.settings.layout;
});

const GET_PROPS = computed(() => {
  return () => {
    let props: any = {};
    if (_props.settings) {
      for (const [key, value] of Object.entries(_props.settings)) {
        props = {
          ...props,
          [key]: value,
        };
      }
      return props;
    }
  };
});
</script>

<template>
  <component 
    v-if="definedDynamicComponent[getCurrentComponent]"
    :is="definedDynamicComponent[getCurrentComponent]" 
    v-bind="{ ...GET_PROPS(), component: _props.component, settings: _props.settings }" 
  />
</template>
