<%--
/**
 * 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="/definition_link/init.jsp" %>

<%
ResultRow row = (ResultRow)request.getAttribute(WebKeys.SEARCH_CONTAINER_RESULT_ROW);

String randomNamespace = (String)row.getParameter("randomNamespace");

WorkflowDefinitionLinkSearchEntry workflowDefinitionLinkSearchEntry = (WorkflowDefinitionLinkSearchEntry)row.getObject();

String className = workflowDefinitionLinkSearchEntry.getClassName();
%>

<portlet:actionURL name="/portal_workflow/update_workflow_definition_link" var="updateWorkflowDefinitionLinkURL">
	<portlet:param name="redirect" value="<%= currentURL %>" />
</portlet:actionURL>

<div class="d-none" id="<%= randomNamespace %>formContainer">
	<aui:form action="<%= updateWorkflowDefinitionLinkURL %>" cssClass="workflow-definition-form" method="post">
		<aui:input name="redirect" type="hidden" value="<%= currentURL %>" />
		<aui:input name="namespace" type="hidden" value="<%= randomNamespace %>" />
		<aui:input name="groupId" type="hidden" value="<%= workflowDefinitionLinkDisplayContext.getGroupId() %>" />
		<aui:input name="resource" type="hidden" value="<%= workflowDefinitionLinkSearchEntry.getResource() %>" />
		<aui:input name="editMode" type="hidden" value="false" />

		<%
		String workflowAssignedValue = "";
		%>

		<aui:select cssClass="form-control-sm workflow-definition-form" label="<%= StringPool.BLANK %>" name='<%= "workflowDefinitionName@" + className %>' title="workflow-definition">

			<%
			WorkflowDefinition defaultWorkflowDefinition = workflowDefinitionLinkDisplayContext.fetchDefaultWorkflowDefinition(className);
			String defaultWorkflowDefinitionLabel = workflowDefinitionLinkDisplayContext.getDefaultWorkflowDefinitionLabel(className);
			%>

			<aui:option><%= HtmlUtil.escape(defaultWorkflowDefinitionLabel) %></aui:option>

			<%
			for (WorkflowDefinition workflowDefinition : workflowDefinitionLinkDisplayContext.getWorkflowDefinitions()) {
				if (!workflowDefinitionLinkDisplayContext.isControlPanelPortlet() && workflowDefinitionLinkDisplayContext.isWorkflowDefinitionEquals(workflowDefinition, defaultWorkflowDefinition)) {
					continue;
				}

				boolean selected = workflowDefinitionLinkDisplayContext.isWorkflowDefinitionSelected(workflowDefinition, className);

				String value = workflowDefinitionLinkDisplayContext.getWorkflowDefinitionValue(workflowDefinition);

				if (selected) {
					workflowAssignedValue = value;
				}
			%>

				<aui:option label="<%= HtmlUtil.escape(workflowDefinitionLinkDisplayContext.getWorkflowDefinitionLabel(workflowDefinition)) %>" selected="<%= selected %>" value="<%= value %>" />

			<%
			}
			%>

		</aui:select>

		<aui:input name="workflowAssignedValue" type="hidden" value="<%= workflowAssignedValue %>" />
	</aui:form>
</div>

<div id="<%= randomNamespace %>definitionLabel">
	<%= HtmlUtil.escape(workflowDefinitionLinkSearchEntry.getWorkflowDefinitionLabel()) %>
</div>