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

<?import javafx.geometry.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.control.Spinner?>
<?import javafx.scene.control.ToggleButton?>
<?import javafx.scene.control.ToggleGroup?>
<?import javafx.scene.control.Separator?>
<?import tornadofx.control.DateTimePicker?>
<?import tornadofx.control.Form?>
<?import tornadofx.control.Fieldset?>
<?import tornadofx.control.Field?>
<?import org.controlsfx.control.SegmentedButton?>
<?import com.sparrowwallet.sparrow.control.CopyableLabel?>
<?import com.sparrowwallet.sparrow.control.IdLabel?>
<?import com.sparrowwallet.sparrow.control.CoinLabel?>
<?import javafx.scene.control.Button?>
<?import org.controlsfx.glyphfont.Glyph?>
<?import javafx.scene.control.ComboBox?>
<?import com.sparrowwallet.drongo.protocol.SigHash?>
<?import javafx.collections.FXCollections?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Hyperlink?>
<?import com.sparrowwallet.sparrow.control.SignaturesProgressBar?>
<?import javafx.scene.control.ProgressBar?>
<?import javafx.scene.control.Tooltip?>
<?import com.sparrowwallet.sparrow.control.DynamicForm?>

<GridPane hgap="10.0" vgap="10.0" styleClass="tx-pane" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.sparrowwallet.sparrow.transaction.HeadersController" stylesheets="@headers.css, @transaction.css, @../general.css">
   <padding>
      <Insets left="25.0" right="25.0" top="25.0" />
   </padding>
    <columnConstraints>
        <ColumnConstraints percentWidth="50" />
        <ColumnConstraints percentWidth="50" />
    </columnConstraints>
   <rowConstraints>
      <RowConstraints />
   </rowConstraints>
    <Form GridPane.columnIndex="0" GridPane.rowIndex="0" GridPane.columnSpan="2">
        <Fieldset text="Transaction" inputGrow="SOMETIMES" wrapWidth="620">
            <Field text="Txid:" styleClass="label-button">
                <IdLabel fx:id="id"/>
                <Button maxWidth="25" minWidth="-Infinity" prefWidth="30" text="Cy" onAction="#copyId">
                    <graphic>
                        <Glyph fontFamily="FontAwesome" icon="COPY" prefWidth="15" />
                    </graphic>
                </Button>
            </Field>
        </Fieldset>
    </Form>

    <Separator GridPane.columnIndex="0" GridPane.rowIndex="1" GridPane.columnSpan="2" styleClass="form-separator"/>

    <Form GridPane.columnIndex="0" GridPane.rowIndex="2">
        <Fieldset text="Headers" inputGrow="SOMETIMES">
            <Field text="Version:">
                <Spinner fx:id="version" prefWidth="60" editable="true" />
            </Field>
            <Field text="Type:">
                <CopyableLabel fx:id="segwit" />
            </Field>
        </Fieldset>
    </Form>

    <Form GridPane.columnIndex="1" GridPane.rowIndex="2">
        <Fieldset fx:id="locktimeFieldset" text="Absolute Locktime" inputGrow="SOMETIMES">
            <Field text="Type:">
                <SegmentedButton>
                    <toggleGroup>
                        <ToggleGroup fx:id="locktimeToggleGroup" />
                    </toggleGroup>
                    <buttons>
                        <ToggleButton fx:id="locktimeNoneType" text="Disabled" userData="none" toggleGroup="$locktimeToggleGroup" />
                        <ToggleButton fx:id="locktimeBlockType" text="Block" userData="block" toggleGroup="$locktimeToggleGroup" />
                        <ToggleButton fx:id="locktimeDateType" text="Date" userData="date" toggleGroup="$locktimeToggleGroup" />
                    </buttons>
                </SegmentedButton>
            </Field>
            <Field fx:id="locktimeNoneField" text="Block:">
                <Spinner fx:id="locktimeNone" disable="true" prefWidth="120"/>
            </Field>
            <Field fx:id="locktimeBlockField" text="Block:">
                <Spinner fx:id="locktimeBlock" editable="true" prefWidth="120"/>
                <Hyperlink fx:id="locktimeCurrentHeight" text="Set current height" onAction="#setLocktimeToCurrentHeight" />
                <Label fx:id="futureBlockWarning">
                    <graphic>
                        <Glyph fontFamily="Font Awesome 5 Free Solid" fontSize="12" icon="EXCLAMATION_TRIANGLE" styleClass="future-warning" />
                    </graphic>
                    <tooltip>
                        <Tooltip text="Future block specified - transaction will not be mined until this block"/>
                    </tooltip>
                </Label>
            </Field>
            <Field fx:id="locktimeDateField" text="Date:">
                <DateTimePicker fx:id="locktimeDate" prefWidth="180"/>
                <Label fx:id="futureDateWarning">
                    <graphic>
                        <Glyph fontFamily="Font Awesome 5 Free Solid" fontSize="12" icon="EXCLAMATION_TRIANGLE" styleClass="future-warning" />
                    </graphic>
                    <tooltip>
                        <Tooltip text="Future date specified - transaction will not be mined until this date"/>
                    </tooltip>
                </Label>
            </Field>
        </Fieldset>
    </Form>

    <Separator GridPane.columnIndex="0" GridPane.rowIndex="3" GridPane.columnSpan="2" styleClass="form-separator"/>

    <Form GridPane.columnIndex="0" GridPane.rowIndex="4">
        <Fieldset text="Size" inputGrow="SOMETIMES">
            <Field text="Bytes:">
                <CopyableLabel fx:id="size" />
            </Field>
            <Field text="vBytes:">
                <CopyableLabel fx:id="virtualSize" />
            </Field>
        </Fieldset>
    </Form>

    <Form GridPane.columnIndex="1" GridPane.rowIndex="4">
        <Fieldset text="Fee" inputGrow="SOMETIMES">
            <Field text="Amount:">
                <CoinLabel fx:id="fee" />
            </Field>
            <Field text="Rate:">
                <CopyableLabel fx:id="feeRate" />
            </Field>
        </Fieldset>
    </Form>

    <Separator GridPane.columnIndex="0" GridPane.rowIndex="5" GridPane.columnSpan="2" styleClass="form-separator"/>

    <DynamicForm fx:id="blockchainForm" GridPane.columnIndex="0" GridPane.columnSpan="2" GridPane.rowIndex="6">
        <Fieldset text="Blockchain" inputGrow="SOMETIMES">
            <Field text="Status:">
                <Label fx:id="blockStatus" contentDisplay="RIGHT" graphicTextGap="5" />
            </Field>
            <Field fx:id="blockHeightField" text="Block Height:">
                <CopyableLabel fx:id="blockHeight" />
            </Field>
            <Field fx:id="blockTimestampField" text="Timestamp:">
                <CopyableLabel fx:id="blockTimestamp" />
            </Field>
            <Field fx:id="blockHashField" text="Block Hash:">
                <IdLabel fx:id="blockHash" />
            </Field>
        </Fieldset>
    </DynamicForm>

    <Form fx:id="signingWalletForm" GridPane.columnIndex="0" GridPane.rowIndex="6">
        <Fieldset text="Signatures" inputGrow="SOMETIMES">
            <Field text="Signing Wallet:">
                <ComboBox fx:id="signingWallet" />
                <Label fx:id="noWalletsWarning" graphicTextGap="5" text="No open wallets can sign. ">
                    <graphic>
                        <Glyph fontFamily="Font Awesome 5 Free Solid" fontSize="12" icon="EXCLAMATION_CIRCLE" />
                    </graphic>
                </Label>
                <Hyperlink fx:id="noWalletsWarningLink" text="Open wallet?" onAction="#openWallet" />
            </Field>
        </Fieldset>
    </Form>

    <Form fx:id="sigHashForm" GridPane.columnIndex="1" GridPane.rowIndex="6">
        <Fieldset text="" inputGrow="SOMETIMES">
            <Field text="Sighash:">
                <ComboBox fx:id="sigHash">
                    <items>
                        <FXCollections fx:factory="observableArrayList">
                            <SigHash fx:constant="ALL" />
                            <SigHash fx:constant="NONE" />
                            <SigHash fx:constant="SINGLE" />
                            <SigHash fx:constant="ANYONECANPAY_ALL" />
                            <SigHash fx:constant="ANYONECANPAY_NONE" />
                            <SigHash fx:constant="ANYONECANPAY_SINGLE" />
                        </FXCollections>
                    </items>
                </ComboBox>
            </Field>
        </Fieldset>
    </Form>

    <VBox fx:id="finalizeButtonBox" styleClass="signatures-buttons" GridPane.columnIndex="0" GridPane.columnSpan="2" GridPane.rowIndex="7">
        <Button fx:id="finalizeTransaction" graphicTextGap="5" text="Finalize Transaction for Signing" prefWidth="Infinity" defaultButton="true" onAction="#finalizeTransaction">
            <graphic>
                <Glyph fontFamily="Font Awesome 5 Free Solid" fontSize="10" icon="LOCK" />
            </graphic>
        </Button>
    </VBox>

    <Form fx:id="signaturesForm" GridPane.columnIndex="0" GridPane.columnSpan="2" GridPane.rowIndex="6">
        <Fieldset text="Signatures" inputGrow="SOMETIMES">
            <VBox>
                <SignaturesProgressBar fx:id="signaturesProgressBar" />
                <ProgressBar fx:id="broadcastProgressBar" maxWidth="Infinity" prefHeight="50" />
            </VBox>
            <VBox>
                <HBox fx:id="signButtonBox" styleClass="signatures-buttons" spacing="20">
                    <SegmentedButton HBox.hgrow="ALWAYS">
                        <buttons>
                            <ToggleButton HBox.hgrow="ALWAYS" text="Show QR" contentDisplay="TOP" wrapText="true" textAlignment="CENTER" onAction="#showPSBT">
                                <graphic>
                                    <Glyph fontFamily="Font Awesome 5 Free Solid" fontSize="20" icon="QRCODE" />
                                </graphic>
                            </ToggleButton>
                            <ToggleButton HBox.hgrow="ALWAYS" text="Scan QR" contentDisplay="TOP" wrapText="true" textAlignment="CENTER" onAction="#scanPSBT">
                                <graphic>
                                    <Glyph fontFamily="Font Awesome 5 Free Solid" fontSize="20" icon="CAMERA" />
                                </graphic>
                            </ToggleButton>
                        </buttons>
                    </SegmentedButton>
                    <SegmentedButton HBox.hgrow="ALWAYS">
                        <buttons>
                            <ToggleButton HBox.hgrow="ALWAYS" text="Save PSBT" contentDisplay="TOP" wrapText="true" textAlignment="CENTER" onAction="#savePSBT">
                                <graphic>
                                    <Glyph fontFamily="Font Awesome 5 Free Solid" fontSize="20" icon="SD_CARD" />
                                </graphic>
                            </ToggleButton>
                            <ToggleButton HBox.hgrow="ALWAYS" text="Load PSBT" contentDisplay="TOP" wrapText="true" textAlignment="CENTER" onAction="#loadPSBT">
                                <graphic>
                                    <Glyph fontFamily="Font Awesome 5 Free Solid" fontSize="20" icon="ARROW_UP" />
                                </graphic>
                            </ToggleButton>
                        </buttons>
                    </SegmentedButton>
                    <Button fx:id="signButton" defaultButton="true" HBox.hgrow="ALWAYS" text="Sign" contentDisplay="TOP" wrapText="true" textAlignment="CENTER" onAction="#signPSBT">
                        <graphic>
                            <Glyph fontFamily="Font Awesome 5 Free Solid" fontSize="20" icon="PEN_FANCY" />
                        </graphic>
                    </Button>
                </HBox>
                <HBox fx:id="broadcastButtonBox" styleClass="signatures-buttons" spacing="20">
                    <Button fx:id="viewFinalButton" HBox.hgrow="ALWAYS" text="View Final Transaction" contentDisplay="TOP" wrapText="true" textAlignment="CENTER" onAction="#extractTransaction">
                        <graphic>
                            <Glyph fontFamily="Font Awesome 5 Free Solid" fontSize="20" icon="SEARCH" />
                        </graphic>
                    </Button>
                    <Button fx:id="broadcastButton" defaultButton="true" HBox.hgrow="ALWAYS" text="Broadcast Transaction" contentDisplay="TOP" wrapText="true" textAlignment="CENTER" onAction="#broadcastTransaction">
                        <graphic>
                            <Glyph fontFamily="Font Awesome 5 Free Solid" fontSize="20" icon="SATELLITE_DISH" />
                        </graphic>
                    </Button>
                    <Button fx:id="saveFinalButton" defaultButton="true" HBox.hgrow="ALWAYS" text="Save Final Transaction" contentDisplay="TOP" wrapText="true" textAlignment="CENTER" onAction="#saveFinalTransaction">
                        <graphic>
                            <Glyph fontFamily="Font Awesome 5 Free Solid" fontSize="20" icon="ARROW_DOWN" />
                        </graphic>
                    </Button>
                    <Button fx:id="payjoinButton" defaultButton="true" HBox.hgrow="ALWAYS" text="Get Payjoin Transaction" contentDisplay="TOP" wrapText="true" textAlignment="CENTER" onAction="#getPayjoinTransaction">
                        <graphic>
                            <Glyph fontFamily="Font Awesome 5 Free Solid" fontSize="20" icon="RANDOM" />
                        </graphic>
                    </Button>
                </HBox>
            </VBox>
        </Fieldset>
    </Form>
</GridPane>
