/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/

"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/main.ts
var main_exports = {};
__export(main_exports, {
  default: () => DisableTabsPlugin
});
module.exports = __toCommonJS(main_exports);
var import_obsidian3 = require("obsidian");

// src/settings.ts
var DEFAULT_SETTINGS = {
  enabled: true,
  hideMobileNewTabIcon: false
};

// src/utils/tab-enforcer.ts
var TabEnforcer = class {
  constructor(app) {
    this.app = app;
  }
  enforceSingleTab() {
    const leaves = [];
    this.app.workspace.iterateRootLeaves((leaf) => {
      leaves.push(leaf);
    });
    if (leaves.length > 1) {
      let active = leaves[leaves.length - 1];
      for (const leaf of leaves) {
        const view = leaf.view;
        if (view && "containerEl" in view) {
          const containerEl = view.containerEl;
          if (containerEl && containerEl.hasClass("is-active")) {
            active = leaf;
            break;
          }
        }
      }
      leaves.forEach((leaf) => {
        if (leaf !== active) {
          leaf.detach();
        }
      });
    }
  }
};

// src/ui/settings-tab.ts
var import_obsidian2 = require("obsidian");

// src/utils/settings-compat.ts
var import_obsidian = require("obsidian");
var ObsidianModule = __toESM(require("obsidian"), 1);
function createSettingsGroup(containerEl, heading, manifestId) {
  if ((0, import_obsidian.requireApiVersion)("1.11.0")) {
    const SettingGroupClass = ObsidianModule.SettingGroup;
    if (SettingGroupClass) {
      const group = heading ? new SettingGroupClass(containerEl).setHeading(heading) : new SettingGroupClass(containerEl);
      return {
        addSetting(cb) {
          group.addSetting(cb);
        }
      };
    }
  }
  if (manifestId) {
    containerEl.addClass(`${manifestId}-settings-compat`);
  }
  {
    if (heading) {
      const headingEl = containerEl.createDiv("setting-group-heading");
      headingEl.createEl("h3", { text: heading });
    }
    return {
      addSetting(cb) {
        const setting = new import_obsidian.Setting(containerEl);
        cb(setting);
      }
    };
  }
}

// src/ui/settings-tab.ts
var DisableTabsSettingTab = class extends import_obsidian2.PluginSettingTab {
  constructor(app, plugin) {
    super(app, plugin);
    this.plugin = plugin;
    this.settings = plugin.settings;
  }
  display() {
    const { containerEl } = this;
    containerEl.empty();
    const generalGroup = createSettingsGroup(containerEl, void 0, "disable-tabs");
    generalGroup.addSetting((setting) => {
      setting.setName("Hide mobile tabs icon").setDesc("Hide the tabs icon on mobile devices").addToggle(
        (toggle) => toggle.setValue(this.settings.hideMobileNewTabIcon).onChange(async (value) => {
          this.settings.hideMobileNewTabIcon = value;
          await this.plugin.saveSettings();
          this.plugin.updateMobileTabIconCSS();
        })
      );
    });
  }
};

// src/main.ts
var DisableTabsPlugin = class extends import_obsidian3.Plugin {
  async onload() {
    const loadedData = await this.loadData();
    this.settings = Object.assign({}, DEFAULT_SETTINGS, loadedData);
    this.tabEnforcer = new TabEnforcer(this.app);
    this.updateMobileTabIconCSS();
    this.registerEvent(this.app.workspace.on("layout-change", () => {
      this.tabEnforcer.enforceSingleTab();
    }));
    this.app.workspace.onLayoutReady(() => {
      this.tabEnforcer.enforceSingleTab();
    });
    this.addSettingTab(new DisableTabsSettingTab(this.app, this));
  }
  updateMobileTabIconCSS() {
    if (this.settings.hideMobileNewTabIcon) {
      document.body.classList.add("disable-tabs-hide-mobile-icon");
    } else {
      document.body.classList.remove("disable-tabs-hide-mobile-icon");
    }
  }
  async saveSettings() {
    await this.saveData(this.settings);
  }
  onunload() {
    document.body.classList.remove("disable-tabs-hide-mobile-icon");
  }
};


/* nosourcemap */