<xf:macro name="checkboxes"
	arg-label="{{ phrase('usable_by_user_groups') }}"
	arg-id="usable_user_group"
	arg-userGroups=""
	arg-selectedUserGroups="!"
	arg-withRow="1">

	<xf:if is="!$userGroups">
		<xf:set var="$userGroupRepo" value="{$xf.app.em.getRepository('XF:UserGroup')}" />
		<xf:set var="$userGroups" value="{$userGroupRepo.getUserGroupTitlePairs()}" />
	</xf:if>
	<xf:set var="$allUserGroups" value="{{ array_keys($userGroups) == $selectedUserGroups || in_array('-1', $selectedUserGroups) }}" />

	<xf:set var="$inner">
		<xf:radio name="{$id}" id="{$id}">
			<xf:option value="all" selected="{$allUserGroups}">{{ phrase('all_user_groups') }}</xf:option>
			<xf:option value="sel" selected="!{$allUserGroups}" label="{{ phrase('selected_user_groups:') }}">
				<xf:dependent>
					<xf:checkbox name="{{ $id . '_ids' }}" listclass="listColumns">
						<xf:foreach loop="$userGroups" key="$userGroupId" value="$userGroupTitle">
							<xf:option value="{$userGroupId}" selected="{{ in_array($userGroupId, $selectedUserGroups) || $allUserGroups  }}">
								{$userGroupTitle}
							</xf:option>
						</xf:foreach>
					</xf:checkbox>

					<xf:checkbox>
						<xf:option data-xf-init="check-all" data-container="{{ '#' . $id }}">{{ phrase('select_all') }}</xf:option>
					</xf:checkbox>
				</xf:dependent>
			</xf:option>
		</xf:radio>
	</xf:set>

	<xf:if is="$withRow">
		<xf:formrow label="{$label}" name="{$id}" id="{$id}">
			{$inner|raw}
		</xf:formrow>
	<xf:else />
		{$inner|raw}
	</xf:if>
</xf:macro>