import cls from 'classnames';
import { useTree, usePrefix, useOutline, useWorkbench } from '../../hooks';
import { observer } from '@formily/reactive-vue';
import { OutlineTreeNode } from './OutlineNode';
import { Insertion } from './Insertion';
import { NodeSymbol } from './context';
import { defineComponent, provide, ref, unref } from 'vue-demi';
import { useStyle } from '@jeamn/formily-prototypes';
import { useEffect } from '../../shared';
export var OutlineTreeWidget = observer(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 = ref();
        var prefixRef = usePrefix('outline-tree');
        var workbenchRef = 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 = useTree(workspaceId);
        var outline = useOutline(workspaceId);
        var outlineRef = ref();
        var style = useStyle();
        provide(NodeSymbol, ref({
            renderActions: props.renderActions,
            renderTitle: props.renderTitle,
        }));
        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 = unref(prefixRef);
            var tree = unref(treeRef);
            if (!outline.value || !workspaceId)
                return null;
            return (<div {...attrs} class={cls(prefix + '-container')} style={style}>
            <div class={prefix + '-content'} ref={refInstance}>
              <OutlineTreeNode node={tree} workspaceId={workspaceId}/>
              <div class={prefix + '-aux'} style={{
                    pointerEvents: 'none',
                }}>
                <Insertion workspaceId={workspaceId}/>
              </div>
            </div>
          </div>);
        };
    },
}));
//# sourceMappingURL=index.jsx.map