package com.sliit.smartserviceassistant.spareparts;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.appsnipp.education.R;

public class DisplayPriceActivity extends AppCompatActivity {

    private Button btn_map;
    private Button btn_videos;
    private TextView avgPrice;

    private String model;
    private String type;
    private String part;
    private String year;

    private TextView topic;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_display_price);

        // Google maps button
        btn_map = findViewById(R.id.btn_launch_stores);
        btn_map.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(DisplayPriceActivity.this, StoresListActivity.class);
                startActivity(intent);
            }
        });

        // Get vehicle details from the main activity interface
        model = getIntent().getStringExtra("key_model");
        type = getIntent().getStringExtra("key_type");
        part = getIntent().getStringExtra("key_part");
        year = getIntent().getStringExtra("key_year");

        // Youtube videos button
        btn_videos = findViewById(R.id.btn_launch_videos);
        btn_videos.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getUrl("https://www.youtube.com/results?search_query=" +
                        model + "+" + type + "+" + part + "+replacement");
            }
        });

        topic = findViewById(R.id.txt_spare_part_name);

        topic.setText(model + " " + type + " " + part + " for the year of " + year);

        avgPrice = findViewById(R.id.txt_avg_price);

//        Call prediction method from Predictor class
        Predictor predictor = new Predictor();
        String value = predictor.predictPrices(model, type, part, year);
        avgPrice.setText("Rs. " + value);

    }

    private void getUrl(String s) {
        Uri uri = Uri.parse(s);
        startActivity(new Intent(Intent.ACTION_VIEW, uri));
    }

}