import PlaceableTab from "./placeable-tab.mjs";

/**
 * The Note-specific placeables tab.
 * @extends {PlaceableTab}
 */
export default class NoteTab extends PlaceableTab {
  /** @override */
  static ENTRY_PARTIAL = "templates/sidebar/tabs/placeable/note.hbs";

  /* -------------------------------------------- */

  /** @override */
  _getEntryLabel(entry) {
    const journal = entry.page ?? entry.entry;
    return entry.text || journal?.name || entry.id;
  }

  /* -------------------------------------------- */

  /** @inheritDoc */
  async _prepareEntry(entry, context) {
    context = await super._prepareEntry(entry, context);
    if ( game.user.isGM ) {
      const journal = entry.page ?? entry.entry;
      const playerAuthor = (entry._source.author === null) || !(entry.author?.isGM ?? true);
      context.isVisible = journal
        ? game.users.some(u => !u.isGM && journal.testUserPermission(u, "LIMITED"))
        : playerAuthor;
    }
    return context;
  }
}
