using System;
using System.Windows.Forms;

namespace AgencySystem
{
    public partial class ContactPage : UserControl
    {
        private static ContactPage _instance;
        public static ContactPage Instance
        {
            get
            {
                if (_instance == null)
                    _instance = new ContactPage();
                return _instance;
            }
        }
        public ContactPage()
        {
            InitializeComponent();
            DefaultScreen.initializeHeading(ContactHeading);
            DefaultScreen.initializePanel(ContactPagePanel);
            ContactHeading.Text = Properties.Resources.ContactHeading;
            SelectStoreToViewDetailsLabel.Text = Properties.Resources.SelectStoreToViewDetailsLabel;
            mapBrowser.Visible = false;

            GenerateComboBox();
        }

        private void GenerateComboBox()
        {
            OurStoresComboBox.Items.Clear();

            /*
                 CONSISTS CODE FOR TESTING
            */
            if (TestDataWithoutDB.testSchemaWithoutDBMark == false)
            {
                OurStoresLayout.OurStores[] allStores = null;
                allStores = OurStoresLayout.GetOurStoresFromDB();

                if(allStores!=null)
                { 
                    foreach (OurStoresLayout.OurStores store in allStores)
                    {
                        string value=null;
                        value += store.City + ", " + store.StreetName + " " + store.StreetNumber;
                        OurStoresComboBox.Items.Add(value);
                    }
                }
            }
            else{
                OurStoresComboBox.Items.Add(TestDataWithoutDB.firstStoreCity+", "+ TestDataWithoutDB.firstStoreStreetName+" "+ TestDataWithoutDB.firstStoreStreetNumber);
                OurStoresComboBox.Items.Add(TestDataWithoutDB.secondStoreCity + ", " + TestDataWithoutDB.secondStoreStreetName + " " + TestDataWithoutDB.secondStoreStreetNumber);
            }
        }

        private void OurStoresComboBox_SelectedValueChanged(object sender, EventArgs e)
        {
            mapBrowser.Visible = true;
            string embeddedpage = @"
            <html>
                <body>
                    <iframe type='text/html' width='440' height='210' 
                        src='https://www.google.com/maps/embed/v1/place?key=AIzaSyDMxQ0lwTKcxqsJtkUbhRtFtMGLDjEZoYE&q=" + OurStoresComboBox.Text + @"' frameborder='0'>
                    </iframe>
                </body>
            </html>";

            mapBrowser.DocumentText = embeddedpage;
        }
    }
}
