import { a as TailwindElement, x } from '../../index-db8c2781.js';
import { n, t } from '../../property-81c75dec.js';
import { r } from '../../state-ebd3d73f.js';
import { o } from '../../style-map-d9a53ff6.js';
import { c as ce } from '../../index-d14b6a34.js';
import '../../directive-2bb7789e.js';

var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __decorateClass = (decorators, target, key, kind) => {
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
    if (decorator = decorators[i])
      result = (kind ? decorator(target, key, result) : decorator(result)) || result;
  if (kind && result)
    __defProp(target, key, result);
  return result;
};
let LuksoImage = class extends TailwindElement {
  constructor() {
    super(...arguments);
    this.src = "";
    this.placeholder = "";
    this.isLoading = true;
    this.resolvedPlaceholder = "";
    this.hasError = false;
    this.imageStyles = ce({
      slots: {
        wrapper: "size-full bg-neutral-100",
        placeholder: "bg-[50%] bg-no-repeat bg-cover bg-neutral-90 relative size-full",
        image: "object-cover opacity-0 size-full"
      },
      variants: {
        isLoading: {
          true: {}
        },
        hasError: {
          true: {}
        }
      },
      compoundVariants: [
        {
          isLoading: false,
          hasError: false,
          class: {
            image: "animate-fade-in animation-fill-forwards"
          }
        },
        {
          isLoading: true,
          hasError: false,
          class: {
            placeholder: "animate-pulse"
          }
        },
        {
          isLoading: false,
          hasError: true,
          class: {
            image: "opacity-0"
          }
        }
      ]
    });
  }
  handleLoad() {
    this.isLoading = false;
    this.hasError = false;
  }
  handleError() {
    this.isLoading = false;
    this.hasError = true;
  }
  async willUpdate(changedProperties) {
    if (changedProperties.has("hasError")) {
      if (this.hasError) {
        this.resolvedPlaceholder = this.placeholder;
      } else {
        this.resolvedPlaceholder = "";
      }
      await this.updateComplete;
    }
  }
  render() {
    const { wrapper, placeholder, image } = this.imageStyles({
      isLoading: this.isLoading,
      hasError: this.hasError
    });
    return x`
      <div class=${wrapper()}>
        <div
          class=${placeholder()}
          style=${o({
      backgroundImage: `url('${this.resolvedPlaceholder}')`
    })}
        >
          <img
            src=${this.src}
            class=${image()}
            loading="lazy"
            alt=""
            @load=${this.handleLoad}
            @error=${this.handleError}
          />
        </div>
      </div>
    `;
  }
};
__decorateClass([
  n({ type: String })
], LuksoImage.prototype, "src", 2);
__decorateClass([
  n({ type: String })
], LuksoImage.prototype, "placeholder", 2);
__decorateClass([
  r()
], LuksoImage.prototype, "isLoading", 2);
__decorateClass([
  r()
], LuksoImage.prototype, "resolvedPlaceholder", 2);
__decorateClass([
  r()
], LuksoImage.prototype, "hasError", 2);
LuksoImage = __decorateClass([
  t("lukso-image")
], LuksoImage);

export { LuksoImage };
