package com.b2lmobitech.fieldcloudhrms

import android.os.Bundle
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity

class TravelDetailsActivity : AppCompatActivity() {

    companion object {
        const val EXTRA_TRAVEL = "extra_travel"
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_travel_details)

        // Optional back icon
        findViewById<ImageView?>(R.id.ivBack)?.setOnClickListener { finish() }

        val travel = intent.getParcelableExtra<TravelModel>(EXTRA_TRAVEL)
        if (travel == null) {
            Toast.makeText(this, "No travel details found", Toast.LENGTH_SHORT).show()
            finish()
            return
        }

        findViewById<TextView>(R.id.tvTravelId).text = travel.travel_id
        findViewById<TextView>(R.id.tvLocation).text = travel.location
        findViewById<TextView>(R.id.tvStartDate).text = travel.start_date
        findViewById<TextView>(R.id.tvEndDate).text = travel.end_date
        findViewById<TextView>(R.id.tvPurpose).text = travel.purpose
        findViewById<TextView>(R.id.tvDuration).text = travel.duration

        // show nice values
        findViewById<TextView>(R.id.tvBillable).text =
            if (travel.customer_billable == "1" || travel.customer_billable.equals("yes", true)) "Yes" else "No"

        findViewById<TextView>(R.id.tvCustomerName).text =
            travel.customer_name.ifBlank { "-" }
    }
}
