<?php /* @var $theView fpcm\view\viewVars */ /* @var $file fpcm\model\files\mediaFile */ ?>
<div class="justify-content-end">

    <?php if ($showPager && in_array($mode, [2, 3, 4])) : ?>
    <div class="navbar">
        <div class="container-fluid">
            <div class="navbar me-auto d-flex gap-1"></div>
            <div class="navbar ms-auto gap-1">
                <?php print $pager; ?>
            </div>
        </div>
    </div>
    <?php endif; ?>

    <?php if ($filterError) : ?>
    <p class="p-3"><?php $theView->icon('search')->setStack('ban text-danger')->setSize('lg')->setStackTop(true); ?> <?php $theView->write('SEARCH_ERROR'); ?></p>
    <?php elseif (!count($files)) : ?>
    <p class="p-3"><?php $theView->icon('images', 'far')->setStack('ban text-danger')->setSize('lg')->setStackTop(true); ?> <?php $theView->write('GLOBAL_NOTFOUND2'); ?></p>
    <?php else : ?>
        <?php $i = 0; ?>
        <?php foreach($files AS $file) : ?>
        <?php $i++; ?>
        <div class="row g-0 px-3 fpcm ui-files-list">
            <div class="card w-100 my-2 fpcm ui-files-item ui-background-transition shadow">
                <div class="row g-0">
                    <div class="col-auto align-self-center me-3">
                    <?php if ($file->isImage()) : ?>                        
                        <a href="<?php print $file->getFileUrl(); ?>"
                           class="fpcm ui-link-fancybox"
                           data-pswp-width="<?php print $file->getWidth(); ?>"
                           data-pswp-height="<?php print $file->getHeight(); ?>">
                        <?php if ($file->hasFileManageThumbnail()) : ?>
                            <img class="img-fluid rounded-start" loading="lazy" 
                                 src="<?php print $file->getFileManagerThumbnailUrl(); ?>" 
                                 title="<?php print $file->getFileName(); ?>" 
                                 alt="<?php if ($file->getAltText()) : ?><?php print $theView->escapeVal($file->getAltText()); ?><?php else : ?><?php print $theView->escapeVal(basename($file->getFilename())); ?><?php endif; ?>"                                 
                                 width="<?php print $thumbsize; ?>"
                                 height="<?php print $thumbsize; ?>">
                        <?php else : ?>
                            <img class="img-fluid rounded-start p-5" loading="lazy" src="<?php print fpcm\classes\loader::libGetFileUrl('font-awesome/svg/file-image.svg'); ?>" title="<?php print $file->getFileName(); ?>" width="<?php print $thumbsize; ?>" height="<?php print $thumbsize; ?>">
                        <?php endif; ?>
                        </a>
                    <?php elseif ($file->isAudioVideo()) : ?>
                        <video controls
                               width="<?php print $thumbsize; ?>"
                               height="<?php print $thumbsize; ?>"
                               class="rounded-start<?php if ($file->isAudio()) : ?> bg-body-tertiary p-3<?php endif; ?>" 
                               <?php if ($file->isAudio()) : ?>poster="<?php print fpcm\classes\loader::libGetFileUrl('font-awesome/svg/file-audio.svg'); ?>"<?php endif; ?>>
                            <source src="<?php print $file->getFileUrl(); ?>" type="<?php print $file->getMimetype(); ?>">
                        </video>
                    <?php endif; ?>
                    </div>
                    <div class="col-auto align-self-center flex-grow-1">
                        <div class="card-body">
                            <p class="card-title"><?php print $theView->escapeVal(basename($file->getFilename())); ?></p>
                            <?php if ($file->getAltText()) : ?>
                            <p class="card-subtitle fs-6 text-secondary-emphasis"><?php print $theView->escapeVal($file->getAltText()); ?></p>
                            <?php endif; ?>
                            <div class="card-text mb-3">
                                <?php if (!$file->existsFolder()) : ?>
                                    <?php $theView->alert('danger')->setIcon('image', 'far')->setText('FILE_LIST_UPLOAD_NOTFOUND'); ?>
                                <?php endif; ?>
                            </div>

                            <div class="navbar gap-1 justify-content-start">
                            <?php $btnList = $file->isAudioVideo() ? 'videos' : 'images'; ?>
                            <?php include $theView->getIncludePath('filemanager/buttons/'.$btnList.'.php'); ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <?php endforeach; ?>
    <?php endif; ?>
</div>