using System;
using System.Text;
using System.Windows.Forms;

namespace SepehrFlightApiSampleClient.Availability.WinForms.SearchByRouteAndDate
{
    public partial class FlightClassExtraInfoUserControl : UserControl
    {
        public FlightClassExtraInfoUserControl()
        {
            InitializeComponent();
        }

        public void SetFlightClass(
            ViewModels.Flight flightViewModel,
            ViewModels.FlightClass flightClassViewModel)
        {
            //adult
            var adultUserControl = new AgeTypeUserControl_Charter();
            adultUserControl.Location = new System.Drawing.Point(6, 6);
            adultUserControl.Dock = DockStyle.Fill;

            adultUserControl.SetData(
                flightClassViewModel.Adult_Fare,
                flightClassViewModel.AdultFreeBaggage);

            tbgAdult.Controls.Clear();
            tbgAdult.Controls.Add(adultUserControl);

            //child
            var childUserControl = new AgeTypeUserControl_Charter();
            childUserControl.Location = new System.Drawing.Point(6, 6);
            childUserControl.Dock = DockStyle.Fill;

            childUserControl.SetData(
                flightClassViewModel.Child_Fare,
                flightClassViewModel.ChildFreeBaggage);

            tbgChild.Controls.Clear();
            tbgChild.Controls.Add(childUserControl);

            //infant
            var infantUserControl = new AgeTypeUserControl_Charter();
            infantUserControl.Location = new System.Drawing.Point(6, 6);
            infantUserControl.Dock = DockStyle.Fill;

            infantUserControl.SetData(
                flightClassViewModel.Infant_Fare,
                flightClassViewModel.InfantFreeBaggage);

            tbgInfant.Controls.Clear();
            tbgInfant.Controls.Add(infantUserControl);


            txtCancelationPolicy.Text = flightClassViewModel.CancelationPolicyList;

            txtNationalities.Text = GetNationalitiesText(flightViewModel);
        }

        private string GetNationalitiesText(ViewModels.Flight flightViewModel)
        {
            var sb = new StringBuilder();

            sb.AppendLine("PermittedNationalityList:");
            sb.AppendLine(string.Join(Environment.NewLine, flightViewModel.PermittedNationalityList));
            sb.AppendLine();

            sb.AppendLine("ProhibitedNationalityList:");
            sb.AppendLine(string.Join(Environment.NewLine, flightViewModel.ProhibitedNationalityList));
            sb.AppendLine();

            return sb.ToString();
        }
    }
}
