import{e as p}from"./editor-BwIo2Pkt.js";import{f as u}from"./file-manager-BqTxa2JX.js";import{a as m}from"./select2-kdrdsacH.js";import{a as s}from"./toast-BolBYJGe.js";import{$ as e}from"./jquery-BJllTr_o.js";import"./mapbox-Cpj98o6Y.js";import"./helper-DH3MvDof.js";import"./moment-BxhnadHa.js";u("file-uploader","image");m();p();e("#add_gap_filler").on("click",function(){const t=e("#question_text").val(),o=(t.match(/\{([A-Z])\}/g)||[]).map(a=>a.replace(/\{|\}/g,""));let i=null;for(let a=0;a<26;a++){const r=String.fromCharCode(65+a);if(!o.includes(r)){i=r;break}}if(i){const a=`{${i}}`;e("input[name='question_text']").val(t+" "+a)}else alert("Maximum 26 gap fillers allowed (A-Z).")});function c(t){e("#question-text-container").children().addClass("hidden"),e("#question-text-container").children().each(function(){e(this).find("input[name='question_text']").removeAttr("name")});const n=e(`#question_${t}_id`);n.removeClass("hidden"),n.find("input").attr("name","question_text")}c(e("#question_input_type").val());e("#question_input_type").on("change",function(){const t=e(this).val();c(t)});e("#explanation_type").on("change",function(){const t=e(this).val();e("#question-explanation").children().addClass("hidden"),e("#question-explanation").children().each(function(){e(this).find("input[name='question_explanation'], textarea[name='question_explanation']").removeAttr("name")});const n=e("#"+t);n.removeClass("hidden"),n.find("input, textarea").attr("name","question_explanation")});e("#question_type").on("change",function(){const t=e("#options_container");switch(t.children().remove(),e("#correct_answers_container").children().remove(),e("#gap_fillers").addClass("hidden"),e("#question_text_example").addClass("hidden"),e(this).val()){case"multiple_choice":break;case"single_choice":break;case"fill_in_the_blank":e("#gap_fillers").removeClass("hidden"),e("#question_text_example").removeClass("hidden");break;case"true_false":t.append(`<div class="space-y-4 border border-neutral-30 dark:border-neutral-500 p-3 rounded-lg  relative" id="meta-row-1">
                    <div class="input-group">
                        <div class="flex justify-between items-center py-2">
                            <label for="name" class="block mb-2 text-sm">Option - A</label>
                            <button type="button" class="btn btn-success correct_answer" data-id="1">
                                <i class="ph ph-check"></i>
                            </button>
                        </div>
                        <input type="text" class="text-input" readonly id="options-label-1" value="True" name="options[0][label]"
                                placeholder="Enter option" />
                        <input type="hidden" name="options[0][value]" id="options-value-1" value="True">
                        <span class="input-text-error"></span>
                    </div>
                </div>
                <div class="space-y-4 border border-neutral-30 dark:border-neutral-500 p-3 rounded-lg  relative" id="meta-row-2">
                    <div class="input-group">
                        <div class="flex justify-between items-center py-2">
                            <label for="name" class="block mb-2 text-sm">Option - B</label>
                            <button type="button" class="btn btn-success correct_answer" data-id="2">
                                <i class="ph ph-check"></i>
                            </button>
                        </div>
                        <input type="text" class="text-input" readonly id="options-label-2" value="False" name="options[1][label]"
                                placeholder="Enter option" />
                        <input type="hidden" name="options[1][value]" id="options-value-2" value="False">
                        <span class="input-text-error"></span>
                    </div>
                </div>
                `);break}});e("#extra_field_container").on("click",function(){const t=e("#options_container"),n=e("#question_type").val(),o=Date.now(),i=t.children().length,a=h(i);if(n=="true_false"&&i>1){s("Only True and False option is allowed");return}t.append(`<div class="space-y-4 border border-neutral-30 dark:border-neutral-500 p-3 rounded-lg  relative" id="meta-row-${o}">
            <div class="input-group">
                <div class="flex flex-col sm:flex-row sm:justify-between sm:items-center py-3 border-b border-gray-200 dark:border-gray-700">
                    <label for="name" class="text-sm font-medium text-gray-700 dark:text-gray-200 mb-2 sm:mb-0">
                        Option - ${a.toUpperCase()}
                    </label>

                    <div class="flex items-center gap-3 text-sm text-gray-600 dark:text-gray-400">
                        <span>Mark as correct answer</span>
                        <button type="button" class="correct_answer p-2 rounded-full hover:bg-green-100 dark:hover:bg-green-900 transition" data-id="${o}" aria-label="Mark as correct">
                            <i class="ph ph-check text-lg text-green-600 dark:text-green-400"></i>
                        </button>
                    </div>
                </div>
                <input type="text" class="text-input" id="options-label-${o}" value="" name="options[${i}][label]"
                        placeholder="Enter option" />
                <input type="hidden" name="options[${i}][value]" id="options-value-${o}" value="${a.toUpperCase()}">
                <span class="input-text-error"></span>
            </div>
            <button type="button" class="text-red-500 mt-2 delete-meta absolute right-0 -top-7" data-id="${o}">
                <i class="ph ph-trash"></i>
            </button>
        </div>`)});e(document).on("click",".delete-meta",function(){const t=e(this).data("id");e(`#meta-row-${t}`).remove()});e(document).on("click",".correct_answer",function(){const t=e(this).data("id"),n=e(`#options-value-${t}`).val();if(!e(`#options-label-${t}`).val()){s("Please enter option");return}if(e("#correct_answers_container").find(`input[value="${n}"]`).length){s("Already added");return}const a=e("#question_type").val();if(a=="true_false"){if(n!="True"&&n!="False"){s("Only True and False option is allowed");return}if(e("#correct_answers_container").children().length>0){s("Only one option is allowed");return}}if(a=="single_choice"&&e("#correct_answers_container").children().length>0){s("Only one option is allowed");return}const r=e("#correct_answers_container"),l=Date.now(),d=r.children().length;r.append(`<div class="flex items-center gap-2" id="meta-row-${l}">
            <span class="text-sm">${n}</span>
            <input type="hidden" name="correct_answers[${d}]" value="${n}">
            <button type="button" class="text-red-500 mt-2 delete-meta" data-id="${l}">
                <i class="ph ph-trash"></i>
            </button>
        </div>`)});function h(t){return String.fromCharCode(97+t)}
