<?php

namespace PHPNative\Tailwind\Parser;

use PHPNative\Tailwind\Style\OverflowEnum;

class Overflow
{

    public static function parse(string $style): ?\PHPNative\Tailwind\Style\Overflow
    {
        preg_match_all("/overflow-auto/", $style, $output_array);
        if (count($output_array[0]) > 0) {
            return new \PHPNative\Tailwind\Style\Overflow(x: OverflowEnum::auto, y: OverflowEnum::auto);
        }

        preg_match_all("/overflow-x-(auto|scroll|hidden|clip)/", $style, $output_array);
        if (count($output_array[0]) > 0) {
            $value = match($output_array[1][0]) {
                'auto' => OverflowEnum::auto,
                'scroll' => OverflowEnum::scroll,
                'hidden' => OverflowEnum::hidden,
                'clip' => OverflowEnum::clip
            };
            return new \PHPNative\Tailwind\Style\Overflow(x: $value);
        }
        preg_match_all("/overflow-y-(auto|scroll|hidden|clip)/", $style, $output_array);
        if (count($output_array[0]) > 0) {
            $value = match($output_array[1][0]) {
                'auto' => OverflowEnum::auto,
                'scroll' => OverflowEnum::scroll,
                'hidden' => OverflowEnum::hidden,
                'clip' => OverflowEnum::clip
            };
            return new \PHPNative\Tailwind\Style\Overflow(y: $value);
        }
        return null;
    }
}