<script lang="ts" setup>
import { enumPageComponentTemplates } from "@/definitions/enum";
import { Article_Button, Article_Detail_Emagazine, Article_Detail_Default, Article_Detail_Infographics, 
  Default_Breadcrumb, ADS_Default, Comment, Article_Detail_Podcast, Article_Detail_Video
} from "./index";
const _props = defineProps<{
  settings: any;
  component?: any;
}>();

const definedDynamicComponent: Record<string, any> = {
  'BREADCRUM_DEFAULT': Default_Breadcrumb,
  'ARTICLE_DETAIL_DEFAULT': Article_Detail_Default,
  'ARTICLE_DETAIL_INFOGRAPHICS': Article_Detail_Infographics,
  'ARTICLE_DETAIL_EMAGAZINE': Article_Detail_Emagazine,
  'ADS_DEFAULT': ADS_Default,
  'ARTICLE_BUTTON': Article_Button,
  'COMMENT_DEFAULT': Comment,
  PODCAST: Article_Detail_Podcast,
  VIDEO: Article_Detail_Video
};

const getCurrentComponent = computed(() => `${_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 :is="definedDynamicComponent[getCurrentComponent]" v-bind="GET_PROPS()" />
</template>
