// 1. 生成演示大列表数据 (异步填充)
const generateListData = () => {
    const data = [];
    data.push({ id: 'r1', label: '研发中心', icon: 'building', parent: '', group: 'group1' });
    data.push({ id: 'r2', label: '创意中心', icon: 'brush', parent: '', group: 'group2' });
    for (let i = 1; i <= 3; i++) {
        data.push({ id: `dev-${i}`, label: `开发 ${i} 组`, parent: 'r1', group: 'group1' });
        data.push({ id: `design-${i}`, label: `设计 ${i} 组`, parent: 'r2', group: 'group2' });
    }
    for (let i = 1; i <= 100; i++) {
        data.push({ id: `user-${i}`, label: `成员 ${i}`, parent: i <= 50 ? 'dev-1' : 'design-1', icon: 'person' });
    }
    State.listData = data;
};

generateListData();

// 2. 业务逻辑
window.resetFormData = () => {
    Object.assign(State.formData, {
        username: 'ApigoUser',
        dateRange: '2026-06-01',
        endDate: '2026-06-07',
        theme: '#0d6efd',
        icon: 'lightning-charge',
        tags: ['Fast', 'Powerful', 'Easy'],
        role: 'admin',
        gender: ['男'],
        notify: true
    });
};

window.showComplexDialog = async () => {
    const result = await UI.showDialog({
        title: '系统升级确认',
        message: '<p>检测到有新版本可用，是否立即升级？</p><div class="alert alert-warning">升级期间服务可能会短暂中断。</div>',
        buttons: ['以后再说', '详细了解', '立即升级'],
        type: 'warning'
    });
    if (result === 3) UI.toast('开始升级...', { type: 'success' });
    else if (result === 2) UI.alert('当前版本: v1.0.11\n目标版本: v1.1.0\n更新内容: 修复了若干已知 Bug。');
};

window.testHTTP = async () => {
    UI.toast('正在发起请求...');
    const resp = await HTTP.get({ url: 'https://jsonplaceholder.typicode.com/todos/1' });
    if (resp.ok) UI.alert('HTTP 请求成功:\n' + JSON.stringify(resp.result, null, 2));
    else UI.toast('请求失败: ' + resp.error, { type: 'danger' });
};
