{{-- Profile edit form --}}

@extends('layouts.app')

@section('content')
  @php(Widget::setLayout(3, 7))

  <form method="POST" action="{{route('account.store')}}" class="row justify-content-center" aria-label="Account Settings">
    @csrf

    <div class="col-md-10">
      {!! Widget::header(1, 'Account Settings') !!}

      {!! Widget::par('
        Profile info can be changed on the
        <a href="'.e(route('profile.edit')).'">profile settings</a> page.
        ', 'text-muted', false) !!}
    </div>

    <div class="col-md-10 mt-3">
      {!! Widget::header(2, 'Identifiers') !!}

      {!! Widget::par('Caution: Changing username will alter URLs of your tables.') !!}
      {!! Widget::text('name', 'Username')->value($user->name)->required()
            ->prepend('@')
            ->help('This is part of your vanity URL, and can be also used to login') !!}

      {!! Widget::par('E-mail change will apply after you confirm the new address.
      We will send you a confirmation link when you submit the form.', 'text-justify') !!}
      {!! Widget::email('email', 'E-Mail Address')->value($user->email)->required()
            ->help('Used to login and for password resets.') !!}
    </div>

    <div class="col-md-10 mt-3">
      {!! Widget::header(2, 'Password Change') !!}
      {!! Widget::par('Leave empty to keep your current password (if any).') !!}

      {!! Widget::password('new_password', 'New Password') !!}

      {!! Widget::password('new_password_confirmation', 'Confirm New Password') !!}
    </div>

    <div class="col-md-10 mt-2">
      <div class="row form-group">
        <div class="col-md-7 offset-md-3">
          <button type="submit" class="btn btn-primary">
            @icon(fa-save fa-pr)Apply Changes
          </button>
        </div>
      </div>
    </div>

    <div class="col-md-10 mt-3">
      {!! Widget::header(2, 'OAuth2 Logins') !!}
      {!! Widget::par('
          Here you can remove identities you do not wish to use anymore.
          To completely revoke the authorization, also remove the app
          from your provider\'s settings.
      ', 'text-justify')!!}

      <?php
        $icons = [
          'github' => 'github',
          'facebook' => 'facebook-square',
          'google' => 'google',
        ];
      ?>

      @if(!count($user->socialIdentities))
        <div class="row form-group">
          <div class="col-md-7 offset-md-3 border border-primary border-dashed rounded">
            No identities connected.
          </div>
        </div>
      @else
        @foreach($user->socialIdentities as $identity)
          <div class="row form-group">
            <div class="col-md-3 col-form-label text-md-right">
              <a href="{{route('forget-identity', ['id' => $identity->getKey()])}}" class="btn btn-danger" role="button">Forget</a>
            </div>
            <div class="col-md-7 border border-primary rounded p-1 pl-0">
              <table>
                <tr>
                  <td rowspan=4>
                    <i class="fa-{{ $icons[$identity->provider] }} fa-huge py-3 px-4" aria-hidden=true></i>
                    <span class="sr-only">{{ucfirst($identity->provider)}}</span>
                  </td>
                  <th>Nickname</th>
                  <td class="pl-2">{{ $identity->nick_name }}</td>
                </tr>
                <tr>
                  <th>Full Name</th>
                  <td class="pl-2">{{ $identity->full_name }}</td>
                </tr>
                <tr>
                  <th>E-Mail</th>
                  <td class="pl-2">{{ $identity->email }}</td>
                </tr>
                <tr>
                  <th>User ID</th>
                  <td class="pl-2">{{ $identity->provider_user_id }}</td>
                </tr>
              </table>
            </div>
          </div>
        @endforeach
      @endif

      {!! Widget::par(
        'Click the buttons below to add a new OAuth2 identity.
        You will be redirected to the authorization form.',
        'text-justify'
      )!!}

      <div class="row form-group">
        <div class="col-md-3 col-form-label text-md-right">
          Add identity
        </div>
        <ul class="col-md-7 sr-list">
          @set('services.oauth_providers.github.client_id')
          <li>
            <a type="submit" href="{{route('oauth-github-authorize')}}" class="btn btn-dark">
              @icon(fa-github fa-pr){{ __('GitHub') }}
            </a>
          @endset

          @set('services.oauth_providers.google.client_id')
          <li>
            <a type="submit" href="{{route('oauth-google-authorize')}}" class="btn btn-dark">
              @icon(fa-google fa-pr){{ __('Google') }}
            </a>
          @endset

          @set('services.oauth_providers.facebook.client_id')
          <li>
            <a type="submit" href="{{route('oauth-facebook-authorize')}}" class="btn btn-dark">
              @icon(fa-facebook-square fa-pr){{ __('Facebook') }}
            </a>
          @endset
        </ul>
      </div>
    </div>
  </form>

@endsection