import { defineComponent, createVNode, ref, provide, computed } from 'vue';
import useConfigInject from '../../config-provider/src/hooks/useConfigInject.mjs';
import useStyle from '../style/index.mjs';
import { layoutProps } from './props.mjs';
import { SiderHookProviderKey } from './injectionKey.mjs';

function generator({
  suffixCls,
  tagName,
  name
}) {
  return (BasicComponent) => {
    const Adapter = /* @__PURE__ */ defineComponent({
      compatConfig: {
        MODE: 3
      },
      name,
      props: layoutProps(),
      setup(props, {
        slots
      }) {
        const {
          prefixCls
        } = useConfigInject(suffixCls, props);
        return () => {
          const basicComponentProps = {
            ...props,
            prefixCls: prefixCls.value,
            tagName
          };
          return createVNode(BasicComponent, basicComponentProps, slots);
        };
      }
    });
    return Adapter;
  };
}
const Basic = /* @__PURE__ */ defineComponent({
  compatConfig: {
    MODE: 3
  },
  props: layoutProps(),
  setup(props, {
    slots
  }) {
    return () => createVNode(props.tagName, {
      class: props.prefixCls
    }, slots);
  }
});
const BasicLayout = /* @__PURE__ */ defineComponent({
  compatConfig: {
    MODE: 3
  },
  inheritAttrs: false,
  props: layoutProps(),
  setup(props, {
    slots,
    attrs
  }) {
    const {
      prefixCls,
      direction
    } = useConfigInject("", props);
    const [wrapSSR, hashId] = useStyle(prefixCls);
    const siders = ref([]);
    const siderHookProvider = {
      addSider: (id) => {
        siders.value = [...siders.value, id];
      },
      removeSider: (id) => {
        siders.value = siders.value.filter((currentId) => currentId !== id);
      }
    };
    provide(SiderHookProviderKey, siderHookProvider);
    const divCls = computed(() => {
      const {
        hasSider
      } = props;
      return {
        [hashId.value]: true,
        [`${props.prefixCls}`]: true,
        [`${props.prefixCls}-has-sider`]: typeof hasSider === "boolean" ? hasSider : siders.value.length > 0,
        [`${props.prefixCls}-rtl`]: direction.value === "rtl"
      };
    });
    return () => {
      const {
        tagName
      } = props;
      return wrapSSR(createVNode(tagName, {
        ...attrs,
        class: [divCls.value, attrs.class]
      }, slots));
    };
  }
});
const Layout = generator({
  suffixCls: "layout",
  tagName: "section",
  name: "ALayout"
})(BasicLayout);
const Header = generator({
  suffixCls: "layout-header",
  tagName: "header",
  name: "ALayoutHeader"
})(Basic);
const Footer = generator({
  suffixCls: "layout-footer",
  tagName: "footer",
  name: "ALayoutFooter"
})(Basic);
const Content = generator({
  suffixCls: "layout-content",
  tagName: "main",
  name: "ALayoutContent"
})(Basic);

export { Content, Footer, Header, Layout };
//# sourceMappingURL=Layout.mjs.map
