-------------------------------------------------------------------------------
--                                                                           --
--               M A L E F - S T Y L E S - S H E E T S . A D B               --
--                                                                           --
--                                 M A L E F                                 --
--                                                                           --
--                              A D A   B O D Y                              --
--                                                                           --
-------------------------------------------------------------------------------
--  Copyright (c) 2021-2024 José Antonio Verde Jiménez  All Rights Reserved  --
-------------------------------------------------------------------------------
-- This file is part of Malef.                                               --
--                                                                           --
-- This program is free software:  you  can redistribute it and/or modify it --
-- under  the terms  of the  GNU  General License  as published by the  Free --
-- Software  Foundation,  either  version 3  of  the  License,  or  (at your --
-- opinion) any later version.                                               --
--                                                                           --
-- This  program  is distributed  in the  hope that  it will be  useful, but --
-- WITHOUT   ANY   WARRANTY;   without   even  the   implied   warranty   of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General --
-- Public License for more details.                                          --
--                                                                           --
-- You should have received  a copy of the  GNU General Public License along --
-- with this program. If not, see <https://www.gnu.org/licenses/>.           --
--                                                                           --
-------------------------------------------------------------------------------

with Malef.Styles.Classes;

package body Malef.Styles.Sheets is

   procedure Insert (
      Sheet    : in out Style_Sheet;
      Key      : in     Wide_Wide_String;
      New_Item : in     Style)
   is
      Position : Style_Maps.Cursor;
      Inserted : Boolean;
   begin
      for Class of Classes.Value (Key) loop
         Style_Maps.Insert (
            Container => Sheet.Map,
            Key       => Class,
            New_Item  => New_Item,
            Position  => Position,
            Inserted  => Inserted);
         if not Inserted then
            Style_Maps.Replace_Element (
               Container => Sheet.Map,
               Position  => Position,
               New_Item  => Sheet.Map (Position) + New_Item);
         end if;
      end loop;
   end Insert;

   procedure Put_Image (
      Buffer : in out Ada.Strings.Text_Buffers.Root_Buffer_Type'Class;
      Arg    : in     Style_Sheet) is
   begin
      for Cursor in Arg.Map.Iterate loop
         Buffer.Wide_Wide_Put (Style_Maps.Key (Cursor));
         Buffer.Put (" ");
         Put_Image (Buffer, Arg.Map (Cursor));
         Buffer.New_Line;
      end loop;
   end Put_Image;

end Malef.Styles.Sheets;
