/**
 * Default state of the store
 *
 * exports
 *
 * - loadingHold
 * - applicationState (initial state of the store)
 * - configPatterns
 * - storePatterns
 */

import type { ApplicationState } from "./types"

/**
 * Used as a timer value
 */
const loadingHold = 300

/**
 * applicationState
 * Our actual application data
 */
const applicationState: ApplicationState = {
  socket: {
    status: null,
    message: null,
  },
  backend: {
    socket: {
      status: null,
      socketId: null,
      health: null,
    },
  },
  user: {
    _id: false,
    nickname: false,
    email: false,
    firstname: false,
    lastname: false,
  },
  project: {
    _id: null,
  },
  ui: {
    availableInterfaces: ["pageNavigation", "modalTools", "topBar"],
    // indicates the left navigation bar state
    navigationOpen: false,
    // indicates if the widget toolbar and other ui edit stuff is displayed
    mobile: false,
    // indicates if the page is in loading state
    loading: true,
    theme: "light",
    locale: "en-EU",
    shortcuts: {},
    landingPage: "",
  },
  notifications: {
    unreadCount: 0,
    toggled: false,
    history: [],
    items: {},
  },
  data: {},
  queriesCache: {},
  queries: {},
  projects: {},
  // the actual config object of the page you see right now. This will be
  // moved into the pages lookup once you change pages
  // a lookup map for all the widgets which are currently known to the application context
  widgets: {},
  // a lookup map for all the pages which are currently known to the
  pages: {},
  compositions: {},
  compositionSlots: {},
  interactionLinks: {},
}
// TODO move patterns to workbench state
/**
 * configPatterns
 */
const configPatterns = {
  grid: {
    // defines the wrapping html template for the whole grid
    type: "default",
    // defines the wrapping html template for the single item within the grid
    items: "card",
    // defines the amount of columns per row
    columns: 1,
  },
  slot: {
    // defines a css class which will be used for the v-col the slot widget is housed in
    class: false,
    // defines the width of the widget by using flexbox grid col numbers 1-12
    column: 12,
    // defines the widget configuration, see widget storePattern
    widget: false,
  },
}

/**
 * Some data object templates
 */
const storePatterns = {
  compositions: {
    // the icon to be displayed in the page navigation
    icon: false,
    // this will determine if we always scroll to the last page position or
    // to the top whenever we enter this page
    scrollTop: false,
    // The title of the page if i18n from db
    title: "",
    // The title of the page if i18n key is handled in frontend
    titleI18n: "",
    // grid config for a page
    grid: configPatterns.grid,
    // the array containing the configs for the 1-n slots
    slots: [[]],
    // the name of the route configured in the vue router
    routeName: false,
    // The uuid of other unique identifier for the page within the application context
    uuid: false,
    version: "0.0.0",
  },
  widget: {
    // The title of the page if i18n from db
    title: "",
    // The title of the page if i18n key is handled in frontend
    titleI18n: "",
    // will usually be set automatically, if set manually, be aware that
    // duplicated uuid lead to shared widget store
    uuid: false,
    // the type of widget which represents a folder name under widgets and a config
    name: false,
    // any working state we want to have available in the store and not just the component
    workingState: {},
    // any acutal config we provide to the widget
    config: {},
    // any data the widget want's to provide to other widgets/plugins/core such as serializers, connection hooks to other modules etc
    public: {},
    version: "0.0.0",
    pluginKey: "",
  },
}

export { loadingHold, applicationState, configPatterns, storePatterns }
