import { r as registerInstance, j as createEvent, h, g as getElement } from './index-aeac5cad.js';
import './_commonjsHelpers-91fffb88.js';
import { b as Schedule } from './index-ec2a4942.js';
import { d as dist } from './index-fdd60c34.js';

const sv = {
  Date: "Datum",
  Month: "Månad",
  Weekday: "Dag",
  Monday: "Måndag",
  Tuesday: "Tisdag",
  Wednesday: "Onsdag",
  Thursday: "Torsdag",
  Friday: "Fredag",
  Saturday: "Lördag",
  Sunday: "Söndag",
  January: "Januari",
  February: "Februari",
  March: "Mars",
  May: "Maj",
  June: "Juni",
  July: "Juli",
  August: "Augusti",
  October: "Oktober",
  First: "Första",
  Second: "Andra",
  Third: "Tredje",
};

function create(language) {
  return dist.create({
    sv,
  }, language);
}

const styleCss = ".sc-payfunc-select-offset-h{display:flex;justify-content:space-between}[frequency=daily].sc-payfunc-select-offset-h{display:none}smoothly-select.sc-payfunc-select-offset{display:grid;flex-grow:2}smoothly-select.sc-payfunc-select-offset:nth-of-type(2){border-left:1px solid rgb(var(--smoothly-medium-color))}";

const PayfuncSelectOffset = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.offsetChanged = createEvent(this, "offsetChanged", 7);
    this.days = [];
  }
  componentWillLoad() {
    this.t = create(this.element);
    this.weekdays = ["Weekday", ...Schedule.weekdays];
    this.quarterly = ["Month", ...Schedule.quarterly];
    this.months = ["Month", ...Schedule.months];
    const days = ["Date", ...Schedule.daysOfMonth.map(day => (day >= 0 ? (day + 1).toString() : day.toString()))];
    this.days = days;
    this.setValues();
  }
  onSelectionChanged(e) {
    const value = Number(e.detail.value);
    e.detail.value = value != undefined && value >= 0 ? (value - 1).toString() : e.detail.value;
    if (e.detail.identifier == "offset") {
      this.value = e.detail.value;
      this.offsetChanged.emit(this.value2 ? [this.value, this.value2] : this.value);
    }
    else if (e.detail.identifier == "offset2") {
      this.value2 = e.detail.value;
      this.offsetChanged.emit([this.value, this.value2]);
    }
  }
  setValues() {
    switch (this.frequency) {
      case "weekly":
        this.values = this.weekdays;
        this.value = "Weekday";
        this.value2 = undefined;
        break;
      case "monthly":
        this.values = this.days;
        this.value = "Date";
        this.value2 = undefined;
        break;
      case "quarterly":
        this.values = this.quarterly;
        this.value = "Month";
        this.values2 = this.days;
        this.value2 = "Date";
        break;
      case "yearly":
        this.values = this.months;
        this.value = "Month";
        this.values2 = this.days;
        this.value2 = "Date";
        break;
      default:
        break;
    }
  }
  render() {
    return [
      this.values && this.value ? (h("smoothly-select", { identifier: "offset", background: "transparent" }, this.values.map(option => this.value == option ? (h("option", { value: option, selected: true }, this.t(option))) : (h("option", { value: option }, this.t(option)))))) : ([]),
      this.values2 && this.value2 && this.value != "Month" ? (h("smoothly-select", { identifier: "offset2", background: "transparent" }, this.values2.map(option => this.value2 == option ? (h("option", { value: option, selected: true }, this.t(option))) : (h("option", { value: option }, this.t(option)))))) : ([]),
    ];
  }
  get element() { return getElement(this); }
  static get watchers() { return {
    "frequency": ["setValues"]
  }; }
};
PayfuncSelectOffset.style = styleCss;

export { PayfuncSelectOffset as payfunc_select_offset };
