package com.example.bb;

import java.util.Calendar;

import android.app.Activity;
import android.app.DialogFragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;

public class Reservation extends Activity {
    private Calendar ciCalendar = Calendar.getInstance();
    private Calendar coCalendar = Calendar.getInstance();

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

        Button checkin = (Button) findViewById(R.id.buttonCheckin);
        checkin.setOnClickListener(new OnClickListener() {
            public void onClick(View view) {
                DialogFragment fragment = new CheckinDialogFragment();
                fragment.show(getFragmentManager(), "checkin");
            }
        });

        Button checkout = (Button) findViewById(R.id.buttonCheckout);
        checkout.setOnClickListener(new OnClickListener() {
            public void onClick(View view) {
                DialogFragment fragment = new CheckoutDialogFragment();
                fragment.show(getFragmentManager(), "checkout");
            }
        });

        final CheckBox cb = (CheckBox) findViewById(R.id.smoking);
        cb.setOnClickListener(new OnClickListener() {
            public void onClick(View view) {
                findViewById(R.id.room1).setEnabled(!cb.isChecked());
                findViewById(R.id.room2).setEnabled(!cb.isChecked());
                findViewById(R.id.room3).setEnabled(!cb.isChecked());
                findViewById(R.id.room4).setEnabled(cb.isChecked());
                findViewById(R.id.room5).setEnabled(cb.isChecked());
            }
        });

        Button next = (Button) findViewById(R.id.done);
        next.setOnClickListener(new OnClickListener() {
            public void onClick(View view) {
                String email = ((EditText) findViewById(R.id.email))
                        .getText().toString();
                if (!email.contains("@")) {
                    /*
                     * // Display a toast message
                     * Toast.makeText(Reservation.this, R.string.invalidEmail,
                     * Toast.LENGTH_LONG).show();
                     */
                    // Display a dialog
                    DialogFragment fragment = new EmailDialogFragment();
                    fragment.show(getFragmentManager(), "bad-email");
                }
                else {
                    Intent i = new Intent();
                    i.setClass(Reservation.this,
                            ThankYouActivity.class);
                    startActivity(i);
                }
            }
        });
    }
    
    public Calendar getCheckinCalendar() {
        return ciCalendar;
    }
    
    public Calendar getCheckoutCalendar() {
        return coCalendar;
    }
}