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

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.control.cell.*?>
<?import javafx.scene.layout.*?>
<?import org.controlsfx.control.CheckComboBox?>
<?import org.controlsfx.glyphfont.Glyph?>
<?import ru.trader.view.support.cells.DistanceCell?>
<?import ru.trader.view.support.NumberField?>
<GridPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
          fx:controller="ru.trader.controllers.SearchController">

    <fx:define><Insets fx:id="separator_margin" top="10" bottom="10"/></fx:define>

    <columnConstraints>
        <ColumnConstraints minWidth="270" maxWidth="270"/>
        <ColumnConstraints fillWidth="true"/>
    </columnConstraints>

    <TitledPane text="%market.systems" prefHeight="500" collapsible="false">
        <GridPane vgap="4">
            <columnConstraints>
                <ColumnConstraints minWidth="100"/>
                <ColumnConstraints minWidth="150" maxWidth="150"/>
            </columnConstraints>
            <Label text="%search.text.from" />
            <HBox GridPane.columnIndex="1">
                <TextField fx:id="sourceText" prefWidth="150" />
                <Button minWidth="30" onAction="#currentAsSource"><graphic><Glyph text="FontAwesome|MAP_MARKER"/></graphic></Button>
            </HBox>
            <HBox GridPane.columnSpan="2" GridPane.rowIndex="1" spacing="10" alignment="BOTTOM_CENTER">
                <RadioButton fx:id="rbSeller" text="%market.order.seller"/>
                <RadioButton fx:id="rbBuyer" text="%market.order.buyer" />
            </HBox>
            <Label text="%search.text.item" GridPane.rowIndex="2"/>
            <TextField fx:id="itemText" prefWidth="150" GridPane.columnIndex="1" GridPane.rowIndex="2"/>
            <HBox GridPane.columnIndex="1" GridPane.rowIndex="3" spacing="4" alignment="CENTER">
                <ListView fx:id="itemsList" HBox.hgrow="ALWAYS" maxHeight="100"/>
                <VBox spacing="4">
                    <Button prefWidth="30" onAction="#addItem"><graphic><Glyph text="FontAwesome|PLUS"/></graphic></Button>
                    <Button prefWidth="30" onAction="#removeItem"><graphic><Glyph text="FontAwesome|MINUS"/></graphic></Button>
                    <Button prefWidth="30" onAction="#clearItems"><graphic><Glyph text="FontAwesome|TRASH"/></graphic></Button>
                </VBox>
            </HBox>
            <Label text="%search.text.distance" GridPane.rowIndex="4" />
            <NumberField fx:id="distance" GridPane.columnIndex="1" GridPane.rowIndex="4" />
            <Label text="%label.station.type" GridPane.rowIndex="5"/>
            <CheckComboBox fx:id="stationTypes" prefWidth="150" GridPane.columnIndex="1" GridPane.rowIndex="5" />
            <Label text="%label.station.services" GridPane.rowIndex="6"/>
            <CheckComboBox fx:id="services" prefWidth="150" GridPane.columnIndex="1" GridPane.rowIndex="6"/>
            <Separator GridPane.columnSpan="2" GridPane.rowIndex="7" GridPane.margin="$separator_margin"/>
            <HBox GridPane.columnSpan="2" GridPane.rowIndex="8" spacing="10" alignment="CENTER">
                <Button text="%search.button.find" onAction="#searchStations" />
            </HBox>
        </GridPane>
    </TitledPane>
    <TableView fx:id="tblResults" GridPane.columnIndex="1" GridPane.hgrow="ALWAYS" GridPane.vgrow="ALWAYS">
        <columns>
            <TableColumn minWidth="200.0" text="%market.system">
                <cellValueFactory><PropertyValueFactory property="system"/></cellValueFactory>
            </TableColumn>
            <TableColumn minWidth="200.0" text="%market.station">
                <cellValueFactory><PropertyValueFactory property="station"/></cellValueFactory>
            </TableColumn>
            <TableColumn minWidth="180.0" text="%market.item">
                <cellValueFactory><PropertyValueFactory property="name"/></cellValueFactory>
            </TableColumn>
            <TableColumn minWidth="110.0" text="%market.offer.price">
                <cellValueFactory><PropertyValueFactory property="price"/></cellValueFactory>
            </TableColumn>
            <TableColumn minWidth="110.0" text="%market.offer.supply">
                <cellValueFactory><PropertyValueFactory property="count"/></cellValueFactory>
            </TableColumn>
            <TableColumn minWidth="110.0" text="%market.order.distance" fx:id="sortColumn" sortType="ASCENDING">
                <cellFactory><DistanceCell /></cellFactory>
                <cellValueFactory><PropertyValueFactory property="distance"/></cellValueFactory>
            </TableColumn>
        </columns>
        <columnResizePolicy>
            <TableView fx:constant="UNCONSTRAINED_RESIZE_POLICY"/>
        </columnResizePolicy>
        <sortOrder>
            <fx:reference source="sortColumn"/>
        </sortOrder>
    </TableView>
</GridPane>
