/*****************************************************************************
Open Source MIT License

Copyright (c) 2017 Matthew Ahmed

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*****************************************************************************/

// SelectDlg.h: interface for the CSelectDlg class.
//
//////////////////////////////////////////////////////////////////////

#pragma once

#include "ZWinDlg.h"
#include "wmp.h" // For member CComPtr< > declarations below

#define WMU_LOADLIST WMU0 + 123
//#define MAX_PLAYLISTS_LB_IX 4095 // Win allows 32K, but never need this much
#define MAX_SELDLG_LB_ITEMS   8192 // Win allows 32K, but never need this much

// 3.0 REPLACE WITH EQUIVALENT CONSTANTS FROM SongsSelection.h
// Values for uRetGroupType
#define GROUP_TYPE_INVALID      0
#define GROUP_TYPE_ALL          1
//#define GROUP_TYPE_NEW          2
//#define GROUP_TYPE_PLAYLIST     3
#define GROUP_TYPE_LBSEL        2  

//#define UTIMERID_BLINK          1029

class CSongsSelection;


//Never needed?// BOOL SelectDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);

class CSelectDlg : public ZDlg  
{
public:
  // Constructor for adding playlist or song group to list
  CSelectDlg(HINSTANCE hInst, CSettings * pSet,
             LPCTSTR sCapt1, LPCTSTR sCapt2, ZWin * pOwner,
             IWMPPlaylistCollection * pPlaylistColl,
             IWMPPlaylistArray *  pPlaylistArr,
             IWMPMediaCollection * pMediaCollection,
             CSongsSelection * pSongSel = NULL);

	~CSelectDlg();
	BOOL OwnProc(HWND hDlg, UINT uMsg, WPARAM wP, LPARAM lP);

  // Public for parent dialog to read after OK
  UINT uRetGroupType; // 3.0 keep, but change values sent
//  UINT uRetIxOrDays;  // 3.0 remove
  INT nRetArrReps[6]; // Counts per star rating, or same count all, or exclusion

  CSongsSelection * GetAndClaimSongsSelection();

protected:
  INT m_nArrLbIxPlayArrIx[MAX_SELDLG_LB_ITEMS]; // 3.0 replaces m_nArrLbStaticIxPlayArrIx
  CSongsSelection * m_pSongsSel;
  BOOL m_bSongsSelClaimed;
  LPCTSTR scPrefixGenre;
  LPCTSTR scPrefixPlist;
  INT nRetAgeLimit; // New songs only. Return 0 for no age limit
  BOOL bRetDedupSongs;
  INT GetWmpPlistArrIxForLbIx(INT nLbIx);

	CSettings * ini;

  // These arrays ix = 0 is All songs same repititions; 1-5 for ratings,
  HWND m_haSpins[6];
  HWND m_haEds[6];

  void OnFrequencyRadioButton();
  void OnNotifySpin(LPNMUPDOWN pud);
  void OnEdReps(WPARAM wP, LPARAM lP);
  void InitRepsSpinEdit();
  BOOL m_bEdChangeBySpinner;

  void OnListBox(WPARAM wP, LPARAM lP);

  void ResetLbForRbAllSongs(); // All that's still used from ResetLbForRb
  BOOL m_bListsStarted; // Not redundant !m_bIsSelect, reset p show window
  BOOL m_b1stListboxLoad;

  // In Select Dlg but not IDD_FREQUENCY
  HWND m_hDaysSpin;
  HWND m_hDaysEd;
  BOOL Mon_DD_YYYY_n_days_ago(INT nDaysAgo, LPTSTR sDate);
  BOOL SetNewSongsDateText(INT nDaysAgo);
  HWND m_hDaysTxt;

  HWND m_hLbSongGroups; // 3.0 also genres with the playlists

  INT ListBoxAppendGenres(); // 3.0 added
  INT ListBoxAppendPlistsFiltered(); // 3.0 renamed & return INT
  INT ListBoxAppendPlistsNoFilter(); // 3.0 renamed & return INT
  INT ListBoxAppendPlaylists(); // 3.0 added; calls Filtered/NoFilter per ini
//  void OnCheckBoxNoFilter();
  void LoadListBox(); // 3.0 added. Wrapper for above functions


  CComPtr<IWMPPlaylistCollection> m_cpWmpPlaylistColl;
  CComPtr<IWMPPlaylistArray> m_cpWmpPlaylistArr;
  // For filtering auto playlists user only
  CComPtr<IWMPMediaCollection> m_cpWmpAllMedia;

	BOOL OnInitDialog();
	void OnOk();
  HANDLE m_hnImgStars;
  RECT m_rcImgStars;
  void OnWmPaint();
};

