<script setup lang="ts">
import { ref } from 'vue'
defineProps<{ title: string; subtitle?: string; status?: string; asOf?: string; version?: string; asideWidth?: string }>()
const showHelp = ref(false)
</script>
<template>
  <section class="ks-page" :style="{ '--ks-aside-width': asideWidth ?? '22rem' }">
    <header class="ks-page__header">
      <div class="ks-page__title-group">
        <nav class="ks-page__breadcrumb" aria-label="Breadcrumb">K-ArtSell &gt; Shadow Run Jobs</nav>
        <h1 class="ks-page__title">{{ title }}</h1>
      </div>
      <div class="ks-page__header-utilities">
        <button v-if="subtitle" class="ks-help-btn" :class="{ active: showHelp }" title="도움말 보기/닫기" aria-label="도움말 보기" @click="showHelp = !showHelp">
          ℹ️ 도움말
        </button>
        <button type="button" class="ks-ai-btn" title="AI 업무 제안" aria-label="AI 제안">
          🤖 AI 제안
        </button>
      </div>
    </header>
    <div v-if="subtitle && showHelp" class="ks-page__subtitle-box">
      <p class="ks-page__subtitle">{{ subtitle }}</p>
    </div>
    <!-- Dedicated KBX Command Bar Row (§3, §5) -->
    <div v-if="$slots.commandBar || $slots.actions" class="ks-page__command-bar" role="toolbar" aria-label="화면 주요 명령어">
      <div class="ks-page__command-bar-group">
        <slot name="commandBar" />
        <slot name="actions" />
      </div>
    </div>
    <div v-if="$slots.summary" class="ks-page__summary"><slot name="summary" /></div>
    <div v-if="$slots.filters" class="ks-page__filters"><slot name="filters" /></div>
    <div class="ks-page__workspace" :class="{ 'has-aside': $slots.aside }">
      <div class="ks-page__content"><slot /></div>
      <aside v-if="$slots.aside" class="ks-page__aside"><slot name="aside" /></aside>
    </div>
    <footer v-if="$slots.footer" class="ks-page__footer"><slot name="footer" /></footer>
  </section>
</template>
<style scoped>
.ks-page { width: 100%; max-width: var(--ks-content-max); margin: 0 auto; height: 100%; flex: 1; display: flex; flex-direction: column; gap: var(--ks-space-2); }
.ks-page__header { display: flex; align-items: center; justify-content: space-between; gap: var(--ks-space-4); flex-shrink: 0; min-height: 32px; border-bottom: 1px solid var(--ks-color-neutral-200); padding-bottom: var(--ks-space-2); }
.ks-page__title-group { display: flex; flex-direction: column; gap: 2px; }
.ks-page__breadcrumb { font-size: 11px; color: var(--ks-color-text-muted); line-height: 14px; }
.ks-page__title { margin: 0; font-size: var(--ks-font-page); line-height: var(--ks-line-page); font-weight: 700; color: var(--ks-color-text); }
.ks-page__header-utilities { display: flex; align-items: center; gap: var(--ks-space-2); flex-shrink: 0; }
.ks-page__subtitle-box { margin: 0; }
.ks-page__subtitle { margin: 0; color: var(--ks-color-text-muted); font-size: var(--ks-font-body); padding: var(--ks-space-2); background: var(--ks-color-canvas); border-radius: var(--ks-radius-sm); border: 1px solid var(--ks-color-border); }
.ks-help-btn, .ks-ai-btn { 
  border: 1px solid var(--ks-color-action); 
  background: var(--ks-color-surface); 
  border-radius: var(--ks-radius-sm); 
  padding: 2px 8px; 
  font-size: 11px; 
  font-weight: 600;
  color: var(--ks-color-action); 
  cursor: pointer; 
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s ease; 
}
.ks-help-btn:hover, .ks-help-btn.active, .ks-ai-btn:hover { 
  background: var(--ks-color-action); 
  color: #ffffff; 
  border-color: var(--ks-color-action); 
  box-shadow: 0 1px 3px rgba(37, 99, 235, 0.25);
}
.ks-page__command-bar { 
  display: flex; 
  align-items: center; 
  justify-content: flex-start;
  padding: 4px 8px; 
  background: var(--ks-color-surface); 
  border: 1px solid var(--ks-color-border); 
  border-radius: var(--ks-radius-sm); 
  flex-shrink: 0; 
  min-height: 34px;
  box-sizing: border-border-box;
}
.ks-page__command-bar-group { display: flex; align-items: center; gap: var(--ks-space-2); flex-wrap: wrap; }
.ks-page__actions { display: flex; align-items: center; gap: var(--ks-space-2); flex-shrink: 0; }
.ks-page__summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: var(--ks-space-3); flex-shrink: 0; }
.ks-page__filters {
  display: flex;
  align-items: center;
  gap: var(--ks-space-3);
  padding: var(--ks-space-2) var(--ks-space-3);
  flex-shrink: 0;
  min-height: 52px;
  background: var(--ks-color-surface);
  border: 1px solid var(--ks-color-border);
  border-radius: var(--ks-radius-sm);
}
.ks-page__filters input,
.ks-page__filters select {
  height: 34px;
  padding: 0 0.75rem;
  border: 1px solid var(--ks-color-border);
  border-radius: 4px;
  background-color: var(--ks-color-surface);
  color: var(--ks-color-text);
  font-size: 13px;
  line-height: 34px;
  box-sizing: border-box;
  font-family: inherit;
}
.ks-page__workspace { min-width: 0; flex: 1; display: grid; min-height: 0; gap: var(--ks-space-4); }
.ks-page__workspace.has-aside { grid-template-columns: minmax(0, 1fr) var(--ks-aside-width); }
.ks-page__content, .ks-page__aside { min-width: 0; min-height: 0; height: 100%; display: flex; flex-direction: column; }
.ks-page__footer { position: sticky; bottom: 0; z-index: 2; display: flex; justify-content: flex-end; gap: var(--ks-space-2); padding: var(--ks-space-3); border: 1px solid var(--ks-color-neutral-200); background: rgb(255 255 255 / 96%); }
@media (max-width: 1100px) { .ks-page__workspace.has-aside { grid-template-columns: 1fr; } }
</style>
