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

const Wrapper = styled.ul<any>`
    display: block;
    padding: 0;
    bottom: 1em;
    text-align: center;
    position: absolute;
    width: 100%;
    height: 3px;
`;
const VerticalWrap = styled.ul`
    position: absolute;
    bottom: 0;
    margin: 0 0 20px;
    padding: 0;
    width: 1px;
    right: -17px;
    display: flex;
    flex-direction: column;
    background: #d8d8d8;
`;
const ItemWrap = styled.li`
    position: relative;
    display: inline-block;
    margin: 0 2px;
    padding: 0;
    text-align: center;
    vertical-align: top;
`;
const VItemWrap = styled.li`
    position: relative;
    display: inline-block;
    margin: 0;
    padding: 0;
    text-align: center;
    vertical-align: top;
`;
const Btn = styled.button<any>`
    display: block;
    width: ${p => (p.active ? 24 : 12)}px;
    height: 3px;
    padding: 0;
    color: transparent;
    font-size: 0;
    background: #fff;
    border: 0;
    border-radius: 1px;
    outline: none;
    cursor: pointer;
    opacity: 0.7;
    transition: all 0.5s;
`;
const VBtn = styled.button<any>`
    display: block;
    height: 40px;
    width: 1px;
    padding: 0;
    color: transparent;
    font-size: 0;
    background: ${p => (p.active ? '#1A1E2A' : 'transparent')};
    border: 0;
    border-radius: 1px;
    outline: none;
    cursor: pointer;
    opacity: 0.7;
    transition: all 0.5s;
`;

const Page = styled.span`
    width: 18px;
    height: 20px;
    opacity: 1;
    font-size: 13px;
    color: #1a1e2a;
    line-height: 20px;
    position: absolute;
    letter-spacing: 0.19px;
    top: -26px;
    left: -6px;
`;
const PageBottom = styled.span`
    width: 18px;
    height: 20px;
    opacity: 1;
    font-size: 13px;
    color: #1a1e2a;
    line-height: 20px;
    position: absolute;
    letter-spacing: 0.19px;
    bottom: -20px;
    left: -6px;
`;
type IProps = {
    activeIndex: number;
    total: number;
    outsideVertical: boolean;
};
const Indicator = function({ total, activeIndex, outsideVertical }: IProps) {
    return outsideVertical ? (
        <VerticalWrap>
            <Page>{'0' + (activeIndex + 1)}</Page>
            {[...(Array(total).keys() as any)].map(e => (
                <VItemWrap key={e}>
                    <VBtn active={e <= activeIndex} />
                </VItemWrap>
            ))}
            <PageBottom>{'0' + total}</PageBottom>
        </VerticalWrap>
    ) : (
        <Wrapper>
            {[...(Array(total).keys() as any)].map(e => (
                <ItemWrap key={e}>
                    <Btn active={e === activeIndex} />
                </ItemWrap>
            ))}
        </Wrapper>
    );
};
export default Indicator;
