import React from 'react';
import { Tabs } from 'antd';
import styled from 'styled-components';
import { motion, AnimatePresence } from 'framer-motion';

// 통합된 애니메이션 탭 컴포넌트
const AnimatedTabs = ({ items, activeKey, onChange }) => {
	return (
		<StyledTabs
			activeKey={activeKey}
			onChange={onChange}
			centered={true}
		>
			{items.map(item => (
				<Tabs.TabPane
					tab={item.label}
					key={item.key}
				>
					<AnimatePresence mode="wait">
						<motion.div
							key={activeKey}
							initial={{ opacity: 0, x: 50 }}
							animate={{ opacity: 1, x: 0 }}
							exit={{ opacity: 0, x: -50 }}
							transition={{
								type: "spring",
								stiffness: 300,
								damping: 30
							}}
						>
							{item.children}
						</motion.div>
					</AnimatePresence>
				</Tabs.TabPane>
			))}
		</StyledTabs>
	);
};

const StyledTabs = styled(Tabs)`
    margin-top: 20px;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;

    .ant-tabs-nav {
        margin-bottom: 16px;
        width: 80%;
    }

    .ant-tabs-nav-wrap {
        justify-content: center;
    }

    .ant-tabs-tab {
        padding: 8px 16px;
        font-size: 14px;
        font-weight: 500;
        transition: all 0.3s;
    }

    .ant-tabs-tab.ant-tabs-tab-active .ant-tabs-tab-btn {
        color: #1890ff;
        font-weight: 600;
    }

    .ant-tabs-ink-bar {
        background-color: #1890ff;
    }

    .ant-tabs-content-holder {
        width: 100%;
        overflow: hidden;
    }
`;

export default AnimatedTabs;
