import type { InteractionLink } from "@shared/types/core/InteractionLink.types"
import type { UserState } from "./user"
import type { Composition } from "@shared/types/core/Composition.types"

export type WidgetBase = {
  uuid: string
  name: string
  title?: string
  titleI18n?: string
  type?: string
  config?: Object
  public?: Object
  author?: string
  pluginKey?: string
}

export type WidgetSlot = {
  class?: string
  column: number
  widget: WidgetBase
}

export type OrganizationState = {
  id: string
}

export type ProjectState = {
  _id: string
}

export type NavigationBarType = "navItem" | "footerItem"

export type PageState = {
  icon?: string
  scrollTop: boolean
  title?: string
  titleI18n?: string
  grid?: {
    type: string
    items: string
    columns: number
    columnSizes?: string
  }
  slots: WidgetSlot[][]
  routeName: string
  uuid: string
  sortOrder: number
  navigationBarType?: NavigationBarType
  hasInspector?: boolean
  scrollY?: number
}

export type UIState = {
  navigationOpen: boolean
  availableInterfaces: ("pageNavigation" | "modalTools" | "topBar")[]
  loading: boolean
  mobile: boolean
  theme: "light" | "dark"
  locale: "de-DE" | "en-EU"
  shortcuts: object
  landingPage: string
}

export type InteractionLinksState = { [key: string]: InteractionLink }

export type CompositionsState = { [key: string]: Composition }

export type ServerState = {
  socket: {
    status: number | null
    socketId: string | null
    health: number | null
  }
}

export type Notification = {
  event: string
  message: {
    color: string
    content: { name: string }
    i18n: string
  }
  state: "read" | "unread" | "seen"
  time: Date
}

export type NotificationsState = {
  unreadCount: number
  toggled: boolean
  history: []
  items: { [key: string]: Notification }
}
export type ApplicationState = {
  widgets: {
    [key: string]: WidgetBase
  }
  ui: UIState
  notifications: any // TODO: implement me
  user: UserState
  project: ProjectState
  // TODO: check if we need multiple types here
  interactionLinks: InteractionLinksState
  compositions: CompositionsState
  backend: ServerState
}

// TODO: finalize this type
export type ProjectConfiguration = {
  browser: {
    ui: UIState
  }
}
