// Popup entry
import { ConfigManager } from '../shared/config.js';

console.log('[SaladDict] Popup opened');

/**
 * 初始化 Popup
 */
async function initPopup() {
  const toggle = document.getElementById('enableSelectionToggle');
  
  // 加载当前状态
  const isEnabled = await ConfigManager.get('general.enableSelection', true);
  
  // 设置开关状态
  if (isEnabled) {
    toggle.classList.add('active');
  }
  
  // 监听开关点击
  toggle.addEventListener('click', async () => {
    const newState = !toggle.classList.contains('active');
    
    // 更新 UI
    toggle.classList.toggle('active');
    
    // 保存配置
    await ConfigManager.set('general.enableSelection', newState);
    
    console.log('[SaladDict] Selection enabled:', newState);
  });
  
  console.log('[SaladDict] Popup initialized, selection enabled:', isEnabled);
}

// DOM 就绪后初始化
document.addEventListener('DOMContentLoaded', initPopup);
