<template>
  <div :class="stickyClass">
    <v-row class="outil-row">
      <v-col cols="12">
        <div class="container-square">
          <v-row
            v-for="square in squares"
            :key="square.id"
            :class="square.bgColor"
            @click="() => handleSquareClick(square)"
          >
            <NuxtLink :to="square.url" class="link">
              <div>
                <v-icon :class="square.iconClass" />
                <p class="text-square">{{ square.text }}</p>
              </div>
            </NuxtLink>
          </v-row>
        </div>
      </v-col>
    </v-row>
  </div>
</template>

<script setup lang="ts">
import { ref, defineProps } from "vue";
import { useRouter } from "vue-router";

const router = useRouter();
const props = defineProps({
  shouldShowStickyMenu: Boolean,
  squaresData: Array,
});

const stickyClass = ref("sticky-scroll");

const squares = ref(props.squaresData);
const telephoneNumber = "09 72 12 60 17";
const handleSquareClick = (square) => {
  if (square.id === 2) {
    router.push({ path: square.url, query: { request: "demo" } });
  } else if (square.id === 4) {
    if (isMobileDevice()) {
      window.location.href = `tel:${telephoneNumber}`;
    } else {
      alert(`Notre numéro de téléphone : ${telephoneNumber}`);
    }
  } else {
    router.push({ path: square.url });
  }
};

const isMobileDevice = () => {
  return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
    navigator.userAgent
  );
};
</script>

<style scoped>
.link {
  text-decoration: none;
  color: white;
}

.container-square {
  display: flex;
  flex-direction: column;
  color: white;
  font-weight: 500;
  font-size: 0.7rem;
  line-height: 15px;
  text-align: center;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.red-square,
.yellow-square,
.blue-square,
.darkblue-square {
  position: relative;
  font-family: "Barlow";
  width: 10rem;
  padding: 1rem;
}

.yellow-square {
  background: #f9d648;
  color: #0e2d32;
}

.red-square {
  background: #d8050b;
}

.blue-square {
  background: rgb(125, 194, 198);
}

.darkblue-square {
  background: #0e2d32;
}

.text-square {
  margin: 0.5rem 2rem;
}
</style>
