import { Button } from "@/components/ui/button";

//import {useSettingStore} from "@/lib/store/useSettings";

import { Tag } from "lucide-react";
import { useState } from "react";
import { toast } from "sonner";
import { useAuth } from "@/lib/authClient";
import type { LotType } from "../../../-types/lots";
import { manualPrintLabels } from "./ManualPrintLabel";

export default function ManualPrint({ lot }: { lot: LotType }) {
	const { session } = useAuth();
	const [printing, setPrinting] = useState(false);
	//const {settings} = useSettingStore();
	//const server = settings.filter((n) => n.name === "server")[0]?.value;
	//const serverPort = settings.filter((n) => n.name === "serverPort")[0]?.value;
	//const serverUrl = `http://${server}:${serverPort}`;

	const handlePrintLabel = async (lot: LotType) => {
		setPrinting(true);
		const labels: any = await manualPrintLabels(lot, session?.user);

		if (labels.success) {
			toast.success(labels.message);
			setTimeout(() => {
				setPrinting(false);
			}, 5 * 1000);
		} else {
			toast.error(labels.message);
			setTimeout(() => {
				setPrinting(false);
			}, 5 * 1000);
		}
	};
	return (
		<Button
			variant="outline"
			size="icon"
			onClick={() => handlePrintLabel(lot)}
			disabled={printing}
		>
			<Tag className="h-[16px] w-[16px]" />
		</Button>
	);
}
