
// Admin Menu - Version Dialog Settings

function showCustomTextarea() {
    var selectedOptionValue = $("#version_dialog_mode option:selected").val();

    if (selectedOptionValue === "custom_text" || selectedOptionValue === "both") {
        $('#version_dialog_custom_textarea').show();
    } else {
        $('#version_dialog_custom_textarea').hide();
    }
}

$(document).ready(function () {
    showCustomTextarea();
});

$('#version_dialog_mode').on('change', function () {
    showCustomTextarea();
});

function markdownToHTML() {
    var markdownContent = $('#markdownDiv').text();
    var converter = new showdown.Converter({
        simplifiedAutoLink: true
    });
    var html = converter.makeHtml(markdownContent);
    $('#formattedHTMLDiv').html(html);
}

function displayVersionDialog() {

	$.ajax({
		url: base_url + "index.php/Version_Dialog/displayVersionDialog",
		type: 'GET',
		dataType: 'html',
		success: function(data) {
			$('body').append(data);

			var versionDialogModal = new bootstrap.Modal(document.getElementById('versionDialogModal'));
			versionDialogModal.show();
			markdownToHTML();
		},
		error: function() {
			console.log('Error loading the versiondialog view.');
		}
	});
}

function dismissVersionDialog() {
	$.ajax({
		url: base_url + 'index.php/user_options/dismissVersionDialog',
		method: 'POST',
	});
}
