package com.example.shridev1;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class RideDetailsActivity extends AppCompatActivity {

    Button bookbutton;
    Button backbutton;


    String [] name = { "Jane Doe", "Greta Thunberg", "Fanny Johansson" };
    String [] rating = { "3/5", "4/5", "5/5" };
    TextView numberOfPassengers;
    int ridersAmount = name.length;

    TextView wherefrom, whereto, pickup, seats, space, car, environment, preferences;
    String wherefrom_s, whereto_s, pickup_s,  seats_s, space_s, car_s, environment_s, preferences_s;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Ta bort titelbaren längst upp
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getSupportActionBar().hide();
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.activity_ride_details);

        numberOfPassengers = (TextView) findViewById(R.id.numberOfPassengers);
        numberOfPassengers.setText(ridersAmount + "/5");

        wherefrom = (TextView) findViewById(R.id.whereFrom_txt2);
        whereto = (TextView) findViewById(R.id.whereTo_txt2);
        pickup = (TextView) findViewById(R.id.pickupPoint_txt2);
        seats = (TextView) findViewById(R.id.carSeats_txt2);
        space = (TextView) findViewById(R.id.carSpace_txt2);
        car = (TextView) findViewById(R.id.carType2);
        environment = (TextView) findViewById(R.id.carEnvironment_txt2);
        preferences = (TextView) findViewById(R.id.carPreferences_txt2);

        bookbutton = (Button)findViewById(R.id.bookridebutton);
        bookbutton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent i = new Intent(getApplicationContext(), BankIDActivity.class);
                startActivity(i);
            }
        });
        backbutton = (Button)findViewById(R.id.backtoridelistbutton);
        backbutton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent i = new Intent(getApplicationContext(), RideListActivity.class);
                startActivity(i);
                Log.d("RideDetailsActivity", "Button clicked");
            }
        });
        getAndSetIntentData();

    ArrayAdapter adapter = new ArrayAdapter<String>(this, R.layout.activity_riders_list, name);

    ListView listView = (ListView) findViewById(R.id.riders_list);
    listView.setAdapter(adapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

                String ridersName = name[i].toString();
                String ridersRating = rating[i].toString();

                Intent intent = new Intent(getApplicationContext(), RidersDetailsActivity.class);
                intent.putExtra("RidersName", ridersName);
                intent.putExtra("RidersRating", ridersRating);
                intent.putExtra("NumberOfPassengers", numberOfPassengers.toString());
                startActivity(intent);

            }
        });

    }
    void getAndSetIntentData () {
        if (getIntent().hasExtra("wherefrom") && getIntent().hasExtra("whereto") && getIntent().hasExtra("pickup") && getIntent().hasExtra("seats")
                && getIntent().hasExtra("space") && getIntent().hasExtra("car") && getIntent().hasExtra("environment") && getIntent().hasExtra("preferences")){
            wherefrom_s = getIntent().getStringExtra("wherefrom");
            whereto_s = getIntent().getStringExtra("whereto");
            pickup_s = getIntent().getStringExtra("pickup");
            seats_s = getIntent().getStringExtra("seats");
            space_s = getIntent().getStringExtra("space");
            car_s = getIntent().getStringExtra("car");
            environment_s = getIntent().getStringExtra("environment");
            preferences_s = getIntent().getStringExtra("preferences");

            wherefrom.setText(wherefrom_s);
            whereto.setText(whereto_s);
            pickup.setText(pickup_s);
            seats.setText(seats_s);
            space.setText(space_s);
            car.setText(car_s);
            environment.setText(environment_s);
            preferences.setText(preferences_s);
        }
    }
}