"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DEFAULT_VIEWPORT_SIZE = void 0;
exports.humanizeViewportStep = humanizeViewportStep;
exports.viewportStepToAIString = viewportStepToAIString;
const mablscript_step_types_1 = require("../../mablscript-step-types");
const BaseStep_1 = __importDefault(require("./BaseStep"));
const yaml_utils_1 = require("../yaml-utils");
exports.DEFAULT_VIEWPORT_SIZE = {
    width: 1080,
    height: 1440,
};
class ViewportStep extends BaseStep_1.default {
    static getStepType() {
        return mablscript_step_types_1.StepType.SET_VIEWPORT;
    }
    constructor(size) {
        super(ViewportStep.getStepType());
        this.size = size;
        this.options = {
            executionContext: 'background',
            editable: true,
        };
    }
    generateMablscript() {
        let mablscript = 'set_viewport(';
        if (this.size) {
            let sizeArgs = '';
            if (this.size.width) {
                sizeArgs += `width : ${this.size.width}`;
            }
            if (this.size.height) {
                if (this.size.width) {
                    sizeArgs += ', ';
                }
                sizeArgs += `height : ${this.size.height}`;
            }
            mablscript += `{ size : { ${sizeArgs} } }`;
        }
        mablscript += ')';
        return mablscript;
    }
    inputVariables() {
        return [];
    }
    static generateStepFromMablStep(mablSetViewportStep) {
        return new ViewportStep(mablSetViewportStep.size);
    }
    static create(descriptor) {
        const step = new ViewportStep(descriptor.size);
        step.generateStepId();
        return step;
    }
}
exports.default = ViewportStep;
function humanizeViewportStep(step) {
    if (step.size) {
        let message = 'Set viewport size';
        const width = `width ${step.size.width}`;
        const height = `height ${step.size.height}`;
        if (step.size.width) {
            message += ` to ${width}`;
            if (step.size.height) {
                message += ` and ${height}`;
            }
        }
        else if (step.size.height) {
            message += ` to ${height}`;
        }
        return message;
    }
    throw new Error('Invalid step; humanized description cannot be generated.');
}
function viewportStepToAIString(step) {
    return (0, yaml_utils_1.toYaml)({
        stepType: step.stepType,
        width: step.size?.width,
        height: step.size?.height,
    });
}
