import CommandBuilder from "../builders/command";

function dropHandler(args, context) {
    const room = context.getRoom(context.player.currentRoom);
    const items = context.player.getInventory();
    let item = null;
    for (let i of items) {
        if (i.name.includes(args[1])) {
            item = i;
            break;
        }
    }
    if (!item) {
        context.print(`You're not carrying a ${args[1]}`);
    } else {
        context.player.removeItem(item.getID());
        room.addItem(item.getID());
        context.print(`You set ${item.name} down on the floor.`);
        item.onDrop();
        
        // Refresh mobile commands when items change
        context.commandHandler.refreshMobileCommands();
    }
}

export default new CommandBuilder()
    .withName("drop")
    .withAliases(["put"])
    .withCategory("Actions")
    .withDescription("Drop an object")
    .withArgument("item", "target", false, "Object to drop")
    .withHandler(dropHandler)
    .create();