// SPDX-FileCopyrightText: 2021 Johannes Loher
//
// SPDX-License-Identifier: MIT

import { createRollCheckMacro } from "../macros/roll-check";
import { createRollItemMacro } from "../macros/roll-item";

export function registerForHotbarDropHook() {
  Hooks.on("hotbarDrop", onHotbarDrop);
}

/**
 * @typedef {Record<string, unknown>} DropData
 * @property {string} type
 */

/**
 * Handle a drop event on the hotbar
 * @param {Hotbar} hotbar The hotbar on which something wqas
 * @param {DropData} data The drop data associated to the drop event
 * @param {string} slot The slot on the hotbar that somethingwas dropped on
 * @returns {void | false}
 */
function onHotbarDrop(hotbar, data, slot) {
  switch (data.type) {
    case "Item": {
      createRollItemMacro(data, slot);
      return false;
    }
    case "Check": {
      createRollCheckMacro(data, slot);
      return false;
    }
  }
}
