@extends('backend.layouts.app')
@section('title')
    {{ __('Customer Details') }}
@endsection
@section('content')
    <div class="main-content">
        <div class="page-title">
            <div class="container-fluid">
                <div class="row">
                    <div class="col">
                        <div class="title-content">
                            <h2 class="title">{{ __('Details of') . ' ' . $user->first_name . ' ' . $user->last_name }}
                            </h2>

                            <div class="d-flex">
                                <a href="{{ route('admin.user.login', ['id' => $user->id, 'redirect_path' => 'user.booking.checkout']) }}"
                                    class="title-btn green-btn me-2" target="_blank"><i
                                        data-lucide="diamond-plus"></i>{{ __('Book Now') }}</a>
                                <a href="{{ route('admin.user.index') }}" class="title-btn"><i
                                        data-lucide="corner-down-left"></i>{{ __('Back') }}</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="container-fluid">
            <div class="row justify-content-center">
                <div class="col-xxl-3 col-xl-6 col-lg-8 col-md-6 col-sm-12">
                    <div class="profile-card">
                        <div class="top">
                            <div class="avatar">
                                <div class="avatar-face">
                                    @if (null != $user->avatar)
                                        <div class="avatar-face">
                                            <img class="avatar-img" src="{{ asset($user->avatar) }}"
                                                alt="{{ $user->full_name }}" />
                                        </div>
                                    @else
                                        <div class="avatar-text">{{ $user->first_name[0] . $user->last_name[0] }}</div>
                                    @endif

                                    @if ($user->portfolio != null)
                                        <div class="port-badge"><img src="{{ asset($user->portfolio?->icon) }}" /></div>
                                    @endif
                                </div>
                            </div>
                            <div class="title-des">
                                <h4>{{ $user->first_name . ' ' . $user->last_name }}</h4>
                                <p>{{ ucwords($user->city) }}@if ($user->city != '')
                                        ,
                                    @endif{{ $user->country }}</p>
                                @if ($user->activities->count() > 0)
                                    @php
                                        $lastLogin = $user->activities->sortByDesc('created_at')->first();
                                        $lastLoginDateTime = optional($lastLogin)->created_at->format('d-m-Y H:i:s');
                                    @endphp
                                    <p>{{ __('Last Login:') }} {{ $lastLoginDateTime }}</p>
                                @else
                                    <p>{{ __('This user has not logged in yet.') }}</p>
                                @endif
                            </div>
                            <div class="btns">
                                @can('customer-login')
                                    <a href="{{ route('admin.user.login', $user->id) }}" target="_blank"
                                        class="site-btn-round green-btn" data-bs-toggle="tooltip" title=""
                                        data-bs-placement="top" data-bs-original-title="Login As User">
                                        <i data-lucide="user-plus"></i>
                                    </a>
                                @endcan

                                @can('customer-basic-manage')
                                    <a href="#" class="site-btn-round red-btn" id="deleteModal" data-bs-toggle="modal"
                                        data-bs-target="#delete" title="Delete User"><i data-lucide="trash-2"></i></a>

                                    <!-- Modal for Popup Box -->
                                    @include('backend.user.include.__delete_popup', ['id' => $user->id])
                                    <!-- Modal for Popup Box End-->
                                @endcan
                            </div>
                        </div>

                        <!-- User Status Update -->
                        @can('all-type-status')
                            @include('backend.user.include.__status_update')
                        @endcan
                        <!-- User Status Update End-->

                    </div>
                </div>

                <div class="col-xxl-9 col-xl-12 col-lg-12 col-md-12 col-sm-12">

                    <div class="site-tab-bars">
                        <ul class="nav nav-pills" id="pills-tab" role="tablist">
                            @canany(['customer-basic-manage', 'customer-change-password'])
                                <li class="nav-item" role="presentation">
                                    <a href="{{ route('admin.user.edit', $user->id) }}"
                                        class="nav-link {{ !request()->has('tab') ? 'active' : '' }}"><i
                                            data-lucide="user"></i>{{ __('Information') }}</a>
                                </li>
                            @endcanany

                            @can('payment-history')
                                <li class="nav-item" role="presentation">
                                    <a href="{{ route('admin.user.edit', ['user' => $user->id, 'tab' => 'transactions']) }}"
                                        class="nav-link {{ request('tab') == 'transactions' ? 'active' : '' }}"><i
                                            data-lucide="cast"></i>{{ __('Payment History') }}</a>
                                </li>
                            @endcan

                            @can('bookings-list')
                                <li class="nav-item" role="presentation">
                                    <a href="{{ route('admin.user.edit', ['user' => $user->id, 'tab' => 'bookings']) }}"
                                        class="nav-link {{ request('tab') == 'bookings' ? 'active' : '' }}"><i
                                            data-lucide="book-open-check"></i>{{ __('Bookings') }}</a>
                                </li>
                            @endcan
                        </ul>
                    </div>

                    <div class="tab-content" id="pills-tabContent">
                        <!-- basic Info -->
                        @canany(['customer-basic-manage', 'customer-change-password'])
                            @include('backend.user.include.__basic_info')
                        @endcanany

                        <!-- transaction -->
                        @can('payment-history-list')
                            @include('backend.user.include.__transactions')
                        @endcan

                        <!-- bookings -->
                        @can('bookings-list')
                            @include('backend.user.include.__bookings')
                        @endcan

                        <!-- ticket -->
                        @canany(['support-ticket-list', 'support-ticket-action'])
                            @include('backend.user.include.__ticket')
                        @endcan
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Modal for Send Email -->
    @can('customer-mail-send')
        @include('backend.user.include.__mail_send', [
            'name' => $user->first_name . ' ' . $user->last_name,
            'id' => $user->id,
        ])
    @endcan
    <!-- Modal for Send Email-->
@endsection

@section('script')
    <script>
        "use strict"

        $('#branch_id').select2();
        $('#country').select2();

        // Delete
        $('body').on('click', '#deleteModal', function() {
            var id = "{{ $user->id }}";

            var url = '{{ route('admin.user.destroy', ':id') }}';
            url = url.replace(':id', id);
            $('#deleteForm').attr('action', url);
            $('#delete').modal('toggle')
        });
    </script>
@endsection
