using System.IO;
using Utils;
namespace DualScreenDemo
{
    public partial class PrimaryForm
    {
        private Button categorySearchButton;
        private Bitmap categorySearchNormalBackground; 
        private Bitmap categorySearchActiveBackground; 

        private Button loveDuetButton;
        private Bitmap loveDuetNormalBackground;
        private Bitmap loveDuetActiveBackground;
        private Button talentShowButton;
        private Bitmap talentShowNormalBackground;
        private Bitmap talentShowActiveBackground;
        private Button medleyDanceButton;
        private Bitmap medleyDanceNormalBackground;
        private Bitmap medleyDanceActiveBackground;
        private Button ninetiesButton;
        private Bitmap ninetiesNormalBackground;
        private Bitmap ninetiesActiveBackground;
        private Button nostalgicSongsButton;
        private Bitmap nostalgicSongsNormalBackground;
        private Bitmap nostalgicSongsActiveBackground;
        private Button chinaSongsButton;
        private Bitmap chinaNormalBackground;
        private Bitmap chinaActiveBackground;
        private Button vietnameseSongsButton;
        private Bitmap vietnameseNormalBackground;
        private Bitmap vietnameseActiveBackground;

        private void ResetCatBtnStatus() 
        {

            loveDuetButton.BackgroundImage = loveDuetNormalBackground;
            talentShowButton.BackgroundImage = talentShowNormalBackground;
            medleyDanceButton.BackgroundImage = medleyDanceNormalBackground;
            ninetiesButton.BackgroundImage = ninetiesNormalBackground;
            nostalgicSongsButton.BackgroundImage = nostalgicSongsNormalBackground;
            chinaSongsButton.BackgroundImage = chinaNormalBackground;
            vietnameseSongsButton.BackgroundImage = vietnameseNormalBackground;
        }


        //private void InitializeButtonsForCategorySearch()
        //{
        //    var data=LoadConfigData();

        //    categorySearchNormalBackground = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別上方_類別查詢(未按).png"));
        //    categorySearchActiveBackground = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別上方_類別查詢(已按).png"));

        //    categorySearchButton = new Button { Text = "" };
        //    categorySearchButton.Name = "categorySearchButton";
        //    ConfigureButton(categorySearchButton, 731, 97, 99, 99,
        //         categorySearchNormalBackground,
        //         categorySearchActiveBackground,
        //         categorySearchActiveBackground,
        //         CategorySearchButton_Click);

        //}

        private void InitializeCategorySearchButtons()
        {

            loveDuetNormalBackground = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\2.次類別\\7.類別查詢_男女情歌(未按).png"));
            talentShowNormalBackground = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\2.次類別\\7.類別查詢_選秀節目(未按).png"));
            medleyDanceNormalBackground = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\2.次類別\\7.類別查詢_串燒舞曲(未按).png"));
            ninetiesNormalBackground = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\2.次類別\\7.類別查詢_90年代(未按).png"));
            nostalgicSongsNormalBackground = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\2.次類別\\7.類別查詢_懷舊老歌(未按).png"));
            chinaNormalBackground = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\2.次類別\\7.類別查詢_中國大陸(未按).png"));
            vietnameseNormalBackground= new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\2.次類別\\7.類別查詢_越南歌曲(未按).png"));

            loveDuetActiveBackground = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\2.次類別\\7.類別查詢_男女情歌(已按).png"));
            talentShowActiveBackground = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\2.次類別\\7.類別查詢_選秀節目(已按).png"));
            medleyDanceActiveBackground = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\2.次類別\\7.類別查詢_串燒舞曲(已按).png"));
            ninetiesActiveBackground = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\2.次類別\\7.類別查詢_90年代(已按).png"));
            nostalgicSongsActiveBackground = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\2.次類別\\7.類別查詢_懷舊老歌(已按).png"));
            chinaActiveBackground = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\2.次類別\\7.類別查詢_中國大陸(已按).png"));
            vietnameseActiveBackground= new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\2.次類別\\7.類別查詢_越南歌曲(已按).png"));

            loveDuetButton = new Button { Text = "", Visible = false };
            ConfigureButton(loveDuetButton, 1197, 225, 225, 50,
                 loveDuetNormalBackground,
                 loveDuetNormalBackground,
                 loveDuetActiveBackground,
                 LoveDuetButton_Click);

            loveDuetButton.MouseLeave += (sender, e) => loveDuetButton.BackgroundImage = loveDuetActiveBackground;


            talentShowButton = new Button { Text = "", Visible = false };
            ConfigureButton(talentShowButton, 1197, 280, 225, 50,
                 talentShowNormalBackground,
                 talentShowNormalBackground,
                 talentShowNormalBackground,
                 TalentShowButton_Click);

            talentShowButton.MouseLeave += (sender, e) => talentShowButton.BackgroundImage = talentShowActiveBackground;


            medleyDanceButton = new Button { Text = "", Visible = false };
            ConfigureButton(medleyDanceButton, 1197, 335, 225, 50,
                     medleyDanceNormalBackground,
                     medleyDanceNormalBackground,
                     medleyDanceNormalBackground,
                     MedleyDanceButton_Click);

            medleyDanceButton.MouseLeave += (sender, e) => medleyDanceButton.BackgroundImage = medleyDanceActiveBackground;


            ninetiesButton = new Button { Text = "", Visible = false };
            ConfigureButton(ninetiesButton, 1197, 390, 225, 50,
                     ninetiesNormalBackground,
                     ninetiesNormalBackground,
                     ninetiesNormalBackground,
                     NinetiesButton_Click);

            ninetiesButton.MouseLeave += (sender, e) => ninetiesButton.BackgroundImage = ninetiesActiveBackground;


            nostalgicSongsButton = new Button { Text = "", Visible = false };
            ConfigureButton(nostalgicSongsButton, 1197, 445, 225, 50,
                     nostalgicSongsNormalBackground,
                     nostalgicSongsNormalBackground,
                     nostalgicSongsNormalBackground,
                     NostalgicSongsButton_Click);

            nostalgicSongsButton.MouseLeave += (sender, e) => nostalgicSongsButton.BackgroundImage = nostalgicSongsActiveBackground;


            chinaSongsButton = new Button { Text = "", Visible = false };
            ConfigureButton(chinaSongsButton, 1197, 500, 225, 50,
                     chinaNormalBackground,
                     chinaNormalBackground,
                     chinaNormalBackground,
                     ChinaSongsButton_Click);

            chinaSongsButton.MouseLeave += (sender, e) => chinaSongsButton.BackgroundImage = chinaActiveBackground;


            vietnameseSongsButton = new Button { Text = "", Visible = false };
            ConfigureButton(vietnameseSongsButton, 1197, 555, 225, 50,
                     vietnameseNormalBackground,
                     vietnameseNormalBackground,
                     vietnameseNormalBackground,
                     VietnameseSongsButton_Click);

            vietnameseSongsButton.MouseLeave += (sender, e) => vietnameseSongsButton.BackgroundImage = vietnameseActiveBackground;

        }

