<?php
// 右侧客户端下载侧边栏组件
$currentPage = basename($_SERVER['PHP_SELF']);
$isClientsPage = ($currentPage === 'clients.php' || $currentPage === 'app_download.php');
?>

<!-- 右侧浮动客户端下载侧边栏 -->
<div class="client-sidebar" id="clientSidebar">
    <!-- 展开/收起按钮 -->
    <div class="sidebar-toggle" id="sidebarToggle" title="客户端下载">
        <i class="fas fa-chevron-left" id="sidebarToggleIcon"></i>
    </div>

    <!-- 侧边栏内容 -->
    <div class="sidebar-content" id="sidebarContent">
        <div class="sidebar-header">
            <span class="sidebar-title">客户端下载</span>
        </div>

        <div class="sidebar-list">
            <!-- Android -->
            <a href="app_download.php" class="sidebar-item sidebar-android" data-platform="android">
                <div class="sidebar-icon">
                    <i class="fab fa-android"></i>
                </div>
                <div class="sidebar-info">
                    <div class="sidebar-platform">Android</div>
                    <div class="sidebar-desc">扫码下载 APK</div>
                </div>
                <i class="fas fa-chevron-right sidebar-arrow"></i>
            </a>

            <!-- iOS -->
            <a href="clients.php?platform=ios" class="sidebar-item sidebar-ios" data-platform="ios">
                <div class="sidebar-icon">
                    <i class="fab fa-apple"></i>
                </div>
                <div class="sidebar-info">
                    <div class="sidebar-platform">iOS</div>
                    <div class="sidebar-desc">添加到主屏幕</div>
                </div>
                <i class="fas fa-chevron-right sidebar-arrow"></i>
            </a>

            <!-- Windows -->
            <a href="clients.php?platform=windows" class="sidebar-item sidebar-windows" data-platform="windows">
                <div class="sidebar-icon">
                    <svg viewBox="0 0 24 24" width="22" height="22" fill="currentColor">
                        <path d="M0 3.449L9.75 2.1v9.451H0m10.949-9.6L24 0v11.4H10.949M0 12.6h9.75v9.451L0 20.699M10.949 12.6H24V24l-13.051-1.349"/>
                    </svg>
                </div>
                <div class="sidebar-info">
                    <div class="sidebar-platform">Windows</div>
                    <div class="sidebar-desc">便携版下载</div>
                </div>
                <i class="fas fa-chevron-right sidebar-arrow"></i>
            </a>

            <!-- Mac -->
            <a href="clients.php?platform=mac" class="sidebar-item sidebar-mac" data-platform="mac">
                <div class="sidebar-icon">
                    <i class="fab fa-apple"></i>
                </div>
                <div class="sidebar-info">
                    <div class="sidebar-platform">Mac</div>
                    <div class="sidebar-desc">本地运行指南</div>
                </div>
                <i class="fas fa-chevron-right sidebar-arrow"></i>
            </a>

            <!-- 微信 -->
            <a href="clients.php?platform=wechat" class="sidebar-item sidebar-wechat" data-platform="wechat">
                <div class="sidebar-icon">
                    <i class="fab fa-weixin"></i>
                </div>
                <div class="sidebar-info">
                    <div class="sidebar-platform">微信小程序</div>
                    <div class="sidebar-desc">扫码进入 H5</div>
                </div>
                <i class="fas fa-chevron-right sidebar-arrow"></i>
            </a>
        </div>

        <div class="sidebar-footer">
            <a href="clients.php" class="sidebar-view-all">
                <i class="fas fa-th-large"></i> 查看全部客户端
            </a>
        </div>
    </div>

    <!-- 展开后显示的小图标 -->
    <div class="sidebar-mini" id="sidebarMini" style="display:none;">
        <a href="app_download.php" class="mini-item" title="Android APP">
            <i class="fab fa-android"></i>
        </a>
        <a href="clients.php?platform=ios" class="mini-item" title="iOS">
            <i class="fab fa-apple"></i>
        </a>
        <a href="clients.php?platform=windows" class="mini-item" title="Windows">
            <svg viewBox="0 0 24 24" width="16" height="16" fill="currentColor">
                <path d="M0 3.449L9.75 2.1v9.451H0m10.949-9.6L24 0v11.4H10.949M0 12.6h9.75v9.451L0 20.699M10.949 12.6H24V24l-13.051-1.349"/>
            </svg>
        </a>
        <a href="clients.php?platform=wechat" class="mini-item" title="微信">
            <i class="fab fa-weixin"></i>
        </a>
        <a href="clients.php" class="mini-item" title="全部客户端">
            <i class="fas fa-ellipsis-h"></i>
        </a>
    </div>
</div>

<style>
/* 右侧客户端下载侧边栏样式 */
.client-sidebar {
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 9999;
    font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
}

