(function(e){var t=Upfront.Settings&&Upfront.Settings.l10n?Upfront.Settings.l10n.global.views:Upfront.mainData.l10n.global.views;define(["scripts/upfront/bg-settings/mixins"],function(n){var r=Upfront.Views.Editor.Settings.Item.extend(_.extend({},n,{group:!1,initialize:function(n){var r=this,i=this.model.get_property_value_by_name("background_map_center"),s=function(){var e=this.get_value();this.model.set_breakpoint_property(this.property_name,e)};i||(this.model.init_property("background_map_center",[10.72225,106.730762]),this.model.init_property("background_map_zoom",10),this.model.init_property("background_map_style","ROADMAP"),this.model.init_property("background_map_controls",""),this.model.init_property("background_show_markers",""));var o={location:new Upfront.Views.Editor.Field.Text({model:this.model,label:t.location+":",property:"background_map_location",use_breakpoint_property:!0,placeholder:"e.g 123 Nice St",change:function(){var e=this.get_value();this.model.set_breakpoint_property(this.property_name,e,!0),r._location=e,r._location_changed=!0},rendered:function(){this.$el.addClass("uf-bgsettings-map-location")}}),refresh:new Upfront.Views.Editor.Field.Button({label:"",compact:!0,classname:"upfront-field-icon upfront-field-icon-refresh-2 upfront-refresh-map",on_click:function(){var e=r.$el.find('input[name="background_map_location"]');e.length&&(r._location=e.val()),r._location_changed=!0,r.geocode_location()}}),zoom:new Upfront.Views.Editor.Field.Slider({model:this.model,label:t.zoom+":",property:"background_map_zoom",use_breakpoint_property:!0,default_value:8,min:1,max:19,step:1,change:s,rendered:function(){this.$el.addClass("uf-bgsettings-map-zoom")}}),style:new Upfront.Views.Editor.Field.Select({model:this.model,label:t.map_style+":",property:"background_map_style",use_breakpoint_property:!0,values:[{label:t.roadmap,value:"ROADMAP"},{label:t.satellite,value:"SATELLITE"},{label:t.hybrid,value:"HYBRID"},{label:t.terrain,value:"TERRAIN"}],change:s,rendered:function(){this.$el.addClass("uf-bgsettings-map-style")}}),controls:new Upfront.Views.Editor.Field.Select({model:this.model,label:t.controls+":",placeholder:t.choose_ctrl,property:"background_map_controls",use_breakpoint_property:!0,multiple:!0,default_value:["pan"],values:[{label:t.pan,value:"pan"},{label:t.zoom,value:"zoom"},{label:t.map_type,value:"map_type"},{label:t.scale,value:"scale"},{label:t.street_view,value:"street_view"},{label:t.overview_map,value:"overview_map"}],change:s,rendered:function(){this.$el.addClass("uf-bgsettings-map-controls")}}),show_markers:new Upfront.Views.Editor.Field.Checkboxes({model:this.model,label:t.show_markers,property:"background_show_markers",use_breakpoint_property:!0,hide_label:!0,values:[{label:t.show_markers,value:1}],multiple:!1,change:s,rendered:function(){this.$el.addClass("uf-bgsettings-map-show-marker")}})};this.$el.addClass("uf-bgsettings-item uf-bgsettings-mapitem"),n.fields=_.map(o,function(e){return e}),this._location=o.location.get_value(),this.$el.on("keypress",'input[name="background_map_location"]',function(t){t.keyCode===13&&(r._location=e(this).val(),r._location_changed=!0,r.geocode_location())}),this.bind_toggles(),this.constructor.__super__.initialize.call(this,n)},geocode_location:function(){if(this._geocoding==1||!this._location_changed)return;var e=this,t=this._location,n=new google.maps.Geocoder;if(!t)return;this._geocoding=!0,n.geocode({address:t},function(t,n){if(n!=google.maps.GeocoderStatus.OK)return!1;var r=t[0].geometry.location;e.model.set_breakpoint_property("background_map_center",[r.lat(),r.lng()]),e._geocoding=!1,e._location_changed=!1})}}));return r})})(jQuery);