-module(gaveta).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/gaveta.gleam").
-export([extract_page_from_link/2]).
-file("src/gaveta.gleam", 7).
-spec extract_page_from_link(list({binary(), binary()}), binary()) -> gleam@option:option(integer()).
extract_page_from_link(Headers, Rel) ->
_pipe = Headers,
_pipe@8 = gleam@list:find_map(
_pipe,
fun(H) ->
{Name, Value} = H,
case Name =:= <<"link"/utf8>> of
false ->
{error, nil};
true ->
_pipe@1 = Value,
_pipe@2 = gleam@string:split(_pipe@1, <<", "/utf8>>),
gleam@list:find_map(
_pipe@2,
fun(Part) ->
Rel_param = <<<<"rel=\""/utf8, Rel/binary>>/binary,
"\""/utf8>>,
case gleam@string:split_once(Part, <<"; "/utf8>>) of
{ok, {Url, R}} when R =:= Rel_param ->
_pipe@3 = Url,
_pipe@4 = gleam@string:drop_start(
_pipe@3,
1
),
_pipe@5 = gleam@string:drop_end(_pipe@4, 1),
_pipe@6 = gleam@string:split(
_pipe@5,
<<"page="/utf8>>
),
_pipe@7 = gleam@list:last(_pipe@6),
gleam@result:'try'(
_pipe@7,
fun gleam_stdlib:parse_int/1
);
_ ->
{error, nil}
end
end
)
end
end
),
gleam@option:from_result(_pipe@8).