export {}

declare global {
  interface Window {
    BRIGHTSPOT: {
      ai: {
        AI_CHAT_ENABLED: boolean
        submitSuggestion: string
        showPromptSuggestions: string
      }
      ariaDebug: boolean
      focusRegions: Record<string, number>
      icons: {
        materialToLucide: Record<string, string>
      }
      js: {
        onFind: function
        onRemove: function
      }
      ui: {
        cms: {
          enableAutomaticUpdates: boolean
          enableV5UI: boolean
        }
        input: {
          secretHide: string
          secretShow: string
        }
        rte: {
          buttonOk: string
          buttonCancel: string
          buttonMoreMenu: string
          olWidgetTitle: string
        }
        sortable: {
          genericList: string
          namedList: string
          contains: string
          canContain: string
          listGainedFocus: string
          itemChangedPosition: string
          itemDragCancelled: string
          itemDragStarted: string
          itemDropped: string
        }
        tooltips: {
          add: string
          action: {
            favorite: string
            unfavorite: string
          }
          actions: {
            actions: string
            contentEdit: string
            contentSelector: string
            searchResult: string
            widget: string
          }
          aspectRatio: string
          calendar: {
            next: string
            previous: string
            schedule: string
          }
          charCountCharacterPlural: string
          charCountCharacterSingular: string
          charCountMaximum: string
          charCountMinimum: string
          charCountWordPlural: string
          charCountWordSingular: string
          chatWithOpenAI: string
          close: string
          collapse: string
          collapseAll: string
          confirmDeleteParentComment: string
          confirmPopupUnsaved: string
          combo: {
            empty: string
            multi: string
          }
          createNew: string
          multiSort: string
          edit: string
          editTheme: string
          expand: string
          expandAll: string
          imageHeight: string
          imageHeightOpen: string
          imageHeightClose: string
          fieldSelect: string
          fieldHide: string
          filtersHide: string
          filtersShow: string
          focusTrapHint: string
          fullScreen: string
          fullScreenSearch: string
          imageEditor: {
            actions: string
            flipH: string
            flipV: string
            focus: string
            open: string
            rotateLeft: string
            rotateRight: string
          }
          itemHide: string
          itemShow: string
          listOpen: string
          menu: {
            open: string
            close: string
          }
          navigation: {
            nextItem: string
            prevItem: string
          }
          new: string
          newNotifications: string
          notifications: string
          open: string
          preview: {
            open: string
            close: string
            iframeTitle: string
            opened: string
            closed: string
          }
          size: string
          skipLinks: {
            heading: string
            pageHeader: string
            mainContent: string
            navigation: string
            note: string
            pageNavigation: string
          }
          skipToContent: string
          remove: string
          reset: string
          resetWeights: string
          restore: string
          search: {
            label: string
          }
          tabs: string
          toggleOff: string
          toggleOn: strings
          view: string
        }
        workflow: {
          add: string
          published: string
          placeholder: string
          remove: string
          stateLegend: string
          transitions: string
          state: string
          transitionLegend: string
        }
      }
      web: {
        pathPrefix: string
        path: string
        pagePaths: { [key: string]: string }
      }
    }
    btuCelebrate: HTMLElement | null
    jQuery: any
    CONTEXT_PATH: string
    DISABLE_RTC: boolean
    PubSub: {
      subscribe: (
        event: string,
        handler: (rte: any) => void,
      ) => { remove: () => void }
    }
    RICH_TEXT_ELEMENTS: unknown
    RTE_PROMPT_PLACEHOLDER: string
    RTE_PROMPT_PREFIX: string
    RTE_PROMPT_RETRY: string
    RTE_WORKING_ON_IT: string
    RTE_ACCEPT: string
    RTE_DISCARD: string
    RTE_TRY_AGAIN: string
    RTE_REPLACE: string
    RTE_REPLACE_ALL: string
    RTE_FIND_IN_ARTICLE: string
    RTE_REPLACE_WITH: string
    RTE_MATCH_CASE: string
    RTE_MATCH_WHOLE_WORD: string
    ROOT_PATH: string
  }

  type Class<T> = new (...args: any[]) => T
  type Constructor<T = object> = new (...args: any[]) => T
  type UnpackCustomEvent<T> = T extends CustomEvent<infer U> ? U : never

  // All global custom event types:
  interface CustomEventMap {
    'btu-announce': CustomEvent<string>
    'btu-resolve-icon': CustomEvent<{ name: string; element: HTMLElement }>
    'page-nav-rail-toggled': CustomEvent<{ toggleState: PageNavToggleState }>
  }

  interface CombinedEventMap extends HTMLElementEventMap, CustomEventMap {}

  interface CustomEventElement {
    addEventListener<K extends keyof CombinedEventMap>(
      type: K,
      listener: (this: CustomEventElement, ev: CombinedEventMap[K]) => void,
      options?: boolean | AddEventListenerOptions,
    ): void
    removeEventListener<K extends keyof CombinedEventMap>(
      type: K,
      listener: (this: CustomEventElement, ev: CombinedEventMap[K]) => void,
      options?: boolean | EventListenerOptions,
    ): void
  }
}
