<?php $__env->startSection('title'); ?>
<?php echo $variables['header_routes']; ?>

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

<?php $__env->startSection('content'); ?>
<section class="content">
    <div class="container-fluid">
        <div class="row">
            <div class="col-12">
                <div class="card">
                    <div class="card-header">
                        <h3 class="card-title"><?php echo $variables['judul']; ?></h3>
                        <div class="float-right">
                            <a href="<?php echo e(route('stores.index')); ?>" class="btn btn-warning btn-sm button-cek-permission" data-permission="stores.index">
                                <i class="fas fa-list"></i> Daftar
                            </a>
                            <a href="<?php echo e(route('stores.edit', $data->id)); ?>" class="btn btn-warning btn-sm button-cek-permission" data-permission="stores.edit">
                                <i class="fas fa-edit"></i> Ubah
                            </a>
                            <a href="<?php echo e(route('stores.destroy', $data->id)); ?>" data='delete' onclick="notificationBeforeDelete(event, this)" class="btn btn-warning btn-sm button-cek-permission" data-permission="stores.destroy">
                                <i class="fas fa-trash"></i> <?php echo e($data->delete_flag ? 'Aktifkan' : 'Nonaktifkan'); ?>

                            </a>
                        </div>
                    </div>
                    <div class="card-body">
                        <!-- Store Header Info -->
                        <div class="row">
                            <div class="col-md-6">
                                <table class="table table-borderless">
                                    <tr>
                                        <td width="40%"><strong>Kode</strong></td>
                                        <td>: <span class="badge badge-info"><?php echo e($data->code); ?></span></td>
                                    </tr>
                                    <tr>
                                        <td><strong>Nama</strong></td>
                                        <td>: <?php echo e($data->name); ?></td>
                                    </tr>
                                    <tr>
                                        <td><strong>Penanggung Jawab</strong></td>
                                        <td>: <?php echo e($data->pic ?: '-'); ?></td>
                                    </tr>
                                    <tr>
                                        <td><strong>Telepon PJ</strong></td>
                                        <td>: 
                                            <?php if($data->pic_phone): ?>
                                            <a href="tel:<?php echo e($data->pic_phone); ?>" class="text-decoration-none">
                                                <?php echo e($data->pic_phone); ?>

                                            </a>
                                            <?php else: ?>
                                            -
                                            <?php endif; ?>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td><strong>Email PJ</strong></td>
                                        <td>: 
                                            <?php if($data->pic_email): ?>
                                            <a href="mailto:<?php echo e($data->pic_email); ?>" class="text-decoration-none">
                                                <?php echo e($data->pic_email); ?>

                                            </a>
                                            <?php else: ?>
                                            -
                                            <?php endif; ?>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                            <div class="col-md-6">
                                <table class="table table-borderless">
                                    <tr>
                                        <td width="40%"><strong>Status</strong></td>
                                        <td>: 
                                            <?php if($data->status == 'Active'): ?>
                                            <span class="badge badge-success"><?php echo e($data->status); ?></span>
                                            <?php else: ?>
                                            <span class="badge badge-secondary"><?php echo e($data->status); ?></span>
                                            <?php endif; ?>
                                        </td>
                                    </tr>
                                    <?php if($data->inactive_date): ?>
                                    <tr>
                                        <td><strong>Tanggal Nonaktif</strong></td>
                                        <td>: <?php echo e($data->inactive_date); ?></td>
                                    </tr>
                                    <?php endif; ?>
                                    <tr>
                                        <td><strong>Dibuat Oleh</strong></td>
                                        <td>: <?php echo e($data->creator->fullname ?? 'System'); ?> (<?php echo e($data->created_at->format('d M Y, H:i')); ?>)</td>
                                    </tr>
                                    <?php if($data->modificator): ?>
                                    <tr>
                                        <td><strong>Diubah Oleh</strong></td>
                                        <td>: <?php echo e($data->modificator->fullname); ?> (<?php echo e($data->updated_at->format('d M Y, H:i')); ?>)</td>
                                    </tr>
                                    <?php endif; ?>
                                    <tr>
                                        <td><strong>Total Item</strong></td>
                                        <td>: <?php echo e($data->storeRawMaterials->where('delete_flag', 0)->count()); ?> item</td>
                                    </tr>
                                </table>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-12">
                                <table class="table table-borderless">
                                    <tr>
                                        <td width="20%"><strong>Alamat</strong></td>
                                        <td>: <?php echo e($data->address ?: '-'); ?></td>
                                    </tr>
                                </table>
                            </div>
                        </div>

                        <?php if($data->description): ?>
                        <div class="row">
                            <div class="col-12">
                                <table class="table table-borderless">
                                    <tr>
                                        <td width="20%"><strong>Deskripsi</strong></td>
                                        <td>: <?php echo e($data->description); ?></td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                        <?php endif; ?>

                        <!-- Items Mapping Section -->
                        <div class="row mt-3">
                            <div class="col-12">
                                <div class="card card-outline card-warning">
                                    <div class="card-header">
                                        <h3 class="card-title">
                                            <i class="fas fa-boxes"></i> Pemetaan Item (<?php echo e($data->storeRawMaterials->where('delete_flag', 0)->count()); ?> item)
                                        </h3>
                                        <div class="card-tools">
                                            <a href="<?php echo e(route('store_raw_materials.index')); ?>?store=<?php echo e($data->id); ?>" class="btn btn-sm btn-warning">
                                                <i class="fas fa-edit"></i> Kelola Pemetaan
                                            </a>
                                        </div>
                                    </div>
                                    <div class="card-body">
                                        <?php if($data->storeRawMaterials->where('delete_flag', 0)->count() > 0): ?>
                                        <div class="table-responsive">
                                            <table class="table table-sm table-hover">
                                                <thead class="bg-warning">
                                                    <tr>
                                                        <th width="5%">No</th>
                                                        <th>Kode Item</th>
                                                        <th>Nama Item</th>
                                                        <th>UOM</th>
                                                        <th>Tipe Dokumen</th>
                                                        <th>Tipe Barang</th>
                                                        <th>Status</th>
                                                        <th>Stok Min</th>
                                                        <th>Stok Maks</th>
                                                        <th>Reorder Point</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    <?php $__currentLoopData = $data->storeRawMaterials->where('delete_flag', 0)->sortBy('rawMaterial.code'); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $mapping): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <tr>
                                                        <td><?php echo e($index + 1); ?></td>
                                                        <td>
                                                            <a href="<?php echo e(route('raw_materials.show', $mapping->rawMaterial->id)); ?>" target="_blank">
                                                                <?php echo e($mapping->rawMaterial->code); ?>

                                                            </a>
                                                        </td>
                                                        <td><?php echo e($mapping->rawMaterial->name); ?></td>
                                                        <td><?php echo e($mapping->rawMaterial->uom); ?></td>
                                                        <td>
                                                            <?php if($mapping->tipe_dokumen === 'DO'): ?>
                                                            <span class="badge badge-primary">DO</span>
                                                            <?php elseif($mapping->tipe_dokumen === 'PO'): ?>
                                                            <span class="badge badge-secondary">PO</span>
                                                            <?php else: ?>
                                                            <span class="badge badge-info">PR</span>
                                                            <?php endif; ?>
                                                        </td>
                                                        <td>
                                                            <?php if($mapping->rawMaterial->tipe_barang === 'Basah'): ?>
                                                            <span class="badge badge-info">Basah</span>
                                                            <?php else: ?>
                                                            <span class="badge badge-secondary">Kering</span>
                                                            <?php endif; ?>
                                                        </td>
                                                        <td>
                                                            <?php if($mapping->is_active): ?>
                                                            <span class="badge badge-success">Aktif</span>
                                                            <?php else: ?>
                                                            <span class="badge badge-secondary">Nonaktif</span>
                                                            <?php endif; ?>
                                                        </td>
                                                        <td class="text-right"><?php echo e(number_format($mapping->min_stock, 2)); ?></td>
                                                        <td class="text-right"><?php echo e(number_format($mapping->max_stock, 2)); ?></td>
                                                        <td class="text-right"><?php echo e(number_format($mapping->reorder_point, 2)); ?></td>
                                                    </tr>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                </tbody>
                                            </table>
                                        </div>

                                        <!-- Summary by Tipe Dokumen -->
                                        <div class="row mt-3">
                                            <div class="col-md-12">
                                                <div class="alert alert-info">
                                                    <strong><i class="fas fa-info-circle"></i> Ringkasan Pengelompokan SPB:</strong><br>
                                                    Item di toko ini akan dikelompokkan menjadi SPB berdasarkan kombinasi Tipe Dokumen × Tipe Barang:
                                                    <ul class="mb-0 mt-2">
                                                        <?php
                                                        $grouping = $data->storeRawMaterials
                                                        ->where('delete_flag', 0)
                                                        ->where('is_active', true)
                                                        ->groupBy(function($item) {
                                                        return $item->tipe_dokumen . '-' . $item->rawMaterial->tipe_barang;
                                                        });
                                                        ?>
                                                        <?php $__currentLoopData = $grouping; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $items): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                        <?php
                                                        list($tipeDoc, $tipeBarang) = explode('-', $key);
                                                        $docBadge = $tipeDoc === 'DO' ? 'primary' : ($tipeDoc === 'PO' ? 'warning' : 'info');
                                                        $barangBadge = $tipeBarang === 'Basah' ? 'info' : 'secondary';
                                                        ?>
                                                        <li>
                                                            <span class="badge badge-<?php echo e($docBadge); ?>"><?php echo e($tipeDoc); ?></span>
                                                            <span class="badge badge-<?php echo e($barangBadge); ?>"><?php echo e($tipeBarang); ?></span>
                                                            : <?php echo e($items->count()); ?> item
                                                        </li>
                                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                    </ul>
                                                    <small class="text-muted">
                                                        <i class="fas fa-arrow-right"></i>
                                                        Dari 1 Stock Opname, toko ini bisa menghasilkan maksimal <?php echo e($grouping->count()); ?> SPB
                                                    </small>
                                                </div>
                                            </div>
                                        </div>
                                        <?php else: ?>
                                        <div class="alert alert-info">
                                            <i class="fas fa-exclamation-triangle"></i>
                                            Belum ada item yang dipetakan ke toko ini.
                                            <a href="<?php echo e(route('store_raw_materials.create')); ?>" class="alert-link">Tambahkan pemetaan</a>
                                        </div>
                                        <?php endif; ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

<form action="" id="delete-form" method="post">
    <?php echo method_field('delete'); ?>
    <?php echo csrf_field(); ?>
</form>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts/base_view', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH D:\LSM\resources\views/m-stores/show.blade.php ENDPATH**/ ?>