package kr.co.hanwha.hifive.view;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import kr.co.hanwha.hifive.R;
import kr.co.hanwha.hifive.enums.TaskEvaluationType;
import kr.co.hanwha.hifive.enums.TaskStatusType;
import kr.co.hanwha.hifive.util.HFTaskUtil;

/**
 * Created by sanghoonkwon on 2018. 3. 13..
 */

public class HFEvaluationStarListView extends LinearLayout {
    private ImageView mImageViewStar1;
    private ImageView mImageViewStar2;
    private ImageView mImageViewStar3;
    private TextView mTextViewStatus;

    public HFEvaluationStarListView(Context context) {
        super(context);
        initialize(context, null);
    }

    public HFEvaluationStarListView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initialize(context, attrs);
    }

    public HFEvaluationStarListView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initialize(context, attrs);
    }

    private void initialize(Context context, @Nullable AttributeSet attrs) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.view_hf_evaluation_star_list, this, true);

        mImageViewStar1 = (ImageView) findViewById(R.id.star1_imageView);
        mImageViewStar2 = (ImageView) findViewById(R.id.star2_imageView);
        mImageViewStar3 = (ImageView) findViewById(R.id.star3_imageView);
        mTextViewStatus = (TextView) findViewById(R.id.status_textView);

        mImageViewStar1.setVisibility(View.GONE);
        mImageViewStar2.setVisibility(View.GONE);
        mImageViewStar3.setVisibility(View.GONE);
        mTextViewStatus.setVisibility(View.GONE);
    }

    public void setEvaluationData(@NonNull int status, @NonNull int evaluation) {

        if (status == TaskStatusType.EVALUATED.getCode() ||
                status == TaskStatusType.REJECTED_EVALUATION.getCode() ||
                status == TaskStatusType.CLOSED.getCode()) {
            mImageViewStar1.setSelected(evaluation == TaskEvaluationType.STAR_ONE.getCode() ||
                    evaluation == TaskEvaluationType.STAR_TWO.getCode() ||
                    evaluation == TaskEvaluationType.STAR_THREE.getCode());
            mImageViewStar2.setSelected(evaluation == TaskEvaluationType.STAR_TWO.getCode() ||
                    evaluation == TaskEvaluationType.STAR_THREE.getCode());
            mImageViewStar3.setSelected(evaluation == TaskEvaluationType.STAR_THREE.getCode());
            mImageViewStar1.setVisibility(View.VISIBLE);
            mImageViewStar2.setVisibility(View.VISIBLE);
            mImageViewStar3.setVisibility(View.VISIBLE);
        } else {
            mImageViewStar1.setVisibility(View.GONE);
            mImageViewStar2.setVisibility(View.GONE);
            mImageViewStar3.setVisibility(View.GONE);
        }

        mTextViewStatus.setText(HFTaskUtil.getRequestStatusText(getContext(), status, evaluation));
        mTextViewStatus.setTextColor(HFTaskUtil.getStatusFontColor(getContext(), status));
        mTextViewStatus.setBackground(HFTaskUtil.getStatusBackground(getContext(), status));
        mTextViewStatus.setVisibility(View.VISIBLE);
    }
}
