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

<a href="<?php echo e(route('user.marketplace.index')); ?>" class="mkt-back"><i class="ti ti-arrow-left"></i> Back to Marketplace</a>

<div class="mkt-show-grid">
    <div class="mkt-show-left">
        <div class="card mp-20">
            <div class="mkt-show-icon"><i class="ti ti-device-mobile"></i></div>
            <div class="mkt-show-category"><?php echo e($item['category']); ?></div>
            <h2 class="mkt-show-title"><?php echo e($item['title']); ?></h2>
            <p class="mkt-show-desc"><?php echo e($item['description'] ?? 'No description provided.'); ?></p>
            <div class="mkt-show-meta">
                <div class="mkt-show-meta-item">
                    <i class="ti ti-user"></i>
                    Sold by <strong><?php echo e($item['seller']); ?></strong>
                </div>
                <div class="mkt-show-meta-item">
                    <i class="ti ti-package"></i>
                    <strong><?php echo e($item['stock']); ?></strong> accounts in stock
                </div>
            </div>
        </div>
    </div>

    <div class="mkt-show-right">
        <div class="card mp-20">
            <h3 class="title">Buy Now</h3>
            <div class="mkt-buy-price"><?php echo e($currency); ?><?php echo e(number_format($item['price'], 2)); ?> <span style="font-size:14px;font-weight:400;color:var(--text-secondary)">per account</span></div>

            <?php if($item['stock'] > 0): ?>
                <form id="mkt-purchase-form" class="mkt-purchase-form">
                    <?php echo csrf_field(); ?>
                    <input type="hidden" name="product_id" value="<?php echo e($item['id']); ?>">
                    <input type="hidden" name="type" value="<?php echo e($item['type']); ?>">
                    <div class="form-group" style="margin-bottom:16px;">
                        <label class="form-label">Quantity <span class="required">*</span></label>
                        <input type="number" name="quantity" id="mkt-qty" class="form-control"
                            min="1" max="<?php echo e($item['stock']); ?>" value="1" required>
                        <small style="color:var(--text-secondary);font-size:12px;margin-top:4px;display:block;">Max: <?php echo e($item['stock']); ?></small>
                    </div>
                    <div class="mkt-total-wrap">
                        <span class="mkt-total-label">Total</span>
                        <span class="mkt-total-amount" id="mkt-total"><?php echo e($currency); ?><?php echo e(number_format($item['price'], 2)); ?></span>
                    </div>
                    <button type="submit" class="mkt-purchase-btn" id="mkt-purchase-btn">
                        <i class="ti ti-shopping-cart"></i> Purchase
                    </button>
                </form>
            <?php else: ?>
                <div class="mkt-out-of-stock"><i class="ti ti-alert-circle"></i> Out of stock</div>
            <?php endif; ?>

            <a href="<?php echo e(route('user.marketplace.my-purchases')); ?>" class="mkt-view-purchases">
                <i class="ti ti-list"></i> View my purchases
            </a>
        </div>
    </div>
</div>

