import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE__emotion_css__ from "@emotion/css";
import * as __WEBPACK_EXTERNAL_MODULE_react_i18next__ from "react-i18next";
import * as __WEBPACK_EXTERNAL_MODULE__block_provider_FormBlockProvider_mjs__ from "../../../block-provider/FormBlockProvider.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__record_provider_index_mjs__ from "../../../record-provider/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_component_antd_variable_Variable_mjs__ from "../../../schema-component/antd/variable/Variable.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_settings_VariableInput_hooks_useVariableOptions_mjs__ from "../../../schema-settings/VariableInput/hooks/useVariableOptions.mjs";
function _tagged_template_literal(strings, raw) {
    if (!raw) raw = strings.slice(0);
    return Object.freeze(Object.defineProperties(strings, {
        raw: {
            value: Object.freeze(raw)
        }
    }));
}
function _templateObject() {
    const data = _tagged_template_literal([
        "\n                & > .ant-space-item:first-child,\n                & > .ant-space-item:last-child {\n                  flex-shrink: 0;\n                }\n              "
    ]);
    _templateObject = function() {
        return data;
    };
    return data;
}
const getVariableComponentWithScope = (Com)=>(props)=>{
        const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
        const { form } = (0, __WEBPACK_EXTERNAL_MODULE__block_provider_FormBlockProvider_mjs__.useFormBlockContext)();
        const record = (0, __WEBPACK_EXTERNAL_MODULE__record_provider_index_mjs__.useRecord)();
        const scope = (0, __WEBPACK_EXTERNAL_MODULE__schema_settings_VariableInput_hooks_useVariableOptions_mjs__.useVariableOptions)({
            collectionField: {
                uiSchema: fieldSchema
            },
            form,
            record,
            uiSchema: fieldSchema,
            noDisabled: true
        });
        return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(Com, {
            ...props,
            scope: scope
        });
    };
const useURLAndHTMLSchema = ()=>{
    const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
    const Com = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>getVariableComponentWithScope(__WEBPACK_EXTERNAL_MODULE__schema_component_antd_variable_Variable_mjs__.Variable.TextArea), []);
    const urlSchema = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
            title: t('URL'),
            type: 'string',
            'x-decorator': 'FormItem',
            'x-component': Com,
            description: t('Do not concatenate search params in the URL'),
            'x-reactions': {
                dependencies: [
                    'mode'
                ],
                fulfill: {
                    state: {
                        hidden: '{{$deps[0] === "html"}}'
                    }
                }
            }
        }), [
        t,
        Com
    ]);
    const modeSchema = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
            title: '{{t("Mode")}}',
            'x-component': 'Radio.Group',
            'x-decorator': 'FormItem',
            default: 'url',
            enum: [
                {
                    value: 'url',
                    label: t('URL')
                },
                {
                    value: 'html',
                    label: t('HTML')
                }
            ]
        }), [
        t
    ]);
    const htmlSchema = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
            title: t('html'),
            type: 'string',
            'x-decorator': 'FormItem',
            'x-component': getVariableComponentWithScope(__WEBPACK_EXTERNAL_MODULE__schema_component_antd_variable_Variable_mjs__.Variable.RawTextArea),
            'x-component-props': {
                rows: 10
            },
            'x-reactions': {
                dependencies: [
                    'mode'
                ],
                fulfill: {
                    state: {
                        hidden: '{{$deps[0] === "url"}}'
                    }
                }
            }
        }), [
        t
    ]);
    const paramsSchema = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
            type: 'array',
            'x-component': 'ArrayItems',
            'x-decorator': 'FormItem',
            title: '{{t("Search parameters")}}',
            items: {
                type: 'object',
                properties: {
                    space: {
                        type: 'void',
                        'x-component': 'Space',
                        'x-component-props': {
                            style: {
                                flexWrap: 'nowrap',
                                maxWidth: '100%'
                            },
                            className: (0, __WEBPACK_EXTERNAL_MODULE__emotion_css__.css)(_templateObject())
                        },
                        properties: {
                            name: {
                                type: 'string',
                                'x-decorator': 'FormItem',
                                'x-component': 'Input',
                                'x-component-props': {
                                    placeholder: '{{t("Name")}}'
                                }
                            },
                            value: {
                                type: 'string',
                                'x-decorator': 'FormItem',
                                'x-component': Com,
                                'x-component-props': {
                                    placeholder: '{{t("Value")}}',
                                    useTypedConstant: true,
                                    changeOnSelect: true
                                }
                            },
                            remove: {
                                type: 'void',
                                'x-decorator': 'FormItem',
                                'x-component': 'ArrayItems.Remove'
                            }
                        }
                    }
                }
            },
            'x-reactions': {
                dependencies: [
                    'mode'
                ],
                fulfill: {
                    state: {
                        hidden: '{{$deps[0] === "html"}}'
                    }
                }
            },
            properties: {
                add: {
                    type: 'void',
                    title: '{{t("Add parameter")}}',
                    'x-component': 'ArrayItems.Addition'
                }
            }
        }), [
        Com
    ]);
    const openInNewWindowSchema = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
            type: 'boolean',
            'x-content': t('Open in new window'),
            'x-decorator': 'FormItem',
            'x-component': 'Checkbox',
            'x-reactions': {
                dependencies: [
                    'mode'
                ],
                fulfill: {
                    state: {
                        hidden: '{{$deps[0] === "html"}}'
                    }
                }
            }
        }), [
        t
    ]);
    return {
        urlSchema,
        paramsSchema,
        openInNewWindowSchema,
        modeSchema,
        htmlSchema
    };
};
export { useURLAndHTMLSchema };
