@*   Xafari Framework version : 17.2.3011.1336   *@

@using DevExpress.ExpressApp.Editors
@using Xafari.Mvc.Editors
@using Xafari.Mvc.MVCx.Editors

@model Xafari.Mvc.Layout.LayoutItemContainer

@{
    //Change current Frame to rendering for NestedFrames
    var frameContainer = this.Model.ViewItem as IFrameContainer;
    var currentFrame = this.ViewData.Frame();

    try
    {
        if (frameContainer != null)
        {
            this.ViewData.SetFrame(frameContainer.Frame);
        }

        var viewItem = this.Model.ViewItem;
        var control = viewItem == null ? null : viewItem.Control as IMvcControl;
        if (control != null)
        {
            if (this.Model.ViewItem is PropertyEditor)
            {
                ((PropertyEditor)this.Model.ViewItem).ReadValue();
            }

            var mvcxPropertyEditor = this.Model.ViewItem as MvcPropertyEditor;
            if (mvcxPropertyEditor != null)
            {
                if (mvcxPropertyEditor.ViewEditMode == ViewEditMode.Edit)
                {
                    <table id="WebEditorContainer" style="border: 0; width: 100%">
                        <tr>
                            @if (!string.IsNullOrEmpty(mvcxPropertyEditor.ErrorMessage))
                            {
                                <td style="padding: 0; text-align: left; width: 1px">
                                    @{
                                PrepareErrorCellEventArgs args = new PrepareErrorCellEventArgs(/*this.Editor, errorCell*/);
                                mvcxPropertyEditor.OnPrepareErrorCell(args);
                                if (!args.Handled)
                                {
                                    var title = mvcxPropertyEditor.ErrorMessage;
                                    var alt = "Error";
                                    var style = "height:16px;width:16px;border-width:0px;margin:5px;";

                                    @Html.Xafari().ImageInfo(mvcxPropertyEditor.ErrorIcon, new { title, alt, style }).GetHtml();
                                }
                                    }
                                </td>
                            }
                            <td class="WebEditorCell" style="padding: 0; text-align: left; width: 100%" title="@(mvcxPropertyEditor.Model.ToolTip)">
                                @Html.Xafari().MvcControl(control).GetHtml()
                            </td>
                        </tr>
                    </table>
                }
                else
                {
                    <div class="WebEditorCell" style="text-align: left" title="@(mvcxPropertyEditor.Model.ToolTip)">
                        @Html.Xafari().MvcControl(control).GetHtml()
                    </div>
                }
            }
            else
            {
                @Html.Xafari().MvcControl(control).GetHtml()
            }

        }
        else
        {
            <div class="EmptySpace"></div>
        }
    }
    finally
    {
        if (frameContainer != null)
        {
            this.ViewData.SetFrame(currentFrame);
        }
    }
}
