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.dialogs.ConfirmationDialog;
import in.techware.carrefour.R;
import in.techware.carrefour.util.AppConstants;

public class OrderInfoActivity extends AppCompatActivity  {

    ConfirmationDialog confirmationDialog;
    EditText itemCodeEditText;
    EditText barCodeEditText;
    EditText supplierDcEditText;
    EditText stockBeginDatEditText;
    EditText lastReceiptEditText;
    EditText pendingOrdersEditText;
    EditText orderDateEditText;
    EditText nextDelDateEditText;
    EditText pcbEditText;
    EditText stockMinEditText;
    EditText facingEditText;
    EditText supplierLpoTypeEditText;
    EditText supplierLeadTimeEditText;

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

        initViews();
        handleKeyboard();

    }

    private void initViews() {
        itemCodeEditText = findViewById(R.id.etxt_item_code);
        barCodeEditText = findViewById(R.id.etxt_barcode);
        supplierDcEditText = findViewById(R.id.etxt_supp_dc);
        stockBeginDatEditText = findViewById(R.id.text_stock_beginning_day);
        lastReceiptEditText = findViewById(R.id.etxt_last_rec_date);
        pendingOrdersEditText = findViewById(R.id.etxt_pending_orders);
        orderDateEditText = findViewById(R.id.etxt_order_date);
        nextDelDateEditText = findViewById(R.id.etxt_next_del_date);
        pcbEditText = findViewById(R.id.etxt_pcb);
        stockMinEditText = findViewById(R.id.etxt_stock_min);
        facingEditText = findViewById(R.id.etxt_facing);
        supplierLpoTypeEditText = findViewById(R.id.etxt_supplier_lpo_type);
        supplierLeadTimeEditText = findViewById(R.id.etxt_supplier_lead_time);

        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);
            supplierDcEditText.setFocusableInTouchMode(true);
            stockBeginDatEditText.setFocusableInTouchMode(true);
            lastReceiptEditText.setFocusableInTouchMode(true);
            pendingOrdersEditText.setFocusableInTouchMode(true);
            orderDateEditText.setFocusableInTouchMode(true);
            nextDelDateEditText.setFocusableInTouchMode(true);
            pcbEditText.setFocusableInTouchMode(true);
            stockMinEditText.setFocusableInTouchMode(true);
            facingEditText.setFocusableInTouchMode(true);
            supplierLpoTypeEditText.setFocusableInTouchMode(true);
            supplierLeadTimeEditText.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);
    }

}
