'use strict';

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

const index = require('./index-8277cbb3.js');
require('./global-b7b1b8fe.js');
const domContextHooks_module = require('./dom-context-hooks.module-e7b6727c.js');
const index_module = require('./index.module-f8c8495f.js');
const cjs = require('./cjs-1066ec21.js');
const utils = require('./utils-6847bc06.js');
require('./JSS-8503a151.js');
require('./mixins-4761d472.js');
const useLeadFormState = require('./useLeadFormState-b4c2ab5b.js');
const sqmLeadInputFieldView = require('./sqm-lead-input-field-view-0cd7ebdb.js');

function useLeadInputField() {
  const leadFormState = domContextHooks_module.d(useLeadFormState.LEAD_FORM_STATE_CONTEXT);
  return {
    states: {
      leadFormState,
    },
  };
}

const LeadInputField = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.ignored = true;
    /**
     * @uiName Optional label
     */
    this.optionalLabel = "(optional)";
    /**
     * @uiName Input type
     * @uiType string
     * @uiEnum ["text", "date", "tel"]
     * @uiEnumNames ["Text", "Date", "Phone Number"]
     */
    this.fieldType = "text";
    /**
     * The message to be displayed when a required field is not filled.
     *
     * @uiName Required field message
     * @uiWidget textArea
     */
    this.requiredFieldErrorMessage = "Please enter a {fieldLabel}";
    /**
     * @uiName Optional
     * @default
     */
    this.fieldOptional = false;
    domContextHooks_module.h$1(this);
  }
  disconnectedCallback() { }
  render() {
    const content = {
      ...utils.getProps(this),
    };
    const missingProps = utils.getMissingProps([
      {
        attribute: "field-name",
        value: this.fieldName,
      },
    ]);
    if (!index_module.isDemo() && missingProps) {
      return (index.h(useLeadFormState.RequiredPropsError, { missingProps: missingProps, heading: "An error occured while loading this form", subheading: "A technical problem prevented this input field from loading. Please contact us with the link to this page.", description: "Values for the following attributes are missing:" }));
    }
    const { states } = index_module.isDemo()
      ? useLeadInputFieldDemo(this)
      : useLeadInputField();
    return (index.h(sqmLeadInputFieldView.LeadInputFieldView, { states: states, content: content }));
  }
};
function useLeadInputFieldDemo(props) {
  return cjs.cjs({
    states: {
      leadForState: {},
    },
    content: {
      fieldName: props.fieldName,
      fieldLabel: props.fieldLabel,
      fieldType: props.fieldType,
      requiredFieldErrorMessage: props.requiredFieldErrorMessage,
    },
  }, props.demoData || {}, { arrayMerge: (_, a) => a });
}

exports.sqm_lead_input_field = LeadInputField;