<?php $__env->stopSection(); ?>
<?php $__env->startPush('style'); ?>
<style>
.mkt-back{display:inline-flex;align-items:center;gap:6px;font-size:14px;color:var(--primary-color);font-weight:500;margin-bottom:20px;text-decoration:none;}
.mkt-show-grid{display:grid;grid-template-columns:1fr 340px;gap:20px;align-items:start;}
.mkt-show-icon{width:60px;height:60px;border-radius:14px;background:rgba(255,132,50,.12);display:flex;align-items:center;justify-content:center;font-size:28px;color:var(--primary-color);margin-bottom:16px;}
.mkt-show-category{font-size:12px;font-weight:600;text-transform:uppercase;color:var(--text-secondary);letter-spacing:.5px;margin-bottom:8px;}
.mkt-show-title{font-size:22px;font-weight:700;color:var(--text-primary);margin:0 0 12px;}
.mkt-show-desc{font-size:14px;color:var(--text-secondary);line-height:1.7;margin:0 0 20px;}
.mkt-show-meta{display:flex;flex-direction:column;gap:10px;}
.mkt-show-meta-item{display:flex;align-items:center;gap:8px;font-size:14px;color:var(--text-primary);}
.mkt-show-meta-item i{color:var(--primary-color);font-size:16px;}
.mkt-buy-price{font-size:28px;font-weight:800;color:var(--primary-color);margin-bottom:20px;}
.mkt-total-wrap{display:flex;align-items:center;justify-content:space-between;padding:14px 0;border-top:var(--border);border-bottom:var(--border);margin-bottom:16px;}
.mkt-total-label{font-size:14px;color:var(--text-secondary);}
.mkt-total-amount{font-size:20px;font-weight:800;color:var(--primary-color);}
.mkt-purchase-btn{width:100%;height:48px;background:var(--primary-color);color:#fff;border:none;border-radius:12px;font-size:15px;font-weight:600;cursor:pointer;display:flex;align-items:center;justify-content:center;gap:8px;transition:opacity .2s;}
.mkt-purchase-btn:hover{opacity:.9;}
.mkt-purchase-btn:disabled{opacity:.6;cursor:not-allowed;}
.mkt-out-of-stock{padding:14px;background:#fef2f2;border-radius:10px;color:#dc2626;font-size:14px;font-weight:600;display:flex;align-items:center;gap:8px;}
.mkt-view-purchases{display:flex;align-items:center;gap:6px;justify-content:center;margin-top:14px;font-size:13px;color:var(--text-secondary);text-decoration:none;}
.mkt-view-purchases:hover{color:var(--primary-color);}
@media(max-width:768px){.mkt-show-grid{grid-template-columns:1fr;}}
</style>
<?php $__env->stopPush(); ?>
<?php $__env->startPush('script'); ?>
<script>
(function () {
    var price    = <?php echo e($item['price']); ?>;
    var currency = <?php echo json_encode($currency, 15, 512) ?>;
    var qtyEl    = document.getElementById('mkt-qty');
    var totalEl  = document.getElementById('mkt-total');

    if (qtyEl && totalEl) {
        qtyEl.addEventListener('input', function () {
            var q = parseInt(qtyEl.value, 10) || 1;
            totalEl.textContent = currency + (price * q).toFixed(2);
        });
    }

    var form = document.getElementById('mkt-purchase-form');
    if (form) {
        form.addEventListener('submit', function (e) {
            e.preventDefault();
            var btn = document.getElementById('mkt-purchase-btn');
            btn.disabled = true;
            btn.innerHTML = '<i class="ti ti-loader"></i> Processing...';

            var fd = new FormData(form);

            fetch('<?php echo e(route("user.marketplace.purchase", [$item["type"], $item["id"]])); ?>', {
                method: 'POST',
                headers: {
                    'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content,
                    'Accept': 'application/json',
                },
                body: fd
            })
            .then(function (r) { return r.json(); })
            .then(function (data) {
                btn.disabled = false;
                btn.innerHTML = '<i class="ti ti-shopping-cart"></i> Purchase';
                if (data.status === 'success') {
                    if (window.iziToast) iziToast.success({ message: data.message, position: 'topRight' });
                    window.location.href = '<?php echo e(route("user.marketplace.my-purchases")); ?>';
                } else {
                    if (window.iziToast) iziToast.error({ message: data.message || 'Error', position: 'topRight' });
                }
            })
            .catch(function () {
                btn.disabled = false;
                btn.innerHTML = '<i class="ti ti-shopping-cart"></i> Purchase';
                if (window.iziToast) iziToast.error({ message: 'Request failed', position: 'topRight' });
            });
        });
    }
})();
</script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('frontend.layout.dash', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\xampp\htdocs\jjd\socialnum\sstack\mine\core\resources\views/frontend/marketplace/show.blade.php ENDPATH**/ ?>