module IHP.IDE.SchemaDesigner.View.Schema.GeneratedCode where

import IHP.ViewPrelude
import IHP.IDE.SchemaDesigner.Types
import IHP.IDE.ToolServer.Types
import IHP.IDE.ToolServer.Layout
import IHP.IDE.SchemaDesigner.View.Layout

data GeneratedCodeView = GeneratedCodeView
    { GeneratedCodeView -> [Statement]
statements :: [Statement]
    , GeneratedCodeView -> Text
generatedHaskellCode :: Text
    }

instance View GeneratedCodeView where
    html :: GeneratedCodeView -> Html
html GeneratedCodeView { [Statement]
Text
generatedHaskellCode :: Text
statements :: [Statement]
$sel:generatedHaskellCode:GeneratedCodeView :: GeneratedCodeView -> Text
$sel:statements:GeneratedCodeView :: GeneratedCodeView -> [Statement]
.. } = [hsx|
        {visualNav}
        <div class="container">
            {databaseControls}
            <div class="row no-gutters bg-white">
                {renderObjectSelector (zip [0..] statements) Nothing}
            </div>
        </div>
        {renderModal modal}
        {customCss}
    |]
        where
            modalContent :: Html
modalContent = [hsx|
                <pre class="generated-haskell-code"><code>{generatedHaskellCode}</code></pre>
            |]
            modalFooter :: Maybe Html
modalFooter = Maybe Html
forall a. Monoid a => a
mempty
            modalCloseUrl :: Text
modalCloseUrl = TablesController -> Text
forall controller. HasPath controller => controller -> Text
pathTo TablesController
TablesAction
            modalTitle :: Text
modalTitle = Text
"Generated Haskell Code"
            modal :: Modal
modal = Modal :: Html -> Maybe Html -> Text -> Text -> Modal
Modal { Html
$sel:modalContent:Modal :: Html
modalContent :: Html
modalContent, Maybe Html
$sel:modalFooter:Modal :: Maybe Html
modalFooter :: Maybe Html
modalFooter, Text
$sel:modalCloseUrl:Modal :: Text
modalCloseUrl :: Text
modalCloseUrl, Text
$sel:modalTitle:Modal :: Text
modalTitle :: Text
modalTitle }
            customCss :: Html
customCss = String -> Html
forall a. ToMarkup a => a -> Html
preEscapedToHtml [plain|
            <style>
                #modal-inner {
                    max-width: 90vw !important;
                }
            </style>|]