<?php $__env->startSection('title', 'Detail Analisis - ' . $analysis->company_name . ' - FIN-ANALYSIS PRO'); ?>

<?php
if (!function_exists('formatCurrency')) {
    function formatCurrency($value, $currency = 'Rp') {
        if ($value === null || $value === '') return $currency . ' 0';
        return $currency . ' ' . number_format((float)$value, 0, ',', '.');
    }
}
?>

<?php $__env->startSection('content'); ?>
<div class="max-w-7xl mx-auto">
    <!-- Header -->
    <div class="mb-6 flex flex-col md:flex-row md:items-center md:justify-between">
        <div>
            <div class="flex items-center space-x-2 mb-2">
                <a href="<?php echo e(route('history.index')); ?>" class="text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-300">
                    <i class="fas fa-arrow-left"></i>
                </a>
                <h1 class="text-2xl font-bold text-gray-900 dark:text-white">
                    Detail Analisis
                </h1>
            </div>
            <p class="text-gray-600 dark:text-gray-400">
                Hasil analisis Altman Z-Score untuk <?php echo e($analysis->company_name); ?>

            </p>
        </div>
        
        <!-- Action Buttons -->
        <div class="mt-4 md:mt-0 flex flex-wrap gap-2">
            <button type="button" 
                    onclick="toggleFavorite(<?php echo e($analysis->id); ?>)"
                    class="btn-outline">
                <i class="fas fa-star mr-2 <?php echo e($analysis->is_favorite ? 'text-yellow-500' : ''); ?>"></i>
                <?php echo e($analysis->is_favorite ? 'Hapus dari Favorit' : 'Tambah ke Favorit'); ?>

            </button>
            
            <a href="<?php echo e(route('report.preview', $analysis->id)); ?>" 
               target="_blank"
               class="btn-outline">
                <i class="fas fa-eye mr-2"></i>
                Preview PDF
            </a>
            
            <a href="<?php echo e(route('report.download', $analysis->id)); ?>" 
               class="btn-primary">
                <i class="fas fa-download mr-2"></i>
                Download PDF
            </a>
        </div>
    </div>

    <!-- Company Info Cards -->
    <div class="grid grid-cols-1 md:grid-cols-4 gap-4 mb-6">
        <div class="card">
            <div class="flex items-center">
                <div class="p-3 bg-primary-100 dark:bg-primary-900/30 rounded-lg">
                    <i class="fas fa-building text-primary-600 dark:text-primary-400 text-xl"></i>
                </div>
                <div class="ml-4">
                    <p class="text-sm text-gray-500 dark:text-gray-400">Perusahaan</p>
                    <p class="font-semibold"><?php echo e($analysis->company_name); ?></p>
                </div>
            </div>
        </div>
        
        <div class="card">
            <div class="flex items-center">
                <div class="p-3 bg-info-100 dark:bg-info-900/30 rounded-lg">
                    <i class="fas fa-tag text-info-600 dark:text-info-400 text-xl"></i>
                </div>
                <div class="ml-4">
                    <p class="text-sm text-gray-500 dark:text-gray-400">Bidang Usaha</p>
                    <p class="font-semibold">
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($analysis->business_field === 'Lainnya'): ?>
                            <?php echo e($analysis->other_field); ?>

                        <?php else: ?>
                            <?php echo e($analysis->business_field); ?>

                        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                    </p>
                </div>
            </div>
        </div>
        
        <div class="card">
            <div class="flex items-center">
                <div class="p-3 bg-warning-100 dark:bg-warning-900/30 rounded-lg">
                    <i class="fas fa-calendar text-warning-600 dark:text-warning-400 text-xl"></i>
                </div>
                <div class="ml-4">
                    <p class="text-sm text-gray-500 dark:text-gray-400">Periode</p>
                    <p class="font-semibold"><?php echo e($analysis->period); ?></p>
                </div>
            </div>
        </div>
        
        <div class="card">
            <div class="flex items-center">
                <div class="p-3 bg-success-100 dark:bg-success-900/30 rounded-lg">
                    <i class="fas fa-chart-line text-success-600 dark:text-success-400 text-xl"></i>
                </div>
                <div class="ml-4">
                    <p class="text-sm text-gray-500 dark:text-gray-400">Tanggal Analisis</p>
                    <p class="font-semibold"><?php echo e($analysis->created_at->format('d/m/Y H:i')); ?></p>
                </div>
            </div>
        </div>
    </div>

    <!-- Main Content Grid -->
    <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
        <!-- Left Column - Z-Score Gauge & Summary -->
        <div class="lg:col-span-1">
            <div class="card mb-6">
                <h3 class="card-header">Ringkasan Z-Score</h3>
                
                <!-- Gauge -->
                <div class="mb-4">
                    <?php if (isset($component)) { $__componentOriginal7b888d4ab7d2ec86640d2173348007f6 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal7b888d4ab7d2ec86640d2173348007f6 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.zscore-gauge','data' => ['score' => $analysis->z_score,'size' => 'lg']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('zscore-gauge'); ?>
<?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(['score' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($analysis->z_score),'size' => 'lg']); ?>
<?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::processComponentKey($component); ?>

<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal7b888d4ab7d2ec86640d2173348007f6)): ?>
<?php $attributes = $__attributesOriginal7b888d4ab7d2ec86640d2173348007f6; ?>
<?php unset($__attributesOriginal7b888d4ab7d2ec86640d2173348007f6); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal7b888d4ab7d2ec86640d2173348007f6)): ?>
<?php $component = $__componentOriginal7b888d4ab7d2ec86640d2173348007f6; ?>
<?php unset($__componentOriginal7b888d4ab7d2ec86640d2173348007f6); ?>
<?php endif; ?>
                </div>
                
                <!-- Score Details -->
                <div class="space-y-3">
                    <div class="flex justify-between items-center p-3 bg-gray-50 dark:bg-gray-800 rounded-lg">
                        <span class="text-gray-600 dark:text-gray-400">Z-Score</span>
                        <span class="font-mono font-bold text-xl 
                            <?php if($analysis->z_category === 'safe'): ?> text-success-600
                            <?php elseif($analysis->z_category === 'warning'): ?> text-warning-600
                            <?php else: ?> text-danger-600
                            <?php endif; ?>">
                            <?php echo e(number_format($analysis->z_score, 4)); ?>

                        </span>
                    </div>
                    
                    <div class="flex justify-between items-center p-3 bg-gray-50 dark:bg-gray-800 rounded-lg">
                        <span class="text-gray-600 dark:text-gray-400">Kategori</span>
                        <span class="badge 
                            <?php if($analysis->z_category === 'safe'): ?> badge-success
                            <?php elseif($analysis->z_category === 'warning'): ?> badge-warning
                            <?php else: ?> badge-danger
                            <?php endif; ?>">
                            <?php echo e($analysis->category_label); ?>

                        </span>
                    </div>
                    
                    <div class="flex justify-between items-center p-3 bg-gray-50 dark:bg-gray-800 rounded-lg">
                        <span class="text-gray-600 dark:text-gray-400">Mata Uang</span>
                        <span class="font-semibold"><?php echo e($analysis->currency); ?></span>
                    </div>
                </div>
            </div>
            
            <!-- Quick Actions -->
            <div class="card">
                <h3 class="card-header">Aksi Cepat</h3>
                <div class="space-y-2">
                    <button onclick="shareAnalysis(<?php echo e($analysis->id); ?>)" class="w-full btn-outline text-left">
                        <i class="fas fa-share-alt mr-2"></i>
                        Bagikan Analisis
                    </button>
                    
                    <button onclick="printAnalysis()" class="w-full btn-outline text-left">
                        <i class="fas fa-print mr-2"></i>
                        Cetak Halaman
                    </button>
                    
                    
                    
                    <button onclick="confirmDelete(<?php echo e($analysis->id); ?>, '<?php echo e($analysis->company_name); ?>')" 
                            class="w-full btn-outline text-left text-danger-600 hover:bg-danger-50 dark:hover:bg-danger-900/20">
                        <i class="fas fa-trash mr-2"></i>
                        Hapus Analisis
                    </button>
                </div>
            </div>
        </div>
        
        <!-- Right Column - Financial Data & Z-Score Components -->
        <div class="lg:col-span-2">
            <!-- Z-Score Components Card -->
            <div class="card mb-6">
                <h3 class="card-header">Komponen Z-Score</h3>
                
                <div class="grid grid-cols-1 md:grid-cols-5 gap-4 mb-6">
                    <div class="text-center p-3 bg-gray-50 dark:bg-gray-800 rounded-lg">
                        <div class="text-xs text-gray-500">X1</div>
                        <div class="font-mono font-bold"><?php echo e(number_format($analysis->x1, 4)); ?></div>
                    </div>
                    <div class="text-center p-3 bg-gray-50 dark:bg-gray-800 rounded-lg">
                        <div class="text-xs text-gray-500">X2</div>
                        <div class="font-mono font-bold"><?php echo e(number_format($analysis->x2, 4)); ?></div>
                    </div>
                    <div class="text-center p-3 bg-gray-50 dark:bg-gray-800 rounded-lg">
                        <div class="text-xs text-gray-500">X3</div>
                        <div class="font-mono font-bold"><?php echo e(number_format($analysis->x3, 4)); ?></div>
                    </div>
                    <div class="text-center p-3 bg-gray-50 dark:bg-gray-800 rounded-lg">
                        <div class="text-xs text-gray-500">X4</div>
                        <div class="font-mono font-bold"><?php echo e(number_format($analysis->x4, 4)); ?></div>
                    </div>
                    <div class="text-center p-3 bg-gray-50 dark:bg-gray-800 rounded-lg">
                        <div class="text-xs text-gray-500">X5</div>
                        <div class="font-mono font-bold"><?php echo e(number_format($analysis->x5, 4)); ?></div>
                    </div>
                </div>
                
                <!-- Interpretation -->
                <?php
                    $interpretation = $analysis->interpretation;
                ?>
                
                <div class="p-4 rounded-lg <?php echo e($analysis->z_category === 'safe' ? 'bg-success-50 dark:bg-success-900/20' : 
                    ($analysis->z_category === 'warning' ? 'bg-warning-50 dark:bg-warning-900/20' : 
                    'bg-danger-50 dark:bg-danger-900/20')); ?>">
                    <h4 class="font-semibold mb-2">Interpretasi</h4>
                    <p class="text-sm mb-3"><?php echo e($interpretation['description']); ?></p>
                    
                    <h5 class="font-medium text-sm mb-2">Rekomendasi:</h5>
                    <ul class="list-disc list-inside text-sm space-y-1">
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::openLoop(); ?><?php endif; ?><?php $__currentLoopData = $interpretation['recommendations']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $rec): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::startLoopIteration(); ?><?php endif; ?>
                            <li><?php echo e($rec); ?></li>
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::endLoop(); ?><?php endif; ?><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::closeLoop(); ?><?php endif; ?>
                    </ul>
                </div>
            </div>
            
            <!-- Financial Data Card -->
            <div class="card">
                <h3 class="card-header">Data Keuangan</h3>
                
                <div class="overflow-x-auto">
                    <table class="min-w-full">
                        <tbody class="divide-y divide-gray-200 dark:divide-gray-700">
                            <tr class="bg-gray-50 dark:bg-gray-900">
                                <td colspan="2" class="px-4 py-2 font-semibold">ASET</td>
                            </tr>
                            <tr>
                                <td class="px-4 py-2">Aset Lancar</td>
                                <td class="px-4 py-2 text-right font-mono">
                                    <?php echo e(formatCurrency($financialData['aset_lancar'] ?? 0, $analysis->currency)); ?>

                                </td>
                            </tr>
                            <tr>
                                <td class="px-4 py-2">Aset Tetap</td>
                                <td class="px-4 py-2 text-right font-mono">
                                    <?php echo e(formatCurrency($financialData['aset_tetap'] ?? 0, $analysis->currency)); ?>

                                </td>
                            </tr>
                            <tr class="font-semibold">
                                <td class="px-4 py-2">Total Aset</td>
                                <td class="px-4 py-2 text-right font-mono text-primary-600">
                                    <?php echo e(formatCurrency(($financialData['aset_lancar'] ?? 0) + ($financialData['aset_tetap'] ?? 0), $analysis->currency)); ?>

                                </td>
                            </tr>
                            
                            <tr class="bg-gray-50 dark:bg-gray-900">
                                <td colspan="2" class="px-4 py-2 font-semibold">LIABILITAS</td>
                            </tr>
                            <tr>
                                <td class="px-4 py-2">Utang Lancar</td>
                                <td class="px-4 py-2 text-right font-mono">
                                    <?php echo e(formatCurrency($financialData['utang_lancar'] ?? 0, $analysis->currency)); ?>

                                </td>
                            </tr>
                            <tr>
                                <td class="px-4 py-2">Utang Jangka Panjang</td>
                                <td class="px-4 py-2 text-right font-mono">
                                    <?php echo e(formatCurrency($financialData['utang_jangka_panjang'] ?? 0, $analysis->currency)); ?>

                                </td>
                            </tr>
                            <tr class="font-semibold">
                                <td class="px-4 py-2">Total Utang</td>
                                <td class="px-4 py-2 text-right font-mono text-warning-600">
                                    <?php echo e(formatCurrency(($financialData['utang_lancar'] ?? 0) + ($financialData['utang_jangka_panjang'] ?? 0), $analysis->currency)); ?>

                                </td>
                            </tr>
                            
                            <tr class="bg-gray-50 dark:bg-gray-900">
                                <td colspan="2" class="px-4 py-2 font-semibold">EKUITAS</td>
                            </tr>
                            <tr class="font-semibold">
                                <td class="px-4 py-2">Nilai Buku Ekuitas</td>
                                <td class="px-4 py-2 text-right font-mono text-success-600">
                                    <?php
                                        $totalAset = ($financialData['aset_lancar'] ?? 0) + ($financialData['aset_tetap'] ?? 0);
                                        $totalUtang = ($financialData['utang_lancar'] ?? 0) + ($financialData['utang_jangka_panjang'] ?? 0);
                                    ?>
                                    <?php echo e(formatCurrency($totalAset - $totalUtang, $analysis->currency)); ?>

                                </td>
                            </tr>
                            
                            <tr class="bg-gray-50 dark:bg-gray-900">
                                <td colspan="2" class="px-4 py-2 font-semibold">LABA RUGI</td>
                            </tr>
                            <tr>
                                <td class="px-4 py-2">Pendapatan</td>
                                <td class="px-4 py-2 text-right font-mono">
                                    <?php echo e(formatCurrency($financialData['pendapatan'] ?? 0, $analysis->currency)); ?>

                                </td>
                            </tr>
                            <tr>
                                <td class="px-4 py-2">Biaya Operasional</td>
                                <td class="px-4 py-2 text-right font-mono">
                                    <?php echo e(formatCurrency($financialData['biaya_operasional'] ?? 0, $analysis->currency)); ?>

                                </td>
                            </tr>
                            <tr>
                                <td class="px-4 py-2">Laba Sebelum Pajak</td>
                                <td class="px-4 py-2 text-right font-mono">
                                    <?php echo e(formatCurrency(($financialData['pendapatan'] ?? 0) - ($financialData['biaya_operasional'] ?? 0), $analysis->currency)); ?>

                                </td>
                            </tr>
                            <tr>
                                <td class="px-4 py-2">Prive</td>
                                <td class="px-4 py-2 text-right font-mono">
                                    <?php echo e(formatCurrency($financialData['prive'] ?? 0, $analysis->currency)); ?>

                                </td>
                            </tr>
                            <tr class="font-semibold">
                                <td class="px-4 py-2">Laba Ditahan</td>
                                <td class="px-4 py-2 text-right font-mono text-info-600">
                                    <?php
                                        $laba = ($financialData['pendapatan'] ?? 0) - ($financialData['biaya_operasional'] ?? 0);
                                    ?>
                                    <?php echo e(formatCurrency($laba - ($financialData['prive'] ?? 0), $analysis->currency)); ?>

                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- Delete Form -->
