import axios from "@/config/axios";
import axios2 from "axios";

export const getLog = async (token, laporan_id) => {
	try {
		let url = `/pemantauan/${laporan_id}?all=true`;
		const res = await axios.get(url, {
			headers: {
				Authorization: token,
			},
		});
		return res.data;
	} catch (error) {
		console.log("error", error);
		return false;
	}
};

export const getLogPT = async (token) => {
	try {
		let url = `/pemantauan/pt`;
		const res = await axios.get(url, {
			headers: {
				Authorization: token,
			},
		});
		return res.data;
	} catch (error) {
		console.log("error", error);
		return false;
	}
};

export const getLogPublic = async ({ no_hp, no_laporan }) => {
	try {
		const res = await axios.get(`/public/pemantauan?no_hp=${no_hp}&no_laporan=${no_laporan}`);
		return res.data;
	} catch (error) {
		console.log("error", error);
		return false;
	}
};

export const createLog = async (token, data) => {
	try {
		const jsonip = await axios2.get("https://jsonip.com", { mode: "cors" });
		const res = await axios.post("/log", { os: navigator.userAgentData.platform, ipv4: jsonip.data.ip, ...data }, { headers: { Authorization: token } });
		return res.data;
	} catch (error) {
		console.log("error", error);
		return false;
	}
};

export const getLog2 = async (token) => {
	try {
		const res = await axios.get(`/log`, { headers: { Authorization: token } });
		return res.data;
	} catch (error) {
		console.log("error", error);
		return false;
	}
};
