"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.OutlineTreeWidget = void 0;
var classnames_1 = __importDefault(require("classnames"));
var hooks_1 = require("../../hooks");
var reactive_vue_1 = require("@formily/reactive-vue");
var OutlineNode_1 = require("./OutlineNode");
var Insertion_1 = require("./Insertion");
var context_1 = require("./context");
var vue_demi_1 = require("vue-demi");
var formily_prototypes_1 = require("@jeamn/formily-prototypes");
var shared_1 = require("../../shared");
exports.OutlineTreeWidget = (0, reactive_vue_1.observer)((0, vue_demi_1.defineComponent)({
    name: 'OutlineTreeWidget',
    props: ['renderActions', 'renderTitle', 'onClose'],
    setup: function (props, _a) {
        var _b, _c;
        var attrs = _a.attrs;
        // { onClose, style, renderActions, renderTitle, className,
        var refInstance = (0, vue_demi_1.ref)();
        var prefixRef = (0, hooks_1.usePrefix)('outline-tree');
        var workbenchRef = (0, hooks_1.useWorkbench)();
        var current = ((_b = workbenchRef.value) === null || _b === void 0 ? void 0 : _b.activeWorkspace) || ((_c = workbenchRef.value) === null || _c === void 0 ? void 0 : _c.currentWorkspace);
        var workspaceId = current === null || current === void 0 ? void 0 : current.id;
        var treeRef = (0, hooks_1.useTree)(workspaceId);
        var outline = (0, hooks_1.useOutline)(workspaceId);
        var outlineRef = (0, vue_demi_1.ref)();
        var style = (0, formily_prototypes_1.useStyle)();
        (0, vue_demi_1.provide)(context_1.NodeSymbol, (0, vue_demi_1.ref)({
            renderActions: props.renderActions,
            renderTitle: props.renderTitle,
        }));
        (0, shared_1.useEffect)(function () {
            var _outline = outline.value;
            if (!workspaceId)
                return;
            if (outlineRef.value && outlineRef.value !== _outline) {
                outlineRef.value.onUnmount();
            }
            if (refInstance.value && outline) {
                _outline.onMount(refInstance.value, window);
            }
            outlineRef.value = _outline;
            return function () {
                var _a;
                (_a = outlineRef.value) === null || _a === void 0 ? void 0 : _a.onUnmount();
            };
        }, [refInstance, outlineRef, outline, function () { var _a, _b; return ((_a = workbenchRef.value) === null || _a === void 0 ? void 0 : _a.activeWorkspace) || ((_b = workbenchRef.value) === null || _b === void 0 ? void 0 : _b.currentWorkspace); }]);
        // outlineRef
        return function () {
            var prefix = (0, vue_demi_1.unref)(prefixRef);
            var tree = (0, vue_demi_1.unref)(treeRef);
            if (!outline.value || !workspaceId)
                return null;
            return (<div {...attrs} class={(0, classnames_1.default)(prefix + '-container')} style={style}>
            <div class={prefix + '-content'} ref={refInstance}>
              <OutlineNode_1.OutlineTreeNode node={tree} workspaceId={workspaceId}/>
              <div class={prefix + '-aux'} style={{
                    pointerEvents: 'none',
                }}>
                <Insertion_1.Insertion workspaceId={workspaceId}/>
              </div>
            </div>
          </div>);
        };
    },
}));
//# sourceMappingURL=index.jsx.map