<%--
/**
 * 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.
 *
 *
 *
 */
--%>

<%
CommercePriceEntry commercePriceEntry = commerceTierPriceEntryDisplayContext.getCommercePriceEntry();

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

<aui:model-context bean="<%= commerceTierPriceEntry %>" model="<%= CommerceTierPriceEntry.class %>" />

<aui:input label='<%= LanguageUtil.get(request, "quantity") %>' name="minQuantity">
	<aui:validator name="min"><%= 1 %></aui:validator>
</aui:input>

<aui:input label="tier-price" name="price" suffix="<%= HtmlUtil.escape(commerceCurrency.getCode()) %>" type="text" value="<%= commerceCurrency.round(price) %>">
	<aui:validator name="max"><%= CommercePriceConstants.PRICE_VALUE_MAX %></aui:validator>
	<aui:validator name="number" />
</aui:input>

<c:if test="<%= commercePriceEntry.isBulkPricing() %>">
	<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="" name="discountLevel1" type="text" value="<%= (commerceTierPriceEntry == null) ? StringPool.BLANK : commerceTierPriceEntry.getDiscountLevel1() %>" wrapperCssClass="pr-2">
				<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="" name="discountLevel2" type="text" value="<%= (commerceTierPriceEntry == null) ? StringPool.BLANK : commerceTierPriceEntry.getDiscountLevel2() %>" wrapperCssClass="pr-2">
				<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="" name="discountLevel3" type="text" value="<%= (commerceTierPriceEntry == null) ? StringPool.BLANK : commerceTierPriceEntry.getDiscountLevel3() %>" wrapperCssClass="pr-2">
				<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="" name="discountLevel4" type="text" value="<%= (commerceTierPriceEntry == null) ? StringPool.BLANK : commerceTierPriceEntry.getDiscountLevel4() %>">
				<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>

	<aui:input helpMessage="override-discount-help" ignoreRequestValue="<%= true %>" inlineLabel="right" label='<%= LanguageUtil.get(request, "override-discount") %>' labelCssClass="simple-toggle-switch" name="overrideDiscount" type="toggle-switch" value="<%= !discountDiscovery %>" />
</c:if>

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

<aui:fieldset cssClass="mb-0">
	<aui:input formName="fm" label="publish-date" name="displayDate" />

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

<c:if test="<%= commercePriceEntry.isBulkPricing() %>">
	<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>
</c:if>