        private void CategorySearchButton_Click(object sender, EventArgs e)
        {
            ResetPrimaryBtnStatus();

            //categorySearchButton.BackgroundImage = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\1.主類別\\主類別上方_類別查詢(已按).png"));
            categorySearchButton.BackgroundImage = categorySearchActiveBackground;
            isOnOrderedSongsPage = false;

            ResetCatBtnStatus();

            loveDuetButton.BackgroundImage = loveDuetActiveBackground;
 
            /*loveDuetSongs = allSongs.Where(song => song.SongGenre.Contains("A1"))
                                .OrderByDescending(song => song.Plays) 
                                .ToList();*/
            /* 清空搜尋欄 */
            ResetinputBox();
            string query = SetQueryforSQL("A1"); 
            var loveDuetSongs = SearchSongs_Mysql(query);
            currentPage = 0; 
            totalPages = (int)Math.Ceiling((double)loveDuetSongs.Count / itemsPerPage);

            
            multiPagePanel.currentPageIndex = 0;
            multiPagePanel.LoadSongs(loveDuetSongs);

            
            SetHotSongButtonsVisibility(false);
            SetNewSongButtonsVisibility(false);
            SetSingerSearchButtonsVisibility(false);
            SetSongSearchButtonsVisibility(false);
            SetPictureBoxLanguageButtonsVisibility(false);
            SetGroupButtonsVisibility(false);
            SetZhuYinSingersAndButtonsVisibility(false);
            SetZhuYinSongsAndButtonsVisibility(false);
            SetEnglishSingersAndButtonsVisibility(false);
            SetEnglishSongsAndButtonsVisibility(false);
            SetPinYinSingersAndButtonsVisibility(false);
            SetPinYinSongsAndButtonsVisibility(false);
            SetPictureBoxToggleLightAndButtonsVisibility(false);
            SetPictureBoxSceneSoundEffectsAndButtonsVisibility(false);
            SetPictureBoxCategoryAndButtonsVisibility(true);

            
            if (pictureBoxQRCode != null)
            {
                pictureBoxQRCode.Visible = false;
                closeQRCodeButton.Visible = false;
            }
        }
        
        private void TogglePictureBoxCategoryButtonsVisibility()
        {
            
            bool areButtonsVisible = loveDuetButton.Visible; 

            
            SetPictureBoxCategoryAndButtonsVisibility(!areButtonsVisible);
        }
        
        private void SetPictureBoxCategoryAndButtonsVisibility(bool isVisible)
        {   
            loveDuetButton.Visible = isVisible;
            loveDuetButton.BringToFront();
            
            talentShowButton.Visible = isVisible;
            talentShowButton.BringToFront();
            
            medleyDanceButton.Visible = isVisible;
            medleyDanceButton.BringToFront();
            
            ninetiesButton.Visible = isVisible;
            ninetiesButton.BringToFront();
            
            nostalgicSongsButton.Visible = isVisible;
            nostalgicSongsButton.BringToFront();
            
            chinaSongsButton.Visible = isVisible;
            chinaSongsButton.BringToFront();

            vietnameseSongsButton.Visible = isVisible;
            vietnameseSongsButton.BringToFront();

            
            
        }

        private string SetQueryforSQL(string contains){
            string query = $"SELECT * FROM song_library_cache WHERE song_category LIKE '%{contains}%' ORDER BY `song_id` DESC;";
            return query;
        }
    }
}