<?php require APPROOT . '/app/Views/layouts/header.php'; ?>

<div class="max-w-4xl mx-auto mb-10">
    <div class="bg-white dark:bg-gray-800 rounded-xl shadow-sm border border-gray-200 dark:border-gray-700/50 overflow-hidden">
        <div class="p-5 border-b border-gray-200 dark:border-gray-700/50 bg-gray-50 dark:bg-gray-900/40 flex justify-between items-center">
            <h1 class="text-sm font-bold text-gray-900 dark:text-white flex items-center uppercase tracking-wider">
                <svg class="w-4 h-4 mr-2 text-primary" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"></path></svg>
                Add Partner Agency
            </h1>
            <a href="<?php echo URLROOT; ?>/admin/partners" class="text-xs text-primary hover:underline font-bold">Back to Partners</a>
        </div>
        
        <div class="p-6 md:p-8">
            <form action="<?php echo URLROOT; ?>/admin/addPartner" method="POST" enctype="multipart/form-data" class="space-y-8">
                
                <!-- Core Details & Login -->
                <div>
                    <h3 class="text-sm font-bold text-gray-900 dark:text-white border-b border-gray-200 dark:border-gray-700/50 pb-2 mb-4">Agency Details & Login Info</h3>
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                        <div class="md:col-span-2">
                            <label class="block text-xs font-bold text-gray-500 uppercase tracking-wider mb-2">Agency Name *</label>
                            <input type="text" name="name" value="<?php echo htmlspecialchars($data['name']); ?>" class="w-full px-4 py-2.5 rounded-lg border <?php echo (!empty($data['name_err'])) ? 'border-red-500' : 'border-gray-300 dark:border-gray-700'; ?> bg-gray-50 dark:bg-gray-900/50 text-gray-900 dark:text-white focus:ring-2 focus:ring-primary outline-none transition-colors" autofocus>
                            <span class="text-xs text-red-500 mt-1 block"><?php echo $data['name_err']; ?></span>
                        </div>
                        <div>
                            <label class="block text-[10px] font-bold text-gray-500 uppercase tracking-wider mb-2">Agency Email (Login ID) *</label>
                            <input type="email" name="email" value="<?php echo htmlspecialchars($data['email']); ?>" placeholder="agency@domain.com" class="w-full px-4 py-2.5 rounded-lg border <?php echo (!empty($data['email_err'])) ? 'border-red-500' : 'border-gray-300 dark:border-gray-700'; ?> bg-gray-50 dark:bg-gray-900/50 text-gray-900 dark:text-white focus:ring-2 focus:ring-primary outline-none transition-colors">
                            <span class="text-xs text-red-500 mt-1 block"><?php echo $data['email_err']; ?></span>
                        </div>
                        <div>
                            <label class="block text-[10px] font-bold text-gray-500 uppercase tracking-wider mb-2">Initial Password *</label>
                            <input type="password" name="password" value="<?php echo htmlspecialchars($data['password'] ?? ''); ?>" placeholder="Min 6 characters" class="w-full px-4 py-2.5 rounded-lg border <?php echo (!empty($data['password_err'])) ? 'border-red-500' : 'border-gray-300 dark:border-gray-700'; ?> bg-gray-50 dark:bg-gray-900/50 text-gray-900 dark:text-white focus:ring-2 focus:ring-primary outline-none transition-colors">
                            <span class="text-xs text-red-500 mt-1 block"><?php echo $data['password_err'] ?? ''; ?></span>
                        </div>
                        <div class="md:col-span-2">
                            <label class="block text-[10px] font-bold text-gray-500 uppercase tracking-wider mb-2">Contact Number</label>
                            <input type="text" name="contact_number" value="<?php echo htmlspecialchars($data['contact_number']); ?>" class="w-full px-4 py-2.5 rounded-lg border border-gray-300 dark:border-gray-700 bg-gray-50 dark:bg-gray-900/50 text-gray-900 dark:text-white focus:ring-2 focus:ring-primary outline-none transition-colors">
                        </div>
                    </div>
                </div>

                <!-- Jobcard System Config -->
                <div>
                    <h3 class="text-sm font-bold text-gray-900 dark:text-white border-b border-gray-200 dark:border-gray-700/50 pb-2 mb-4">Jobcard Customization</h3>
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                        <div>
                            <label class="block text-[10px] font-bold text-gray-500 uppercase tracking-wider mb-2">Jobcard Prefix</label>
                            <input type="text" name="jobcard_prefix" value="<?php echo htmlspecialchars($data['jobcard_prefix'] ?? 'PRT-'); ?>" placeholder="e.g. AGT-" class="w-full px-4 py-2.5 rounded-lg border border-gray-300 dark:border-gray-700 bg-gray-50 dark:bg-gray-900/50 text-gray-900 dark:text-white focus:ring-2 focus:ring-primary outline-none transition-colors">
                        </div>
                        <div>
                            <label class="block text-[10px] font-bold text-gray-500 uppercase tracking-wider mb-2">Next Sequence Number</label>
                            <input type="number" name="jobcard_sequence" value="<?php echo htmlspecialchars((string)($data['jobcard_sequence'] ?? 1)); ?>" class="w-full px-4 py-2.5 rounded-lg border border-gray-300 dark:border-gray-700 bg-gray-50 dark:bg-gray-900/50 text-gray-900 dark:text-white focus:ring-2 focus:ring-primary outline-none transition-colors">
                        </div>
                        <div class="md:col-span-2 p-5 border border-gray-200 dark:border-gray-700/50 rounded-xl bg-gray-50 dark:bg-gray-900/30 flex flex-col items-center justify-center text-center">
                            <label class="block text-xs font-bold text-gray-700 dark:text-gray-300 mb-2 w-full">Partner Logo (For PDF)</label>
                            <p class="text-[10px] text-gray-500 mb-4 border-b border-gray-200 dark:border-gray-700/50 w-full pb-3">This logo will replace your company logo on PDFs generated for this partner.</p>
                            <input type="file" name="logo" class="text-xs text-gray-500 dark:text-gray-400 w-full file:mr-4 file:py-1.5 file:px-3 file:rounded-md file:border-0 file:text-xs file:font-bold file:bg-primary file:text-white hover:file:opacity-90 transition-colors">
                        </div>
                    </div>
                </div>

                <!-- Address -->
                <div>
                    <h3 class="text-sm font-bold text-gray-900 dark:text-white border-b border-gray-200 dark:border-gray-700/50 pb-2 mb-4">Address Information</h3>
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                        <div class="md:col-span-2">
                            <label class="block text-[10px] font-bold text-gray-500 uppercase tracking-wider mb-2">Street Address</label>
                            <input type="text" name="address_street" value="<?php echo htmlspecialchars($data['address_street'] ?? ''); ?>" class="w-full px-4 py-2.5 rounded-lg border border-gray-300 dark:border-gray-700 bg-gray-50 dark:bg-gray-900/50 text-gray-900 dark:text-white focus:ring-2 focus:ring-primary outline-none transition-colors">
                        </div>
                        <div>
                            <label class="block text-[10px] font-bold text-gray-500 uppercase tracking-wider mb-2">Suburb</label>
                            <input type="text" name="address_suburb" value="<?php echo htmlspecialchars($data['address_suburb'] ?? ''); ?>" class="w-full px-4 py-2.5 rounded-lg border border-gray-300 dark:border-gray-700 bg-gray-50 dark:bg-gray-900/50 text-gray-900 dark:text-white focus:ring-2 focus:ring-primary outline-none transition-colors">
                        </div>
                        <div>
                            <label class="block text-[10px] font-bold text-gray-500 uppercase tracking-wider mb-2">City</label>
                            <input type="text" name="address_city" value="<?php echo htmlspecialchars($data['address_city'] ?? ''); ?>" class="w-full px-4 py-2.5 rounded-lg border border-gray-300 dark:border-gray-700 bg-gray-50 dark:bg-gray-900/50 text-gray-900 dark:text-white focus:ring-2 focus:ring-primary outline-none transition-colors">
                        </div>
                        <div>
                            <label class="block text-[10px] font-bold text-gray-500 uppercase tracking-wider mb-2">State / Province</label>
                            <input type="text" name="address_state" value="<?php echo htmlspecialchars($data['address_state'] ?? ''); ?>" class="w-full px-4 py-2.5 rounded-lg border border-gray-300 dark:border-gray-700 bg-gray-50 dark:bg-gray-900/50 text-gray-900 dark:text-white focus:ring-2 focus:ring-primary outline-none transition-colors">
                        </div>
                        <div>
                            <label class="block text-[10px] font-bold text-gray-500 uppercase tracking-wider mb-2">Postal / Zip Code</label>
                            <input type="text" name="address_zip" value="<?php echo htmlspecialchars($data['address_zip'] ?? ''); ?>" class="w-full px-4 py-2.5 rounded-lg border border-gray-300 dark:border-gray-700 bg-gray-50 dark:bg-gray-900/50 text-gray-900 dark:text-white focus:ring-2 focus:ring-primary outline-none transition-colors">
                        </div>
                        <div class="md:col-span-2">
                            <label class="block text-[10px] font-bold text-gray-500 uppercase tracking-wider mb-2">Country</label>
                            <input type="text" name="address_country" value="<?php echo htmlspecialchars($data['address_country'] ?? ''); ?>" class="w-full px-4 py-2.5 rounded-lg border border-gray-300 dark:border-gray-700 bg-gray-50 dark:bg-gray-900/50 text-gray-900 dark:text-white focus:ring-2 focus:ring-primary outline-none transition-colors">
                        </div>
                    </div>
                </div>

                <div class="pt-2">
                    <button type="submit" class="w-full md:w-auto bg-primary hover:opacity-90 text-white font-bold py-3 px-10 rounded-lg shadow-sm transition-all focus:ring-4 focus:ring-primary/50">
                        Create Partner & Generate Login
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>

<?php require APPROOT . '/app/Views/layouts/footer.php'; ?>