<mvc:View
	controllerName="com.example.fiori.bp3.controller.Wizard"
	xmlns:mvc="sap.ui.core.mvc"
	xmlns="sap.m"
	xmlns:core="sap.ui.core"
	xmlns:form="sap.ui.layout.form"
	xmlns:l="sap.ui.layout"
	height="100%">
	<Page
		id="wizardPage"
		title="{i18n>appTitle}"
		showNavButton="true"
		navButtonPress=".onNavHome"
		busy="{draft>/create/busy}"
		busyIndicatorDelay="0">
		<headerContent>
			<Button
				icon="sap-icon://reset"
				tooltip="{i18n>reset}"
				press=".onResetDraft" />
		</headerContent>
		<subHeader>
			<Toolbar>
				<Title text="{i18n>appSubtitle}" level="H5" />
				<ToolbarSpacer />
				<ObjectStatus text="API_BUSINESS_PARTNER" state="Information" inverted="true" />
			</Toolbar>
		</subHeader>
		<content>
			<Wizard
				id="createWizard"
				complete=".onWizardComplete"
				navigationChange=".onNavigationChange"
				enableBranching="false"
				finishButtonText="{i18n>finishReview}"
				class="sapUiResponsivePadding--header sapUiResponsivePadding--content">

				<!-- Step 1: Registry (external CCIAA) -->
				<WizardStep
					id="stepRegistry"
					title="{i18n>step1Title}"
					icon="sap-icon://inspect"
					validated="{= !!${draft>/cciaa/selectedKey} || (!!${draft>/general/vatNumber} &amp;&amp; !!${draft>/general/name1}) }">
					<MessageStrip
						text="{i18n>step1Info}"
						type="Information"
						showIcon="true"
						class="sapUiSmallMarginBottom" />
					<form:SimpleForm
						editable="true"
						layout="ColumnLayout"
						columnsM="2"
						columnsL="3"
						columnsXL="3"
						labelSpanM="12">
						<form:content>
							<Label text="{i18n>vat}" labelFor="inpVat" />
							<Input id="inpVat" value="{draft>/search/vatNumber}" maxLength="16" submit=".onSearchCciaa" />
							<Label text="{i18n>fiscalCode}" />
							<Input value="{draft>/search/fiscalCode}" maxLength="16" submit=".onSearchCciaa" />
							<Label text="{i18n>companyName}" />
							<Input value="{draft>/search/companyName}" submit=".onSearchCciaa" />
						</form:content>
					</form:SimpleForm>
					<Button
						text="{i18n>searchCciaa}"
						type="Emphasized"
						icon="sap-icon://search"
						press=".onSearchCciaa"
						busy="{draft>/cciaa/busy}"
						class="sapUiSmallMarginBottom" />
					<Text text="{i18n>searchHint}" class="sapUiTinyMarginBottom" />
					<List
						id="cciaaList"
						mode="SingleSelectMaster"
						selectionChange=".onSelectCompany"
						items="{draft>/cciaa/results}"
						headerText="{i18n>resultsTitle}"
						noDataText="{i18n>noData}"
						visible="{draft>/cciaa/searched}"
						busy="{draft>/cciaa/busy}"
						busyIndicatorDelay="0"
						growing="true"
						growingThreshold="20">
						<StandardListItem
							title="{draft>CompanyName}"
							description="{draft>VatNumber} · {draft>City} ({draft>Region})"
							info="{draft>Status}"
							infoState="{path: 'draft>Status', formatter: '.formatter.statusState'}"
							type="Active"
							icon="sap-icon://building" />
					</List>
					<MessageStrip
						text="{i18n>msgSelected}: {draft>/general/name1}"
						type="Success"
						showIcon="true"
						visible="{= !!${draft>/cciaa/selectedKey} }"
						class="sapUiSmallMarginTop" />
				</WizardStep>

				<!-- Step 2: General BP data -->
				<WizardStep
					id="stepGeneral"
					title="{i18n>step2Title}"
					icon="sap-icon://customer"
					validated="{= !!${draft>/general/name1} &amp;&amp; !!${draft>/general/vatNumber} }">
					<form:SimpleForm
						editable="true"
						layout="ColumnLayout"
						columnsM="2"
						columnsL="2"
						title="{i18n>generalFormTitle}">
						<form:content>
							<Label text="{i18n>bpCategory}" />
							<SegmentedButton selectedKey="{draft>/general/bpCategory}">
								<items>
									<SegmentedButtonItem key="2" text="{i18n>catOrg}" />
									<SegmentedButtonItem key="1" text="{i18n>catPerson}" />
								</items>
							</SegmentedButton>
							<Label text="{i18n>grouping}" />
							<Input value="{draft>/general/grouping}" />
							<Label text="{i18n>name1}" required="true" />
							<Input value="{draft>/general/name1}" />
							<Label text="{i18n>name2}" />
							<Input value="{draft>/general/name2}" />
							<Label text="{i18n>legalForm}" />
							<Select selectedKey="{draft>/general/legalForm}">
								<items>
									<core:Item key="SRL" text="{i18n>legalSRL}" />
									<core:Item key="SPA" text="{i18n>legalSPA}" />
									<core:Item key="SAPA" text="{i18n>legalSAPA}" />
									<core:Item key="DI" text="{i18n>legalDI}" />
								</items>
							</Select>
							<Label text="{i18n>vat}" required="true" />
							<Input value="{draft>/general/vatNumber}" />
							<Label text="{i18n>fiscalCode}" />
							<Input value="{draft>/general/fiscalCode}" />
							<Label text="{i18n>industry}" />
							<Select selectedKey="{draft>/general/industry}">
								<items>
									<core:Item key="MANU" text="{i18n>indMANU}" />
									<core:Item key="TRAD" text="{i18n>indTRAD}" />
									<core:Item key="SERV" text="{i18n>indSERV}" />
									<core:Item key="TECH" text="{i18n>indTECH}" />
									<core:Item key="LOGI" text="{i18n>indLOGI}" />
								</items>
							</Select>
							<Label text="{i18n>roles}" />
							<CheckBox text="{i18n>roleCustomer}" selected="{draft>/general/customerRole}" />
							<Label text="" />
							<CheckBox text="{i18n>roleSupplier}" selected="{draft>/general/supplierRole}" />
						</form:content>
					</form:SimpleForm>
				</WizardStep>

				<!-- Step 3: Address -->
				<WizardStep
					id="stepAddress"
					title="{i18n>step3Title}"
					icon="sap-icon://map"
					validated="{= !!${draft>/address/city} &amp;&amp; !!${draft>/address/postalCode} }">
					<form:SimpleForm
						editable="true"
						layout="ColumnLayout"
						columnsM="2"
						columnsL="2"
						title="{i18n>addressFormTitle}">
						<form:content>
							<Label text="{i18n>street}" />
							<Input value="{draft>/address/street}" />
							<Label text="{i18n>houseNumber}" />
							<Input value="{draft>/address/houseNumber}" width="6rem" />
							<Label text="{i18n>postalCode}" required="true" />
							<Input value="{draft>/address/postalCode}" width="8rem" />
							<Label text="{i18n>city}" required="true" />
							<Input value="{draft>/address/city}" />
							<Label text="{i18n>region}" />
							<Input value="{draft>/address/region}" maxLength="3" width="5rem" />
							<Label text="{i18n>country}" />
							<Select selectedKey="{draft>/address/country}">
								<items>
									<core:Item key="IT" text="Italia" />
									<core:Item key="DE" text="Germania" />
									<core:Item key="FR" text="Francia" />
									<core:Item key="CH" text="Svizzera" />
								</items>
							</Select>
							<Label text="{i18n>email}" />
							<Input value="{draft>/address/email}" type="Email" />
							<Label text="{i18n>phone}" />
							<Input value="{draft>/address/phone}" type="Tel" />
							<Label text="{i18n>pec}" />
							<Input value="{draft>/address/pec}" type="Email" />
						</form:content>
					</form:SimpleForm>
				</WizardStep>

				<!-- Step 4: Review + deep create -->
				<WizardStep
					id="stepReview"
					title="{i18n>step4Title}"
					icon="sap-icon://accept"
					validated="true">
					<MessageStrip
						text="{i18n>step4Info}"
						type="Information"
						showIcon="true"
						class="sapUiSmallMarginBottom" />
					<MessageStrip
						id="reviewConfirmedStrip"
						text="{i18n>reviewConfirmed}"
						type="Success"
						showIcon="true"
						visible="{draft>/create/reviewDone}"
						class="sapUiSmallMarginBottom" />
					<l:Grid defaultSpan="L6 M12 S12">
						<VBox class="sapUiSmallMargin">
							<Title text="{i18n>reviewGeneral}" level="H5" class="sapUiSmallMarginBottom" />
							<ObjectAttribute title="{i18n>name1}" text="{draft>/general/name1}" />
							<ObjectAttribute title="{i18n>vat}" text="{draft>/general/vatNumber}" />
							<ObjectAttribute title="{i18n>fiscalCode}" text="{draft>/general/fiscalCode}" />
							<ObjectAttribute
								title="{i18n>legalForm}"
								text="{path: 'draft>/general/legalForm', formatter: '.formatter.legalFormText'}" />
							<ObjectAttribute
								title="{i18n>industry}"
								text="{path: 'draft>/general/industry', formatter: '.formatter.industryText'}" />
							<ObjectAttribute
								title="{i18n>roles}"
								text="{
									parts: [
										{ path: 'draft>/general/customerRole' },
										{ path: 'draft>/general/supplierRole' }
									],
									formatter: '.formatter.rolesText'
								}" />
							<ObjectAttribute title="{i18n>grouping}" text="{draft>/general/grouping}" />
						</VBox>
						<VBox class="sapUiSmallMargin">
							<Title text="{i18n>reviewAddress}" level="H5" class="sapUiSmallMarginBottom" />
							<ObjectAttribute
								title="{i18n>street}"
								text="{
									parts: [
										{ path: 'draft>/address/street' },
										{ path: 'draft>/address/houseNumber' },
										{ path: 'draft>/address/postalCode' },
										{ path: 'draft>/address/city' },
										{ path: 'draft>/address/region' }
									],
									formatter: '.formatter.fullAddress'
								}" />
							<ObjectAttribute title="{i18n>country}" text="{draft>/address/country}" />
							<ObjectAttribute title="{i18n>email}" text="{draft>/address/email}" />
							<ObjectAttribute title="{i18n>phone}" text="{draft>/address/phone}" />
							<ObjectAttribute title="{i18n>pec}" text="{draft>/address/pec}" />
						</VBox>
					</l:Grid>
					<Button
						id="btnCreateBp"
						text="{i18n>createBp}"
						type="Emphasized"
						icon="sap-icon://save"
						press=".onCreateBp"
						busy="{draft>/create/busy}"
						enabled="{= ${draft>/create/reviewDone} &amp;&amp; !${draft>/create/busy} }"
						class="sapUiMediumMarginTop" />
					<Text
						text="{i18n>createNeedsReview}"
						visible="{= !${draft>/create/reviewDone} }"
						class="sapUiSmallMarginTop" />
				</WizardStep>
			</Wizard>
		</content>
	</Page>
</mvc:View>
