<script lang="ts" setup>
import { enumPageComponentTemplates } from "@/definitions/enum";
import { Dynamic_Section, Dynamic_Category, Dynamic_Collection, CollectionPaging, Dynamic_Other, Dynamic_Advertising, Dynamic_Article } from "./index";
const _props = defineProps<{
  settings: any;
  component?: any;
}>();

const definedDynamicComponent: Record<string, any> = {
  [enumPageComponentTemplates.ARTICLE]: Dynamic_Article,
  [enumPageComponentTemplates.CATEGORY]: Dynamic_Category,
  [enumPageComponentTemplates.COLLECTION]: Dynamic_Collection,
  [enumPageComponentTemplates.SECTION]: Dynamic_Section,
  [enumPageComponentTemplates.OTHER]: Dynamic_Other,
  [enumPageComponentTemplates.ADVERTISING]: Dynamic_Advertising
};

const getCurrentComponent = computed(() => `${_props.settings.template}`);


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

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