'use strict';

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

const shared_tailwindElement_index = require('../../index-aaa67d55.cjs');
const queryAssignedElements = require('../../query-assigned-elements-1d5d9d4c.cjs');
const state = require('../../state-f73a8b4f.cjs');
const index = require('../../index-e9668573.cjs');
require('../../directive-8278ab14.cjs');

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.LuksoCheckbox = class LuksoCheckbox extends shared_tailwindElement_index.TailwindElement {
  constructor() {
    super(...arguments);
    this.name = "";
    this.id = "";
    this.ref = void 0;
    this.type = "text";
    this.size = "medium";
    this.error = "";
    this.checked = false;
    this.customClass = "";
    this.isReadonly = false;
    this.isDisabled = false;
    this.hasFocus = false;
    this.hasHighlight = false;
    this.defaultContainerStyles = `
        flex items-center gap-2
        select-none
    `;
    this.defaultInputStyles = `
        peer
        absolute
        top-0 left-0
        opacity-0
    `;
    this.defaultLabelStyles = `
    text-neutral-20 block
    `;
    this.defaultCheckboxStyles = `
    relative
    bg-neutral-100
    justify-center items-center flex
    border border-solid rounded-md
    outline-none transition transition-all duration-150 appearance-none`;
  }
  checkedIconTemplate() {
    return shared_tailwindElement_index.x`
      <lukso-icon
        class=${index.customClassMap({
      hidden: !this.checked
    })}
        name="tick"
        color=${this.isDisabled ? "neutral-60" : "neutral-20"}
      ></lukso-icon>
    `;
  }
  checkboxTemplate() {
    return shared_tailwindElement_index.x`
      <div
        class=${index.customClassMap({
      [this.defaultCheckboxStyles]: true,
      [this.error === "" ? "border-neutral-90" : "border-red-85"]: !this.hasHighlight,
      [this.error === "" ? "border-neutral-35" : "border-red-65"]: this.hasHighlight,
      ["border-neutral-60"]: this.isDisabled,
      ["h-[40px] w-[40px]"]: this.size === "medium",
      ["h-[32px] w-[32px]"]: this.size === "small",
      ["h-[28px] w-[28px]"]: this.size === "x-small",
      [this.customClass]: !!this.customClass
    })}
      >
        ${this.checkedIconTemplate()}
      </div>
    `;
  }
  inputTemplate() {
    const id = this.id || this.name;
    return shared_tailwindElement_index.x`
      <input
        name=${this.name}
        ?checked=${this.checked ? "checked" : void 0}
        type="checkbox"
        class=${index.customClassMap({
      [this.defaultInputStyles]: true,
      ["text-neutral-60"]: this.isDisabled
    })}
        ref=${this.ref}
        id=${id}
        data-testid=${this.name ? `input-${this.name}` : "input"}
        ?disabled=${this.isDisabled ? true : void 0}
        ?readonly=${this.isReadonly ? true : void 0}
        @change=${!this.isReadonly ? this.handleChange : "return false;"}
      />
    `;
  }
  errorTemplate() {
    return shared_tailwindElement_index.x`
      <div class="paragraph-inter-12-regular text-red-65 pt-2">
        ${this.error}
      </div>
    `;
  }
  labelTemplate() {
    return shared_tailwindElement_index.x`
      <span
        class=${index.customClassMap({
      [this.defaultLabelStyles]: true,
      ["paragraph-inter-16-regular"]: this.size === "medium" || this.size === "small",
      ["paragraph-inter-12-semi-bold"]: this.size === "x-small",
      ["text-red-65"]: this.error !== "",
      ["text-neutral-60"]: this.isDisabled
    })}
      >
        <slot></slot>
      </span>
    `;
  }
  profileUsernameTemplate() {
    return shared_tailwindElement_index.x`
      <div class="flex items-center text-neutral-20 gap-2 justify-center">
        <slot></slot>
      </div>
    `;
  }
  render() {
    return shared_tailwindElement_index.x`
      <div>
        <label
          for=${this.name}
          class=${index.customClassMap({
      [this.defaultContainerStyles]: true,
      ["cursor-not-allowed"]: this.isDisabled || this.isReadonly
    })}
          @mouseenter=${this.handleMouseOver}
          @mouseleave=${this.handleMouseOut}
        >
          ${this.inputTemplate()} ${this.checkboxTemplate()}
          ${this.type === "text" ? this.labelTemplate() : shared_tailwindElement_index.A}
          ${this.type === "profile" ? this.profileUsernameTemplate() : shared_tailwindElement_index.A}
        </label>
      </div>
    `;
  }
  async handleChange(event) {
    const target = event.target;
    this.checked = target.checked;
    await this.updateComplete;
    this.dispatchEvent(
      new CustomEvent("on-change", {
        detail: {
          value: target.value,
          checked: target.checked,
          event
        },
        bubbles: true,
        composed: true
      })
    );
  }
  handleMouseOver() {
    if (!this.isReadonly && !this.isDisabled) {
      this.hasHighlight = true;
    }
  }
  handleMouseOut() {
    if (!this.hasFocus) {
      this.hasHighlight = false;
    }
  }
};
__decorateClass([
  queryAssignedElements.n({ type: String })
], exports.LuksoCheckbox.prototype, "name", 2);
__decorateClass([
  queryAssignedElements.n({ type: String })
], exports.LuksoCheckbox.prototype, "id", 2);
__decorateClass([
  queryAssignedElements.n({ type: String })
], exports.LuksoCheckbox.prototype, "ref", 2);
__decorateClass([
  queryAssignedElements.n({ type: String })
], exports.LuksoCheckbox.prototype, "type", 2);
__decorateClass([
  queryAssignedElements.n({ type: String })
], exports.LuksoCheckbox.prototype, "size", 2);
__decorateClass([
  queryAssignedElements.n({ type: String })
], exports.LuksoCheckbox.prototype, "error", 2);
__decorateClass([
  queryAssignedElements.n({ type: Boolean })
], exports.LuksoCheckbox.prototype, "checked", 2);
__decorateClass([
  queryAssignedElements.n({ type: String, attribute: "custom-class" })
], exports.LuksoCheckbox.prototype, "customClass", 2);
__decorateClass([
  queryAssignedElements.n({ type: Boolean, attribute: "is-readonly" })
], exports.LuksoCheckbox.prototype, "isReadonly", 2);
__decorateClass([
  queryAssignedElements.n({ type: Boolean, attribute: "is-disabled" })
], exports.LuksoCheckbox.prototype, "isDisabled", 2);
__decorateClass([
  state.t()
], exports.LuksoCheckbox.prototype, "hasFocus", 2);
__decorateClass([
  state.t()
], exports.LuksoCheckbox.prototype, "hasHighlight", 2);
exports.LuksoCheckbox = __decorateClass([
  queryAssignedElements.e("lukso-checkbox")
], exports.LuksoCheckbox);
