<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.control.Spinner?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.layout.FlowPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Region?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>

<ScrollPane fitToHeight="true" fitToWidth="true" hbarPolicy="AS_NEEDED" vbarPolicy="AS_NEEDED" pannable="true" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.example.petshopdesktop.controllers.SaleController">
   <content>
      <VBox minHeight="-Infinity" minWidth="0.0" maxWidth="Infinity" spacing="10.0" style="-fx-font-size: 14px;">
         <padding>
            <Insets bottom="16.0" left="16.0" right="16.0" top="16.0" />
         </padding>
         <children>
            <HBox alignment="CENTER_LEFT" spacing="12.0" maxWidth="Infinity">
               <children>
                  <VBox spacing="2.0" HBox.hgrow="ALWAYS">
                     <children>
                        <Label text="Sales" textFill="#2c3e50">
                           <font>
                              <Font name="System Bold" size="20.0" />
                           </font>
                        </Label>
                        <HBox spacing="8.0">
                           <children>
                              <Label fx:id="lblModeNote" text="" textFill="#7f8c8d">
                                 <font>
                                    <Font name="System Bold" size="11.0" />
                                 </font>
                              </Label>
                              <Label fx:id="lblStatus" text="" textFill="#16a085" visible="false" managed="true">
                                 <font>
                                    <Font name="System Bold" size="11.0" />
                                 </font>
                              </Label>
                           </children>
                        </HBox>
                     </children>
                  </VBox>
                  <HBox alignment="CENTER_RIGHT" spacing="8.0">
                     <children>
                        <Button fx:id="btnRefund" mnemonicParsing="false" onAction="#btnRefund" prefHeight="32.0" style="-fx-background-color: #FF6b6b; -fx-cursor: hand; -fx-background-radius: 8;" text="Process Refund" textFill="WHITE">
                           <font>
                              <Font name="System Bold" size="14.0" />
                           </font>
                           <padding>
                              <Insets bottom="12.0" left="24.0" right="24.0" top="12.0" />
                           </padding>
                        </Button>
                        <Button fx:id="btnRefresh" mnemonicParsing="false" onAction="#btnRefresh" prefHeight="32.0" prefWidth="96.0" style="-fx-background-color: #4ECDC4; -fx-cursor: hand; -fx-background-radius: 8;" text="Refresh" textFill="WHITE">
                           <font>
                              <Font name="System Bold" size="14.0" />
                           </font>
                           <padding>
                              <Insets bottom="12.0" left="24.0" right="24.0" top="12.0" />
                           </padding>
                        </Button>
                     </children>
                  </HBox>
               </children>
            </HBox>

            <VBox fx:id="vbCreateSale" maxWidth="Infinity" spacing="10.0" style="-fx-background-color: #ffffff; -fx-background-radius: 12; -fx-border-color: #e6e6e6; -fx-border-radius: 12; -fx-border-width: 1;">
               <padding>
                  <Insets bottom="12.0" left="12.0" right="12.0" top="12.0" />
               </padding>
               <children>
                  <Label text="Create Sale" textFill="#2c3e50">
                     <font>
                        <Font name="System Bold" size="13.0" />
                     </font>
                  </Label>
                  <FlowPane hgap="8.0" maxWidth="Infinity" prefWrapLength="680.0" vgap="8.0">
                     <children>
                        <ComboBox fx:id="cbProduct" minWidth="220.0" prefHeight="24.0" prefWidth="320.0" promptText="Select a product" />
                        <Spinner fx:id="spQuantity" prefHeight="24.0" prefWidth="90.0" />
                        <Button fx:id="btnAddToCart" mnemonicParsing="false" onAction="#btnAddToCart" prefHeight="24.0" style="-fx-background-color: #FF6b6b; -fx-cursor: hand; -fx-background-radius: 8;" text="Add" textFill="WHITE">
                           <font>
                              <Font name="System Bold" size="13.0" />
                           </font>
                           <padding>
                              <Insets bottom="8.0" left="18.0" right="18.0" top="8.0" />
                           </padding>
                        </Button>
                        <Button fx:id="btnRemoveSelected" mnemonicParsing="false" onAction="#btnRemoveSelected" prefHeight="24.0" style="-fx-background-color: #34495E; -fx-cursor: hand; -fx-background-radius: 8;" text="Remove Selected" textFill="WHITE">
                           <font>
                              <Font name="System Bold" size="13.0" />
                           </font>
                           <padding>
                              <Insets bottom="8.0" left="18.0" right="18.0" top="8.0" />
                           </padding>
                        </Button>
                     </children>
                  </FlowPane>
                  <FlowPane hgap="8.0" maxWidth="Infinity" prefWrapLength="680.0" vgap="8.0">
                     <children>
                        <ComboBox fx:id="cbCustomer" minWidth="200.0" prefHeight="24.0" prefWidth="260.0" promptText="Customer (optional)" />
                        <Label fx:id="lblLoyaltyPoints" text="" textFill="#16a085" visible="false" managed="false">
                           <font><Font name="System Bold" size="12.0" /></font>
                        </Label>
                        <CheckBox fx:id="chkUseLoyaltyPoints" text="Use Loyalty Points" visible="false" managed="false" />
                        <TextField fx:id="txtCouponCode" prefHeight="24.0" prefWidth="160.0" promptText="Coupon code" />
                        <Button fx:id="btnApplyCoupon" mnemonicParsing="false" onAction="#btnApplyCoupon" prefHeight="24.0" style="-fx-background-color: #27ae60; -fx-cursor: hand; -fx-background-radius: 8;" text="Apply" textFill="WHITE">
                           <font><Font name="System Bold" size="13.0" /></font>
                           <padding><Insets bottom="8.0" left="14.0" right="14.0" top="8.0" /></padding>
                        </Button>
                        <Button fx:id="btnClearCoupon" mnemonicParsing="false" onAction="#btnClearCoupon" prefHeight="24.0" style="-fx-background-color: #7f8c8d; -fx-cursor: hand; -fx-background-radius: 8;" text="Clear" textFill="WHITE">
                           <font><Font name="System Bold" size="13.0" /></font>
                           <padding><Insets bottom="8.0" left="14.0" right="14.0" top="8.0" /></padding>
                        </Button>
                        <Label fx:id="lblCouponStatus" text="" textFill="#27ae60" wrapText="false">
                           <font><Font size="12.0" /></font>
                        </Label>
                     </children>
                  </FlowPane>
                  <TableView fx:id="tvCart" prefHeight="120.0" style="-fx-background-color: white; -fx-background-radius: 10;" VBox.vgrow="ALWAYS">
                     <columns>
                        <TableColumn fx:id="colCartProduct" prefWidth="310.0" text="Product" />
                        <TableColumn fx:id="colCartQty" prefWidth="90.0" text="Qty" />
                        <TableColumn fx:id="colCartUnitPrice" prefWidth="120.0" text="Unit Price" />
                        <TableColumn fx:id="colCartTotal" prefWidth="120.0" text="Total" />
                     </columns>
                  </TableView>
                  <Separator />
                  <HBox alignment="CENTER_LEFT" spacing="12.0" maxWidth="Infinity">
                     <children>
                        <HBox alignment="CENTER_LEFT" spacing="8.0">
                           <children>
                              <Label text="Payment" textFill="#2c3e50">
                                 <font>
                                    <Font name="System Bold" size="13.0" />
                                 </font>
                              </Label>
                              <ComboBox fx:id="cbPaymentMethod" prefHeight="34.0" prefWidth="160.0" />
                           </children>
                        </HBox>
                        <Region HBox.hgrow="ALWAYS" />
                        <VBox spacing="2.0">
                           <children>
                              <HBox spacing="8.0" alignment="CENTER_LEFT">
                                 <children>
                                    <Label text="Subtotal:" textFill="#2c3e50"><font><Font size="12.0" /></font></Label>
                                    <Label fx:id="lblSubtotal" text="" textFill="#2c3e50"><font><Font size="12.0" /></font></Label>
                                 </children>
                              </HBox>
                              <HBox fx:id="hbCouponDiscount" spacing="8.0" alignment="CENTER_LEFT" visible="false" managed="false">
                                 <children>
                                    <Label fx:id="lblCouponDiscountLabel" text="Coupon Discount:" textFill="#27ae60"><font><Font size="12.0" /></font></Label>
                                    <Label fx:id="lblCouponDiscount" text="-$0.00" textFill="#27ae60"><font><Font size="12.0" /></font></Label>
                                 </children>
                              </HBox>
                              <HBox fx:id="hbLoyaltyDiscount" spacing="8.0" alignment="CENTER_LEFT" visible="false" managed="false">
                                 <children>
                                    <Label fx:id="lblLoyaltyDiscountLabel" text="Loyalty Discount:" textFill="#27ae60"><font><Font size="12.0" /></font></Label>
                                    <Label fx:id="lblLoyaltyDiscount" text="-$0.00" textFill="#27ae60"><font><Font size="12.0" /></font></Label>
                                 </children>
                              </HBox>
                              <HBox spacing="8.0" alignment="CENTER_LEFT">
                                 <children>
                                    <Label text="Total:" textFill="#2c3e50"><font><Font name="System Bold" size="13.0" /></font></Label>
                                    <Label fx:id="lblCartTotal" text="" textFill="#2c3e50"><font><Font name="System Bold" size="16.0" /></font></Label>
                                 </children>
                              </HBox>
                           </children>
                        </VBox>
                        <FlowPane hgap="8.0" prefWrapLength="220.0" vgap="8.0">
                           <children>
                              <Button fx:id="btnClearCart" mnemonicParsing="false" onAction="#btnClearCart" prefHeight="36.0" style="-fx-background-color: transparent; -fx-border-color: #FF6b6b; -fx-border-radius: 8; -fx-cursor: hand;" text="Clear" textFill="#FF6b6b">
                                 <font>
                                    <Font name="System Bold" size="13.0" />
                                 </font>
                                 <padding>
                                    <Insets bottom="8.0" left="18.0" right="18.0" top="8.0" />
                                 </padding>
                              </Button>
                              <Button fx:id="btnSaveSale" mnemonicParsing="false" onAction="#btnSaveSale" prefHeight="36.0" style="-fx-background-color: #4ECDC4; -fx-cursor: hand; -fx-background-radius: 8;" text="Save Sale" textFill="WHITE">
                                 <font>
                                    <Font name="System Bold" size="13.0" />
                                 </font>
                                 <padding>
                                    <Insets bottom="8.0" left="18.0" right="18.0" top="8.0" />
                                 </padding>
                              </Button>
                           </children>
                        </FlowPane>
                     </children>
                  </HBox>
               </children>
            </VBox>

            <HBox alignment="CENTER_LEFT" prefHeight="24.0" spacing="10.0" style="-fx-background-color: white; -fx-background-radius: 14; -fx-border-width: 1; -fx-border-radius: 14; -fx-border-color: #e6e6e6;" maxWidth="Infinity">
               <padding>
                  <Insets bottom="10.0" left="15.0" right="15.0" top="10.0" />
               </padding>
               <children>
                  <TextField fx:id="txtSearch" prefHeight="22.0" promptText="Search sales..." style="-fx-border-width: 0; -fx-background-color: transparent;" HBox.hgrow="ALWAYS">
                     <font>
                        <Font size="15.0" />
                     </font>
                  </TextField>
                  <ComboBox fx:id="cbFilterPayment" prefWidth="140.0" promptText="All Payments" />
                  <ComboBox fx:id="cbFilterRefundStatus" prefWidth="140.0" promptText="All Status" />
                  <ComboBox fx:id="cbFilterCustomer" prefWidth="160.0" promptText="All Customers" />
                  <ComboBox fx:id="cbStoreFilter" prefWidth="150.0" promptText="All Stores" visible="false" managed="false" />
               </children>
            </HBox>
            <TableView fx:id="tvSales" prefHeight="270.0" style="-fx-background-color: white; -fx-background-radius: 12; -fx-padding: 2;" VBox.vgrow="ALWAYS">
               <columns>
                  <TableColumn fx:id="colSaleId" minWidth="50.0" prefWidth="60.0" text="ID" />
                  <TableColumn fx:id="colSaleDate" minWidth="150.0" prefWidth="170.0" text="Date" />
                  <TableColumn fx:id="colEmployeeName" minWidth="150.0" prefWidth="160.0" text="Employee" />
                  <TableColumn fx:id="colCustomerName" minWidth="120.0" prefWidth="140.0" text="Customer" />
                  <TableColumn fx:id="colServiceProduct" minWidth="260.0" prefWidth="320.0" text="Product" />
                  <TableColumn fx:id="colSaleQuantity" minWidth="55.0" prefWidth="70.0" text="Qty" />
                  <TableColumn fx:id="colSaleUnitPrice" minWidth="100.0" prefWidth="115.0" text="Unit Price" />
                  <TableColumn fx:id="colSaleTotal" minWidth="100.0" prefWidth="120.0" text="Total" />
                  <TableColumn fx:id="colSalePaymentType" minWidth="95.0" prefWidth="110.0" text="Payment" />
                  <TableColumn fx:id="colStoreName" minWidth="100.0" prefWidth="130.0" text="Store" />
               </columns>
            </TableView>
         </children>
      </VBox>
   </content>
</ScrollPane>
