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

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 __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
var __export = (target, all) => {
  __markAsModule(target);
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __reExport = (target, module2, desc) => {
  if (module2 && typeof module2 === "object" || typeof module2 === "function") {
    for (let key of __getOwnPropNames(module2))
      if (!__hasOwnProp.call(target, key) && key !== "default")
        __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
  }
  return target;
};
var __toModule = (module2) => {
  return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
};
var __async = (__this, __arguments, generator) => {
  return new Promise((resolve, reject) => {
    var fulfilled = (value) => {
      try {
        step(generator.next(value));
      } catch (e) {
        reject(e);
      }
    };
    var rejected = (value) => {
      try {
        step(generator.throw(value));
      } catch (e) {
        reject(e);
      }
    };
    var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
    step((generator = generator.apply(__this, __arguments)).next());
  });
};

// main.ts
__export(exports, {
  default: () => StillePlugin
});
var import_obsidian = __toModule(require("obsidian"));
var nameOfApplication = `Stille`;
var DEFAULT_SETTINGS = {
  unfocusedLevel: 0.3,
  statusBarLabel: true,
  statusBarLabelText: `${nameOfApplication} on`,
  unfocusTitle: false
};
var moonIcon = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M195 125c0-26.3 5.3-51.3 14.9-74.1C118.7 73 51 155.1 51 253c0 114.8 93.2 208 208 208 97.9 0 180-67.7 202.1-158.9-22.8 9.6-47.9 14.9-74.1 14.9-106 0-192-86-192-192z"/></svg>`;
var StillePlugin = class extends import_obsidian.Plugin {
  constructor() {
    super(...arguments);
    this.stilleStatus = false;
  }
  onload() {
    return __async(this, null, function* () {
      yield this.loadSettings();
      (0, import_obsidian.addIcon)("moon", moonIcon);
      this.addRibbonIcon("moon", "Toggle Stille", () => {
        this.toggleStille();
      });
      this.statusBar = this.addStatusBarItem();
      this.statusBar.setText(this.settings.statusBarLabelText);
      this.toggleLabelDisplay(this.settings.statusBarLabel, true);
      this.toggleDimTitle(this.settings.unfocusTitle);
      this.addCommand({
        id: "toggleStille",
        name: "Toggle Stille",
        callback: () => {
          this.toggleStille();
        },
        hotkeys: [{ modifiers: ["Mod", "Shift"], key: "S" }]
      });
      this.addSettingTab(new StilleSettingTab(this.app, this));
      this.stilleStatus = true;
      this.toggleStille();
    });
  }
  onunload() {
    return __async(this, null, function* () {
      this.removeStyleFromView();
      this.statusBar.remove();
    });
  }
  loadSettings() {
    return __async(this, null, function* () {
      this.settings = Object.assign({}, DEFAULT_SETTINGS, yield this.loadData());
    });
  }
  saveSettings() {
    return __async(this, null, function* () {
      yield this.saveData(this.settings);
    });
  }
  toggleStille() {
    return __async(this, null, function* () {
      this.stilleStatus = !this.stilleStatus;
      if (this.stilleStatus) {
        this.addStyleToView();
        this.settings.statusBarLabelText = `${nameOfApplication} on`;
        this.statusBar.setText(this.settings.statusBarLabelText);
      } else {
        this.removeStyleFromView();
        this.settings.statusBarLabelText = `${nameOfApplication} off`;
        this.statusBar.setText(this.settings.statusBarLabelText);
      }
    });
  }
  addStyleToView() {
    this.styleElement = document.createElement("style");
    this.styleElement.id = "stilleStyles";
    document.head.appendChild(this.styleElement);
    document.body.classList.add("StilleStyle");
    const dimTitle = this.settings.unfocusTitle;
    if (dimTitle) {
      this.toggleDimTitle(dimTitle);
    }
    this.updateStyles();
  }
  removeStyleFromView() {
    if (this.styleElement) {
      this.styleElement.remove();
      document.body.removeClass("StilleStyle");
      document.body.removeClass("StilleUnfocusTitle");
    }
  }
  updateStyles() {
    this.styleElement.textContent = `body {
																			--unfocusedLevel: ${this.settings.unfocusedLevel};
																		}`;
  }
  toggleLabelDisplay(value, pluginOnLoad) {
    if (!value) {
      this.statusBar.remove();
    }
    if (value && !pluginOnLoad) {
      this.statusBar = this.addStatusBarItem();
      this.statusBar.setText(this.settings.statusBarLabelText);
    }
  }
  toggleDimTitle(value) {
    if (value) {
      document.body.classList.add("StilleUnfocusTitle");
    } else {
      document.body.classList.remove("StilleUnfocusTitle");
    }
  }
  toggleLabel(value) {
    return __async(this, null, function* () {
      this.toggleLabelDisplay(value);
      this.settings.statusBarLabel = value;
      yield this.saveSettings();
    });
  }
  toggleTitle(value) {
    return __async(this, null, function* () {
      this.toggleDimTitle(value);
      this.settings.unfocusTitle = value;
      yield this.saveSettings();
    });
  }
  refresh() {
    this.removeStyleFromView();
    this.addStyleToView();
  }
};
var StilleSettingTab = class extends import_obsidian.PluginSettingTab {
  constructor(app, plugin) {
    super(app, plugin);
    this.plugin = plugin;
  }
  display() {
    const { containerEl } = this;
    containerEl.empty();
    containerEl.createEl("h3", {
      text: `${nameOfApplication} \u2014 Focus on your writing.`
    });
    containerEl.createEl("h4", {
      text: "v" + this.plugin.manifest.version
    });
    containerEl.createEl("a", {
      text: `Learn more about ${nameOfApplication}`,
      href: "https://michaelsoolee.com/obsidian-focus-plugin-stille/"
    });
    containerEl.createEl("br");
    containerEl.createEl("span", {
      text: `If ${nameOfApplication} has helped you focus, consider buying me a slice of pizza \u{1F355} `
    });
    containerEl.createEl("a", {
      text: "Buy Michael, a slice of pizza",
      href: "https://michaellee.gumroad.com/l/buy-michael-pizza"
    });
    containerEl.createEl("br");
    containerEl.createEl("br");
    new import_obsidian.Setting(containerEl).setName("Opacity level for unfocused text").setDesc("This is the opacity level for text that is unfocused. This value should be a decimal value from 0.0 to 1.0.").addText((text) => text.setPlaceholder("A value from 0.0 to 1.0").setValue(this.plugin.settings.unfocusedLevel + "").onChange((value) => __async(this, null, function* () {
      this.plugin.settings.unfocusedLevel = Number(value);
      yield this.plugin.saveSettings();
      this.plugin.refresh();
    })));
    new import_obsidian.Setting(containerEl).setName("Toggle status bar label").setDesc(`Use this to toggle the visibility of the status bar label for ${nameOfApplication}.`).addToggle((barStatus) => barStatus.setValue(this.plugin.settings.statusBarLabel).onChange(() => __async(this, null, function* () {
      yield this.plugin.toggleLabel(!this.plugin.settings.statusBarLabel);
    })));
    new import_obsidian.Setting(containerEl).setName("Dim title").setDesc(`Dim the title of the note when ${nameOfApplication} is on.`).addToggle((title) => title.setValue(this.plugin.settings.unfocusTitle).onChange(() => __async(this, null, function* () {
      yield this.plugin.toggleTitle(!this.plugin.settings.unfocusTitle);
    })));
  }
};
