using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Banker
{
    public partial class Form2 : Form
    {
        private Customer currentCustomer;

        public Form2(Customer customer)
        {
            InitializeComponent();
            currentCustomer = customer;

            label2.Text = "Your balance is " + currentCustomer.Balance.ToString("C") + " INR.";
            label3.Text = "Password: " + currentCustomer.Password;
            label6.Text = "Username: " + currentCustomer.Username;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            currentCustomer.Password = textBox1.Text;
            MessageBox.Show("Password changed successfully!");
            label3.Text = "Password: " + currentCustomer.Password; 
        }

        private void label2_Click(object sender, EventArgs e)
        {
        }

        private void label3_Click(object sender, EventArgs e)
        {
            label3.Text = "Password: " + currentCustomer.Password;
        }

        private void btnTransferMoney_Click(object sender, EventArgs e)
        {
            decimal transferAmount;
            if (decimal.TryParse(textBoxAmount.Text, out transferAmount))
            {
                if (currentCustomer.Balance >= transferAmount)
                {
                    currentCustomer.Balance -= transferAmount;

                    string transactionDetails = "Transferred " + transferAmount.ToString("C") + " INR to " + textBoxBeneficiary.Text;

                    currentCustomer.AddTransaction(transactionDetails);

                    label2.Text = "Your balance is " + currentCustomer.Balance.ToString("C") + " INR.";

                    textBoxAmount.Clear();
                    textBoxBeneficiary.Clear();
                    listBoxTransactions.Items.Clear();
                    foreach (var transaction in currentCustomer.LastTransactions)
                    {
                        listBoxTransactions.Items.Add(transaction);
                    }

                    MessageBox.Show(transactionDetails);
                }
                else
                {
                    MessageBox.Show("Insufficient balance for this transfer.");
                }
            }
            else
            {
                MessageBox.Show("Please enter a valid amount.");
            }
        }

        private void label12_Click(object sender, EventArgs e)
        {
            string currentTime = DateTime.Now.ToString("HH:mm:ss");

            label12.Text = "Last Accessed Time: " + currentTime;
        }

        private void label13_Click(object sender, EventArgs e)
        {
            string currentDate = DateTime.Now.ToString("yyyy-MM-dd");

            label13.Text = "Last Accessed Date: " + currentDate;
        }
    }
}
