"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.d = function(exports1, definition) {
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = function(obj, prop) {
        return Object.prototype.hasOwnProperty.call(obj, prop);
    };
})();
(()=>{
    __webpack_require__.r = function(exports1) {
        if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    useColumnSchema: ()=>useColumnSchema,
    TableColumnDecorator: ()=>TableColumnDecorator
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const schema_namespaceObject = require("@tachybase/schema");
const external_index_js_namespaceObject = require("../../../index.js");
const external_Table_Column_ActionBar_js_namespaceObject = require("./Table.Column.ActionBar.js");
const external_utils_js_namespaceObject = require("./utils.js");
const useColumnSchema = ()=>{
    const { getField } = (0, external_index_js_namespaceObject.useCollection_deprecated)();
    const compile = (0, external_index_js_namespaceObject.useCompile)();
    const columnSchema = (0, schema_namespaceObject.useFieldSchema)();
    const { getCollectionJoinField } = (0, external_index_js_namespaceObject.useCollectionManager_deprecated)();
    const fieldSchema = columnSchema.reduceProperties((buf, s)=>{
        if ((0, external_utils_js_namespaceObject.isCollectionFieldComponent)(s)) return s;
        return buf;
    }, null);
    if (!fieldSchema) return {};
    const collectionField = getField(fieldSchema.name) || getCollectionJoinField(null == fieldSchema ? void 0 : fieldSchema['x-collection-field']);
    return {
        columnSchema,
        fieldSchema,
        collectionField,
        uiSchema: compile(null == collectionField ? void 0 : collectionField.uiSchema)
    };
};
const TableColumnDecorator = (props)=>{
    const Designer = (0, external_index_js_namespaceObject.useDesigner)();
    const { isInSubTable } = (0, external_index_js_namespaceObject.useFlag)() || {};
    const { styles } = (0, external_Table_Column_ActionBar_js_namespaceObject.useStyles)({
        margin: isInSubTable ? '-12px -8px' : '-18px -16px',
        padding: isInSubTable ? '12px 8px' : '18px 16px'
    });
    const field = (0, schema_namespaceObject.useField)();
    const { fieldSchema, uiSchema, collectionField } = useColumnSchema();
    const compile = (0, external_index_js_namespaceObject.useCompile)();
    (0, external_react_namespaceObject.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, jsx_runtime_namespaceObject.jsx)(external_index_js_namespaceObject.SortableItem, {
        className: styles.designer,
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_index_js_namespaceObject.CollectionFieldContext.Provider, {
            value: collectionField,
            children: [
                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Designer, {
                    fieldSchema: fieldSchema,
                    uiSchema: uiSchema,
                    collectionField: collectionField
                }),
                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                    role: "button",
                    children: (null == field ? void 0 : field.title) || compile(null == uiSchema ? void 0 : uiSchema.title)
                })
            ]
        })
    });
};
var __webpack_export_target__ = exports;
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
    value: true
});
