<?php
 
 
 
$activeTab = $activeTab ?? 'login';
?>

<div class="auth-page">
    <div class="auth-card">

        <div class="auth-tabs">
            <button type="button" class="auth-tabs__btn <?php echo $activeTab === 'login' ? 'active' : ''; ?>" data-tab="login"><?php echo __('log_in'); ?></button>
            <button type="button" class="auth-tabs__btn <?php echo $activeTab === 'register' ? 'active' : ''; ?>" data-tab="register"><?php echo __('sign_up'); ?></button>
            <button type="button" class="auth-tabs__btn <?php echo $activeTab === 'forgot' ? 'active' : ''; ?>" data-tab="forgot"><?php echo __('forgot_password'); ?></button>
        </div>

        <?php if (!empty($error)): ?>
            <div class="form-error"><?php echo htmlspecialchars($error); ?></div>
        <?php endif; ?>

        <?php if (!empty($success)): ?>
            <div class="form-success"><?php echo htmlspecialchars($success); ?></div>
        <?php endif; ?>

        
        <div class="auth-panel <?php echo $activeTab === 'login' ? 'active' : ''; ?>" id="panel-login">
            <form action="<?php echo url('/login'); ?>" method="POST">
                <?php echo Router::csrfField(); ?>

                <div class="form-group">
                    <label for="login_id"><?php echo __('email_or_username'); ?></label>
                    <input type="text" id="login_id" name="login" required autocomplete="username" placeholder="<?php echo __('email_or_username'); ?>">
                </div>

                <div class="form-group">
                    <label for="login_pw"><?php echo __('password'); ?></label>
                    <input type="password" id="login_pw" name="password" required autocomplete="current-password" placeholder="<?php echo __('password'); ?>">
                </div>

                <button type="submit" class="btn btn-primary" style="width:100%;"><?php echo __('log_in'); ?></button>
            </form>
        </div>

        
        <div class="auth-panel <?php echo $activeTab === 'register' ? 'active' : ''; ?>" id="panel-register">
            <form action="<?php echo url('/register'); ?>" method="POST">
                <?php echo Router::csrfField(); ?>

                <div class="form-group">
                    <label for="reg_username"><?php echo __('username'); ?></label>
                    <input type="text" id="reg_username" name="username" required autocomplete="username" placeholder="<?php echo __('username'); ?>" value="<?php echo htmlspecialchars($_POST['username'] ?? ''); ?>">
                </div>

                <div class="form-group">
                    <label for="reg_email"><?php echo __('email'); ?></label>
                    <input type="email" id="reg_email" name="email" required autocomplete="email" placeholder="<?php echo __('email'); ?>" value="<?php echo htmlspecialchars($_POST['email'] ?? ''); ?>">
                </div>

                <div class="form-group">
                    <label for="reg_pw"><?php echo __('password'); ?></label>
                    <input type="password" id="reg_pw" name="password" required autocomplete="new-password" placeholder="<?php echo __('password'); ?>">
                </div>

                <div class="form-group">
                    <label for="reg_pw2"><?php echo __('confirm_password'); ?></label>
                    <input type="password" id="reg_pw2" name="password_confirm" required autocomplete="new-password" placeholder="<?php echo __('confirm_password'); ?>">
                </div>

                <button type="submit" class="btn btn-primary" style="width:100%;"><?php echo __('sign_up'); ?></button>
            </form>
        </div>

        
        <div class="auth-panel <?php echo $activeTab === 'forgot' ? 'active' : ''; ?>" id="panel-forgot">
            <p style="font-size:14px;color:var(--text-muted);margin-bottom:16px;"><?php echo __('forgot_password_desc'); ?></p>
            <form action="<?php echo url('/forgot-password'); ?>" method="POST">
                <?php echo Router::csrfField(); ?>

                <div class="form-group">
                    <label for="forgot_email"><?php echo __('email'); ?></label>
                    <input type="email" id="forgot_email" name="email" required autocomplete="email" placeholder="<?php echo __('email'); ?>">
                </div>

                <button type="submit" class="btn btn-primary" style="width:100%;"><?php echo __('send_reset_link'); ?></button>
            </form>
        </div>

    </div>
</div>
