

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

    <title>相册</title>

    <link rel="shortcut icon" href="/static//static/images/favicon.ico" type="image/x-icon">
    <link rel="icon" href="/static//static/images/favicon.ico" type="image/x-icon">

    <link rel="stylesheet" href="/static/css/swiper-bundle.min.css">
    <link rel="stylesheet" href="/static/css/font-awesome.min.css">
    <link rel="stylesheet" href="/static/css/magnific-popup.min.css">
    <link rel="stylesheet" href="/static/css/animate.min.css">
    <link rel="stylesheet" href="/static/js/layui/css/layui.css">
    <link rel="stylesheet" href="/static/css/main.css?v=2025041601">

</head>
<style>
    .video-hover-container {
        position: relative;
        display: inline-block;
    }

    .video-hover-container img,
    .video-hover-container video {
        display: block;
        object-fit: cover;
    }

    .video-hover-container a {
        display: block;
        position: relative;
    }

    /* Spinner styles */
    .spinner {
        width: 40px;
        height: 40px;
        border: 4px solid #fff;
        border-top: 4px solid transparent;
        border-radius: 50%;
        animation: spin 1s linear infinite;
    }

    @keyframes spin {
        0% { transform: rotate(0deg); }
        100% { transform: rotate(360deg); }
    }
</style>

<body class="main-body">

<div class="menu-overlay"></div>


<main class="main">

    <section class="gallery">

{{--        @include('__sidebar', ['foldersTree'=> $foldersTree,'active'=>true])--}}

        <div class="update-content">
            <div class="update-log" >
                <a href="/update-log" class="update-log-link">
                    <div class="timestamp"><i class="fa fa-volume-up"></i> <span class="update-time">&nbsp;</span> <span class="user_name">&nbsp;</span> <span class="action">&nbsp;</span> <span class="model">&nbsp;</span>  <span class="highlight log-content">&nbsp;</span></div>
                </a>
{{--                <a href="javascript:void(0)" onclick="logout()" class="login-out-link">--}}
{{--                    退出登录--}}
{{--                </a>--}}
                <div class="clear"></div>
            </div>
        </div>


        <div class="content-page gallery-content gallery-wrap">
            <div class="content-inner">
                <div class="title-wrapper" style="margin-left: 0">
                    <h2 class="title">{{$album['model']}}</h2>
                    <div class="subtitle">
                        <p></p>
                    </div>
                </div>

                <div class="album-tab">
                    @foreach($showTabs as $tab)
                        <a href="#album-{{$tab['column']}}" @if($loop->first)class="is-active"@endif column={{$tab['column']}}>{{$tab['title']}}</a>
                    @endforeach
                </div>

                <!-- Album Animals START -->
                <div class="gallery-album-line">
                    <a href="javascript:history.back();" class="gallery-album-prev"><i class="fa fa-angle-double-left"></i> 返回 </a>
                    <a href="javascript:void(0);" class="download-all">下载全部 <i class="fa fa-download"></i></a>
                </div>

                @foreach($showTabs as $tab)
                <div class="grid-album @if($loop->first)gallery-album is-active @endif" id="album-{{$tab['column']}}">
                    @php
                        $content = json_decode($album[$tab['column']], true);
                    @endphp
                    @if (empty($content))
                        数据为空
                    @endif

                    @if ($tab['column'] == 'video' || $tab['column'] == 'pdf')
                        @if ($tab['column'] == 'video' && empty($content) == false)
                            <?php
                                //$content倒序
                                array_walk($content, function(&$item, $index) {
                                    $item['__index'] = $index;
                                });
                                usort($content, function($a, $b) {
                                    // order > 0 的元素组内排序（倒序）
                                    if ($a['order'] > 0 && $b['order'] > 0) {
                                        return $b['order'] <=> $a['order'];
                                    }
                                    // order = 0 的元素组内排序（按原始索引倒序）
                                    elseif ($a['order'] == 0 && $b['order'] == 0) {
                                        return $b['__index'] <=> $a['__index']; // 注意这里用b比a
                                    }
                                    // 不同组间的排序（order>0的总是排在最前）
                                    else {
                                        return ($a['order'] > 0) ? -1 : 1;
                                    }
                                });
                            ?>
                            <table class="album_table">
                                <thead>
                                <tr>
                                    <th>图片</th>
                                    <th>中文标题</th>
                                    <th>英文标题</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($content as $item)
                                <tr>
                                    <td class="video-hover-container">
                                        <a href="javascript:void(0)" style="display: inline-block;">
                                            <img src="{{ossUrl($item['cover'])}}?x-oss-process=image/resize,w_260" class="void-img" data-index="{{$loop->index}}" data-preview="{{ossUrl($item['preview_url'])}}" data-poster="{{ossUrl($item['cover'])}}?x-oss-process=image/resize,w_260">
                                        </a>
                                    </td>
                                    <td>
                                        {{@$item['video_title']}}
                                    </td>
                                    <td>
                                        {{@$item['video_en_title']}}
                                    </td>
                                    <td>
                                        <button data-src="{{ossUrl($item['video_src'])}}" class="video-btn">播放</button>
                                        <a href="/download?url={{urlencode(ossUrl($item['video_src']))}}" download class="download-btn" target="_blank"><button>下载</button></a>
                                    </td>
                                </tr>
                                @endforeach
                                </tbody>
                            </table>
                            <br/>
                        @endif

                        @if ($tab['column'] == 'pdf' && empty($content) == false)
                                <table class="album_table">
                                    <thead>
                                    <tr>
                                        <th>PDF标题</th>
                                        <th>PDF标题(英文)</th>
                                        <th width="15%">操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    @foreach($content as $item)
                                        <tr>
                                            <td>{{$item['pdf_title']}}</td>
                                            <td>{{@$item['pdf_title_en']}}</td>
                                            <td>
                                                <a href="/download?url={{urlencode(ossUrl($item['pdf_src']))}}" download class="download-btn" target="_blank"><button>下载</button></a>
                                            </td>
                                        </tr>
                                    @endforeach
                                    </tbody>
                                </table>
                            <br/>
                        @endif
                    @elseif ($tab['column'] == 'parameters' && empty($content) == false)
                        <table class="album_table">
                            <thead>
                            <tr>
                                <th>属性名</th>
                                <th>属性值</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($content as $item)
                                <tr>
                                    <td>{{$item['key']}}</td>
                                    <td>
                                        {{$item['value']}}
                                    </td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                    @else
                        <div class="grid-sizer"></div>
                        @foreach($content as $item)
                        <div class="grid-item album-item">
                            <div class="album-thumb album-thumb-detail">
                                <img  data-src="{{ossUrl($item)}}" src="{{ossUrl($item)}}?x-oss-process=image/resize,w_380"  loading="lazy" alt="1">
                                <div class="album-mask">
                                    <!-- 下载图标 -->
                                    <a href="javascript:void(0)" data-src="{{ossUrl($item)}}" download class="download-icon">
                                        <i class="fa fa-cloud-download"></i>
                                    </a>
                                </div>
                            </div>
                        </div>
                        @endforeach
                    @endif
                </div>
                @endforeach
                <!-- Album Animals END -->
            </div><!-- end container-inner -->
        </div>

        <!-- 视频遮罩层 -->
        <div id="overlay" class="overlay">
            <div class="video-container">
                <video id="videoPlayer" controls>
                    Your browser does not support the video tag.
                </video>
            </div>
        </div>

    </section> <!-- end gallery -->
