package com.usai.apex.mainframe;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.View;
import android.widget.ListView;

import com.usai.apex.R;
import com.usai.apex.SearchListActivity;

import org.json.JSONObject;


/**
 * A simple {@link Fragment} subclass.
 */
public class SearchFragment extends StaticModelistFragment {


    public SearchFragment() {
        // Required empty public constructor
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState)
    {
        super.onActivityCreated(savedInstanceState);

        setupAdapter(R.raw.search);

//        adapter.getView()

        customize_style();
//        JSONObject jsonobj=loadjson(R.raw.search);
//        adapter        = new SimpleRoundCornerAdapter(this.getActivity(),
//                getData(jsonobj), R.layout.static_modelist_cell, new String[] { "title",
//                "img","detail" }, new int[] { R.id.tv_name, R.id.iv_icon,R.id.tv_detail });
//        setListAdapter(adapter);
////        this.getListView().setDivider(R.drawable.);
//        this.getListView().setDividerHeight(18);
//        this.getListView().setBackgroundColor(Color.WHITE);

    }

//    @Override
//    public View onCreateView(LayoutInflater inflater, ViewGroup container,
//                             Bundle savedInstanceState) {
//
//        View v= super.onCreateView(inflater,container,savedInstanceState);
//
//
//        return v;
//        // Inflate the layout for this fragment
////        return inflater.inflate(R.layout.fragment_search, container, false);
//    }

    @Override
    public void onListItemClick(ListView l, View v, int position, long id)
    {

        JSONObject jsonobj=loadjson(R.raw.search);
        Log.d("FragmentList", "Item clicked: " + id);

        String 	title = (String) getData(jsonobj).get(position-1).get("title");

//        Intent intent = new Intent();
        if (title.equals("Ocean Booking"))
        {
            Intent intent = new Intent();
            intent.setClass(getActivity(), SearchListActivity.class);
            // intent.putExtra("user", ApexTrackingApplication.get_user());
            // intent.putExtra("password", password);
            intent.putExtra("function_name", "Ocean Booking");
            intent.putExtra("title", "Booking Search");
            startActivity(intent);
        }
        else if (title.equals("Ocean B/L Info."))
        {
            Intent intent = new Intent();
            intent.setClass(getActivity(), SearchListActivity.class);
            // intent.putExtra("user", user);
            // intent.putExtra("password", password);
            intent.putExtra("function_name", "Ocean B/L info.");
            intent.putExtra("title", "B/L info. Search");
            startActivity(intent);
        }

//		else if (title.equals("Saved Detail/Search"))
//		{
//			intent.setClass(getActivity(), SearchHistoryActivity.class);
//		}
//		else if (title.equals("Change Password"))
//		{
//			intent.setClass(getActivity(), ChangePasswordActivity.class);
//
//			startActivityForResult(intent, REQUEST_CHANGEPASSWORD_ACTIVITY);
//			return;
//		}
        else if (title.equals("Container Detail"))
        {
            Intent intent = new Intent();
            intent.setClass(getActivity(), SearchListActivity.class);
            // intent.putExtra("user", user);
            // intent.putExtra("password", password);
            intent.putExtra("function_name", "Container detail");
            intent.putExtra("title", "Container Search");
            startActivity(intent);
        }
        else if (title.equals("Document"))
        {
//
//            Intent intent = new Intent();
//            intent.setClass(getActivity(), DocumentsActivity.class);
//
//            startActivity(intent);


            Intent intent = new Intent();
            intent.setClass(getActivity(), SearchListActivity.class);

            intent.putExtra("function_name", "Download Document");
            intent.putExtra("title", "Document Search");
            startActivity(intent);
        }


    }
}
