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.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import kr.co.hanwha.hifive.R;
import kr.co.hanwha.hifive.enums.ProjectAchievementType;

public class HFMyHomeProfileUnitView extends LinearLayout {
    private ImageView mImageViewStatus;
    private TextView mTextViewProject;

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

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

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

    private void initialize(Context context, @Nullable AttributeSet attrs) {
//        if (isInEditMode()) return;

        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.view_hf_my_home_profile_unit, this, true);

        initLayout();

    }

    private void initLayout() {
        mImageViewStatus = (ImageView) findViewById(R.id.status_imageView);
        mTextViewProject = (TextView) findViewById(R.id.project_textView);
    }

    public void setProjectInfo(int achievement, @NonNull String projectName) {
        ProjectAchievementType achieveType = ProjectAchievementType.valueOf(achievement);
        switch (achieveType) {
            case GREEN:
                mImageViewStatus.setBackground(getContext().getResources().getDrawable(R.mipmap.ic_unit_g));
                break;
            case YELLOW:
                mImageViewStatus.setBackground(getContext().getResources().getDrawable(R.mipmap.ic_unit_y));
                break;
            case ORANGE:
                mImageViewStatus.setBackground(getContext().getResources().getDrawable(R.mipmap.ic_unit_o));
                break;
            case RED:
                mImageViewStatus.setBackground(getContext().getResources().getDrawable(R.mipmap.ic_unit_r));
                break;
            default:
                mImageViewStatus.setBackground(getContext().getResources().getDrawable(R.mipmap.ic_unit_g));
                break;
        }
        mTextViewProject.setText(projectName);
    }

}