import { apiClient } from "../../app/api/client";

export interface PageResponse {
  status: boolean;
  message: string;
  data: PageData;
  tenant: any;
}

export interface PageData {
  id: string;
  franchisee_id: string | null;
  is_global: boolean;
  title: string;
  slug: string;
  template_id: string;
  content: {
    iframe?: {
      iframeurl: string;
    };
    [key: string]: any;
  };
  status: string;
  seo_title: string | null;
  seo_description: string | null;
  template: {
    id: string;
    name: string;
    slug: string;
  };
}

export async function getPageBySlug(slug: string, domain: string): Promise<PageResponse | null> {
  try {
    const response = await apiClient.get<PageResponse>(`pages/${slug}`, {
      headers: { "X-Domain": domain },
    });
    return response.data;
  } catch (error) {
    console.error(`[getPageBySlug] Error fetching page ${slug}:`, error);
    return null;
  }
}
