<?php
/**
 * 芋头CMS
 * ============================================================================
 * 版权所有 2016-2028 沅陵县乌托邦网络服务有限公司，并保留所有权利。
 * 网站地址: http://www.yutoucms.cn
 * ----------------------------------------------------------------------------
 * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
 * ============================================================================
 * Author: 芋头 <mxgsf@qq.com>
 * Date: 2026-5-20
 */

require_once __DIR__ . '/../../core/lib/license.php';
$license = new \Core\Lib\License();
$licenseLevel = $license->getLevel();


if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    requireAdminCsrfToken();
    $configs = isset($_POST['config']) ? $_POST['config'] : [];
    foreach ($configs as $key => $value) {
        $exists = $db->fetch("SELECT id FROM {$db->table('config')} WHERE config_key = ?", [$key]);
        if ($exists) {
            $db->update('config', ['config_value' => $value], 'config_key = ?', [$key]);
        } else {
            $db->insert('config', ['config_key' => $key, 'config_value' => $value, 'config_type' => 'text', 'config_group' => 'basic']);
        }
    }
    echo '<script>alert("保存成功");location.href="?act=site"</script>';
    exit;
}
$allConfigs = $db->fetchAll("SELECT * FROM {$db->table('config')} WHERE config_group = 'basic' ORDER BY id ASC");
$configData = [];
foreach ($allConfigs as $cfg) { $configData[$cfg['config_key']] = $cfg['config_value']; }
?>
<div class="page-container fade-in">
    <div class="page-header">
        <div class="page-title">
            <div class="page-icon"><svg style="width:22px;height:22px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg></div>
            <div>
                <h1>站点设置</h1>
                <p style="font-size:12px;color:#64748b;margin:0;">配置网站基本信息与系统参数</p>
            </div>
        </div>
        <div class="page-actions">
            <button type="submit" form="siteForm" class="btn btn-success btn-lg"><svg style="width:22px;height:22px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"/><polyline points="17 21 17 13 7 13 7 21"/><polyline points="7 3 7 8 15 8"/></svg> 保存设置</button>
        </div>
    </div>
    <form method="post" id="siteForm">
        <input type="hidden" name="csrf_token" value="<?php echo htmlspecialchars(getAdminCsrfToken()); ?>">
        <div class="site-tabs">
            <button type="button" class="site-tab active" data-tab="basic" onclick="return switchSiteTab(this);">
                <svg style="width:16px;height:16px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06A1.65 1.65 0 0 0 15 19.4 1.65 1.65 0 0 0 13.5 21v0a2 2 0 0 1-3 0v0A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.6 15 1.65 1.65 0 0 0 3 13.5h0a2 2 0 0 1 0-3h0A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.6 1.65 1.65 0 0 0 10.5 3h0a2 2 0 0 1 3 0h0A1.65 1.65 0 0 0 15 4.6a1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9 1.65 1.65 0 0 0 21 10.5h0a2 2 0 0 1 0 3h0A1.65 1.65 0 0 0 19.4 15z"/></svg>
                基础配置
            </button>
            <button type="button" class="site-tab" data-tab="company" onclick="return switchSiteTab(this);">
                <svg style="width:16px;height:16px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M3 21h18"/><path d="M5 21V7l8-4v18"/><path d="M19 21V11l-6-4"/><path d="M9 9h1"/><path d="M9 13h1"/><path d="M9 17h1"/></svg>
                公司介绍与联系方式
            </button>
        </div>
        <div class="site-tab-panel active" id="tab-basic">
        <!-- 基本信息 -->
        <div class="form-section">
            <div class="form-section-header"><svg style="width:16px;height:16px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/></svg> 基本信息</div>
            <div class="form-section-body">
                <div class="form-row">
                    <div class="form-group"><label>网站名称</label><input type="text" name="config[site_name]" class="form-control" value="<?php echo htmlspecialchars(isset($configData['site_name']) ? $configData['site_name'] : ''); ?>" placeholder="请输入网站名称"></div>
                    <div class="form-group"><label>网站URL</label><input type="text" name="config[site_url]" class="form-control" value="<?php echo htmlspecialchars(isset($configData['site_url']) ? $configData['site_url'] : ''); ?>" placeholder="如：http://www.example.com"></div>
                </div>
                
                <div class="form-row">
                    <div class="form-group"><label>ICP备案号</label><input type="text" name="config[site_icp]" class="form-control" value="<?php echo htmlspecialchars(isset($configData['site_icp']) ? $configData['site_icp'] : ''); ?>" placeholder="如：京ICP备xxxxxx号"></div>
                </div>
                <div class="form-row">
                    <div class="form-group"><label>公安备案号</label><input type="text" name="config[site_police_icp]" class="form-control" value="<?php echo htmlspecialchars(isset($configData['site_police_icp']) ? $configData['site_police_icp'] : ''); ?>" placeholder="如：京公网安备xxxxxx号"></div>
                    <div class="form-group"></div>
                </div>
            </div>
        </div>

        <!-- 站点形象 -->
        <div class="form-section">
            <div class="form-section-header"><svg style="width:22px;height:22px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/></svg> 站点形象</div>
            <div class="form-section-body">
                <div class="form-row">
                    <div class="form-group">
                        <label>网站LOGO</label>
                        <div class="upload-box" id="logoUploadBox">
                            <input type="hidden" name="config[site_logo]" id="site_logo" value="<?php echo htmlspecialchars(isset($configData['site_logo']) ? $configData['site_logo'] : ''); ?>">
                            <?php $logoUrl = !empty($configData['site_logo']) ? htmlspecialchars($configData['site_logo']) : ''; ?>
                            <?php if (!empty($logoUrl)): ?>
                            <div class="upload-preview" id="logoPreview"><img src="<?php echo $logoUrl; ?>" id="logoImg"><span class="upload-remove" onclick="removeUpload('logo')">×</span></div>
                            <div class="upload-placeholder" id="logoPlaceholder" onclick="triggerUpload('logo')" style="display:none;"><svg style="width:14px;height:14px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg><span>点击上传LOGO</span></div>
                            <?php else: ?>
                            <div class="upload-placeholder" id="logoPlaceholder" onclick="triggerUpload('logo')"><svg style="width:14px;height:14px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg><span>点击上传LOGO</span></div>
                            <div class="upload-preview" id="logoPreview" style="display:none;"><img src="" id="logoImg"><span class="upload-remove" onclick="removeUpload('logo')">×</span></div>
                            <?php endif; ?>
                        </div>
                        <input type="file" id="logoFile" style="display:none;" accept="image/*" onchange="handleFileUpload(this, 'logo')">
                        <p class="form-help">建议尺寸：200×60 像素，支持 JPG/PNG/SVG</p>
                    </div>
                  
                </div>
            </div>
        </div>

        <!-- 系统设置 -->
        <div class="form-section">
            <div class="form-section-header"><svg style="width:22px;height:22px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="4" y1="21" x2="4" y2="14"/><line x1="4" y1="10" x2="4" y2="3"/><line x1="12" y1="21" x2="12" y2="12"/><line x1="12" y1="8" x2="12" y2="3"/><line x1="20" y1="21" x2="20" y2="16"/><line x1="20" y1="12" x2="20" y2="3"/><line x1="1" y1="14" x2="7" y2="14"/><line x1="9" y1="8" x2="15" y2="8"/><line x1="17" y1="16" x2="23" y2="16"/></svg> 系统设置</div>
            <div class="form-section-body">
                <div class="form-row">
                    <div class="form-group">
                        <label>系统更新提醒</label>
                        <select name="config[update_remind]" class="form-control">
                            <option value="modal" <?php echo ((isset($configData['update_remind']) ? $configData['update_remind'] : 'modal')) === 'modal' ? 'selected' : ''; ?>>弹窗提醒</option>
                            <option value="backend" <?php echo ((isset($configData['update_remind']) ? $configData['update_remind'] : 'modal')) === 'backend' ? 'selected' : ''; ?>>仅后台提醒</option>
                            <option value="off" <?php echo ((isset($configData['update_remind']) ? $configData['update_remind'] : 'modal')) === 'off' ? 'selected' : ''; ?>>关闭提醒</option>
                        </select>
                        <p class="form-help">弹窗提醒：在检测到新版本时弹出提示；仅后台提醒：在后台顶部显示提示条；关闭提醒：不再提醒</p>
                    </div>
                    <div class="form-group">
                        <label>站点状态</label>
                        <div class="toggle-group" id="siteStatusGroup">
                            <label class="toggle-item<?php echo ((isset($configData['site_status']) ? $configData['site_status'] : 'open')) === 'open' ? ' active' : ''; ?>" data-value="open">
                                <svg style="width:22px;height:22px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><line x1="2" y1="12" x2="22" y2="12"/><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"/></svg> 开启
                            </label>
                            <label class="toggle-item<?php echo ((isset($configData['site_status']) ? $configData['site_status'] : 'open')) === 'close' ? ' active' : ''; ?>" data-value="close">
                                <svg style="width:14px;height:14px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><line x1="4.93" y1="4.93" x2="19.07" y2="19.07"/></svg> 关闭
                            </label>
                        </div>
                        <input type="hidden" name="config[site_status]" id="siteStatusInput" value="<?php echo htmlspecialchars(isset($configData['site_status']) ? $configData['site_status'] : 'open'); ?>">
                        <p class="form-help">关闭站点后前台显示维护提示，无法访问</p>
                    </div>
                </div>
                <div class="form-group" id="closeReasonGroup" style="<?php echo ((isset($configData['site_status']) ? $configData['site_status'] : 'open')) === 'close' ? '' : 'display:none;'; ?>">
                    <label>关站提示信息</label>
                    <textarea name="config[site_close_msg]" class="form-control" rows="3" placeholder="站点关闭时显示的提示信息"><?php echo htmlspecialchars(isset($configData['site_close_msg']) ? $configData['site_close_msg'] : ''); ?></textarea>
                </div>
                <?php if ($licenseLevel == 1): ?>
                <div class="form-group" style="background:#fef3c7;border:1px solid #fde68a;border-radius:8px;padding:12px;font-size:13px;color:#92400e;">
                    <svg style="width:14px;height:14px;vertical-align:middle;margin-right:6px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/></svg>
                    <strong>免费版限制：</strong>产品数量最多 <strong>5个</strong>，升级到基础版/专业版可无限制使用。
                    <a href="?act=version" style="color:#2563eb;text-decoration:underline;">立即升级</a>
                </div>
                <?php endif; ?>
            </div>
        </div>

        <!-- SEO设置 -->
        <div class="form-section">
            <div class="form-section-header"><svg style="width:14px;height:14px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg> SEO设置</div>
            <div class="form-section-body">
                <div class="form-group"><label>SEO标题</label><input type="text" name="config[seo_title]" class="form-control" value="<?php echo htmlspecialchars(isset($configData['seo_title']) ? $configData['seo_title'] : ''); ?>" placeholder="SEO标题"></div>
                <div class="form-group"><label>SEO关键字</label><input type="text" name="config[seo_keywords]" class="form-control" value="<?php echo htmlspecialchars(isset($configData['seo_keywords']) ? $configData['seo_keywords'] : ''); ?>" placeholder="关键字1,关键字2,关键字3"></div>
                <div class="form-group"><label>SEO描述</label><textarea name="config[seo_description]" class="form-control" rows="3" placeholder="网站描述"><?php echo htmlspecialchars(isset($configData['seo_description']) ? $configData['seo_description'] : ''); ?></textarea></div>
            </div>
        </div>

        <!-- 水印设置 -->
        <div class="form-section">
            <div class="form-section-header"><svg style="width:22px;height:22px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/></svg> 水印设置</div>
            <div class="form-section-body">
                <div class="form-row">
                    <div class="form-group">
                        <label>图标水印</label>
                        <div class="upload-box" id="watermarkUploadBox">
                            <input type="hidden" name="config[watermark_image]" id="watermark_image" value="<?php echo htmlspecialchars(isset($configData['watermark_image']) ? $configData['watermark_image'] : ''); ?>">
                            <?php $wmUrl = !empty($configData['watermark_image']) ? htmlspecialchars($configData['watermark_image']) : ''; ?>
                            <?php if ($wmUrl): ?>
                            <div class="upload-preview" id="watermarkPreview"><img src="<?php echo $wmUrl; ?>" id="watermarkImg"><span class="upload-remove" onclick="removeUpload('watermark')">×</span></div>
                            <?php else: ?>
                            <div class="upload-placeholder" id="watermarkPlaceholder" onclick="triggerUpload('watermark')"><svg style="width:14px;height:14px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg><span>点击上传水印图标</span></div>
                            <div class="upload-preview" id="watermarkPreview" style="display:none;"><img src="" id="watermarkImg"><span class="upload-remove" onclick="removeUpload('watermark')">×</span></div>
                            <?php endif; ?>
                        </div>
                        <input type="file" id="watermarkFile" style="display:none;" accept="image/*" onchange="handleFileUpload(this, 'watermark')">
                        <p class="form-help">建议尺寸：200×60 像素透明PNG</p>
                    </div>
                    <div class="form-group">
                        <label>文字水印内容</label>
                        <input type="text" name="config[watermark_text]" class="form-control" value="<?php echo htmlspecialchars(isset($configData['watermark_text']) ? $configData['watermark_text'] : ''); ?>" placeholder="如水印文字">
                    </div>
                </div>
                <div class="form-row">
                    <div class="form-group">
                        <label>水印位置</label>
                        <select name="config[watermark_position]" class="form-control">
                            <option value="右下" <?php echo (isset($configData['watermark_position']) ? $configData['watermark_position'] : '右下') === '右下' ? 'selected' : ''; ?>>右下角</option>
                            <option value="左下" <?php echo (isset($configData['watermark_position']) ? $configData['watermark_position'] : '右下') === '左下' ? 'selected' : ''; ?>>左下角</option>
                            <option value="右上" <?php echo (isset($configData['watermark_position']) ? $configData['watermark_position'] : '右下') === '右上' ? 'selected' : ''; ?>>右上角</option>
                            <option value="左上" <?php echo (isset($configData['watermark_position']) ? $configData['watermark_position'] : '右下') === '左上' ? 'selected' : ''; ?>>左上角</option>
                            <option value="居中" <?php echo (isset($configData['watermark_position']) ? $configData['watermark_position'] : '右下') === '居中' ? 'selected' : ''; ?>>正中间</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>水印透明度</label>
                        <select name="config[watermark_alpha]" class="form-control">
                            <option value="0.3" <?php echo ((isset($configData['watermark_alpha']) ? $configData['watermark_alpha'] : '0.5')) === '0.3' ? 'selected' : ''; ?>>30%</option>
                            <option value="0.5" <?php echo ((isset($configData['watermark_alpha']) ? $configData['watermark_alpha'] : '0.5')) === '0.5' ? 'selected' : ''; ?>>50%</option>
                            <option value="0.7" <?php echo ((isset($configData['watermark_alpha']) ? $configData['watermark_alpha'] : '0.5')) === '0.7' ? 'selected' : ''; ?>>70%</option>
                            <option value="1.0" <?php echo ((isset($configData['watermark_alpha']) ? $configData['watermark_alpha'] : '0.5')) === '1.0' ? 'selected' : ''; ?>>100%</option>
                        </select>
                    </div>
                </div>
            </div>
        </div>

        </div>

        <div class="site-tab-panel" id="tab-company">
            <div class="form-section">
                <div class="form-section-header"><svg style="width:22px;height:22px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M3 21h18"/><path d="M5 21V7l8-4v18"/><path d="M19 21V11l-6-4"/><path d="M9 9h1"/><path d="M9 13h1"/><path d="M9 17h1"/></svg> 公司介绍</div>
                <div class="form-section-body">
                    <div class="form-group">
                        <label>公司介绍</label>
                        <textarea name="config[company_intro]" class="form-control" rows="8" placeholder="请输入公司介绍，可用于前台关于我们、页脚等位置展示"><?php echo htmlspecialchars(isset($configData['company_intro']) ? $configData['company_intro'] : ''); ?></textarea>
                        <p class="form-help">建议填写公司简介、主营业务、品牌优势等内容。前台会自动截取摘要展示。</p>
                    </div>
                </div>
            </div>

            <div class="form-section">
                <div class="form-section-header"><svg style="width:22px;height:22px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M22 16.92v3a2 2 0 0 1-2.18 2 19.8 19.8 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6A19.8 19.8 0 0 1 2.12 4.18 2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72c.12.91.33 1.8.63 2.65a2 2 0 0 1-.45 2.11L8.09 9.69a16 16 0 0 0 6.22 6.22l1.21-1.21a2 2 0 0 1 2.11-.45c.85.3 1.74.51 2.65.63A2 2 0 0 1 22 16.92z"/></svg> 联系方式</div>
                <div class="form-section-body">
                    <div class="form-row">
                        <div class="form-group"><label>联系人</label><input type="text" name="config[contact_person]" class="form-control" value="<?php echo htmlspecialchars(isset($configData['contact_person']) ? $configData['contact_person'] : ''); ?>" placeholder="如：张经理"></div>
                        <div class="form-group"><label>联系电话</label><input type="text" name="config[site_phone]" class="form-control" value="<?php echo htmlspecialchars(isset($configData['site_phone']) ? $configData['site_phone'] : ''); ?>" placeholder="如：400-888-8888"></div>
                    </div>
                    <div class="form-row">
                        <div class="form-group"><label>联系邮箱</label><input type="email" name="config[site_email]" class="form-control" value="<?php echo htmlspecialchars(isset($configData['site_email']) ? $configData['site_email'] : ''); ?>" placeholder="admin@example.com"></div>
                        <div class="form-group"><label>联系地址</label><input type="text" name="config[site_address]" class="form-control" value="<?php echo htmlspecialchars(isset($configData['site_address']) ? $configData['site_address'] : ''); ?>" placeholder="请输入详细地址"></div>
                    </div>
                    <div class="form-row">
                        <div class="form-group"><label>微信号</label><input type="text" name="config[contact_wechat]" class="form-control" value="<?php echo htmlspecialchars(isset($configData['contact_wechat']) ? $configData['contact_wechat'] : ''); ?>" placeholder="请输入微信号"></div>
                        <div class="form-group"><label>QQ</label><input type="text" name="config[contact_qq]" class="form-control" value="<?php echo htmlspecialchars(isset($configData['contact_qq']) ? $configData['contact_qq'] : ''); ?>" placeholder="请输入QQ号码"></div>
                    </div>
                </div>
            </div>
        </div>
    </form>

