import React from 'react';
import { Document, Page, Text, View, StyleSheet, Image } from '@react-pdf/renderer';
import { KLZLogoVector } from './KLZLogoVector';

export interface PersonData {
  name: string;
  role: string;
  phone: string;
  email: string;
}

interface PDFBusinessCardProps {
  person: PersonData;
  qrCodeDataUrl: string;
}

// Mintel Aesthetics Colors - EXACT PROD COLORS
const COLORS = {
  primary: '#011dff', // Bright Royal Blue
  primaryDark: '#000e7a',
  green: '#82ed20', // Brand Accent Green
  white: '#ffffff',
  grayText: '#6c757d',
  lightGray: '#f8f9fa',
};

const styles = StyleSheet.create({
  pageBleed: {
    // 85x55mm + 3mm bleed on each side = 91x61mm
    width: '91mm',
    height: '61mm',
    backgroundColor: COLORS.primary,
    position: 'relative',
    fontFamily: 'Helvetica',
    overflow: 'hidden',
  },
  pageBleedBack: {
    width: '91mm',
    height: '61mm',
    backgroundColor: COLORS.white,
    position: 'relative',
    fontFamily: 'Helvetica',
    overflow: 'hidden',
  },

  // -- FRONT --
  frontContainer: {
    flex: 1,
    position: 'relative',
  },
  frontLogoPos: {
    position: 'absolute',
    top: '8mm',
    right: '8mm',
  },
  frontBottomBar: {
    position: 'absolute',
    bottom: 0,
    left: 0,
    right: 0,
    height: '35mm',
    backgroundColor: COLORS.primaryDark,
    borderTopWidth: 2,
    borderTopColor: COLORS.green,
    display: 'flex',
    justifyContent: 'center',
    alignItems: 'center',
  },
  frontTagline: {
    color: COLORS.white,
    fontSize: 12,
    fontWeight: 'bold',
    letterSpacing: 2,
    textTransform: 'uppercase',
  },
  frontSubTagline: {
    color: COLORS.green,
    fontSize: 7,
    marginTop: 4,
    letterSpacing: 1,
    textTransform: 'uppercase',
  },

  // -- BACK --
  backContainer: {
    flex: 1,
    position: 'relative',
    padding: '6mm 6mm',
  },
  backLogo: {
    marginBottom: '8mm',
  },
  backMiddle: {
    flexDirection: 'row',
    justifyContent: 'space-between',
    alignItems: 'flex-start',
    width: '100%',
  },
  nameSection: {
    flexDirection: 'column',
    width: '35%',
  },
  nameText: {
    fontSize: 13,
    fontWeight: 'bold',
    color: COLORS.primary,
    marginBottom: 3,
  },
  roleText: {
    fontSize: 7,
    fontWeight: 'normal',
    color: COLORS.grayText,
    letterSpacing: 0.5,
    textTransform: 'uppercase',
  },
  contactSection: {
    flexDirection: 'column',
    width: '45%',
    paddingLeft: '3mm',
    borderLeftWidth: 1,
    borderLeftColor: COLORS.lightGray,
  },
  contactRow: {
    flexDirection: 'row',
    alignItems: 'center',
    marginBottom: 5,
  },
  iconCircle: {
    width: 6,
    height: 6,
    borderRadius: 3,
    backgroundColor: COLORS.green,
    marginRight: 6,
  },
  contactText: {
    fontSize: 6.5,
    color: COLORS.primaryDark,
    fontWeight: 'normal',
  },
  qrSection: {
    width: '20%',
    alignItems: 'flex-end',
  },
  qrCodeWrapper: {
    width: '15mm',
    height: '15mm',
    padding: 1,
    backgroundColor: COLORS.white,
  },
  qrCode: {
    width: '100%',
    height: '100%',
  },
  footer: {
    position: 'absolute',
    bottom: '5mm',
    left: '6mm',
    right: '6mm',
    flexDirection: 'row',
    justifyContent: 'flex-start',
    alignItems: 'center',
  },
  footerText: {
    fontSize: 6,
    color: COLORS.grayText,
    letterSpacing: 0.5,
  },
  pipe: {
    fontSize: 6,
    color: COLORS.green,
    marginHorizontal: 5,
    fontWeight: 'bold',
  },
});

export const PDFBusinessCard: React.FC<PDFBusinessCardProps> = ({ person, qrCodeDataUrl }) => {
  return (
    <Document
      title={`Business Card - ${person.name}`}
      author="KLZ Cables"
      creator="KLZ Print Engine"
    >
      {/* FRONT - Clean Modern KLZ Brand */}
      <Page size={[258, 173]} style={styles.pageBleed}>
        <View style={styles.frontLogoPos}>
          <KLZLogoVector width={110} color={COLORS.white} />
        </View>

        <View style={styles.frontBottomBar}>
          <Text style={styles.frontTagline}>Empowering Energy</Text>
          <Text style={styles.frontSubTagline}>High-Quality Cable Infrastructure</Text>
        </View>
      </Page>

      {/* BACK - Clean White with Bright Blue & Green Accents */}
      <Page size={[258, 173]} style={styles.pageBleedBack}>
        <View style={styles.backContainer}>
          <View style={styles.backLogo}>
            <KLZLogoVector width={70} color={COLORS.primary} />
          </View>

          <View style={styles.backMiddle}>
            <View style={styles.nameSection}>
              <Text style={styles.nameText}>{person.name}</Text>
              <Text style={styles.roleText}>{person.role}</Text>
            </View>

            <View style={styles.contactSection}>
              <View style={styles.contactRow}>
                <View style={styles.iconCircle} />
                <Text style={styles.contactText}>{person.phone}</Text>
              </View>
              <View style={styles.contactRow}>
                <View style={styles.iconCircle} />
                <Text style={styles.contactText}>{person.email}</Text>
              </View>
              <View style={styles.contactRow}>
                <View style={styles.iconCircle} />
                <Text style={styles.contactText}>klz-cables.com</Text>
              </View>
            </View>

            <View style={styles.qrSection}>
              <View style={styles.qrCodeWrapper}>
                <Image src={qrCodeDataUrl} style={styles.qrCode} />
              </View>
            </View>
          </View>

          <View style={styles.footer}>
            <Text style={styles.footerText}>KLZ Vertriebs GmbH</Text>
            <Text style={styles.pipe}>|</Text>
            <Text style={styles.footerText}>Raiffeisenstraße 22</Text>
            <Text style={styles.pipe}>|</Text>
            <Text style={styles.footerText}>73630 Remshalden</Text>
          </View>
        </View>
      </Page>
    </Document>
  );
};
