"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 DocumentFinderForm {
    constructor(props) {
        this.props = props;
        this.buttonSearch = (0, jquery_1.default)('<button type="button" class="btn btn-primary">Пошук</button>');
        this.buttonSearch.on('click', () => this.props.onSubmit());
        this.buttonReset = (0, jquery_1.default)('<button type="button" class="btn btn-light ml-1">Очистити</button>');
        this.buttonReset.on('click', () => this.props.onReset());
        this.inputNum = (0, jquery_1.default)('<input class="form-control">');
        this.inputNum.on('change', () => this.props.num = this.inputNum.val());
        this.inputName = (0, jquery_1.default)('<input class="form-control">');
        this.inputName.on('change', () => this.props.name = this.inputName.val());
        this.inputMonth = (0, jquery_1.default)('<input class="form-control">');
        this.inputMonth.on('change', () => this.props.month = this.inputMonth.val());
        this.inputYear = (0, jquery_1.default)('<input class="form-control">');
        this.inputYear.on('change', () => this.props.year = this.inputYear.val());
        this.inputDateBegin = (0, jquery_1.default)('<input class="form-control">');
        this.inputDateBegin.on('change', () => this.props.dateBegin = (0, util_1.charToDate)(this.inputDateBegin.val()));
        this.inputDateEnd = (0, jquery_1.default)('<input class="form-control">');
        this.inputDateEnd.on('change', () => this.props.dateEnd = (0, util_1.charToDate)(this.inputDateEnd.val()));
    }
    render() {
        this.inputNum.val(this.props.num);
        this.inputName.val(this.props.name);
        this.inputMonth.val(this.props.month);
        this.inputYear.val(this.props.year);
        this.inputDateBegin.val((0, util_1.dateToChar)(this.props.dateBegin));
        this.inputDateEnd.val((0, util_1.dateToChar)(this.props.dateEnd));
        const form = (0, jquery_1.default)('<form></form>');
        const buttonGroup = (0, jquery_1.default)('<div class="form-group row mb-2"><div class="col-sm-9 offset-sm-3"></div></div>');
        form.append(buttonGroup);
        const buttonGroupCol = buttonGroup.find('.col-sm-9');
        buttonGroupCol.append(this.buttonSearch);
        buttonGroupCol.append(this.buttonReset);
        const formGroup1 = (0, jquery_1.default)('<div class="form-group row mb-2">' +
            '<label class="col-form-label col-sm-3 text-right">Номер</label>' +
            '<div class="col-sm-9"></div>' +
            '</div>');
        formGroup1.find('.col-sm-9').append(this.inputNum);
        form.append(formGroup1);
        const formGroup2 = (0, jquery_1.default)('<div class="form-group row mb-2">' +
            '<label class="col-form-label col-sm-3 text-right">Назва</label>' +
            '<div class="col-sm-9"></div>' +
            '</div>');
        formGroup2.find('.col-sm-9').append(this.inputName);
        form.append(formGroup2);
        const formGroup3 = (0, jquery_1.default)('<div class="form-group row mb-2">' +
            '<label class="col-form-label col-sm-3 text-right">За</label>' +
            '<div class="col-sm-1"><div class="form-control-plaintext">м.</div></div>' +
            '<div class="col-sm-3"></div>' +
            '<div class="col-sm-1"><div class="form-control-plaintext">р.</div></div>' +
            '<div class="col-sm-4"></div>' +
            '</div>');
        formGroup3.find('.col-sm-3:last').append(this.inputMonth);
        formGroup3.find('.col-sm-4').append(this.inputYear);
        form.append(formGroup3);
        const formGroup4 = (0, jquery_1.default)('<div class="form-group row mb-2">' +
            '<label class="col-form-label col-sm-3 text-right">Дата з</label>' +
            '<div class="col-sm-9"></div>' +
            '</div>');
        formGroup4.find('.col-sm-9').append(this.inputDateBegin);
        form.append(formGroup4);
        const formGroup5 = (0, jquery_1.default)('<div class="form-group row mb-2">' +
            '<label class="col-form-label col-sm-3 text-right">Дата по</label>' +
            '<div class="col-sm-9"></div>' +
            '</div>');
        formGroup5.find('.col-sm-9').append(this.inputDateEnd);
        form.append(formGroup5);
        return form;
    }
}
exports.default = DocumentFinderForm;
