import React, { useState, useEffect } from "react"; import { __, sprintf } from "@wordpress/i18n"; import apiFetch from '@wordpress/api-fetch'; import EditFont from "../fonts/edit/EditFont"; import { useSelector, useDispatch } from 'react-redux'; import Custom_Fonts_Icons from "@Common/svg-icons"; const ListItem = ({ item }) => { const [active, setActive] = useState(false); const [checkDelete, setCheckDelete] = useState(false); const [editFontId, setEditFontId] = useState(item.id); const [editFontType, setEditFontType] = useState(item['font-type'] ? item['font-type'] : 'local'); const [editFontName, setEditFontName] = useState(item.title); const [openPopup, setOpenPopup] = useState(false); const [removeTitle, setRemoveTitle] = useState(__( 'Remove', 'custom-fonts')); const updatedEditData = useSelector( ( state ) => state.editFont ); const [editFontData, setEditFontData] = useState(updatedEditData); const dispatch = useDispatch(); useEffect( () => { if ( openPopup ) { setEditFontData( editFontData ); dispatch( { type: 'SET_EDIT_FONT', payload: editFontData } ); } else { setEditFontData( null ); dispatch( { type: 'SET_EDIT_FONT', payload: null } ); } }, [openPopup] ); const deleteFontPost = ( e ) => { e.preventDefault(); e.stopPropagation(); setRemoveTitle(__( 'Removing...', 'custom-fonts')); const formData = new window.FormData(); formData.append( 'action', 'bcf_delete_font' ); formData.append( 'security', bsf_custom_fonts_admin.delete_font_nonce ); formData.append( 'font_id', e.target.dataset.font_id ); apiFetch( { url: bsf_custom_fonts_admin.ajax_url, method: 'POST', body: formData, } ).then( (response) => { if ( response.success ) { setTimeout( () => { window.location.reload(); }, 500 ); } } ) .catch((error) => { console.error('Error during API request:', error); }); }; const getFontWeightTitle = ( weight, type, style ) => { if ( undefined === weight ) { weight = '400'; } let updatedWeight = weight, oldWeight = ( 'google' === type ) ? weight : style; if ( 'italic' === weight ) { oldWeight = '400italic'; } if ( oldWeight.includes('italic') ) { updatedWeight = `${oldWeight.replace('italic', '')} ` + __( 'Italic', 'custom-fonts' ); } switch ( weight ) { case '100': case '100italic': return __( 'Thin ', 'custom-fonts' ) + updatedWeight; case '200': case '200italic': return __( 'Extra Light ', 'custom-fonts' ) + updatedWeight; case '300': case '300italic': return __( 'Light ', 'custom-fonts' ) + updatedWeight; case '400': case '400italic': return __( 'Regular ', 'custom-fonts' ) + updatedWeight; case '500': case '500italic': return __( 'Medium ', 'custom-fonts' ) + updatedWeight; case '600': case '600italic': return __( 'Semi Bold ', 'custom-fonts' ) + updatedWeight; case '700': case '700italic': return __( 'Bold ', 'custom-fonts' ) + updatedWeight; case '800': case '800italic': return __( 'Extra Bold ', 'custom-fonts' ) + updatedWeight; case '900': case '900italic': return __( 'Ultra-Bold ', 'custom-fonts' ) + updatedWeight; default: return updatedWeight; } } const setupEditFontScreen = (e) => { e.stopPropagation(); const fontId = e.target.dataset.font_id; const fontType = e.target.dataset.font_type; const fontName = e.target.dataset.font_name; setOpenPopup(! openPopup); setEditFontId(fontId); setEditFontType(fontType); setEditFontName(fontName); } const getAssetDetail = ( fontItem ) => { const fontType = fontItem['font-type'] ? fontItem['font-type'] : 'local'; if ( fontType === 'local' ) { return } else { const fontName = fontItem.title.replace( / /g, "+" ); return } } const getRenderFontWeight = (weight) => { if ( undefined === weight ) { weight = '400'; } if ( weight.includes('italic') ) { return weight.replace( "italic", "" ); } return weight; } const getFontAssetLink = (type, font, weight, version) => { if ( type === 'local' ) { return ''; } const fontName = font.replace( / /g, "+" ); return } const getFontStyle = (type, style, weight) => { let considerStyler = ( '' === type || 'local' === type ) ? style : weight; if ( undefined === considerStyler || '' === considerStyler ) { return 'normal'; } if ( considerStyler.includes('italic') ) { return 'italic'; } return style; } const expandFontItem = (e) => { e.preventDefault(); e.stopPropagation(); setActive(!active); } const setupDeleteFontPost = (e) => { e.preventDefault(); e.stopPropagation(); setCheckDelete(true) } const setupCancelDeletingFontPost = (e) => { e.preventDefault(); e.stopPropagation(); setCheckDelete(false); } return ( <>
{ getAssetDetail(item) }

{item['fonts-data'].font_name}

{`(${item['fonts-data']['variations'] ? item['fonts-data']['variations'].length : 0} ${__( 'variants', 'custom-fonts' )})`}
{checkDelete ? (
{ sprintf( /* translators: %s: Font name. */ __( 'Remove "%s" font?', 'custom-fonts' ), item.title ) }
{__('Cancel', 'custom-fonts')}
{removeTitle}
) : (
{__('Edit', 'custom-fonts')}
{__('Remove', 'custom-fonts')}
)}
setActive(!active)} className="sm:ml-11 mobile:ml-2 cursor-pointer" > {Custom_Fonts_Icons['dropdownlistitem']}
{active && item['fonts-data']['variations'] && (
{ item['fonts-data']['variations'].map(( varItem, varKey ) => (
{getFontAssetLink(item['font-type'], item.title, varItem.font_weight, varKey)}
{ getFontWeightTitle( varItem.font_weight, item['font-type'], varItem.font_style ) }

{__('How vexingly quick daft zebras jump!', 'custom-fonts')}

)) }
)}
{ } ); }; export default ListItem; Site is undergoing maintenance
logo

Website is under maintenance

Thank you for your patience!

© Air Patrol North Ltd. 2025

Deprecated: Function WP_Dependencies->add_data() was called with an argument that is deprecated since version 6.9.0! IE conditional comments are ignored by all supported browsers. in /home/airpatrolnorth/public_html/wp-includes/functions.php on line 6131