using System;
using System.Windows.Forms;
using SepehrFlightApiSampleClient.Booking.WinForms.Book.InMemoryDatabase.BookedPnrs.Model;
using SepehrFlightApiSampleClient.Booking.WinForms.Book.InMemoryDatabase.BookedPnrs.Repository;
using SepehrFlightApiSampleClient.Refund.WinForms;

namespace SepehrFlightApiSampleClient.Booking.WinForms.Book
{
    public partial class BookedPnrForm : Form
    {
        private readonly MainForm _mainForm;
        private readonly RetrieveBookingForm _retrieveBookingForm;

        public BookedPnrForm(
            MainForm mainForm,
            RetrieveBookingForm retrieveBookingForm)
        {
            _mainForm = mainForm;
            _retrieveBookingForm = retrieveBookingForm;
            InitializeComponent();

            dgvPendingRequests.AutoGenerateColumns = true;
        }

        public void DataBindGrid()
        {
            bnsBookedPnrs = new BindingSource();
            bnsBookedPnrs.DataSource = BookedPnrRepository.GetAll();
            dgvPendingRequests.DataSource = bnsBookedPnrs;
        }

        private void BookedPnrForm_Load(object sender, EventArgs e)
        {
            DataBindGrid();
        }

        private void btnRefund_Click(object sender, EventArgs e)
        {
            var currentItem = (BookedPnr)bnsBookedPnrs.Current;

            if (currentItem == null) return;

            _retrieveBookingForm.txtPnr.Text = currentItem.Pnr;
            _mainForm.tabControlMain.SelectedTab = _mainForm.tbgRefund;
            _mainForm.tabControlRefund.SelectedTab = _mainForm.tbgRefundRetrievePnr;
        }
    }
}
