// ============================================================
// LegalTextModal — 协议/法律文本展示弹窗
// 从 src/assets/legal/ 加载 .txt 文件，主题适配渲染
// ============================================================

import { Modal, Typography } from 'antd';
import { FileTextOutlined } from '@ant-design/icons';

import { useTheme } from '@/app/providers/ThemeProvider';

// Vite ?raw 导入：将 .txt 内容作为字符串直接内联
import serviceAgreement from '@/assets/legal/用户服务协议.txt?raw';
import pointsAgreement from '@/assets/legal/积分充值服务协议.txt?raw';

const { Paragraph } = Typography;

/** 协议名称 → 文本内容映射 */
const legalTexts: Record<string, { title: string; content: string }> = {
   service: { title: '用户服务协议', content: serviceAgreement },
   points: { title: '积分充值服务协议', content: pointsAgreement },
};

interface LegalTextModalProps {
   open: boolean;
   /** 协议标识：'service' | 'points' */
   type: 'service' | 'points';
   onClose: () => void;
}

export function LegalTextModal({ open, type, onClose }: LegalTextModalProps) {
   const { isDark } = useTheme();
   const legal = legalTexts[type];

   if (!legal) return null;

   return (
      <Modal
         open={open}
         onCancel={onClose}
         footer={null}
         width={640}
         centered
         title={
            <span className="flex items-center gap-2">
               <FileTextOutlined />
               {legal.title}
            </span>
         }
         styles={{
            body: {
               maxHeight: '60vh',
               overflowY: 'auto',
               padding: '20px 24px',
               background: isDark ? '#1A1730' : '#FFFFFF',
               color: isDark ? '#E8E6F0' : '#1E1B4B',
               fontSize: 14,
               lineHeight: 2,
               whiteSpace: 'pre-wrap',
               wordBreak: 'break-word',
               fontFamily: 'var(--font-family-base)',
            },
         }}
      >
         <Paragraph
            style={{
               color: isDark ? '#E8E6F0' : '#1E1B4B',
               fontSize: 14,
               lineHeight: 2,
               whiteSpace: 'pre-wrap',
               margin: 0,
            }}
         >
            {legal.content}
         </Paragraph>
      </Modal>
   );
}
