<?php
$title='网站信息配置';
include __DIR__ . '/head.php';
if($userrow['vip'] <= 1)exit("<script language='javascript'>alert('无权限访问');window.location.href='./set.php';</script>");
?>
<div class="py-8">
    <!-- 主容器 -->
    <div class="max-w-3xl mx-auto">
        <!-- 配置卡片 -->
        <div class="bg-white rounded-2xl shadow-2xl p-6 hover:shadow-2xl/80 transition-shadow">
            <h2 class="text-xl font-bold text-gray-800 mb-6">网站信息配置</h2>
            
            <form onsubmit="saveSetting(this);return false;" method="post" class="space-y-5">
                <!-- 网站名称 -->
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">网站名称</label>
                    <div class="relative">
                        <span class="absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 transition-colors group-focus-within:text-indigo-500">
                            <i class="fas fa-globe"></i>
                        </span>
                        <input type="text" class="w-full pl-12 pr-4 py-3 border border-gray-200 rounded-xl focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 transition-all group" 
                               name="sitename" value="<?php echo $userrow['sitename']?>">
                    </div>
                </div>
                
                <!-- 标题栏后缀 -->
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">标题栏后缀</label>
                    <div class="relative">
                        <span class="absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 transition-colors group-focus-within:text-indigo-500">
                            <i class="fas fa-heading"></i>
                        </span>
                        <input type="text" class="w-full pl-12 pr-4 py-3 border border-gray-200 rounded-xl focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 transition-all group" 
                               name="title" value="<?php echo $userrow['title']?>">
                    </div>
                </div>
                
                <!-- 关键字 -->
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">关键字</label>
                    <div class="relative">
                        <span class="absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 transition-colors group-focus-within:text-indigo-500">
                            <i class="fas fa-tags"></i>
                        </span>
                        <input type="text" class="w-full pl-12 pr-4 py-3 border border-gray-200 rounded-xl focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 transition-all group" 
                               name="keywords" value="<?php echo $userrow['keywords']?>">
                    </div>
                </div>
                
                <!-- 网站描述 -->
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">网站描述</label>
                    <div class="relative">
                        <span class="absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 transition-colors group-focus-within:text-indigo-500">
                            <i class="fas fa-file-alt"></i>
                        </span>
                        <input type="text" class="w-full pl-12 pr-4 py-3 border border-gray-200 rounded-xl focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 transition-all group" 
                               name="description" value="<?php echo $userrow['description']?>">
                    </div>
                </div>
                
                <!-- QQ号 -->
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">QQ号</label>
                    <div class="relative">
                        <span class="absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 transition-colors group-focus-within:text-indigo-500">
                            <i class="fab fa-qq"></i>
                        </span>
                        <input type="text" class="w-full pl-12 pr-4 py-3 border border-gray-200 rounded-xl focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 transition-all group" 
                               name="qq" value="<?php echo $userrow['qq']?>" placeholder="填写自己的QQ号">
                    </div>
                    <p class="text-sm text-red-600 mt-1">用于下级用户客服 以及找回密码的凭据</p>
                </div>
                
                <!-- 微信号 -->
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">微信号</label>
                    <div class="relative">
                        <span class="absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 transition-colors group-focus-within:text-indigo-500">
                            <i class="fab fa-weixin"></i>
                        </span>
                        <input type="text" class="w-full pl-12 pr-4 py-3 border border-gray-200 rounded-xl focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 transition-all group" 
                               name="kf_wx" value="<?php echo $userrow['kf_wx']?>" placeholder="可留空">
                    </div>
                    <p class="text-sm text-red-600 mt-1">用于下级用户客服</p>
                </div>
                
                <!-- 售后群链接 -->
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">售后群链接</label>
                    <div class="relative">
                        <span class="absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 transition-colors group-focus-within:text-indigo-500">
                            <i class="fab fa-qq"></i>
                        </span>
                        <input type="text" class="w-full pl-12 pr-4 py-3 border border-gray-200 rounded-xl focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 transition-all group" 
                               name="shouhou_qun" value="<?php echo htmlspecialchars($userrow['shouhou_qun'] ?? ''); ?>" placeholder="QQ群加群链接，留空则下级显示主站设置的">
                    </div>
                    <p class="text-sm text-red-600 mt-1">留空则使用主站配置</p>
                </div>
                
                <!-- 分站 App 下载 -->
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">分站 App 下载链接</label>
                    <div class="relative">
                        <span class="absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 transition-colors group-focus-within:text-indigo-500">
                            <i class="fas fa-download"></i>
                        </span>
                        <input type="url" class="w-full pl-12 pr-4 py-3 border border-gray-200 rounded-xl focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 transition-all group" 
                               name="fz_app_download_url" value="<?php echo htmlspecialchars($userrow['fz_app_download_url'] ?? ''); ?>" placeholder="https:// 留空则使用主站「网站信息」里的 App 下载配置">
                    </div>
                </div>
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">分站 App 按钮名称</label>
                    <div class="relative">
                        <span class="absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 transition-colors group-focus-within:text-indigo-500">
                            <i class="fas fa-mobile-alt"></i>
                        </span>
                        <input type="text" class="w-full pl-12 pr-4 py-3 border border-gray-200 rounded-xl focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 transition-all group" 
                               name="fz_app_download_name" value="<?php echo htmlspecialchars($userrow['fz_app_download_name'] ?? ''); ?>" placeholder="如：下载App（留空则默认「下载App」）">
                    </div>
                    <p class="text-sm text-red-600 mt-1">仅当填写了上方下载链接时生效；链接留空则下级首页与主站一致</p>
                </div>
                
                <!-- 用户公告 -->
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">用户公告</label>
                    <div class="relative">
                        <span class="absolute left-4 top-3 text-gray-400 transition-colors group-focus-within:text-indigo-500">
                            <i class="fas fa-bullhorn"></i>
                        </span>
                        <textarea class="w-full pl-12 pr-4 py-3 border border-gray-200 rounded-xl focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 transition-all group" 
                                  name="gonggao" rows="5" placeholder="用于显示下级用户的功能内容，可留空"><?php echo $userrow['gonggao']?></textarea>
                    </div>
                </div>
                
                <!-- 用户弹窗公告 -->
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">用户弹窗公告</label>
                    <div class="relative">
                        <span class="absolute left-4 top-3 text-gray-400 transition-colors group-focus-within:text-indigo-500">
                            <i class="fas fa-bell"></i>
                        </span>
                        <textarea class="w-full pl-12 pr-4 py-3 border border-gray-200 rounded-xl focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 transition-all group" 
                                  name="alert_gonggao" rows="5" placeholder="可留空"><?php echo $userrow['alert_gonggao']?></textarea>
                    </div>
                </div>
                
                <!-- 提交按钮 -->
                <button type="submit" 
                        class="w-full py-3 bg-gradient-to-r from-indigo-600 to-purple-600 hover:from-indigo-700 hover:to-purple-700 text-white font-semibold rounded-xl shadow-lg transition-all duration-300 transform hover:scale-[1.02] active:scale-[0.98] hover:shadow-xl focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2">
                    <i class="fas fa-save mr-2"></i>保存设置
                </button>
            </form>
            
            <!-- 底部链接 -->
            <div class="mt-6 text-center text-sm text-gray-500">
                <a href="javascript:history.back(-1)" class="hover:text-indigo-600 transition-colors duration-300">
                    <i class="fas fa-arrow-left mr-1"></i>返回上一层
                </a>
            </div>
        </div>
    </div>
