/// <summary>
        /// Builds the layout (sections) of the modern page
        /// </summary>
        /// <param name="pageData">Information about the source page</param>
        public void Transform(Tuple <Pages.PageLayout, List <WebPartEntity> > pageData)
        {
            bool includeVerticalColumn  = false;
            int  verticalColumnEmphasis = 0;

            if (pageData.Item1 == Pages.PageLayout.PublishingPage_AutoDetectWithVerticalColumn)
            {
                includeVerticalColumn  = true;
                verticalColumnEmphasis = GetVerticalColumnBackgroundEmphasis();
            }

            // First drop all sections...ensure the default section is gone
            page.ClearPage();

            // Should not occur, but to be at the safe side...
            if (pageData.Item2.Count == 0)
            {
                page.AddSection(PnPCore.CanvasSectionTemplate.OneColumn, 1, GetBackgroundEmphasis(1));
                return;
            }

            var firstRow = pageData.Item2.OrderBy(p => p.Row).First().Row;
            var lastRow  = pageData.Item2.OrderBy(p => p.Row).Last().Row;

            // Loop over the possible rows...will take in account possible row gaps
            // Each row means a new section
            int sectionOrder = 1;

            for (int rowIterator = firstRow; rowIterator <= lastRow; rowIterator++)
            {
                var webpartsInRow = pageData.Item2.Where(p => p.Row == rowIterator);
                if (webpartsInRow.Any())
                {
                    // Determine max column number
                    int maxColumns = 1;

                    foreach (var wpInRow in webpartsInRow)
                    {
                        if (wpInRow.Column > maxColumns)
                        {
                            maxColumns = wpInRow.Column;
                        }
                    }

                    // Deduct the vertical column
                    if (includeVerticalColumn && rowIterator == firstRow)
                    {
                        maxColumns--;
                    }

                    if (maxColumns > 3)
                    {
                        LogError(LogStrings.Error_Maximum3ColumnsAllowed, LogStrings.Heading_PublishingLayoutTransformator);
                        throw new Exception("Publishing transformation layout mapping can maximum use 3 columns");
                    }
                    else
                    {
                        if (maxColumns == 1)
                        {
                            if (includeVerticalColumn && rowIterator == firstRow)
                            {
                                page.AddSection(PnPCore.CanvasSectionTemplate.OneColumnVerticalSection, sectionOrder, GetBackgroundEmphasis(rowIterator), verticalColumnEmphasis);
                            }
                            else
                            {
                                page.AddSection(PnPCore.CanvasSectionTemplate.OneColumn, sectionOrder, GetBackgroundEmphasis(rowIterator));
                            }
                        }
                        else if (maxColumns == 2)
                        {
                            // if we've only an image in one of the columns then make that one the 'small' column
                            var imageWebPartsInRow = webpartsInRow.Where(p => p.Type == WebParts.WikiImage);
                            if (imageWebPartsInRow.Any())
                            {
                                Dictionary <int, int> imageWebPartsPerColumn = new Dictionary <int, int>();
                                foreach (var imageWebPart in imageWebPartsInRow.OrderBy(p => p.Column))
                                {
                                    if (imageWebPartsPerColumn.TryGetValue(imageWebPart.Column, out int wpCount))
                                    {
                                        imageWebPartsPerColumn[imageWebPart.Column] = wpCount + 1;
                                    }
                                    else
                                    {
                                        imageWebPartsPerColumn.Add(imageWebPart.Column, 1);
                                    }
                                }

                                var firstImageColumn  = imageWebPartsPerColumn.First();
                                var secondImageColumn = imageWebPartsPerColumn.Last();

                                if (firstImageColumn.Key == secondImageColumn.Key)
                                {
                                    // there was only one column with images
                                    var firstImageColumnOtherWebParts = webpartsInRow.Where(p => p.Column == firstImageColumn.Key && p.Type != WebParts.WikiImage);
                                    if (!firstImageColumnOtherWebParts.Any())
                                    {
                                        // no other web parts in this column
                                        var orderedList = webpartsInRow.OrderBy(p => p.Column).First();

                                        if (orderedList.Column == firstImageColumn.Key)
                                        {
                                            // image left
                                            if (includeVerticalColumn && rowIterator == firstRow)
                                            {
                                                page.AddSection(PnPCore.CanvasSectionTemplate.TwoColumnRightVerticalSection, sectionOrder, GetBackgroundEmphasis(rowIterator), verticalColumnEmphasis);
                                            }
                                            else
                                            {
                                                page.AddSection(PnPCore.CanvasSectionTemplate.TwoColumnRight, sectionOrder, GetBackgroundEmphasis(rowIterator));
                                            }
                                        }
                                        else
                                        {
                                            // image right
                                            if (includeVerticalColumn && rowIterator == firstRow)
                                            {
                                                page.AddSection(PnPCore.CanvasSectionTemplate.TwoColumnLeftVerticalSection, sectionOrder, GetBackgroundEmphasis(rowIterator), verticalColumnEmphasis);
                                            }
                                            else
                                            {
                                                page.AddSection(PnPCore.CanvasSectionTemplate.TwoColumnLeft, sectionOrder, GetBackgroundEmphasis(rowIterator));
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (includeVerticalColumn && rowIterator == firstRow)
                                        {
                                            page.AddSection(PnPCore.CanvasSectionTemplate.TwoColumnVerticalSection, sectionOrder, GetBackgroundEmphasis(rowIterator), verticalColumnEmphasis);
                                        }
                                        else
                                        {
                                            page.AddSection(PnPCore.CanvasSectionTemplate.TwoColumn, sectionOrder, GetBackgroundEmphasis(rowIterator));
                                        }
                                    }
                                }
                                else
                                {
                                    if (firstImageColumn.Value == 1 || secondImageColumn.Value == 1)
                                    {
                                        // does one of the two columns have anything else besides image web parts
                                        var firstImageColumnOtherWebParts  = webpartsInRow.Where(p => p.Column == firstImageColumn.Key && p.Type != WebParts.WikiImage);
                                        var secondImageColumnOtherWebParts = webpartsInRow.Where(p => p.Column == secondImageColumn.Key && p.Type != WebParts.WikiImage);

                                        if (!firstImageColumnOtherWebParts.Any() && !secondImageColumnOtherWebParts.Any())
                                        {
                                            // two columns with each only one image...
                                            if (includeVerticalColumn && rowIterator == firstRow)
                                            {
                                                page.AddSection(PnPCore.CanvasSectionTemplate.TwoColumnVerticalSection, sectionOrder, GetBackgroundEmphasis(rowIterator), verticalColumnEmphasis);
                                            }
                                            else
                                            {
                                                page.AddSection(PnPCore.CanvasSectionTemplate.TwoColumn, sectionOrder, GetBackgroundEmphasis(rowIterator));
                                            }
                                        }
                                        else if (!firstImageColumnOtherWebParts.Any() && secondImageColumnOtherWebParts.Any())
                                        {
                                            if (includeVerticalColumn && rowIterator == firstRow)
                                            {
                                                page.AddSection(PnPCore.CanvasSectionTemplate.TwoColumnRightVerticalSection, sectionOrder, GetBackgroundEmphasis(rowIterator), verticalColumnEmphasis);
                                            }
                                            else
                                            {
                                                page.AddSection(PnPCore.CanvasSectionTemplate.TwoColumnRight, sectionOrder, GetBackgroundEmphasis(rowIterator));
                                            }
                                        }
                                        else if (firstImageColumnOtherWebParts.Any() && !secondImageColumnOtherWebParts.Any())
                                        {
                                            if (includeVerticalColumn && rowIterator == firstRow)
                                            {
                                                page.AddSection(PnPCore.CanvasSectionTemplate.TwoColumnLeftVerticalSection, sectionOrder, GetBackgroundEmphasis(rowIterator), verticalColumnEmphasis);
                                            }
                                            else
                                            {
                                                page.AddSection(PnPCore.CanvasSectionTemplate.TwoColumnLeft, sectionOrder, GetBackgroundEmphasis(rowIterator));
                                            }
                                        }
                                        else
                                        {
                                            if (includeVerticalColumn && rowIterator == firstRow)
                                            {
                                                page.AddSection(PnPCore.CanvasSectionTemplate.TwoColumnVerticalSection, sectionOrder, GetBackgroundEmphasis(rowIterator), verticalColumnEmphasis);
                                            }
                                            else
                                            {
                                                page.AddSection(PnPCore.CanvasSectionTemplate.TwoColumn, sectionOrder, GetBackgroundEmphasis(rowIterator));
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (includeVerticalColumn && rowIterator == firstRow)
                                        {
                                            page.AddSection(PnPCore.CanvasSectionTemplate.TwoColumnVerticalSection, sectionOrder, GetBackgroundEmphasis(rowIterator), verticalColumnEmphasis);
                                        }
                                        else
                                        {
                                            page.AddSection(PnPCore.CanvasSectionTemplate.TwoColumn, sectionOrder, GetBackgroundEmphasis(rowIterator));
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (includeVerticalColumn && rowIterator == firstRow)
                                {
                                    page.AddSection(PnPCore.CanvasSectionTemplate.TwoColumnVerticalSection, sectionOrder, GetBackgroundEmphasis(rowIterator), verticalColumnEmphasis);
                                }
                                else
                                {
                                    page.AddSection(PnPCore.CanvasSectionTemplate.TwoColumn, sectionOrder, GetBackgroundEmphasis(rowIterator));
                                }
                            }
                        }
                        else if (maxColumns == 3)
                        {
                            if (includeVerticalColumn && rowIterator == firstRow)
                            {
                                page.AddSection(PnPCore.CanvasSectionTemplate.ThreeColumnVerticalSection, sectionOrder, GetBackgroundEmphasis(rowIterator), verticalColumnEmphasis);
                            }
                            else
                            {
                                page.AddSection(PnPCore.CanvasSectionTemplate.ThreeColumn, sectionOrder, GetBackgroundEmphasis(rowIterator));
                            }
                        }

                        sectionOrder++;
                    }
                }
                else
                {
                    // non used row...ignore
                }
            }
        }
        /// <summary>
        /// Transforms a classic wiki/webpart page layout into a modern client side page layout
        /// </summary>
        /// <param name="pageData">Information about the analyed page</param>
        public virtual void Transform(Tuple <Pages.PageLayout, List <WebPartEntity> > pageData)
        {
            switch (pageData.Item1)
            {
            // In case of a custom layout let's stick with one column as model
            case PageLayout.Wiki_OneColumn:
            case PageLayout.WebPart_FullPageVertical:
            case PageLayout.Wiki_Custom:
            case PageLayout.WebPart_Custom:
            {
                page.AddSection(PnPCore.CanvasSectionTemplate.OneColumn, 1);
                return;
            }

            case PageLayout.Wiki_TwoColumns:
            {
                page.AddSection(PnPCore.CanvasSectionTemplate.TwoColumn, 1);
                return;
            }

            case PageLayout.Wiki_ThreeColumns:
            {
                page.AddSection(PnPCore.CanvasSectionTemplate.ThreeColumn, 1);
                return;
            }

            case PageLayout.Wiki_TwoColumnsWithSidebar:
            case PageLayout.WebPart_2010_TwoColumnsLeft:
            {
                page.AddSection(PnPCore.CanvasSectionTemplate.TwoColumnLeft, 1);
                return;
            }

            case PageLayout.WebPart_HeaderRightColumnBody:
            {
                page.AddSection(PnPCore.CanvasSectionTemplate.OneColumn, 1);
                page.AddSection(PnPCore.CanvasSectionTemplate.TwoColumnLeft, 2);
                return;
            }

            case PageLayout.WebPart_HeaderLeftColumnBody:
            {
                page.AddSection(PnPCore.CanvasSectionTemplate.OneColumn, 1);
                page.AddSection(PnPCore.CanvasSectionTemplate.TwoColumnRight, 2);
                return;
            }

            case PageLayout.Wiki_TwoColumnsWithHeader:
            {
                page.AddSection(PnPCore.CanvasSectionTemplate.OneColumn, 1);
                page.AddSection(PnPCore.CanvasSectionTemplate.TwoColumn, 2);
                return;
            }

            case PageLayout.Wiki_TwoColumnsWithHeaderAndFooter:
            {
                page.AddSection(PnPCore.CanvasSectionTemplate.OneColumn, 1);
                page.AddSection(PnPCore.CanvasSectionTemplate.TwoColumn, 2);
                page.AddSection(PnPCore.CanvasSectionTemplate.OneColumn, 3);
                return;
            }

            case PageLayout.Wiki_ThreeColumnsWithHeader:
            {
                page.AddSection(PnPCore.CanvasSectionTemplate.OneColumn, 1);
                page.AddSection(PnPCore.CanvasSectionTemplate.ThreeColumn, 2);
                return;
            }

            case PageLayout.Wiki_ThreeColumnsWithHeaderAndFooter:
            case PageLayout.WebPart_HeaderFooterThreeColumns:
            case PageLayout.WebPart_HeaderFooter4ColumnsTopRow:
            case PageLayout.WebPart_HeaderFooter2Columns4Rows:
            {
                page.AddSection(PnPCore.CanvasSectionTemplate.OneColumn, 1);
                page.AddSection(PnPCore.CanvasSectionTemplate.ThreeColumn, 2);
                page.AddSection(PnPCore.CanvasSectionTemplate.OneColumn, 3);
                return;
            }

            case PageLayout.WebPart_LeftColumnHeaderFooterTopRow3Columns:
            case PageLayout.WebPart_RightColumnHeaderFooterTopRow3Columns:
            {
                page.AddSection(PnPCore.CanvasSectionTemplate.OneColumn, 1);
                page.AddSection(PnPCore.CanvasSectionTemplate.OneColumn, 2);
                page.AddSection(PnPCore.CanvasSectionTemplate.ThreeColumn, 3);
                page.AddSection(PnPCore.CanvasSectionTemplate.OneColumn, 4);
                return;
            }

            default:
            {
                page.AddSection(PnPCore.CanvasSectionTemplate.OneColumn, 1);
                return;
            }
            }
        }