@extends('layouts.app')

@section('title', 'ড্যাশবোর্ড - আমবাগান যুব কল্যাণ সমিতি')

@section('styles')
<style>
    .profile-card {
        border-radius: 10px;
        overflow: hidden;
    }
    
    .profile-header {
        background: linear-gradient(135deg, #1a5f7a, #2a9d8f);
        padding: 30px;
        color: white;
    }
    
    .profile-avatar {
        width: 100px;
        height: 100px;
        border-radius: 50%;
        border: 3px solid white;
        object-fit: cover;
    }
    
    .info-card {
        border-left: 4px solid #1a5f7a;
        border-radius: 8px;
        margin-bottom: 20px;
    }
    
    .info-card.saving {
        border-left-color: #28a745;
    }
    
    .info-card.loan {
        border-left-color: #dc3545;
    }
    
    .info-card.notice {
        border-left-color: #17a2b8;
    }
    
    .info-card.meeting {
        border-left-color: #ffc107;
    }
    
    .card-icon {
        font-size: 2rem;
        opacity: 0.8;
    }
    
    .quick-action {
        border: 1px solid #dee2e6;
        border-radius: 8px;
        padding: 20px;
        text-align: center;
        transition: all 0.3s;
        height: 100%;
    }
    
    .quick-action:hover {
        background-color: #f8f9fa;
        transform: translateY(-5px);
    }
    
    .quick-action-icon {
        font-size: 2rem;
        margin-bottom: 10px;
        color: #1a5f7a;
    }
</style>
@endsection

@section('breadcrumbs')
<nav aria-label="breadcrumb">
    <ol class="breadcrumb bg-light">
        <li class="breadcrumb-item active">ড্যাশবোর্ড</li>
    </ol>
</nav>
@endsection

@section('content')
<div class="container-fluid">
    <!-- প্রোফাইল কার্ড -->
    <div class="card profile-card mb-4">
        <div class="profile-header">
            <div class="row align-items-center">
                <div class="col-md-2 text-center">
                    @if($member->photo)
                    <img src="{{ asset('storage/' . $member->photo) }}" alt="Profile" class="profile-avatar">
                    @else
                    <div class="profile-avatar bg-light d-flex align-items-center justify-content-center">
                        <i class="fas fa-user fa-3x text-dark"></i>
                    </div>
                    @endif
                </div>
                <div class="col-md-10">
                    <h3 class="mb-2">{{ $member->name }}</h3>
                    <p class="mb-1">
                        <i class="fas fa-id-card me-2"></i>সদস্য নং: {{ $member->member_id }}
                    </p>
                    <p class="mb-1">
                        <i class="fas fa-phone me-2"></i>ফোন: {{ $member->phone }}
                    </p>
                    <p class="mb-1">
                        <i class="fas fa-envelope me-2"></i>ইমেইল: {{ $member->email }}
                    </p>
                    <p class="mb-0">
                        <i class="fas fa-calendar-alt me-2"></i>যোগদান: {{ date('d/m/Y', strtotime($member->join_date)) }}
                    </p>
                </div>
            </div>
        </div>
    </div>
    
    <!-- তথ্য কার্ড -->
    <div class="row mb-4">
        <div class="col-md-3">
            <div class="card info-card saving">
                <div class="card-body">
                    <div class="d-flex align-items-center">
                        <div class="card-icon text-success me-3">
                            <i class="fas fa-piggy-bank"></i>
                        </div>
                        <div>
                            <h5 class="card-title mb-1">{{ number_format($totalSavings, 2) }} টাকা</h5>
                            <p class="card-text mb-0">মোট সঞ্চয়</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="col-md-3">
            <div class="card info-card loan">
                <div class="card-body">
                    <div class="d-flex align-items-center">
                        <div class="card-icon text-danger me-3">
                            <i class="fas fa-hand-holding-usd"></i>
                        </div>
                        <div>
                            <h5 class="card-title mb-1">{{ $activeLoans->count() }}</h5>
                            <p class="card-text mb-0">চলমান ঋণ</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="col-md-3">
            <div class="card info-card">
                <div class="card-body">
                    <div class="d-flex align-items-center">
                        <div class="card-icon text-warning me-3">
                            <i class="fas fa-balance-scale"></i>
                        </div>
                        <div>
                            <h5 class="card-title mb-1">{{ number_format($totalLoanBalance, 2) }} টাকা</h5>
                            <p class="card-text mb-0">বকেয়া ঋণ</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="col-md-3">
            <div class="card info-card">
                <div class="card-body">
                    <div class="d-flex align-items-center">
                        <div class="card-icon text-info me-3">
                            <i class="fas fa-calendar-check"></i>
                        </div>
                        <div>
                            <h5 class="card-title mb-1">{{ $member->monthlySavings()->where('status', 'paid')->count() }}</h5>
                            <p class="card-text mb-0">পরিশোধিত মাস</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <!-- চলমান ঋণ -->
    @if($activeLoans->count() > 0)
    <div class="row mb-4">
        <div class="col-md-12">
            <div class="card">
                <div class="card-header">
                    <h5 class="card-title mb-0">
                        <i class="fas fa-hand-holding-usd me-2"></i>আমার চলমান ঋণ
                    </h5>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-hover">
                            <thead>
                                <tr>
                                    <th>ঋণ নং</th>
                                    <th>ধরন</th>
                                    <th>পরিমাণ</th>
                                    <th>বকেয়া</th>
                                    <th>মাসিক কিস্তি</th>
                                    <th>স্ট্যাটাস</th>
                                    <th>কার্যক্রম</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach($activeLoans as $loan)
                                <tr>
                                    <td>LN-{{ str_pad($loan->id, 4, '0', STR_PAD_LEFT) }}</td>
                                    <td>{{ $loan->loan_type_in_bangla }}</td>
                                    <td>{{ number_format($loan->loan_amount, 2) }} টাকা</td>
                                    <td>
                                        <span class="badge bg-warning">
                                            {{ number_format($loan->remaining_balance, 2) }} টাকা
                                        </span>
                                    </td>
                                    <td>{{ number_format($loan->monthly_installment, 2) }} টাকা</td>
                                    <td>
                                        <span class="badge bg-{{ $loan->status == 'active' ? 'success' : 'info' }}">
                                            {{ $loan->status_in_bangla }}
                                        </span>
                                    </td>
                                    <td>
                                        <a href="{{ route('loans.show', $loan) }}" class="btn btn-sm btn-outline-primary">
                                            <i class="fas fa-eye"></i>
                                        </a>
                                    </td>
                                </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    @endif
    
    <!-- দ্রুত কার্যক্রম -->
    <div class="row mb-4">
        <div class="col-md-12">
            <div class="card">
                <div class="card-header">
                    <h5 class="card-title mb-0">
                        <i class="fas fa-bolt me-2"></i>দ্রুত কার্যক্রম
                    </h5>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-3 mb-3">
                            <a href="{{ route('savings.history') }}" class="quick-action">
                                <div class="quick-action-icon">
                                    <i class="fas fa-history"></i>
                                </div>
                                <h6>সঞ্চয় ইতিহাস</h6>
                                <p class="text-muted small">আপনার সমস্ত সঞ্চয় দেখুন</p>
                            </a>
                        </div>
                        
                        <div class="col-md-3 mb-3">
                            <a href="{{ route('loans.my-loans') }}" class="quick-action">
                                <div class="quick-action-icon">
                                    <i class="fas fa-file-invoice-dollar"></i>
                                </div>
                                <h6>আমার ঋণ</h6>
                                <p class="text-muted small">ঋণ বিবরণ ও কিস্তি</p>
                            </a>
                        </div>
                        
                        <div class="col-md-3 mb-3">
                            <a href="{{ route('notices.index') }}" class="quick-action">
                                <div class="quick-action-icon">
                                    <i class="fas fa-bullhorn"></i>
                                </div>
                                <h6>নোটিশ বোর্ড</h6>
                                <p class="text-muted small">সকল নোটিশ দেখুন</p>
                            </a>
                        </div>
                        
                        <div class="col-md-3 mb-3">
                            <a href="{{ route('meetings.index') }}" class="quick-action">
                                <div class="quick-action-icon">
                                    <i class="fas fa-calendar-alt"></i>
                                </div>
                                <h6>মিটিং</h6>
                                <p class="text-muted small">আসন্ন ও পুরাতন মিটিং</p>
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <!-- সাম্প্রতিক নোটিশ এবং মিটিং -->
    <div class="row">
        <!-- সাম্প্রতিক নোটিশ -->
        <div class="col-md-6">
            <div class="card info-card notice">
                <div class="card-header">
                    <div class="d-flex justify-content-between align-items-center">
                        <h5 class="card-title mb-0">
                            <i class="fas fa-bullhorn me-2"></i>সাম্প্রতিক নোটিশ
                        </h5>
                        <a href="{{ route('notices.index') }}" class="btn btn-sm btn-outline-primary">
                            সব দেখুন
                        </a>
                    </div>
                </div>
                <div class="card-body">
                    @if(count($recentNotices) > 0)
                    @foreach($recentNotices as $notice)
                    <div class="mb-3 pb-3 border-bottom">
                        <h6 class="mb-2">
                            <a href="{{ route('notices.show', $notice) }}" class="text-decoration-none">
                                {{ $notice->title }}
                            </a>
                            @if($notice->is_important)
                            <span class="badge bg-danger ms-2">গুরুত্বপূর্ণ</span>
                            @endif
                        </h6>
                        <p class="mb-2 small text-muted">{{ Str::limit(strip_tags($notice->content), 80) }}</p>
                        <div class="d-flex justify-content-between">
                            <small class="text-muted">
                                <i class="fas fa-user me-1"></i>
                                {{ $notice->creator->name ?? 'অজানা' }}
                            </small>
                            <small class="text-muted">
                                <i class="fas fa-calendar me-1"></i>
                                {{ $notice->created_at->format('d/m/Y') }}
                            </small>
                        </div>
                    </div>
                    @endforeach
                    @else
                    <div class="text-center py-3">
                        <i class="fas fa-bell-slash fa-2x text-muted mb-3"></i>
                        <p class="text-muted">কোনো নোটিশ পাওয়া যায়নি</p>
                    </div>
                    @endif
                </div>
            </div>
        </div>
        
        <!-- আসন্ন মিটিং -->
        <div class="col-md-6">
            <div class="card info-card meeting">
                <div class="card-header">
                    <div class="d-flex justify-content-between align-items-center">
                        <h5 class="card-title mb-0">
                            <i class="fas fa-calendar-alt me-2"></i>আসন্ন মিটিং
                        </h5>
                        <a href="{{ route('meetings.index') }}" class="btn btn-sm btn-outline-primary">
                            সব দেখুন
                        </a>
                    </div>
                </div>
                <div class="card-body">
                    @if(count($upcomingMeetings) > 0)
                    @foreach($upcomingMeetings as $meeting)
                    <div class="mb-3 pb-3 border-bottom">
                        <h6 class="mb-2">{{ $meeting->title }}</h6>
                        <p class="mb-2 small text-muted">
                            <i class="fas fa-map-marker-alt me-1"></i>{{ $meeting->location }}
                        </p>
                        <div class="d-flex justify-content-between">
                            <small class="text-muted">
                                <i class="fas fa-calendar-day me-1"></i>
                                {{ date('d/m/Y', strtotime($meeting->date)) }}
                            </small>
                            <small class="text-muted">
                                <i class="fas fa-clock me-1"></i>
                                {{ date('h:i A', strtotime($meeting->time)) }}
                            </small>
                        </div>
                        <div class="mt-2">
                            <a href="{{ route('meetings.show', $meeting) }}" class="btn btn-sm btn-outline-primary">
                                বিস্তারিত
                            </a>
                        </div>
                    </div>
                    @endforeach
                    @else
                    <div class="text-center py-3">
                        <i class="fas fa-calendar-times fa-2x text-muted mb-3"></i>
                        <p class="text-muted">কোনো আসন্ন মিটিং নেই</p>
                    </div>
                    @endif
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

@section('scripts')
<script>
$(document).ready(function() {
    // ঋণ তথ্য টগল
    $('.loan-details-btn').click(function() {
        const loanId = $(this).data('loan-id');
        $('#loanDetails-' + loanId).toggle();
    });
});
</script>
@endsection