package com.xxrv.coupon.fragment;

import android.os.Bundle;
import android.support.v7.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.ruiwenliu.wrapper.base.BaseBean;
import com.ruiwenliu.wrapper.base.BaseFragment;
import com.ruiwenliu.wrapper.weight.refresh.SimpleRefreshLayout;
import com.ruiwenliu.wrapper.weight.refresh.SimpleRefreshView;
import com.xxrv.coupon.R;
import com.xxrv.coupon.R2;
import com.xxrv.coupon.presenter.CouponAllPresenter;

import java.util.LinkedHashMap;
import java.util.Map;

import butterknife.BindView;

/**
 * 优惠券  已过期
 */
public class ExpiredCouponFragment extends BaseFragment<CouponAllPresenter> implements BaseQuickAdapter.RequestLoadMoreListener, SimpleRefreshLayout.OnSimpleRefreshListener {

    @BindView(R2.id.rv_content)
    RecyclerView rvContent;
    @BindView(R2.id.refresh)
    SimpleRefreshLayout mSimpleRefreshLayout;

    private int countPage;
    private int mPage;
    
    public static ExpiredCouponFragment getInstance(int type) {
        Bundle bundl = new Bundle();
        bundl.putInt("type", type);
        ExpiredCouponFragment fragment = new ExpiredCouponFragment();
        fragment.setArguments(bundl);
        return fragment;
    }

    @Override
    public int getViewLayout() {
        return R.layout.fragment_coupon_wait;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        mSimpleRefreshLayout.setHeaderView(new SimpleRefreshView(_mActivity));
        mSimpleRefreshLayout.setOnSimpleRefreshListener(this);

    }

    @Override
    protected void loadData(Bundle savedInstanceState) {
        onFresh();
    }

    /**
     * 刷新
     */
    private void onFresh() {
        mPage = 1;
        geDataList(mPage);
    }

    /**
     * 请求数据
     *
     * @param page
     */
    private void geDataList(int page) {
        Map<String, Object> map = new LinkedHashMap<>();
        map.put("page", page);
        map.put("type",2);
//        mPresenter.postData( 0, DiscoveryApi.DISCOVERY_UNAUTH_LIST, DiscoveryRecommendBean.class, map, page == 1 ? false : false);
    }

    @Override
    public void onShowResult(int requestType, BaseBean result) {
        mSimpleRefreshLayout.onRefreshComplete();
//        processData((DiscoveryRecommendBean) result);
    }

//    private void processData(DiscoveryRecommendBean bean) {
//        if (mPage == 1) {
//            countPage = bean.getData().getTotalPage();
//            mAdapter.setNewData(bean.getData().getList());
//            if (bean.getData().getTotalCount() == 0) {
//
//            }
//        } else {
//            mAdapter.addData(bean.getData().getList());
//            mAdapter.loadMoreComplete();
//        }
//    }

    @Override
    public void onLoadMoreRequested() {
//        if (mPage >= countPage) {
//            mAdapter.loadMoreEnd();
//        } else {
//            mPage++;
//            geDataList(mPage);
//        }
    }

    @Override
    public void onRefresh() {
        onFresh();
    }
}
