import { Modal, Text, Box, Flex, Button, TextInput, SegmentedControl } from "@mantine/core";
import { useState } from "react";
import { type NotificationFormType } from "./types";
import NotificationCard from "./notificationCard";

interface DevicePreviewModalProps {
    opened: boolean;
    onClose: () => void;
    data: NotificationFormType;
}

const DevicePreviewModal: React.FC<DevicePreviewModalProps> = ({
    opened,
    onClose,
    data,
}) => {
    const [device, setDevice] = useState<"ios" | "android">("ios");

    return (
        <Modal
            opened={opened}
            onClose={onClose}
            title="Device Preview"
            centered
            size={600}
        >
            <Flex justify="center" align="center" direction="column" gap="md">
                <Text size="sm" c="dimmed" ta="center" style={{ maxWidth: 420 }}>
                    This preview provides a general idea of how your message will appear on a mobile device.
                </Text>

                <SegmentedControl
                    value={device}
                    onChange={(val) => setDevice(val as "ios" | "android")}
                    data={[
                        { label: "iOS", value: "ios" },
                        { label: "Android", value: "android" },
                    ]}
                />

                <Box
                    style={{
                        width: "420px",
                        height: "600px",
                        border: "12px solid #1c1c1e",
                        borderRadius: "36px",
                        background: device === "ios"
                            ? "linear-gradient(180deg, #3a2a3f 0%, #1a1420 100%)"
                            : "linear-gradient(180deg, #c8c8ca 0%, #b9b8b6 100%)",
                        position: "relative",
                        overflow: "hidden",
                        boxShadow: "0 10px 25px rgba(0,0,0,0.2)",
                    }}
                >
                    <Box
                        style={{
                            height: "24px",
                            display: "flex",
                            justifyContent: "space-between",
                            alignItems: "center",
                            padding: "0 16px",
                        }}
                    >
                        <Text size="xs" fw={700} c="#fff">9:41</Text>
                        <Flex gap={4}>
                            <Box w={12} h={12} bg="white" style={{ borderRadius: '50%' }} opacity={0.3} />
                        </Flex>
                    </Box>

                    {device === "android" && (
                        <Text fz={14} fw={600} c="#fff" px="md" pt={14} style={{ textShadow: "0 1px 3px rgba(0,0,0,0.35)" }}>
                            Karma Subito
                        </Text>
                    )}

                    <Box p="sm" mt={device === "ios" ? "md" : 0}>
                        <NotificationCard title={data.title} body={data.text} image={data.image} device={device} />
                    </Box>
                </Box>

                <Box w="100%" style={{ maxWidth: 420 }}>
                    <Text size="sm" fw={500} mb={5}>Send Test Email</Text>
                    <Flex gap="xs">
                        <TextInput
                            placeholder="Enter email address"
                            style={{ flex: 1 }}
                            size="sm"
                        />
                        <Button size="sm" variant="filled" color="blue">Send</Button>
                    </Flex>
                </Box>
            </Flex>
        </Modal>
    );
};

export default DevicePreviewModal;