<form id="delete-form" method="POST" style="display: none;">
    <?php echo csrf_field(); ?>
    <?php echo method_field('DELETE'); ?>
</form>

<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
<script>
function confirmDelete(id, companyName) {
    if (confirm(`Apakah Anda yakin ingin menghapus analisis untuk "${companyName}"?`)) {
        const form = document.getElementById('delete-form');
        form.action = `/history/${id}`;
        form.submit();
    }
}

function toggleFavorite(id) {
    fetch(`/api/analysis/${id}/favorite`, {
        method: 'POST',
        headers: {
            'X-CSRF-TOKEN': '<?php echo e(csrf_token()); ?>',
            'Accept': 'application/json'
        }
    })
    .then(response => response.json())
    .then(data => {
        if (data.success) {
            location.reload();
        }
    })
    .catch(error => {
        console.error('Error:', error);
        alert('Gagal mengubah status favorit');
    });
}

function shareAnalysis(id) {
    // Generate shareable link
    fetch(`/api/analysis/${id}/share`, {
        method: 'POST',
        headers: {
            'X-CSRF-TOKEN': '<?php echo e(csrf_token()); ?>',
            'Accept': 'application/json'
        }
    })
    .then(response => response.json())
    .then(data => {
        if (data.shareable_link) {
            // Copy to clipboard
            navigator.clipboard.writeText(data.shareable_link).then(() => {
                alert('Link berhasil disalin ke clipboard!');
            });
        }
    })
    .catch(error => {
        console.error('Error:', error);
        alert('Gagal membuat link sharing');
    });
}

function printAnalysis() {
    window.print();
}
</script>
<?php $__env->stopPush(); ?>
<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/roky/projects/V1/resources/views/history/show.blade.php ENDPATH**/ ?>