<?php
N2Localization::addJS(array(
    'Add animation',
    'Animation chain',
    'Animation',
    'Col',
    'Content',
    'Dark Mode',
    'Delete layer',
    'Design',
    'Duplicate layer',
    'Edit',
    'Go to slide ID',
    'Go to slide',
    'Group',
    'Layer',
    'Load design',
    'Lock Guides',
    'More',
    'NOTE: Layer design changes apply to each device. Watch <a href="%s" target="_blank">video tutorial</a> to learn responsive tools.',
    'Next slide',
    'Overwrite preset',
    'Pick the align point of the child layer!',
    'Pick the align point of the parent layer!',
    'Pick the child layer!',
    'Pick the parent layer!',
    'Preset',
    'Previous slie',
    'Reset design to default',
    'Row',
    'Ruler',
    'Save as new',
    'Save design as new preset',
    'Scroll to',
    'Settings',
    'Show Guides',
    'Slide event',
    'Smart Snap',
    'There is not any layer available to be child of the selected layer!',
));

$externals = N2SmartSliderSettings::get('external-css-files');
if (!empty($externals)) {
    $externals = explode("\n", $externals);
    foreach ($externals AS $external) {
        echo "<link rel='stylesheet' href='" . $external . "' type='text/css' media='all' />";
    }
}

include(dirname(__FILE__) . '/_layer-window.php');
/**
 * @var $slidesModel N2SmartsliderSlidesModel
 */
$slide = $slidesModel->get(N2Request::getInt('slideid', 0));


/** @var N2SmartSliderManager $sliderManager */
$sliderManager  = $this->appType->app->get('sliderManager');
$slider         = $sliderManager->getSlider();
$renderedSlider = $sliderManager->render();

if ($slider->params->get('global-lightbox', 0)) {
    define('N2_SS_SLIDER_CUSTOM_LIGHTBOX', 1);
}

include(dirname(__FILE__) . '/_main-top-bar.php');


$renderedSlide = null;
if ($slide) {
    $params = new N2Data($slide['params'], true);
    if ($params->get('static-slide', 0)) {
        foreach ($slider->staticSlides AS $s) {
            if ($s->id == $slide['id']) {
                $renderedSlide = $s;
                break;
            }
        }
    }
    if ($renderedSlide == null) {
        foreach ($slider->slides AS $s) {
            if ($s->id == $slide['id']) {
                $renderedSlide = $s;
                break;
            }
        }
    }
} else {
    $renderedSlide = new N2SmartSliderSlide($slider, array('params' => ''));
}

ob_start();
?>

    <div id="n2-ss-slide-edit-slides" class="n2-ss-slides-outer-container">
        <div class="n2-heading-bar ">
            <div class="n2-h1 n2-heading">Slides</div>
        </div>
        <?php
        $this->renderInline("slidemanager", array(
            'sliderObj' => $slider
        ));
        ?>
        <div class="n2-clear"></div>
    </div>
<?php
$slidesOuterHTML = ob_get_clean();

$thumbnail = $renderedSlide->getThumbnail();
if (empty($thumbnail)) {
    $thumbnail = N2ImageHelper::fixed('$system$/images/placeholder/image.png');
}
$title = $renderedSlide->getTitle();
if (empty($thumbnail)) {
    $thumbnail = N2ImageHelper::fixed('$system$/images/placeholder/image.png');
}
?>

