<!-- M-Pesa Settings Edit Modal -->
<form action="/settings/api/mpesa/edit" method="post" enctype="multipart/form-data">
    <div class="modal-dialog modal-xl modal-dialog-scrollable">
        <div class="modal-content">
            <!-- Modal Header -->
            <div class="modal-header bg-primary text-white">
                <h5 class="modal-title" id="editMpesaSettingsModalLabel<?= $setting['id'] ?>">
                    <i class="bi bi-phone me-2"></i> Edit M-Pesa Daraja API Settings
                </h5>
                <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>

            <!-- Modal Body -->
            <div class="modal-body">
                <div class="container-fluid">
                    <!-- Warning Alert -->
                    <div class="alert alert-warning mb-4">
                        <i class="bi bi-exclamation-triangle-fill me-2"></i>
                        <strong>Important:</strong> Please use below Mpesa Developer Settings only if you know what it does...
                    </div>

                    <!-- Information Card -->
                    <div class="card mb-4">
                        <div class="card-body">
                            <h6 class="card-title"><i class="bi bi-info-circle me-2"></i>Edit Mpesa Endpoints Settings</h6>
                            <p class="card-text mb-0">Update your M-Pesa Daraja API credentials and endpoints for payment processing.</p>
                        </div>
                    </div>

                    <!-- Hidden Fields -->
                    <input type="hidden" name="id" value="<?= $setting['id'] ?>">
                    <input type="hidden" name="uuid" value="<?= $setting['uuid'] ?>">

                    <!-- Settings Form -->
                    <div class="row g-3">
                        <!-- Basic Settings -->
                        <div class="col-12">
                            <h6 class="border-bottom pb-2 mb-3">Basic Settings</h6>
                        </div>

                        <!-- Shortcode Type -->
                        <div class="col-md-6 col-lg-4">
                            <label for="shortcodeType<?= $setting['id'] ?>" class="form-label">Mpesa Shortcode Type *</label>
                            <select class="form-select" id="shortcodeType<?= $setting['id'] ?>" name="shortcodeType" required>
                                <option value="1" <?= $setting['shortcode_type'] == '1' ? 'selected' : '' ?>>Till Number</option>
                                <option value="2" <?= $setting['shortcode_type'] == '2' ? 'selected' : '' ?>>Paybill Number</option>
                            </select>
                        </div>

                        <!-- Environment -->
                        <div class="col-md-6 col-lg-4">
                            <label for="apiEnvironment<?= $setting['id'] ?>" class="form-label">Environment *</label>
                            <select class="form-select" id="apiEnvironment<?= $setting['id'] ?>" name="apiEnvironment" required>
                                <option value="1" <?= $setting['api_environment'] == '1' ? 'selected' : '' ?>>Live</option>
                                <option value="2" <?= $setting['api_environment'] == '2' ? 'selected' : '' ?>>Sandbox</option>
                            </select>
                        </div>

                        <!-- Status -->
                        <div class="col-md-6 col-lg-4">
                            <label for="apiStatus<?= $setting['id'] ?>" class="form-label">Status *</label>
                            <select class="form-select" id="apiStatus<?= $setting['id'] ?>" name="apiStatus" required>
                                <option value="1" <?= $setting['api_status'] == '1' ? 'selected' : '' ?>>Active</option>
                                <option value="2" <?= $setting['api_status'] == '2' ? 'selected' : '' ?>>Inactive</option>
                            </select>
                        </div>

                        <!-- API Credentials -->
                        <div class="col-12 mt-3">
                            <h6 class="border-bottom pb-2 mb-3">API Credentials</h6>
                        </div>

                        <!-- Consumer Key -->
                        <div class="col-md-6 col-lg-4">
                            <label for="consumerKey<?= $setting['id'] ?>" class="form-label">Consumer Key *</label>
                            <div class="input-group">
                                <input type="password" class="form-control" id="consumerKey<?= $setting['id'] ?>" name="consumerKey"
                                    value="<?= ($setting['consumer_key']) ?>" required>
                                <button class="btn btn-outline-secondary toggle-password" type="button" data-target="consumerKey<?= $setting['id'] ?>">
                                    <i class="bi bi-eye"></i>
                                </button>
                            </div>
                        </div>

                        <!-- Consumer Secret -->
                        <div class="col-md-6 col-lg-4">
                            <label for="consumerSecret<?= $setting['id'] ?>" class="form-label">Consumer Secret *</label>
                            <div class="input-group">
                                <input type="password" class="form-control" id="consumerSecret<?= $setting['id'] ?>" name="consumerSecret"
                                    value="<?= ($setting['consumer_secret']) ?>" required>
                                <button class="btn btn-outline-secondary toggle-password" type="button" data-target="consumerSecret<?= $setting['id'] ?>">
                                    <i class="bi bi-eye"></i>
                                </button>
                            </div>
                        </div>

                        <!-- Pass Key -->
                        <div class="col-md-6 col-lg-4">
                            <label for="passKey<?= $setting['id'] ?>" class="form-label">Pass Key *</label>
                            <div class="input-group">
                                <input type="password" class="form-control" id="passKey<?= $setting['id'] ?>" name="passKey"
                                    value="<?= ($setting['pass_key']) ?>" required>
                                <button class="btn btn-outline-secondary toggle-password" type="button" data-target="passKey<?= $setting['id'] ?>">
                                    <i class="bi bi-eye"></i>
                                </button>
                            </div>
                            <div class="form-text">
                                <small>IT administrator should request the Pass Key from Safaricom Daraja API.</small>
                            </div>
                        </div>

                        <!-- Business Information -->
                        <div class="col-12 mt-3">
                            <h6 class="border-bottom pb-2 mb-3">Business Information</h6>
                        </div>

                        <!-- Business Shortcode -->
                        <div class="col-md-6 col-lg-4">
                            <label for="businessShortcode<?= $setting['id'] ?>" class="form-label">Business Shortcode *</label>
                            <input type="text" class="form-control" id="businessShortcode<?= $setting['id'] ?>" name="businessShortcode"
                                value="<?= ($setting['business_shortcode']) ?>" required>
                        </div>

                        <!-- Business MSISDN -->
                        <div class="col-md-6 col-lg-4">
                            <label for="businessMsisdn<?= $setting['id'] ?>" class="form-label">Business MSISDN *</label>
                            <input type="text" class="form-control" id="businessMsisdn<?= $setting['id'] ?>" name="businessMsisdn"
                                value="<?= ($setting['business_msisdn']) ?>" placeholder="2547XXXXXXXX" required>
                            <div class="form-text">
                                <small>Format: 2547XXXXXXXX</small>
                            </div>
                        </div>

                        <!-- Party A -->
                        <div class="col-md-6 col-lg-4">
                            <label for="partyA<?= $setting['id'] ?>" class="form-label">Party A *</label>
                            <input type="text" class="form-control" id="partyA<?= $setting['id'] ?>" name="partyA"
                                value="<?= ($setting['party_a']) ?>" required>
                        </div>

                        <!-- Party B -->
                        <div class="col-md-6 col-lg-4">
                            <label for="partyB<?= $setting['id'] ?>" class="form-label">Party B *</label>
                            <input type="text" class="form-control" id="partyB<?= $setting['id'] ?>" name="partyB"
                                value="<?= ($setting['party_b']) ?>" required>
                        </div>

                        <!-- Initiator Name -->
                        <div class="col-md-6 col-lg-4">
                            <label for="initiatorName<?= $setting['id'] ?>" class="form-label">Initiator Name *</label>
                            <input type="text" class="form-control" id="initiatorName<?= $setting['id'] ?>" name="initiatorName"
                                value="<?= ($setting['initiator_name']) ?>" required>
                        </div>

                        <!-- Webhook Endpoints -->
                        <div class="col-12 mt-3">
                            <h6 class="border-bottom pb-2 mb-3">Webhook Endpoints</h6>
                        </div>

                        <!-- Confirmation URL -->
                        <div class="col-md-6">
                            <label for="confirmationUrl<?= $setting['id'] ?>" class="form-label">Confirmation URL Endpoint *</label>
                            <input type="url" class="form-control" id="confirmationUrl<?= $setting['id'] ?>" name="confirmationUrl"
                                value="<?= ($setting['confirmation_url']) ?>" required>
                            <div class="form-text">
                                <small>URL where M-Pesa sends payment confirmation notifications</small>
                            </div>
                        </div>

                        <!-- Validation URL -->
                        <div class="col-md-6">
                            <label for="validationUrl<?= $setting['id'] ?>" class="form-label">Validation URL Endpoint *</label>
                            <input type="url" class="form-control" id="validationUrl<?= $setting['id'] ?>" name="validationUrl"
                                value="<?= ($setting['validation_url']) ?>" required>
                            <div class="form-text">
                                <small>URL where M-Pesa sends payment validation requests</small>
                            </div>
                        </div>

                        <!-- Validation Settings -->
                        <div class="col-12 mt-3">
                            <h6 class="border-bottom pb-2 mb-3">Validation Settings</h6>
                        </div>

                        <!-- Validation Parameter -->
                        <div class="col-md-6">
                            <label for="validationParameter<?= $setting['id'] ?>" class="form-label">Validation Parameter *</label>
                            <select class="form-select" id="validationParameter<?= $setting['id'] ?>" name="validationParameter" required>
                                <option value="1" <?= $setting['validation_parameter'] == '1' ? 'selected' : '' ?>>Accepted</option>
                                <option value="2" <?= $setting['validation_parameter'] == '2' ? 'selected' : '' ?>>Rejected</option>
                            </select>
                            <div class="form-text">
                                <small>
                                    <strong>Accepted:</strong> Prompts the API to accept transactions with no validation<br>
                                    <strong>Rejected:</strong> Prompts the API to reject transactions if no validation done
                                </small>
                            </div>
                        </div>

                        <!-- Result Code Parameter -->
                        <div class="col-md-6">
                            <label for="resultCodeParameter<?= $setting['id'] ?>" class="form-label">Validation Result Code Parameter *</label>
                            <select class="form-select" id="resultCodeParameter<?= $setting['id'] ?>" name="resultCodeParameter" required>
                                <option value="1" <?= $setting['result_code_parameter'] == '1' ? 'selected' : '' ?>>Success Code</option>
                                <option value="2" <?= $setting['result_code_parameter'] == '2' ? 'selected' : '' ?>>Rejected</option>
                            </select>
                            <div class="form-text">
                                <small>
                                    <strong>Success Code:</strong> Shows transaction success status<br>
                                    <strong>Rejected:</strong> Shows transaction rejection status
                                </small>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Modal Footer -->
            <div class="modal-footer">
                <div class="d-flex justify-content-between w-100">
                    <div>
                        <button type="button" class="btn btn-outline-secondary reset-form-btn" data-id="<?= $setting['id'] ?>">
                            <i class="bi bi-arrow-clockwise me-2"></i> Reset
                        </button>
                        <button type="button" class="btn btn-outline-danger clear-form-btn" data-id="<?= $setting['id'] ?>">
                            <i class="bi bi-trash me-2"></i> Clear All
                        </button>
                    </div>
                    <div>
                        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
                            <i class="bi bi-x-circle me-2"></i> Cancel
                        </button>
                        <button type="button" class="btn btn-primary edit-mpesa-api-setting-btn" id="edit-mpesa-api-setting-btn">
                            <i class="bi bi-save me-2"></i> Update Settings
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>