import axios from "@/config/axios";

export const getPT = async (token, params) => {
	try {
		let url = "/pt";
		if (params) {
			url += "?";
			if (params.search || params.pembina) {
				const parseURL = [];
				if (params.search) parseURL.push(`search=${params.search}`);
				if (params.pembina) parseURL.push(`pembina=${params.pembina}`);
				url += parseURL.join("&");
			}
		}
		const response = await axios.get(url, {
			headers: {
				Authorization: token,
			},
		});
		return response.data;
	} catch (error) {
		console.log("error", error);
		return false;
	}
};

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

export const ptPublic = async (params) => {
	try {
		let url = "/public/pt";
		if (params) {
			url += "?";
			if (params.search) {
				const parseURL = [];
				if (params.search) parseURL.push(`search=${params.search}`);
				url += parseURL.join("&");
			}
		}
		const response = await axios.get(url);
		return response.data;
	} catch (error) {
		console.log("error", error);
		return false;
	}
};

export const getPembina = async (token, params) => {
	try {
		let url = "/lembaga";
		if (params) {
			url += "?";
			if (params.search) {
				url += `search=${params.search}`;
			}
		}
		const response = await axios.get(url, {
			headers: {
				Authorization: token,
			},
		});
		return response.data;
	} catch (error) {
		console.log("error", error);
		return false;
	}
};
