import { r as registerInstance, h as h$1 } from './index-38ad4957.js';
import './global-96c14d63.js';
import { i as d, n as h } from './dom-context-hooks.module-50442785.js';
import { i as isDemo } from './index.module-b23fdad8.js';
import { c as cjs } from './cjs-bdfb4486.js';
import { g as getProps, a as getMissingProps } from './utils-334c1e34.js';
import './JSS-67b5cff8.js';
import './mixins-f750863a.js';
import { L as LEAD_FORM_STATE_CONTEXT, R as RequiredPropsError } from './useLeadFormState-dd4e8b08.js';
import { L as LeadInputFieldView } from './sqm-lead-input-field-view-d1b91650.js';

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

const LeadInputField = class {
  constructor(hostRef) {
    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;
    h(this);
  }
  disconnectedCallback() { }
  render() {
    const content = {
      ...getProps(this),
    };
    const missingProps = getMissingProps([
      {
        attribute: "field-name",
        value: this.fieldName,
      },
    ]);
    if (!isDemo() && missingProps) {
      return (h$1(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 } = isDemo()
      ? useLeadInputFieldDemo(this)
      : useLeadInputField();
    return (h$1(LeadInputFieldView, { states: states, content: content }));
  }
};
function useLeadInputFieldDemo(props) {
  return cjs({
    states: {
      leadForState: {},
    },
    content: {
      fieldName: props.fieldName,
      fieldLabel: props.fieldLabel,
      fieldType: props.fieldType,
      requiredFieldErrorMessage: props.requiredFieldErrorMessage,
    },
  }, props.demoData || {}, { arrayMerge: (_, a) => a });
}

export { LeadInputField as sqm_lead_input_field };
