export default async function fetchWidgetConfig() {
  const location = window.location.origin;
  const endpoint = "/wp-json/firevert/v1/promo-time-widget/main";

  const response = await fetch(`${location}${endpoint}`, {
    method: "GET",
    credentials: "same-origin",
    headers: {
      "Content-Type": "application/json",
      "X-WP-Nonce": window.firevert.restNonce,
    },
  });

  const data = await response.json();
  if (!response.ok) throw new Error(data.error);
  if (response.status !== 200) return;

  return data;
}
