"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const createdHook_1 = require("./createdHook");
function initBodyJs(parser) {
    const { webViewHooks, webview } = parser;
    createdHook_1.default(parser);
    webViewHooks.vueHooks.methodsHook.tapPromise('methods', (methods) => __awaiter(this, void 0, void 0, function* () {
        return methods.concat([
            {
                name: 'onSubmit',
                functionConstructorParams: [
                    'item',
                    `
                    if (this.form.key
                        && this.form.langs[0].value
                        && this.form.key != ''
                        && this.form.langs[0].value != ''
                        && this.form.key != 'undefined'
                        && this.form.langs[0].value != 'undefined'
                    ) {
                        htmlBtnCallbacks[item.key](this.form)
                    } else {
                        triggerParentListener('showInformationMessage', 'key and first lang value can not be null');
                    }
                    `
                ]
            }
        ]);
    }));
    webViewHooks.bodyFooterJsHook.tapPromise('footerJs', (jsArr) => __awaiter(this, void 0, void 0, function* () {
        const createds = yield webViewHooks.vueHooks.createdHook.promise([]);
        const methods = yield webViewHooks.vueHooks.methodsHook.promise([]);
        return jsArr.concat([
            `
            <script type="text/javascript">
                // 处理createed
                const createdInits = ${JSON.stringify(createds, null, 4)}.map(functionConstructorParams => {
                    return new Function(...functionConstructorParams);
                });
                // 处理 methods
                var methodObjs = {};
                ${JSON.stringify(methods, null, 4)}.forEach(method => {
                    methodObjs[method.name] = new Function(...method.functionConstructorParams);
                });
            </script>
            `,
            `
            <script type="text/javascript">
            window.app = new Vue({
                el: '#app',
                data() {
                    return {
                        form: {
                            key: '',
                            langs: [],
                        },
                        btns: htmlBtns
                    }
                },
                computed: {
                },
                created() {
                    createdInits.forEach((initFunction) => {
                        initFunction(this);
                    });
                },
                methods: methodObjs
            });
            </script>
            `
        ]);
    }));
}
exports.default = initBodyJs;
//# sourceMappingURL=bodyFooterJs.js.map