<?php if (isset($component)) { $__componentOriginal2587877bb4e520741a841aceca30fb82 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal2587877bb4e520741a841aceca30fb82 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.mb-layout','data' => ['pageTitle' => $pageTitle ?? 'Google Ads chat','conversations' => $conversations,'conversationId' => $conversationId,'googleChat' => true]] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('mb-layout'); ?>
<?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(['page-title' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($pageTitle ?? 'Google Ads chat'),'conversations' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($conversations),'conversation-id' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($conversationId),'google-chat' => true]); ?>
    <?php $__env->startPush('styles'); ?>
        <style>
            .mb-platform-choice { max-width: 760px; margin: 0 auto 28px; padding: 28px; border: 1px solid var(--mb-border); border-radius: 16px; background: var(--mb-surface); box-shadow: 0 8px 24px rgba(15, 23, 42, .06); }
            .mb-platform-choice-title { color: var(--mb-text); font-size: 1.1rem; font-weight: 700; }
            .mb-platform-choice-note { margin-top: 6px; color: var(--mb-text-muted); font-size: .9rem; }
            .mb-platform-choice-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 20px; }
            .mb-google-upload { max-width: 760px; margin: 0 auto 18px; padding: 14px 16px; border: 1px solid var(--mb-border); border-radius: 12px; background: var(--mb-surface); }
            @media (max-width: 640px) { .mb-platform-choice { padding: 20px; } .mb-platform-choice-actions { grid-template-columns: 1fr; } }
        </style>
    <?php $__env->stopPush(); ?>
    <section class="mb-chat" data-context="Manage Google Ads campaigns">
        <div class="mb-chat-scroll" id="chatScroll">
            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(empty($transcript)): ?>
                <div class="mb-platform-choice" id="platformChoice">
                    <div class="mb-platform-choice-title">Start with your landing page</div>
                    <div class="mb-platform-choice-note">We will analyze it first, then guide you through account and campaign setup.</div>
                    <form id="landingForm" class="mt-3">
                        <label class="form-label" for="landingUrl">Landing page URL</label>
                        <div class="input-group">
                            <input class="form-control" id="landingUrl" type="url" placeholder="https://example.com" required>
                            <button class="btn btn-primary" type="submit">Continue</button>
                        </div>
                    </form>
                    <div id="platformStep" hidden>
                        <div class="mb-platform-choice-note mt-3">Which platforms should this campaign support?</div>
                        <div class="mb-platform-choice-actions">
                            <button type="button" class="btn btn-outline-primary" data-platform-choice="google"><i class="bi bi-google me-1"></i> Google Ads</button>
                            <button type="button" class="btn btn-dark" data-platform-choice="both"><i class="bi bi-layers me-1"></i> Google Ads + Meta</button>
                        </div>
                    </div>
                </div>
            <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>

            <div id="msgs" class="d-flex flex-column">
                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__currentLoopData = $transcript; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $message): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <div class="mb-msg<?php echo e($message['role'] === 'user' ? ' me' : ''); ?>">
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($message['html']): ?>
                            <?php echo $message['html']; ?>

                        <?php else: ?>
                            <?php echo e($message['text']); ?>

                        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                    </div>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
            </div>
        </div>
        <form id="googleImageUpload" class="mb-google-upload" hidden>
            <div class="d-flex flex-wrap gap-2 align-items-center">
                <strong>Upload a required Google Ads image</strong>
                <select class="form-select form-select-sm w-auto" id="googleImageField" aria-label="Image type">
                    <option value="marketing_image_assets">Landscape (1200x628)</option>
                    <option value="square_marketing_image_assets">Square (1200x1200)</option>
                </select>
            </div>
            <div class="input-group input-group-sm mt-2">
                <input class="form-control" id="googleImageFile" type="file" accept="image/*" required>
                <button class="btn btn-primary" type="submit">Submit</button>
            </div>
            <div id="googleImageUploadNote" class="small text-body-secondary mt-2">Choose an image with the exact dimensions shown.</div>
        </form>
        <div class="mb-composer-wrap">
            <div class="mb-composer" id="composerBox">
                <div class="mb-attachments" id="attachments"></div>
                <textarea rows="1" placeholder="Ask Google Ads to list, create, or update campaigns..." aria-label="Google Ads message" id="composer"></textarea>
                <div class="mb-composer-bar">
                    <button class="mb-icon-btn" data-pop="attach" aria-label="Add attachment" aria-haspopup="menu"><i class="bi bi-plus-lg"></i></button>
                    <button class="mb-send" data-action="send" aria-label="Send"><i class="bi bi-arrow-up"></i></button>
                </div>
                <input type="file" id="fileInput" multiple hidden accept="image/*,video/mp4,video/quicktime">
            </div>
        </div>

        <div class="mb-pop mb-menu mb-attach-menu d-none" id="pop-attach" role="menu">
            <button type="button" class="mb-menu-item" data-action="attach-file" role="menuitem"><i class="bi bi-paperclip"></i>Attach file</button>
        </div>
    </section>
    <?php $__env->startPush('scripts'); ?>
        <script>
            window.chat = {
                conversation: <?php echo json_encode($conversationId, 15, 512) ?>,
                sendUrl: <?php echo json_encode(route('googlechat.send'), 15, 512) ?>,
                uploadImageUrl: <?php echo json_encode(route('googlechat.upload-image'), 15, 512) ?>,
                platform: null,
                landingUrl: null,
                awaiting: <?php echo json_encode($awaiting ?? [], 15, 512) ?>,
                choices: <?php echo json_encode($choices ?? [], 15, 512) ?>,
                hasCampaign: false,
                token: <?php echo json_encode(csrf_token(), 15, 512) ?>,
            };
        </script>
        
        <script src="<?php echo e(asset('assets/js/chat.js')); ?>?v=<?php echo e(filemtime(public_path('assets/js/chat.js'))); ?>"></script>
        <script>
            document.getElementById('landingForm')?.addEventListener('submit', function (event) {
                event.preventDefault();
                window.chat.landingUrl = document.getElementById('landingUrl').value.trim();
                document.getElementById('landingForm').hidden = true;
                document.getElementById('platformStep').hidden = false;
            });
            document.querySelectorAll('[data-platform-choice]').forEach(function (button) {
                button.addEventListener('click', function () {
                    window.chat.platform = button.dataset.platformChoice;
                    document.getElementById('platformChoice')?.remove();
                    document.getElementById('composer').value = 'Analyze my landing page and start a Google Ads campaign.';
                    window.MB.Composer.submit();
                });
            });
            document.getElementById('googleImageUpload')?.addEventListener('submit', function (event) {
                event.preventDefault();
                var form = event.currentTarget;
                var file = document.getElementById('googleImageFile').files[0];
                var field = document.getElementById('googleImageField').value;
                var required = field === 'square_marketing_image_assets' ? [1200, 1200] : [1200, 628];
                var note = document.getElementById('googleImageUploadNote');
                if (!file) return;
                var image = new Image();
                image.onload = function () {
                    if (image.width !== required[0] || image.height !== required[1]) {
                        note.textContent = 'This image is '+image.width+'x'+image.height+'. Upload exactly '+required[0]+'x'+required[1]+'.';
                        return;
                    }
                    var body = new FormData(form);
                    body.append('conversation', window.chat.conversation || '');
                    body.append('image_field', field);
                    body.append('image', file);
                    note.textContent = 'Uploading...';
                    fetch(window.chat.uploadImageUrl, { method: 'POST', headers: { 'X-CSRF-TOKEN': window.chat.token, Accept: 'application/json' }, body: body })
                        .then(function (response) { return response.json().then(function (data) { return { ok: response.ok, data: data }; }); })
                        .then(function (result) {
                            if (!result.ok) {
                                note.textContent = result.data.message || 'Upload failed.';

                                return;
                            }

                            note.textContent = result.data.message || 'Image uploaded.';
                            document.getElementById('composer').value = 'The ' + field.replace(/_assets$/, '').replace(/_/g, ' ') + ' has been uploaded. Continue to the next campaign step.';
                            window.MB.Composer.submit();
                        })
                        .catch(function () { note.textContent = 'Upload failed. Try again.'; });
                };
                image.src = URL.createObjectURL(file);
            });
        </script>
    <?php $__env->stopPush(); ?>
 <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal2587877bb4e520741a841aceca30fb82)): ?>
<?php $attributes = $__attributesOriginal2587877bb4e520741a841aceca30fb82; ?>
<?php unset($__attributesOriginal2587877bb4e520741a841aceca30fb82); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal2587877bb4e520741a841aceca30fb82)): ?>
<?php $component = $__componentOriginal2587877bb4e520741a841aceca30fb82; ?>
<?php unset($__componentOriginal2587877bb4e520741a841aceca30fb82); ?>
<?php endif; ?>
<?php /**PATH /var/www/php85/koushik/arb.admedia.com/resources/views/googlechat.blade.php ENDPATH**/ ?>