All files / src/components SplashScreen.tsx

0% Statements 0/194
0% Branches 0/1
0% Functions 0/1
0% Lines 0/194

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
import { Download, RefreshCw, Play } from "lucide-react";
import type { SplashScreenState, SplashStep, StepStatus } from "@/hooks/useSplashScreen";
import type { UpdateState } from "@/hooks/useUpdateChecker";
import { openUrl } from "@/lib/openUrl";
import bmcQr from "@/assets/bmc-qr.png";
 
const BMC_URL = "https://buymeacoffee.com/MaxMB15";
 
interface SplashScreenProps {
	splash: SplashScreenState;
	updateState: UpdateState;
}
 
export const SplashScreen = ({ splash, updateState }: SplashScreenProps) => {
	const { steps, allDone, progress, update, hasProviders, dismiss } = splash;
 
	return (
		<div className="fixed inset-0 z-50 flex bg-background">
			<LeftPanel
				steps={steps}
				allDone={allDone}
				progress={progress}
				update={update}
				hasProviders={hasProviders}
				onDismiss={dismiss}
				updateState={updateState}
			/>
			<RightPanel />
		</div>
	);
};
 
// ── Left panel ──────────────────────────────────────────────────────────────
 
interface LeftPanelProps {
	steps: SplashStep[];
	allDone: boolean;
	progress: number;
	update: UpdateState["update"];
	hasProviders: boolean;
	onDismiss: () => void;
	updateState: UpdateState;
}
 
const LeftPanel = ({
	steps,
	allDone,
	progress,
	update,
	hasProviders,
	onDismiss,
	updateState,
}: LeftPanelProps) => {
	const { installing, progress: installProgress, error, install: handleInstall } = updateState;
 
	return (
		<div className="flex-1 flex flex-col items-center justify-center gap-10 px-16 border-r border-border">
			{/* Logo + branding */}
			<div className="flex flex-col items-center gap-4 text-center">
				<div className="w-16 h-16 rounded-2xl bg-primary flex items-center justify-center text-primary-foreground shadow-lg">
					<Play className="w-7 h-7 fill-current" />
				</div>
				<div>
					<h1 className="text-2xl font-bold tracking-tight">Max Video Player</h1>
					<p className="text-sm text-muted-foreground mt-0.5">Open Source IPTV Player</p>
				</div>
			</div>
 
			{/* Content area */}
			<div className="w-full max-w-sm flex flex-col gap-6">
				{!hasProviders ? (
					<div className="text-center space-y-2">
						<p className="text-base font-semibold">Welcome to Max Video Player</p>
						<p className="text-sm text-muted-foreground leading-relaxed">
							Add a playlist in the Playlists tab to get started.
						</p>
					</div>
				) : (
					<>
						{/* Progress bar */}
						<div className="space-y-3">
							<div className="h-1.5 w-full rounded-full bg-secondary overflow-hidden">
								<div
									className="h-full bg-primary rounded-full transition-all duration-500 ease-out"
									style={{ width: `${Math.round(progress * 100)}%` }}
								/>
							</div>
						</div>
 
						{/* Step list */}
						<div className="space-y-3">
							{steps.map((step) => (
								<StepRow key={step.id} step={step} />
							))}
						</div>
					</>
				)}
 
				{/* No-providers: show update step */}
				{!hasProviders && steps.length > 0 && (
					<div className="space-y-3">
						{steps.map((step) => (
							<StepRow key={step.id} step={step} />
						))}
					</div>
				)}
 
				{/* Update card */}
				{allDone && update && (
					<div className="rounded-xl bg-primary/10 border border-primary/25 px-5 py-4 space-y-1.5">
						<p className="text-sm font-semibold text-primary">
							Update available — v{update.version}
						</p>
						<p className="text-xs text-muted-foreground leading-relaxed">
							{update.body ?? "A new version is ready to install."}
						</p>
						{installing && installProgress !== null && (
							<div className="mt-2 h-1 w-full rounded-full bg-secondary overflow-hidden">
								<div
									className="h-full bg-primary transition-all duration-200"
									style={{ width: `${installProgress}%` }}
								/>
							</div>
						)}
						{error && <p className="mt-1.5 text-xs text-destructive">{error}</p>}
					</div>
				)}
 
				{/* Action row */}
				<div className="flex items-center justify-center gap-3 pt-2">
					{allDone && update ? (
						<>
							<button
								type="button"
								onClick={handleInstall}
								disabled={installing}
								className="flex items-center gap-2 text-sm font-semibold bg-primary text-primary-foreground px-5 py-2.5 rounded-xl hover:bg-primary/90 transition-colors disabled:opacity-60"
							>
								{installing ? (
									<RefreshCw className="h-4 w-4 animate-spin" />
								) : (
									<Download className="h-4 w-4" />
								)}
								{installing
									? installProgress !== null
										? `Downloading… ${installProgress}%`
										: "Installing…"
									: "Install Update"}
							</button>
							<button
								type="button"
								onClick={onDismiss}
								className="text-sm text-muted-foreground underline hover:text-foreground transition-colors"
							>
								Skip for now →
							</button>
						</>
					) : (
						<button
							type="button"
							onClick={onDismiss}
							disabled={!allDone}
							className="text-sm font-semibold bg-primary text-primary-foreground px-6 py-2.5 rounded-xl hover:bg-primary/90 transition-colors disabled:opacity-40 disabled:cursor-not-allowed"
						>
							Get Started →
						</button>
					)}
				</div>
			</div>
		</div>
	);
};
 
