'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-9c866aeb.js');
const consumer = require('./consumer-3f5ce850.js');
const index$1 = require('./index-cf22257b.js');

const scPriceChoicesCss = "sc-price-choices{display:block;position:relative}sc-block-ui{z-index:9}";

const ScPriceChoices = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.scRemoveLineItem = index.createEvent(this, "scRemoveLineItem", 7);
    this.scUpdateLineItem = index.createEvent(this, "scUpdateLineItem", 7);
    /** Number of columns */
    this.columns = 1;
    /** Required by default */
    this.required = true;
  }
  handleChange() {
    this.el.querySelectorAll('sc-price-choice').forEach(priceChoice => {
      var _a;
      const choice = priceChoice.querySelector('sc-choice') || priceChoice.querySelector('sc-choice-container');
      if (!(choice === null || choice === void 0 ? void 0 : choice.checked)) {
        this.scRemoveLineItem.emit({ price_id: priceChoice.priceId, quantity: priceChoice.quantity });
      }
      else {
        const lineItem = index$1.getLineItemByPriceId((_a = this.order) === null || _a === void 0 ? void 0 : _a.line_items, choice.value);
        this.scUpdateLineItem.emit({ price_id: priceChoice.priceId, quantity: (lineItem === null || lineItem === void 0 ? void 0 : lineItem.quantity) || (priceChoice === null || priceChoice === void 0 ? void 0 : priceChoice.quantity) || 1 });
      }
    });
  }
  render() {
    return (index.h(index.Fragment, null, index.h("sc-choices", { label: this.label, required: this.required, class: "loaded price-selector", style: { '--columns': this.columns.toString() } }, index.h("slot", null))));
  }
  get el() { return index.getElement(this); }
};
consumer.openWormhole(ScPriceChoices, ['order'], false);
ScPriceChoices.style = scPriceChoicesCss;

exports.sc_price_choices = ScPriceChoices;
