import { jsx } from "react/jsx-runtime";
import { useEffect, useMemo } from "react";
import { observer, useFieldSchema } from "@tachybase/schema";
import { createStyles } from "antd-style";
import { Variable, useCompile } from "../../schema-component/index.mjs";
import { useCurrentFormVariable } from "../VariableInput/hooks/useFormVariable.mjs";
import { useCurrentObjectVariable } from "../VariableInput/hooks/useIterationVariable.mjs";
function _tagged_template_literal(strings, raw) {
    if (!raw) raw = strings.slice(0);
    return Object.freeze(Object.defineProperties(strings, {
        raw: {
            value: Object.freeze(raw)
        }
    }));
}
function _templateObject() {
    const data = _tagged_template_literal([
        "\n      min-width: 400px;\n      margin-right: 15;\n      .ant-input {\n        width: 100% !important;\n      }\n    "
    ]);
    _templateObject = function() {
        return data;
    };
    return data;
}
const useStyles = createStyles((param)=>{
    let { css } = param;
    return {
        variableInput: css(_templateObject())
    };
});
const ChildDynamicComponent = observer((props)=>{
    const { styles } = useStyles();
    const { rootCollection, onChange, value, collectionField } = props;
    const fieldSchema = useFieldSchema();
    const { currentFormSettings } = useCurrentFormVariable({
        collectionName: rootCollection,
        collectionField
    });
    const { currentObjectSettings } = useCurrentObjectVariable({
        schema: null == collectionField ? void 0 : collectionField.uiSchema,
        collectionField
    });
    const compile = useCompile();
    const result = useMemo(()=>[
            currentFormSettings,
            currentObjectSettings
        ].filter(Boolean), [
        currentFormSettings,
        currentObjectSettings
    ]);
    const scope = compile(result);
    useEffect(()=>{
        onChange(fieldSchema.default);
    }, []);
    return /*#__PURE__*/ jsx(Variable.Input, {
        value: value,
        onChange: onChange,
        scope: scope,
        className: styles.variableInput
    });
}, {
    displayName: 'ChildDynamicComponent'
});
export { ChildDynamicComponent };
