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 __());
    };
})();
var AnalyticsKosgu;
(function (AnalyticsKosgu) {
    var AnalyticsSheet = (function (_super) {
        __extends(AnalyticsSheet, _super);
        function AnalyticsSheet(id, _document) {
            var _this = _super.call(this, id, false) || this;
            _this._document = _document;
            return _this;
        }
        AnalyticsSheet.prototype.IsTotal = function (row) {
            return (row === 0);
        };
        AnalyticsSheet.prototype.FormatEventHandler = function (sheetId, row, column, groupIndex) {
            if (column < AnalyticsSheet._strCodeColumn) {
                if (this.IsTotal(row)) {
                    return SheetFormatCollection.Default;
                }
                else {
                    return SheetFormatCollection.Spr;
                }
            }
            else if (column > AnalyticsSheet._strCodeColumn) {
                if (this.IsTotal(row)) {
                    return SheetFormatCollection.Calc;
                }
                else {
                    return SheetFormatCollection.Free;
                }
            }
            else {
                return SheetFormatCollection.Default;
            }
        };
        AnalyticsSheet.prototype.CanEditCellEventHandler = function (sheetId, row, column, fieldId, rowLevel) {
            return ((column > AnalyticsSheet._strCodeColumn) && !this.IsTotal(row));
        };
        AnalyticsSheet.prototype.CantEditEventHandler = function (sheetId, row, column, fieldId, rowLevel) {
            return (row > 0);
        };
        AnalyticsSheet.prototype.AnalyticsDataCanCloseEventHandler = function (buttonResult) {
            var sourceTable = this._document.AnalyticsDataTable;
            if (buttonResult === MessageResults.Cancel) {
                return true;
            }
            else {
                var i = 0;
                while (sourceTable.Locate(sourceTable.Kosgu.ForeignKey.Id, sourceTable.Kosgu.ForeignKey.Value, true)) {
                    i++;
                }
                sourceTable.ClearLocateFlag();
                var existsKosgu = (i > 1);
                if (existsKosgu) {
                    Client.ShowMessage("\u041E\u0448\u0438\u0431\u043A\u0430", "\u0423\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0441\u0442\u0440\u043E\u043A\u0430 \u0441 \u041A\u041E\u0421\u0413\u0423 = \"" + sourceTable.Kosgu.Code + "\"", MessageIcons.Error);
                }
                else {
                    var needPrefix = (this.RowCount === 1);
                    sourceTable.FillAnalyticsData(needPrefix);
                }
                return (!existsKosgu && buttonResult === MessageResults.Ok);
            }
        };
        return AnalyticsSheet;
    }(Sheet));
    AnalyticsSheet._strCodeColumn = 1;
    AnalyticsKosgu.AnalyticsSheet = AnalyticsSheet;
    var AnalyticsStaticSheet = (function (_super) {
        __extends(AnalyticsStaticSheet, _super);
        function AnalyticsStaticSheet(id, _document) {
            var _this = _super.call(this, id, false) || this;
            _this._document = _document;
            return _this;
        }
        AnalyticsStaticSheet.prototype.IsTotal = function (row) {
            return (row === 0);
        };
        AnalyticsStaticSheet.prototype.FormatEventHandler = function (sheetId, row, column, groupIndex) {
            if (column > AnalyticsStaticSheet._strCodeColumn) {
                if (this.IsTotal(row)) {
                    return SheetFormatCollection.Calc;
                }
                else {
                    return SheetFormatCollection.Free;
                }
            }
            else {
                return SheetFormatCollection.Default;
            }
        };
        AnalyticsStaticSheet.prototype.CanEditCellEventHandler = function (sheetId, row, column, fieldId, rowLevel) {
            return ((column > AnalyticsStaticSheet._strCodeColumn) && !this.IsTotal(row));
        };
        AnalyticsStaticSheet.prototype.CantEditEventHandler = function (sheetId, row, column, fieldId, rowLevel) {
            return ((column > AnalyticsStaticSheet._strCodeColumn) && !this.IsTotal(row));
        };
        return AnalyticsStaticSheet;
    }(Sheet));
    AnalyticsStaticSheet._strCodeColumn = 1;
    AnalyticsKosgu.AnalyticsStaticSheet = AnalyticsStaticSheet;
    var AnalyticsNonEditableSheet = (function (_super) {
        __extends(AnalyticsNonEditableSheet, _super);
        function AnalyticsNonEditableSheet(id, _document) {
            var _this = _super.call(this, id, false) || this;
            _this._document = _document;
            return _this;
        }
        AnalyticsNonEditableSheet.prototype.IsTotal = function (row) {
            return (row === 0);
        };
        AnalyticsNonEditableSheet.prototype.FormatEventHandler = function (sheetId, row, column, groupIndex) {
            if (column < AnalyticsNonEditableSheet._strCodeColumn) {
                if (this.IsTotal(row)) {
                    return SheetFormatCollection.Default;
                }
                else {
                    return SheetFormatCollection.Related;
                }
            }
            else if (column > AnalyticsNonEditableSheet._strCodeColumn) {
                if (this.IsTotal(row)) {
                    return SheetFormatCollection.Calc;
                }
                else {
                    return SheetFormatCollection.Related;
                }
            }
            else {
                return SheetFormatCollection.Default;
            }
        };
        AnalyticsNonEditableSheet.prototype.CanEditCellEventHandler = function (sheetId, row, column, fieldId, rowLevel) {
            return false;
        };
        AnalyticsNonEditableSheet.prototype.CantEditEventHandler = function (sheetId, row, column, fieldId, rowLevel) {
            return false;
        };
        return AnalyticsNonEditableSheet;
    }(Sheet));
    AnalyticsNonEditableSheet._strCodeColumn = 1;
    AnalyticsKosgu.AnalyticsNonEditableSheet = AnalyticsNonEditableSheet;
})(AnalyticsKosgu || (AnalyticsKosgu = {}));
