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

namespace OsaGateway
{
    public partial class NewCall : Form
    {
        string[] items;
        Thread thread;

        public NewCall()
        {
            InitializeComponent();
            Contacts.Choosed += new Contacts.ContactsFormHandler(Contacts_Choosed);
        }
        public NewCall(string phoneNumber)
        {
            InitializeComponent();
            Contacts.Choosed += new Contacts.ContactsFormHandler(Contacts_Choosed);
            this.mtbPhoneNumber.Text = phoneNumber + "; ";
        }

        void Contacts_Choosed(List<Contact> contacts)
        {
            foreach (Contact item in contacts)
            {
                mtbPhoneNumber.Text += item.Phone + "; ";
            }
        }
        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Contacts c = new Contacts(true);
            c.Show();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            items = mtbPhoneNumber.Text.Replace(" ", string.Empty).Split(new string[] { ";", ",", ".", "/", "|" }, StringSplitOptions.RemoveEmptyEntries);
            string[] items2 = items;
            if (items.Count() <= 0)
                mtbPhoneNumber.BackColor = Color.Orange;
            else
            {
                thread = new Thread(new ThreadStart(RunCall));
                thread.Start();
                foreach (string item in items2)
                    Calls.Add(item, TrafficType.Outgoing);
                this.Hide();
                this.Close();
            }
        }

        private void RunCall()
        {
            foreach (string item in items)
                Program.gateway.RingThePhone(item, false);
        }
    }
}
