"use client"; import { useState, useEffect } from "react"; import { useRouter } from "next/navigation"; import Link from "next/link"; import { Mic, MicOff, Sparkles, BookOpen, Printer, ArrowLeft, RotateCcw, X } from "lucide-react"; const DRAFT_STORAGE_KEY = "zineDraft"; // Helper to get correct path based on subdomain function useZinePath() { const [isSubdomain, setIsSubdomain] = useState(false); useEffect(() => { setIsSubdomain(window.location.hostname.startsWith("zine.")); }, []); return (path: string) => { if (isSubdomain) { // On subdomain, /zine/create becomes /create return path.replace(/^\/zine/, "") || "/"; } return path; }; } const STYLES = [ { value: "punk-zine", label: "Punk Zine", description: "Xerox texture, high contrast, DIY collage" }, { value: "mycelial", label: "Mycelial", description: "Organic networks, spore patterns, earth tones" }, { value: "minimal", label: "Minimal", description: "Clean lines, white space, modern" }, { value: "collage", label: "Collage", description: "Layered imagery, mixed media" }, { value: "retro", label: "Retro", description: "1970s aesthetic, earth tones" }, ]; const TONES = [ { value: "rebellious", label: "Rebellious", description: "Defiant, punk attitude" }, { value: "regenerative", label: "Regenerative", description: "Hopeful, nature-inspired, healing" }, { value: "playful", label: "Playful", description: "Whimsical, fun, light-hearted" }, { value: "informative", label: "Informative", description: "Educational, factual" }, { value: "poetic", label: "Poetic", description: "Lyrical, metaphorical" }, ]; interface ZineDraft { topic: string; style: string; tone: string; savedAt: string; } export default function ZinePage() { const router = useRouter(); const getPath = useZinePath(); const [topic, setTopic] = useState(""); const [style, setStyle] = useState("mycelial"); const [tone, setTone] = useState("regenerative"); const [isListening, setIsListening] = useState(false); const [isLoading, setIsLoading] = useState(false); const [savedDraft, setSavedDraft] = useState(null); const [showDraftBanner, setShowDraftBanner] = useState(false); // Load saved draft on mount useEffect(() => { try { const saved = localStorage.getItem(DRAFT_STORAGE_KEY); if (saved) { const draft: ZineDraft = JSON.parse(saved); // Only show draft if it has a topic if (draft.topic?.trim()) { setSavedDraft(draft); setShowDraftBanner(true); } } } catch { // Ignore localStorage errors } }, []); // Auto-save draft when form changes useEffect(() => { if (topic.trim()) { const draft: ZineDraft = { topic, style, tone, savedAt: new Date().toISOString(), }; try { localStorage.setItem(DRAFT_STORAGE_KEY, JSON.stringify(draft)); } catch { // Ignore localStorage errors } } }, [topic, style, tone]); const restoreDraft = () => { if (savedDraft) { setTopic(savedDraft.topic); setStyle(savedDraft.style); setTone(savedDraft.tone); setShowDraftBanner(false); } }; const clearDraft = () => { try { localStorage.removeItem(DRAFT_STORAGE_KEY); } catch { // Ignore localStorage errors } setSavedDraft(null); setShowDraftBanner(false); }; const handleVoiceInput = () => { if (!("webkitSpeechRecognition" in window) && !("SpeechRecognition" in window)) { alert("Voice input is not supported in this browser. Try Chrome or Edge."); return; } const SpeechRecognition = (window as any).SpeechRecognition || (window as any).webkitSpeechRecognition; const recognition = new SpeechRecognition(); recognition.continuous = false; recognition.interimResults = false; recognition.lang = "en-US"; recognition.onstart = () => setIsListening(true); recognition.onend = () => setIsListening(false); recognition.onerror = () => setIsListening(false); recognition.onresult = (event: any) => { const transcript = event.results[0][0].transcript; setTopic((prev) => (prev ? prev + " " + transcript : transcript)); }; if (isListening) { recognition.stop(); } else { recognition.start(); } }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!topic.trim()) return; setIsLoading(true); // Store the input in sessionStorage and navigate to create page sessionStorage.setItem("zineInput", JSON.stringify({ topic, style, tone })); router.push(getPath("/zine/create")); }; return (
{/* Back to MycoFi */}
MycoFi
{/* Header */}

MYCOZINE

Transform your ideas into printable 8-page mini-zines with AI

{/* Features */}
AI-Generated
8 Pages
Print Ready
{/* Saved Draft Banner */} {showDraftBanner && savedDraft && (
Saved Draft Found

“{savedDraft.topic.length > 60 ? savedDraft.topic.slice(0, 60) + "..." : savedDraft.topic}”

Saved {new Date(savedDraft.savedAt).toLocaleDateString()} at{" "} {new Date(savedDraft.savedAt).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" })}

)} {/* Main Form */}
{/* Topic Input */}