"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.IndentAction = void 0;
const action_1 = require("../action");
const node_mutation_1 = __importDefault(require("../node-mutation"));
/**
* IndentAction to indent the node.
* @extends BaseAction
*/
class IndentAction extends action_1.BaseAction {
/**
* Create an IndentAction
* @param {T} node
* @param {IndentOptions} options
* @param options.adapter - adapter to parse the node
*/
constructor(node, { tabSize, adapter }) {
super(node, "", { adapter });
this.tabSize = tabSize || 1;
this.type = "replace";
}
/**
* Calculate the begin and end positions.
* @protected
*/
calculatePositions() {
this.start = this.adapter.getStart(this.node);
this.end = this.adapter.getEnd(this.node);
}
/**
* The rewritten source code.
* @returns {string} rewritten code.
*/
get newCode() {
const source = this.adapter.getSource(this.node);
return source.split("\n").map(line => ' '.repeat(node_mutation_1.default.tabWidth * this.tabSize) + line).join("\n");
}
}
exports.IndentAction = IndentAction;