<?php echo $slidesOuterHTML; ?>

    <div class="n2-ss-edit-slide-top">
    <div class="n2-ss-edit-slide-top-thumbnail" onclick="n2('.n2-ss-tab-background').trigger('click');"><img src="<?php echo $thumbnail; ?>"/></div>
    <div class="n2-ss-edit-slide-top-details">
        <div class="n2-h1" onclick="n2('.n2-ss-tab-settings').trigger('click');n2('#slidetitle').trigger('focus');">
            <?php
            $title = $renderedSlide->getTitle();
            if (empty($title)) {
                $title = n2_('New slide');
            }
            echo $title;
            ?>
        </div>
        <div class="n2-h4"><a class="n2-ss-back-to" href="<?php echo $this->appType->router->createUrl(array(
                "slider/edit",
                array('sliderid' => $sliderId)
            )) ?>"><?php n2_e('Back to slider'); ?></a></div>
        <div id="n2-form-matrix-slide-settings-external-tab" class="n2-ss-edit-slide-top-tabs">
            <?php
            $tab = 0;
            if (!$slider->isStaticEdited) {
                echo N2Html::tag('a', array(
                    'href'     => '#',
                    'data-tab' => $tab++,
                    'class'    => 'n2-ss-tab-background n2-button n2-button-l n2-radius-s n2-button-with-icon n2-h4' . ($tab == 1 ? ' n2-first' : '')
                ), n2_('Background'));
            }

            if (!$slider->isStaticEdited) {
                switch ($slider->data->get('type')) {
                    case 'simple':
                    case 'block':
                        echo N2Html::tag('a', array(
                            'href'     => '#',
                            'data-tab' => $tab++,
                            'class'    => 'n2-ss-tab-animation n2-button n2-button-l n2-radius-s n2-button-with-icon n2-h4' . ($tab == 1 ? ' n2-first' : '')
                        ), n2_('Animation'));
                        break;
                }
            }

            if ($slide['generator_id'] > 0) {
                echo N2Html::tag('a', array(
                    'href'     => '#',
                    'data-tab' => $tab++,
                    'class'    => 'n2-ss-tab-settings n2-button n2-button-l n2-radius-s n2-button-with-icon n2-h4' . ($tab == 1 ? ' n2-first' : '')
                ), n2_('Settings'));
                echo N2Html::tag('a', array(
                    'href'     => '#',
                    'data-tab' => $tab++,
                    'class'    => 'n2-ss-tab-generator n2-button n2-button-l n2-radius-s n2-button-with-icon n2-h4 n2-last' . ($tab == 1 ? ' n2-first' : '')
                ), n2_('Generator'));
            } else {
                echo N2Html::tag('a', array(
                    'href'     => '#',
                    'data-tab' => $tab++,
                    'class'    => 'n2-ss-tab-settings n2-button n2-button-l n2-radius-s n2-button-with-icon n2-h4 n2-last' . ($tab == 1 ? ' n2-first' : '')
                ), n2_('Settings'));
            }
            ?>
        </div>
    </div>
    <div class="n2-heading-actions">
        <span class="n2-heading-actions-label n2-h4"></span>
        <?php
        if ($slide['id'] > 0) {
            $app          = N2Base::getApplication('smartslider');
            $accessEdit   = N2Acl::canDo('smartslider_edit', $app->info);
            $accessDelete = N2Acl::canDo('smartslider_delete', $app->info);
            if ($accessEdit) {
                echo N2Html::tag('a', array(
                    'data-label' => n2_('Duplicate slide'),
                    'href'       => $this->appType->router->createUrl(array(
                        'slides/duplicate',
                        array(
                            'sliderid' => $sliderId,
                            'slideid'  => $slide['id']
                        ) + N2Form::tokenizeUrl()
                    ))
                ), N2Html::tag('i', array('class' => 'n2-i n2-i-a-duplicate')));
            }

            if ($accessDelete) {
                echo N2Html::tag('a', array(
                    'data-label' => n2_('Delete slide'),
                    "onclick"    => "return NextendDeleteModalLink(this, 'slide-delete', " . json_encode($slide['title']) . ");",
                    'href'       => $this->appType->router->createUrl(array(
                        'slides/delete',
                        array(
                            'sliderid' => $sliderId,
                            'slideid'  => $slide['id']
                        ) + N2Form::tokenizeUrl()
                    ))
                ), N2Html::tag('i', array('class' => 'n2-i n2-i-a-delete')));
            }
        }
        ?>
        <script type="text/javascript">
            nextend.ready(
                function ($) {
                    var label = $('.n2-heading-actions-label');
                    $('.n2-heading-actions > a').on({
                        mouseenter: function () {
                            label.html($(this).data('label'));
                        },
                        mouseleave: function () {
                            label.html('');
                        }
                    });
                }
            );
        </script>
    </div>
</div>

