package com.datarecovery.master.dialog;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;

import com.datarecovery.master.R;
import com.datarecovery.master.data.consts.EventId;
import com.datarecovery.master.databinding.DialogScanFileBinding;
import com.datarecovery.master.handler.EventHelper;
import com.datarecovery.master.module.homepage.FunctionBean;
import com.datarecovery.master.utils.Maps;


@BaseDialog.FullScreen(height = false)
public class ScanFileDialog extends BaseDialog<DialogScanFileBinding> {

    private final LiveData<String> detectedLastFileName;
    private final int function;
    private final int eventId;

    private OnCancelListener onCancelListener;

    public ScanFileDialog(@NonNull Context context, LiveData<String> detectedLastFileName, int function) {
        super(context, R.style.Theme_Common_Dialog);
        this.detectedLastFileName = detectedLastFileName;
        this.function = function;
        this.eventId = getEventIdByFunction(function);
        setCancelable(false);
        binding.setCancelClick(v -> {
            EventHelper.report(EventId.EVENT_3000001, Maps.asMap("id", eventId));
            if (onCancelListener != null) {
                onCancelListener.onCancel();
            }
            dismiss();
        });
        binding.setDetectedFileName(detectedLastFileName);
    }

    public void setOnCancelListener(OnCancelListener onCancelListener) {
        this.onCancelListener = onCancelListener;
    }

    private int getEventIdByFunction(int function) {
        switch (function) {
            case FunctionBean.IMG_RECOVERY:
                return 101;
            case FunctionBean.FILE_RECOVERY:
                return 102;
            case FunctionBean.VIDEO_RECOVERY:
                return 103;
            case FunctionBean.AUDIO_RECOVERY:
                return 104;
            case FunctionBean.IMG_CLEARING:
                return 105;
        }
        return 0;
    }

    @Override
    protected void onShow() {
        super.onShow();
        EventHelper.report(EventId.EVENT_3000000, Maps.asMap("id", eventId));
    }

    public interface OnCancelListener {
        void onCancel();
    }
}
