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

<!--
/*
* Copyright (C) 2018-2020, 2023 Andrew Gegg
 *
 *	This file is part of the Gardeners Notebook application
 *
  * The Gardeners Notebook application is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/gpl.html>.
 */

/*
    Change log
    2.1.0   Remove Detail_2 - it's not used
    2.2.6   Save button is no longer the defaultButton - never clear when to hit Enter or what it would do
    2.4.0   Display products as a tree by ProductCategory
    2.7.0   Display the ShoppingList as a Drag source to create PurchaseItems
    3.0.6   Trap short form dates to circumvent bug JDK-8269867 in JavaFX
    3.1.0	Use SafeDatePicker.
 */

-->

<?import java.net.URL?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ButtonBar?>
<?import javafx.scene.control.ContextMenu?>
<!--<?import javafx.scene.control.DatePicker?>-->
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TreeTableColumn?>
<?import javafx.scene.control.TreeTableView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>

<?import uk.co.gardennotebook.SafeDatePicker?>

<fx:root hgap="5.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="404.0" prefWidth="600.0" type="javafx.scene.layout.GridPane" vgap="5.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1">
    <stylesheets>
        <URL value="@notebook.css" />
    </stylesheets>

    <columnConstraints>
        <ColumnConstraints hgrow="NEVER" minWidth="10.0" />
        <ColumnConstraints hgrow="NEVER" minWidth="10.0" />
        <ColumnConstraints hgrow="NEVER" minWidth="10.0" />
        <ColumnConstraints hgrow="NEVER" minWidth="10.0" />
        <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
    </columnConstraints>

    <rowConstraints>
        <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="NEVER" />
        <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="NEVER" />
        <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="NEVER" />
        <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="NEVER" />
        <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="ALWAYS" />
        <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="NEVER" />
    </rowConstraints>

    <children>
        <Label alignment="CENTER_RIGHT" prefHeight="17.0" text="%lbl.date" GridPane.columnIndex="0" GridPane.halignment="RIGHT" GridPane.rowIndex="0" />
<!--        <DatePicker id="dtpDate" fx:id="dtpDate" editable="true" prefWidth="150.0" styleClass="notebook-mandatory-field" GridPane.columnIndex="1" GridPane.rowIndex="0" />-->
        <SafeDatePicker id="dtpDate" fx:id="dtpDate" editable="true" prefWidth="150.0" styleClass="notebook-mandatory-field" GridPane.columnIndex="1" GridPane.rowIndex="0" onAction="#dtpDateOnAction" />
        <Label alignment="CENTER_RIGHT" prefHeight="17.0" text="%lbl.deliverydate" GridPane.columnIndex="2" GridPane.halignment="RIGHT" />
