import { useCallback } from "react";
import { useFieldSchema } from "@tachybase/schema";
import lodash from "lodash";
import { useBlockContext } from "../../../../block-provider/BlockProvider.mjs";
import { useCollection } from "../../../../data-source/index.mjs";
import { useCompile } from "../../../hooks/index.mjs";
const useGetAriaLabelOfBlockItem = (defaultName)=>{
    var _fieldSchema_xcomponent, _collection_getField_uiSchema, _collection_getField;
    const fieldSchema = useFieldSchema();
    const compile = useCompile();
    const component = lodash.isString(fieldSchema['x-component']) ? fieldSchema['x-component'] : null == (_fieldSchema_xcomponent = fieldSchema['x-component']) ? void 0 : _fieldSchema_xcomponent.displayName;
    const collectionField = compile(fieldSchema['x-collection-field']);
    const { name: blockName } = useBlockContext() || {};
    const collection = useCollection();
    const name = defaultName || blockName;
    const title = compile(fieldSchema['title']) || compile(null == collection ? void 0 : null == (_collection_getField = collection.getField(fieldSchema.name)) ? void 0 : null == (_collection_getField_uiSchema = _collection_getField.uiSchema) ? void 0 : _collection_getField_uiSchema.title);
    const getAriaLabel = useCallback((postfix)=>{
        postfix = postfix ? "-".concat(postfix) : '';
        return [
            'block-item',
            component,
            null == collection ? void 0 : collection.name,
            name,
            collectionField,
            title,
            postfix
        ].filter(Boolean).join('-');
    }, [
        component,
        null == collection ? void 0 : collection.name,
        name,
        collectionField,
        title
    ]);
    return {
        getAriaLabel
    };
};
export { useGetAriaLabelOfBlockItem };
