extends ../layouts/room
block content

  - var actionUrl = room ? `/chat/room/${room._id}` : '/chat/room';

  .content-block.uk-height-1-1.uk-overflow-auto
    form(method="POST", action= actionUrl).uk-form
      .uk-card.uk-card-default.uk-card-small
        .uk-card-header
          div(uk-grid).uk-grid-small.uk-flex-middle
            .uk-width-expand
              h1.uk-card-title.uk-text-truncate #{room ? room.name : 'Create Chat Room'}
            if room
              .uk-width-auto
                button(type="button", onclick="return dtp.app.chat.deleteChatRoom(event);").uk-button.uk-button-danger.uk-border-rounded
                  span
                    i.fas.fa-trash
                  span.uk-margin-small-left Delete

        .uk-card-body
          .uk-margin
            label(for="name").uk-form-label Room name
            input(id="name", name="name", type="text", placeholder="Enter room name", value= room ? room.name : undefined).uk-input

          .uk-margin
            label(for="description").uk-form-label Room description
            textarea(id="description", name="description", rows="2", placeholder="Enter room description").uk-textarea= room ? room.description : undefined

          .uk-margin
            label(for="policy").uk-form-label Room policy
            textarea(id="policy", name="policy", rows="2", placeholder="Enter room use policy").uk-textarea= room ? room.policy : undefined

          .uk-margin
            div(uk-grid)
              .uk-width-auto
                fieldset
                  legend Room Visibility
                  div(uk-grid).uk-grid-small.uk-flex-middle
                    .uk-width-auto
                      label
                        input(id="is-public", name="visibility", type="radio", value="public", checked= room ? room.visibility === 'public' : true).uk-radio
                        |  Public
                    .ui-width-auto
                      label
                        input(id="is-private", name="visibility", type="radio", value="private", checked= room ? room.visibility === 'private' : false).uk-radio
                        |  Private

              .uk-width-auto
                fieldset
                  legend Membership Policy
                  div(uk-grid).uk-grid-small.uk-flex-middle
                    .uk-width-auto
                      label
                        input(id="membership-open", name="membershipPolicy", type="radio", value="open", checked= room ? room.membershipPolicy === 'open' : true).uk-radio
                        |  Open
                    .uk-width-auto
                      label
                        input(id="membership-closed", name="membershipPolicy", type="radio", value="closed", checked= room ? room.membershipPolicy === 'closed' : false).uk-radio
                        |  Closed

        .uk-card-footer
          div(uk-grid)
            .uk-width-expand
              +renderBackButton()
            .uk-width-auto
              button(type="submit").uk-button.uk-button-primary.uk-border-rounded #{room ? 'Update' : 'Create'} room