<%= form_for(@screen) do |f| %>
  <%= render partial: "layouts/errors", object: @screen %>

  <fieldset>
    <legend><span><%= t('.provide_details') %></span></legend>


    <div class="row-fluid">
      <div class="span4">
        <div class="clearfix">
          <%= f.label :name %>
          <div class="input">
            <%= f.text_field :name, class: "input-xlarge", autofocus: true %>
          </div>
        </div>

        <div class="clearfix">
          <%= f.label :location %>
          <div class="input">
            <%= f.text_field :location, class: "input-xlarge" %>
          </div>
        </div>

        <div class="clearfix">
          <%= f.label :time_zone %>
        	<div class="input">
        	  <%= f.time_zone_select :time_zone, ActiveSupport::TimeZone.us_zones, default: ConcertoConfig[:system_time_zone]  %>
        	</div>
        </div>

        <% if ConcertoConfig['public_concerto'] %>
          <div class="clearfix">
            <div class="input checkbox">
              <ul class="inputs-list">
                <li><%= f.check_box :is_public %> <%= f.label :is_public %></li>
              </ul>
            </div>
          </div>
        <% end %>

      </div>
      <div class="span4">
        <div class="clearfix">
          <%= f.label :owner %>
          <div class="input">
            <% if can?(:manage, :all)
                 @users = User.order('last_name ASC')
                 @groups = Group.order('name ASC')
               else
                 @users = [current_user]
                 @groups = current_user.leading_groups + current_user.supporting_groups(:screen, [:all])
               end
               options = {}
               if !@users.empty?
                 options[User] = @users.map { |u| [u.name, "User-#{u.id}"]}
               end
               if !@groups.empty?
                 options[Group] = @groups.map { |g| [g.name, "Group-#{g.id}"] }
               end
            %>

            <%= render partial: "elements/owner_select", locals: { options: options, screen: @screen} %>
            <%= f.hidden_field :owner_type %>
            <%= f.hidden_field :owner_id %>
           </div>
        </div>

    <div class="clearfix">
      <label><%= t('.authentication') %></label>

      <div class="input checkbox">
        <ul class="inputs-list">
          <% if @screen.unsecured? %>
            <li>
              <%= f.radio_button(:auth_action, Screen::AUTH_NO_SECURITY) %>
              <%= f.label(:auth_action, t('.no_auth'), value: Screen::AUTH_NO_SECURITY) %>
            </li>
            <li>
              <%= f.radio_button(:auth_action, Screen::AUTH_NEW_TOKEN) %>
              <%= f.label(:auth_action, t('.new_token'), value: Screen::AUTH_NEW_TOKEN) %>
            </li>
          <% elsif @screen.auth_by_token? or @screen.auth_in_progress? %>
            <li>
              <%= f.radio_button(:auth_action, Screen::AUTH_KEEP_TOKEN) %>
              <%= f.label(:auth_action, t('.private_token'), value: Screen::AUTH_KEEP_TOKEN) %>
            </li>
            <li>
              <%= f.radio_button(:auth_action, Screen::AUTH_NO_SECURITY) %>
              <%= f.label(:auth_action, t('.no_auth'), value: Screen::AUTH_NO_SECURITY) %>
            </li>
            <li>
              <%= f.radio_button(:auth_action, Screen::AUTH_NEW_TOKEN) %>
              <%= f.label(:auth_action, t('.new_token_override'), value: Screen::AUTH_NEW_TOKEN) %>
            </li>
          <% elsif @screen.auth_by_mac? %>
            <li>
              <%= f.radio_button(:auth_action, Screen::AUTH_LEGACY_SCREEN) %>
              <%= f.label(:auth_action, value: Screen::AUTH_LEGACY_SCREEN) do %>
                <%= t '.existing_mac' %>
                <strong><%= @screen.mac_address %></strong>
              <% end %>
            </li>
            <li>
              <%= f.radio_button(:auth_action, Screen::AUTH_NO_SECURITY) %>
              <%= f.label(:auth_action, t('.no_auth'), value: Screen::AUTH_NO_SECURITY) %>
            </li>
            <li>
              <%= f.radio_button(:auth_action, Screen::AUTH_NEW_TOKEN) %>
              <%= f.label(:auth_action, t('.new_token'), value: Screen::AUTH_NEW_TOKEN) %>
            </li>
          <% end %>
        </ul>
      </div>
    </div>

    <div class="clearfix sub-fields" id="screen_new_temp_token_container">
      <%= f.label :new_temp_token %>
      <div class="input">
        <%= f.text_field :new_temp_token, class: "input-xlarge" %>
      </div>
    </div>

      </div>

    </div>

  </fieldset>

  <%= render partial: 'template_selection', locals: { f: f } %>

  <div class="submit_bar actions">
    <%= f.submit button_text, class: "btn btn-primary" %>
    <%= link_to t(:cancel), (@screen.persisted? ? screen_path : screens_path), class: "btn" %>
  </div>
<% end %>
