---


import FontAwesome from '@components/form/FontAwesome.svelte';
import { slugify } from '../../utils/fetch-data';

import type { Section } from '../../types/Service';

interface Props {
	title: string;
	sections: Section[];
  bigTitle?: boolean;
}

const { title, sections, bigTitle } = Astro.props;

---

<div class="wrap">

{ bigTitle ?
  <h2><FontAwesome iconName={slugify(title)} />{title} </h2> :
  <a class="category-title" href={`/${slugify(title)}`}><h3>{title}</h3></a>
}

{ !bigTitle && <span class="section-icon"><FontAwesome iconName={slugify(title)} /></span> }

<ul>
  {sections.map((section) => (
    <li class="section">
      <a href={`/${slugify(title)}/${slugify(section.name)}`}>
        <span>{section.name}</span> 
        <span class="service-count">({section.services ? section.services.length : 0})</span>
      </a>
    </li>
  ))}
</ul>
</div>


<style lang="scss">

.wrap {
  position: relative;
  &:hover {
    .section-icon :global(svg){
      opacity: 1;
      transform: scale(1.2);
    }
  }
}

h2 {
  font-family: "Lekton", sans-serif;
  font-size: 2rem;
  margin: -2rem 0 2rem -2rem;
  box-shadow: 6px 6px 0 var(--box-outline);
  border: 2px solid var(--box-outline);
  background: var(--accent);
  color: var(--accent-fg);
  width: fit-content;
  padding: 0.25rem 0.5rem;
  display: flex;
  justify-content: center;
  gap: 1rem;
  :global(svg) {
    width: 2rem;
    height: 2rem;
    color: var(--accent-fg);
  }
}

.category-title {
  text-decoration: none;
  color: var(--foreground);
  z-index: 2;
  position: relative;
  h3 {
    font-family: "Lekton", sans-serif;
    font-weight: bold;
    margin: 0;
    font-size: 1.8rem;
    position: relative;
    &:after {    
      background: none repeat scroll 0 0 transparent;
      bottom: 0;
      content: "";
      display: block;
      height: 3px;
      left: 50%;
      position: absolute;
      background: var(--accent);
      transition: width 0.3s ease 0s, left 0.3s ease 0s;
      width: 0;
    }
    &:hover:after { 
      width: 80%; 
      left: 0; 
    }
  }
  
}

ul {
  list-style: circle;
  padding-left: 1rem;
  li {
    margin: 0.5rem 0;
    font-size: 1.25rem;
    a {
      text-decoration: none;
      color: var(--foreground);
      position: relative;
      &:after {    
        background: none repeat scroll 0 0 transparent;
        bottom: 0;
        content: "";
        display: block;
        height: 2px;
        left: 50%;
        position: absolute;
        background: var(--accent-3);
        transition: width 0.15s ease 0s, left 0.15s ease 0s;
        width: 0;
      }
      &:hover:after {
        text-decoration: underline;
        width: 80%; 
        left: 0; 
      }
    }
    .service-count {
      color: var(--accent-3);
    }
  }
}

.section-icon {
  position: absolute;
  right: 0;
  top: 0;
  width: fit-content;
  :global(svg) {
    width: 2rem;
    height: 2rem;
    opacity: 0.5;
    text-shadow: 3px 3px 0 black;
    color: var(--accent-3);
    transition: all 0.2s ease-in-out;
  }
}
</style>
