import jQuery from "jquery";
import { state } from "./editor";
import { listAllSpaces } from "../../datasets/datasets";
import { SPACE } from "../../config";

/**
 * Initiates all the handlers for button presses and input changes.
 */
export function initInteractions() {
    jQuery("button#clear-collection").on("click", () => {
        state.clearSelectedItems();
    });

    // Fill space dropdown
    var selectContainer = jQuery("#space-id-select");
    listAllSpaces().then((spaces) => {
        spaces.forEach(space => {
            var selectedTxt = "";
            if (space === SPACE) {
                selectedTxt = "selected ";
            }

            var child = "<option " + selectedTxt + "value=\"" + space + "\">" + space + "</option>"
            selectContainer.append(child);
        });
    });
    selectContainer.val(SPACE);
}