package com.example.mynotepad.MenuFeatures;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;


import com.example.mynotepad.R;

public class CustomToolbarOption extends LinearLayout implements View.OnClickListener {
    private View rootView;
    private ImageView blackStarImg , yellowStarImg , deleteImg , closeImg;
    private CustomToolbarOptionListener customToolbarOptionListener;

    public CustomToolbarOption(Context context) {
        super(context);
        init(context);
    }

    public CustomToolbarOption(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    private void init(Context context){
        rootView = inflate(context, R.layout.custom_toolbar_options, this);
        blackStarImg = findViewById(R.id.black_star);
        yellowStarImg = findViewById(R.id.yellow_star);
        deleteImg = findViewById(R.id.deleteImg);
        closeImg = findViewById(R.id.closeImg);

        yellowStarImg.setOnClickListener(this);
        blackStarImg.setOnClickListener(this);
        deleteImg.setOnClickListener(this);
        closeImg.setOnClickListener(this);

    }


    @Override
    public void onClick(View view) {
        if (customToolbarOptionListener != null){
            if (view.getId() == closeImg.getId())
            customToolbarOptionListener.onCloseClicked();
            if (view.getId() == deleteImg.getId())
            customToolbarOptionListener.onDeleteClicked();
            if (view.getId() == yellowStarImg.getId() || view.getId() == blackStarImg.getId())
            customToolbarOptionListener.onStarClicked();
        }
    }

    public void setCustomToolbarOptionListener(CustomToolbarOptionListener customToolbarOptionListener) {
        this.customToolbarOptionListener = customToolbarOptionListener;
    }

    public void setYellowStar(){
        yellowStarImg.setVisibility(VISIBLE);
        blackStarImg.setVisibility(GONE);
    }

    public void setBlackStar(){
        yellowStarImg.setVisibility(GONE);
        blackStarImg.setVisibility(VISIBLE);
    }

    public void hideRecycleBin(){
        deleteImg.setVisibility(GONE);
    }

    public void hideStar(){
        yellowStarImg.setVisibility(GONE);
        blackStarImg.setVisibility(GONE);
    }
}