</main>

{{--<footer class="site-footer">--}}
{{--    <div class="footer-copyright">--}}
{{--        © 2025 <strong>mietub</strong>. All rights reserved.--}}
{{--    </div>--}}
{{--</footer>--}}



<script src="/static/js/jquery-3.7.0.min.js"></script>
<script src="/static/js/swiper-bundle.min.js"></script>
<script src="/static/js/wow.min.js"></script>
<script src="/static/js/masonry.pkgd.min.js"></script>
<script src="/static/js/imagesloaded.pkgd.min.js"></script>
<script src="/static/js/magnific-popup.min.js"></script>
<script src="/static/js/blazy.min.js"></script>
<script src="/static/js/parazoom.min.js"></script>
<script src="/static/js/layui/layui.js"></script>
<script src="/static/js/script.js"></script>


<script>
    $(document).ready(function() {
        $('.grid-album:first').addClass('');
    });

    // 视频预览播放
    $(document).ready(function() {
        function isMobile() {
            return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
        }
        $('.video-hover-container').each(function() {
            var $container = $(this);
            var $img = $container.find('img');
            $img.data('original-src', $img.attr('src'));
        });

        // Object to track load status using data-index as key
        var loadIndexes = {};
        var loadingVar = {};

        $('.video-hover-container').on('mouseenter', function(e) {
            if (isMobile()) {
                return;
            }
            e.preventDefault(); // Prevent link default behavior during hover
            var $container = $(this);
            var $img = $container.find('img');
            var $link = $container.find('a');
            var videoUrl = $img.data('preview');
            var posterUrl = $img.data('poster');
            var index = $img.data('index'); // Get the data-index value

            // Initialize loadIndexes[index] if not set
            if (!loadIndexes.hasOwnProperty(index)) {
                loadIndexes[index] = 0;
            }

            // Create loading overlay
            loadingVar[index] = $('<div>', {
                class: 'loading-overlay',
                css: {
                    position: 'absolute',
                    top: 0,
                    left: 0,
                    width: '100%',
                    height: '100%',
                    background: 'rgba(0,0,0,0.5)',
                    display: 'flex',
                    alignItems: 'center',
                    justifyContent: 'center',
                    zIndex: 10
                }
            }).append('<div class="spinner"></div>');

            // Create video element
            var $video = $('<video>', {
                src: videoUrl,
                poster: posterUrl,
                autoplay: true,
                muted: true,
                loop: true,
                css: {
                    width: $img.width(),
                    height: $img.height(),
                    display: 'none' // Initially hidden until loaded
                }
            }).on('loadedmetadata', function() {
                $(this).prop('muted', true); // 确保静音
            });

            if (loadIndexes[index] === 0 && videoUrl != "") {
                loadIndexes[index] = 1;
                $container.css('position', 'relative');
                $link.append(loadingVar[index]);
            }

            // When video can play
            $video.on('canplay', function() {
                if (loadIndexes[index] === 1) {
                    loadIndexes[index] = 2;
                    loadingVar[index].remove();
                    $img.hide();
                    $video.show();
                    $link.append($video);
                }
            });

            // Maintain link functionality
            $link.on('click', function(e) {
                if ($video.is(':visible')) {
                    e.preventDefault(); // Prevent click when video is showing
                }
            });
        });

        $('.video-hover-container').on('mouseleave', function() {
            var $container = $(this);
            var $img = $container.find('img');
            var index = $img.data('index'); // Get the data-index value

            if (loadIndexes[index] === 2 || loadIndexes[index] === 1) {
                loadIndexes[index] = 0;
                var $video = $container.find('video');
                var $loading = $container.find('.loading-overlay');
                $video.remove();
                $loading.remove();
                $img.show();
            }
        });
    });
</script>
</body>
</html>
