import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
import * as __WEBPACK_EXTERNAL_MODULE__ant_design_pro_layout__ from "@ant-design/pro-layout";
import * as __WEBPACK_EXTERNAL_MODULE_antd__ from "antd";
import * as __WEBPACK_EXTERNAL_MODULE_react_router_dom__ from "react-router-dom";
import * as __WEBPACK_EXTERNAL_MODULE__index_mjs__ from "../index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__ from "../schema-component/index.mjs";
const EditableTitle = (props)=>{
    const [title, setTitle] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(props.title);
    const [visible, setVisible] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(false);
    const { refresh } = (0, __WEBPACK_EXTERNAL_MODULE__index_mjs__.useSchemaTemplateManager)();
    const { run } = (0, __WEBPACK_EXTERNAL_MODULE__index_mjs__.useRequest)({
        resource: 'uiSchemaTemplates',
        action: 'update',
        params: {
            filterByTk: props.filterByTk
        }
    }, {
        manual: true,
        debounceWait: 500,
        onSuccess () {
            refresh();
        }
    });
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
        children: visible ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Input, {
            defaultValue: title,
            size: 'large',
            onBlur: ()=>{
                setVisible(false);
            },
            onChange: (e)=>{
                setTitle(e.target.value);
                run({
                    filterByTk: props.filterByTk,
                    values: {
                        name: e.target.value
                    }
                });
            }
        }) : /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
            onClick: ()=>{
                setVisible(true);
            },
            children: title || /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("span", {
                style: {
                    color: '#bbb'
                },
                children: "未命名"
            })
        })
    });
};
const BlockTemplateDetails = ()=>{
    var _data_data, _data_data1;
    const navigate = (0, __WEBPACK_EXTERNAL_MODULE_react_router_dom__.useNavigate)();
    const params = (0, __WEBPACK_EXTERNAL_MODULE_react_router_dom__.useParams)();
    const key = null == params ? void 0 : params.key;
    const value = (0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(__WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.SchemaComponentContext);
    const { data, loading } = (0, __WEBPACK_EXTERNAL_MODULE__index_mjs__.useRequest)({
        resource: 'uiSchemaTemplates',
        action: 'get',
        params: {
            filterByTk: key
        }
    });
    if (loading) return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Spin, {});
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("div", {
        children: [
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__ant_design_pro_layout__.PageHeader, {
                style: {
                    backgroundColor: 'white'
                },
                onBack: ()=>{
                    navigate('/admin/plugins/block-templates');
                },
                ghost: false,
                title: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(EditableTitle, {
                    filterByTk: key,
                    title: null == data ? void 0 : null === (_data_data = data.data) || void 0 === _data_data ? void 0 : _data_data.name
                })
            }),
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                style: {
                    margin: 'var(--tb-spacing)'
                },
                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.SchemaComponentContext.Provider, {
                    value: {
                        ...value,
                        designable: true
                    },
                    children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.RemoteSchemaComponent, {
                        uid: null == data ? void 0 : null === (_data_data1 = data.data) || void 0 === _data_data1 ? void 0 : _data_data1.uid
                    })
                })
            })
        ]
    });
};
export { BlockTemplateDetails };
