<?php if (isset($component)) { $__componentOriginal91fdd17964e43374ae18c674f95cdaa3 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal91fdd17964e43374ae18c674f95cdaa3 = $attributes; } ?>
<?php $component = App\View\Components\AdminLayout::resolve([] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('admin-layout'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\App\View\Components\AdminLayout::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes([]); ?>
   <div class="container px-6 mx-auto">
       <div class="flex justify-between items-center my-6">
           <h2 class="text-2xl font-semibold text-gray-700">Trade History</h2>
       </div>

       <?php if (isset($component)) { $__componentOriginal6912374916afbfe53350098c2f0b0678 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal6912374916afbfe53350098c2f0b0678 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.session-status','data' => ['class' => 'mb-4','status' => session('status'),'errors' => $errors]] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('session-status'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['class' => 'mb-4','status' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(session('status')),'errors' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($errors)]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal6912374916afbfe53350098c2f0b0678)): ?>
<?php $attributes = $__attributesOriginal6912374916afbfe53350098c2f0b0678; ?>
<?php unset($__attributesOriginal6912374916afbfe53350098c2f0b0678); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal6912374916afbfe53350098c2f0b0678)): ?>
<?php $component = $__componentOriginal6912374916afbfe53350098c2f0b0678; ?>
<?php unset($__componentOriginal6912374916afbfe53350098c2f0b0678); ?>
<?php endif; ?>

       <!-- Stats -->
       <div class="grid grid-cols-1 md:grid-cols-4 gap-6 mb-6">
           <div class="bg-white rounded-lg shadow-md p-6">
               <div class="flex items-center">
                   <div class="p-3 rounded-full bg-blue-100">
                       <i class="ri-exchange-line text-2xl text-blue-500"></i>
                   </div>
                   <div class="ml-4">
                       <p class="text-gray-500 text-sm">Total Trades</p>
                       <p class="text-xl font-semibold"><?php echo e($trades->total()); ?></p>
                   </div>
               </div>
           </div>
           
           <div class="bg-white rounded-lg shadow-md p-6">
               <div class="flex items-center">
                   <div class="p-3 rounded-full bg-green-100">
                       <i class="ri-arrow-up-circle-line text-2xl text-green-500"></i>
                   </div>
                   <div class="ml-4">
                       <p class="text-gray-500 text-sm">Win Rate</p>
                       <p class="text-xl font-semibold">
                           <?php echo e(number_format(($trades->where('result', 'win')->count() / max($trades->count(), 1)) * 100, 1)); ?>%
                       </p>
                   </div>
               </div>
           </div>
           
           <div class="bg-white rounded-lg shadow-md p-6">
               <div class="flex items-center">
                   <div class="p-3 rounded-full bg-green-100">
                       <i class="ri-money-dollar-circle-line text-2xl text-green-500"></i>
                   </div>
                   <div class="ml-4">
                       <p class="text-gray-500 text-sm">Total Profit</p>
                       <p class="text-xl font-semibold">$<?php echo e(number_format($trades->sum('profit'), 2)); ?></p>
                   </div>
               </div>
           </div>
           
           <div class="bg-white rounded-lg shadow-md p-6">
               <div class="flex items-center">
                   <div class="p-3 rounded-full bg-red-100">
                       <i class="ri-arrow-down-circle-line text-2xl text-red-500"></i>
                   </div>
                   <div class="ml-4">
                       <p class="text-gray-500 text-sm">Total Loss</p>
                       <p class="text-xl font-semibold">$<?php echo e(number_format($trades->where('result', 'loss')->sum('amount'), 2)); ?></p>
                   </div>
               </div>
           </div>
       </div>

       <!-- Trades Table -->
       <div class="bg-white rounded-lg shadow-md overflow-hidden">
           <div class="overflow-x-auto">
               <table class="w-full whitespace-no-wrap">
                   <thead>
                       <tr class="text-xs font-semibold tracking-wide text-left text-gray-500 uppercase bg-gray-50 border-b">
                           <th class="px-4 py-3">Bot/Date</th>
                           <th class="px-4 py-3">Trading Pair</th>
                           <th class="px-4 py-3">Action</th>
                           <th class="px-4 py-3">Amount</th>
                           <th class="px-4 py-3">Price</th>
                           <th class="px-4 py-3">Result</th>
                           <th class="px-4 py-3">Profit/Loss</th>
                           <th class="px-4 py-3">Actions</th>
                       </tr>
                   </thead>
                   <tbody class="bg-white divide-y">
                       <?php $__empty_1 = true; $__currentLoopData = $trades; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $trade): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                           <tr class="text-gray-700">
                               <td class="px-4 py-3">
                                   <div class="flex flex-col">
                                       <span class="font-medium"><?php echo e($trade->bot->name); ?></span>
                                       <span class="text-sm text-gray-500"><?php echo e($trade->created_at->format('M d, Y H:i')); ?></span>
                                   </div>
                               </td>
                               <td class="px-4 py-3"><?php echo e($trade->trading_pair); ?></td>
                               <td class="px-4 py-3">
                                   <span class="px-2 py-1 text-xs rounded-full 
                                       <?php echo e($trade->action === 'buy' ? 'bg-green-100 text-green-800' : 'bg-red-100 text-red-800'); ?>">
                                       <?php echo e(ucfirst($trade->action)); ?>

                                   </span>
                               </td>
                               <td class="px-4 py-3">$<?php echo e(number_format($trade->amount, 2)); ?></td>
                               <td class="px-4 py-3">$<?php echo e(number_format($trade->price, 2)); ?></td>
                               <td class="px-4 py-3">
                                   <?php if($trade->result === null): ?>
                                       <span class="px-2 py-1 text-xs rounded-full bg-yellow-100 text-yellow-800">
                                           Pending
                                       </span>
                                   <?php else: ?>
                                       <span class="px-2 py-1 text-xs rounded-full 
                                           <?php echo e($trade->result === 'win' ? 'bg-green-100 text-green-800' : 'bg-red-100 text-red-800'); ?>">
                                           <?php echo e(ucfirst($trade->result)); ?>

                                       </span>
                                   <?php endif; ?>
                               </td>
                               <td class="px-4 py-3">
                                   <?php if($trade->result === null): ?>
                                       <span class="text-yellow-600">Pending</span>
                                   <?php else: ?>
                                       <span class="<?php echo e($trade->result === 'win' ? 'text-green-600' : 'text-red-600'); ?>">
                                           <?php echo e($trade->result === 'win' ? '+' : '-'); ?>$<?php echo e(number_format($trade->result === 'win' ? $trade->profit : $trade->amount, 2)); ?>

                                       </span>
                                   <?php endif; ?>
                               </td>
                               <td class="px-4 py-3">
                                   <?php if($trade->result === null): ?>
                                       <button onclick="openTradeModal(<?php echo e($trade->id); ?>)" 
                                               class="p-1 text-blue-600 hover:text-blue-900 rounded-full hover:bg-blue-100">
                                           <i class="ri-edit-line text-lg"></i>
                                       </button>
                                   <?php endif; ?>
                               </td>
                           </tr>
                       <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                           <tr>
                               <td colspan="8" class="px-4 py-8 text-center text-gray-500">
                                   No trades found
                               </td>
                           </tr>
                       <?php endif; ?>
                   </tbody>
               </table>
           </div>
           
           <div class="px-4 py-3 border-t">
               <?php echo e($trades->links()); ?>

           </div>
       </div>
   </div>

   <!-- Trade Update Modal -->
   <div id="tradeModal" class="fixed inset-0 bg-black bg-opacity-50 hidden z-50">
       <div class="flex items-center justify-center min-h-screen px-4">
           <div class="bg-white rounded-lg shadow-xl max-w-md w-full">
               <div class="p-6">
                   <h3 class="text-lg font-medium text-gray-900 mb-4">Update Trade Result</h3>
                   <form id="updateTradeForm" method="POST">
                       <?php echo csrf_field(); ?>
                       <?php echo method_field('PUT'); ?>
                       
                       <div class="mb-4">
                           <label class="block text-sm font-medium text-gray-700 mb-2">Result</label>
                           <select name="result" class="w-full px-3 py-2 border border-gray-300 rounded-lg">
                               <option value="win">Win</option>
                               <option value="loss">Loss</option>
                           </select>
                       </div>

                       <div class="mb-4">
                           <label class="block text-sm font-medium text-gray-700 mb-2">Profit Amount</label>
                           <input type="number" name="profit" step="0.01" min="0" 
                                  class="w-full px-3 py-2 border border-gray-300 rounded-lg">
                       </div>

                       <div class="flex justify-end space-x-3">
                           <button type="button" onclick="closeTradeModal()"
                                   class="px-4 py-2 text-sm font-medium text-gray-700 bg-gray-100 rounded-lg hover:bg-gray-200">
                               Cancel
                           </button>
                           <button type="submit"
                                   class="px-4 py-2 text-sm font-medium text-white bg-purple-600 rounded-lg hover:bg-purple-700">
                               Update
                           </button>
                       </div>
                   </form>
               </div>
           </div>
       </div>
   </div>

   <script>
       function openTradeModal(tradeId) {
           const modal = document.getElementById('tradeModal');
           const form = document.getElementById('updateTradeForm');
           form.action = `/admin/trades/${tradeId}`;
           modal.classList.remove('hidden');
       }

       function closeTradeModal() {
           const modal = document.getElementById('tradeModal');
           modal.classList.add('hidden');
       }
   </script>
 <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal91fdd17964e43374ae18c674f95cdaa3)): ?>
<?php $attributes = $__attributesOriginal91fdd17964e43374ae18c674f95cdaa3; ?>
<?php unset($__attributesOriginal91fdd17964e43374ae18c674f95cdaa3); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal91fdd17964e43374ae18c674f95cdaa3)): ?>
<?php $component = $__componentOriginal91fdd17964e43374ae18c674f95cdaa3; ?>
<?php unset($__componentOriginal91fdd17964e43374ae18c674f95cdaa3); ?>
<?php endif; ?><?php /**PATH C:\Users\Digi\Downloads\Laravel Deployment Task_ Validate, Preview, and Package ZIP\aurumsafe\fsfcore\resources\views\admin\trades\index.blade.php ENDPATH**/ ?>