<?php
declare(strict_types=1);

require_once __DIR__ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'app.php';
require_once __DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'fate_public_session.php';
require_once __DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'fate_public_member_auth.php';
require_once __DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'fate_public_urls.php';
require_once __DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'fate_store_geocode.php';
require_once __DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'google_place_opening_hours.php';
require_once __DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'fate_member_stores.php';
require_once __DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'fate_member_store_submit.php';
require_once __DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'fate_store_listing.php';

fate_public_session_start();
fate_public_member_require_login(fate_public_login_next_from_request('member_add_store.php'));

$member = fate_public_member_current();
$memberId = (int)$member['id'];

$pdo = null;
$dbErr = null;
try {
    require_once __DIR__ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'pdo.php';
    if (isset($GLOBALS['pdo']) && $GLOBALS['pdo'] instanceof PDO) {
        $pdo = $GLOBALS['pdo'];
    }
} catch (Throwable $e) {
    $dbErr = $e->getMessage();
}

if ($pdo instanceof PDO) {
    fate_public_member_require_interact($pdo, fate_public_login_next_from_request('member_add_store.php'));
}

$error = null;
$success = null;
$newStoreId = 0;

$defaults = [
    'store_name' => '',
    'city_name' => '',
    'district_name' => '',
    'zip_code' => '',
    'street_address' => '',
    'place_formatted_address' => '',
    'google_map_location' => '',
    'phone' => '',
    'mobile' => '',
    'line' => '',
    'wechat' => '',
    'website' => '',
    'facebook' => '',
    'description' => '',
    'spa_type' => '',
    'business_type' => '',
    'payment_method' => '',
    'parking' => '',
    'basic_charge' => '',
    'business_hours_start' => '',
    'business_hours_end' => '',
    'service_target' => 'both_customers',
    'appointment_required' => '非預約制',
    'multi_hours_json' => '{}',
];

