package com.cygnusa.hyperm;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.text.Html;
import android.view.MenuItem;
import android.widget.TextView;

import com.github.mikephil.charting.charts.BarChart;
import com.cygnusa.hyperm.util.GlobalData;

public class TermsandConditions extends AppCompatActivity {
    private BarChart mChart;
    private String strTermsnContions;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_terms);
        Bundle extras = getIntent().getExtras();
        if (extras != null) {
            strTermsnContions = extras.getString("tnc");
        }
        TextView about = (TextView)findViewById(R.id.terms_conditions);
//        String youtContentStr = String.valueOf(Html
//                .fromHtml("<![CDATA[<body style=\"text-align:justify;color:#222222; \">"
//                        + strTermsnContions
//                        + "</body>]]>"));

        String htmlText = "<html><body style=\"text-align:justify\"> %s </body></Html>";
        about.setText(Html.fromHtml(String.format(String.format(htmlText, strTermsnContions), "text/html", "utf-8")));
        setupWindowAnimations();
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        toolbar.setContentInsetStartWithNavigation(0);
        toolbar.setTitle("");
        getSupportActionBar().setTitle("");
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        @SuppressLint("PrivateResource")
        Drawable backArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_material);
        backArrow.setColorFilter(getResources().getColor(R.color.btn_bg_color), PorterDuff.Mode.SRC_ATOP);
        getSupportActionBar().setHomeAsUpIndicator(backArrow);
    }
    protected void onResume() {
        super.onResume();

        if (GlobalData.canLogout) {
            finish();
        }
    }
    @Override
    public void onBackPressed() {
        Intent result = new Intent();
        setResult(Activity.RESULT_CANCELED, result);
        finish();
        this.overridePendingTransition(R.anim.animation_f_enter,
                R.anim.animation_f_leave);
    }

    private void setupWindowAnimations() {
        this.overridePendingTransition(R.anim.animation_enter,
                R.anim.animation_leave);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish();
            overridePendingTransition(R.anim.animation_f_enter,
                    R.anim.animation_f_leave);
        }
        return super.onOptionsItemSelected(item);
    }

}
