namespace WinFormsApp1
{
    public class MenuBuilder
    {
        private MenuStrip _menu;

        public MenuBuilder(MenuStrip menu)
        {
            _menu = menu;
        }

        public void UpdatePlaylistMenu(List<string> titles, List<string> urls)
        {
            _menu.Items.Clear();

            var playlistMenu = new ToolStripMenuItem("Playlist");

            for (int i = 0; i < titles.Count; i++)
            {
                var item = new ToolStripMenuItem(titles[i]);
                item.Tag = urls[i];

                item.Click += (s, e) =>
                {
                    string url = (string)((ToolStripMenuItem)s).Tag;

                    // 外に通知したいならイベントにする（後述）
                    OnItemClicked?.Invoke(url);
                };

                playlistMenu.DropDownItems.Add(item);
            }

            _menu.Items.Add(playlistMenu);
        }

        public event Action<string> OnItemClicked;
    }
}
