'use strict';

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

const index = require('./index-9c866aeb.js');
const watchers = require('./watchers-203d7acd.js');
require('./index-f6f80680.js');
require('./add-query-args-17c551b6.js');

const scCustomerPhoneCss = ":host{display:block}";

const ScCustomerPhone = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.scChange = index.createEvent(this, "scChange", 7);
    this.scClear = index.createEvent(this, "scClear", 7);
    this.scInput = index.createEvent(this, "scInput", 7);
    this.scFocus = index.createEvent(this, "scFocus", 7);
    this.scBlur = index.createEvent(this, "scBlur", 7);
    /** The input's size. */
    this.size = 'medium';
    /** The input's value attribute. */
    this.value = '';
    /** Draws a pill-style input with rounded edges. */
    this.pill = false;
    /** Should we show the label */
    this.showLabel = true;
    /** The input's help text. */
    this.help = '';
    /** Disables the input. */
    this.disabled = false;
    /** Makes the input readonly. */
    this.readonly = false;
    /** Makes the input a required field. */
    this.required = false;
    /**
     * This will be true when the control is in an invalid state. Validity is determined by props such as `type`,
     * `required`, `minlength`, `maxlength`, and `pattern` using the browser's constraint validation API.
     */
    this.invalid = false;
  }
  async handleChange() {
    this.value = this.input.value;
    this.scChange.emit();
  }
  async reportValidity() {
    var _a, _b;
    return (_b = (_a = this.input) === null || _a === void 0 ? void 0 : _a.reportValidity) === null || _b === void 0 ? void 0 : _b.call(_a);
  }
  componentWillLoad() {
    this.handleCheckoutChange();
    this.removeChangeListener = watchers.onChange('checkout', () => this.handleCheckoutChange());
  }
  disconnectedCallback() {
    this.removeChangeListener();
  }
  handleCheckoutChange() {
    var _a, _b, _c, _d, _e, _f;
    // we only want to do this  if we don't have a value.
    if (this === null || this === void 0 ? void 0 : this.value)
      return;
    // if the checkout has a phone, use that.
    if ((_a = watchers.state.checkout) === null || _a === void 0 ? void 0 : _a.phone) {
      this.value = (_b = watchers.state.checkout) === null || _b === void 0 ? void 0 : _b.phone;
      return;
    }
    // if the customer has a phone, use that.
    if ((_d = (_c = watchers.state.checkout) === null || _c === void 0 ? void 0 : _c.customer) === null || _d === void 0 ? void 0 : _d.phone) {
      this.value = (_f = (_e = watchers.state.checkout) === null || _e === void 0 ? void 0 : _e.customer) === null || _f === void 0 ? void 0 : _f.phone;
      return;
    }
  }
  render() {
    return (index.h("sc-phone-input", { name: "phone", ref: el => (this.input = el), value: this.value, label: this.label, help: this.help, autocomplete: "phone", placeholder: this.placeholder, readonly: this.readonly, required: this.required, invalid: this.invalid, autofocus: this.autofocus, hasFocus: this.hasFocus, onScChange: () => this.handleChange(), onScInput: () => this.scInput.emit(), onScFocus: () => this.scFocus.emit(), onScBlur: () => this.scBlur.emit() }));
  }
};
ScCustomerPhone.style = scCustomerPhoneCss;

exports.sc_customer_phone = ScCustomerPhone;
