<?php

use Drupal\user\Entity\User;
use Drupal\shortcut\Entity\Shortcut;

/**
 * @file
 * Install, update and uninstall functions for the profilename install profile.
 */

/**
 * Implements hook_install().
 *
 * Perform actions to set up the site for this profile.
 *
 * @see system_install()
 */
function kamihaya_cms_install() {
  \Drupal::service('theme_installer')->install(['kamihaya_digitalagency', 'gin']);
  \Drupal::configFactory()
    ->getEditable('system.theme')
    ->set('default', 'kamihaya_digitalagency')
    ->set('admin', 'gin')
    ->save();
  // Use admin theme while editing the content
  // \Drupal::configFactory()
  //   ->getEditable('node.settings')
  //   ->set('use_admin_theme', 'true')
  //   ->save();
}

/**
 * Install custom modules.
 */
function kamihaya_cms_update_10001() {
  $modules = [];
  if (!\Drupal::moduleHandler()->moduleExists('kamihaya_cms_language_selector')) {
    $modules[] = 'kamihaya_cms_language_selector';
  }
  if (!\Drupal::moduleHandler()->moduleExists('kamihaya_cms_menu_icon')) {
    $modules[] = 'kamihaya_cms_menu_icon';
  }

  if (empty($modules)) {
    return;
  }
  /** @var \Drupal\Core\Extension\ModuleInstallerInterface $module_installer */
  $module_installer = \Drupal::service("module_installer");
  $module_installer->install($modules);
}

/**
 * Install custom modules.
 */
function kamihaya_cms_update_10002() {
  $modules = [];
  if (!\Drupal::moduleHandler()->moduleExists('kamihaya_cms_media_type')) {
    $modules[] = 'kamihaya_cms_media_type';
  }
  if (!\Drupal::moduleHandler()->moduleExists('kamihaya_cms_paragraph_type')) {
    $modules[] = 'kamihaya_cms_paragraph_type';
  }
  if (!\Drupal::moduleHandler()->moduleExists('kamihaya_cms_content_type')) {
    $modules[] = 'kamihaya_cms_content_type';
  }

  if (empty($modules)) {
    return;
  }
  /** @var \Drupal\Core\Extension\ModuleInstallerInterface $module_installer */
  $module_installer = \Drupal::service("module_installer");
  $module_installer->install($modules);
}

/**
 * Install custom modules.
 */
function kamihaya_cms_update_10003() {
  $modules = [];
  if (!\Drupal::moduleHandler()->moduleExists('kamihaya_cms_block_type')) {
    $modules[] = 'kamihaya_cms_block_type';
  }

  if (empty($modules)) {
    return;
  }
  /** @var \Drupal\Core\Extension\ModuleInstallerInterface $module_installer */
  $module_installer = \Drupal::service("module_installer");
  $module_installer->install($modules);
}

/**
 * Install Editoria11y Accessibility Checker module.
 */
function kamihaya_cms_update_10004() {
  $modules = [];
  if (!\Drupal::moduleHandler()->moduleExists('editoria11y')) {
    $modules[] = 'editoria11y';
  }

  if (empty($modules)) {
    return;
  }
  /** @var \Drupal\Core\Extension\ModuleInstallerInterface $module_installer */
  $module_installer = \Drupal::service("module_installer");
  $module_installer->install($modules);
}

/**
 * Install Block Field and Views Reference module.
 */
function kamihaya_cms_update_10005() {
  $modules = [];
  if (!\Drupal::moduleHandler()->moduleExists('block_field')) {
    $modules[] = 'block_field';
  }
  if (!\Drupal::moduleHandler()->moduleExists('viewsreference')) {
    $modules[] = 'viewsreference';
  }

  if (empty($modules)) {
    return;
  }
  /** @var \Drupal\Core\Extension\ModuleInstallerInterface $module_installer */
  $module_installer = \Drupal::service("module_installer");
  $module_installer->install($modules);
}

/**
 * Install Blazy and Slick modules.
 */
function kamihaya_cms_update_10006() {
  $modules = [];
  if (!\Drupal::moduleHandler()->moduleExists('blazy')) {
    $modules[] = 'blazy';
  }
  if (!\Drupal::moduleHandler()->moduleExists('slick')) {
    $modules[] = 'slick';
  }

  if (empty($modules)) {
    return;
  }
  /** @var \Drupal\Core\Extension\ModuleInstallerInterface $module_installer */
  $module_installer = \Drupal::service("module_installer");
  $module_installer->install($modules);
}

/**
 * Install Twig weak module.
 */
function kamihaya_cms_update_10007() {
  $modules = [];
  if (!\Drupal::moduleHandler()->moduleExists('twig_tweak')) {
    $modules[] = 'twig_tweak';
  }

  if (empty($modules)) {
    return;
  }
  /** @var \Drupal\Core\Extension\ModuleInstallerInterface $module_installer */
  $module_installer = \Drupal::service("module_installer");
  $module_installer->install($modules);
}

/**
 * Install Metatag Views module.
 */
function kamihaya_cms_update_10008() {
  \Drupal::service('module_installer')->install(['metatag_views'], TRUE);
}

/**
 * Install Webp module.
 */
function kamihaya_cms_update_10009() {
  $modules = [];
  if (!\Drupal::moduleHandler()->moduleExists('webp')) {
    $modules[] = 'webp';
  }

  if (empty($modules)) {
    return;
  }
  /** @var \Drupal\Core\Extension\ModuleInstallerInterface $module_installer */
  $module_installer = \Drupal::service("module_installer");
  $module_installer->install($modules);
}
