<?php
/* ============================================================================
   WBMCZ ADMIN — STAFF FORM FIELDS
   ----------------------------------------------------------------------------
   The boxes on the "Add Admin" and "Add Employee" forms are not fixed. Here a
   Super Admin decides which boxes appear, what they are called, whether they
   are required, and whether they belong on the Admin form, the Employee form,
   or both.

   The four boxes the system needs to make an account — name, mobile, email and
   password — can be renamed and re-ordered but never removed.
   ============================================================================ */
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../db.php';
require_once __DIR__ . '/../includes/functions.php';
require_once __DIR__ . '/../includes/Language.php';
require_once __DIR__ . '/../includes/rbac.php';
require_once __DIR__ . '/../includes/acl.php';
require_once __DIR__ . '/../includes/activity.php';

if (!isLoggedIn() || !isAdmin()) { redirect('login.php'); }
acl_ensure_schema($db);
acl_guard('staff.fields');

$lang         = new Language($db);
$current_lang = $lang->getCurrentLanguage();
$user_id      = (int)$_SESSION['user_id'];

$user_data = $db->select("SELECT * FROM users WHERE id = ?", [$user_id]);
$user      = !empty($user_data) ? $user_data[0] : null;
if (!$user) { session_destroy(); redirect('login.php'); }

$company_name = getSetting('company_name', 'WBMCZ');
$flash_ok  = $_SESSION['flash_success'] ?? ''; unset($_SESSION['flash_success']);
$flash_err = $_SESSION['flash_error']   ?? ''; unset($_SESSION['flash_error']);

/* seed the standard boxes the first time this page is opened */
try {
    $have = $db->select("SELECT COUNT(*) c FROM staff_form_fields");
    if ((int)($have[0]['c'] ?? 0) === 0) { acl_seed_fields($db); }
} catch (\Throwable $e) {}

$TYPES = ['text' => 'Text', 'textarea' => 'Long text', 'number' => 'Number', 'tel' => 'Phone',
          'email' => 'Email', 'date' => 'Date', 'select' => 'Dropdown', 'url' => 'Link', 'password' => 'Password'];
$APPLY = ['both' => 'Admin & Employee', 'admin' => 'Admin only', 'employee' => 'Employee only'];

/* ============================================================================
   SAVE A FIELD
   ============================================================================ */
if (isset($_POST['save_field'])) {
    $id    = (int)($_POST['field_id'] ?? 0);
    $label = trim((string)($_POST['label'] ?? ''));
    $key   = strtolower(trim((string)($_POST['field_key'] ?? '')));
    $key   = preg_replace('/[^a-z0-9_]/', '_', $key);
    $type  = $_POST['field_type'] ?? 'text';
    $apply = $_POST['applies_to'] ?? 'both';
    $opts  = trim((string)($_POST['options'] ?? ''));
    $ph    = trim((string)($_POST['placeholder'] ?? ''));
    $help  = trim((string)($_POST['help_text'] ?? ''));
    $req   = !empty($_POST['is_required']) ? 1 : 0;
    $stat  = !empty($_POST['status']) ? 1 : 0;
    $order = (int)($_POST['sort_order'] ?? 0);

    if ($label === '') { $_SESSION['flash_error'] = 'Give the box a label.'; redirect('staff_fields.php'); }
    if (!isset($TYPES[$type])) { $type = 'text'; }
    if (!isset($APPLY[$apply])) { $apply = 'both'; }

    if ($id > 0) {
        $cur = $db->select("SELECT * FROM staff_form_fields WHERE id = ?", [$id]);
        if (empty($cur)) { redirect('staff_fields.php'); }
        /* a system box keeps its key, its type and its required flag */
        if ((int)$cur[0]['is_system'] === 1) {
            $key   = $cur[0]['field_key'];
            $type  = $cur[0]['field_type'];
            $req   = (int)$cur[0]['is_required'];
            $stat  = 1;
            if (in_array($key, ['name', 'mobile', 'email', 'password'], true)) { $apply = 'both'; }
        }
        try {
            $db->insert(
                "UPDATE staff_form_fields SET field_key = ?, label = ?, field_type = ?, applies_to = ?,
                        options = ?, placeholder = ?, help_text = ?, is_required = ?, status = ?, sort_order = ?
                 WHERE id = ?",
                [$key, $label, $type, $apply, $opts, $ph, $help, $req, $stat, $order, $id]
            );
            activity_log($db, 'update', 'User Management', "Staff form field updated: $label");
            $_SESSION['flash_success'] = "“$label” saved.";
        } catch (\Throwable $e) { $_SESSION['flash_error'] = 'That field key is already used by another box.'; }
    } else {
        if ($key === '') { $key = substr(preg_replace('/[^a-z0-9_]/', '_', strtolower($label)), 0, 40); }
        try {
            $db->insert(
                "INSERT INTO staff_form_fields (field_key, label, field_type, applies_to, options, placeholder, help_text, is_required, status, sort_order, is_system)
                 VALUES (?,?,?,?,?,?,?,?,?,?,0)",
                [$key, $label, $type, $apply, $opts, $ph, $help, $req, $stat, $order]
            );
            activity_log($db, 'create', 'User Management', "Staff form field added: $label");
            $_SESSION['flash_success'] = "“$label” added to the form.";
        } catch (\Throwable $e) { $_SESSION['flash_error'] = 'That field key is already in use — try another one.'; }
    }
    redirect('staff_fields.php');
}

