<script lang="ts" setup>
import { Home, Article } from "./index";
import type { Page } from "@/models/cms";
import { enumPageKey } from "@/definitions/enum";

const _props = defineProps<{
  settings: any;
  page: Page;
}>();

const definedDynamicPage: Record<string, any> = {
  [enumPageKey.HOME]: Home,
  [enumPageKey.ARTICLE]: Article,
};

const getCurrentTemplate = computed(() => {
  return _props.page?.taxonomy || "";
});

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 
        class="overflow-x-hidden"
        v-if="definedDynamicPage[getCurrentTemplate]" 
        :is="definedDynamicPage[getCurrentTemplate]" 
        v-bind="{...(GET_PROPS()), settings: _props.settings}"
    >
        <slot />
    </component>
</template>