
// --- Cloud Config ---
var CLOUD_TYPES = [
  {type:'quark',label:'夸克网盘',icon:'/admin/icons/quark.png'},
  {type:'baidu',label:'百度网盘',icon:'/admin/icons/baidu.png'},
  {type:'aliyun',label:'阿里云盘',icon:'/admin/icons/aliyun.png'},
  {type:'115',label:'115网盘',icon:'/admin/icons/115.png'},
  {type:'tianyi',label:'天翼云盘',icon:'/admin/icons/tianyi.png'},
  {type:'123pan',label:'123云盘',icon:'/admin/icons/123pan.png'},
  {type:'uc',label:'UC网盘',icon:'/admin/icons/uc.png'},
  {type:'xunlei',label:'迅雷网盘',icon:'/admin/icons/xunlei.png'},
  {type:'pikpak',label:'PikPak',icon:'/admin/icons/pikpak.png'},
  {type:'magnet',label:'磁力链接',icon:'🧲'},
  {type:'ed2k',label:'电驴链接',icon:'🔗'},
  {type:'others',label:'其他',icon:'⬜'}
];
var QR_TYPES = ['quark','baidu'];
var __cloudToggles = {};
var __qrType = '', __qrSession = '', __qrCookie = '', __qrTimer = null;

function page_cloud_config(c){
  c.innerHTML = '<div class="loading">加载中...</div>';
  Promise.all([
    api('/api/admin/system-configs').catch(function(e){ console.error(e); return {}; }),
    api('/api/admin/cloud-configs').catch(function(e){ console.error(e); return []; })
  ]).then(function(res){
    var d = res[0]||{}, accounts = res[1]||[];
    __cloudToggles = {};
    CLOUD_TYPES.forEach(function(ct){
      var v = d['cloud_type_'+ct.type+'_enabled'];
      __cloudToggles[ct.type] = v===undefined ? (ct.type!=='others') : (v==='true'||v==='1');
    });
    renderCloudPage(c, accounts);
  }).catch(function(e){
    c.innerHTML = '<div class="card"><p style="color:var(--danger)">加载失败: '+e.message+'</p></div>';
  });
}