if (isset($_POST['toggle_field'])) {
    $id = (int)($_POST['field_id'] ?? 0);
    $f  = $db->select("SELECT * FROM staff_form_fields WHERE id = ?", [$id]);
    if (!empty($f) && (int)$f[0]['is_system'] !== 1) {
        $new = (int)$f[0]['status'] === 1 ? 0 : 1;
        try { $db->insert("UPDATE staff_form_fields SET status = ? WHERE id = ?", [$new, $id]); } catch (\Throwable $e) {}
        $_SESSION['flash_success'] = "“{$f[0]['label']}” is now " . ($new ? 'shown on the form.' : 'hidden from the form.');
    } else {
        $_SESSION['flash_error'] = 'A box the system needs cannot be switched off.';
    }
    redirect('staff_fields.php');
}

if (isset($_POST['delete_field'])) {
    $id = (int)($_POST['field_id'] ?? 0);
    $f  = $db->select("SELECT * FROM staff_form_fields WHERE id = ?", [$id]);
    if (!empty($f) && (int)$f[0]['is_system'] !== 1) {
        try {
            $db->insert("DELETE FROM staff_form_fields WHERE id = ?", [$id]);
            $db->insert("DELETE FROM staff_field_values WHERE field_key = ?", [$f[0]['field_key']]);
            activity_log($db, 'delete', 'User Management', "Staff form field removed: {$f[0]['label']}");
            $_SESSION['flash_success'] = "“{$f[0]['label']}” removed from the form.";
        } catch (\Throwable $e) {}
    } else {
        $_SESSION['flash_error'] = 'A box the system needs cannot be removed.';
    }
    redirect('staff_fields.php');
}

if (isset($_POST['reorder'])) {
    foreach (($_POST['order'] ?? []) as $fid => $ord) {
        try { $db->insert("UPDATE staff_form_fields SET sort_order = ? WHERE id = ?", [(int)$ord, (int)$fid]); }
        catch (\Throwable $e) {}
    }
    $_SESSION['flash_success'] = 'The order was saved.';
    redirect('staff_fields.php');
}

