// Copyright (c) 2014, 2026, Oracle and/or its affiliates.  Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/


@import "oj.utilities.bidi";



//*****************************************************************************
// flips the right and left properties if needed.
//*****************************************************************************

@function oj-shorthand-property-rtl-flip ($propertyValue)
{ 

  // when the property value length is less than 3 it means the right 
  // and left are the same, so we only need to flip anything if all 4 
  // sides are specified
  @if (length($propertyValue) == 4)
  { 
    @return nth($propertyValue, 1) nth($propertyValue, 4) nth($propertyValue, 3) nth($propertyValue, 2);
  }

  @return $propertyValue;
}

//*****************************************************************************
// sometimes "shorthand" properties are used, as in 
//   border-width: 1px 2px 0 3px.
// this function lets you ask for the value of a particular side
//*****************************************************************************

@function oj-shorthand-property-value-side ($propertyValue, $side)
{
  @if ($side == top or length($propertyValue) == 1 )
  {
    @return nth($propertyValue, 1);
  }
  @else if (length($propertyValue) == 2)
  {
    @if ($side == bottom)
    {
      @return nth($propertyValue, 1);
    }
    @else
    {
      @return nth($propertyValue, 2);
    }
  }
  @else if (length($propertyValue) == 3)
  {
    @if ($side == bottom)
    {
      @return nth($propertyValue, 3);
    }
    @else
    {
      @return nth($propertyValue, 2);
    }
  }
  @else if (length($propertyValue) == 4)
  {
    @if ($side == right)
    {
      @return nth($propertyValue, 2);
    }
    @if ($side == bottom)
    {
      @return nth($propertyValue, 3);
    }
    @else
    {
      @return nth($propertyValue, 4);
    }
  }
}


@function oj-shorthand-property-value-top ($propertyValue)
{
  @return oj-shorthand-property-value-side($propertyValue, top);
}

@function oj-shorthand-property-value-right ($propertyValue)
{
  @return oj-shorthand-property-value-side($propertyValue, right);
}

@function oj-shorthand-property-value-bottom ($propertyValue)
{
  @return oj-shorthand-property-value-side($propertyValue, bottom);
}

@function oj-shorthand-property-value-left ($propertyValue)
{
  @return oj-shorthand-property-value-side($propertyValue, left);
}