<?php

N2SS3::initLicense();

$slidesModel = new N2SmartsliderSlidesModel();

$slides   = $slidesModel->getAll($sliderObj->sliderId);
$optimize = new N2SmartSliderFeatureOptimize($sliderObj);

$router = N2Base::getApplication('smartslider')
                ->getApplicationType('backend')->router;
?>
<script type="text/javascript">
    document.getElementsByTagName("BODY")[0].setAttribute("data-slides", '<?php echo count($slides); ?>');
</script>
<div id="n2-ss-slides-container">
    <div id="n2-ss-slides" data-showcreateslide="0">

        <div class="n2-ss-slides-create">
            <div>
                <script type="text/javascript">
                N2R('documentReady', function ($) {
                    var showCreateSlide = 0;
                    $('.n2-ss-add-slide-button').on('click', function (e) {
                        e.preventDefault();
                        showCreateSlide = (showCreateSlide === 1 ? 0 : 1);
                        $('#n2-ss-slides').attr('data-showcreateslide', showCreateSlide);

                        if (showCreateSlide) {
                            $(e.currentTarget).html('<?php n2_e('Close'); ?>');
                        } else {
                            $(e.currentTarget).html('<?php n2_e('Add slide'); ?>');
                        }
                    });
                });
                </script>
                <div class="n2-ss-slides-create-heading"><?php n2_e('Add Slide'); ?></div>

                <div class="n2-ss-slides-create-inner">
                    <div class="n2-ss-slides-create-action-box" data-action="image">
                        <div class="n2-ss-slides-create-action-box-icon n2-i n2-i-slide-image"></div>
                        <div class="n2-ss-slides-create-action-box-label"><?php n2_e('Image'); ?></div>
                    </div>
                    <div class="n2-ss-slides-create-action-box" data-action="library" data-href="<?php echo $router->createUrl(array(
                        "slides/create",
                        array(
                            "sliderid" => N2Request::getInt('sliderid'),
                            "static"   => 0,
                            "mode"     => 'sample'
                        )
                    )); ?>">
                        <div class="n2-ss-slides-create-action-box-icon n2-i n2-i-slide-library"></div>
                        <div class="n2-ss-slides-create-action-box-label"><?php n2_e('Library'); ?></div>
                    </div>
                    <div class="n2-ss-slides-create-action-box" data-action="empty" data-href="<?php echo $router->createUrl(array(
                        "slides/create",
                        array(
                            "sliderid" => N2Request::getInt('sliderid'),
                            "static"   => 0
                        )
                    )); ?>">
                        <div class="n2-ss-slides-create-action-box-icon n2-i n2-i-slide-empty"></div>
                        <div class="n2-ss-slides-create-action-box-label"><?php n2_e('Empty'); ?></div>
                    </div>
                    <div class="n2-ss-slides-create-action-box" data-action="video">
                        <div class="n2-ss-slides-create-action-box-icon n2-i n2-i-slide-video"></div>
                        <div class="n2-ss-slides-create-action-box-label"><?php n2_e('Video'); ?></div>
                    </div>
                    <?php
                    if (N2Platform::$hasPosts) {
                        ?>
                        <div class="n2-ss-slides-create-action-box" data-action="post">
                        <div class="n2-ss-slides-create-action-box-icon n2-i n2-i-slide-post"></div>
                        <div class="n2-ss-slides-create-action-box-label"><?php n2_e('Post'); ?></div>
                    </div>
                        <?php
                    }
                    ?>
                    <div class="n2-ss-slides-create-action-box" data-action="static" data-href="<?php echo $router->createUrl(array(
                        "slides/create",
                        array(
                            "sliderid" => N2Request::getInt('sliderid'),
                            "static"   => 1
                        )
                    )); ?>">
                        <div class="n2-ss-slides-create-action-box-icon n2-i n2-i-slide-static"></div>
                        <div class="n2-ss-slides-create-action-box-label"><?php n2_e('Static Overlay'); ?></div>
                    </div>
                    <div class="n2-ss-slides-create-action-box" data-action="dynamic" data-href="<?php echo $router->createUrl(array(
                        "generator/create",
                        array(
                            "sliderid" => N2Request::getInt('sliderid')
                        )
                    )); ?>">
                        <div class="n2-ss-slides-create-action-box-icon n2-i n2-i-slide-dynamic"></div>
                        <div class="n2-ss-slides-create-action-box-label"><?php n2_e('Dynamic'); ?></div>
                    </div>
                </div>
            </div>
        </div>

        <div class="n2-ss-slides-header">
            <div class="n2-ss-bulk-controls">
                <?php
                ob_start();
                N2Html::buttonMenu(array(
                    "content" => N2Html::tag('div', array(
                        'class' => 'n2-button-menu'
                    ), N2Html::tag('div', array(
                        'class' => 'n2-button-menu-inner n2-border-radius'
                    ), N2Html::link(n2_('Select all'), '#', array(
                            'class' => 'n2-h4'
                        )) . N2Html::link(n2_('Select none'), '#', array(
                            'class' => 'n2-h4'
                        )) . N2Html::link(n2_('Select published'), '#', array(
                            'class' => 'n2-h4'
                        )) . N2Html::link(n2_('Select unpublished'), '#', array(
                            'class' => 'n2-h4'
                        ))))
                ));
                $selectButtonMenu = ob_get_clean();

                echo N2Html::tag('div', array('class' => 'n2-button n2-button-plain n2-button-with-actions n2-bulk-select n2-radius-s'), N2Html::tag('span', array(
                        'class' => 'n2-button-inner n2-h4'
                    ), n2_('Select')) . $selectButtonMenu);

                echo N2HTML::tag('div', array(
                    'class' => 'n2-bulk-actions'
                ), N2Html::link(n2_('Delete'), '#', array(
                        'data-action' => 'deleteSlides',
                        'class'       => 'n2-button n2-button-normal n2-button-m n2-radius-s n2-button-plain n2-color-red n2-button-inner n2-h4'
                    )) . N2Html::link(n2_('Duplicate'), '#', array(
                        'data-action' => 'duplicateSlides',
                        'class'       => 'n2-button n2-button-normal n2-button-m n2-radius-s n2-button-plain n2-button-inner n2-h4'
                    )) . N2Html::link(n2_('Copy'), '#', array(
                        'data-action' => 'copySlides',
                        'class'       => 'n2-button n2-button-normal n2-button-m n2-radius-s n2-button-plain n2-button-inner n2-h4'
                    )) . N2Html::link(n2_('Publish'), '#', array(
                        'data-action' => 'publishSlides',
                        'class'       => 'n2-button n2-button-normal n2-button-m n2-radius-s n2-button-plain n2-button-inner n2-h4'
                    )) . N2Html::link(n2_('Unpublish'), '#', array(
                        'data-action' => 'unPublishSlides',
                        'class'       => 'n2-button n2-button-normal n2-button-m n2-radius-s n2-button-plain n2-button-inner n2-h4'
                    )));


                ?>
            </div>
        </div>


    <div class="n2-ss-slides-container">
        <?php
        echo N2Html::tag('div', array('class' => 'n2-box n2-box-small n2-box-slide-add n2-h3'), N2Html::link(n2_('Add slide'), '#', array(
            'class' => 'n2-ss-add-slide-button n2-button n2-button-l n2-button-green n2-radius-s n2-uc n2-h3'
        )));
        $parameters = array();
        if (N2Platform::$isWordpress) {
            $parameters['nonce']     = wp_create_nonce('internal-linking');
            $parameters['wpAjaxUrl'] = admin_url('admin-ajax.php');
        }
        N2JS::addInline('new N2Classes.SlidesManager("' . $appType->router->createUrl(array(
                "slides/index",
                array(
                    "sliderid" => $sliderObj->sliderId,
                )
            )) . '","' . N2Base::getApplication('system')
                               ->getApplicationType('backend')->router->createUrl("content/search") . '", ' . json_encode($parameters) . ', ' . (defined('N2_IMAGE_UPLOAD_DISABLE') ? 1 : 0) . ", '" . N2Base::getApplication('system')->router->createAjaxUrl(array('browse/upload')) . "', 'slider" . $sliderObj->sliderId . "');");

        N2Localization::addJS(array(
            'Add video',
            'Video url',
            'Examples',
            'Add post',
            'Keyword',
            'No search term specified. Showing recent items.',
            'Showing items match for "%s"',
            'Select'
        ));

        $slidesObj = array();
        foreach ($slides AS $i => $slide) {
            $slidesObj[$i] = new N2SmartSliderSlide($sliderObj, $slide);
            $slidesObj[$i]->initGenerator();
        }

        foreach ($slidesObj AS $slideObj) {
            $slideObj->fillSample();
            echo N2SmartsliderSlidesModel::box($slideObj, $sliderObj, $appType, $optimize);
        }
        ?>
        <a class="n2-box n2-box-small n2-box-slide-dummy n2-h3" href="#"><?php printf(n2_('Slide #%d'), 1); ?></a>
        <a class="n2-box n2-box-small n2-box-slide-dummy n2-h3" href="#"><?php printf(n2_('Slide #%d'), 2); ?></a>
        <a class="n2-box n2-box-small n2-box-slide-dummy n2-h3" href="#"><?php printf(n2_('Slide #%d'), 3); ?></a>
        <div class="n2-box n2-box-small n2-box-slide-drag-images n2-h6"><?php n2_e("Drop your images here!"); ?></div>

        <a class="n2-box n2-box-slide-drag-upload n2-h2 n2-uc"
           href="#"><?php echo n2_('Drop images to create slides'); ?></a>

        <div class="n2-clear"></div>
    </div>
    <div class="n2-h5 n2-ss-block-slides-notice">
        <p><?php echo n2_(' You should switch to Simple Type to <b>display all slides</b>!'); ?></p>
        <a href="#" onclick="<?php echo 'N2Classes.$(\'#slidertype_options .n2-subform-image-option\').first().trigger(\'click\');return false;'; ?>"
           class="n2-button n2-button-normal n2-button-l n2-button-blue n2-radius-m n2-h4">
            Switch to Simple Type
        </a>
    </div>
</div>

    <div id="n2-ss-slide-menu" class="n2-box-menu">
        <a href="#" class="n2-button n2-button-icon n2-button-s n2-button-grey n2-radius-s"><?php echo N2Html::tag('i', array('class' => 'n2-i n2-it n2-i-more2'), ''); ?></a>
        <div class="n2-box-menu-content">
            <ul>
                <li data-action="duplicate"><?php n2_e("Duplicate"); ?></li>
                <li data-action="copy"><?php n2_e("Copy"); ?></li>
                <li data-action="publish"><?php n2_e("Publish"); ?></li>
                <li data-action="unpublish"><?php n2_e("Unpublish"); ?></li>
                <li data-action="generator"><?php n2_e("Edit generator"); ?></li>
                <li data-action="setFirst"><?php n2_e("Set as first"); ?></li>
                <li data-action="delete"><?php n2_e("Delete"); ?></li>
            </ul>
        </div>
    </div>
</div>