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

<%@ include file="/init.jsp" %>

<%
CommercePriceListDisplayContext commercePriceListDisplayContext = (CommercePriceListDisplayContext)request.getAttribute(WebKeys.PORTLET_DISPLAY_CONTEXT);

CommercePriceList commercePriceList = commercePriceListDisplayContext.getCommercePriceList();

String headerTitle = LanguageUtil.get(request, "add-price-list");

if (commercePriceList != null) {
	headerTitle = commercePriceList.getName();
}
%>

<liferay-portlet:renderURL var="editCommercePriceListExternalReferenceCodeURL" windowState="<%= LiferayWindowState.POP_UP.toString() %>">
	<portlet:param name="mvcRenderCommandName" value="/commerce_price_list/edit_commerce_price_list_external_reference_code" />
	<portlet:param name="commercePriceListId" value="<%= String.valueOf(commercePriceListDisplayContext.getCommercePriceListId()) %>" />
</liferay-portlet:renderURL>

<commerce-ui:header
	actions="<%= commercePriceListDisplayContext.getHeaderActionModels() %>"
	bean="<%= commercePriceList %>"
	beanIdLabel="id"
	externalReferenceCode="<%= (commercePriceList == null) ? StringPool.BLANK : commercePriceList.getExternalReferenceCode() %>"
	externalReferenceCodeEditUrl="<%= (commercePriceList == null) ? StringPool.BLANK : editCommercePriceListExternalReferenceCodeURL %>"
	model="<%= CommercePriceList.class %>"
	title="<%= headerTitle %>"
	wrapperCssClasses="side-panel-top-anchor"
/>

<liferay-frontend:screen-navigation
	containerWrapperCssClass="container"
	key="<%= CommercePriceListScreenNavigationConstants.SCREEN_NAVIGATION_KEY_COMMERCE_PRICE_LIST_GENERAL %>"
	modelBean="<%= commercePriceListDisplayContext.getCommercePriceList() %>"
	portletURL="<%= currentURLObj %>"
/>

<aui:script>
	document
		.getElementById('<portlet:namespace />publishButton')
		.addEventListener('click', (e) => {
			e.preventDefault();

			var form = document.getElementById('<portlet:namespace />fm');

			if (!form) {
				throw new Error('Form with id: <portlet:namespace />fm not found!');
			}

			var workflowActionInput = document.getElementById(
				'<portlet:namespace />workflowAction'
			);

			if (workflowActionInput) {
				workflowActionInput.value =
					'<%= WorkflowConstants.ACTION_PUBLISH %>';
			}

			submitForm(form);
		});
</aui:script>