if ($_SERVER['REQUEST_METHOD'] === 'POST' && $dbErr === null) {
    $csrf = isset($_POST['csrf']) && is_string($_POST['csrf']) ? $_POST['csrf'] : '';
    if (!fate_public_member_csrf_check($csrf)) {
        $error = '工作階段逾期，請重新整理後再試。';
    } else {
        foreach (array_keys($defaults) as $k) {
            if (isset($_POST[$k]) && is_string($_POST[$k])) {
                $defaults[$k] = trim($_POST[$k]);
            }
        }
        $defaults['appointment_required'] = !empty($_POST['appointment_required']) ? '預約' : '非預約制';

        $multiHoursRaw = isset($_POST['multi_hours_json']) && is_string($_POST['multi_hours_json'])
            ? trim($_POST['multi_hours_json'])
            : '{}';
        $multiHours = fate_parse_multi_hours_json($multiHoursRaw);
        $defaults['multi_hours_json'] = json_encode($multiHours, JSON_UNESCAPED_UNICODE);

        $storeName = $defaults['store_name'];
        $city = $defaults['city_name'];
        $district = $defaults['district_name'];
        $street = $defaults['street_address'];

        if ($storeName === '' || $city === '' || $district === '' || $street === '') {
            $error = '請填寫店名、城市、地區與街道地址。';
        } elseif (!isset($_FILES['cover_photo_path']) || (int) ($_FILES['cover_photo_path']['error'] ?? UPLOAD_ERR_NO_FILE) !== UPLOAD_ERR_OK) {
            $error = '請上傳封面照片。';
        } else {
            try {
                $geoQuery = fate_build_geocode_query($city, $district, $street);
                $manualGml = fate_parse_manual_gps($defaults['google_map_location']);
                if ($manualGml !== null) {
                    $geo = [
                        'ok' => true,
                        'google_map_location' => $manualGml,
                        'display_name' => $geoQuery,
                    ];
                } else {
                    $geo = fate_store_geocode_address($city, $district, $street, $defaults['zip_code']);
                    if (empty($geo['ok'])) {
                        throw new RuntimeException(
                            (string) ($geo['error'] ?? '無法由地址取得 GPS')
                            . '（可手動填入 GPS 欄位：緯度,經度）'
                        );
                    }
                }

                $gml = (string) ($geo['google_map_location'] ?? '');
                $placeAddr = trim((string) ($defaults['place_formatted_address'] ?? ''));
                if ($placeAddr === '' && !empty($geo['display_name'])) {
                    $placeAddr = (string) $geo['display_name'];
                }
                if ($placeAddr === '') {
                    $placeAddr = $geoQuery;
                }

                $coverPath = fate_member_store_save_uploaded_image($_FILES['cover_photo_path'], 'member_cover');

                $photoPaths = [];
                if (isset($_FILES['interior_images']) && is_array($_FILES['interior_images']['name'])) {
                    $n = count($_FILES['interior_images']['name']);
                    for ($i = 0; $i < $n && $i < 4; $i++) {
                        if ((int) ($_FILES['interior_images']['error'][$i] ?? UPLOAD_ERR_NO_FILE) !== UPLOAD_ERR_OK) {
                            continue;
                        }
                        $one = [
                            'name' => $_FILES['interior_images']['name'][$i],
                            'type' => $_FILES['interior_images']['type'][$i] ?? '',
                            'tmp_name' => $_FILES['interior_images']['tmp_name'][$i],
                            'error' => $_FILES['interior_images']['error'][$i],
                            'size' => $_FILES['interior_images']['size'][$i] ?? 0,
                        ];
                        try {
                            $photoPaths[] = ['path' => fate_member_store_save_uploaded_image($one, 'member_int')];
                        } catch (Throwable $eUp) {
                            error_log('member add_store interior: ' . $eUp->getMessage());
                        }
                    }
                }

                $result = fate_member_store_insert_manual($pdo, $memberId, [
                    'store_name' => $storeName,
                    'city_name' => $city,
                    'district_name' => $district,
                    'street_address' => $street,
                    'place_formatted_address' => $placeAddr,
                    'google_map_location' => $gml,
                    'phone' => $defaults['phone'],
                    'mobile' => $defaults['mobile'],
                    'line' => $defaults['line'],
                    'wechat' => $defaults['wechat'],
                    'website' => $defaults['website'],
                    'facebook' => $defaults['facebook'],
                    'basic_charge' => $defaults['basic_charge'],
                    'cover_photo_path' => $coverPath,
                    'photo_paths' => $photoPaths,
                    'business_hours_start' => $defaults['business_hours_start'],
                    'business_hours_end' => $defaults['business_hours_end'],
                    'multi_hours' => $multiHours,
                    'business_type' => $defaults['business_type'],
                    'appointment_required' => $defaults['appointment_required'],
                    'parking' => $defaults['parking'],
                    'payment_method' => $defaults['payment_method'],
                    'spa_type' => $defaults['spa_type'],
                ], FATE_STORE_LISTING_FIXED);

                if (empty($result['ok'])) {
                    throw new RuntimeException((string) ($result['error'] ?? '儲存失敗'));
                }

                header('Location: member_profile.php?tab=stores&submitted=1', true, 303);
                exit;

            } catch (Throwable $e) {
                $error = $e->getMessage();
                error_log('member add_store error: ' . $e->getMessage());
            }
        }
    }
}

$csrf = fate_public_member_csrf_token();
$scriptPrefix = dirname((string) ($_SERVER['SCRIPT_NAME'] ?? ''));
$scriptPrefix = str_replace('\\', '/', $scriptPrefix);
$scriptPrefix = rtrim($scriptPrefix, '/');
$citiesApi = $scriptPrefix . '/api/member_cities.php';
$geocodeApi = $scriptPrefix . '/api/member_geocode.php';
$weekdaysEn = ['Monday' => '一', 'Tuesday' => '二', 'Wednesday' => '三', 'Thursday' => '四', 'Friday' => '五', 'Saturday' => '六', 'Sunday' => '日'];
$parkingOptions = ['路邊停車', '備專用停車場', '收費停車場（100M）'];

// Set variables required by sidebar.php
$fatePublicMember = $member;
$cityFilter = '';
$sort = 'rating';
$storeSearchQ = '';
$storeSearchTotal = null;
$buildHomeQuery = static function (array $overrides): string {
    return './?' . http_build_query(array_merge($_GET, $overrides));
};

