//
//  ESCDemoController.swift
//  iOSPrinterDemo
//
//  Created by mellow on 2017/4/19.
//  Copyright © 2017年 Mellow. All rights reserved.
//

import Foundation

class ESCViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
    
    var tableView: UITableView?
    var functions: [String]?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.title = "ESC Demo"
        
        self.tableView = UITableView.init(frame: self.view.frame, style: UITableViewStyle.plain)
        self.tableView!.dataSource = self;
        self.tableView!.delegate = self;
        self.view.addSubview(self.tableView!)
        
        self.functions = [NSLocalizedString("Print English text", comment: ""), NSLocalizedString("Print Chinese text", comment: ""), NSLocalizedString("Print barcode", comment: ""), NSLocalizedString("Print bitmap", comment: ""), NSLocalizedString("Print electronic waybill", comment: ""),NSLocalizedString("Print QR code", comment: ""),NSLocalizedString("Print traditional Chinese text", comment: ""),NSLocalizedString("Print Japanese text", comment: ""),NSLocalizedString("Print Korean text", comment: ""),NSLocalizedString("Draw line demo", comment: ""),NSLocalizedString("Print by the command of drawing line", comment: "")]
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(true)
    }
    
    open func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        return self.functions!.count
    }
    
    open func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cellIdentifier = "ESCDemoControllerCell"
        var cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier)
        
        if cell == nil {
            
            cell = UITableViewCell.init(style: UITableViewCellStyle.subtitle, reuseIdentifier: cellIdentifier)
        }
        
        cell!.textLabel!.text = self.functions?[indexPath.row]
        return cell!
    }
    
    open func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        zplTest(withIndexPath: indexPath)
        
    }
    
    // MARK: - Method
    func zplTest(withIndexPath indexPath: IndexPath) {
        let esc = PTTestESC()
        
        switch indexPath.row {
        case 0: esc.printEnglishText();    break;
        case 1: esc.printSimplifiedChineseText();    break;
        case 2: esc.printBarcode();    break;
        case 3: esc.printBitmap();    break;
        case 4: esc.printElectronicSheet();    break;
        case 5: esc.printQRcode();    break;
        case 6: esc.printTraditionalModeCode();    break;
        case 7: esc.printJapanText();    break;
        case 8: esc.printKoreanText();    break;
        case 9: esc.printWithTemplate();  break;
        case 10: esc.drawLineAndRectangle(); break;
        default: break;
        }
    }
}
