"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.d = (exports1, definition)=>{
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
    __webpack_require__.r = (exports1)=>{
        if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    AtomicFacetNumberInput: ()=>AtomicFacetNumberInput
});
const external_lit_namespaceObject = require("lit");
const decorators_js_namespaceObject = require("lit/decorators.js");
const ref_js_namespaceObject = require("lit/directives/ref.js");
const external_button_cjs_namespaceObject = require("../button.cjs");
const binding_guard_cjs_namespaceObject = require("../../../decorators/binding-guard.cjs");
const bindings_cjs_namespaceObject = require("../../../decorators/bindings.cjs");
const error_guard_cjs_namespaceObject = require("../../../decorators/error-guard.cjs");
const light_dom_cjs_namespaceObject = require("../../../mixins/light-dom.cjs");
const event_utils_cjs_namespaceObject = require("../../../utils/event-utils.cjs");
function _ts_decorate(decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
    else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function _ts_metadata(k, v) {
    if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
}
class AtomicFacetNumberInput extends (0, light_dom_cjs_namespaceObject.LightDomMixin)(external_lit_namespaceObject.LitElement) {
    initialize() {
        this.start = this.filterState?.range?.start;
        this.end = this.filterState?.range?.end;
    }
    render() {
        const label = this.bindings.i18n.t(this.label);
        const minText = this.bindings.i18n.t('min');
        const maxText = this.bindings.i18n.t('max');
        const minAria = this.bindings.i18n.t('number-input-minimum', {
            label
        });
        const maxAria = this.bindings.i18n.t('number-input-maximum', {
            label
        });
        const apply = this.bindings.i18n.t('apply');
        const applyAria = this.bindings.i18n.t('number-input-apply', {
            label
        });
        const inputClasses = 'p-2.5 input-primary placeholder-neutral-dark min-w-0 mr-1';
        const labelClasses = 'text-neutral-dark text-sm';
        const step = 'integer' === this.type ? '1' : 'any';
        return (0, external_lit_namespaceObject.html)`
      <form
        class="mt-4 gap-y-0.5 px-2"
        part="input-form"
        @submit=${(e)=>{
            e.preventDefault();
            this.apply();
            return false;
        }}
      >
        <label
          part="label-start"
          class=${labelClasses}
          for="${this.filterState.facetId}_start"
        >
          ${minText}
        </label>
        <input
          part="input-start"
          id="${this.filterState.facetId}_start"
          type="number"
          step=${step}
          .value=${this.startValue}
          class=${inputClasses}
          aria-label=${minAria}
          required
          min=${Number.MIN_SAFE_INTEGER}
          max=${this.end ?? Number.MAX_SAFE_INTEGER}
          @input=${(e)=>{
            this.start = e.target.valueAsNumber;
        }}
          ${(0, ref_js_namespaceObject.ref)(this.startRef)}
        />
        <label
          part="label-end"
          class=${labelClasses}
          for="${this.filterState.facetId}_end"
        >
          ${maxText}
        </label>
        <input
          part="input-end"
          id="${this.filterState.facetId}_end"
          type="number"
          step=${step}
          .value=${this.endValue}
          class=${inputClasses}
          aria-label=${maxAria}
          required
          min=${this.start ?? Number.MIN_SAFE_INTEGER}
          max=${Number.MAX_SAFE_INTEGER}
          @input=${(e)=>{
            this.end = e.target.valueAsNumber;
        }}
          ${(0, ref_js_namespaceObject.ref)(this.endRef)}
        />
        ${(0, external_button_cjs_namespaceObject.renderButton)({
            props: {
                style: 'outline-primary',
                type: 'submit',
                part: 'input-apply-button',
                class: 'flex-none truncate p-2.5',
                ariaLabel: applyAria,
                text: apply
            }
        })((0, external_lit_namespaceObject.html)``)}
      </form>
    `;
    }
    apply() {
        if (!this.startRef.value?.validity.valid || !this.endRef.value?.validity.valid) return;
        this.dispatchEvent((0, event_utils_cjs_namespaceObject.buildCustomEvent)('atomic/numberInputApply'));
        this.filter.setRange({
            start: this.start,
            end: this.end
        });
    }
    get startValue() {
        return this.filterState.range?.start !== void 0 ? String(this.filterState.range.start) : '';
    }
    get endValue() {
        return this.filterState.range?.end !== void 0 ? String(this.filterState.range.end) : '';
    }
    constructor(...args){
        super(...args), this.startRef = (0, ref_js_namespaceObject.createRef)(), this.endRef = (0, ref_js_namespaceObject.createRef)();
    }
}
AtomicFacetNumberInput.styles = (0, external_lit_namespaceObject.css)`
    [part='input-form'] {
      display: grid;
      grid-template-areas:
        'label-start label-end .'
        'input-start input-end apply-button';
      grid-template-columns: 1fr 1fr auto;
    }

    [part='label-start'] {
      grid-area: label-start;
    }
    [part='label-end'] {
      grid-area: label-end;
    }
    [part='input-start'] {
      grid-area: input-start;
    }
    [part='input-end'] {
      grid-area: input-end;
    }

    [part='input-apply-button'] {
      grid-area: apply-button;
    }
  `;
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: String
    }),
    _ts_metadata("design:type", "u" < typeof NumberInputType ? Object : NumberInputType)
], AtomicFacetNumberInput.prototype, "type", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: String
    }),
    _ts_metadata("design:type", String)
], AtomicFacetNumberInput.prototype, "label", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Object
    }),
    _ts_metadata("design:type", "u" < typeof NumericFilter ? Object : NumericFilter)
], AtomicFacetNumberInput.prototype, "filter", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Object,
        attribute: 'filter-state'
    }),
    _ts_metadata("design:type", "u" < typeof NumericFilterState ? Object : NumericFilterState)
], AtomicFacetNumberInput.prototype, "filterState", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof AnyBindings ? Object : AnyBindings)
], AtomicFacetNumberInput.prototype, "bindings", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicFacetNumberInput.prototype, "error", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", Number)
], AtomicFacetNumberInput.prototype, "start", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", Number)
], AtomicFacetNumberInput.prototype, "end", void 0);
_ts_decorate([
    (0, binding_guard_cjs_namespaceObject.bindingGuard)(),
    (0, error_guard_cjs_namespaceObject.errorGuard)(),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", []),
    _ts_metadata("design:returntype", void 0)
], AtomicFacetNumberInput.prototype, "render", null);
AtomicFacetNumberInput = _ts_decorate([
    (0, decorators_js_namespaceObject.customElement)('atomic-facet-number-input'),
    (0, bindings_cjs_namespaceObject.bindings)()
], AtomicFacetNumberInput);
exports.AtomicFacetNumberInput = __webpack_exports__.AtomicFacetNumberInput;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AtomicFacetNumberInput"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
