<?php require __DIR__.'/../layouts/header.php'; $p=is_array($p??null)?$p:[]; $prefs=is_array($prefs??null)?$prefs:[]; $photos=$photos??[]; $interests=$interests??[]; $sel=$sel??[]; $prompts=$prompts??[]; ?>
<div class="section-head"><div><div class="eyebrow">MY PROFILE</div><h1>Your profile</h1></div><span class="badge">18+ adult platform</span></div>
<div class="profile-layout"><section class="panel profile-card"><div class="avatar"><?php if($photos):?><img src="<?=url($photos[0]['path'])?>" alt="Profile photo"><?php else:?>V<?php endif;?></div>
<h2><?=e($u['name']??'Member')?> <?= paid_badge_html((int)($u['id']??0)) ?> <small><?=isset($u['dob'])?age_from_dob($u['dob']):''?></small></h2><p><?=e($p['city']??'Nairobi')?>, <?=e($u['country']??'Kenya')?></p><p><?=e($p['bio']??'')?:'Add a bio to tell people what makes you, you.'?></p>
<div class="progress"><span style="width:<?=max(0,min(100,(int)($p['profile_completion']??20)))?>%"></span></div><p class="muted"><?=max(0,min(100,(int)($p['profile_completion']??20)))?>% profile complete</p><hr><h3>Your photos <small class="muted">(up to 6)</small></h3>
<div class="photo-grid"><?php foreach($photos as $ph):?><div><img src="<?=url($ph['path'])?>" alt=""><form method="post" action="<?=url('profile/photo/delete')?>"><?=csrf()?><input type="hidden" name="photo_id" value="<?=$ph['id']?>"><button class="x">×</button></form></div><?php endforeach;?></div>
<form method="post" action="<?=url('profile/photo')?>" enctype="multipart/form-data"><?=csrf()?><p class="muted" style="font-size:12px;margin:0 0 8px">Upload <strong>clear photos of yourself</strong> (face visible). Avoid logos, screenshots, or object-only shots. JPG/PNG/WebP, min 400×400, max 8MB. Up to 6 photos.</p><label>Add personal photo<input type="file" name="photo" accept="image/jpeg,image/png,image/webp" required></label><button class="btn">Upload photo</button></form></section>
<section class="panel"><h2>Edit profile & discovery</h2><form method="post" action="<?=url('profile/save')?>"><?=csrf()?><div class="grid two">
<label>City<input name="city" value="<?=old('city',$p['city']??'Nairobi')?>" required></label>
<label>Country
<select name="country">
<?php foreach (world_countries() as $continent => $clist): ?>
<optgroup label="<?= e($continent) ?>">
<?php foreach ($clist as $c): ?>
<option value="<?= e($c) ?>" <?= (($u['country'] ?? 'Kenya') === $c) ? 'selected' : '' ?>><?= e($c) ?></option>
<?php endforeach; ?>
</optgroup>
<?php endforeach; ?>
</select>
</label><label>Relationship goal<select name="relationship_goal"><?php foreach(['Long-term','Short-term','New friends','Still figuring it out'] as $v):?><option value="<?=e($v)?>" <?=((($p['relationship_goal']??'Long-term')===$v)?'selected':'')?>><?=e($v)?></option><?php endforeach;?></select></label>
<label>Gender<input name="gender" value="<?=old('gender',$p['gender']??'')?>" placeholder="e.g. Woman, Man"></label><label>Orientation<input name="orientation" value="<?=old('orientation',$p['orientation']??'')?>" placeholder="e.g. Men, Women, Everyone"></label><label>Pronouns<input name="pronouns" value="<?=old('pronouns',$p['pronouns']??'')?>"></label>
<label>Minimum age<input type="number" min="18" max="99" name="min_age" value="<?=e($prefs['min_age']??18)?>"></label><label>Maximum age<input type="number" min="18" max="99" name="max_age" value="<?=e($prefs['max_age']??99)?>"></label><label>Maximum distance (km)<input type="number" min="1" max="500" name="max_distance_km" value="<?=e($prefs['max_distance_km']??50)?>"></label>
<label>Show me<select name="show_gender"><?php foreach(['Everyone','Men','Women'] as $g):?><option value="<?=e($g)?>" <?=((($prefs['show_gender']??'Everyone')===$g)?'selected':'')?>><?=e($g)?></option><?php endforeach;?></select></label></div>
<label>Bio<textarea name="bio" rows="5" maxlength="500" placeholder="Tell people about yourself..."><?=old('bio',$p['bio']??'')?></textarea></label>
<label>Hobbies <small class="muted">(comma separated)</small><input name="hobbies" value="<?=old('hobbies',$p['hobbies']??'')?>" maxlength="500" placeholder="e.g. hiking, cooking, photography"></label>
<label>Likes <small class="muted">(things you enjoy)</small><input name="likes_text" value="<?=old('likes_text',$p['likes_text']??'')?>" maxlength="500" placeholder="e.g. live music, brunch, travel"></label>
<label>Location label <small class="muted">(area shown on profile)</small><input name="location_label" value="<?=old('location_label',$p['location_label']??'')?>" maxlength="190" placeholder="e.g. Westlands, Nairobi"></label>
<label>Phone number <small class="muted">(for M-Pesa; optional visibility)</small><input name="phone" type="tel" value="<?=old('phone',$u['phone']??'')?>" maxlength="30" placeholder="07XX XXX XXX"></label>
<label class="check"><input type="checkbox" name="show_phone" <?=!empty($p['show_phone'])?'checked':''?>> Show my phone number on my public profile</label>
<label class="check"><input type="checkbox" name="dealbreakers" <?=!empty($prefs['dealbreakers'])?'checked':''?>> Treat my age/distance preferences as firm filters.</label>
<h3>Interests</h3>
<p class="muted" style="font-size:12px;margin:0 0 8px">Tick all that fit you — shared interests rank higher in discovery.</p>
<div class="interest-grid"><?php foreach($interests as $i):?><label class="interest"><input type="checkbox" name="interests[]" value="<?=$i['id']?>" <?=in_array((int)$i['id'],$sel,true)?'checked':''?>> <?=e($i['name'])?></label><?php endforeach;?></div>
<label style="margin-top:12px">Other interests <small class="muted">(type your own, comma separated)</small>
<input name="custom_interests" value="<?=old('custom_interests',$p['custom_interests']??'')?>" maxlength="500" placeholder="e.g. salsa, podcasts, volunteering, board games">
</label>
<h3>Ice breakers</h3><p class="muted" style="font-size:12px;margin:0 0 8px">Short answers others see on your full profile before they match.</p><?php foreach($prompts as $pr):?><label><?=e($pr['prompt'])?><input name="prompt_answer[<?=$pr['id']?>]" value="<?=e($pr['answer']??'')?>" maxlength="500"></label><?php endforeach;?><button class="btn">Save everything</button></form></section></div><?php require __DIR__.'/../layouts/footer.php'; ?>