import React from 'react';
import styled from 'styled-components';
import ModalPortal from '../Abstractions/ModalPortal';
import { Button, ButtonTypes } from '../Button';
import { DraggableContainer } from '../DraggableContainer';
import ShopImage from './shopImage.png';

export interface IShopModalProps {
    onClose: () => void;
    message?: string;
    url: string
}

export const ShopModal: React.FC<IShopModalProps> = ({
    onClose,
    message,
    url,
}) => {
    const openShop = () => {
        window.open(url, "_blank");
        onClose()
    }

    return (
        <ModalPortal>
            <Container onPointerDown={onClose}>
                <DraggableContainer width="auto" dragDisabled>
                    <Wrapper onPointerDown={e => e.stopPropagation()}>
                        <BackgroundContainer />
                        <Description>{message ?? 'Check out our shop items to prevent future death and enhance your gameplay!'}</Description>
                        <ButtonsWrapper>
                            <div className="cancel-button">
                                <Button
                                    buttonType={ButtonTypes.RPGUIButton}
                                    onPointerDown={onClose}
                                >
                                    Back to Game
                                </Button>
                            </div>
                            <Button
                                buttonType={ButtonTypes.RPGUIButton}
                                onPointerDown={openShop}
                            >
                                Go to Shop
                            </Button>
                        </ButtonsWrapper>
                    </Wrapper>
                </DraggableContainer>
            </Container>
        </ModalPortal>
    );
};

const Container = styled.div`
  position: absolute;
  width: 100%;
  height: 100%;
  left: 0;
  top: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1001;
`;

const Wrapper = styled.div`
  p {
    margin: 0;
  }
`;

const ButtonsWrapper = styled.div`
  display: flex;
  justify-content: space-around;
  gap: 5px;
  margin-top: 5px;
  padding-left: 10%;
  padding-right: 10%;

  .cancel-button {
    filter: grayscale(0.7);
  }
`;

const Description = styled.div`
    padding-left: 15%;
    padding-right: 15%;
    color: white;
    font-size: 10px ;
    line-height: 15px;
    padding-top: 10px;
    padding-bottom: 10px;
`

const BackgroundContainer = styled.div`
  position: relative; /* Certifique-se de que o pai tem posição relativa */
  background-image: url(${ShopImage});
  background-size: 70%;
  background-position: center;
  background-repeat: no-repeat;
  height: 300px;
  margin-bottom: 10px;
::before {
    content: ''; /* necessário para pseudo-elementos */
    position: absolute; /* posição absoluta em relação ao seu pai */
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4); /* cor de fundo preta com opacidade de 50% */
    z-index: 1; /* garantir que o overlay esteja acima da imagem de fundo */
    width: 70%;
    margin: auto;
  }
   > * {
    position: relative;
    z-index: 2;
  }
`
