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 F01409;
(function (F01409) {
    var InterfaceRules = (function (_super) {
        __extends(InterfaceRules, _super);
        function InterfaceRules() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        InterfaceRules.prototype.SheetP1FormatEventHandler = function (sheetId, row, column, groupIndex) {
            switch (column) {
                case 0:
                case 1:
                    return SheetFormatCollection.Default;
                default:
                    var rowCount = this.Document.Sheets.getValue(sheetId).RowCount;
                    if (this.Document.CommonRules.IsFooterRow(sheetId, row) && column > 1) {
                        return SheetFormatCollection.Calc;
                    }
                    else if (row === 0 || row === 1 || row === rowCount - 8) {
                        return SheetFormatCollection.Calc;
                    }
                    else if (row === rowCount - 3) {
                        return SheetFormatCollection.Free;
                    }
                    else {
                        return SheetFormatCollection.Related;
                    }
            }
        };
        InterfaceRules.prototype.SheetP1EditingCellEventHandler = function (sheetId, row, column, fieldId, rowLevel) {
            var rowCount = this.Document.Sheets.getValue(sheetId).RowCount;
            return ((column > 1) && (row === rowCount - 3));
        };
        InterfaceRules.prototype.IsFooterRow = function (sheetId, row) {
            return this.Document.CommonRules.IsFooterRow(sheetId, row, 3);
        };
        InterfaceRules.prototype.SheetP2Sp4FormatEventHandler = function (sheetId, row, column, groupIndex) {
            if (column === 1) {
                return undefined;
            }
            else {
                return this.Document.CommonRules.StandardFormat(sheetId, row, column, InterfaceRules._sheetP2Sp4Info);
            }
        };
        InterfaceRules.prototype.SheetP2Sp4CalcEventHandler = function (sheetId, row, column, fieldId) {
            return this.Document.CommonRules.StandardCalc(sheetId, row, column, InterfaceRules._sheetP2Sp4Info);
        };
        InterfaceRules.prototype.SheetP2DailyPayEditingCellEventHandler = function (sheetId, row, column, fieldId, rowLevel) {
            if (column === 1) {
                return false;
            }
            else if (column > 1) {
                var table = this.Document.P2DailyPayDataTable;
                var key = this.Document.Sheets.getValue(sheetId).Table.GetKeyBySourceTable(table);
                return key != null;
            }
        };
        InterfaceRules.prototype.SheetP2DailyPayFormatEventHandler = function (sheetId, row, column, groupIndex) {
            return this.Document.CommonRules.StandardFormat(sheetId, row, column, InterfaceRules._sheetP2DailyPayInfo);
        };
        InterfaceRules.prototype.SheetP2DailyPayCalcEventHandler = function (sheetId, row, column, fieldId) {
            if (BaseObasTableFields.StrCodeField.Equal(fieldId)) {
                var code = row + 11;
                return ObasHelper.FillWithCharacter(code.toString(), 4);
            }
        };
        InterfaceRules.prototype.SheetP3DailyPayCalcEventHandler = function (sheetId, row, column, fieldId) {
            if (this.Document.CommonRules.IsFooterRow(sheetId, row)) {
                if (BaseObasTableFields.StrCodeField.Equal(fieldId)) {
                    return 1000;
                }
                else if (column > 1) {
                    if (column === 3 || column === 4 || column === 9 || column === 10) {
                        return ObasHelper.X;
                    }
                    else {
                        var sheet = this.Document.Sheets.getValue(sheetId);
                        return this.Document.CommonRules.GetFooterSum(sheet, row, column);
                    }
                }
                else {
                    if (column === 0) {
                        return InterfaceRules.TotalRowName;
                    }
                }
            }
            else if (BaseObasTableFields.StrCodeField.Equal(fieldId)) {
                return ObasHelper.FillWithCharacter((row + 1).toString(), 4);
            }
            else {
                return this.Document.CommonRules
                    .StandardCalc(sheetId, row, column, InterfaceRules._sheetP3DailyPayInfo);
            }
            return undefined;
        };
        InterfaceRules.prototype.ObjectDescSheetFormatEventHandler = function (sheetId, row, column, groupIndex) {
            switch (column) {
                case 0:
                case 1:
                case 2:
                    return SheetFormatCollection.Related;
                case 8:
                    return SheetFormatCollection.Default;
                case 9:
                case 13:
                    return SheetFormatCollection.Spr;
                default:
                    return SheetFormatCollection.Free;
            }
        };
        InterfaceRules.prototype.ObjectDescSheetCalcEventHandler = function (sheetId, row, column, fieldId) {
            if (BaseObasTableFields.StrCodeField.Equal(fieldId)) {
                return ObasHelper.FillWithCharacter(row + 1, 6);
            }
            return undefined;
        };
        InterfaceRules.prototype.ObjectDescSheetCanAddEventHandler = function (sheetId, row, column, fieldId, rowLevel) {
            return column > 7;
        };
        InterfaceRules.prototype.ObjectDescSheetCanEditEventHandler = function (sheetId, row, column, fieldId, rowLevel) {
            var table = this._document.Sheets.getValue(sheetId).Table;
            if (column > 7) {
                return table.GetKeyBySourceTable(this._document.P5RefObjDescNpaTable) != null;
            }
            else {
                return table.GetKeyBySourceTable(this._document.P5RefObjDescNpaTable.ParentTable) != null;
            }
        };
        InterfaceRules.prototype.ObjectDescSheetCanDeleteEventHandler = function (sheetId, row, column, fieldId, rowLevel) {
            var table = this._document.Sheets.getValue(sheetId).Table;
            if (column > 7) {
                return table.GetKeyBySourceTable(this._document.P5RefObjDescNpaTable) != null;
            }
            else {
                return false;
            }
        };
        InterfaceRules.prototype.FilterOKPD = function () {
            var okpdCode = ObasTableCollection.OkpdSprTable.Code.Value || "";
            return okpdCode.length >= 5;
        };
        InterfaceRules.prototype.FilterKosgu = function () {
            var kosguCodes = ["212", "214", "222", "226", "266", "267"];
            var kosguCode = ObasTableCollection.KosguSprTable.Code.Value;
            return this.Document.CommonRules.FilterKosgu() && (kosguCodes.indexOf(kosguCode) > -1);
        };
        InterfaceRules.prototype.FilterKosguPart5 = function () {
            var kosguCodes = ["222", "225", "226", "266", "267", "310", "340", "343", "346"];
            var kosguCode = ObasTableCollection.KosguSprTable.Code.Value;
            return this.Document.CommonRules.FilterKosgu() && (kosguCodes.indexOf(kosguCode) > -1);
        };
        InterfaceRules._sheetRowCodeInfo = {
            Column: 1,
            Length: 3,
            LevelIncs: [1],
            CalcTotalCode: function (sheet, row) {
                return 100;
            }
        };
        InterfaceRules._sheetP2Sp4Info = {
            MaxLevel: 1,
            CodeInfo: InterfaceRules._sheetRowCodeInfo,
            ColumnsInfo: [
                InterfaceRules._freeColConstAll,
                SheetColumnInfoCollection.CalcColFormatOnly,
                SheetColumnInfoCollection.FreeColAllX,
                SheetColumnInfoCollection.FreeColAllX,
                SheetColumnInfoCollection.FreeColAllCalc,
                SheetColumnInfoCollection.FreeColAllCalc,
                SheetColumnInfoCollection.CalcColAllCalc,
                SheetColumnInfoCollection.CalcColAllCalc,
                SheetColumnInfoCollection.FreeColAllCalc,
                SheetColumnInfoCollection.FreeColAllCalc
            ]
        };
        InterfaceRules._sheetP2DailyPayInfo = {
            MaxLevel: 1,
            ColumnsInfo: [
                InterfaceRules._defaultColConstAll,
                SheetColumnInfoCollection.SprColAllDefault,
                SheetColumnInfoCollection.AllDefault,
                SheetColumnInfoCollection.FreeColAllX,
                SheetColumnInfoCollection.FreeColAllCalc,
                SheetColumnInfoCollection.FreeColAllX,
                SheetColumnInfoCollection.CalcColAllCalc
            ]
        };
        return InterfaceRules;
    }(F01400.InterfaceRules));
    F01409.InterfaceRules = InterfaceRules;
    var AnalyticSheet = (function (_super) {
        __extends(AnalyticSheet, _super);
        function AnalyticSheet(id, _document) {
            var _this = _super.call(this, id, false) || this;
            _this._document = _document;
            return _this;
        }
        AnalyticSheet.prototype.IsTotal = function (row) {
            return (row === 0 || row === 1 || row === 5 || row === 9 || row === 12);
        };
        AnalyticSheet.prototype.FormatEventHandler = function (sheetId, row, column, groupIndex) {
            if (column > AnalyticSheet._strCodeColumn) {
                if (this.IsTotal(row)) {
                    return SheetFormatCollection.Calc;
                }
                else {
                    return SheetFormatCollection.Free;
                }
            }
            else {
                return SheetFormatCollection.Default;
            }
        };
        AnalyticSheet.prototype.CalcEventHandler = function (sheetId, row, column, fieldId) {
            if (column > AnalyticSheet._strCodeColumn) {
                if (this.IsTotal(row)) {
                    var result = new SheetCalcResult(BaseFormulas.SUM);
                    switch (row) {
                        case 0:
                            for (var i = 1; i < this.RowCount; i++) {
                                if (!this.IsTotal(i)) {
                                    result.AddCoordinates(new CellCoordinate(i, column));
                                }
                            }
                            break;
                        case 1:
                            for (var i = 2; i < 5; i++) {
                                result.AddCoordinates(new CellCoordinate(i, column));
                            }
                            break;
                        case 5:
                            for (var i = 6; i < 9; i++) {
                                result.AddCoordinates(new CellCoordinate(i, column));
                            }
                            break;
                        case 9:
                            for (var i = 10; i < 12; i++) {
                                result.AddCoordinates(new CellCoordinate(i, column));
                            }
                            break;
                        case 12:
                            for (var i = 13; i < this.RowCount; i++) {
                                result.AddCoordinates(new CellCoordinate(i, column));
                            }
                            break;
                    }
                    return result.ToArray();
                }
            }
            return undefined;
        };
        AnalyticSheet.prototype.CanEditCellEventHandler = function (sheetId, row, column, fieldId, rowLevel) {
            return ((column > AnalyticSheet._strCodeColumn) && !this.IsTotal(row));
        };
        AnalyticSheet._strCodeColumn = 1;
        return AnalyticSheet;
    }(Sheet));
    F01409.AnalyticSheet = AnalyticSheet;
})(F01409 || (F01409 = {}));
