import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import "react";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_components__ from "@tachybase/components";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash";
import * as __WEBPACK_EXTERNAL_MODULE_react_i18next__ from "react-i18next";
import * as __WEBPACK_EXTERNAL_MODULE__index_mjs__ from "../../../index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__application_index_mjs__ from "../../../application/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__application_schema_settings_SchemaSettings_mjs__ from "../../../application/schema-settings/SchemaSettings.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__ from "../../../collection-manager/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_component_antd_action_Action_Designer_mjs__ from "../../../schema-component/antd/action/Action.Designer.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_settings_index_mjs__ from "../../../schema-settings/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__hooks_mjs__ from "./hooks.mjs";
const SchemaSettingsActionLinkItem = ()=>{
    const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
    const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
    const { dn } = (0, __WEBPACK_EXTERNAL_MODULE__index_mjs__.useDesignable)();
    const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
    const { urlSchema, paramsSchema, openInNewWindowSchema } = (0, __WEBPACK_EXTERNAL_MODULE__hooks_mjs__.useURLAndHTMLSchema)();
    const componentProps = fieldSchema['x-component-props'] || {};
    const initialValues = {
        url: componentProps.url,
        params: componentProps.params || [
            {}
        ],
        openInNewWindow: componentProps.openInNewWindow
    };
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__schema_settings_index_mjs__.SchemaSettingsModalItem, {
        title: t('Edit link'),
        components: {
            ArrayItems: __WEBPACK_EXTERNAL_MODULE__tachybase_components__.ArrayItems
        },
        schema: {
            type: 'object',
            title: t('Edit link'),
            properties: {
                url: {
                    ...urlSchema,
                    required: true
                },
                params: paramsSchema,
                openInNewWindow: openInNewWindowSchema
            }
        },
        onSubmit: (param)=>{
            let { url, params, openInNewWindow } = param;
            componentProps.url = url;
            componentProps.params = params;
            componentProps.openInNewWindow = openInNewWindow;
            fieldSchema['x-component-props'] = componentProps;
            field.componentProps.url = url;
            field.componentProps.params = params;
            field.componentProps.openInNewWindow = openInNewWindow;
            dn.emit('patch', {
                schema: {
                    ['x-uid']: fieldSchema['x-uid'],
                    'x-component-props': componentProps
                }
            });
            dn.refresh();
        },
        initialValues: initialValues
    });
};
const customizeLinkActionSettings = new __WEBPACK_EXTERNAL_MODULE__application_schema_settings_SchemaSettings_mjs__.SchemaSettings({
    name: 'actionSettings:link',
    items: [
        {
            name: 'editButton',
            Component: __WEBPACK_EXTERNAL_MODULE__schema_component_antd_action_Action_Designer_mjs__.ButtonEditor,
            useComponentProps () {
                const { buttonEditorProps } = (0, __WEBPACK_EXTERNAL_MODULE__application_index_mjs__.useSchemaToolbar)();
                return buttonEditorProps;
            }
        },
        {
            name: 'editLink',
            Component: SchemaSettingsActionLinkItem
        },
        {
            name: 'linkageRules',
            Component: __WEBPACK_EXTERNAL_MODULE__schema_settings_index_mjs__.SchemaSettingsLinkageRules,
            useVisible () {
                const record = (0, __WEBPACK_EXTERNAL_MODULE__index_mjs__.useCollectionRecord)();
                return !__WEBPACK_EXTERNAL_MODULE_lodash__["default"].isEmpty(null == record ? void 0 : record.data);
            },
            useComponentProps () {
                const { name } = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.useCollection_deprecated)();
                const { linkageRulesProps } = (0, __WEBPACK_EXTERNAL_MODULE__application_index_mjs__.useSchemaToolbar)();
                return {
                    ...linkageRulesProps,
                    collectionName: name
                };
            }
        },
        {
            name: 'remove',
            sort: 100,
            Component: __WEBPACK_EXTERNAL_MODULE__schema_component_antd_action_Action_Designer_mjs__.RemoveButton,
            useComponentProps () {
                const { removeButtonProps } = (0, __WEBPACK_EXTERNAL_MODULE__application_index_mjs__.useSchemaToolbar)();
                return removeButtonProps;
            }
        }
    ]
});
export { SchemaSettingsActionLinkItem, customizeLinkActionSettings };
