<?php $__env->startPush('styles'); ?>
    <link rel="stylesheet" href="<?php echo e(asset('assets/css/profile-details.css')); ?>">
<?php $__env->stopPush(); ?>

<?php $__env->startSection('content'); ?>
    <?php
        $content = $profileDetailsContent ?? [];
        $name = trim((string) data_get($candidate, 'candidate_name', 'Candidate'));
        $code = trim((string) data_get($candidate, 'ref_no', ''));
        $country = trim((string) data_get($candidate, 'nationality', '-'));
        $religion = trim((string) data_get($candidate, 'religion', '-'));
        $languages = array_values(array_filter((array) data_get($candidate, 'languages', [])));
        $experience = trim((string) data_get($candidate, 'experience_bucket', '-'));
        $salary = data_get($candidate, 'salary');
        $salaryText = is_numeric($salary) ? number_format((int) $salary) . ' AED / month' : '-';
        $photo = trim((string) data_get($candidate, 'photo', ''));
        $cvUrl = trim((string) data_get($candidate, 'cv_url', ''));
        $videoUrl = trim((string) data_get($candidate, 'video', ''));

        $backText = (string) data_get($content, 'back.text', 'Back to profiles');
        $featuredProfileText = (string) data_get($content, 'hero.featured_profile', 'Featured Profile');
        $codeLabel = (string) data_get($content, 'hero.code_label', 'Code');

        $nationalityLabel = (string) data_get($content, 'labels.nationality', 'Nationality');
        $religionLabel = (string) data_get($content, 'labels.religion', 'Religion');
        $languagesLabel = (string) data_get($content, 'labels.languages', 'Languages');
        $experienceLabel = (string) data_get($content, 'labels.experience', 'Experience');
        $expectedSalaryLabel = (string) data_get($content, 'labels.expected_salary', 'Expected Salary');

        $hireWhatsappText = (string) data_get($content, 'actions.hire_whatsapp', 'Hire on WhatsApp');
        $viewCvText = (string) data_get($content, 'actions.view_cv', 'View CV');
        $cvNotAvailableText = (string) data_get($content, 'actions.cv_not_available', 'CV Not Available');
        $playVideoText = (string) data_get($content, 'actions.play_video', 'Play video');
        $videoNotAvailableText = (string) data_get($content, 'actions.video_not_available', 'Video not available');

        $otherProfilesTitle = (string) data_get($content, 'other_profiles.title', 'View Other Profiles');
        $otherProfilesDesc = (string) data_get($content, 'other_profiles.description', 'Explore more candidates and open any profile for full details.');
        $viewProfileText = (string) data_get($content, 'other_profiles.view_profile', 'View profile');
        $viewMoreProfilesText = (string) data_get($content, 'other_profiles.view_more_profiles', 'View More Profiles');

        $waPhone = (string) data_get($content, 'whatsapp.phone', '97180032332');
        $waTemplate = (string) data_get($content, 'whatsapp.message_template', 'Hello, I am interested in hiring {name} ({code}).');
        $waMessage = rawurlencode(str_replace(['{name}', '{code}'], [$name, $code], $waTemplate));
        $waHireUrl = 'https://wa.me/' . $waPhone . '?text=' . $waMessage;
    ?>

    <div class="profile-video-modal" id="profileVideoModal" aria-hidden="true">
        <div class="profile-video-backdrop" id="profileVideoBackdrop"></div>
        <div class="profile-video-dialog">
            <button class="profile-video-close" id="profileVideoClose" type="button" aria-label="Close video">
                <i class="fa-solid fa-xmark"></i>
            </button>
            <video id="profileVideoPlayer" controls playsinline preload="metadata"></video>
        </div>
    </div>

    <section class="profile-details-page section-space">
        <div class="main-container">
            <a class="back-link" href="<?php echo e($locale === 'ar' ? route('ar.profiles') : route('profiles')); ?>">&larr; <?php echo e(e($backText)); ?></a>

            <div class="profile-hero-card">
                <div class="profile-hero-media">
                    <?php if($photo !== ''): ?>
                        <img src="<?php echo e(e($photo)); ?>" alt="<?php echo e(e($name)); ?>">
                    <?php else: ?>
                        <div class="profile-photo-fallback"><?php echo e(strtoupper(substr($name, 0, 1))); ?></div>
                    <?php endif; ?>
                </div>

                <div class="profile-hero-content">
                    <p class="profile-pill"><?php echo e(e($featuredProfileText)); ?></p>
                    <h1><?php echo e(e($name)); ?></h1>
                    <?php if($code !== ''): ?>
                        <p class="profile-code"><?php echo e(e($codeLabel)); ?>: <?php echo e(e($code)); ?></p>
                    <?php endif; ?>

                    <div class="profile-quick-details">
                        <div class="quick-row">
                            <span class="label"><?php echo e(e($nationalityLabel)); ?></span>
                            <span class="value"><?php echo e(e($country)); ?></span>
                        </div>
                        <div class="quick-row">
                            <span class="label"><?php echo e(e($religionLabel)); ?></span>
                            <span class="value"><?php echo e(e($religion)); ?></span>
                        </div>
                        <div class="quick-row">
                            <span class="label"><?php echo e(e($languagesLabel)); ?></span>
                            <span class="value"><?php echo e(e(count($languages) ? implode(', ', $languages) : '-')); ?></span>
                        </div>
                        <div class="quick-row">
                            <span class="label"><?php echo e(e($experienceLabel)); ?></span>
                            <span class="value"><?php echo e(e($experience !== '' ? $experience : '-')); ?></span>
                        </div>
                        <div class="quick-row">
                            <span class="label"><?php echo e(e($expectedSalaryLabel)); ?></span>
                            <span class="value"><?php echo e(e($salaryText)); ?></span>
                        </div>
                    </div>

                    <div class="profile-action-buttons">
                        <a class="btn-profile-action btn-hire-whatsapp" href="<?php echo e(e($waHireUrl)); ?>" target="_blank" rel="noopener noreferrer">
                            <i class="fa-brands fa-whatsapp"></i>
                            <span><?php echo e(e($hireWhatsappText)); ?></span>
                        </a>
                        <?php if($cvUrl !== ''): ?>
                            <a class="btn-profile-action btn-view-cv" href="<?php echo e(e($cvUrl)); ?>" target="_blank" rel="noopener noreferrer">
                                <i class="fa-regular fa-file-lines"></i>
                                <span><?php echo e(e($viewCvText)); ?></span>
                            </a>
                        <?php else: ?>
                            <button class="btn-profile-action btn-view-cv is-disabled" type="button" disabled>
                                <i class="fa-regular fa-file-lines"></i>
                                <span><?php echo e(e($cvNotAvailableText)); ?></span>
                            </button>
                        <?php endif; ?>
                        <?php if($videoUrl !== ''): ?>
                            <button class="btn-profile-action btn-play-video profile-video-modal-open" type="button" data-video="<?php echo e(e($videoUrl)); ?>" aria-label="<?php echo e(e($playVideoText)); ?>">
                                <i class="fa-solid fa-play"></i>
                                <span><?php echo e(e($playVideoText)); ?></span>
                            </button>
                        <?php else: ?>
                            <button class="btn-profile-action btn-play-video is-disabled" type="button" disabled>
                                <i class="fa-solid fa-play"></i>
                                <span><?php echo e(e($videoNotAvailableText)); ?></span>
                            </button>
                        <?php endif; ?>
                    </div>
                </div>
            </div>

            <?php if(!empty($otherProfiles) && count($otherProfiles)): ?>
                <div class="other-profiles-wrap">
                    <div class="other-profiles-head">
                        <h2><?php echo e(e($otherProfilesTitle)); ?></h2>
                        <p><?php echo e(e($otherProfilesDesc)); ?></p>
                    </div>

                    <div class="other-profiles-grid">
                        <?php $__currentLoopData = $otherProfiles; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <?php
                                $itemName = trim((string) data_get($item, 'candidate_name', 'Candidate'));
                                $itemSlug = trim((string) data_get($item, 'slug', ''));
                                $itemPhoto = trim((string) data_get($item, 'photo', ''));
                                $itemCode = trim((string) data_get($item, 'ref_no', ''));
                                $itemVideo = trim((string) data_get($item, 'video', ''));
                                $itemCountry = trim((string) data_get($item, 'nationality', '-'));
                                $itemReligion = trim((string) data_get($item, 'religion', '-'));
                                $itemLanguages = array_values(array_filter((array) data_get($item, 'languages', [])));
                                $itemExp = trim((string) data_get($item, 'experience_bucket', '-'));
                                $itemSalary = data_get($item, 'salary');
                                $itemSalaryText = is_numeric($itemSalary) ? number_format((int) $itemSalary) . ' AED / month' : '-';
                                $itemUrl = $itemSlug !== ''
                                    ? ($locale === 'ar' ? route('ar.profiles.show', ['slug' => $itemSlug]) : route('profiles.show', ['slug' => $itemSlug]))
                                    : '#';
                            ?>

                            <a class="other-profile-card" href="<?php echo e(e($itemUrl)); ?>">
                                <div class="thumb">
                                    <?php if($itemPhoto !== ''): ?>
                                        <img src="<?php echo e(e($itemPhoto)); ?>" alt="<?php echo e(e($itemName)); ?>">
                                    <?php else: ?>
                                        <div class="profile-photo-fallback"><?php echo e(strtoupper(substr($itemName, 0, 1))); ?></div>
                                    <?php endif; ?>
                                    <?php if($itemCode !== ''): ?>
                                        <span class="ref-chip"><?php echo e(e($itemCode)); ?></span>
                                    <?php endif; ?>
                                    <?php if($itemVideo !== ''): ?>
                                        <button class="profile-video-trigger profile-video-trigger-sm" type="button" data-video="<?php echo e(e($itemVideo)); ?>" aria-label="Play profile video">
                                            <i class="fa-solid fa-play"></i>
                                        </button>
                                    <?php endif; ?>
                                </div>
                                <div class="meta">
                                    <h3><?php echo e(e($itemName)); ?></h3>
                                    <p class="meta-line"><?php echo e(e($itemCountry)); ?> &middot; <?php echo e(e($itemReligion !== '' ? $itemReligion : '-')); ?></p>
                                    <p class="meta-line"><strong>Languages:</strong> <?php echo e(e(count($itemLanguages) ? implode(', ', $itemLanguages) : '-')); ?></p>
                                    <p class="meta-line"><strong>Experience:</strong> <?php echo e(e($itemExp !== '' ? $itemExp : '-')); ?></p>
                                    <p class="meta-line"><strong>Salary:</strong> <?php echo e(e($itemSalaryText)); ?></p>
                                    <span class="view-link"><?php echo e(e($viewProfileText)); ?></span>
                                </div>
                            </a>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </div>

                    <div class="more-profiles-cta">
                        <a class="btn-view-more-profiles" href="<?php echo e($locale === 'ar' ? route('ar.profiles') : route('profiles')); ?>">
                            <i class="fa-solid fa-users"></i>
                            <span><?php echo e(e($viewMoreProfilesText)); ?></span>
                        </a>
                    </div>
                </div>
            <?php endif; ?>
        </div>
    </section>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
