@extends($activeTemplate . 'layouts.master') @section('content')
{{-- ── Header ──────────────────────────────────── --}}

@lang('Salary')

@lang('Earn weekly salary rewards based on team turnover')

{{-- ── Team Turnover Card ───────────────────────── --}}
turnover

@lang('Team Turnover')

{{ showAmount($teamTurnover) }} {{ gs('cur_sym') }}

{{-- ── Section Title ────────────────────────────── --}}
@lang('Salary Levels')
{{-- ── Salary Level Cards ───────────────────────── --}}
@php // Find the single best salary level the user currently matches $currentSalary = $salaries->where('min_turnover', '<=', $teamTurnover) ->filter(function($s) use ($teamTurnover) { return $s->max_turnover == 0 || $teamTurnover <= $s->max_turnover; }) ->sortByDesc('min_turnover') ->first(); $currentSalaryId = $currentSalary ? $currentSalary->id : null; @endphp @forelse($salaries as $salary) @php // Dynamic live logic: // 1. Locked: User hasn't reached this min_turnover yet $isLocked = $teamTurnover < $salary->min_turnover; // 2. Passed: This is a lower level than what the user currently qualifies for $isPassed = ($currentSalary && $salary->min_turnover < $currentSalary->min_turnover) || ($salary->max_turnover > 0 && $teamTurnover > $salary->max_turnover); // 3. Active: This is the EXACT live level matching the current turnover $isActive = $salary->id == $currentSalaryId; $lastClaim = \App\Models\UserSalaryLog::where('user_id', auth()->id()) ->where('user_salary_id', $salary->id) ->latest()->first(); $isActivated = $lastClaim ? true : false; // Fix: use copy() to avoid Carbon mutation bug $nextClaimAt = $isActivated ? $lastClaim->created_at->copy()->addMinutes(1) : null; $canCollect = true; // FORCED TRUE FOR DEMO // diffInSeconds($nextClaimAt) from now → positive = future seconds remaining $secsRemaining = ($isActivated && !$canCollect && $nextClaimAt) ? (int) $nextClaimAt->diffInSeconds(now()) : 0; // Progress toward this level (capped 0–100) $progress = 0; if ($salary->max_turnover > 0 && $salary->min_turnover >= 0) { $range = $salary->max_turnover - $salary->min_turnover; $progress = $range > 0 ? min(100, max(0, (($teamTurnover - $salary->min_turnover) / $range) * 100)) : ($teamTurnover >= $salary->min_turnover ? 100 : 0); } elseif ($salary->max_turnover == 0 && $salary->min_turnover > 0) { $progress = $teamTurnover >= $salary->min_turnover ? 100 : min(99, ($teamTurnover / $salary->min_turnover) * 100); } // Status label & colour if ($isPassed) { $statusLabel = 'Completed'; $statusClass = 'bg-green-500/20 text-green-400'; $iconSrc = 'https://cdn-icons-png.flaticon.com/128/5511/5511414.png'; $iconBg = 'bg-green-500/20 border-green-400/30'; $iconGlow = 'glow-green'; } elseif ($isLocked) { $statusLabel = 'Locked'; $statusClass = 'bg-red-500/15 text-red-400'; $iconSrc = 'https://cdn-icons-png.flaticon.com/128/615/615075.png'; $iconBg = 'bg-slate-700/60 border-white/10'; $iconGlow = 'glow-gray'; } else { $statusLabel = $isActivated ? ($canCollect ? 'Collect Now' : 'Active') : 'Unlocked'; $statusClass = $canCollect ? 'bg-yellow-500/25 text-yellow-300' : 'bg-blue-500/20 text-blue-300'; $iconSrc = 'https://cdn-icons-png.flaticon.com/128/2583/2583344.png'; $iconBg = 'bg-blue-500/20 border-blue-400/30'; $iconGlow = 'glow-blue'; } $cardClass = $isPassed ? 'is-passed' : ($isLocked ? 'is-locked' : 'is-active'); @endphp
{{-- Faint glow blob --}} @if($isActive)
@endif
{{-- Icon --}}
{{-- Body --}}
{{-- Name + badge --}}

{{ __($salary->name) }}

{{ __($statusLabel) }}
{{-- Rate + Requirement --}}

@lang('Salary:') {{ number_format($salary->amount, 2) }}%  ·  @lang('Turnover Required:') {{ gs('cur_sym') }}{{ showAmount($salary->min_turnover) }} @if($salary->max_turnover > 0) – {{ gs('cur_sym') }}{{ showAmount($salary->max_turnover) }} @else + @endif

{{-- Your turnover vs requirement --}}

@lang('Your Turnover:') {{ gs('cur_sym') }}{{ showAmount($teamTurnover) }} @if($isLocked)  ·  @lang('Need') {{ gs('cur_sym') }}{{ showAmount($salary->min_turnover - $teamTurnover) }} @lang('more') @endif

{{-- Progress Bar --}}
{{-- Last Claim + Next Claim Info --}} @if($isActivated)
{{-- Last Claim Date --}}
@lang('Last Claim:') {{ $lastClaim->created_at->format('d M Y, h:i A') }}
{{-- Next Claim Date + Countdown --}} @if(!$canCollect && $nextClaimAt)
@lang('Next Claim:') {{ $nextClaimAt->format('d M Y, h:i A') }}
@lang('Time Left:') {{ gmdate('H:i:s', $secsRemaining) }}
@elseif($canCollect)
@lang('Ready to collect your weekly reward!')
@endif
@endif {{-- Action Button --}} @if($isActive) @if(!$isActivated)
@csrf
@elseif($canCollect)
@csrf
@else {{-- Live countdown button --}} @endif @elseif($isPassed) @else @endif
@empty

@lang('No Salary Levels Defined')

@lang('Check back later.')

@endforelse
{{-- ── How It Works ─────────────────────────────── --}}
@lang('How It Works')
  • @lang('Build your team turnover to unlock higher salary levels.')
  • @lang('Once unlocked, activate the salary to start earning.')
  • @lang('Collect your reward every 7 days after activation.')
  • @lang('Rewards are credited directly to your Interest Wallet.')
@push('script') @endpush @endsection