import React, { useRef, useState } from 'react';
import { usePage, Head } from '@inertiajs/react';
import Layout from '../../../Layouts';
import {
  Card,
  Col,
  Container,
  Form,
  Row,
  Tab
} from 'react-bootstrap';
import BreadCrumb from '../../../Components/Common/BreadCrumb';
import { PuntoSuministro } from '../../../resources/PuntoSuministro';

const Edit = () => {
  const { punto } = usePage<{ punto: PuntoSuministro }>().props;
  // Puedes agregar aquí los estados y handlers necesarios para edición
  console.log(punto);
  return (
    <React.Fragment>
      <Head title="Editar Punto de Suministro" />
      <div className="page-content">
        <Container fluid>
          <BreadCrumb title="Puntos de Suministro" pageTitle="Editar" />
          <Row>
            <Col xl={12}>
              <Card>
                <Card.Header className="bg-light">
                  <h4 className="card-title mb-0">Editar Punto de Suministro</h4>
                </Card.Header>
                <Card.Body>
                  <form className="vertical-navs-step form-steps">
                    <Tab.Container defaultActiveKey={1}>
                      <Row className="gy-5">
                        <Col lg={12}>
                          <div className="px-lg-4 ">
                            <Card>
                              <Card.Header className="bg-light">
                                <h4 className="card-title mb-0">Datos del Punto de Suministro</h4>
                                <p className="text-muted">
                                  Edita los datos generales del punto de suministro.
                                </p>
                              </Card.Header>
                              <Card.Body>
                                <Row className="g-3">
                                  <Col md={4}>
                                    <Form.Label className="form-label">Cliente</Form.Label>
                                    <Form.Control
                                      type="text"
                                      value={punto.cliente?.RazSocCli || ''}
                                      disabled
                                    />
                                  </Col>
                                  <Col md={4}>
                                    <Form.Label className="form-label">Dirección</Form.Label>
                                    <Form.Control
                                      type="text"
                                      value={punto.NomViaPunSum || ''}
                                      disabled
                                    />
                                  </Col>
                                  <Col md={4}>
                                    <Form.Label className="form-label">Localidad</Form.Label>
                                    <Form.Control
                                      type="text"
                                      value={punto.localidad?.DesLoc || ''}
                                      disabled
                                    />
                                  </Col>
                                  <Col md={4}>
                                    <Form.Label className="form-label">Provincia</Form.Label>
                                    <Form.Control
                                      type="text"
                                      value={punto.localidad?.provincia?.DesPro || ''}
                                      disabled
                                    />
                                  </Col>
                                </Row>
                              </Card.Body>
                            </Card>
                            <Card className="mt-4">
                              <Card.Header className="bg-light">
                                <h5 className="card-title mb-0">CUPS Eléctricos</h5>
                              </Card.Header>
                              <Card.Body>
                                <table className="table table-bordered">
                                  <thead>
                                    <tr>
                                      <th>CUPS</th>
                                      <th>Pot. P1</th>
                                      <th>Pot. P2</th>
                                      <th>Pot. P3</th>
                                      <th>Pot. P4</th>
                                      <th>Pot. P5</th>
                                      <th>Pot. P6</th>
                                      <th>Tarifa</th>
                                      <th>Estado</th>
                                    </tr>
                                  </thead>
                                  <tbody>
                                    {punto.cups_electricos?.length ? punto.cups_electricos.map((cups, idx) => (
                                      <tr key={idx}>
                                        <td>{cups.CUPsEle}</td>
                                        <td>{cups.PotConP1}</td>
                                        <td>{cups.PotConP2}</td>
                                        <td>{cups.PotConP3}</td>
                                        <td>{cups.PotConP4}</td>
                                        <td>{cups.PotConP5}</td>
                                        <td>{cups.PotConP6}</td>
                                        <td>{cups.tarifa_electrica?.NomTarEle}</td>
                                        <td>{cups.EstCUPs === 1 ? 'Activo' : 'Inactivo'}</td>
                                      </tr>
                                    )) : (
                                      <tr><td colSpan={9} className="text-center">No hay CUPS eléctricos</td></tr>
                                    )}
                                  </tbody>
                                </table>
                              </Card.Body>
                            </Card>
                            <Card className="mt-4">
                              <Card.Header className="bg-light">
                                <h5 className="card-title mb-0">CUPS Gas</h5>
                              </Card.Header>
                              <Card.Body>
                                <table className="table table-bordered">
                                  <thead>
                                    <tr>
                                      <th>CUPS</th>
                                      <th>Caudal Diario</th>
                                      <th>Caudal Anual</th>
                                      <th>Tarifa</th>
                                      <th>Estado</th>
                                    </tr>
                                  </thead>
                                  <tbody>
                                    {punto.cups_gas?.length ? punto.cups_gas.map((cups, idx) => (
                                      <tr key={idx}>
                                        <td>{cups.CupsGas}</td>
                                        <td>{cups.caudaldiario}</td>
                                        <td>{cups.ConAnuCup}</td>
                                        <td>{cups.tarifa_gas?.NomTarGas}</td>
                                        <td>{cups.EstCUPs === 1 ? 'Activo' : 'Inactivo'}</td>
                                      </tr>
                                    )) : (
                                      <tr><td colSpan={5} className="text-center">No hay CUPS de gas</td></tr>
                                    )}
                                  </tbody>
                                </table>
                              </Card.Body>
                            </Card>
                          </div>
                        </Col>
                      </Row>
                    </Tab.Container>
                  </form>
                </Card.Body>
              </Card>
            </Col>
          </Row>
        </Container>
      </div>
    </React.Fragment>
  );
};

Edit.layout = (page: any) => <Layout children={page} />;
export default Edit; 