package com.facebook.share.widget;

import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import com.facebook.internal.AppCall;
import com.facebook.internal.DialogPresenter;
import com.facebook.internal.FacebookDialogBase.ModeHandler;
import com.facebook.internal.NativeAppCallAttachmentStore;
import com.facebook.internal.NativeAppCallAttachmentStore$Attachment;
import com.facebook.share.internal.ShareContentValidation;
import com.facebook.share.internal.WebDialogParameters;
import com.facebook.share.model.ShareContent;
import com.facebook.share.model.ShareLinkContent;
import com.facebook.share.model.ShareOpenGraphContent;
import com.facebook.share.model.SharePhoto;
import com.facebook.share.model.SharePhoto.Builder;
import com.facebook.share.model.SharePhotoContent;
import com.facebook.share.model.SharePhotoContent$Builder;
import com.facebook.share.widget.ShareDialog.Mode;
import com.google.firebase.analytics.FirebaseAnalytics$a;
import com.tencent.matrix.trace.core.AppMethodBeat;
import java.util.ArrayList;
import java.util.UUID;

class ShareDialog$WebShareHandler extends ModeHandler {
    final /* synthetic */ ShareDialog this$0;

    private ShareDialog$WebShareHandler(ShareDialog shareDialog) {
        this.this$0 = shareDialog;
        super(shareDialog);
    }

    public Object getMode() {
        return Mode.WEB;
    }

    public boolean canShow(ShareContent shareContent, boolean z) {
        AppMethodBeat.i(97701);
        if (shareContent == null || !ShareDialog.access$900(shareContent)) {
            AppMethodBeat.o(97701);
            return false;
        }
        AppMethodBeat.o(97701);
        return true;
    }

    public AppCall createAppCall(ShareContent shareContent) {
        Bundle create;
        AppMethodBeat.i(97702);
        ShareDialog.access$700(this.this$0, ShareDialog.access$1000(this.this$0), shareContent, Mode.WEB);
        AppCall createBaseAppCall = this.this$0.createBaseAppCall();
        ShareContentValidation.validateForWebShare(shareContent);
        if (shareContent instanceof ShareLinkContent) {
            create = WebDialogParameters.create((ShareLinkContent) shareContent);
        } else if (shareContent instanceof SharePhotoContent) {
            create = WebDialogParameters.create(createAndMapAttachments((SharePhotoContent) shareContent, createBaseAppCall.getCallId()));
        } else {
            create = WebDialogParameters.create((ShareOpenGraphContent) shareContent);
        }
        DialogPresenter.setupAppCallForWebDialog(createBaseAppCall, getActionName(shareContent), create);
        AppMethodBeat.o(97702);
        return createBaseAppCall;
    }

    private String getActionName(ShareContent shareContent) {
        if ((shareContent instanceof ShareLinkContent) || (shareContent instanceof SharePhotoContent)) {
            return FirebaseAnalytics$a.SHARE;
        }
        if (shareContent instanceof ShareOpenGraphContent) {
            return "share_open_graph";
        }
        return null;
    }

    private SharePhotoContent createAndMapAttachments(SharePhotoContent sharePhotoContent, UUID uuid) {
        AppMethodBeat.i(97703);
        SharePhotoContent$Builder readFrom = new SharePhotoContent$Builder().readFrom(sharePhotoContent);
        ArrayList arrayList = new ArrayList();
        ArrayList arrayList2 = new ArrayList();
        int i = 0;
        while (true) {
            int i2 = i;
            if (i2 < sharePhotoContent.getPhotos().size()) {
                Object obj = (SharePhoto) sharePhotoContent.getPhotos().get(i2);
                Bitmap bitmap = obj.getBitmap();
                if (bitmap != null) {
                    NativeAppCallAttachmentStore$Attachment createAttachment = NativeAppCallAttachmentStore.createAttachment(uuid, bitmap);
                    obj = new Builder().readFrom(obj).setImageUrl(Uri.parse(createAttachment.getAttachmentUrl())).setBitmap(null).build();
                    arrayList2.add(createAttachment);
                }
                arrayList.add(obj);
                i = i2 + 1;
            } else {
                readFrom.setPhotos(arrayList);
                NativeAppCallAttachmentStore.addAttachments(arrayList2);
                SharePhotoContent build = readFrom.build();
                AppMethodBeat.o(97703);
                return build;
            }
        }
    }
}
