<?xml version="1.0" encoding="UTF-8"?>
<flow
    xmlns="http://www.springframework.org/schema/webflow"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/webflow  
                        http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd"
    parent="addItem"
    start-state="wizard1">

 	<input
        name="itemId"
        value="flowScope.itemId"
        type="string" />

    <input
        name="itemType"
        value="flowScope.itemType"
        type="gov.va.med.pharmacy.peps.common.vo.EntityType" />
        
    <view-state
        id="wizard1"
        view="product.wizard.input.1">

        <transition
            on="computeFields"
            to="computeFields" />
        <transition
            on="next"
            to="wizard2" />
    </view-state>

    <action-state id="computeFields">
        <evaluate expression="managedItemCommand.computeProductUniquenessFields()">

        </evaluate>
        <transition
            on="success"
            to="wizard1" />
    </action-state>

<!--     <action-state id="next1"> -->
<!--         <evaluate expression="managedItemCommand.validateWizard()"> -->

<!--         </evaluate> -->
<!--         <transition -->
<!--             on="success" -->
<!--             to="wizard2" /> -->
<!--     </action-state> -->

    <view-state
        id="wizard2"
        view="product.wizard.input.2a">

        <transition
            on="previous"
            to="wizard1" />
        <transition
            on="confirm"
            to="editItem" />
       </view-state>
        
<!--    	<action-state id="previous1"> -->
<!--         <evaluate expression="managedItemCommand.validateWizard()"> -->

<!--         </evaluate> -->
<!--         <transition -->
<!--             on="success" -->
<!--             to="wizard1" /> -->
<!--     </action-state> -->

	<subflow-state
        id="editItem"
        subflow="editItem">
        <input
            name="itemId"
            value="flowScope.itemId"
            type="string" />
        <input
            name="itemType"
            value="flowScope.itemType"
            type="gov.va.med.pharmacy.peps.common.vo.EntityType" />
        <input
            name="item"
            value="flowScope.item"
            type="gov.va.med.pharmacy.peps.common.vo.ManagedItemVo" />
        <input
            name="oldItem"
            value="flowScope.oldItem"
            type="gov.va.med.pharmacy.peps.common.vo.ManagedItemVo" />

        <transition
            on="end"
            to="chooseEnd">
            <set
                name="flowScope.item"
                value="currentEvent.attributes.item"
                type="gov.va.med.pharmacy.peps.common.vo.ManagedItemVo" />
            <set
                name="flowScope.itemId"
                value="currentEvent.attributes.itemId != null ? currentEvent.attributes.itemId : currentEvent.attributes.item.id"
                type="string" />
            <set
                name="flowScope.itemType"
                value="currentEvent.attributes.itemType"
                type="gov.va.med.pharmacy.peps.common.vo.EntityType" />
        </transition>
        <transition
            on="searchEnd"
            to="search" />
        <transition
            on="retrieveEnd"
            to="retrieve" />
        <transition
            on="cancel"
            to="cancel" />            
    </subflow-state>
        
</flow>