<%= if Enum.count(@car_settings) > 0 do %> <%= if Enum.count(@car_settings) > 1 do %>
<% end %> <.form :let={f} for={get_in(@car_settings, [@car, :changeset])} phx-change="change" as={:"car_settings_#{@car}"} >

<%= gettext("Data Collection") %>

<%= label(f, :enabled, gettext("Enabled"), class: "label") %>
<%= checkbox(f, :enabled, class: "switch is-rounded is-success") %> <%= label(f, :enabled, nil) %>

<%= gettext("Sleep Mode") %>

<%= unless Ecto.Changeset.get_field(f.source, :use_streaming_api) do %>
<%= label(f, :suspend_min, gettext("Time to Try Sleeping"), class: "label") %>
<%= select( f, :suspend_min, (Enum.filter(12..30, &(rem(&1, 3) == 0)) ++ Enum.filter(35..90, &(rem(&1, 5) == 0))) |> Enum.map(&{"#{&1} #{gettext("min")}", &1}) ) %>

<%= error_tag(f, :suspend_min) %>

<%= label(f, :suspend_after_idle_min, gettext("Idle Time Before Trying to Sleep"), class: "label" ) %>
<%= select( f, :suspend_after_idle_min, 3..60 |> Enum.filter(&(&1 == 3 or rem(&1, 5) == 0)) |> Enum.map(&{"#{&1} #{gettext("min")}", &1}) ) %>

<%= error_tag(f, :suspend_after_idle_min) %>

<% end %>

<%= gettext("Charge cost") %>

<%= label(f, :free_supercharging, gettext("Free Supercharging"), class: "label") %>
<%= checkbox(f, :free_supercharging, class: "switch is-rounded is-success") %> <%= label(f, :free_supercharging, nil) %>

<%= gettext("Streaming API") %>

<%= label(f, :use_streaming_api, gettext("Enabled"), class: "label") %>
<%= checkbox(f, :use_streaming_api, class: "switch is-rounded is-success") %> <%= label(f, :use_streaming_api, nil) %>

<%= gettext("Battery") %>

<%= label(f, :lfp_battery, gettext("LFP Battery"), class: "label") %>
<%= checkbox(f, :lfp_battery, class: "switch is-rounded is-success") %> <%= label(f, :lfp_battery, nil) %>
<% end %>
<%= gettext("General Settings") %>
<.form :let={f} for={@global_settings.changeset} phx-change="change">

<%= gettext("Range") %>

<%= label f, :preferred_range, class: "label has-tooltip-multiline", data_tooltip: gettext("The car's estimate of remaining range is based on a fixed energy consumption in Wh/km. The Wh/km factor is determined by Tesla and is not country specific whereas the rated range is based on regulatory tests in the different markets for that vehicle.") do %> <%= gettext("Preferred Range") %>  <% end %>
<%= select(f, :preferred_range, [ {gettext("ideal"), :ideal}, {gettext("rated"), :rated} ]) %>

<%= error_tag(f, :preferred_range) %>

<%= gettext("Language") %>

<%= label(f, :ui, gettext("Web App"), class: "label") %>
<%= select(f, :ui, supported_ui_languages(), selected: @locale) %>
<%= label(f, :language, gettext("Addresses"), class: "label") %>
<%= select(f, :language, GlobalSettings.supported_languages(), disabled: !@addresses_migrated? or @refreshing_addresses? ) %>

<%= @refresh_error || error_tag(f, :language) %>

<%= gettext("Units") %>

<%= label(f, :unit_of_length, gettext("Length"), class: "label") %>
<%= select(f, :unit_of_length, [:km, :mi]) %>

<%= error_tag(f, :unit_of_length) %>

<%= label(f, :unit_of_temperature, gettext("Temperature"), class: "label") %>
<%= select(f, :unit_of_temperature, "°C": :C, "°F": :F) %>

<%= error_tag(f, :unit_of_temperature) %>

<%= label(f, :unit_of_pressure, gettext("Tire Pressure"), class: "label") %>
<%= select(f, :unit_of_pressure, [:bar, :psi]) %>

<%= error_tag(f, :unit_of_pressure) %>

<%= gettext("URLs") %>

<%= label(f, :base_url, gettext("Web App"), class: "label") %>
<%= text_input(f, :base_url, type: :url, class: "input", phx_debounce: "blur", placeholder: "teslamate.example.com" ) %>

<%= error_tag(f, :base_url) %>

<%= label(f, :grafana_url, gettext("Dashboards"), class: "label") %>
<%= text_input(f, :grafana_url, type: :url, class: "input", phx_debounce: "blur", placeholder: "grafana.example.com" ) %>

<%= error_tag(f, :grafana_url) %>

<%= gettext("Version") %> <%= Application.spec(:teslamate, :vsn) %><%= if @update do vsn = link @update, to: "https://github.com/teslamate-org/teslamate/releases", target: "_blank", rel: "noopener noreferrer" [" (", gettext("Update available"), ": ", vsn, ")"] end %>
<%= gettext("GitHub") %> <%= link("teslamate-org/teslamate", to: "https://github.com/teslamate-org/teslamate", target: "_blank", rel: "noopener noreferrer" ) %>
<%= gettext("Documentation") %> <%= link("docs.teslamate.org", to: "https://docs.teslamate.org", target: "_blank", rel: "noopener noreferrer" ) %>
<%= if TeslaMate.Api.signed_in?() and not TeslaMate.Import.enabled?() do %>
<% end %>