import { PluginOptions, guildPlugin } from "knub";
import { GuildContextMenuLinks } from "../../data/GuildContextMenuLinks.js";
import { LogsPlugin } from "../Logs/LogsPlugin.js";
import { MutesPlugin } from "../Mutes/MutesPlugin.js";
import { UtilityPlugin } from "../Utility/UtilityPlugin.js";
import { ContextClickedEvt } from "./events/ContextClickedEvt.js";
import { ContextMenuPluginType, zContextMenusConfig } from "./types.js";
import { loadAllCommands } from "./utils/loadAllCommands.js";

const defaultOptions: PluginOptions<ContextMenuPluginType> = {
  config: {
    can_use: false,

    user_muteindef: false,
    user_mute1d: false,
    user_mute1h: false,
    user_info: false,

    message_clean10: false,
    message_clean25: false,
    message_clean50: false,
  },
  overrides: [
    {
      level: ">=50",
      config: {
        can_use: true,
      },
    },
  ],
};

export const ContextMenuPlugin = guildPlugin<ContextMenuPluginType>()({
  name: "context_menu",

  dependencies: () => [MutesPlugin, LogsPlugin, UtilityPlugin],
  configParser: (input) => zContextMenusConfig.parse(input),
  defaultOptions,

  // prettier-ignore
  events: [
    ContextClickedEvt,
  ],

  beforeLoad(pluginData) {
    const { state, guild } = pluginData;

    state.contextMenuLinks = new GuildContextMenuLinks(guild.id);
  },

  afterLoad(pluginData) {
    loadAllCommands(pluginData);
  },
});
