"use client"

import * as React from 'react';
import Card from '@mui/material/Card';
import InputAdornment from '@mui/material/InputAdornment';
import OutlinedInput from '@mui/material/OutlinedInput';
import { MagnifyingGlass as MagnifyingGlassIcon } from '@phosphor-icons/react/dist/ssr/MagnifyingGlass';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
import Box from '@mui/material/Box';

interface TabPanelProps {
  children?: React.ReactNode;
  index: number;
  value: number;
}

interface AboutFiltersProps {
  value: number;
  onChange: (event: React.SyntheticEvent, newValue: number) => void;
  onSearchChange: (query: string) => void;
  onSearchChange1: (query: string) => void;
}

function CustomTabPanel(props: TabPanelProps) {
  const { children, value, index, ...other } = props;

  return (
    <div
      role="tabpanel"
      hidden={value !== index}
      id={`simple-tabpanel-${index}`}
      aria-labelledby={`simple-tab-${index}`}
      {...other}
    >
      {value === index && <Box sx={{ p: 3 }}>{children}</Box>}
    </div>
  );
}

function a11yProps(index: number) {
  return {
    id: `simple-tab-${index}`,
    'aria-controls': `simple-tabpanel-${index}`,
  };
}

export function AboutFilters({value,onChange,onSearchChange,onSearchChange1}:AboutFiltersProps): React.JSX.Element {
  
  const [searchText, setSearchText] = React.useState('');
  const [searchText1, setSearchText1] = React.useState('');

  React.useEffect(() => {
    const delayDebounceFn = setTimeout(() => {
      onSearchChange(searchText);
      onSearchChange1(searchText1);
    }, 300);

    return () => clearTimeout(delayDebounceFn);
  }, [searchText, onSearchChange, searchText1, onSearchChange1]);

  const handleSearchChange = (event: React.ChangeEvent<HTMLInputElement>) => {
    setSearchText(event.target.value);
  };
  const handleSearchChange1 = (event: React.ChangeEvent<HTMLInputElement>) => {
    setSearchText1(event.target.value);
  };


  return (
<Card sx={{ p: 2,pr:10 }}>
  <Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', width: '100%' }}>
    <OutlinedInput
      onChange={(event:any) => {
        if (value === 1) { 
          handleSearchChange(event);
        } else if (value === 2) { 
          handleSearchChange1(event);
        }
      }}
      fullWidth
      placeholder="Search..."
      startAdornment={
        <InputAdornment position="start">
          <MagnifyingGlassIcon fontSize="var(--icon-fontSize-md)" />
        </InputAdornment>
      }
      sx={{ maxWidth: '500px', borderRadius:'35px',height:'45px', '& .MuiOutlinedInput-notchedOutline': {
        borderColor: 'none', // Default border color
      },
      '&.Mui-focused .MuiOutlinedInput-notchedOutline': {
        borderColor: 'black', // Yellow border color on focus
      }, }}
    />

    <Box sx={{ ml: 2}}>
      <Tabs value={value} onChange={onChange} sx={{border:'1px solid #b3b9c6',borderRadius:'25px',
      width:'330px',
      '& .MuiTabs-indicator': {
        backgroundColor: 'transparent' 
      }}} aria-label="basic tabs example">
        <Tab label="About" {...a11yProps(0)}  sx={{
        bgcolor: value === 0 ? '#000000' : 'transparent',
        borderRadius:'25px',
        px:'10px',
        minWidth:'30%',
        marginLeft:'0px',
        // color:'black',
        '&.Mui-selected': {
          marginLeft:'0px', 
        color: '#FFDD31', 
      },
      // '& .mui-1bjxqox-MuiButtonBase-root-MuiTab-root+.mui-1bjxqox-MuiButtonBase-root-MuiTab-root': {
      //     marginLeft: '0px', // Apply marginLeft 0px for the last tab
      //   },
      }}/>
        <Tab label="Testimonials" {...a11yProps(1)} sx={{
        bgcolor: value === 1 ? '#000000' : 'transparent',
        borderRadius:'25px',
        px:'10px',
        minWidth:'30%',
        marginLeft:'0px',
        // color:'black',
        '&.Mui-selected': {
          marginLeft:'0px',
        color: '#FFDD31', 
      },
      '& .mui-1bjxqox-MuiButtonBase-root-MuiTab-root+.mui-1bjxqox-MuiButtonBase-root-MuiTab-root': {
          marginLeft: '0px', // Apply marginLeft 0px for the last tab
        },
      }} />
        <Tab label="Success Stories" {...a11yProps(2)} sx={{
        bgcolor: value === 2 ? '#000000' : 'transparent',
        borderRadius:'25px',
        px:'10px',
        minWidth:'30%',
        marginLeft:'0px',
        // color:'black',
        '&.Mui-selected': {
          marginLeft:'0px',
        color: '#FFDD31', 
      },
// '& .mui-1bjxqox-MuiButtonBase-root-MuiTab-root+.mui-1bjxqox-MuiButtonBase-root-MuiTab-root': {
//           marginLeft: '0px', // Apply marginLeft 0px for the last tab
//         },
      }} />
      </Tabs>
    </Box>
  </Box>
</Card>
  );
}
