<?php
$translate = $this->plugin('translate');
$escape = $this->plugin('escapeHtml');
$this->htmlElement('body')->appendAttribute('class', 'site-pages edit');
$this->ckEditor();
$this->headScript()->appendFile($this->assetUrl('vendor/sortablejs/Sortable.min.js', 'Omeka'));
$this->headScript()->appendFile($this->assetUrl('js/site-page-edit.js', 'Omeka'));
$this->blockLayout()->prepareForm();
$form->prepare();
?>
<?php echo $this->pageTitle($page->title(), 1, $translate('Pages'), $translate('Edit')); ?>

<?php echo $this->form()->openTag($form); ?>
<div id="page-actions">
    <?php if ($page->isPublic()): ?>
    <?php echo $this->hyperlink('', '#', [
        'class' => 'o-icon-public button',
        'title' => $translate('Make private'),
    ]); ?>
    <input type="hidden" name="o:is_public" value="1">
    <?php else: ?>
    <?php echo $this->hyperlink('', '#', [
        'class' => 'o-icon-private button',
        'title' => $translate('Make public'),
    ]); ?>
    <input type="hidden" name="o:is_public" value="0">
    <?php endif; ?>
    <a href="<?php echo $page->siteUrl(); ?>" class="button" target="_blank"><?php echo $translate('View'); ?></a>
    <a href="#" class="delete button"><?php echo $translate('Delete'); ?></a>
    <?php echo $this->cancelButton(); ?>
    <button><?php echo $translate('Save'); ?></button>
</div>

<?php echo $this->formCollection($form, false); ?>

<?php echo $this->blockLayout()->forms($page); ?>

<?php echo $this->form()->closeTag(); ?>

<div id="new-block" class="active sidebar" data-url="<?php echo $this->url('admin/site/slug/page/default', ['action' => 'block'], true); ?>">
    <h3><?php echo $translate('Add new block'); ?></h3>
    <?php foreach ($this->blockLayout()->getLayouts() as $layout): ?>
      <?php /* if ($layout == "html") { continue; } */ ?>
      <?php /* if ($layout == "tableOfContents") { continue; } */ ?>
      <?php if ($layout == "searchingForm") { continue; } ?>
    <button type="button" value="<?php echo $escape($layout); ?>" class="option">
        <?php echo $escape($translate($this->blockLayout()->getLayoutLabel($layout))); ?>
    </button>
    <?php endforeach; ?>
</div>

<div id="attachment-options" class="sidebar" data-url="<?php echo $this->url(null, ['action' => 'attachment-item-options'], true); ?>">
    <div id="attachment-options-main" class="confirm-main">
        <a href="#" class="sidebar-close o-icon-close"><span class="screen-reader-text"><?php echo $translate('Close'); ?></span></a>
        <div id="attachment-item"></div>
        <div id="attachment-caption" class="option">
            <h3><?php echo $translate('Caption'); ?></h3>
            <?php echo $this->hyperlink('', '#', [
                'class' => 'collapse',
                'title' => $translate('Collapse'),
            ]); ?>
            <div class="collapsible">
                <textarea class="caption wysiwyg"></textarea>
            </div>
        </div>
    </div>
    <div id="attachment-confirm-panel" class="confirm-panel">
        <button><?php echo $translate('Apply changes'); ?></button>
    </div>
</div>

<?php echo $this->deleteConfirm($page, 'page'); ?>

<?php echo $this->partial('common/resource-select-sidebar'); ?>
