"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PackageHandler = void 0;
const ipc_1 = require("../ipc");
const PackageManager_1 = require("./PackageManager");
const hotreload_config_1 = require("../hotreload-config");
let PackageHandler = class PackageHandler {
    packageManager;
    constructor(packageManager) {
        this.packageManager = packageManager;
    }
    /**
     * Install an application from a local path.
     */
    async handleInstallApp(args) {
        const { sourcePath } = args;
        return await this.packageManager.installApp(sourcePath);
    }
    /**
     * Uninstall an application by its ID.
     */
    async handleUninstallApp(args) {
        const { appId } = args;
        return await this.packageManager.uninstallApp(appId);
    }
    /**
     * List all installed applications.
     * @param showHidden - If true, includes overlay apps (hidden by default)
     */
    async handleListApps(args) {
        return this.packageManager.getInstalledApps(args.showHidden);
    }
    /**
     * Toggle hot reload for an app
     */
    async handleToggleHotReload(params) {
        const enabled = await (0, hotreload_config_1.toggleHotReload)(params.appId);
        console.log(`Hot reload ${enabled ? "enabled" : "disabled"} for ${params.appId}`);
        return { enabled };
    }
    /**
     * Check if hot reload is enabled for an app
     */
    async handleIsHotReloadEnabled(params) {
        const enabled = await (0, hotreload_config_1.isHotReloadEnabled)(params.appId);
        return { enabled };
    }
    /**
     * Get the icon for an installed application as a data URL.
     */
    async handleGetAppIcon(args) {
        const { appId } = args;
        const icon = await this.packageManager.getAppIcon(appId);
        return { icon };
    }
};
exports.PackageHandler = PackageHandler;
__decorate([
    (0, ipc_1.EdenHandler)("install"),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], PackageHandler.prototype, "handleInstallApp", null);
__decorate([
    (0, ipc_1.EdenHandler)("uninstall"),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], PackageHandler.prototype, "handleUninstallApp", null);
__decorate([
    (0, ipc_1.EdenHandler)("list"),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], PackageHandler.prototype, "handleListApps", null);
__decorate([
    (0, ipc_1.EdenHandler)("toggle-hot-reload"),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], PackageHandler.prototype, "handleToggleHotReload", null);
__decorate([
    (0, ipc_1.EdenHandler)("is-hot-reload-enabled"),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], PackageHandler.prototype, "handleIsHotReloadEnabled", null);
__decorate([
    (0, ipc_1.EdenHandler)("get-icon"),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], PackageHandler.prototype, "handleGetAppIcon", null);
exports.PackageHandler = PackageHandler = __decorate([
    (0, ipc_1.EdenNamespace)("package"),
    __metadata("design:paramtypes", [PackageManager_1.PackageManager])
], PackageHandler);
//# sourceMappingURL=PackageHandler.js.map