import { Button } from "@/components/ui/button";
import {
    Tooltip,
    TooltipContent,
    TooltipProvider,
    TooltipTrigger,
} from "@/components/ui/tooltip";
import axios from "axios";
import { Octagon } from "lucide-react";

export default function StopServer(plantData: any) {
    const token = localStorage.getItem("auth_token");
    const handleStopServer = async (plant: string) => {
        let data: any = {
            processType: "stop",
            plantToken: plant,
        };
        const url: string = window.location.host.split(":")[0];
        if (url === "localhost") {
            data = { ...data, remote: "true" };
        }
        try {
            const res = await axios.post("/api/server/serviceprocess", data, {
                headers: { Authorization: `Bearer ${token}` },
            });

            console.log(res);
        } catch (error) {
            console.log(error);
        }
    };
    return (
        <div>
            <TooltipProvider>
                <Tooltip>
                    <TooltipTrigger asChild>
                        <Button
                            variant="destructive"
                            size={"icon"}
                            onClick={() =>
                                handleStopServer(plantData.plantToken)
                            }
                        >
                            <Octagon />
                        </Button>
                    </TooltipTrigger>
                    <TooltipContent>
                        <p>Stop Server ... Needs added still</p>
                    </TooltipContent>
                </Tooltip>
            </TooltipProvider>
        </div>
    );
}
