import React from 'react';
import { useAuth } from '@/client/home/hooks/AuthProvider';
import { useNavigate } from 'react-router-dom';

const HomePage: React.FC = () => {
  const { user } = useAuth();
  const navigate = useNavigate();

  return (
    <div className="min-h-screen bg-gradient-to-br from-blue-50 via-white to-purple-50 flex flex-col">
      {/* 顶部导航 */}
      <header className="bg-white shadow-sm border-b border-gray-100 fixed w-full z-10">
        <div className="container mx-auto px-4 py-4 flex justify-between items-center">
          <div className="flex items-center space-x-2">
            <div className="w-8 h-8 bg-gradient-to-r from-blue-600 to-purple-600 rounded-lg flex items-center justify-center">
              <svg xmlns="http://www.w3.org/2000/svg" className="h-5 w-5 text-white" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z" />
              </svg>
            </div>
            <h1 className="text-xl font-bold text-gray-900">云存储平台</h1>
          </div>
          
          {user ? (
            <div className="flex items-center space-x-4">
              <a
                href="/admin/files"
                className="text-sm text-gray-600 hover:text-blue-600 transition-colors"
              >
                文件管理
              </a>
              <div className="flex items-center cursor-pointer hover:bg-gray-50 rounded-lg px-3 py-2 transition-colors" onClick={() => navigate(`/member`)}>
                <div className="w-8 h-8 rounded-full bg-gradient-to-r from-blue-500 to-purple-500 flex items-center justify-center mr-2">
                  <span className="text-white text-sm font-medium">{user.username.charAt(0).toUpperCase()}</span>
                </div>
                <span className="hidden md:inline text-sm text-gray-700">{user.username}</span>
              </div>
            </div>
          ) : (
            <div className="flex space-x-3">
              <button 
                onClick={() => navigate('/login')}
                className="px-4 py-2 rounded-lg text-sm text-blue-600 hover:bg-blue-50 transition-colors"
              >
                登录
              </button>
              <button 
                onClick={() => navigate('/register')}
                className="px-4 py-2 rounded-lg text-sm bg-gradient-to-r from-blue-600 to-purple-600 text-white hover:from-blue-700 hover:to-purple-700 transition-all shadow-sm hover:shadow-md"
              >
                免费注册
              </button>
            </div>
          )}
        </div>
      </header>
      
      {/* 主内容区 */}
      <main className="flex-grow container mx-auto px-4 pt-24 pb-12">
        {/* 英雄区域 */}
        <div className="text-center py-12">
          <h2 className="text-4xl md:text-5xl font-bold text-gray-900 mb-6">
            安全、高效的
            <span className="text-transparent bg-clip-text bg-gradient-to-r from-blue-600 to-purple-600"> 文件存储平台</span>
          </h2>
          <p className="text-lg text-gray-600 mb-8 max-w-2xl mx-auto">
            基于 MinIO 构建的企业级云存储解决方案，支持大文件分片上传、断点续传、
            文件预览与分享，为您的数据提供银行级安全保障。
          </p>
          
          <div className="flex flex-col sm:flex-row gap-4 justify-center">
            <a
              href={user ? '/admin/files' : '/register'}
              className="px-8 py-3 rounded-lg bg-gradient-to-r from-blue-600 to-purple-600 text-white font-medium hover:from-blue-700 hover:to-purple-700 transition-all shadow-lg hover:shadow-xl"
            >
              {user ? '进入文件管理' : '立即开始使用'}
            </a>
            <a
              href="/admin"
              className="px-8 py-3 rounded-lg border border-gray-300 text-gray-700 font-medium hover:bg-gray-50 transition-colors"
            >
              管理后台
            </a>
          </div>
        </div>

        {/* 功能特性 */}
        <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mt-16">
          <div className="bg-white rounded-xl p-6 shadow-sm border border-gray-100 hover:shadow-md transition-shadow">
            <div className="w-12 h-12 bg-blue-100 rounded-lg flex items-center justify-center mb-4">
              <svg xmlns="http://www.w3.org/2000/svg" className="h-6 w-6 text-blue-600" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12" />
              </svg>
            </div>
            <h3 className="font-semibold text-lg mb-2">大文件上传</h3>
            <p className="text-gray-600 text-sm">支持分片上传，单个文件最大可达 5TB，断点续传不中断</p>
          </div>
          
          <div className="bg-white rounded-xl p-6 shadow-sm border border-gray-100 hover:shadow-md transition-shadow">
            <div className="w-12 h-12 bg-green-100 rounded-lg flex items-center justify-center mb-4">
              <svg xmlns="http://www.w3.org/2000/svg" className="h-6 w-6 text-green-600" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z" />
              </svg>
            </div>
            <h3 className="font-semibold text-lg mb-2">文件管理</h3>
            <p className="text-gray-600 text-sm">完整的文件生命周期管理，支持文件预览、下载、分享和版本控制</p>
          </div>
          
          <div className="bg-white rounded-xl p-6 shadow-sm border border-gray-100 hover:shadow-md transition-shadow">
            <div className="w-12 h-12 bg-purple-100 rounded-lg flex items-center justify-center mb-4">
              <svg xmlns="http://www.w3.org/2000/svg" className="h-6 w-6 text-purple-600" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z" />
              </svg>
            </div>
            <h3 className="font-semibold text-lg mb-2">安全保障</h3>
            <p className="text-gray-600 text-sm">端到端加密存储，多重备份机制，确保数据安全可靠</p>
          </div>
          
          <div className="bg-white rounded-xl p-6 shadow-sm border border-gray-100 hover:shadow-md transition-shadow">
            <div className="w-12 h-12 bg-orange-100 rounded-lg flex items-center justify-center mb-4">
              <svg xmlns="http://www.w3.org/2000/svg" className="h-6 w-6 text-orange-600" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M8 7h12m0 0l-4-4m4 4l-4 4m0 6H4m0 0l4 4m-4-4l4-4" />
              </svg>
            </div>
            <h3 className="font-semibold text-lg mb-2">多端同步</h3>
            <p className="text-gray-600 text-sm">支持Web、移动端等多平台访问，随时随地管理您的文件</p>
          </div>

          {/* 供应链可视化大屏 */}
          <div
            className="bg-white rounded-xl p-6 shadow-sm border border-gray-100 hover:shadow-md transition-shadow cursor-pointer"
            onClick={() => navigate('/supply-chain/grain-oil')}
          >
            <div className="w-12 h-12 bg-indigo-100 rounded-lg flex items-center justify-center mb-4">
              <svg xmlns="http://www.w3.org/2000/svg" className="h-6 w-6 text-indigo-600" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z" />
              </svg>
            </div>
            <h3 className="font-semibold text-lg mb-2">供应链可视化</h3>
            <p className="text-gray-600 text-sm">粮食油脂供应链大屏展示，实时监控产业链运行状态</p>
          </div>

          {/* 财务数据可视化大屏 */}
          <div
            className="bg-white rounded-xl p-6 shadow-sm border border-gray-100 hover:shadow-md transition-shadow cursor-pointer"
            onClick={() => navigate('/financial-dashboard')}
          >
            <div className="w-12 h-12 bg-emerald-100 rounded-lg flex items-center justify-center mb-4">
              <svg xmlns="http://www.w3.org/2000/svg" className="h-6 w-6 text-emerald-600" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z" />
              </svg>
            </div>
            <h3 className="font-semibold text-lg mb-2">财务数据可视化</h3>
            <p className="text-gray-600 text-sm">财务指标大屏展示，直观查看资产、利润、收入等关键数据</p>
          </div>
        </div>

        {/* 技术架构 */}
        <div className="mt-16 bg-white rounded-xl p-8 shadow-sm border border-gray-100">
          <h3 className="text-2xl font-bold text-center mb-8">技术架构</h3>
          <div className="grid grid-cols-1 md:grid-cols-3 gap-8">
            <div className="text-center">
              <div className="w-16 h-16 bg-blue-100 rounded-full flex items-center justify-center mx-auto mb-4">
                <span className="text-2xl font-bold text-blue-600">R</span>
              </div>
              <h4 className="font-semibold mb-2">React 18</h4>
              <p className="text-sm text-gray-600">现代化的前端框架，提供流畅的用户体验</p>
            </div>
            <div className="text-center">
              <div className="w-16 h-16 bg-green-100 rounded-full flex items-center justify-center mx-auto mb-4">
                <span className="text-2xl font-bold text-green-600">M</span>
              </div>
              <h4 className="font-semibold mb-2">MinIO</h4>
              <p className="text-sm text-gray-600">高性能对象存储，支持S3协议的标准云存储</p>
            </div>
            <div className="text-center">
              <div className="w-16 h-16 bg-purple-100 rounded-full flex items-center justify-center mx-auto mb-4">
                <span className="text-2xl font-bold text-purple-600">T</span>
              </div>
              <h4 className="font-semibold mb-2">TypeScript</h4>
              <p className="text-sm text-gray-600">类型安全的开发体验，提升代码质量和可维护性</p>
            </div>
          </div>
        </div>

        {/* 文件管理功能预览 */}
        <div className="mt-16">
          <div className="text-center mb-8">
            <h3 className="text-2xl font-bold mb-4">文件管理功能一览</h3>
            <p className="text-gray-600">完整的文件生命周期管理解决方案</p>
          </div>
          
          <div className="grid grid-cols-1 md:grid-cols-2 gap-8">
            <div className="bg-white rounded-xl p-6 shadow-sm border border-gray-100">
              <h4 className="font-semibold text-lg mb-4 flex items-center">
                <svg xmlns="http://www.w3.org/2000/svg" className="h-5 w-5 mr-2 text-blue-600" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                  <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10" />
                </svg>
                核心功能
              </h4>
              <ul className="space-y-2 text-sm text-gray-600">
                <li>• 支持多种文件格式上传（图片、文档、视频、音频等）</li>
                <li>• 大文件分片上传，支持断点续传</li>
                <li>• 文件预览功能（图片、PDF、文本等）</li>
                <li>• 文件搜索和分类管理</li>
                <li>• 文件分享和权限控制</li>
              </ul>
            </div>
            
            <div className="bg-white rounded-xl p-6 shadow-sm border border-gray-100">
              <h4 className="font-semibold text-lg mb-4 flex items-center">
                <svg xmlns="http://www.w3.org/2000/svg" className="h-5 w-5 mr-2 text-green-600" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                  <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
                </svg>
                技术特性
              </h4>
              <ul className="space-y-2 text-sm text-gray-600">
                <li>• RESTful API 设计，支持分页查询</li>
                <li>• 文件元数据存储（类型、大小、描述等）</li>
                <li>• 用户关联，支持个人文件管理</li>
                <li>• 时间戳记录，完整的操作日志</li>
                <li>• 响应式设计，适配多端访问</li>
              </ul>
            </div>
          </div>
        </div>
      </main>
      
      {/* 页脚 */}
      <footer className="bg-white border-t border-gray-100 py-8">
        <div className="container mx-auto px-4">
          <div className="text-center">
            <p className="text-gray-600 mb-4">
              基于 MinIO 的企业级云存储解决方案
            </p>
            <div className="flex justify-center space-x-6 text-sm">
              <a href="/admin" className="text-blue-600 hover:text-blue-700 transition-colors">管理后台</a>
              <a href="/ui" className="text-blue-600 hover:text-blue-700 transition-colors">API 文档</a>
            </div>
            <p className="text-gray-400 text-xs mt-4">
              © {new Date().getFullYear()} 云存储平台. Built with React, TypeScript & MinIO
            </p>
          </div>
        </div>
      </footer>
    </div>
  );
};

export default HomePage;