var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import { Status, copyToClipboard } from '@darajs/ui-utils';
import { resolveVariable } from '../shared/interactivity/resolve-variable';
import { isSingleVariable, isVariable } from '../types';
import { UserError } from '../types/core';
const CopyToClipboard = (ctx, actionImpl) => __awaiter(void 0, void 0, void 0, function* () {
    var _a, _b;
    let value;
    if (!isVariable(actionImpl.value)) {
        value = actionImpl.value;
    }
    else {
        if (!isSingleVariable(actionImpl.value)) {
            throw new UserError('CopyToClipboard only supports simple Variables');
        }
        value = (yield resolveVariable(actionImpl.value, ctx.wsClient, ctx.taskCtx, ctx.extras, (v) => ctx.snapshot.getPromise(v)));
    }
    const success = yield copyToClipboard(value);
    if (!success) {
        ctx.notificationCtx.pushNotification({
            key: '_copyToClipboard',
            message: (_a = actionImpl.error_message) !== null && _a !== void 0 ? _a : '',
            status: Status.ERROR,
            title: 'Error copying to clipboard',
        });
    }
    else {
        ctx.notificationCtx.pushNotification({
            key: '_copyToClipboard',
            message: (_b = actionImpl.success_message) !== null && _b !== void 0 ? _b : '',
            status: Status.SUCCESS,
            title: 'Copied to clipboard',
        });
    }
});
export default CopyToClipboard;
//# sourceMappingURL=copy-to-clipboard.js.map