import { jsx } from "react/jsx-runtime";
import { useEffect } from "react";
import { observer, useField, useFieldSchema, useForm } from "@tachybase/schema";
import { useFormBlockContext } from "../../../block-provider/index.mjs";
import { useCollection_deprecated } from "../../../collection-manager/index.mjs";
import { useCompile } from "../../hooks/index.mjs";
import { ActionBar } from "../action/index.mjs";
const TableField = observer((props)=>{
    const fieldSchema = useFieldSchema();
    const { getField } = useCollection_deprecated();
    const field = useField();
    const collectionField = getField(fieldSchema.name);
    const compile = useCompile();
    const ctx = useFormBlockContext();
    useEffect(()=>{
        if (!field.title) {
            var _collectionField_uiSchema;
            field.title = compile(null == collectionField ? void 0 : null == (_collectionField_uiSchema = collectionField.uiSchema) ? void 0 : _collectionField_uiSchema.title);
        }
        if (null == ctx ? void 0 : ctx.field) {
            ctx.field.added = ctx.field.added || new Set();
            ctx.field.added.add(fieldSchema.name);
        }
    }, []);
    useEffect(()=>{
        field.decoratorProps.asterisk = fieldSchema.required;
    }, [
        fieldSchema.required
    ]);
    return /*#__PURE__*/ jsx("div", {
        children: props.children
    });
}, {
    displayName: 'TableField'
});
TableField.ActionBar = observer((props)=>{
    const form = useForm();
    if (form.readPretty) return null;
    return /*#__PURE__*/ jsx("div", {
        style: {
            marginBottom: 8,
            marginTop: -32
        },
        children: /*#__PURE__*/ jsx(ActionBar, {
            ...props
        })
    });
}, {
    displayName: 'TableField.ActionBar'
});
export { TableField };
