<?php
/*
 * AIWK Common Header
 * 위치: /var/www/html/aiwk/aiwk_header.php
 * 사용:
 *   $AIWK_PAGE = array('title'=>'Wallet', 'active_menu'=>'wallet');
 *   require_once __DIR__ . '/../aiwk_header.php';
 *
 * 역할:
 *   - Bootstrap 5.3 CDN 로드
 *   - Tailwind CDN 로드 시 prefix=tw- 강제
 *   - data-bs-theme 기반 light/dark 공통 처리
 *   - 여러 폴더에서 같은 레이아웃 재사용
 */
require_once dirname(__FILE__) . '/aiwk_ui_config.php';

if (!isset($AIWK_PAGE) || !is_array($AIWK_PAGE)) $AIWK_PAGE = array();

$aiwk_title = aiwk_ui_opt('title', $AIWK_PAGE);
$aiwk_theme = aiwk_ui_opt('theme', $AIWK_PAGE);
$aiwk_use_tailwind = aiwk_ui_opt('use_tailwind', $AIWK_PAGE);
$aiwk_fluid = aiwk_ui_opt('fluid', $AIWK_PAGE);
$aiwk_body_class = aiwk_ui_opt('body_class', $AIWK_PAGE);
$aiwk_active_menu = aiwk_ui_opt('active_menu', $AIWK_PAGE);
$aiwk_show_navbar = aiwk_ui_opt('show_navbar', $AIWK_PAGE);
$aiwk_container_class = $aiwk_fluid ? 'container-fluid' : 'container';
?>
<!doctype html>
<html lang="ko" data-bs-theme="<?php echo aiwk_h($aiwk_theme); ?>">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php echo aiwk_h($aiwk_title); ?></title>
<link rel="stylesheet" href="<?php echo aiwk_h(AIWK_BS53_CSS); ?>">
<?php if ($aiwk_use_tailwind) { ?>
<script>
/* Tailwind CDN MVP 설정. Bootstrap과 충돌 방지를 위해 반드시 tw- prefix 사용. */
tailwind = window.tailwind || {};
tailwind.config = {
  prefix: 'tw-',
  corePlugins: {
    preflight: false
  }
};
</script>
<script src="<?php echo aiwk_h(AIWK_TAILWIND_CDN); ?>"></script>
<?php } ?>
<link rel="stylesheet" href="<?php echo aiwk_h(aiwk_url('/assets/aiwk/aiwk_common.css')); ?>">
</head>
<body class="<?php echo aiwk_h($aiwk_body_class); ?>">
<?php if ($aiwk_show_navbar) { ?>
<nav class="navbar navbar-expand-lg border-bottom bg-body sticky-top aiwk-navbar">
  <div class="container-fluid">
    <a class="navbar-brand fw-bold" href="<?php echo aiwk_h(aiwk_url('/')); ?>">AIWK</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#aiwkMainNav" aria-controls="aiwkMainNav" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="aiwkMainNav">
      <ul class="navbar-nav me-auto mb-2 mb-lg-0">
        <li class="nav-item"><a class="nav-link <?php echo $aiwk_active_menu === 'wallet' ? 'active' : ''; ?>" href="<?php echo aiwk_h(aiwk_url('/wallet/wallet_demo.php')); ?>">Wallet</a></li>
        <li class="nav-item"><a class="nav-link <?php echo $aiwk_active_menu === 'sample' ? 'active' : ''; ?>" href="<?php echo aiwk_h(aiwk_url('/sample/wallet_use_sample.php')); ?>">Sample</a></li>
      </ul>
      <div class="d-flex gap-2 align-items-center">
        <button type="button" class="btn btn-sm btn-outline-secondary" onclick="aiwkSetTheme('light')">Light</button>
        <button type="button" class="btn btn-sm btn-outline-secondary" onclick="aiwkSetTheme('dark')">Dark</button>
      </div>
    </div>
  </div>
</nav>
<?php } ?>
<main class="<?php echo aiwk_h($aiwk_container_class); ?> py-4 aiwk-main">
