"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const jquery_1 = __importDefault(require("jquery"));
const util_1 = require("./util");
class DocumentFinderResult {
    constructor(props) {
        this.props = props;
    }
    render() {
        const table = (0, jquery_1.default)('<table class="table table-xs table-bordered"><thead>' +
            '<tr><th>Вид/Карт.</th><th>№ Ссылка</th><th>Наименование</th><th>Дата/Текст</th><th>Кат_Стр</th><th>Начало</th></tr>' +
            '</thead><tbody>' +
            '</tbody></table>');
        const tbody = table.find('tbody');
        if (this.props.error !== null) {
            tbody.html('<tr><td colspan="6" class="text-danger text-center">' + this.props.error + '</td></tr>');
            return table;
        }
        else if (this.props.result.length === 0) {
            tbody.html('<tr><td colspan="6" class="text-center">По данному запросу ничего не найдено</td></tr>');
            return table;
        }
        for (let i = 0; i < this.props.result.length; i++) {
            const doc = this.props.result[i];
            let color = '';
            if ((doc.beginDate == doc.endDate && doc.beginDate !== null) || doc.visible === false) {
                color = '#f00';
            }
            else if (doc.endDate !== null && doc.endDate < new Date()) {
                color = '#a0a0a0';
            }
            else if (doc.beginDate === null) {
                color = '#5b883d';
            }
            const tr = (0, jquery_1.default)('<tr></tr>');
            tr.append('<td class="align-top"><a href="aMDODoc.html?p_file=' + doc.helpFile + '&p_page=' + doc.help + '" style="color: ' + color + '">' + doc.lawGroup + '</a></td>');
            const td2 = (0, jquery_1.default)('<td class="align-top cursor-pointer" style="color: ' + color + '">' + doc.lawNum + '</td>');
            td2.one('click', () => this.props.onSelectItem(doc));
            tr.append(td2);
            tr.append('<td class="align-top"><a href="aMDODoc.html?p_file=' + doc.helpFile + '&p_page=' + doc.help + '" style="color: ' + color + '">' + doc.lawName + '</a></td>');
            const td4 = (0, jquery_1.default)('<td class="align-top cursor-pointer" style="color: ' + color + '">' + (0, util_1.dateToChar)(doc.lawDate) + '</td>');
            td4.one('click', () => this.props.onSelectItem(doc));
            tr.append(td4);
            const td5 = (0, jquery_1.default)('<td class="align-top cursor-pointer" style="color: ' + color + '">' + doc.helpFile + '</td>');
            td5.one('click', () => this.props.onSelectItem(doc));
            tr.append(td5);
            const td6 = (0, jquery_1.default)('<td class="align-top cursor-pointer" style="color: ' + color + '">' + (0, util_1.dateToChar)(doc.beginDate) + '</td>');
            td6.one('click', () => this.props.onSelectItem(doc));
            tr.append(td6);
            tbody.append(tr);
        }
        return table;
    }
}
exports.default = DocumentFinderResult;
