'use strict';

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

const lit = require('lit');
const decorators_js = require('lit/decorators.js');
const tailwindVariants = require('tailwind-variants');
const index = require('../../chunks/index-BBPgtFEP.js');
require('../lukso-form-label/index.cjs');
require('../lukso-form-description/index.cjs');
require('../lukso-form-error/index.cjs');
require('../../tailwind-config.cjs');
require('../../chunks/index-oDo-wiUs.js');
const cn = require('../../chunks/cn-JMx_imgS.js');
require('viem');

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.LuksoRadio = class LuksoRadio extends index.TailwindElement {
  constructor() {
    super(...arguments);
    this.name = "";
    this.id = "";
    this.value = "";
    this.size = "medium";
    this.label = "";
    this.description = "";
    this.error = "";
    this.checked = false;
    this.customClass = "";
    this.isReadonly = false;
    this.isDisabled = false;
    this.hasFocus = false;
    this.hasHighlight = false;
    this.radioStyles = tailwindVariants.tv({
      slots: {
        container: "flex items-center gap-2 select-none outline-none",
        radio: `
        relative bg-neutral-100 justify-center items-center flex
        border border-solid rounded-full border-neutral-35
        outline-none transition transition-all duration-150 appearance-none shrink-0
      `,
        indicator: "rounded-full absolute appearance-none transition duration-300 ease-in",
        content: "text-neutral-20 block",
        errorText: "paragraph-inter-12-regular text-red-65 pt-2"
      },
      variants: {
        size: {
          medium: {
            radio: "h-10 w-[40px]",
            indicator: "w-[26px] h-[26px]",
            content: "paragraph-inter-16-regular"
          },
          small: {
            radio: "h-[32px] w-[32px]",
            indicator: "w-[20px] h-[20px]",
            content: "paragraph-inter-16-regular"
          },
          "x-small": {
            radio: "h-7 w-[28px]",
            indicator: "w-[17px] h-[17px]",
            content: "paragraph-inter-12-semi-bold"
          }
        },
        hasError: {
          true: {
            radio: "border-red-65",
            content: "text-red-65"
          },
          false: {
            radio: "border-neutral-90"
          }
        },
        hasHighlight: {
          true: {
            radio: "border-neutral-35"
          }
        },
        isDisabled: {
          true: {
            radio: "border-neutral-90",
            content: "text-neutral-90",
            indicator: "bg-neutral-90",
            container: "cursor-not-allowed"
          },
          false: {
            indicator: "bg-green-54"
          }
        },
        isReadonly: {
          true: {
            container: "cursor-not-allowed"
          }
        },
        isChecked: {
          true: {},
          false: {}
        }
      },
      compoundVariants: [
        {
          hasHighlight: true,
          hasError: true,
          class: {
            radio: "border-red-65"
          }
        },
        {
          isDisabled: true,
          class: {
            container: "cursor-not-allowed"
          }
        }
      ]
    });
  }
  // Expose the focus method for programmatic focusing
  focus() {
    const radioElement = this.renderRoot.querySelector('[role="radio"]');
    if (radioElement instanceof HTMLElement) {
      radioElement.focus();
    }
  }
  checkedIndicatorTemplate() {
    const { indicator } = this.radioStyles({
      size: this.size,
      isDisabled: this.isDisabled,
      isChecked: this.checked
    });
    return lit.html`
      <div class=${cn.cn(indicator(), this.checked ? "" : "hidden")}></div>
    `;
  }
  radioTemplate() {
    const { radio } = this.radioStyles({
      size: this.size,
      hasError: !!this.error,
      hasHighlight: this.hasHighlight,
      isDisabled: this.isDisabled
    });
    return lit.html`
      <div class=${cn.cn(radio(), this.customClass)}>
        ${this.checkedIndicatorTemplate()}
      </div>
    `;
  }
  contentTemplate() {
    const { content } = this.radioStyles({
      size: this.size,
      hasError: !!this.error,
      isDisabled: this.isDisabled
    });
    return lit.html`
      <div class=${content()}>
        <slot></slot>
      </div>
    `;
  }
  render() {
    const { container } = this.radioStyles({
      isDisabled: this.isDisabled,
      isReadonly: this.isReadonly
    });
    return lit.html`
      <div>
        <lukso-form-label label=${this.label}></lukso-form-label>
        <lukso-form-description
          description=${this.description}
        ></lukso-form-description>
        <div
          class=${container()}
          @mouseenter=${this.handleMouseOver}
          @mouseleave=${this.handleMouseOut}
          @click=${!this.isDisabled && !this.isReadonly ? this.handleClick : void 0}
          @keydown=${this.handleKeydown}
          @focus=${this.handleFocus}
          @blur=${this.handleBlur}
          aria-checked=${this.checked}
          role="radio"
          tabindex=${!this.isDisabled && !this.isReadonly ? "0" : "-1"}
          aria-disabled=${this.isDisabled}
          aria-readonly=${this.isReadonly}
          aria-labelledby="${this.id || `radio-${this.value}`}"
          id="${this.id || `radio-${this.value}`}"
          part="radio"
        >
          ${this.radioTemplate()} ${this.contentTemplate()}
        </div>
        <lukso-form-error error=${this.error}></lukso-form-error>
      </div>
    `;
  }
  handleKeydown(event) {
    if (this.isDisabled || this.isReadonly) return;
    if (event.key === " " || event.key === "Enter") {
      event.preventDefault();
      this.handleClick(event);
    }
    if ([
      "ArrowUp",
      "ArrowDown",
      "ArrowLeft",
      "ArrowRight",
      "Home",
      "End"
    ].includes(event.key)) {
      const radioGroup = this.closest("lukso-radio-group");
      if (radioGroup) {
        return;
      }
    }
  }
  handleFocus() {
    this.hasFocus = true;
    this.hasHighlight = true;
  }
  handleBlur() {
    this.hasFocus = false;
    this.hasHighlight = false;
  }
  async handleClick(event) {
    if (this.isReadonly || this.isDisabled) return;
    this.checked = true;
    await this.updateComplete;
    this.dispatchEvent(
      new CustomEvent("on-change", {
        detail: {
          value: this.value,
          checked: true,
          event
        },
        bubbles: true,
        composed: true
      })
    );
  }
  handleMouseOver() {
    if (!this.isReadonly && !this.isDisabled) {
      this.hasHighlight = true;
    }
  }
  handleMouseOut() {
    if (!this.hasFocus) {
      this.hasHighlight = false;
    }
  }
};
__decorateClass([
  decorators_js.property({ type: String })
], exports.LuksoRadio.prototype, "name", 2);
__decorateClass([
  decorators_js.property({ type: String })
], exports.LuksoRadio.prototype, "id", 2);
__decorateClass([
  decorators_js.property({ type: String })
], exports.LuksoRadio.prototype, "value", 2);
__decorateClass([
  decorators_js.property({ type: String })
], exports.LuksoRadio.prototype, "size", 2);
__decorateClass([
  decorators_js.property({ type: String })
], exports.LuksoRadio.prototype, "label", 2);
__decorateClass([
  decorators_js.property({ type: String })
], exports.LuksoRadio.prototype, "description", 2);
__decorateClass([
  decorators_js.property({ type: String })
], exports.LuksoRadio.prototype, "error", 2);
__decorateClass([
  decorators_js.property({ type: Boolean })
], exports.LuksoRadio.prototype, "checked", 2);
__decorateClass([
  decorators_js.property({ type: String, attribute: "custom-class" })
], exports.LuksoRadio.prototype, "customClass", 2);
__decorateClass([
  decorators_js.property({ type: Boolean, attribute: "is-readonly" })
], exports.LuksoRadio.prototype, "isReadonly", 2);
__decorateClass([
  decorators_js.property({ type: Boolean, attribute: "is-disabled" })
], exports.LuksoRadio.prototype, "isDisabled", 2);
__decorateClass([
  decorators_js.state()
], exports.LuksoRadio.prototype, "hasFocus", 2);
__decorateClass([
  decorators_js.state()
], exports.LuksoRadio.prototype, "hasHighlight", 2);
exports.LuksoRadio = __decorateClass([
  index.safeCustomElement("lukso-radio")
], exports.LuksoRadio);
