"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = Object.setPrototypeOf ||
        ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
        function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
//React
var React = require("react");
var wjGridSheet = require("wijmo/wijmo.react.grid.sheet");
var RedoUndo = /** @class */ (function (_super) {
    __extends(RedoUndo, _super);
    function RedoUndo(props) {
        var _this = _super.call(this, props) || this;
        _this.state = {
            undoStack: null
        };
        _this.undoSheetInit = _this.undoSheetInit.bind(_this);
        _this.undo = _this.undo.bind(_this);
        _this.redo = _this.redo.bind(_this);
        return _this;
    }
    RedoUndo.prototype.undoSheetInit = function (undoSheet) {
        var _this = this;
        this.undoSheet = undoSheet;
        if (undoSheet) {
            undoSheet.deferUpdate(function () {
                var colIdx, rowIdx;
                _this.setState({
                    undoStack: undoSheet.undoStack
                });
                undoSheet.undoStack.undoStackChanged.addHandler(function () {
                    _this.setState({
                        undoStack: undoSheet.undoStack
                    });
                });
                for (colIdx = 0; colIdx < undoSheet.columns.length; colIdx++) {
                    for (rowIdx = 0; rowIdx < undoSheet.rows.length; rowIdx++) {
                        undoSheet.setCellData(rowIdx, colIdx, colIdx + rowIdx);
                    }
                }
            });
        }
    };
    // Excutes undo command.
    RedoUndo.prototype.undo = function () {
        this.undoSheet.undo();
    };
    // Excutes redo command.
    RedoUndo.prototype.redo = function () {
        this.undoSheet.redo();
    };
    RedoUndo.prototype.render = function () {
        return React.createElement("div", null,
            React.createElement("h2", { id: "undoRedo" }, "Undo / Redo"),
            React.createElement("p", null, "The FlexSheet control enables you to undo/redo following operations:"),
            React.createElement("div", { className: "row" },
                React.createElement("div", { className: "col-md-5" },
                    React.createElement("ul", { className: "nav nav-tabs", role: "tablist" },
                        React.createElement("li", { className: "active" },
                            React.createElement("a", { href: "#udJsx", role: "tab", "data-toggle": "tab" }, "JSX")),
                        React.createElement("li", null,
                            React.createElement("a", { href: "#udJs", role: "tab", "data-toggle": "tab" }, "TS"))),
                    React.createElement("div", { className: "tab-content" },
                        React.createElement("div", { className: "tab-pane active pane-content", id: "udJsx" },
                            '<wjGridSheet.FlexSheet\n',
                            '    initialized={this.undoSheetInit}>\n',
                            '    <wjGridSheet.Sheet name="Unbound" rowCount={20} columnCount={8}></wjGridSheet.Sheet>\n',
                            '</wjGridSheet.FlexSheet>\n',
                            ' <button type="button" className="btn btn-default" disabled={!(this.state.undoStack && this.state.undoStack.canUndo)} onClick={this.undo}>Undo</button>\n',
                            ' <button type="button" className="btn btn-default" disabled={!(this.state.undoStack && this.state.undoStack.canRedo)} onClick={this.redo}>Redo</button>\n'),
                        React.createElement("div", { className: "tab-pane pane-content", id: "udJs" },
                            '  undoSheet: wjcGridSheet.FlexSheet;\n',
                            '  undoStack: wjcGridSheet.UndoStack;\n',
                            '  constructor(props) {\n',
                            '      super(props);\n',
                            '      this.state = {\n',
                            '          undoStack: null\n',
                            '      }\n',
                            '       this.undoSheetInit = this.undoSheetInit.bind(this);\n',
                            '       this.undo = this.undo.bind(this);\n',
                            '       this.redo = this.redo.bind(this);\n',
                            '  }\n',
                            '\n',
                            '  undoSheetInit(undoSheet: wjcGridSheet.FlexSheet) {\n',
                            '      this.undoSheet = undoSheet;\n',
                            '      if (undoSheet) {\n',
                            '          undoSheet.deferUpdate(() => {\n',
                            '              let colIdx,\n',
                            '                  rowIdx;\n',
                            '      this.setState({\n',
                            '          undoStack: undoSheet.undoStack\n',
                            '      });\n',
                            '              undoSheet.undoStack.undoStackChanged.addHandler(()=> {\n',
                            '                  this.setState({\n',
                            '                      undoStack: undoSheet.undoStack\n',
                            '                  });\n',
                            '              });\n',
                            '              for (colIdx = 0; colIdx < undoSheet.columns.length; colIdx++) {\n',
                            '                  for (rowIdx = 0; rowIdx < undoSheet.rows.length; rowIdx++) {\n',
                            '                      undoSheet.setCellData(rowIdx, colIdx, colIdx + rowIdx);\n',
                            '                  }\n',
                            '              }\n',
                            '          });\n',
                            '      }\n',
                            '  }\n',
                            '\n',
                            '  // Excutes undo command.\n',
                            '  undo() {\n',
                            '      this.undoSheet.undo();\n',
                            '  }\n',
                            '\n',
                            '  // Excutes redo command.\n',
                            '  redo() {\n',
                            '      this.undoSheet.redo();\n',
                            '  }\n'))),
                React.createElement("div", { className: "col-md-7" },
                    React.createElement("h4", null, "Result (live):"),
                    React.createElement(wjGridSheet.FlexSheet, { initialized: this.undoSheetInit },
                        React.createElement(wjGridSheet.Sheet, { name: "Unbound", rowCount: 20, columnCount: 8 })),
                    React.createElement("button", { type: "button", className: "btn btn-default", disabled: !(this.state.undoStack && this.state.undoStack.canUndo), onClick: this.undo }, "Undo"),
                    React.createElement("button", { type: "button", className: "btn btn-default", disabled: !(this.state.undoStack && this.state.undoStack.canRedo), onClick: this.redo }, "Redo"))));
    };
    return RedoUndo;
}(React.Component));
exports.RedoUndo = RedoUndo;
//# sourceMappingURL=RedoUndo.js.map