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

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

data EditEnumValueView = EditEnumValueView
    { EditEnumValueView -> [Statement]
statements :: [Statement]
    , EditEnumValueView -> Text
enumName :: Text
    , EditEnumValueView -> Int
valueId :: Int
    , EditEnumValueView -> Text
value :: Text
    }

instance View EditEnumValueView where
    html :: EditEnumValueView -> Html
html EditEnumValueView { Int
[Statement]
Text
value :: Text
valueId :: Int
enumName :: Text
statements :: [Statement]
$sel:value:EditEnumValueView :: EditEnumValueView -> Text
$sel:valueId:EditEnumValueView :: EditEnumValueView -> Int
$sel:enumName:EditEnumValueView :: EditEnumValueView -> Text
$sel:statements:EditEnumValueView :: EditEnumValueView -> [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
            enum :: Maybe Statement
enum = 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
enum
            
            modalContent :: Html
modalContent = [hsx|
                <form method="POST" action={UpdateEnumValueAction}>
                    <input type="hidden" name="enumName" value={enumName}/>
                    <input type="hidden" name="valueId" value={tshow valueId}/>

                    <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" value={value}/>
                        </div>
                    </div>

                    <div class="text-right">
                        <button type="submit" class="btn btn-primary">Edit Enum Value</button>
                    </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
"Edit 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 }