'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 styleMap_js = require('lit/directives/style-map.js');
const index = require('../../chunks/index-BBPgtFEP.js');
require('../../tailwind-config.cjs');
require('../../chunks/index-oDo-wiUs.js');
const cn = require('../../chunks/cn-JMx_imgS.js');
require('viem');
require('../lukso-icon/index.cjs');
require('../../chunks/index-Dh7fuono.js');
require('../lukso-form-label/index.cjs');
require('../lukso-form-description/index.cjs');
require('../lukso-form-error/index.cjs');

const style = ":host {\n\n    display: inline-flex\n}\n\n:host([is-full-width]) {\n\n    display: flex;\n\n    width: 100%\n}";

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;
};
const FOCUS_DELAY_MS = 10;
exports.LuksoColorPicker = class LuksoColorPicker extends index.TailwindStyledElement(style) {
  constructor() {
    super(...arguments);
    this.value = "";
    this.name = "";
    this.placeholder = "#000000";
    this.label = "";
    this.id = "";
    this.description = "";
    this.error = "";
    this.customClass = "";
    this.isFullWidth = false;
    this.isReadonly = false;
    this.isDisabled = false;
    this.autofocus = false;
    this.keepFocusOnEscape = false;
    this.size = "medium";
    this.hasFocus = false;
    this.hasHighlight = false;
    this.styles = tailwindVariants.tv({
      slots: {
        wrapper: "group grid border overflow-hidden",
        input: `bg-neutral-100 border-solid placeholder:text-neutral-70 w-full
        outline-none transition transition-all duration-150 appearance-none`,
        color: "border-r border-solid",
        colorInput: "h-[inherit] w-[inherit] opacity-0"
      },
      variants: {
        hasError: {
          true: {
            wrapper: "border-red-85 hover:border-red-65",
            color: "border-red-85 group-hover:border-red-65"
          },
          false: {
            wrapper: "border-neutral-90",
            color: "border-neutral-90"
          }
        },
        hasHighlight: {
          true: {
            wrapper: "border-neutral-35",
            color: "border-neutral-35"
          }
        },
        isReadonly: {
          true: { input: "cursor-not-allowed", colorInput: "cursor-not-allowed" }
        },
        isDisabled: {
          true: {
            input: "text-neutral-60 cursor-not-allowed",
            color: "opacity-50",
            colorInput: "cursor-not-allowed"
          },
          false: {
            wrapper: "hover:border-neutral-35",
            input: "text-neutral-20",
            color: "group-hover:border-neutral-35"
          }
        },
        isFullWidth: {
          true: { wrapper: "w-full" },
          false: { wrapper: "w-[350px]" }
        },
        size: {
          small: {
            wrapper: "grid-cols-[28px,auto] rounded-8",
            input: "h-7 px-2 py-1 paragraph-inter-12-regular rounded-r-8",
            color: "h-7 w-[28px]"
          },
          medium: {
            wrapper: "grid-cols-[40px,auto] rounded-12",
            input: "h-10 px-3 py-2 paragraph-inter-14-regular rounded-r-10",
            color: "h-10 w-[40px]"
          },
          large: {
            wrapper: "grid-cols-[48px,auto] rounded-12",
            input: "h-12 px-4 py-3 paragraph-inter-14-regular rounded-r-12",
            color: "h-12 w-[48px]"
          },
          "x-large": {}
        }
      },
      compoundVariants: [
        {
          isFullWidth: false,
          class: { wrapper: "w-[300px]" }
        },
        {
          isFullWidth: false,
          size: "small",
          class: { wrapper: "w-[190px]" }
        },
        {
          isFullWidth: false,
          size: "small",
          class: { wrapper: "w-[210px]" }
        },
        {
          hasHighlight: true,
          hasError: true,
          class: {
            wrapper: "border-red-65 hover:border-red-65",
            color: "border-red-65 group-hover:border-red-65"
          }
        },
        {
          isReadonly: false,
          isDisabled: false,
          class: {
            colorInput: "cursor-pointer"
          }
        }
      ]
    });
  }
  connectedCallback() {
    super.connectedCallback();
    if (this.autofocus) {
      setTimeout(() => {
        const input = this.shadowRoot?.querySelector(
          "input[autofocus]"
        );
        input?.focus();
      }, FOCUS_DELAY_MS);
    }
  }
  inputTemplate(styles) {
    return lit.html`
      <input
        .value=${this.value}
        name=${this.name ? this.name : lit.nothing}
        type="text"
        placeholder=${this.placeholder ? this.placeholder : lit.nothing}
        ?autofocus=${this.autofocus}
        autocomplete="off"
        id=${this.id ? this.id : lit.nothing}
        data-testid=${this.name ? `input-${this.name}` : "input"}
        ?readonly=${this.isReadonly ? true : void 0}
        ?disabled=${this.isDisabled ? true : void 0}
        class=${cn.cn(styles, this.customClass)}
        @focus=${this.handleFocus}
        @input=${this.handleInput}
        @change=${this.handleChange}
        @blur=${this.handleBlur}
        @keyup=${this.handleKeyUp}
        @keydown=${this.handleKeyDown}
      />
    `;
  }
  colorPickerTemplate(styles, colorInputStyles) {
    return lit.html`<div
      class=${styles}
      style=${styleMap_js.styleMap({
      backgroundColor: `${this.value}`
    })}
    >
      <input
        .value=${this.value}
        type="color"
        ?disabled=${this.isDisabled || this.isReadonly ? true : void 0}
        class=${colorInputStyles}
        @input=${this.handleInput}
      />
    </div>`;
  }
  handleFocus() {
    if (!this.isReadonly && !this.isDisabled) {
      this.hasFocus = true;
      this.hasHighlight = true;
    }
  }
  async handleBlur(event) {
    this.hasFocus = false;
    this.hasHighlight = false;
    await this.updateComplete;
    const target = event.target;
    const blurEvent = new CustomEvent("on-blur", {
      detail: {
        value: target?.value,
        event
      },
      bubbles: false,
      composed: true
    });
    this.dispatchEvent(blurEvent);
  }
  async handleChange(event) {
    await this.updateComplete;
    const target = event.target;
    const changeEvent = new CustomEvent("on-change", {
      detail: {
        value: target?.value,
        event
      },
      bubbles: false,
      composed: true
    });
    this.dispatchEvent(changeEvent);
  }
  async handleInput(event) {
    await this.updateComplete;
    const target = event.target;
    this.value = target?.value;
    const changeEvent = new CustomEvent("on-input", {
      detail: {
        value: target?.value,
        event
      },
      bubbles: false,
      composed: true
    });
    this.dispatchEvent(changeEvent);
  }
  async handleKeyUp(event) {
    await this.updateComplete;
    const target = event.target;
    const keyEvent = new CustomEvent("on-key-up", {
      detail: {
        value: target?.value,
        event
      },
      bubbles: true,
      composed: true
    });
    this.dispatchEvent(keyEvent);
    if (event.key === "Escape" && !this.keepFocusOnEscape) {
      this.blur();
    }
  }
  async handleKeyDown(event) {
    await this.updateComplete;
    const target = event.target;
    const keyEvent = new CustomEvent("on-key-down", {
      detail: {
        value: target.value,
        event
      },
      bubbles: true,
      composed: true
    });
    this.dispatchEvent(keyEvent);
  }
  render() {
    const { wrapper, input, color, colorInput } = this.styles({
      hasError: !!this.error,
      hasHighlight: this.hasHighlight,
      isReadonly: this.isReadonly,
      isDisabled: this.isDisabled,
      isFullWidth: this.isFullWidth,
      size: this.size
    });
    return lit.html`
      <div class="w-[inherit]">
        <lukso-form-label
          for-name=${this.name}
          label=${this.label}
        ></lukso-form-label>
        <lukso-form-description
          description=${this.description}
        ></lukso-form-description>
        <div class=${wrapper()}>
          ${this.colorPickerTemplate(color(), colorInput())}
          <div class="relative w-full">${this.inputTemplate(input())}</div>
        </div>
        <lukso-form-error error=${this.error}></lukso-form-error>
      </div>
    `;
  }
};
__decorateClass([
  decorators_js.property({ type: String })
], exports.LuksoColorPicker.prototype, "value", 2);
__decorateClass([
  decorators_js.property({ type: String })
], exports.LuksoColorPicker.prototype, "name", 2);
__decorateClass([
  decorators_js.property({ type: String })
], exports.LuksoColorPicker.prototype, "placeholder", 2);
__decorateClass([
  decorators_js.property({ type: String })
], exports.LuksoColorPicker.prototype, "label", 2);
__decorateClass([
  decorators_js.property({ type: String })
], exports.LuksoColorPicker.prototype, "id", 2);
__decorateClass([
  decorators_js.property({ type: String })
], exports.LuksoColorPicker.prototype, "description", 2);
__decorateClass([
  decorators_js.property({ type: String })
], exports.LuksoColorPicker.prototype, "error", 2);
__decorateClass([
  decorators_js.property({ type: String, attribute: "custom-class" })
], exports.LuksoColorPicker.prototype, "customClass", 2);
__decorateClass([
  decorators_js.property({ type: Boolean, attribute: "is-full-width" })
], exports.LuksoColorPicker.prototype, "isFullWidth", 2);
__decorateClass([
  decorators_js.property({ type: Boolean, attribute: "is-readonly" })
], exports.LuksoColorPicker.prototype, "isReadonly", 2);
__decorateClass([
  decorators_js.property({ type: Boolean, attribute: "is-disabled" })
], exports.LuksoColorPicker.prototype, "isDisabled", 2);
__decorateClass([
  decorators_js.property({ type: Boolean })
], exports.LuksoColorPicker.prototype, "autofocus", 2);
__decorateClass([
  decorators_js.property({ type: Boolean, attribute: "keep-focus-on-escape" })
], exports.LuksoColorPicker.prototype, "keepFocusOnEscape", 2);
__decorateClass([
  decorators_js.property({ type: String })
], exports.LuksoColorPicker.prototype, "size", 2);
__decorateClass([
  decorators_js.state()
], exports.LuksoColorPicker.prototype, "hasFocus", 2);
__decorateClass([
  decorators_js.state()
], exports.LuksoColorPicker.prototype, "hasHighlight", 2);
exports.LuksoColorPicker = __decorateClass([
  index.safeCustomElement("lukso-color-picker")
], exports.LuksoColorPicker);
