//ライセンス情報はAgeOnフォルダのLISENCEフォルダを参照してください
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Diagnostics;
using mshtml;

using nispi.controlclass;

namespace nispi
{
    class FileMenu
    {
        //ronin
        public ToolStripMenuItemParts mainMenuItemUseRonin;
        public ToolStripMenuItemParts mainMenuItemNotUseRonin;
        //be.2ch.net
        public ToolStripMenuItemParts mainMenuItemUseBe;
        public ToolStripMenuItemParts mainMenuItemNotUseBe;
        //be.2ch.sc
        public ToolStripMenuItemParts mainMenuItemUseSCBe;
        public ToolStripMenuItemParts mainMenuItemNotUseSCBe;


        public ToolStripMenuItemParts mainMenuItemOnLine;
        public ToolStripMenuItemParts mainMenuItemOffLine;
        public ToolStripMenuItemParts mainMenuItemTaskTray;
        public ToolStripMenuItemParts mainMenuItemExit;

        public ToolStripMenuItemParts mainMenuItemReStart;

        public NotifyIcon notifyIcon;

        public static MainForm form = null;

        public FileMenu(ToolStripMenuItemParts menuItem)
        {
            //ronin
            mainMenuItemUseRonin = ToolStripMenuItemPartsManager.Pop();
            mainMenuItemNotUseRonin = ToolStripMenuItemPartsManager.Pop();
            //be.2ch.net
            mainMenuItemUseBe = ToolStripMenuItemPartsManager.Pop();
            mainMenuItemNotUseBe = ToolStripMenuItemPartsManager.Pop();
            //be.2ch.sc
            mainMenuItemUseSCBe = ToolStripMenuItemPartsManager.Pop();
            mainMenuItemNotUseSCBe = ToolStripMenuItemPartsManager.Pop();
            //オンライン／オフライン
            mainMenuItemOnLine = ToolStripMenuItemPartsManager.Pop();
            mainMenuItemOffLine = ToolStripMenuItemPartsManager.Pop();

            mainMenuItemTaskTray = ToolStripMenuItemPartsManager.Pop();
            mainMenuItemExit = ToolStripMenuItemPartsManager.Pop();

            mainMenuItemReStart = ToolStripMenuItemPartsManager.Pop();

            mainMenuItemOnLine.Enabled = false;
            mainMenuItemOffLine.Enabled = true;

            //タスクトレー化
            this.notifyIcon = new NotifyIcon();
            this.notifyIcon.Icon = Resources.icon;
            this.notifyIcon.Visible = true;
            this.notifyIcon.Text = "AgeOn";
            this.notifyIcon.Click += new EventHandler(NotifyIcon_Click);

            //ronin
            mainMenuItemUseRonin.Text = "浪人を使用する(&R)";
            mainMenuItemUseRonin.Click += new EventHandler(mainMenuItemUseRonin_Click);
            mainMenuItemUseRonin.Image = Resources.ronin_login;

            mainMenuItemNotUseRonin.Text = "浪人を使用しない(&E)";
            mainMenuItemNotUseRonin.Click += new EventHandler(mainMenuItemNotUseRonin_Click);
            mainMenuItemNotUseRonin.Image = Resources.ronin_logout;

            //be.2ch.net
            mainMenuItemUseBe.Text = "Beを使用する(&B)";
            mainMenuItemUseBe.Click += new EventHandler(mainMenuItemUseBe_Click);
            mainMenuItemUseBe.Image = Resources.ronin_login;

            mainMenuItemNotUseBe.Text = "Beを使用しない(&V)";
            mainMenuItemNotUseBe.Click += new EventHandler(mainMenuItemNotUseBe_Click);
            mainMenuItemNotUseBe.Image = Resources.ronin_logout;

            //be.2ch.sc
            mainMenuItemUseSCBe.Text = "Be(SC)を使用する(&S)";
            mainMenuItemUseSCBe.Click += new EventHandler(mainMenuItemUseSCBe_Click);
            mainMenuItemUseSCBe.Image = Resources.ronin_login;

            mainMenuItemNotUseSCBe.Text = "Be(SC)を使用しない(&A)";
            mainMenuItemNotUseSCBe.Click += new EventHandler(mainMenuItemNotUseSCBe_Click);
            mainMenuItemNotUseSCBe.Image = Resources.ronin_logout;

            //on/off
            mainMenuItemOnLine.Text = "オンライン(&W)";
            mainMenuItemOnLine.Click += new EventHandler(menuItemOnLine_Click);
            mainMenuItemOnLine.Image = Resources.online;

            mainMenuItemOffLine.Text = "オフライン(&F)";
            mainMenuItemOffLine.Click += new EventHandler(menuItemOffLine_Click);
            mainMenuItemOffLine.Image = Resources.offline;

            mainMenuItemTaskTray.Text = "タスクトレイ化(&T)";
            mainMenuItemTaskTray.Click += new EventHandler(menuItemTaskTray_Click);

            mainMenuItemExit.Text = "終了する(&Q)";
            mainMenuItemExit.Image = Resources.CaptionClose;
            mainMenuItemExit.Click += new EventHandler(menuItemExit_Click);

            mainMenuItemReStart.Text = "再起動する(&X)";
            mainMenuItemReStart.Click += new EventHandler(menuItemReStart_Click);

            menuItem.DropDownItemsAdd(mainMenuItemUseRonin);
            menuItem.DropDownItemsAdd(mainMenuItemNotUseRonin);
            menuItem.DropDownItemsAdd("-");
            menuItem.DropDownItemsAdd(mainMenuItemUseBe);
            menuItem.DropDownItemsAdd(mainMenuItemNotUseBe);
            menuItem.DropDownItemsAdd("-");
            menuItem.DropDownItemsAdd(mainMenuItemUseSCBe);
            menuItem.DropDownItemsAdd(mainMenuItemNotUseSCBe);
            menuItem.DropDownItemsAdd("-");
            menuItem.DropDownItemsAdd(mainMenuItemOnLine);
            menuItem.DropDownItemsAdd(mainMenuItemOffLine);
            menuItem.DropDownItemsAdd("-");
            menuItem.DropDownItemsAdd(mainMenuItemTaskTray);
            menuItem.DropDownItemsAdd(mainMenuItemReStart);
            menuItem.DropDownItemsAdd(mainMenuItemExit);
        }

