<h2 style="padding: 10px; background-color: whitesmoke; text-align: center;">تنظیمات پیامک احراز هویت افزونه دیجیتس</h2>
<form id="form-digits-settings" method="POST">
    <table class="form-table">
        <tbody>
        <tr>
            <th scope="row">
                <label for="title">عنوان</label>
            </th>
            <td>
                <input type="text" id="title" value="<?php echo $data['template']['title'] ?? 'پیامک احراز هویت افزونه دیجیتس'; ?>" readonly style="min-width: 400px;"/>
            </td>
        </tr>
        <tr>
            <th scope="row">
                <label for="is_active">وضعیت</label>
            </th>
            <td>
                <input type="radio" name="is_active" id="is_active_1" value="1" <?php echo ($data['template']['is_active'] ?? '') == 1 ? 'checked' : ''; ?> checked />
                <label>فعال</label>
                <br/>
                <input type="radio" name="is_active" id="is_active_0" value="0" <?php echo ($data['template']['is_active'] ?? '') == 0 ? 'checked' : ''; ?> />
                <label>غیرفعال</label>
            </td>
        </tr>
        <tr>
            <th>
                <label for="pattern">الگو</label>
            </th>
            <td>
                <select name="pattern_id" id="select-pattern" required style="min-width: 400px;">
                    <option value="">انتخاب</option>
                    <?php foreach($data['patterns'] as $pattern): ?>
                        <option value="<?= $pattern['id'] ?>"
                                data-pattern_text="<?php echo $pattern['pattern']; ?>"
                                data-pattern_variables='<?php echo $pattern['variables_json']; ?>'
                            <?php echo ($data['template']['pattern_id'] ?? '') === $pattern['id'] ? 'selected' : ''; ?>
                        >
                            <?php echo $pattern['title']; ?>
                        </option>
                    <?php endforeach; ?>
                </select>
                <p id="p-show-pattern"></p>
            </td>
        </tr>
        <tr>
            <th>
                <label for="">جایگذاری</label>
            </th>
            <td style="padding-top: 0;">
                <table>
                    <thead>
                    <tr>
                        <th>متغیر الگو</th>
                        <th>متغیر دیجیتس</th>
                        <th>مقدار پیش‌فرض</th>
                    </tr>
                    </thead>
                    <tbody id="tbody-variables-and-values">
                    <!-- show inputs by jquery -->
                    <?php if (isset( $data['template']['variables_and_values'] )): ?>
                        <?php foreach($data['template']['variables_and_values'] as $item): ?>
                            <tr>
                                <td>
                                    <?php echo $item['index'] . ' - ' . $item['variable']; ?>
                                    <input type="hidden" name="variables_and_values[<?php echo $item['index']; ?>][index]" value="<?php echo $item['index']; ?>" />
                                    <input type="hidden" name="variables_and_values[<?php echo $item['index']; ?>][variable]" value="<?php echo $item['variable']; ?>" />
                                </td>
                                <td>
                                    <select name="variables_and_values[<?php echo $item['index']; ?>][value]" class="select-variable-value" data-index="<?php echo $item['index']; ?>">
                                        <option value="">انتخاب</option>
                                        <option value="{NAME}" <?php echo '{NAME}' === $item['value'] ? 'selected' : ''; ?>>NAME</option>
                                        <option value="{DOMAIN}" <?php echo '{DOMAIN}' === $item['value'] ? 'selected' : ''; ?>>DOMAIN</option>
                                        <option value="{OTP}" <?php echo '{OTP}' === $item['value'] ? 'selected' : ''; ?>>OTP</option>
                                    </select>
                                </td>
                                <td>
                                    <input type="text" name="variables_and_values[<?php echo $item['index']; ?>][default]" value="<?php echo $item['default']; ?>" class="input-variable-default" data-index="<?php echo $item['index']; ?>" <?php echo empty($item['value']) ? 'required' : ''; ?> />
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    <?php endif; ?>
                    </tbody>
                </table>
            </td>
        </tr>
        </tbody>
    </table>
    <button type="submit" class="button button-primary">
        ذخیره تغییرات
    </button>
    <a href="" class="button button-cancel">لغو</a>
</form>