$fields = [];
try { $fields = $db->select("SELECT * FROM staff_form_fields ORDER BY sort_order ASC, id ASC"); }
catch (\Throwable $e) {}
?>
<!DOCTYPE html>
<html lang="<?php echo $current_lang; ?>">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Staff Form Fields - <?php echo htmlspecialchars($company_name); ?> Admin</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap" rel="stylesheet">
    <style>
        body { font-family: 'Inter', sans-serif; }
        [x-cloak] { display: none !important; }
        .lbl { display:block; font-size:11px; font-weight:700; color:#475569; margin-bottom:4px; }
        .fld { width:100%; border:1px solid #cbd5e1; border-radius:10px; padding:8px 11px; font-size:13px; background:#fff; }
        .fld:focus { outline:none; border-color:#6366f1; box-shadow:0 0 0 3px rgba(99,102,241,.15); }
    </style>
</head>
<body class="bg-gray-50" x-data="fieldBoard()" x-cloak>

<div class="flex h-screen overflow-hidden">

    <?php include __DIR__ . '/includes/sidebar.php'; ?>

    <div class="flex-1 flex flex-col min-w-0 bg-gray-100 overflow-hidden">

        <header class="h-20 bg-white flex items-center justify-between px-4 lg:px-8 shadow-sm border-b border-gray-200 z-40 relative flex-shrink-0">
            <div class="flex items-center min-w-0">
                <button @click="sidebarOpen = !sidebarOpen" class="p-2 mr-3 text-slate-500 hover:text-indigo-600 rounded-lg hover:bg-gray-100"><i class="fas fa-bars text-xl"></i></button>
                <div class="min-w-0">
                    <h2 class="text-xl font-bold truncate text-slate-800">Staff Form Fields</h2>
                    <p class="text-[11px] text-slate-400 hidden sm:block">The boxes that appear when an Admin or an Employee is created</p>
                </div>
            </div>
            <div class="flex items-center gap-2">
                <a href="staff.php" class="hidden sm:inline-flex items-center gap-2 px-4 py-2 rounded-xl bg-white ring-1 ring-slate-200 text-xs font-bold text-slate-600 hover:bg-slate-50"><i class="fas fa-users-gear"></i> Staff Accounts</a>
                <button @click="openField(null)" class="inline-flex items-center gap-2 px-4 py-2.5 rounded-xl bg-gradient-to-r from-indigo-600 to-violet-600 text-white text-xs font-bold shadow"><i class="fas fa-plus"></i> Add a box</button>
            </div>
        </header>

        <main class="flex-1 overflow-y-auto p-4 md:p-6 lg:p-8">

            <?php if ($flash_ok): ?>
            <div class="mb-5 bg-emerald-50 border border-emerald-200 text-emerald-700 px-4 py-3 rounded-xl text-sm"><i class="fas fa-check-circle mr-2"></i><?php echo htmlspecialchars($flash_ok); ?></div>
            <?php endif; ?>
            <?php if ($flash_err): ?>
            <div class="mb-5 bg-rose-50 border border-rose-200 text-rose-700 px-4 py-3 rounded-xl text-sm"><i class="fas fa-circle-exclamation mr-2"></i><?php echo htmlspecialchars($flash_err); ?></div>
            <?php endif; ?>

            <div class="mb-5 rounded-2xl border border-indigo-200 bg-indigo-50/60 px-5 py-4 text-xs text-indigo-900">
                <p class="font-bold mb-1"><i class="fas fa-circle-info mr-1"></i>How this works</p>
                <p>Every box you switch on here shows up on the Add Staff form. Say whether it belongs on the Admin form,
                   the Employee form or both, and whether it must be filled in. <b>Name, Mobile, Email and Password</b> are
                   marked <span class="font-bold">System</span> — you can rename and re-order them, but they cannot be removed,
                   because an account cannot be made without them.</p>
            </div>

            <form id="reorderForm" method="POST"><input type="hidden" name="reorder" value="1"></form>

            <div class="bg-white rounded-2xl shadow-sm border border-slate-200 overflow-hidden">
                <div class="p-5 md:p-6 border-b border-slate-100 flex flex-wrap items-center justify-between gap-3">
                    <div>
                        <h3 class="text-lg font-extrabold text-slate-800">The form, box by box</h3>
                        <p class="text-xs text-slate-400 mt-0.5">Change a number to move a box up or down, then save the order.</p>
                    </div>
                    <button type="submit" form="reorderForm" class="px-4 py-2 rounded-xl bg-slate-800 text-white text-xs font-bold"><i class="fas fa-arrow-down-1-9 mr-1"></i>Save the order</button>
                </div>

                <div class="overflow-x-auto">
                    <table class="w-full text-left border-collapse text-xs">
                        <thead>
                            <tr class="bg-slate-50 text-[10px] uppercase text-slate-500 tracking-wider border-b border-slate-200">
                                <th class="p-4 font-semibold w-20">Order</th>
                                <th class="p-4 font-semibold">Box</th>
                                <th class="p-4 font-semibold">Type</th>
                                <th class="p-4 font-semibold">Shows on</th>
                                <th class="p-4 font-semibold">Must be filled?</th>
                                <th class="p-4 font-semibold">Status</th>
                                <th class="p-4 font-semibold text-center">Action</th>
                            </tr>
                        </thead>
                        <tbody class="divide-y divide-slate-100">
                        <?php foreach ($fields as $f):
                            $sys = (int)$f['is_system'] === 1;
                            $on  = (int)$f['status'] === 1; ?>
                            <tr class="hover:bg-slate-50/70 align-top">
                                <td class="p-4">
                                    <input type="number" form="reorderForm" name="order[<?php echo (int)$f['id']; ?>]" value="<?php echo (int)$f['sort_order']; ?>" class="fld !py-1.5 !px-2 w-16 text-center">
                                </td>
                                <td class="p-4">
                                    <p class="font-bold text-slate-800 text-sm"><?php echo htmlspecialchars($f['label']); ?></p>
                                    <p class="text-[10px] text-slate-400 font-mono"><?php echo htmlspecialchars($f['field_key']); ?></p>
                                    <?php if (!empty($f['placeholder'])): ?>
                                    <p class="text-[10px] text-slate-300 italic mt-0.5">“<?php echo htmlspecialchars($f['placeholder']); ?>”</p>
                                    <?php endif; ?>
                                </td>
                                <td class="p-4 whitespace-nowrap">
                                    <span class="bg-slate-100 text-slate-600 text-[10px] font-bold px-2 py-1 rounded-md border border-slate-200"><?php echo $TYPES[$f['field_type']] ?? $f['field_type']; ?></span>
                                    <?php if (!empty($f['maps_to'])): ?>
                                    <p class="text-[10px] text-slate-300 mt-1">saved as <?php echo htmlspecialchars($f['maps_to']); ?></p>
                                    <?php endif; ?>
                                </td>
                                <td class="p-4 whitespace-nowrap">
                                    <span class="text-[10px] font-bold px-2 py-1 rounded-md <?php echo $f['applies_to'] === 'both' ? 'bg-violet-50 text-violet-600' : ($f['applies_to'] === 'admin' ? 'bg-rose-50 text-rose-600' : 'bg-teal-50 text-teal-600'); ?>">
                                        <?php echo $APPLY[$f['applies_to']] ?? $f['applies_to']; ?>
                                    </span>
                                </td>
                                <td class="p-4 whitespace-nowrap">
                                    <?php if ((int)$f['is_required'] === 1): ?>
                                        <span class="text-[10px] font-bold text-rose-600"><i class="fas fa-asterisk mr-1"></i>Required</span>
                                    <?php else: ?>
                                        <span class="text-[10px] text-slate-400">Optional</span>
                                    <?php endif; ?>
                                </td>
                                <td class="p-4 whitespace-nowrap">
                                    <span class="inline-flex items-center gap-1.5 px-2.5 py-1 rounded-lg text-[10px] font-bold ring-1 <?php echo $on ? 'bg-emerald-50 text-emerald-600 ring-emerald-200' : 'bg-slate-100 text-slate-500 ring-slate-200'; ?>">
                                        <i class="fas <?php echo $on ? 'fa-eye' : 'fa-eye-slash'; ?>"></i><?php echo $on ? 'On the form' : 'Hidden'; ?>
                                    </span>
                                    <?php if ($sys): ?><p class="text-[10px] font-black text-indigo-500 mt-1"><i class="fas fa-lock mr-1"></i>SYSTEM</p><?php endif; ?>
                                </td>
                                <td class="p-4">
                                    <div class="flex items-center justify-center gap-1.5">
                                        <button type="button" @click="openField(<?php echo htmlspecialchars(json_encode([
                                            'id' => (int)$f['id'], 'field_key' => $f['field_key'], 'label' => $f['label'],
                                            'field_type' => $f['field_type'], 'applies_to' => $f['applies_to'],
                                            'options' => $f['options'], 'placeholder' => $f['placeholder'],
                                            'help_text' => $f['help_text'], 'is_required' => (int)$f['is_required'],
                                            'status' => (int)$f['status'], 'sort_order' => (int)$f['sort_order'],
                                            'is_system' => $sys ? 1 : 0,
                                        ]), ENT_QUOTES); ?>)" title="Edit"
                                                class="w-8 h-8 rounded-lg bg-sky-50 text-sky-600 hover:bg-sky-100"><i class="fas fa-pen text-xs"></i></button>
                                        <?php if (!$sys): ?>
                                        <form method="POST" class="inline">
                                            <input type="hidden" name="toggle_field" value="1">
                                            <input type="hidden" name="field_id" value="<?php echo (int)$f['id']; ?>">
                                            <button type="submit" title="<?php echo $on ? 'Hide from the form' : 'Show on the form'; ?>"
                                                    class="w-8 h-8 rounded-lg <?php echo $on ? 'bg-amber-50 text-amber-600 hover:bg-amber-100' : 'bg-emerald-50 text-emerald-600 hover:bg-emerald-100'; ?>"><i class="fas <?php echo $on ? 'fa-eye-slash' : 'fa-eye'; ?> text-xs"></i></button>
                                        </form>
                                        <button type="button" @click="askDelete(<?php echo (int)$f['id']; ?>, '<?php echo htmlspecialchars(addslashes($f['label']), ENT_QUOTES); ?>')" title="Remove"
                                                class="w-8 h-8 rounded-lg bg-rose-50 text-rose-600 hover:bg-rose-100"><i class="fas fa-trash text-xs"></i></button>
                                        <?php else: ?>
                                        <span class="text-[10px] text-slate-400 font-bold bg-slate-100 px-2 py-1 rounded"><i class="fas fa-lock"></i></span>
                                        <?php endif; ?>
                                    </div>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </main>
    </div>
