{{!
  Copyright IBM Corp. 2016, 2025
  SPDX-License-Identifier: BUSL-1.1
}}

<Messages::TabPageHeader
  @authenticated={{@message.authenticated}}
  @pageTitle={{@message.title}}
  @breadcrumbs={{@breadcrumbs}}
/>

<Toolbar>
  <ToolbarActions aria-label="message delete and edit">
    {{#if @capabilities.canDelete}}
      <ConfirmAction
        class="toolbar-button"
        @buttonColor="secondary"
        @onConfirmAction={{this.deleteMessage}}
        @confirmTitle="Are you sure?"
        @confirmMessage="This will delete this message permanently. You cannot undo this action."
        @buttonText="Delete message"
      />
      <div class="toolbar-separator"></div>
    {{/if}}
    {{#if @capabilities.canUpdate}}
      <LinkTo class="toolbar-link" @route="messages.message.edit" @model={{@message.id}} data-test-link-to="edit">
        Edit message
        <Icon @name="chevron-right" />
      </LinkTo>
    {{/if}}
  </ToolbarActions>
</Toolbar>

{{#each this.displayFields as |field|}}
  {{#if (or (eq field "end_time") (eq field "start_time"))}}
    {{! if the attr is an end_time and is falsy, we want to show a 'Never' text value }}
    <InfoTableRow
      @label={{capitalize (humanize (dasherize field))}}
      @value={{if
        (and (eq field "end_time") (not (get @message field)))
        "Never"
        (date-format (get @message field) "MMM d, yyyy hh:mm aaa" withTimeZone=true)
      }}
    />
  {{else if (eq field "link")}}
    {{#if (is-empty-value @message.link)}}
      <InfoTableRow @label="Link" @value="None" />
    {{else}}
      {{#each-in @message.link as |title href|}}
        <InfoTableRow @label="Link" @value={{title}}>
          <Hds::Link::Inline @icon="external-link" @href={{href}} data-test-link="message link">{{title}}</Hds::Link::Inline>
        </InfoTableRow>
      {{/each-in}}
    {{/if}}
  {{else}}
    <InfoTableRow @label={{capitalize (humanize (dasherize field))}} @value={{get @message field}} />
  {{/if}}

{{/each}}