"use client";
import React, { useEffect, useState } from "react";
import { Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious } from "@/components/ui/pagination";
import { Checkbox } from "@/components/ui/checkbox";
import { Icon } from "@iconify/react/dist/iconify.js";
import { getListContent } from "@/service/landing/landing";
import { formatDateToIndonesian } from "@/utils/globals";

const categories = [
  { id: 1, title: "HUT HUMAS KE - 73" },
  { id: 2, title: "OPERASI ZEBRA 2024" },
  { id: 3, title: "PON XXI" },
  { id: 4, title: "OPS LILIN NATARU 2024" },
  { id: 5, title: "HUT HUMAS KE - 72" },
  { id: 6, title: "OPS MANTAP PRAJA & PILKADA 2024" },
  { id: 6, title: "OPS KETUPAT 2024" },
  { id: 6, title: "OPS PATUH 2024" },
  { id: 6, title: "HARI JUANG POLRI" },
  { id: 6, title: "HUT RI KE-79" },
  { id: 6, title: "HARI BHAYANGKARA KE-78" },
];

const formatAudio = [
  { id: 1, title: "WAV" },
  { id: 2, title: "MP3" },
];

const FilterPage = () => {
  const [audioData, setAudioData] = useState<any>();
  const [page, setPage] = useState(1);
  useEffect(() => {
    initFetch();
  }, []);
  const initFetch = async () => {
    const response = await getListContent({ page: page - 1, size: 12, sortBy: "createdAt", contentTypeId: "4" });
    console.log(response);
    setAudioData(response?.data?.data?.content);
  };
  return (
    <div className="flex flex-col">
      {/* Header */}
      <div className="flex flex-col md:flex-row items-start gap-5 p-10 bg-gray-200">
        <p>
          {" "}
          Audio {">"} <span className="font-bold">Semua Audio</span>
        </p>
        <p className="font-bold">|</p>
        <p>Terdapat 32499 artikel berisi Audio yang dapat diunduh </p>
      </div>
      {/* Left */}
      <div className="flex flex-col lg:flex-row gap-6 p-4">
        {/* Sidebar Kiri */}
        <div className="lg:w-1/4 w-full bg-white p-4 rounded-lg shadow-md">
          <h2 className="text-lg font-semibold mb-4">Filter</h2>
          <div className="space-y-6">
            {/* Pencarian */}
            <div>
              <label htmlFor="search" className="block text-sm font-medium text-gray-700">
                Pencarian
              </label>
              <input type="text" id="search" placeholder="Cari judul..." className="mt-1 w-full border rounded-md py-2 px-3 focus:ring-red-500 focus:border-red-500" />
            </div>

            {/* Tahun & Bulan */}
            <div>
              <label htmlFor="month" className="block text-sm font-medium text-gray-700">
                Pilih Tahun & Bulan
              </label>
              <input type="month" id="month" className="mt-1 w-full border rounded-md py-2 px-3 focus:ring-red-500 focus:border-red-500" />
            </div>

            {/* Tanggal */}
            <div>
              <label htmlFor="date" className="block text-sm font-medium text-gray-700">
                Pilih Tanggal
              </label>
              <input type="date" id="date" className="mt-1 w-full border rounded-md py-2 px-3 focus:ring-red-500 focus:border-red-500" />
            </div>

            {/* Kategori */}
            <div>
              <h3 className="text-sm font-medium text-gray-700">Kategori</h3>
              <ul className="mt-2 space-y-2">
                {categories.map((category) => (
                  <li key={category?.id}>
                    <label className="inline-flex items-center">
                      <Checkbox id="terms" />
                      <span className="ml-2 text-gray-700">{category.title}</span>
                    </label>
                  </li>
                ))}
              </ul>
            </div>
            {/* Garis */}
            <div className="border-t border-black my-4"></div>
            {/* Garis */}
            <div>
              <h3 className="text-sm font-medium text-gray-700">Format Foto</h3>
              <ul className="mt-2 space-y-2">
                {formatAudio.map((format) => (
                  <li key={format?.id}>
                    <label className="inline-flex items-center">
                      <Checkbox id="terms" />
                      <span className="ml-2 text-gray-700">{format.title}</span>
                    </label>
                  </li>
                ))}
              </ul>
            </div>
          </div>
        </div>

        {/* Konten Kanan */}
        <div className="flex-1">
          <div className="flex flex-col items-end mb-4">
            <h2 className="text-lg font-semibold tetx-red-300">Urutkan berdasarkan</h2>
            <select className="border rounded-md py-2 px-3 focus:ring-red-500 focus:border-red-500">
              <option value="terbaru">Terbaru</option>
              <option value="terlama">Terpopuler</option>
            </select>
          </div>
          {/* Card */}
          <div className=" grid grid-cols-1 gap-6 ">
            {audioData?.map((audio: any) => (
              <a href="#" key={audio?.id} className="flex flex-col sm:flex-row items-center hover:scale-110 transition-transform duration-300 bg-white dark:bg-gray-800 cursor-pointer shadow-md rounded-lg p-4 gap-4 w-full">
                <div className="flex items-center justify-center bg-red-500 text-white rounded-lg w-16 h-16">
                  <svg width="32" height="34" viewBox="0 0 32 34" fill="null" xmlns="http://www.w3.org/2000/svg">
                    <path
                      d="M23.404 0.452014C23.7033 0.35857 24.0204 0.336816 24.3297 0.388509C24.639 0.440203 24.9318 0.563895 25.1845 0.749599C25.4371 0.935304 25.6426 1.17782 25.7843 1.45756C25.9259 1.73731 25.9998 2.04644 26 2.36001V14.414C25.3462 14.2296 24.6766 14.1064 24 14.046V8.36001L10 12.736V27C10 28.1264 9.6197 29.2197 8.92071 30.1029C8.22172 30.9861 7.24499 31.6075 6.14877 31.8663C5.05255 32.125 3.90107 32.0061 2.88089 31.5287C1.86071 31.0514 1.03159 30.2435 0.52787 29.2361C0.024152 28.2286 -0.124656 27.0806 0.105556 25.9781C0.335768 24.8755 0.931513 23.883 1.79627 23.1613C2.66102 22.4396 3.74413 22.031 4.87009 22.0017C5.99606 21.9724 7.09893 22.3242 8.00001 23V6.73601C7.99982 6.30956 8.13596 5.8942 8.38854 5.55059C8.64112 5.20698 8.99692 4.9531 9.40401 4.82601L23.404 0.452014ZM10 10.64L24 6.26601V2.36001L10 6.73601V10.64ZM5.00001 24C4.20436 24 3.44129 24.3161 2.87869 24.8787C2.31608 25.4413 2.00001 26.2044 2.00001 27C2.00001 27.7957 2.31608 28.5587 2.87869 29.1213C3.44129 29.6839 4.20436 30 5.00001 30C5.79566 30 6.55872 29.6839 7.12133 29.1213C7.68394 28.5587 8.00001 27.7957 8.00001 27C8.00001 26.2044 7.68394 25.4413 7.12133 24.8787C6.55872 24.3161 5.79566 24 5.00001 24ZM32 25C32 27.387 31.0518 29.6761 29.364 31.364C27.6761 33.0518 25.387 34 23 34C20.6131 34 18.3239 33.0518 16.636 31.364C14.9482 29.6761 14 27.387 14 25C14 22.6131 14.9482 20.3239 16.636 18.6361C18.3239 16.9482 20.6131 16 23 16C25.387 16 27.6761 16.9482 29.364 18.6361C31.0518 20.3239 32 22.6131 32 25ZM27.47 24.128L21.482 20.828C21.3298 20.7443 21.1583 20.7016 20.9846 20.7043C20.8108 20.707 20.6408 20.7549 20.4912 20.8433C20.3416 20.9317 20.2176 21.0576 20.1315 21.2086C20.0453 21.3595 20 21.5302 20 21.704V28.304C20 28.4778 20.0453 28.6486 20.1315 28.7995C20.2176 28.9504 20.3416 29.0763 20.4912 29.1647C20.6408 29.2531 20.8108 29.301 20.9846 29.3037C21.1583 29.3064 21.3298 29.2638 21.482 29.18L27.47 25.88C27.6268 25.7937 27.7575 25.6669 27.8486 25.5128C27.9397 25.3587 27.9877 25.183 27.9877 25.004C27.9877 24.825 27.9397 24.6493 27.8486 24.4952C27.7575 24.3412 27.6268 24.2143 27.47 24.128Z"
                      fill="white"
                    />
                  </svg>
                </div>

                <div className="flex flex-col  flex-1">
                  <div className="text-gray-500 dark:text-gray-400 flex flex-row text-sm">
                    {formatDateToIndonesian(new Date(audio?.createdAt))} {audio?.timezone ? audio?.timezone : "WIB"} | <Icon icon="formkit:eye" width="15" height="15" /> 518
                  </div>
                  <div className="font-semibold text-gray-900 dark:text-white mt-1 text-sm">{audio?.title}</div>
                </div>
                <div className="flex items-center justify-center gap-3">
                  <div className="mt-2">
                    <img src="/assets/wave.svg" className="w-80" />
                  </div>
                  <div className="flex flex-row items-center justify-center text-gray-500 dark:text-gray-400">
                    <img src="/assets/audio-icon.png" alt="#" className="flex items-center justify-center" />
                    <div className="flex mx-2 items-center justify-center">{audio?.duration}</div>
                    <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20">
                      <path fill="#f00" d="M7.707 10.293a1 1 0 1 0-1.414 1.414l3 3a1 1 0 0 0 1.414 0l3-3a1 1 0 0 0-1.414-1.414L11 11.586V6h5a2 2 0 0 1 2 2v7a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h5v5.586zM9 4a1 1 0 0 1 2 0v2H9z" />
                    </svg>
                  </div>
                </div>
              </a>
            ))}
          </div>
        </div>
      </div>
      <Pagination className="p-3">
        <PaginationContent>
          <PaginationItem>
            <PaginationPrevious href="#" />
          </PaginationItem>
          <PaginationItem>
            <PaginationLink href="#">1</PaginationLink>
          </PaginationItem>
          <PaginationItem>
            <PaginationLink href="#" isActive>
              2
            </PaginationLink>
          </PaginationItem>
          <PaginationItem>
            <PaginationLink href="#">3</PaginationLink>
          </PaginationItem>
          <PaginationItem>
            <PaginationEllipsis />
          </PaginationItem>
          <PaginationItem>
            <PaginationNext href="#" />
          </PaginationItem>
        </PaginationContent>
      </Pagination>
    </div>
  );
};

export default FilterPage;