<script>
(() => {
    const modal = document.getElementById('profileVideoModal');
    const backdrop = document.getElementById('profileVideoBackdrop');
    const closeBtn = document.getElementById('profileVideoClose');
    const triggers = Array.from(document.querySelectorAll('.profile-video-modal-open[data-video], .profile-video-trigger[data-video]'));
    const video = document.getElementById('profileVideoPlayer');
    if (!modal || !video || !triggers.length) return;

    const openVideo = (url) => {
        if (!url) return;
        video.src = url;
        video.load();
        modal.classList.add('show');
        modal.setAttribute('aria-hidden', 'false');
        document.body.classList.add('profile-video-open');
    };

    const closeVideo = () => {
        modal.classList.remove('show');
        modal.setAttribute('aria-hidden', 'true');
        document.body.classList.remove('profile-video-open');
        video.pause();
        video.currentTime = 0;
        video.removeAttribute('src');
        video.load();
    };

    triggers.forEach((trigger) => {
        trigger.addEventListener('click', (event) => {
            event.preventDefault();
            event.stopPropagation();
            openVideo(trigger.getAttribute('data-video') || '');
        });
    });
    closeBtn?.addEventListener('click', closeVideo);
    backdrop?.addEventListener('click', closeVideo);
    document.addEventListener('keydown', (event) => {
        if (event.key === 'Escape' && modal.classList.contains('show')) closeVideo();
    });
})();
</script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make($locale === 'ar' ? 'layouts.app_rtl' : 'layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/onesourceerp/public_html/project/resources/views/profile_details.blade.php ENDPATH**/ ?>