jQuery(document).ready(function(t){let e=dinaProvinceCityData.data;function i(){let e=[];t(".dina-city-list li").each(function(){let i=t(this).data();e.push({state_code:i.stateCode,state_label:i.stateLabel,city_code:i.cityCode,city_label:i.cityLabel})}),t(".dina-redux-province-city-json").val(JSON.stringify(e)).trigger("change")}t(".dina-province-city-wrapper").on("change",".dina-province-select",function(){let i=t(this).val();!function i(n){let a=t(".dina-city-select");a.empty().append('<option value="">'+dinaProvinceCityData.i18n.selectcity+"</option>"),n&&e[n]&&(e[n].cities.forEach(function(t){a.append('<option value="'+t.code+'">'+t.label+"</option>")}),a.prop("disabled",!1),a.hasClass("select2-hidden-accessible")&&a.select2("destroy"),a.select2({dir:dinaProvinceCityData.direction,width:"200px",placeholder:dinaProvinceCityData.i18n.selectcity,language:{noResults:function(){return dinaProvinceCityData.i18n.noresult}}}))}(i)}),t(".dina-province-city-wrapper").on("click",".dina-add-city",function(){let n=t(".dina-province-select").val(),a=t(".dina-city-select").val();if(!n||!a)return;let c=e[n],l=c.cities.find(function(t){return t.code===a}),o=t('<li data-state-code="'+n+'" data-state-label="'+c.label+'" data-city-code="'+a+'" data-city-label="'+l.label+'">'+c.label+" - "+l.label+'<button type="button" class="dina-remove-city button-link">'+dinaProvinceCityData.i18n.delete+"</button></li>");t(".dina-city-list").append(o),i()}),t(".dina-province-city-wrapper").on("click",".dina-remove-city",function(){t(this).closest("li").remove(),i()});try{let n=JSON.parse(t(".dina-redux-province-city-json").val()||"[]");n.forEach(function(e){let i=t('<li data-state-code="'+e.state_code+'" data-state-label="'+e.state_label+'" data-city-code="'+e.city_code+'" data-city-label="'+e.city_label+'">'+e.state_label+" - "+e.city_label+'<button type="button" class="dina-remove-city button-link">'+dinaProvinceCityData.i18n.delete+"</button></li>");t(".dina-city-list").append(i)})}catch(a){console.warn("Invalid initial province-city JSON")}!function i(){let n=t(".dina-province-select");t.each(e,function(t,e){n.append('<option value="'+t+'">'+e.label+"</option>")}),n.select2({dir:dinaProvinceCityData.direction,width:"200px",placeholder:dinaProvinceCityData.i18n.selectprovince,language:{noResults:function(){return dinaProvinceCityData.i18n.noresult}}})}()});