<div class="row">
  <div class="col s12 m6 offset-m3">
    <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
      <% if resource.errors.any? %>
        <div class="card red lighten-3">
          <div class="card-content">
            <div class="card-title">Please fix the following errors:</div>
            <ul class="browser-default">
              <%= devise_error_messages! %>
            </ul>
          </div>
        </div>
      <% end %>

      <div class="card">
        <div class="card-content">
          <div class="card-title">
            Sign up for Notebook.ai
          </div>
          <div style="padding: 0 2em; padding-top: 1em">
            <%= image_tag 'logos/both-small.png', class: 'hide-on-small-only', style: 'width: 100%' %>
            <%= image_tag 'logos/book-small.png', class: 'hide-on-med-and-up', style: 'width: 100%' %>
          </div>

          <div class="field">
            <%= f.label 'Your name' %><br />
            <%= f.text_field :name, autofocus: true %>
          </div>

          <div class="field">
            <%= f.label :email %> <em>(This is the email you will log in with)</em><br />
            <%= f.email_field :email %>
          </div>

          <div class="field">
            <%= f.label :password %>
            <% if @minimum_password_length %>
            <em>(<%= @minimum_password_length %> characters minimum)</em>
            <% end %><br />
            <%= f.password_field :password, autocomplete: "off" %>
          </div>

          <div class="field">
            <%= f.label :password_confirmation %><br />
            <%= f.password_field :password_confirmation, autocomplete: "off" %>
          </div>

          <!--
          <div class="field">
            <%= f.label :promo_code %><br />
            <%= f.text_field :promo_code, value: 'LAUNCHPARTY', disabled: "disabled" %>
          </div>
          -->

          <%
            if params.key?('referral') ||  session.key?('referral')
              referral_code = params['referral'] || session['referral']
              referrer = ReferralCode.where(code: referral_code).first
              if referrer.present?
          %>
              <div class="row">
                <div class="col s12 m6">
                  <div class="field">
                    <%= f.label :referral_code %><br />
                    <%= f.text_field :referral_code, value: referral_code, readonly: true %>
                  </div>
                </div>
                <div class="col s12 m6">
                  <%= f.label 'The following user will receive credit for referring you' %><br />
                  <%= f.text_field :referral_user, value: referrer.user.name.split('@').first, disabled: "disabled" %>
                </div>
              </div>
          <%
              end
            end
          %>

          <div class="field">
            <%= f.label :email_updates do %>
              <%= f.check_box :email_updates %>
              <span>We're always working to improve Notebook.ai. Please leave this box checked if you'd like to receive occasional updates about
                what's new.</span>
            <% end %>
          </div>

          <div class="actions center" style="margin-top: 20px;">
            <%= f.submit "Sign up", class: 'btn btn-large blue' %>
            <p class="center">
              <br />
              <%= render "devise/shared/links" %>
            </p>
          </div>
        </div>
      </div>
    <% end %>
  </div>
</div>
