<?php
$viewModel = $block->getData('view_model');
$defaultTypes = ['simple', 'bundle'];
$typeOptions = $viewModel->getTypeOptions();
$formatOptions = $viewModel->getFormatOptions();
$defaultFormat = $viewModel->getDefaultFormat();
?>
<a href="<?= $escaper->escapeUrl($viewModel->getUrl('autogedal_ean/index/index')) ?>"
   class="action-default scalable back aget-back">
    <span><?= $escaper->escapeHtml(__('Back to EAN Tools')) ?></span>
</a>

<form action="<?= $escaper->escapeUrl($viewModel->getUrl('autogedal_ean/missing/post')) ?>" method="post">
    <input name="form_key" type="hidden" value="<?= $escaper->escapeHtmlAttr($viewModel->getFormKey()) ?>"/>

    <div class="aget-panel">
        <h2 class="aget-panel__title"><?= $escaper->escapeHtml(__('Products without EANs')) ?></h2>
        <p class="aget-panel__hint">
            <?= $escaper->escapeHtml(__(
                'Generate a list of products without an EAN code, filtered by status and product type.'
            )) ?>
        </p>

        <div class="aget-field">
            <label class="aget-field__label" for="status"><?= $escaper->escapeHtml(__('Product status')) ?></label>
            <select id="status" name="status" class="admin__control-select">
                <option value="enabled"><?= $escaper->escapeHtml(__('Enabled products only')) ?></option>
                <option value="all"><?= $escaper->escapeHtml(__('All products')) ?></option>
                <option value="disabled"><?= $escaper->escapeHtml(__('Disabled products only')) ?></option>
            </select>
        </div>

        <div class="aget-field">
            <span class="aget-field__label"><?= $escaper->escapeHtml(__('Product type')) ?></span>
            <?php foreach ($typeOptions as $value => $label): ?>
                <?php $available = $viewModel->isTypeAvailable($value); ?>
                <div class="aget-checkbox<?= $available ? '' : ' aget-checkbox--disabled' ?>">
                    <input type="checkbox"
                           id="type_<?= $escaper->escapeHtmlAttr($value) ?>"
                           name="types[]"
                           value="<?= $escaper->escapeHtmlAttr($value) ?>"
                           <?= $available ? '' : 'disabled' ?>
                           <?= $available && in_array($value, $defaultTypes, true) ? 'checked' : '' ?>/>
                    <label for="type_<?= $escaper->escapeHtmlAttr($value) ?>">
                        <?= $escaper->escapeHtml($label) ?>
                        <?php if (!$available): ?>
                            <span class="aget-checkbox__note"><?= $escaper->escapeHtml(__('no products')) ?></span>
                        <?php endif; ?>
                    </label>
                </div>
            <?php endforeach; ?>
            <span class="aget-field__note">
                <?= $escaper->escapeHtml(__('If no product type is selected, all types are included.')) ?>
            </span>
        </div>

        <div class="aget-field">
            <label class="aget-field__label" for="format"><?= $escaper->escapeHtml(__('File format')) ?></label>
            <select id="format" name="format" class="admin__control-select">
                <?php foreach ($formatOptions as $value => $label): ?>
                    <option value="<?= $escaper->escapeHtmlAttr($value) ?>"
                        <?= $value === $defaultFormat ? 'selected' : '' ?>>
                        <?= $escaper->escapeHtml($label) ?>
                    </option>
                <?php endforeach; ?>
            </select>
        </div>

        <div class="aget-actions">
            <button type="submit" class="action-default primary scalable">
                <span><?= $escaper->escapeHtml(__('Generate file')) ?></span>
            </button>
        </div>
    </div>
</form>