<?php
if ($isAddSample):
    ?>
    <div class="n2-ss-sample-slides-container">
        <div class="n2-ss-sample-slide-settings">
            <div class="n2-ss-sample-slide-settings-col" style="margin-left:auto;">
                <div id="n2-ss-sample-slide-setting-background-image">
                    <i class="n2-i n2-i-close"></i>
                </div>
            </div>
            <div class="n2-ss-sample-slide-settings-col n2-ss-sample-slide-settings-image-specific">
                <div class="n2-ss-sample-slide-setting">
                    <div class="n2-ss-sample-slide-setting-label"><?php n2_e("Opacity"); ?></div>
                    <div class="n2-ss-sample-slide-setting-field">
                        <div id="n2-ss-sample-slide-setting-opacity-slider" class="ui-slider"></div>
                    </div>
                </div>
                <div class="n2-ss-sample-slide-setting">
                    <div class="n2-ss-sample-slide-setting-label"><?php n2_e("Blur"); ?></div>
                    <div class="n2-ss-sample-slide-setting-field">
                        <div id="n2-ss-sample-slide-setting-blur-slider" class="ui-slider"></div>
                    </div>
                </div>
            </div>
            <div class="n2-ss-sample-slide-settings-col">
                <div class="n2-ss-sample-slide-setting">
                    <div class="n2-ss-sample-slide-setting-label"><?php n2_e("Color"); ?></div>
                    <div class="n2-ss-sample-slide-setting-field">
                        <input id="n2-ss-sample-slide-setting-color" type="hidden"/>
                    </div>
                </div>
                <div class="n2-ss-sample-slide-setting n2-ss-sample-slide-setting-gradient-specific">
                    <div class="n2-ss-sample-slide-setting-label"><?php n2_e("Gradient"); ?></div>
                    <div class="n2-ss-sample-slide-setting-field">
                        <input id="n2-ss-sample-slide-setting-gradient" type="hidden"/>
                    </div>
                </div>
            </div>
            <div class="n2-ss-sample-slide-settings-col" style="margin-left: auto;flex-direction: row;align-items: center;">
                <?php
                echo N2Html::tag('a', array(
                    'href'    => $this->appType->router->createUrl(array(
                        "slider/edit",
                        array(
                            "sliderid" => $sliderId
                        )
                    )),
                    'style'   => 'margin:10px;',
                    'class'   => 'n2-button n2-button-normal n2-button-red n2-button-l n2-h4 n2-b n2-uc n2-radius-s',
                    'onclick' => 'return nextend.cancel(this.href);'
                ), n2_('Cancel'));

                echo N2Html::tag('a', array(
                    'href'    => '#',
                    'style'   => 'margin:10px;',
                    'class'   => 'n2-button n2-button-normal n2-button-green n2-button-l n2-h4 n2-b n2-uc n2-radius-s',
                    'onclick' => 'return NextendForm.submit("#smartslider-form");'
                ), n2_('Save'));
                ?>
            </div>
        </div>

    </div>
<?php endif; ?>

    <form id="smartslider-form" action="" method="post">
    <?php
    $slideData = $slidesModel->renderEditForm($slider, $slide);
    ?>
        <input name="save" value="1" type="hidden"/>
</form>

<?php
if (!$isAddSample && !N2Base::getApplication('smartslider')->storage->get('tutorial', 'hideContentMode')):
    ?>
    <div id="n2-ss32-content-mode-tutorial">
        <div class="n2-ss-tutorial-container">
            <div class="n2-ss-tutorial-left">
                <a href="https://smartslider3.com/videos/contentmode" target="_blank">
                    <img src="<?php echo N2ImageHelper::fixed('$ss$/admin/images/contentmode.png'); ?>" style="width:400px;height:220px;max-width:none;"/>
                </a>
            </div>
            <div class="n2-ss-tutorial-right">
                <div class="n2-h1">Slide Editing in 3.2</div>
                <p>Start building your first slide by watching the video and learn the basic steps of to the Slide editing. Smart Slider 3.2 introduces the new Content Builder mode which is a block-based system where you can add rows, columns and of course layers to the slide.</p>

                <a href="https://smartslider3.com/videos/contentmode" class="n2-button n2-button-normal n2-button-green n2-button-l n2-h4 n2-b n2-uc n2-radius-s" target="_blank">Watch now</a><a onclick="NextendAjaxHelper.ajax({url: NextendAjaxHelper.makeAjaxUrl('<?php echo $this->appType->router->createAjaxUrl(array('settings/hidecontentmode')); ?>')});n2('#n2-ss32-content-mode-tutorial').remove(); return false;" href="#" class="n2-button n2-button-normal n2-button-grey n2-button-l n2-h4 n2-b n2-uc n2-radius-s" target="_blank">Close</a>
            </div>
        </div>
    </div>
    <?php
endif;
?>

<?php
include dirname(__FILE__) . '/_canvas.php';
include dirname(__FILE__) . '/_layer-list.php';