'use strict';

var index = require('./index-p7cvUYAE.js');
var parts = require('./parts-BXshb_S-.js');
var formControlHelpText = require('./form-control-help-text-BdbTxD5g.js');
var formControlErrorText = require('./form-control-error-text-BO58Y6zF.js');
require('./event-types-YOY5TKUN.js');
var formInputMasks = require('./form-input-masks-BnNFJ3IJ.js');
var inputHandlers = require('./input-handlers-_51J5q7J.js');
var Business = require('./Business-oBifyXkW.js');
var countryConfig = require('./country-config-C1bWmF8P.js');
var businessFormOptions = require('./business-form-options-CnlrfbQ6.js');

const FormControlNumber = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.formControlInput = index.createEvent(this, "formControlInput", 7);
        this.formControlBlur = index.createEvent(this, "formControlBlur", 7);
        this.isFocused = false;
        this.disabled = false;
        this.handleFormControlInput = (event) => {
            const target = event.target;
            const name = target.getAttribute('name');
            this.inputHandler(name, target.value);
            this.formControlInput.emit({ name, value: target.value });
        };
        this.updateInput = (newValue) => {
            const inputElement = this.el.querySelector('input');
            if (inputElement) {
                inputElement.value = newValue || '';
            }
        };
    }
    handleDefaultValueChange(newValue) {
        this.updateInput(newValue);
    }
    componentDidLoad() {
        this.updateInput(this.defaultValue);
    }
    get part() {
        if (this.isFocused && this.errorText) {
            return parts.inputInvalidAndFocused;
        }
        if (this.isFocused) {
            return parts.inputFocused;
        }
        if (this.errorText) {
            return parts.inputInvalid;
        }
        return parts.input;
    }
    render() {
        return (index.h(index.Host, { key: 'a47de1fbb4fbd97b47c4dc934d58a628c65f1dbf' }, index.h("div", { key: 'bbd063c3f0c68bdad5f1849fed8ac318ebb423ef', class: 'form-group d-flex flex-column' }, index.h("label", { key: '796cb0253dc523ceb21464f3ce528509abffecfa', part: parts.label, class: "form-label", htmlFor: this.name }, this.label), index.h("input", { key: '8ceaf162d7db2c639b679a431dea7b962593eb09', id: this.name, name: this.name, onFocus: () => this.isFocused = true, onBlur: () => {
                this.isFocused = false;
                this.formControlBlur.emit();
            }, onInput: this.handleFormControlInput, part: this.part, class: this.errorText ? 'form-control is-invalid' : 'form-control', type: "number", disabled: this.disabled }), index.h(formControlHelpText.FormControlHelpText, { key: '6935e075c057a55f0af02051eb97310b187ae807', helpText: this.helpText, name: this.name }), index.h(formControlErrorText.FormControlErrorText, { key: '019b48db586768219622e657e121772e4f0203c5', errorText: this.errorText, name: this.name }))));
    }
    get el() { return index.getElement(this); }
    static get watchers() { return {
        "defaultValue": ["handleDefaultValueChange"]
    }; }
};

