package epson.print.phlayout;


import java.util.ArrayList;
import java.util.Iterator;

import epson.print.EPImage;

public class PhotoPreviewImageList {
    private ArrayList<EpImageWrapper> mEpImageWrapperList = new ArrayList<>();
    private ArrayList<LayoutInfo> mLayoutInfoList = new ArrayList<>();

    public void clearExceptSrcFileName() {
    }

    public int size() {
        return mEpImageWrapperList.size();
    }

    public void add(@NonNull String str, int i) {
        add(new EpImageWrapper(str, (String) null, i));
    }

    public void add(@NonNull EpImageWrapper epImageWrapper) {
        mEpImageWrapperList.add(epImageWrapper);
        mLayoutInfoList.add(new LayoutInfo());
    }

    public void addOrgNameEpOrgName(@NonNull EpImageWrapper epImageWrapper) {
        mEpImageWrapperList.add(new EpImageWrapper(epImageWrapper.epImage.getOriginalFileName(), epImageWrapper.orgFilename, epImageWrapper.epImage.index));
        mLayoutInfoList.add(new LayoutInfo());
    }

    public void setList(@Nullable ArrayList<EpImageWrapper> arrayList) {
        clear();
        if (arrayList != null) {
            Iterator<EpImageWrapper> it = arrayList.iterator();
            while (it.hasNext()) {
                addOrgNameEpOrgName(it.next());
            }
        }
    }

    @NonNull
    public ArrayList<String> getGalleryFileList() {
        ArrayList<String> arrayList = new ArrayList<>();
        for (int i = 0; i < size(); i++) {
            EPImage ePImage = mEpImageWrapperList.get(i).epImage;
            if (ePImage == null) {
                arrayList.add((Object) null);
            } else {
                arrayList.add(ePImage.getOriginalFileName());
            }
        }
        return arrayList;
    }

    @Nullable
    public EPImage get(int i) {
        return mEpImageWrapperList.get(i).epImage;
    }

    public ArrayList<String> getArgumentFileList() {
        ArrayList<String> arrayList = new ArrayList<>();
        Iterator<EpImageWrapper> it = mEpImageWrapperList.iterator();
        while (it.hasNext()) {
            arrayList.add(it.next().getArgumentFilename());
        }
        return arrayList;
    }

    public void set(int i, @NonNull EPImage ePImage) {
        mEpImageWrapperList.get(i).epImage = ePImage;
    }

    public void clear() {
        mEpImageWrapperList.clear();
        mLayoutInfoList.clear();
    }

    public void remove(int i) {
        mEpImageWrapperList.remove(i);
        mLayoutInfoList.remove(i);
    }

    @NonNull
    public Element getElement(int i) {
        if (i >= 0 && i <= mEpImageWrapperList.size()) {
            return new Element(i);
        }
        throw new IndexOutOfBoundsException();
    }

    private static class LayoutInfo {
        int fitMode = 0;

        LayoutInfo() {
        }
    }

    public class Element {
        private int mIndex;

        @VisibleForTesting
        Element(int i) {
            mIndex = i;
        }

        public EPImage getEPImage() {
            return PhotoPreviewImageList.this.get(this.mIndex);
        }

        public void setFitMode(int i) {
            ((LayoutInfo) PhotoPreviewImageList.this.mLayoutInfoList.get(this.mIndex)).fitMode = i;
        }

        public int getFitMode() {
            return ((LayoutInfo) PhotoPreviewImageList.this.mLayoutInfoList.get(this.mIndex)).fitMode;
        }
    }

    public static class EpImageWrapper {
        public EPImage epImage;
        public String orgFilename;

        public EpImageWrapper(@NonNull String str, @Nullable String str2, int i) {
            epImage = new EPImage(str, i);
            orgFilename = str2;
        }

        public String getArgumentFilename() {
            String str = orgFilename;
            if (str != null) {
                return str;
            }
            return epImage.getOriginalFileName();
        }
    }
}
