package macampcorp.macamp.activities;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import macampcorp.macamp.activities.viewers.ResourceListActivity;
import macampcorp.macamp.game.Game;
import macampcorp.macamp.utils.Android;

public class EndActivity extends AppCompatActivity {
    public static final int REQUEST_CODE=1011;

    protected boolean mWon=false;
    protected TextView mText;
    protected Button mRetry;
    protected LinearLayout mRoot;

    public String _(int x)
    {
        return  getResources().getString(x);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_end);
        mWon=getIntent().getBooleanExtra("won", false);
        mRetry = findViewById(R.id.btn_retry);
        mRoot = findViewById(R.id.ll_end);


        mText=findViewById(R.id.tv_end);
        if(mWon)
        {
            mText.setText(Html.fromHtml(_(R.string.text_success)));
            mRetry.setVisibility(View.GONE);
        }
        else
        {
            mText.setText(Html.fromHtml(_(R.string.text_fail)));
            mRetry.setVisibility(View.VISIBLE);
            CrashActivity.start(this);
        }
    }

    public void onCredits(View v)
    {
        CreditsActivity.start(this);
    }

    public void onQuit(View v)
    {
        finish();
    }

    public void onRetry(View v)
    {
        HostActivity.startGame(this, true);
        finish();
    }

    public static void start(Activity a, boolean win)
    {
        Intent it = new Intent(a, EndActivity.class);
        it.putExtra("won", win);
        a.startActivityForResult(it, REQUEST_CODE);
    }

    public void onJournal(View v)
    {
        ResourceListActivity.start(this);
    }
}
