package com.joe.print.mvp.print;

import android.content.Context;
import android.graphics.Bitmap;

import com.gingersoft.gsa.cloud.base.utils.toast.ToastUtils;
import com.gingersoft.gsa.cloud.print.PrintDataMaker;
import com.gingersoft.gsa.cloud.print.PrinterWriter;
import com.gingersoft.gsa.cloud.print.PrinterWriter58mm;
import com.gingersoft.gsa.cloud.print.PrinterWriter80mm;
import com.joe.print.R;

import java.util.ArrayList;
import java.util.List;

/**
 * 打印測試
 * 测试数据生成
 */
public class TestPrintDataMaker implements PrintDataMaker {

    private Context context;
    //    private String qr;
    private int width;
    private int height;

    public TestPrintDataMaker(Context context, int width, int height) {
        this.context = context;
//        this.qr = qr;
        this.width = width;
        this.height = height;
    }

    @Override
    public List<byte[]> getPrintData(int type) {
        ArrayList<byte[]> data = new ArrayList<>();
        try {
            PrinterWriter printer;
            printer = type == PrinterWriter58mm.TYPE_58 ? new PrinterWriter58mm(height, width) : new PrinterWriter80mm(height, width);
            printer.setAlignCenter();
            data.add(printer.getDataAndReset());
            ArrayList<byte[]> image = printer.getImageByte(context.getResources(), R.mipmap.ic_launcher);
            data.addAll(image);

            List<Bitmap> bitmaps = PrintUtils.getPrintBitmap(context, -1, width);//根據打印類型獲得不同的bitmap
            if (bitmaps.size() <= 0) {
                ToastUtils.show(context, "打印失敗");
                return null;
            }
            for (int i = 0; i < bitmaps.size(); i++) {
                ArrayList<byte[]> image1 = printer.getImageByte(bitmaps.get(i));
                data.addAll(image1);//draw2PxPoint2(bitmaps.get(i)
                printer.printLineFeed();
                printer.printLineFeed();
                printer.printLineFeed();
                printer.printLineFeed();
                printer.printLineFeed();
                printer.feedPaperCutPartial();
            }
            data.add(printer.getDataAndReset());
//            printer.setAlignLeft();
//            printer.printLine();
//            printer.printLineFeed();
//
//            printer.printLineFeed();
//            printer.setAlignCenter();
//            printer.setEmphasizedOn();
//            printer.setFontSize(1);
//            printer.print("Selftest");
//            printer.printLineFeed();
//            printer.setFontSize(0);
//            printer.setEmphasizedOff();
//            printer.printLineFeed();
//
//            printer.print("Gingersoft");
//            printer.printLineFeed();
//            printer.print("客服电话：××××××××");
//            printer.printLineFeed();
//
//            printer.setAlignLeft();
//            printer.printLineFeed();
//
//            printer.print("订单号：88888888888888888");
//            printer.printLineFeed();
//
//            printer.print("预计送达：" +
//                    new SimpleDateFormat("yyyy/MM/dd HH:mm", Locale.getDefault())
//                            .format(new Date(System.currentTimeMillis())));
//            printer.printLineFeed();
//
//            printer.setEmphasizedOn();
//            printer.print("#8（已付款）");
//            printer.printLineFeed();
//            printer.print("××区××路×××大厦××楼×××室");
//            printer.printLineFeed();
//            printer.setEmphasizedOff();
//            printer.printLineFeed();
//            printer.print("备注：多加点辣椒，多加点香菜，多加点酸萝卜，多送点一次性手套");
//            printer.printLineFeed();
//
//            printer.printLine();
//            printer.printLineFeed();
//            printer.printLineFeed();
//            printer.printLineFeed();

            data.add(printer.getDataAndClose());
            return data;
        } catch (Exception e) {
            return new ArrayList<>();
        }
    }
}
