import React from "react";
import styled from "styled-components";

/**
 *
 * @param {{zoom: number, color: string}} param0
 * @returns
 */
const Loader = ({ zoom, color, isOpen }) => {
  return (
    <Wrap zoom={zoom} isOpen={isOpen}>
      <Container zoom={zoom} color={color}>
        <div></div>
        <div></div>
        <div></div>
      </Container>
    </Wrap>
  );
};

const Wrap = styled.div`
  width: ${({ zoom, isOpen }) =>
    zoom && isOpen ? (zoom * 100 * 80) / 100 : 30}px;
  height: ${({ zoom, isOpen }) =>
    zoom && isOpen ? (zoom * 100 * 80) / 100 : 30}px;
  display: flex;
  align-items: center;
  justify-content: "center";
`;

const Container = styled.div`
  display: inline-block;
  position: relative;
  width: fit-content;
  height: fit-content;
  width: 80px;
  height: 80px;
  transform: scale(${({ zoom }) => zoom ?? 1});
  & > div {
    position: absolute;
    /* display: flex; */
    gap: 2px;
    left: 8px;
    width: 16px;
    background: ${({ color }) => color ?? "#fff"};
    animation: lds-facebook 1.2s cubic-bezier(0, 0.5, 0.5, 1) infinite;
  }
  & > div:nth-child(1) {
    left: 8px;
    animation-delay: -0.24s;
  }
  & > div:nth-child(2) {
    left: 32px;
    animation-delay: -0.12s;
  }
  & > div:nth-child(3) {
    left: 56px;
    animation-delay: 0;
  }
  @keyframes lds-facebook {
    0% {
      top: 8px;
      height: 64px;
    }
    50%,
    100% {
      top: 24px;
      height: 32px;
    }
  }
`;

export default Loader;
