<%--
/**
 * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
 *
 * The contents of this file are subject to the terms of the Liferay Enterprise
 * Subscription License ("License"). You may not use this file except in
 * compliance with the License. You can obtain a copy of the License by
 * contacting Liferay, Inc. See the License for the specific language governing
 * permissions and limitations under the License, including but not limited to
 * distribution rights of the Software.
 *
 *
 *
 */
--%>

<%
CommerceCurrency commerceCurrency = commercePriceList.getCommerceCurrency();

String priceInputLabel = "price-list-price";

if (CommercePriceListConstants.TYPE_PROMOTION.equals(commercePriceEntryDisplayContext.getCommercePriceListType(portletName))) {
	priceInputLabel = "promotion-price";
}

boolean discountDiscovery = BeanParamUtil.getBoolean(commercePriceEntry, request, "discountDiscovery", true);
%>

<commerce-ui:panel
	title='<%= LanguageUtil.get(request, "details") %>'
>
	<liferay-ui:error exception="<%= CommercePriceListMaxPriceValueException.class %>">
		<liferay-ui:message arguments="<%= CommercePriceConstants.PRICE_VALUE_MAX %>" key="price-max-value-is-x" />
	</liferay-ui:error>

	<div class="row">
		<div class="col-4">
			<label class="control-label" for="entryBasePrice"><liferay-ui:message key="base-price" /></label>

			<p id="entryBasePrice"><%= HtmlUtil.escape(commercePriceEntryDisplayContext.getBasePrice()) %></p>
		</div>

		<div class="col-4">
			<aui:input label="<%= priceInputLabel %>" name="price" suffix="<%= HtmlUtil.escape(commerceCurrency.getCode()) %>" type="text" value="<%= commerceCurrency.round(commercePriceEntry.getPrice()) %>">
				<aui:validator name="min"><%= CommercePriceConstants.PRICE_VALUE_MIN %></aui:validator>
				<aui:validator name="max"><%= CommercePriceConstants.PRICE_VALUE_MAX %></aui:validator>
				<aui:validator name="number" />
			</aui:input>
		</div>

		<div class="col-4">
			<div class="row">
				<div class="col-12">
					<aui:input helpMessage="override-discount-help" ignoreRequestValue="<%= true %>" label='<%= LanguageUtil.get(request, "override-discount") %>' name="overrideDiscount" type="toggle-switch" value="<%= !discountDiscovery %>" />
				</div>
			</div>
		</div>
	</div>

	<div class="row">
		<div class="col-4">
			<aui:input cssClass="mb-2" formName="fm" label="publish-date" name="displayDate" />
		</div>

		<div class="col-4">
			<liferay-ui:error exception="<%= CommercePriceListExpirationDateException.class %>" message="please-enter-a-valid-expiration-date" />

			<aui:fieldset>
				<aui:input cssClass="mb-2" dateTogglerCheckboxLabel="never-expire" disabled="<%= neverExpire %>" formName="fm" name="expirationDate" />
			</aui:fieldset>
		</div>

		<div class="col-4">
			<div class="<%= discountDiscovery ? "hide" : StringPool.BLANK %>" id="<portlet:namespace />discountLevels">
				<label class="control-label" for="<portlet:namespace />discountLevel1"><liferay-ui:message key="discount-levels" /></label>

				<div class="d-flex">
					<aui:input disabled="<%= discountDiscovery %>" ignoreRequestValue="<%= true %>" inlineField="<%= true %>" label="l1" name="discountLevel1" type="text" value="<%= commercePriceEntry.getDiscountLevel1() %>" wrapperCssClass="discount-label-wrapper">
						<aui:validator name="min"><%= CommercePriceConstants.PRICE_VALUE_MIN %></aui:validator>
						<aui:validator name="max"><%= CommercePriceConstants.PRICE_VALUE_MAX %></aui:validator>
						<aui:validator name="number" />
					</aui:input>

					<aui:input disabled="<%= discountDiscovery %>" ignoreRequestValue="<%= true %>" inlineField="<%= true %>" label="l2" name="discountLevel2" type="text" value="<%= commercePriceEntry.getDiscountLevel2() %>" wrapperCssClass="discount-label-wrapper">
						<aui:validator name="min"><%= CommercePriceConstants.PRICE_VALUE_MIN %></aui:validator>
						<aui:validator name="max"><%= CommercePriceConstants.PRICE_VALUE_MAX %></aui:validator>
						<aui:validator name="number" />
					</aui:input>

					<aui:input disabled="<%= discountDiscovery %>" ignoreRequestValue="<%= true %>" inlineField="<%= true %>" label="l3" name="discountLevel3" type="text" value="<%= commercePriceEntry.getDiscountLevel3() %>" wrapperCssClass="discount-label-wrapper">
						<aui:validator name="min"><%= CommercePriceConstants.PRICE_VALUE_MIN %></aui:validator>
						<aui:validator name="max"><%= CommercePriceConstants.PRICE_VALUE_MAX %></aui:validator>
						<aui:validator name="number" />
					</aui:input>

					<aui:input disabled="<%= discountDiscovery %>" ignoreRequestValue="<%= true %>" inlineField="<%= true %>" label="l4" name="discountLevel4" type="text" value="<%= commercePriceEntry.getDiscountLevel4() %>" wrapperCssClass="discount-label-wrapper">
						<aui:validator name="min"><%= CommercePriceConstants.PRICE_VALUE_MIN %></aui:validator>
						<aui:validator name="max"><%= CommercePriceConstants.PRICE_VALUE_MAX %></aui:validator>
						<aui:validator name="number" />
					</aui:input>
				</div>
			</div>
		</div>
	</div>
</commerce-ui:panel>

<aui:script use="aui-base">
	A.one('#<portlet:namespace />overrideDiscount').on('change', function (event) {
		if (this.attr('checked')) {
			A.one('#<portlet:namespace />discountLevels').show();

			A.one('#<portlet:namespace />discountLevel1').attr('disabled', false);
			A.one('#<portlet:namespace />discountLevel1').removeClass('disabled');

			A.one('#<portlet:namespace />discountLevel2').attr('disabled', false);
			A.one('#<portlet:namespace />discountLevel2').removeClass('disabled');

			A.one('#<portlet:namespace />discountLevel3').attr('disabled', false);
			A.one('#<portlet:namespace />discountLevel3').removeClass('disabled');

			A.one('#<portlet:namespace />discountLevel4').attr('disabled', false);
			A.one('#<portlet:namespace />discountLevel4').removeClass('disabled');
		}
		else {
			A.one('#<portlet:namespace />discountLevels').hide();

			A.one('#<portlet:namespace />discountLevel1').attr('disabled', true);
			A.one('#<portlet:namespace />discountLevel1').addClass('disabled');

			A.one('#<portlet:namespace />discountLevel2').attr('disabled', true);
			A.one('#<portlet:namespace />discountLevel2').addClass('disabled');

			A.one('#<portlet:namespace />discountLevel3').attr('disabled', true);
			A.one('#<portlet:namespace />discountLevel3').addClass('disabled');

			A.one('#<portlet:namespace />discountLevel4').attr('disabled', true);
			A.one('#<portlet:namespace />discountLevel4').addClass('disabled');
		}
	});
</aui:script>