{{- warnf "The \"twitter\", \"tweet\", and \"twitter_simple\" shortcodes were deprecated in v0.142.0 and will be removed in a future release. Please use the \"x\" shortcode instead." }}
{{- if not site.Config.Privacy.Twitter.Disable -}}
  {{- $id := or (.Get "id") "" -}}
  {{- $user := or (.Get "user") "" -}}
  {{- if and $id $user -}}
    {{- template "render-simple-tweet" (dict "id" $id "user" $user "ctx" .) -}}
  {{- else -}}
    {{- errorf "The %q shortcode requires two named parameters: user and id. See %s" .Name .Position -}}
  {{- end -}}
{{- end -}}

{{- define "render-simple-tweet" -}}
  {{- $dnt := site.Config.Privacy.Twitter.EnableDNT }}
  {{- $url := printf "https://twitter.com/%v/status/%v" .user .id -}}
  {{- $query := querify "url" $url "dnt" $dnt "omit_script" true -}}
  {{- $request := printf "https://publish.twitter.com/oembed?%s" $query -}}
  {{- with try (resources.GetRemote $request) -}}
    {{- with .Err -}}
      {{- warnidf "shortcode-twitter-simple-getremote" "The %q shortcode was unable to retrieve the remote data: %s. See %s" $.ctx.Name . $.ctx.Position -}}
    {{- else with .Value -}}
      {{- if not site.Config.Services.Twitter.DisableInlineCSS }}
        {{- template "__h_simple_twitter_css" (dict "ctx" $.ctx) }}
      {{- end }}
      {{- (. | transform.Unmarshal).html | safeHTML -}}
    {{- else -}}
      {{- warnidf "shortcode-twitter-simple-getremote" "The %q shortcode was unable to retrieve the remote data. See %s" $.ctx.Name $.ctx.Position -}}
    {{- end -}}
  {{- end -}}
{{- end -}}

{{- define "__h_simple_twitter_css" -}}
  {{- if not (.ctx.Page.Store.Get "__h_simple_twitter_css") -}}
    {{/* Only include once */}}
    {{- .ctx.Page.Store.Set "__h_simple_twitter_css" true -}}
    <style type="text/css">
      .twitter-tweet {
        font:
          14px/1.45 -apple-system,
          BlinkMacSystemFont,
          "Segoe UI",
          Roboto,
          Oxygen-Sans,
          Ubuntu,
          Cantarell,
          "Helvetica Neue",
          sans-serif;
        border-left: 4px solid #2b7bb9;
        padding-left: 1.5em;
        color: #555;
      }
      .twitter-tweet a {
        color: #2b7bb9;
        text-decoration: none;
      }
      blockquote.twitter-tweet a:hover,
      blockquote.twitter-tweet a:focus {
        text-decoration: underline;
      }
    </style>
  {{- end -}}
{{- end -}}
