<div class="wrapper">
  <div class="button-previous">&#10094;</div>
  <div class="square-wrapper">
    <div class="square">
      <div class="content-wrapper" style="background-image: url('https://images.unsplash.com/photo-1685171755238-0b1c05b0fd84?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1074&q=80') "> 
        <div class="content"> 
          <div class="text">This is the content of the Home page.</div>
          <div class="close-button">X</div>
        </div>
      </div>
      <div class="label">Домой</div>
    </div>
    <div class="square">
      <div class="content-wrapper" style="background-image: url('https://images.unsplash.com/photo-1682685797898-6d7587974771?ixlib=rb-4.0.3&ixid=M3wxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1170&q=80');"> 
        <div class="content"> 
          <div class="text">This is the content of the Gallery page.</div>
          <div class="close-button">X</div>
        </div>
      </div>
      <div class="label">Gallery</div>
    </div>
    <div class="square">
      <div class="content-wrapper" style="background-image: url('https://images.unsplash.com/flagged/photo-1553505192-acca7d4509be?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1190&q=80');"> 
        <div class="content"> 
          <div class="text">This is the content of the Portfolio page.</div>
          <div class="close-button">X</div>
        </div>
      </div>
      <div class="label">Portfolio</div>
    </div>
    <div class="square">
      <div class="content-wrapper" style="background-image: url('https://images.unsplash.com/photo-1687073558736-531dc8bfd15b?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1171&q=80');"> 
        <div class="content"> 
          <div class="text">This is the content of the Contact Us page.</div>
          <div class="close-button">X</div>
        </div>
      </div>
      <div class="label">Contact Us</div>
    </div>
    <div class="square">
      <div class="content-wrapper" style="background-image: url('https://images.unsplash.com/photo-1686842545569-97e13c7f992f?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1170&q=80');"> 
        <div class="content"> 
          <div class="text">This is the content of the About page.</div>
          <div class="close-button">X</div>
        </div>
      </div>
      <div class="label">About</div>
    </div>
  </div>
  <div class="button-next">&#10095;</div>
</div>
@import url("https://fonts.googleapis.com/css?family=Lato:100,300,400,700");
html,
body {
  width: 100%;
  height: 100%;
  font-family: Lato, sans-serif;
  color: white;
  background-image: linear-gradient(-20deg, #2b5876 0%, #4e4376 100%);
}
.content-wrapper {
  background-repeat: no-repeat !important;  
  background-size: cover !important;
}
 

.wrapper {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 350px;
  height: 200px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.wrapper div[class^=button] {
  width: 20px;
  height: 20px;
  padding: 10px;
  cursor: pointer;
  font-size: 20px;
  color: white;
  text-align: center;
  border-radius: 100%;
}
.wrapper div[class^=button]:hover {
  background: #1d3461;
  opacity: 0.8;
}
.wrapper div[class^=button]:active {
  background: white;
  opacity: 0.8;
}
.wrapper .square-wrapper {
  transform: rotate(-45deg);
  position: relative;
  width: 150px;
  height: 150px;
}
.wrapper .square-wrapper .square {
  position: absolute;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  border: 10px solid white;
  transition: all 0.6s cubic-bezier(0.645, 0.045, 0.355, 1);
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 1;
  visibility: visible;
}
.wrapper .square-wrapper .square.hide {
  opacity: 0;
  visibility: hidden;
}



.wrapper .square-wrapper .square .content-wrapper {
  position: absolute;
  color: white;
  width: 100%;
  height: 100%;
  background: inherit;
  will-change: transform;
  transition: all 1.5s cubic-bezier(0.86, 0, 0.07, 1);
}
.wrapper .square-wrapper .square .content-wrapper .content {
  display: none;
  position: relative;
  width: 100%;
  height: 100%;
  justify-content: center;
  align-items: center;
}
.wrapper .square-wrapper .square .content-wrapper .content .text {
  font-size: 40px;
  font-weight: 300;
  text-align: center;
}
.wrapper .square-wrapper .square .content-wrapper .content .close-button {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 40px;
  font-weight: 300;
  cursor: pointer;
}
.wrapper .square-wrapper .square .label {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 120px;
  text-align: center;
  transform: translate(-50%, -50%) rotate(45deg);
  text-transform: uppercase;
  cursor: pointer;
  color: white;
}
.wrapper .square-wrapper .square.expand .content-wrapper {
  width: 100vw;
  height: 100vh;
  transform: rotate(45deg);
}
.wrapper .square-wrapper .square.expand .label {
  display: none;
}
.wrapper .square-wrapper .square.expand.show-content .content {
  display: flex;
}
.wrapper .square-wrapper .square:nth-child(1) {
  z-index: 4;
}
.wrapper .square-wrapper .square:nth-child(2) {
  z-index: 3;
}
.wrapper .square-wrapper .square:nth-child(3) {
  z-index: 2;
}
.wrapper .square-wrapper .square:nth-child(4) {
  z-index: 1;
}
.wrapper .square-wrapper .square:nth-child(5) {
  z-index: 0;
}
.wrapper .square-wrapper .square:nth-child(4n+1) {
  transform-origin: left top;
  background: #f786aa;
}
.wrapper .square-wrapper .square:nth-child(4n+1).hide {
  transform: rotate(90deg);
}
.wrapper .square-wrapper .square:nth-child(4n+2) {
  transform-origin: right bottom;
  background: #f7d488;
}
.wrapper .square-wrapper .square:nth-child(4n+2).hide {
  transform: rotate(-90deg);
}
.wrapper .square-wrapper .square:nth-child(4n+3) {
  transform-origin: left top;
  background: #ffa8a9;
}
.wrapper .square-wrapper .square:nth-child(4n+3).hide {
  transform: rotate(-90deg);
}
.wrapper .square-wrapper .square:nth-child(4n+4) {
  transform-origin: right bottom;
  background: #f7d488;
}
.wrapper .square-wrapper .square:nth-child(4n+4).hide {
  transform: rotate(90deg);
}
let squares = document.querySelectorAll(".square");
let previousButton = document.querySelector(".button-previous");
let nextButton = document.querySelector(".button-next");
let currentIndex = 0;

previousButton.addEventListener("click", function () {
  if (squares[currentIndex - 1]) {
    squares[currentIndex - 1].classList.remove("hide");
    currentIndex--;
    updateButtons();
  }
});

nextButton.addEventListener("click", function () {
  if (squares[currentIndex + 1]) {
    squares[currentIndex].classList.add("hide");
    currentIndex++;
    updateButtons();
  }
});

function updateButtons() {
  if (currentIndex === 0) {
    previousButton.style.visibility = "hidden";
  } else {
    previousButton.style.visibility = "visible";
  }
  console.log(currentIndex);
  if (currentIndex + 1 === squares.length) {
    nextButton.style.visibility = "hidden";
  } else {
    nextButton.style.visibility = "visible";
  }
}

function toggleExpand() {
  squares[currentIndex].classList.toggle("expand");
  setTimeout(() => {
    squares[currentIndex].classList.toggle("show-content");
  }, 1500);
}

Array.from(document.querySelectorAll(".label")).forEach(element => {
  element.addEventListener("click", toggleExpand);
});

Array.from(document.querySelectorAll(".close-button")).forEach(element => {
  element.addEventListener("click", toggleExpand);
});

init();

function init() {
  updateButtons();
}