module IHP.IDE.Data.View.ShowForeignKeyHoverCard where

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

data ShowForeignKeyHoverCardView = ShowForeignKeyHoverCardView
    { ShowForeignKeyHoverCardView -> [DynamicField]
record :: [DynamicField]
    , ShowForeignKeyHoverCardView -> Text
foreignTableName :: Text
    }

instance View ShowForeignKeyHoverCardView where
    beforeRender :: ShowForeignKeyHoverCardView -> IO ()
beforeRender ShowForeignKeyHoverCardView
_ = (?context::ControllerContext) =>
((?context::ControllerContext) => Layout) -> IO ()
((?context::ControllerContext) => Layout) -> IO ()
setLayout (\Html
view -> Html
view)
    html :: ShowForeignKeyHoverCardView -> Html
html ShowForeignKeyHoverCardView { [DynamicField]
Text
foreignTableName :: Text
record :: [DynamicField]
$sel:foreignTableName:ShowForeignKeyHoverCardView :: ShowForeignKeyHoverCardView -> Text
$sel:record:ShowForeignKeyHoverCardView :: ShowForeignKeyHoverCardView -> [DynamicField]
.. } = [hsx| 
        <div class="foreign-key-hovercard">
            <h1>{tableNameToModelName foreignTableName}</h1>
            {forEach record renderField}
        </div>
    |]
        where
            renderField :: model -> Html
renderField model
field = [hsx|
                <div class="mb-2">
                    <div style="font-size: 12px; color: rgba(197, 207, 211, 0.8)">{get #fieldName field}:</div>

                    <div>
                        {get #fieldValue field}
                    </div>
                </div>
            |]