<style>
.site-tabs{display:flex;gap:10px;margin:0 0 16px 0;background:#fff;border:1px solid #e2e8f0;border-radius:12px;padding:8px;box-shadow:0 1px 2px rgba(15,23,42,.04);}
.site-tab{display:flex;align-items:center;gap:8px;border:0;background:transparent;color:#64748b;padding:10px 18px;border-radius:9px;font-size:14px;font-weight:600;cursor:pointer;transition:all .2s;}
.site-tab:hover{background:#f1f5f9;color:#1d4ed8;}
.site-tab.active{background:linear-gradient(135deg,#3B82F6,#1D4ED8);color:#fff;box-shadow:0 2px 8px rgba(59,130,246,.25);}
.site-tab-panel{display:none;}
.site-tab-panel.active{display:block;}
.toggle-group{display:flex;gap:8px;margin-top:6px;}
.toggle-item{display:flex;align-items:center;gap:6px;padding:8px 16px;border:1px solid #d1d5db;border-radius:8px;cursor:pointer;font-size:13px;color:#64748b;transition:all .2s;}
.toggle-item input{display:none;}
.toggle-item:hover{border-color:#6366f1;color:#6366f1;}
.toggle-item.active{border-color:#6366f1;background:#6366f1;color:#fff;}
.upload-box{position:relative;min-height:100px;border:2px dashed #e2e8f0;border-radius:8px;display:flex;align-items:center;justify-content:center;overflow:hidden;transition:border-color .2s;}
.upload-box:hover{border-color:#6366f1;}
.upload-placeholder{display:flex;flex-direction:column;align-items:center;gap:6px;padding:20px;color:#94a3b8;cursor:pointer;}
.upload-placeholder span{font-size:12px;}
.upload-preview{position:relative;width:100%;min-height:100px;display:flex;align-items:center;justify-content:center;}
.upload-preview img{max-width:100%;max-height:100px;object-fit:contain;}
.upload-remove{position:absolute;top:4px;right:4px;width:22px;height:22px;background:rgba(239,68,68,1);color:#fff;border-radius:50%;display:flex;align-items:center;justify-content:center;font-size:16px;cursor:pointer;line-height:1;}
.upload-remove:hover{background:#dc2626;}
.form-help{font-size:11px;color:#94a3b8;margin:4px 0 0 0;}
</style>
<script>
function triggerUpload(type){
    var fileInputId = (type === 'watermark') ? 'watermarkFile' : type + 'File';
    document.getElementById(fileInputId).click();
}
function handleFileUpload(fileInput, type){
    var file = fileInput.files[0];
    if(!file) return;
    var formData = new FormData();
    formData.append('file', file);
    formData.append('upload_type', 'image');
    var xhr = new XMLHttpRequest();
    xhr.open('POST', '?act=upload', true);
    xhr.onload = function(){
        if(xhr.status === 200){
            var res = JSON.parse(xhr.responseText);
            if(res.code === 200){
                var url = res.data.url;
                var inputId = (type === 'watermark') ? 'watermark_image' : 'site_' + type;
                document.getElementById(inputId).value = url;
                document.getElementById(type + 'Img').src = url;
                document.getElementById(type + 'Placeholder').style.display = 'none';
                document.getElementById(type + 'Preview').style.display = 'flex';
            } else {
                alert(res.msg || '上传失败');
            }
        }
    };
    xhr.send(formData);
}
function removeUpload(type){
    var inputId = (type === 'watermark') ? 'watermark_image' : 'site_' + type;
    document.getElementById(inputId).value = '';
    document.getElementById(type + 'Preview').style.display = 'none';
    document.getElementById(type + 'Placeholder').style.display = 'flex';
}
// 站点开关联动

// site settings tab switch
function switchSiteTab(btn) {
    var target = btn.getAttribute('data-tab');
    var tabs = document.querySelectorAll('.site-tab');
    var panels = document.querySelectorAll('.site-tab-panel');
    for (var i = 0; i < tabs.length; i++) { tabs[i].classList.remove('active'); }
    for (var j = 0; j < panels.length; j++) { panels[j].classList.remove('active'); }
    btn.classList.add('active');
    var panel = document.getElementById('tab-' + target);
    if (panel) { panel.classList.add('active'); }
    return false;
}
var siteTabs = document.querySelectorAll('.site-tab');
var sitePanels = document.querySelectorAll('.site-tab-panel');
for (var i = 0; i < siteTabs.length; i++) {
    siteTabs[i].onclick = function() {
        return switchSiteTab(this);
    };
}
var statusGroup = document.getElementById('siteStatusGroup');
if (statusGroup) {
    var labels = statusGroup.querySelectorAll('label');
    labels.forEach(function(label) {
        label.addEventListener('click', function() {
            var val = label.getAttribute('data-value');
            labels.forEach(function(l) { l.classList.remove('active'); });
            label.classList.add('active');
            document.getElementById('siteStatusInput').value = val;
            var closeReason = document.getElementById('closeReasonGroup');
            if (closeReason) {
                closeReason.style.display = val === 'close' ? '' : 'none';
            }
        });
    });
}
lucide.createIcons();
</script>