// ── Step row ──────────────────────────────────────────────────────────────
 
const StepRow = ({ step }: { step: SplashStep }) => {
	return (
		<div className="flex items-center gap-3 text-sm">
			<StepIcon status={step.status} />
			<span
				className={
					step.status === "done"
						? "text-foreground"
						: step.status === "error"
							? "text-amber-500"
							: step.status === "active"
								? "text-primary font-medium"
								: "text-muted-foreground"
				}
			>
				{step.label}
			</span>
		</div>
	);
};
 
const StepIcon = ({ status }: { status: StepStatus }) => {
	if (status === "done") {
		return (
			<span className="w-5 h-5 rounded-full bg-green-500 flex items-center justify-center shrink-0">
				<svg viewBox="0 0 12 12" fill="none" className="w-3 h-3">
					<path
						d="M2 6l3 3 5-5"
						stroke="white"
						strokeWidth="1.5"
						strokeLinecap="round"
						strokeLinejoin="round"
					/>
				</svg>
			</span>
		);
	}
	if (status === "error") {
		return (
			<span className="w-5 h-5 rounded-full bg-amber-500 flex items-center justify-center shrink-0">
				<svg viewBox="0 0 12 12" fill="none" className="w-3 h-3">
					<path
						d="M6 3v4M6 8.5v.5"
						stroke="white"
						strokeWidth="1.5"
						strokeLinecap="round"
					/>
				</svg>
			</span>
		);
	}
	if (status === "active") {
		return <RefreshCw className="w-5 h-5 text-primary animate-spin shrink-0" />;
	}
	return <span className="w-5 h-5 rounded-full border-2 border-border shrink-0" />;
};
 
// ── Right panel ───────────────────────────────────────────────────────────
 
const RightPanel = () => {
	return (
		<div className="w-80 flex flex-col items-center justify-center gap-5 px-8 bg-card border-l border-border">
			{/* Header */}
			<div className="flex flex-col items-center gap-2 text-center">
				<span className="text-4xl">☕</span>
				<h2 className="text-lg font-bold">Support free & open source software</h2>
				<p className="text-xs text-muted-foreground">No account needed · takes 2 seconds</p>
			</div>
 
			{/* QR code */}
			<button
				type="button"
				onClick={() => openUrl(BMC_URL)}
				className="w-40 rounded-xl overflow-hidden border border-border hover:border-primary transition-colors"
				aria-label="Scan to donate via Buy Me a Coffee"
			>
				<img src={bmcQr} alt="Buy Me a Coffee QR code" className="w-full h-auto" />
			</button>
 
			{/* Support button */}
			<button
				type="button"
				onClick={() => openUrl(BMC_URL)}
				className="w-full bg-[#5F7FFF] hover:bg-[#4a6cf0] text-white font-semibold py-3 rounded-xl transition-colors text-sm"
			>
				Buy me a coffee
			</button>
		</div>
	);
};