<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Database Setup - Fixture Manager</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            background-color: #f5f5f5;
        }
        .container {
            background: white;
            padding: 30px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        .header {
            text-align: center;
            color: #333;
            margin-bottom: 30px;
        }
        .warning {
            background: #fff3cd;
            border: 1px solid #ffeaa7;
            color: #856404;
            padding: 15px;
            border-radius: 5px;
            margin-bottom: 20px;
        }
        .step {
            background: #f8f9fa;
            border-left: 4px solid #007bff;
            padding: 15px;
            margin: 15px 0;
        }
        .step h3 {
            margin-top: 0;
            color: #007bff;
        }
        .code {
            background: #2d3748;
            color: #e2e8f0;
            padding: 15px;
            border-radius: 5px;
            font-family: 'Courier New', monospace;
            overflow-x: auto;
            margin: 10px 0;
        }
        .success {
            background: #d4edda;
            border: 1px solid #c3e6cb;
            color: #155724;
            padding: 15px;
            border-radius: 5px;
            margin: 15px 0;
        }
        .btn {
            background: #007bff;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            text-decoration: none;
            display: inline-block;
            margin: 10px 5px;
        }
        .btn:hover {
            background: #0056b3;
        }
        .config-example {
            background: #f1f3f4;
            border: 1px solid #dadce0;
            padding: 15px;
            border-radius: 5px;
            margin: 10px 0;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>🔧 Database Setup Required</h1>
            <p>The Fixture Manager needs a MySQL database to function properly.</p>
        </div>

        <div class="warning">
            <strong>⚠️ Database Not Connected</strong><br>
            The application cannot connect to the database. Please follow the steps below to set up your database.
        </div>

        <div class="step">
            <h3>Step 1: Install MySQL Server</h3>
            <p>If you don't have MySQL installed, install it first:</p>
            <div class="code">
# Ubuntu/Debian
sudo apt update
sudo apt install mysql-server

# CentOS/RHEL/Fedora
sudo yum install mysql-server
# or
sudo dnf install mysql-server

# Start MySQL service
sudo systemctl start mysql
sudo systemctl enable mysql
            </div>
        </div>

        <div class="step">
            <h3>Step 2: Create Database and User</h3>
            <p>Log into MySQL and create the database:</p>
            <div class="code">
# Log into MySQL as root
sudo mysql -u root -p

# Create database
CREATE DATABASE fixture_manager CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

# Create user (replace 'your_password' with a secure password)
CREATE USER 'fixture_user'@'localhost' IDENTIFIED BY 'your_password';

# Grant privileges
GRANT ALL PRIVILEGES ON fixture_manager.* TO 'fixture_user'@'localhost';
FLUSH PRIVILEGES;

# Exit MySQL
EXIT;
            </div>
        </div>

        <div class="step">
            <h3>Step 3: Configure Environment Variables</h3>
            <p>Create a <code>.env</code> file in the application directory with your database settings:</p>
            <div class="config-example">
                <strong>Example .env file:</strong>
                <div class="code">
# Database Configuration
MYSQL_HOST=localhost
MYSQL_PORT=3306
MYSQL_USER=fixture_user
MYSQL_PASSWORD=your_password
MYSQL_DATABASE=fixture_manager

# Security
SECRET_KEY=your-secret-key-here
JWT_SECRET_KEY=your-jwt-secret-key-here

# Application Settings
HOST=0.0.0.0
PORT=5000
DEBUG=False
LOG_LEVEL=INFO

# File Upload Settings
UPLOAD_FOLDER=/var/lib/fixture-daemon/uploads
MAX_CONTENT_LENGTH=524288000

# Daemon Settings
DAEMON_PID_FILE=/var/run/fixture-daemon.pid
DAEMON_LOG_FILE=/var/log/fixture-daemon.log
DAEMON_WORKING_DIR=/var/lib/fixture-daemon
                </div>
            </div>
        </div>

        <div class="step">
            <h3>Step 4: Initialize Database Schema</h3>
            <p>The application will automatically create the necessary tables when it connects to the database.</p>
            <p>Alternatively, you can manually run the schema file:</p>
            <div class="code">
mysql -u fixture_user -p fixture_manager < database/schema.sql
            </div>
        </div>

        <div class="step">
            <h3>Step 5: Restart the Application</h3>
            <p>After configuring the database, restart the Fixture Manager daemon:</p>
            <div class="code">
# Stop the daemon
./fixture-manager stop

# Start the daemon
./fixture-manager start

# Or restart
./fixture-manager restart
            </div>
        </div>

        <div class="success">
            <strong>✅ Default Admin Account</strong><br>
            Once the database is set up, a default admin account will be created:<br>
            <strong>Username:</strong> admin<br>
            <strong>Password:</strong> admin123<br>
            <em>Please change this password immediately after first login!</em>
        </div>

        <div style="text-align: center; margin-top: 30px;">
            <a href="/" class="btn">🔄 Check Connection</a>
            <a href="/health" class="btn">📊 System Health</a>
        </div>

        <div style="margin-top: 30px; padding-top: 20px; border-top: 1px solid #eee; color: #666; font-size: 14px;">
            <p><strong>Need Help?</strong></p>
            <ul>
                <li>Check the application logs: <code>tail -f /var/log/fixture-daemon.log</code></li>
                <li>Verify MySQL is running: <code>sudo systemctl status mysql</code></li>
                <li>Test database connection: <code>mysql -u fixture_user -p fixture_manager</code></li>
            </ul>
        </div>
    </div>
</body>
</html>