<%= render 'tabs', user: current_user %>

<h1>Edit Profile</h1>

<% if defined?(@user) && @user.errors.any? %>
  <div class="notice is-danger">
    There were some errors while saving your profile:

    <ul>
      <% @user.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
    </ul>
  </div>
<% end %>

<%= form_for current_user, url: update_user_profile_path do |f| %>
  <div class="form-group has-padding-2">
  <img alt="user avatar" class="has-float-right has-margin-2" title="Current avatar" src="<%= avatar_url(current_user, 64) %>" height="64" width="64" />
    <%= f.label :avatar, class: "form-element" %>
    <div class="form-caption">
      An optional profile picture. Max file size <%= SiteSetting['MaxUploadSize'] %>.
    </div>
    <%= f.file_field :avatar, class: "form-element" %>
  </div>
  <div class="has-clear-clear"></div>

  <div class="form-group has-padding-2">
    <%= f.label :username, class: "form-element" %>
    <div class="form-caption">What other people call you.</div>
    <%= f.text_field :username, class: 'form-element', autocomplete: 'off' %>
  </div>

  <%= render 'shared/body_field', f: f, field_name: :profile_markdown, field_label: 'Profile', post: current_user %>

  <div class="post-preview"></div>

  <div class="form-group-horizontal">
    <div class="form-group">
      <%= f.label :website, class: "form-element" %>
      <div class="form-caption">A link to anywhere on the internet for your stuff.</div>
      <%= f.text_field :website, class: 'form-element', autocomplete: 'off' %>
    </div>

    <div class="form-group">
      <%= f.label :twitter, class: "form-element" %>
      <div class="form-caption">Your Twitter username, if you've got one you want to share.</div>
      <%= f.text_field :twitter, class: 'form-element', autocomplete: 'off' %>
    </div>
  </div>

  <%= f.submit 'Save', class: 'button is-very-large is-filled' %>
<% end %>

<% unless SiteSetting['AllowContentTransfer'] %>
  <h2>Link with Stack Exchange</h2>
  <div class="notice is-warning">
    You can't link a Stack Exchange account to your account on this site because there is no associated
    Stack Exchange site from which to transfer your content.
  </div>
<% end %>

<% if SiteSetting['AllowContentTransfer'] && current_user.se_acct_id.nil? %>
  <div class="has-padding-4">
    <h2>Link with Stack Exchange</h2>
    <p>
      If you have an account on Stack Exchange, you can link it to your account here. Once your accounts are linked,
      you'll be able to request that any content you created on Stack Exchange that has been copied across here is
      transferred to you.
    </p>
    <%= link_to stack_oauth_url, class: 'button is-outlined' do %>
      <i class="fab fa-stack-exchange"></i> Authenticate
    <% end %>
  </div>
<% elsif SiteSetting['AllowContentTransfer'] && !current_user.transferred_content %>
  <div class="has-padding-4">
    <h3>Claim your Stack Exchange content</h3>
    <p>
      Your account has a <a href="https://stackexchange.com/users/<%= current_user.se_acct_id %>">linked Stack Exchange account</a>.
      You can use the button below to have your content from Stack Exchange that has been copied here transferred to you.
    </p>
    <%= form_tag claim_stack_content_path do %>
      <div class="notice is-warning has-margin-top-4 has-margin-bottom-4">
        <i class="fas fa-exclamation-circle"></i>
        <strong>To claim your Stack Exchange content, we need you to agree to re-license your posts.</strong><br/>
        When you posted on Stack Exchange, you granted Stack Exchange a CC BY-SA license to distribute your content; that's
        what lets us display your content here too, as long as we attribute it back to you on Stack Exchange. When you claim your
        content, we'll remove that attribution link to Stack Exchange and link it to you here instead, but we need you to grant us
        a license under <%= license_link %> to do so.
        <div class="checkbox has-margin-top-4">
          <%= label_tag :agree_to_relicense, class: "form-element" do %>
            <%= check_box_tag :agree_to_relicense, 'true', class: "form-element-checkbox" %>
            I agree to relicense my posts to <%= SiteSetting['SiteName'] %> under <%= license_link %>.
          <% end %>
        </div>
      </div>
      <%= submit_tag 'Claim Content', name: nil, class: 'button is-outlined' %>
    <% end %>
  </div>
<% end %>