defmodule Phosphoricons do
  @moduledoc """
  Provides precompiled icon compiles from [heroicons.com v<%= @vsn %>](heroicons.com).

  Heroicons are designed by [Steve Schoger](https://twitter.com/steveschoger)

  ## Usage

  Hero icons come in three styles – outline (`24x24`), solid (`24x24`), and mini (`20x20`).

  By default, the icon components will use the outline style, but the `solid` or
  `mini` attributes may be passed to select styling, for example:

  ```heex
  <Heroicons.cake />
  <Heroicons.cake solid />
  <Heroicons.cake mini />
  ```

  You can also pass arbitrary HTML attributes to the components:

   ```heex
  <Heroicons.cake class="w-2 h-2" />
  <Heroicons.cake solid class="w-2 h-2" />
  ```

  ## Heroicons License Attribution

  MIT License

  Copyright (c) 2020 Refactoring UI Inc.

  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  SOFTWARE.
  """
  use Phoenix.Component

  defp svg(assigns) do
    case assigns do
      %{bold: false, duotone: false, fill: false, light: false, thin: false} ->
        ~H"<.svg_regular {@rest}><%%= {:safe, @paths[:regular]} %></.svg_regular>"
      %{bold: true, duotone: false, fill: false, light: false, thin: false} ->
        ~H"<.svg_bold {@rest}><%%= {:safe, @paths[:bold]} %></.svg_bold>"
      %{bold: false, duotone: true, fill: false, light: false, thin: false} ->
        ~H"<.svg_duotone {@rest}><%%= {:safe, @paths[:duotone]} %></.svg_duotone>"
      %{bold: false, duotone: false, fill: true, light: false, thin: false} ->
        ~H"<.svg_fill {@rest}><%%= {:safe, @paths[:fill]} %></.svg_fill>"
      %{bold: false, duotone: false, fill: false, light: true, thin: false} ->
        ~H"<.svg_light {@rest}><%%= {:safe, @paths[:light]} %></.svg_light>"
      %{bold: false, duotone: false, fill: false, light: false, thin: true} ->
        ~H"<.svg_thin {@rest}><%%= {:safe, @paths[:thin]} %></.svg_thin>"
      %{} -> raise ArgumentError, "expected one of bold, duotone, fill, light or thin, but got multiple."
    end
  end


  attr :rest, :global, default: %{"aria-hidden": "true", viewBox: "0 0 256 256", fill: "none", stroke: "currentColor"}
  slot :inner_block, required: true
  defp svg_regular(assigns) do
    ~H"""
    <svg xmlns="http://www.w3.org/2000/svg" {@rest}>
      <%%= render_slot(@inner_block) %>
    </svg>
    """
  end

  attr :rest, :global, default: %{"aria-hidden": "true", viewBox: "0 0 256 256", fill: "none", stroke: "currentColor"}
  slot :inner_block, required: true
  defp svg_bold(assigns) do
    ~H"""
    <svg xmlns="http://www.w3.org/2000/svg" {@rest}>
    <%%= render_slot(@inner_block) %>
    </svg>
    """
  end

  attr :rest, :global, default: %{"aria-hidden": "true", viewBox: "0 0 256 256", fill: "currentColor", stroke: "currentColor"}
  slot :inner_block, required: true
  defp svg_duotone(assigns) do
    ~H"""
    <svg xmlns="http://www.w3.org/2000/svg" {@rest}>
    <%%= render_slot(@inner_block) %>
    </svg>
    """
  end

  attr :rest, :global, default: %{"aria-hidden": "true", viewBox: "0 0 256 256", fill: "currentColor"}
  slot :inner_block, required: true
  defp svg_fill(assigns) do
    ~H"""
    <svg xmlns="http://www.w3.org/2000/svg" {@rest}>
      <%%= render_slot(@inner_block) %>
    </svg>
    """
  end

  attr :rest, :global, default: %{"aria-hidden": "true", viewBox: "0 0 256 256", fill: "none", stroke: "currentColor"}
  slot :inner_block, required: true
  defp svg_light(assigns) do
    ~H"""
    <svg xmlns="http://www.w3.org/2000/svg" {@rest}>
    <%%= render_slot(@inner_block) %>
    </svg>
    """
  end

  attr :rest, :global, default: %{"aria-hidden": "true", viewBox: "0 0 256 256", fill: "none", stroke: "currentColor"}
  slot :inner_block, required: true
  defp svg_thin(assigns) do
    ~H"""
    <svg xmlns="http://www.w3.org/2000/svg" {@rest}>
    <%%= render_slot(@inner_block) %>
    </svg>
    """
  end

  <%= for icon <- @icons, {func, [bold, duotone, fill, light, regular, thin]} = icon do %>
  @doc """
  Renders the `<%= func %>` icon.

  By default, the outlined (24x24) component is used, but the `solid` or `mini`
  attributes can be provided for alternative styles.

  You may also pass arbitrary HTML attributes to be applied to the svg tag.

  ## Examples

  ```heex
  <Heroicons.<%= func %> />
  <Heroicons.<%= func %> class="w-4 h-4" />
  <Heroicons.<%= func %> solid />
  <Heroicons.<%= func %> mini />
  <Heroicons.<%= func %> outline />
  ```
  """
  attr :rest, :global, doc: "the arbitrary HTML attributes for the svg container", include: ~w(fill stroke stroke-width)
  attr :regular, :boolean, default: true
  attr :bold, :boolean, default: false
  attr :duotone, :boolean, default: false
  attr :fill, :boolean, default: false
  attr :light, :boolean, default: false
  attr :thin, :boolean, default: false

  def <%= func %>(assigns) do
    svg(assign(assigns, paths: %{
              regular: ~S|<%= regular %>|,
              bold: ~S|<%= bold %>|,
              duotone: ~S|<%= duotone %>|,
              fill: ~S|<%= fill %>|,
              light: ~S|<%= light %>|,
              thin: ~S|<%= thin %>|
               }))
  end
  <% end %>
end
