@extends('layouts.app-mobile-partner')
@section('title', 'Partner Dashboard — Befikreyy')
@section('apptitle', 'Dashboard')

@section('content')

{{-- Greeting hero --}}
<section class="partner-hero">
    <div class="partner-hero-bg"></div>
    <div class="partner-hero-content">
        <div class="hello-row">
            <div>
                <div class="hello-eyebrow">{{ greeting_label_partner() }}, Partner</div>
                <h2 class="hello-name">{{ explode(' ', $user->name)[0] }} <span class="hello-wave">👋</span></h2>
                <p class="hello-sub">{{ $profile->display_name }} · {{ $profile->experience_years ?? 0 }}y experience</p>
            </div>
            <div class="hello-av">{{ strtoupper(substr($user->name, 0, 1)) }}</div>
        </div>

        <div class="partner-kpis">
            <div class="pa-kpi">
                <span class="kpi-num">{{ $stats['today'] }}</span>
                <span class="kpi-lbl">Today</span>
            </div>
            <div class="pa-kpi">
                <span class="kpi-num">{{ $stats['pending'] }}</span>
                <span class="kpi-lbl">Upcoming</span>
            </div>
            <div class="pa-kpi">
                <span class="kpi-num">{{ $stats['completed'] }}</span>
                <span class="kpi-lbl">Done</span>
            </div>
            <div class="pa-kpi">
                <span class="kpi-num">{{ $stats['rating'] }}★</span>
                <span class="kpi-lbl">Rating</span>
            </div>
        </div>
    </div>
</section>

{{-- Today's schedule --}}
@if($today_visits->count())
<section class="app-section">
    <div class="section-h">
        <h3>📍 Today's schedule</h3>
        <a href="{{ route('pa.visits', ['tab' => 'today']) }}" class="link-sm">All today →</a>
    </div>
    <div class="today-list">
        @foreach($today_visits as $v)
            <a href="{{ route('pa.visit', $v) }}" class="today-row">
                <div class="today-time">
                    <strong>{{ $v->scheduled_slot ?? '10:00 AM' }}</strong>
                    <span>{{ $v->booking->area->name ?? '—' }}</span>
                </div>
                <div class="today-info">
                    <strong>{{ $v->booking->service->name ?? 'Service' }}</strong>
                    <span class="muted">{{ $v->booking->customer->name ?? 'Customer' }} · {{ $v->booking->customer->phone ?? '' }}</span>
                </div>
                <span class="visit-pill visit-pill-{{ $v->status }}">{{ ucfirst(str_replace('_',' ',$v->status)) }}</span>
            </a>
        @endforeach
    </div>
</section>
@endif

{{-- Upcoming visits --}}
<section class="app-section">
    <div class="section-h">
        <h3>🗓 Upcoming visits</h3>
    </div>
    @if($upcoming->count())
        <div class="upcoming-list">
            @foreach($upcoming as $v)
                <a href="{{ route('pa.visit', $v) }}" class="upcoming-row">
                    <div class="up-date">
                        <strong>{{ $v->scheduled_date->format('d') }}</strong>
                        <span>{{ $v->scheduled_date->format('M') }}</span>
                    </div>
                    <div class="up-info">
                        <strong>{{ $v->booking->service->name ?? 'Service' }}</strong>
                        <span class="muted">{{ $v->scheduled_slot }} · {{ $v->booking->area->name ?? '—' }}</span>
                    </div>
                    <span class="visit-pill visit-pill-scheduled">{{ ucfirst($v->status) }}</span>
                </a>
            @endforeach
        </div>
    @else
        <div class="empty-app">
            <div class="ea-ic">📅</div>
            <h3>No upcoming visits</h3>
            <p>You're all caught up! New visits will appear here.</p>
        </div>
    @endif
</section>

{{-- Schedule / Attendance / Leave cards --}}
<section class="app-section">
    <div class="schedule-hub">
        <a href="{{ route('pa.bookings') }}" class="sh-card">
            <x-icon name="bookings" :size="22" class="shc-ic" />
            <div class="shc-info">
                <strong>My bookings</strong>
                <span class="muted">Add & manage customer subscriptions</span>
            </div>
            <span class="caret">›</span>
        </a>
        <a href="{{ route('pa.schedule') }}" class="sh-card">
            <x-icon name="calendar" :size="22" class="shc-ic" />
            <div class="shc-info">
                <strong>Monthly schedule</strong>
                <span class="muted">See all visits in calendar</span>
            </div>
            <span class="caret">›</span>
        </a>
        <a href="{{ route('pa.attendance') }}" class="sh-card">
            <x-icon name="pin" :size="22" class="shc-ic" />
            <div class="shc-info">
                <strong>Mark attendance</strong>
                <span class="muted">Check in / out with photo proof</span>
            </div>
            <span class="caret">›</span>
        </a>
        <a href="{{ route('pa.leaves') }}" class="sh-card">
            <x-icon name="leaf" :size="22" class="shc-ic" />
            <div class="shc-info">
                <strong>Apply for leave</strong>
                <span class="muted">Request a day off</span>
            </div>
            <span class="caret">›</span>
        </a>
        <a href="{{ route('pa.team.index') }}" class="sh-card">
            <x-icon name="profile" :size="22" class="shc-ic" />
            <div class="shc-info">
                <strong>My team</strong>
                <span class="muted">Helpers who can take visits for you</span>
            </div>
            <span class="caret">›</span>
        </a>
    </div>
</section>

{{-- Trust strip --}}
<section class="app-section">
    <div class="trust-strip">
        <div class="trust-item">
            <span class="ic">🛡️</span>
            <div><strong>Verified</strong><small>Aadhaar + police verified</small></div>
        </div>
        <div class="trust-item">
            <span class="ic">💸</span>
            <div><strong>Weekly payout</strong><small>Direct to your UPI/bank</small></div>
        </div>
    </div>
</section>

<div class="app-footer-link">
    <a href="{{ route('pa.about') }}">About this app</a> ·
    <a href="{{ route('pa.contact') }}">Contact</a> ·
    <a href="{{ route('home') }}" target="_blank">Open website</a>
</div>

@php
function greeting_label_partner() {
    $h = (int) date('H');
    if ($h < 12) return 'Good morning';
    if ($h < 17) return 'Good afternoon';
    return 'Good evening';
}
@endphp

@endsection