#include <iostream>
#include <vector>
using namespace std;

class Book {
public:
    string id, name;
    bool issue = false;

    Book(string i, string n) {
        id = i;
        name = n;
    }
};

vector<Book> b = {
    {"B001","C++"},
    {"B002","Java"},
    {"B003","Python"}
};

#define RED "\033[31m"
#define GREEN "\033[32m"
#define BLUE "\033[34m"
#define CYAN "\033[36m"
#define YELLOW "\033[33m"
#define RESET "\033[0m"

int main() {

    string u, p, id;
    int ch;

    // COLORFUL LOGIN PAGE
    cout << CYAN;
    cout << "\n****************************************\n";
    cout << "*      LIBRARY MANAGEMENT SYSTEM       *\n";
    cout << "****************************************\n";
    cout << RESET;

    cout << BLUE << "\n========== LOGIN PAGE ==========\n" << RESET;

    cout << YELLOW << "Username : " << RESET;
    cin >> u;

    cout << YELLOW << "Password : " << RESET;
    cin >> p;

    if(u != "admin" || p != "1234") {
        cout << RED << "\nWrong Login!\n" << RESET;
        return 0;
    }

    cout << GREEN << "\nLogin Successful!\n" << RESET;

    // MENU
    cout << CYAN;
    cout << "\n1. View Books";
    cout << "\n2. Issue Book";
    cout << "\n3. Return Book";
    cout << "\n4. Exit\n";
    cout << RESET;

    while(true) {

        cout << "\nEnter Choice: ";
        cin >> ch;

        if(ch == 1) {

            cout << "\n--- BOOKS ---\n";

            for(auto x : b) {
                cout << x.id << " - " << x.name;

                if(x.issue)
                    cout << RED << " (Issued)";

                cout << RESET << endl;
            }
        }

        else if(ch == 2) {

            cout << "Enter Book ID: ";
            cin >> id;

            for(auto &x : b) {
                if(x.id == id) {
                    x.issue = true;
                    cout << GREEN << "Book Issued!\n" << RESET;
                }
            }
        }

        else if(ch == 3) {

            cout << "Enter Book ID: ";
            cin >> id;

            for(auto &x : b) {
                if(x.id == id) {
                    x.issue = false;
                    cout << GREEN << "Book Returned!\n" << RESET;
                }
            }
        }

        else if(ch == 4) {
            cout << RED << "Good Bye!\n" << RESET;
            break;
        }

        else {
            cout << RED << "Invalid Choice!\n" << RESET;
        }
    }

    return 0;
}
