/*!
 * Built by ShiftSoftware
 * Copyright (c)
 */
import { Host, h } from "@stencil/core";
import { functionHooks } from "../../features/form-hook/index";
import { sharedFormLocalesSchema } from "../../features/multi-lingual/index";
import getLanguageFromUrl from "../../global/lib/get-language-from-url";
import cn from "../../global/lib/cn";
import { LoaderIcon } from "../../global/assets/loader-icon";
import { getFormValidations } from "./defaults/validation";
import { getFormMappers } from "./defaults/mappers";
const validation = getFormValidations();
const elementMapper = getFormMappers();
export class TestDriveForm {
    constructor() {
        this.locale = { sharedFormLocales: sharedFormLocalesSchema.getDefault() };
        this.isLoading = false;
        this.structureRendered = false;
        this.isDev = false;
        this.isMobileForm = false;
    }
    async changeLanguage(newLanguage) {
        await functionHooks.formLanguageChange(this, newLanguage);
    }
    setIsLoading(isLoading) {
        functionHooks.formLoadingHandler(this, isLoading);
    }
    setErrorCallback(error) {
        functionHooks.formErrorHandler(this, error);
    }
    setSuccessCallback(data) {
        functionHooks.formSuccessHandler(this, data);
    }
    async componentWillLoad() {
        if (!this.language)
            this.language = getLanguageFromUrl();
    }
    async formSubmit(formValues) {
        await functionHooks.onFormSubmit({ context: this, formValues });
    }
    // #endregion
    // #region Component Logic
    async componentDidLoad() {
        await functionHooks.formDidLoadHandler(this, validation);
    }
    async getForm() {
        return await functionHooks.formGetFormHandler(this);
    }
    async submit() {
        await functionHooks.handleFormSubmit(this);
    }
    async structureChanged(isRendered) {
        await functionHooks.formStructureRenderedHandler(this, isRendered);
    }
    // #endregion
    render() {
        var _a, _b;
        return (h(Host, { key: '9d8227808af37e4965405d70ac605774ec66fcf3', translate: "no" }, h("div", { key: '1c31f3cfd7ad7b0d4b48685cd93542344a62ef61', part: cn('shift-form', (_b = (_a = this.structure) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.theme, this.theme) }, h("div", { key: '8147d9cf0187fbf600c0249da4089121a345a49f', part: "form-container", class: "relative min-h-[150px]" }, h("div", { key: '6c7d9ab23d1529696b0a7f913d83464c4576ac97', part: "form-loader-container", class: cn('form-loader-container absolute top-0 left-0 w-full h-full pointer-events-none flex justify-center items-center transition-opacity duration-500', {
                'opacity-0': this.structureRendered,
            }) }, h(LoaderIcon, { key: '2e293679ef8f7102c52018dca6bc6d59baf02340', part: "form-loader-icon", class: "img" })), h("flexible-container", { key: '13088d5264491c636f0bac5d25a99f36fbf66709', onlyForMounting: true, isOpened: this.structureRendered }, !!this.form && (h("form-structure", { key: '0e9b794aeb7efa933b3d57950ab640d1c5a9268b', form: this.form, fields: this.fields, formId: this.formId, formLocale: this.locale, structure: this.structure, isLoading: this.isLoading, language: this.localeLanguage, errorMessage: this.errorMessage, formElementMapper: elementMapper, successMessage: this.locale['Form submitted successfully.'] || 'Form submitted successfully.' }, h("slot", { key: '5a4d6bf7a3225e42e75a00eead76add8f4be7eaa' }))))))));
    }
    static get is() { return "test-drive-form"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["./defaults/style.css"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["defaults/style.css"]
        };
    }
    static get properties() {
        return {
            "language": {
                "type": "string",
                "attribute": "language",
                "mutable": true,
                "complexType": {
                    "original": "LanguageKeys",
                    "resolved": "\"ar\" | \"en\" | \"ku\" | \"ru\"",
                    "references": {
                        "LanguageKeys": {
                            "location": "import",
                            "path": "~features/multi-lingual",
                            "id": "src/features/multi-lingual/index.ts::LanguageKeys"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": true
            },
            "gistId": {
                "type": "string",
                "attribute": "gist-id",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false
            },
            "extraHeader": {
                "type": "unknown",
                "attribute": "extra-header",
                "mutable": false,
                "complexType": {
                    "original": "object",
                    "resolved": "object",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false
            },
            "extraPayload": {
                "type": "unknown",
                "attribute": "extra-payload",
                "mutable": false,
                "complexType": {
                    "original": "object",
                    "resolved": "object",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false
            },
            "structureUrl": {
                "type": "string",
                "attribute": "structure-url",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false
            },
            "loadingChanges": {
                "type": "unknown",
                "attribute": "loading-changes",
                "mutable": false,
                "complexType": {
                    "original": "(loading: boolean) => void",
                    "resolved": "(loading: boolean) => void",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false
            },
            "errorCallback": {
                "type": "unknown",
                "attribute": "error-callback",
                "mutable": false,
                "complexType": {
                    "original": "(error: any, message: string) => Promise<void | boolean>",
                    "resolved": "(error: any, message: string) => Promise<boolean | void>",
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false
            },
            "successCallback": {
                "type": "unknown",
                "attribute": "success-callback",
                "mutable": false,
                "complexType": {
                    "original": "(data: any, message?: string) => Promise<void | boolean>",
                    "resolved": "(data: any, message?: string) => Promise<boolean | void>",
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false
            },
            "stepChangeCallback": {
                "type": "unknown",
                "attribute": "step-change-callback",
                "mutable": false,
                "complexType": {
                    "original": "(step: number, currentForm?: any) => void",
                    "resolved": "(step: number, currentForm?: any) => void",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false
            },
            "structure": {
                "type": "unknown",
                "attribute": "structure",
                "mutable": true,
                "complexType": {
                    "original": "FormElementStructure<any> | undefined",
                    "resolved": "{ steps?: Record<LanguageKeys, Step>[]; data?: Record<string, any>; requiredContext?: Record<string, boolean>; } & { id?: string; step?: number; type?: string; class?: string; staticValue?: any; isHidden?: boolean; isDisabled?: boolean; children?: any[]; } & { tag: string; name?: any; } | { steps?: Record<LanguageKeys, Step>[]; data?: Record<string, any>; requiredContext?: Record<string, boolean>; } & { id?: string; step?: number; type?: string; class?: string; staticValue?: any; isHidden?: boolean; isDisabled?: boolean; children?: any[]; } & { tag?: string; name: any; }",
                    "references": {
                        "FormElementStructure": {
                            "location": "import",
                            "path": "~features/form-hook",
                            "id": "src/features/form-hook/index.ts::FormElementStructure"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false
            },
            "fields": {
                "type": "unknown",
                "attribute": "fields",
                "mutable": true,
                "complexType": {
                    "original": "object",
                    "resolved": "object",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false
            },
            "formReadyCallback": {
                "type": "unknown",
                "attribute": "form-ready-callback",
                "mutable": false,
                "complexType": {
                    "original": "() => void",
                    "resolved": "() => void",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false
            },
            "theme": {
                "type": "string",
                "attribute": "theme",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false
            },
            "formId": {
                "type": "string",
                "attribute": "form-id",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false
            },
            "isDev": {
                "type": "boolean",
                "attribute": "is-dev",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "false"
            },
            "disableScrollToTop": {
                "type": "boolean",
                "attribute": "disable-scroll-to-top",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false
            },
            "isMobileForm": {
                "type": "boolean",
                "attribute": "is-mobile-form",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "false"
            },
            "getMobileToken": {
                "type": "unknown",
                "attribute": "get-mobile-token",
                "mutable": false,
                "complexType": {
                    "original": "() => string",
                    "resolved": "() => string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false
            }
        };
    }
    static get states() {
        return {
            "locale": {},
            "errorMessage": {},
            "isLoading": {},
            "localeLanguage": {},
            "structureRendered": {},
            "form": {}
        };
    }
    static get methods() {
        return {
            "getForm": {
                "complexType": {
                    "signature": "() => Promise<FormHook<any>>",
                    "parameters": [],
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        },
                        "FormHook": {
                            "location": "import",
                            "path": "~features/form-hook",
                            "id": "src/features/form-hook/index.ts::FormHook"
                        }
                    },
                    "return": "Promise<FormHook<any>>"
                },
                "docs": {
                    "text": "",
                    "tags": []
                }
            },
            "submit": {
                "complexType": {
                    "signature": "() => Promise<void>",
                    "parameters": [],
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        }
                    },
                    "return": "Promise<void>"
                },
                "docs": {
                    "text": "",
                    "tags": []
                }
            }
        };
    }
    static get elementRef() { return "el"; }
    static get watchers() {
        return [{
                "propName": "language",
                "methodName": "changeLanguage"
            }, {
                "propName": "structureRendered",
                "methodName": "structureChanged"
            }];
    }
}
