<?php
/** @var \Dotdigitalgroup\Email\Block\Customer\Account\Books $block */
// @codingStandardsIgnoreFile
?>
<form id="connector-newsletter-form-validate" method="post" action="<?= $block->escapeHtml($block->getSaveUrl()) ?>">
    <?= $block->getBlockHtml('formkey') ?>
    <legend class="legend"><span><?= $block->escapeHtml(__('General Subscription')) ?></span></legend>
    <fieldset class="fieldset">
        <div class="field choice">
            <input type="checkbox" name="is_subscribed" id="subscription" value="1"
                   title="<?= $block->escapeHtmlAttr(__('General Subscription')) ?>"
                <?php if ($block->isSubscribed()): ?> checked="checked"<?php endif; ?> class="checkbox">
            <label for="subscription" class="label">
                    <span>
                        <?php if(strlen($block->getCustomerConsentText())) : ?>
                            <?= $block->escapeHtml($block->getCustomerConsentText()) ?>
                        <?php else : ?>
                            <?= $block->escapeHtml(__('General Subscription')) ?>
                        <?php endif; ?>
                    </span>
            </label>
        </div>
        <?php /* Extensions placeholder */ ?>
        <?= $block->getChildHtml('customer.form.newsletter.extra') ?>
    </fieldset>
    <?php if ($block->canShowAnything()) : ?>
        <?php $additionalBooks = $block->getAdditionalBooksToShow();
            $dataFields = $block->getDataFieldsToShow();
            $canShowAddressBook = $block->getCanShowAdditionalBooks();
            $canShowDataFields = $block->getCanShowDataFields(); ?>

            <?php if ($block->getCanShowPreferences()) : ?>
                <fieldset class="fieldset">
                    <legend class="legend"><span><?= $block->escapeHtml(__('Preferences')) ?></span></legend>
                    <ul class="form-list" style="padding-left: 0">
                        <?php foreach ($block->getPreferencesToShow() as $prefId => $preferences) : ?>
                            <?php if (! $preferences['isPreference']) : ?>
                                <h5 style="margin-bottom: 10px"><?= $block->escapeHtml($preferences['catLabel']) ?></h5>
                                <?php foreach ($preferences['catPreferences'] as $catPrefId => $catPref) : ?>
                                    <li class="control" style="display: block; margin: 5px 0 5px 10px">
                                        <input type="checkbox" name="preferences[]"
                                           id="<?= $block->escapeHtml($catPref["label"] . '_' . $catPrefId); ?>"
                                           value="<?= $block->escapeHtml($prefId . ',' . $catPrefId) ?>"
                                           title="<?= $block->escapeHtml($catPref["label"]) ?>"
                                            <?php if ($catPref["isOptedIn"]) : ?>
                                                checked="checked"
                                            <?php endif; ?> class="checkbox"
                                        />
                                        <label for="<?= $block->escapeHtml($catPref["label"] . '_' . $catPrefId); ?>">
                                            <?= $block->escapeHtml($catPref["label"]) ?>
                                        </label>
                                    </li>
                                <?php endforeach; ?>
                            <?php else: ?>
                                <li class="control" style="display: block; margin: 17px 0 17px 10px">
                                    <input type="checkbox" name="preferences[]"
                                       id="<?= $block->escapeHtml($preferences["label"] . '_' . $prefId); ?>"
                                       value="<?= $block->escapeHtml($prefId) ?>"
                                       title="<?= $block->escapeHtml($preferences["label"]) ?>"
                                        <?php if ($preferences["isOptedIn"]) : ?>
                                            checked="checked"
                                        <?php endif; ?> class="checkbox"
                                    />
                                    <label for="<?= $block->escapeHtml($preferences["label"] . '_' . $prefId); ?>">
                                        <?= $block->escapeHtml($preferences["label"]) ?>
                                    </label>
                                </li>
                            <?php endif; ?>
                        <?php endforeach; ?>
                    </ul>
                </fieldset>
            <?php endif; ?>
            <?php if (!empty($additionalBooks) && $canShowAddressBook) : ?>
                <fieldset class="fieldset">
                    <legend class="legend">
                        <span><?= $block->escapeHtml(__('Subscriptions')) ?></span>
                    </legend>
                    <ul class="form-list" style="padding-left: 0">
                        <?php foreach ($additionalBooks as $books) : ?>
                            <li class="control" style="display: block; margin: 5px 0 5px 10px">
                                <input type="checkbox" name="additional_subscriptions[]"
                                   id="<?= $block->escapeHtml($books["name"]); ?>"
                                   value="<?= $block->escapeHtml($books["value"]) ?>"
                                   title="<?= $block->escapeHtml($books["name"]) ?>"
                                    <?php if ($books["subscribed"]) : ?>
                                        checked="checked"
                                    <?php endif; ?> class="checkbox"
                                />
                                <label for="<?= $block->escapeHtml($books["name"]); ?>">
                                    <?= $block->escapeHtml($books["name"]) ?>
                                </label>
                            </li>
                        <?php endforeach; ?>
                    </ul>
                </fieldset>
            <?php endif; ?>
            <?php if (!empty($dataFields) && $canShowDataFields) : ?>
                <fieldset class="fieldset">
                    <legend class="legend">
                        <span><?= $block->escapeHtml(__('Information')) ?></span>
                    </legend>
                    <ul class="form-list" style="padding-left: 0">
                        <?php foreach ($dataFields as $dataField) : ?>
                            <li class="fields" style="display: block">
                                <div class="field" style="margin-bottom: 10px;">
                                    <label for="<?= $block->escapeHtml($dataField['name']) ?>">
                                        <?= $block->escapeHtml($dataField['name']) ?>
                                    </label>
                                    <div class="input-box">
                                        <input style="width: 50%" type="text"
                                           class="input-text <?php if ($dataField['type'] == "Date") : ?>
                                               date-field <?php endif; ?>"
                                           title="<?= $block->escapeHtml($dataField['name']) ?>"
                                           value="<?= $block->escapeHtml($dataField['value']) ?>"
                                           name="data_fields[<?= $block->escapeHtml($dataField['name']) ?>]"
                                           id="<?= $block->escapeHtml($dataField['name']) ?>"
                                        />
                                    </div>
                                </div>
                            </li>
                        <?php endforeach; ?>
                    </ul>
                </fieldset>
            <?php endif; ?>
    <?php endif; ?>
    <div class="actions-toolbar">
        <div class="primary">
            <button type="submit" title="Save" class="action save primary">
                <span>Save</span>
            </button>
        </div>
    </div>
</form>