        //ronin
        private void mainMenuItemUseRonin_Click(object sender, EventArgs e)
        {
            Ronin ronin = new Ronin();
            if (ronin.LogIn() == true)
            {
                //ログイン成功ならメニューを書き換える
                mainMenuItemUseRonin.Enabled = false;
                mainMenuItemNotUseRonin.Enabled = true;
                Const.form.roninToolStripStatusLabel.Text = "Ronin：ログイン　　　";
            }
            else
                Const.form.roninToolStripStatusLabel.Text = "Ronin：ログオフ　　　";
        }
        private void mainMenuItemNotUseRonin_Click(object sender, EventArgs e)
        {
            Ronin ronin = new Ronin();
            ronin.LogOut();
            //メニューを書き換える
            mainMenuItemUseRonin.Enabled = true;
            mainMenuItemNotUseRonin.Enabled = false;
            Const.form.roninToolStripStatusLabel.Text = "Ronin：ログオフ　　　";
        }
        //be.2ch.net
        private void mainMenuItemUseBe_Click(object sender, EventArgs e)
        {
            Be be = new Be();
            if (be.GetBeCookie() == true)
            {
                //ログイン成功ならメニューを書き換える
                mainMenuItemUseBe.Enabled = false;
                mainMenuItemNotUseBe.Enabled = true;
                Const.form.be2chToolStripStatusLabel.Text = "2chBe：ログイン　　　";
            }
            else
                Const.form.be2chToolStripStatusLabel.Text = "2chBe：ログオフ　　　";
        }
        private void mainMenuItemNotUseBe_Click(object sender, EventArgs e)
        {
            Be be = new Be();
            be.LogOutBe();
            //メニューを書き換える
            mainMenuItemUseBe.Enabled = true;
            mainMenuItemNotUseBe.Enabled = false;
            Const.form.be2chToolStripStatusLabel.Text = "2chBe：ログオフ　　　";
        }
        //be.2ch.sc
        private void mainMenuItemUseSCBe_Click(object sender, EventArgs e)
        {
            Be be = new Be();
            if (be.GetSCBeCookie() == true)
            {
                //ログイン成功ならメニューを書き換える
                mainMenuItemUseSCBe.Enabled = false;
                mainMenuItemNotUseSCBe.Enabled = true;
                Const.form.beSCToolStripStatusLabel.Text = "2chBe(SC)：ログイン　　　";
            }
            else
                Const.form.beSCToolStripStatusLabel.Text = "2chBe(SC)：ログオフ　　　";
        }
        private void mainMenuItemNotUseSCBe_Click(object sender, EventArgs e)
        {
            Be be = new Be();
            be.LogOutSCBe();
            //メニューを書き換える
            mainMenuItemUseSCBe.Enabled = true;
            mainMenuItemNotUseSCBe.Enabled = false;
            Const.form.beSCToolStripStatusLabel.Text = "2chBe(SC)：ログオフ　　　";
        }

        //on/off
        private void menuItemOnLine_Click(object sender, EventArgs e)
        {
            Const.OnLine = true;
            mainMenuItemOffLine.Enabled = true;
            mainMenuItemOnLine.Enabled = false;
            Const.form.onLineToolStripStatusLabel.Text = "状態：オンライン　　　";
        }
        private void menuItemOffLine_Click(object sender, EventArgs e)
        {
            Const.OnLine = false;
            mainMenuItemOffLine.Enabled = false;
            mainMenuItemOnLine.Enabled = true;
            Const.form.onLineToolStripStatusLabel.Text = "状態：オフライン　　　";
        }
        //タスクトレー
        private void menuItemTaskTray_Click(object sender, EventArgs e)
        {
            Const.form.mainForm.Hide();
            Const.form.mapMainForm.mapMainForm.Hide();
        }

        private void NotifyIcon_Click(object sender, EventArgs e)
        {
            Const.form.mainForm.Show();
            Const.form.mapMainForm.mapMainForm.Show();
        }

        private void menuItemReStart_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("ExitAndRun.exe");
            this.notifyIcon.Dispose();
        }

        private void menuItemExit_Click(object sender, EventArgs e)
        {
            this.notifyIcon.Dispose();
            Const.form.mapMainForm.mapMainForm.Close();
            Const.form.mainForm.Close();
        }
    }
}