-module(internal@flash). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/internal/flash.gleam"). -export([set_flash_message/3, set_flash_messages/2, get_flash/1]). -export_type([flash_prop/0]). -type flash_prop() :: {flash_prop, binary(), binary()}. -file("src/internal/flash.gleam", 15). -spec flash_encode(flash_prop()) -> binary(). flash_encode(Prop) -> _pipe = gleam@json:object( [{erlang:element(2, Prop), gleam@json:string(erlang:element(3, Prop))}] ), gleam@json:to_string(_pipe). -file("src/internal/flash.gleam", 20). -spec set_cookie( binary(), gleam@http@request:request(wisp@internal:connection()) ) -> gleam@http@request:request(wisp@internal:connection()). set_cookie(Value, Req) -> {request, erlang:element(2, Req), [{<<"inertia_flash"/utf8>>, Value} | erlang:element(3, Req)], erlang:element(4, Req), erlang:element(5, Req), erlang:element(6, Req), erlang:element(7, Req), erlang:element(8, Req), erlang:element(9, Req)}. -file("src/internal/flash.gleam", 24). -spec set_flash_message( gleam@http@request:request(wisp@internal:connection()), binary(), binary() ) -> gleam@http@request:request(wisp@internal:connection()). set_flash_message(Req, Key, Msg) -> _pipe = {flash_prop, Key, Msg}, _pipe@1 = flash_encode(_pipe), set_cookie(_pipe@1, Req). -file("src/internal/flash.gleam", 28). -spec set_flash_messages( gleam@http@request:request(wisp@internal:connection()), list(flash_prop()) ) -> gleam@http@request:request(wisp@internal:connection()). set_flash_messages(Req, Messages) -> _pipe = Messages, _pipe@1 = gleam@list:map( _pipe, fun(Fp) -> {erlang:element(2, Fp), gleam@json:string(erlang:element(3, Fp))} end ), _pipe@2 = gleam@json:object(_pipe@1), _pipe@3 = gleam@json:to_string(_pipe@2), set_cookie(_pipe@3, Req). -file("src/internal/flash.gleam", 36). -spec get_flash(gleam@http@request:request(wisp@internal:connection())) -> gleam@option:option(gleam@dict:dict(binary(), binary())). get_flash(Req) -> case wisp:get_cookie(Req, <<"inertia_flash"/utf8>>, plain_text) of {ok, Res} -> Dec = gleam@dynamic@decode:dict( {decoder, fun gleam@dynamic@decode:decode_string/1}, {decoder, fun gleam@dynamic@decode:decode_string/1} ), case gleam@json:parse(Res, Dec) of {ok, Obj} -> {some, Obj}; {error, _} -> none end; {error, _} -> none end.