"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__, {
    AtomicCommerceFacetNumberInput: ()=>AtomicCommerceFacetNumberInput
});
const bueno_namespaceObject = require("@coveo/bueno");
const external_lit_namespaceObject = require("lit");
const decorators_js_namespaceObject = require("lit/decorators.js");
const ref_js_namespaceObject = require("lit/directives/ref.js");
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 AtomicCommerceFacetNumberInput extends (0, light_dom_cjs_namespaceObject.LightDomMixin)(external_lit_namespaceObject.LitElement) {
    initialize() {
        this.start = this.range?.start;
        this.end = this.range?.end;
    }
    apply() {
        if (!this.startRef?.validity.valid || !this.endRef?.validity.valid) return;
        this.dispatchEvent((0, event_utils_cjs_namespaceObject.buildCustomEvent)('atomic-number-input-apply', {
            start: this.start,
            end: this.end
        }));
    }
    get absoluteMinimum() {
        const { field } = this.facet.state;
        const isPriceField = [
            'ec_price',
            'ec_promo_price'
        ].includes(field);
        return isPriceField ? 0 : Number.MIN_SAFE_INTEGER;
    }
    get minimumInputValue() {
        return (0, bueno_namespaceObject.isUndefined)(this.start) ? this.absoluteMinimum : this.start;
    }
    get maximumInputValue() {
        return (0, bueno_namespaceObject.isUndefined)(this.end) ? Number.MAX_SAFE_INTEGER : this.end;
    }
    get startValue() {
        return this.range?.start !== void 0 ? String(this.range.start) : '';
    }
    get endValue() {
        return this.range?.end !== void 0 ? String(this.range.end) : '';
    }
    render() {
        const { facetId } = this.facet.state;
        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 = '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="${facetId}_start">
          ${minText}
        </label>
        <input
          part="input-start"
          id="${facetId}_start"
          type="number"
          step=${step}
          .value=${this.startValue}
          class=${inputClasses}
          aria-label=${minAria}
          required
          min=${this.absoluteMinimum}
          max=${this.maximumInputValue}
          @input=${(e)=>{
            this.start = e.target.valueAsNumber;
        }}
          ${(0, ref_js_namespaceObject.ref)((ref)=>{
            this.startRef = ref;
        })}
        />
        <label part="label-end" class=${labelClasses} for="${facetId}_end">
          ${maxText}
        </label>
        <input
          part="input-end"
          id="${facetId}_end"
          type="number"
          step=${step}
          .value=${this.endValue}
          class=${inputClasses}
          aria-label=${maxAria}
          required
          min=${this.minimumInputValue}
          max=${Number.MAX_SAFE_INTEGER}
          @input=${(e)=>{
            this.end = e.target.valueAsNumber;
        }}
          ${(0, ref_js_namespaceObject.ref)((ref)=>{
            this.endRef = ref;
        })}
        />
        <button
          style="outline-primary"
          type="submit"
          part="input-apply-button"
          class="flex-none truncate p-2.5"
          aria-label=${applyAria}
        >
          ${apply}
        </button>
      </form>
    `;
    }
}
AtomicCommerceFacetNumberInput.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.state)(),
    _ts_metadata("design:type", "u" < typeof CommerceBindings ? Object : CommerceBindings)
], AtomicCommerceFacetNumberInput.prototype, "bindings", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicCommerceFacetNumberInput.prototype, "error", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: String
    }),
    _ts_metadata("design:type", String)
], AtomicCommerceFacetNumberInput.prototype, "label", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Object
    }),
    _ts_metadata("design:type", "u" < typeof Range ? Object : Range)
], AtomicCommerceFacetNumberInput.prototype, "range", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Object
    }),
    _ts_metadata("design:type", "u" < typeof NumericFacet ? Object : NumericFacet)
], AtomicCommerceFacetNumberInput.prototype, "facet", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", Number)
], AtomicCommerceFacetNumberInput.prototype, "start", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", Number)
], AtomicCommerceFacetNumberInput.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)
], AtomicCommerceFacetNumberInput.prototype, "render", null);
AtomicCommerceFacetNumberInput = _ts_decorate([
    (0, decorators_js_namespaceObject.customElement)('atomic-commerce-facet-number-input'),
    (0, bindings_cjs_namespaceObject.bindings)()
], AtomicCommerceFacetNumberInput);
exports.AtomicCommerceFacetNumberInput = __webpack_exports__.AtomicCommerceFacetNumberInput;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AtomicCommerceFacetNumberInput"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
