@namespace Connected.Components
@typeparam T
@inherits InputBase<T>

<CascadingValue Name="SubscribeToParentForm" Value="false" IsFixed="true">
	<div class="select" id="@_elementId">
		<InputControl Label="@Label" Variant="@Variant" HelperText="@HelperText" HelperTextOnFocus="@HelperTextOnFocus" FullWidth="@FullWidth" Margin="@Margin" Class="@Classname"
						 Error="@HasError" ErrorText="@ErrorText" ErrorId="@ErrorId" Disabled="@Disabled" @onclick="@ToggleMenu" Required="@Required" ForId="@FieldId">
			<InputContent>
                <Input @ref="_elementReference" InputType="@(CanRenderValue || (Strict && !IsValueInList) ? InputType.Hidden : InputType.Text)"
                          Class="select-input" Margin="@Margin" Placeholder="@Placeholder"
                          Variant="@Variant"
                          TextUpdateSuppression="false"
                          Value="@(Strict && !IsValueInList ? null : Text)" DisableUnderLine="@DisableUnderLine"
                          Disabled="@Disabled" ReadOnly="true" Error="@HasError" ErrorId="@ErrorId"
                          OnAdornmentClick="@OnAdornmentClick" AdornmentIcon="@_currentIcon" Adornment="@Adornment"
                          AdornmentColor="@AdornmentColor" IconSize="@IconSize" AdornmentText="@AdornmentText"
                          Clearable="@Clearable" OnClearButtonClick="(async (e) => await SelectClearButtonClickHandlerAsync(e))"
                          @attributes="CustomAttributes" OnBlur="@OnLostFocus">
                    @if (CanRenderValue)
                    {
                        @GetSelectedValuePresenter()
                    }
                </Input>
				<Popover Open=@(_isOpen) MaxHeight="@MaxHeight" AnchorOrigin="@AnchorOrigin" TransformOrigin="@TransformOrigin" Class="@PopoverClass" RelativeWidth="true">
					<CascadingValue Value="@((ISelect)this)" IsFixed="true">
						<List Clickable="true" Dense="@Dense" @bind-SelectedValue="_activeItemId">
                            @if (MultiSelection && SelectAll)
							{
								<ListItem Icon="@SelectAllCheckBoxIcon" Text="@SelectAllText" OnClick="SelectAllClickAsync" OnClickHandlerPreventDefault="true" Dense="@Dense" Class="mb-2" />
                                <Divider />
							}
							@ChildContent
						</List>
					</CascadingValue>
				</Popover>
			</InputContent>
		</InputControl>
	</div>
    @*Shadow select items for IsValueInList and CanRenderValue*@
    <CascadingValue Value="@((IShadowSelect)this)" IsFixed="true">
        <CascadingValue Name="HideContent" Value="true">
			@ChildContent
		</CascadingValue>
	</CascadingValue>

</CascadingValue>
<!-- mousedown instead of click needed to close the menu before OnLostFocus runs -->
<Overlay Visible="_isOpen" @onmousedown="@(() => CloseMenu(false))" LockScroll="@LockScroll" />