
<?php $__env->startSection('title','Detail Produk'); ?>
<?php $__env->startSection('content'); ?>

        <div class="py-3">
			<div class="container">
				<!-- Contact Form -->
				<div class="card mb-3">
					<div class="card-body">
						<h5 class="mb-3">Detail Produk</h5>
						<div class="contact-form">
							<div class="col-md-12 mb-4">
                                    <?php
                                        $gambar = $produk->gambar;
                                        $daftarGambar = explode(";", $gambar); // pisahkan string menjadi array    
                                    ?>
                                    <img src="https://ptgib.co.id/asset/img_produk/<?php echo e($daftarGambar[0]); ?>" class="card-img-top" alt="${item.judul}" style="object-fit: cover;">
                                    <div class="card-body">
                                        <h5 class="card-title"><?php echo e($produk->judul); ?></h5>
                                        <div><?=$produk->isi_produk?></div>
                                        <?php if(Auth::check()): ?>
                                            <?php if(isset($data_unit)): ?>
                                                    <a href="javascript:void(0);" id="toggleButton">
                                                        Lihat Detail Unit <i class="fa fa-arrow-down" aria-hidden="true"></i>
                                                    </a>
                                                <?php $__currentLoopData = $data_unit; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $lokasi): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                   
                                                    <div id="detailContent" style="display: none; margin-top: 10px;">
                                                    
                                                            <table class="table stripted-table">
                                                                <tr>
                                                                    <td colspan="2" style="text-align: center">
                                                                        Lokasi : <?php echo e($lokasi['alamat']); ?>

                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td>Serial Number</td>
                                                                    <td>Tgl. Pembelian</td>
                                                                </tr>
                                                                <?php $__currentLoopData = $lokasi['unit']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $unit): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                    <tr>
                                                                        <td><?php echo e($unit->serial_number); ?></td>
                                                                        <td><?php echo e(TanggalHelper::get_dd_mm_yyyy($unit->tgl_pembelian)); ?></td>
                                                                    </tr>
                                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                            </table>
                                                        
                                                        
                                                    </div>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            <?php endif; ?>
                                        <?php endif; ?>
                                        
                                        
                                    </div>
                                
                            </div>
						</div>
					</div>
				</div>
			</div>
		</div>
<?php $__env->startSection('js'); ?>
<script>
    

    function loadFile(event) {
        const output = document.getElementById("preview");
        output.style.display = "block";
        output.src = URL.createObjectURL(event.target.files[0]);
        document.getElementById("error-message").style.display = "none"; // Sembunyikan pesan error jika file dipilih
    }

	function loadFileGaleri(event) {
        const output = document.getElementById("preview_galeri");
        output.style.display = "block";
        output.src = URL.createObjectURL(event.target.files[0]);
        
    }

	$(document).ready(function() {
        $.ajax({
            url: "<?php echo e(route('get.lokasi')); ?>",
            type: "GET",
            dataType: "json",
            success: function(data) {
				//console.log(data);
				
                let select = $('#id_lokasi');
                select.empty();
                select.append('<option value="">--Pilih Lokasi--</option>'); // Opsi default
				let selectedLokasiId = "<?php echo e($komplain->id_lokasi ?? ''); ?>";

                $.each(data, function(index, lokasi) {
                    let selected = lokasi.id == selectedLokasiId ? 'selected' : '';
                    select.append('<option value="' + lokasi.id + '" ' + selected + '>' + lokasi.alamat + '</option>');
                    
                });

                select.trigger("chosen:updated"); // Jika pakai Chosen.js
            },
            error: function(xhr) {
                console.log("Error: " + xhr.responseText);
            }
        });

        
    });

	function pilihLokasi(idLokasi) {
        const produkSelect = document.getElementById('id_item');
        produkSelect.innerHTML = '<option value="">-- Memuat Produk... --</option>';

        fetch("<?php echo e(url('/get-produk-customer')); ?>/" + idLokasi)
            .then(response => response.json())
            .then(data => {
                produkSelect.innerHTML = '<option value="">-- Pilih Produk --</option>';

                if (data.length > 0) {
                    data.forEach(item => {
                        const option = document.createElement('option');
                        option.value = item.id;
                        option.textContent = item.judul;
                        produkSelect.appendChild(option);
                    });
                } else {
                    const option = document.createElement('option');
                    option.value = '';
                    option.textContent = 'Produk tidak ditemukan';
                    produkSelect.appendChild(option);
                }
            })
            .catch(error => {
                console.error('Gagal mengambil produk:', error);
                produkSelect.innerHTML = '<option value="">Gagal memuat produk</option>';
            });
    }

	function pilihProduk(idItem) {
        const produkSelect = document.getElementById('id_unit');
        produkSelect.innerHTML = '<option value="">-- Memuat Unit... --</option>';

        fetch("<?php echo e(url('/get-unit-customer')); ?>/" + idItem)
            .then(response => response.json())
            .then(data => {
                produkSelect.innerHTML = '<option value="">-- Pilih Unit --</option>';

                if (data.length > 0) {
                    data.forEach(item => {
                        const option = document.createElement('option');
                        option.value = item.id;
                        option.textContent = item.serial_number+' tgl. pembelian : '+formatTanggal(item.tgl_pembelian);
                        produkSelect.appendChild(option);
                    });
                } else {
                    const option = document.createElement('option');
                    option.value = '';
                    option.textContent = 'Unit tidak ditemukan';
                    produkSelect.appendChild(option);
                }
            })
            .catch(error => {
                console.error('Gagal mengambil produk:', error);
                produkSelect.innerHTML = '<option value="">Gagal memuat unit</option>';
            });
    }

    function formatTanggal(tgl) {
        const date = new Date(tgl);
        const pad = n => n.toString().padStart(2, '0');
        const shortYear = date.getFullYear().toString().slice(-2); // ambil dua digit terakhir
        return `${pad(date.getDate())}/${pad(date.getMonth() + 1)}/${shortYear}`;
    }

    document.getElementById('toggleButton').addEventListener('click', function() {
        var content = document.getElementById('detailContent');
        var button = document.getElementById('toggleButton');
        
        if (content.style.display === "none") {
            content.style.display = "block";
            button.innerHTML = 'Tutup Detail Unit <i class="fa fa-arrow-up" aria-hidden="true"></i>';
        } else {
            content.style.display = "none";
            button.innerHTML = 'Lihat Detail Unit <i class="fa fa-arrow-down" aria-hidden="true"></i>';
        }
    });                                       

</script>
<?php $__env->stopSection(); ?>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.master', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home3/baktijay/public_html/ptgib.co.id/admin_pwa/resources/views/qr_produk/edit.blade.php ENDPATH**/ ?>