{namespace i=TYPO3\CMS\Install\ViewHelpers}

<f:layout name="Step" />

<f:section name="Content">
	<f:render partial="Action/Step/StepCounter.html" arguments="{steps: steps, currentStep: currentStep}" />

	<h3>Select database</h3>

	<f:if condition="{errors -> f:count()}">
		<f:for each="{errors}" as="error">
			<div class="alert alert-danger">
				<h4>Exception</h4>
				<p>{error}</p>
			</div>
		</f:for>
	</f:if>

	<f:if condition="{isInitialInstallationInProgress}">
		<f:then>
			You have two options:
		</f:then>
	</f:if>

	<form method="post" id="stepInstaller-databaseSelect">
		<f:render partial="Action/Common/HiddenFormFields" arguments="{_all}" />
		<input type="hidden" value="execute" name="install[set]" />

		<p>&nbsp;</p>
		<div class="row">
			<div class="col-md-6">

				<f:if condition="{isInitialInstallationInProgress}">

					<f:then>
						<f:comment>
							First installation
						</f:comment>
						<div class="radio">
							<label for="t3-install-form-db-select-type-existing">
								<input id="t3-install-form-db-select-type-existing" type="radio" name="install[values][type]" value="existing" class="radio" checked="checked" />
								Use an existing empty database:
							</label>
						</div>
						<div class="form-group">
							<select
									id="t3-install-step-database-existing"
									name="install[values][existing]"
									class="form-control"
									onfocus="document.getElementById('t3-install-form-db-select-type-existing').checked=true;"
									>
								<option value="">-- Select database --</option>
								<f:for each="{databaseList}" as="database">
									<f:if condition="{database.tables}">
										<f:then>
											<option value="{database.name}" disabled="disabled">{database.name} ({database.tables} Tables)</option>
										</f:then>
										<f:else>
											<option value="{database.name}">{database.name}</option>
										</f:else>
									</f:if>
								</f:for>
							</select>
						</div>
						<div class="radio">
							<label for="t3-install-step-database-new">
								<input
										id="t3-install-form-db-select-type-new"
										type="radio"
										name="install[values][type]"
										value="new"
										class="radio"
										/>
								OR create a new database:</label>
						</div>
						<div class="form-group">
							<p>
								<em>Attention: The database user must have sufficient privileges to create the whole structure.</em>
								<br />
								Enter a name for your TYPO3 database.
							</p>
							<input
								id="t3-install-step-database-new"
								class="t3-install-form-input-text form-control"
								type="text"
								name="install[values][new]"
								checked="checked"
								onfocus="document.getElementById('t3-install-form-db-select-type-new').checked=true;"
							/>
						</div>
					</f:then>

					<f:else>
						<f:comment>
							Upgrading
						</f:comment>
						<input
							id="t3-install-form-db-select-type-existing"
							type="hidden"
							name="install[values][type]"
							value="existing"
						/>
						<div class="">
							<label for="t3-install-step-database-existing">Select an existing database:</label>
							<p>The database will not be altered in any way.</p>
							<select
								id="t3-install-step-database-existing"
								name="install[values][existing]"
								onfocus="document.getElementById('t3-install-form-db-select-type-existing').checked=true;"
							>
								<option value="">Select database</option>
								<f:for each="{databaseList}" as="database">
									<option value="{database}">{database}</option>
								</f:for>
							</select>
						</div>
					</f:else>

				</f:if>
				<div class="form-group">
					<button class="btn btn-success" type="submit">
						Continue
					</button>
				</div>
			</div>
		</div>
	</form>
</f:section>
