import { c as createStore } from './index-96e8c812.js';

const config = {
  env: "local",
  url: "http://localhost:3333",
  firebase: {
    apiKey: "AIzaSyAz5C9TRxQ9bUkTwVaD6Yc-Iisw57UslPM",
    authDomain: "fireenjin-live.firebaseapp.com",
    databaseURL: "https://fireenjin-live.firebaseio.com",
    projectId: "fireenjin-live",
    storageBucket: "fireenjin-live.appspot.com",
    messagingSenderId: "756564610596",
    appId: "1:756564610596:web:4fdf5a6ddfd319a93392b1",
    measurementId: "G-Q0ZHGFCQFN",
  },
  dynamicLinkDomain: "fireenjin.page.link",
};

function env(key, fallback) {
  const value = !key
    ? config
    : key && key.indexOf(".") >= 0
      ? key.split(".").reduce((p, c) => (p && p[c]) || null, config)
      : key && typeof config[key] !== "undefined"
        ? config[key]
        : null;
  return fallback &&
    ((!value && value !== false && value !== 0) ||
      typeof value === "undefined" ||
      value === null)
    ? fallback
    : value;
}

const { state, onChange } = createStore({
  config: env(),
  version: (localStorage === null || localStorage === void 0 ? void 0 : localStorage.getItem) && localStorage.getItem("fireenjin:version")
    ? localStorage.getItem("fireenjin:version")
    : "1.1.0",
  profile: ((localStorage === null || localStorage === void 0 ? void 0 : localStorage.getItem) && localStorage.getItem("fireenjin:profile")
    ? JSON.parse(localStorage.getItem("fireenjin:profile"))
    : {}),
  session: null,
  templates: ((localStorage === null || localStorage === void 0 ? void 0 : localStorage.getItem) &&
    localStorage.getItem("fireenjin:templates")
    ? JSON.parse(localStorage.getItem("fireenjin:templates"))
    : []),
  partials: ((localStorage === null || localStorage === void 0 ? void 0 : localStorage.getItem) && localStorage.getItem("fireenjin:partials")
    ? JSON.parse(localStorage.getItem("fireenjin:partials"))
    : []),
  template: ((localStorage === null || localStorage === void 0 ? void 0 : localStorage.getItem) && localStorage.getItem("fireenjin:template")
    ? JSON.parse(localStorage.getItem("fireenjin:template"))
    : {}),
  isOnline: false,
  editorSizes: ((localStorage === null || localStorage === void 0 ? void 0 : localStorage.getItem) &&
    localStorage.getItem("fireenjin:editorSizes")
    ? JSON.parse(localStorage.getItem("fireenjin:editorSizes"))
    : [50, 50]),
  isPreviewing: ((localStorage === null || localStorage === void 0 ? void 0 : localStorage.getItem) &&
    localStorage.getItem("fireenjin:isPreviewing")
    ? JSON.parse(localStorage.getItem("fireenjin:isPreviewing"))
    : false),
});
onChange("editorSizes", (value) => {
  localStorage.setItem("fireenjin:editorSizes", JSON.stringify(value));
});
onChange("isPreviewing", (value) => {
  localStorage.setItem("fireenjin:isPreviewing", JSON.stringify(value));
});
onChange("profile", (value) => {
  localStorage.setItem("fireenjin:profile", JSON.stringify(value));
});
onChange("version", (value) => {
  localStorage.setItem("fireenjin:version", value);
});
onChange("template", (value) => {
  localStorage.setItem("fireenjin:template", JSON.stringify(value));
});
onChange("templates", (value) => {
  localStorage.setItem("fireenjin:templates", JSON.stringify(value));
});
onChange("partials", (value) => {
  localStorage.setItem("fireenjin:partials", JSON.stringify(value));
});

export { env as e, state as s };