<!--        <DatePicker id="dtpDeliveryDate" fx:id="dtpDeliveryDate" editable="true" prefWidth="150.0" GridPane.columnIndex="3" onAction="#dtpDeliveryDateOnAction" />-->
        <SafeDatePicker id="dtpDeliveryDate" fx:id="dtpDeliveryDate" editable="true" prefWidth="150.0" GridPane.columnIndex="3" />

        <Label alignment="CENTER_RIGHT" prefHeight="17.0" text="%lbl.retailer" GridPane.columnIndex="0" GridPane.halignment="RIGHT" GridPane.rowIndex="1" />
        <uk.co.gardennotebook.RetailerCombo id="parentRetailer" fx:id="parentRetailer" editable="true" mandatory="true" prefWidth="150.0" styleClass="notebook-mandatory-field" GridPane.columnIndex="1" GridPane.rowIndex="1" />

        <Label alignment="CENTER_RIGHT" prefHeight="17.0" text="%lbl.totalprice" GridPane.columnIndex="0" GridPane.halignment="RIGHT" GridPane.rowIndex="2" />
        <TextField id="numTotalPrice" fx:id="numTotalPrice" editable="true" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="2" />

        <Label alignment="CENTER_RIGHT" prefHeight="17.0" text="%lbl.orderno" GridPane.columnIndex="0" GridPane.halignment="RIGHT" GridPane.rowIndex="3" />
        <TextField id="fldOrderNo" fx:id="fldOrderNo" editable="true" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="3" />
        <Label alignment="CENTER_RIGHT" prefHeight="17.0" text="%lbl.invoiceno" GridPane.columnIndex="2" GridPane.halignment="RIGHT" GridPane.rowIndex="3" />
        <TextField id="fldInvoiceNo" fx:id="fldInvoiceNo" editable="true" prefWidth="150.0" GridPane.columnIndex="3" GridPane.rowIndex="3" />

        <SplitPane dividerPositions="0.20, 0.60" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity"
                   orientation="VERTICAL" GridPane.columnIndex="0" GridPane.columnSpan="2147483647" GridPane.hgrow="ALWAYS" GridPane.rowIndex="4"
                   GridPane.vgrow="ALWAYS">
            <GridPane>
                <columnConstraints>
                    <ColumnConstraints hgrow="ALWAYS" maxWidth="1.7976931348623157E308" minWidth="10.0"/>
                </columnConstraints>
                <rowConstraints>
                    <RowConstraints minHeight="10.0" vgrow="NEVER"/>
                    <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="ALWAYS"/>
                </rowConstraints>
                <padding>
                    <Insets bottom="5.0"/>
                </padding>
                <Label prefHeight="17.0" text="%lbl.comments" GridPane.halignment="LEFT" GridPane.rowIndex="0" GridPane.valignment="TOP"/>
                <TableView id="tbvComment" fx:id="tbvComment" editable="true" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="0"
                           GridPane.rowIndex="1">
                    <columns>
                        <TableColumn fx:id="tbvCommentDate" minWidth="50.0" prefWidth="-1.0" text="%col.comment.date"/>
                        <TableColumn fx:id="tbvCommentText" minWidth="50.0" prefWidth="-1.0" text="%col.comment.text"/>
                    </columns>
                </TableView>
            </GridPane>

            <GridPane>
                <columnConstraints>
                    <ColumnConstraints hgrow="ALWAYS" maxWidth="1.7976931348623157E308" minWidth="10.0"/>
                </columnConstraints>
                <rowConstraints>
                    <RowConstraints minHeight="10.0" vgrow="NEVER"/>
                    <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="ALWAYS"/>
                </rowConstraints>
                <padding>
                    <Insets bottom="5.0"/>
                </padding>
                <Label text="%lbl.purchaseitems" GridPane.halignment="LEFT" GridPane.rowIndex="0" GridPane.valignment="TOP"/>
                <!-- The PurchaseItems table must be editable so that new items can be entered directly but existing products must NOT be editable
                        This is enforced in the code
                    -->
                <TableView id="tbvItems" fx:id="tbvItems" editable="true" onDragDropped="#tbvItemsOnDragDropped" onDragOver="#tbvItemsOnDragOver"
                           prefHeight="91.0" prefWidth="483.0" GridPane.rowIndex="1">
                    <columns>
                        <TableColumn text="%col.product">
                            <columns>
                                <TableColumn id="tbvPIProductCategory" fx:id="tbvPIProductCategory" prefWidth="75.0" text="%col.product.category"/>
                                <TableColumn id="tbvPIProductName" fx:id="tbvPIProductName" prefWidth="75.0" text="%col.product.name"/>
                                <TableColumn id="tbvPIProductDetail" fx:id="tbvPIProductDetail" prefWidth="75.0" text="%col.product.detail_1"/>
                                <TableColumn id="tbvPIProductBrand" fx:id="tbvPIProductBrand" prefWidth="75.0" text="%col.product.brand"/>
                            </columns>
                        </TableColumn>
                        <TableColumn id="tbvPIQuantity" fx:id="tbvPIQuantity" style="-fx-alignment: center-right;" text="%col.quantity"/>
                        <TableColumn id="tbvPIUnit" fx:id="tbvPIUnit" text="%col.unit"/>
                        <TableColumn id="tbvPIItemCost" fx:id="tbvPIItemCost" prefWidth="75.0" style="-fx-alignment: center-right;" text="%col.itemcost"/>
                        <TableColumn text="%col.purchase.watchfor">
                            <columns>
                                <TableColumn id="tbvPIWatchForHusbandry" fx:id="tbvPIWatchForHusbandry" text="%col.purchase.watchforhusbandry" />
                                <TableColumn id="tbvPIWatchForGroundwork" fx:id="tbvPIWatchForGroundwork" text="%col.purchase.watchforgroundwork" />
                                <TableColumn id="tbvPIWatchForAfter" fx:id="tbvPIWatchForAfter" text="%col.purchase.after" />
                            </columns>
                        </TableColumn >
                        <TableColumn id="tbvPIComment" fx:id="tbvPIComment" prefWidth="75.0" text="%col.comment"/>
                    </columns>
                    <contextMenu>
                        <ContextMenu onShowing="#ctxmnuTopOnAction">
                            <items>
                                <MenuItem id="ctxmnuDelete" fx:id="ctxmnuDelete" onAction="#ctxmnuDeleteOnAction" text="%menu.delete"/>
                                <Menu id="ctxmnuTopHistory" fx:id="ctxmnuTopHistory" mnemonicParsing="false" text="%menu.history">
                                    <MenuItem id="ctxmnuDescendants" fx:id="ctxmnuDescendants" onAction="#ctxmnuDescendantsOnAction"
                                              text="%menu.descendants"/>
                                    <Menu id="ctxmnuNewDescendant" fx:id="ctxmnuNewDescendant" mnemonicParsing="false" text="%menu.newdescendant">
                                        <MenuItem id="ctxmnuNewHusbandry" fx:id="ctxmnuNewHusbandry" mnemonicParsing="true"
                                                  onAction="#ctxmnuDescendantHusbandryOnAction" text="%menu.newhusbandry"/>
                                        <MenuItem id="ctxmnuNewGroundwork" fx:id="ctxmnuNewGroundwork" mnemonicParsing="true"
                                                  onAction="#ctxmnuDescendantGroundworkOnAction" text="%menu.newgroundwork"/>
                                        <MenuItem id="ctxmnuNewAffliction" fx:id="ctxmnuNewAffliction" mnemonicParsing="true"
                                                  onAction="#ctxmnuDescendantAfflictionOnAction" text="%menu.newaffliction"/>
                                    </Menu>
                                </Menu>
                            </items>
                        </ContextMenu>
                    </contextMenu>
                </TableView>
            </GridPane>

            <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
                <TabPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
                    <Tab text="%tab.product" closable="false">
                        <GridPane>
                            <columnConstraints>
                                <ColumnConstraints hgrow="ALWAYS" maxWidth="1.7976931348623157E308" minWidth="10.0"/>
                            </columnConstraints>
                            <rowConstraints>
                                <RowConstraints minHeight="10.0" vgrow="NEVER"/>
                                <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="ALWAYS"/>
                            </rowConstraints>
                            <padding>
                                <Insets top="5.0"/>
                            </padding>
                            <Label text="%lbl.products" GridPane.halignment="LEFT" GridPane.rowIndex="0" GridPane.valignment="TOP"/>
                            <!-- The Products table is essentially NOT editable, only the description and comment columns -->
                            <TreeTableView id="tbvProducts" fx:id="tbvProducts" editable="true" showRoot="false" prefHeight="200.0"
                                           prefWidth="200.0" GridPane.rowIndex="1">
                                <columns>
                                    <TreeTableColumn id="tbvProdProductName" fx:id="tbvProdProductName" editable="false" prefWidth="75.0"
                                                     text="%col.product.name"/>
                                    <TreeTableColumn id="tbvProdProductDetail" fx:id="tbvProdProductDetail" editable="false" prefWidth="75.0"
                                                     text="%col.product.detail_1"/>
                                    <!--            <TableColumn id="tbvProdProductDetail_2" fx:id="tbvProdProductDetail_2" editable="false" prefWidth="75.0" text="%col.product.detail_2" />   -->
                                    <TreeTableColumn id="tbvProdProductBrand" fx:id="tbvProdProductBrand" editable="false" prefWidth="75.0"
                                                     text="%col.product.brand"/>
                                    <TreeTableColumn id="tbvProdProductDescription" fx:id="tbvProdProductDescription" editable="true"
                                                     prefWidth="75.0" text="%col.product.description"/>
                                    <TreeTableColumn id="tbvProdComment" fx:id="tbvProdComment" editable="true" prefWidth="75.0"
                                                     text="%col.comment"/>
                                </columns>
                                <contextMenu>
                                    <ContextMenu onShowing="#ctxmnuProdOnShowing">
                                        <items>
                                            <MenuItem id="ctxmnuProdCopyToPU" fx:id="ctxmnuProdCopyToPU" onAction="#ctxmnuProdCopyToPUOnAction"
                                                      text="%menu.purchase.copyprod"/>
                                        </items>
                                    </ContextMenu>
                                </contextMenu>
                            </TreeTableView>
                        </GridPane>
                    </Tab>
                    <Tab text="%tab.shoppinglist" closable="false">
                        <GridPane>
                            <columnConstraints>
                                <ColumnConstraints hgrow="ALWAYS" minWidth="10.0" prefWidth="100.0"/>
                            </columnConstraints>
                            <rowConstraints>
                                <RowConstraints minHeight="10.0" vgrow="NEVER"/>
                                <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="ALWAYS"/>
                            </rowConstraints>
                            <padding>
                                <Insets top="5.0"/>
                            </padding>
                            <Label text="%lbl.shoppinglist" GridPane.halignment="LEFT" GridPane.rowIndex="0" GridPane.valignment="TOP"/>
                            <TableView id="tblShoppingList" fx:id="tblShoppingList" editable="true" minHeight="10"
                                       maxHeight="1.7976931348623157E308" prefHeight="515.0" prefWidth="600.0"
                                       GridPane.rowIndex="1">
                                <columns>
                                    <TableColumn text="%col.product">
                                        <columns>
                                            <TableColumn id="tbvShopProductCategory" fx:id="tbvShopProductCategory" editable="false"
                                                         prefWidth="75.0" text="%col.product.category"/>
                                            <TableColumn id="tbvShopProductName" fx:id="tbvShopProductName" editable="false" prefWidth="75.0"
                                                         text="%col.product.name"/>
                                            <TableColumn id="tbvShopProductDetail" fx:id="tbvShopProductDetail" editable="false"
                                                         prefWidth="75.0" text="%col.product.detail_1"/>
                                            <TableColumn id="tbvShopProductBrand" fx:id="tbvShopProductBrand" editable="false" prefWidth="75.0"
                                                         text="%col.product.brand"/>
                                        </columns>
                                    </TableColumn>
                                    <TableColumn id="tbvShopNonSpecific" fx:id="tbvShopNonSpecific" editable="true" prefWidth="75.0"
                                                 text="%col.shop.nonspecific"/>
                                    <TableColumn id="tbvShopComment" fx:id="tbvShopComment" editable="true" prefWidth="75.0"
                                                 text="%col.comment"/>
                                </columns>
                                <contextMenu>
                                    <ContextMenu onShowing="#ctxmnuShopOnShowing">
                                        <items>
                                            <MenuItem id="ctxmnuShopMarkDelete" fx:id="ctxmnuShopMarkDelete"
                                                      onAction="#ctxmnuShopMarkDeleteOnAction" text="%menu.purchase.markdelete"/>
                                            <MenuItem id="ctxmnuShopNoDelete" fx:id="ctxmnuShopNoDelete" onAction="#ctxmnuShopNoDeleteOnAction"
                                                      text="%menu.purchase.nodelete"/>
                                            <MenuItem id="ctxmnuShopCopyToPU" fx:id="ctxmnuShopCopyToPU" onAction="#ctxmnuShopCopyToPUOnAction"
                                                      text="%menu.purchase.copyprod"/>
                                        </items>
                                    </ContextMenu>
                                </contextMenu>
                            </TableView>
                        </GridPane>
                    </Tab>
                </TabPane>
            </AnchorPane>

        </SplitPane>

        <ButtonBar prefHeight="40.0" prefWidth="200.0" GridPane.columnSpan="2147483647" GridPane.rowIndex="5">
            <buttons>
                <Button id="btnCancel" cancelButton="true" mnemonicParsing="false" onAction="#btnCancelOnAction" styleClass="notebook-cmd-button" text="%btn.cancel" />
                <Button id="btnSave" fx:id="btnSave" mnemonicParsing="false" onAction="#btnSaveOnAction" styleClass="notebook-cmd-button" text="%btn.save" />   <!-- defaultButton="true" -->
                <Button id="btnDelete" fx:id="btnDelete" mnemonicParsing="false" onAction="#btnDeleteOnAction" styleClass="notebook-cmd-button" text="%btn.delete" />
            </buttons>
        </ButtonBar>

    </children>

    <padding>
        <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
    </padding>

</fx:root>