const OwnerFormInputs = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.isEditingIdentification = false;
        this.inputHandler = (name, value) => {
            inputHandlers.updateFormValues(this.formController, { [name]: value });
        };
        this.onAddressFormUpdate = (values) => {
            inputHandlers.updateAddressFormValues(this.formController, Object.assign(Object.assign({}, this.formController.values.getValue().address), values));
        };
    }
    render() {
        var _a, _b, _c;
        return (index.h("div", { key: '6f4bb241699db7c16cb99016363cbbc1a4484a4a', class: "row gy-3" }, index.h("div", { key: 'fc0317736a62ac34f98f2b7a43a5073d785dfa0d', class: "col-12 col-md-8" }, index.h("form-control-text", { key: '8123035dfd371841e0830d0019c425d25977c160', name: "name", label: "Full Name", defaultValue: this.ownerDefaultValue.name, errorText: this.errors.name, inputHandler: this.inputHandler })), index.h("div", { key: 'a16e9ecc81fd4965d3a42b2569a7ea0615ecbf97', class: "col-12 col-md-4" }, index.h("form-control-select", { key: 'bd9b0ee5c7cf45ac3d67da96f951f167c93033e0', name: "title", label: "Title", options: businessFormOptions.businessTitleOptions, defaultValue: this.ownerDefaultValue.title, errorText: this.errors.title, inputHandler: this.inputHandler })), index.h("div", { key: '5376a38a98ad715a3159ccf4e8c8e54b48fa1c7c', class: "col-12 col-md-6" }, index.h("form-control-text", { key: '7d08e58ae5fc15d5299c8646d5260602a51b9fbf', name: "email", label: "Email Address", defaultValue: this.ownerDefaultValue.email, errorText: this.errors.email, inputHandler: this.inputHandler })), index.h("div", { key: '6f80f898cb354b40d8d6784110abd5a1c49ff9d9', class: "col-12 col-md-6" }, index.h("form-control-number-masked", { key: '8a7d577c4c1c5b54f733ee51a1970c17de27d0b0', name: "phone", label: "Phone Number", defaultValue: this.ownerDefaultValue.phone, errorText: this.errors.phone, inputHandler: this.inputHandler, mask: formInputMasks.PHONE_MASKS.US })), index.h("div", { key: '5ace697b3fb38b52dca74ccd49207498b779ade8', class: "col-12 col-md-3" }, index.h("form-control-date", { key: 'ec8d614b62fe2913c52fd228e7df1fef1b1d7d83', name: "dob_full", label: "Birth Date", defaultValue: this.ownerDefaultValue.dob_full, errorText: this.errors.dob_full, inputHandler: this.inputHandler, onFormControlInput: (e) => inputHandlers.updateDateOfBirthFormValues(e, this.formController), helpText: "Must be 18 or older." })), index.h("div", { key: '8fad1824571295e3464d26191eb23d373591e47d', class: "col-12 col-md-3" }, index.h("form-control-number", { key: 'c0ffdbf26ea5d65de8c3e98c2cd7d03430d4a8c2', name: "ownership_percentage", label: "% of Ownership", defaultValue: (_a = this.ownerDefaultValue) === null || _a === void 0 ? void 0 : _a.ownership_percentage, errorText: this.errors.ownership_percentage, inputHandler: this.inputHandler })), index.h("div", { key: '94d93a03f2513bb69da43bd68c3fddc62dbc18d6', class: "col-12 col-md-6" }, (!((_b = this.ownerDefaultValue) === null || _b === void 0 ? void 0 : _b.ssn_last4) || this.isEditingIdentification) ? (index.h("form-control-number-masked", { name: "identification_number", label: this.country === Business.CountryCode.CAN ? countryConfig.countryLabels[this.country].idNumberLabelOptional : countryConfig.countryLabels[this.country].idNumberLabel, defaultValue: this.isEditingIdentification ? '' : this.ownerDefaultValue.identification_number, errorText: this.errors.identification_number, inputHandler: this.inputHandler, mask: formInputMasks.IDENTITY_MASKS[this.country], helpText: countryConfig.countryLabels[this.country].identityHelpText })) : (index.h("div", null, index.h("label", { class: "form-label", part: parts.label }, this.country === Business.CountryCode.CAN ? countryConfig.countryLabels[this.country].idNumberLabelOptional : countryConfig.countryLabels[this.country].idNumberLabel), index.h("div", { class: "input-group mb-3" }, index.h("input", { type: "text", class: "form-control", part: parts.inputDisabled, value: `****${(_c = this.ownerDefaultValue) === null || _c === void 0 ? void 0 : _c.ssn_last4}`, disabled: true }), index.h("button", { class: "btn btn-secondary", type: "button", part: parts.buttonSecondary, onClick: () => {
                this.isEditingIdentification = true;
                // Clear last4 and current value to force validation
                inputHandlers.updateFormValues(this.formController, {
                    ssn_last4: null,
                    identification_number: ''
                });
            } }, "Change"))))), index.h("div", { key: '63d73015c84a1ab370b6686a643797b92096212f', class: "col-12" }, index.h("identity-address-form", { key: '4eff1f856b32e6d31cc18315b5b338c932723cf9', errors: this.errors.address, defaultValues: this.ownerDefaultValue.address, handleFormUpdate: this.onAddressFormUpdate, country: this.country }))));
    }
    ;
};

exports.form_control_number = FormControlNumber;
exports.owner_form_inputs = OwnerFormInputs;
