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

import { notifications } from "../ui/notifications.js";
import { getGame } from "../utils/utils.js";

export function registerForPreCreateItemHook() {
  Hooks.on("preCreateItem", preCreateItem);
}

/**
 * @param {import('../documents/item/item.js').DS4Item} item
 * @returns {void | false}
 */
function preCreateItem(item) {
  if (item.parent instanceof Actor && !item.parent.canOwnItemType(item.type)) {
    notifications.warn(
      getGame().i18n.format("DS4.WarningActorCannotOwnItem", {
        actorName: item.actor.name,
        actorType: item.actor.type,
        itemName: item.name,
        itemType: item.type,
      }),
    );
    return false;
  }
}
