<?php
declare(strict_types=1);

namespace WP_AUX\Entities\Embeds\VideoSource;

use WP_AUX\Entities\Embeds\VideoSourceEntity;

class VimeoVideoSourceEntity extends VideoSourceEntity
{
  public static string $urlPattern = '/.*(?:vimeo.com\/|video\/)([0-9]*).*/';
  public static string $embedPattern = 'https://player.vimeo.com/video/{id}';
  public static string $linkPattern = 'https://vimeo.com/{id}';

  public static string $allowFullscreen = 'allowfullscreen';

  protected function embedUrlParams(): string
  {
    $params = [];

    if ($this->autoplay) {
      if ($this->disableControls) {
        $params[] = 'background=1';
      } else {
        $params[] = 'autoplay=1&autopause=0';
        $params[] = 'muted=1';
      }
    } else {
      if ($this->muted) {
        $params[] = 'muted=1';
      }

      if ($this->disableControls) {
        $params[] = 'controls=0';
      }
    }

    if ($this->loop) {
      $params[] = 'loop=1';
    }

    return join('&', $params);
  }
}
