<?php
if (TL_MODE == 'FE') {
    $GLOBALS['TL_CSS'][] = 'files/base/layout/css/elements/custom-elements/ce_rsce_headimagelogo.min.css|static';
}
?>

<div <?php echo $this->cssID; ?>
        class="content--element <?php echo $this->class; ?> <?php if ($this->pull_content) : ?>pull-content<?php endif; ?>">
    <div class="ce--inner <?php if ($this->boxed_image) : ?>with-boxed-logo<?php endif; ?>">

        <?php if ($this->headline || $this->subline || $this->topline) : ?>
        <div class="ce--headline"
             data-aos="<?php if ($this->animation_type) : ?><?php echo $this->animation_type; ?><?php else : ?>animate__fadeInUp<?php endif; ?>">
            <div class="container">
                <?php if ($this->topline) : ?>
                    <span class="ce--topline"><?php echo $this->topline; ?></span>
                <?php endif; ?>
                <?php if ($this->headline) : ?>
                <<?php echo($this->hl); ?>>
                <?php echo($this->headline); ?>
            </<?php echo($this->hl); ?>>
            <?php endif; ?>
            <?php if ($this->subline) : ?>
                <span class="ce--subline"><?php echo $this->subline; ?></span>
            <?php endif; ?>
        </div>
    </div>
    <?php endif; ?>

    <div class="<?php if (count($this->slides) > 1) : ?>swiper<?php endif; ?> mainslider mainslider_<?php echo $this->id; ?> <?php if ($this->image_height) : ?>not-fullHeight<?php endif; ?> <?php if ($this->diagonal_cut) : ?>with-diagonalCut<?php endif; ?>">
        <!-- Additional required wrapper -->
        <div class="swiper-wrapper">
            <!-- Slides -->

            <?php foreach ($this->slides as $key => $slide) : ?>

                <?php
                if (!property_exists($slide, "size")) {
                    $slide->{"size"} = "";
                }
                ?>


                <?php
                $filename = FilesModel::findByUuid($slide->image)->path;
                $ext = pathinfo($filename, PATHINFO_EXTENSION);
                $filename_mobile = FilesModel::findByUuid($slide->mobile_image)->path;
                $ext_mobile = pathinfo($filename_mobile, PATHINFO_EXTENSION);
                ?>

                <div class="swiper-slide">
                    <div class="ce--mainimage slide_<?php echo $key; ?> <?php echo $slide->text_style; ?>  <?php if (!$slide->text_firstline && !$slide->text_secondline) : ?>no-text<?php endif; ?> ">
                        <div class="image--holder <?php if ($this->image_maxheight) : ?>with-maxheight<?php endif; ?> <?php if ($ext == "mp4") : ?>with-video<?php endif; ?>"
                             style="background: url(<?= Image::get(FilesModel::findByUuid($slide->image)->path, $slide->size[0], $slide->size[1], $slide->size[2]); ?>) center center no-repeat; <?php if ($this->image_maxheight) : ?>max-height: <?php echo $this->image_maxheight; ?> !important;<?php endif; ?>  <?php if ($this->image_height) : ?>height: <?php echo $this->image_height; ?>vh; min-height: 250px;<?php endif; ?>">

                            <?php if ($slide->alternate_background_color): ?>
                                <style>
                                    <?php
                                        $color = $slide->alternate_background_color;
                                        $color = str_replace("&#41", ")",$color);
                                        $color = str_replace("&#40", "(",$color);
                                        $color = str_replace("(;", "(",$color);
                                        $color = str_replace("&#35;", "#",$color);
                                        $color = str_replace(");", ")",$color);
                                    ?>

                                    html body .ce_rsce_headimagelogo .mainslider_<?php echo $this->id;?> .slide_<?php echo $key;?>.style-2 .mainimage--content .mainimage--content-inner:before,
                                    html body .ce_rsce_headimagelogo .mainslider_<?php echo $this->id;?> .slide_<?php echo $key;?>.style-2 .mainimage--content .mainimage--content-inner .mainimage--content-inner--wrapper:after {
                                        background-color: <?= $color; ?> !important;
                                    }

                                    html body .ce_rsce_headimagelogo .mainslider_<?php echo $this->id;?> .slide_<?php echo $key;?>.style-1 .mainimage--content .mainimage--content-inner {
                                        background-color: <?= $color; ?> !important;
                                        padding: 20px;
                                        box-shadow: 0 .5rem 1rem rgba(0, 0, 0, .15);
                                    }

                                </style>
                            <?php endif; ?>

                            <?php if ($ext == "mp4") : ?>
                                <video style="<?php if ($this->image_maxheight) : ?>min-height: <?php echo $this->image_maxheight; ?>; min-width: 0px;<?php endif; ?>"
                                       <?php if ($ext_mobile == "mp4" && $ext_mobile) : ?>class=" d-none d-md-block" <?php endif; ?>
                                       autoplay muted loop playsinline data-src="{{file::<?= $slide->image ?>}}">
                                    <source type="video/mp4" src="{{file::<?= $slide->image ?>}}">
                                </video>
                            <?php endif; ?>
                            <?php if ($ext_mobile == "mp4" && $ext_mobile) : ?>
                                <video style="<?php if ($this->image_maxheight) : ?>min-height: <?php echo $this->image_maxheight; ?>; min-width: 0px;"
                                       <?php endif; ?>class="d-md-none" src="{{file::<?= $slide->mobile_image ?>}}"
                                       autoplay muted loop
                                       playsinline>
                                    <source type="video/mp4" src="{{file::<?= $slide->mobile_image ?>}}">
                                </video>
                            <?php endif; ?>


                            <?php if ($slide->text_firstline || $slide->text_secondline || count($slide->buttons) >= 1) : ?>
                                <div data-aos="<?php if ($slide->animation_type) : ?><?php echo $slide->animation_type; ?><?php else : ?>animate__fadeInUp<?php endif; ?>"
                                     class="mainimage--content"
                                     <?php if ($slide->image_height < 50 && $slide->image_height != "") : ?>style="top: 140px;" <?php endif; ?>>


                                    <div class="container">


                                        <div class="mainimage--content-inner <?php echo $slide->textbox_position; ?> <?php echo $slide->text_align; ?>"
                                             style="<?php if ($slide->text_color) : ?>color: <?php echo $slide->text_color; ?>;<?php endif; ?> <?php if ($slide->maxWidth) : ?>max-width: <?php echo $slide->maxWidth; ?>;<?php endif; ?>">

                                            <div class="mainimage--content-inner--wrapper">
                                                <?php if ($slide->firstline_headline) : ?>
                                                    <h1 style="<?php if ($slide->text_color) : ?>color: <?php echo $slide->text_color; ?>;<?php endif; ?>"
                                                        class="first-line mb-0 <?php if ($slide->dynamic_fontsize): ?>dynamic-fontsize<?php endif; ?>"><?php echo $slide->text_firstline; ?></h1>
                                                <?php else : ?>
                                                    <span style="<?php if ($slide->text_color) : ?>color: <?php echo $slide->text_color; ?>;<?php endif; ?>"
                                                          class="first-line mb-0 <?php if ($slide->dynamic_fontsize): ?>dynamic-fontsize<?php endif; ?>"><?php echo $slide->text_firstline; ?></span>
                                                <?php endif; ?>
                                                <?php if ($slide->text_secondline) : ?>
                                                    <span class="second-line <?php if ($slide->dynamic_fontsize): ?>dynamic-fontsize-sm<?php endif; ?>"><?php echo $slide->text_secondline; ?></span>
                                                <?php endif; ?>
                                                <?php if ($slide->text_infotext) : ?>
                                                    <div class="infotext--text">
                                                        <?php echo $slide->text_infotext; ?>
                                                    </div>
                                                <?php endif; ?>

                                                <?php if (count($slide->buttons) >= 1) : ?>
                                                    <div class="button--wrapper">
                                                        <?php foreach ($slide->buttons as $button) : ?>
                                                            <a data-aos="<?php if ($button->animation_type) : ?><?php echo $button->animation_type; ?><?php else : ?>animate__fadeInUp<?php endif; ?>"
                                                               class="d-inline-block btn <?php if ($button->link_size) : ?><?php echo $button->link_size; ?><?php endif; ?> <?php echo $button->link_type; ?>"
                                                               href="<?php echo $button->link_url; ?><?php if ($button->link_betreff) : ?>?subject=<?php echo $button->link_betreff; ?><?php endif; ?>"><?php echo $button->link_text; ?></a>
                                                        <?php endforeach ?>
                                                    </div>
                                                <?php endif; ?>
                                            </div>
                                        </div>

                                    </div>

                                </div>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
            <?php endforeach ?>
        </div>
        <?php if (count($this->slides) > 1) : ?><?php if (!$this->boxed_image) : ?>
            <div class="swiper-pagination"></div>
        <?php endif; ?>
            <div class="swiper-button-prev"></div>
            <div class="swiper-button-next"></div>
        <?php endif; ?>
    </div>

    <?php if ($this->boxed_image) : ?>
        <div class="boxed-logo">
            <img data-aos="<?php if ($this->boxed_image_animation_type) : ?><?php echo $this->boxed_image_animation_type; ?><?php else : ?>animate__fadeInUp<?php endif; ?>"
                 src="<?= Image::get(FilesModel::findByUuid($this->boxed_image)->path, null, null, null); ?>">
        </div>
    <?php endif; ?>
