"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileProvider = void 0;
const vscode = __importStar(require("vscode"));
class FileProvider {
    constructor(model, output) {
        this.model = model;
        this.output = output;
        this._onDidChangeTreeData = new vscode.EventEmitter();
        this.onDidChangeTreeData = this._onDidChangeTreeData.event;
    }
    refresh() {
        this._onDidChangeTreeData.fire();
    }
    getTreeItem(element) {
        const item = new vscode.TreeItem(element.name, element.isFile ? vscode.TreeItemCollapsibleState.None : vscode.TreeItemCollapsibleState.Collapsed);
        // 设置上下文值，用于右键菜单
        item.contextValue = element.isFile ? 'squirrel.file' : 'squirrel.folder';
        // 设置虚拟文件 URI
        const uri = vscode.Uri.parse(`squirrel:/${element.key}`);
        item.resourceUri = uri;
        if (element.isFile) {
            // 设置文件图标
            item.iconPath = new vscode.ThemeIcon('file-code');
            // 为文件设置点击命令
            item.command = {
                command: 'squirrel.openFile',
                title: '打开',
                arguments: [element]
            };
            // 如果有内容，显示状态
            if (element.content) {
                item.description = '已加载';
            }
            else {
                item.description = '未加载';
            }
        }
        else {
            // 文件夹图标
            item.iconPath = new vscode.ThemeIcon('folder');
        }
        return item;
    }
    getChildren(element) {
        try {
            const result = this.model.getChildren(element?.key);
            if (this.output) {
                const label = element ? `children:${element.key}` : 'children:<root>';
                this.output.appendLine(`[Squirrel] get${label} -> ${result.length} items`);
            }
            return Promise.resolve(result);
        }
        catch (error) {
            if (this.output) {
                this.output.appendLine(`[Squirrel] Error getting children: ${error}`);
            }
            return Promise.resolve([]);
        }
    }
    getParent(element) {
        // 简单实现，返回 undefined 表示根目录
        return Promise.resolve(undefined);
    }
}
exports.FileProvider = FileProvider;
//# sourceMappingURL=provider.js.map