import { jsx } from "react/jsx-runtime";
import { useMemo } from "react";
import { App, Button, Result, Typography } from "antd";
import { useTranslation } from "react-i18next";
import { DEFAULT_DATA_SOURCE_KEY } from "../data-source/DataSourceManager.mjs";
import { CardItem, EllipsisWithTooltip, useCompile, useDesignable } from "../../schema-component/index.mjs";
import { useCollection } from "../collection/index.mjs";
import { useDataSourceManager } from "../data-source/index.mjs";
import { useDataSource } from "../data-source/DataSourceProvider.mjs";
const { Text } = Typography;
const CollectionDeletedPlaceholder = (param)=>{
    let { type, name, message } = param;
    const { designable, dn } = useDesignable();
    const { modal } = App.useApp();
    const { t } = useTranslation();
    const dataSource = useDataSource();
    const compile = useCompile();
    const collection = useCollection();
    const dataSourceManager = useDataSourceManager();
    const nameValue = useMemo(()=>{
        if ('DataSource' === type) return name;
        const dataSourcePrefix = (null == dataSourceManager ? void 0 : dataSourceManager.getDataSources().length) >= 1 && dataSource && dataSource.key !== DEFAULT_DATA_SOURCE_KEY ? "".concat(compile(dataSource.displayName || dataSource.key), " > ") : '';
        if ('Collection' === type) return "".concat(dataSourcePrefix).concat(name);
        const collectionPrefix = collection ? "".concat(compile(collection.title) || collection.name || collection.tableName, " > ") : '';
        return "".concat(dataSourcePrefix).concat(collectionPrefix).concat(name);
    }, []);
    const blockType = useMemo(()=>{
        if ('Field' === type) return 'Field';
        return 'Block';
    }, [
        type
    ]);
    const messageValue = useMemo(()=>{
        if (!name) return "".concat(t(type), " ", 'name is required');
        if (message) return "".concat(t(type), ' "').concat(nameValue, '" ').concat(message);
        return t('The {{type}} "{{name}}" may have been deleted. Please remove this {{blockType}}.', {
            type: t(type).toLocaleLowerCase(),
            name: nameValue,
            blockType: t(blockType)
        }).replaceAll('&gt;', '>');
    }, [
        message,
        nameValue,
        type,
        t,
        blockType
    ]);
    if (designable) {
        if ('Field' === type) return /*#__PURE__*/ jsx(EllipsisWithTooltip, {
            ellipsis: true,
            children: /*#__PURE__*/ jsx(Text, {
                type: "secondary",
                children: messageValue
            })
        });
        return /*#__PURE__*/ jsx(CardItem, {
            children: /*#__PURE__*/ jsx(Result, {
                status: "404",
                subTitle: messageValue,
                extra: /*#__PURE__*/ jsx(Button, {
                    onClick: ()=>modal.confirm({
                            title: t('Delete block'),
                            content: t('Are you sure you want to delete it?'),
                            ...confirm,
                            onOk () {
                                dn.remove(null, {
                                    removeParentsIfNoChildren: true,
                                    breakRemoveOn: {
                                        'x-component': 'Grid'
                                    }
                                });
                            }
                        }),
                    children: t('Delete')
                }, "Delete")
            })
        });
    }
    return null;
};
export { CollectionDeletedPlaceholder };
