"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.init = void 0;
var operators_1 = require("rxjs/operators");
var common_1 = require("../common");
var STYLE = ['BOLD', 'ITALIC', 'UNDERLINE'];
function init(args) {
    var grid = args.grid, command$ = args.command$;
    var style$ = command$.pipe(operators_1.filter(function (e) { return STYLE.includes(e.command); }), operators_1.filter(function (e) { return !e.isCancelled; }));
    style$.subscribe(function (e) {
        var command = e.command;
        var field = toField(command);
        var values = common_1.toSelectionValues({ cells: grid.data.cells, selection: e.selection });
        var defaults = common_1.DEFAULT.CELL.PROPS.style;
        var changes = Object.keys(values).reduce(function (acc, key) {
            var cell = grid.cell(key);
            var value = cell.data.value;
            var error = cell.data.error;
            var props = common_1.util.cell.value.toggleCellProp({
                defaults: defaults,
                props: cell.data.props,
                section: 'style',
                field: field,
            });
            acc[key] = { value: value, props: props, error: error };
            return acc;
        }, {});
        grid.changeCells(changes, { source: 'PROPS/style' });
    });
}
exports.init = init;
var toField = function (command) {
    switch (command) {
        case 'BOLD':
            return 'bold';
        case 'ITALIC':
            return 'italic';
        case 'UNDERLINE':
            return 'underline';
        default:
            throw new Error("Command '" + command + "' not supported");
    }
};
