(e=>{"function"==typeof define&&define.amd?define("repeaterField",e):e()})(function(){function u(e){return(u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}jQuery(function(f){function e(){f(".resturant-menu-repeater").each(function(){var p=f(this),c=p.find("[data-repeater-list]"),s=p.find("[data-repeater-create]");c.length&&"function"==typeof f.fn.sortable&&!c.hasClass("ui-sortable")&&c.sortable({animation:150,handle:".repeater-drag-handle",placeholder:"sortable-placeholder",forcePlaceholderSize:!0,helper:"clone",appendTo:p,items:"> [data-repeater-item]",start:function(e,t){t.placeholder.height(t.item.outerHeight()),t.item.addClass("sortable-dragging")},stop:function(e,t){t.item.removeClass("sortable-dragging"),c.children("[data-repeater-item]").each(function(i){f(this).find("input, textarea, select").each(function(){var e,t=f(this),a=t.attr("name");a&&(e=a.replace(/\[\d+\](\[[^\]]+\])$/,"["+i+"]$1"))!==a&&t.attr("name",e)})}),c.trigger("repeater:reordered",{item:t.item,newIndex:t.item.index()})}}),c.off("click.repeaterDuplicate").on("click.repeaterDuplicate",".repeater-duplicate-action",function(e){e.preventDefault();var e=f(this).closest("[data-repeater-item]"),t=parseInt(p.attr("data-selection-limit"),10);if(!isNaN(t)&&0<t&&t<=c.find("[data-repeater-item]").length)return;var a,i,n,r,o,d={},t=(e.find("input, textarea, select").each(function(){var e=f(this),t=e.attr("name");t&&(t=t.match(/\[([^\]]+)\]$/))&&t[1]&&(t=t[1],e.is(":checkbox")?d[t]=e.prop("checked"):e.is(":radio")?e.prop("checked")&&(d[t]=e.val()):e.is('input[type="file"]')||(d[t]=e.val()))}),s.trigger("click"),c.find("[data-repeater-item]:last")),l=(t.find("input, textarea, select").each(function(){var e=f(this),t=e.attr("name");t&&(t=t.match(/\[([^\]]+)\]$/))&&t[1]&&(t=t[1],d.hasOwnProperty(t))&&(e.is(":checkbox")?e.prop("checked",d[t]):e.is(":radio")?e.val()===d[t]?e.prop("checked",!0):e.prop("checked",!1):e.is('input[type="file"]')||e.val(d[t]))}),"mylisting_accordion_photo");d.hasOwnProperty(l)&&d[l]&&(a=d[l],(l=t.find('input[type="file"][name$="['+l+']"]')).length)&&l.attr("name")&&(i=l.attr("name"),(n=t.find('input[type="hidden"][name="'+i+'"]')).length||(n=f('<input type="hidden">').attr("name",i).addClass("input-text outer-photo"),l.after(n)),n.val(a),(n=t.find(".job-manager-uploaded-files")).empty(),a&&"object"===("undefined"==typeof CASE27?"undefined":u(CASE27))&&CASE27.js_field_html_img&&((r=f(f.parseHTML(CASE27.js_field_html_img))).find(".job-manager-uploaded-file-preview img").attr("src",a),(o=r.find(".input-text")).val(a),o.attr("name","current_"+i),n.append(r),"function"==typeof RemoveUploadedFile)&&RemoveUploadedFile(n),l.val("")),"function"==typeof RepeaterUploadFiles&&RepeaterUploadFiles(t),t.trigger("repeater:item:duplicated",{originalItem:e.get(0),newItem:t.get(0)}),f(document).trigger("mylisting:refresh-scripts")})})}function t(){f(".resturant-menu-repeater").each(function(){var e,a=f(this),i=a.find("[data-repeater-list]"),n=a.find("[data-repeater-create]"),r=parseInt(a.attr("data-selection-limit"),10);function t(){var e=i.find("[data-repeater-item]"),t=e.filter(":visible").length,t=0<t?t:e.length;r<=t?(a.find(".repeater-duplicate-action").prop("disabled",!0).addClass("disabled"),n.prop("disabled",!0).addClass("disabled")):(a.find(".repeater-duplicate-action").prop("disabled",!1).removeClass("disabled"),n.prop("disabled",!1).removeClass("disabled"))}isNaN(r)||r<=0||(t(),e=new MutationObserver(function(e){e.forEach(function(e){"childList"===e.type&&t()})}),i.length&&i.get(0)&&e.observe(i.get(0),{childList:!0}),n.on("click",function(){setTimeout(t,50)}))})}function a(){var e=f(".resturant-menu-repeater[data-uploaded-list]");e.length&&("function"==typeof RepeaterUploadFiles?e.find("[data-repeater-item]").each(function(){RepeaterUploadFiles(f(this))}):setTimeout(a,500))}e(),t(),a(),f(document).on("repeater-initialized c27-tab-changed",function(){e(),t(),a()})})});