</div>

<script src="../assets/js/jquery.min.js"></script>
<script type="text/javascript">
// 模态框相关函数
function openModal(title, content, footerCallback) {
    document.getElementById('modalTitle').textContent = title;
    document.getElementById('modalBody').innerHTML = content;
    
    const modalFooter = document.getElementById('modalFooter');
    if (footerCallback) {
        modalFooter.innerHTML = footerCallback();
        modalFooter.classList.remove('hidden');
    } else {
        modalFooter.classList.add('hidden');
    }
    
    document.getElementById('appModal').classList.remove('hidden');
    document.body.style.overflow = 'hidden';
}

function closeModal() {
    document.getElementById('appModal').classList.add('hidden');
    document.body.style.overflow = '';
}

// Toast 提示函数
function showToast(message, type = 'info', duration = 2000) {
    const toastWrap = document.getElementById('toastWrap');
    const toast = document.createElement('div');
    
    let bgClass = 'bg-gray-800';
    if (type === 'success') bgClass = 'bg-green-600';
    if (type === 'error') bgClass = 'bg-red-600';
    if (type === 'warning') bgClass = 'bg-yellow-600';
    
    toast.className = `${bgClass} text-white px-4 py-2 rounded-lg shadow-lg flex items-center gap-2 transform transition-all duration-300 ease-in-out opacity-0 translate-y-[-10px]`;
    toast.innerHTML = `<i class="fas fa-${type === 'success' ? 'check' : type === 'error' ? 'exclamation' : type === 'warning' ? 'exclamation-triangle' : 'info'}"></i><span>${message}</span>`;
    
    toastWrap.appendChild(toast);
    
    // 触发动画
    setTimeout(() => {
        toast.classList.remove('opacity-0', 'translate-y-[-10px]');
    }, 10);
    
    // 自动移除
    setTimeout(() => {
        toast.classList.add('opacity-0', 'translate-y-[-10px]');
        setTimeout(() => {
            toastWrap.removeChild(toast);
        }, 300);
    }, duration);
}

