<?php $__env->startSection('title', $account ? 'Edit Committee Account' : 'Register Committee Account'); ?>

<?php $__env->startSection('content'); ?>
<?php
    $lookup = session('committee_lookup');
    $found = is_array($lookup) && empty($lookup['missing']) ? $lookup : null;
    $fromOtherEvent = $found && ! empty($found['from_other_event']);
    $missing = is_array($lookup) && ! empty($lookup['missing']);
    $emailValue = old('email', $account['email'] ?? ($found['email'] ?? ($lookup['email'] ?? '')));
    $isEdit = (bool) $account;
    $showDetails = $isEdit || $found || $missing;
?>

<div class="pg-head">
    <div>
        <a href="<?php echo e(route('mexco.admin.committee')); ?>" class="cell-sub">← Committee Accounts</a>
        <h1 class="mt-1"><?php echo e($isEdit ? 'Edit committee account' : 'Register committee account'); ?></h1>
        <p>
            <?php if($isEdit): ?>
                Update contact details for MeXCo Attend login. Their participant role stays unchanged.
            <?php else: ?>
                Search an email from this event or another MeXCo event. One account can join multiple events.
            <?php endif; ?>
        </p>
    </div>
</div>

<?php if(! $isEdit): ?>
<div class="card form-panel" style="max-width:560px;margin-bottom:1rem">
    <form method="POST" action="<?php echo e(route('mexco.admin.committee.lookup')); ?>">
        <?php echo csrf_field(); ?>
        <div class="form-row" style="margin-bottom:0">
            <label class="form-label">Search by email</label>
            <div style="display:flex;gap:.5rem;flex-wrap:wrap">
                <input type="email" name="email" class="form-input <?php $__errorArgs = ['email'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                       value="<?php echo e($emailValue); ?>" placeholder="name@organisation.edu" required style="flex:1;min-width:220px">
                <button type="submit" class="btn-purple">Search</button>
            </div>
            <div class="cell-sub mt-1">Looks up participants across all events.</div>
            <?php $__errorArgs = ['email'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?><div class="text-danger small mt-1"><?php echo e($message); ?></div><?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
        </div>
    </form>
</div>
<?php endif; ?>

<?php if($found && ! $fromOtherEvent): ?>
    <div class="alert-flash alert-success" style="max-width:560px">
        <span>
            Found <strong><?php echo e($found['name']); ?></strong>
            (<?php echo e(strtoupper($found['role'] ?? 'VISITOR')); ?>).
            Their current role will be kept, and committee access will be added.
        </span>
    </div>
<?php elseif($fromOtherEvent): ?>
    <div class="alert-flash alert-success" style="max-width:560px">
        <span>
            Found <strong><?php echo e($found['name']); ?></strong>
            <?php if(!empty($found['user_id'])): ?>
                <span class="mono">(<?php echo e($found['user_id']); ?>)</span>
            <?php endif; ?>
            from <strong><?php echo e($found['event_name'] ?? 'another event'); ?></strong>.
            They will be added to this event with the same Pass account, plus committee access.
        </span>
    </div>
<?php elseif($missing): ?>
    <div class="alert-flash" style="max-width:560px;background:#EFF6FF;color:#1E40AF;border:1px solid #BFDBFE">
        <span>No participant found for that email. Register them as a new committee account (participant role defaults to VISITOR).</span>
    </div>
<?php endif; ?>
<?php if($showDetails): ?>
<div class="card form-panel" style="max-width:560px">
    <form method="POST" action="<?php echo e($isEdit ? route('mexco.admin.committee.update', $account['slug']) : route('mexco.admin.committee.store')); ?>">
        <?php echo csrf_field(); ?>
        <?php if($isEdit): ?> <?php echo method_field('PUT'); ?> <?php endif; ?>

        <div class="form-row">
            <label class="form-label">Email address</label>
            <input type="email" name="email" class="form-input"
                   value="<?php echo e($emailValue); ?>" <?php echo e($isEdit || $found ? 'readonly' : ''); ?> required>
            <div class="cell-sub mt-1">Used to sign in to MeXCo Attend.</div>
        </div>
        <div class="form-row">
            <label class="form-label">Full name</label>
            <input type="text" name="name" class="form-input <?php $__errorArgs = ['name'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                   value="<?php echo e(old('name', $account['name'] ?? ($found['name'] ?? ''))); ?>" <?php echo e($found ? '' : 'required'); ?>>
            <?php $__errorArgs = ['name'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?><div class="text-danger small mt-1"><?php echo e($message); ?></div><?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
        </div>
        <div class="form-row">
            <label class="form-label">IC / ID number</label>
            <input type="text" name="ic" class="form-input <?php $__errorArgs = ['ic'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                   value="<?php echo e(old('ic', $account['ic'] ?? ($found['ic'] ?? ''))); ?>"
                   inputmode="numeric"
                   <?php echo e(($found && strlen(preg_replace('/\D/', '', (string) ($found['ic'] ?? ''))) >= 6) ? '' : 'required'); ?>>
            <div class="cell-sub mt-1">
                <?php if($found && !empty($found['ic'])): ?>
                    Existing IC will be kept if you leave this unchanged.
                <?php else: ?>
                    Required for Attend login (full IC or at least 6 digits).
                <?php endif; ?>
            </div>
            <?php $__errorArgs = ['ic'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?><div class="text-danger small mt-1"><?php echo e($message); ?></div><?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
        </div>
        <div class="form-grid">
            <div class="form-row">
                <label class="form-label">Organisation</label>
                <input type="text" name="org" class="form-input" value="<?php echo e(old('org', $account['org'] ?? ($found['org'] ?? ''))); ?>">
            </div>
            <div class="form-row">
                <label class="form-label">WhatsApp</label>
                <input type="text" name="phone" class="form-input" value="<?php echo e(old('phone', $account['phone'] ?? ($found['phone'] ?? ''))); ?>">
            </div>
        </div>

        <?php if(($found && ! $fromOtherEvent) || $isEdit): ?>
            <div class="form-row">
                <label class="form-label">Roles on this event</label>
                <div style="display:flex;flex-wrap:wrap;gap:.4rem">
                    <span class="status-pill" style="background:#EEF2FF;color:#4338CA"><?php echo e(strtoupper($account['role'] ?? $found['role'] ?? 'VISITOR')); ?></span>
                    <span class="status-pill" style="background:#F3EEFF;color:#5B21B6">COMMITTEE</span>
                </div>
                <div class="cell-sub mt-1">Participant role is unchanged. Committee access is added for MeXCo Attend.</div>
            </div>
        <?php elseif($fromOtherEvent): ?>
            <div class="form-row">
                <label class="form-label">Roles on this event</label>
                <div style="display:flex;flex-wrap:wrap;gap:.4rem">
                    <span class="status-pill" style="background:#EEF2FF;color:#4338CA">VISITOR</span>
                    <span class="status-pill" style="background:#F3EEFF;color:#5B21B6">COMMITTEE</span>
                </div>
                <div class="cell-sub mt-1">They will be registered on this event as VISITOR with committee Attend access. Same UserID is reused.</div>
            </div>
        <?php endif; ?>

        <button type="submit" class="btn-purple">
            <?php if($isEdit): ?>
                Save changes
            <?php elseif($fromOtherEvent): ?>
                Add to this event as committee
            <?php elseif($found): ?>
                Add as committee
            <?php else: ?>
                Register account
            <?php endif; ?>
        </button>
        <a href="<?php echo e($attendUrl); ?>" class="btn-outline" style="margin-left:.5rem" target="_blank" rel="noopener">
            <?php if(!empty($account['email']) || !empty($found['email']) || !empty($emailValue)): ?>
                Open Attend as this user
            <?php else: ?>
                Open Attend
            <?php endif; ?>
        </a>
    </form>
</div>
<?php endif; ?>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('admin.layout', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\laragon\www\myapp\resources\views/admin/committee/form.blade.php ENDPATH**/ ?>