'use strict';
import { c } from 'react/compiler-runtime';
import { jsx } from 'react/jsx-runtime';
import { createContext, useState, useEffect, useContext } from 'react';
import { publicImages } from '../../../../fd-toolbox/constants/public-files.js';
import { emptyUuid } from '../../../../fd-toolbox/constants/constants.js';
import { fileExtensionsWithoutDot } from '../../../../base-repo/app-constants/internal-system-constants.js';
import { createError } from '../../../../fd-toolbox/errors/errors.js';
import { getLoginState } from '../../../../fd-toolbox/auth/internal-login-states.js';
import { metaErrorMessages } from '../../../meta/constants/meta-error-messages-constants.js';

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", {
  value,
  configurable: true
});
const emptyLoginState = {
  loggedIn: false,
  displayName: "",
  userId: "",
  email: "",
  imageUrl: `/${publicImages.user}/${emptyUuid}.${fileExtensionsWithoutDot.webp}`
};
const AuthContext = createContext({
  loginState: emptyLoginState
});
function AuthProvider(t0) {
  const $ = c(5);
  const {
    children
  } = t0;
  const [loginState, setLoginState] = useState(emptyLoginState);
  let t1;
  let t2;
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
    t1 = () => {
      setLoginState(getLoginState());
    };
    t2 = [];
    $[0] = t1;
    $[1] = t2;
  } else {
    t1 = $[0];
    t2 = $[1];
  }
  useEffect(t1, t2);
  let t3;
  if ($[2] !== children || $[3] !== loginState) {
    const contextValue = {
      loginState,
      setLoginState
    };
    t3 = jsx(AuthContext.Provider, {
      value: contextValue,
      children
    });
    $[2] = children;
    $[3] = loginState;
    $[4] = t3;
  } else {
    t3 = $[4];
  }
  return t3;
}
__name(AuthProvider, "AuthProvider");
function useAuth() {
  const context = useContext(AuthContext);
  if (!context) {
    throw createError(metaErrorMessages.authProviderUsedOutside);
  }
  return context;
}
__name(useAuth, "useAuth");

export { AuthContext, AuthProvider, useAuth };
