import React, { useState } from 'react';

const STORAGE_KEY = 'dexos-cookie-consent';

const CookieBanner = () => {
  const [visible, setVisible] = useState(() => !localStorage.getItem(STORAGE_KEY));

  const handleConsent = (accepted) => {
    localStorage.setItem(STORAGE_KEY, accepted ? 'accepted' : 'rejected');
    setVisible(false);
  };

  if (!visible) return null;

  return (
    <div className="cookie-banner" role="dialog" aria-modal="true" aria-label="Zgoda na pliki cookie">
      <div className="cookie-content">
        <h4>Ciasteczka</h4>
        <p>Używamy plików cookie, aby dostarczać spersonalizowane treści i analizować ruch na stronie.</p>
        <div className="cookie-actions">
          <button className="button-secondary" onClick={() => handleConsent(false)}>
            Odrzuć
          </button>
          <button className="button-primary" onClick={() => handleConsent(true)}>
            Akceptuj
          </button>
        </div>
      </div>
    </div>
  );
};

export default CookieBanner;
