import { fetchData } from '@/lib/data-service'; export const fetchProductData = async (url: string, authToken: string) => { try { return await fetchData(url, { headers: { Authorization: `Bearer ${authToken}` }, credentials: "include", }); } catch (error) { console.error("Error fetching product data:", error); throw error; } }; export const saveProductData = async ( url: string, data: any, authToken: string, method: "POST" | "PUT" = "POST" ) => { try { return await fetchData(url, { method, headers: { Authorization: `Bearer ${authToken}`, "Content-Type": "application/json", }, credentials: "include", body: JSON.stringify(data), }); } catch (error) { console.error("Error saving product data:", error); throw error; } }; export const saveProductImage = async(url: string, file:File, authToken: string) => { try{ const formData = new FormData(); formData.append("file", file); return await fetchData(url, { method: "PUT", headers: { Authorization: `Bearer ${authToken}`, //"Content-Type": "multipart/form-data", }, body: formData, }); } catch (error) { console.error("Error uploading image:", error); throw error; } } export const deleteProductData = async (url: string, authToken: string) => { try { return await fetchData(url, { method: "DELETE", headers: { Authorization: `Bearer ${authToken}`, "Content-Type": "application/json", }, credentials: "include", }); } catch (error) { console.error("Error deleting product data:", error); throw error; } };