import Badge from 'antd/es/badge';
import React from 'react';
import { Store, Action } from "redux";
import { manifest } from "@/manifest";
import "@loop/plugin-sdk/lib/window"
import { PluginClass, PluginRegistry } from "@loop/plugin-sdk/lib/plugin";
import { GlobalState } from "@loop/plugin-sdk/lib/loop/types/store";

const Comp = (num: number) => () => <Badge count={num} showZero color='#faad14' />
const El = (num: number) => <Badge count={num} showZero color='#faad14' />

export default class Plugin extends PluginClass {
  public async initialize(registry: PluginRegistry, store: Store<GlobalState, Action<Record<string, unknown>>>) {
    registry.registerChannelHeaderButtonAction(Comp(1), () => {}, "ABC", "CBA");
    registry.registerMainMenuAction(Comp(3), () => {}, Comp(3))
    registry.registerPostDropdownMenuAction(El(4), () => {}, () => true)
    registry.registerCreatePostActionComponent(El(5), <span>ABC</span>, () => {})
    registry.registerCreatePostLabelComponent(Comp(6))
    registry.registerPopoverUserAttributesComponent(Comp(7))
    registry.registerPopoverUserActionsComponent(Comp(8))
    const { toggleRHSPlugin } = registry.registerRightHandSidebarComponent(Comp(35), "ABC9")
    registry.registerChannelHeaderMenuAction(Comp(2), () => store.dispatch(toggleRHSPlugin));
    registry.registerLeftSidebarHeaderComponent(Comp(9))
    registry.registerBottomTeamSidebarComponent(Comp(10))
    registry.registerLinkTooltipComponent(Comp(11))
    registry.registerActionAfterChannelCreation(Comp(12), () => {})
    registry.registerChannelIntroButtonAction(El(12), () => {}, El(13))
    registry.registerCallButtonAction(El(14), El(15), () => {})

    registry.registerPostCardTypeComponent("my", Comp(16)) // ???

    registry.registerFileDropdownMenuAction(() => true, Comp(17), () => {})
    registry.registerUserGuideDropdownMenuAction(Comp(18), () => {})
    //registry.registerPostActionComponent(Comp(19))
    //registry.registerPostEditorActionComponent(Comp(20))
      // registry.registerCodeBlockActionComponent(Comp(21)) // временно depricated
      // registry.registerNewMessagesSeparatorActionComponent(Comp(22)) // временно depricated
    registry.registerPostDropdownSubMenuAction(
      Comp(23),
      (...args) => { console.log(23, args); },
      (...args) => { console.log(23, args); return true }
    )
    registry.registerPostDropdownMenuComponent(Comp(24))
    registry.registerFileUploadMethod(
      Comp(25),
      (...args) => { console.log(25, args); },
      Comp(26),
    )
    registry.registerSidebarChannelLinkLabelComponent(Comp(27))
    registry.registerChannelToastComponent(Comp(28))
    registry.registerGlobalComponent(Comp(29))
    registry.registerAppBarComponent(
      'https://wilix.org/icon.png',
      () => {},
      Comp(30),
      null,
      Comp(31),
      Comp(32),
    )
    registry.registerSiteStatisticsHandler((...args) => {
      console.log(33, args);
      return {
        abc: Comp(33)
      }
    })
    registry.registerRootComponent(Comp(34))
  }
}

window.registerPlugin(manifest.id, new Plugin());
