////
/// @group site.rems
////

@use '../utils' as *;
@use 'config' as *;

// ---------------------------------------------------------------------------
// PUBLIC API
// ---------------------------------------------------------------------------

/// Convert px to rem for a given base font size (the font size of the document root element)
/// @example rems(1.5px) => 0.1rem;

@function rems($px, $round: 1000) {
    $px: strip-unit($px);
    $basepx: strip-unit(get(font-size-base));

    @if (is-number($px)) {
        $r: divide($px, $basepx) * 1rem;
        @return if(sass($round > 0): round-f($r, $round) ; else: $r);
    } @else {
        @warn 'Could not convert "#{$px}" to rems because it is not a number.';
        @return $px;
    }
}

/// Convert rem to px for a given base font size (the font size of the document root element)
/// @example px(1.3rem, 10px) => 13px

@function px($rems, $basepx: null) {
    $basepx: if-null($basepx, get(font-size-base));
    $rems: strip-unit($rems) * 1rem;
    @return divide($rems * $basepx, 1rem);
}
