<?php
    $trialSeconds = $tenant?->trialSecondsRemaining() ?? 0;
    $trialStarted = $tenant?->approved_at ?? $tenant?->created_at;
    $trialTotal = ($tenant?->trial_ends_at && $trialStarted) ? max(1, $trialStarted->diffInSeconds($tenant->trial_ends_at)) : 1;
    $trialDays = ($tenant?->trial_ends_at && $trialStarted) ? max(1, (int) ceil($trialStarted->diffInHours($tenant->trial_ends_at) / 24)) : 14;
    $trialUsed = $tenant?->trial_ends_at ? max(0, $trialTotal - $trialSeconds) : 0;
    $trialPercent = min(100, max(0, ($trialUsed / $trialTotal) * 100));
?>

<?php if($tenant?->isOnTrial()): ?>
    <div class="trial-countdown alert border-0 shadow-sm mb-4" data-trial-countdown="<?php echo e($tenant->trial_ends_at->toIso8601String()); ?>">
        <div class="d-flex flex-column flex-xl-row justify-content-between gap-3">
            <div>
                <div class="fw-semibold"><i class="bi bi-hourglass-split me-1"></i> Free trial active</div>
                <div class="small text-muted">Your <?php echo e($trialDays); ?>-day trial ends on <?php echo e(app_datetime($tenant->trial_ends_at)); ?>.</div>
            </div>
            <div class="trial-clock text-xl-end">
                <span data-days><?php echo e(floor($trialSeconds / 86400)); ?></span>d
                <span data-hours><?php echo e(floor(($trialSeconds % 86400) / 3600)); ?></span>h
                <span data-minutes><?php echo e(floor(($trialSeconds % 3600) / 60)); ?></span>m
                <span data-seconds><?php echo e($trialSeconds % 60); ?></span>s
            </div>
        </div>
        <div class="progress mt-3" style="height: 8px;">
            <div class="progress-bar bg-info" style="width: <?php echo e($trialPercent); ?>%"></div>
        </div>
        <div class="d-flex justify-content-between align-items-center small text-muted mt-2">
            <span>Trial started</span>
            <a href="<?php echo e(route('tenant.billing.index')); ?>#payment-options" class="btn btn-sm btn-success">
                <i class="bi bi-cash-coin me-1"></i> Pay now
            </a>
        </div>
    </div>
<?php elseif($tenant?->trial_ends_at && $tenant->isExpired()): ?>
    <div class="alert alert-warning border-0 shadow-sm mb-4">
        <div class="fw-semibold"><i class="bi bi-exclamation-triangle me-1"></i> Trial or subscription expired</div>
        <div class="small">Renew your plan from payment center to continue normal operation.</div>
    </div>
<?php endif; ?>
<?php /**PATH C:\Users\Polite hp\Documents\Codex\2026-05-08\build-a-complete-production-ready-saas\microfinance-saas\resources\views/partials/trial-countdown.blade.php ENDPATH**/ ?>