module IHP.IDE.SchemaDesigner.View.EnumValues.New where

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

data NewEnumValueView = NewEnumValueView
    { NewEnumValueView -> [Statement]
statements :: [Statement]
    , NewEnumValueView -> Text
enumName :: Text
    }

instance View NewEnumValueView where
    html :: NewEnumValueView -> Html
html NewEnumValueView { [Statement]
Text
enumName :: Text
statements :: [Statement]
$sel:enumName:NewEnumValueView :: NewEnumValueView -> Text
$sel:statements:NewEnumValueView :: NewEnumValueView -> [Statement]
.. } = [hsx|
        <div class="row no-gutters bg-white" id="schema-designer-viewer">
            {renderObjectSelector (zip [0..] statements) (Just enumName)}
            {renderEnumSelector enumName (zip [0..] values)}
        </div>
        {migrationStatus}
        {renderModal modal}
    |]
        where
            table :: Maybe Statement
table = Text -> [Statement] -> Maybe Statement
forall (t :: * -> *).
Foldable t =>
Text -> t Statement -> Maybe Statement
findStatementByName Text
enumName [Statement]
statements
            values :: [Text]
values = [Text] -> (Statement -> [Text]) -> Maybe Statement -> [Text]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (Proxy "values" -> Statement -> [Text]
forall model (name :: Symbol) value.
(KnownSymbol name, HasField name model value) =>
Proxy name -> model -> value
get IsLabel "values" (Proxy "values")
Proxy "values"
#values) Maybe Statement
table

            modalContent :: Html
modalContent = [hsx|
                <form method="POST" action={CreateEnumValueAction}>
                    <input type="hidden" name="enumName" value={enumName}/>

                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label">Name:</label>
                        <div class="col-sm-10">
                            <input name="enumValueName" type="text" class="form-control" autofocus="autofocus"/>
                            <div class="invalid-feedback">It's highly recommended to use snake case / underscores for naming your enum values</div>
                            <small class="text-muted">
                                Use underscores instead of camel case. E.g.: <code>public_user</code>, <code>in_progress</code>, <code>currency_eur</code>
                            </small>
                        </div>
                    </div>

                    <div class="text-right">
                        <input type="submit" name="submit" value="Save" class="btn btn-secondary mr-2">
                        <input type="submit" name="submit" value="Save & Add Another" class="btn btn-primary">
                    </div>
                </form>
            |]
            modalFooter :: Maybe Html
modalFooter = Maybe Html
forall a. Monoid a => a
mempty 
            modalCloseUrl :: Text
modalCloseUrl = EnumsController -> Text
forall controller. HasPath controller => controller -> Text
pathTo ShowEnumAction :: Text -> EnumsController
ShowEnumAction { Text
$sel:enumName:ShowEnumAction :: Text
enumName :: Text
enumName }
            modalTitle :: Text
modalTitle = Text
"New Enum Value"
            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 }