import { useState } from "react";
import { Button } from "./components/ui/button";
import HomeButton from "./components/ui/homeButton";
import { lazy, Suspense } from "react";
import LandingPage from "./components/LandingPage";

// 동적 import로 EditSheetViewer 로드 (필요할 때만)
const EditSheetViewer = lazy(
  () => import("./components/sheet/EditSheetViewer"),
);

function App() {
  const [showTestViewer, setShowTestViewer] = useState(false);

  const handleGetStarted = () => {
    setShowTestViewer(true);
  };

  const handleDownloadClick = () => {
    // TODO: 다운로드 기능 구현
    console.log("Download clicked");
  };

  const handleAccountClick = () => {
    // TODO: 계정 페이지 이동 기능 구현
    console.log("Account clicked");
  };

  return (
    <div className="min-h-screen">
      {showTestViewer ? (
        // 에디트 뷰어 모드
        <div className="min-h-screen bg-gray-50">
          {/* 헤더 */}
          <header className="bg-white shadow-sm border-b">
            <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
              <div className="flex justify-between items-center h-16">
                <div className="flex items-center">
                  <HomeButton
                    className="ml-0"
                    style={{ position: "absolute", left: "1%" }}
                    onClick={() => {
                      if (window.confirm("랜딩페이지로 돌아가시겠습니까?")) {
                        setShowTestViewer(false);
                      }
                    }}
                  >
                    sheetEasy AI
                  </HomeButton>
                </div>
                <div className="flex items-center space-x-4">
                  <Button
                    variant="outline"
                    size="sm"
                    onClick={() => setShowTestViewer(false)}
                    className="bg-green-500 hover:bg-green-600 text-white border-green-500"
                  >
                    🏠 홈으로
                  </Button>
                  <span className="text-sm text-gray-600">
                    Univer CE 에디트 모드
                  </span>
                </div>
              </div>
            </div>
          </header>

          {/* 메인 콘텐츠 */}
          <main className="h-[calc(100vh-4rem)]">
            <div className="h-full">
              <Suspense
                fallback={
                  <div className="h-full flex items-center justify-center">
                    <div className="text-center">
                      <div className="animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600 mx-auto mb-4"></div>
                      <p className="text-gray-600">🚀 그리드 그리는 중...</p>
                    </div>
                  </div>
                }
              >
                <EditSheetViewer />
              </Suspense>
            </div>
          </main>
        </div>
      ) : (
        // 랜딩페이지 모드
        <LandingPage
          onGetStarted={handleGetStarted}
          onDownloadClick={handleDownloadClick}
          onAccountClick={handleAccountClick}
        />
      )}
    </div>
  );
}

export default App;
