@use '@nice-digital/nds-core/scss/visibility';
@use '@nice-digital/nds-core/scss/colours';

////
/// @group helpers
////

.show-print {
  @include visibility.show-print;
}

.hide-print {
  @include visibility.hide-print;
}

.remove-appended-print-link {
  @include visibility.remove-appended-print-link;
}

/// Whether to output a default set of generic print styles for things
/// like avoiding page breaks after headings etc. If you disabled this,
/// be sure to add your own print styles.
/// @since 0.2.0
$output-default-print-styles: true !default;

// Printing
// -------------------------
// Source: https://github.com/h5bp/html5-boilerplate/blob/master/css/main.css
@if $output-default-print-styles {
  @media print {
    * {
      background: transparent !important;
      box-shadow: none !important;
      color: colours.$text-print !important; // Black prints faster: h5bp.com/s
      text-shadow: none !important;
    }

    a,
    a:visited {
      text-decoration: underline;
    }

    // Don't show links in headings
    // stylelint-disable no-descending-specificity
    h1 a,
    h2 a,
    h3 a,
    h4 a,
    h5 a,
    h6 a {
      @include visibility.remove-appended-print-link;
    }

    a[href]:after {
      content: ' (' attr(href) ')';
    }

    abbr[title]:after {
      content: ' (' attr(title) ')';
    }

    // Don't show links for images, or javascript/internal links
    .ir a:after,
    a[href^='javascript:']:after,
    a[href^='#']:after {
      content: '';
    }

    pre,
    blockquote {
      border: 1px solid #999;
      page-break-inside: avoid;
    }

    thead {
      display: table-header-group; // h5bp.com/t
    }

    tr,
    img {
      page-break-inside: avoid;
    }

    img {
      max-width: 100% !important;
    }

    // Hide all images that don't have, or have a blank, alt attribute
    img:not([alt]),
    img[alt=''] {
      @include visibility.hide-print;
    }

    @page {
      margin: 0.5cm;
    }

    p,
    h2,
    h3 {
      orphans: 3;
      widows: 3;
    }

    h2,
    h3 {
      page-break-after: avoid;
    }
  }
}
