import { useEffect, useState } from "react";

import { http } from "../services/http.service";

export const useVersion = () => {
	const [version, setVersion] = useState("1.0.0");
	const { get } = http;

	useEffect(() => {
		const load = async () => {
			try {
				const result = await get<{ version: string }>("/api/version");
				setVersion(result.version);
			} catch (error) {
				console.error("Error loading version:", error);
			}
		};

		load();
	}, []);

	return {
		version,
	};
};
