// src/lib/server-api.ts
var API_URL = process.env.API_URL || "http://localhost:3000/api/v1";
var API_KEY = process.env.API_KEY || "";
async function serverFetch(endpoint, options = {}) {
  var _a;
  const url = `${API_URL}${endpoint}`;
  try {
    const fetchOptions = {
      headers: {
        "X-API-Key": API_KEY,
        "Content-Type": "application/json"
      },
      cache: options.cache
    };
    if (options.revalidate) {
      fetchOptions.next = { revalidate: options.revalidate };
    }
    const response = await fetch(url, fetchOptions);
    if (!response.ok) {
      console.error(`[Server API] Error ${response.status} for ${endpoint}`);
      return null;
    }
    const json = await response.json();
    return (_a = json.data) != null ? _a : json;
  } catch (error) {
    console.error(`[Server API] Failed to fetch ${endpoint}:`, error);
    return null;
  }
}
var serverApi = {
  get: (endpoint, options) => {
    return serverFetch(endpoint, options || { revalidate: 60 });
  }
};
var defaultOptions = { revalidate: 60 };
async function getCompanyInformation() {
  return serverFetch("/public/company_information", defaultOptions);
}
async function getAdsConfig() {
  const data = await serverFetch("/public/ads_config", defaultOptions);
  return data != null ? data : null;
}
function getMetaPixelId(adsConfig) {
  const id = adsConfig && typeof adsConfig === "object" && "meta_pixel_id" in adsConfig && adsConfig.meta_pixel_id;
  const str = id != null && id !== "" ? String(id).trim() : "";
  return str !== "" && str !== "null" && /^\d+$/.test(str) ? str : null;
}
async function getServices() {
  return serverFetch("/public/services", defaultOptions);
}
async function getService(slug) {
  return serverFetch(`/public/services/by_slug/${slug}`, defaultOptions);
}
async function getLocations() {
  return serverFetch("/public/locations", defaultOptions);
}
async function getLocation(slug) {
  return serverFetch(`/public/locations/by_slug/${slug}`, defaultOptions);
}
async function getReviews() {
  return serverFetch("/public/reviews", defaultOptions);
}
async function getFAQs() {
  return serverFetch("/public/faq_questions", defaultOptions);
}
async function getBlogPosts() {
  return serverFetch("/public/blog_posts", defaultOptions);
}
async function getBlogPost(slug) {
  return serverFetch(`/public/blog_posts/by_slug/${slug}`, defaultOptions);
}
async function getTeamMembers() {
  return serverFetch("/public/team_members", defaultOptions);
}
async function getWebsitePhotos() {
  return serverFetch("/public/website_photos", defaultOptions);
}
async function getJobPostings() {
  return serverFetch("/public/job_postings", defaultOptions);
}
async function getJobPosting(slug) {
  return serverFetch(`/public/job_postings/by_slug/${slug}`, defaultOptions);
}
async function getSocialPosts() {
  return serverFetch("/public/social_posts", defaultOptions);
}
async function getTestimonials() {
  return getReviews();
}
async function getForm(formType) {
  return serverFetch(`/public/forms/${encodeURIComponent(formType)}`, defaultOptions);
}
export {
  getAdsConfig,
  getBlogPost,
  getBlogPosts,
  getCompanyInformation,
  getFAQs,
  getForm,
  getJobPosting,
  getJobPostings,
  getLocation,
  getLocations,
  getMetaPixelId,
  getReviews,
  getService,
  getServices,
  getSocialPosts,
  getTeamMembers,
  getTestimonials,
  getWebsitePhotos,
  serverApi
};
//# sourceMappingURL=server-api.js.map