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__index_mjs__ from "../../../index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__Table_Column_ActionBar_mjs__ from "./Table.Column.ActionBar.mjs";
const useColumnSchema = ()=>{
    const { getField } = (0, __WEBPACK_EXTERNAL_MODULE__index_mjs__.useCollection_deprecated)();
    const compile = (0, __WEBPACK_EXTERNAL_MODULE__index_mjs__.useCompile)();
    const columnSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
    const fieldSchema = columnSchema.reduceProperties((buf, s)=>{
        if ('CollectionField' === s['x-component']) return s;
        return buf;
    }, null);
    if (!fieldSchema) return {};
    const collectionField = getField(fieldSchema.name);
    return {
        columnSchema,
        fieldSchema,
        collectionField,
        uiSchema: compile(null == collectionField ? void 0 : collectionField.uiSchema)
    };
};
const TableColumnDecorator = (props)=>{
    const Designer = (0, __WEBPACK_EXTERNAL_MODULE__index_mjs__.useDesigner)();
    const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
    const { fieldSchema, uiSchema, collectionField } = useColumnSchema();
    const { styles } = (0, __WEBPACK_EXTERNAL_MODULE__Table_Column_ActionBar_mjs__.useStyles)();
    const { refresh } = (0, __WEBPACK_EXTERNAL_MODULE__index_mjs__.useDesignable)();
    const compile = (0, __WEBPACK_EXTERNAL_MODULE__index_mjs__.useCompile)();
    (0, __WEBPACK_EXTERNAL_MODULE_react__.useLayoutEffect)(()=>{
        if (field.title) return;
        if (!fieldSchema) return;
        if (null == uiSchema ? void 0 : uiSchema.title) field.title = null == uiSchema ? void 0 : uiSchema.title;
    }, [
        null == uiSchema ? void 0 : uiSchema.title
    ]);
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)(__WEBPACK_EXTERNAL_MODULE__index_mjs__.SortableItem, {
        className: styles.designer,
        children: [
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(Designer, {
                fieldSchema: fieldSchema,
                uiSchema: uiSchema,
                collectionField: collectionField
            }),
            field.title || compile(null == uiSchema ? void 0 : uiSchema.title)
        ]
    });
};
export { TableColumnDecorator, useColumnSchema };
