<?php
/** @var \PortalPeople\DisabledPostcodes\Block\Adminhtml\Postcode\Edit $block */
$row = $block->getRow();
?>
<section class="admin__page-section">
    <div class="admin__page-section-title">
        <span class="title">
            <?= (int)$row['id'] > 0
                ? $block->escapeHtml(__('Edit Disabled Postcode Rule'))
                : $block->escapeHtml(__('New Disabled Postcode Rule')) ?>
        </span>
    </div>
    <div class="admin__page-section-content">
        <form action="<?= $block->escapeUrl($block->getSaveUrl()) ?>" method="post">
            <?= $block->getBlockHtml('formkey') ?>
            <input type="hidden" name="entity_id" value="<?= (int)$row['id'] ?>"/>

            <div class="admin__field">
                <label class="admin__field-label" for="postcode"><span><?= $block->escapeHtml(__('Postcode / Area')) ?></span></label>
                <div class="admin__field-control">
                    <input class="admin__control-text" type="text" id="postcode" name="postcode" required="required"
                           value="<?= $block->escapeHtmlAttr((string)$row['postcode']) ?>"/>
                </div>
            </div>

            <div class="admin__field">
                <label class="admin__field-label" for="match_type"><span><?= $block->escapeHtml(__('Match Type')) ?></span></label>
                <div class="admin__field-control">
                    <select class="admin__control-select" id="match_type" name="match_type">
                        <option value="area" <?= ((string)$row['match_type'] === 'area') ? 'selected="selected"' : '' ?>><?= $block->escapeHtml(__('Area Prefix')) ?></option>
                        <option value="exact" <?= ((string)$row['match_type'] === 'exact') ? 'selected="selected"' : '' ?>><?= $block->escapeHtml(__('Exact Postcode')) ?></option>
                    </select>
                </div>
            </div>

            <div class="admin__field">
                <label class="admin__field-label" for="store_id"><span><?= $block->escapeHtml(__('Store')) ?></span></label>
                <div class="admin__field-control">
                    <select class="admin__control-select" id="store_id" name="store_id">
                        <option value="0" <?= ((int)$row['store_id'] === 0) ? 'selected="selected"' : '' ?>><?= $block->escapeHtml(__('All Stores (0)')) ?></option>
                        <?php foreach ($block->getStoreOptions() as $group): ?>
                            <?php if (empty($group['value']) || !is_array($group['value'])) { continue; } ?>
                            <?php foreach ($group['value'] as $store): ?>
                                <option value="<?= (int)$store['value'] ?>" <?= ((int)$row['store_id'] === (int)$store['value']) ? 'selected="selected"' : '' ?>>
                                    <?= $block->escapeHtml($store['label']) ?>
                                </option>
                            <?php endforeach; ?>
                        <?php endforeach; ?>
                    </select>
                </div>
            </div>

            <div class="admin__field">
                <label class="admin__field-label" for="description"><span><?= $block->escapeHtml(__('Description')) ?></span></label>
                <div class="admin__field-control">
                    <input class="admin__control-text" type="text" id="description" name="description"
                           value="<?= $block->escapeHtmlAttr((string)$row['description']) ?>"/>
                </div>
            </div>

            <div class="admin__field">
                <label class="admin__field-label" for="is_active"><span><?= $block->escapeHtml(__('Active')) ?></span></label>
                <div class="admin__field-control">
                    <select class="admin__control-select" id="is_active" name="is_active">
                        <option value="1" <?= !empty($row['is_active']) ? 'selected="selected"' : '' ?>><?= $block->escapeHtml(__('Yes')) ?></option>
                        <option value="0" <?= empty($row['is_active']) ? 'selected="selected"' : '' ?>><?= $block->escapeHtml(__('No')) ?></option>
                    </select>
                </div>
            </div>

            <div class="admin__field">
                <div class="admin__field-control">
                    <button type="submit" class="action-primary"><span><?= $block->escapeHtml(__('Save')) ?></span></button>
                    <a href="<?= $block->escapeUrl($block->getBackUrl()) ?>" class="action-secondary" style="margin-left: 8px;"><span><?= $block->escapeHtml(__('Back')) ?></span></a>
                </div>
            </div>
        </form>
    </div>
</section>
