<?php $__env->startSection('seo'); ?>
    <title>Pago realizado con éxito | <?php echo e(infoEmail()->host); ?></title>
    <meta name="description" content="Pago realizado con éxito" />
    <meta name="keywords" content="pago exitoso, pago completado">
<?php $__env->stopSection(); ?>
<?php $__env->startSection('content'); ?>
    <!-- Fin sección migas de pan -->

    <section class="bj_shop_area sec_padding" data-bg-color="#f5f5f5">
        <div class="container">
            <div class="row">
                <div class="col-lg-12">
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($user): ?>
                        <div class="card mt-3">
                            <div class="card-header">
                                <h2 style="font-size: 1.5rem;font-weight: bold;padding: 20px 0;">¡Gracias por tu pedido!</h2>
                                <span>Tu pago ha sido procesado correctamente. Hemos recibido tu pedido y lo estamos tramitando.<br>
                                Se ha enviado un correo de confirmación con todos los detalles del pedido a tu dirección de correo electrónico.
                                </span>
                            </div>

                            <div class="card-body">
                                <ul class="nav nav-tabs" id="nav-tab" role="tablist">
                                    <li class="nav-item" role="presentation">
                                        <a class="nav-link active" id="nav-home-tab" data-bs-toggle="tab" href="#nav-home"
                                           role="tab" aria-controls="nav-home" aria-selected="true">
                                            Tu dirección
                                        </a>
                                    </li>
                                    <li class="nav-item" role="presentation">
                                        <a class="nav-link" id="nav-profile-tab" data-bs-toggle="tab" href="#nav-profile"
                                           role="tab" aria-controls="nav-profile" aria-selected="false">
                                            Editar
                                        </a>
                                    </li>
                                </ul>

                                <div class="tab-content" id="nav-tabContent">
                                    <!-- Bloque dirección de envío -->
                                    <div class="tab-pane fade show active" id="nav-home" role="tabpanel"
                                         aria-labelledby="nav-home-tab">
                                        <ul class="list-group">
                                            <li class="list-group-item"><?php echo e($user->name); ?></li>
                                            <li class="list-group-item"><?php echo e($user->phone); ?></li>
                                            <li class="list-group-item"><?php echo e($user->email); ?></li>
                                            <li class="list-group-item"><?php echo e($user->country); ?></li>
                                            <li class="list-group-item"><?php echo e($user->state); ?> <?php echo e($user->city); ?> <?php echo e($user->street1); ?></li>
                                            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($user->street2): ?>
                                                <li class="list-group-item"><?php echo e($user->street2); ?></li>
                                            <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                            <li class="list-group-item"><?php echo e($user->postal); ?></li>
                                        </ul>
                                    </div>

                                    <!-- Formulario edición datos -->
                                    <div class="tab-pane fade" id="nav-profile" role="tabpanel"
                                         aria-labelledby="nav-profile-tab">
                                        <form action="<?php echo e(url('paypal/success')); ?>" method="POST" id="form">
                                            <input type="hidden" name="type" value="form">
                                            <?php echo csrf_field(); ?>
                                            <input type="hidden" name="trans_id" value="<?php echo e($user->trans_id); ?>">

                                            <div class="row">
                                                <div class="col-md-6 mb-3">
                                                    <label for="country" class="form-label small text-gray">País/región <span style="color: red;">*</span></label>
                                                    <select class="nice-select" name="country" id="country" required>
                                                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::openLoop(); ?><?php endif; ?><?php $__currentLoopData = $countries; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $k=>$v): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::startLoopIteration(); ?><?php endif; ?>
                                                            <option <?php echo e($k === $user->country ? 'selected' : ''); ?> value="<?php echo e($k); ?>"><?php echo e($v); ?></option>
                                                        <?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; ?>
                                                    </select>
                                                </div>

                                                <div class="col-md-6 mb-3">
                                                    <label for="first-name" class="form-label small text-gray">Nombre y apellidos <span style="color: red;">*</span></label>
                                                    <input class="form-control" name="name" id="first-name" type="text"
                                                           value="<?php echo e($user->name); ?>" required>
                                                </div>

                                                <div class="col-md-6 mb-3">
                                                    <label for="email-address" class="form-label small text-gray">Correo electrónico <span style="color: red;">*</span></label>
                                                    <input class="form-control" name="email" id="email-address" type="email"
                                                           required value="<?php echo e($user->email); ?>">
                                                </div>

                                                <div class="col-md-6 mb-3">
                                                    <label for="phone-number" class="form-label small text-gray">Número de teléfono <span style="color: red;">*</span></label>
                                                    <input class="form-control" name="phone" id="phone-number" type="text"
                                                           required value="<?php echo e($user->phone); ?>">
                                                </div>

                                                <div class="col-md-6 mb-3">
                                                    <label for="notice" class="form-label small text-gray">Línea de dirección 1 <span style="color: red;">*</span></label>
                                                    <input class="form-control" name="street1" id="notice" required
                                                           value="<?php echo e($user->street1); ?>">
                                                </div>

                                                <div class="col-md-6 mb-3">
                                                    <label for="zip" class="form-label small text-gray">Código postal <span style="color: red;">*</span></label>
                                                    <input class="form-control" name="postal" id="zip" type="text" required
                                                           value="<?php echo e($user->postal); ?>">
                                                </div>

                                                <div class="col-md-6 mb-3">
                                                    <label for="city" class="form-label small text-gray">Ciudad <span style="color: red;">*</span></label>
                                                    <input class="form-control" name="city" id="city" type="text" required
                                                           value="<?php echo e($user->city); ?>">
                                                </div>
                                                <div class="col-md-6 mb-3">
                                                    <label for="city" class="form-label small text-gray">Provincia/Ciudad autónoma <span style="color: red;">*</span></label>
                                                    <input class="form-control" name="state" id="state" type="text" required
                                                           value="<?php echo e($user->state); ?>">
                                                </div>
                                                <div class="col-12 text-center mt-4">
                                                    <button type="button" id="form-update"
                                                            class="btn btn-lg btn-success">
                                                        Confirmar
                                                    </button>
                                                </div>
                                            </div>
                                        </form>
                                    </div>
                                </div>
                            </div>
                        </div>
                    <?php else: ?>
                        <p>
                            Si necesitas ayuda, contacta con nuestro servicio de atención al cliente en el correo
                            <a href="mailto:<?php echo e(infoEmail()->email); ?>"><?php echo e(infoEmail()->email); ?></a>.
                        </p>
                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                </div>
            </div>
        </div>
    </section>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('js'); ?>
    <!-- Script validación formulario -->
    <script src="/static/js/form-validate.js"></script>

    <script>
        // Gestión manual de pestañas Bootstrap
        $(function () {
            $('#nav-tab a').on('click', function (e) {
                e.preventDefault();
                $(this).tab('show');
            });
        });

        // Lógica envío formulario AJAX
        document.getElementById('form-update').addEventListener('click', function () {
            let validator = new FormValidator('form');
            if (validator.validateForm()) {
                const form = document.getElementById('form');
                const formDataArray = [];
                const elements = form.elements;
                for (let i = 0; i < elements.length; i++) {
                    const elem = elements[i];
                    if (!elem.name || elem.disabled || ['submit', 'reset', 'button'].includes(elem.type)) {
                        continue;
                    }
                    if (['checkbox', 'radio'].includes(elem.type) && !elem.checked) {
                        continue;
                    }
                    if (elem.tagName === 'SELECT') {
                        const selectedOption = elem.options[elem.selectedIndex];
                        formDataArray.push({
                            name: elem.name,
                            value: selectedOption.value || selectedOption.textContent
                        });
                        continue;
                    }
                    formDataArray.push({
                        name: elem.name,
                        value: elem.value
                    });
                }
                const formData = {};
                formDataArray.forEach(field => {
                    if (formData[field.name]) {
                        if (!Array.isArray(formData[field.name])) {
                            formData[field.name] = [formData[field.name]];
                        }
                        formData[field.name].push(field.value);
                    } else {
                        formData[field.name] = field.value;
                    }
                });

                $.ajax({
                    url: '<?php echo e(url('paypal/success')); ?>',
                    method: 'post',
                    dataType: 'json',
                    headers: {
                        'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content,
                    },
                    data: formData,
                    success: function (response) {
                        if (response.status === 'success') {
                            alert('¡Actualización realizada correctamente!');
                            window.location.reload();
                        }
                    }
                });
                return false;
            }
        });
    </script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH D:\laragon\2026\es0701\resources\views/paypal/success.blade.php ENDPATH**/ ?>