import { d as t, F as d, e as E, u as V, f as k, A as s, g as I, W as D } from "./FetchConfigsUtils-476a602b.mjs";
import { useCallback as j } from "react";
import { DesktopChecker as T } from "@accelbyte/sdk";
import { z as e } from "zod";
var y = /* @__PURE__ */ ((a) => (a.GRADIENT = "gradient", a.FULL = "full", a))(y || {});
const P = e.object({
  isEnabled: e.boolean(),
  type: e.nativeEnum(y),
  opacity: e.number().min(0).max(100)
}), $ = e.object({
  header: e.number().nullable(),
  footer: e.number().nullable()
}), o = e.object({
  hex: e.string(),
  rgb: e.object({
    r: e.number(),
    g: e.number(),
    b: e.number(),
    a: e.number()
  })
}), w = e.object({
  background: o,
  card: o,
  overlay: o,
  primary: o,
  secondary: o,
  text: o
}), C = e.object({
  body: e.string(),
  customBodyFontUrl: e.string(),
  title: e.string(),
  customTitleFontUrl: e.string()
}), z = e.object({
  templatePreview: e.string().optional(),
  isLocalStyleEnabled: e.boolean(),
  window: e.object({
    colors: e.object({
      primary: o,
      secondary: o,
      text: o,
      overlay: o,
      background: o,
      card: o
    }),
    fonts: C
  })
}), _ = e.object({
  background: e.string(),
  backgroundOverlay: P
}), A = e.object({
  url: e.string(),
  name: e.string()
}), N = e.object({
  images: e.array(A),
  defaultIndex: e.number()
}), x = e.object({
  window: e.object({
    colors: w,
    fonts: C
  })
}), G = e.object({
  url: e.string(),
  platform: e.string(),
  apps: e.array(e.string())
}), l = e.object({
  draft: e.string(),
  published: e.string()
});
var v = /* @__PURE__ */ ((a) => (a.SINGLE = "single-game", a.MULTIPLE = "multiple-game", a))(v || {});
const U = e.object({
  isAccountOverviewVisible: e.boolean().default(!0),
  isChangePasswordVisible: e.boolean().default(!0),
  isDeleteAccountVisible: e.boolean().default(!0),
  isGetLauncherVisible: e.boolean().default(!0),
  isLinkedAccountsVisible: e.boolean().default(!0),
  isMyProfileVisible: e.boolean().default(!0),
  isNewsVisible: e.boolean().default(!1),
  isNotificationsVisible: e.boolean().default(!1),
  isOrderHistoryVisible: e.boolean().default(!0),
  isPaymentMethodsVisible: e.boolean().default(!0),
  isPersonalDataVisible: e.boolean().default(!0),
  isLegalAgreementsVisible: e.boolean().default(!0),
  isPurchasedItemsVisible: e.boolean().default(!0),
  isRedeemCodeVisible: e.boolean().default(!0),
  isStoreVisible: e.boolean().default(!0),
  isSubscriptionsVisible: e.boolean().default(!1),
  isVirtualCurrencyVisible: e.boolean().default(!1),
  isNewsV2Visible: e.boolean().default(!1),
  isTwitchDropEnabled: e.boolean().default(!0),
  isLegalEnabled: e.boolean().default(!0)
});
e.object({
  ppTemplateInfo: t.merge(
    e.object({
      data: l
    })
  ),
  launcherTemplateInfo: t.merge(
    e.object({
      data: l
    })
  ),
  loginTemplateInfo: t.merge(
    e.object({
      data: l
    })
  ),
  legalTemplateInfo: t.merge(
    e.object({
      data: l
    })
  ),
  paymentTemplateInfo: t.merge(
    e.object({
      data: l
    })
  ),
  twitchDropTemplateInfo: t.merge(
    e.object({
      data: l
    })
  ),
  supportTemplateInfo: t.merge(
    e.object({
      data: l
    })
  ),
  ppFeatureFlags: t.merge(
    e.object({
      data: U
    })
  ),
  launcherFeatureFlags: t,
  loginFeatureFlags: t,
  supportFeatureFlags: t,
  experimentalFeatureFlags: t,
  socialLinks: t.merge(
    e.object({
      data: e.object({
        value: e.array(G)
      })
    })
  ),
  copyright: t.merge(
    e.object({
      data: e.object({
        value: e.string()
      })
    })
  ),
  globalPageConfig: t.merge(
    e.object({
      data: x,
      name: e.string(),
      format: e.string(),
      updatedAt: e.string(),
      version: e.number()
    })
  ),
  companyLogo: t.merge(
    e.object({
      data: N,
      name: e.string(),
      format: e.string(),
      updatedAt: e.string(),
      version: e.number()
    })
  ),
  templateConfig: t.merge(
    e.object({
      data: e.object({
        value: e.union([e.literal("single-game"), e.literal("multiple-game")])
      })
    })
  ),
  appId: t.merge(
    e.object({
      data: e.object({
        value: e.string()
      })
    })
  ),
  avatarsList: t.merge(
    e.object({
      data: e.object({
        value: e.string()
      })
    })
  ),
  brandName: t.merge(
    e.object({
      data: e.object({
        value: e.string()
      })
    })
  ),
  favicon: t.merge(
    e.object({
      data: e.object({
        value: e.string()
      })
    })
  ),
  pageTitle: t.merge(
    e.object({
      data: e.object({
        value: e.string()
      })
    })
  ),
  launcherIcon: t.merge(
    e.object({
      data: e.object({
        value: e.string()
      })
    })
  )
});
const F = {
  discoveryConfigData: null,
  flags: null,
  discoveryConfigError: null,
  fetchDiscoveryConfigStatus: d.IDLE,
  allSocialLinks: null,
  isSingleGame: !0
}, H = E(F);
function q() {
  const [a] = V(), [i, r] = k(H), u = T.isDesktopApp() ? s.LAUNCHER : s.PP, L = j(() => {
    r(F);
  }, []), h = j(
    async (f) => {
      let c = null, g = null, b = null, m = null, p = !0;
      try {
        r({ discoveryConfigError: null, fetchDiscoveryConfigStatus: d.FETCHING });
        const n = await I.fetchDiscovery({
          sdk: a,
          appName: u,
          widgetOptions: f,
          useConfigService: f === void 0
        });
        return b = R(n, u), c = n, m = n.socialLinks.data.value.filter((S) => S.apps.includes(u)), p = n.templateConfig.data.value === v.SINGLE, {
          data: {
            discoveryConfigData: c,
            flags: b
          }
        };
      } catch (n) {
        return g = D.getErrorType(n), { error: g };
      } finally {
        r({
          discoveryConfigData: c,
          discoveryConfigError: g,
          flags: b,
          allSocialLinks: m,
          fetchDiscoveryConfigStatus: d.IDLE,
          isSingleGame: p
        });
      }
    },
    [a]
  );
  return {
    state: i,
    mutations: {
      resetState: L,
      fetchDiscoveryConfigs: h
    }
  };
}
function R(a, i) {
  let r = null;
  switch (i) {
    case s.PP:
      r = { ...a.ppFeatureFlags.data, ...a.experimentalFeatureFlags.data };
      break;
    case s.LAUNCHER:
      r = {
        ...a.launcherFeatureFlags.data,
        ...a.experimentalFeatureFlags.data
      };
      break;
    default:
      return null;
  }
  return r;
}
export {
  _ as B,
  N as C,
  x as G,
  $ as L,
  z as P,
  G as S,
  v as T,
  U as a,
  q as u
};