</div>

<!-- ================= FIELD EDITOR ================= -->
<div x-show="box" x-cloak class="fixed inset-0 z-[70] flex items-center justify-center p-4 bg-slate-900/50 backdrop-blur-sm" @click.self="box = false">
    <div class="bg-white rounded-2xl shadow-2xl w-full max-w-2xl max-h-[92vh] overflow-y-auto">
        <form method="POST">
            <input type="hidden" name="save_field" value="1">
            <input type="hidden" name="field_id" :value="f.id">

            <div class="px-6 py-5 border-b border-slate-100 flex items-center justify-between">
                <div>
                    <h3 class="text-lg font-extrabold text-slate-800" x-text="f.id ? 'Edit this box' : 'Add a box to the form'"></h3>
                    <p class="text-xs text-slate-400" x-show="f.is_system"><i class="fas fa-lock mr-1"></i>A box the system needs — you can rename and re-order it, nothing more.</p>
                </div>
                <button type="button" @click="box = false" class="w-9 h-9 rounded-xl bg-slate-100 text-slate-500 hover:bg-slate-200"><i class="fas fa-xmark"></i></button>
            </div>

            <div class="p-6 space-y-4">
                <div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
                    <div>
                        <label class="lbl">What should it be called? <span class="text-rose-500">*</span></label>
                        <input type="text" name="label" x-model="f.label" class="fld" required placeholder="Full Address">
                    </div>
                    <div>
                        <label class="lbl">Field key <span class="text-slate-400 font-normal">(leave blank and one is made)</span></label>
                        <input type="text" name="field_key" x-model="f.field_key" class="fld font-mono text-xs" :readonly="f.is_system" placeholder="address">
                    </div>
                </div>

                <div class="grid grid-cols-1 sm:grid-cols-3 gap-4">
                    <div>
                        <label class="lbl">Kind of box</label>
                        <select name="field_type" x-model="f.field_type" class="fld" :disabled="f.is_system">
                            <?php foreach ($TYPES as $tk => $tl): ?><option value="<?php echo $tk; ?>"><?php echo $tl; ?></option><?php endforeach; ?>
                        </select>
                    </div>
                    <div>
                        <label class="lbl">Shows on</label>
                        <select name="applies_to" x-model="f.applies_to" class="fld">
                            <?php foreach ($APPLY as $ak => $al): ?><option value="<?php echo $ak; ?>"><?php echo $al; ?></option><?php endforeach; ?>
                        </select>
                    </div>
                    <div>
                        <label class="lbl">Order</label>
                        <input type="number" name="sort_order" x-model="f.sort_order" class="fld">
                    </div>
                </div>

                <div x-show="f.field_type === 'select'">
                    <label class="lbl">The choices — one per line</label>
                    <textarea name="options" x-model="f.options" rows="4" class="fld" placeholder="Male&#10;Female&#10;Other"></textarea>
                </div>

                <div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
                    <div><label class="lbl">Grey hint inside the box</label><input type="text" name="placeholder" x-model="f.placeholder" class="fld"></div>
                    <div><label class="lbl">Small note under the box</label><input type="text" name="help_text" x-model="f.help_text" class="fld"></div>
                </div>

                <div class="flex flex-wrap gap-5 pt-1">
                    <label class="flex items-center gap-2 text-xs font-bold text-slate-600">
                        <input type="checkbox" name="is_required" x-model="f.is_required" class="w-4 h-4 rounded accent-rose-600" :disabled="f.is_system"> Must be filled in
                    </label>
                    <label class="flex items-center gap-2 text-xs font-bold text-slate-600">
                        <input type="checkbox" name="status" x-model="f.status" class="w-4 h-4 rounded accent-emerald-600" :disabled="f.is_system"> Show this box on the form
                    </label>
                </div>
            </div>

            <div class="px-6 py-4 border-t border-slate-100 flex justify-end gap-2">
                <button type="button" @click="box = false" class="px-5 py-2.5 rounded-xl bg-white ring-1 ring-slate-200 text-xs font-bold text-slate-600">Cancel</button>
                <button type="submit" class="px-6 py-2.5 rounded-xl bg-indigo-600 text-white text-xs font-bold"><i class="fas fa-check mr-1"></i> Save</button>
            </div>
        </form>
    </div>
