// Adrians Zemturis
// Grupa: 110
// PR: 6.3
// Kompilators: Visual Studio Community 2022

using System;
using System.Collections.Generic;

class HelloWorld {
    static bool running = true;
    static List<string> reserver_str = new List<string>();
    static int[][] seats = new int[][]
    {
        new int[] { 0, 0, 0, 0, 0 },                // 1. rinda (5 vietas)
        new int[] { 0, 0, 0, 0, 0, 0, 0 },          // 2. rinda (7 vietas)
        new int[] { 0, 0, 0, 0},                    // 3. rinda (4 vietas)
        new int[] { 0, 0, 0, 0, 0, 0},              // 4. rinda (6 vietas)
        new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}   // 5. rinda (10 vietas)
        
    };
    
    static string GetReserveSymbol(int reserve_num) {
        switch (reserve_num) {
            case 0:
                return " ";
            case 1:
                return "X";
            default:
                return "?";
        }
    }
    
    static void ParaditZali(int[][] zale) {
        Console.Clear();
        for (int y = 0; y < zale.Length; y++) {
            for (int x = 0; x < zale[y].Length; x++) {
                string R_symbol = GetReserveSymbol(zale[y][x]);
                if (R_symbol == " ") {
                    R_symbol = $"{x},{y}";
                }
                Console.Write($"[{R_symbol}]  ");
            }
            Console.WriteLine();
        }
    }
    
    static bool ReservetVietu(int[][] zale, List<string>reser_str) {
        Console.Clear();
        
        Console.Write("Ievadiet rindu: ");
        int user_X = Convert.ToInt32(Console.ReadLine());
        Console.Write("Ievadiet kolonu: ");
        int user_Y = Convert.ToInt32(Console.ReadLine());
        
        if (user_Y < zale.Length && user_Y >= 0) {
            var rinda = zale[user_Y];
            if (user_X < rinda.Length && user_X >= 0) {
                if (zale[user_Y][user_X] == 0) {
                    zale[user_Y][user_X] = 1;
                    reser_str.Add($"Kolona {user_Y}\nRinda: {user_X}");
                    return true;
                }
            }
        }
        return false;
    }
    
    static void ParaditReservacijasSarakstu(List<string>reser_str) {
        Console.Clear();
        for (int i = 0; i < reser_str.Count; i++) {
            Console.Write($"Rezervacija: {i}\n");
            Console.Write(reser_str[i]);
            Console.WriteLine("\n");
        }
    }
    
    static void ApstradatIzveli() {
        Console.Clear();
        Console.WriteLine("Paradit zali(1)\nRezervet vietu(2)\nParadit rezervacijas sarakstu(3)\nIziet(4)");
        string inp = Console.ReadLine();
        int user_choice = Convert.ToInt32(inp);
        
        switch (user_choice) {
            case 1:
                ParaditZali(seats);
                break;
            case 2:
                bool success = ReservetVietu(seats, reserver_str);
                if (success == false) {
                    Console.WriteLine("Nepareizi ievaditi dati!");
                } else {
                    Console.WriteLine("Veiksmigi rezerejat vietu!");
                }
                break;
            case 3:
                ParaditReservacijasSarakstu(reserver_str);
                break;
            case 4:
                running = false;
                break;
            default:
                break;
        }
    }
    
    static void Main() {
        
        while (running) {
            ApstradatIzveli();
            Console.ReadKey();
        }
    }
}
