module IHP.IDE.SchemaDesigner.View.Schema.Code 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 CodeView = CodeView
    { CodeView -> Text
schema :: Text
    , CodeView -> Maybe ByteString
error :: Maybe ByteString
    }

instance View CodeView where
    html :: CodeView -> Html
html CodeView { Maybe ByteString
Text
error :: Maybe ByteString
schema :: Text
$sel:error:CodeView :: CodeView -> Maybe ByteString
$sel:schema:CodeView :: CodeView -> Text
.. } = [hsx|
        <div class="editor-container">
            <div id="editor">{preEscapedToHtml schema}</div>
        </div>
        {errorDiv}
        <div class="toolbox">
            <button id="save-button" class="btn btn-primary">Save</button>
        </div>
    |]
        where
            errorDiv :: Html
errorDiv = case Maybe ByteString
error of
                Maybe ByteString
Nothing -> Html
forall a. Monoid a => a
mempty
                Just ByteString
error -> String -> Html
forall a. ToMarkup a => a -> Html
preEscapedToHtml [plain|
                        <div class="error-box">
                            <pre class="text-white p-5">#{error}</pre>
                        </div>
                    |]