/* eslint-disable spellcheck/spell-checker */
'use client';
import React from 'react';
import { Card, Form, Row, Col, Input, Button } from 'antd';
import type { FormInstance } from 'antd';
import MasterCities from '@/components/masterDropdowns/MasterCities';

interface Props {
  form: FormInstance;
  selectedCityId: number | null;
  forUserId: number;
  forUserName: string;
  onSubmit: (forUserId: number, forUserName: string) => void;
}

const NewLaunchFormCard: React.FC<Props> = ({ form, selectedCityId, forUserId, forUserName, onSubmit }) => (
  <Card size="small" style={{ background: '#f6ffed', border: '1px solid #b7eb8f', marginBottom: 8 }}>
    <Form form={form} layout="vertical">
      <Row gutter={12}>
        <Col xs={24} md={12}>
          <Form.Item
            name="name"
            label="Launch Name"
            rules={[
              { required: true, message: 'Please enter a launch name' },
              {
                pattern: /^[A-Za-z0-9][A-Za-z0-9 _.-]*$/,
                message: 'Only letters, numbers, spaces, hyphens, underscores and periods are allowed',
              },
            ]}
          >
            <Input placeholder="e.g. Tower C Phase 2" />
          </Form.Item>
        </Col>
        <Col xs={24} md={12}>
          <Form.Item
            name="location"
            label="Location"
            rules={[{ required: true, message: 'Please enter location' }]}
          >
            <Input placeholder="e.g. Mumbai, Bangalore" />
          </Form.Item>
        </Col>
      </Row>
      <Row gutter={12}>
        <Col xs={24} md={12}>
          <MasterCities
            label="City"
            name="city_id"
            placeholder="Select City"
            filter={{ status: 'active' }}
            rules={[{ required: true, message: 'Please select a city' }]}
            disabled={!!selectedCityId}
            onChange={(value) => form.setFieldsValue({ city_id: value })}
          />
        </Col>
      </Row>
      <Button type="primary" size="small" onClick={() => onSubmit(forUserId, forUserName)}>
        Create Launch
      </Button>
    </Form>
  </Card>
);

export default NewLaunchFormCard;
