import { jsx } from "react/jsx-runtime";
import { useMemo } from "react";
import { useTranslation } from "react-i18next";
import { useCollectionManager, useDataBlockProps } from "../../data-source/index.mjs";
import { useCollection } from "../../data-source/collection/CollectionProvider.mjs";
import { useCompile } from "../../schema-component/index.mjs";
import { SchemaToolbar } from "../../schema-settings/GeneralSchemaDesigner.mjs";
import { useSchemaTemplate } from "../../schema-templates/index.mjs";
const BlockSchemaToolbar = (props)=>{
    const { t } = useTranslation();
    const cm = useCollectionManager();
    const collecttion = useCollection();
    let { name: currentCollectionName, title: currentCollectionTitle } = collecttion || {};
    const template = useSchemaTemplate();
    const { association } = useDataBlockProps() || {};
    const compile = useCompile();
    if (association) {
        const [collectionName] = association.split('.');
        const { name, title } = cm.getCollection(collectionName);
        currentCollectionName = name;
        currentCollectionTitle = title;
    }
    const associationField = cm.getCollectionField(association);
    const templateName = [
        'FormItem',
        'ReadPrettyFormItem'
    ].includes(null == template ? void 0 : template.componentName) ? "".concat(null == template ? void 0 : template.name, " ").concat(t('(Fields only)')) : null == template ? void 0 : template.name;
    const toolbarTitle = useMemo(()=>[
            getCollectionTitle({
                collectionTitle: currentCollectionTitle,
                collectionName: currentCollectionName,
                associationField,
                compile
            }),
            templateName
        ].filter(Boolean), [
        compile,
        currentCollectionTitle,
        currentCollectionName,
        associationField,
        templateName
    ]);
    return /*#__PURE__*/ jsx(SchemaToolbar, {
        title: toolbarTitle,
        ...props
    });
};
function getCollectionTitle(props) {
    const { collectionTitle, collectionName, associationField, compile } = props;
    if (associationField) {
        var _associationField_uiSchema;
        return "".concat(compile(collectionTitle || collectionName), " > ").concat(compile((null == (_associationField_uiSchema = associationField.uiSchema) ? void 0 : _associationField_uiSchema.title) || associationField.name));
    }
    return collectionTitle || collectionName;
}
export { BlockSchemaToolbar };