// Loading 遮罩函数
function showLoading() {
    document.getElementById('loadingOverlay').classList.remove('hidden');
}

function hideLoading() {
    document.getElementById('loadingOverlay').classList.add('hidden');
}

    function saveSetting(obj){
        if($('input[name="qq"]').val() == ''){
            showToast('请填写正确的QQ号，非常重要<br>如果忘记平台的登录密码可用这个QQ号找回的', 'error');
            return false;
        }
        showLoading();
        $.ajax({
            type : 'POST',
            url : 'ajax.php?act=site',
            data : $(obj).serialize(),
            dataType : 'json',
            success : function(data) {
                hideLoading();
                if(data.code == 1){
                    openModal('提示', '设置保存成功！', function() {
                        return '<button onclick="window.location.reload()" class="w-full py-2 bg-indigo-600 hover:bg-indigo-700 text-white rounded-lg font-medium transition-colors">确定</button>';
                    });
                }else{
                    showToast(data.msg, 'error');
                }
            },
            error:function(data){
                hideLoading();
                showToast('服务器错误', 'error');
                return false;
            }
        });
    }
</script>

<!-- 通用模态框 -->
<div id="appModal" class="fixed inset-0 z-50 hidden">
    <div class="fixed inset-0 bg-black/50 transition-opacity" onclick="closeModal()"></div>
    <div class="fixed inset-0 flex items-center justify-center p-4">
        <div class="bg-white rounded-2xl shadow-2xl w-full max-w-md max-h-[85vh] flex flex-col relative transform transition-all">
            <div class="flex items-center justify-between px-5 py-4 border-b border-gray-100">
                <h3 id="modalTitle" class="text-lg font-semibold text-gray-800"></h3>
                <button onclick="closeModal()" class="w-8 h-8 flex items-center justify-center rounded-full hover:bg-gray-100 text-gray-400 hover:text-gray-600 transition-colors">
                    <i class="fas fa-times"></i>
                </button>
            </div>
            <div id="modalBody" class="px-5 py-4 overflow-y-auto"></div>
            <div id="modalFooter" class="px-5 py-3 border-t border-gray-100 hidden"></div>
        </div>
    </div>
</div>

