import { defineComponent, getCurrentInstance, inject, ref, computed, openBlock, createElementBlock, normalizeClass, renderSlot } from 'vue';
import getPrefixCls from '../_util/getPrefixCls';
import { noop } from '../_util/utils';
import { COMPONENT_NAME, LAYOUT_PROVIDE_KEY } from './const';

const prefixCls = getPrefixCls('layout');
const layoutMainProps = {
  embedded: {
    type: Boolean,
    default: false
  }
};
var script = defineComponent({
  name: COMPONENT_NAME.MAIN,
  props: layoutMainProps,
  setup(props) {
    const vm = getCurrentInstance();
    if (!vm.parent || !vm.parent.type || vm.parent.type.name !== COMPONENT_NAME.LAYOUT) {
      console.warn(`[${COMPONENT_NAME.MAIN}] must be a child of ${COMPONENT_NAME.LAYOUT}`);
    }
    const {
      addChild,
      embedded
    } = inject(LAYOUT_PROVIDE_KEY, {
      addChild: noop,
      embedded: ref(false)
    });
    addChild({
      type: COMPONENT_NAME.MAIN
    });
    const classList = computed(() => [`${prefixCls}-main`, (embedded.value || props.embedded) && 'is-embedded'].filter(Boolean));
    return {
      classList
    };
  }
});

function render(_ctx, _cache, $props, $setup, $data, $options) {
  return openBlock(), createElementBlock("main", {
    class: normalizeClass(_ctx.classList)
  }, [renderSlot(_ctx.$slots, "default")], 2 /* CLASS */);
}

script.render = render;
script.__file = "components/layout/main.vue";

export { script as default, layoutMainProps };
