import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import "react";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE__data_source_index_mjs__ from "../data-source/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__ from "../schema-component/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__SchemaSettings_mjs__ from "./SchemaSettings.mjs";
const SchemaSettingCollection = ()=>{
    var _collections_dataSource_options;
    const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
    const collections = (0, __WEBPACK_EXTERNAL_MODULE__data_source_index_mjs__.useCollectionManager)();
    const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
    const options = null == collections ? void 0 : null === (_collections_dataSource_options = collections.dataSource['options']) || void 0 === _collections_dataSource_options ? void 0 : _collections_dataSource_options.collections.map((value)=>({
            label: value.title,
            value: value.name
        }));
    const { dn } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useDesignable)();
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__SchemaSettings_mjs__.SchemaSettingsSelectItem, {
        title: "Edit Collection",
        options: options,
        value: fieldSchema['collectionName'],
        onChange: (name)=>{
            field.setValue('');
            const titleField = collections.getCollection(name).titleField;
            fieldSchema['collectionName'] = name;
            fieldSchema.default = '';
            fieldSchema['x-component-props'] = {
                ...fieldSchema['x-component-props'],
                collection: name,
                fieldNames: {
                    label: titleField,
                    value: titleField
                },
                defaultValue: ''
            };
            fieldSchema['x-decorator-props'] = name;
            field.componentProps = fieldSchema['x-component-props'];
            dn.emit('patch', {
                schema: {
                    ['x-uid']: fieldSchema['x-uid'],
                    collectionName: fieldSchema['collectionName'],
                    ['x-component-props']: fieldSchema['x-component-props'],
                    ['x-decorator-props']: fieldSchema['x-decorator-props'],
                    default: ''
                }
            });
            dn.refresh();
        }
    }, "component-field");
};
export { SchemaSettingCollection };
