"use client"; import { useRef, useState } from "react"; import { Download, Upload, X } from "lucide-react"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { useI18n } from "./I18nProvider"; export function ExportMap({ id, disabled = false, }: { id: string; disabled?: boolean; }) { const { t } = useI18n(); const [busy, setBusy] = useState(false); const [status, setStatus] = useState(""); const [error, setError] = useState(""); async function download() { setBusy(true); setError(""); try { const { exportMap } = await import("@/lib/map-transfer"); await exportMap(id, (message, values) => setStatus(t(message, values))); setStatus(t("Map ZIP downloaded. Share it with a friend.")); } catch (error) { setStatus(""); setError(error instanceof Error ? error.message : "Could not export map"); } finally { setBusy(false); } } return (
{status && (

{status}

)} {error && (

{t(error)}

)}
); } export function ImportMap({ signedIn }: { signedIn: boolean }) { const { t } = useI18n(); const router = useRouter(); const dialog = useRef(null); const [busy, setBusy] = useState(false); const [status, setStatus] = useState(""); const [error, setError] = useState(""); async function upload(file: File) { setBusy(true); setError(""); try { const { importMap } = await import("@/lib/map-transfer"); const id = await importMap(file, (message, values) => setStatus(t(message, values)), ); dialog.current?.close(); router.push(`/dashboard/${id}`); router.refresh(); } catch (error) { setStatus(""); setError(error instanceof Error ? error.message : "Could not import map"); } finally { setBusy(false); } } return ( <> { if (busy) event.preventDefault(); }} >

{t("Import a shared map")}

{t( "Choose a MineGeo ZIP exported by the map owner. Play it privately without moderator review. The original owner keeps publication rights. Maximum size: 256 MB.", )}

{signedIn ? ( ) : ( {t("Sign in to import")} )} {status &&

{status}

} {error && (

{t(error)}

)}
); }