<script lang="ts" setup>
import { enumPageComponentTemplate, enumPageComponentKey, enumPageComponentLayouts } from "@/definitions/enum";
import { Advertisings } from "./index";

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

const definedDynamicComponent: Record<string, any> = {
  [enumPageComponentTemplate[enumPageComponentKey.ADVERTISING]["ADVERTISING"]]: Advertisings,
};

const getCurrentComponent = computed(() => `${_props.settings.template}`);
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;
    }
  };
});
// console.log(getCurrentComponent.value, 'quảng caosd ád')
</script>

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