(function () {
    $(document).ready(function () {
        console.log("Initialization of slconv.js finished.");
        $("#slconv-btn-convert").click(function () {
            console.log("Convert button clicked");
            convert();
        });
    });

    async function convert() {
        console.log("Converting...");
        const inputText = $("#input-textarea").val();
        console.log(inputText);
        const matches = inputText.match(/\n/g);
        const matchCount = matches ? matches.length : 0;
        console.log("Number of matches (newlines):", matchCount);
        const outputText = inputText.replace(/\n/g, ' ');
        console.log(outputText);
        $("#output-textarea").val(outputText);
        $("#output-container-div").removeClass("visually-hidden");
        $("#rm-count").text(matchCount);
        await Neutralino.clipboard.writeText(outputText);
    }
})();