<?php
$translate = $this->plugin('translate');
$escape = $this->plugin('escapeHtml');
$formLabel = $this->plugin('formLabel');
$formElement = $this->plugin('formElement');
$this->headScript()->appendFile($this->assetUrl('vendor/sortablejs/Sortable.min.js', 'Omeka'));
$this->headScript()->appendFile($this->assetUrl('js/resource-form.js', 'Omeka'));
$form->prepare();
?>

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

<?php echo $this->sectionNav([
    'resource-values' => $translate('Values'),
    'item-media' => $translate('Media'),
    'item-sets' => $translate('Item sets'),
    'sites' => $translate('Sites'),
    'advanced-settings' => $translate('Advanced'),
], $sectionNavEvent); ?>

<?php $this->trigger("view.$action.form.before", ['form' => $form]); ?>

<?php echo $this->partial('common/resource-fields.phtml', [
    'form' => $form,
    'resource' => $item,
    'action' => $action,
]); ?>

<fieldset id="item-media" class="section" aria-labelledby="media-label">
    <?php echo $this->partial('omeka/admin/item/manage-media', [
        'mediaForms' => $mediaForms,
        'resource' => $item,
    ]); ?>
</fieldset>

<fieldset id="item-sets" class="section" aria-labelledby="item-sets-label">
    <?php echo $this->partial('omeka/admin/item/manage-item-sets', [
        'item' => $item,
    ]); ?>
</fieldset>

<fieldset id="sites" class="section" aria-labelledby="sites-label">
    <?php echo $this->partial('omeka/admin/item/manage-sites', [
        'item' => $item,
    ]); ?>
</fieldset>

<div id="page-actions">
    <?php if ($item && $item->isPublic() || (!isset($item)) && !$this->setting('default_to_private')) : ?>
    <?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; ?>
    <?php echo (isset($deleteButton)) ? $deleteButton : ''; ?>
    <?php echo $this->cancelButton(); ?>
    <button type="submit" name="add-item-submit"><?php echo $escape($submitLabel); ?></button>
</div>

<?php $this->trigger("view.$action.form.after", ['form' => $form]); ?>

<?php echo $formElement($form->get('csrf')); ?>

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

<?php echo $this->partial('common/resource-form-templates.phtml'); ?>