$fatePageTitle = '推薦新店家 — ' . htmlspecialchars($fateBrand['title_main'] ?? 'FATE', ENT_QUOTES, 'UTF-8');
require_once __DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'fate_seo.php';
$fateSeoContext = fate_seo_private_page_context();
require_once __DIR__ . '/templates/default/partials/head.php';
?>
<body>
    <header class="topbar">
        <div class="topbar-inner">
            <a class="brand" href="./"><?= htmlspecialchars($fateBrand['title_main'] ?? 'FATE', ENT_QUOTES, 'UTF-8') ?> <span><?= htmlspecialchars($fateBrand['title_sub'] ?? '店家探索', ENT_QUOTES, 'UTF-8') ?></span></a>
            <nav>
                <a href="./">探索列表</a>
                <a href="member_profile.php">我的帳號</a>
                <a href="logout.php">登出</a>
            </nav>
        </div>
    </header>

    <div class="layout-shell layout-shell--detail">
        <div class="layout">
            <div class="layout-main">
                <nav class="store-bc" aria-label="麵包屑">
                    <a href="./">探索</a>
                    <span class="store-bc__sep" aria-hidden="true">/</span>
                    <a href="member_profile.php">我的帳號</a>
                    <span class="store-bc__sep" aria-hidden="true">/</span>
                    <span class="store-bc__cur">推薦定點店家</span>
                </nav>

                <header class="page-head page-head--compact">
                    <h1 class="page-title">推薦定點店家</h1>
                    <p class="sub">填寫有<strong>固定店面或可公開地址</strong>的店家資訊，送出後將由管理員審核，通過後即會公開展示於「定點店家」分類。
                        若為<strong>非定點服務</strong>（無固定店面、不公開路名），請改用
                        <a href="member_add_store_mobile.php" class="text-accent-link">非定點服務</a>表單。</p>
                </header>

                <?php if ($error !== null): ?>
                    <div class="member-profile-msg member-profile-msg--bad"><?= htmlspecialchars($error, ENT_QUOTES, 'UTF-8') ?></div>
                <?php endif; ?>

                <section class="store-card-fate store-card-fate--block member-profile-card">
                    <form method="post" action="member_add_store.php" enctype="multipart/form-data" class="member-profile-form" id="fateAddStoreForm">
                        <input type="hidden" name="csrf" value="<?= htmlspecialchars($csrf, ENT_QUOTES, 'UTF-8') ?>">

                        <h3 class="member-profile-tab-subtitle" style="margin-top:0;">基本資料</h3>
                        <p class="sub" style="margin-bottom:1rem;color:var(--muted);font-size:0.8rem;">店名、城市、地區、街道為必填項目。</p>
                        
                        <label class="member-profile-label" for="store_name">店名 *</label>
                        <input type="text" name="store_name" id="store_name" class="member-profile-input" required maxlength="255" value="<?= htmlspecialchars($defaults['store_name'], ENT_QUOTES, 'UTF-8') ?>">

                        <div style="display:grid; grid-template-columns:1fr 1fr; gap:1rem;">
                            <div>
                                <label class="member-profile-label" for="citySelector">城市 *</label>
                                <select name="city_name" id="citySelector" class="member-profile-input" required style="width:100%;">
                                    <option value="">載入中…</option>
                                </select>
                            </div>
                            <div>
                                <label class="member-profile-label" for="districtSelector">地區 *</label>
                                <select name="district_name" id="districtSelector" class="member-profile-input" required disabled style="width:100%;">
                                    <option value="">請先選擇城市</option>
                                </select>
                            </div>
                        </div>
                        <span id="cityDistrictStatus" style="font-size:0.8rem; display:block; margin-top:0.25rem; color:var(--muted);"></span>

                        <label class="member-profile-label" for="zipCode">郵遞區號</label>
                        <input type="text" name="zip_code" id="zipCode" class="member-profile-input" maxlength="10" value="<?= htmlspecialchars($defaults['zip_code'], ENT_QUOTES, 'UTF-8') ?>" readonly>

                        <label class="member-profile-label" for="streetAddress">街道地址 *</label>
                        <input type="text" name="street_address" id="streetAddress" class="member-profile-input" required value="<?= htmlspecialchars($defaults['street_address'], ENT_QUOTES, 'UTF-8') ?>">

                        <label class="member-profile-label" for="placeFormattedAddress">完整顯示地址（選填）</label>
                        <input type="text" name="place_formatted_address" id="placeFormattedAddress" class="member-profile-input" value="<?= htmlspecialchars($defaults['place_formatted_address'], ENT_QUOTES, 'UTF-8') ?>" placeholder="例如：台北市信義區市府路45號">

                        <div style="margin: 1rem 0;">
                            <button type="button" class="member-profile-btn" id="btnGeocodePreview">由地址預覽 GPS</button>
                            <span id="geocodeStatus" style="font-size:0.8rem; color:var(--muted); margin-left:0.5rem;"></span>
                        </div>

                        <label class="member-profile-label" for="gpsLocation">GPS 經緯度</label>
                        <input type="text" name="google_map_location" id="gpsLocation" class="member-profile-input" value="<?= htmlspecialchars($defaults['google_map_location'], ENT_QUOTES, 'UTF-8') ?>" placeholder="預覽自動帶入，或手動填入：緯度,經度" autocomplete="off">

                        <div class="member-profile-tab-divider"></div>

                        <h3 class="member-profile-tab-subtitle">店家照片</h3>
                        
                        <label class="member-profile-label" for="coverPhotoInput">封面照片 * (JPEG/PNG/WebP/GIF，最大 8MB)</label>
                        <input type="file" name="cover_photo_path" id="coverPhotoInput" accept="image/jpeg,image/png,image/gif,image/webp" required class="member-profile-input member-profile-input--file">
                        <div id="coverPhotoPreview" class="photo-preview" hidden style="display: flex; gap: 0.5rem; margin-top: 0.5rem; flex-wrap: wrap;"></div>

                        <label class="member-profile-label" for="interiorImagesInput">店內環境照片（最多 4 張，選填）</label>
                        <input type="file" name="interior_images[]" id="interiorImagesInput" accept="image/jpeg,image/png,image/gif,image/webp" multiple class="member-profile-input member-profile-input--file">
                        <div id="interiorPhotoPreview" class="photo-preview" hidden style="display: flex; gap: 0.5rem; margin-top: 0.5rem; flex-wrap: wrap;"></div>

                        <div class="member-profile-tab-divider"></div>

                        <h3 class="member-profile-tab-subtitle">聯絡與營業資訊 (選填)</h3>

                        <div style="display:grid; grid-template-columns:1fr 1fr; gap:1rem;">
                            <div>
                                <label class="member-profile-label" for="phone">電話</label>
                                <input type="text" name="phone" id="phone" class="member-profile-input" value="<?= htmlspecialchars($defaults['phone'], ENT_QUOTES, 'UTF-8') ?>">
                            </div>
                            <div>
                                <label class="member-profile-label" for="mobile">手機</label>
                                <input type="text" name="mobile" id="mobile" class="member-profile-input" value="<?= htmlspecialchars($defaults['mobile'], ENT_QUOTES, 'UTF-8') ?>">
                            </div>
                        </div>

                        <div style="display:grid; grid-template-columns:1fr 1fr; gap:1rem;">
                            <div>
                                <label class="member-profile-label" for="line">LINE 帳號/連結</label>
                                <input type="text" name="line" id="line" class="member-profile-input" value="<?= htmlspecialchars($defaults['line'], ENT_QUOTES, 'UTF-8') ?>">
                            </div>
                            <div>
                                <label class="member-profile-label" for="wechat">WeChat 帳號</label>
                                <input type="text" name="wechat" id="wechat" class="member-profile-input" value="<?= htmlspecialchars($defaults['wechat'], ENT_QUOTES, 'UTF-8') ?>">
                            </div>
                        </div>

                        <label class="member-profile-label" for="website">官方網站 URL</label>
                        <input type="url" name="website" id="website" class="member-profile-input" value="<?= htmlspecialchars($defaults['website'], ENT_QUOTES, 'UTF-8') ?>">

                        <label class="member-profile-label" for="facebook">Facebook 粉專 URL</label>
                        <input type="url" name="facebook" id="facebook" class="member-profile-input" value="<?= htmlspecialchars($defaults['facebook'], ENT_QUOTES, 'UTF-8') ?>">

                        <div style="display:grid; grid-template-columns:1fr 1fr; gap:1rem;">
                            <div>
                                <label class="member-profile-label" for="service_target">服務對象</label>
                                <select name="service_target" id="service_target" class="member-profile-input" style="width:100%;">
                                    <option value="male_customers" <?= $defaults['service_target'] === 'male_customers' ? 'selected' : '' ?>>男性專屬</option>
                                    <option value="female_customers" <?= $defaults['service_target'] === 'female_customers' ? 'selected' : '' ?>>女性專屬</option>
                                    <option value="both_customers" <?= $defaults['service_target'] === 'both_customers' ? 'selected' : '' ?>>男女皆可</option>
                                </select>
                            </div>
                            <div>
                                <label class="member-profile-label" for="business_type">業態</label>
                                <input type="text" name="business_type" id="business_type" class="member-profile-input" value="<?= htmlspecialchars($defaults['business_type'], ENT_QUOTES, 'UTF-8') ?>" placeholder="例：按摩、SPA">
                            </div>
                        </div>

                        <div style="display:grid; grid-template-columns:1fr 1fr; gap:1rem;">
                            <div>
                                <label class="member-profile-label" for="spa_type">SPA 類型</label>
                                <input type="text" name="spa_type" id="spa_type" class="member-profile-input" value="<?= htmlspecialchars($defaults['spa_type'], ENT_QUOTES, 'UTF-8') ?>" placeholder="例：指壓,油壓,芳療 (逗號分隔)">
                            </div>
                            <div>
                                <label class="member-profile-label" for="basic_charge">起價 (元)</label>
                                <input type="number" name="basic_charge" id="basic_charge" min="0" step="1" class="member-profile-input" value="<?= htmlspecialchars($defaults['basic_charge'], ENT_QUOTES, 'UTF-8') ?>">
                            </div>
                        </div>

                        <div style="display:grid; grid-template-columns:1fr 1fr; gap:1rem;">
                            <div>
                                <label class="member-profile-label" for="businessHoursStart">營業開始時間</label>
                                <input type="time" name="business_hours_start" id="businessHoursStart" class="member-profile-input" value="<?= htmlspecialchars($defaults['business_hours_start'], ENT_QUOTES, 'UTF-8') ?>">
                            </div>
                            <div>
                                <label class="member-profile-label" for="businessHoursEnd">營業結束時間</label>
                                <input type="time" name="business_hours_end" id="businessHoursEnd" class="member-profile-input" value="<?= htmlspecialchars($defaults['business_hours_end'], ENT_QUOTES, 'UTF-8') ?>">
                            </div>
                        </div>

                        <div style="margin:1rem 0;">
                            <label class="member-profile-label">營業時段細項設定</label>
                            <div style="display:flex; gap:0.5rem; margin-bottom:0.5rem;">
                                <button type="button" class="member-profile-btn" id="btnSetSimple24Hours" style="padding:0.4rem 0.8rem; font-size:0.8rem;">簡易 24 小時</button>
                                <button type="button" class="member-profile-btn" id="btnOpenHoursModal" style="padding:0.4rem 0.8rem; font-size:0.8rem;">多時段 (Google 格式)</button>
                            </div>
                            <p id="hoursSummary" style="font-size:0.8rem; color:var(--muted);">尚未設定（預設使用起迄時間，或留空）</p>
                            <input type="hidden" name="multi_hours_json" id="multiHoursJson" value="<?= htmlspecialchars($defaults['multi_hours_json'], ENT_QUOTES, 'UTF-8') ?>">
                        </div>

                        <div style="display:grid; grid-template-columns:1fr 1fr; gap:1rem;">
                            <div>
                                <label class="member-profile-label" for="payment_method">付款方式</label>
                                <input type="text" name="payment_method" id="payment_method" class="member-profile-input" value="<?= htmlspecialchars($defaults['payment_method'], ENT_QUOTES, 'UTF-8') ?>" placeholder="例：現金、信用卡">
                            </div>
                            <div>
                                <label class="member-profile-label" for="parkingSelect">停車資訊</label>
                                <select name="parking" id="parkingSelect" class="member-profile-input" style="width:100%;">
                                    <option value="">請選擇</option>
                                    <?php foreach ($parkingOptions as $parkOpt): ?>
                                        <option value="<?= htmlspecialchars($parkOpt, ENT_QUOTES, 'UTF-8') ?>" <?= $defaults['parking'] === $parkOpt ? 'selected' : '' ?>><?= htmlspecialchars($parkOpt, ENT_QUOTES, 'UTF-8') ?></option>
                                    <?php endforeach; ?>
                                </select>
                            </div>
                        </div>

                        <label class="member-profile-label" style="display:flex; align-items:center; gap:0.5rem; margin:1rem 0; cursor:pointer;">
                            <input type="checkbox" name="appointment_required" value="1" <?= $defaults['appointment_required'] === '預約' ? 'checked' : '' ?>>
                            <span>此店家需要預約</span>
                        </label>

                        <label class="member-profile-label" for="description">店家簡介</label>
                        <textarea name="description" id="description" rows="4" class="member-profile-input" style="resize:vertical; min-height:100px;"><?= htmlspecialchars($defaults['description'], ENT_QUOTES, 'UTF-8') ?></textarea>

                        <div class="member-profile-form-actions" style="margin-top:2rem;">
                            <button type="submit" class="member-profile-btn member-profile-btn--primary">送出推薦（待審核）</button>
                            <a href="member_profile.php?tab=stores" class="member-profile-btn member-profile-btn--ghost">返回列表</a>
                        </div>
                    </form>
                </section>
            </div>

            <?php require __DIR__ . '/templates/default/partials/sidebar.php'; ?>
        </div>
    </div>

    <dialog class="hours-dialog" id="multiHoursModal" aria-labelledby="multiHoursModalTitle" style="border:1px solid var(--line); border-radius:var(--radius); background:var(--bg2); color:var(--fg); padding:1.5rem; max-width:480px; margin:auto;">
        <form method="dialog" onsubmit="return false;" style="display:flex; flex-direction:column; gap:1rem;">
            <header style="display:flex; justify-content:space-between; align-items:center;">
                <h3 id="multiHoursModalTitle">多時段營業時間設定</h3>
                <button type="button" id="btnCancelMultiHours" style="border:none; background:none; color:var(--muted); font-size:1.5rem; cursor:pointer;">&times;</button>
            </header>
            <p style="font-size:0.75rem; color:var(--muted);">格式如 <code>09:00-18:00</code>；休息填 <code>Closed</code>；24小時填 <code>00:00-00:00</code>。</p>
            
            <table style="width:100%; border-collapse:collapse;">
                <tbody>
                    <?php foreach ($weekdaysEn as $dayKey => $dayLabel): ?>
                    <tr>
                        <td style="padding:0.4rem 0; font-size:0.9rem;">週<?= htmlspecialchars($dayLabel, ENT_QUOTES, 'UTF-8') ?></td>
                        <td style="padding:0.4rem 0;">
                            <div style="display:flex; gap:0.25rem; align-items:center;">
                                <input type="text" class="multi-hours-input" data-day="<?= htmlspecialchars($dayKey, ENT_QUOTES, 'UTF-8') ?>" placeholder="09:00-18:00" class="member-profile-input" style="padding:0.25rem 0.5rem; font-size:0.8rem; margin:0; width:120px; border: 1px solid var(--line); background:var(--bg); color:var(--fg); border-radius:4px;">
                                <button type="button" class="member-profile-btn hours-set-closed" data-day="<?= htmlspecialchars($dayKey, ENT_QUOTES, 'UTF-8') ?>" style="padding:0.25rem 0.5rem; font-size:0.75rem; margin:0;">休息</button>
                                <button type="button" class="member-profile-btn hours-set-24h" data-day="<?= htmlspecialchars($dayKey, ENT_QUOTES, 'UTF-8') ?>" style="padding:0.25rem 0.5rem; font-size:0.75rem; margin:0;">24h</button>
                            </div>
                        </td>
                    </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
            
            <footer style="display:flex; justify-content:flex-end; gap:0.5rem; margin-top:1rem;">
                <button type="button" class="member-profile-btn member-profile-btn--ghost" id="btnCancelMultiHoursFoot">取消</button>
                <button type="button" class="member-profile-btn member-profile-btn--primary" id="btnSaveMultiHours">套用</button>
            </footer>
        </form>
    </dialog>

    <script>
    window.FATE_ADD_STORE_CFG = <?= json_encode([
        'citiesApi' => $citiesApi,
        'geocodeApi' => $geocodeApi,
        'initialCity' => $defaults['city_name'],
        'initialDistrict' => $defaults['district_name'],
        'multiHoursJson' => $defaults['multi_hours_json'],
    ], JSON_UNESCAPED_UNICODE) ?>;
    </script>
    <script src="admin/static/add_store.js?v=<?= time() ?>"></script>
<?php
require __DIR__ . '/templates/default/partials/footer.php';
?>
