// import 'package:esc_pos_utils/esc_pos_utils.
dart';
// import 'package:esc_pos_printer/esc_pos_printer.dart';
// import 'package:esc_pos_bluetooth/esc_pos_bluetooth.dart';
// import 'package:intl/[Link]';
// import 'package:flutter/[Link]';
// import 'package:nb_posx/database/db_utils/db_constants.dart';
// import 'package:nb_posx/database/models/order_item.dart';
// import 'package:nb_posx/database/db_utils/db_preferences.dart';
// class UniversalPrinterService {
// final String wifiPrinterIp = '[Link]'; // Replace with your printer's
IP
// final int wifiPrinterPort = 9100; // Replace with your printer's port
// Future<void> printReceipt(
// List<OrderItem> items,
// double totalValue,
// String orderType,
// String salesOrderNo,
// BuildContext context) async {
// String promotionString =
// await DBPreferences().getPreference(PROMOTION_RECEIPT);
// bool isPrinted = false;
// // Check and print via USB Printer
// if (await _isUSBPrinterConnected()) {
// await _printViaUSB(items, totalValue, orderType, salesOrderNo);
// isPrinted = true;
// }
// // Check and print via Bluetooth EPOS Printer
// else if (await _isBluetoothPrinterConnected()) {
// await _printViaBluetooth(items, totalValue, orderType, salesOrderNo);
// isPrinted = true;
// }
// // Check and print via WiFi Printer
// else if (await _isWiFiPrinterConnected()) {
// await _printViaWiFi(items, totalValue, orderType, salesOrderNo);
// isPrinted = true;
// }
// // Show popup if no printer is connected
// if (!isPrinted) {
// _showDeviceNotConnectedPopup(context);
// }
// }
// Future<bool> _isUSBPrinterConnected() async {
// // Implement USB printer detection logic here
// // Placeholder for demonstration
// return false;
// }
// Future<bool> _isBluetoothPrinterConnected() async {
// // Placeholder: Replace with actual Bluetooth printer discovery
// // Assumes `_printViaBluetooth` can check connection status
// return await _printViaBluetooth([], 0, '', '');
// }
// Future<bool> _isWiFiPrinterConnected() async {
// final profile = await [Link]();
// final printer = NetworkPrinter(PaperSize.mm80, profile);
// final res = await [Link](wifiPrinterIp, port: wifiPrinterPort);
// if (res == [Link]) {
// [Link]();
// return true;
// }
// return false;
// }
// Future<void> _printViaUSB(List<OrderItem> items, double totalValue,
// String orderType, String salesOrderNo) async {
// // Implement USB printing logic here
// }
// Future<void> _printViaBluetooth(
// List<OrderItem> items,
// double totalValue,
// String orderType,
// String salesOrderNo) async {
// final profile = await [Link]();
// final printer = BluetoothPrinter(PaperSize.mm80, profile);
// // Discover devices
// final printerList = await [Link]();
// if ([Link]) {
// print('No Bluetooth printers found');
// return;
// }
// // Connect to the first available printer
// final bluetoothPrinter = [Link];
// final res = await [Link](bluetoothPrinter);
// if (res == [Link]) {
// await _printContent(printer, items, totalValue, orderType, salesOrderNo);
// [Link]();
// } else {
// print('Failed to connect to Bluetooth printer');
// }
// }
// Future<void> _printViaWiFi(
// List<OrderItem> items,
// double totalValue,
// String orderType,
// String salesOrderNo) async {
// final profile = await [Link]();
// final printer = NetworkPrinter(PaperSize.mm80, profile);
// final res = await [Link](wifiPrinterIp, port: wifiPrinterPort);
// if (res == [Link]) {
// await _printContent(printer, items, totalValue, orderType, salesOrderNo);
// [Link]();
// } else {
// print('Failed to connect to WiFi printer');
// }
// }
// Future<void> _printContent(dynamic printer,
// List<OrderItem> items,
// double totalValue,
// String orderType,
// String salesOrderNo) async {
// String date = DateFormat("dd/MM/yyyy").format([Link]());
// String time = DateFormat("HH:mm").format([Link]());
// String lastFourDigits = [Link]([Link] - 4);
// // Print header
// [Link]('XTC GELATO',
// styles: const PosStyles(align: [Link], bold: true));
// [Link]('XTConICE Gelato Limited',
// styles: const PosStyles(align: [Link]));
// [Link]('Shop 4B, 45-47 Cochrane Street',
// styles: const PosStyles(align: [Link]));
// [Link]('Central, Hong Kong SAR',
// styles: const PosStyles(align: [Link]));
// [Link]('Tel: +852 2541 0500 - [Link]',
// styles: const PosStyles(align: [Link]));
// [Link]();
// [Link](' Check#: $lastFourDigits');
// // Print order details
// [Link]([
// PosColumn(text: 'Date: $date', width: 6),
// PosColumn(text: 'Time: $time', width: 6, styles: const PosStyles(align:
[Link])),
// ]);
// [Link]('Cashier: edna', styles: const PosStyles(align:
[Link]));
// for (var item in items) {
// int itemCount = 1;
// [Link]([
// PosColumn(text: [Link](), width: 2),
// PosColumn(text: [Link], width: 6),
// PosColumn(text: ([Link] *
[Link]).toStringAsFixed(2), width: 2),
// ]);
// itemCount++;
// }
// // Print totals
// [Link]([
// PosColumn(text: 'Sub Total', width: 6, styles: const PosStyles(bold:
true)),
// PosColumn(text: [Link](2), width: 6, styles: const
PosStyles(align: [Link])),
// ]);
// [Link]([
// PosColumn(text: 'Discount 10% - ', width: 6, styles: const PosStyles(bold:
true)),
// PosColumn(text: (totalValue * 0.9).toStringAsFixed(2), width: 6, styles:
const PosStyles(align: [Link])),
// ]);
// [Link]([
// PosColumn(text: 'Total', width: 6, styles: const PosStyles(bold: true)),
// PosColumn(text: [Link](2), width: 6, styles: const
PosStyles(align: [Link], bold: true)),
// ]);
// // Print footer
// [Link]();
// [Link]('Thank You. Please come again.',
// styles: const PosStyles(align: [Link]));
// [Link]('謝謝。歡迎再來。', styles: const PosStyles(align: [Link]));
// [Link]('XTConICE Gelato Limited.',
// styles: const PosStyles(align: [Link]));
// [Link]('Powered by NestorBird',
// styles: const PosStyles(align: [Link]));
// [Link]();
// [Link](await DBPreferences().getPreference(PROMOTION_RECEIPT),
// styles: const PosStyles(align: [Link]));
// [Link](2);
// [Link]();
// }
// void _showDeviceNotConnectedPopup(BuildContext context) {
// showDialog(
// context: context,
// builder: (BuildContext context) {
// return AlertDialog(
// title: Text("Device Not Connected"),
// content: Text("No printer device is connected. Please connect a
printer and try again."),
// actions: <Widget>[
// TextButton(
// child: Text("OK"),
// onPressed: () {
// [Link](context).pop();
// },
// ),
// ],
// );
// },
// );
// }
// }
// import 'package:esc_pos_utils/esc_pos_utils.dart'; // Import the public library
// import 'package:esc_pos_bluetooth/esc_pos_bluetooth.dart';
// import 'package:esc_pos_printer/esc_pos_printer.dart';
// import 'package:intl/[Link]';
// import 'package:flutter/[Link]';
// import 'package:nb_posx/database/db_utils/db_constants.dart';
// import 'package:nb_posx/database/models/order_item.dart';
// import 'package:nb_posx/database/db_utils/db_preferences.dart';
// class UniversalPrinterService {
// final String wifiPrinterIp =
// '[Link]'; // Replace with your printer's IP
// final int wifiPrinterPort = 9100; // Replace with your printer's port
// Future<void> printReceipt(List<OrderItem> items, double totalValue,
// String orderType, String salesOrderNo, BuildContext context) async {
// String promotionString =
// await DBPreferences().getPreference(PROMOTION_RECEIPT);
// bool isPrinted = false;
// // Check and print via Bluetooth Printer
// if (await _isBluetoothPrinterConnected()) {
// await _printViaBluetooth(items, totalValue, orderType, salesOrderNo);
// isPrinted = true;
// }
// // Check and print via WiFi Printer
// else if (await _isWiFiPrinterConnected()) {
// await _printViaWiFi(items, totalValue, orderType, salesOrderNo);
// isPrinted = true;
// }
// // Show popup if no printer is connected
// if (!isPrinted) {
// _showDeviceNotConnectedPopup(context);
// }
// }
// Future<bool> _isBluetoothPrinterConnected() async {
// // Implement Bluetooth printer detection logic here
// // This method assumes you have a list of known devices or can discover them
// // Replace with actual Bluetooth connection logic
// try {
// final profile = await [Link]();
// final printer = BluetoothPrinter(PaperSize.mm80, profile);
// // Here you should implement Bluetooth printer discovery logic
// // The following code is just for illustration
// final printerList = await [Link]();
// if ([Link]) {
// return false;
// }
// // Connect to the first available printer
// final bluetoothPrinter = [Link];
// final res = await [Link](bluetoothPrinter);
// if (res == [Link]) {
// [Link]();
// return true;
// } else {
// return false;
// }
// } catch (e) {
// print('Failed to connect to Bluetooth printer: $e');
// return false;
// }
// }
// Future<bool> _isWiFiPrinterConnected() async {
// final profile = await [Link]();
// final printer = NetworkPrinter(PaperSize.mm80, profile);
// final res = await [Link](wifiPrinterIp, port: wifiPrinterPort);
// if (res == [Link]) {
// [Link]();
// return true;
// }
// return false;
// }
// Future<void> _printViaBluetooth(List<OrderItem> items, double totalValue,
// String orderType, String salesOrderNo) async {
// final profile = await [Link]();
// final printer = BluetoothPrinter(PaperSize.mm80, profile);
// // Discover devices
// final printerList = await [Link]();
// if ([Link]) {
// print('No Bluetooth printers found');
// return;
// }
// // Connect to the first available printer
// final bluetoothPrinter = [Link];
// final res = await [Link](bluetoothPrinter);
// if (res == [Link]) {
// await _printContent(printer, items, totalValue, orderType, salesOrderNo);
// [Link]();
// } else {
// print('Failed to connect to Bluetooth printer');
// }
// }
// Future<void> _printViaWiFi(List<OrderItem> items, double totalValue,
// String orderType, String salesOrderNo) async {
// final profile = await [Link]();
// final printer = NetworkPrinter(PaperSize.mm80, profile);
// final res = await [Link](wifiPrinterIp, port: wifiPrinterPort);
// if (res == [Link]) {
// await _printContent(printer, items, totalValue, orderType, salesOrderNo);
// [Link]();
// } else {
// print('Failed to connect to WiFi printer');
// }
// }
// Future<void> _printContent(dynamic printer, List<OrderItem> items,
// double totalValue, String orderType, String salesOrderNo) async {
// String date = DateFormat("dd/MM/yyyy").format([Link]());
// String time = DateFormat("HH:mm").format([Link]());
// String lastFourDigits = [Link]([Link] - 4);
// // Print header
// [Link]('XTC GELATO',
// styles: PosStyles(align: [Link], bold: true));
// [Link]('XTConICE Gelato Limited',
// styles: PosStyles(align: [Link]));
// [Link]('Shop 4B, 45-47 Cochrane Street',
// styles: PosStyles(align: [Link]));
// [Link]('Central, Hong Kong SAR',
// styles: PosStyles(align: [Link]));
// [Link]('Tel: +852 2541 0500 - [Link]',
// styles: PosStyles(align: [Link]));
// [Link]();
// [Link](' Check#: $lastFourDigits');
// // Print order details
// [Link]([
// PosColumn(text: 'Date: $date', width: 6),
// PosColumn(
// text: 'Time: $time',
// width: 6,
// styles: PosStyles(align: [Link])),
// ]);
// [Link]('Cashier: edna', styles: PosStyles(align: [Link]));
// for (var item in items) {
// int itemCount = 1;
// [Link]([
// PosColumn(text: [Link](), width: 2),
// PosColumn(text: [Link], width: 6),
// PosColumn(
// text: ([Link] * [Link]).toStringAsFixed(2),
// width: 2),
// ]);
// itemCount++;
// }
// // Print totals
// [Link]([
// PosColumn(text: 'Sub Total', width: 6, styles: PosStyles(bold: true)),
// PosColumn(
// text: [Link](2),
// width: 6,
// styles: PosStyles(align: [Link])),
// ]);
// [Link]([
// PosColumn(
// text: 'Discount 10% - ', width: 6, styles: PosStyles(bold: true)),
// PosColumn(
// text: (totalValue * 0.9).toStringAsFixed(2),
// width: 6,
// styles: PosStyles(align: [Link])),
// ]);
// [Link]([
// PosColumn(text: 'Total', width: 6, styles: PosStyles(bold: true)),
// PosColumn(
// text: [Link](2),
// width: 6,
// styles: PosStyles(align: [Link], bold: true)),
// ]);
// // Print footer
// [Link]();
// [Link]('Thank You. Please come again.',
// styles: PosStyles(align: [Link]));
// [Link]('謝謝。歡迎再來。', styles: PosStyles(align: [Link]));
// [Link]('XTConICE Gelato Limited.',
// styles: PosStyles(align: [Link]));
// [Link]('Powered by NestorBird',
// styles: PosStyles(align: [Link]));
// [Link]();
// [Link](await DBPreferences().getPreference(PROMOTION_RECEIPT),
// styles: PosStyles(align: [Link]));
// [Link](2);
// [Link]();
// }
// void _showDeviceNotConnectedPopup(BuildContext context) {
// showDialog(
// context: context,
// builder: (BuildContext context) {
// return AlertDialog(
// title: Text("Device Not Connected"),
// content: Text(
// "No printer device is connected. Please connect a printer and try
again."),
// actions: <Widget>[
// TextButton(
// child: Text("OK"),
// onPressed: () {
// [Link](context).pop();
// },
// ),
// ],
// );
// },
// );
// }
// }