import "../chunks/cropper.sPLHEPuZ.js";
import { C as U } from "../chunks/button.CAa1kvwe.js";
import P from "./space.js";
import { C as _ } from "../chunks/typography.DJC_UXgs.js";
import { n as h, C as H } from "../chunks/lib-cortex-element.CVMmyPMC.js";
import { b as at, c as ot } from "../chunks/asset.53rQdj1g.js";
import { c as W } from "../chunks/component.styles.CRO4Odto.js";
import { U as a, T as d } from "../chunks/asset-link-format.BSRDqHg7.js";
import { c as F } from "../chunks/custom-element.L4WJXn1j.js";
import { L as E } from "../chunks/i18n.BABe9hN4.js";
import { w as S } from "../chunks/watch.BCJD77bD.js";
import { s as et, c as it } from "../chunks/number.Dp6Prh44.js";
import { b as Y } from "../chunks/transformation.Cqz3hPaQ.js";
import { i as N, x as m, E as rt } from "../chunks/lit-element.jLBm65_O.js";
import { r as f } from "../chunks/state.CSDxrqLd.js";
import { n as C } from "../chunks/when.Dr1es41R.js";
import T from "./details.js";
import ht from "./divider.js";
import I from "./icon.js";
import { C as K } from "../chunks/icon-button.C2s3pHG4.js";
import Z from "./input.js";
import { C as Q } from "../chunks/option.DGXQzdtb.js";
import G from "./select.js";
import { c as nt } from "../chunks/image.o1b1mD-J.js";
import { e as V } from "../chunks/query.BBf1UFkC.js";
import { c as L } from "../chunks/repeat.DbF2p5ae.js";
import { o as A } from "../chunks/style-map.llVFPd__.js";
import st from "./tooltip.js";
import lt from "./button-group.js";
import ct from "./checkbox.js";
const pt = N`.asset-link-format__details{--header-padding:var(--cx-spacing-small) var(--cx-spacing-medium)}.asset-link-format__details::part(icon){width:var(--cx-font-size-3x-large);height:var(--cx-font-size-3x-large);background-color:var(--cx-color-neutral-100);border-radius:var(--cx-border-radius-large);color:var(--cx-color-neutral-600);font-size:var(--cx-font-size-large);justify-content:center;align-items:center;display:flex}.asset-link-format__details::part(input-label){color:var(--cx-color-neutral-400);margin-inline-start:var(--cx-spacing-small)}.asset-link-format__header{padding:var(--cx-spacing-medium)}.asset-link-format__section-header{padding:0 var(--cx-spacing-medium);border-top:var(--section-header-border-width,1px) solid var(--cx-color-neutral-200);background-color:var(--cx-color-neutral-50)}.asset-link-format__undo,.asset-link-format__reset{--color:var(--cx-color-primary);--background-color:transparent}`, dt = N`cx-details::part(base){border-bottom-width:0}cx-space{width:100%}cx-space cx-input{flex:1}.crop__unit-select{width:120px}.crop__input-group{flex:1;display:flex}`;
var ut = Object.defineProperty, mt = Object.getOwnPropertyDescriptor, u = (t, e, i, s) => {
  for (var o = s > 1 ? void 0 : s ? mt(e, i) : e, r = t.length - 1, n; r >= 0; r--)
    (n = t[r]) && (o = (s ? n(e, i, o) : n(o)) || o);
  return s && o && ut(e, i, o), o;
};
let p = class extends H {
  constructor() {
    super(...arguments), this.localize = new E(this), this.open = !1, this.width = 0, this.height = 0, this.maxWidth = 0, this.maxHeight = 0, this.ratioWidth = 1, this.ratioHeight = 1, this.percentageWidth = 0, this.percentageHeight = 0, this.unit = a.Pixel, this.disabledApply = !1, this.lastAppliedSetting = {
      [a.Pixel]: {
        height: 0,
        percentageHeight: 100,
        percentageWidth: 100,
        unit: a.Pixel,
        width: 0,
        x: 0,
        y: 0
      },
      [a.AspectRatio]: {
        height: 1,
        percentageHeight: 100,
        percentageWidth: 100,
        unit: a.AspectRatio,
        width: 1,
        x: 0,
        y: 0
      }
    }, this.loading = !1, this.cropModes = [], this.focusModes = [], this.focusMode = "manual", this.cropMode = "free", this.keepAspectRatio = !1, this.invalidWidth = !1, this.invalidHeight = !1, this.aspectRatio = 0;
  }
  get selectedMode() {
    return this.cropModes.find((t) => t.value === this.cropMode);
  }
  async handleCropModeChange() {
    if (typeof this.cropMode == "string" && /^\d+:\d+$/.test(this.cropMode)) {
      const [t, e] = this.cropMode.split(":").map(Number);
      this.aspectRatio = t / e;
      return;
    }
    if (this.keepAspectRatio) {
      if (this.unit === a.Pixel && this.width && this.height) {
        this.aspectRatio = this.width / this.height;
        return;
      } else if (this.unit === a.AspectRatio && this.ratioWidth && this.ratioHeight) {
        this.aspectRatio = this.ratioWidth / this.ratioHeight;
        return;
      }
    }
    if (this.maxWidth && this.maxHeight) {
      this.aspectRatio = this.maxWidth / this.maxHeight;
      return;
    }
    this.aspectRatio = 1;
  }
  async handleOpenChange() {
    this.cropMode = "free", await this.updateComplete, this.open || (this.width = this.lastAppliedSetting[a.Pixel].width, this.height = this.lastAppliedSetting[a.Pixel].height, this.unit = a.Pixel, this.emit("cx-asset-link-format-crop-change", {
      detail: {
        height: this.lastAppliedSetting[a.Pixel].height,
        keepAspectRatio: this.keepAspectRatio,
        unit: a.Pixel,
        width: this.lastAppliedSetting[a.Pixel].width
      }
    }));
  }
  handleWidthChange(t) {
    if (!t.target.value) {
      this.invalidWidth = !0;
      return;
    }
    this.invalidWidth = !1;
    let e = Number(t.target.value);
    this.unit === a.Pixel && (e = Math.max(Math.min(e, this.maxWidth), 1)), t.target.value = e.toString();
    let i = this.unit === a.Pixel ? this.height : this.ratioHeight, s = !1;
    this.keepAspectRatio && (i = Math.round(e / this.aspectRatio), this.unit === a.Pixel && i > this.maxHeight && (i = this.maxHeight, s = !0)), this.invalidHeight = !1, this.emit("cx-asset-link-format-crop-change", {
      detail: {
        breakAspectRatio: s,
        height: i,
        keepAspectRatio: this.keepAspectRatio,
        unit: this.unit,
        width: e
      }
    });
  }
  handleHeightChange(t) {
    if (!t.target.value) {
      this.invalidHeight = !0;
      return;
    }
    this.invalidHeight = !1;
    let e = Number(t.target.value);
    this.unit === a.Pixel && (e = Math.max(Math.min(e, this.maxHeight), 1)), t.target.value = e.toString();
    let i = this.unit === a.Pixel ? this.width : this.ratioWidth, s = !1;
    this.keepAspectRatio && (i = Math.round(e * this.aspectRatio), this.unit === a.Pixel && i > this.maxWidth && (i = this.maxWidth, s = !0)), this.invalidWidth = !1, this.emit("cx-asset-link-format-crop-change", {
      detail: {
        breakAspectRatio: s,
        height: e,
        keepAspectRatio: this.keepAspectRatio,
        unit: this.unit,
        width: i
      }
    });
  }
  onCropModeChange(t) {
    const e = t.target.value, i = this.cropModes.find((s) => s.value === e)?.auto;
    if (e === "free")
      this.selectedMode?.auto && this.emit("cx-asset-link-format-crop-change", {
        detail: {
          height: this.lastAppliedSetting[a.Pixel].height,
          keepAspectRatio: !1,
          silent: !0,
          unit: a.Pixel,
          width: this.lastAppliedSetting[a.Pixel].width
        }
      });
    else if (!i) {
      const [s, o] = e.split(":").map(Number);
      if (this.unit === a.Pixel) {
        const { height: r, width: n } = nt(
          this.maxWidth,
          this.maxHeight,
          s,
          o
        );
        this.emit("cx-asset-link-format-crop-change", {
          detail: {
            height: r,
            keepAspectRatio: !0,
            silent: !0,
            unit: a.Pixel,
            width: n
          }
        });
      } else
        this.emit("cx-asset-link-format-crop-change", {
          detail: {
            height: o,
            keepAspectRatio: !0,
            silent: !0,
            unit: a.AspectRatio,
            width: s
          }
        });
    }
    this.emit("cx-asset-link-format-crop-mode-change", {
      detail: {
        mode: e
      }
    });
  }
  onFocusModeChange(t) {
    const e = t.target.value;
    this.emit("cx-asset-link-format-crop-focus-mode-change", {
      detail: {
        mode: e
      }
    });
  }
  /**
   * Handles the change of the unit of measurement for the crop settings.
   * When the unit is changed to Aspect Ratio, it emits an event with the last applied settings for Aspect Ratio.
   * When the unit is changed to Pixels, it emits an event with the last applied settings for Pixels.
   * This allows the parent component to update the crop settings accordingly.
   */
  onUnitChange(t) {
    t.target.value === a.AspectRatio ? this.emit("cx-asset-link-format-crop-change", {
      detail: {
        height: this.lastAppliedSetting[a.AspectRatio].height,
        keepAspectRatio: this.keepAspectRatio,
        unit: a.AspectRatio,
        width: this.lastAppliedSetting[a.AspectRatio].width
      }
    }) : this.emit("cx-asset-link-format-crop-change", {
      detail: {
        height: this.lastAppliedSetting[a.Pixel].height,
        keepAspectRatio: this.keepAspectRatio,
        unit: a.Pixel,
        width: this.lastAppliedSetting[a.Pixel].width
      }
    }), this.emit("cx-asset-link-format-crop-mode-change", {
      detail: {
        mode: "free"
      }
    });
  }
  handleInputChange(t) {
    t.stopPropagation(), this.emit("cx-asset-link-format-crop-changed");
  }
  handleApply() {
    this.loading || this.emit("cx-asset-link-format-crop-apply", {
      detail: {
        height: this.height,
        unit: this.unit,
        width: this.width
      }
    });
  }
  /**
   * Handles showing the details section.
   * This method prevents the event from propagating if the target is not the base element, such as tooltips, select dropdowns, or other interactive elements inside the details.
   * This ensures that the details section is only shown when the user interacts with the base element.
   */
  onShowDetails(t) {
    t.target !== this.base && t.stopPropagation();
  }
  /**
   * Handles hiding the details section.
   * This method prevents the event from propagating if the target is not the base element, such as tooltips, select dropdowns, or other interactive elements inside the details.
   * This ensures that the details section is only hidden when the user interacts with the base element.
   */
  onHideDetails(t) {
    t.target !== this.base && t.stopPropagation();
  }
  handleAspectRatioClick() {
    this.keepAspectRatio && this.cropMode !== "free" && this.emit("cx-asset-link-format-crop-mode-change", {
      detail: {
        mode: "free"
      }
    }), this.emit("cx-asset-link-format-crop-change", {
      detail: {
        height: this.unit === a.Pixel ? this.height : this.ratioHeight,
        keepAspectRatio: !this.keepAspectRatio,
        unit: this.unit,
        width: this.unit === a.Pixel ? this.width : this.ratioWidth
      }
    });
  }
  render() {
    const t = this.cropModes.filter((i) => !i.auto), e = this.cropModes.filter((i) => i.auto);
    return m`<cx-details class="details" ?open=${this.open} @cx-show=${this.onShowDetails} @cx-hide=${this.onHideDetails}><cx-space slot="summary" align-items="center"><div part="icon"><cx-icon name="crop"></cx-icon></div><cx-typography variant="body2">${this.localize.term("crop")}</cx-typography></cx-space><cx-space direction="vertical" spacing="small"><cx-select data-testid="cx-asset-link-format-crop-mode" value=${this.cropMode} hoist style=${A({
      width: "100%"
    })} @cx-change=${this.onCropModeChange} ?disabled=${this.loading}>${L(
      t,
      (i) => i.value,
      ({ label: i, value: s }) => m`<cx-option value=${s}>${i}</cx-option>`
    )}
          ${C(
      e.length > 0,
      () => m`<cx-divider></cx-divider><small>${this.localize.term("autoCropping")}</small>`
    )}
          ${L(
      e,
      (i) => i.value,
      ({ label: i, value: s }) => m`<cx-option value=${s}>${i}</cx-option>`
    )}</cx-select><cx-space spacing="small"><div class="crop__input-group"><cx-input data-testid="cx-asset-link-format-crop-width" placeholder=${this.localize.term("width")} mask="num" .maskBlocks=${{ num: { mask: Number, min: 1 } }} value=${this.unit === a.Pixel ? this.width.toString() : this.ratioWidth.toString()} @cx-change=${this.handleInputChange} @cx-input=${this.handleWidthChange} required ?disabled=${this.loading}><cx-typography slot="prefix" variant="body3" part="input-label">
                W
              </cx-typography></cx-input><cx-icon-button data-testid="cx-asset-link-format-crop-aspect-ratio" name=${this.keepAspectRatio ? "insert_link" : "link_off"} @click=${this.handleAspectRatioClick} style=${A({
      color: this.keepAspectRatio ? "var(--cx-color-primary)" : void 0
    })} ?disabled=${this.loading}></cx-icon-button><cx-input data-testid="cx-asset-link-format-crop-height" placeholder=${this.localize.term("height")} mask="num" .maskBlocks=${{ num: { mask: Number, min: 1 } }} value=${this.unit === a.Pixel ? this.height.toString() : this.ratioHeight.toString()} ?disabled=${this.loading} @cx-change=${this.handleInputChange} @cx-input=${this.handleHeightChange} required><cx-typography slot="prefix" variant="body3" part="input-label">
                H
              </cx-typography></cx-input></div><cx-select data-testid="cx-asset-link-format-crop-unit" value=${this.unit} hoist class="crop__unit-select" ?disabled=${this.loading} @cx-change=${this.onUnitChange}><cx-option value=${a.Pixel}>${this.localize.term("pixels")}</cx-option><cx-option value=${a.AspectRatio}>${this.localize.term("aspectRatio")}</cx-option></cx-select></cx-space>${C(
      this.focusModes.length > 0,
      () => m`<cx-select data-testid="cx-asset-link-format-crop-focus-mode" value=${this.focusMode} hoist style=${A({
        width: "100%"
      })} @cx-change=${this.onFocusModeChange} ?disabled=${this.loading || this.selectedMode?.disabledSize}>${L(
        this.focusModes,
        (i) => i.value,
        ({ label: i, value: s }) => m`<cx-option value=${s}>${i}</cx-option>`
      )}</cx-select>`
    )}<cx-button data-testid="cx-asset-link-format-crop-apply" variant="primary" ?disabled=${this.disabledApply || this.invalidHeight || this.invalidWidth} ?loading=${this.loading} style=${A({
      marginLeft: "auto"
    })} @click=${this.handleApply}>${this.localize.term("apply")}</cx-button></cx-space></cx-details>`;
  }
};
p.styles = [W, dt];
p.dependencies = {
  "cx-button": U,
  "cx-details": T,
  "cx-divider": ht,
  "cx-icon": I,
  "cx-icon-button": K,
  "cx-input": Z,
  "cx-option": Q,
  "cx-select": G,
  "cx-space": P,
  "cx-typography": _
};
u([
  V(".details")
], p.prototype, "base", 2);
u([
  h({ reflect: !0, type: Boolean })
], p.prototype, "open", 2);
u([
  h({ reflect: !0, type: Number })
], p.prototype, "width", 2);
u([
  h({ reflect: !0, type: Number })
], p.prototype, "height", 2);
u([
  h({ attribute: "max-width", reflect: !0, type: Number })
], p.prototype, "maxWidth", 2);
u([
  h({ attribute: "max-height", reflect: !0, type: Number })
], p.prototype, "maxHeight", 2);
u([
  h({ attribute: "ratio-width", reflect: !0, type: Number })
], p.prototype, "ratioWidth", 2);
u([
  h({ attribute: "ratio-height", reflect: !0, type: Number })
], p.prototype, "ratioHeight", 2);
u([
  h({ attribute: "percentage-width", reflect: !0, type: Number })
], p.prototype, "percentageWidth", 2);
u([
  h({ attribute: "percentage-height", reflect: !0, type: Number })
], p.prototype, "percentageHeight", 2);
u([
  h({ reflect: !0, type: String })
], p.prototype, "unit", 2);
u([
  h({ attribute: "disabled-apply", reflect: !0, type: Boolean })
], p.prototype, "disabledApply", 2);
u([
  h({ attribute: "last-applied-setting", reflect: !1, type: Object })
], p.prototype, "lastAppliedSetting", 2);
u([
  h({ reflect: !0, type: Boolean })
], p.prototype, "loading", 2);
u([
  h({ attribute: "crop-modes", reflect: !1, type: Array })
], p.prototype, "cropModes", 2);
u([
  h({ attribute: "focus-modes", reflect: !1, type: Object })
], p.prototype, "focusModes", 2);
u([
  h({ attribute: "focus-mode", reflect: !0, type: String })
], p.prototype, "focusMode", 2);
u([
  h({ attribute: "crop-mode", reflect: !0, type: String })
], p.prototype, "cropMode", 2);
u([
  h({ attribute: "keep-aspect-ratio", reflect: !0, type: Boolean })
], p.prototype, "keepAspectRatio", 2);
u([
  f()
], p.prototype, "invalidWidth", 2);
u([
  f()
], p.prototype, "invalidHeight", 2);
u([
  f()
], p.prototype, "aspectRatio", 2);
u([
  S("cropMode", { waitUntilFirstUpdate: !0 }),
  S("maxWidth", { waitUntilFirstUpdate: !0 }),
  S("maxHeight", { waitUntilFirstUpdate: !0 }),
  S("keepAspectRatio")
], p.prototype, "handleCropModeChange", 1);
u([
  S("open")
], p.prototype, "handleOpenChange", 1);
p = u([
  F("cx-asset-link-format-crop")
], p);
const gt = N`.extension{padding:var(--cx-spacing-small) var(--cx-spacing-medium);border:solid 1px var(--cx-color-neutral-200);background-color:var(--cx-color-neutral-0);& cx-select{flex:1;width:100%}}`;
var xt = Object.defineProperty, ft = Object.getOwnPropertyDescriptor, J = (t, e, i, s) => {
  for (var o = s > 1 ? void 0 : s ? ft(e, i) : e, r = t.length - 1, n; r >= 0; r--)
    (n = t[r]) && (o = (s ? n(e, i, o) : n(o)) || o);
  return s && o && xt(e, i, o), o;
};
let O = class extends H {
  constructor() {
    super(...arguments), this.localize = new E(this), this.value = "", this.items = [];
  }
  handleExtensionChange(t) {
    const e = t.target.value;
    this.emit("cx-asset-link-format-extension-change", {
      detail: e
    });
  }
  render() {
    return m`<cx-space direction="vertical" spacing="small" class="extension"><cx-typography variant="body2">${this.localize.term("extension")}</cx-typography><cx-select data-label=${this.localize.term("extension")} data-testid="cx-asset-link-format-extension-select" value=${this.value} hoist @cx-change=${this.handleExtensionChange}>${L(
      this.items,
      (t) => t.value,
      (t) => m`<cx-option value=${t.value}>${t.displayName}</cx-option>`
    )}</cx-select></cx-space>`;
  }
};
O.styles = [W, gt];
O.dependencies = {
  "cx-option": Q,
  "cx-select": G,
  "cx-space": P,
  "cx-typography": _
};
J([
  h({ reflect: !0, type: String })
], O.prototype, "value", 2);
J([
  h({ reflect: !1, type: Array })
], O.prototype, "items", 2);
O = J([
  F("cx-asset-link-format-extension")
], O);
const yt = N`cx-details::part(base){border-bottom-width:0}`;
var zt = Object.defineProperty, St = Object.getOwnPropertyDescriptor, R = (t, e, i, s) => {
  for (var o = s > 1 ? void 0 : s ? St(e, i) : e, r = t.length - 1, n; r >= 0; r--)
    (n = t[r]) && (o = (s ? n(e, i, o) : n(o)) || o);
  return s && o && zt(e, i, o), o;
};
let w = class extends H {
  constructor() {
    super(...arguments), this.localize = new E(this), this.open = !1, this.value = "", this.items = [], this.loading = !1, this.scopedValue = "";
  }
  handleValueChange() {
    this.scopedValue = this.value;
  }
  handleOpenChange() {
    this.open || (this.scopedValue = this.value);
  }
  handleProxyChange(t) {
    const e = t.target.value;
    this.scopedValue = e;
  }
  /**
   * Handles the application of the selected proxy format.
   * This method emits a custom event with the selected proxy format when the "Apply" button is clicked.
   * It prevents further actions if the component is currently loading.
   */
  handleApply() {
    if (this.loading)
      return;
    const t = this.items.find(
      (e) => e.id === this.scopedValue
    );
    t && this.emit("cx-asset-link-format-proxy-change", {
      detail: t
    });
  }
  /**
   * Handles showing the details section.
   * This method prevents the event from propagating if the target is not the base element, such as tooltips, select dropdowns, or other interactive elements inside the details.
   * This ensures that the details section is only shown when the user interacts with the base element.
   */
  onShowDetails(t) {
    t.target !== this.base && t.stopPropagation();
  }
  /**
   * Handles hiding the details section.
   * This method prevents the event from propagating if the target is not the base element, such as tooltips, select dropdowns, or other interactive elements inside the details.
   * This ensures that the details section is only hidden when the user interacts with the base element.
   */
  onHideDetails(t) {
    t.target !== this.base && t.stopPropagation();
  }
  render() {
    return m`<cx-details class="details" ?open=${this.open} @cx-show=${this.onShowDetails} @cx-hide=${this.onHideDetails}><cx-space slot="summary" align-items="center"><div part="icon"><cx-icon name="photo_size_select_large"></cx-icon></div><cx-typography variant="body2">${this.localize.term("format")}</cx-typography></cx-space><cx-space direction="vertical" spacing="small" class="format"><cx-select data-label=${this.localize.term("imageFormat")} data-testid="cx-asset-link-format-proxy-select" value=${this.scopedValue} hoist @cx-change=${this.handleProxyChange} ?disabled=${this.loading}>${L(
      this.items,
      (t) => t.id,
      (t) => m`<cx-option value=${t.id}>${t.proxyLabel}</cx-option>`
    )}</cx-select><cx-button data-testid="cx-asset-link-format-proxy-apply" variant="primary" style=${A({
      "margin-left": "auto"
    })} ?disabled=${this.scopedValue === this.value} ?loading=${this.loading} @click=${this.handleApply}>${this.localize.term("apply")}</cx-button></cx-space></cx-details>`;
  }
};
w.styles = [W, yt];
w.dependencies = {
  "cx-button": U,
  "cx-details": T,
  "cx-icon": I,
  "cx-option": Q,
  "cx-select": G,
  "cx-space": P,
  "cx-typography": _
};
R([
  V(".details")
], w.prototype, "base", 2);
R([
  h({ reflect: !0, type: Boolean })
], w.prototype, "open", 2);
R([
  h({ reflect: !0, type: String })
], w.prototype, "value", 2);
R([
  h({ reflect: !1, type: Array })
], w.prototype, "items", 2);
R([
  h({ reflect: !0, type: Boolean })
], w.prototype, "loading", 2);
R([
  f()
], w.prototype, "scopedValue", 2);
R([
  S("value")
], w.prototype, "handleValueChange", 1);
R([
  S("open", { waitUntilFirstUpdate: !0 })
], w.prototype, "handleOpenChange", 1);
w = R([
  F("cx-asset-link-format-proxy")
], w);
const wt = N`cx-details::part(base){border-bottom-width:0}`;
var bt = Object.defineProperty, vt = Object.getOwnPropertyDescriptor, D = (t, e, i, s) => {
  for (var o = s > 1 ? void 0 : s ? vt(e, i) : e, r = t.length - 1, n; r >= 0; r--)
    (n = t[r]) && (o = (s ? n(e, i, o) : n(o)) || o);
  return s && o && bt(e, i, o), o;
};
let b = class extends H {
  constructor() {
    super(...arguments), this.localize = new E(this), this.open = !1, this.value = 100, this.loading = !1, this.scopedValue = 100;
  }
  /**
   * A computed property that checks if the current quality value is invalid.
   * The value is considered invalid if it is not a number, less than 1, greater than 100, or equal to the current value.
   * @return {boolean} True if the value is invalid, false otherwise.
   */
  get invalidValue() {
    return isNaN(Number(this.scopedValue)) || Number(this.scopedValue) < 1 || Number(this.scopedValue) > 100 || this.value === this.scopedValue;
  }
  handleValueChange() {
    this.scopedValue = this.value;
  }
  handleQualityChange(t) {
    const e = t.target.value;
    this.scopedValue = Number(e);
  }
  /**
   * Handles the application of the input quality.
   * This method emits a custom event with the input quality when the "Apply" button is clicked.
   * It prevents further actions if the component is currently loading.
   */
  handleApply() {
    this.loading || this.emit("cx-asset-link-format-quality-change", {
      detail: Number(this.scopedValue)
    });
  }
  /**
   * Handles showing the details section.
   * This method prevents the event from propagating if the target is not the base element, such as tooltips, select dropdowns, or other interactive elements inside the details.
   * This ensures that the details section is only shown when the user interacts with the base element.
   */
  onShowDetails(t) {
    t.target !== this.base && t.stopPropagation();
  }
  /**
   * Handles hiding the details section.
   * This method prevents the event from propagating if the target is not the base element, such as tooltips, select dropdowns, or other interactive elements inside the details.
   * This ensures that the details section is only hidden when the user interacts with the base element.
   */
  onHideDetails(t) {
    t.target !== this.base && t.stopPropagation();
  }
  render() {
    return m`<cx-details class="details" ?open=${this.open} @cx-show=${this.onShowDetails} @cx-hide=${this.onHideDetails}><cx-space slot="summary" align-items="center"><div class="details__summary__icon"><div part="icon"><cx-icon name="blur_on"></cx-icon></div></div><cx-typography variant="body2">${this.localize.term("quality")}</cx-typography></cx-space><cx-space spacing="small"><cx-tooltip data-testid="cx-asset-link-format-quality-tooltip" content=${this.localize.term("qualityHelpText")} hoist><cx-input data-testid="cx-asset-link-format-quality" class="details__checkbox" mask="num" .maskBlocks=${{ num: { mask: Number, max: 100, min: 1 } }} value=${this.scopedValue.toString()} style=${A({
      flex: "1"
    })} @cx-input=${this.handleQualityChange}></cx-input></cx-tooltip><cx-button data-testid="cx-asset-link-format-quality-apply" variant="primary" ?disabled=${this.invalidValue} ?loading=${this.loading} @click=${this.handleApply}>${this.localize.term("apply")}</cx-button></cx-space></cx-details>`;
  }
};
b.styles = [W, wt];
b.dependencies = {
  "cx-button": U,
  "cx-details": T,
  "cx-icon": I,
  "cx-input": Z,
  "cx-space": P,
  "cx-tooltip": st,
  "cx-typography": _
};
D([
  V(".details")
], b.prototype, "base", 2);
D([
  h({ reflect: !0, type: Boolean })
], b.prototype, "open", 2);
D([
  h({ reflect: !0, type: Number })
], b.prototype, "value", 2);
D([
  h({ reflect: !0, type: Boolean })
], b.prototype, "loading", 2);
D([
  f()
], b.prototype, "scopedValue", 2);
D([
  S("value")
], b.prototype, "handleValueChange", 1);
b = D([
  F("cx-asset-link-format-quality")
], b);
const kt = N`cx-details::part(base){border-bottom-width:0}cx-space{width:100%}cx-space cx-input{flex:1}.resize__unit-select{width:120px}.resize__input-group{flex:1;display:flex}`;
var $t = Object.defineProperty, Ct = Object.getOwnPropertyDescriptor, y = (t, e, i, s) => {
  for (var o = s > 1 ? void 0 : s ? Ct(e, i) : e, r = t.length - 1, n; r >= 0; r--)
    (n = t[r]) && (o = (s ? n(e, i, o) : n(o)) || o);
  return s && o && $t(e, i, o), o;
};
let g = class extends H {
  constructor() {
    super(...arguments), this.localize = new E(this), this.open = !1, this.width = 0, this.height = 0, this.maxWidth = 0, this.maxHeight = 0, this.ratioWidth = 1, this.ratioHeight = 1, this.unit = a.Pixel, this.lastAppliedSetting = {
      [a.Pixel]: { height: 0, width: 0 },
      [a.AspectRatio]: { height: 1, width: 1 }
    }, this.loading = !1, this.keepAspectRatio = !1, this.invalidWidth = !1, this.invalidHeight = !1, this.aspectRatio = 0;
  }
  /**
   * A computed property that checks if the current resize settings match the last applied settings.
   * This is used to disable the apply button when no changes have been made.
   * @returns {boolean} True if the current settings match the last applied settings, false otherwise.
   */
  get disabledApply() {
    return this.lastAppliedSetting[this.unit].width === this.width && this.lastAppliedSetting[this.unit].height === this.height;
  }
  async handleCropModeChange() {
    if (this.keepAspectRatio) {
      if (this.unit === a.Pixel && this.width && this.height) {
        this.aspectRatio = this.width / this.height;
        return;
      } else if (this.unit === a.AspectRatio && this.ratioWidth && this.ratioHeight) {
        this.aspectRatio = this.ratioWidth / this.ratioHeight;
        return;
      }
    }
    if (this.maxWidth && this.maxHeight) {
      this.aspectRatio = this.maxWidth / this.maxHeight;
      return;
    }
    this.aspectRatio = 1;
  }
  async handleOpenChange() {
    await this.updateComplete, this.open || (this.width = this.lastAppliedSetting[a.Pixel].width, this.height = this.lastAppliedSetting[a.Pixel].height, this.unit = a.Pixel, this.emit("cx-asset-link-format-resize-change", {
      detail: {
        height: this.lastAppliedSetting[a.Pixel].height,
        keepAspectRatio: this.keepAspectRatio,
        unit: a.Pixel,
        width: this.lastAppliedSetting[a.Pixel].width
      }
    }));
  }
  handleWidthChange(t) {
    if (!t.target.value) {
      this.invalidWidth = !0;
      return;
    }
    this.invalidWidth = !1;
    let e = Number(t.target.value);
    this.unit === a.Pixel && (e = Math.max(Math.min(e, this.maxWidth), 1)), t.target.value = e.toString();
    let i = this.unit === a.Pixel ? this.height : this.ratioHeight;
    this.keepAspectRatio && (i = Math.min(
      Math.round(e / this.aspectRatio),
      this.maxHeight
    ), this.invalidHeight = !1), this.emit("cx-asset-link-format-resize-change", {
      detail: {
        height: i,
        keepAspectRatio: this.keepAspectRatio,
        unit: this.unit,
        width: e
      }
    });
  }
  handleHeightChange(t) {
    if (!t.target.value) {
      this.invalidHeight = !0;
      return;
    }
    this.invalidHeight = !1;
    let e = Number(t.target.value);
    this.unit === a.Pixel && (e = Math.max(Math.min(e, this.maxHeight), 1)), t.target.value = e.toString();
    let i = this.unit === a.Pixel ? this.width : this.ratioWidth;
    this.keepAspectRatio && (i = Math.min(
      Math.round(e * this.aspectRatio),
      this.maxWidth
    ), this.invalidWidth = !1), this.emit("cx-asset-link-format-resize-change", {
      detail: {
        height: e,
        keepAspectRatio: this.keepAspectRatio,
        unit: this.unit,
        width: i
      }
    });
  }
  onUnitChange(t) {
    t.target.value === a.AspectRatio ? this.emit("cx-asset-link-format-resize-change", {
      detail: {
        height: this.lastAppliedSetting[a.AspectRatio].height,
        keepAspectRatio: this.keepAspectRatio,
        unit: a.AspectRatio,
        width: this.lastAppliedSetting[a.AspectRatio].width
      }
    }) : this.emit("cx-asset-link-format-resize-change", {
      detail: {
        height: this.lastAppliedSetting[a.Pixel].height,
        keepAspectRatio: this.keepAspectRatio,
        unit: a.Pixel,
        width: this.lastAppliedSetting[a.Pixel].width
      }
    });
  }
  handleApply() {
    this.loading || this.emit("cx-asset-link-format-resize-apply", {
      detail: {
        height: this.height,
        unit: this.unit,
        width: this.width
      }
    });
  }
  /**
   * Handles showing the details section.
   * This method prevents the event from propagating if the target is not the base element, such as tooltips, select dropdowns, or other interactive elements inside the details.
   * This ensures that the details section is only shown when the user interacts with the base element.
   */
  onShowDetails(t) {
    t.target !== this.base && t.stopPropagation();
  }
  /**
   * Handles hiding the details section.
   * This method prevents the event from propagating if the target is not the base element, such as tooltips, select dropdowns, or other interactive elements inside the details.
   * This ensures that the details section is only hidden when the user interacts with the base element.
   */
  onHideDetails(t) {
    t.target !== this.base && t.stopPropagation();
  }
  handleAspectRatioClick() {
    this.emit("cx-asset-link-format-resize-change", {
      detail: {
        height: this.unit === a.Pixel ? this.height : this.ratioHeight,
        keepAspectRatio: !this.keepAspectRatio,
        unit: this.unit,
        width: this.unit === a.Pixel ? this.width : this.ratioWidth
      }
    });
  }
  render() {
    return m`<cx-details class="details" ?open=${this.open} @cx-show=${this.onShowDetails} @cx-hide=${this.onHideDetails}><cx-space slot="summary" align-items="center"><div part="icon"><cx-icon name="aspect_ratio"></cx-icon></div><cx-typography variant="body2">${this.localize.term("resize")}</cx-typography></cx-space><cx-space direction="vertical" spacing="small"><cx-space spacing="small"><div class="resize__input-group"><cx-input data-testid="cx-asset-link-format-resize-width" placeholder=${this.localize.term("width")} mask="num" .maskBlocks=${{ num: { mask: Number, min: 1 } }} value=${this.unit === a.Pixel ? this.width.toString() : this.ratioWidth.toString()} @cx-input=${this.handleWidthChange} required ?disabled=${this.loading}><cx-typography slot="prefix" variant="body3" part="input-label">
                W
              </cx-typography></cx-input><cx-icon-button data-testid="cx-asset-link-format-resize-aspect-ratio" name=${this.keepAspectRatio ? "insert_link" : "link_off"} @click=${this.handleAspectRatioClick} style=${A({
      color: this.keepAspectRatio ? "var(--cx-color-primary)" : void 0
    })} ?disabled=${this.loading}></cx-icon-button><cx-input data-testid="cx-asset-link-format-resize-height" placeholder=${this.localize.term("height")} mask="num" .maskBlocks=${{ num: { mask: Number, min: 1 } }} value=${this.unit === a.Pixel ? this.height.toString() : this.ratioHeight.toString()} @cx-input=${this.handleHeightChange} required ?disabled=${this.loading}><cx-typography slot="prefix" variant="body3" part="input-label">
                H
              </cx-typography></cx-input></div><cx-select data-testid="cx-asset-link-format-resize-unit" value=${this.unit} hoist class="resize__unit-select" @cx-change=${this.onUnitChange}><cx-option value=${a.Pixel}>${this.localize.term("pixels")}</cx-option><cx-option value=${a.AspectRatio}>${this.localize.term("aspectRatio")}</cx-option></cx-select></cx-space><cx-button data-testid="cx-asset-link-format-resize-apply" variant="primary" ?disabled=${this.disabledApply || this.invalidHeight || this.invalidWidth} ?loading=${this.loading} style=${A({
      marginLeft: "auto"
    })} @click=${this.handleApply}>${this.localize.term("apply")}</cx-button></cx-space></cx-details>`;
  }
};
g.styles = [W, kt];
g.dependencies = {
  "cx-button": U,
  "cx-details": T,
  "cx-icon": I,
  "cx-icon-button": K,
  "cx-input": Z,
  "cx-option": Q,
  "cx-select": G,
  "cx-space": P,
  "cx-typography": _
};
y([
  V(".details")
], g.prototype, "base", 2);
y([
  h({ reflect: !0, type: Boolean })
], g.prototype, "open", 2);
y([
  h({ reflect: !0, type: Number })
], g.prototype, "width", 2);
y([
  h({ reflect: !0, type: Number })
], g.prototype, "height", 2);
y([
  h({ attribute: "max-width", reflect: !0, type: Number })
], g.prototype, "maxWidth", 2);
y([
  h({ attribute: "max-height", reflect: !0, type: Number })
], g.prototype, "maxHeight", 2);
y([
  h({ attribute: "ratio-width", reflect: !0, type: Number })
], g.prototype, "ratioWidth", 2);
y([
  h({ attribute: "ratio-height", reflect: !0, type: Number })
], g.prototype, "ratioHeight", 2);
y([
  h({ reflect: !0, type: String })
], g.prototype, "unit", 2);
y([
  h({ attribute: "last-applied-setting", reflect: !1, type: Object })
], g.prototype, "lastAppliedSetting", 2);
y([
  h({ reflect: !0, type: Boolean })
], g.prototype, "loading", 2);
y([
  h({ attribute: "keep-aspect-ratio", reflect: !0, type: Boolean })
], g.prototype, "keepAspectRatio", 2);
y([
  f()
], g.prototype, "invalidWidth", 2);
y([
  f()
], g.prototype, "invalidHeight", 2);
y([
  f()
], g.prototype, "aspectRatio", 2);
y([
  S("cropMode", { waitUntilFirstUpdate: !0 }),
  S("maxWidth", { waitUntilFirstUpdate: !0 }),
  S("maxHeight", { waitUntilFirstUpdate: !0 }),
  S("keepAspectRatio")
], g.prototype, "handleCropModeChange", 1);
y([
  S("open")
], g.prototype, "handleOpenChange", 1);
g = y([
  F("cx-asset-link-format-resize")
], g);
const At = N`cx-details::part(base){border-bottom-width:0}`;
var Rt = Object.defineProperty, Mt = Object.getOwnPropertyDescriptor, q = (t, e, i, s) => {
  for (var o = s > 1 ? void 0 : s ? Mt(e, i) : e, r = t.length - 1, n; r >= 0; r--)
    (n = t[r]) && (o = (s ? n(e, i, o) : n(o)) || o);
  return s && o && Rt(e, i, o), o;
};
let v = class extends H {
  constructor() {
    super(...arguments), this.localize = new E(this), this.open = !1, this.value = 0, this.defaultValue = 0, this.loading = !1;
  }
  handleOpenChange() {
    this.open || this.emit("cx-asset-link-format-rotation-change", {
      detail: 0
    });
  }
  handleRotationChange(t) {
    const e = t.target.value, i = et(Number(e));
    (Number(e) > 360 || Number(e) < -360) && (t.target.value = i.toString()), this.emit("cx-asset-link-format-rotation-change", {
      detail: i
    });
  }
  handleButtonClick(t) {
    this.emit("cx-asset-link-format-rotation-change", {
      detail: et(t)
    });
  }
  handleClockwiseClick() {
    this.handleButtonClick(this.value + 90);
  }
  handleCounterClockwiseClick() {
    this.handleButtonClick(this.value - 90);
  }
  /**
   * Handles the application of the input rotation.
   * This method emits a custom event with the input rotation when the "Apply" button is clicked.
   * It prevents further actions if the component is currently loading.
   */
  handleApply() {
    this.value === 360 || this.value === -360 || this.loading || this.emit("cx-asset-link-format-rotation-apply", {
      detail: this.value
    });
  }
  render() {
    return m`<cx-details class="details" ?open=${this.open}><cx-space slot="summary" align-items="center"><div part="icon"><cx-icon name="rotate_90_degrees_cw"></cx-icon></div><cx-typography variant="body2">Rotate</cx-typography></cx-space><cx-space spacing="small"><cx-button-group label=${this.localize.term("history")}><cx-icon-button data-testid="cx-asset-link-format-rotation-ccw" name="rotate_90_degrees_ccw" label=${this.localize.term("undo")} outline size="small" ?disabled=${this.loading || this.value === -360} @click=${this.handleCounterClockwiseClick}></cx-icon-button><cx-icon-button data-testid="cx-asset-link-format-rotation-cw" name="rotate_90_degrees_cw" label=${this.localize.term("redo")} outline size="small" ?disabled=${this.loading || this.value === 360} @click=${this.handleClockwiseClick}></cx-icon-button></cx-button-group><cx-input data-testid="cx-asset-link-format-rotation" value=${(this.value + this.defaultValue).toString()} placeholder="0" mask="num" .maskBlocks=${{ num: { mask: Number, max: 360, min: -360, signed: !0 } }} ?disabled=${this.loading} style=${A({
      flex: "none",
      width: "80px"
    })} @cx-input=${this.handleRotationChange}></cx-input><cx-button data-testid="cx-asset-link-format-rotation-apply" variant="primary" ?disabled=${this.value === 0} ?loading=${this.loading} @click=${this.handleApply}>${this.localize.term("apply")}</cx-button></cx-space></cx-details>`;
  }
};
v.styles = [W, At];
v.dependencies = {
  "cx-button": U,
  "cx-button-group": lt,
  "cx-details": T,
  "cx-icon": I,
  "cx-icon-button": K,
  "cx-space": P,
  "cx-typography": _
};
q([
  V(".details")
], v.prototype, "base", 2);
q([
  h({ reflect: !0, type: Boolean })
], v.prototype, "open", 2);
q([
  h({ reflect: !0, type: Number })
], v.prototype, "value", 2);
q([
  h({ attribute: "default-value", reflect: !0, type: Number })
], v.prototype, "defaultValue", 2);
q([
  h({ reflect: !0, type: Boolean })
], v.prototype, "loading", 2);
q([
  S("open", { waitUntilFirstUpdate: !0 })
], v.prototype, "handleOpenChange", 1);
v = q([
  F("cx-asset-link-format-rotation")
], v);
const Pt = N`cx-details::part(base){border-bottom-width:0}`;
var _t = Object.defineProperty, Ht = Object.getOwnPropertyDescriptor, X = (t, e, i, s) => {
  for (var o = s > 1 ? void 0 : s ? Ht(e, i) : e, r = t.length - 1, n; r >= 0; r--)
    (n = t[r]) && (o = (s ? n(e, i, o) : n(o)) || o);
  return s && o && _t(e, i, o), o;
};
let M = class extends H {
  constructor() {
    super(...arguments), this.localize = new E(this), this.open = !1, this.value = !1;
  }
  handleApply(t) {
    this.emit("cx-asset-link-format-metadata-change", {
      detail: t.target.checked
    });
  }
  /**
   * Handles showing the details section.
   * This method prevents the event from propagating if the target is not the base element, such as tooltips, select dropdowns, or other interactive elements inside the details.
   * This ensures that the details section is only shown when the user interacts with the base element.
   */
  onShowDetails(t) {
    t.target !== this.base && t.stopPropagation();
  }
  /**
   * Handles hiding the details section.
   * This method prevents the event from propagating if the target is not the base element, such as tooltips, select dropdowns, or other interactive elements inside the details.
   * This ensures that the details section is only hidden when the user interacts with the base element.
   */
  onHideDetails(t) {
    t.target !== this.base && t.stopPropagation();
  }
  render() {
    return m`<cx-details class="details" ?open=${this.open} @cx-show=${this.onShowDetails} @cx-hide=${this.onHideDetails}><cx-space slot="summary" align-items="center"><div class="details__summary__icon"><div part="icon"><cx-icon name="short_text"></cx-icon></div></div><cx-typography variant="body2">${this.localize.term("metadata")}</cx-typography></cx-space><cx-space spacing="small"><cx-tooltip data-testid="cx-asset-link-format-metadata-tooltip" content=${this.localize.term("metadataHelpText")} hoist><cx-checkbox data-testid="cx-asset-link-format-metadata" class="details__checkbox" ?checked=${this.value} @cx-change=${this.handleApply}>${this.localize.term("preserveMetadata")}</cx-checkbox></cx-tooltip></cx-space></cx-details>`;
  }
};
M.styles = [W, Pt];
M.dependencies = {
  "cx-button": U,
  "cx-checkbox": ct,
  "cx-details": T,
  "cx-icon": I,
  "cx-space": P,
  "cx-tooltip": st,
  "cx-typography": _
};
X([
  V(".details")
], M.prototype, "base", 2);
X([
  h({ reflect: !0, type: Boolean })
], M.prototype, "open", 2);
X([
  h({ reflect: !0, type: Boolean })
], M.prototype, "value", 2);
M = X([
  F("cx-asset-link-format-metadata")
], M);
var Wt = Object.defineProperty, Ft = Object.getOwnPropertyDescriptor, c = (t, e, i, s) => {
  for (var o = s > 1 ? void 0 : s ? Ft(e, i) : e, r = t.length - 1, n; r >= 0; r--)
    (n = t[r]) && (o = (s ? n(e, i, o) : n(o)) || o);
  return s && o && Wt(e, i, o), o;
};
let l = class extends H {
  constructor() {
    super(), this.localize = new E(this), this.baseUrl = void 0, this.token = void 0, this.asset = void 0, this.cropModes = [
      {
        label: "Free",
        value: "free"
      },
      {
        label: "Widescreen (16:9)",
        value: "16:9"
      },
      {
        label: "Phone (9:16)",
        value: "9:16"
      },
      {
        label: "Presentation (4:3)",
        value: "4:3"
      },
      {
        label: "Square (1:1)",
        value: "1:1"
      },
      {
        label: "Landscape (3:2)",
        value: "3:2"
      },
      {
        label: "Portrait (2:3)",
        value: "2:3"
      },
      {
        auto: !0,
        disabledSize: !0,
        label: "Azure AI",
        value: "AzureAI"
      }
    ], this.focusModes = [
      {
        label: "Manual focus",
        value: "manual"
      },
      {
        label: "Center focus",
        value: "center"
      },
      {
        auto: !0,
        label: "Optical focus",
        value: "Optical"
      },
      {
        auto: !0,
        label: "Google AI",
        value: "GoogleAI"
      },
      {
        auto: !0,
        label: "Smart Swatch",
        value: "SmartSwatch"
      }
    ], this.extensions = [], this.proxies = void 0, this.forCropper = void 0, this.useSession = "", this.transformations = [], this.selectedProxy = "", this.useCustomExtension = !1, this.noMetadata = !1, this.noCrop = !1, this.noResize = !1, this.noRotate = !1, this.lastImageSize = {
      height: 0,
      width: 0
    }, this.hideHeader = !1, this.canReset = !1, this.queryElement = null, this.activeSetting = "cx-asset-link-format-proxy", this.selectedFormat = void 0, this.resizeSize = {
      height: 0,
      keepAspectRatio: !0,
      ratioHeight: 1,
      ratioWidth: 1,
      unit: a.Pixel,
      width: 0
    }, this.cropSize = {
      cropMode: "free",
      focusMode: "manual",
      height: 0,
      keepAspectRatio: !0,
      percentageHeight: 0,
      percentageWidth: 0,
      ratioHeight: 1,
      ratioWidth: 1,
      unit: a.Pixel,
      width: 0,
      x: 0,
      y: 0
    }, this.rotation = 0, this.defaultSize = {
      height: 0,
      width: 0
    }, this.cropperElement = null, this.parameters = [], this.loading = !1, this.lastAction = void 0, this.frozenIndex = void 0, this.preResetTransformations = void 0, this.apiGetTransformAssetLink = at, this.apiGetCropFocusMode = ot, this.onCropComplete = this.onCropComplete.bind(this), this.onCropDragStart = this.onCropDragStart.bind(this);
  }
  /** True when there are transformations beyond the frozen index (i.e. user has added new ones). */
  get hasUnfrozenTransformations() {
    return !(this.transformations.length === 0 || this.frozenIndex !== void 0 && this.frozenIndex >= this.transformations.length - 1);
  }
  /**
   * Checks if the crop apply button should be disabled.
   * This is determined by comparing the current crop size with the last crop size.
   * If the current crop size is equal to the last crop size, the button is disabled.
   * @return {boolean} - Returns true if the crop apply button should be disabled, false otherwise.
   */
  get disabledCropApply() {
    const t = [
      "height",
      "percentageHeight",
      "percentageWidth",
      "unit",
      "width",
      "x",
      "y"
    ];
    for (const e of t)
      if (this.cropSize[e] !== this.lastCropSize[this.cropSize.unit][e])
        return !1;
    return !0;
  }
  /**
   * Returns the list of formats available for the asset link.
   * This is derived from the `proxies` property, filtering out any proxies that have a `cdnName`.
   */
  get formats() {
    return this.proxies?.filter((t) => !t.cdnName) || [];
  }
  get imageSize() {
    return {
      height: this.selectedFormat?.height ?? 0,
      width: this.selectedFormat?.width ?? 0
    };
  }
  /**
   * Returns the last crop size based on the transformations applied to the asset link.
   * This is calculated by iterating through the transformations and applying the last crop, resize, or rotate transformation to the default size of the asset.
   * It returns an object with the last crop size in both pixel and aspect ratio units.
   */
  get lastCropSize() {
    const t = it(
      this.lastImageSize.width,
      this.lastImageSize.height
    );
    return {
      [a.AspectRatio]: {
        height: t.height,
        percentageHeight: 100,
        percentageWidth: 100,
        unit: a.AspectRatio,
        width: t.width,
        x: 0,
        y: 0
      },
      [a.Pixel]: {
        height: this.lastImageSize.height,
        percentageHeight: 100,
        percentageWidth: 100,
        unit: a.Pixel,
        width: this.lastImageSize.width,
        x: 0,
        y: 0
      }
    };
  }
  /**
   * Returns the last resize size based on the transformations applied to the asset link.
   * This is calculated by iterating through the transformations and applying the last crop, resize, or rotate transformation to the default size of the asset.
   * It returns an object with the last resize size in both pixel and aspect ratio units.
   */
  get lastResizeSize() {
    const t = it(
      this.lastImageSize.width,
      this.lastImageSize.height
    );
    return {
      [a.AspectRatio]: {
        height: t.height,
        unit: a.AspectRatio,
        width: t.width
      },
      [a.Pixel]: {
        height: this.lastImageSize.height,
        unit: a.Pixel,
        width: this.lastImageSize.width
      }
    };
  }
  /**
   * Returns the transformation string for the asset link.
   */
  get transformationString() {
    return Y({
      asset: this.asset,
      baseUrl: "",
      parameters: this.parameters,
      transformations: this.transformations,
      useSession: this.useSession
    }).replace(/\/t\//g, "");
  }
  runConnectedCallback() {
    this.hasUpdated && this.cropperElement && (this.cropperElement.addEventListener(
      "cx-cropper-crop-complete",
      this.onCropComplete
    ), this.cropperElement.addEventListener(
      "cx-cropper-crop-drag-start",
      this.onCropDragStart
    ));
  }
  disconnectedCallback() {
    super.disconnectedCallback(), this.cropperElement && (this.cropperElement.removeEventListener(
      "cx-cropper-crop-complete",
      this.onCropComplete
    ), this.cropperElement.removeEventListener(
      "cx-cropper-crop-drag-start",
      this.onCropDragStart
    ));
  }
  updated(t) {
    if ((t.has("forCropper") || t.has("queryElement")) && this.handleCropperSelectorChange(), t.has("asset") && this.handleAssetChange(), t.has("proxies") && this.handleProxiesChange(), t.has("activeSetting") && this.handleActiveSettingChange(), t.has("selectedFormat") && this.handleSelectedFormatChange(), t.has("resizeSize") && this.handleResizeSizeChange(), t.has("cropSize") && this.handleCropSizeChange(), t.has("rotation") && this.handleRotationChange(), t.has("cropperElement") && this.handleCropperElementChange(), t.has("selectedFormat")) {
      if (!this.asset || !this.selectedFormat || this.selectedFormat.extension === t.get("selectedFormat")?.extension)
        return;
      const e = this.proxies?.find(
        (s) => s.id === this.selectedProxy
      );
      this.loading = !0, this.apiGetTransformAssetLink({
        assetId: this.asset.id,
        extension: this.asset.extension,
        format: e?.proxyName ?? "",
        siteUrl: this.baseUrl,
        token: this.token,
        transformations: this.transformationString
      }).then((s) => {
        this.loading = !1, !(!s?.relativePath || !this.selectedFormat) && (this.lastAction === d.Rotate && (this.rotation = 0), this.lastAction = void 0, this.lastImageSize = {
          height: s.height,
          width: s.width
        }, this.selectedFormat = {
          ...this.selectedFormat,
          height: s.height,
          url: this.baseUrl && this.baseUrl.length > 0 ? `${this.baseUrl}/${s.relativePath}` : s.relativePath,
          width: s.width
          /**
           * For local development uses the base URL to construct the full URL.
           * url: `${this.baseUrl}/${response.relativePath}`,
           */
        });
      });
      const i = Y({
        asset: this.asset,
        baseUrl: "",
        extension: this.selectedFormat.extension,
        parameters: this.parameters,
        transformations: this.transformations,
        useSession: this.useSession
      });
      this.emit("cx-asset-link-format-change", {
        detail: i
      });
    }
  }
  getCropSize() {
    return this.cropSize;
  }
  setActiveSetting(t) {
    this.activeSetting = t;
  }
  freezeTransformations() {
    this.frozenIndex = this.transformations.length - 1;
  }
  async handleTransformationsChange() {
    if (await this.updateComplete, !this.asset || !this.selectedFormat)
      return;
    const t = this.proxies?.find(
      (r) => r.id === this.selectedProxy
    );
    this.loading = !0;
    const e = await this.apiGetTransformAssetLink({
      assetId: this.asset.id,
      extension: this.selectedFormat.extension,
      format: t?.proxyName ?? "",
      siteUrl: this.baseUrl,
      token: this.token,
      transformations: this.transformationString
    });
    if (this.loading = !1, !e?.relativePath || !this.selectedFormat)
      return;
    this.lastImageSize = {
      height: e.height,
      width: e.width
    }, this.resizeSize = {
      height: e.height,
      keepAspectRatio: !0,
      ratioHeight: 1,
      ratioWidth: 1,
      unit: a.Pixel,
      width: e.width
    }, this.cropSize = {
      cropMode: "free",
      focusMode: "manual",
      height: e.height,
      keepAspectRatio: this.cropSize.keepAspectRatio,
      percentageHeight: 100,
      percentageWidth: 100,
      ratioHeight: 1,
      ratioWidth: 1,
      unit: a.Pixel,
      width: e.width,
      x: 0,
      y: 0
    }, this.lastAction === d.Rotate && (this.rotation = 0), this.lastAction = void 0;
    const i = this.transformations.some(
      (r) => r.key === d.Metadata
    ), s = this.transformations.findLast(
      (r) => r.key === d.Quality
    );
    this.selectedFormat = {
      ...this.selectedFormat,
      height: e.height,
      keepMetadata: i,
      quality: s?.value?.quality ?? this.selectedFormat.quality,
      url: this.baseUrl && this.baseUrl.length > 0 ? `${this.baseUrl}/${e.relativePath}` : e.relativePath,
      width: e.width
      /**
       * For local development uses the base URL to construct the full URL.
       * url: `${this.baseUrl}/${response.relativePath}`,
       */
    };
    const o = Y({
      asset: this.asset,
      baseUrl: "",
      extension: this.selectedFormat.extension,
      parameters: this.parameters,
      transformations: this.transformations,
      useSession: this.useSession
    });
    this.emit("cx-asset-link-format-change", {
      detail: o
    });
  }
  handleCropperElementChange() {
    this.cropperElement && (this.cropperElement.resizer = this.resizeSize, this.cropperElement.cropper = this.cropSize, this.cropperElement.rotation = this.rotation, this.cropperElement.disabled = this.activeSetting !== "cx-asset-link-format-crop", this.cropperElement.addEventListener(
      "cx-cropper-crop-complete",
      this.onCropComplete
    ), this.cropperElement.addEventListener(
      "cx-cropper-crop-drag-start",
      this.onCropDragStart
    ), this.cropperElement.loadable = !0);
  }
  handleCropperSelectorChange() {
    this.forCropper && (this.queryElement ? this.cropperElement = this.queryElement.querySelector(`#${this.forCropper}`) : this.cropperElement = document.getElementById(this.forCropper));
  }
  handleAssetChange() {
    if (!this.asset)
      return;
    this.freezeTransformations(), this.asset.width && this.asset.height && (this.defaultSize = {
      height: Number.parseInt(this.asset.height, 10),
      width: Number.parseInt(this.asset.width, 10)
    });
    const t = this.transformations.findLast(
      (e) => e.key === d.Quality
    );
    this.selectedFormat = {
      extension: this.asset.extension,
      height: this.defaultSize.height,
      keepMetadata: !1,
      originalUrl: this.asset.originalUrl,
      quality: t?.value?.quality || 100,
      rotation: 0,
      url: this.asset.imageUrl,
      width: this.defaultSize.width,
      x: 0,
      y: 0
    }, this.resizeSize = {
      ...this.resizeSize,
      height: this.defaultSize.height,
      width: this.defaultSize.width
    }, this.cropSize = {
      cropMode: "free",
      focusMode: "manual",
      height: this.defaultSize.height,
      keepAspectRatio: !0,
      percentageHeight: 100,
      percentageWidth: 100,
      ratioHeight: 1,
      ratioWidth: 1,
      unit: a.Pixel,
      width: this.defaultSize.width,
      x: 0,
      y: 0
    }, this.rotation = 0, this.parameters = [], this.activeSetting = "cx-asset-link-format-proxy", this.selectedProxy || (this.selectedProxy = this.proxies && this.proxies.length > 0 ? this.proxies[0].id : "");
  }
  handleProxiesChange() {
    !this.proxies || this.proxies.length === 0 || (!this.selectedProxy || !this.proxies.some((t) => t.id === this.selectedProxy)) && (this.selectedProxy = this.proxies[0].id);
  }
  async handleSelectedProxyChange(t) {
    if (!this.asset || !this.selectedProxy)
      return;
    const e = this.proxies?.find(
      (s) => s.id === this.selectedProxy
    );
    if (!e || !this.selectedFormat)
      return;
    e.proxyName === "TRX" && (e.formatHeight = Number(this.asset.height), e.formatWidth = Number(this.asset.width));
    const i = this.proxies?.find((s) => s.id === t);
    i && (this.asset && i.proxyName === "TRX" && (i.formatHeight = Number(this.asset.height), i.formatWidth = Number(this.asset.width)), this.transformations = this.transformations.map((s) => {
      if (s.key === d.Crop) {
        const o = s.value, r = o.width / i.formatWidth * e.formatWidth, n = o.height / i.formatHeight * e.formatHeight, x = o.x / i.formatWidth * e.formatWidth, z = o.y / i.formatHeight * e.formatHeight;
        return {
          ...s,
          value: {
            height: n,
            width: r,
            x,
            y: z
          }
        };
      }
      if (s.key === d.Resize) {
        const o = s.value, r = o.width / i.formatWidth * e.formatWidth, n = o.height / i.formatHeight * e.formatHeight;
        return {
          ...s,
          value: {
            height: n,
            width: r
          }
        };
      }
      return s;
    })), this.defaultSize = {
      height: e.formatHeight || this.defaultSize.height,
      width: e.formatWidth || this.defaultSize.width
    }, this.selectedFormat = {
      ...this.selectedFormat,
      height: this.defaultSize.height,
      width: this.defaultSize.width
    }, await this.updateComplete, this.cropSize = {
      cropMode: "free",
      focusMode: "manual",
      height: this.lastCropSize[a.Pixel].height,
      keepAspectRatio: !0,
      percentageHeight: 100,
      percentageWidth: 100,
      ratioHeight: 1,
      ratioWidth: 1,
      unit: a.Pixel,
      width: this.lastCropSize[a.Pixel].width,
      x: 0,
      y: 0
    }, this.resizeSize = {
      height: this.lastResizeSize[a.Pixel].height,
      keepAspectRatio: !0,
      ratioHeight: 1,
      ratioWidth: 1,
      unit: a.Pixel,
      width: this.lastResizeSize[a.Pixel].width
    };
  }
  handleLoadingChange() {
    this.cropperElement && (this.cropperElement.loading = this.loading);
  }
  handleSelectedFormatChange() {
    !this.cropperElement || !this.selectedFormat?.url || (this.cropperElement.image = this.selectedFormat);
  }
  handleResizeSizeChange() {
    this.cropperElement && (this.cropperElement.resizer = this.resizeSize);
  }
  handleCropSizeChange() {
    this.cropperElement && (this.cropperElement.cropper = this.cropSize);
  }
  handleRotationChange() {
    this.cropperElement && (this.cropperElement.rotation = this.rotation);
  }
  handleActiveSettingChange() {
    this.cropperElement && (this.resizeSize = {
      height: this.lastResizeSize[a.Pixel].height,
      keepAspectRatio: !0,
      ratioHeight: 1,
      ratioWidth: 1,
      unit: a.Pixel,
      width: this.lastResizeSize[a.Pixel].width
    }, this.cropperElement.disabled = this.activeSetting !== "cx-asset-link-format-crop");
  }
  async handleRequestAutoCropSuggestion({
    cropMode: t,
    focusMode: e,
    height: i,
    keepAspectRatio: s,
    percentageHeight: o,
    percentageWidth: r,
    ratioHeight: n,
    ratioWidth: x,
    unit: z,
    useCropMode: $,
    width: B
  }) {
    if (!this.selectedFormat?.url || e === "manual")
      return;
    this.loading = !0, this.lastAction = d.Crop;
    const k = await this.apiGetCropFocusMode({
      autoCropMode: e,
      cropHeight: i,
      cropWidth: B,
      imageUrl: this.selectedFormat.url
    });
    if (k) {
      let j = o, tt = r;
      i || (j = k.height * 100 / this.selectedFormat.height), B || (tt = k.width * 100 / this.selectedFormat.width), this.cropSize = {
        ...this.cropSize,
        height: k.height,
        percentageHeight: j ?? this.cropSize.percentageHeight,
        percentageWidth: tt ?? this.cropSize.percentageWidth,
        width: k.width,
        x: k.x * 100 / this.selectedFormat.width,
        y: k.y * 100 / this.selectedFormat.height,
        ...$ ? {
          cropMode: e,
          focusMode: "manual",
          keepAspectRatio: !1
        } : {
          cropMode: t ?? this.cropSize.cropMode,
          focusMode: e
        },
        keepAspectRatio: s ?? this.cropSize.keepAspectRatio,
        ratioHeight: n ?? this.cropSize.ratioHeight,
        ratioWidth: x ?? this.cropSize.ratioWidth,
        unit: z ?? this.cropSize.unit
      };
    }
    this.loading = !1, this.lastAction = void 0;
  }
  async onCropComplete(t) {
    const { croppedArea: e } = t.detail, {
      height: i,
      width: s,
      x: o,
      y: r
    } = e;
    if (s === 0 || i === 0)
      return;
    const n = this.cropSize.percentageWidth !== s, x = this.cropSize.percentageHeight !== i;
    let z = this.cropSize.height, $ = this.cropSize.width;
    n && ($ = Math.round(s * this.selectedFormat.width / 100)), x && (z = Math.round(
      i * this.selectedFormat.height / 100
    ));
    const B = this.cropSize.focusMode;
    this.focusModes.find(
      (j) => j.value === B
    )?.auto && this.selectedFormat?.url && this.cropperElement ? await this.handleRequestAutoCropSuggestion({
      focusMode: B,
      height: z,
      percentageHeight: i,
      percentageWidth: s,
      width: $
    }) : this.cropSize = {
      ...this.cropSize,
      height: z,
      percentageHeight: i,
      percentageWidth: s,
      width: $,
      x: o,
      y: r
    };
  }
  onCropDragStart() {
    let t = this.cropSize.cropMode;
    const e = this.cropModes.find(
      (i) => i.value === t
    )?.auto;
    (this.cropSize.focusMode !== "manual" || e) && (e && (t = "free"), this.cropSize = {
      ...this.cropSize,
      cropMode: t,
      focusMode: "manual"
    });
  }
  onDetailsShow(t) {
    const e = t.target;
    e.shadowRoot?.querySelector(".details") && (this.activeSetting = e.localName);
  }
  onDetailsHide(t) {
    this.activeSetting === t.target.localName && (this.activeSetting = "");
  }
  onProxyChange(t) {
    const e = t.detail;
    this.lastAction = d.Proxy, this.selectedProxy = e.id;
  }
  async onCropModeChange(t) {
    const { mode: e } = t.detail;
    if (this.cropModes.find((s) => s.value === e)?.auto)
      await this.handleRequestAutoCropSuggestion({
        focusMode: e,
        useCropMode: !0
      });
    else {
      const s = this.focusModes.find(
        (z) => z.value === this.cropSize.focusMode
      )?.auto;
      let o = this.cropSize.keepAspectRatio, r = this.cropSize.focusMode, n = this.cropSize.x, x = this.cropSize.y;
      e === "free" ? (o = !1, r = "manual") : this.cropSize.unit === a.Pixel && !s && (n = 0, x = 0), s ? await this.handleRequestAutoCropSuggestion({
        cropMode: e,
        focusMode: r,
        height: this.cropSize.height,
        keepAspectRatio: o,
        width: this.cropSize.width
      }) : this.cropSize = {
        ...this.cropSize,
        cropMode: e,
        focusMode: r,
        keepAspectRatio: o,
        x: n,
        y: x
      };
    }
  }
  onCropFocusModeChange(t) {
    const { mode: e } = t.detail;
    this.focusModes.find((s) => s.value === e)?.auto && this.selectedFormat?.url ? this.handleRequestAutoCropSuggestion({
      focusMode: e,
      height: this.cropSize.height,
      width: this.cropSize.width
    }) : this.cropSize = {
      ...this.cropSize,
      focusMode: e
    };
  }
  async onCropChange(t) {
    const e = this.cropSize.unit;
    if (t.detail.unit === a.AspectRatio) {
      const i = t.detail.width / t.detail.height, s = Math.min(
        Math.max(Math.round(this.cropSize.height * i), 0),
        this.resizeSize.width
      ), o = Math.min(
        Math.max(Math.round(s / i), 0),
        this.resizeSize.height
      ), r = o * 100 / this.selectedFormat.height, n = s * 100 / this.selectedFormat.width;
      let x = this.cropSize.x, z = this.cropSize.y;
      x + n > 100 && (x = 100 - n), z + r > 100 && (z = 100 - r);
      let $ = this.cropSize.cropMode;
      this.cropModes.find(
        (k) => k.value === $
      )?.auto && ($ = "free"), t.detail.silent ? (this.cropSize.height = o, this.cropSize.keepAspectRatio = t.detail.keepAspectRatio, this.cropSize.percentageHeight = r, this.cropSize.percentageWidth = n, this.cropSize.ratioHeight = t.detail.height, this.cropSize.ratioWidth = t.detail.width, this.cropSize.unit = a.AspectRatio, this.cropSize.width = s) : this.cropSize = {
        ...this.cropSize,
        cropMode: $,
        height: o,
        keepAspectRatio: t.detail.keepAspectRatio,
        percentageHeight: r,
        percentageWidth: n,
        ratioHeight: t.detail.height,
        ratioWidth: t.detail.width,
        unit: a.AspectRatio,
        width: s,
        x,
        y: z
      };
    } else {
      const i = this.selectedFormat ? t.detail.height * 100 / this.selectedFormat.height : 100, s = this.selectedFormat ? t.detail.width * 100 / this.selectedFormat.width : 100;
      let o = this.cropSize.x, r = this.cropSize.y;
      o + s > 100 && (o = 100 - s), r + i > 100 && (r = 100 - i);
      let n = this.cropSize.cropMode;
      const x = this.cropModes.find(
        (z) => z.value === n
      )?.auto;
      (t.detail.breakAspectRatio || x) && (n = "free"), t.detail.silent ? (this.cropSize.cropMode = n, this.cropSize.height = t.detail.height, this.cropSize.keepAspectRatio = t.detail.keepAspectRatio, this.cropSize.percentageHeight = i, this.cropSize.percentageWidth = s, this.cropSize.unit = a.Pixel, this.cropSize.width = t.detail.width, this.cropSize.x = o, this.cropSize.y = r) : this.cropSize = {
        ...this.cropSize,
        cropMode: n,
        height: t.detail.height,
        keepAspectRatio: t.detail.keepAspectRatio,
        percentageHeight: i,
        percentageWidth: s,
        unit: a.Pixel,
        width: t.detail.width,
        x: o,
        y: r
      };
    }
    e !== this.cropSize.unit && (this.cropSize = {
      ...this.cropSize,
      cropMode: "free"
    }, this.onCropChanged());
  }
  async onCropChanged() {
    this.focusModes.find(
      (e) => e.value === this.cropSize.focusMode
    )?.auto && await this.handleRequestAutoCropSuggestion({
      focusMode: this.cropSize.focusMode,
      height: this.cropSize.height,
      width: this.cropSize.width
    });
  }
  onCropApply(t) {
    const { height: e, mode: i, unit: s, width: o } = t.detail;
    if (this.preResetTransformations = void 0, this.lastAction = d.Crop, !(!this.cropperElement || !this.selectedFormat))
      if (e && o && s) {
        let r = o, n = e;
        if (s === a.AspectRatio && (r = this.cropSize.percentageWidth * this.selectedFormat.width / 100, n = this.cropSize.percentageHeight * this.selectedFormat.height / 100), i)
          this.transformations = [
            ...this.transformations,
            {
              key: d.Crop,
              value: {
                height: n,
                mode: i,
                width: r
              }
            }
          ];
        else {
          const x = this.cropSize.x / 100 * this.selectedFormat.width, z = this.cropSize.y / 100 * this.selectedFormat.height;
          this.transformations = [
            ...this.transformations,
            {
              key: d.Crop,
              value: {
                height: n,
                unit: s,
                width: r,
                x,
                y: z
              }
            }
          ];
        }
      } else i && (this.transformations = [
        ...this.transformations,
        {
          key: d.Crop,
          value: {
            mode: i
          }
        }
      ]);
  }
  onResizeChange(t) {
    if (t.detail.unit === a.AspectRatio) {
      const e = t.detail.width / t.detail.height, i = Math.max(
        Math.round(this.lastResizeSize[a.Pixel].height * e),
        0
      ), s = Math.max(Math.round(i / e), 0);
      this.resizeSize = {
        ...this.resizeSize,
        height: s,
        keepAspectRatio: t.detail.keepAspectRatio,
        ratioHeight: t.detail.height,
        ratioWidth: t.detail.width,
        unit: t.detail.unit,
        width: i
      };
    } else
      this.resizeSize = {
        ...this.resizeSize,
        height: Math.max(t.detail.height, 0),
        keepAspectRatio: t.detail.keepAspectRatio,
        unit: t.detail.unit,
        width: Math.max(t.detail.width, 0)
      };
  }
  onResizeApply(t) {
    if (!this.selectedFormat)
      return;
    const { height: e, unit: i, width: s } = t.detail;
    this.preResetTransformations = void 0, this.lastAction = d.Resize;
    const o = this.selectedFormat.width || this.defaultSize.width, r = this.selectedFormat.height || this.defaultSize.height;
    let n = s, x = e;
    this.resizeSize.unit !== i ? (n = o, x = r) : i === a.AspectRatio && (n = Math.round(s / e * r), x = r), this.transformations = [
      ...this.transformations,
      {
        key: d.Resize,
        value: {
          height: x,
          unit: i,
          width: n
        }
      }
    ];
  }
  onRotationChange(t) {
    this.rotation = t.detail;
  }
  onRotationApply(t) {
    if (!this.selectedFormat)
      return;
    const e = t.detail;
    this.preResetTransformations = void 0, this.lastAction = d.Rotate, this.transformations = [
      ...this.transformations,
      {
        key: d.Rotate,
        value: {
          rotation: e
        }
      }
    ];
  }
  onQualityChange(t) {
    if (!this.selectedFormat)
      return;
    const e = t.detail;
    this.selectedFormat.quality = e, this.preResetTransformations = void 0, this.lastAction = d.Quality, this.transformations = [
      ...this.transformations,
      {
        key: d.Quality,
        value: {
          quality: e
        }
      }
    ];
  }
  onMetadataChange(t) {
    if (!this.selectedFormat)
      return;
    const e = t.detail;
    this.preResetTransformations = void 0, this.selectedFormat = {
      ...this.selectedFormat,
      keepMetadata: e
    }, e ? this.transformations = [
      ...this.transformations.filter(
        (i) => i.key !== d.Metadata
      ),
      {
        key: d.Metadata,
        value: {
          keepMetadata: e
        }
      }
    ] : this.transformations = this.transformations.filter(
      (i) => i.key !== d.Metadata
    );
  }
  onExtensionChange(t) {
    if (!this.selectedFormat)
      return;
    const e = t.detail;
    this.selectedFormat = {
      ...this.selectedFormat,
      extension: e
    };
  }
  syncQuality() {
    const t = this.transformations.findLast(
      (e) => e.key === d.Quality
    )?.value?.quality;
    this.selectedFormat && (this.selectedFormat = {
      ...this.selectedFormat,
      quality: t ?? 100
    });
  }
  handleUndo() {
    !this.hasUnfrozenTransformations && this.preResetTransformations !== void 0 ? (this.transformations = this.preResetTransformations, this.preResetTransformations = void 0) : this.transformations = this.transformations.slice(0, -1), this.syncQuality();
  }
  handleReset() {
    this.preResetTransformations = [...this.transformations], this.transformations = [], this.frozenIndex = -1, this.syncQuality();
  }
  render() {
    return m`<div class="asset-link-format" @cx-show=${this.onDetailsShow} @cx-hide=${this.onDetailsHide}>${C(
      !this.hideHeader,
      () => m`<cx-space class="asset-link-format__section-header" direction="horizontal" spacing="small" align-items="center" justify-content="space-between"><cx-typography variant="body3">${this.localize.term("transformations")}</cx-typography><cx-space direction="horizontal" spacing="3x-small" align-items="center"><cx-button class="asset-link-format__undo" variant="custom" ?disabled=${!this.hasUnfrozenTransformations && this.preResetTransformations === void 0} @click=${this.handleUndo}>${this.localize.term("undo")}</cx-button>${C(this.canReset, () => m`<cx-button class="asset-link-format__reset" variant="custom" ?disabled=${this.transformations.length === 0} @click=${this.handleReset}>${this.localize.term("reset")}</cx-button>`)}</cx-space></cx-space>`,
      () => rt
    )}<cx-asset-link-format-proxy class="asset-link-format__details" value=${this.selectedProxy || this.proxies?.[0]?.id || ""} ?open=${this.activeSetting === "cx-asset-link-format-proxy"} .items=${this.formats} ?loading=${this.loading && this.lastAction === d.Proxy} @cx-asset-link-format-proxy-change=${this.onProxyChange}></cx-asset-link-format-proxy>${C(
      !this.noCrop,
      () => m`<cx-asset-link-format-crop class="asset-link-format__details" ?open=${this.activeSetting === "cx-asset-link-format-crop"} ?disabled-apply=${this.disabledCropApply} ?loading=${this.loading && this.lastAction === d.Crop} ?keep-aspect-ratio=${this.cropSize.keepAspectRatio} focus-mode=${this.cropSize.focusMode} crop-mode=${this.cropSize.cropMode} width=${this.cropSize.width} height=${this.cropSize.height} max-width=${this.lastResizeSize[a.Pixel].width} max-height=${this.lastResizeSize[a.Pixel].height} percentage-width=${this.cropSize.percentageWidth} percentage-height=${this.cropSize.percentageHeight} ratio-width=${this.cropSize.ratioWidth} ratio-height=${this.cropSize.ratioHeight} unit=${this.cropSize.unit} .lastAppliedSetting=${this.lastCropSize} .cropModes=${this.cropModes} .focusModes=${this.focusModes} @cx-asset-link-format-crop-mode-change=${this.onCropModeChange} @cx-asset-link-format-crop-focus-mode-change=${this.onCropFocusModeChange} @cx-asset-link-format-crop-change=${this.onCropChange} @cx-asset-link-format-crop-changed=${this.onCropChanged} @cx-asset-link-format-crop-apply=${this.onCropApply}></cx-asset-link-format-crop>`
    )}
      ${C(
      !this.noResize,
      () => m`<cx-asset-link-format-resize class="asset-link-format__details" ?open=${this.activeSetting === "cx-asset-link-format-resize"} ?loading=${this.loading && this.lastAction === d.Resize} ?keep-aspect-ratio=${this.resizeSize.keepAspectRatio} width=${this.resizeSize.width} height=${this.resizeSize.height} max-width=${this.imageSize.width} max-height=${this.imageSize.height} ratio-width=${this.resizeSize.ratioWidth} ratio-height=${this.resizeSize.ratioHeight} unit=${this.resizeSize.unit} .lastAppliedSetting=${this.lastResizeSize} @cx-asset-link-format-resize-change=${this.onResizeChange} @cx-asset-link-format-resize-apply=${this.onResizeApply}></cx-asset-link-format-resize>`
    )}
      ${C(
      !this.noRotate,
      () => m`<cx-asset-link-format-rotation class="asset-link-format__details" ?loading=${this.loading && this.lastAction === d.Rotate} ?open=${this.activeSetting === "cx-asset-link-format-rotation"} default-value=${this.selectedFormat?.rotation ?? 0} value=${this.rotation} @cx-asset-link-format-rotation-change=${this.onRotationChange} @cx-asset-link-format-rotation-apply=${this.onRotationApply}></cx-asset-link-format-rotation>`
    )}<cx-asset-link-format-quality class="asset-link-format__details" ?loading=${this.loading && this.lastAction === d.Quality} ?open=${this.activeSetting === "cx-asset-link-format-quality"} value=${this.selectedFormat?.quality ?? 100} @cx-asset-link-format-quality-change=${this.onQualityChange}></cx-asset-link-format-quality>${C(
      !this.noMetadata,
      () => m`<cx-asset-link-format-metadata class="asset-link-format__details" ?open=${this.activeSetting === "cx-asset-link-format-metadata"} .value=${this.selectedFormat?.keepMetadata ?? !1} @cx-asset-link-format-metadata-change=${this.onMetadataChange}></cx-asset-link-format-metadata>`
    )}
      ${C(
      this.useCustomExtension,
      () => m`<cx-asset-link-format-extension .items=${this.extensions} value=${this.selectedFormat?.extension ?? ""} @cx-asset-link-format-extension-change=${this.onExtensionChange}></cx-asset-link-format-extension>`
    )}</div>`;
  }
};
l.styles = [W, pt];
l.dependencies = {
  "cx-asset-link-format-crop": p,
  "cx-asset-link-format-extension": O,
  "cx-asset-link-format-metadata": M,
  "cx-asset-link-format-proxy": w,
  "cx-asset-link-format-quality": b,
  "cx-asset-link-format-resize": g,
  "cx-asset-link-format-rotation": v,
  "cx-button": U,
  "cx-space": P,
  "cx-typography": _
};
c([
  h({ attribute: "base-url", type: String })
], l.prototype, "baseUrl", 2);
c([
  h({ attribute: "token", type: String })
], l.prototype, "token", 2);
c([
  h({ reflect: !1, type: Object })
], l.prototype, "asset", 2);
c([
  h({ attribute: "crop-modes", reflect: !1, type: Array })
], l.prototype, "cropModes", 2);
c([
  h({ attribute: "focus-modes", reflect: !1, type: Object })
], l.prototype, "focusModes", 2);
c([
  h({ reflect: !1, type: Array })
], l.prototype, "extensions", 2);
c([
  h({ reflect: !1, type: Array })
], l.prototype, "proxies", 2);
c([
  h({ attribute: "for-cropper", reflect: !0, type: String })
], l.prototype, "forCropper", 2);
c([
  h({ attribute: "use-session", reflect: !0, type: String })
], l.prototype, "useSession", 2);
c([
  h({ reflect: !1, type: Array })
], l.prototype, "transformations", 2);
c([
  h({ attribute: "selected-proxy", reflect: !0, type: String })
], l.prototype, "selectedProxy", 2);
c([
  h({ attribute: "use-custom-extension", reflect: !0, type: Boolean })
], l.prototype, "useCustomExtension", 2);
c([
  h({ attribute: "no-metadata", reflect: !0, type: Boolean })
], l.prototype, "noMetadata", 2);
c([
  h({ attribute: "no-crop", reflect: !0, type: Boolean })
], l.prototype, "noCrop", 2);
c([
  h({ attribute: "no-resize", reflect: !0, type: Boolean })
], l.prototype, "noResize", 2);
c([
  h({ attribute: "no-rotate", reflect: !0, type: Boolean })
], l.prototype, "noRotate", 2);
c([
  h({ attribute: "last-image-size", reflect: !1, type: Object })
], l.prototype, "lastImageSize", 2);
c([
  h({ attribute: "hide-header", reflect: !1, type: Boolean })
], l.prototype, "hideHeader", 2);
c([
  h({ attribute: "can-reset", type: Boolean })
], l.prototype, "canReset", 2);
c([
  h({ attribute: !1, reflect: !1, type: Object })
], l.prototype, "queryElement", 2);
c([
  f()
], l.prototype, "activeSetting", 2);
c([
  f()
], l.prototype, "selectedFormat", 2);
c([
  f()
], l.prototype, "resizeSize", 2);
c([
  f()
], l.prototype, "cropSize", 2);
c([
  f()
], l.prototype, "rotation", 2);
c([
  f()
], l.prototype, "defaultSize", 2);
c([
  f()
], l.prototype, "cropperElement", 2);
c([
  f()
], l.prototype, "parameters", 2);
c([
  f()
], l.prototype, "loading", 2);
c([
  f()
], l.prototype, "lastAction", 2);
c([
  f()
], l.prototype, "frozenIndex", 2);
c([
  f()
], l.prototype, "preResetTransformations", 2);
c([
  S(["transformations"])
], l.prototype, "handleTransformationsChange", 1);
c([
  S("selectedProxy")
], l.prototype, "handleSelectedProxyChange", 1);
c([
  S("loading")
], l.prototype, "handleLoadingChange", 1);
l = c([
  F("cx-asset-link-format")
], l);
export {
  l as default
};
