jQuery(function(a){WCML_Currency_Switcher_Settings={_currency_languages_saving:0,init:function(){a(document).ready(function(){a(document).on("change","#currency_switcher_style",WCML_Currency_Switcher_Settings.update_currency_switcher_style),a(document).on("click",".currency_switcher_save",WCML_Currency_Switcher_Settings.save_currency_switcher_settings),a(document).on("click",".delete_currency_switcher",WCML_Currency_Switcher_Settings.delete_currency_switcher),a(document).on("change",".js-wcml-cs-colorpicker-preset",WCML_Currency_Switcher_Settings.set_currency_switcher_color_pre_set),a(document).on("keyup",'input[name="wcml_curr_template"]',WCML_Currency_Switcher_Settings.setup_currency_switcher_template_keyup),a(document).on("change",'input[name="wcml_curr_template"]',WCML_Currency_Switcher_Settings.setup_currency_switcher_template_change),WCML_Currency_Switcher_Settings.open_dialog_from_hash()})},initColorPicker:function(){a(".wcml-ui-dialog .js-wcml-cs-panel-colors").find(".js-wcml-cs-colorpicker").wpColorPicker({change:function(b){var c=a(this).closest(".wcml-ui-dialog");WCML_Currency_Switcher_Settings.currency_switcher_preview(c)},clear:function(b){var c=a(this).closest(".wcml-ui-dialog");WCML_Currency_Switcher_Settings.currency_switcher_preview(c)}})},save_currency_switcher_settings:function(){var b=a(this).closest(".wcml-ui-dialog"),c=a(''),d=b.find("#wcml-cs-widget option:selected").text(),e=b.find("#wcml_currencies_switcher_id").val(),f=b.find("#wcml-cs-widget").val(),g=b.find('input[name="wcml_cs_widget_title"]').val(),h=b.find("#currency_switcher_style").val();c.show(),a(this).parent().append(c),b.find(":submit,:button").prop("disabled",!0);var i=b.find('input[name="wcml_curr_template"]').val();i||(i=b.find("#currency_switcher_default").val());var j={};return b.find("input.js-wcml-cs-colorpicker").each(function(){j[a(this).attr("name")]=a(this).val()}),a.ajax({type:"POST",dataType:"json",url:ajaxurl,data:{action:"wcml_currencies_switcher_save_settings",wcml_nonce:b.find("#wcml_currencies_switcher_save_settings_nonce").val(),switcher_id:e,widget_id:f,widget_title:g,switcher_style:h,template:i,color_scheme:j},success:function(g){if(b.find(".ui-dialog-titlebar-close").trigger("click"),void 0===f&&(f=e),a("#wcml_currency_switcher_options_form_new_widget #wcml-cs-widget option").each(function(){a(this).val()==f&&a(this).remove()}),0==a("#wcml_currency_switcher_options_form_new_widget #wcml-cs-widget option").length&&a(".wcml_add_cs_sidebar").fadeOut(),a("#currency-switcher-widget .wcml-cs-list").find("thead tr").is(":hidden")&&a("#currency-switcher-widget .wcml-cs-list").find("thead tr").fadeIn(),0==a(".wcml-currency-preview."+f).length){var h=a(".wcml-cs-empty-row").clone();h.removeClass("wcml-cs-empty-row"),h.find(".wcml-currency-preview").addClass(f),h.find(".wcml-cs-widget-name").html(d),h.find(".edit_currency_switcher").attr("data-switcher",f),h.find(".edit_currency_switcher").attr("data-dialog","wcml_currency_switcher_options_"+f),h.find(".edit_currency_switcher").attr("data-content","wcml_currency_switcher_options_"+f),h.find(".delete_currency_switcher").attr("data-switcher",f),h.show(),a(".wcml-cs-list").find("tr.wcml-cs-empty-row").before(h),a(".wcml-cs-list").is(":hidden")&&a(".wcml-cs-list").fadeIn()}a("#wcml_currency_switcher_options_"+f).remove(),b.find(".wcml-dialog-container").attr("id","wcml-dialog-wcml_currency_switcher_options_"+f),b.find(":submit,:button").prop("disabled",!1),b.find("#wcml_currencies_switcher_id").val(f),c.remove(),WCML_Currency_Switcher_Settings.currency_switcher_preview(b,!0)}}),!1},delete_currency_switcher:function(b){b.preventDefault();var c=a(this).data("switcher"),d=a(this).closest("tr"),e=a('');a(this).parent().html(e),a.ajax({type:"POST",dataType:"json",url:ajaxurl,data:{action:"wcml_delete_currency_switcher",wcml_nonce:a("#wcml_delete_currency_switcher_nonce").val(),switcher_id:c},success:function(b){var e=d.find(".wcml-cs-widget-name").html();a("#wcml_currency_switcher_options_form_new_widget #wcml-cs-widget").append('"),d.remove(),1==a("#currency-switcher-widget .wcml-cs-list").find("tbody tr").length&&a("#currency-switcher-widget .wcml-cs-list").find("thead tr").fadeOut(),a(".wcml_add_cs_sidebar").is(":hidden")&&a(".wcml_add_cs_sidebar").fadeIn()}})},currency_switcher_preview:_.debounce(function(b,c){var d=b.find('input[name="wcml_curr_template"]').val();d||(d=b.find("#currency_switcher_default").val());var e=a('');b.find("#wcml_curr_sel_preview_wrap").append(e);var f={};b.find("input.js-wcml-cs-colorpicker").each(function(){f[a(this).attr("name")]=a(this).val()});var g=b.find("#wcml_currencies_switcher_id").val(),h=b.find("#currency_switcher_style").val();a.ajax({type:"POST",url:ajaxurl,dataType:"json",data:{action:"wcml_currencies_switcher_preview",wcml_nonce:b.find("#wcml_currencies_switcher_preview_nonce").val(),switcher_id:g,switcher_style:h,template:d,color_scheme:f},success:function(d){d.success&&(d=d.data,0==a("#"+d.inline_styles_id).length?a("head").append('"):a("#"+d.inline_styles_id).html(d.inline_css),e.remove(),c?("new_widget"==g&&(g=b.find("#wcml-cs-widget").val()),a(".wcml-currency-preview."+g).html(d.preview)):b.find(".wcml-currency-preview").html(d.preview),"wcml-dropdown-click"==h&&WCMLCurrecnySwitcherDropdownClick.init())}})},500),set_currency_switcher_color_pre_set:function(){var b=a(this).val(),c=a(this).closest(".wcml-ui-dialog");if("undefined"!=settings.pre_selected_colors[b]){var d,e=settings.pre_selected_colors[b];for(d in e)a('.wcml-ui-dialog input[name="'+d+'"]').val(e[d]),a('.wcml-ui-dialog input[name="'+d+'"]').closest(".wp-picker-container").find(".wp-color-result").css("background-color",e[d])}WCML_Currency_Switcher_Settings.currency_switcher_preview(c)},update_currency_switcher_style:function(b){var c=a(this).closest(".wcml-ui-dialog");WCML_Currency_Switcher_Settings.currency_switcher_preview(c)},setup_currency_switcher_template_keyup:function(b){var c=a(this).closest(".wcml-ui-dialog");discard=!0,a(this).closest(".wcml-section").find(".button-wrap input").css("border-color","#1e8cbe"),WCML_Currency_Switcher_Settings.currency_switcher_preview(c)},setup_currency_switcher_template_change:function(b){a(this).val()||a(this).val(a("#currency_switcher_default").val())},open_dialog_from_hash:function(){var b=window.location.hash.substring(1).split("/"),c=b[0]||"",d=b[1]||"";"currency-switcher"==c&&(a('.edit_currency_switcher[data-switcher="'+d+'"]').trigger("click"),parent.location.hash="")}},WCML_Currency_Switcher_Settings.init()});