.sidebar-toggle {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 80px;
    background: linear-gradient(135deg, #b64a2a, #d4663a);
    border-radius: 8px 0 0 8px;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: -2px 0 12px rgba(182, 74, 42, 0.25);
    z-index: 10;
    transition: right 0.3s ease;
}

.sidebar-content {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 220px;
    background: #fff;
    border-radius: 16px 0 0 16px;
    box-shadow: -4px 0 24px rgba(0,0,0,0.12);
    overflow: hidden;
    transition: right 0.3s ease, opacity 0.3s ease;
    opacity: 1;
}

.client-sidebar.collapsed .sidebar-content {
    opacity: 0;
    pointer-events: none;
}

.sidebar-header {
    background: linear-gradient(135deg, #b64a2a, #d4663a);
    padding: 12px 16px;
    text-align: center;
}

.sidebar-title {
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 1px;
}

.sidebar-list {
    padding: 6px 0;
    max-height: 420px;
    overflow-y: auto;
}

.sidebar-item {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    text-decoration: none;
    color: #333;
    transition: background 0.2s;
    cursor: pointer;
}

.sidebar-item:hover {
    background: #fff5f0;
}

.sidebar-item:hover .sidebar-platform {
    color: #b64a2a;
}

.sidebar-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    margin-right: 10px;
    flex-shrink: 0;
}

.sidebar-android .sidebar-icon { background: linear-gradient(135deg, #4caf50, #66bb6a); }
.sidebar-ios .sidebar-icon { background: linear-gradient(135deg, #333, #555); }
.sidebar-windows .sidebar-icon { background: linear-gradient(135deg, #0078d4, #2b88d8); }
.sidebar-mac .sidebar-icon { background: linear-gradient(135deg, #555, #777); }
.sidebar-wechat .sidebar-icon { background: linear-gradient(135deg, #09bb07, #10c810); }

.sidebar-icon i, .sidebar-icon svg {
    font-size: 18px;
}

.sidebar-info {
    flex: 1;
    min-width: 0;
}

.sidebar-platform {
    font-size: 13px;
    font-weight: 600;
    color: #333;
    line-height: 1.2;
}

.sidebar-desc {
    font-size: 11px;
    color: #999;
    line-height: 1.2;
    margin-top: 2px;
}

.sidebar-arrow {
    color: #ccc;
    font-size: 10px;
    transition: transform 0.2s;
}

.sidebar-item:hover .sidebar-arrow {
    color: #b64a2a;
    transform: translateX(2px);
}

.sidebar-footer {
    border-top: 1px solid #f0f0f0;
    padding: 10px 14px;
}

.sidebar-view-all {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 12px;
    color: #b64a2a;
    text-decoration: none;
    font-weight: 500;
}

.sidebar-view-all:hover {
    color: #d4663a;
}

/* 收起后显示的迷你图标列 */
.sidebar-mini {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: #fff;
    padding: 8px 4px;
    border-radius: 12px 0 0 12px;
    box-shadow: -2px 0 12px rgba(0,0,0,0.08);
}

.mini-item {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #b64a2a;
    text-decoration: none;
    border-radius: 6px;
    transition: background 0.2s;
    position: relative;
}

.mini-item:hover {
    background: #fff5f0;
}

.mini-item i, .mini-item svg {
    font-size: 14px;
}

.mini-item[title]:hover::after {
    content: attr(title);
    position: absolute;
    right: 40px;
    top: 50%;
    transform: translateY(-50%);
    background: #333;
    color: #fff;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
}

/* 侧边栏展开状态 */
.client-sidebar.expanded .sidebar-toggle {
    right: 220px;
}

.client-sidebar.expanded .sidebar-toggle i {
    transform: rotate(180deg);
}

.sidebar-toggle i {
    transition: transform 0.3s;
}

.client-sidebar.collapsed .sidebar-mini {
    display: flex !important;
}

/* 移动端适配 */
@media (max-width: 768px) {
    .client-sidebar {
        top: auto;
        bottom: 60px;
        transform: none;
    }

    .sidebar-content {
        width: 180px;
        top: auto;
        bottom: 50%;
        transform: translateY(50%);
    }

    .sidebar-toggle {
        top: auto;
        bottom: 50%;
        transform: translateY(50%);
    }

    .client-sidebar.expanded .sidebar-toggle {
        right: 180px;
    }

    .sidebar-item {
        padding: 8px 10px;
    }

    .sidebar-icon {
        width: 30px;
        height: 30px;
        margin-right: 8px;
    }

    .sidebar-platform {
        font-size: 12px;
    }

    .sidebar-desc {
        display: none;
    }
}

/* 滚动条美化 */
.sidebar-list::-webkit-scrollbar {
    width: 4px;
}

.sidebar-list::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-list::-webkit-scrollbar-thumb {
    background: #f0e0d0;
    border-radius: 2px;
}
</style>

<script>
// 侧边栏交互
(function() {
    var sidebar = document.getElementById('clientSidebar');
    var toggle = document.getElementById('sidebarToggle');

    if (!sidebar || !toggle) return;

    toggle.addEventListener('click', function() {
        sidebar.classList.toggle('expanded');
        sidebar.classList.toggle('collapsed');
        var icon = document.getElementById('sidebarToggleIcon');
        var mini = document.getElementById('sidebarMini');
        var content = document.getElementById('sidebarContent');

        if (sidebar.classList.contains('expanded')) {
            content.style.opacity = '1';
            content.style.pointerEvents = 'auto';
            mini.style.display = 'none';
        } else {
            content.style.opacity = '0';
            content.style.pointerEvents = 'none';
            setTimeout(function() {
                mini.style.display = 'flex';
            }, 300);
        }
    });

    // 默认展开（首次访问）
    if (!sessionStorage.getItem('sidebarCollapsed')) {
        sidebar.classList.add('expanded');
    } else {
        sidebar.classList.add('collapsed');
        document.getElementById('sidebarMini').style.display = 'flex';
    }

    // 点击展开时记住状态
    toggle.addEventListener('click', function() {
        sessionStorage.setItem('sidebarCollapsed', sidebar.classList.contains('collapsed') ? '1' : '0');
    });
})();
</script>
