import { round, getNumberOfBins } from '../../internal';
import { forEach } from '../../renderer/utils';
import { cssClass } from '../../styles';
/** @internal */
export default function append(col, node, dialog) {
    var domain = col.getMapping().domain;
    var current = col.getGroupThresholds();
    var isThreshold = current.length <= 1;
    var ranking = col.findMyRanker();
    node.insertAdjacentHTML('beforeend', "\n    <label class=\"" + cssClass('checkbox') + "\">\n      <input type=\"radio\" name=\"threshold\" value=\"threshold\" " + (isThreshold ? 'checked' : '') + ">\n      <span>at&nbsp;<input type=\"number\" size=\"10\" id=\"" + dialog.idPrefix + "N1\" value=\"" + (current.length > 0 ? current[0] : round((domain[1] - domain[0]) / 2, 2)) + "\"\n          required min=\"" + domain[0] + "\" max=\"" + domain[1] + "\" step=\"any\" " + (!isThreshold ? 'disabled' : '') + ">\n      </span>\n    </label>\n    <label class=\"" + cssClass('checkbox') + "\">\n      <input type=\"radio\" name=\"threshold\" value=\"bins\" " + (!isThreshold ? 'checked' : '') + ">\n      <span> in&nbsp;<input type=\"number\" size=\"5\" id=\"" + dialog.idPrefix + "N2\" value=\"" + (current.length > 1 ? current.length : getNumberOfBins(ranking.getOrderLength())) + "\"\n          required min=\"2\" step=\"1\" " + (isThreshold ? 'disabled' : '') + ">&nbsp;bins\n      </span>\n    </label>\n  ");
    var threshold = node.querySelector("#" + dialog.idPrefix + "N1");
    var bins = node.querySelector("#" + dialog.idPrefix + "N2");
    var update = function () {
        threshold.disabled = !isThreshold;
        bins.disabled = isThreshold;
        if (isThreshold) {
            col.setGroupThresholds([threshold.valueAsNumber]);
            return;
        }
        var count = parseInt(bins.value, 10);
        var delta = (domain[1] - domain[0]) / count;
        var act = domain[0] + delta;
        var thresholds = [act];
        for (var i = 1; i < count - 1; ++i) {
            act += delta;
            thresholds.push(act);
        }
        col.setGroupThresholds(thresholds);
    };
    threshold.addEventListener('change', update, { passive: true });
    bins.addEventListener('change', update, { passive: true });
    forEach(node, 'input[name=threshold]', function (d) {
        d.addEventListener('change', function () {
            isThreshold = d.value === 'threshold';
            update();
        }, { passive: true });
    });
}
//# sourceMappingURL=groupNumber.js.map