package in.techware.carrefour.activity.info;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import in.techware.carrefour.activity.BaseAppCompatNoDrawerActivity;
import in.techware.carrefour.dialogs.ConfirmationDialog;
import in.techware.carrefour.R;
import in.techware.carrefour.util.AppConstants;

public class ProductInfoActivity extends BaseAppCompatNoDrawerActivity {

    ConfirmationDialog confirmationDialog;
    EditText itemCodeEditText;
    EditText barCodeEditText;
    EditText avgNormalSaleEditText;
    EditText secEditText;
    EditText famEditText;
    EditText sellingPriceEditText;
    EditText assortmentEditText;
    EditText facingEditText;
    EditText stockBeginDayEditText;
    EditText numberOfDaysEditText;

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

        initViews();
        handleKeyboard();
    }

    private void initViews() {
        itemCodeEditText = findViewById(R.id.etxt_item_code);
        barCodeEditText = findViewById(R.id.etxt_barcode);
        avgNormalSaleEditText = findViewById(R.id.etxt_avg_normal_sale);
        secEditText = findViewById(R.id.etxt_sec);
        famEditText = findViewById(R.id.etxt_fam);
        sellingPriceEditText = findViewById(R.id.etxt_selling_price);
        assortmentEditText = findViewById(R.id.etxt_assortment);
        facingEditText = findViewById(R.id.etxt_facing);
        stockBeginDayEditText = findViewById(R.id.etxt_stock_beg_day);
        numberOfDaysEditText = findViewById(R.id.etxt_no_of_days);


        confirmationDialog =new ConfirmationDialog(this);
        confirmationDialog.setConfirmationDialogActionListener(new ConfirmationDialog.ConfirmationDialogActionListener() {
            @Override
            public void onYesClicked() {
                finishAffinity();
            }

            @Override
            public void onNoClicked() {

            }
        });
    }

    private void handleKeyboard() {
        if (getSharedPreferences(AppConstants.PREF_FILE, 0).getBoolean(AppConstants.KEYBOARD_STATUS, false)){
            itemCodeEditText.setFocusableInTouchMode(true);
            barCodeEditText.setFocusableInTouchMode(true);
            avgNormalSaleEditText.setFocusableInTouchMode(true);
            secEditText.setFocusableInTouchMode(true);
            famEditText.setFocusableInTouchMode(true);
            sellingPriceEditText.setFocusableInTouchMode(true);
            assortmentEditText.setFocusableInTouchMode(true);
            facingEditText.setFocusableInTouchMode(true);
            stockBeginDayEditText.setFocusableInTouchMode(true);
            numberOfDaysEditText.setFocusableInTouchMode(true);
        }
    }

    public void onMainPageClick(View v){
        Intent intent = new Intent(getApplicationContext(), ProductInfoActivity.class);
        startActivity(intent);
        finish();
    }

    public void onLabelPageClick(View v){
        Intent intent = new Intent(getApplicationContext(), LabelActivity.class);
        startActivity(intent);
        finish();
    }

    public void onOrderPageClick(View v){
        Intent intent = new Intent(getApplicationContext(), OrderInfoActivity.class);
        startActivity(intent);
        finish();
    }

    public void onWeekPageClick(View v){
        Intent intent = new Intent(getApplicationContext(), WeekMovementActivity.class);
        startActivity(intent);
        finish();
    }

    public void onExitClick(View v){
        confirmationDialog.show(R.string.message_do_you_really_want_to_exit);
    }

}
