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

var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// main.ts
var main_exports = {};
__export(main_exports, {
  default: () => OpenWeather
});
module.exports = __toCommonJS(main_exports);
var import_obsidian = require("obsidian");
var displayErrorMsg = true;
var DEFAULT_SETTINGS = {
  location: "",
  key: "",
  units: "metric",
  excludeFolder: "",
  weatherFormat1: "%desc% \u2022 Current Temp: %temp%\xB0C \u2022 Feels Like: %feels%\xB0C\n",
  weatherFormat2: "%name%: %dateMonth4% %dateDay2% - %timeH2%:%timeM% %ampm1%\nCurrent Temp: %temp%\xB0C \u2022 Feels Like: %feels%\xB0C\nWind: %wind-speed% Km/h from the %wind-dir%^ with gusts up to %wind-gust% Km/h^\nSunrise: %sunrise% \u2022 Sunset: %sunset%\n",
  weatherFormat3: "%icon%&nbsp;%dateMonth4% %dateDay2% %dateYear1% \u2022 %timeH2%:%timeM% %ampm1% \u2022 %desc%<br>&nbsp;Recorded Temp: %temp% \u2022 Felt like: %feels%<br>&nbsp;Wind: %wind-speed% Km/h from the %wind-dir%^ with gusts up to %wind-gust% Km/h^<br>&nbsp;Sunrise: %sunrise% \u2022 Sunset: %sunset%",
  weatherFormat4: "%icon%&nbsp;%dateMonth4% %dateDay2% %dateYear1% \u2022 %timeH2%:%timeM% %ampm1% \u2022 %desc%<br>&nbsp;Current Temp: %temp% \u2022 Feels like: %feels%<br>&nbsp;Wind: %wind-speed% Km/h from the %wind-dir%^ with gusts up to %wind-gust% Km/h^<br>&nbsp;Sunrise: %sunrise% \u2022 Sunset: %sunset%",
  statusbarActive: true,
  weatherFormatSB: " | %desc% | Current Temp: %temp%\xB0C | Feels Like: %feels%\xB0C | ",
  statusbarUpdateFreq: "15"
};
var FormatWeather = class {
  constructor(location, key, units, format) {
    this.location = location;
    this.key = key;
    this.units = units;
    this.format = format;
  }
  async getWeather() {
    let weatherData;
    let weatherString;
    let url = `https://api.openweathermap.org/data/2.5/weather?q=${this.location}&appid=${this.key}&units=${this.units}`;
    let req = await fetch(url);
    let json = await req.json();
    let conditions = json.weather[0].description;
    conditions = conditions.replace(/^\w|\s\w/g, (c2) => c2.toUpperCase());
    let iconName = json.weather[0].icon;
    const iconApi = await fetch("http://openweathermap.org/img/w/" + iconName + ".png");
    let iconUrl = iconApi.url;
    let temp = json.main.temp;
    temp = Math.round(temp);
    let feelsLike = json.main.feels_like;
    feelsLike = Math.round(feelsLike);
    let tempMin = json.main.temp_min;
    tempMin = Math.round(tempMin);
    let tempMax = json.main.temp_max;
    tempMax = Math.round(tempMax);
    let pressure = json.main.pressure;
    let humidity = json.main.humidity;
    let seaLevel = json.main.sea_level;
    let groundLevel = json.main.grnd_level;
    let visibility = json.visibility;
    let windSpeed = json.wind.speed;
    if (this.units == "metric") {
      windSpeed = Math.round(windSpeed * 3.6);
    } else {
      windSpeed = Math.round(windSpeed);
    }
    let windDirection = json.wind.deg;
    windDirection = this.getCardinalDirection(windDirection);
    let windGust = json.wind.gust;
    if (windGust != void 0) {
      if (this.units == "metric") {
        windGust = Math.round(windGust * 3.6);
      } else {
        windGust = Math.round(windGust);
      }
    } else {
      windGust = "N/A";
    }
    let dt = json.dt;
    let a = new Date(dt * 1e3);
    const months1 = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"];
    const months2 = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"];
    const months3 = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
    const months4 = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
    let year1 = a.getFullYear();
    let year2str = String(year1).slice(-2);
    let year2 = Number(year2str);
    let month1 = months1[a.getMonth()];
    let month2 = months2[a.getMonth()];
    let month3 = months3[a.getMonth()];
    let month4 = months4[a.getMonth()];
    let date1 = a.getDate();
    let date2 = a.getDate() < 10 ? "0" + a.getDate() : a.getDate();
    let ampm1 = "AM";
    let ampm2 = "am";
    if (a.getHours() > 11) {
      ampm1 = "PM";
      ampm2 = "pm";
    }
    let hour1 = a.getHours();
    let hour2 = a.getHours();
    if (a.getHours() > 12) {
      hour2 = a.getHours() - 12;
    }
    if (a.getHours() == 0) {
      hour1 = 12;
      hour2 = 12;
    }
    let min = a.getMinutes() < 10 ? "0" + a.getMinutes() : a.getMinutes();
    let sec = a.getSeconds() < 10 ? "0" + a.getSeconds() : a.getSeconds();
    let sr = json.sys.sunrise;
    let b = new Date(sr * 1e3);
    let srhour = b.getHours() < 10 ? "0" + b.getHours() : b.getHours();
    let srmin = b.getMinutes() < 10 ? "0" + b.getMinutes() : b.getMinutes();
    let srsec = b.getSeconds() < 10 ? "0" + b.getSeconds() : b.getSeconds();
    let sunrise = srhour + ":" + srmin + ":" + srsec;
    let ss = json.sys.sunset;
    let c = new Date(ss * 1e3);
    let sshour = c.getHours() < 10 ? "0" + c.getHours() : c.getHours();
    let ssmin = c.getMinutes() < 10 ? "0" + c.getMinutes() : c.getMinutes();
    let sssec = c.getSeconds() < 10 ? "0" + c.getSeconds() : c.getSeconds();
    let sunset = sshour + ":" + ssmin + ":" + sssec;
    let name = json.name;
    weatherData = {
      "status": "ok",
      "conditions": conditions,
      "icon": iconUrl,
      "temp": temp,
      "feelsLike": feelsLike,
      "tempMin": tempMin,
      "tempMax": tempMax,
      "pressure": pressure,
      "humidity": humidity,
      "seaLevel": seaLevel,
      "groundLevel": groundLevel,
      "visibility": visibility,
      "windSpeed": windSpeed,
      "windDirection": windDirection,
      "windGust": windGust,
      "year1": year1,
      "year2": year2,
      "month1": month1,
      "month2": month2,
      "month3": month3,
      "month4": month4,
      "date1": date1,
      "date2": date2,
      "ampm1": ampm1,
      "ampm2": ampm2,
      "hour1": hour1,
      "hour2": hour2,
      "min": min,
      "sec": sec,
      "sunrise": sunrise,
      "sunset": sunset,
      "name": name
    };
    weatherString = this.format.replace(/%desc%/g, weatherData.conditions);
    weatherString = weatherString.replace(/%icon%/g, `<img src=${weatherData.icon} />`);
    weatherString = weatherString.replace(/%temp%/g, weatherData.temp);
    weatherString = weatherString.replace(/%feels%/g, weatherData.feelsLike);
    weatherString = weatherString.replace(/%tempmin%/g, weatherData.tempMin);
    weatherString = weatherString.replace(/%tempmax%/g, weatherData.tempMax);
    weatherString = weatherString.replace(/%pressure%/g, weatherData.pressure);
    weatherString = weatherString.replace(/%humidity%/g, weatherData.humidity);
    weatherString = weatherString.replace(/%pressure-sl%/g, weatherData.seaLevel);
    weatherString = weatherString.replace(/%pressure-gl%/g, weatherData.groundLevel);
    weatherString = weatherString.replace(/%visibility%/g, weatherData.visibility);
    weatherString = weatherString.replace(/%wind-speed%/g, weatherData.windSpeed);
    weatherString = weatherString.replace(/%wind-dir%/g, weatherData.windDirection);
    if (weatherData.windGust == "N/A") {
      weatherString = weatherString.replace(/\^.+\^/g, "");
    } else {
      weatherString = weatherString.replace(/%wind-gust%/g, weatherData.windGust);
      weatherString = weatherString.replace(/\^(.+)\^/g, "$1");
    }
    weatherString = weatherString.replace(/%dateYear1%/g, `${weatherData.year1}`);
    weatherString = weatherString.replace(/%dateYear2%/g, `${weatherData.year2}`);
    weatherString = weatherString.replace(/%dateMonth1%/g, `${weatherData.month1}`);
    weatherString = weatherString.replace(/%dateMonth2%/g, `${weatherData.month2}`);
    weatherString = weatherString.replace(/%dateMonth3%/g, `${weatherData.month3}`);
    weatherString = weatherString.replace(/%dateMonth4%/g, `${weatherData.month4}`);
    weatherString = weatherString.replace(/%dateDay1%/g, `${weatherData.date1}`);
    weatherString = weatherString.replace(/%dateDay2%/g, `${weatherData.date2}`);
    weatherString = weatherString.replace(/%ampm1%/g, `${weatherData.ampm1}`);
    weatherString = weatherString.replace(/%ampm2%/g, `${weatherData.ampm2}`);
    weatherString = weatherString.replace(/%timeH1%/g, `${weatherData.hour1}`);
    weatherString = weatherString.replace(/%timeH2%/g, `${weatherData.hour2}`);
    weatherString = weatherString.replace(/%timeM%/g, `${weatherData.min}`);
    weatherString = weatherString.replace(/%timeS%/g, `${weatherData.sec}`);
    weatherString = weatherString.replace(/%sunrise%/g, `${weatherData.sunrise}`);
    weatherString = weatherString.replace(/%sunset%/g, `${weatherData.sunset}`);
    weatherString = weatherString.replace(/%name%/g, `${weatherData.name}`);
    return weatherString;
  }
  async getWeatherString() {
    let weatherString = await this.getWeather();
    return weatherString;
  }
  getCardinalDirection(angle) {
    const directions = ["North", "Northeast", "East", "Southeast", "South", "Southwest", "West", "Northwest"];
    return directions[Math.round(angle / 45) % 8];
  }
};
var OpenWeather = class extends import_obsidian.Plugin {
  async onload() {
    await this.loadSettings();
    this.addRibbonIcon("thermometer-snowflake", "OpenWeather", (evt) => {
      const view = this.app.workspace.getActiveViewOfType(import_obsidian.MarkdownView);
      if (!view) {
        new import_obsidian.Notice("Open a Markdown file first.");
        return;
      }
      if (view.getViewType() === "markdown") {
        const md = view;
        if (md.getMode() === "source") {
          new InsertWeatherPicker(this.settings.location, this.settings.key, this.settings.units, this.settings.weatherFormat1, this.settings.weatherFormat2, this.settings.weatherFormat3, this.settings.weatherFormat4).open();
        } else {
          new import_obsidian.Notice("Markdown file must be in source mode to insert weather string.");
        }
      } else {
        new import_obsidian.Notice("Open a Markdown file first.");
      }
    });
    this.statusBar = this.addStatusBarItem();
    if (this.settings.statusbarActive) {
      if (this.settings.key.length == 0 || this.settings.location.length == 0) {
        if (displayErrorMsg) {
          new import_obsidian.Notice("OpenWeather plugin settings are undefined, check your settings.", 8e3);
          this.statusBar.setText("");
          console.log("Err:", displayErrorMsg);
          displayErrorMsg = false;
        }
      } else {
        let wstr = new FormatWeather(this.settings.location, this.settings.key, this.settings.units, this.settings.weatherFormatSB);
        let weatherStr = await wstr.getWeatherString();
        this.statusBar.setText(weatherStr);
      }
    } else {
      this.statusBar.setText("");
    }
    this.addCommand({
      id: "replace-template-string",
      name: "Replace template strings",
      editorCallback: async (editor, view) => {
        if (this.settings.weatherFormat1.length > 0) {
          if (view.data.contains("%weather1%")) {
            let wstr = new FormatWeather(this.settings.location, this.settings.key, this.settings.units, this.settings.weatherFormat1);
            let weatherStr = await wstr.getWeatherString();
            let doc = editor.getValue().replace(/%weather1%/gmi, weatherStr);
            editor.setValue(doc);
          }
        }
        if (this.settings.weatherFormat2.length > 0) {
          if (view.data.contains("%weather2%")) {
            let wstr = new FormatWeather(this.settings.location, this.settings.key, this.settings.units, this.settings.weatherFormat2);
            let weatherStr = await wstr.getWeatherString();
            let doc = editor.getValue().replace(/%weather2%/gmi, weatherStr);
            editor.setValue(doc);
          }
        }
        if (this.settings.weatherFormat3.length > 0) {
          if (view.data.contains("%weather3%")) {
            let wstr = new FormatWeather(this.settings.location, this.settings.key, this.settings.units, this.settings.weatherFormat3);
            let weatherStr = await wstr.getWeatherString();
            let doc = editor.getValue().replace(/%weather3%/gmi, weatherStr);
            editor.setValue(doc);
          }
        }
        if (this.settings.weatherFormat4.length > 0) {
          if (view.data.contains("%weather4%")) {
            let wstr = new FormatWeather(this.settings.location, this.settings.key, this.settings.units, this.settings.weatherFormat4);
            let weatherStr = await wstr.getWeatherString();
            let doc = editor.getValue().replace(/%weather4%/gmi, weatherStr);
            editor.setValue(doc);
          }
        }
      }
    });
    this.addCommand({
      id: "insert-format-one",
      name: "Insert weather format one",
      editorCallback: async (editor, view) => {
        if (this.settings.weatherFormat1.length > 0) {
          let wstr = new FormatWeather(this.settings.location, this.settings.key, this.settings.units, this.settings.weatherFormat1);
          let weatherStr = await wstr.getWeatherString();
          editor.replaceSelection(`${weatherStr}`);
        } else {
          new import_obsidian.Notice("Weather string 1 is undefined! Please add a definition for it in the OpenWeather plugin settings.", 5e3);
        }
      }
    });
    this.addCommand({
      id: "insert-format-two",
      name: "Insert weather format two",
      editorCallback: async (editor, view) => {
        if (this.settings.weatherFormat2.length > 0) {
          let wstr = new FormatWeather(this.settings.location, this.settings.key, this.settings.units, this.settings.weatherFormat2);
          let weatherStr = await wstr.getWeatherString();
          editor.replaceSelection(`${weatherStr}`);
        } else {
          new import_obsidian.Notice("Weather string 2 is undefined! Please add a definition for it in the OpenWeather plugin settings.", 5e3);
        }
      }
    });
    this.addCommand({
      id: "insert-format-three",
      name: "Insert weather format three",
      editorCallback: async (editor, view) => {
        if (this.settings.weatherFormat3.length > 0) {
          let wstr = new FormatWeather(this.settings.location, this.settings.key, this.settings.units, this.settings.weatherFormat3);
          let weatherStr = await wstr.getWeatherString();
          editor.replaceSelection(`${weatherStr}`);
        } else {
          new import_obsidian.Notice("Weather string 3 is undefined! Please add a definition for it in the OpenWeather plugin settings.", 5e3);
        }
      }
    });
    this.addCommand({
      id: "insert-format-four",
      name: "Insert weather format four",
      editorCallback: async (editor, view) => {
        if (this.settings.weatherFormat4.length > 0) {
          let wstr = new FormatWeather(this.settings.location, this.settings.key, this.settings.units, this.settings.weatherFormat4);
          let weatherStr = await wstr.getWeatherString();
          editor.replaceSelection(`${weatherStr}`);
        } else {
          new import_obsidian.Notice("Weather string 4 is undefined! Please add a definition for it in the OpenWeather plugin settings.", 5e3);
        }
      }
    });
    this.addSettingTab(new OpenWeatherSettingsTab(this.app, this));
    this.registerEvent(this.app.workspace.on("file-open", async (file) => {
      if (file) {
        await new Promise((r) => setTimeout(r, 2e3));
        await this.replaceTemplateStrings();
        await this.updateCurrentWeatherDiv();
      }
    }));
    this.registerEvent(this.app.metadataCache.on("resolved", async () => {
      await this.replaceTemplateStrings();
      await this.updateCurrentWeatherDiv();
    }));
    let updateFreq = this.settings.statusbarUpdateFreq;
    this.registerInterval(window.setInterval(() => this.updateWeather(), Number(updateFreq) * 60 * 1e3));
    this.registerInterval(window.setInterval(() => this.updateCurrentWeatherDiv(), Number(updateFreq) * 60 * 1e3));
  }
  async updateCurrentWeatherDiv() {
    const view = this.app.workspace.getActiveViewOfType(import_obsidian.MarkdownView);
    if (!view)
      return;
    if (document.getElementsByClassName("weather_current_1").length === 1) {
      const divEl = document.getElementsByClassName("weather_current_1")[0];
      let wstr = new FormatWeather(this.settings.location, this.settings.key, this.settings.units, this.settings.weatherFormat1);
      let weatherStr = await wstr.getWeatherString();
      divEl.innerHTML = weatherStr;
    }
    if (document.getElementsByClassName("weather_current_2").length === 1) {
      const divEl = document.getElementsByClassName("weather_current_2")[0];
      let wstr = new FormatWeather(this.settings.location, this.settings.key, this.settings.units, this.settings.weatherFormat2);
      let weatherStr = await wstr.getWeatherString();
      divEl.innerHTML = weatherStr;
    }
    if (document.getElementsByClassName("weather_current_3").length === 1) {
      const divEl = document.getElementsByClassName("weather_current_3")[0];
      let wstr = new FormatWeather(this.settings.location, this.settings.key, this.settings.units, this.settings.weatherFormat3);
      let weatherStr = await wstr.getWeatherString();
      divEl.innerHTML = weatherStr;
    }
    if (document.getElementsByClassName("weather_current_4").length === 1) {
      const divEl = document.getElementsByClassName("weather_current_4")[0];
      let wstr = new FormatWeather(this.settings.location, this.settings.key, this.settings.units, this.settings.weatherFormat4);
      let weatherStr = await wstr.getWeatherString();
      divEl.innerHTML = weatherStr;
    }
  }
  async replaceTemplateStrings() {
    const view = this.app.workspace.getActiveViewOfType(import_obsidian.MarkdownView);
    if (!view)
      return;
    const file = app.workspace.getActiveFile();
    if (view.file.parent.path === this.settings.excludeFolder)
      return;
    let editor = view.getViewData();
    if (editor == null)
      return;
    if (this.settings.weatherFormat1.length > 0) {
      if (editor.contains("%weather1%")) {
        let wstr = new FormatWeather(this.settings.location, this.settings.key, this.settings.units, this.settings.weatherFormat1);
        let weatherStr = await wstr.getWeatherString();
        editor = editor.replace(/%weather1%/gmi, weatherStr);
        file == null ? void 0 : file.vault.modify(file, editor);
      }
    }
    if (this.settings.weatherFormat2.length > 0) {
      if (editor.contains("%weather2%")) {
        let wstr = new FormatWeather(this.settings.location, this.settings.key, this.settings.units, this.settings.weatherFormat2);
        let weatherStr = await wstr.getWeatherString();
        editor = editor.replace(/%weather2%/gmi, weatherStr);
        file == null ? void 0 : file.vault.modify(file, editor);
      }
    }
    if (this.settings.weatherFormat3.length > 0) {
      if (editor.contains("%weather3%")) {
        let wstr = new FormatWeather(this.settings.location, this.settings.key, this.settings.units, this.settings.weatherFormat3);
        let weatherStr = await wstr.getWeatherString();
        editor = editor.replace(/%weather3%/gmi, weatherStr);
        file == null ? void 0 : file.vault.modify(file, editor);
      }
    }
    if (this.settings.weatherFormat4.length > 0) {
      if (editor.contains("%weather4%")) {
        let wstr = new FormatWeather(this.settings.location, this.settings.key, this.settings.units, this.settings.weatherFormat4);
        let weatherStr = await wstr.getWeatherString();
        editor = editor.replace(/%weather4%/gmi, weatherStr);
        file == null ? void 0 : file.vault.modify(file, editor);
      }
    }
  }
  async updateWeather() {
    if (this.settings.statusbarActive) {
      if (this.settings.key.length == 0 || this.settings.location.length == 0) {
        if (displayErrorMsg) {
          new import_obsidian.Notice("OpenWeather plugin settings are undefined, check your settings.");
          this.statusBar.setText("");
          displayErrorMsg = false;
        }
      } else {
        let wstr = new FormatWeather(this.settings.location, this.settings.key, this.settings.units, this.settings.weatherFormatSB);
        let weatherStr = await wstr.getWeatherString();
        this.statusBar.setText(weatherStr);
      }
    } else {
      this.statusBar.setText("");
    }
  }
  onunload() {
  }
  async loadSettings() {
    this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
  }
  async saveSettings() {
    await this.saveData(this.settings);
  }
};
var ALL_COMMANDS = [];
var InsertWeatherPicker = class extends import_obsidian.SuggestModal {
  constructor(location, key, units, weatherFormat1, weatherFormat2, weatherFormat3, weatherFormat4) {
    super(app);
    this.location = location;
    this.key = key;
    this.units = units;
    this.weatherFormat1 = weatherFormat1;
    this.weatherFormat2 = weatherFormat2;
    this.weatherFormat3 = weatherFormat3;
    this.weatherFormat4 = weatherFormat4;
  }
  async getSuggestions(query) {
    ALL_COMMANDS = [];
    if (this.weatherFormat1.length > 0) {
      let wstr = new FormatWeather(this.location, this.key, this.units, this.weatherFormat1);
      let weatherStr = await wstr.getWeatherString();
      this.weatherFormat1 = weatherStr;
      ALL_COMMANDS.push({ command: "Insert Weather String - Format 1", format: this.weatherFormat1 });
    }
    if (this.weatherFormat2.length > 0) {
      let wstr = new FormatWeather(this.location, this.key, this.units, this.weatherFormat2);
      let weatherStr = await wstr.getWeatherString();
      this.weatherFormat2 = weatherStr;
      ALL_COMMANDS.push({ command: "Insert Weather String - Format 2", format: this.weatherFormat2 });
    }
    if (this.weatherFormat3.length > 0) {
      let wstr = new FormatWeather(this.location, this.key, this.units, this.weatherFormat3);
      let weatherStr = await wstr.getWeatherString();
      this.weatherFormat3 = weatherStr;
      ALL_COMMANDS.push({ command: "Insert Weather String - Format 3", format: this.weatherFormat3 });
    }
    if (this.weatherFormat4.length > 0) {
      let wstr = new FormatWeather(this.location, this.key, this.units, this.weatherFormat4);
      let weatherStr = await wstr.getWeatherString();
      this.weatherFormat4 = weatherStr;
      ALL_COMMANDS.push({ command: "Insert Weather String - Format 4", format: this.weatherFormat4 });
    }
    ALL_COMMANDS.push({ command: "Replace Template Strings", format: "Replace all occurences of %weather1%, %weather2%, %weather3% and %weather4%\nin the current document." });
    return ALL_COMMANDS.filter((command) => command.command.toLowerCase().includes(query.toLowerCase()));
  }
  renderSuggestion(command, el) {
    el.createEl("div", { text: command.command });
    el.createEl("small", { text: command.format });
  }
  async onChooseSuggestion(command, evt) {
    this.command = command.command;
    this.format = command.format;
    this.close();
    const view = this.app.workspace.getActiveViewOfType(import_obsidian.MarkdownView);
    if (!view)
      return;
    if (view.file.parent.path === "Templates")
      return;
    let editor = view.getViewData();
    if (editor == null)
      return;
    if (command.command == "Replace Template Strings") {
      if (this.weatherFormat1.length > 0) {
        editor = editor.replace(/%weather1%/gmi, this.weatherFormat1);
        view.setViewData(editor, false);
      }
      if (this.weatherFormat2.length > 0) {
        editor = editor.replace(/%weather2%/gmi, this.weatherFormat2);
        view.setViewData(editor, false);
      }
      if (this.weatherFormat3.length > 0) {
        editor = editor.replace(/%weather3%/gmi, this.weatherFormat3);
        view.setViewData(editor, false);
      }
      if (this.weatherFormat4.length > 0) {
        editor = editor.replace(/%weather4%/gmi, this.weatherFormat4);
        view.setViewData(editor, false);
      }
    } else {
      view.editor.replaceSelection(this.format);
    }
  }
};
var OpenWeatherSettingsTab = class extends import_obsidian.PluginSettingTab {
  constructor(app2, plugin) {
    super(app2, plugin);
    this.plugin = plugin;
  }
  display() {
    const { containerEl } = this;
    containerEl.empty();
    const abstractFiles = app.vault.getAllLoadedFiles();
    const folders = [];
    abstractFiles.forEach((folder) => {
      if (folder instanceof import_obsidian.TFolder && folder.name.length > 0) {
        folders.push(folder);
      }
    });
    containerEl.createEl("h2", { text: "Settings for calling OpenWeather API" });
    new import_obsidian.Setting(containerEl).setName("Enter Location").setDesc("Name of the city you want to retrieve weather for").addText((text) => text.setPlaceholder("Enter city Eg. edmonton").setValue(this.plugin.settings.location).onChange(async (value) => {
      this.plugin.settings.location = value;
      await this.plugin.saveSettings();
      await this.plugin.updateWeather();
    }));
    new import_obsidian.Setting(containerEl).setName("OpenWeather API Key").setDesc("A free OpenWeather API key is required for the plugin to work. Go to https://openweathermap.org to register and get a key").addText((text) => text.setPlaceholder("Enter OpenWeather API Key").setValue(this.plugin.settings.key).onChange(async (value) => {
      this.plugin.settings.key = value;
      await this.plugin.saveSettings();
      await this.plugin.updateWeather();
    }));
    new import_obsidian.Setting(containerEl).setName("Units of Measurement").setDesc("Units of measurement. Standard, Metric and Imperial units are available").addDropdown((dropDown) => {
      dropDown.addOption("standard", "Standard");
      dropDown.addOption("metric", "Metric");
      dropDown.addOption("imperial", "Imperial");
      dropDown.onChange(async (value) => {
        this.plugin.settings.units = value;
        await this.plugin.saveSettings();
        await this.plugin.updateWeather();
      }).setValue(this.plugin.settings.units);
    });
    containerEl.createEl("br");
    containerEl.createEl("h2", { text: "Folder to Exclude From Automatic Template Strings Replacement" });
    new import_obsidian.Setting(containerEl).setName("Exclude Folder").setDesc("Folder to Exclude from Automatic Template String Replacement").addDropdown((dropDown) => {
      folders.forEach((e) => {
        dropDown.addOption(e.name, e.name);
      });
      dropDown.onChange(async (value) => {
        this.plugin.settings.excludeFolder = value;
        await this.plugin.saveSettings();
      }).setValue(this.plugin.settings.excludeFolder);
    });
    containerEl.createEl("br");
    containerEl.createEl("h2", { text: "Weather Strings Formatting (Up to 4 Strings are Available)" });
    new import_obsidian.Setting(containerEl).setName("Weather String Format 1").setDesc("Weather string format one").addTextArea((textArea) => {
      textArea.setPlaceholder("Weather String Format 1").setValue(this.plugin.settings.weatherFormat1).onChange(async (value) => {
        this.plugin.settings.weatherFormat1 = value;
        await this.plugin.saveSettings();
      });
      textArea.inputEl.setAttr("rows", 10);
      textArea.inputEl.setAttr("cols", 60);
    });
    new import_obsidian.Setting(containerEl).setName("Weather String Format 2").setDesc("Weather string format two").addTextArea((textArea) => {
      textArea.setPlaceholder("Weather String Format 2").setValue(this.plugin.settings.weatherFormat2).onChange(async (value) => {
        this.plugin.settings.weatherFormat2 = value;
        await this.plugin.saveSettings();
      });
      textArea.inputEl.setAttr("rows", 10);
      textArea.inputEl.setAttr("cols", 60);
    });
    new import_obsidian.Setting(containerEl).setName("Weather String Format 3").setDesc("Weather string format three").addTextArea((textArea) => {
      textArea.setPlaceholder("Weather String Format 3").setValue(this.plugin.settings.weatherFormat3).onChange(async (value) => {
        this.plugin.settings.weatherFormat3 = value;
        await this.plugin.saveSettings();
      });
      textArea.inputEl.setAttr("rows", 10);
      textArea.inputEl.setAttr("cols", 60);
    });
    new import_obsidian.Setting(containerEl).setName("Weather String Format 4").setDesc("Weather string format four").addTextArea((textArea) => {
      textArea.setPlaceholder("Weather String Format 4").setValue(this.plugin.settings.weatherFormat4).onChange(async (value) => {
        this.plugin.settings.weatherFormat4 = value;
        await this.plugin.saveSettings();
      });
      textArea.inputEl.setAttr("rows", 10);
      textArea.inputEl.setAttr("cols", 60);
    });
    if (import_obsidian.Platform.isDesktop) {
      containerEl.createEl("br");
      containerEl.createEl("h2", { text: "Show Weather in Statusbar Options" });
      new import_obsidian.Setting(containerEl).setName("Show Weather in Statusbar").setDesc("Enable weather display in statusbar").addToggle((toggle) => toggle.setValue(this.plugin.settings.statusbarActive).onChange(async (value) => {
        this.plugin.settings.statusbarActive = value;
        await this.plugin.saveSettings();
        await this.plugin.updateWeather();
      }));
      new import_obsidian.Setting(containerEl).setName("Weather String Format Statusbar").setDesc("Weather string format for the statusbar").addTextArea((textArea) => {
        textArea.setPlaceholder("Statusbar Weather Format").setValue(this.plugin.settings.weatherFormatSB).onChange(async (value) => {
          this.plugin.settings.weatherFormatSB = value;
          await this.plugin.saveSettings();
          await this.plugin.updateWeather();
        });
        textArea.inputEl.setAttr("rows", 10);
        textArea.inputEl.setAttr("cols", 60);
      });
    } else {
      this.plugin.settings.statusbarActive = false;
    }
    containerEl.createEl("br");
    containerEl.createEl("h2", { text: `Show Weather in Statusbar and Dynamic DIV's Delay` });
    new import_obsidian.Setting(containerEl).setName("Update Frequency").setDesc("Update frequency for weather information displayed on the statusbar and dynamic DIV's").addDropdown((dropDown) => {
      dropDown.addOption("1", "Every Minute");
      dropDown.addOption("5", "Every 5 Minutes");
      dropDown.addOption("10", "Every 10 Minutes");
      dropDown.addOption("15", "Every 15 Minutes");
      dropDown.addOption("20", "Every 20 Minutes");
      dropDown.addOption("30", "Every 30 Minutes");
      dropDown.addOption("60", "Every Hour");
      dropDown.onChange(async (value) => {
        this.plugin.settings.statusbarUpdateFreq = value;
        await this.plugin.saveSettings();
        await this.plugin.updateWeather();
      }).setValue(this.plugin.settings.statusbarUpdateFreq);
    });
  }
};
