"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);
};
var TaskEditContextActionProvider_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TaskEditContextActionProvider = void 0;
/********************************************************************************
 * Copyright (c) 2023 EclipseSource and others.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v. 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0.
 *
 * This Source Code may also be made available under the following Secondary
 * Licenses when the conditions for such availability set forth in the Eclipse
 * Public License v. 2.0 are satisfied: GNU General Public License, version 2
 * with the GNU Classpath Exception which is available at
 * https://www.gnu.org/software/classpath/license.html.
 *
 * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
 ********************************************************************************/
const server_1 = require("@eclipse-glsp/server");
const inversify_1 = require("inversify");
const graph_extension_1 = require("../graph-extension");
const edit_task_operation_handler_1 = require("./edit-task-operation-handler");
let TaskEditContextActionProvider = TaskEditContextActionProvider_1 = class TaskEditContextActionProvider {
    constructor() {
        this.contextId = 'task-editor';
    }
    getActions(editorContext) {
        var _a, _b;
        const text = (_b = (_a = editorContext.args) === null || _a === void 0 ? void 0 : _a['text'].toString()) !== null && _b !== void 0 ? _b : '';
        const taskNode = this.modelState.index.findParentElement(editorContext.selectedElementIds[0], (0, server_1.toTypeGuard)(graph_extension_1.TaskNode));
        if (!taskNode) {
            return [];
        }
        if (text.startsWith(TaskEditContextActionProvider_1.TYPE_PREFIX)) {
            const taskId = taskNode.id;
            return [
                { label: 'type:automated', actions: [edit_task_operation_handler_1.EditTaskOperation.create({ taskId, feature: 'taskType', value: 'automated' })] },
                { label: 'type:manual', actions: [edit_task_operation_handler_1.EditTaskOperation.create({ taskId, feature: 'taskType', value: 'manual' })] }
            ];
        }
        if (text.startsWith(TaskEditContextActionProvider_1.DURATION_PREFIX)) {
            return [];
        }
        const taskType = taskNode.type.substring(TaskEditContextActionProvider_1.TASK_PREFIX.length);
        const duration = taskNode.duration;
        return [
            { label: 'type:', actions: [], text: `${TaskEditContextActionProvider_1.TYPE_PREFIX}${taskType}` },
            {
                label: 'duration:',
                actions: [],
                text: `${TaskEditContextActionProvider_1.DURATION_PREFIX}${duration !== null && duration !== void 0 ? duration : 0}`
            }
        ];
    }
};
TaskEditContextActionProvider.DURATION_PREFIX = 'duration:';
TaskEditContextActionProvider.TYPE_PREFIX = 'type:';
TaskEditContextActionProvider.TASK_PREFIX = 'task:';
__decorate([
    (0, inversify_1.inject)(server_1.ModelState),
    __metadata("design:type", Object)
], TaskEditContextActionProvider.prototype, "modelState", void 0);
TaskEditContextActionProvider = TaskEditContextActionProvider_1 = __decorate([
    (0, inversify_1.injectable)()
], TaskEditContextActionProvider);
exports.TaskEditContextActionProvider = TaskEditContextActionProvider;
//# sourceMappingURL=task-edit-context-provider.js.map