import { Component, Element, Event, h, Prop, State } from "@stencil/core";
import { Schedule } from "@payfunc/model";
import * as translation from "./translation";
export class PayfuncSchedule {
  constructor() {
    this.advanced = false;
  }
  componentWillLoad() {
    this.t = translation.create(this.element);
    this.frequency = typeof this.schedule == "object" ? this.schedule.frequency : this.schedule;
    this.offset = Schedule.is(this.schedule) && this.schedule.frequency != "daily" ? this.schedule.offset : undefined;
    this.divisor = Schedule.is(this.schedule) ? this.schedule.divisor : undefined;
  }
  render() {
    return [
      h("section", null,
        h("label", null, this.t("frequency")),
        h("smoothly-display", { type: "text", value: this.t(this.frequency) })),
      (this.frequency == "quarterly" || this.frequency == "yearly") && this.offset != undefined ? (h("section", null,
        h("label", null, this.t("month")),
        h("smoothly-display", { type: "text", value: this.t(Array.isArray(this.offset) ? Schedule.months[this.offset[0]] : Schedule.months[this.offset]) }))) : ([]),
      (this.frequency == "monthly" ||
        ((this.frequency == "yearly" || this.frequency == "quarterly") && Array.isArray(this.offset))) &&
        this.offset != undefined ? (h("section", null,
        h("label", null, this.t("date")),
        h("smoothly-display", { type: "text", value: this.t(Array.isArray(this.offset) ? (this.offset[1] + 1).toString() : (this.offset + 1).toString()) }))) : ([]),
      this.frequency == "weekly" && !Array.isArray(this.offset) && this.offset != undefined ? (h("section", null,
        h("label", null, this.t("weekday")),
        h("smoothly-display", { type: "text", value: this.t(Schedule.weekdays[this.offset - 1]) }))) : ([]),
      this.divisor != undefined ? (h("section", null,
        h("label", null, this.t("divisor")),
        h("smoothly-display", { type: "text", value: Array.isArray(this.divisor)
            ? this.divisor[0].toString() + " / " + this.divisor[1].toString()
            : this.divisor.toString() }))) : ([]),
    ];
  }
  static get is() { return "payfunc-schedule"; }
  static get encapsulation() { return "scoped"; }
  static get originalStyleUrls() { return {
    "$": ["style.css"]
  }; }
  static get styleUrls() { return {
    "$": ["style.css"]
  }; }
  static get properties() { return {
    "schedule": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "Schedule | Frequency",
        "resolved": "\"daily\" | \"monthly\" | \"quarterly\" | \"weekly\" | \"yearly\" | { frequency: \"daily\"; divisor?: number | [number, number] | undefined; } | { frequency: \"monthly\"; divisor?: number | [number, number] | undefined; offset?: 0 | 2 | 1 | 3 | 4 | 5 | 6 | -3 | -2 | -1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | undefined; } | { frequency: \"quarterly\"; divisor?: number | [number, number] | undefined; offset?: 0 | 2 | 1 | [monthOfQuarter, dayOfMonth] | undefined; } | { frequency: \"weekly\"; divisor?: number | [number, number] | undefined; offset?: 0 | 2 | 1 | 3 | 4 | 5 | 6 | undefined; } | { frequency: \"yearly\"; divisor?: number | [number, number] | undefined; offset?: 0 | 2 | 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | [monthOfYear, dayOfMonth] | undefined; }",
        "references": {
          "Schedule": {
            "location": "import",
            "path": "@payfunc/model"
          },
          "Frequency": {
            "location": "import",
            "path": "@payfunc/model"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "schedule",
      "reflect": false
    }
  }; }
  static get states() { return {
    "advanced": {},
    "t": {},
    "frequency": {},
    "offset": {},
    "dueDates": {},
    "divisor": {}
  }; }
  static get events() { return [{
      "method": "notice",
      "name": "notice",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "any",
        "resolved": "any",
        "references": {}
      }
    }]; }
  static get elementRef() { return "element"; }
}
