#pragma once
#include "../__INCLUDE/LvSTileViewAdapterHandle.hpp"

class CNodeAdapter : public LvAdapterHandle
{
public:
	CNodeAdapter(STileView* pOwner) : LvAdapterHandle(pOwner)
		, m_funBtnDel(&CNodeAdapter::OnEventDelBtn, this)
		, m_callBackItemClick(nullptr)
		, m_callBackBtnClick(nullptr)
		, m_count(0)
		, m_callshowview(nullptr)
	{
		m_seleset = true;
	}
	~CNodeAdapter()
	{

	}

	virtual SStringT GetColumnName(int iCol) const
	{
		return L"col_nick";
	}

	void SetItemClickCallBack(std::function<void(int)> fun)
	{
		m_callBackItemClick = fun;
	}
	void SetBtnClickCallBack(std::function<void(int)> fun)
	{
		m_callBackBtnClick = fun;
	}

	void SetCount(int count) {
		m_count = count;
		notifyDataSetChanged();
	}

	void SetShowView(std::function<void(int nItem, SWindow* pItem)> fun) {
		m_callshowview = fun;
	}

private:
	int getCount()
	{
		return m_count;
	}

	void ShowView(int nItem, SWindow* pItem)
	{
		if (m_callshowview)
		{
			m_callshowview(nItem, pItem);
		}
		/*auto process_info = Clogin_info::getSingletonPtr()->m_server_gourp_tiles[nItem];
		pItem->FindChildByName2<SStatic>(L"titile")->SetWindowTextW(S_CA2W(process_info.title.c_str(), CP_UTF8));*/
	}



	void ItemHover(int nItem, SItemPanel* pItem, const CPoint& pt)
	{
		SWindow* pBtn = pItem->FindChildByName(L"ml_btn_del");
		if (NULL != pBtn)
			pBtn->SetVisible(TRUE, TRUE);

		SWindow* pCount = pItem->FindChildByName(L"ml_count");
		if (NULL != pCount)
			pCount->SetVisible(FALSE, TRUE);
	}
	void ItemLeave(int nItem, SItemPanel* pItem)
	{
		SWindow* pBtn = pItem->FindChildByName(L"ml_btn_del");
		if (NULL != pBtn)
			pBtn->SetVisible(FALSE, TRUE);

		SWindow* pCount = pItem->FindChildByName(L"ml_count");
		if (NULL != pCount && !pCount->GetWindowText().IsEmpty())
		{
			pCount->SetVisible(TRUE, TRUE);
		}
	}


	void ItemClick(int nItem, SItemPanel* pItem, const CPoint& pt)
	{
		if (nullptr != m_callBackItemClick)
			m_callBackItemClick(nItem);
	}
	bool IsItemClick(int nItem, const SStringT& szSndName)
	{
		if (0 == szSndName.CompareNoCase(L"ml_btn_del"))
			return false;

		return true;
	}

	bool OnEventDelBtn(EventArgs* e)
	{
		e->bubbleUp = false;
		EventCmd* pEvt = sobj_cast<EventCmd>(e);
		if (NULL == pEvt) return true;

		SImageButton* pBtn = sobj_cast<SImageButton>(pEvt->sender);
		if (NULL == pBtn) return true;

		SItemPanel* pItem = sobj_cast<SItemPanel>(pBtn->GetParent());
		if (NULL == pItem) return true;

		if (nullptr != m_callBackBtnClick)
			m_callBackBtnClick(static_cast<int>(pItem->GetItemIndex()));

		return true;
	}


private:

	std::function<void(int)>						m_callBackItemClick;		// item ���� �ص�
	std::function<void(int)>						m_callBackBtnClick;			//  item  btn �ص�
	std::function<void(int nItem, SWindow* pItem)>	m_callshowview;
	int m_count;
	INT m_nCurCheck;
	bool m_seleset;
	MemberFunctionSlot<CNodeAdapter, EventArgs>			m_funBtnDel;
};