function openNewAccordionFields(collapseElement, arrow) {
    collapseAccordionPM(`#${collapseElement}`, `#${arrow}`);
    $("#OpenNewButton").toggleClass("hidden");
    $("#AddNewButton").toggleClass("hidden");
}

function setIsDirty(element, className) {
    const fieldsWrapper = $(element).closest(`.${className}`);

    if (!fieldsWrapper.hasClass("isDirty") && !fieldsWrapper.attr("id").includes("new")) {
        fieldsWrapper.addClass("isDirty");
    }
}

function collapseAccordionPM(id, element) {
    if ($(id).hasClass('in')) {
        $(id).removeClass('in');
        $(id).addClass('collapsed');
        $(element).addClass('collapsed');
    }
    else {
        $(id).addClass('in');
        $(id).removeClass('collapsed');
        $(element).removeClass('collapsed');
    }
}

function handleNewRow(newRow) {
    // Add new row at the end of modal
    $(".pm-accordion-wrapper").append(newRow);

    // Close row that is used for adding new experience
    $(".new-pm-accordion td:first-child").click();

    // Initiliaze everything in added row
    forEveryHTMLElement('.pm-accordion-wrapper .pm-accordion-row:last-child .js-switch', initializeSwitcheryByElement);
    forEveryHTMLElement('.pm-accordion-wrapper .pm-accordion-row:last-child .select2', initializeSelect2ByElement);

    // Open added row
    $(".pm-accordion-wrapper .pm-accordion-row:last-child td:first-child").click();
    $(".divided-content-main").animate({ scrollTop: $(document).height() }, 1000);
}
