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

$sectionNavs = [
    'resource-values' => $this->translate('Values'),
];
?>

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

<?php echo $this->sectionNav($sectionNavs, $sectionNavEvent); ?>
<?php $this->trigger("view.$action.form.before", ['form' => $form]); ?>
<?php
//produces a <fieldset> with the id and class atts passed in.
//on, e.g., the item add/edit pages, the id will work with the classes on
//the nav lis above. (see globals.js)
echo $this->partial(
    'common/resource-fields.phtml',
    [
        'id'                   => 'resource-values',
        'class'                => 'section active',
        'form'                 => $form,
        'resource'             => $itemSet,
        'propertySelectorText' => $this->translate('Click on a property to add it to the add panel')
    ]
);
?>

    <div id="page-actions">
        <?php if ($itemSet && $itemSet->isOpen()): ?>
        <a href="#"
        class="o-icon-unlock button"
        aria-label="<?php echo $escape($this->translate('Close item set')); ?>"
        title="<?php echo $escape($this->translate('Close item set')); ?>"></a>
        <input type="hidden" name="o:is_open" value="1">
        <?php else: ?>
        <a href="#"
        class="o-icon-lock button"
        aria-label="<?php echo $escape($this->translate('Open item set')); ?>"
        title="<?php echo $escape($this->translate('Open item set')); ?>"></a>
        <input type="hidden" name="o:is_open" value="0">
        <?php endif; ?>

        <?php if ($itemSet && $itemSet->isPublic() || !isset($itemSet) ): ?>
        <a href="#"
        class="o-icon-public button"
        aria-label="<?php echo $escape($this->translate('Make private')); ?>"
        title="<?php echo $escape($this->translate('Make private')); ?>"></a>
        <input type="hidden" name="o:is_public" value="1">
        <?php else: ?>
        <a href="#"
        class="o-icon-private button"
        aria-label="<?php echo $escape($this->translate('Make public')); ?>"
        title="<?php echo $escape($this->translate('Make public')); ?>"></a>
        <input type="hidden" name="o:is_public" value="0">
        <?php endif; ?>

        <?php echo (isset($deleteButton)) ? $deleteButton : ''; ?>
        <input type="submit" name="add-item-set-submit" value="<?php echo $this->translate('Save'); ?>">
    </div>
    <?php $this->trigger("view.$action.form.after", ['form' => $form]); ?>
<?php echo $formElement($form->get('csrf')); ?>
</form>

<?php
/*
 * the sidebar and templates are not going into the fields partial because
 * they exist outside the form, and the partial needs to work with
 * multiple resource fieldsets (item and media, e.g.)
 */
echo $this->partial('common/resource-form-templates.phtml');
?>
