/**
 * 充电桩大盘 - 引导弹窗模块
 */

const STORAGE_KEY = 'guide_dismissed_until';
const DISMISS_DURATION = 30 * 24 * 60 * 60 * 1000; // 30 天（每月显示一次）

/**
 * 检查是否需要显示引导
 */
export function shouldShowGuide() {
  try {
    const dismissedUntil = localStorage.getItem(STORAGE_KEY);
    if (dismissedUntil) {
      return Date.now() > parseInt(dismissedUntil, 10);
    }
    return true;
  } catch (e) {
    return true;
  }
}

/**
 * 显示引导弹窗
 */
export function showGuideModal() {
  const modal = document.getElementById('guide-modal');
  if (modal) {
    modal.classList.add('show');
  }
}

/**
 * 隐藏引导弹窗（也记录月度 dismiss，确保当月不再弹）
 */
export function hideGuideModal() {
  try {
    const dismissUntil = Date.now() + DISMISS_DURATION;
    localStorage.setItem(STORAGE_KEY, dismissUntil.toString());
  } catch (e) {
    console.warn('[引导] 保存状态失败', e);
  }
  const modal = document.getElementById('guide-modal');
  if (modal) {
    modal.classList.remove('show');
  }
}


/**
 * 初始化引导弹窗
 */
export function initGuideModal() {
  if (shouldShowGuide()) {
    // 延迟显示，让主界面先渲染完成
    setTimeout(() => {
      showGuideModal();
    }, 500);
  }
}
