import { r as t, g as i, h as e, H as s, a as o } from "./p-9b9ccd0c.js";

import { L as a } from "./p-311eedf3.js";

import { v as n, c as r } from "./p-b32b6b1f.js";

import { c as l } from "./p-c5196b3b.js";

const h = "button.button-secondary{border-color:var(--color-border-neutral-default)}:host{display:grid;block-size:100%;grid-template-rows:1fr max-content}.commit-date-container,.commit-number-container{display:grid;gap:var(--spacing-gap-xl)}.commit-date-container{grid-template-rows:max-content max-content max-content max-content}.commit-number-container{grid-template-rows:max-content max-content max-content}.heading{margin-block:0}.tooltip{position:absolute}";

var c = undefined && undefined.__classPrivateFieldGet || function(t, i, e, s) {
  if (e === "a" && !s) throw new TypeError("Private accessor was defined without a getter");
  if (typeof i === "function" ? t !== i || !s : !i.has(t)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
  return e === "m" ? s : e === "a" ? s.call(t) : s ? s.value : i.get(t);
};

var m = undefined && undefined.__classPrivateFieldSet || function(t, i, e, s, o) {
  if (s === "m") throw new TypeError("Private method is not writable");
  if (s === "a" && !o) throw new TypeError("Private accessor was defined without a setter");
  if (typeof i === "function" ? t !== i || !o : !i.has(t)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
  return s === "a" ? o.call(t, e) : o ? o.value = e : i.set(t, e), e;
};

var d, u, f, p, b, v, y, w, g, k, C, D, M, W, _, x;

const N = [ "resets/box-sizing", "utils/form", "utils/spacing", "utils/layout", "components/checkbox", "components/button", "components/edit", "components/radio-group", "components/tooltip", "utils/layout" ];

const T = {
  fromCommitDate: {
    value: "fromCommitDate"
  },
  fromCommitNumber: {
    value: "fromCommitNumber"
  }
};

const j = class {
  constructor(s) {
    t(this, s);
    d.set(this, void 0);
    u.set(this, void 0);
    f.set(this, void 0);
    p.set(this, i(`./gx-ide-assets/team-dev-bring-all-changes-selector/shortcuts.json`));
    // TODO: evaluate if this should be a global helper function.
    // It is used on other dialogs as well.
        b.set(this, (t => {
      var i, s, o;
      return ((s = (i = this.validatableControls) === null || i === void 0 ? void 0 : i.get(t === null || t === void 0 ? void 0 : t.id)) === null || s === void 0 ? void 0 : s.hasError) && ((o = this.validatableControls.get(t.id)) === null || o === void 0 ? void 0 : o.message) && e("ch-tooltip", {
        class: "tooltip",
        actionElement: t,
        blockAlign: l.tooltipSettings.blockAlign,
        inlineAlign: l.tooltipSettings.inlineAlign,
        delay: l.tooltipSettings.delay
      }, this.validatableControls.get(t.id).message);
    }));
    v.set(this, (t => {
      t.forEach((t => {
        if (t.id && !this.validatableControls.has(t.id)) {
          this.validatableControls.set(t.id, {
            reference: t,
            hasError: false,
            message: undefined
          });
        }
      }));
    }));
    y.set(this, (async () => {
      await this.cancelCallback();
    }));
    w.set(this, (async () => {
      let t;
      const i = {
        operationType: this.selectedOption,
        fromDate: this.selectedOption === "fromCommitDate" ? this.sinceCommitDate : undefined,
        fromRevision: this.selectedOption === "fromCommitNumber" ? this.sinceCommitNumber : undefined
      };
      t = await this.confirmCallback(i);
      this.validatableControls = n(t, this.validatableControls);
    }));
    g.set(this, (t => {
      const i = new Date;
      let e = new Date;
      switch (t) {
       case "lastSevenDays":
        e.setDate(i.getDate() - 7);
        break;

       case "lastThirtyDays":
        e.setDate(i.getDate() - 30);
        break;

       case "lastNinetyDays":
        e.setDate(i.getDate() - 90);
        break;
      }
      this.sinceCommitDate = e;
    }));
    k.set(this, (t => {
      const i = t.detail;
      if (i && i !== "") {
        const [t, e, s] = i.split("-").map(Number);
        this.sinceCommitDate = new Date(t, e - 1, s);
      } else {
        this.sinceCommitDate = undefined;
      }
      r(this.validatableControls, "commit-date");
    }));
    C.set(this, (t => {
      this.sinceCommitNumber = Number(t.detail);
      r(this.validatableControls, "commit-number");
    }));
    D.set(this, (t => {
      this.selectedOption = t.detail;
      if (this.selectedOption === "fromCommitDate") {
        this.sinceCommitNumber = undefined;
        r(this.validatableControls, "commit-number");
      } else if (this.selectedOption === "fromCommitNumber") {
        this.sinceCommitDate = undefined;
        r(this.validatableControls, "commit-date");
      }
    }));
    M.set(this, (() => {
      if (this.selectedOption === "fromCommitDate") {
        // Validate that sinceCommitDate is a valid date
        return !(this.sinceCommitDate instanceof Date && !isNaN(this.sinceCommitDate.getTime()));
      } else if (this.selectedOption === "fromCommitNumber") {
        // Validate that sinceCommitNumber is a valid number
        return !(this.sinceCommitNumber > 0);
      }
      return true;
    }));
    W.set(this, (() => {
      var t;
      if (this.selectedOption !== "fromCommitDate") {
        return null;
      }
      return e("div", {
        class: "layout layout--cols-2-1"
      }, e("div", {
        class: "layout__panel"
      }, e("div", {
        class: "field field-block"
      }, e("label", {
        class: "label",
        htmlFor: "commit-date"
      }, c(this, d, "f").labels.commitDate), e("ch-edit", {
        class: {
          input: true,
          "input-error": (t = this.validatableControls.get("commit-date")) === null || t === void 0 ? void 0 : t.hasError
        },
        id: "commit-date",
        type: "date",
        value: this.sinceCommitDate && this.sinceCommitDate.toISOString().split("T")[0],
        onInput: c(this, k, "f"),
        ref: t => m(this, f, t, "f")
      }), c(this, b, "f").call(this, c(this, f, "f")))));
    }));
    _.set(this, (() => {
      var t;
      if (this.selectedOption !== "fromCommitNumber") {
        return null;
      }
      return e("div", {
        class: "layout layout--cols-2-1"
      }, e("div", {
        class: "layout__panel"
      }, e("div", {
        class: "field field-block"
      }, e("label", {
        class: "label",
        htmlFor: "commit-number"
      }, c(this, d, "f").labels.commitNumber), e("ch-edit", {
        class: {
          input: true,
          "input-error": (t = this.validatableControls.get("commit-number")) === null || t === void 0 ? void 0 : t.hasError
        },
        id: "commit-number",
        type: "number",
        placeholder: c(this, d, "f").placeholders.commitNumber,
        onInput: c(this, C, "f"),
        mode: "numeric",
        ref: t => m(this, u, t, "f")
      }), c(this, b, "f").call(this, c(this, u, "f")))));
    }));
    x.set(this, (() => {
      if (this.selectedOption !== "fromCommitDate") {
        return null;
      }
      return e("div", {
        class: "layout layout--cols-3"
      }, e("div", {
        class: "layout__panel"
      }, e("button", {
        id: "last-seven-days-button",
        class: "button-secondary",
        onClick: () => c(this, g, "f").call(this, "lastSevenDays")
      }, c(this, d, "f").captions.lastSevenDays)), e("div", {
        class: "layout__panel"
      }, e("button", {
        id: "last-thirty-days-button",
        class: "button-secondary",
        onClick: () => c(this, g, "f").call(this, "lastThirtyDays")
      }, c(this, d, "f").captions.lastThirtyDays)), e("div", {
        class: "layout__panel"
      }, e("button", {
        id: "last-ninety-days-button",
        class: "button-secondary",
        onClick: () => c(this, g, "f").call(this, "lastNinetyDays")
      }, c(this, d, "f").captions.lastNinetyDays)));
    }));
    this.sinceCommitDate = undefined;
    this.sinceCommitNumber = undefined;
    this.selectedOption = T.fromCommitDate.value;
    this.radioGroupModel = [];
    this.validatableControls = new Map;
    this.cancelCallback = undefined;
    this.confirmCallback = undefined;
  }
  async componentWillLoad() {
    m(this, d, await a.getComponentStrings(this.el), "f");
    this.radioGroupModel = [ {
      value: T.fromCommitDate.value,
      caption: c(this, d, "f").captions.commitDate
    }, {
      value: T.fromCommitNumber.value,
      caption: c(this, d, "f").captions.commitNumber
    } ];
  }
  componentDidRender() {
    if (this.selectedOption === "fromCommitDate" && c(this, f, "f")) {
      c(this, v, "f").call(this, [ c(this, f, "f") ]);
    }
    if (this.selectedOption === "fromCommitNumber" && c(this, u, "f")) {
      c(this, v, "f").call(this, [ c(this, u, "f") ]);
    }
  }
  render() {
    return e(s, {
      class: "widget"
    }, e("ch-theme", {
      model: N
    }), e("ch-shortcuts", {
      src: c(this, p, "f")
    }), e("div", {
      class: {
        "spacing-body": true,
        "commit-date-container": this.selectedOption === "fromCommitDate",
        "commit-number-container": this.selectedOption === "fromCommitNumber"
      }
    }, e("p", {
      class: "body-regular-m heading"
    }, c(this, d, "f").labels.selectRange), e("ch-radio-group-render", {
      class: "radio-group",
      direction: "horizontal",
      model: this.radioGroupModel,
      onChange: c(this, D, "f"),
      value: T.fromCommitDate.value
    }), c(this, x, "f").call(this), c(this, W, "f").call(this), c(this, _, "f").call(this)), e("footer", {
      class: "dialog-footer-with-border spacing-body"
    }, e("div", {
      class: "buttons-spacer"
    }, e("button", {
      class: "button-secondary",
      id: "cancel-button",
      onClick: c(this, y, "f")
    }, c(this, d, "f").buttons.cancel), e("button", {
      id: "confirm-button",
      class: "button-primary",
      onClick: c(this, w, "f"),
      disabled: c(this, M, "f").call(this)
    }, c(this, d, "f").buttons.confirm))));
  }
  static get assetsDirs() {
    return [ "gx-ide-assets/team-dev-bring-all-changes-selector" ];
  }
  get el() {
    return o(this);
  }
};

d = new WeakMap, u = new WeakMap, f = new WeakMap, p = new WeakMap, b = new WeakMap, 
v = new WeakMap, y = new WeakMap, w = new WeakMap, g = new WeakMap, k = new WeakMap, 
C = new WeakMap, D = new WeakMap, M = new WeakMap, W = new WeakMap, _ = new WeakMap, 
x = new WeakMap;

j.style = h;

export { j as gx_ide_team_dev_bring_all_changes_selector };
//# sourceMappingURL=p-e883cd82.entry.js.map