package com.pixelnx.localhelp.ui.order;


import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;

import android.view.View;
import android.widget.ImageView;

import com.androidnetworking.AndroidNetworking;
import com.androidnetworking.common.Priority;
import com.androidnetworking.error.ANError;
import com.androidnetworking.interfaces.ParsedRequestListener;
import com.pixelnx.localhelp.R;
import com.pixelnx.localhelp.model.ModelUserData;
import com.pixelnx.localhelp.utils.Consts;
import com.pixelnx.localhelp.utils.ProjectUtils;
import com.pixelnx.localhelp.utils.sharedpref.SharedPref;
import com.pixelnx.localhelp.utils.widgets.CustomTextSemiBold;

import java.util.ArrayList;

public class ActivityNewOrder extends Activity implements View.OnClickListener {
Context mContext;
ImageView backIv;
   SharedPref sharedPref;
    ModelUserData modelUserData;
    RecyclerView rvList;
    ArrayList<ModelNewOrderData.Data> data;
    CustomTextSemiBold noData;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new_order);
        mContext=ActivityNewOrder.this;
        sharedPref = SharedPref.getInstance(mContext);
        modelUserData = sharedPref.getUser(Consts.Status.SP);
        initial();
    }
    void initial(){
        backIv=findViewById(R.id.backIv);
        noData=findViewById(R.id.nodata);
        rvList=findViewById(R.id.rvList);
        rvList.setLayoutManager(new LinearLayoutManager(mContext));
        backIv.setOnClickListener(this);
apiDeliveryOrder();

    }
    void apiDeliveryOrder(){
        ProjectUtils.showProgressDialog(mContext, false, "Loading...");
        AndroidNetworking.post(Consts.Status.BASE_URL +Consts.Status.API_DELIVERY_ORDER)
                .addBodyParameter("vendor_id",""+modelUserData.getData().getUserId())
                .setPriority(Priority.IMMEDIATE)
                .setTag(Consts.Status.SEARCH_API)
                .build()
                .getAsObject(ModelNewOrderData.class, new ParsedRequestListener<ModelNewOrderData>() {
                    @Override
                    public void onResponse(ModelNewOrderData response) {

                        if(response.getStatus().equalsIgnoreCase("1")){
                        data=new ArrayList<>();
                        ProjectUtils.pauseProgressDialog();

                        AdapterOrderList adapterOrderList=new AdapterOrderList(mContext,response.getOrderData(), "N");
                        rvList.setAdapter(adapterOrderList);}else{
                            noData.setVisibility(View.VISIBLE);
                        }
                        ProjectUtils.pauseProgressDialog();
                    }

                    @Override
                    public void onError(ANError anError) {

                        ProjectUtils.pauseProgressDialog();

                    }
                });



    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.backIv) {
            onBackPressed();
        }

    }
}
