Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
require("../../_virtual/_rolldown/runtime.cjs");
const require_safe_custom_element = require("../../shared/safe-custom-element.cjs");
const require_index = require("../../shared/tailwind-element/index.cjs");
const require_decorate = require("../../_virtual/_@oxc-project_runtime@0.127.0/helpers/decorate.cjs");
require("../lukso-icon/index.cjs");
require("../lukso-sanitize/index.cjs");
require("../lukso-form-description/index.cjs");
require("../lukso-form-error/index.cjs");
require("../lukso-form-label/index.cjs");
require("../lukso-input/index.cjs");
require("../lukso-dropdown/index.cjs");
require("../lukso-dropdown-option/index.cjs");
const require_style = require("./style.css?inline.cjs");
const require_rules = require("./rules.cjs");
let lit = require("lit");
let lit_decorators_js = require("lit/decorators.js");
let tailwind_variants = require("tailwind-variants");
//#region src/components/lukso-time-picker/index.ts
var LuksoTimePicker = class LuksoTimePicker extends require_index.TailwindStyledElement(require_style.default) {
	constructor(..._args) {
		super(..._args);
		this.locale = typeof navigator !== "undefined" ? navigator.language : "en-US";
		this.timeFormat = "auto";
		this.size = "medium";
		this.isStandalone = true;
		this.isDisabled = false;
		this._selectedHour = (/* @__PURE__ */ new Date()).getHours();
		this._selectedMinute = (/* @__PURE__ */ new Date()).getMinutes();
		this._showAmPmPicker = false;
		this.styles = (0, tailwind_variants.tv)({
			slots: {
				outer: "flex flex-col",
				card: "flex items-center bg-neutral-100 rounded-12 shadow-drop-shadow-small w-full",
				timeRow: "flex items-center gap-2",
				timeSeparator: "text-paragraph-sm text-neutral-40",
				ampmWrapper: "relative",
				ampmBtn: "w-9 text-center text-paragraph-xxs-bold text-neutral-20 border border-neutral-85 rounded-4 px-1.5 py-0.5 hover:bg-neutral-95 cursor-pointer transition-colors"
			},
			variants: {
				size: {
					small: { outer: "w-[240px]" },
					medium: { outer: "w-[300px]" },
					large: { outer: "w-[360px]" },
					"x-large": { outer: "w-[420px]" },
					full: { outer: "w-full" }
				},
				isDisabled: { true: { outer: "opacity-50 pointer-events-none" } }
			}
		});
	}
	willUpdate(changed) {
		if (changed.has("value") && this.value) {
			const [hStr, mStr] = this.value.split(":");
			const h = parseInt(hStr, 10);
			const m = parseInt(mStr, 10);
			if (!isNaN(h) && !isNaN(m)) {
				this._selectedHour = Math.max(0, Math.min(23, h));
				this._selectedMinute = Math.max(0, Math.min(59, m));
			}
		}
	}
	get _uses24Hour() {
		if (this.timeFormat === "24h") return true;
		if (this.timeFormat === "12h") return false;
		try {
			return new Intl.DateTimeFormat(this.locale, { hour: "numeric" }).resolvedOptions().hour12 === false;
		} catch {
			return true;
		}
	}
	get _displayHour() {
		if (this._uses24Hour) return String(this._selectedHour).padStart(2, "0");
		const h = this._selectedHour % 12;
		return String(h === 0 ? 12 : h);
	}
	get _displayMinute() {
		return String(this._selectedMinute).padStart(2, "0");
	}
	get _amPmLabel() {
		return this._selectedHour < 12 ? "AM" : "PM";
	}
	_buildTimeValue() {
		return `${String(this._selectedHour).padStart(2, "0")}:${String(this._selectedMinute).padStart(2, "0")}`;
	}
	_handleHourChange(event) {
		const { value: rawStringValue, event: innerEvent } = event.detail;
		const sanitized = (this._uses24Hour ? require_rules.RULES_MAP.isHour24 : require_rules.RULES_MAP.isHour12).sanitize(rawStringValue);
		const rawValue = parseInt(sanitized, 10);
		if (isNaN(rawValue) || !this._uses24Hour && rawValue === 0) return;
		if (this._uses24Hour) this._selectedHour = rawValue;
		else {
			const isPm = this._selectedHour >= 12;
			this._selectedHour = isPm ? rawValue === 12 ? 12 : rawValue + 12 : rawValue === 12 ? 0 : rawValue;
		}
		this._emitChange(innerEvent);
	}
	_handleMinuteChange(event) {
		const { value: rawStringValue, event: innerEvent } = event.detail;
		const sanitized = require_rules.RULES_MAP.isMinute.sanitize(rawStringValue);
		const rawValue = parseInt(sanitized, 10);
		if (isNaN(rawValue)) return;
		this._selectedMinute = rawValue;
		this._emitChange(innerEvent);
	}
	_toggleAmPmPicker(e) {
		e.stopPropagation();
		this._showAmPmPicker = !this._showAmPmPicker;
	}
	_selectAmPm(period, e) {
		e.stopPropagation();
		const isCurrentlyAm = this._selectedHour < 12;
		const wantAm = period === "AM";
		if (isCurrentlyAm !== wantAm) this._selectedHour = wantAm ? this._selectedHour - 12 : this._selectedHour + 12;
		this._showAmPmPicker = false;
		this._emitChange(e);
	}
	_emitChange(event) {
		this.dispatchEvent(new CustomEvent("on-change", {
			detail: {
				value: this._buildTimeValue(),
				event
			},
			bubbles: true,
			composed: true
		}));
	}
	_renderTimeRow(timeRow, timeSeparator, ampmWrapper, ampmBtn) {
		return lit.html`
      <div class=${timeRow()}>
        <div class="w-8">
          <lukso-input
            type="text"
            size="medium"
            ?borderless=${true}
            .rules=${["allowNumbersAndDot", "disallowDecimal"]}
            ?is-full-width=${true}
            custom-class="text-center text-neutral-20 !px-1"
            .value=${this._displayHour}
            aria-label="Hours"
            @on-input=${this._handleHourChange}
          ></lukso-input>
        </div>
        <span class=${timeSeparator()}>:</span>
        <div class="w-8">
          <lukso-input
            type="text"
            size="medium"
            ?borderless=${true}
            .rules=${["allowNumbersAndDot", "disallowDecimal"]}
            ?is-full-width=${true}
            custom-class="text-center text-neutral-20 !px-1"
            .value=${this._displayMinute}
            aria-label="Minutes"
            @on-input=${this._handleMinuteChange}
          ></lukso-input>
        </div>
        ${!this._uses24Hour ? lit.html`
              <div
                class=${ampmWrapper()}
                @click=${(e) => e.stopPropagation()}
              >
                <button
                  type="button"
                  class=${ampmBtn()}
                  @click=${this._toggleAmPmPicker}
                  aria-haspopup="listbox"
                  aria-expanded=${this._showAmPmPicker ? "true" : "false"}
                >
                  ${this._amPmLabel}
                </button>
                <lukso-dropdown
                  ?is-open=${this._showAmPmPicker}
                  open-top
                  is-right
                  size="small"
                >
                  <lukso-dropdown-option
                    size="small"
                    ?is-selected=${this._amPmLabel === "AM"}
                    @click=${(e) => this._selectAmPm("AM", e)}
                    >AM</lukso-dropdown-option
                  >
                  <lukso-dropdown-option
                    size="small"
                    ?is-selected=${this._amPmLabel === "PM"}
                    @click=${(e) => this._selectAmPm("PM", e)}
                    >PM</lukso-dropdown-option
                  >
                </lukso-dropdown>
              </div>
            ` : lit.nothing}
      </div>
    `;
	}
	render() {
		const { outer, card, timeRow, timeSeparator, ampmWrapper, ampmBtn } = this.styles({
			size: this.size,
			isDisabled: this.isDisabled
		});
		const controls = this._renderTimeRow(timeRow, timeSeparator, ampmWrapper, ampmBtn);
		if (!this.isStandalone) return controls;
		return lit.html`
      <div
        class=${outer()}
        @click=${() => {
			this._showAmPmPicker = false;
		}}
      >
        <lukso-form-label label=${this.label ?? lit.nothing}></lukso-form-label>
        <lukso-form-description
          description=${this.description ?? lit.nothing}
        ></lukso-form-description>
        <div class=${card()}>${controls}</div>
        <lukso-form-error error=${this.error ?? lit.nothing}></lukso-form-error>
      </div>
    `;
	}
};
require_decorate.__decorate([(0, lit_decorators_js.property)({ type: String })], LuksoTimePicker.prototype, "value", void 0);
require_decorate.__decorate([(0, lit_decorators_js.property)({ type: String })], LuksoTimePicker.prototype, "locale", void 0);
require_decorate.__decorate([(0, lit_decorators_js.property)({
	type: String,
	attribute: "time-format"
})], LuksoTimePicker.prototype, "timeFormat", void 0);
require_decorate.__decorate([(0, lit_decorators_js.property)({ type: String })], LuksoTimePicker.prototype, "size", void 0);
require_decorate.__decorate([(0, lit_decorators_js.property)({
	type: Boolean,
	attribute: "is-standalone"
})], LuksoTimePicker.prototype, "isStandalone", void 0);
require_decorate.__decorate([(0, lit_decorators_js.property)({ type: String })], LuksoTimePicker.prototype, "label", void 0);
require_decorate.__decorate([(0, lit_decorators_js.property)({ type: String })], LuksoTimePicker.prototype, "description", void 0);
require_decorate.__decorate([(0, lit_decorators_js.property)({ type: String })], LuksoTimePicker.prototype, "error", void 0);
require_decorate.__decorate([(0, lit_decorators_js.property)({
	type: Boolean,
	attribute: "is-disabled"
})], LuksoTimePicker.prototype, "isDisabled", void 0);
require_decorate.__decorate([(0, lit_decorators_js.state)()], LuksoTimePicker.prototype, "_selectedHour", void 0);
require_decorate.__decorate([(0, lit_decorators_js.state)()], LuksoTimePicker.prototype, "_selectedMinute", void 0);
require_decorate.__decorate([(0, lit_decorators_js.state)()], LuksoTimePicker.prototype, "_showAmPmPicker", void 0);
LuksoTimePicker = require_decorate.__decorate([require_safe_custom_element.safeCustomElement("lukso-time-picker")], LuksoTimePicker);
//#endregion
Object.defineProperty(exports, "LuksoTimePicker", {
	enumerable: true,
	get: function() {
		return LuksoTimePicker;
	}
});
