<form method="POST" id="form-gravityforms-template-otp" action="<?php add_query_arg(['action' => 'create']); ?>">
    <input type="hidden" name="action" value="edit" />
    <table class="form-table">
        <tbody>
            <tr>
                <th scope="row">
                    <label for="input_name">عنوان</label>
                </th>
                <td>
                    <input type="text" name="title" id="input_name" value="gravityforms OTP" required readonly style="min-width: 300px;"/>
                </td>
            </tr>
            <tr>
                <th scope="row">وضعیت</th>
                <td>
                    <input type="radio" name="is_active" value="1" <?php echo isset($data['template']['is_active']) && $data['template']['is_active'] ? 'checked' : ''; ?> checked />
                    <label>فعال</label>
                    <br/>
                    <input type="radio" name="is_active" value="0" <?php echo isset($data['template']['is_active']) && !$data['template']['is_active'] ? 'checked' : ''; ?> />
                    <label>غیرفعال</label>
                </td>
            </tr>
            <tr>
                <th scope="row">
                    <label for="select-pattern">الگو</label>
                </th>
                <td>
                    <select name="pattern_id" id="select-pattern" required style="min-width: 300px;">
                        <option value="">انتخاب</option>
                        <?php foreach($data['patterns'] as $pattern): ?>
                            <option value="<?= $pattern['id'] ?>"
                                    data-pattern_text="<?= $pattern['pattern'] ?>"
                                    data-pattern_variables='<?= $pattern['variables_json'] ?>'
                                    <?php echo isset($data['template']['pattern_id']) && $data['template']['pattern_id'] == $pattern['id'] ? 'selected' : ''; ?>
                            >
                                <?= $pattern['title'] ?>
                            </option>
                        <?php endforeach; ?>
                    </select>
                    <br/>
                    <p id="p-show-pattern"></p>
                </td>
            </tr>
            <tr>
                <th scope="row">
                    <label for="">جایگذاری</label>
                </th>
                <!--
                <td style="padding-top: 0;">
                    <div id="div_pattern_variables_and_form_fields">
                        <table id="table_pattern_variables_and_form_fields">
                            <thead>
                                <tr>
                                    <th>متغیر الگو</th>
                                    <th>متغیر</th>
                                    <th>مقدار پیش فرض</th>
                                </tr>
                            </thead>
                            <tbody id="tbody-variables-and-values">

                            </tbody>
                        </table>
                    </div>
                </td>
                -->
                <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">
        &nbsp;
        ذخیره
        &nbsp;
    </button>
</form>