import { cssClass } from '../../styles';
/** @internal */
export default function append(col, node, dialog) {
    var current = col.getGroupCriteria();
    var isRegex = current.length > 0 && current[0] instanceof RegExp;
    node.insertAdjacentHTML('beforeend', "\n    <label class=\"" + cssClass('checkbox') + "\">\n      <input type=\"radio\" name=\"regex\" value=\"startsWith\" id=\"" + dialog.idPrefix + "RW\" " + (!isRegex ? 'checked' : '') + ">\n      <span>Text starts with &hellip;</span>\n    </label>\n    <label class=\"" + cssClass('checkbox') + "\">\n      <input type=\"radio\" name=\"regex\" value=\"regex\" id=\"" + dialog.idPrefix + "RE\" " + (isRegex ? 'checked' : '') + ">\n      <span>Use regular expressions</span>\n    </label>\n    <textarea class=\"" + cssClass('textarea') + "\" required rows=\"5\" placeholder=\"e.g. Test,a.*\" id=\"" + dialog.idPrefix + "T\">" + current.map(function (d) { return typeof d === 'string' ? d : d.source; }).join('\n') + "</textarea>\n    <button class=\"" + cssClass('dialog-button') + "\" id=\"" + dialog.idPrefix + "A\">Apply</button>\n  ");
    var button = node.querySelector("#" + dialog.idPrefix + "A");
    var isRegexCheck = node.querySelector("#" + dialog.idPrefix + "RE");
    var groups = node.querySelector("#" + dialog.idPrefix + "T");
    button.onclick = function (evt) {
        evt.preventDefault();
        evt.stopPropagation();
        var items = groups.value.trim().split('\n').map(function (d) { return d.trim(); }).filter(function (d) { return d.length > 0; });
        var invalid = items.length === 0;
        groups.setCustomValidity(invalid ? 'At least one group is required' : '');
        if (invalid) {
            groups.reportValidity(); // typedoc not uptodate
            return;
        }
        if (isRegexCheck.checked) {
            items = items.map(function (d) { return new RegExp(d.toString(), 'gm'); });
        }
        col.setGroupCriteria(items);
    };
}
//# sourceMappingURL=groupString.js.map