<?php
    $themes = Cms\Classes\Theme::all();
    $activeTheme = Cms\Classes\Theme::getActiveTheme();
    $cnt = count($themes);
?>
<?php foreach ($themes as $index => $theme): ?>
    <?php
        $isLast = $index == $cnt-1;
        $isActive = $activeTheme && $activeTheme->getDirName() == $theme->getDirName();
        $author = $theme->getConfigValue('author');
    ?>
    <div class="layout-row <?= $isLast ? 'last' : null ?> min-size <?= $isActive ? 'active' : null ?>">
        <div class="layout-cell min-height theme-thumbnail">
            <div class="thumbnail-container"><img src="<?= $theme->getPreviewImageUrl() ?>"/></div>
        </div>
        <div class="layout-cell min-height theme-description">
            <h3><?= e($theme->getConfigValue('name', $theme->getDirName())) ?></h3>
            <?php if (strlen($author)): ?>
                <p class="author">by <a href="<?= e($theme->getConfigValue('homepage', '#')) ?>"><?= e($author) ?></a></p>
            <?php endif ?>
            <p class="description"><?= e($theme->getConfigValue('description', 'The theme description is not provided.')) ?></p>
            <div class="controls">
                <?php if ($isActive): ?>
                    <button
                        type="submit"
                        disabled
                        class="btn btn-disabled">
                        <i class="icon-star"></i>
                        <?= e(trans('cms::lang.theme.active_button')) ?>
                    </button>
                <?php else: ?>
                    <button
                        type="submit"
                        data-request="onSetActiveTheme"
                        data-request-data="theme: '<?= e($theme->getDirName()) ?>'"
                        data-stripe-load-indicator
                        class="btn btn-primary">
                        <i class="icon-check"></i>
                        <?= e(trans('cms::lang.theme.activate_button')) ?>
                    </button>
                <?php endif ?>
                <?php if ($theme->hasCustomData()): ?>
                    <a
                        href="<?= Backend::url('cms/themes/update/'.$theme->getDirName()) ?>"
                        class="btn btn-default">
                        <i class="icon-pencil"></i>
                        <?= e(trans('cms::lang.theme.customize_button')) ?>
                    </a>
                <?php endif ?>
            </div>
        </div>
    </div>
<?php endforeach ?>

<div class="layout-row links">
    <div class="layout-cell theme-thumbnail">
        <!-- Spacer -->
    </div>
    <div class="layout-cell theme-description">
        <a class="find-more-themes" href="http://octobercms.com/themes"><?= e(trans('cms::lang.theme.find_more_themes')) ?></a>
    </div>
</div>