<?php
$__template->layout('Layout.main');
?>
<?php $__template->section('title'); ?>تعديل شبكة — <?= e($grid->name_ar) ?><?php $__template->endSection(); ?>

<?php $__template->section('content'); ?>

<div style="max-width:700px;margin:0 auto;">
    <div style="margin-bottom:20px;">
        <a href="/facility-grids/<?= (int) $grid->id ?>" style="color:#6B7280;text-decoration:none;font-size:13px;"><i data-lucide="arrow-right" style="width:14px;height:14px;vertical-align:middle;"></i> <?= e($grid->name_ar) ?></a>
    </div>

    <div class="card" style="padding:24px;">
        <h2 style="margin:0 0 24px;font-size:18px;font-weight:800;"><i data-lucide="settings" style="width:20px;height:20px;vertical-align:middle;margin-left:8px;color:#1e3a5f;"></i> تعديل الشبكة</h2>

        <form action="/facility-grids/<?= (int) $grid->id ?>/update" method="POST">
            <?= csrf_field() ?>

            <div style="display:grid;grid-template-columns:1fr 1fr;gap:16px;margin-bottom:20px;">
                <div>
                    <label style="display:block;font-size:13px;font-weight:600;margin-bottom:6px;">المرفق</label>
                    <select name="facility_id" style="width:100%;padding:10px 12px;border:1px solid #D1D5DB;border-radius:8px;font-size:13px;">
                        <?php foreach ($facilities as $f): ?>
                        <option value="<?= (int) $f['id'] ?>" <?= (int) $grid->facility_id === (int) $f['id'] ? 'selected' : '' ?>><?= e($f['name_ar']) ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div>
                    <label style="display:block;font-size:13px;font-weight:600;margin-bottom:6px;">نوع الشبكة</label>
                    <select name="grid_type" style="width:100%;padding:10px 12px;border:1px solid #D1D5DB;border-radius:8px;font-size:13px;">
                        <?php foreach ($gridTypes as $k => $v): ?>
                        <option value="<?= e($k) ?>" <?= $grid->grid_type === $k ? 'selected' : '' ?>><?= e($v) ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
            </div>

            <div style="display:grid;grid-template-columns:1fr 1fr;gap:16px;margin-bottom:20px;">
                <div>
                    <label style="display:block;font-size:13px;font-weight:600;margin-bottom:6px;">الاسم بالعربية *</label>
                    <input type="text" name="name_ar" required value="<?= e($grid->name_ar) ?>" style="width:100%;padding:10px 12px;border:1px solid #D1D5DB;border-radius:8px;font-size:13px;">
                </div>
                <div>
                    <label style="display:block;font-size:13px;font-weight:600;margin-bottom:6px;">الاسم بالإنجليزية</label>
                    <input type="text" name="name_en" value="<?= e($grid->name_en ?? '') ?>" style="width:100%;padding:10px 12px;border:1px solid #D1D5DB;border-radius:8px;font-size:13px;">
                </div>
            </div>

            <div style="display:grid;grid-template-columns:1fr 1fr;gap:16px;margin-bottom:20px;">
                <div>
                    <label style="display:block;font-size:13px;font-weight:600;margin-bottom:6px;">عدد الصفوف *</label>
                    <input type="number" name="rows_count" required min="1" max="50" value="<?= (int) $grid->rows_count ?>" style="width:100%;padding:10px 12px;border:1px solid #D1D5DB;border-radius:8px;font-size:13px;">
                </div>
                <div>
                    <label style="display:block;font-size:13px;font-weight:600;margin-bottom:6px;">عدد الأعمدة *</label>
                    <input type="number" name="cols_count" required min="1" max="50" value="<?= (int) $grid->cols_count ?>" style="width:100%;padding:10px 12px;border:1px solid #D1D5DB;border-radius:8px;font-size:13px;">
                </div>
            </div>

            <div style="display:grid;grid-template-columns:1fr 1fr;gap:16px;margin-bottom:20px;">
                <div>
                    <label style="display:block;font-size:13px;font-weight:600;margin-bottom:6px;">مسمى الصف</label>
                    <input type="text" name="row_label_ar" value="<?= e($grid->row_label_ar ?? 'حارة') ?>" style="width:100%;padding:10px 12px;border:1px solid #D1D5DB;border-radius:8px;font-size:13px;">
                </div>
                <div>
                    <label style="display:block;font-size:13px;font-weight:600;margin-bottom:6px;">مسمى العمود</label>
                    <input type="text" name="col_label_ar" value="<?= e($grid->col_label_ar ?? 'قسم') ?>" style="width:100%;padding:10px 12px;border:1px solid #D1D5DB;border-radius:8px;font-size:13px;">
                </div>
            </div>

            <div style="display:grid;grid-template-columns:1fr 1fr;gap:16px;margin-bottom:20px;">
                <div>
                    <label style="display:block;font-size:13px;font-weight:600;margin-bottom:6px;">الطول الفعلي (متر)</label>
                    <input type="number" name="physical_length" step="0.1" min="0" value="<?= $grid->physical_length ?? '' ?>" style="width:100%;padding:10px 12px;border:1px solid #D1D5DB;border-radius:8px;font-size:13px;">
                </div>
                <div>
                    <label style="display:block;font-size:13px;font-weight:600;margin-bottom:6px;">العرض الفعلي (متر)</label>
                    <input type="number" name="physical_width" step="0.1" min="0" value="<?= $grid->physical_width ?? '' ?>" style="width:100%;padding:10px 12px;border:1px solid #D1D5DB;border-radius:8px;font-size:13px;">
                </div>
            </div>

            <div style="display:flex;gap:12px;">
                <button type="submit" class="btn btn-primary" style="flex:1;padding:12px;">
                    <i data-lucide="save" style="width:16px;height:16px;vertical-align:middle;margin-left:6px;"></i> حفظ التغييرات
                </button>
                <a href="/facility-grids/<?= (int) $grid->id ?>" class="btn btn-outline" style="padding:12px 24px;">إلغاء</a>
            </div>
        </form>
    </div>
</div>

<?php $__template->endSection(); ?>
