import { isDemo } from "@saasquatch/component-boilerplate";
import { withHooks } from "@saasquatch/stencil-hooks";
import { Component, h, Prop, State } from "@stencil/core";
import deepmerge from "deepmerge";
import { RequiredPropsError } from "../../utils/RequiredPropsError";
import { getMissingProps, getProps } from "../../utils/utils";
import { LeadCheckboxFieldView, } from "./sqm-lead-checkbox-field-view";
import { useLeadCheckboxField } from "./useCheckboxField";
/**
 * @uiName Lead Form Checkbox Field
 * @validParents ["sqm-lead-form"]
 */
export class LeadCheckboxField {
  constructor() {
    this.ignored = true;
    /**
     * @uiName Checkbox label
     * @uiWidget textArea
     */
    this.checkboxLabel = "By signing up you agree to the {labelLink}";
    /**
     * Used with link text if the checkbox label contains {labelLink}
     *
     * @uiName Checkbox label link
     */
    this.checkboxLabelLink = "https://example.com";
    /**
     * @uiName Checkbox label link lext
     */
    this.checkboxLabelLinkText = "Terms and Conditions";
    /**
     * @uiName Unchecked error message
     */
    this.errorMessage = "Must be checked";
    /**
     * @uiName Optional
     */
    this.checkboxOptional = false;
    withHooks(this);
  }
  disconnectedCallback() { }
  render() {
    const missingProps = getMissingProps([
      {
        attribute: "checkbox-name",
        value: this.checkboxName,
      },
    ]);
    if (!isDemo() && missingProps) {
      return (h(RequiredPropsError, { missingProps: missingProps, heading: "An error occured while loading this form", subheading: "A technical problem prevented this checkbox field from loading. Please contact us with the link to this page.", description: "Values for the following attributes are missing:" }));
    }
    const content = {
      ...getProps(this),
    };
    const { states } = isDemo()
      ? useLeadCheckboxFieldDemo(this)
      : useLeadCheckboxField();
    return (h(LeadCheckboxFieldView, { states: states, content: content }));
  }
  static get is() { return "sqm-lead-checkbox-field"; }
  static get properties() { return {
    "checkboxName": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": "Checkbox name attribute",
            "name": "uiName"
          }, {
            "text": undefined,
            "name": "required"
          }],
        "text": "This name is used as the key for this form field on submission. The name must be unique within this specific form."
      },
      "attribute": "checkbox-name",
      "reflect": false
    },
    "checkboxLabel": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "text": "Checkbox label",
            "name": "uiName"
          }, {
            "text": "textArea",
            "name": "uiWidget"
          }],
        "text": ""
      },
      "attribute": "checkbox-label",
      "reflect": false,
      "defaultValue": "\"By signing up you agree to the {labelLink}\""
    },
    "checkboxLabelLink": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [{
            "text": "Checkbox label link",
            "name": "uiName"
          }],
        "text": "Used with link text if the checkbox label contains {labelLink}"
      },
      "attribute": "checkbox-label-link",
      "reflect": false,
      "defaultValue": "\"https://example.com\""
    },
    "checkboxLabelLinkText": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [{
            "text": "Checkbox label link lext",
            "name": "uiName"
          }],
        "text": ""
      },
      "attribute": "checkbox-label-link-text",
      "reflect": false,
      "defaultValue": "\"Terms and Conditions\""
    },
    "errorMessage": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [{
            "text": "Unchecked error message",
            "name": "uiName"
          }],
        "text": ""
      },
      "attribute": "error-message",
      "reflect": false,
      "defaultValue": "\"Must be checked\""
    },
    "checkboxOptional": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [{
            "text": "Optional",
            "name": "uiName"
          }],
        "text": ""
      },
      "attribute": "checkbox-optional",
      "reflect": false,
      "defaultValue": "false"
    },
    "demoData": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "DemoData<LeadCheckboxFieldViewProps>",
        "resolved": "{ states?: { leadFormState?: LeadFormState; }; content?: { checkboxName: string; checkboxLabel: string; checkboxLabelLink?: string; checkboxLabelLinkText?: string; checkboxOptional?: boolean; errorMessage?: string; }; }",
        "references": {
          "DemoData": {
            "location": "import",
            "path": "../../global/demo"
          },
          "LeadCheckboxFieldViewProps": {
            "location": "import",
            "path": "./sqm-lead-checkbox-field-view"
          }
        }
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [{
            "text": undefined,
            "name": "undocumented"
          }, {
            "text": "object",
            "name": "uiType"
          }],
        "text": ""
      }
    }
  }; }
  static get states() { return {
    "ignored": {}
  }; }
}
function useLeadCheckboxFieldDemo(props) {
  return deepmerge({
    states: {
      leadFormState: {},
    },
  }, props.demoData || {}, { arrayMerge: (_, a) => a });
}
