!function(t){"use strict";var e=/\{\{(\d+)\}\}/g;function a(e){var a=t("#lwTemplateBody"),n=a[0].selectionStart,l=a[0].selectionEnd,r=a.val().substring(n,l),c=a.val().substring(0,n)+e+r+e+a.val().substring(l);a.val(c),a[0].selectionStart=a[0].selectionEnd=n+r.length+2,a.focus(),t("#lwTemplateBody").trigger("input"),__DataRequest.updateModels({text_body:c})}t("#lwTemplateBody").on("input",(function(){!function(a){var n=function(e,a){var n=e.match(a),l=[];if(n){t.each(n,(function(e,a){-1===t.inArray(a,l)&&l.push(a)})),l.sort((function(t,e){return Number(t.match(/\d+/)[0])-Number(e.match(/\d+/)[0])}));var r=l.reduce((function(t,e,a){return t[e.match(/\d+/)[0]]=a+1,t}),{});return e.replace(a,(function(t){var e=t.match(/\d+/)[0];return"{{".concat(r[e],"}}")}))}return e}(a,/\{\{\d+\}\}/g);t("#lwTemplateBody").val(n);var l={},r=n.match(e);if(r)for(var c=0;c<r.length;c++){var o={text_variable:r[c],text_variable_value:r[c]};l[r[c].replace(/\{\{(\d+)\}\}/g,"$1")]=o,__DataRequest.updateModels({newBodyTextInputFields:l})}else __DataRequest.updateModels({newBodyTextInputFields:l})}(t(this).val())})),t("#lwAddPlaceHolder").click((function(){!function(){var e=t("#lwTemplateBody"),a=e.val(),n=e.prop("selectionStart"),l=/\{\{\d+\}\}/g,r=a.match(l)||[],c=0;r.forEach((function(t){var e=parseInt(t.match(/\d+/)[0],10);e>c&&(c=e)}));var o=a.substring(0,n),i=a.substring(n,a.length),u=o+" {{".concat(c+1,"}} ")+i;e.val(u);var d=n+" {{".concat(c+1,"}} ").length;e[0].selectionStart=e[0].selectionEnd=d,e.focus(),t("#lwTemplateBody").trigger("input"),__DataRequest.updateModels({text_body:u})}()})),t("#lwHeaderTextBody").on("input",(function(){t(this).val().match(e)?__DataRequest.updateModels({enableHeaderVariableExample:!0}):__DataRequest.updateModels({enableHeaderVariableExample:!1})})),t("#lwAddSinglePlaceHolder").click((function(){var e=t("#lwHeaderTextBody"),a=e.val(),n=e.prop("selectionStart"),l=a.substring(0,n)+" {{1}}"+a.substring(n,a.length);e.val(l),t("#lwHeaderTextBody").trigger("input"),__DataRequest.updateModels({header_text_body:l})})),t("#lwBoldBtn").click((function(){a("*")})),t("#lwItalicBtn").click((function(){a("_")})),t("#lwStrikeThroughBtn").click((function(){a("~")})),t("#lwCodeBtn").click((function(){a("```")}))}(jQuery);