</div>

<?php if (TL_MODE == 'FE'): ?>
    <script>
        window.addEventListener('load', function () {
            if ($('.swiper.mainslider_<?php echo $this->id; ?>').length) {
                const swiper_<?php echo $this->id; ?> = new Swiper('.swiper.mainslider_<?php echo $this->id; ?>', {

                    loop: true,

                    speed: <?php if ($this->transition_time) : ?><?= $this->transition_time; ?><?php else:?>1500<?php endif;?>,
                    effect: <?php if ($this->slide_effect) : ?>'<?= $this->slide_effect; ?>'<?php else:?>
                    'slide'<?php endif;?>,

                    <?php if ($this->autoplay) : ?>
                    autoplay: {
                        delay: <?php if ($this->autoplay_time) : ?><?= $this->autoplay_time; ?><?php else:?>3000<?php endif;?>,
                    },
                    <?php endif; ?>

                    <?php if (count($this->slides) > 1) : ?>
                    navigation: {
                        nextEl: '.swiper.mainslider_<?php echo $this->id; ?> .swiper-button-next',
                        prevEl: '.swiper.mainslider_<?php echo $this->id; ?> .swiper-button-prev',
                    },
                    <?php if (!$this->boxed_image) : ?>
                    pagination: {
                        el: '.swiper.mainslider_<?php echo $this->id; ?> .swiper-pagination',
                        clickable: true,
                    },
                    <?php endif; ?>
                    <?php endif; ?>


                    on: {
                        realIndexChange: function () {
                            $('.mainslider_<?php echo $this->id; ?> .swiper-slide .ce--mainimage *[data-aos]').removeClass('aos-init').removeClass('aos-animate');
                            $('.mainslider_<?php echo $this->id; ?> .swiper-slide:not(.swiper-slide-active) .ce--mainimage .mainimage--content').hide();

                            setTimeout(function () {
                                $('.mainslider_<?php echo $this->id; ?> .swiper-slide .ce--mainimage .mainimage--content').show();
                            }, 500);
                        },
                    }
                });
            }
        }, {passive: true})
    </script>
<?php endif; ?>
<?php if ($this->show_breadcrumb) : ?>
    <div class="container mt-3 mb-5">
        {{insert_module::48}}
    </div>
<?php endif; ?>

</div>