import * as Chrome from "@point_of_sale/../tests/tours/utils/chrome_util";
import * as Dialog from "@point_of_sale/../tests/tours/utils/dialog_util";
import * as Order from "@point_of_sale/../tests/tours/utils/generic_components/order_widget_util";
import * as PaymentScreen from "@point_of_sale/../tests/tours/utils/payment_screen_util";
import * as ProductScreen from "@point_of_sale/../tests/tours/utils/product_screen_util";
import * as ReceiptScreen from "@point_of_sale/../tests/tours/utils/receipt_screen_util";
import * as TicketScreen from "@point_of_sale/../tests/tours/utils/ticket_screen_util";
import { inLeftSide } from "@point_of_sale/../tests/tours/utils/common";
import { registry } from "@web/core/registry";

/**
 * Sell two lines, pay, then refund the whole ticket with a single click on the
 * button this module adds. The destination order must end up with every line
 * negated at its full quantity, without touching the numpad.
 */
registry.category("web_tour.tours").add("pos_full_refund_tour", {
  steps: () =>
    [
      Chrome.startPoS(),
      Dialog.confirm("Open Register"),
      ProductScreen.addOrderline("Desk Pad", "2", "3"),
      ProductScreen.addOrderline("Letter Tray", "3", "2"),
      ProductScreen.clickPayButton(),
      PaymentScreen.clickPaymentMethod("Bank"),
      PaymentScreen.clickValidate(),
      ReceiptScreen.isShown(),
      ReceiptScreen.clickNextOrder(),

      ProductScreen.clickRefund(),
      TicketScreen.selectOrder("-0001"),
      TicketScreen.clickControlButton("Do Full Refund"),

      { ...ProductScreen.back(), isActive: ["mobile"] },
      ProductScreen.isShown(),
      inLeftSide([
        ...Order.hasLine("Desk Pad", "-2"),
        ...Order.hasLine("Letter Tray", "-3"),
      ]),
    ].flat(),
});