</div>

<!-- ================= DELETE ================= -->
<div x-show="del" x-cloak class="fixed inset-0 z-[80] flex items-center justify-center p-4 bg-slate-900/50 backdrop-blur-sm" @click.self="del = false">
    <div class="bg-white rounded-2xl shadow-2xl w-full max-w-sm p-6 text-center">
        <div class="w-14 h-14 rounded-2xl bg-rose-50 text-rose-500 flex items-center justify-center text-xl mx-auto mb-4"><i class="fas fa-trash"></i></div>
        <h3 class="text-base font-extrabold text-slate-800 mb-1">Remove this box?</h3>
        <p class="text-xs text-slate-500 mb-5">“<b x-text="delName"></b>” disappears from the form, and whatever staff filled into it is deleted too.</p>
        <form method="POST" class="flex gap-2">
            <input type="hidden" name="delete_field" value="1">
            <input type="hidden" name="field_id" :value="delId">
            <button type="button" @click="del = false" class="flex-1 px-4 py-2.5 rounded-xl bg-white ring-1 ring-slate-200 text-xs font-bold text-slate-600">Keep it</button>
            <button type="submit" class="flex-1 px-4 py-2.5 rounded-xl bg-rose-600 text-white text-xs font-bold">Remove</button>
        </form>
    </div>
</div>

<script>
function fieldBoard() {
    return {
        sidebarOpen: window.innerWidth >= 768,
        box: false, del: false, delId: 0, delName: '',
        f: { id: 0, field_key: '', label: '', field_type: 'text', applies_to: 'both',
             options: '', placeholder: '', help_text: '', is_required: false, status: true,
             sort_order: 100, is_system: false },

        openField(row) {
            if (!row) {
                this.f = { id: 0, field_key: '', label: '', field_type: 'text', applies_to: 'both',
                           options: '', placeholder: '', help_text: '', is_required: false, status: true,
                           sort_order: 500, is_system: false };
            } else {
                this.f = {
                    id: row.id, field_key: row.field_key, label: row.label,
                    field_type: row.field_type, applies_to: row.applies_to,
                    options: row.options || '', placeholder: row.placeholder || '',
                    help_text: row.help_text || '',
                    is_required: row.is_required == 1, status: row.status == 1,
                    sort_order: row.sort_order, is_system: row.is_system == 1
                };
            }
            this.box = true;
        },

        askDelete(id, name) { this.delId = id; this.delName = name; this.del = true; }
    };
}
</script>

</body>
</html>
