@extends('layout.main')
@section('body')
    @php
        $menu = 'Profile';
        $pageTitle = 'User Profile';
    @endphp

    @include('layout.navbar')
    @include('layout.sidebar')

    {{-- Main Content --}}
    <div class="main-container">
        <div class="pd-ltr-20 xs-pd-20-10">
            <div class="min-height-200px">
                <div class="page-header">
                    <div class="row">
                        <div class="col-md-6 col-sm-12">
                            <div class="title">
                                <h4>{{ $menu }}</h4>
                            </div>
                            <nav aria-label="breadcrumb" role="navigation">
                                <ol class="breadcrumb">
                                    <li class="breadcrumb-item"><a href="{{ route('dashboard.index') }}">Dashboard</a></li>
                                    @if (isset($pageTitle))
                                        <li class="breadcrumb-item active" aria-current="page">{{ $pageTitle }}</li>
                                    @else
                                        <li class="breadcrumb-item active" aria-current="page"></li>
                                    @endif
                                </ol>
                            </nav>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xl-4 col-lg-4 col-md-4 col-sm-12 mb-30">
                        <div class="pd-20 card-box height-50-p">
                            <div class="profile-photo">
                                <a href="modal" data-toggle="modal" data-target="#modal" class="edit-avatar">
                                    <i class="fa fa-pencil"></i>
                                </a>
                                @if (Auth::user()->profile_picture)
                                    <img src="{{ asset('storage/' . Auth::user()->profile_picture) }}" class="rounded-profile-picture">
                                @else
                                    <img src="{{ asset('vendors/images/user.png') }}">
                                @endif
                                <div class="modal fade center-modal" id="modal" tabindex="-1" role="dialog"
                                    aria-labelledby="modalLabel" aria-hidden="true">
                                    <div class="modal-dialog modal-dialog-centered" role="document">
                                        <div class="modal-content">
                                            <div class="modal-header">
                                                <h4 class="modal-title" id="myLargeModalLabel">Upload Profile</h4>
                                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                                            </div>
                                            <div class="modal-body">
                                                <form action="{{ '/update-profile-picture' }}" method="post" enctype="multipart/form-data">
                                                    @csrf
                                                    <div class="img-container text-center">
                                                        @if (Auth::user()->profile_picture)
                                                            <img
                                                                src="{{ asset('storage/' . Auth::user()->profile_picture) }}" class="img-fluid mx-auto mt-2" style="max-width: 100%; max-height: 200px;">
                                                        @else
                                                            <img src="{{ asset('vendors/images/user.png') }}" class="img-fluid mx-auto mt-2" style="max-width: 100%; max-height: 200px;">
                                                        @endif
                                                    </div>
                                            </div>
                                            <div class="modal-footer">
                                                <input type="file" class="form-control-file" id="profile_picture" name="profile_picture" accept="image/*">
                                            </div>
                                            <div class="modal-footer">
                                                <button type="button" class="btn btn-secondary" data-dismiss="modal">Batal</button>
                                                <button type="submit" class="btn btn-primary">Simpan</button>
                                                </form>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <h5 class="text-center h5 mb-0">{{ Auth::user()->name }}</h5>
                            <p class="text-center text-muted font-14">
                                {{ Auth::user()->role }}
                            </p>
                        </div>
                    </div>
                    <div class="col-xl-8 col-lg-8 col-md-8 col-sm-12 mb-30">
                        <div class="card-box height-100-p overflow-hidden">
                            <div class="profile-tab height-100-p">
                                <div class="tab height-100-p">
                                    <ul class="nav nav-tabs customtab" role="tablist">
                                        <li class="nav-item">
                                            <a class="nav-link active" data-toggle="tab" href="#profile"
                                                role="tab">Profile</a>
                                        </li>
                                        <li class="nav-item">
                                            <a class="nav-link" data-toggle="tab" href="#password"
                                                role="tab">Password</a>
                                        </li>
                                    </ul>
                                    <div class="tab-content">
                                        <!-- Profile -->
                                        <div class="tab-pane fade show active" id="profile" role="tabpanel">
                                            <div class="profile-setting">
                                                <form method="POST" action="{{ route('user-profile') }}"
                                                    class="needs-validation" novalidate="">
                                                    @csrf
                                                    <h4 class=" text-center text-blue h5 mt-3 mb-0">Data Diri
                                                    </h4>
                                                    <ul class="profile-edit-list row">
                                                        <li class="col-md-4">
                                                            <div class="form-group">
                                                                <label for="name">Nama</label>
                                                                <input id="name" type="text" class="form-control"
                                                                    name="name" value="{{ Auth::user()->name }}">
                                                                <div class="invalid-feedback">Please fill in your name
                                                                </div>
                                                            </div>
                                                            @if ($errors->has('name'))
                                                                <div class="alert alert-danger">
                                                                    {{ $errors->first('name') }}
                                                                </div>
                                                            @endif
                                                        </li>
                                                        <li class="col-md-4">
                                                            <div class="form-group">
                                                                <label for="name">Username</label>
                                                                <input id="name" type="text" class="form-control"
                                                                    name="username" value="{{ Auth::user()->username }}">
                                                                <div class="invalid-feedback">Please fill in your username
                                                                </div>
                                                            </div>
                                                            @if ($errors->has('username'))
                                                                <div class="alert alert-danger">
                                                                    {{ $errors->first('username') }}</div>
                                                            @endif
                                                        </li>
                                                        <li class="col-md-4">
                                                            <div class="form-group">
                                                                <label for="name">Email</label>
                                                                <input id="name" type="text" class="form-control"
                                                                    name="email" value="{{ Auth::user()->email }}">
                                                                <div class="invalid-feedback">Please fill in your email
                                                                </div>
                                                            </div>
                                                            @if ($errors->has('email'))
                                                                <div class="alert alert-danger">
                                                                    {{ $errors->first('email') }}</div>
                                                            @endif
                                                        </li>
                                                    </ul>
                                                    <div class="col-sm-12">
                                                        <div class="input-group mb-3 mx-auto">
                                                            <button class="btn btn-primary btn-lg btn-block"
                                                                type="submit">Simpan</button>
                                                        </div>
                                                    </div>
                                                </form>
                                            </div>
                                        </div>

                                        <!-- Password -->
                                        <div class="tab-pane fade" id="password" role="tabpanel">
                                            <div class="profile-setting">
                                                <form method="POST" action="{{ route('update-password') }}">
                                                    @csrf
                                                    <h4 class=" text-center text-blue h5 mt-3 mb-0">Data Password</h4>
                                                    <ul class="profile-edit-list row">
                                                        <li class="col-md-6">
                                                            <div class="form-group">
                                                                <label for="password">Password Lama</label>
                                                                <input id="password" type="text" class="form-control"
                                                                    name="password">
                                                                <div class="invalid-feedback">Please fill in your current
                                                                    password </div>
                                                            </div>
                                                            @if ($errors->has('password'))
                                                                <div class="alert alert-danger">
                                                                    {{ $errors->first('password') }}</div>
                                                            @endif
                                                        </li>
                                                        <li class="col-md-6">
                                                            <div class="form-group">
                                                                <label for="new_password">Password Baru</label>
                                                                <input id="new_password" type="text"
                                                                    class="form-control" name="new_password">
                                                                <div class="invalid-feedback">Please fill in your new
                                                                    password </div>
                                                            </div>
                                                            @if ($errors->has('new_password'))
                                                                <div class="alert alert-danger">
                                                                    {{ $errors->first('new_password') }}</div>
                                                            @endif
                                                        </li>
                                                    </ul>
                                                    <div class="col-sm-12">
                                                        <div class="input-group mb-3 mx-auto">
                                                            <button class="btn btn-primary btn-lg btn-block"
                                                                type="submit">Simpan</button>
                                                        </div>
                                                    </div>
                                                </form>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="footer-wrap pd-20 mb-20 card-box">
                <strong>Sistem Pendukung Keputusan Pemilihan Ekstrakurikuler Metode SMARTER</strong>
            </div>
        </div>
    </div>
@endsection
