/// <summary>
 /// Creates an ID container.
 /// </summary>
 /// <param name="children"></param>
 /// <param name="updateRegionSets">The intermediate-post-back update-region sets that this component will be a part of.</param>
 public FlowIdContainer(IEnumerable <FlowComponent> children, IEnumerable <UpdateRegionSet> updateRegionSets = null)
 {
     identifiedComponent = new IdentifiedFlowComponent(
         () => new IdentifiedComponentData <FlowComponentOrNode>(
             "",
             new UpdateRegionLinker(
                 "",
                 new PreModificationUpdateRegion(updateRegionSets, identifiedComponent.ToCollection, () => "").ToCollection(),
                 arg => identifiedComponent.ToCollection()).ToCollection(),
             new ErrorSourceSet(),
             errorsBySource => children));
 }
        /// <summary>
        /// Creates a list item containing these components.
        /// </summary>
        /// <param name="children"></param>
        /// <param name="id">The ID of the item. This is required if you're adding the item on an intermediate post-back or want to remove the item on an
        /// intermediate post-back. Do not pass null or the empty string.</param>
        /// <param name="displaySetup"></param>
        /// <param name="classes">The classes on the item.</param>
        /// <param name="visualOrderRank"></param>
        /// <param name="updateRegionSets">The intermediate-post-back update-region sets that this item will be a part of.</param>
        /// <param name="removalUpdateRegionSets">The intermediate-post-back update-region sets that this item's removal will be a part of.</param>
        /// <param name="etherealChildren"></param>
        public static ComponentListItem ToComponentListItem(
            this IEnumerable <FlowComponentOrNode> children, string id, DisplaySetup displaySetup = null, ElementClassSet classes   = null, int?visualOrderRank = null,
            IEnumerable <UpdateRegionSet> updateRegionSets            = null, IEnumerable <UpdateRegionSet> removalUpdateRegionSets = null,
            IEnumerable <EtherealComponentOrElement> etherealChildren = null)
        {
            return(new ComponentListItem(
                       (includeContentContainer, itemTypeClasses, width) => {
                FlowComponentOrNode component = null;
                component =
                    new IdentifiedFlowComponent(
                        () =>
                        new IdentifiedComponentData <FlowComponentOrNode>(
                            id,
                            new UpdateRegionLinker(
                                "",
                                new PreModificationUpdateRegion(updateRegionSets, component.ToCollection, () => "").ToCollection(),
                                arg => component.ToCollection()).ToCollection(),
                            ImmutableArray <EwfValidation> .Empty,
                            errorsByValidation => new DisplayableElement(
                                context => {
                    var attributes = new List <Tuple <string, string> >();
                    if (visualOrderRank.HasValue || width != null)
                    {
                        attributes.Add(
                            Tuple.Create(
                                "style",
                                StringTools.ConcatenateWithDelimiter(
                                    ", ",
                                    visualOrderRank.HasValue ? "order: {0}".FormatWith(visualOrderRank.Value) : "",
                                    width != null ? "width: {0}".FormatWith(width.Value) : "")));
                    }

                    return new DisplayableElementData(
                        displaySetup,
                        () => new DisplayableElementLocalData("li", attributes: attributes),
                        classes: CssElementCreator.ItemClass.Add(itemTypeClasses).Add(classes ?? ElementClassSet.Empty),
                        children:
                        includeContentContainer
                                                                                                                              ? new DisplayableElement(
                            innerContext =>
                            new DisplayableElementData(
                                null,
                                () => new DisplayableElementLocalData("div"),
                                classes: CssElementCreator.ItemClass,
                                children: children,
                                etherealChildren: etherealChildren)).ToCollection()
                                                                                                                              : children,
                        etherealChildren: includeContentContainer ? null : etherealChildren);
                }).ToCollection()));
                return component;
            },
                       id,
                       removalUpdateRegionSets));
        }
        internal static ComponentListItem ToComponentListItem(
            this IReadOnlyCollection <FlowComponent> content, string id, DisplaySetup displaySetup, ElementClassSet classes, int?visualOrderRank,
            IEnumerable <UpdateRegionSet> updateRegionSets, IEnumerable <UpdateRegionSet> removalUpdateRegionSets,
            IReadOnlyCollection <EtherealComponent> etherealContent,
            Func <ElementContext, string, IReadOnlyCollection <Tuple <string, string> >, DisplayableElementLocalData> localDataGetter)
        {
            return(new ComponentListItem(
                       (includeContentContainer, itemTypeClasses, width) => {
                FlowComponentOrNode component = null;
                component = new IdentifiedFlowComponent(
                    () => new IdentifiedComponentData <FlowComponentOrNode>(
                        id,
                        new UpdateRegionLinker(
                            "",
                            new PreModificationUpdateRegion(updateRegionSets, component.ToCollection, () => "").ToCollection(),
                            arg => component.ToCollection()).ToCollection(),
                        new ErrorSourceSet(),
                        errorsBySource => new DisplayableElement(
                            context => {
                    var attributes = new List <Tuple <string, string> >();
                    if (visualOrderRank.HasValue || width != null)
                    {
                        attributes.Add(
                            Tuple.Create(
                                "style",
                                StringTools.ConcatenateWithDelimiter(
                                    ", ",
                                    visualOrderRank.HasValue ? "order: {0}".FormatWith(visualOrderRank.Value) : "",
                                    width != null ? "width: {0}".FormatWith(width.Value) : "")));
                    }

                    return new DisplayableElementData(
                        displaySetup,
                        () => !includeContentContainer && localDataGetter != null
                                                                                              ? localDataGetter(context, "li", attributes)
                                                                                              : new DisplayableElementLocalData("li", focusDependentData: new DisplayableElementFocusDependentData(attributes: attributes)),
                        classes: CssElementCreator.ItemClass.Add(itemTypeClasses).Add(classes ?? ElementClassSet.Empty),
                        children: includeContentContainer
                                                                                                  ? new DisplayableElement(
                            innerContext => new DisplayableElementData(
                                null,
                                () => localDataGetter != null ? localDataGetter(innerContext, "div", null) : new DisplayableElementLocalData("div"),
                                classes: CssElementCreator.ItemClass,
                                children: content,
                                etherealChildren: etherealContent)).ToCollection()
                                                                                                  : content,
                        etherealChildren: includeContentContainer ? null : etherealContent);
                }).ToCollection()));
                return component;
            },
                       id,
                       removalUpdateRegionSets));
        }