<style>
.file-upload-box {
    border: 1px dashed #ccc;
    padding: 10px;
    cursor: pointer;
}
.file-upload-box:hover {
    background-color: #f9f9f9;
}
</style>

<div class='card'>
    <form action='' method='POST' enctype='multipart/form-data'>
        <div class='panel panel-primary ch'>
            <div class='panel-heading'>
                <h4 class='text-center'>Save School Information</h4>
            </div>
            <div class='panel-body'>
                <div class='row'>
                    <div class='col-xs-12 col-sm-12 col-md-12'>
                        <table class="table table-striped">
                            <tbody>
                                <?php
                                $fields = [
                                    ['label' => 'School Name', 'name' => 'school_name', 'type' => 'text', 'value' => $admin_data['school_name'], 'placeholder' => 'School Name'],
                                    ['label' => 'School Address', 'name' => 'school_address', 'type' => 'text', 'value' => $admin_data['school_address'], 'placeholder' => 'School Address'],
                                    ['label' => 'School Motto', 'name' => 'school_motto', 'type' => 'text', 'value' => $admin_data['school_motto'], 'placeholder' => 'School Motto'],
                                    ['label' => 'School Phone', 'name' => 'school_phone', 'type' => 'text', 'value' => $admin_data['school_phone'], 'placeholder' => 'School Contact Phone '],
                                    ['label' => 'School Mail', 'name' => 'school_mail', 'type' => 'text', 'value' => $admin_data['school_mail'], 'placeholder' => 'School Mail '],
                                    ['label' => 'School Website', 'name' => 'school_website', 'type' => 'text', 'value' => $admin_data['school_website'], 'placeholder' => 'School Website '],                                                                                                                                                                    
                                    ['label' => 'School Whatsapp No', 'name' => 'school_whatsapp', 'type' => 'text', 'value' => $admin_data['school_whatsapp'], 'placeholder' => 'School Whatsapp Contact'],                                    
                                    ['label' => 'School Short Name', 'name' => 'school_short_name', 'type' => 'text', 'value' => $admin_data['school_short_name'], 'placeholder' => 'School Short Name'],                                                                                           
                                    ['label' => 'ADM No Initials', 'name' => 'adm_no_initials', 'type' => 'text', 'value' => $admin_data['adm_no_initials'], 'placeholder' => 'School Admission No Initials '],
                                    
                                ];

                                foreach ($fields as $field): ?>
                                    <tr>
                                        <td><?= $field['label'] ?></td>
                                        <td>
                                            <input
                                                name="<?= $field['name'] ?>"
                                                type="<?= $field['type'] ?>"
                                                placeholder="<?= $field['placeholder'] ?>"
                                                class="form-control"
                                                value="<?= htmlspecialchars($field['value']) ?>"
                                                required>
                                        </td>
                                    </tr>
                                <?php endforeach; ?>
                            </tbody>
                        </table>

                        <h5><strong>Upload School Logo, Stamp, and Favicon</strong></h5>
                        <div class="row text-center">
                            <?php
                            $uploads = [
                                ['label' => 'School Logo', 'name' => 'logo', 'preview_id' => 'logo-preview', 'current' => $admin_data['school_logo'], 'height' => 80],
                                ['label' => 'School Stamp/Signature', 'name' => 'stamp', 'preview_id' => 'stamp-preview', 'current' => $admin_data['school_stamp'], 'height' => 80],
                                ['label' => 'Favicon', 'name' => 'favicon', 'preview_id' => 'favicon-preview', 'current' => $admin_data['school_favicon'], 'height' => 32]
                            ];

                            foreach ($uploads as $upload): ?>
                                <div class="col-md-4 col-sm-12 mb-3">
                                    <div class="border p-3 rounded shadow-sm">
                                        <strong><?= $upload['label'] ?></strong>
                                        <div class="file-upload-box mt-2" data-preview-id="<?= $upload['preview_id'] ?>">
                                            <input type="file" name="<?= $upload['name'] ?>" class="file-input form-control-file" accept="image/*">
                                            <p class="upload-msg small text-muted mt-1">Click or drag to upload</p>
                                        </div>
                                        <?php if (!empty($upload['current'])): ?>
                                            <br>
                                            <img id="<?= $upload['preview_id'] ?>" src="<?= '../' .htmlspecialchars($upload['current']) ?>" alt="<?= $upload['label'] ?>" height="<?= $upload['height'] ?>">

                                        <?php endif; ?>
                                    </div>
                                </div>
                            <?php endforeach; ?>
                        </div>

                        <div class='row'>
                            <div class='col-xs-12 text-right'>
                                <button name='admin_upload_btn' class='btn btn-primary' style='border-radius:10px;' type='submit'>
                                    Save
                                </button>
                            </div>
                        </div>
                        <br><br>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>

