text: import {EnhancedItemActor} from "./enhanceditemactor.js";
  import {EnhancedItemSheet} from "./enhanceditemsheet.js";
  import {EnhancedItemTab} from "./enhancedItemtab.js";
  
  //CONFIG.debug.hooks = true;
  
  Handlebars.registerHelper('enabled', function(value, options) {
      return Boolean(value) ? "" : "disabled";
  });
  
  Hooks.once('init', () => {
  
      game.settings.register("enhanceditems", "identifiedOnly", {
          name: "ENHANCEDITEMS.SettingIdentifiedOnly",
          hint: "ENHANCEDITEMS.SettingIdentifiedOnlyHint",
          scope: "world",
          type: Boolean,
          default: true,
          config: true,
      });
  
      game.settings.register("enhanceditems", "hideFromPlayers", {
          name: "ENHANCEDITEMS.SettingHideFromPlayers",
          hint: "ENHANCEDITEMS.SettingHideFromPlayersHint",
          scope: "world",
          type: Boolean,
          default: false,
          config: true,
      });
  
      if(typeof Babele !== 'undefined') {
  
          Babele.get().register({
              module: 'enhanceditems',
              lang: 'it',
              dir: 'lang/packs/it'
          });
      }
  });
  
  Hooks.once('ready', () => {
      game.actors.entities.filter(actor => actor.permission >= 1).forEach(actor => {
          EnhancedItemActor.bind(actor);
      });
  });
  
  Hooks.once('createActor', (actor) => {
      if(actor.permission >= 2) {
          EnhancedItemActor.bind(actor);
      }
  });
  
  Hooks.on(`renderItemSheet5e`, (app, html, data) => {
      if(!game.user.isGM && game.settings.get("enhanceditems", "hideFromPlayers")) {
          return;
      }
      EnhancedItemTab.bind(app, html, data);
  });
  
  
  Hooks.on(`renderActorSheet5eCharacterNew`, (app, html, data) => {
      EnhancedItemSheet.bind(app, html, data);
  });
  
  Hooks.on(`renderActorSheet5eNPCNew`, (app, html, data) => {
      EnhancedItemSheet.bind(app, html, data);
  });
  
  Hooks.on(`ActorSheet5eStarship`, (app, html, data) => {
      EnhancedItemSheet.bind(app, html, data);
  });
  
  Hooks.on(`ActorSheet5eVehicle`, (app, html, data) => {
      EnhancedItemSheet.bind(app, html, data);
  });
  
  
  Hooks.on(`renderActorSheet5eCharacter`, (app, html, data) => {
      EnhancedItemSheet.bind(app, html, data);
  });
  
  Hooks.on(`renderActorSheet5eNPC`, (app, html, data) => {
      EnhancedItemSheet.bind(app, html, data);
  });
  
  
  Hooks.on("hotbarDrop", async (bar, data, slot) => {
      if ( data.type !== "EnhancedItem" ) return;
  
      const command = `EnhancedItems.roll("${data.enhancedItemName}","${data.itemName}");`;
      let macro = game.macros.entities.find(m => (m.name === data.name) && (m.command === command));
      if (!macro) {
          macro = await Macro.create({
              name: data.name,
              type: "script",
              img: data.img,
              command: command,
              flags: {"sw5e.itemMacro": true}
          }, {displaySheet: false});
      }
      game.user.assignHotbarMacro(macro, slot);
  
      return false;
  });
  
  Hooks.on(`createItem`, (item) => {
      if(item.actor) {
          const actor = item.actor;
          const miActor = EnhancedItemActor.get(actor.id);
          if(miActor && miActor.listening && miActor.actor.id === actor.id) {
              miActor.buildItems();
          }
      }
  });
  
  Hooks.on(`updateItem`, (item) => {
      if (item.actor) {
          const actor = item.actor;
          const miActor = EnhancedItemActor.get(actor.id);
          if (miActor && miActor.listening && miActor.actor.id === actor.id) {
              setTimeout(miActor.buildItems.bind(miActor), 500);
          }
      }
  });
  
  Hooks.on(`deleteItem`, (item) => {
      if (item.actor) {
          const actor = item.actor;
          const miActor = EnhancedItemActor.get(actor.id);
          if (miActor && miActor.listening && miActor.actor.id === actor.id) {
              miActor.buildItems();
          }
      }
  });
  
  Hooks.on(`dropItemSheetData`, (item, app, data, event) => {
      EnhancedItemTab.onDrop(app, event, item);
  });
  
  window.EnhancedItems = {
  
      actor: function(id) {
          return EnhancedItemActor.get(id);
      },
  
      roll: function(enhancedItemName, itemName) {
  
          const speaker = ChatMessage.getSpeaker();
          let actor;
          if ( speaker.token ) actor = game.actors.tokens[speaker.token];
          if ( !actor ) actor = game.actors.get(speaker.actor);
  
          const enhancedItemActor = actor ? EnhancedItemActor.get(actor.id) : null;
          if ( !enhancedItemActor ) return ui.notifications.warn(game.i18n.localize("ENHANCEDITEMS.WarnNoActor"));
  
          enhancedItemActor.rollByName(enhancedItemName, itemName);
      },
  
      bindItemSheet: function(app, html, data) {
          EnhancedItemTab.bind(app, html, data);
      },
  
      bindCharacterSheet: function(app, html, data) {
          EnhancedItemSheet.bind(app, html, data);
      }
  };
  