'use strict';

Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });

const lit = require('lit');
const decorators_js = require('lit/decorators.js');
const styleMap_js = require('lit/directives/style-map.js');
const tailwindVariants = require('tailwind-variants');
const index = require('../../chunks/index-BBPgtFEP.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;
};
exports.LuksoImage = class LuksoImage extends index.TailwindElement {
  constructor() {
    super(...arguments);
    this.src = "";
    this.placeholder = "";
    this.isLoading = true;
    this.resolvedPlaceholder = "";
    this.hasError = false;
    this.imageStyles = tailwindVariants.tv({
      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 lit.html`
      <div class=${wrapper()}>
        <div
          class=${placeholder()}
          style=${styleMap_js.styleMap({
      backgroundImage: `url('${this.resolvedPlaceholder}')`
    })}
        >
          <img
            src=${this.src}
            class=${image()}
            loading="lazy"
            alt=""
            @load=${this.handleLoad}
            @error=${this.handleError}
          />
        </div>
      </div>
    `;
  }
};
__decorateClass([
  decorators_js.property({ type: String, reflect: true })
], exports.LuksoImage.prototype, "src", 2);
__decorateClass([
  decorators_js.property({ type: String })
], exports.LuksoImage.prototype, "placeholder", 2);
__decorateClass([
  decorators_js.state()
], exports.LuksoImage.prototype, "isLoading", 2);
__decorateClass([
  decorators_js.state()
], exports.LuksoImage.prototype, "resolvedPlaceholder", 2);
__decorateClass([
  decorators_js.state()
], exports.LuksoImage.prototype, "hasError", 2);
exports.LuksoImage = __decorateClass([
  index.safeCustomElement("lukso-image")
], exports.LuksoImage);
