<script setup>
import { computed, useSlots } from "vue";
import { useNamespace } from "@yh-ui/hooks";
import { useComponentTheme } from "@yh-ui/theme";
defineOptions({ name: "YhContainer" });
const props = defineProps({
  direction: { type: String, required: false },
  themeOverrides: { type: null, required: false }
});
const slots = useSlots();
const ns = useNamespace("container");
const { themeStyle } = useComponentTheme(
  "container",
  computed(() => props.themeOverrides)
);
const isVertical = computed(() => {
  if (props.direction) return props.direction === "vertical";
  const defaultSlot = slots.default?.();
  if (!defaultSlot) return false;
  return defaultSlot.some((vnode) => {
    const tag = vnode.type?.name;
    return tag === "YhHeader" || tag === "YhFooter";
  });
});
</script>

<template>
  <section :class="[ns.b(), ns.is('vertical', isVertical)]" :style="themeStyle">
    <slot />
  </section>
</template>

<style>
@charset "UTF-8";
/**
 * YH-UI Sass Variables
 * 原具体的 CSS 变量输出规则 (:root, html.dark 等) 已移至 root.scss，以防止各组件样式编译时产生重复的全局变量 CSS 冗余。
 */
.yh-container {
  display: flex;
  flex-direction: row;
  flex: 1;
  flex-basis: auto;
  box-sizing: border-box;
  width: 100%;
  min-height: 0;
}
.yh-container.is-vertical {
  flex-direction: column;
}

.yh-header {
  box-sizing: border-box;
  flex-shrink: 0;
  padding: var(--yh-header-padding, 0 20px);
  display: flex;
  align-items: center;
  background-color: var(--yh-header-bg-color, transparent);
  border-bottom: var(--yh-header-border-bottom, none);
}

.yh-aside {
  box-sizing: border-box;
  flex-shrink: 0;
  overflow: auto;
  background-color: var(--yh-aside-bg-color, transparent);
  border-right: var(--yh-aside-border-right, none);
}

.yh-main {
  display: block;
  flex: 1;
  flex-basis: auto;
  overflow: auto;
  box-sizing: border-box;
  padding: var(--yh-main-padding, 20px);
  background-color: var(--yh-main-bg-color, transparent);
}

.yh-footer {
  box-sizing: border-box;
  flex-shrink: 0;
  padding: var(--yh-footer-padding, 0 20px);
  display: flex;
  align-items: center;
  background-color: var(--yh-footer-bg-color, transparent);
  border-top: var(--yh-footer-border-top, none);
}
</style>
