import DocumentDirectory from "../document-directory.mjs";

/**
 * @import Item from "@client/documents/item.mjs";
 */

/**
 * The World Item directory listing.
 * @extends {DocumentDirectory<Item>}
 */
export default class ItemDirectory extends DocumentDirectory {

  /** @inheritDoc */
  static DEFAULT_OPTIONS = {
    collection: "Item"
  };

  /** @override */
  static tabName = "items";

  /* -------------------------------------------- */
  /*  Rendering                                   */
  /* -------------------------------------------- */

  /** @inheritDoc */
  _getEntryContextOptions() {
    const options = super._getEntryContextOptions();
    const configureOwnershipIndex = options.findIndex(o => o.label === "OWNERSHIP.Configure");
    options.splice(configureOwnershipIndex + 1, 0, {
      label: "ITEM.ViewArt",
      icon: "fa-solid fa-image",
      visible: li => {
        const item = game.items.get(li.dataset.entryId);
        const { img } = item.constructor.getDefaultArtwork(item._source);
        return item.img !== img;
      },
      onClick: (event, li) => {
        const item = game.items.get(li.dataset.entryId);
        new foundry.applications.apps.ImagePopout({
          src: item.img,
          uuid: item.uuid,
          window: { title: item.name }
        }).render({ force: true });
      }
    });
    return options;
  }
}
