<%
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
# Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
# This program is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free Software
# Foundation; either version 3.0 of the License, or (at your option) any later
# version.
#
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public License along
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
%>

<% readonly = !can_edit_user?(@user, current_user) %>

<%= form_for @user, url: update_user_path, method: :post do |f|  %>
  <%= hidden_field_tag :setting, "account" %>
  <div class="form-group">
    <div class="row">
      <div class="col-sm-6 mb-4">
        <%= f.label :name, t("settings.account.fullname"), class: "form-label" %>
        <div class="input-icon">
          <%= f.text_field :name, class: "form-control #{form_is_invalid?(@user, :name)}", placeholder: t("settings.account.fullname"), readonly: readonly %>
        </div>
      </div>

      <div class="col-sm-6 mb-4">
        <%= f.label :email, t("email"), class: "form-label" %>
        <div class="input-icon">
          <%= f.email_field :email, class: "form-control #{form_is_invalid?(@user, :email)}", placeholder: t("email"), readonly: readonly %>
        </div>
      </div>
    </div>
    
    <%= f.label :provider, t("settings.account.provider"), class: "form-label" %>
    <%= f.text_field :provider, class: "form-control", readonly: "" %>
    <br>
    <%= f.label :language, t("settings.account.language"), class: "form-label" %>
    <select id="language-dropdown" class="selectpicker show-tick w-50">
      <% language_options.each do |lang| %>
        <option value="<%=lang[1]%>" <%= 'selected' if lang[1] == @user.language %>><%= lang[0] %></option>
      <% end %>
    </select>
    <%= f.hidden_field :language, id: "user_language", value: @user.language %>


    <%= f.label :roles, t("settings.account.roles"), class: "form-label mt-5" %>
    <% if current_user.role.get_permission("can_manage_users") %>
      <select id="role-dropdown" class="selectpicker show-tick" >
        <% role_options.each do |role| %>
          <option value="<%=role.id%>"><%= translated_role_name(role) %></option>
        <% end %>
      </select>

      <%= f.hidden_field :role_id, id: "user_role_id", value: @user.role.id %>
    <% else %>
      <span style="<%= "background-color: #{role_colour(@user.role)};border-color: #{role_colour(@user.role)};" %>" class="tag custom-role-tag">
        <%= translated_role_name(@user.role) %>
      </span>
    <% end %>

    <%= f.label :image, t("settings.account.image"), class: "form-label mt-5" %>
    <div class="row">
      <div class="col-5 col-sm-2">
        <% if @user.image.blank? || !valid_url?(@user.image) %>
          <span class="avatar avatar-xxl mr-5 mt-2 bg-primary"><%= @user.name.first %></span>
        <% else %>
          <%= image_tag(@user.image, class: "avatar avatar-xxl mr-5 mt-2") %>
        <% end %>
      </div>
      <div class="col-7 col-sm-10 mt-5">
        <%= f.text_field :image, class: "form-control #{form_is_invalid?(@user, :image)}", placeholder: t("settings.account.image_url") %>
      </div>
    </div>
  </div>
  <div class="card-footer">
    <%= f.submit t("update"), class: "btn btn-primary float-right ml-4" %>

    <% if can_reset_password %>
      <%= link_to t("settings.account.reset_password"), admin_reset_path(user_uid: @user.uid), class: "btn btn-primary float-right" %>
    <% end %>
  </div>
<% end %>
