package com.youra.qlicker.Acitvitys.EER.KYC;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;

import com.google.android.material.datepicker.MaterialDatePicker;
import com.youra.qlicker.R;

public class KYCSiteProfActivity extends AppCompatActivity {

    private View thumbView;
    private  String[] Activetes = { "xxxxx", "wwwww", "sssssss" };

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

        ImageView btn_back = (ImageView) findViewById(R.id.img_back);
        TextView btn_next = (TextView) findViewById(R.id.btn_next);

        ///dropdown
        AutoCompleteTextView drop_activite=  (AutoCompleteTextView) findViewById(R.id.dropdown_activete);
        AutoCompleteTextView drop_prof=  (AutoCompleteTextView) findViewById(R.id.dropdown_prof);
        AutoCompleteTextView drop_revenu=  (AutoCompleteTextView) findViewById(R.id.dropdown_revenu);
        AutoCompleteTextView drop_contra=  (AutoCompleteTextView) findViewById(R.id.dropdown_typecontra);

        ///range
        TextView txt_selected = (TextView) findViewById(R.id.txt_selected);
        SeekBar range = (SeekBar) findViewById(R.id.seekBar_revune);



        ///fill drop down
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, Activetes);
        drop_activite.setAdapter(adapter);
        drop_prof.setAdapter(adapter);
        drop_revenu.setAdapter(adapter);
        drop_revenu.setAdapter(adapter);
        drop_contra.setAdapter(adapter);




        /// change from range bar
        range.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

                // You can have your own calculation for progress
                seekBar.setThumb(getThumb(progress));
                txt_selected.setText(String.valueOf(progress));
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });

        /// inisialize range
        thumbView = LayoutInflater.from(KYCSiteProfActivity.this).inflate(R.layout.layout_seekbar_thumb, null, false);
        range.setThumb( getThumb(  3000 )  );
        range.setProgress(3000);
        txt_selected.setText("3000");


        /// click btn for return previous activity
        btn_next.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                 startActivity(new Intent(KYCSiteProfActivity.this,  KYCAgenceActivity.class ));

            }
        });

        /// click btn for return previous activity
        btn_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                finish();
            }
        });
    }

    /**
     * function creet text down from thumb
     * @param progress
     * @return
     */
    private Drawable getThumb(int progress) {
        ((TextView) thumbView.findViewById(R.id.tvProgress)).setText(progress + "");

        thumbView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        Bitmap bitmap = Bitmap.createBitmap(thumbView.getMeasuredWidth(), thumbView.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        thumbView.layout(0, 0, thumbView.getMeasuredWidth(), thumbView.getMeasuredHeight());
        thumbView.draw(canvas);

        return new BitmapDrawable(getResources(), bitmap);
    }

    /**
     * function show datepicer
     */
     private void showDialogDate(){
         //datepicker
         MaterialDatePicker.Builder builder = MaterialDatePicker.Builder.datePicker();
         MaterialDatePicker picker = builder.build();

         picker.show(this.getSupportFragmentManager(), "DATE_PICKER");
     }
}