<?php
session_start();
require 'config.php'; // Include your config file for Azure AD settings

// Build URL to redirect user to Azure AD login
$auth_url = $authorize_url . '?' . http_build_query([
    'client_id' => $client_id,
    'response_type' => 'code',
    'redirect_uri' => $redirect_uri,
    'response_mode' => 'query',
    'scope' => $scope,
    'state' => bin2hex(random_bytes(8)),  // CSRF protection
]);

$_SESSION['oauth2state'] = $auth_url;
?>

<!doctype html>
<html lang="en" style="height: 100%">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <title><?php echo $module_name; ?></title>
    <link rel="icon" type="image/x-icon" href="../../../../public/assets/images/login/robi_favicon-32x32.png">
  
    <link href="../../../../public/assets/css/bootstrap.v4.4.1.min.css" type="text/css" rel="stylesheet"/>
    <link rel="stylesheet" type="text/css" href="../../../../public/assets/css/acc_mod_index.css" media="all">
    
    <style type="text/css">
        * {
            padding: 0;
            margin: 0;
            outline: none;
        }
        body {
            font-family: 'Roboto', sans-serif !important;
            height: 100vh;
            color: #666 !important;
            background: #f5f5f5;
        }
        
        .login-container {
            max-width: 450px;
            margin: 0 auto;
            padding: 40px 20px;
        }
        
        .login-card {
            background: white;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            padding: 40px 30px;
            text-align: center;
        }
        
        .logo-section {
            margin-bottom: 30px;
        }
        
        .logo-section img {
            max-width: 60px;
            height: auto;
            margin-bottom: 15px;
        }
        
        .portal-title {
            font-size: 24px;
            font-weight: 600;
            color: #333;
            margin: 0 0 8px 0;
        }
        
        .portal-subtitle {
            font-size: 16px;
            color: #666;
            margin-bottom: 40px;
        }
        
        .ad-login-btn {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            background: #d32f2f;
            color: white;
            padding: 12px 24px;
            border-radius: 4px;
            text-decoration: none;
            font-weight: 500;
            font-size: 16px;
            width: 100%;
            margin-bottom: 30px;
            transition: background-color 0.3s;
            border: none;
        }
        
        .ad-login-btn:hover {
            background: #b71c1c;
            color: white;
            text-decoration: none;
        }
        
        .partner-login-section {
            border-top: 1px solid #e0e0e0;
            padding-top: 20px;
        }
        
        .partner-login-title {
            font-size: 14px;
            color: #666;
            margin-bottom: 10px;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }
        
        .partner-login-link {
            color: #1976d2;
            text-decoration: none;
            font-size: 14px;
        }
        
        .partner-login-link:hover {
            text-decoration: underline;
            color: #1565c0;
        }
        
        .privacy-footer {
            text-align: center;
            margin-top: 30px;
            padding: 15px;
            background: #f8f9fa;
            border-radius: 4px;
        }
        
        .privacy-link {
            color: #666;
            text-decoration: none;
            font-size: 13px;
        }
        
        .privacy-link:hover {
            color: #333;
            text-decoration: underline;
        }
        
        .separator {
            color: #999;
            margin: 0 8px;
            font-size: 13px;
        }
        
        @media only screen and (max-width: 600px) {
            .login-container {
                padding: 20px 15px;
            }
            
            .login-card {
                padding: 30px 20px;
            }
            
            .portal-title {
                font-size: 20px;
            }
            
            .portal-subtitle {
                font-size: 14px;
            }
        }
    </style>
</head>

<body>

<div class="container h-100">
    <div class="row h-100 justify-content-center align-items-center">
        <div class="col-12">
            <div class="login-container">
                <div class="login-card">
                    <?php if ($msg != '') { ?>
                        <div class="alert alert-danger"><?=$msg;?></div>
                    <?php } ?>
                    
                    <div class="logo-section">
                        <?php
                            $cloud_logo = "../../../../public/assets/images/logo/clouderplogo.png";
                            $project_logo = "../../../../public/assets/images/logo/".$cid.".png";
                            if (is_file($project_logo)) {
                                $show_logo = $project_logo;
                            } else {
                                $show_logo = $cloud_logo;
                            }
                        ?>
                        <img alt="Robi Logo" src="<?=$show_logo?>" />
                        <h1 class="portal-title">E-Sourcing Portal</h1>
                        <p class="portal-subtitle">Login to your Account</p>
                    </div>
                    
                    <!-- AD Login Button -->
                    <a href="<?php echo htmlspecialchars($auth_url); ?>" class="ad-login-btn">
                        Login with AD (Robi user Only)
                    </a>
                    

                </div>
                
                <!-- Privacy and Cookie Policy Footer -->
                <div class="privacy-footer">
                    <a href="https://www.robi.com.bd/en/privacy-policy" target="_blank" class="privacy-link">Privacy Policy</a>
                    <span class="separator">|</span>
                    <a href="https://www.robi.com.bd/en/cookies-policy" target="_blank" class="privacy-link">Cookie Policy</a>
                </div>
            </div>
        </div>
    </div>
</div>

</body>

</html>
